Skip to content

Commit

Permalink
multiple updates
Browse files Browse the repository at this point in the history
  • Loading branch information
twitchyvr committed Nov 20, 2023
1 parent 7699e35 commit 9cac5f7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
15 changes: 4 additions & 11 deletions src/headers/disk-sub-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@ 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 @@ -25,6 +14,10 @@ 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
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ module.exports = async function (context, req) {
// Process telemetry
const telemetry = new Telemetry(telemetryData)

if (telemetry.error) {
// Handle error case
context.res = {
status: 400,
body: telemetry.error
}
return
}
// console.log('Telemetry headers:', telemetry.headers)
// console.log(telemetry.header)

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

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: 13 additions & 4 deletions src/utils/telemetry-file-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@ const telemetryHeaderFromFileDescriptor = fd =>
.then(TelemetryHeader.fromBuffer)

// Disk sub header telemetry
const diskSubHeaderFromFileDescriptor = fd =>
readFileToBuffer(fd, DISK_SUB_HEADER_SIZE_IN_BYTES, HEADER_SIZE_IN_BYTES)
.then(DiskSubHeader.fromBuffer)
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 sessionInfoStringFromFileDescriptor = (fd, telemetryHeader) => {
if (!isNumber(telemetryHeader.sessionInfoOffset, 'sessionInfoOffset') ||
Expand Down Expand Up @@ -65,7 +74,7 @@ const varHeadersFromFileDescriptor = (fd, telemetryHeader) => {
return Promise.reject(new Error('Invalid buffer size'))
}

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

0 comments on commit 9cac5f7

Please sign in to comment.