-2

I have received ASCII characters to GPS device but I can understand how to read data to the ASCII characters.

I have received data like this

+RESP:GTFRI,EF8019,866425032153324,ZK105,,,,,0,0000000000000000,1,0.0,21,29.5,120.101247,30.344809,20190710013252,,0460,0000,580C,8500,31&0,1,42,0,36638,0,0,0,0,1,,0.0&0.0&0.0&0.0&0&0&0&030015&D50052&0&0&00000000000000000000,49,20190710013252,6D1F$
Akshay I
  • 3,675
  • 1
  • 34
  • 57

5 Answers5

2

This is not a javascript problem. You have the string:

+RESP:GTFRI,EF8019,866425032153324,ZK105,,,,,0,0000000000000000,1,0.0,21,29.5,120.101247,30.344809,20190710013252,,0460,0000,580C,8500,31&0,1,42,0,36638,0,0,0,0,1,,0.0&0.0&0.0&0.0&0&0&0&030015&D50052&0&0&00000000000000000000,49,20190710013252,6D1F$

.. and literally that is the human readable value. That is to say, the string that humans can read literally starts with +RESP .. and ends with $.

Your problem is you don't understand what this string means, not figuring out how to display it on screen.

My personal debugging process when faced with something like this is to use http://www.google.com. Googling the string +RESP:GTFRI gives me a PDF document as the first result. It is the documentation of the Track Air Interface Protocol which is a protocol used by a GPS device called Enduro Pro.

This link may not last forever but for now the document can be found at: http://www.trackingtheworld.com/wt_products/wtenduropro/Documents/Enduro_Pro_Tracker_Air_Interface_Protocol_1.04.pdf.

The documentation of the +RESP:GTFRI packet can be found on page 39.

It looks like it uses AT commands (a format for serial protocols) where commands sent to the device starts with AT+<command> and responses starts with +RESP:<command>. So the packet encodes the reply to the GTFRI command (datatype) which is the command to configure scheduled report (page 19).

Whenever you encounter a new kind of AT command it is worth googling the first few characters (the command words). I have never worked with this device and don't know anything about it but I got all the above from googling +RESP:GTFRI.

Ideally, since you presumably actually have access to the device you should also have copies of the documentation. But I've been in the industry long enough to know that that's not always the case.

slebetman
  • 109,858
  • 19
  • 140
  • 171
  • Note that this protocol is not a standard GPS protocol but that is normal. The standard for GPS is NMEA but almost all non-military manufacturer also implement their own protocol such as Garmin, Trimble etc – slebetman Jul 10 '19 at 07:04
1

Your question is contradictory:

How to convert ASCII characters to readable value

ASCII characters were invented to be readable values, representing numbers (ASCII codes), representing bytes....

Maybe you meant ASCII codes. In this case, in javascript, you can convert an ASCII code to its relative char with this:

String.fromCharCode(code)

But to be honest, I don't think your problem has nothing to do with ASCII. What you need is information about the response format of the GPS, and this is something that should inevitably be documented somewhere.

François Huppé
  • 2,006
  • 1
  • 6
  • 15
0

You can use the fromCharCode() method to perform your desired task. Just wrap up all your ascii values into an array and pass it in a function

const arr = [] //all your ascii codes go here
const values = [""] //all your converted data will come here
arr.forEach(function(val){
  values.push(string.fromCharCode(val));
 });
-1

Check fromCharCode() function Example :

    function myFunction() {
            var res = String.fromCharCode(72, 69, 76, 76, 79);
           document.getElementById("demo").innerHTML = res;
    }

The Result : HELLO

Shanmugapriya D
  • 306
  • 3
  • 13
  • it's not working in my case. my ascii node is like this - +RESP:GTFRI,EF8019,866425032153324,ZK105,,,,,0,0000000000000000,1,0.0,21,29.5,120.101247,30.344809,20190710013252,,0460,0000,580C,8500,31&0,1,42,0,36638,0,0,0,0,1,,0.0&0.0&0.0&0.0&0&0&0&030015&D50052&0&0&00000000000000000000,49,20190710013252,6D1F$ – Akshay I Jul 10 '19 at 06:12
-2

I would suggest you to split the text by comma "," to get an array of string, and then access each part of the GPS text. I'm no GPS expert, however I'm guessing that each part separated by comma represents something.

Example:

// store the values coming from gps to some variable
var gpsText = "+RESP:GTFRI,EF8019,866425032153324,ZK105,,,,,0,0000000000000000,1,0.0,21,29.5,120.101247,30.344809,20190710013252,,0460,0000,580C,8500,31&0,1,42,0,36638,0,0,0,0,1,,0.0&0.0&0.0&0.0&0&0&0&030015&D50052&0&0&00000000000000000000,49,20190710013252,6D1F$";
// Now split it:
var gpsParts = gpsText.split(',');

This should give you an array with following items:

0: "+RESP:GTFRI"
1: "EF8019"
2: "866425032153324"
3: "ZK105"
4: ""
5: ""
6: ""
7: ""
8: "0"
9: "0000000000000000"
10: "1"
11: "0.0"
12: "21"
13: "29.5"
14: "120.101247"
15: "30.344809"
16: "20190710013252"
17: ""
18: "0460"
19: "0000"
20: "580C"
21: "8500"
22: "31&0"
23: "1"
24: "42"
25: "0"
26: "36638"
27: "0"
28: "0"
29: "0"
30: "0"
31: "1"
32: ""
33: "0.0&0.0&0.0&0.0&0&0&0&030015&D50052&0&0&00000000000000000000"
34: "49"
35: "20190710013252"
36: "6D1F$"

Now, you'll need to know what each of these 37 parts means, and probably further split the 33'rd item by the ampersand (&), e.g.:

var a = gpsParts[33].split('&');

Next, you'll need to know what each item in the above array a means.

Hope this helps.

Nripendra
  • 359
  • 6
  • 12