Click here to Skip to main content
15,921,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello @Devs, I'm trying to make a TCP communication with a GPS device that sends binary info through GPRS.
I was working so far with several devices using UDP with ACK request to prevent loss of info.
Well now I have to do a TCP comunication with gps, I probe multiple TCP listeners (thinking it was an easy task) somethings come to the listener but then when i trying to parse to string or something i get empty strings (I think q parsing'm wrong or something like that).
Well i Request Dev support to the company and they send a chunks of code c++ and some info, which i dont kwow how to put together and build some small TCP C# listener and receive/respond ACK, interpretate info, etc.

This is the info from support GPS that they send me.



Hi

Please refer to the attached basic source code for Server U Series.
In addition, kindly refer to P1 protocol Message Format from page 5 to 8 to develop your platform. Please note P1 only supports Binary format, please ignore the definition of ASCII format.
For example, after you issued the GPRS communication commands such as AT$HOSTS, AT$APN, AT$MODID, AT$IPTYPE, etc., P1 will send the first Heart Beat data to server for the communication request.

For instance,
00 04 00 02 00 00 00 00 3C 08 B6 A1 00 AB 00 06 01 39 0C 0D 06 12
Transaction ID = 0x00 04
Message Encoding = 0x00
Message Type = 0x02
Modem ID = 0x00 00 00 00 3C 08 B6 A1
Message ID = 0x00 AB
Data Length = 0x00 06
RTC Hour = 0x01
RTC Minute = 0x39
RTC Seconds = 0x0C
RTC Year = 0x0D
RTC Month = 0x06
RTC Day = 0x12

When server receives the connection request from the P1 device, server has to reply an ACK to establish the GPRS connection.

For instance to reply the HB data above,
00 04 00 03 00 00
Transaction ID = 0x00 04
Message Encoding = 0x00
Message Type = 0x03
Status Code = 0x0000

As for the tracking report, for example when you issue AT$GPSS=60,2,60 and AT$GPSMSG=1,3,0, the server should be able to receive Report ID 3 GPS updated message every 60 seconds from P1.

For instance, where the bytes in red is message ID, it is very important to recognize what kind of report/alerts you are receiving from the device.
00 06 00 02 00 00 00 00 3C 08 B6 A1 00 03 00 2E 01 38 35 0D 06 12 00 26 3D EE 00 B9 9E 01 00 00 34 00 01 03 07 00 00 00 00 4C 05 00 00 00 10 67 00 00 01 38 35 0D 06 12 01 39 27 0D 06 12

Server should response every message with the same transaction ID coming from the device.

00 06 00 03 00 00

Furthermore, if you would like to send command from server to device, the procedure will be like the follows.
For example, to query MODID by issuing AT$MODID? from server to device.

Server sends AT$MODID? in binary format,
00 02 01 00 00 09 41 54 24 4D 4F 44 49 44 3F
0x00 02 – Transation ID
0x01 – Message Encoding
0x00 – Message Type
0x 00 09 – Data Length
0x41 54 24 4D 4F 44 49 44 3F – transfer theses bytes to Text is AT$MODID? You can easily TEXT to HEX converter on the internet.

When device receives the command request form the server, P1 should respond for example $MODID=100100100,

OK:MODID
$MODID=100100100
00 02 01 01 00 1c 4f 4b 3a 4d 4f 44 49 44 0d 0a
24 4d 4f 44 49 44 3d 31 30 30 31 30 30 31 30 30 0d 0a
0x00 02 – Transaction ID
0x01 – Message Encoding
0x01 – Message Type
0x00 1c – Data Length
0x4f 4b 3a 4d 4f 44 49 44 0d 0a – OK:MODID
0x24 4d 4f 44 49 44 3d 31 30 30 31 30 30 31 30 30 0d 0a –$MODID=100100100

Hope this is clear for you.



Any idea how it interpretate this with c#?
Hope someone knows something about this.

Regards!
Posted
Updated 13-Dec-16 19:38pm
v3
Comments
Richard MacCutchan 28-Jan-14 11:50am    
What exactly is the problem? Those notes are explaining how to interpret it.
agent_kruger 28-Jan-14 12:10pm    
actually with the big size of you're question nobody will answer. Please cut it into short then present it to us. So, that we can understand and help you ,sir

1 solution

Sounds like you are having an issue with correct string encoding. You are receiving binary data which can be a problem.

It looks as though you may be getting data but not being interpreted correctly. you may try using the following line of code using the iso-8859-1 Western European (ISO) encoding. I use this encoding with good success. I've also used (1252) as well for binary data.
C#
string strData = Encoding.GetEncoding(28591).GetString(buffer, 0, buffer.Length);


Without seeing your code it is difficult to know where the issue lies, it may well be that if you are treating the values as string they may well be being converted to their ascii equivalents, In that case, using the same encoding I would pass these values into an int or Byte array for proper interpretation.

Good luck.
 
Share this answer
 
Comments
turcodel8 29-Jan-14 9:04am    
Hi, thanks for the reply, can you show me or attach a little app in c# for achieve this?

Regards!
S Houghtelin 29-Jan-14 9:06am    
Hi, you made it sound as though you had some code written, what did you have?
S Houghtelin 29-Jan-14 9:24am    
Here is a site that has a very basic code for sending and receiving using sockets.
http://www.csharp-examples.net/socket-send-receive/

I told you what you needed to do to receive the values as binary data. Put the data into an array and parse the data by reading the value at the index location in the received data array as described in your original post. If you want me to write the code for you I will do so but for a fee, I don’t think you can afford my rates.
Good Luck,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900