📄 protocol.h
字号:
#define SAVED_SYS_PARAMS_LEN sizeof(SYS_PARAMETERS) - 8
#else //MASTER_PROTOCOL, for slave
// Sys Params is structured to improve memory utilization. It is used
// to read the mid out of flash and then is converted to system parameters
// that are used during operation.
typedef struct _SYS_PARAMETERS
{
// Structure used for flash reads
struct
{
unsigned char signature; // Parameters initialized and valid signature
unsigned char mid_1; // Manufacturing id of bound bridge
unsigned char mid_2;
unsigned char mid_3;
unsigned char mid_4;
} bridge_mid;
#ifdef ENCRYPT_TEA
struct
{
unsigned long key[4];
unsigned char signature;
} encrypt_key;
#endif // ENCRYPT_TEA
// Structure used for system operation
struct
{
unsigned char channel; // Currently selected channel
unsigned char pn_code; // Currently selected pncode
unsigned char seed; // CRC seed used for transmissions
unsigned char pin; // Pin used for transmissions
} network_id;
} SYS_PARAMETERS;
#define SAVED_SYS_PARAMS_LEN sizeof(SYS_PARAMETERS) - 4
#endif //MASTER_PROTOCOL
//! Size of encryption key
#define ENCRYPT_KEY_SIZE 17
//! To set up a data packet
typedef union _LP_PACKET
{
//! To hold all data of bind request packet
struct
{
//! To hold the header data of bind request packet
struct
{
//! Reserved
unsigned reserved : 0x01;
//! Type of device part of bind request packet
unsigned dev_type : 0x02;
//! Reserved
unsigned reserved1 : 0x01;
//! Type of bind request packet
unsigned type : 0x04;
} hdr;
} bind_request;
//! To hold the data of bind response packet
struct
{
//! To hold the header data of bind response packet
struct
{
//! Reserved
unsigned reserved : 0x01;
//! Type of device part of bind request packet
unsigned dev_type : 0x02;
//! Reserved
unsigned reserved1 : 0x01;
//! Type of bind response packet
unsigned type : 0x04;
} hdr;
//! 1st byte of radio manufacturing ID
unsigned char mid_1;
//! 2nd byte of radio manufacturing ID
unsigned char mid_2;
//! 3rd byte of radio manufacturing ID
unsigned char mid_3;
//! 4th byte of radio manufacturing ID
unsigned char mid_4;
} bind_response;
//! To hold the data of connect request packet
struct
{
//! To hold the header data of connect request packet
struct
{
//! Reserved
unsigned reserved : 0x01;
//! Type of device part of bind request packet
unsigned dev_type : 0x02;
//! Reserved
unsigned reserved1 : 0x01;
//! Type of connect request packet
unsigned type : 0x04;
} hdr;
//! 1st byte of radio manufacturing ID
unsigned char mid_1;
//! 2nd byte of radio manufacturing ID
unsigned char mid_2;
//! 3rd byte of radio manufacturing ID
unsigned char mid_3;
//! 4th byte of radio manufacturing ID
unsigned char mid_4;
} connect_request;
//! To hold the data of connect response packet
struct
{
//! To hold the header data of connect response packet
struct
{
//! Reserved
unsigned reserved : 0x03;
//! Data packet flag to tell whether it was a good or bad data
unsigned flag : 0x01;
//! Type of connect response packet
unsigned type : 0x04;
} hdr;
} connect_response;
//! To hold the data of the ping packet
struct
{
//! To hold the header data of the ping packet
struct
{
//! Specify a Ping (0) or Ping Response (1)
unsigned flag : 0x01;
//! Reserved
unsigned reserved : 0x03;
//! Type of ping packet
unsigned type : 0x04;
} hdr;
} ping;
//! To hold the data of an data packet
struct
{
//! To hold the header of a data packet
struct
{
//! Type of device part of data packet
unsigned data_dev_type : 0x02; // bit0 and bit1 swapped for backward compatible
//! Data toggle information of data part of packet
unsigned dt_data : 0x01;
// Back channel request
unsigned back_ch_req: 0x01;
//! Packet type
unsigned type : 0x04;
} hdr;
//! Buffer to hold data packet
unsigned char payload[PAYLOAD_LENGTH];
} data;
//! To hold the transmit data of null packet
struct
{
//! To hold the transmit header data of null packet
struct
{
//! Type of device part of null packet
unsigned dev_type : 0x02; // bit0 and bit1 swapped for backward compatible
//! Reserved
unsigned reserved : 0x02;
//! Type of data packet
unsigned type : 0x04;
} hdr;
} null;
#ifdef ENCRYPT_TEA
struct
{
//! To hold the header data of the encrypted data packet
unsigned char header;
//! Buffer to hold part of encrypted data packet
unsigned long payload[2];
} encrypt;
#endif // ENCRYPT_TEA
#ifdef ENCRYPT_AES
struct
{
//! Buffer to hold part of encrypted data packet
unsigned char payload[16];
} encrypt_aes;
#endif //ENCRYPT_AES
//! To hold the first byte of the receive packet
struct
{
//! First byte of receive packet
unsigned char byte;
} first;
} LP_PACKET;
//--------------------------------------
// Globals
//--------------------------------------
//! Packet for receiving data from the radio
extern LP_PACKET rx_packet;
//! Packet for transmitting data to the radio
extern LP_PACKET tx_packet;
//! The number of bytes in rx_packet per the radio
extern unsigned char rx_data_length;
//! A collection of system parameters for easy encapsulation
extern SYS_PARAMETERS sys_params;
//--------------------------------------
// API Function Declarations
//--------------------------------------
#ifdef MASTER_PROTOCOL
extern void MasterProtocolInit(void);
extern void MasterProtocolPingMode(unsigned char reason);
extern void MasterProtocolButtonBindMode(unsigned short retry_count);
extern void MasterProtocolDataMode( void );
extern void MasterProtocolUnbind(void);
#else //MASTER_PROTOCOL
extern void SlaveProtocolInit(void);
extern void SlaveProtocolButtonBind(unsigned char dev_type);
extern void SlaveProtocolReconnect(unsigned char dev_type);
extern PROTOCOL_STATUS SlaveProtocolSendPacket( unsigned char dev_type
,unsigned char data_dev_type
,unsigned char data_length
#ifdef BACK_CHANNEL_SUPPORT
,unsigned char back_channel
#endif //BACK_CHANNEL_SUPPORT
);
extern void* SlaveProtocolGetTxPkt(void);
extern void SlaveProtocolUnbind(void);
#endif //MASTER_PROTOCOL
extern unsigned char RadioReceivePacket(void);
extern unsigned char RadioSendPacket(unsigned char retry, unsigned char length);
extern void RadioStartReceivePacket(void);
#endif // _PROTOCOL_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -