Commit 4524f534 by zacharyc

Added ability to have duplicate channels for compatibility with

ljstream.


git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7090 ddd99763-3ecb-0310-9145-efcb8ce7c51f
parent a9200acc
Showing with 45 additions and 13 deletions
...@@ -115,20 +115,26 @@ int nerdjack_detect(char * ipAddress) { ...@@ -115,20 +115,26 @@ int nerdjack_detect(char * ipAddress) {
return 0; return 0;
} }
typedef struct {
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_data_stream(int data_fd, char * command, int numChannels, int *channel_list, int precision, int convert, int lines)
{ {
unsigned char buf[NERDJACK_PACKET_SIZE]; unsigned char buf[NERDJACK_PACKET_SIZE];
int numGroups = NERDJACK_NUM_SAMPLES / numChannels; //int numGroups = NERDJACK_NUM_SAMPLES / numChannels;
int index = 0; int index = 0;
int totalread = 0; //int totalread = 0;
int ret = 0; int ret = 0;
int alignment = 0; int alignment = 0;
signed short datapoint = 0; signed short datapoint = 0;
signed short dataline[NERDJACK_CHANNELS]; signed short dataline[NERDJACK_CHANNELS];
long double voltline[NERDJACK_CHANNELS]; long double voltline[NERDJACK_CHANNELS];
int destination[NERDJACK_CHANNELS]; deststruct destination[NERDJACK_CHANNELS];
int tempdestlist[NERDJACK_CHANNELS];
unsigned short currentcount = 0; unsigned short currentcount = 0;
unsigned long memused = 0; unsigned long memused = 0;
unsigned short packetsready = 0; unsigned short packetsready = 0;
...@@ -144,23 +150,42 @@ int nerd_data_stream(int data_fd, char * command, int numChannels, int *channel_ ...@@ -144,23 +150,42 @@ int nerd_data_stream(int data_fd, char * command, int numChannels, int *channel_
int channels_left = numChannels; int channels_left = numChannels;
int channelprocessing = 0; int channelprocessing = 0;
int currentalign = 0; int currentalign = 0; //Index into sampled channels
int i; int i;
int numDuplicates = 0;
//Loop through channel_list until all channels recognized //Loop through channel_list until all channels recognized
//destination holds the index where each channel should go for reordering //start with channelprocessing = 0 and increment through channels.
//If a channel is found in the list set it up appropriately.
do { do {
//numduplicates = 0;
destination[currentalign].numCopies = 0;
for(i = 0; i < numChannels; i++) { for(i = 0; i < numChannels; i++) {
if(channelprocessing == channel_list[i]) { if(channelprocessing == channel_list[i]) {
destination[currentalign] = i; //destination[currentalign] = i;
currentalign++; tempdestlist[destination[currentalign].numCopies] = i;
if(destination[currentalign].numCopies > 0) {
numDuplicates++;
}
destination[currentalign].numCopies++;
//currentalign++;
channels_left--; channels_left--;
break; //break;
} }
} }
if(destination[currentalign].numCopies > 0) {
destination[currentalign].destlist = malloc( destination[currentalign].numCopies * sizeof(int) );
memcpy(destination[currentalign].destlist, tempdestlist, destination[currentalign].numCopies * sizeof(int));
currentalign++;
}
channelprocessing++; channelprocessing++;
} while(channels_left > 0); } while(channels_left > 0);
int numChannelsSampled = numChannels - numDuplicates;
int numGroups = NERDJACK_NUM_SAMPLES / numChannelsSampled;
/* Send request */ /* Send request */
ret = send_all_timeout(data_fd, command, strlen(command), 0, ret = send_all_timeout(data_fd, command, strlen(command), 0,
& (struct timeval) { .tv_sec = NERDJACK_TIMEOUT }); & (struct timeval) { .tv_sec = NERDJACK_TIMEOUT });
...@@ -217,19 +242,26 @@ int nerd_data_stream(int data_fd, char * command, int numChannels, int *channel_ ...@@ -217,19 +242,26 @@ int nerd_data_stream(int data_fd, char * command, int numChannels, int *channel_
} else { } else {
volts = (long double) (datapoint / 32767.0 ) * ((precision & 0x02) ? 5.0 : 10.0); volts = (long double) (datapoint / 32767.0 ) * ((precision & 0x02) ? 5.0 : 10.0);
} }
voltline[destination[alignment]] = volts; for(i = 0; i < destination[alignment].numCopies; i++) {
voltline[destination[alignment].destlist[i]] = volts;
}
} else { } else {
dataline[destination[alignment]] = datapoint; for(i = 0; i < destination[alignment].numCopies; i++) {
dataline[destination[alignment].destlist[i]] = datapoint;
}
} }
//Each point is two bytes, so increment index and total bytes read //Each point is two bytes, so increment index and total bytes read
index++; index++;
index++; index++;
totalread++;
alignment++; alignment++;
//totalread++;
//Since channel data is packed, we need to know when to insert a newline //Since channel data is packed, we need to know when to insert a newline
if(alignment == numChannels){ if(alignment == numChannelsSampled){
if(convert) { if(convert) {
for(i = 0; i < numChannels; i++) { for(i = 0; i < numChannels; i++) {
printf("%Lf ",voltline[i]); printf("%Lf ",voltline[i]);
......
/* This file was automatically generated. */ /* This file was automatically generated. */
#define VERSION "1.3 (2008-09-19)" #define VERSION "1.0 (2009-01-21)"
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