Skip to content

Commit

Permalink
Integrate LTE tracker, send correct status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoBiernat committed Sep 13, 2023
1 parent 88792c6 commit 7cd8469
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions Server/src/routes/tracker.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export class TrackerRoute {

const [lastLog]: [lastLog?: Log, ...rest: never[]] = await database.logs.getAll(undefined, tracker.uid, 1)


const apiTracker: APITracker = {
id: tracker.uid,
vehicleId: tracker.vehicleId,
Expand Down Expand Up @@ -242,38 +241,50 @@ export class TrackerRoute {
let speed = 0
let field0Present = false

let field6Present = false
let battery = 0
let battery = undefined
// let temperature = 0
for (const record of trackerData.Records) {
for (const field of record.Fields) {
switch (field.FType) {
case 0: // gps, heading and speed
let gpsField: LteRecordField0 = field // we know that it is a gps field
case 0: {
// gps, heading and speed
const gpsField: LteRecordField0 = field // we know that it is a gps field
field0Present = true
longitude = gpsField.Long
latitude = gpsField.Lat
heading = gpsField.Head
speed = gpsField.Spd
break
case 6: // analogue data (battery, temperature)
let analogueField: LteRecordField6 = field
field6Present = true
}
case 6: {
// analogue data (battery, temperature)
const analogueField: LteRecordField6 = field
battery = analogueField.AnalogueData["1"] / 1000 // TODO: find out if 1 is actually the battery
// temperature = analogueField.AnalogueData["3"] / 100
break
}
}
}
}
if (!field0Present) {
res.sendStatus(400)
return
}
const ok = await TrackerService.appendLog(
associatedVehicle,
new Date(), // TODO: use payload timestamp
[longitude, latitude],
heading,
speed,
trackerId,
undefined, // TODO: verify if AnalogueData["1"] is actually battery voltage before inserting
battery, // TODO: verify if AnalogueData["1"] is actually battery voltage before inserting
req.body
)
if (ok == null) {
res.sendStatus(500)
return
}
res.sendStatus(200)
return
}
}

0 comments on commit 7cd8469

Please sign in to comment.