Changes

17,587 bytes added ,  13:40, 10 June 2020
Created page with "==RUT955 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..."
==RUT955 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 RUT955 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;" | IO Element
|-
| style="text-align: center; background: white;" | 1
| style="text-align: center; background: white;" | Digital Input Status 1
| style="text-align: center; background: white;" | 1
| style="text-align: center; background: white;" | Logic: 0/1
|-
| style="text-align: center; background: white;" | 2
| style="text-align: center; background: white;" | Digital Input Status 2
| style="text-align: center; background: white;" | 1
| style="text-align: center; background: white;" | Logic: 0/1
|-
| style="text-align: center; background: white;" | 9
| style="text-align: center; background: white;" | Analog Input 1
| style="text-align: center; background: white;" | 2
| style="text-align: center; background: white;" | Voltage: mV, 0 - 30 V
|-
| 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
|-
|}

===Example===
----
Received data:
08040000015C1A473FC0000E3BD4A520B53DC300570167070000000403020101001504010
9158500000000015C1A475348000E3BD4AE20B53DC0005701670800000004030201010015
040109158500000000015C1A4766D0000E3BD4AE20B53DBF0057016708000000040302010
10015040109158500000000015C1A477A58000E3BD4B120B53DBD00570167080000000403
02010100150401091585000004

'''08''' – Codec ID
'''04''' - Number of Data (4 records)
'''1st record data'''
'''0000015C1A473FC0''' – Timestamp in milliseconds (1495089496000 → 1495089496,000 in Unix Timestamp = 18 May 2017 06:38:16 UTC)
'''00''' – Priority

'''GPS Element'''
'''0E3BD4A5''' – Longitude 23.8802085 = 23.8802085 º N
'''20B53DC3''' – Latitude 54.8748739 = 54.8748739 º E
'''0057''' – Altitude 87 meters
'''0167''' – Angle 359º
'''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)
'''04''' – 4 IO elements in record
'''03''' – 3 IO elements, which length is 1 Byte
'''02''' – IO element ID = 02
'''01''' – 2’nd IO element’s value = 1
'''01''' – IO element ID = 01
'''00''' – 1’st IO element’s value = 0
'''15''' – IO element ID = 21
'''04''' – 21’nd IO element’s value = 4
'''01''' – 1 IO element, which value length is 2 Bytes
'''09''' – 1 IO element ID = 09
'''1585''' – 9’th IO element’s value = 5509
'''00''' – 0 IO elements, which value length is 4 Bytes
'''00''' – 0 IO elements, which value length is 8 Bytes

'''2’nd record data'''
0000015C1A475348000E3BD4AE20B53DC000570167080000000403020101001504010915850000

'''3’d record data'''
0000015C1A4766D0000E3BD4AE20B53DBF00570167080000000403020101001504010915850000

'''4’th record data
0000015C1A477A58000E3BD4B120B53DBD00570167080000000403020101001504010915850000

'''04''' – Number of Data (4 records)

==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 01 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]]