Browse Source

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
tags/ethstream-1.1
zacharyc 14 years ago
parent
commit
4aab606162
3 changed files with 21 additions and 8 deletions
  1. +8
    -4
      ethstream.c
  2. +12
    -3
      nerdjack.c
  3. +1
    -1
      nerdjack.h

+ 8
- 4
ethstream.c View File

@@ -54,6 +54,7 @@ struct options opt[] = {
{ 'f', "forceretry", NULL, "retry no matter what happens" },
{ 'c', "convert", NULL, "convert output to volts" },
{ '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" },
{ 'h', "help", NULL, "this help" },
{ 'v', "verbose", NULL, "be verbose" },
@@ -64,7 +65,7 @@ struct options opt[] = {
int doStream(const char *address, uint8_t scanconfig, uint16_t scaninterval,
int *channel_list, int channel_count, int convert, int maxlines);
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 columns_left = 0;
@@ -91,6 +92,7 @@ int main(int argc, char *argv[])
int oneshot = 0;
int forceretry = 0;
int convert = CONVERT_DEC;
int showmem = 0;
uint8_t scanconfig;
uint16_t scaninterval;
#if UE9_CHANNELS > NERDJACK_CHANNELS
@@ -189,6 +191,8 @@ int main(int argc, char *argv[])
}
convert = CONVERT_HEX;
break;
case 'm':
showmem++;
case 'v':
verb_count++;
break;
@@ -303,7 +307,7 @@ int main(int argc, char *argv[])
for (;;) {
int ret;
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);
} else {
@@ -344,7 +348,7 @@ int main(int argc, char *argv[])
}

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 fd_data;
@@ -379,7 +383,7 @@ int nerdDoStream(const char *address, int *channel_list, int channel_count, int
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");
goto out1;
}


+ 12
- 3
nerdjack.c View File

@@ -32,8 +32,12 @@
int nerdjack_choose_scan(double desired_rate, double *actual_rate, int *period)
{
*period = round((double) NERDJACK_CLOCK_RATE / desired_rate);
* actual_rate = (double) NERDJACK_CLOCK_RATE / (double) *period;
*period = floor((double) NERDJACK_CLOCK_RATE / desired_rate);
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) {
return -1;
}
@@ -157,7 +161,7 @@ int nerd_send_command(const char * address, char * command)
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];

@@ -262,6 +266,11 @@ int nerd_data_stream(int data_fd, int numChannels, int *channel_list, int precis
packetsready = (buf[10] << 8) | (buf[11]);
alignment = 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(charsread > index) {


+ 1
- 1
nerdjack.h View File

@@ -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);

/* 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 */
int nerdjack_detect(char * ipAddress);


Loading…
Cancel
Save