forked from xuos/xiuos
fix lora function bug in webserver
This commit is contained in:
parent
cc7109af18
commit
348d53df91
|
@ -78,17 +78,27 @@ static int wb_event;
|
||||||
static unsigned int status = 0;
|
static unsigned int status = 0;
|
||||||
static pthread_t wb_event_task;
|
static pthread_t wb_event_task;
|
||||||
|
|
||||||
|
enum ModulesType
|
||||||
|
{
|
||||||
|
MODULES_NULL = 0, // null
|
||||||
|
MODULES_4G, // support 4G modules
|
||||||
|
MODULES_LORA, // support LoRa modules
|
||||||
|
MODULES_ALL, //all
|
||||||
|
};
|
||||||
|
|
||||||
/*define device info*/
|
/*define device info*/
|
||||||
#ifdef APPLICATION_WEBSERVER_XISHUTONG_4G
|
#ifdef APPLICATION_WEBSERVER_XISHUTONG_4G
|
||||||
static const char* device_name = "矽数通4G";
|
static const char* device_name = "矽数通4G";
|
||||||
static const char* device_type = "xishutong-arm32";
|
static const char* device_type = "xishutong-arm32";
|
||||||
static const char* device_serial_num = "123456789";
|
static const char* device_serial_num = "123456789";
|
||||||
|
static int support_module = MODULES_NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef APPLICATION_WEBSERVER_XISHUTONG
|
#ifdef APPLICATION_WEBSERVER_XISHUTONG
|
||||||
static const char* device_name = "矽数通";
|
static const char* device_name = "矽数通";
|
||||||
static const char* device_type = "xishutong-arm32";
|
static const char* device_type = "xishutong-arm32";
|
||||||
static const char* device_serial_num = "123456789";
|
static const char* device_serial_num = "123456789";
|
||||||
|
static int support_module = MODULES_LORA;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*define webserver info*/
|
/*define webserver info*/
|
||||||
|
@ -107,6 +117,7 @@ int rs485_uart_fd = -1;
|
||||||
|
|
||||||
#define RS485_DEVICE_PATH "/dev/usart4_dev4"
|
#define RS485_DEVICE_PATH "/dev/usart4_dev4"
|
||||||
|
|
||||||
|
#ifdef APPLICATION_WEBSERVER_XISHUTONG_4G
|
||||||
/*define net 4G info*/
|
/*define net 4G info*/
|
||||||
static struct net_4g_info {
|
static struct net_4g_info {
|
||||||
char map_ip[20];
|
char map_ip[20];
|
||||||
|
@ -125,6 +136,7 @@ static struct net_4g_mqtt_info {
|
||||||
int client_id;
|
int client_id;
|
||||||
int connect_status;
|
int connect_status;
|
||||||
} net_4g_mqtt_info;
|
} net_4g_mqtt_info;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*define net LoRa info*/
|
/*define net LoRa info*/
|
||||||
struct net_lora_info
|
struct net_lora_info
|
||||||
|
@ -162,6 +174,31 @@ static uint16_t tcp_socket_port = 8888;
|
||||||
static char *plc_json;
|
static char *plc_json;
|
||||||
#define JSON_FILE_NAME "test_recipe.json"
|
#define JSON_FILE_NAME "test_recipe.json"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Function implementation - judge using 4G modules or LoRa modules
|
||||||
|
******************************************************************************/
|
||||||
|
static int JudgeModulesType(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
int retry = 5;
|
||||||
|
|
||||||
|
#ifdef APPLICATION_WEBSERVER_XISHUTONG_4G
|
||||||
|
extern int TestLoraRadio(int argc, char *argv[]);
|
||||||
|
char* check_params[2] = {"TestLoraRadio", "check"};
|
||||||
|
do {
|
||||||
|
ret = TestLoraRadio(2, check_params);
|
||||||
|
if (ret > 0) {
|
||||||
|
retry = 0;
|
||||||
|
support_module = MODULES_LORA;
|
||||||
|
} else {
|
||||||
|
retry--;
|
||||||
|
}
|
||||||
|
} while (retry > 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return support_module;
|
||||||
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Function implementation - define interface info
|
* Function implementation - define interface info
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
@ -288,24 +325,19 @@ static void NetMqttDisconnect(void)
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
static void NetLoraConnect(void)
|
static void NetLoraConnect(void)
|
||||||
{
|
{
|
||||||
char* init_params[2] = {"TestLoraRadio", "probe"};
|
char* tx_params[5] = {"TestLoraRadio", "tx", "1", "2000", "2"};
|
||||||
char* tx_params[4] = {"TestLoraRadio", "tx", "1", "2000"};
|
|
||||||
extern int TestLoraRadio(int argc, char *argv[]);
|
extern int TestLoraRadio(int argc, char *argv[]);
|
||||||
|
|
||||||
if (0 == net_lora_info.lora_init_flag) {
|
if (0 == net_lora_info.lora_init_flag) {
|
||||||
TestLoraRadio(2, init_params);
|
|
||||||
net_lora_info.lora_init_flag = 1;
|
net_lora_info.lora_init_flag = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
TestLoraRadio(4, tx_params);
|
TestLoraRadio(5, tx_params);
|
||||||
net_lora_info.connect_status = 1;
|
net_lora_info.connect_status = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void NetLoraDisconnect(void)
|
static void NetLoraDisconnect(void)
|
||||||
{
|
{
|
||||||
char* disconnect_params[2] = {"TestLoraRadio", "txdone"};
|
|
||||||
extern int TestLoraRadio(int argc, char *argv[]);
|
|
||||||
TestLoraRadio(2, disconnect_params);
|
|
||||||
net_lora_info.connect_status = 0;
|
net_lora_info.connect_status = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,8 +526,14 @@ static void fn(struct mg_connection* c, int ev, void* ev_data, void* fn_data)
|
||||||
{
|
{
|
||||||
if (ev == MG_EV_HTTP_MSG) {
|
if (ev == MG_EV_HTTP_MSG) {
|
||||||
struct mg_http_message *hm = (struct mg_http_message*)ev_data, tmp = { 0 };
|
struct mg_http_message *hm = (struct mg_http_message*)ev_data, tmp = { 0 };
|
||||||
|
/*define modules info*/
|
||||||
|
if (mg_http_match_uri(hm, "/net/getModulesInfo")) {
|
||||||
|
mg_http_reply(c, 200, "Content-Type: application/json\r\n",
|
||||||
|
"{%m:%d}\n",
|
||||||
|
MG_ESC("modulesStatus"), JudgeModulesType());
|
||||||
|
}
|
||||||
/*define device info*/
|
/*define device info*/
|
||||||
if (mg_http_match_uri(hm, "/getSystemInfo")) {
|
else if (mg_http_match_uri(hm, "/getSystemInfo")) {
|
||||||
mg_http_reply(c, 200, "Content-Type: application/json\r\n",
|
mg_http_reply(c, 200, "Content-Type: application/json\r\n",
|
||||||
"{%m:%m, %m:%m, %m:%m, %m:%m, %m:%m, %m:%m}\n",
|
"{%m:%m, %m:%m, %m:%m, %m:%m, %m:%m, %m:%m}\n",
|
||||||
MG_ESC("deviceName"), MG_ESC(device_name),
|
MG_ESC("deviceName"), MG_ESC(device_name),
|
||||||
|
|
|
@ -479,6 +479,7 @@ uint8_t RadioRxPayload[255];
|
||||||
|
|
||||||
bool IrqFired = false;
|
bool IrqFired = false;
|
||||||
static bool lora_radio_init = false;
|
static bool lora_radio_init = false;
|
||||||
|
static bool lora_spi_init = false;
|
||||||
/*
|
/*
|
||||||
* SX126x DIO IRQ callback functions prototype
|
* SX126x DIO IRQ callback functions prototype
|
||||||
*/
|
*/
|
||||||
|
@ -552,6 +553,16 @@ static TimerEvent_t RxTimeoutTimer;
|
||||||
uint8_t RadioCheck(void)
|
uint8_t RadioCheck(void)
|
||||||
{
|
{
|
||||||
uint8_t test = 0;
|
uint8_t test = 0;
|
||||||
|
|
||||||
|
if( lora_spi_init == false ) {
|
||||||
|
int ret = lora_radio_spi_init();
|
||||||
|
if (ret < 0) {
|
||||||
|
LORA_RADIO_DEBUG_LOG(LR_DBG_INTERFACE, LOG_LEVEL, "SX126x SPI Init Failed\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
lora_spi_init = true;
|
||||||
|
LORA_RADIO_DEBUG_LOG(LR_DBG_INTERFACE, LOG_LEVEL, "SX126x SPI Init Succeed\n");
|
||||||
|
}
|
||||||
|
|
||||||
LORA_RADIO_DEBUG_LOG(LR_DBG_INTERFACE, LOG_LEVEL, "Packet Type is %s\n",( SX126x.PacketParams.PacketType == PACKET_TYPE_LORA )? "LoRa":"FSK");
|
LORA_RADIO_DEBUG_LOG(LR_DBG_INTERFACE, LOG_LEVEL, "Packet Type is %s\n",( SX126x.PacketParams.PacketType == PACKET_TYPE_LORA )? "LoRa":"FSK");
|
||||||
|
|
||||||
|
@ -668,13 +679,13 @@ bool RadioInit( RadioEvents_t *events )
|
||||||
lora_radio_init = true;
|
lora_radio_init = true;
|
||||||
}
|
}
|
||||||
#elif defined LORA_RADIO_DRIVER_USING_RTOS_XIUOS
|
#elif defined LORA_RADIO_DRIVER_USING_RTOS_XIUOS
|
||||||
if( lora_radio_init == false ) {
|
if( lora_spi_init == false ) {
|
||||||
int ret = lora_radio_spi_init();
|
int ret = lora_radio_spi_init();
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
LORA_RADIO_DEBUG_LOG(LR_DBG_INTERFACE, LOG_LEVEL, "SX126x SPI Init Failed\n");
|
LORA_RADIO_DEBUG_LOG(LR_DBG_INTERFACE, LOG_LEVEL, "SX126x SPI Init Failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
lora_spi_init = true;
|
||||||
LORA_RADIO_DEBUG_LOG(LR_DBG_INTERFACE, LOG_LEVEL, "SX126x SPI Init Succeed\n");
|
LORA_RADIO_DEBUG_LOG(LR_DBG_INTERFACE, LOG_LEVEL, "SX126x SPI Init Succeed\n");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -88,7 +88,7 @@ void SX126xProcessIrqs( void );
|
||||||
|
|
||||||
void SX126xInit( DioIrqHandler dioIrq )
|
void SX126xInit( DioIrqHandler dioIrq )
|
||||||
{
|
{
|
||||||
SX126xReset( );
|
// SX126xReset( );
|
||||||
|
|
||||||
SX126xIoIrqInit( dioIrq );
|
SX126xIoIrqInit( dioIrq );
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,10 @@ if LORA_RADIO_DRIVER_USING_XISHUTONG_ARM32
|
||||||
string "lora device pin driver path"
|
string "lora device pin driver path"
|
||||||
default "/dev/spi2_dev0"
|
default "/dev/spi2_dev0"
|
||||||
|
|
||||||
|
config LORA_RADIO_BUSY_PIN
|
||||||
|
int "xishutong-arm32 board lora chip busy pin[PC12]"
|
||||||
|
default "141"
|
||||||
|
|
||||||
config LORA_RADIO_RESET_PIN
|
config LORA_RADIO_RESET_PIN
|
||||||
int "xishutong-arm32 board lora chip reset pin[PD02]"
|
int "xishutong-arm32 board lora chip reset pin[PD02]"
|
||||||
default "144"
|
default "144"
|
||||||
|
|
|
@ -191,18 +191,20 @@ void SX126xIoInit( void )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef LORA_RADIO_DRIVER_USING_EDU_ARM32
|
|
||||||
struct PinParam pin_param;
|
struct PinParam pin_param;
|
||||||
|
struct PinStat pin_stat;
|
||||||
|
struct PrivIoctlCfg ioctl_cfg;
|
||||||
|
|
||||||
|
#ifdef LORA_RADIO_DRIVER_USING_EDU_ARM32
|
||||||
pin_param.cmd = GPIO_CONFIG_MODE;
|
pin_param.cmd = GPIO_CONFIG_MODE;
|
||||||
pin_param.mode = GPIO_CFG_OUTPUT;
|
pin_param.mode = GPIO_CFG_OUTPUT;
|
||||||
pin_param.pin = LORA_RADIO_RFSW1_PIN;
|
pin_param.pin = LORA_RADIO_RFSW1_PIN;
|
||||||
|
|
||||||
struct PrivIoctlCfg ioctl_cfg;
|
|
||||||
ioctl_cfg.ioctl_driver_type = PIN_TYPE;
|
ioctl_cfg.ioctl_driver_type = PIN_TYPE;
|
||||||
ioctl_cfg.args = &pin_param;
|
ioctl_cfg.args = &pin_param;
|
||||||
PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg);
|
PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg);
|
||||||
|
|
||||||
struct PinStat pin_stat;
|
|
||||||
pin_stat.pin = LORA_RADIO_RFSW1_PIN;
|
pin_stat.pin = LORA_RADIO_RFSW1_PIN;
|
||||||
pin_stat.val = GPIO_LOW;
|
pin_stat.val = GPIO_LOW;
|
||||||
PrivWrite(pin_fd, &pin_stat, 1);
|
PrivWrite(pin_fd, &pin_stat, 1);
|
||||||
|
@ -218,6 +220,7 @@ void SX126xIoInit( void )
|
||||||
pin_stat.pin = LORA_RADIO_RFSW2_PIN;
|
pin_stat.pin = LORA_RADIO_RFSW2_PIN;
|
||||||
pin_stat.val = GPIO_LOW;
|
pin_stat.val = GPIO_LOW;
|
||||||
PrivWrite(pin_fd, &pin_stat, 1);
|
PrivWrite(pin_fd, &pin_stat, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
pin_param.cmd = GPIO_CONFIG_MODE;
|
pin_param.cmd = GPIO_CONFIG_MODE;
|
||||||
pin_param.mode = GPIO_CFG_INPUT;
|
pin_param.mode = GPIO_CFG_INPUT;
|
||||||
|
@ -230,7 +233,6 @@ void SX126xIoInit( void )
|
||||||
pin_stat.pin = LORA_RADIO_BUSY_PIN;
|
pin_stat.pin = LORA_RADIO_BUSY_PIN;
|
||||||
pin_stat.val = GPIO_LOW;
|
pin_stat.val = GPIO_LOW;
|
||||||
PrivWrite(pin_fd, &pin_stat, 1);
|
PrivWrite(pin_fd, &pin_stat, 1);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SX126xIoIrqInit( DioIrqHandler dioIrq )
|
void SX126xIoIrqInit( DioIrqHandler dioIrq )
|
||||||
|
|
|
@ -131,6 +131,10 @@ Modification:
|
||||||
#define LORA_RADIO_RESET_PIN 144//PD02 on xishutong-arm32
|
#define LORA_RADIO_RESET_PIN 144//PD02 on xishutong-arm32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef LORA_RADIO_BUSY_PIN
|
||||||
|
#define LORA_RADIO_BUSY_PIN 141//PC12 on xishutong-arm32
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef LORA_SPI_DEV_NAME
|
#ifndef LORA_SPI_DEV_NAME
|
||||||
#define LORA_SPI_DEV_NAME "/dev/spi2_dev0"
|
#define LORA_SPI_DEV_NAME "/dev/spi2_dev0"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -92,7 +92,7 @@ static uint8_t lora_chip_initialized;
|
||||||
static bool master_flag = true;
|
static bool master_flag = true;
|
||||||
static bool rx_only_flag = false;
|
static bool rx_only_flag = false;
|
||||||
static bool tx_only_flag = false;
|
static bool tx_only_flag = false;
|
||||||
static bool tx_continues = false;
|
static int tx_continues = false;
|
||||||
|
|
||||||
static lora_radio_test_t lora_radio_test_paras =
|
static lora_radio_test_t lora_radio_test_paras =
|
||||||
{
|
{
|
||||||
|
@ -1119,7 +1119,7 @@ static void *lora_radio_test_thread_entry(void *parameter)
|
||||||
TX_LED_TOGGLE;
|
TX_LED_TOGGLE;
|
||||||
if (tx_only_flag == false) {
|
if (tx_only_flag == false) {
|
||||||
radio_rx();
|
radio_rx();
|
||||||
} else if (tx_continues) {
|
} else if (tx_seq_cnt < tx_continues) {
|
||||||
PrivTaskDelay(1000);
|
PrivTaskDelay(1000);
|
||||||
PrivEvenTrigger(radio_event, EV_RADIO_TX_START);
|
PrivEvenTrigger(radio_event, EV_RADIO_TX_START);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1142,7 +1142,10 @@ static void *lora_radio_test_thread_entry(void *parameter)
|
||||||
LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON_DISABLE,
|
LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON_DISABLE,
|
||||||
true, 0, 0, lora_radio_test_paras.iq_inversion, tx_timeout );
|
true, 0, 0, lora_radio_test_paras.iq_inversion, tx_timeout );
|
||||||
|
|
||||||
send_ping_packet(master_address,slaver_address,payload_len);
|
|
||||||
|
if (tx_seq_cnt < tx_continues) {
|
||||||
|
send_ping_packet(master_address,slaver_address,payload_len);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* tx_seq_cnt start from 0 */
|
/* tx_seq_cnt start from 0 */
|
||||||
if( tx_seq_cnt < max_tx_nbtrials ) {
|
if( tx_seq_cnt < max_tx_nbtrials ) {
|
||||||
|
@ -1226,6 +1229,18 @@ int TestLoraRadio(int argc, char *argv[])
|
||||||
LORA_RADIO_DEBUG_LOG(LR_DBG_SHELL, LOG_LVL_INFO, "\n");
|
LORA_RADIO_DEBUG_LOG(LR_DBG_SHELL, LOG_LVL_INFO, "\n");
|
||||||
} else {
|
} else {
|
||||||
const char *cmd0 = argv[1];
|
const char *cmd0 = argv[1];
|
||||||
|
|
||||||
|
if (!strcmp(cmd0, "check")) {
|
||||||
|
LORA_RADIO_DEBUG_LOG(LR_DBG_SHELL, LOG_LVL_INFO, "LoRa Modules start to check using SPI");
|
||||||
|
|
||||||
|
if( Radio.Check() ) {
|
||||||
|
LORA_RADIO_DEBUG_LOG(LR_DBG_SHELL, LOG_LVL_INFO, "LoRa Modules check ok!");
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
LORA_RADIO_DEBUG_LOG(LR_DBG_SHELL, LOG_LVL_INFO, "LoRa Modules check failed!\n!");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( lora_radio_tester_init() == false ) {
|
if( lora_radio_tester_init() == false ) {
|
||||||
LORA_RADIO_DEBUG_LOG(LR_DBG_SHELL, LOG_LVL_INFO, "LoRa Chip Init Failed");
|
LORA_RADIO_DEBUG_LOG(LR_DBG_SHELL, LOG_LVL_INFO, "LoRa Chip Init Failed");
|
||||||
|
@ -1304,10 +1319,10 @@ int TestLoraRadio(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
PrivEvenTrigger(radio_event, EV_RADIO_INIT);
|
PrivEvenTrigger(radio_event, EV_RADIO_INIT);
|
||||||
} else if(!strcmp(cmd0, "tx")) {
|
} else if(!strcmp(cmd0, "tx")) {
|
||||||
/* eg: lora tx 1 0 */
|
/* eg: lora tx 1 0 1 */
|
||||||
master_flag = true;
|
master_flag = true;
|
||||||
tx_only_flag = true;
|
tx_only_flag = true;
|
||||||
tx_continues = true;
|
tx_continues = 4;
|
||||||
|
|
||||||
if (argc >= 3) {
|
if (argc >= 3) {
|
||||||
tx_only_flag = atol(argv[2]);
|
tx_only_flag = atol(argv[2]);
|
||||||
|
@ -1315,6 +1330,9 @@ int TestLoraRadio(int argc, char *argv[])
|
||||||
if (argc >= 4) {
|
if (argc >= 4) {
|
||||||
tx_timeout = atol(argv[3]);
|
tx_timeout = atol(argv[3]);
|
||||||
}
|
}
|
||||||
|
if (argc >= 5) {
|
||||||
|
tx_continues = atol(argv[4]);
|
||||||
|
}
|
||||||
PrivEvenTrigger(radio_event, EV_RADIO_INIT);
|
PrivEvenTrigger(radio_event, EV_RADIO_INIT);
|
||||||
} else if(!strcmp(cmd0, "txdone")) {
|
} else if(!strcmp(cmd0, "txdone")) {
|
||||||
tx_continues = false;
|
tx_continues = false;
|
||||||
|
|
|
@ -400,7 +400,7 @@ void LoraOpen(void)
|
||||||
{
|
{
|
||||||
x_err_t ret = EOK;
|
x_err_t ret = EOK;
|
||||||
|
|
||||||
bus = BusFind(SPI_BUS_NAME_1);
|
bus = BusFind(SPI_BUS_NAME_2);
|
||||||
dev = BusFindDevice(bus, SX12XX_DEVICE_NAME);
|
dev = BusFindDevice(bus, SX12XX_DEVICE_NAME);
|
||||||
|
|
||||||
ret = SpiLoraOpen(dev);
|
ret = SpiLoraOpen(dev);
|
||||||
|
|
Loading…
Reference in New Issue