Commit f2d65660 by zacharyc

Packet reordering shifted PC side.



git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7287 ddd99763-3ecb-0310-9145-efcb8ce7c51f
parent 357e8089
Showing with 52 additions and 7 deletions
...@@ -178,16 +178,48 @@ int nerd_send_command(const char * address, void * command, int length) ...@@ -178,16 +178,48 @@ int nerd_send_command(const char * address, void * command, int length)
} }
//Initialize the channel structure to distill how data should be displayed //Initialize the channel structure to distill how data should be displayed
static int nerd_init_channels(deststruct * destination, int numChannels, int *channel_list) { static void nerd_init_channels(deststruct * destination, int numChannels, int numChannelsSampled, int *channel_list) {
int channels_left = numChannels; //int channels_left = numChannels;
int channelprocessing = 0; int channelprocessing = 0;
int currentalign = 0; //Index into sampled channels int currentalign = 0; //Index into sampled channels
int i; int i;
int numDuplicates = 0; //int numDuplicates = 0;
int tempdestlist[NERDJACK_CHANNELS]; int tempdestlist[NERDJACK_CHANNELS];
//Clear out destination stuff
for(i=0; i < numChannelsSampled;i++) {
destination[i].numCopies = 0;
}
for(channelprocessing = 0; channelprocessing < numChannelsSampled; channelprocessing++) {
//Find out how many copies of each channel so we malloc the right things
currentalign = 0;
for(i = 0; i < numChannels; i++) {
if(channelprocessing == channel_list[i]) {
tempdestlist[currentalign] = i;
currentalign++;
}
}
//If this channel is wanted, set it up.
if(currentalign > 0) {
destination[channelprocessing].numCopies = currentalign;
destination[channelprocessing].destlist = malloc( destination[channelprocessing].numCopies * sizeof(int) );
memcpy(destination[channelprocessing].destlist, tempdestlist, destination[channelprocessing].numCopies * sizeof(int) );
}
}
return;
}
/*
//Loop through channel_list until all channels recognized //Loop through channel_list until all channels recognized
//start with channelprocessing = 0 and increment through channels. //start with channelprocessing = 0 and increment through channels.
//If a channel is found in the list set it up appropriately. //If a channel is found in the list set it up appropriately.
...@@ -220,7 +252,7 @@ static int nerd_init_channels(deststruct * destination, int numChannels, int *ch ...@@ -220,7 +252,7 @@ static int nerd_init_channels(deststruct * destination, int numChannels, int *ch
return numDuplicates; return numDuplicates;
} }
*/
int nerd_data_stream(int data_fd, int numChannels, int *channel_list, int precision, int convert, int lines, int showmem, unsigned short * currentcount) int nerd_data_stream(int data_fd, int numChannels, int *channel_list, int precision, int convert, int lines, int showmem, unsigned short * currentcount)
{ {
//Variables that should persist across retries //Variables that should persist across retries
...@@ -235,7 +267,6 @@ int nerd_data_stream(int data_fd, int numChannels, int *channel_list, int precis ...@@ -235,7 +267,6 @@ int nerd_data_stream(int data_fd, int numChannels, int *channel_list, int precis
unsigned short dataline[NERDJACK_CHANNELS]; unsigned short dataline[NERDJACK_CHANNELS];
long double voltline[NERDJACK_CHANNELS]; long double voltline[NERDJACK_CHANNELS];
int i; int i;
deststruct destination[NERDJACK_CHANNELS];
unsigned long memused = 0; unsigned long memused = 0;
...@@ -254,11 +285,22 @@ int nerd_data_stream(int data_fd, int numChannels, int *channel_list, int precis ...@@ -254,11 +285,22 @@ int nerd_data_stream(int data_fd, int numChannels, int *channel_list, int precis
} }
int numDuplicates = nerd_init_channels(destination,numChannels, channel_list); int numChannelsSampled = channel_list[0] + 1;
//The number sampled will be the highest channel requested plus 1 (i.e. channel 0 requested means 1 sampled)
for(i = 0; i < numChannels; i++) {
if (channel_list[i] + 1 > numChannelsSampled)
numChannelsSampled = channel_list[i] + 1;
}
deststruct destination[numChannelsSampled];
nerd_init_channels(destination,numChannels,numChannelsSampled, channel_list);
//Now destination structure array is set as well as numDuplicates. //Now destination structure array is set as well as numDuplicates.
int numChannelsSampled = numChannels - numDuplicates; //int numChannelsSampled = numChannels - numDuplicates;
int numGroups = NERDJACK_NUM_SAMPLES / numChannelsSampled; int numGroups = NERDJACK_NUM_SAMPLES / numChannelsSampled;
...@@ -313,6 +355,7 @@ int nerd_data_stream(int data_fd, int numChannels, int *channel_list, int precis ...@@ -313,6 +355,7 @@ int nerd_data_stream(int data_fd, int numChannels, int *channel_list, int precis
while(charsread > charsprocessed) { while(charsread > charsprocessed) {
datapoint = ntohs(buf.data[index]); datapoint = ntohs(buf.data[index]);
//datapoint = (buf[index] << 8 | buf[index+1]); //datapoint = (buf[index] << 8 | buf[index+1]);
if(destination[alignment].numCopies != 0) {
switch(convert) { switch(convert) {
case CONVERT_VOLTS: case CONVERT_VOLTS:
if(alignment <= 5) { if(alignment <= 5) {
...@@ -334,6 +377,8 @@ int nerd_data_stream(int data_fd, int numChannels, int *channel_list, int precis ...@@ -334,6 +377,8 @@ int nerd_data_stream(int data_fd, int numChannels, int *channel_list, int precis
break; break;
} }
}
//Each point is two bytes, so increment index and total bytes read //Each point is two bytes, so increment index and total bytes read
charsprocessed++; charsprocessed++;
charsprocessed++; charsprocessed++;
......
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