Commit 01359f47 by YOUR NAME

added raw binary output mode

parent 0b1ad741
Showing with 26 additions and 2 deletions
ethstream ethstream
ethstream.1 ethstream.1
ethstream.txt ethstream.txt
*.d
*.o
\ No newline at end of file
...@@ -59,6 +59,7 @@ struct options opt[] = { ...@@ -59,6 +59,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/temperature"}, {'c', "convert", NULL, "convert output to volts/temperature"},
{'H', "converthex", NULL, "convert output to hex"}, {'H', "converthex", NULL, "convert output to hex"},
{'B', "convertbinary", NULL, "output raw binary data"},
{'m', "showmem", NULL, "output memory stats with data (NJ only)"}, {'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"},
...@@ -102,7 +103,6 @@ void handle_sig(int sig) ...@@ -102,7 +103,6 @@ void handle_sig(int sig)
* if the stream is not closed correctly * * if the stream is not closed correctly *
******************************************************/ ******************************************************/
if(ue9_running==1){ if(ue9_running==1){
printf("Performing clean shutdown of LabJack\n");
ue9_stream_stop(fd_cmd); ue9_stream_stop(fd_cmd);
ue9_buffer_flush(fd_cmd); ue9_buffer_flush(fd_cmd);
ue9_close(fd_data); ue9_close(fd_data);
...@@ -324,6 +324,15 @@ int main(int argc, char *argv[]) ...@@ -324,6 +324,15 @@ int main(int argc, char *argv[])
} }
convert = CONVERT_HEX; convert = CONVERT_HEX;
break; break;
case 'B':
if (convert != 0) {
info("specify only one conversion type\n");
goto printhelp;
}
convert = CONVERT_BINARY;
// convert stdout to binary stream
// freopen (NULL,"wb",stdout);
break;
case 'm': case 'm':
showmem++; showmem++;
case 'v': case 'v':
...@@ -782,6 +791,16 @@ int data_callback(int channels, int *channel_list, int gain_count, int *gain_lis ...@@ -782,6 +791,16 @@ int data_callback(int channels, int *channel_list, int gain_count, int *gain_lis
struct callbackInfo *ci = (struct callbackInfo *)context; struct callbackInfo *ci = (struct callbackInfo *)context;
static int lines = 0; static int lines = 0;
if (ci->convert == CONVERT_BINARY) {
/* CONVERT_BINARY */
if (fwrite(data, sizeof(uint16_t), channels, stdout) < 0)
goto bad;
lines++;
if (ci->maxlines && lines >= ci->maxlines)
return -1;
return 0;
}
columns_left = channels; columns_left = channels;
for (i = 0; i < channels; i++) { for (i = 0; i < channels; i++) {
if (ci->convert == CONVERT_VOLTS && if (ci->convert == CONVERT_VOLTS &&
...@@ -809,7 +828,8 @@ int data_callback(int channels, int *channel_list, int gain_count, int *gain_lis ...@@ -809,7 +828,8 @@ int data_callback(int channels, int *channel_list, int gain_count, int *gain_lis
/* CONVERT_HEX */ /* CONVERT_HEX */
if (printf("%04X", data[i]) < 0) if (printf("%04X", data[i]) < 0)
goto bad; goto bad;
} else { }
else {
/* CONVERT_DEC */ /* CONVERT_DEC */
if (printf("%d", data[i]) < 0) if (printf("%d", data[i]) < 0)
goto bad; goto bad;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#define CONVERT_DEC 0 #define CONVERT_DEC 0
#define CONVERT_VOLTS 1 #define CONVERT_VOLTS 1
#define CONVERT_HEX 2 #define CONVERT_HEX 2
#define CONVERT_BINARY 3
#define TIMEOUT 5 /* Timeout for connect/send/recv, in seconds */ #define TIMEOUT 5 /* Timeout for connect/send/recv, in seconds */
......
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