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.
277 lines
6.9 KiB
277 lines
6.9 KiB
1 year ago
|
#include "tpc_lora.h"
|
||
|
#include "c_lib.h"
|
||
|
#include "debug_drv.h"
|
||
|
TS_pp_lrdlora_ ts_lrdlora_send, ts_lrdlora_rec;
|
||
|
ts_s2b_lrdlora_ ts_s2b_lrdlora;////协议处理变量
|
||
|
|
||
|
///查询MAC地址指令 68 00 07 91 01 99 16
|
||
|
/// 帧头 长度 配置 MAC地址 校验和 帧尾
|
||
|
#define DATA_LORA_LEN 7
|
||
|
#if 0
|
||
|
配置MAC,NetID,band指令 配置MAC地址指令 68 00 0D 90 01 61 61 62 62 63 63 EA 16 发1
|
||
|
帧头 长度 配置 REQ 配置的MAC地址 校验和 帧尾 收1 68 00 07 20 00 27 16
|
||
|
1|0010000 帧头 长度 配置 成功 校验和 帧尾
|
||
|
0|0100000
|
||
|
send:
|
||
|
68 00 0D 90 01 61 61 62 62 63 63 EA 16
|
||
|
| | | |ocr
|
||
|
| tail
|
||
|
rec:
|
||
|
68 00 07 20 00 27 16
|
||
|
| | | |ocr
|
||
|
| tail
|
||
|
|
||
|
|
||
|
|
||
|
查询MAC地址指令 68 00 07 91 01 99 16 发2
|
||
|
帧头 长度 配置 MAC地址 校验和 帧尾 收2 68 00 0D 20 00 61 61 62 62 63 63 27 16
|
||
|
1|0010001 帧头 长度 配置 成功 查询到的MAC地址 校验和 帧尾
|
||
|
68 0|0100000
|
||
|
|
||
|
配置NetID地址指令 68 00 08 90 02 AB 45 16 发3
|
||
|
帧头 长度 配置 REQ NetID地址 校验和 帧尾 收3 68 00 07 20 00 27 16
|
||
|
1|0010000 帧头 长度 配置 成功 校验和 帧尾
|
||
|
0|0100000
|
||
|
|
||
|
查询NetID地址指令 68 00 07 91 02 9A 16 发4
|
||
|
帧头 长度 配置 REQ 校验和 帧尾 收4 68 00 08 20 00 AB D3 16
|
||
|
1|0010000 帧头 长度 配置 成功 结果 校验和 帧尾
|
||
|
0|0100000
|
||
|
|
||
|
配置Band地址指令 68 00 08 90 03 09 A4 16 发5
|
||
|
帧头 长度 配置 REQ band地址 校验和 帧尾 收5 68 00 07 20 00 27 16
|
||
|
1|0010000 帧头 长度 配置 成功 校验和 帧尾
|
||
|
0|0100000
|
||
|
|
||
|
查询Band地址指令 68 00 07 91 03 9B 16 发6
|
||
|
帧头 长度 配置 REQ 校验和 帧尾 收6 68 00 08 20 00 09 27 16
|
||
|
1|0010000 帧头 长度 配置 成功 查询到band=09 校验和 帧尾
|
||
|
0|0100000
|
||
|
|
||
|
集中器点抄 点抄空包 68 00 0C 84 61 61 62 62 63 63 DC 16 发7 该指令需要入网,是否能够模拟入网???
|
||
|
帧头 长度 配置 配置的MAC地址 校验和 帧尾 收7 68 00 07 20 00 27 16
|
||
|
1|0000100 指令下发成功 帧头 长度 配置 成功 校验和 帧尾
|
||
|
0|0100000
|
||
|
收7 68 00 10 05 61 61 62 62 63 63 FF E3 00 09 4C 16
|
||
|
应答 帧头 长度 配置 MAC地址 RSSI=-16 SNR=13 校验和 帧尾
|
||
|
0|0000401
|
||
|
收7 68 00 07 06 00 0D 16
|
||
|
点抄结束 帧头 长度 配置 成功 校验和 帧尾
|
||
|
0|0100000
|
||
|
收7 68 00 06 03 09 16
|
||
|
应答3次 帧头 长度 配置 校验和 帧尾
|
||
|
0|0000011
|
||
|
收7 68 00 06 03 09 16
|
||
|
通过串口TX给MCU 帧头 长度 配置 校验和 帧尾
|
||
|
0|0000011
|
||
|
收7 68 00 06 03 09 16
|
||
|
以避免串口丢包 帧头 长度 配置 校验和 帧尾
|
||
|
0|0000011
|
||
|
|
||
|
#endif
|
||
|
u8 test3[]={0x68,0x00,0x07,0x20,0x00,0x27,0x16,0x68,0x16,0x68,0x10 ,0x07,0x20,0x00,0x16,0x68,0x00,0x06,0x03,0x09,0x16,0x68,0x00,0x06,0x04,0x0a,0x16 };
|
||
|
///u8 test3[]={0x68,0x00,0x07,0x20,0x34,0x27,0x16,0x68,0x16,0x68,0x10 ,0x07,0x20,0x00,0x16};
|
||
|
///u8 test3[]={0x68,0x00,0x09,0x20,0x34,0x56,0x78,0x27,0x16,0x68,0x16,0x68,0x10 ,0x07,0x20,0x00,0x16};
|
||
|
|
||
|
void L1_s2b_lora_init(void) //reentrant 初始化
|
||
|
{
|
||
|
u8 i = 0;
|
||
|
ts_s2b_lrdlora.ok = 0;
|
||
|
ts_s2b_lrdlora.debugok = 0;
|
||
|
ts_s2b_lrdlora.head = 0;
|
||
|
ts_s2b_lrdlora.num = 0;
|
||
|
ts_s2b_lrdlora.sp = (U8 *)&ts_lrdlora_rec;
|
||
|
|
||
|
ts_s2b_lrdlora.tp = &ts_lrdlora_rec;
|
||
|
|
||
|
/************
|
||
|
for (i = 0;i < 27;i ++)
|
||
|
{
|
||
|
ts_s2b_lrdlora.reg =test3[i];
|
||
|
L1_s2b_lora(&ts_s2b_lrdlora);
|
||
|
}************/
|
||
|
}
|
||
|
|
||
|
/// 68 00 07 20 00 27 16
|
||
|
//// | | | |ocr
|
||
|
/// | tail
|
||
|
/* num 0 1 2 3 4 5 6
|
||
|
0 68
|
||
|
1 68 00
|
||
|
2 68 00 07
|
||
|
6 68 00 07 20 00 27 16
|
||
|
|
||
|
68 00 07 20 00 27 16
|
||
|
|
||
|
68 00 08 20 00 00 28 16
|
||
|
*/
|
||
|
void L1_s2b_lora(ts_s2b_lrdlora_ *p)
|
||
|
{
|
||
|
if(p->head == 0)
|
||
|
{
|
||
|
if (D_lrdlora_filter == p->reg)
|
||
|
{
|
||
|
p->head = 1;
|
||
|
p->num = 0;
|
||
|
p->len = 5;
|
||
|
p->sp[p->num] = p->reg;
|
||
|
p->num++;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if(p->num <3)
|
||
|
{
|
||
|
p->sp[p->num] = p->reg;
|
||
|
p->num++;
|
||
|
}else if(3 == p->num)
|
||
|
{
|
||
|
p->len = D_2uc_u16(p->sp[1], p->sp[2]); ///可以读到整个报文的长度
|
||
|
p->ocr = p->sp[1] + p->sp[2];
|
||
|
p->a=p->len ;
|
||
|
if(p->len > D_TS_lrdlora_data_len2)
|
||
|
{
|
||
|
p->ok = 4;
|
||
|
p->head = 0;
|
||
|
}
|
||
|
p->sp[p->num] = p->reg;
|
||
|
p->ocr += p->sp[p->num];
|
||
|
p->num++;
|
||
|
}
|
||
|
else if(p->num < (p->len-2))
|
||
|
{
|
||
|
p->sp[p->num] = p->reg;
|
||
|
p->ocr += p->sp[p->num];
|
||
|
p->num++;
|
||
|
if(p->num > D_TS_lrdlora_data_len2)
|
||
|
{
|
||
|
p->ok = 2;p->head = 0;
|
||
|
}
|
||
|
}else if(p->num == (p->len-2))
|
||
|
{
|
||
|
p->tp->ocr = p->reg;
|
||
|
p->num++;
|
||
|
}else
|
||
|
{
|
||
|
p->tp->filtert = p->reg;
|
||
|
if (0x16 == p->tp->filtert )/////&&////( ) (ocr == p->sp[p->len-2] )
|
||
|
{ p->ok = 3;
|
||
|
if(p->tp->ocr = p->ocr)
|
||
|
{
|
||
|
p->ok = 1;
|
||
|
}
|
||
|
}
|
||
|
p->head = 0;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
#if 0
|
||
|
|
||
|
void L1_s2b_lora(ts_s2b_lrdlora_ *p)
|
||
|
{
|
||
|
if(p->head == 0)
|
||
|
{
|
||
|
if (D_lrdlora_filter == p->reg)
|
||
|
{
|
||
|
p->head = 1;
|
||
|
p->num = 0;
|
||
|
p->len = 5;
|
||
|
p->sp[p->num] = p->reg;
|
||
|
p->num++;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// vU8 ocr;
|
||
|
//
|
||
|
p->sp[p->num] = p->reg;
|
||
|
p->num++;
|
||
|
if(p->num <3)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
{
|
||
|
|
||
|
//p->sp[1] //00
|
||
|
//p->sp[2] //07
|
||
|
p->len = D_2uc_u16(p->sp[1], p->sp[2]); ///可以读到整个报文的长度
|
||
|
p->a=p->len ;
|
||
|
if(p->len > D_TS_lrdlora_data_len2)
|
||
|
{
|
||
|
p->len = D_TS_lrdlora_data_len2;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
else if(p->num < p->len)
|
||
|
{
|
||
|
if(p->num > D_TS_lrdlora_data_len2)
|
||
|
{
|
||
|
p->num = D_TS_lrdlora_data_len2;p->ok = 2;p->head = 0;
|
||
|
}
|
||
|
p->sp[p->num] = p->reg; ///此时reg需要指向报文的第四个字节数
|
||
|
p->num++;
|
||
|
}else if(p->num >= p->len)
|
||
|
{/// >= len
|
||
|
// vU8 i;
|
||
|
// for(i = 1;i <= (p->len-3);i++) ///计算校验和 cal ocr
|
||
|
// {
|
||
|
// ocr = ocr + p->sp[i];
|
||
|
// }
|
||
|
p->ok = 1;
|
||
|
if ( //// (ocr == p->sp[p->len-2] )&&
|
||
|
(0x16 == p->sp[p->len-1] ) )
|
||
|
{
|
||
|
p->head = 0;p->ok = 3;
|
||
|
}
|
||
|
p->head = 0;
|
||
|
}else
|
||
|
{
|
||
|
///p->ok = 3;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void TS_lora_send(void)
|
||
|
|
||
|
{
|
||
|
|
||
|
TS_lrdlora_send.filter = 0x68;
|
||
|
///send(TS_lrdlora_send.filter)
|
||
|
L1_uartD_uchexArray(TS_lrdlora_send.filter, 1);
|
||
|
///send(TS_lrdlora_send.DIR|TS_lrdlora_send.CMD) ///命令字或运算
|
||
|
L1_uartD_uchexArray(TS_lrdlora_send.DIR|TS_lrdlora_send.CMD, 1);
|
||
|
p=TS_lrdlora_send.buf;
|
||
|
for(len)
|
||
|
{
|
||
|
send(*p);
|
||
|
p++
|
||
|
cor ;
|
||
|
}
|
||
|
///send(TS_lrdlora_send.ocr)
|
||
|
L1_uartD_uchexArray(TS_lrdlora_send.ocr,1);
|
||
|
///send(TS_lrdlora_send.filtert)
|
||
|
L1_uartD_uchexArray(TS_lrdlora_send.filtert,1);
|
||
|
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
/*
|
||
|
vU8 Fun_SC_Check(vU8 *p1, vU16 len)//累加校验和
|
||
|
{
|
||
|
vU8 sum = 0;
|
||
|
for(len;len >= 1; len--)
|
||
|
{
|
||
|
sum += *p1++;
|
||
|
}
|
||
|
|
||
|
return sum;
|
||
|
}
|
||
|
*/
|
||
|
|