Changes

17,053 bytes added ,  13:41, 10 June 2020
Created page with "==RUT850 GPS DATA PROTOCOL== ===AVL data array=== ---- Because the smallest information amount that can be written is one bit, there can be some bits left unused when result i..."
==RUT850 GPS DATA PROTOCOL==
===AVL data array===
----
Because the smallest information amount that can be written is one bit, there can be some bits left unused when result is byte array. Any unused bits should be left blank.

{| class="wikitable"
|+
| style="text-align: center; width: 100px; background: white;" | Codec ID
| style="text-align: center; width: 200px; background: white;" | Number of Data
| style="text-align: center; width: 80px; background: #E6E6FF;" | Data
| style="text-align: center; width: 200px; background: white;" | Number of Data
|-
| style="text-align: center; background: white;" | ''1 Byte''
| style="text-align: center; background: white;" | ''1 Byte''
| style="text-align: center; background: #E6E6FF;" | ''...''
| style="text-align: center; background: white;" | ''1 byte''
|-
|}

Number of data – number of encoded data (number of records). In RUT850 codec ID is 08

===Data===
----
{| class="wikitable"
|+
| style="text-align: center; width: 130px; background: white;" | AVL Data
| style="text-align: center; width: 60px; background: white;" | ...
| style="text-align: center; width: 130px; background: white;" | AVL Data
|-
|}
AVL data – encoded data element.

===AVL Data===
----
{| class="wikitable"
|+
| style="text-align: center; width: 140px; background: white;" | Timestamp
| style="text-align: center; width: 100px; background: white;" | Priority
| style="text-align: center; width: 140px; background: white;" | GPS Element
| style="text-align: center; width: 130px; background: white;" | IO Element
|-
| style="text-align: center; background: white;" | ''8 Bytes''
| style="text-align: center; background: white;" | ''1 Byte''
| style="text-align: center; background: white;" | ''15 Bytes''
| style="text-align: center; background: white;" | ''...''
|-
|}
Timestamp – difference, in milliseconds, between the current time and midnight, January 1, 1970 UTC.

===Priority===
----
{| class="wikitable"
|+
| style="text-align: center; width: 80px; background: white;" | 0
| style="text-align: center; width: 120px; background: white;" | low
|-
| style="text-align: center; background: white;" | 1
| style="text-align: center; background: white;" | High
|-
| style="text-align: center; background: white;" | 2
| style="text-align: center; background: white;" | Panic
|-
| style="text-align: center; background: white;" | 3
| style="text-align: center; background: white;" | Security
|-
|}

===GPS Element===
----
{| class="wikitable"
|+
| style="text-align: center; width: 90px; background: white;" | Longitude
| style="text-align: center; width: 90px; background: white;" | Latitude
| style="text-align: center; width: 80px; background: white;" | Altitude
| style="text-align: center; width: 80px; background: white;" | Angle
| style="text-align: center; width: 90px; background: white;" | Satellites
| style="text-align: center; width: 80px; background: white;" | Speed
|-
| style="text-align: center; background: white;" | ''4 Bytes''
| style="text-align: center; background: white;" | ''4 Bytes''
| style="text-align: center; background: white;" | ''2 Bytes''
| style="text-align: center; background: white;" | ''2 Bytes''
| style="text-align: center; background: white;" | ''1 Byte''
| style="text-align: center; background: white;" | ''2 Bytes''
|-
|}

X Longitude
Y Latitude
Altitude In meters above sea level
Angle In degrees, 0 is north, increasing clock-wise
Satellites Number of visible satellites
Speed In km/h. 0x0000 if GPS data is invalid

Longitude and latitude are integer values built from degrees, minutes, seconds and milliseconds by formula:

[[File:Gps_element_formula.png]]

d Degrees
m Minutes
s Seconds
ms Milliseconds
p Precision (10000000)

If longitude is in west or latitude in south, multiply result by –1. To determine if the coordinate is negative, convert it to binary format and check the very first bit. If it is 0, coordinate is positive, if it is 1, coordinate is negative. Example:

