Skip to content
Snippets Groups Projects
Commit 5f1b73e6 authored by f4grx's avatar f4grx
Browse files

add radio RX function with green LED

fix all apps to init the system before using devices.
We still have a problem: when sysdaemon is used as startup, and we run additional apps, the radio device FDs are not valid anymore. we need to fix this by sending radio packets to the sysdaemon with a thread and work queue.
parent f07874ff
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,7 @@
int hn70ap_radio_init(void);
int hn70ap_radio_transmit(uint8_t device, uint8_t *buf, size_t len);
int hn70ap_radio_receive (uint8_t device, uint8_t *buf, size_t len);
#endif /* HN70AP_SYSTEM_H */
......@@ -40,6 +40,7 @@
#include <fcntl.h>
#include <syslog.h>
#include <unistd.h>
#include <hn70ap/radio.h>
#include <hn70ap/leds.h>
......@@ -103,3 +104,35 @@ int hn70ap_radio_transmit(uint8_t device, uint8_t *buf, size_t len)
return ret;
}
int hn70ap_radio_receive(uint8_t device, uint8_t *buf, size_t len)
{
int fd;
int ret;
if(device == HN70AP_RADIO_MAIN)
{
fd = fd_main;
}
else if(device == HN70AP_RADIO_AUX)
{
fd = fd_aux;
}
else
{
return ERROR;
}
/* Turn on radio LED in transmit mode */
hn70ap_leds_state(LED_1A, LED_STATE_OFF);
hn70ap_leds_state(LED_1B, LED_STATE_ON);
/* Transmit */
ret = read(fd, buf, len);
/* Turn off radio LED */
hn70ap_leds_state(LED_1A, LED_STATE_OFF);
hn70ap_leds_state(LED_1B, LED_STATE_OFF);
return ret;
}
......@@ -48,6 +48,9 @@
#include <fcntl.h>
#include <unistd.h>
#include <hn70ap/system.h>
#include <hn70ap/radio.h>
/****************************************************************************
* Public Functions
****************************************************************************/
......@@ -62,7 +65,6 @@ int main(int argc, FAR char *argv[])
int rxt_main(int argc, char *argv[])
#endif
{
char *devname = "/dev/raux";
int ret = OK;
int fd;
int buflen = 1024;
......@@ -70,32 +72,21 @@ int rxt_main(int argc, char *argv[])
uint8_t *buf;
if(argc > 1)
{
devname = argv[1];
}
printf("RX test using aux radio\n");
printf("RX test using %s\n", devname);
fd = open(devname, O_RDWR);
if(fd<0)
{
fprintf(stderr, "open failed!\n");
ret = ERROR;
goto done;
}
hn70ap_system_init();
buf = malloc(buflen);
if(!buf)
{
fprintf(stderr, "open failed!\n");
fprintf(stderr, "malloc failed!\n");
ret = ERROR;
goto retclose;
goto done;
}
do
{
ret = read(fd, buf, buflen);
ret = hn70ap_radio_receive(HN70AP_RADIO_AUX, buf, buflen);
printf("read done, ret = %d, errno=%d\n", ret, errno);
if(ret > 0)
{
......@@ -105,14 +96,17 @@ int rxt_main(int argc, char *argv[])
}
printf("\n");
}
else if(ret < 0 && errno==ETIMEDOUT)
{
printf("RX timeout\n");
continue;
}
}
while(ret > 0);
printf("Read sequence done.\n");
free(buf);
retclose:
close(fd);
done:
return ret;
}
......
......@@ -94,7 +94,7 @@ int sysdaemon_main(int argc, char *argv[])
hn70ap_netmonitor_init();
hn70ap_leds_state(LED_GREEN, LED_STATE_ON);
if(ret == OK)
if(ret != OK)
{
hn70ap_leds_state(LED_RED, LED_STATE_ON);
}
......
......@@ -48,6 +48,9 @@
#include <fcntl.h>
#include <unistd.h>
#include <hn70ap/system.h>
#include <hn70ap/radio.h>
/****************************************************************************
* Public Functions
****************************************************************************/
......@@ -55,7 +58,7 @@
int txt_usage(void)
{
printf(
"txt [device] hexdata_nospaces\n"
"txt hexdata_nospaces\n"
);
return ERROR;
}
......@@ -114,21 +117,14 @@ int main(int argc, FAR char *argv[])
int txt_main(int argc, char *argv[])
#endif
{
char *devname = "/dev/raux";
char *data;
int ret = OK;
int fd;
int buflen = 1024;
int len;
uint8_t *buf;
if(argc == 3)
{
devname = argv[1];
data = argv[2];
}
else if(argc == 2)
if(argc == 2)
{
data = argv[1];
}
......@@ -137,6 +133,8 @@ int txt_main(int argc, char *argv[])
return txt_usage();
}
hn70ap_system_init();
buf = malloc(buflen);
if(!buf)
{
......@@ -159,20 +157,10 @@ int txt_main(int argc, char *argv[])
len += 1;
}
printf("\nTX test using %s (%d bytes)\n", devname, len);
fd = open(devname, O_RDWR);
if(fd<0)
{
fprintf(stderr, "open failed!\n");
ret = ERROR;
goto retfree;
}
ret = write(fd, buf, len);
printf("\nTX test using aux radio(%d bytes)\n", len);
ret = hn70ap_radio_transmit(HN70AP_RADIO_AUX, buf, len);
printf("write done, ret = %d, errno=%d\n", ret, errno);
close(fd);
retfree:
free(buf);
done:
......
......@@ -1191,15 +1191,11 @@ CONFIG_DRIVERS_WIRELESS=y
CONFIG_DRIVERS_GENERICRADIO=y
CONFIG_GENERICRADIO_UPPER=y
CONFIG_GENERICRADIO_SI4463=y
CONFIG_GENERICRADIO_SI4463_ANTSWITCH_ALT=y
# CONFIG_GENERICRADIO_SI4463_FRAMING_L1 is not set
CONFIG_GENERICRADIO_SI4463_FRAMING_L2B=y
# CONFIG_GENERICRADIO_SI4463_FRAMING_L2L is not set
CONFIG_GENERICRADIO_SI4463_USE_WDS_CONFIG=y
# CONFIG_GENERICRADIO_SI4463_DEFAULT_SYNCWORD_NONE is not set
# CONFIG_GENERICRADIO_SI4463_DEFAULT_SYNCWORD_A55A is not set
# CONFIG_GENERICRADIO_SI4463_DEFAULT_SYNCWORD_4242 is not set
# CONFIG_GENERICRADIO_SI4463_DEFAULT_SYNCWORD_A55AA55A is not set
# CONFIG_GENERICRADIO_SI4463_DEFAULT_SYNCWORD_42424242 is not set
# CONFIG_WL_NRF24L01 is not set
# CONFIG_DRIVERS_CONTACTLESS is not set
......
......@@ -787,7 +787,7 @@ CONFIG_PREALLOC_TIMERS=4
# CONFIG_INIT_NONE is not set
CONFIG_INIT_ENTRYPOINT=y
# CONFIG_INIT_FILEPATH is not set
CONFIG_USER_ENTRYPOINT="sysdaemon_main"
CONFIG_USER_ENTRYPOINT="nsh_main"
CONFIG_RR_INTERVAL=200
# CONFIG_SCHED_SPORADIC is not set
CONFIG_TASK_NAME_SIZE=0
......@@ -1188,7 +1188,14 @@ CONFIG_DRIVERS_WIRELESS=y
# CONFIG_SPIRIT_NETDEV is not set
# CONFIG_DRIVERS_IEEE802154 is not set
# CONFIG_DRIVERS_IEEE80211 is not set
# CONFIG_DRIVERS_GENERICRADIO is not set
CONFIG_DRIVERS_GENERICRADIO=y
CONFIG_GENERICRADIO_UPPER=y
CONFIG_GENERICRADIO_SI4463=y
CONFIG_GENERICRADIO_SI4463_ANTSWITCH_ALT=y
# CONFIG_GENERICRADIO_SI4463_FRAMING_L1 is not set
CONFIG_GENERICRADIO_SI4463_FRAMING_L2B=y
# CONFIG_GENERICRADIO_SI4463_FRAMING_L2L is not set
CONFIG_GENERICRADIO_SI4463_USE_WDS_CONFIG=y
# CONFIG_WL_NRF24L01 is not set
# CONFIG_DRIVERS_CONTACTLESS is not set
......@@ -1667,7 +1674,9 @@ CONFIG_FSUTILS_MKSMARTFS=y
#
# hn70ap apps
#
# CONFIG_HN70AP_BEACON is not set
CONFIG_HN70AP_BEACON=y
CONFIG_HN70AP_BEACON_PRIORITY=100
CONFIG_HN70AP_BEACON_STACKSIZE=2048
CONFIG_HN70AP_CONFIG=y
CONFIG_HN70AP_CONFIG_PRIORITY=100
CONFIG_HN70AP_CONFIG_STACKSIZE=2048
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment