Skip to content

File syn_cjt188.c

FileList > proto > syn_cjt188.c

Go to the source code of this file

Implementation of CJ/T 188-2004 / 2018 Protocol Driver.

  • #include "syn_cjt188.h"
  • #include "../util/syn_pack.h"
  • #include <string.h>

Public Functions

Type Name
uint8_t syn_cjt188_checksum (const uint8_t * buf, size_t len)
Calculate CJ/T 188 8-bit checksum.
bool syn_cjt188_decoder_feed (SYN_CJT188_Decoder * decoder, uint8_t byte, SYN_CJT188_Frame * out_frame)
Feed a single byte into the streaming decoder.
void syn_cjt188_decoder_init (SYN_CJT188_Decoder * decoder)
Initialize a CJ/T 188 streaming decoder instance.
size_t syn_cjt188_encode_read_req (uint8_t * out_buf, size_t buf_size, uint8_t meter_type, const uint8_t meter_id, const uint8_t vendor_id, uint16_t data_id, uint8_t seq)
Encode a CJ/T 188 Read Meter Data Request ( 0x01 ).
size_t syn_cjt188_encode_valve_ctrl (uint8_t * out_buf, size_t buf_size, uint8_t meter_type, const uint8_t meter_id, const uint8_t vendor_id, bool open_valve, uint8_t seq)
Encode a CJ/T 188 Valve Control Request ( 0x04 ).
bool syn_cjt188_parse_frame (const uint8_t * buf, size_t len, SYN_CJT188_Frame * out_frame)
Parse a raw CJ/T 188 binary frame.

Public Functions Documentation

function syn_cjt188_checksum

Calculate CJ/T 188 8-bit checksum.

uint8_t syn_cjt188_checksum (
    const uint8_t * buf,
    size_t len
) 

Parameters:

  • buf Pointer to frame starting at 0x68.
  • len Length of frame from 0x68 up to payload end (excluding CS and 0x16).

Returns:

8-bit sum modulo 256.


function syn_cjt188_decoder_feed

Feed a single byte into the streaming decoder.

bool syn_cjt188_decoder_feed (
    SYN_CJT188_Decoder * decoder,
    uint8_t byte,
    SYN_CJT188_Frame * out_frame
) 

Parameters:

  • decoder Decoder instance.
  • byte Received byte from UART/RS-485.
  • out_frame Output frame structure populated when a complete frame arrives.

Returns:

true if a complete valid frame was decoded, false otherwise.


function syn_cjt188_decoder_init

Initialize a CJ/T 188 streaming decoder instance.

void syn_cjt188_decoder_init (
    SYN_CJT188_Decoder * decoder
) 


function syn_cjt188_encode_read_req

Encode a CJ/T 188 Read Meter Data Request ( 0x01 ).

size_t syn_cjt188_encode_read_req (
    uint8_t * out_buf,
    size_t buf_size,
    uint8_t meter_type,
    const uint8_t meter_id,
    const uint8_t vendor_id,
    uint16_t data_id,
    uint8_t seq
) 

Parameters:

  • out_buf Buffer to write encoded frame into.
  • buf_size Capacity of out_buf (at least 17 bytes for 4x FE + frame).
  • meter_type Meter type (e.g. SYN_CJT188_METER_COLD_WATER).
  • meter_id 5-byte BCD meter ID array.
  • vendor_id 2-byte vendor code array.
  • data_id Data ID (e.g. SYN_CJT188_DI_READ_METER_DATA).
  • seq Sequence number.

Returns:

Total bytes written to out_buf, or 0 if buffer too small.


function syn_cjt188_encode_valve_ctrl

Encode a CJ/T 188 Valve Control Request ( 0x04 ).

size_t syn_cjt188_encode_valve_ctrl (
    uint8_t * out_buf,
    size_t buf_size,
    uint8_t meter_type,
    const uint8_t meter_id,
    const uint8_t vendor_id,
    bool open_valve,
    uint8_t seq
) 

Parameters:

  • out_buf Buffer to write encoded frame into.
  • buf_size Capacity of out_buf (at least 18 bytes).
  • meter_type Meter type.
  • meter_id 5-byte BCD meter ID array.
  • vendor_id 2-byte vendor code array.
  • open_valve true for OPEN (0x55), false for CLOSE (0x99).
  • seq Sequence number.

Returns:

Total bytes written, or 0 if buffer too small.


function syn_cjt188_parse_frame

Parse a raw CJ/T 188 binary frame.

bool syn_cjt188_parse_frame (
    const uint8_t * buf,
    size_t len,
    SYN_CJT188_Frame * out_frame
) 

Parameters:

  • buf Pointer to frame buffer (may begin with optional preamble 0xFE).
  • len Length of raw buffer.
  • out_frame Pointer to output frame structure.

Returns:

true if valid frame parsed, false otherwise.



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