You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
186 lines
6.9 KiB
186 lines
6.9 KiB
1 year ago
|
#ifndef BSP_lora_H
|
||
|
#define BSP_lora_H
|
||
|
|
||
|
#include "bsp_config.h"
|
||
|
#include "msp_uart1.h"
|
||
|
#include "TTSS_task.h"
|
||
|
|
||
|
#define D_Lora_lrd_max (32+1) ///
|
||
|
|
||
|
typedef struct
|
||
|
{
|
||
|
u8 n;
|
||
|
u8 *pstr;
|
||
|
///////////////////////////////
|
||
|
}TS_uc2info_;
|
||
|
extern TS_uc2info_ code ts_ucinfo_lora[12];
|
||
|
|
||
|
typedef struct
|
||
|
{ U16 r1;
|
||
|
U16 sphygmus;
|
||
|
U16 Oxygen_saturation;
|
||
|
U16 body_temperature;
|
||
|
U16 heart_rate;
|
||
|
}TS_Lora_param_;
|
||
|
|
||
|
extern TS_Lora_param_ ts_lora_param;
|
||
|
////利尔达的协议
|
||
|
typedef struct
|
||
|
{
|
||
|
u8 head;/// 1、帧头: 帧起始标志,固定值为 0x68。
|
||
|
U16 len;////帧头到帧尾的总字节长度。
|
||
|
u8 dcmd;
|
||
|
///u8 cmd:7; /// CMD: 命令字,指示不同的帧类型。
|
||
|
///u8 dir:1; ///高位 DIR: 指示帧传送方向,0:模组->用户。1:用户->模组。
|
||
|
///////////////////////////////
|
||
|
u8 buf[D_Lora_lrd_max];
|
||
|
///////////////////////////////
|
||
|
u8 cs; //// 校验和:从长度到数据字段的校验码,使用累加和进行计算,即各字节相加求和取最低字节。
|
||
|
u8 tail; //// 帧尾: 帧结束标志,固定值为 0x16
|
||
|
u8 *pbuf;
|
||
|
///////////////////////////////
|
||
|
}TS_Lora_lrd_;
|
||
|
extern TS_Lora_lrd_ ts_lora_lrd;
|
||
|
|
||
|
|
||
|
#define D_cmd_filter_lora 0xfE
|
||
|
extern void L2_lora_init(void);
|
||
|
extern void L3_lora_debug(u8 filter);
|
||
|
extern void lora_param_init(void);
|
||
|
|
||
|
typedef struct
|
||
|
{
|
||
|
TS_task task;
|
||
|
TS_Lora_lrd_ *p;
|
||
|
u8 ok;
|
||
|
}TS_task_lora_;
|
||
|
extern TS_task_lora_ ts_task_lora;
|
||
|
|
||
|
extern u8 Lora_mac[10][6];
|
||
|
/*****
|
||
|
节点对用户的交互接口为串口协议帧形式,
|
||
|
(串口波特率 115200,无校验,8 位数据位,1 位停止位),
|
||
|
大端模式。帧内字段以 HEX 形式表示,以下为整体帧结构:
|
||
|
|
||
|
1、帧头: 帧起始标志,固定值为 0x68。
|
||
|
2、长度: 帧头到帧尾的总字节长度。
|
||
|
3、DIR: 指示帧传送方向,0:模组->用户。1:用户->模组。
|
||
|
4、CMD: 命令字,指示不同的帧类型。
|
||
|
5、数据: 可变长的数据部分,不同命令的数据字段内容不同,参照各条命令中的定义。
|
||
|
6、校验和:从长度到数据字段的校验码,使用累加和进行计算,即各字节相加求和取最低字节。
|
||
|
7、帧尾: 帧结束标志,固定值为 0x16。
|
||
|
|
||
|
1、配置项目字段:0x01-MAC 地址,0x02-NetID,0x03-通信频段
|
||
|
|
||
|
数据 = 配置项目(1Byte)+ 内容(1-200byte)
|
||
|
|
||
|
0x68 0x00 0x08 1 0 0 1 0 0 0 0 REQ DATA
|
||
|
|
||
|
char buf[12]={ 0x68 ,0x00 ,0x07 ,0x91 ,0x01 ,0x99 ,0x16};
|
||
|
TS_Lora_lrd_ *p;
|
||
|
|
||
|
p= (TS_Lora_lrd_ *)buf;
|
||
|
p->len =9;
|
||
|
|
||
|
|
||
|
项目中的重要定义:需要在设计文档中详述,在程序中明确
|
||
|
///>>>>>>>>>>>>>>part 1: 网络拓扑
|
||
|
|
||
|
///-------P1--------------------------------------P2---------------------------P3-----------协议段
|
||
|
///PC--usb2ttl_uart--DM集中器(CC)/网关.`..`..470M-510M`.`..`.`-WB 节点1/NODE1---MCU1(用户)
|
||
|
/// .`..`..470M-510M`.`..`.`-WB 节点2/NODE2---MCU2(用户)
|
||
|
/// .`..`..470M-510M`.`..`.`-WB 节点3/NODE3---MCU3(用户)
|
||
|
/// .`..`..470M-510M`.`..`.`-WB 节点4/NODE4---MCU4(用户)
|
||
|
/// .`..`..470M-510M`.`..`.`-WB 节点5/NODE5---MCU5(用户)
|
||
|
|
||
|
///>>>>>>>>>>>>>>part 2: 硬件明细
|
||
|
|
||
|
|
||
|
////LoRa 自组网 荧火系列节点 L-LRNWB25-75TN4 -----------------WB 节点 panel point; hybrid; packing; node;---NODE
|
||
|
///LoRa 自组网 荧火系列集中器\对应型号: L-LRNDM34-77TN4-------DM集中器 concentrator -CC
|
||
|
|
||
|
///>>>>>>>>>>>>>>part 3: 文档(规格书)明细
|
||
|
|
||
|
P1 协议参考文档 DS_LoRa自组网_荧火系列集中器_接口协议_V1.0.220414_Release
|
||
|
P3 协议参考文档 DS_LoRa自组网_荧火系列节点_接口协议_V1.0.220414_Release
|
||
|
|
||
|
///>>>>>>>>>>>>>>part 4: 协议明细
|
||
|
|
||
|
P3协议:P3 协议参考文档 DS_LoRa自组网_荧火系列节点_接口协议_V1.0.220414_Release
|
||
|
|
||
|
0:模组->用户。1:用户->模组。 对于节点而言 用户指的是节点MCU 也就是本文字所在的这个程序的载体
|
||
|
0:模组-用户>MCU。1:用户MCU->模组。
|
||
|
|
||
|
集中器下发到节点--针对P3就是 节点到MCU--------《很关键,容易迷糊和误解!!!》
|
||
|
|
||
|
|
||
|
**********/
|
||
|
|
||
|
//>>>>>>>>>>>>>>>>>P3协议>命令和配置类
|
||
|
|
||
|
#define D_lora_lrd_mod2userMcu 0////0:模组->用户。1:用户->模组。
|
||
|
#define D_lora_lrd_userMcu2mod 1
|
||
|
#define D_lora_lrd_mod2userMcu_B (D_lora_lrd_mod2userMcu<<7)
|
||
|
#define D_lora_lrd_userMcu2mod_B (D_lora_lrd_userMcu2mod<<7)
|
||
|
///1.1.1 信息查询/配置类
|
||
|
|
||
|
#define D_lora_REQ_query_OK 0
|
||
|
#define D_lora_REQ_query_MAC 0x01
|
||
|
#define D_lora_REQ_query_NetID 0x02
|
||
|
#define D_lora_REQ_query_BAND 0x03///1、查询内容字段:0x01-MAC 地址,0x02-NetID,0x03-通信频段
|
||
|
|
||
|
#define D_lora_cmd_ACK (D_lora_lrd_mod2userMcu_B|B0010_0000)////20
|
||
|
#define D_lora_cmd_config (D_lora_lrd_userMcu2mod_B|B0001_0000)////90 1、配置项目字段:0x01-MAC 地址,0x02-NetID,0x03-通信频段
|
||
|
#define D_lora_cmd_query (D_lora_lrd_userMcu2mod_B|B0001_0001)////91 1、查询内容字段:0x01-MAC 地址,0x02-NetID,0x03-通信频段
|
||
|
|
||
|
////>>>>>>>>>>>>>>>>>P3协议>数据类
|
||
|
////数据下发
|
||
|
////1、用户数据:该字段内容为集中器下发至节点的用户数据,例如控制指令
|
||
|
////2、用户收到该帧后需回复“数据下发应答帧”
|
||
|
#define D_lora_cmd_dat_ack (D_lora_lrd_mod2userMcu_B|B0000_0100)////04 1、用户数据:该字段内容会上报至集中器,例如传感器数据。
|
||
|
#define D_lora_cmd_data (D_lora_lrd_userMcu2mod_B|B0000_0011)////93
|
||
|
|
||
|
////>>>>>>>>>>>>>>>>>P3协议>网络类
|
||
|
|
||
|
///1.1.3 网络/数据类
|
||
|
///1、控制字内容:0x01-主动入网
|
||
|
///2、设备主动入网结束后,模块返回“入网信息帧”指示入网结果。
|
||
|
|
||
|
////
|
||
|
#define D_lora_cmd_net_ack (D_lora_lrd_mod2userMcu_B|B0000_0010)////02
|
||
|
#define D_lora_cmd_net (D_lora_lrd_userMcu2mod_B|B0000_0001)////81 1、用户数据:该字段内容会上报至集中器,例如传感器数据。
|
||
|
|
||
|
|
||
|
#define D_lora_cmd_net_ctrl 0x01/// 1、控制字内容:0x01-主动入网
|
||
|
|
||
|
#define D_lora_cmd_01_ack (D_lora_lrd_mod2userMcu_B|B0000_0110)////06 主动上报应答
|
||
|
#define D_lora_cmd_data_zudong (D_lora_lrd_userMcu2mod_B|B0000_0101)////85 主动数据上报
|
||
|
|
||
|
#define D_eeprom_para 0
|
||
|
|
||
|
|
||
|
#define D_lora_reset_ON() D_P47_ON()
|
||
|
#define D_lora_reset_OFF() D_P47_OFF()
|
||
|
#define D_lora_reset(); D_stdIO_P4(BITN7); D_lora_reset_OFF();Lc_delay_ms(100);D_lora_reset_ON();Lc_delay_ms(1);
|
||
|
#define D_lora_wakeup_ON() D_P14_ON()
|
||
|
#define D_lora_wakeup_OFF() D_P14_OFF()
|
||
|
#define D_lora_wakeup(); D_stdIO_P1(BITN4); D_lora_wakeup_ON();Lc_delay_ms(1);D_lora_wakeup_OFF();Lc_delay_ms(1);
|
||
|
|
||
|
|
||
|
|
||
|
extern u8 L3_tpc_lora(char *buf);
|
||
|
extern void L2_task_lora_register(void);
|
||
|
extern void L2_task_lora_handle(TS_task_lora_ *s);
|
||
|
extern void L2_lora_tianbao(char *buf,u16 len);
|
||
|
extern void L2_lora_send(void);
|
||
|
extern void L3_lora_set_mac(u8 *mac);
|
||
|
|
||
|
extern void L3_lora_set_netid(u8 netid);
|
||
|
void L3_lora_set_d10(u8 *d,u8 len);
|
||
|
extern void L3_lora_set_band(u8 band);
|
||
|
void L3_lora_set_netin(void);
|
||
|
u8 L3_tpc_FEdebug(void);
|
||
|
|
||
|
|
||
|
void L2_lora_send(void);
|
||
|
#endif
|