Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
twitchyvr committed Nov 26, 2023
1 parent 75fed0f commit 7d6921b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
15 changes: 11 additions & 4 deletions src/headers/disk-sub-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ const SIZE_IN_BYTES = 32
* Total size: 32 bytes
*/
class DiskSubHeader {
/**
* DiskSubHeader constructor.
*
* params = {
* startDate,
* startTime,
* endTime,
* lapCount,
* recordCount
* }
*/
constructor (params) {
Object.assign(this, params)
}
Expand All @@ -14,10 +25,6 @@ class DiskSubHeader {
* Instantiate an instance of DiskSubHeader using the contents of the supplied buffer.
*/
static fromBuffer (buffer) {
if (buffer.length !== SIZE_IN_BYTES) {
throw new Error(`Expected buffer length of ${SIZE_IN_BYTES}, but got ${buffer.length}`)
}

return new DiskSubHeader({
startDate: buffer.slice(0, 8).readFloatLE(),
startTime: buffer.slice(8, 16).readDoubleLE(),
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = async function (context, req) {
context.log('Type of rawData:', typeof rawData)
context.log('Buffer size:', rawData.length)

<<<<<<< HEAD
// Try to process telemetry
try {
const telemetry = await Telemetry.fromBuffer(rawData)
Expand All @@ -27,6 +28,10 @@ module.exports = async function (context, req) {
variables: telemetry.variables(),
telemetry: telemetry.samples()
}
=======
// console.log('Telemetry headers:', telemetry.headers)
// console.log(telemetry.header)
>>>>>>> parent of 9cac5f7 (multiple updates)

context.res = {
status: 200,
Expand Down
18 changes: 2 additions & 16 deletions src/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,9 @@ class Telemetry {
* Telemetry constructor.
*/
constructor (telemetryHeader, diskSubHeader, sessionInfo, varHeaders, fd) {
// Throw errors if required params are missing
if (!telemetryHeader) {
throw new Error('Telemetry header is required')
if (!telemetryHeader || !diskSubHeader || !varHeaders) {
throw new Error('Missing telemetry data components')
}

if (!diskSubHeader) {
throw new Error('Disk sub header is required')
}

if (!sessionInfo) {
throw new Error('Session Info is required')
}

if (!varHeaders) {
throw new Error('varHeaders is required')
}

console.log('Telemetry Header:', telemetryHeader)
console.log('Disk Sub Header:', diskSubHeader)

Expand Down
17 changes: 4 additions & 13 deletions src/utils/telemetry-file-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,9 @@ const telemetryHeaderFromFileDescriptor = fd =>
.then(TelemetryHeader.fromBuffer)

// Disk sub header telemetry
const diskSubHeaderFromFileDescriptor = fd => {
// Ensure the start position and length are correct
const startPosition = HEADER_SIZE_IN_BYTES
const length = DISK_SUB_HEADER_SIZE_IN_BYTES

return readFileToBuffer(fd, HEADER_SIZE_IN_BYTES, DISK_SUB_HEADER_SIZE_IN_BYTES)
.then(buffer => {
console.log('Disk Sub Header buffer length:', buffer.length)
console.log('Disk Sub Header buffer content:', buffer.toString('hex'))
return DiskSubHeader.fromBuffer(buffer)
})
}
const diskSubHeaderFromFileDescriptor = fd =>
readFileToBuffer(fd, DISK_SUB_HEADER_SIZE_IN_BYTES, HEADER_SIZE_IN_BYTES)
.then(DiskSubHeader.fromBuffer)

const sessionInfoStringFromFileDescriptor = (fd, telemetryHeader) => {
if (!isNumber(telemetryHeader.sessionInfoOffset, 'sessionInfoOffset') ||
Expand Down Expand Up @@ -75,7 +66,7 @@ const varHeadersFromFileDescriptor = (fd, telemetryHeader) => {
return Promise.reject(new Error('Invalid buffer size'))
}

return readFileToBuffer(fd, startPosition, length)
return readFileToBuffer(fd, startPosition, fullBufferSize)
.then(buffer => {
return R.range(0, numberOfVariables).map(count => {
const start = count * VAR_HEADER_SIZE_IN_BYTES
Expand Down

0 comments on commit 7d6921b

Please sign in to comment.