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

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;
}
*/