Commit 1d760e03 by zacharyc

Updated ethstream to have separate Command and Data ports for NerdJack


git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7212 ddd99763-3ecb-0310-9145-efcb8ce7c51f
parent 57cfac2b
Showing with 64 additions and 19 deletions
......@@ -337,23 +337,35 @@ int nerdDoStream(const char *address, int *channel_list, int channel_count, int
static int first_call = 1;
char command[13];
/* Open connection. If this fails, and this is the
first attempt, return a different error code so we give up. */
fd_data = nerd_open(address, NERDJACK_DATA_PORT);
if (fd_data < 0) {
info("Connect failed: %s:%d\n", address, NERDJACK_DATA_PORT);
if (nerd_generate_command(command, channel_list, channel_count, precision, period) < 0) {
info("Failed to create configuration command\n");
goto out;
}
if (nerd_send_command(address,"STOP") < 0) {
info("Failed to send STOP command\n");
goto out;
}
if (nerd_send_command(address,command) < 0) {
if (first_call)
retval = -ENOTCONN;
info("Failed to send command\n");
goto out;
}
first_call = 0;
if (nerd_generate_command(command, channel_list, channel_count, precision, period) < 0) {
info("Failed to create configuration command\n");
goto out1;
/* Open connection. If this fails, and this is the
first attempt, return a different error code so we give up. */
fd_data = nerd_open(address, NERDJACK_DATA_PORT);
if (fd_data < 0) {
info("Connect failed: %s:%d\n", address, NERDJACK_DATA_PORT);
goto out;
}
if (nerd_data_stream(fd_data, command, channel_count, channel_list, precision, convert, lines) < 0) {
if (nerd_data_stream(fd_data, channel_count, channel_list, precision, convert, lines) < 0) {
info("Failed to open data stream\n");
goto out1;
}
......
......@@ -120,7 +120,43 @@ int numCopies;
int * destlist;
} deststruct;
int nerd_data_stream(int data_fd, char * command, int numChannels, int *channel_list, int precision, int convert, int lines)
int nerd_send_command(const char * address, char * command)
{
int ret,fd_command;
char buf[3];
fd_command = nerd_open(address, NERDJACK_COMMAND_PORT);
if (fd_command < 0) {
info("Connect failed: %s:%d\n", address, NERDJACK_COMMAND_PORT);
return -2;
}
/* Send request */
ret = send_all_timeout(fd_command, command, strlen(command), 0,
& (struct timeval) { .tv_sec = NERDJACK_TIMEOUT });
if (ret < 0 || ret != strlen(command)) {
verb("short send %d\n", (int)ret);
return -1;
}
ret = recv_all_timeout(fd_command,buf,3,0,
& (struct timeval) { .tv_sec = NERDJACK_TIMEOUT });
nerd_close_conn(fd_command);
if (ret < 0 || ret != 3) {
verb("Error receiving OK for command\n");
return -1;
}
if (0 != strcmp("OK",buf)){
verb("Did not receive OK. Received %s\n",buf);
return -3;
}
return 0;
}
int nerd_data_stream(int data_fd, int numChannels, int *channel_list, int precision, int convert, int lines)
{
unsigned char buf[NERDJACK_PACKET_SIZE];
......@@ -128,7 +164,7 @@ int nerd_data_stream(int data_fd, char * command, int numChannels, int *channel_
int index = 0;
//int totalread = 0;
int ret = 0;
//int ret = 0;
int alignment = 0;
signed short datapoint = 0;
unsigned short dataline[NERDJACK_CHANNELS];
......@@ -186,13 +222,6 @@ int nerd_data_stream(int data_fd, char * command, int numChannels, int *channel_
int numChannelsSampled = numChannels - numDuplicates;
int numGroups = NERDJACK_NUM_SAMPLES / numChannelsSampled;
/* Send request */
ret = send_all_timeout(data_fd, command, strlen(command), 0,
& (struct timeval) { .tv_sec = NERDJACK_TIMEOUT });
if (ret < 0 || ret != strlen(command)) {
verb("short send %d\n", (int)ret);
return -1;
}
//Loop forever to grab data
while((charsread = recv_all_timeout(data_fd,buf,NERDJACK_PACKET_SIZE,0,
......
......@@ -19,6 +19,7 @@
#define NERDJACK_CLOCK_RATE 54000000
#define NERDJACK_DATA_PORT 49155
#define NERDJACK_UDP_RECEIVE_PORT 49156
#define NERDJACK_COMMAND_PORT 49157
#define NERDJACK_PACKET_SIZE 1460
#define NERDJACK_NUM_SAMPLES 724
......@@ -31,8 +32,11 @@ int nerd_close_conn(int data_fd);
int nerd_generate_command(char * command, int * channel_list, int channel_count, int precision,
unsigned short period);
/* Send given command to NerdJack */
int nerd_send_command(const char * address, char * command);
/* Stream data out of the NerdJack */
int nerd_data_stream(int data_fd, char * command, int numChannels, int * channel_list, int precision, int convert, int lines);
int nerd_data_stream(int data_fd, int numChannels, int * channel_list, int precision, int convert, int lines);
/* Detect the IP Address of the NerdJack and return in ipAddress */
int nerdjack_detect(char * ipAddress);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment