added fuzzy matching feature to at_echo; added set some AT+ commands for RHF76; added support for LSM6DS3;
1. in tos_at.h, added int fuzzy_matching; field into at_echo_st struct, if this field is set to K_TRUE, then if echo message contains the string in "echo_expect" field. 2. added __API__ int tos_at_echo_fuzzy_matching_create(at_echo_t *echo, char *buffer, size_t buffer_size, char *echo_expect_contains) api to tos_at.c, which will create an at_echo_t with fuzzy_matching = K_TRUE; 3. added RHF76_ATCMD_SET_DELAY and rhf76_set_delay to RHF76.h to allow set/query RX delay config 4. added RHF76_ATCMD_SET_DATA_RATE and rhf76_set_data_rate to RHF76.h to allow set/query date rate config 5. added rhf76_at_cmd_exe for DEBUG purpose, so that user can execute any AT+ commands they want 6. added code in lora_demo.c to demonstrate package segmentation.
This commit is contained in:
@@ -154,7 +154,7 @@ static int rhf76_set_chanel(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int rhf76_set_repeat(uint8_t num)
|
||||
int rhf76_set_repeat(uint8_t num)
|
||||
{
|
||||
int try = 0;
|
||||
at_echo_t echo;
|
||||
@@ -174,6 +174,56 @@ static int rhf76_set_repeat(uint8_t num)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rhf76_set_data_rate(uint8_t num)
|
||||
{
|
||||
if(num>15) return -1; // num should between [0, 15]
|
||||
int try = 0;
|
||||
at_echo_t echo;
|
||||
char cmd[14] = {0};
|
||||
char expect[10] = {'\0'};
|
||||
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_SET_DATA_RATE, num);
|
||||
snprintf(expect, sizeof(expect), " DR%d", num);
|
||||
|
||||
tos_at_echo_fuzzy_matching_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;
|
||||
}
|
||||
|
||||
int rhf76_set_delay(char *param)
|
||||
{
|
||||
int try = 0;
|
||||
at_echo_t echo;
|
||||
char cmd[20] = {0};
|
||||
char expect[20] = {'\0'};
|
||||
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_SET_DELAY, param);
|
||||
snprintf(expect, sizeof(expect), "+DELAY %s", param);
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, expect);
|
||||
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 3000, cmd);
|
||||
if(strstr(param,"?")!=NULL) return 0;
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rhf76_at_cmd_exe(char *cmd)
|
||||
{
|
||||
at_echo_t echo;
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 8000, cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rhf76_set_adr_off(void)
|
||||
{
|
||||
int try = 0;
|
||||
@@ -329,10 +379,34 @@ static int rhf76_init(void)
|
||||
printf("rhf76 set repeat times for unconfirmed message FAILED\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
at_delay_ms(2000);
|
||||
printf("Init RHF76 LoRa done\n");
|
||||
|
||||
/*----------------------------------------------------*/
|
||||
/*--- the following code is only used for debuging ---*/
|
||||
/*----------------------------------------------------*/
|
||||
|
||||
/*<-- query/set UART Timeout (~TX timeout) -->*/
|
||||
// rhf76_at_cmd_exe("AT+UART=TIMEOUT, 300\r\n");
|
||||
// rhf76_at_cmd_exe("AT+UART=TIMEOUT\r\n");
|
||||
|
||||
/*<-- query current band config -->*/
|
||||
// rhf76_at_cmd_exe("AT+DR=SCHEME\r\n");
|
||||
// rhf76_at_cmd_exe("AT+LW=CDR\r\n");
|
||||
|
||||
/*<-- query current data rate and the corresponding max payload size -->*/
|
||||
rhf76_set_data_rate(0);
|
||||
// rhf76_at_cmd_exe("at+dr=0\r\n");
|
||||
// rhf76_at_cmd_exe("AT+DR\r\n");
|
||||
// rhf76_at_cmd_exe("AT+LW=LEN\r\n");
|
||||
|
||||
/*<-- query RX1\RX2\JRX1\JRX2 delay config -->*/
|
||||
// rhf76_set_delay("?");
|
||||
|
||||
/*<-- query RF config -->*/
|
||||
// rhf76_at_cmd_exe("AT+MODE=TEST\r\n");
|
||||
// rhf76_at_cmd_exe("AT+TEST=?\r\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -454,7 +528,6 @@ static int rhf76_send(const void *buf, size_t len)
|
||||
|
||||
static int rhf76_send_unconfirmed(const void *buf, size_t len)
|
||||
{
|
||||
|
||||
char *str_buf = NULL;
|
||||
at_echo_t echo;
|
||||
|
||||
|
@@ -69,9 +69,11 @@ typedef enum lora_key_type {
|
||||
#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_DELAY "AT+DELAY=%s\r\n"
|
||||
|
||||
#define RHF76_ATCMD_SET_BAND_CN470 "AT+DR=CN470\r\n"
|
||||
#define RHF76_ATCMD_REPLY_BAND_CN470 "+DR: CN470"
|
||||
#define RHF76_ATCMD_SET_DATA_RATE "AT+DR=%d\r\n"
|
||||
|
||||
#define RHF76_ATCMD_SET_CHANNEL "at+ch=num,80-87\r\n"
|
||||
#define RHF76_ATCMD_SET_ADR_OFF "at+adr=off\r\n"
|
||||
@@ -84,5 +86,66 @@ typedef enum lora_key_type {
|
||||
|
||||
int rhf76_lora_init(hal_uart_port_t uart_port);
|
||||
|
||||
/**
|
||||
* @brief set the delay for RX1,RX2,JRX1,JRX2 OR query current delay config
|
||||
* @note Examples:
|
||||
* to set the delay(ms):
|
||||
* rhf76_set_delay("RX1,2000");
|
||||
*
|
||||
* to query current delay config:
|
||||
* rhf76_set_delay("?");
|
||||
*
|
||||
* @param params operation string
|
||||
*
|
||||
* @retval int Status
|
||||
*/
|
||||
int rhf76_set_delay(char *param);
|
||||
|
||||
/**
|
||||
* @brief set repeat times when sending unconfirmed message
|
||||
* @note it is equal to sending
|
||||
* AT+REPT=2
|
||||
* +REPT: 2
|
||||
*
|
||||
* @param num repeat times
|
||||
*
|
||||
* @retval int Status
|
||||
*/
|
||||
int rhf76_set_repeat(uint8_t num);
|
||||
|
||||
|
||||
/**
|
||||
* @brief set date rate, which would affect the maximum payload size
|
||||
* @note this function is for DEBUG purpose only, it allows user to execute
|
||||
* AT+ commands by passing the AT+ command to the function as an arg-
|
||||
* ument.
|
||||
* For example,users can query the RF configuration by following code:
|
||||
*
|
||||
* rhf76_at_cmd_exe("AT+MODE=TEST\r\n");
|
||||
* rhf76_at_cmd_exe("AT+TEST=?\r\n");
|
||||
*
|
||||
* @param num data rate
|
||||
*
|
||||
* @retval int Status
|
||||
*/
|
||||
int rhf76_set_data_rate(uint8_t num);
|
||||
|
||||
|
||||
/**
|
||||
* @brief execute AT+ commands
|
||||
* @note this function is for DEBUG purpose only, it allows user to execute
|
||||
* AT+ commands by passing the AT+ command to the function as an arg-
|
||||
* ument.
|
||||
* For example,users can query the RF configuration by following code:
|
||||
*
|
||||
* rhf76_at_cmd_exe("AT+MODE=TEST\r\n");
|
||||
* rhf76_at_cmd_exe("AT+TEST=?\r\n");
|
||||
*
|
||||
* @param cmd AT+ commands
|
||||
*
|
||||
* @retval int Status
|
||||
*/
|
||||
int rhf76_at_cmd_exe(char *cmd);
|
||||
|
||||
#endif /* __RHF76_H__ */
|
||||
|
||||
|
Reference in New Issue
Block a user