From 569f009c264ee6a93e4f7da0083dab4d33840a8b Mon Sep 17 00:00:00 2001 From: TheoH Date: Fri, 18 Jul 2014 22:21:59 -0700 Subject: [PATCH] Fixed RNH version logging command --- src/devices/rnh.c | 15 +++++++++------ src/logger.c | 16 +++++++++++++++- src/utilities/net_addrs.c | 21 ++++++++++++++++++++- src/utilities/net_addrs.h | 11 +++++++++-- 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/src/devices/rnh.c b/src/devices/rnh.c index 81f61ed..f1ca452 100644 --- a/src/devices/rnh.c +++ b/src/devices/rnh.c @@ -42,9 +42,8 @@ void rnh_raw_in(unsigned char *buffer, int unsigned len, unsigned char* timestam rnh_data_out(&packet); } -static int s; -static uint8_t buffer[50]; static void version_callback(struct pollfd *pfd){ + uint8_t buffer[50]; int length = read(pfd->fd, buffer, sizeof(buffer)); if(length < 0){ @@ -52,19 +51,23 @@ static void version_callback(struct pollfd *pfd){ } else { rnh_version_out(buffer, length); } - fcf_remove_fd(s); - close(s); + fcf_remove_fd(pfd->fd); + close(pfd->fd); } void rnh_init(void){ - s = socket(AF_INET, SOCK_STREAM, SOCK_NONBLOCK); + int s = socket(AF_INET, SOCK_STREAM, 0); + if(s < 0){ + perror("Couldn't get rnh socket"); + return; + } if(connect(s, RNH_RCI_ADDR, sizeof(struct sockaddr_in)) < 0){ perror("rnh_init: connect() failed"); close(s); return; } fcf_add_fd(s, POLLIN, version_callback); - if(write(s, "#VERS", 5) < 0){ + if(write(s, "#VERS\r\n", 7) < 0){ perror("rnh_init: write failed"); } diff --git a/src/logger.c b/src/logger.c index 46dfb33..12e67b5 100644 --- a/src/logger.c +++ b/src/logger.c @@ -231,8 +231,22 @@ void log_receive_rnh(RNHMessage * packet) { logg(packet, sizeof(message_header) + ntohs(packet->data_length)); } +//FIXME: move to psas_packet +struct VERSMessage { + message_header header; + uint8_t data[50]; +} __attribute__((packed)); + void log_receive_rnh_version(uint8_t * message, unsigned int length){ - logg(message, length); + struct VERSMessage vers = { + .header = { + .ID = {"VERS"}, + .timestamp = {0}, + .data_length = length + } + }; + memcpy(vers.data, message, length); + logg(&vers, sizeof(message_header) + length); } void log_receive_fcfh(unsigned char *buffer, int unsigned len, unsigned char* timestamp) { diff --git a/src/utilities/net_addrs.c b/src/utilities/net_addrs.c index 7245071..be41b0a 100644 --- a/src/utilities/net_addrs.c +++ b/src/utilities/net_addrs.c @@ -33,7 +33,26 @@ .sin_addr = { (addr) } \ } -const struct sockaddr * RNH_RCI_ADDR = make_addr(RNH_IP, RNH_RCI); + +#ifdef FCF_FC_NETWORK +#define RNH_RCI_PORT RCI_PORT +#define SENSOR_RCI_PORT RCI_PORT +#define GPS_RCI_PORT RCI_PORT +#define ROLL_RCI_PORT RCI_PORT + +#else +#define RNH_RCI_PORT 37001 +#define SENSOR_RCI_PORT 37002 +#define GPS_RCI_PORT 37003 +#define ROLL_RCI_PORT 37004 +#endif + +const struct sockaddr * RCI_ADDR = make_addr(FC_IP, RCI_PORT); +const struct sockaddr * RNH_RCI_ADDR = make_addr(RNH_IP, RNH_RCI_PORT); +const struct sockaddr * SENSOR_RCI_ADDR = make_addr(SENSOR_IP, SENSOR_RCI_PORT); +const struct sockaddr * GPS_RCI_ADDR = make_addr(GPS_IP, GPS_RCI_PORT); +const struct sockaddr * ROLL_RCI_ADDR = make_addr(ROLL_IP, ROLL_RCI_PORT); + const struct sockaddr * RNH_BATTERY_ADDR = make_addr(RNH_IP, RNH_BATTERY); const struct sockaddr * RNH_PORT_ADDR = make_addr(RNH_IP, RNH_PORT); const struct sockaddr * RNH_ALARM_ADDR = make_addr(RNH_IP, RNH_ALARM); diff --git a/src/utilities/net_addrs.h b/src/utilities/net_addrs.h index 16d4791..5f9ab5a 100644 --- a/src/utilities/net_addrs.h +++ b/src/utilities/net_addrs.h @@ -23,11 +23,18 @@ #define WIFI_IP IPv4(127,0,0,1) #endif + +/* RCI */ +#define RCI_PORT 23 +extern const struct sockaddr * RCI_ADDR; +extern const struct sockaddr * RNH_RCI_ADDR; +extern const struct sockaddr * SENSOR_RCI_ADDR; +extern const struct sockaddr * GPS_RCI_ADDR; +extern const struct sockaddr * ROLL_RCI_ADDR; + /* Rocket Net Hub */ -#define RNH_RCI 36100 // RCI listener #define RNH_BATTERY 36101 // Battery data #define RNH_PORT 36102 // Port data -extern const struct sockaddr * RNH_RCI_ADDR; #define RNH_ALARM 36103 // Battery alarm #define RNH_UMBDET 36104 // Umbilical detect extern const struct sockaddr * RNH_BATTERY_ADDR;