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.
818 lines
24 KiB
818 lines
24 KiB
#include "bsp_lora.h"
|
|
//#include "tpc_debug.h"
|
|
#include "tpc_lora.h"
|
|
////
|
|
#include "c_lib.h"
|
|
#include "msp_uart1.h"
|
|
#include "msp_uart2.h"
|
|
|
|
#include "debug_drv.h"
|
|
#include "msp_eeprom.h"
|
|
|
|
#include "max30102.h"
|
|
|
|
#include "MLX90615.h"
|
|
|
|
|
|
///[2023-02-07 00:40:43.110 T]68 00 0D 90 01 32 33 34 35 36 39 DB 16
|
|
//// | 1 2 3 4 5 6 |
|
|
///[2023-02-07 00:40:43.172 R]68 00 07 20 00 27 16
|
|
u8 Lora_mac[10][6]={
|
|
{0x61 ,0x61 ,0x62 ,0x62 ,0x63 ,0x64 },
|
|
{0x71 ,0x61 ,0x62 ,0x62 ,0x63 ,0x64 },
|
|
{0x81 ,0x61 ,0x62 ,0x62 ,0x63 ,0x64 },
|
|
{0x91 ,0x61 ,0x62 ,0x62 ,0x63 ,0x64 },
|
|
{0xa1 ,0x61 ,0x62 ,0x62 ,0x63 ,0x64 }
|
|
};
|
|
/********
|
|
TS_uc2info_ code ts_ucinfo_lora[12]={
|
|
0x00,"succses 成功", ///0
|
|
0x01 ,"head tail error帧头帧尾非法",///0
|
|
0x02 ," 帧长度非法",///0
|
|
0x03 ," 帧方向异常",///0
|
|
0x04 ," 非法命令",///0
|
|
0x05 ," 校验和错误",///0
|
|
0x06 ," 网内无设备",///0
|
|
0x07 ,"MAC 地址错误",///0
|
|
0x08 ," 数据内容错误",///0
|
|
0x09 ," FLASH 写入错误",///0
|
|
0x0A ," 存储溢出错误",///0
|
|
0x0B ," 设备忙",///11
|
|
};
|
|
*********/
|
|
TS_uc2info_ code ts_ucinfo_lora[12]={
|
|
0x00 ,"R:ack success" ,///0 01 "success 成功",
|
|
0x01 ,"E:head tail " ,///1 02 "head tail error帧头帧尾非法",
|
|
0x02 ,"E:len" ,///2 03 " 帧长度非法",
|
|
0x03 ,"E:dir" ,///3 04 " 帧方向异常",
|
|
0x04 ,"E:cmd" ,///4 05 " 非法命令",
|
|
0x05 ,"E:ocr " ,///5 06 " 校验和错误",
|
|
0x06 ,"E:no device in net " ,///6 07 " 网内无设备",
|
|
0x07 ,"E:mac addr " ,///7 08 "MAC 地址错误",
|
|
0x08 ,"E:data " ,///8 09 " 数据内容错误",
|
|
0x09 ,"E:flash write " ,///9 10 " FLASH 写入错误",
|
|
0x0A ,"E:mem overflow " ,///10 11 " 存储溢出错误",
|
|
0x0B ,"R:busy" ///11 12 " 设备忙",
|
|
};
|
|
#define D_lora_SUCCESS 0
|
|
#define D_lora_FAIL 1
|
|
#define D_lora_NONE 0xff
|
|
|
|
TS_uc2info_ code ts_ucinfo_inet[5]={
|
|
0x05 ,"R:inet none " ,///0 01
|
|
0x00 ,"R:inet success " ,///1 02 0x01-设备入网成功,
|
|
0x01 ,"E:inet fail " ,///2 03 0x02-设备入网失败
|
|
0x03 ,"E:out of net " ,///3 04 ,0x03-设备已离网
|
|
0x04 ,"E:cmd" ///4 05 " 非法命令",
|
|
};
|
|
|
|
TS_uc2info_ code ts_ucinfo_sf[3]={
|
|
0x00 ,"R:data up success " ,///0 01
|
|
0x01 ,"E:data up fail" ,///1 02 0x01-设备入网成功,
|
|
0x02 ,"E:??"
|
|
|
|
};
|
|
|
|
TS_Lora_lrd_ ts_lora_lrd=
|
|
{
|
|
0x68,////u8 head;/// 1、帧头: 帧起始标志,固定值为 0x68。
|
|
0x00,////U16 len;////帧头到帧尾的总字节长度。
|
|
0x27,////u8 dcmd;
|
|
///u8 cmd:7; /// CMD: 命令字,指示不同的帧类型。
|
|
///u8 dir:1; ///高位 DIR: 指示帧传送方向,0:模组->用户。1:用户->模组。
|
|
///////////////////////////////
|
|
////u8 buf[D_Lora_lrd_max];
|
|
0x0A,
|
|
0x01 ,0x02 ,0x03 ,0x04 ,0x05 ,0x06 ,0x07 ,0x08 ,0x09 ,0x10,
|
|
0x11 ,0x12 ,0x13 ,0x14 ,0x15 ,0x16 ,0x17 ,0x18 ,0x19 ,0x20,
|
|
0x21 ,0x22 ,0x23 ,0x24 ,0x25 ,0x26 ,0x27 ,0x28 ,0x29 ,0x30,
|
|
0x31, 0x32,
|
|
///d2 68 00 27 85 0A 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
|
|
////21 22 23 24 25 26 27 28 29 30 31 32 B0 16
|
|
|
|
///////////////////////////////
|
|
0xb0,////u8 cs; //// 校验和:从长度到数据字段的校验码,使用累加和进行计算,即各字节相加求和取最低字节。
|
|
0x16,////u8 tail; //// 帧尾: 帧结束标志,固定值为 0x16
|
|
|
|
|
|
};
|
|
TS_Lora_lrd_ ts_lora_lrd32 =
|
|
{
|
|
0x68,////u8 head;/// 1、帧头: 帧起始标志,固定值为 0x68。
|
|
0x0027,////U16 len;////帧头到帧尾的总字节长度。
|
|
0x85,////u8 dcmd;
|
|
///u8 cmd:7; /// CMD: 命令字,指示不同的帧类型。
|
|
///u8 dir:1; ///高位 DIR: 指示帧传送方向,0:模组->用户。1:用户->模组。
|
|
///////////////////////////////
|
|
////u8 buf[D_Lora_lrd_max];
|
|
0x0A,
|
|
0x01 ,0x02 ,0x03 ,0x04 ,0x05 ,0x06 ,0x07 ,0x08 ,0x09 ,0x10,
|
|
0x11 ,0x12 ,0x13 ,0x14 ,0x15 ,0x16 ,0x17 ,0x18 ,0x19 ,0x20,
|
|
0x21 ,0x22 ,0x23 ,0x24 ,0x25 ,0x26 ,0x27 ,0x28 ,0x29 ,0x30,
|
|
0x31, 0x32,
|
|
///d2 68 00 27 85 0A 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
|
|
////21 22 23 24 25 26 27 28 29 30 31 32 B0 16
|
|
|
|
///////////////////////////////
|
|
0xb0,////u8 cs; //// 校验和:从长度到数据字段的校验码,使用累加和进行计算,即各字节相加求和取最低字节。
|
|
0x16,////u8 tail; //// 帧尾: 帧结束标志,固定值为 0x16
|
|
|
|
|
|
};
|
|
|
|
|
|
void L2_lora_rec(void);
|
|
void L3_lora_set_d32(u8 *d);
|
|
void L3_lora_set_d8(u8 *d,u8 len);
|
|
|
|
TS_task_lora_ ts_task_lora;
|
|
TS_para_ ts_para;
|
|
TS_Lora_param_ ts_lora_param;
|
|
|
|
void L2_lora_init(void)
|
|
{
|
|
D_lora_wakeup_ON();
|
|
D_lora_reset();
|
|
|
|
ts_task_lora.ok = 0;
|
|
printf("\r\n read ts_para (%d) = ",(int)sizeof(ts_para));
|
|
L0_Iap_Read_array(D_eeprom_para,(char*)&ts_para,sizeof(ts_para));
|
|
if (ts_para.mac[0] == 0xff)
|
|
{
|
|
Lc_buf_copy_uc(ts_para.mac,Lora_mac[0],6);
|
|
ts_para.req = 0x01;
|
|
ts_para.netid = 0xAB;
|
|
ts_para.band = 0x09;
|
|
printf("\r\n reset ts_para to factory");
|
|
}
|
|
L0_Iap_Program_array(D_eeprom_para,(char*)&ts_para,sizeof(ts_para));
|
|
/// L1_uartD_uchexArray((char*)&ts_para, sizeof(ts_para));
|
|
|
|
}
|
|
|
|
void L2_task_lora_register(void)
|
|
{
|
|
L1_task_reg_clear(&ts_task_lora.task);
|
|
L3_task_s_go(ts_task_lora,D_task_init);
|
|
|
|
}
|
|
|
|
///step 1 init
|
|
///step 2 查询mac地址和eeprom是否一致 不一致使用eeprom中
|
|
///step 3 查询netid
|
|
///step 4 查询bank
|
|
///step 5 入网
|
|
///step 6
|
|
|
|
|
|
#define D_task_lora_set 0x41
|
|
|
|
#define D_task_Lora_cmd_init 0x41
|
|
#define D_task_Lora_cmd_mac 0x42
|
|
|
|
#define D_task_Lora_cmd_mac_ok 0x52
|
|
#define D_task_Lora_cmd_netid 0x43
|
|
#define D_task_Lora_cmd_netid_ok 0x53
|
|
#define D_task_Lora_cmd_band 0x44
|
|
#define D_task_Lora_cmd_band_ok 0x54
|
|
#define D_task_Lora_cmd_innet 0x45
|
|
#define D_task_Lora_cmd_innet_ok 0x55
|
|
|
|
#define D_task_Lora_cmd_32 0x46
|
|
#define D_task_Lora_cmd_32_ok 0x56
|
|
|
|
///发送32个字节
|
|
////d2 68 00 27 85 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 a5 16
|
|
|
|
|
|
#define D_delay_lorat D_Tdelay_3s
|
|
|
|
|
|
////集中器网关必须使能白名单??
|
|
////L2_task_lora_handle(&ts_task_lora);
|
|
void L2_task_lora_handle(TS_task_lora_ *s)
|
|
{
|
|
unsigned char d = 0;
|
|
TTSS_Task_init():
|
|
printf("\r\nL2_task_lora_handle TTSS_Task_init");
|
|
L2_lora_init();
|
|
L2_task_Tdelay_go(D_Tdelay_2s,D_task_Lora_cmd_init);
|
|
|
|
TTSS_Task_step(D_task_Lora_cmd_init):
|
|
L3_lora_set_mac(Lora_mac[0]);////
|
|
ts_task_lora.ok = D_lora_NONE;
|
|
L2_task_Tdelay_go(D_delay_lorat,D_task_Lora_cmd_mac);
|
|
TTSS_Task_step(D_task_Lora_cmd_mac):
|
|
|
|
printf("\r\n read ts_para (%d) = ",(int)sizeof(ts_para));
|
|
L0_Iap_Read_array(D_eeprom_para,(char*)&ts_para,sizeof(ts_para));
|
|
printf("\r\n---> lora Lora_cmd_mac ");
|
|
L3_lora_set_mac(ts_para.mac);
|
|
L2_task_go(D_task_Lora_cmd_mac_ok);
|
|
TTSS_Task_step(D_task_Lora_cmd_mac_ok):
|
|
if(D_lora_SUCCESS == ts_task_lora.ok)
|
|
{
|
|
ts_task_lora.ok = D_lora_NONE;
|
|
L2_task_go(D_task_Lora_cmd_netid);
|
|
}
|
|
/// 0x68 ,0x00 ,0x08 ,0x90 ,0x02 ,0xAB ,0x45 ,0x16
|
|
TTSS_Task_step(D_task_Lora_cmd_netid):
|
|
printf("\r\n---> lora Lora_cmd_netid %X ",(int)ts_para.netid);
|
|
L3_lora_set_netid(ts_para.netid );
|
|
L2_task_go(D_task_Lora_cmd_netid_ok);
|
|
TTSS_Task_step(D_task_Lora_cmd_netid_ok):
|
|
if(D_lora_SUCCESS == ts_task_lora.ok)
|
|
{
|
|
printf("D_lora_SUCCESS:cmd_netid");
|
|
ts_task_lora.ok = D_lora_NONE;
|
|
L2_task_go(D_task_Lora_cmd_band);
|
|
}
|
|
TTSS_Task_step(D_task_Lora_cmd_band):
|
|
printf("\r\n---> lora Lora_cmd_band %X ",(int)ts_para.band);
|
|
L3_lora_set_band(ts_para.band);
|
|
/// 0x68 ,0x00 ,0x08 ,0x90 ,0x03 ,0x09 ,0xA4 ,0x16
|
|
//68 00 08 90 03 09 A4 16
|
|
L2_task_go(D_task_Lora_cmd_band_ok);
|
|
TTSS_Task_step(D_task_Lora_cmd_band_ok):
|
|
if(D_lora_SUCCESS == ts_task_lora.ok)
|
|
{
|
|
printf("D_lora_SUCCESS:Lora_cmd_band");
|
|
ts_task_lora.ok = D_lora_NONE;
|
|
L2_task_go(D_task_Lora_cmd_innet);
|
|
}
|
|
TTSS_Task_step(D_task_Lora_cmd_innet):
|
|
/// 68 00 07 81 01 89 16 ///节点主动入网(band、NetID默认暂不保存,
|
|
printf("\r\n---> lora Lora_cmd_innet ");
|
|
L3_lora_set_netin();
|
|
L1_OLED_ShowChar(0,0,'O',D_6X8);////表示没有入网成功
|
|
L2_task_go(D_task_Lora_cmd_innet_ok);
|
|
TTSS_Task_step(D_task_Lora_cmd_innet_ok):
|
|
if(D_lora_NONE != ts_task_lora.ok)
|
|
{
|
|
if(D_lora_SUCCESS == ts_task_lora.ok)
|
|
{
|
|
L1_OLED_ShowChar(0,0,'Y',D_6X8);////表示 入网成功
|
|
printf("D_lora_SUCCESS: innet_ok");
|
|
L2_task_go(D_task_Lora_cmd_32);
|
|
}else
|
|
{
|
|
L2_task_go(D_task_Lora_cmd_innet);
|
|
}
|
|
ts_task_lora.ok = D_lora_NONE;
|
|
|
|
}else
|
|
{
|
|
}
|
|
TTSS_Task_step(D_task_Lora_cmd_32):
|
|
|
|
printf("\r\n D_task_Lora_cmd_32 %2X %c",(int)ts_lora_lrd32.buf[0],ts_lora_lrd32.buf[0]);
|
|
if(ts_lora_lrd32.buf[0] < ' ')
|
|
{
|
|
ts_lora_lrd32.buf[0] = ' ';
|
|
|
|
}else if(ts_lora_lrd32.buf[0] > '~')
|
|
{
|
|
|
|
ts_lora_lrd32.buf[0] = ' ';
|
|
}else
|
|
{
|
|
ts_lora_lrd32.buf[0] ++;
|
|
}
|
|
|
|
|
|
|
|
L1_OLED_ShowChar(6,0,'s',D_6X8);///发送一个数据累加一个
|
|
/// L3_lora_set_d32(ts_max30102.send);
|
|
|
|
ts_lora_param.Oxygen_saturation = (int)ts_max30102.SPO2_out;
|
|
ts_lora_param.body_temperature = (int)ts_mx95.u16out_10o;
|
|
ts_lora_param.heart_rate = (int)ts_max30102.hr_out2;
|
|
ts_lora_param.sphygmus = (int)ts_max30102.hr_out;
|
|
|
|
/// L3_lora_set_d8((char *)&ts_lora_param,8);
|
|
L3_lora_set_d10((char *)&ts_lora_param,10);
|
|
|
|
///L3_lora_set_d8(ts_max30102.send,8);
|
|
L2_task_go(D_task_Lora_cmd_32_ok);
|
|
TTSS_Task_step(D_task_Lora_cmd_32_ok):
|
|
if(D_lora_NONE != ts_task_lora.ok)
|
|
{
|
|
if(D_lora_SUCCESS == ts_task_lora.ok)
|
|
{
|
|
L1_OLED_ShowChar(0,0,'y',D_6X8);////表示 发送成功
|
|
printf("D_lora_SUCCESS: cmd_32_ok");
|
|
}else
|
|
{
|
|
L1_OLED_ShowChar(0,0,'O',D_6X8);////表示
|
|
}
|
|
ts_task_lora.ok = D_lora_NONE;
|
|
L1_OLED_ShowChar(8,0,ts_lora_lrd32.buf[0],D_6X8);///发送一个数据累加一个
|
|
L2_task_Tdelay_go(D_Tdelay_15s,D_task_Lora_cmd_32);
|
|
}
|
|
TTSS_Task_end();
|
|
////////////////////////////////////////////////////////////
|
|
L2_lora_rec();
|
|
if(ts_key.val)
|
|
{
|
|
ts_key.val = 0;
|
|
printf("\r\n```\\_____ ");
|
|
L3_lora_set_d32(ts_max30102.send);////按下按键 发送波形数据
|
|
L2_task_go(D_task_Lora_cmd_32_ok);
|
|
}
|
|
|
|
}
|
|
|
|
//// add +32字节数据 add为子机地址
|
|
///d2 68 00 27 85 0A 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 B0 16
|
|
|
|
void L2_lora_rec(void)
|
|
{
|
|
|
|
if(1 == ts_Urec[D_UART2].ok)
|
|
{ ts_Urec[D_UART2].ok = 0;////收到一帧数据
|
|
printf("\r\n<--- lora ask: ");
|
|
/// sprintf(," %s ",ts_Urecbuf.r2);
|
|
//pd = (TS_P_debug*)ts_Urecbuf.r2;////
|
|
//L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num);
|
|
L1_uartD_uchexArray(ts_Urecbuf.r2, ts_Urec[D_UART2].num);
|
|
ts_task_lora.p = (TS_Lora_lrd_ *)ts_Urecbuf.r2;
|
|
//ts_task_lora.ok = ts_task_lora.p->buf[0];
|
|
|
|
|
|
printf(" cmd:%2X=(%2X) ",(int)ts_task_lora.p->dcmd,(int)ts_task_lora.p->buf[0] );
|
|
switch (ts_task_lora.p->dcmd)
|
|
{////68 00 07 02 02 0B 16
|
|
///buf 0 1 2
|
|
case D_lora_cmd_ACK:
|
|
printf(" %s ", ts_ucinfo_lora[ts_task_lora.p->buf[0] ].pstr);
|
|
ts_task_lora.ok = ts_ucinfo_lora[ts_task_lora.p->buf[0] ].n;
|
|
break;
|
|
case D_lora_cmd_net_ack:
|
|
printf(" %s ", ts_ucinfo_inet[ts_task_lora.p->buf[0] ].pstr);
|
|
ts_task_lora.ok = ts_ucinfo_inet[ts_task_lora.p->buf[0] ].n;
|
|
break;
|
|
case D_lora_cmd_01_ack:///06
|
|
printf(" %s ", ts_ucinfo_sf[ts_task_lora.p->buf[0] ].pstr);
|
|
ts_task_lora.ok = ts_ucinfo_sf[ts_task_lora.p->buf[0] ].n;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
////通过debug串口 透传协议
|
|
u8 L3_tpc_lora(char *buf)
|
|
{////
|
|
u16 num=0;
|
|
u8 d = 0;
|
|
TS_Lora_lrd_ *p;
|
|
////debug协议使用串口1 故而再次简单解析 要求第一个字符必须为Fx
|
|
if(0x68 == buf[0])
|
|
{
|
|
p= (TS_Lora_lrd_ *)buf;
|
|
if(p->dcmd&0x80)
|
|
{
|
|
printf("\r\n user-->mod ");
|
|
}else
|
|
{
|
|
printf("\r\n user<<--mod ");
|
|
}
|
|
printf("D=%X ",(int)buf[5]);
|
|
printf(" len %d cmd %X REQ=%d(00=succes) ",p->len,(int)p->dcmd,(int)p->buf[0]);
|
|
L0_uartN_Arrayhex_withoutbuf(D_UART1,&buf[5], p->len-6-1);
|
|
///L0_uartN_Arrayhex_withoutbuf(D_UART1,&ts_Urecbuf.r2[5], p->len-6);////(U8 *)&pd,错误的表达方式 pd就是地址
|
|
////return 1;
|
|
}else
|
|
{
|
|
printf("\r\n cmd error!!");
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
///0x68 0x00 0x08 1 0 0 1 0 0 0 0 REQ DATA CS 0x16
|
|
/// 0 1 2 3 4 5 6 7
|
|
////////// 01 mac6
|
|
////68 00 07 91 01 99 16
|
|
////0 1 2 3 (4) 5 6
|
|
/// 0 1 2 3 ocr
|
|
|
|
///填报mac时 01 mac0 mac1 mac2 mac3 mac4 mac5
|
|
///填报dat时 addr d[0] d[1] d[2] d[3] d[4] d[5]........
|
|
|
|
void L2_lora_tianbao(char *buf,u16 len)///填报协议 把buf中的len长度 填入到 lora的结构体ts_lora_lrd中
|
|
{ //需要把buf长度传进来 blen 参数还需要buf
|
|
int i;
|
|
/// u8 t;
|
|
vU16 ocr = 0;
|
|
char *p;
|
|
p = (char*)&ts_lora_lrd;
|
|
ts_lora_lrd.head = 0x68;
|
|
ts_lora_lrd.tail= 0x16;
|
|
///ts_lora_lrd.len = ;
|
|
|
|
/// buf[0] = ts_lora_lrd.req;
|
|
|
|
///<<<<<<<<<<data
|
|
|
|
ocr = p[1];
|
|
ocr += p[2];
|
|
ocr += p[3];
|
|
|
|
for(i = 0;i < len;i ++)
|
|
{
|
|
ts_lora_lrd.buf[i] = buf[i];
|
|
ocr += ts_lora_lrd.buf[i];
|
|
}
|
|
ts_lora_lrd.cs = (ocr&0x00ff);//校验和:从长度到数据字段的校验码,使用累加和进行计算,即各字节相加求和取最低字节。
|
|
}
|
|
|
|
//// d0
|
|
////68 00 07 91 01 99 16
|
|
////0 1 2 3 (4) 5 6
|
|
void L2_lora_send(void)////把当前ts_lora_lrd的内容发送出去
|
|
{
|
|
|
|
printf("\r\n L2_lora_send ");
|
|
D_lora_wakeup();
|
|
L1_uart2_Array((char*)&ts_lora_lrd, 4);
|
|
L1_uart2_Array(ts_lora_lrd.buf, ts_lora_lrd.len-6);
|
|
L1_uart2_Array((char *)&ts_lora_lrd.cs, 2);
|
|
|
|
|
|
L1_uartD_uchexArray((char*)&ts_lora_lrd, 4);
|
|
L1_uartD_uchexArray(ts_lora_lrd.buf, ts_lora_lrd.len-6);
|
|
L1_uartD_uchexArray((char *)&ts_lora_lrd.cs, 2);
|
|
}
|
|
|
|
|
|
////1、用户数据:该字段内容会上报至集中器,例如传感器数据。
|
|
|
|
void L3_lora_set_band(u8 band)
|
|
{
|
|
ts_lora_lrd.dcmd = D_lora_cmd_config;
|
|
ts_lora_lrd.buf[0] = D_lora_REQ_query_BAND;
|
|
ts_lora_lrd.buf[1] = band;
|
|
ts_lora_lrd.len = 6+(1+1);
|
|
|
|
L2_lora_tianbao(ts_lora_lrd.buf,1+1);////把 填报
|
|
L2_lora_send();
|
|
}
|
|
|
|
void L3_lora_set_netid(u8 netid)
|
|
{
|
|
ts_lora_lrd.dcmd = D_lora_cmd_config;
|
|
ts_lora_lrd.buf[0] = D_lora_REQ_query_NetID;
|
|
ts_lora_lrd.buf[1] = netid;
|
|
ts_lora_lrd.len = 6+(1+1);
|
|
|
|
L2_lora_tianbao(ts_lora_lrd.buf,1+1);////把 填报
|
|
L2_lora_send();
|
|
}
|
|
void L3_lora_set_netin(void)
|
|
{
|
|
ts_lora_lrd.dcmd = D_lora_cmd_net;
|
|
ts_lora_lrd.buf[0] = D_lora_cmd_net_ctrl;
|
|
ts_lora_lrd.len = 6+(1);
|
|
|
|
L2_lora_tianbao(ts_lora_lrd.buf,1+0);////把 填报
|
|
L2_lora_send();
|
|
}
|
|
|
|
|
|
void L3_lora_set_mac(u8 *mac)
|
|
{
|
|
ts_lora_lrd.dcmd = D_lora_cmd_config;
|
|
ts_lora_lrd.buf[0] = D_lora_REQ_query_MAC;
|
|
ts_lora_lrd.len = 6+(1+6);
|
|
Lc_buf_copy_uc((char*)&ts_lora_lrd.buf[1],mac,6);
|
|
L2_lora_tianbao(ts_lora_lrd.buf,1+6);////把 填报
|
|
L2_lora_send();
|
|
}
|
|
|
|
|
|
///d2 68 00 27 85 0A 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
|
|
/// 0 1
|
|
////21 22 23 24 25 26 27 28 29 30 31 32 B0 16
|
|
|
|
///L3_lora_set_d();
|
|
///ts_lora_lrd32
|
|
///使用前 先把32fifo数据放入到 buf[1] buf[32]中 buf[0]放置当前时间戳
|
|
////ts_max30102.send[i]
|
|
////L3_lora_set_d32(ts_max30102.send);
|
|
|
|
void L3_lora_set_d32(u8 *d)
|
|
{
|
|
Lc_buf_copy_uc((char*)&ts_lora_lrd32.buf[1],d,32);
|
|
|
|
ts_lora_lrd32.len = 0x0027;////39 = 32+1+6
|
|
///校验和:从长度到数据字段的校验码,使用累加和进行计算,即各字节相加求和取最低字节。
|
|
ts_lora_lrd32.cs = Lc_ocr8((char*)&ts_lora_lrd32.len,3+D_Lora_lrd_max);
|
|
ts_lora_lrd32.tail = 0x16;
|
|
|
|
D_lora_wakeup();
|
|
L1_uart2_Array((char*)&ts_lora_lrd32,ts_lora_lrd32.len);
|
|
|
|
L1_uartD_uchexArray((char*)&ts_lora_lrd32,ts_lora_lrd32.len);
|
|
}
|
|
void L3_lora_set_d8(u8 *d,u8 len)
|
|
{
|
|
ts_lora_lrd32.len = 14;////39 = 8+0+6
|
|
|
|
|
|
Lc_buf_copy_uc((char*)&ts_lora_lrd32.buf[0],d,len);
|
|
///校验和:从长度到数据字段的校验码,使用累加和进行计算,即各字节相加求和取最低字节。
|
|
ts_lora_lrd32.cs = Lc_ocr8((char*)&ts_lora_lrd32.len,3+len);
|
|
ts_lora_lrd32.buf[len] = ts_lora_lrd32.cs;
|
|
ts_lora_lrd32.buf[len+1] = 0x16;
|
|
|
|
|
|
D_lora_wakeup();
|
|
L1_uart2_Array((char*)&ts_lora_lrd32,ts_lora_lrd32.len);
|
|
|
|
L1_uartD_uchexArray((char*)&ts_lora_lrd32,ts_lora_lrd32.len);
|
|
}
|
|
|
|
void L3_lora_set_d10(u8 *d,u8 len)
|
|
{
|
|
ts_lora_lrd32.len = 14+2;////39 = 8+0+6
|
|
|
|
|
|
Lc_buf_copy_uc((char*)&ts_lora_lrd32.buf[0],d,len);
|
|
///校验和:从长度到数据字段的校验码,使用累加和进行计算,即各字节相加求和取最低字节。
|
|
ts_lora_lrd32.cs = Lc_ocr8((char*)&ts_lora_lrd32.len,3+len);
|
|
ts_lora_lrd32.buf[len] = ts_lora_lrd32.cs;
|
|
ts_lora_lrd32.buf[len+1] = 0x16;
|
|
|
|
|
|
D_lora_wakeup();
|
|
L1_uart2_Array((char*)&ts_lora_lrd32,ts_lora_lrd32.len);
|
|
|
|
L1_uartD_uchexArray((char*)&ts_lora_lrd32,ts_lora_lrd32.len);
|
|
}
|
|
|
|
|
|
u8 L3_tpc_FEdebug(void)
|
|
{
|
|
printf("\r\n read ts_para (%d) = ",(int)sizeof(ts_para));
|
|
L0_Iap_Read_array(D_eeprom_para,(char*)&ts_para,sizeof(ts_para));
|
|
L1_uartD_uchexArray((char*)&ts_para, sizeof(ts_para));
|
|
|
|
if(ts_Urec[D_UART1].sp[1] == 0x10)
|
|
{///FE 11 r1 r2 r3 r4 r5 r6 读取ts_para
|
|
return 1;
|
|
}
|
|
else if(ts_Urec[D_UART1].sp[1] == 0x11)
|
|
{///FE 10 r1 r2 r3 r4 r5 r6 写入mac r1 r2 r3 r4 r5 r6
|
|
printf("\r\n write mac = ");
|
|
|
|
Lc_buf_copy_uc(ts_para.mac,&ts_Urec[D_UART1].sp[2],6);
|
|
L1_uartD_uchexArray((char*)&ts_para,sizeof(ts_para));
|
|
|
|
L0_Iap_Program_array(D_eeprom_para,(char*)&ts_para,sizeof(ts_para));
|
|
}else if(ts_Urec[D_UART1].sp[1] == 0x12)
|
|
{///FE 12 AB r2 r3 r4 r5 r6 设置netid
|
|
printf("\r\n write netid = ");
|
|
ts_para.netid = ts_Urec[D_UART1].sp[2];
|
|
L0_Iap_Program_array(D_eeprom_para,(char*)&ts_para,sizeof(ts_para));
|
|
}else if(ts_Urec[D_UART1].sp[1] == 0x13)
|
|
{///FE 12 AB r2 r3 r4 r5 r6 设置bank
|
|
printf("\r\n write bank = ");
|
|
|
|
ts_para.band = ts_Urec[D_UART1].sp[2];
|
|
L0_Iap_Program_array(D_eeprom_para,(char*)&ts_para,sizeof(ts_para));
|
|
}else
|
|
{
|
|
|
|
}
|
|
printf("\r\n read ts_para2 (%d) = ",(int)sizeof(ts_para));
|
|
L0_Iap_Read_array(D_eeprom_para,(char*)&ts_para,sizeof(ts_para));
|
|
L1_uartD_uchexArray((char*)&ts_para, sizeof(ts_para));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#if 0///001
|
|
|
|
|
|
|
|
///68 00 0d 90 01 32 33 34 35
|
|
//// 68 00 0D 90 01 61 61 62 62 63 64 EB 16
|
|
u8 Lora_cmd_mac[]={
|
|
0x68 ,0x00 ,0x0D ,0x90 ,0x01 ,0x61 ,0x61 ,0x62 ,0x62 ,0x63 ,0x64 ,0xEB ,0x16
|
|
//1 2 3 4 5 6 7 8 9 10 11 12 13 配置节点MAC地址是61 61 62 62 63 63
|
|
// 1 2 3 4 5 6
|
|
//0 1 2 3 4 5 6 7 8 9 10 11 12
|
|
|
|
// 0x68 ,0x00 ,0x0D ,0x90 ,0x01 ,0x61 ,0x61 ,0x62 ,0x62 ,0x63 ,0x72 ,0xF3 ,0x16
|
|
// 0x68 ,0x00 ,0x0D ,0x90 ,0x01 ,0x61 ,0x61 ,0x62 ,0x62 ,0x63 ,0x71 ,0xF2 ,0x16
|
|
// 0x68 ,0x00 ,0x0D ,0x90 ,0x01 ,0x61 ,0x61 ,0x62 ,0x62 ,0x63 ,0x70 ,0xF1 ,0x16
|
|
// 0x68 ,0x00 ,0x0D ,0x90 ,0x01 ,0x61 ,0x61 ,0x62 ,0x62 ,0x63 ,0x69 ,0xF0 ,0x16
|
|
// 0x68 ,0x00 ,0x0D ,0x90 ,0x01 ,0x61 ,0x61 ,0x62 ,0x62 ,0x63 ,0x68 ,0xEF ,0x16
|
|
// 0x68 ,0x00 ,0x0D ,0x90 ,0x01 ,0x61 ,0x61 ,0x62 ,0x62 ,0x63 ,0x67 ,0xEE ,0x16
|
|
// 0x68 ,0x00 ,0x0D ,0x90 ,0x01 ,0x61 ,0x61 ,0x62 ,0x62 ,0x63 ,0x66 ,0xED ,0x16
|
|
// 0x68 ,0x00 ,0x0D ,0x90 ,0x01 ,0x61 ,0x61 ,0x62 ,0x62 ,0x63 ,0x65 ,0xEC ,0x16
|
|
// 0x68 ,0x00 ,0x0D ,0x90 ,0x01 ,0x61 ,0x61 ,0x62 ,0x62 ,0x63 ,0x64 ,0xEB ,0x16
|
|
// 0x68 ,0x00 ,0x0D ,0x90 ,0x01 ,0x61 ,0x61 ,0x62 ,0x62 ,0x63 ,0x63 ,0xEA ,0x16
|
|
};
|
|
|
|
//68 00 07 91 01 99 16
|
|
u8 Lora_cmd_mac_que[]={
|
|
0x68 ,0x00 ,0x07 ,0x91 ,0x01 ,0x99 ,0x16
|
|
//1 2 3 4 5 6 7 8 9 10 11 12 13 查询MAC地址指令
|
|
|
|
//0 1 2 3 4 5 6 7 8 9 10 11 12
|
|
|
|
};
|
|
|
|
///
|
|
u8 Lora_cmd_netid_AB[]={
|
|
0x68 ,0x00 ,0x08 ,0x90 ,0x02 ,0xAB ,0x45 ,0x16
|
|
//1 2 3 4 5 6 7 8 9 10 11 12 13 配置NetID=AB
|
|
|
|
//0 1 2 3 4 5 6 7 8 9 10 11 12
|
|
|
|
};
|
|
|
|
////68 00 07 91 02 9A 16
|
|
u8 test5[]={
|
|
0x68 ,0x00 ,0x07 ,0x91 ,0x02 ,0x9A ,0X16
|
|
//1 2 3 4 5 6 7 8 9 10 11 12 13 查询到NetID=AB
|
|
|
|
//0 1 2 3 4 5 6 7 8 9 10 11 12
|
|
|
|
};
|
|
u8 Lora_cmd_band[]={
|
|
0x68 ,0x00 ,0x08 ,0x90 ,0x03 ,0x09 ,0xA4 ,0x16
|
|
//1 2 3 4 5 6 7 8 9 10 11 12 13 配置band=09
|
|
|
|
//0 1 2 3 4 5 6 7 8 9 10 11 12
|
|
|
|
};
|
|
u8 test7[]={
|
|
0x68 ,0x00 ,0x07 ,0x91 ,0x03 ,0x9B ,0x16
|
|
//1 2 3 4 5 6 7 8 9 10 11 12 13 查询到band=09
|
|
|
|
//0 1 2 3 4 5 6 7 8 9 10 11 12
|
|
|
|
};
|
|
|
|
/// 68 00 07 81 01 89 16 ///节点主动入网(band、NetID默认暂不保存,
|
|
u8 Lora_cmd_innet[]={
|
|
0x68 ,0x00 ,0x07 ,0x81 ,0x01 ,0x89 ,0x16
|
|
//1 2 3 4 5 6 7 8 9 10 11 12 13 节点主动入网(band、NetID默认暂不保存,MAC地址默认保存)
|
|
|
|
//0 1 2 3 4 5 6 7 8 9 10 11 12
|
|
|
|
};
|
|
|
|
/****
|
|
void L3_lora_ONdebug(u8 filter)
|
|
{
|
|
|
|
|
|
if(filter == pd->filter)
|
|
{///filter num d1 d2 d3 ....dn
|
|
//// FD 08 11 22 33 44 55 66 77 88 Lc_delay_ms(1);
|
|
|
|
/// L1_uartD_uchexArray(TS_s2b_debug.sp,TS_debug_rec.R1);
|
|
|
|
printf("\r\n FD ok");
|
|
switch (pd->ocr)
|
|
{
|
|
case 0x11: //配置节点MAC地址是61 61 62 62 63 64
|
|
|
|
printf("11");
|
|
D_lora_wakeup(); L1_uart2_Array(Lora_cmd_mac, 13);
|
|
printf(" lora send ");
|
|
L1_uartD_uchexArray(Lora_cmd_mac, 13);
|
|
//1 2 3 4 5 6 7 8 9 10 11 12 13
|
|
break;
|
|
case 0x12: //查询MAC地址指令
|
|
|
|
printf("12");
|
|
D_lora_wakeup(); L1_uart2_Array(Lora_cmd_mac_que, 7);
|
|
printf(" lora send2 ");
|
|
L1_uartD_uchexArray(Lora_cmd_mac_que, 7);
|
|
//1 2 3 4 5 6 7 8 9 10 11 12 13
|
|
break;
|
|
case 0x14: //配置NetID=AB
|
|
|
|
printf("14");
|
|
D_lora_wakeup(); L1_uart2_Array(Lora_cmd_netid_AB, 8);
|
|
printf(" lora send4 ");
|
|
L1_uartD_uchexArray(Lora_cmd_netid_AB, 8);
|
|
//1 2 3 4 5 6 7 8 9 10 11 12 13
|
|
break;
|
|
case 0x15: //查询到NetID=AB
|
|
|
|
printf("15");
|
|
D_lora_wakeup(); L1_uart2_Array(test5, 7);
|
|
printf(" lora send5 ");
|
|
L1_uartD_uchexArray(test5, 7);
|
|
//1 2 3 4 5 6 7 8 9 10 11 12 13
|
|
break;
|
|
case 0x16: //配置band=09
|
|
|
|
printf("16");
|
|
D_lora_wakeup(); L1_uart2_Array(Lora_cmd_band, 8);
|
|
printf(" lora send6 ");
|
|
L1_uartD_uchexArray(Lora_cmd_band, 8);
|
|
//1 2 3 4 5 6 7 8 9 10 11 12 13
|
|
break;
|
|
case 0x17: //查询到band=09
|
|
|
|
printf("17");
|
|
D_lora_wakeup(); L1_uart2_Array(test7, 7);
|
|
printf(" lora send7 ");
|
|
L1_uartD_uchexArray(test7, 7);
|
|
//1 2 3 4 5 6 7 8 9 10 11 12 13
|
|
break;
|
|
case 0x18: //节点主动入网
|
|
|
|
printf("18");
|
|
D_lora_wakeup(); L1_uart2_Array(Lora_cmd_innet, 7);
|
|
printf(" lora send8 ");
|
|
L1_uartD_uchexArray(Lora_cmd_innet, 7);
|
|
//1 2 3 4 5 6 7 8 9 10 11 12 13
|
|
break;
|
|
|
|
default:
|
|
printf(" pp error\r\n ");
|
|
|
|
break;
|
|
};
|
|
|
|
printf("333");
|
|
}
|
|
}
|
|
|
|
***********/
|
|
|
|
/*
|
|
void LORA_send(void)
|
|
|
|
{
|
|
vU8 add;
|
|
ts_lrdlora_send.filter = 0x68;
|
|
//// ts_lrdlora_send.len = DATA_LORA_LEN;
|
|
ts_lrdlora_send.DIR = 1;
|
|
ts_lrdlora_send.CMD = 0x37; /// 取值范围:0x7F~0x00;
|
|
/// ts_lrdlora_send.req = 0x01;
|
|
ts_lrdlora_send.filtert = 0x16;
|
|
L0_uart1_0d0a();
|
|
///L1_uartD_sendArray(&TS_lrdlora_send.filter,1);
|
|
///L1_uartD_sendArray(&TS_lrdlora_send.len,2);
|
|
///L1_uartD_sendArray(&TS_lrdlora_send.order,1);
|
|
///L1_uartD_sendArray(&TS_lrdlora_send.REQ,1);
|
|
///L1_uartD_sendArray(&TS_lrdlora_send.buf,6);
|
|
/// add = Fun_SC_Check(&ts_lrdlora_send.buf,4);
|
|
L1_uartD_sendArray(&add,1);
|
|
ts_lrdlora_send.ocr = add;
|
|
//buf 确定长度 for(i = 0;i<len;i++)(len是buf长度)
|
|
//打包函数 把数据整合 重新定义一个结构体(输入参数)
|
|
L1_uartD_sendArray(&ts_lrdlora_send.buf,14);
|
|
L0_uart1_0d0a();
|
|
|
|
}
|
|
*/
|
|
|
|
void lora_param_init(void)
|
|
{
|
|
|
|
D_lora_wakeup();
|
|
L1_uart2_Array(Lora_cmd_mac, 13);
|
|
printf("\r\n lora Lora_cmd_mac ");
|
|
L1_uartD_uchexArray(Lora_cmd_mac, 13);
|
|
Lc_delay_ms(400);
|
|
|
|
D_lora_wakeup();
|
|
L1_uart2_Array(Lora_cmd_netid_AB, 8);
|
|
printf("\r\n lora Lora_cmd_netid_AB ");
|
|
L1_uartD_uchexArray(Lora_cmd_netid_AB, 8);
|
|
Lc_delay_ms(400);
|
|
|
|
D_lora_wakeup();
|
|
L1_uart2_Array(Lora_cmd_band, 8);
|
|
printf("\r\n lora Lora_cmd_band ");
|
|
L1_uartD_uchexArray(Lora_cmd_band, 8);
|
|
|
|
D_lora_wakeup();
|
|
L1_uart2_Array(Lora_cmd_innet, 7);
|
|
printf("\r\n lora Lora_cmd_innet ");
|
|
L1_uartD_uchexArray(Lora_cmd_innet, 7);
|
|
Lc_delay_ms(400);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif/// 001
|
|
|
|
|
|
|