File syn_cjt188.h¶
FileList > proto > syn_cjt188.h
Go to the source code of this file
CJ/T 188-2004 / CJ/T 188-2018 Smart Metering Protocol. More...
#include "../common/syn_defs.h"#include <stdbool.h>#include <stddef.h>#include <stdint.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_CJT188_Decoder Streaming Decoder State Machine for CJ/T 188. |
| struct | SYN_CJT188_Frame Decoded CJ/T 188 Protocol Frame. |
| struct | SYN_CJT188_MeterData Parsed CJ/T 188 Meter Response Data. |
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. |
Macros¶
| Type | Name |
|---|---|
| define | SYN_CJT188_CTRL_READ_DATA 0x01U |
| define | SYN_CJT188_CTRL_READ_DATA_RESP 0x81U |
| define | SYN_CJT188_CTRL_WRITE_ADDR 0x15U |
| define | SYN_CJT188_CTRL_WRITE_ADDR_RESP 0x95U |
| define | SYN_CJT188_CTRL_WRITE_DATA 0x04U |
| define | SYN_CJT188_CTRL_WRITE_DATA_RESP 0x84U |
| define | SYN_CJT188_DI_READ_HIST_DATA 0xD120U |
| define | SYN_CJT188_DI_READ_METER_DATA 0x901FU |
| define | SYN_CJT188_DI_VALVE_CONTROL 0xA017U |
| define | SYN_CJT188_END_BYTE 0x16U |
| define | SYN_CJT188_MAX_FRAME_SIZE 128U |
| define | SYN_CJT188_METER_COLD_WATER 0x10U |
| define | SYN_CJT188_METER_COOLING 0x21U |
| define | SYN_CJT188_METER_DRINK_WATER 0x12U |
| define | SYN_CJT188_METER_GAS 0x30U |
| define | SYN_CJT188_METER_HEAT 0x20U |
| define | SYN_CJT188_METER_HOT_WATER 0x11U |
| define | SYN_CJT188_METER_POWER 0x40U |
| define | SYN_CJT188_METER_RECLAIMED_WATER 0x13U |
| define | SYN_CJT188_MIN_FRAME_SIZE 13U |
| define | SYN_CJT188_PREAMBLE_BYTE 0xFEU |
| define | SYN_CJT188_START_BYTE 0x68U |
| define | SYN_CJT188_VALVE_CLOSE 0x99U |
| define | SYN_CJT188_VALVE_OPEN 0x55U |
Detailed Description¶
Implements non-blocking, zero-malloc CJ/T 188 protocol framing, data encoding, valve control commands, 8-bit checksum verification, and streaming UART decoding for cold water, hot water, heat, and gas meters.
Public Functions Documentation¶
function syn_cjt188_checksum¶
Calculate CJ/T 188 8-bit checksum.
Parameters:
bufPointer to frame starting at 0x68.lenLength 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:
decoderDecoder instance.byteReceived byte from UART/RS-485.out_frameOutput 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.
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_bufBuffer to write encoded frame into.buf_sizeCapacity of out_buf (at least 17 bytes for 4x FE + frame).meter_typeMeter type (e.g. SYN_CJT188_METER_COLD_WATER).meter_id5-byte BCD meter ID array.vendor_id2-byte vendor code array.data_idData ID (e.g. SYN_CJT188_DI_READ_METER_DATA).seqSequence 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_bufBuffer to write encoded frame into.buf_sizeCapacity of out_buf (at least 18 bytes).meter_typeMeter type.meter_id5-byte BCD meter ID array.vendor_id2-byte vendor code array.open_valvetrue for OPEN (0x55), false for CLOSE (0x99).seqSequence number.
Returns:
Total bytes written, or 0 if buffer too small.
function syn_cjt188_parse_frame¶
Parse a raw CJ/T 188 binary frame.
Parameters:
bufPointer to frame buffer (may begin with optional preamble0xFE).lenLength of raw buffer.out_framePointer to output frame structure.
Returns:
true if valid frame parsed, false otherwise.
Macro Definition Documentation¶
define SYN_CJT188_CTRL_READ_DATA¶
Read meter data request
define SYN_CJT188_CTRL_READ_DATA_RESP¶
Read meter data response
define SYN_CJT188_CTRL_WRITE_ADDR¶
Write meter address request
define SYN_CJT188_CTRL_WRITE_ADDR_RESP¶
Write meter address resp
define SYN_CJT188_CTRL_WRITE_DATA¶
Write data / control req
define SYN_CJT188_CTRL_WRITE_DATA_RESP¶
Write data / control resp
define SYN_CJT188_DI_READ_HIST_DATA¶
Read historical data
define SYN_CJT188_DI_READ_METER_DATA¶
Read meter current data
define SYN_CJT188_DI_VALVE_CONTROL¶
Valve control command
define SYN_CJT188_END_BYTE¶
Frame end delimiter
define SYN_CJT188_MAX_FRAME_SIZE¶
Max supported frame length
define SYN_CJT188_METER_COLD_WATER¶
Cold water meter
define SYN_CJT188_METER_COOLING¶
Heat meter (cooling)
define SYN_CJT188_METER_DRINK_WATER¶
Direct drinking water meter
define SYN_CJT188_METER_GAS¶
Gas meter
define SYN_CJT188_METER_HEAT¶
Heat / caloric meter (heat)
define SYN_CJT188_METER_HOT_WATER¶
Domestic hot water meter
define SYN_CJT188_METER_POWER¶
Power meter
define SYN_CJT188_METER_RECLAIMED_WATER¶
Reclaimed water meter
define SYN_CJT188_MIN_FRAME_SIZE¶
Min frame without preamble
define SYN_CJT188_PREAMBLE_BYTE¶
Leading preamble byte
define SYN_CJT188_START_BYTE¶
Frame start delimiter
define SYN_CJT188_VALVE_CLOSE¶
Close valve command
define SYN_CJT188_VALVE_OPEN¶
Open valve command
The documentation for this class was generated from the following file src/syntropic/proto/syn_cjt188.h