173 lines
6.1 KiB
C
173 lines
6.1 KiB
C
/****************************************************************************
|
|
|
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
|
|
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
|
be copied by any method or incorporated into another program without
|
|
the express written consent of Aerospace C.Power. This Information or any portion
|
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
|
liability for its use in any way and conveys no license or title under
|
|
any patent or copyright and makes no representation or warranty that this
|
|
Information is free from patent or copyright infringement.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef PROTO_1662_H
|
|
#define PROTO_1662_H
|
|
|
|
#include "os_types_api.h"
|
|
#include "iot_utils_api.h"
|
|
#include "iot_pkt_api.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* pack for the structures in the whole file */
|
|
#pragma pack(push) /* save the pack status */
|
|
#pragma pack(1) /* 1 byte align */
|
|
|
|
/* definition frame start and end char */
|
|
#define PROTO_1662_START_END_CHAR 0x7E
|
|
|
|
/* definition frame address char */
|
|
#define PROTO_1662_ADDR_CHAR 0xFF
|
|
|
|
/* definition frame control char */
|
|
#define PROTO_1662_CTRL_CHAR 0x03
|
|
|
|
/* definition frame default rssi */
|
|
#define PROTO_1662_DEF_RSSI 0x0
|
|
|
|
/* definition frame protocol type */
|
|
#define PROTO_1662_PROTO_TRANS 0x21
|
|
#define PROTO_1662_PROTO_MODULE_TO_METER 0x22
|
|
#define PROTO_1662_PROTO_METER_TO_MODULE 0x23
|
|
#define PROTO_1662_PROTO_RPT 0x24
|
|
|
|
/* definition frame command */
|
|
#define PROTO_1662_CMD_TRANS 0xBF
|
|
#define PROTO_1662_CMD_GET_REQ 0xC0
|
|
#define PROTO_1662_CMD_SET_REQ 0xC1
|
|
#define PROTO_1662_CMD_EVENT 0xC2
|
|
#define PROTO_1662_CMD_ACTION_REQ 0xC3
|
|
#define PROTO_1662_CMD_GET_RESP 0xC4
|
|
#define PROTO_1662_CMD_SET_RESP 0xC5
|
|
#define PROTO_1662_CMD_ACTION_RESP 0xC7
|
|
#define PROTO_1662_CMD_ERR 0xC8
|
|
#define PROTO_1662_CMD_GET_FLW_REQ 0xCA
|
|
#define PROTO_1662_CMD_GET_FLW_RESP 0xCB
|
|
|
|
/* definition di */
|
|
#define PROTO_1662_DI_METER_SN 0x8005
|
|
#define PROTO_1662_DI_TRANS 0x8001
|
|
#define PROTO_1662_DI_VERSION 0x282f
|
|
|
|
/* definition frame len */
|
|
#define PROTO_1662_START_END_CHAR_LEN (2)
|
|
#define PROTO_1662_FCS_LEN (2)
|
|
#define PROTO_1662_INFO_LEN (2)
|
|
#define PROTO_1662_DI_LEN (2)
|
|
#define PROTO_1662_VERSION_LEN (2)
|
|
|
|
/* definition hex invalid */
|
|
#define PROTO_1662_HEX_INVALID (0xff)
|
|
|
|
typedef struct _proto_1662_header {
|
|
/* start char, see PROTO_1662_START_END_CHAR */
|
|
uint8_t start_char;
|
|
/* address, see PROTO_1662_ADDR_CHAR */
|
|
uint8_t addr;
|
|
/* control, see PROTO_1662_CTRL_CHAR */
|
|
uint8_t ctrl;
|
|
/* rssi, see PROTO_1662_DEF_RSSI */
|
|
uint8_t rssi;
|
|
/* protocol type, see PROTO_1662_PROTO_XXX */
|
|
uint8_t proto_type;
|
|
/* infomtion len, include cmd and data, big endian data */
|
|
uint8_t info_len[2];
|
|
/* command, see PROTO_1662_CMD_XXX */
|
|
uint8_t cmd;
|
|
/* data */
|
|
uint8_t data[0];
|
|
} proto_1662_header_t;
|
|
|
|
typedef struct _proto_1662_tailer {
|
|
/* check sum, big endian data */
|
|
uint8_t fcs[PROTO_1662_FCS_LEN];
|
|
/* end char. see PROTO_1662_START_END_CHAR */
|
|
uint8_t end_char;
|
|
} proto_1662_tailer_t;
|
|
|
|
typedef struct _proto_1662_di_sn {
|
|
/* di, see PROTO_1662_DI_METER_SN, little endian data */
|
|
uint8_t di[PROTO_1662_DI_LEN];
|
|
/* length of sn */
|
|
uint8_t sn_len;
|
|
/* sn, data is ascii */
|
|
uint8_t sn[0];
|
|
} proto_1662_di_sn;
|
|
|
|
typedef struct _proto_1662_di_version_resp {
|
|
/* di, see PROTO_1662_DI_TRANS, little endian data */
|
|
uint8_t trans_di[PROTO_1662_DI_LEN];
|
|
/* length of sn */
|
|
uint8_t len;
|
|
/* di, see PROTO_1662_DI_VERSION, big endian data*/
|
|
uint8_t ver_di[PROTO_1662_DI_LEN];
|
|
/* version, little endian data */
|
|
uint8_t version[PROTO_1662_VERSION_LEN];
|
|
/* version day, BCD data */
|
|
uint8_t version_day;
|
|
/* version month, BCD data */
|
|
uint8_t version_month;
|
|
/* version year, BCD data */
|
|
uint8_t version_year;
|
|
} proto_1662_di_version_resp;
|
|
|
|
#pragma pack(pop) /* restore the pack status */
|
|
|
|
/**
|
|
* @brief proto_1662_format_check - check if a 1662 packet is a valid.
|
|
* @param data: packet data
|
|
* @param len: length of the packet data
|
|
* @retval: NULL -- Incorrect protocol format.
|
|
* @retval: otherwise -- pointer to the 1662 protocol header
|
|
*/
|
|
proto_1662_header_t *proto_1662_format_check(uint8_t *data,
|
|
uint32_t len);
|
|
|
|
/**
|
|
* @brief proto_1662_build_ra_msg() - Creates a read address message for
|
|
* the 1662 protocol.
|
|
* @retval: NULL -- for failure case.
|
|
* @retval: pkt -- the iot pkt buffer for 1662 protocol.
|
|
*/
|
|
iot_pkt_t *proto_1662_build_ra_msg(void);
|
|
|
|
/**
|
|
* @brief proto_1662_build_trans_msg() - Creates a transmission message for
|
|
* the 1662 protocol.
|
|
* @param data: packet transmission data
|
|
* @param len: length of the packet data
|
|
* @retval: NULL -- for failure case.
|
|
* @retval: pkt -- the iot pkt buffer for 1662 protocol.
|
|
*/
|
|
iot_pkt_t *proto_1662_build_trans_msg(uint8_t *data, uint16_t len);
|
|
|
|
/**
|
|
* @brief proto_1662_ascii_to_hex() - change ascii to hex for
|
|
* the 1662 protocol.
|
|
* @param ascii: packet transmission data
|
|
* @retval: PROTO_1662_HEX_INVALID -- for failure case.
|
|
* @retval: other -- hex data.
|
|
*/
|
|
uint8_t proto_1662_ascii_to_hex(uint8_t ascii);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* PROTO_1662_H */
|