143 lines
3.7 KiB
C
143 lines
3.7 KiB
C
|
|
/*
|
|||
|
|
*********************************************************************************************************
|
|||
|
|
* IAR Development Kits
|
|||
|
|
* on the
|
|||
|
|
*
|
|||
|
|
* Nano100
|
|||
|
|
*
|
|||
|
|
* Filename : uart_RFModule.h
|
|||
|
|
* Version : V1.00
|
|||
|
|
* Programmer(s) : Qian Xianghong
|
|||
|
|
*********************************************************************************************************
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#ifndef USER_UART_RFMODULE_PRESENT
|
|||
|
|
#define USER_UART_RFMODULE_PRESENT
|
|||
|
|
|
|||
|
|
// <20><>ʼ<EFBFBD><CABC>
|
|||
|
|
void RF_Init();
|
|||
|
|
void RF_Open();
|
|||
|
|
|
|||
|
|
// ģ<><C4A3><EFBFBD>ϵ磬<CFB5><E7A3AC><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
void RF_PowerOn();
|
|||
|
|
void RF_PowerOff();
|
|||
|
|
// <20>ն<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>Ѱ<EFBFBD><D1B0><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѱ<EFBFBD><D1B0><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>Ӧ<EFBFBD><D3A6>
|
|||
|
|
// <20><>Ѱ5<D1B0>Σ<EFBFBD>ȡ<EFBFBD><C8A1>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊͨ<CEAA><CDA8><EFBFBD><EFBFBD><EFBFBD>ء<EFBFBD>
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>10<31><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
uint8_t rf_check_gateway();
|
|||
|
|
// <20><><EFBFBD>鵱ǰ<E9B5B1>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
uint8_t rf_has_gateway();
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
void rf_clear_gateway();
|
|||
|
|
// Ӧ<>ò㷢<C3B2>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
uint8_t rf_app_send_data(uint8_t payload_len, uint8_t *payload);
|
|||
|
|
|
|||
|
|
#define RF_MIN_FRAME_LEN (24)
|
|||
|
|
#define RF_MAX_FRAME_LEN (61)
|
|||
|
|
#define RF_MIN_PAYLOAD_LEN (0)
|
|||
|
|
#define RF_MAX_PAYLOAD_LEN (RF_MAX_FRAME_LEN - RF_MIN_FRAME_LEN)
|
|||
|
|
|
|||
|
|
#define RF_DIR_UP (0) // <20><><EFBFBD><EFBFBD>
|
|||
|
|
#define RF_DIR_DOWN (1) // <20><><EFBFBD><EFBFBD>
|
|||
|
|
#define RF_MAC_TYPE_DATA (0) // mac֡-<2D><><EFBFBD><EFBFBD>
|
|||
|
|
#define RF_MAC_TYPE_ACK (1) // mac֡-ACK
|
|||
|
|
#define RF_NET_TYPE_DATA (0) // net֡-<2D><><EFBFBD><EFBFBD>
|
|||
|
|
#define RF_NET_TYPE_FIND_RELAY (1) // net֡-Ѱ<><D1B0><EFBFBD>м<EFBFBD><D0BC><EFBFBD>
|
|||
|
|
#define RF_NET_TYPE_RESP_RELAY (2) // net֡-Ӧ<><D3A6><EFBFBD>м<EFBFBD><D0BC><EFBFBD>
|
|||
|
|
|
|||
|
|
#define RF_FRAME_SOF (0x1B) // <20><>ʶһ<CAB6><D2BB>֡<EFBFBD>Ŀ<EFBFBD>ʼ
|
|||
|
|
#define RF_MARK_LS (('S' << 8) | 'L')
|
|||
|
|
#define RF_APP_AJH ('A') // data.idatatank.com:8088
|
|||
|
|
#define RF_APP_PRAX ('P') // tts.praxair.com.cn:7005
|
|||
|
|
#define RF_APP_LANSHI ('L') // data.cd-ls.cn:8088
|
|||
|
|
#define RF_PROTOCOL_VER_1 (1)
|
|||
|
|
|
|||
|
|
// <20><>Ƶ<EFBFBD><C6B5>ʼ<EFBFBD><CABC>״̬
|
|||
|
|
extern uint8_t RF_initStatus;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ
|
|||
|
|
#pragma anon_unions
|
|||
|
|
#pragma pack(push, 1)
|
|||
|
|
|
|||
|
|
typedef struct // size = RF_MAX_FRAME_LEN
|
|||
|
|
{
|
|||
|
|
uint8_t sof; // RF_FRMAE_SOF
|
|||
|
|
uint8_t len; // bytes from sof to crc<72><63>RF_MIN_FRAME_LEN~RF_MAX_FRAME_LEN<45><4E>
|
|||
|
|
uint16_t vendor_id; // RF_MARK_LS
|
|||
|
|
uint8_t app_id; // RF_APP_AJH or RF_APP_PRAX or RF_APP_LANSHI
|
|||
|
|
uint8_t protocol_ver; // RF_PROTOCOL
|
|||
|
|
unsigned dir : 1; // RF_DIR_UP or RF_DIR_DOWN
|
|||
|
|
unsigned mac_type : 2; // RF_MAC_TYPE_DATA or RF_MAC_TYPE_ACK
|
|||
|
|
unsigned mac_ack_req : 1; // is ack requested?
|
|||
|
|
unsigned net_type : 2; // RF_NET_TYPE_DATA or RF_NET_TYPE_FIND_RELAY or RF_NET_TYPE_RESP_RELAY
|
|||
|
|
unsigned : 2; // reserved
|
|||
|
|
uint8_t mac_fn; // mac frame number
|
|||
|
|
uint8_t destPSN[6];
|
|||
|
|
uint8_t srcPSN[6];
|
|||
|
|
uint8_t app_pn; // package number
|
|||
|
|
unsigned app_idx : 7; // frame number in package
|
|||
|
|
unsigned app_tbc : 1; // to be continue?
|
|||
|
|
uint8_t app_payload[RF_MAX_PAYLOAD_LEN];
|
|||
|
|
uint16_t crc; // ռλ<D5BC>ã<EFBFBD>ʵ<EFBFBD><CAB5>crc<72><63><EFBFBD>ܸ<EFBFBD><DCB8><EFBFBD>ǰ
|
|||
|
|
} rf_frame_t;
|
|||
|
|
|
|||
|
|
// mac<61><63>ack<63><6B>Ϣ
|
|||
|
|
typedef struct
|
|||
|
|
{
|
|||
|
|
uint8_t srcPSN[6];
|
|||
|
|
uint8_t mac_fn;
|
|||
|
|
} rf_ack_t;
|
|||
|
|
|
|||
|
|
// Ӧ<>ò<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>Ϣ
|
|||
|
|
typedef struct
|
|||
|
|
{
|
|||
|
|
uint8_t srcPSN[6];
|
|||
|
|
uint8_t app_pn;
|
|||
|
|
uint8_t payload_len;
|
|||
|
|
uint8_t payload[RF_MAX_PAYLOAD_LEN];
|
|||
|
|
} rf_resp_t;
|
|||
|
|
|
|||
|
|
typedef struct
|
|||
|
|
{
|
|||
|
|
unsigned staDiff : 2;
|
|||
|
|
unsigned staPress : 2;
|
|||
|
|
unsigned staETempr1 : 2;
|
|||
|
|
unsigned charging : 1;
|
|||
|
|
unsigned bat_low : 1;
|
|||
|
|
unsigned measure_type : 2;
|
|||
|
|
unsigned bottle_type : 2;
|
|||
|
|
unsigned L_source : 3;
|
|||
|
|
unsigned location_type : 1; // 0-GPS,1-<2D><>վ
|
|||
|
|
} rf_sensor_t;
|
|||
|
|
|
|||
|
|
typedef struct // size = 37
|
|||
|
|
{
|
|||
|
|
uint16_t diff;
|
|||
|
|
uint16_t press;
|
|||
|
|
int16_t tempr;
|
|||
|
|
rf_sensor_t Sensor;
|
|||
|
|
uint16_t density;
|
|||
|
|
uint32_t longitude;
|
|||
|
|
uint32_t latitude;
|
|||
|
|
uint16_t voltage;
|
|||
|
|
uint8_t batPct;
|
|||
|
|
int8_t batCurrent;
|
|||
|
|
uint32_t relative_time;
|
|||
|
|
uint8_t hardVer;
|
|||
|
|
uint8_t softVer;
|
|||
|
|
uint32_t L;
|
|||
|
|
uint32_t d;
|
|||
|
|
uint8_t chargePct;
|
|||
|
|
} rf_app_data_t;
|
|||
|
|
|
|||
|
|
#pragma pack(pop)
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>ʽΪx16+x15+x2+1<><31>LSB˳<42><CBB3>
|
|||
|
|
// ͬibutton<6F><6E>crc<72>㷨<EFBFBD><E3B7A8><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>modbus<75><73>crc<72>㷨
|
|||
|
|
uint16_t rf_crc_16(uint8_t *message, int16_t len);
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
uint32_t rf_get_seconds();
|
|||
|
|
|
|||
|
|
#endif
|