Skip to content

File syn_dlt645.c

FileList > proto > syn_dlt645.c

Go to the source code of this file

DL/T 645 Electricity Meter Communication Protocol Implementation.

  • #include "syn_dlt645.h"
  • #include "../util/syn_assert.h"
  • #include <string.h>

Public Functions

Type Name
uint8_t syn_dlt645_calc_checksum (const uint8_t * buf, size_t len)
Compute DL/T 645 arithmetic modulo-256 checksum over buffer.
void syn_dlt645_decoder_feed (SYN_DLT645_Decoder * dec, uint8_t rx_byte)
Feed a single byte into the streaming decoder.
void syn_dlt645_decoder_init (SYN_DLT645_Decoder * dec, SYN_DLT645_Ver version, SYN_DLT645_FrameCallback cb, void * ctx)
Initialize a streaming DL/T 645 decoder.
size_t syn_dlt645_encode (const SYN_DLT645_Frame * frame, uint8_t * out_buf, size_t out_capacity)
Encode a DL/T 645 frame into a binary transmission buffer.
SYN_Status syn_dlt645_parse (const uint8_t * in_buf, size_t len, SYN_DLT645_Ver version, SYN_DLT645_Frame * out_frame)
Parse a raw byte buffer into a DL/T 645 frame.

Public Functions Documentation

function syn_dlt645_calc_checksum

Compute DL/T 645 arithmetic modulo-256 checksum over buffer.

uint8_t syn_dlt645_calc_checksum (
    const uint8_t * buf,
    size_t len
) 

Parameters:

  • buf Buffer starting from SOF (0x68).
  • len Length of buffer from SOF to end of data field.

Returns:

Modulo-256 checksum byte.


function syn_dlt645_decoder_feed

Feed a single byte into the streaming decoder.

void syn_dlt645_decoder_feed (
    SYN_DLT645_Decoder * dec,
    uint8_t rx_byte
) 

Parameters:

  • dec Decoder instance.
  • rx_byte Single byte received from UART ISR.

function syn_dlt645_decoder_init

Initialize a streaming DL/T 645 decoder.

void syn_dlt645_decoder_init (
    SYN_DLT645_Decoder * dec,
    SYN_DLT645_Ver version,
    SYN_DLT645_FrameCallback cb,
    void * ctx
) 

Parameters:

  • dec Decoder instance.
  • version Expected protocol version.
  • cb Frame received callback.
  • ctx User callback context.

function syn_dlt645_encode

Encode a DL/T 645 frame into a binary transmission buffer.

size_t syn_dlt645_encode (
    const SYN_DLT645_Frame * frame,
    uint8_t * out_buf,
    size_t out_capacity
) 

Parameters:

  • frame Input frame data.
  • out_buf Destination output buffer.
  • out_capacity Output buffer capacity (min 20 bytes).

Returns:

Number of bytes written to out_buf (0 on error).


function syn_dlt645_parse

Parse a raw byte buffer into a DL/T 645 frame.

SYN_Status syn_dlt645_parse (
    const uint8_t * in_buf,
    size_t len,
    SYN_DLT645_Ver version,
    SYN_DLT645_Frame * out_frame
) 

Parameters:

  • in_buf Input buffer containing the complete frame.
  • len Length of input buffer.
  • version Protocol version expected (1997 or 2007).
  • out_frame Destination frame struct.

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on validation failure.



The documentation for this class was generated from the following file src/syntropic/proto/syn_dlt645.c