Commit 4aab6061 by zacharyc

Fixed up rate determination and added memory test routine for NerdJack


git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7235 ddd99763-3ecb-0310-9145-efcb8ce7c51f
parent c81d372d
Showing with 21 additions and 8 deletions
...@@ -54,6 +54,7 @@ struct options opt[] = { ...@@ -54,6 +54,7 @@ struct options opt[] = {
{ 'f', "forceretry", NULL, "retry no matter what happens" }, { 'f', "forceretry", NULL, "retry no matter what happens" },
{ 'c', "convert", NULL, "convert output to volts" }, { 'c', "convert", NULL, "convert output to volts" },
{ 'H', "converthex", NULL, "convert output to hex" }, { 'H', "converthex", NULL, "convert output to hex" },
{ 'm', "showmem", NULL, "output memory stats with data (NJ only)" },
{ 'l', "lines", "num", "if set, output this many lines and quit" }, { 'l', "lines", "num", "if set, output this many lines and quit" },
{ 'h', "help", NULL, "this help" }, { 'h', "help", NULL, "this help" },
{ 'v', "verbose", NULL, "be verbose" }, { 'v', "verbose", NULL, "be verbose" },
...@@ -64,7 +65,7 @@ struct options opt[] = { ...@@ -64,7 +65,7 @@ struct options opt[] = {
int doStream(const char *address, uint8_t scanconfig, uint16_t scaninterval, int doStream(const char *address, uint8_t scanconfig, uint16_t scaninterval,
int *channel_list, int channel_count, int convert, int maxlines); int *channel_list, int channel_count, int convert, int maxlines);
int nerdDoStream(const char *address, int *channel_list, int channel_count, int precision, int nerdDoStream(const char *address, int *channel_list, int channel_count, int precision,
unsigned short period, int convert, int lines); unsigned short period, int convert, int lines, int showmem);
int data_callback(int channels, uint16_t *data, void *context); int data_callback(int channels, uint16_t *data, void *context);
int columns_left = 0; int columns_left = 0;
...@@ -91,6 +92,7 @@ int main(int argc, char *argv[]) ...@@ -91,6 +92,7 @@ int main(int argc, char *argv[])
int oneshot = 0; int oneshot = 0;
int forceretry = 0; int forceretry = 0;
int convert = CONVERT_DEC; int convert = CONVERT_DEC;
int showmem = 0;
uint8_t scanconfig; uint8_t scanconfig;
uint16_t scaninterval; uint16_t scaninterval;
#if UE9_CHANNELS > NERDJACK_CHANNELS #if UE9_CHANNELS > NERDJACK_CHANNELS
...@@ -189,6 +191,8 @@ int main(int argc, char *argv[]) ...@@ -189,6 +191,8 @@ int main(int argc, char *argv[])
} }
convert = CONVERT_HEX; convert = CONVERT_HEX;
break; break;
case 'm':
showmem++;
case 'v': case 'v':
verb_count++; verb_count++;
break; break;
...@@ -303,7 +307,7 @@ int main(int argc, char *argv[]) ...@@ -303,7 +307,7 @@ int main(int argc, char *argv[])
for (;;) { for (;;) {
int ret; int ret;
if(nerdjack) { if(nerdjack) {
ret = nerdDoStream(address, channel_list, channel_count, precision, period, convert, lines); ret = nerdDoStream(address, channel_list, channel_count, precision, period, convert, lines, showmem);
verb("nerdDoStream returned %d\n", ret); verb("nerdDoStream returned %d\n", ret);
} else { } else {
...@@ -344,7 +348,7 @@ int main(int argc, char *argv[]) ...@@ -344,7 +348,7 @@ int main(int argc, char *argv[])
} }
int nerdDoStream(const char *address, int *channel_list, int channel_count, int precision, int nerdDoStream(const char *address, int *channel_list, int channel_count, int precision,
unsigned short period, int convert, int lines) unsigned short period, int convert, int lines, int showmem)
{ {
int retval = -EAGAIN; int retval = -EAGAIN;
int fd_data; int fd_data;
...@@ -379,7 +383,7 @@ int nerdDoStream(const char *address, int *channel_list, int channel_count, int ...@@ -379,7 +383,7 @@ int nerdDoStream(const char *address, int *channel_list, int channel_count, int
goto out; goto out;
} }
if (nerd_data_stream(fd_data, channel_count, channel_list, precision, convert, lines) < 0) { if (nerd_data_stream(fd_data, channel_count, channel_list, precision, convert, lines, showmem) < 0) {
info("Failed to open data stream\n"); info("Failed to open data stream\n");
goto out1; goto out1;
} }
......
...@@ -32,8 +32,12 @@ ...@@ -32,8 +32,12 @@
int nerdjack_choose_scan(double desired_rate, double *actual_rate, int *period) int nerdjack_choose_scan(double desired_rate, double *actual_rate, int *period)
{ {
*period = round((double) NERDJACK_CLOCK_RATE / desired_rate); *period = floor((double) NERDJACK_CLOCK_RATE / desired_rate);
* actual_rate = (double) NERDJACK_CLOCK_RATE / (double) *period; if(*period > UINT16_MAX) {
info("Cannot sample that slowly\n");
return -1;
}
*actual_rate = (double) NERDJACK_CLOCK_RATE / (double) *period;
if(*actual_rate != desired_rate) { if(*actual_rate != desired_rate) {
return -1; return -1;
} }
...@@ -157,7 +161,7 @@ int nerd_send_command(const char * address, char * command) ...@@ -157,7 +161,7 @@ int nerd_send_command(const char * address, char * command)
return 0; return 0;
} }
int nerd_data_stream(int data_fd, 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, int showmem)
{ {
unsigned char buf[NERDJACK_PACKET_SIZE]; unsigned char buf[NERDJACK_PACKET_SIZE];
...@@ -262,6 +266,11 @@ int nerd_data_stream(int data_fd, int numChannels, int *channel_list, int precis ...@@ -262,6 +266,11 @@ int nerd_data_stream(int data_fd, int numChannels, int *channel_list, int precis
packetsready = (buf[10] << 8) | (buf[11]); packetsready = (buf[10] << 8) | (buf[11]);
alignment = 0; alignment = 0;
numgroups = 0; numgroups = 0;
if(showmem) {
printf("%lX %hd %hd\n",memused, adcused, packetsready);
continue;
}
//While there is still more data in the packet, process it //While there is still more data in the packet, process it
while(charsread > index) { while(charsread > index) {
......
...@@ -36,7 +36,7 @@ int nerd_generate_command(char * command, int * channel_list, int channel_count, ...@@ -36,7 +36,7 @@ int nerd_generate_command(char * command, int * channel_list, int channel_count,
int nerd_send_command(const char * address, char * command); int nerd_send_command(const char * address, char * command);
/* Stream data out of the NerdJack */ /* Stream data out of the NerdJack */
int nerd_data_stream(int data_fd, 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, int showmem);
/* Detect the IP Address of the NerdJack and return in ipAddress */ /* Detect the IP Address of the NerdJack and return in ipAddress */
int nerdjack_detect(char * 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