Codec

From Teltonika Telematics Wiki

Introduction

A codec is a device or computer program for encoding or decoding a digital data stream or signal. Codec is a portmanteau of coder-decoder. A codec encodes a data stream or a signal for transmission and storage, possibly in encrypted form, and the decoder function reverses the encoding for playback or editing.


Codec ID table

Codec 8 Codec 8 extended Codec 12 Codec 13 Codec 16
0x08 0x8E 0x0C 0x0D 0x10

Codec 8

  • AVL data packet

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.

Below table represents AVL data packet structure.


4 zeros Data field length Codec ID Number of Data 1 AVL Data Number of Data 2 CRC-16
4 bytes 4 bytes 1 byte 1 byte 30-147 bytes 1 byte 4 bytes

Number of data – number of encoded data (number of records). Codec ID is constant 08.

Data field length is the length of bytes [codec id, number of data 2]. Number of data 1 should always be equal to number of data 2 byte. CRC-16 is 4 bytes, but first two are zeroes and last two are CRC-16 calculated for [codec id, number of data 2] Minimum AVL packet size is 45 bytes (all IO elements disabled). Maximum AVL packet size for one record is 783 bytes.


  • AVL data
Timestamp Priority GPS Element IO element
8 bytes 1 byte 15 bytes 6-123


Timestamp – difference, in milliseconds, between the current time and midnight, January 1, 1970 UTC

  • Priority


0 Low
1 High
2 Panic


  • GPS Element


Longtitude Latitude Alitude Angle Stellites Speed
4 bytes 4 bytes 2 bytes 2 bytes 1 bytes 2 bytes

X Longitude

Y Latitude1

Altitude In meters above sea level1

Angle In degrees, 0 is north, increasing clock-wise 1

Satellites Number of visible satellites1

Speed Speed in km/h. 0x0000 if GPS data is invalid1

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

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.


  • IO Element
Event IO ID 1 byte
N of Total IO 1 byte
N1 of One Byte IO 1 byte
1’st IO ID 1 byte
1’st IO Value 1 byte
...
N1’th IO ID 1 byte
N1’th IO Value 1 byte
N2 of Two Bytes 1 byte
1’st IO ID 1 byte
1’st IO Value 2 bytes
...
N2’th IO ID 1 byte
N2’th IO Value 2 bytes
N4 of Four Bytes 1 byte
1’st IO ID 1 byte
1’st IO Value 4 byte
...
N4’th IO ID 1 byte
N4’th IO Value 4 bytes
N8 of Eight Bytes 1 byte
1’st IO ID 1 byte
1’st IO Value 8 bytes
...
N8’th IO ID 1 byte
N8’th IO Value 8 bytes

Event IO ID – if data is acquired on event – this field defines which IO property has changed and generated an event. If data cause is not event – the value is 0.

N total number of properties coming with record (N=N1+N2+N4+N8)

N1 number of properties, which length is 1 byte

N2 number of properties, which length is 2 bytes

N4 number of properties, which length is 4 bytes

N8 number of properties, which length is 8 bytes


Example

Received data:

Treciad.png

00000000 4 zeroes, 4 bytes

0000008c data length, 4 bytes

08 – Codec ID

0- Number of Data (1 record)

1’st record data

0000013feb55ff74 – Timestamp in milliseconds (1374042849140)

GMT: Wed, 17 Jul 2013 06:34:09 GMT

00 – Priority

GPS Element

0f0ea850 – Longitude 252618832 = 25,2618832º N

209a6900 – Latitude 546990336 = 54,6990336 º E

0094 – Altitude 148 meters

0 – Angle 214º

0 – 12 Visible sattelites

0 – 0 km/h speed

IO Element

00 – IO element ID of Event generated (in this case when 00 – data generated not on event)

1e – 30 IO elements in record (total)

09 – 9 IO elements, which length is 1 Byte

0 – IO element ID = 01

0 – IO element’s value = 0

02 – IO element ID = 02

0 – IO element’s value = 0

03 – IO element ID = 03

0 – IO element’s value = 0

4 – IO element ID = 04

0 – IO element’s value = 0

16 – IO element ID = 22 (dec)

0 – IO element’s value = 1

47 – IO element ID = 71 (dec)

03 – IO element’s value = 3

F0 – IO element ID = 240 (dec)

0 – IO element’s value = 0

15 – IO element ID = 21 (dec)

04 – IO element’s value = 0

C8 – IO element ID = 200 (dec)

0 – IO element’s value = 0

0C – 12 IO elements, which value length is 2 Bytes

09 – IO element ID = 9 (dec)

0073 – IO element’s value

0a – IO element ID = 10 (dec)

0046 – IO element’s value

0b – IO element ID = 11 (dec)

0050 – IO element’s value

13 – IO element ID = 19 (dec)

0046 – IO element’s value

43 – IO element ID = 67 (dec)

06d7 – IO element’s value

1 – IO element ID = 68 (dec)

0 – IO element’s value

B5 – IO element ID = 181 (dec)

000b – IO element’s value

B6 – IO element ID = 182 (dec)

0007 – IO element’s value

42 – IO element ID = 66 (dec)

2e9f – IO element’s value

2 – IO element ID = 24 (dec)

0 – IO element’s value

cd – IO element ID = 205 (dec)

3 – IO element’s value

CE – IO element ID = 206 (dec)

0 – IO element’s value

07 – 7 IO elements, which value length is 4 Bytes

C7 – IO element ID = 199 (dec)

0 – IO element’s value

f1 – IO element ID = 241 (dec)

0000601a – IO element’s value

46 – IO element ID = 70 (dec)

00000134 – IO element’s value

48 – IO element ID = 72 (dec)

00000bb8 – IO element’s value

4 – IO element ID = 73 (dec)

00000bb8 – IO element’s value

4a – IO element ID = 74 (dec)

00000bb8 – IO element’s value

4c – IO element ID = 76 (dec)

1 – IO element’s value

02 – 2 IO elements, which value length is 8 Bytes

4e – IO element ID = 78 (dec)

0 – IO element’s value

cf – IO element ID = 207 (dec)

0 – IO element’s value

0 – Number of Data (1 record)

00003fca - CRC-16, 4 Bytes (first 2 are always zeros)