0

I am in the process of building a telemetry parser. The way the telemetry data is set up is it includes a ascii trigger byte, 1-8 ascii data bytes and ">" as the terminator byte. One of the trigger bytes is a backslash "\" (why they chose to include the back slash character as one of the triggers is beyond me).

Telemetry data format specification

I Have built some code to separate the data but as soon as I process the data the backslash has been striped

Here is an example of the raw telemetry data and my attempt to parse it:

function telemetryParser(data) {
  TelemetryData = data.split(">");
  console.log(TelemetryData);
  for (var i = 0; i < TelemetryData.length; i++) {
    triggerParser(TelemetryData[i])
  }
  // return altitude;
}

function triggerParser(data) {
  const triggers = ["#", "{", "<", "(", "\\", "@", "~", "!", "=", "?", "%", "^", "["]
  const element = ["flightTime", "Altitude100", "altitude", "velocity", "acceleration", "flightPhase", "channelStatus", "temperature", "callSign", "voltage", "apogee", "maxVolocity", "maxAcceleration"]
  for (var j = 0; j < triggers.length; j++) {
    if (data.split(triggers[j])[1]) {
      console.log(element[j] + ":" + data.split(triggers[j])[1])
    }
  }
}

telemetryParser(tData)
<script>
  const tData = `    {040>@2>#0010>~AB---->( 0213>\-001>?079>! 212>=KM6ZFL>01>?079>! 212>=KM6ZFL>
    {045>@2>#0014>~AB---->( 0072>\-001>?079>! 212>=KM6ZFL>
    {046>@4>#0016>~AB---->( 0033>\-001>?079>! 212>=KM6ZFL>
    {043>@5>#0022>~1B---->(-0029>\ 004>%04679>^0660>[025>?079>! 209>=KM6ZFL>`
</script>

Result:

telemetryParser("{040>@2>#0010>~AB---->( 0213>\-001>?079>! 212>=KM6ZFL>01>?079>! 212>=KM6ZFL>")

parser.js:3 (14) ['{040', '@2', '#0010', '~AB----', '( 0213', '-001', '?079', '! 212', '=KM6ZFL', '01', '?079', '! 212', '=KM6ZFL', '']0: "{040"1: "@2"2: "#0010"3: "~AB----"4: "( 0213"5: "-001"6: "?079"7: "! 212"8: "=KM6ZFL"9: "01"10: "?079"11: "! 212"12: "=KM6ZFL"13: ""length: 14[[Prototype]]: Array(0)
parser.js:26 Altitude100:040
parser.js:26 flightPhase:2
parser.js:26 flightTime:0010
parser.js:26 channelStatus:AB----
parser.js:26 velocity: 0213
(expecting acceleration: -001 here)
parser.js:26 voltage:079
parser.js:26 temperature: 212
parser.js:26 callSign:KM6ZFL
parser.js:26 voltage:079
parser.js:26 temperature: 212
parser.js:26 callSign:KM6ZFL
undefined

How would I keep or change the backslash so I don't lose track of the data as the back slash is the only way I have to identify the data, also I can not do a \\ as I have no control over the data that is coming in?

  • I made you a snippet. It does not show the same as you post as a result – mplungjan Feb 01 '22 at 08:07
  • 1
    The problem is that your input string does not have any backslash. The backslash in the literal serves as an escape character. So double it. – trincot Feb 01 '22 at 08:10
  • @trincot I cant double it as that is the way its given to me from a serial device – Austinthemighty Feb 01 '22 at 17:16
  • Please realise that if you get a string really containing backslashes, then you did not represent that in your code here. The code you present here creates a string without backslashes. – trincot Feb 01 '22 at 17:28
  • @trincot if you look at the result code snip it there is a \ in the function call – Austinthemighty Feb 01 '22 at 21:16
  • @trincot i get that, and that is the whole problem that i am dealing with, that \ or "escape character", this is the string that is given to me from the device ```{040>@2>#0010>~AB---->( 0213>\-001>?079>! 212>=KM6ZFL>01>?079>! 212>=KM6ZFL>``` – Austinthemighty Feb 01 '22 at 21:22
  • OK, but then you don't do the same in the above script as what you get from the device. One apparently has backslashes and the other not. It's not the same thing. So present us the real string. Strings can have backslash characters just as any other character, that is not the problem. The problem is that you misrepresent what you get from the device. – trincot Feb 01 '22 at 21:29
  • Here is a hint: replace `const tData = ` with `const tData = String.raw`, immediately followed by the template string. Then the backslash does not have to be doubled to be interpreted literally. Like I have tried to explain you in all of my above comments: your string literal does not encode a backslash. Either you need to double them, or you have to use another method to build the string. – trincot Feb 01 '22 at 21:33
  • @trincot i never mispresented the string @mplungjan edited my original question removing context, but this is the real string from the serial device ```{040>@2>#0010>~AB---->( 0213>\-001>?079>! 212>=KM6ZFL>01>?079>! 212>=KM6ZFL>``` – Austinthemighty Feb 01 '22 at 21:35
  • Oh well, if you know better... Moving on. – trincot Feb 01 '22 at 21:35
  • @trincot also if you look at the bottom of page 5 of this it has more example strings http://eggtimerrocketry.com/wp-content/uploads/2021/05/Eggtimer-Telemetry-Data-Format.pdf – Austinthemighty Feb 01 '22 at 21:36
  • Sorry, I stop with this discussion. You seem not to be hearing what I say. Anyway your question is closed, because it is duplicate. – trincot Feb 01 '22 at 21:37

0 Answers0