Received value: 20 9c ca 80

Converted to BIN: 00100000 10011100 11001010 10000000 first bit is 0, which means coordinate is positive

Convered to DEC: 547146368

For more information see two‘s compliment arithmetics.

===I/O Element===
----
{| class="wikitable"
|+
| colspan=4; style="text-align: center; width: 620px; background: #C9D8E6;" | I/O elements (sent to server only if enabled)
|-
| style="text-align: center; width: 90px; background: white;" | Property ID
| style="text-align: center; width: 180px; background: white;" | Property Name
| style="text-align: center; width: 80px; background: white;" | Bytes
| style="text-align: center; width: 270px; background: white;" | Description
|-
| style="text-align: center; background: white;" | 21
| style="text-align: center; background: white;" | GSM level
| style="text-align: center; background: white;" | 1
| style="text-align: center; background: white;" | GSM signal level value in scale 1-5
|-
| style="text-align: center; background: white;" | 239
| style="text-align: center; background: white;" | Voltage state
| style="text-align: center; background: white;" | 1
| style="text-align: center; background: white;" | Sleep mode voltage state 1 – voltage is above the limit; 0 - voltage is lower
|-
| style="text-align: center; background: white;" | 240
| style="text-align: center; background: white;" | Ignition state
| style="text-align: center; background: white;" | 1
| style="text-align: center; background: white;" | Sleep mode ignition state 1 – ignition is on; 0 – ignition is off
|-
|}

===Example===
----
Received data:
0000004308020000015FA570D4A0000E48B4FF20B8D8BF005200BD070000000303F001EF0
115030000000000015FA570DC70000E48B4FE20B8D8C0005200BD070000000303F001EF01
15030000000000002000065D5
'''00000043''' - AVL data length
'''08''' – Codec ID
'''02''' - Number of Data (4 records)
'''1st record data'''
'''0000015FA570D4A''' – Timestamp in milliseconds (1476020749000 → 1476020749,000 in Unix Timestamp = Sunday, October 9, 2016 1:45:49 PM)
'''00''' – Priority

'''GPS Element'''
'''0E48B4FF''' – Longitude 23.9645951 = 23.9645951 º N
'''20B53DC3''' – Latitude 54.8985023 = 54.8985023 º E
'''0052''' – Altitude 82 meters
'''00BD''' – Angle 189º
'''07''' – 7 Visible satellites
'''0000''' – 0 km/h speed

'''I/O Element'''
'''00''' – IO element ID of Event generated (in this case when 00 – data generated not on event)
'''03''' – 3 IO elements in record
'''03''' – 3 IO elements, which length is 1 Byte
'''F0''' – IO element ID = 240
'''01''' – 240th IO element’s value = 1
'''EF''' – IO element ID = 240
'''01''' – 239th IO element’s value = 1
'''15''' – IO element ID = 21
'''03''' – 21st IO element’s value = 3
'''00''' – 0 IO elements, which value length is 2 Bytes
'''00''' – 0 IO elements, which value length is 4 Bytes
'''00''' – 0 IO elements, which value length is 8 Bytes

'''2’nd record data'''
0000015FA570DC70000E48B4FE20B8D8C0005200BD070000000000000000

'''Footer'''
020000272A
'''02''' – Number of Data (4 records); 0000272A – CRC value of data

==Sending data over TCP/IP==
===AVL data packet===
----
AVL packet is used to encapsulate AVL data and send it to server.

{| class="wikitable"
|+
| style="text-align: center; width: 80px; background: white;" | Four zeros
| style="text-align: center; width: 90px; background: white;" | Data length
| style="text-align: center; width: 60px; background: white;" | Data
| style="text-align: center; width: 60px; background: white;" | CRC
|-
|}

Four zeros Four zero bytes (0x00)
Data length Number of bytes in data field (Integer)
Data Any AVL data array
CRC 16bit CRC value of data (Integer). Polynomial 0xA001.

