added sending unconfirmed message for RHF76
1. added AT+ command "AT+MSGHEX" and change previous RHF76_ATCMD_FMT_SEND_MSGHEX to RHF76_ATCMD_FMT_SEND_CMSGHEX 2. implement send_unconfirmed with a non-breaking approach: added int (*send_unconfirmed)(const void *buf, size_t len); event handle in lora_module_st; added int tos_lora_module_send_unconfirmed(const void *buf, size_t len); in lora_module_wrapper.c; and implement static int rhf76_send_unconfirmed(const void *buf, size_t len) in RHF76.c 3. added { "+MSGHEX: PORT:", rhf76_incoming_data_process } in event array rhf76_at_event so that the device is able to process the downlink data when it is configurated to send unconfirmed message. 4. added AT+ command "AT+REPT", and implement the static int rhf76_set_repeat(uint8_t num) to enable user to set repeat times (1-15) while using "unconfirmed message" 5. updated the instructions of implemeting up-link parser and downlink parser on the server in the file "..\board\NUCLEO_STM32L073RZ\BSP\Src\lora_demo.c"
This commit is contained in:
@@ -154,6 +154,26 @@ static int rhf76_set_chanel(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int rhf76_set_repeat(uint8_t num)
|
||||
{
|
||||
int try = 0;
|
||||
at_echo_t echo;
|
||||
char cmd[14] = {0};
|
||||
char expect[10] = {'\0'};
|
||||
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_SET_REPT, num);
|
||||
snprintf(expect, sizeof(expect), "+REPT: %d", num);
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, expect);
|
||||
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 3000, cmd);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int rhf76_set_adr_off(void)
|
||||
{
|
||||
int try = 0;
|
||||
@@ -305,9 +325,14 @@ static int rhf76_init(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(rhf76_set_repeat(1)!=0){
|
||||
printf("rhf76 set repeat times for unconfirmed message FAILED\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
at_delay_ms(2000);
|
||||
printf("Init RHF76 LoRa done\n");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -377,6 +402,7 @@ __STATIC__ void rhf76_incoming_data_process(void)
|
||||
|
||||
at_event_t rhf76_at_event[] = {
|
||||
{ "+CMSGHEX: PORT:", rhf76_incoming_data_process },
|
||||
{ "+MSGHEX: PORT:", rhf76_incoming_data_process }
|
||||
};
|
||||
|
||||
static char __num2hex(uint8_t num)
|
||||
@@ -405,7 +431,6 @@ static void __hex2str(uint8_t *in, char *out, int len)
|
||||
|
||||
static int rhf76_send(const void *buf, size_t len)
|
||||
{
|
||||
|
||||
char *str_buf = NULL;
|
||||
|
||||
str_buf = tos_mmheap_calloc(2 * len + 1, sizeof(char));
|
||||
@@ -416,7 +441,7 @@ static int rhf76_send(const void *buf, size_t len)
|
||||
|
||||
char cmd[100] = {0};
|
||||
at_echo_t echo;
|
||||
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_FMT_SEND_MSGHEX, str_buf);
|
||||
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_FMT_SEND_CMSGHEX, str_buf);
|
||||
cmd[sizeof(cmd) - 1] = '\0';
|
||||
tos_mmheap_free(str_buf);
|
||||
tos_at_echo_create(&echo, NULL, 0, "+CMSG: ACK Received");
|
||||
@@ -427,18 +452,43 @@ static int rhf76_send(const void *buf, size_t len)
|
||||
return len;
|
||||
}
|
||||
|
||||
static int rhf76_send_unconfirmed(const void *buf, size_t len)
|
||||
{
|
||||
|
||||
char *str_buf = NULL;
|
||||
at_echo_t echo;
|
||||
|
||||
str_buf = tos_mmheap_calloc(2 * len + 1, sizeof(char));
|
||||
if (!str_buf) {
|
||||
return -1;
|
||||
}
|
||||
__hex2str((uint8_t *)buf, str_buf, len);
|
||||
|
||||
char cmd[100] = {0};
|
||||
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_FMT_SEND_MSGHEX, str_buf);
|
||||
cmd[sizeof(cmd) - 1] = '\0';
|
||||
tos_mmheap_free(str_buf);
|
||||
tos_at_echo_create(&echo, NULL, 0, "+MSGHEX: Done");
|
||||
tos_at_cmd_exec(&echo, 6000, cmd);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return -1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static int rhf76_close(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
lora_module_t lora_module_rhf76 = {
|
||||
.init = rhf76_init,
|
||||
.join_otaa = rhf76_join_otaa,
|
||||
.join_abp = rhf76_join_abp,
|
||||
.send = rhf76_send,
|
||||
.close = rhf76_close,
|
||||
.recv_callback = K_NULL,
|
||||
.init = rhf76_init,
|
||||
.join_otaa = rhf76_join_otaa,
|
||||
.join_abp = rhf76_join_abp,
|
||||
.send = rhf76_send,
|
||||
.send_unconfirmed = rhf76_send_unconfirmed,
|
||||
.close = rhf76_close,
|
||||
.recv_callback = K_NULL,
|
||||
};
|
||||
|
||||
int rhf76_lora_init(hal_uart_port_t uart_port)
|
||||
|
@@ -65,7 +65,10 @@ typedef enum lora_key_type {
|
||||
#define RHF76_ATCMD_FMT_SET_KEY_TYPE_APPKEY "AT+KEY=\"appkey\",%s\r\n"
|
||||
#define RHF76_ATCMD_FMT_SET_KEY_TYPE_APPSKEY "AT+KEY=\"appskey\",%s\r\n"
|
||||
#define RHF76_ATCMD_FMT_SET_KEY_TYPE_NWKSKEY "AT+KEY=\"nwkskey\",%s\r\n"
|
||||
#define RHF76_ATCMD_FMT_SEND_MSGHEX "AT+CMSGHEX=\"%s\"\r\n"
|
||||
#define RHF76_ATCMD_FMT_SEND_CMSGHEX "AT+CMSGHEX=\"%s\"\r\n"
|
||||
#define RHF76_ATCMD_FMT_SEND_MSGHEX "AT+MSGHEX=\"%s\"\r\n"
|
||||
|
||||
#define RHF76_ATCMD_SET_REPT "AT+REPT=%d\r\n"
|
||||
|
||||
#define RHF76_ATCMD_SET_BAND_CN470 "AT+DR=CN470\r\n"
|
||||
#define RHF76_ATCMD_REPLY_BAND_CN470 "+DR: CN470"
|
||||
|
Reference in New Issue
Block a user