Skip to content

Commit

Permalink
Fixed RNH version logging command
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirteenFish committed Jul 19, 2014
1 parent 148b229 commit 569f009
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/devices/rnh.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,32 @@ 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){
perror("rnh version callback: read() failed");
} 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");
}

Expand Down
16 changes: 15 additions & 1 deletion src/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 20 additions & 1 deletion src/utilities/net_addrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions src/utilities/net_addrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 569f009

Please sign in to comment.