===Communication with server===
----
First when module connects to server, module sends its IMEI. IMEI is sent the same way as encoding barcode. First comes short identifying number of bytes written and then goes IMEI as text (bytes).

For example IMEI 123456789012345 would be sent as <span style=color:blue>000F313233343536373839303132333435</span>.

After receiving IMEI, server should determine if it would accept data from this module. If yes server will reply to module <span style=color:blue>01</span> if not <span style=color:blue>00</span>. Note that confirmation should be sent as binary packet.

Then module starts to send first AVL data packet. After server receives packet and parses it, server must report to module number of data received as integer (four bytes).

If sent data number and reported by server doesn’t match module resends sent data.

Example:

Module connects to server and sends IMEI:

<span style=color:blue>000F313233343536373839303132333435</span>

Server accepts the module:

<span style=color:blue>01</span>

Module sends data packet:

{| class="wikitable"
|+
| style="text-align: center; width: 200px; background: white;" | '''AVL data packet header'''
| style="text-align: center; width: 200px; background: white;" | '''AVL data array'''
| style="text-align: center; width: 200px; background: white;" | '''CRC'''
|-
| style="text-align: left; background: white;" | Four zero bytes, ‘AVL data array’ length – 254
| style="text-align: left; background: white;" | CodecId – 08, NumberOfData – 2. (Encoded using continuous bit stream. Last byte padded to align to byte boundary)
| style="text-align: left; background: white;" | CRC of ‘AVL data array’
|-
| style="text-align: left; background: white;" | <span style=color:blue>00000000</span><span style=color:green>000000FE</span>
| style="text-align: leftr; background: white;" | <span style=color:blue>08</span><span style=color:green>02</span>...<span style=color:blue>(data elements)</span>...<span style=color:green>02</span>
| style="text-align: center; background: white;" | <span style=color:blue>00008612</span>
|}
Server acknowledges data reception (2 data elements): <span style=color:blue>00000002</span>

==SENDING DATA OVER UDP/IP==
===UDP channel protocol===
----
UDP channel is a transport layer protocol above UDP/IP to add reliability to plain UDP/IP using acknowledgment packets. The packet structure is as follows:

{| class="wikitable"
|+
| colspan=4; style="text-align: center; width: 640px; background: white;" | '''UDP datagram'''
|-
| rowspan=5; style="text-align: left; width: 120px; background: white;" | UDP channel packet x N
|-
| style="text-align: center; width: 150px; background: white;" | Packet length
| style="text-align: center; width: 120px; background: white;" | 2 bytes
| style="text-align: center; width: 250px; background: white;" | Packet length (excluding this field) in big endian byte order
|-
| style="text-align: center; background: white;" | Packet Id
| style="text-align: center; background: white;" | 2 bytes
| style="text-align: center; background: white;" | Packet id unique for this channel
|-
| style="text-align: center; background: white;" | Packet type
| style="text-align: center; background: white;" | 1 byte
| style="text-align: center; background: white;" | Type of this packet
|-
| style="text-align: center; background: white;" | Packet payload
| style="text-align: center; background: white;" | m bytes
| style="text-align: center; background: white;" | Data payload
|-
|}

{| class="wikitable"
|+
| colspan=2; style="text-align: center; width: 350px; background: white;" | '''Packet Type'''
|-
| style="text-align: center; width: 50px; background: white;" | 1
| style="text-align: center; width: 300px; background: white;" | Data packet requiring acknowledgment
|-
|}

Acknowledgment packet should have the same packet id as acknowledged data packet and empty data payload. Acknowledgement should be sent in binary format.

{| class="wikitable"
|+
| colspan=3; style="text-align: center; width: 450px; background: white;" | '''Acknowledgement packet'''
|-
| style="text-align: center; width: 150px; background: white;" | Packet length
| style="text-align: center; width: 120px; background: white;" | 2 bytes
| style="text-align: center; width: 180px; background: white;" | 0x0003
|-
| style="text-align: center; width: 150px; background: white;" | Packet id
| style="text-align: center; width: 120px; background: white;" | 2 bytes
| style="text-align: center; width: 180px; background: white;" | The same as in acknowledged packet
|-
| style="text-align: center; width: 150px; background: white;" | Packet type
| style="text-align: center; width: 120px; background: white;" | 1 byte
| style="text-align: center; width: 180px; background: white;" | 0x01
|-
|}

===Sending AVL data using UDP channel===
----
AVL data is sent encapsulated in UDP channel packets (Data payload field).

{| class="wikitable"
|+
| colspan=3; style="text-align: center; width: 510px; background: white;" | '''AVL data encapsulated in UDP channel packet'''
|-
| style="text-align: center; width: 180px; background: white;" | AVL packet id (1 byte)
| style="text-align: center; width: 150px; background: white;" | Module IMEI
| style="text-align: center; width: 180px; background: white;" | AVL data array
|-
|}

AVL packet id (1 byte) id identifying this AVL packet
Module IMEI IMEI of a sending module encoded the same as with TCP
AVL data array array of encoded AVL data

{| class="wikitable"
|+
| colspan=2; style="text-align: center; width: 500px; background: white;" | '''Server response to AVL data packet'''
|-
| style="text-align: center; width: 200px; background: white;" | AVL packet id (1 byte)
| style="text-align: center; width: 300px; background: white;" | Number of accepted AVL elements (1 byte)
|-
|}

AVL packet id (1 byte) – id of received AVL data packet

Number of AVL data elements accepted (1 byte) – number of AVL data array entries from the beginning of array, which were accepted by the server.

Scenario:

Module sends UDP channel packet with encapsulated AVL data packet (Packet type=1).

Server sends UDP channel packet with encapsulated response (Packet type=1).

Module validates AVL packet id and Number of accepted AVL elements. If server response with valid AVL packet id is not received within configured timeout, module can retry sending.

Example:

Module sends the data:

{| class="wikitable"
|+
| style="text-align: center; width: 150px; background: white;" | '''UDP channel header'''
| style="text-align: center; width: 280px; background: white;" | '''AVL packet header'''
| style="text-align: center; width: 200px; background: white;" | '''AVL data array'''
|-
| style="text-align: left; width: 150px; background: white;" | Len – 253,

Id – 0xCAFE,

Packet type – 01
| style="text-align: left; width: 120px; background: white;" | AVL packet id – 0xDD,

IMEI – 1234567890123456
| style="text-align: left; width: 180px; background: white;" | CodecId – 08,

NumberOfData – 2. (Encoded using continuous bit stream)
|-
| style="text-align: left; width: 150px; background: white;" | <span style=color:blue>00FD</span><span style=color:green>CAFE</span><span style=color:blue>01</span>
| style="text-align: left; width: 120px; background: white;" | <span style=color:blue>DD</span><span style=color:green>000F3133343536373839303132333435</span>
| style="text-align: left; width: 180px; background: white;" | <span style=color:blue>08</span><span style=color:green>02</span>…<span style=color:blue>(data elements)</span>…<span style=color:green>02</span>
|-
|}

Server must respond with acknowledgment:

{| class="wikitable"
|+
| style="text-align: center; width: 300px; background: white;" | '''UDP channel header'''
| style="text-align: center; width: 300px; background: white;" | '''AVL packet acknowledgement'''
|-
| style="text-align: left; width: 150px; background: white;" | Len – 5,

Id – 0xCAFE,

Packet type – 01
| style="text-align: left; width: 120px; background: white;" | AVL packet id – 0xDD,

NumberOfAcceptedData – 2
|-
| style="text-align: left; width: 150px; background: white;" | <span style=color:blue>0005</span><span style=color:green>CAFE</span><span style=color:blue>01</span>
| style="text-align: left; width: 120px; background: white;" | <span style=color:blue>DD</span><span style=color:green>02</span>
|}

[[Category:Other Topics]]

Navigation menu