Teltonika SDK Typescript
    Preparing search index...

    Class TeltonikaCodec12ResponsePacket

    Class for parsing Teltonika Codec 12 response packets. Extends TeltonikaBasePacket to handle Codec 12 specific response parsing.

    TeltonikaCodec12ResponsePacket

    const packet = new TeltonikaCodec12ResponsePacket(rawBuffer);
    const records = packet.records; // Array of TeltonikaCodec12ResponseRecord

    Hierarchy (View Summary)

    Index

    Accessors

    • get calculatedCrc(): number

      Calculates the CRC-16 of the data payload.

      Returns number

    • get response(): Buffer<ArrayBuffer>

      Creates a response buffer to acknowledge receipt of the packet. Typically contains the number of data records processed.

      Returns Buffer<ArrayBuffer>

    • get state(): {
          codecId: TeltonikaCodec;
          crc: number;
          data: Buffer<ArrayBufferLike>;
          numberOfData1: number;
          numberOfData2: number;
          preamble: Buffer<ArrayBufferLike>;
          raw: Buffer<ArrayBufferLike>;
          size: number;
      }

      Returns the internal state of the packet.

      Returns {
          codecId: TeltonikaCodec;
          crc: number;
          data: Buffer<ArrayBufferLike>;
          numberOfData1: number;
          numberOfData2: number;
          preamble: Buffer<ArrayBufferLike>;
          raw: Buffer<ArrayBufferLike>;
          size: number;
      }

    Constructors

    Methods

    • Calculate the byte length of the IO section.
      This method walks through all IO groups in the order defined by Teltonika Codec8E specification:

      Each group starts with a 2-byte counter followed by that many IO entries. The total IO section length is derived exclusively from these counters and value sizes.

      Parameters

      • data: Buffer

        Buffer containing the IO section, starting at N1 of One Byte IO

      • groups: TeltonikaIoGroup[] = ...

        IO group value sizes (default: [1, 2, 4, 8, 0])

      • layout: TeltonikaIoLayout = {}

        Define the layout to calcul IO length.

      Returns number

      Total number of bytes occupied by the IO section

    • Parse Teltonika packet header fields from the raw buffer.

      Packet structure (Codec8 / Codec8E):

      0–3 : Preamble (always 0x00000000) 4–7 : Data Field Length 8 : Codec ID 9 : Number of Data 1 (records count) 10.. : AVL Data -5 : Number of Data 2 (records count) -4..-1: CRC-16

      Parameters

      • raw: Buffer

        Full Teltonika packet buffer

      Returns void

      Codec8E packet example:

      00 00 00 00   // Preamble
      00 00 00 4A   // Data Field Length (74 bytes)
      8E            // Codec ID (Codec8E)
      01            // Number of Data 1
      ...           // AVL Data
      01            // Number of Data 2
      00 00 29 94   // CRC-16
      
      const buffer = Buffer.from(
      "000000000000004A8E01" +
      "0000016B4F831C6801" + // timestamp + priority
      "000000000000000000000000" +
      "00010005000100010100010011001d" +
      "00010010015e2c88" +
      "0002000b000000003544c87a000e000000001dd7e06a" +
      "0001" +
      "00002994",
      "hex"
      );

      packet.parse(buffer);

      console.log(packet.codecId); // 0x8E
      console.log(packet.numberOfData1); // 1
      console.log(packet.numberOfData2); // 1
      console.log(packet.size); // 74
    • Parse all IO groups (N1, N2, N4, N8, NX) of an AVL record and merge them into a single IO object.

      Parameters

      • data: Buffer

        Buffer containing IO section of the AVL record

      • total: number

        Total number of IO properties (N)

      • groups: TeltonikaIoGroup[] = ...

        IO group value sizes (default: [1, 2, 4, 8, 0])

      • layout: TeltonikaIoLayout = {}

        Define the layout to parse IO.

      Returns Record<number, Buffer>

      Object mapping AVL IO IDs to raw Buffer values

      From https://wiki.teltonika-gps.com/view/Codec#Codec_8_Extended
      Codec8E AVL IO example:
      Event IO ID:
      00 01
      N of Total ID:
      00 05
      N1 (1 byte):
      00 01
      00 01 | 01
      N2 (2 bytes):
      00 01
      00 11 | 00 1D
      N4 (4 bytes):
      00 01
      00 10 | 01 5E 2C 88
      N8 (8 bytes):
      00 02
      00 0B | 00 00 00 00 35 44 C8 7A
      00 0E | 00 00 00 00 1D D7 E0 6A
      NX:
      00 00

      const ioBuffer = Buffer.from(
      "0001000101" +
      "00010011001d" +
      "00010010015e2c88" +
      "0002000b000000003544c87a000e000000001dd7e06a" +
      "0000",
      "hex"
      );

      const io = packet.parseIo(ioBuffer, 5);
      console.log(io);
      // {
      // 1: <Buffer 01>, // DIN1
      // 17: <Buffer 00 1d>, // Axis X
      // 16: <Buffer 01 5e 2c 88>, // Total Odometer
      // 11: <Buffer 00 00 00 00 35 44 c8 7a>, // ICCID1
      // 14: <Buffer 00 00 00 00 1d d7 e0 6a> // ICCID2
      // }
    • Parse a single IO group from an AVL record.

      This method parses one IO group (N1, N2, N4, N8 or NX) according to Teltonika Codec8E specification.

      Parameters

      • data: Buffer

        Buffer containing IO data starting at the group counter

      • offset: number

        Current offset in the buffer

      • n: TeltonikaIoGroup

        Value size in bytes:

        • 1 → N1 (1 byte values)
        • 2 → N2 (2 byte values)
        • 4 → N4 (4 byte values)
        • 8 → N8 (8 byte values)
        • 0 → NX (variable length values)
      • layout: TeltonikaIoLayout = {}

        Define the layout to parse io group.

      Returns { io: Record<number, Buffer<ArrayBufferLike>>; offset: number }

      Parsed IO values and updated offset

      Codec8E N1 (1 byte IO) example:

      N1 of One Byte IO 00 01 IO ID 00 01 (DIN1) IO Value 01

      const buffer = Buffer.from(
      "0001000101", // count=1, id=1, value=01
      "hex"
      );

      const { io, offset } = packet.parseIoGroup(buffer, 0, 1);

      console.log(io);
      // { 1: <Buffer 01> }
      console.log(offset);
      // 5

    Properties

    Codec identifier of this packet

    crc: number

    CRC-16 checksum from the packet

    data: Buffer

    Raw data buffer containing the payload

    numberOfData1: number

    Number of data records (part 1)

    numberOfData2: number

    Number of data records (part 2)

    preamble: Buffer

    Preamble of the packet (first 4 bytes)

    raw: Buffer

    Full raw buffer of the packet, including header and CRC

    Parsed records from the packet

    size: number

    Size of the data part of the packet