summaryrefslogtreecommitdiffstats
path: root/servers/gpib_server_lin/src
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-04-30 16:46:20 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-04-30 16:46:20 -0500
commit408e828f4732c9bb4aa3673c87d85109e06c08e1 (patch)
treeecd25f872402cea120a442d3f2744d74d699b675 /servers/gpib_server_lin/src
parentf8d372779417eeb809088893ca58ad6a318ab418 (diff)
downloadulab-408e828f4732c9bb4aa3673c87d85109e06c08e1.tar.gz
ulab-408e828f4732c9bb4aa3673c87d85109e06c08e1.zip
Fixups for ca server
Add very preliminary client for ca and TDE
Diffstat (limited to 'servers/gpib_server_lin/src')
-rw-r--r--servers/gpib_server_lin/src/commanalyzer_functions.c306
-rw-r--r--servers/gpib_server_lin/src/commanalyzer_functions.h8
-rw-r--r--servers/gpib_server_lin/src/main_server_lin.c159
3 files changed, 432 insertions, 41 deletions
diff --git a/servers/gpib_server_lin/src/commanalyzer_functions.c b/servers/gpib_server_lin/src/commanalyzer_functions.c
index 0a91731..207a4d5 100644
--- a/servers/gpib_server_lin/src/commanalyzer_functions.c
+++ b/servers/gpib_server_lin/src/commanalyzer_functions.c
@@ -653,4 +653,310 @@ int commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions( char * comm
else {
return -1;
}
+}
+
+int commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions( char * commanalyzerType, int gpibDevice) {
+ if ((strcmp("HP8924C", commanalyzerType) == 0)) {
+ return 10;
+ }
+ else {
+ return -1;
+ }
+}
+
+double commanalyzer_get_spectrum_analyzer_reference_power_level(double * retval, char * commanalyzerType, int gpibDevice) {
+ unsigned char segarray[4194304];
+ unsigned char floatstring[1024];
+ long array_pointer;
+ long ai;
+ long left_char;
+ long right_char;
+
+ int max_num_bytes = 0;
+
+ if ((strcmp("HP8924C", commanalyzerType) == 0)) {
+ // Send request
+ printf("[INFO] Getting spectrum analyzer reference power level\n\r");
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ sprintf(falpha,"SAN:RLEV?");
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Writing: %s\n\r", falpha);
+ #endif
+ if (gpib_write(gpibDevice, falpha) == 0) {
+ max_num_bytes = 24; // Request more bytes than are possible to ensure no bytes are left behind
+ }
+ else {
+ return 2;
+ }
+ }
+
+ // Read response
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
+ #endif
+
+ ibtmo(gpibDevice, T10s);
+ ibeos(gpibDevice, 0x0);
+
+ ai = gpib_read_array(gpibDevice, max_num_bytes, segarray);
+ if (ai == -1) {
+ return 1;
+ }
+ else {
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ segarray[ai] = 0;
+ *retval = atof(segarray);
+ }
+ else {
+ return 2;
+ }
+ }
+
+ ibtmo(gpibDevice, T10s);
+
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Read %li bytes from GPIB device\n", ai);
+ #endif
+
+ return 0;
+ }
+ else {
+ return -1;
+ }
+}
+
+double commanalyzer_get_spectrum_analyzer_scale(double * retval, char * commanalyzerType, int gpibDevice) {
+ unsigned char segarray[4194304];
+ unsigned char floatstring[1024];
+ long array_pointer;
+ long ai;
+ long left_char;
+ long right_char;
+
+ int max_num_bytes = 0;
+
+ if ((strcmp("HP8924C", commanalyzerType) == 0)) {
+ // Send request
+ printf("[INFO] Getting spectrum analyzer scale\n\r");
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ sprintf(falpha,"SAN:DISP:SCAL?");
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Writing: %s\n\r", falpha);
+ #endif
+ if (gpib_write(gpibDevice, falpha) == 0) {
+ max_num_bytes = 24; // Request more bytes than are possible to ensure no bytes are left behind
+ }
+ else {
+ return 2;
+ }
+ }
+
+ // Read response
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
+ #endif
+
+ ibtmo(gpibDevice, T10s);
+ ibeos(gpibDevice, 0x0);
+
+ ai = gpib_read_array(gpibDevice, max_num_bytes, segarray);
+ if (ai == -1) {
+ return 1;
+ }
+ else {
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ left_char = 1;
+ right_char = 0;
+ array_pointer = 0;
+ for (right_char=left_char;right_char<ai;right_char++) {
+ if (segarray[right_char] == ' ') {
+ break;
+ }
+ }
+ strncpy(floatstring, segarray+left_char, right_char-left_char);
+ floatstring[right_char-left_char] = 0;
+ *retval = atof(floatstring);
+ }
+ else {
+ return 2;
+ }
+ }
+
+ ibtmo(gpibDevice, T10s);
+
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Read %li bytes from GPIB device\n", ai);
+ #endif
+
+ return 0;
+ }
+ else {
+ return -1;
+ }
+}
+
+int commanalyzer_set_display_brightness(float percent, char * commanalyzerType, int gpibDevice) {
+ int instrument_scale;
+
+ if ((strcmp("HP8924C", commanalyzerType) == 0)) {
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ instrument_scale = ((percent/100.0)*7.0)+1;
+ }
+ printf("[INFO] Setting display brightness to %d\n\r", instrument_scale);
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ sprintf(falpha,"CONF:INT %d", instrument_scale);
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Writing: %s\n\r", falpha);
+ #endif
+ if (gpib_write(gpibDevice, falpha) == 0) {
+ return 0;
+ }
+ else {
+ return 2;
+ }
+ }
+ }
+ else {
+ return 1;
+ }
+}
+
+double commanalyzer_get_spectrum_analyzer_center_frequency(double * retval, char * commanalyzerType, int gpibDevice) {
+ unsigned char segarray[4194304];
+ unsigned char floatstring[1024];
+ long array_pointer;
+ long ai;
+ long left_char;
+ long right_char;
+
+ int max_num_bytes = 0;
+
+ if ((strcmp("HP8924C", commanalyzerType) == 0)) {
+ // Send request
+ printf("[INFO] Getting spectrum analyzer center frequency\n\r");
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ sprintf(falpha,"SAN:CFR?");
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Writing: %s\n\r", falpha);
+ #endif
+ if (gpib_write(gpibDevice, falpha) == 0) {
+ max_num_bytes = 24; // Request more bytes than are possible to ensure no bytes are left behind
+ }
+ else {
+ return 2;
+ }
+ }
+
+ // Read response
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
+ #endif
+
+ ibtmo(gpibDevice, T10s);
+ ibeos(gpibDevice, 0x0);
+
+ ai = gpib_read_array(gpibDevice, max_num_bytes, segarray);
+ if (ai == -1) {
+ return 1;
+ }
+ else {
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ left_char = 1;
+ right_char = 0;
+ array_pointer = 0;
+ for (right_char=left_char;right_char<ai;right_char++) {
+ if (segarray[right_char] == ' ') {
+ break;
+ }
+ }
+ strncpy(floatstring, segarray+left_char, right_char-left_char);
+ floatstring[right_char-left_char] = 0;
+ *retval = atof(floatstring);
+ }
+ else {
+ return 2;
+ }
+ }
+
+ ibtmo(gpibDevice, T10s);
+
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Read %li bytes from GPIB device\n", ai);
+ #endif
+
+ return 0;
+ }
+ else {
+ return -1;
+ }
+}
+
+double commanalyzer_get_spectrum_analyzer_span(double * retval, char * commanalyzerType, int gpibDevice) {
+ unsigned char segarray[4194304];
+ unsigned char floatstring[1024];
+ long array_pointer;
+ long ai;
+ long left_char;
+ long right_char;
+
+ int max_num_bytes = 0;
+
+ if ((strcmp("HP8924C", commanalyzerType) == 0)) {
+ // Send request
+ printf("[INFO] Getting spectrum analyzer frequency span\n\r");
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ sprintf(falpha,"SAN:SPAN?");
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Writing: %s\n\r", falpha);
+ #endif
+ if (gpib_write(gpibDevice, falpha) == 0) {
+ max_num_bytes = 24; // Request more bytes than are possible to ensure no bytes are left behind
+ }
+ else {
+ return 2;
+ }
+ }
+
+ // Read response
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
+ #endif
+
+ ibtmo(gpibDevice, T10s);
+ ibeos(gpibDevice, 0x0);
+
+ ai = gpib_read_array(gpibDevice, max_num_bytes, segarray);
+ if (ai == -1) {
+ return 1;
+ }
+ else {
+ if (strcmp("HP8924C", commanalyzerType) == 0) {
+ left_char = 1;
+ right_char = 0;
+ array_pointer = 0;
+ for (right_char=left_char;right_char<ai;right_char++) {
+ if (segarray[right_char] == ' ') {
+ break;
+ }
+ }
+ strncpy(floatstring, segarray+left_char, right_char-left_char);
+ floatstring[right_char-left_char] = 0;
+ *retval = atof(floatstring);
+ }
+ else {
+ return 2;
+ }
+ }
+
+ ibtmo(gpibDevice, T10s);
+
+ #ifdef ENABLE_EXTRA_DEBUGGING
+ printf("[DEBG] Read %li bytes from GPIB device\n", ai);
+ #endif
+
+ return 0;
+ }
+ else {
+ return -1;
+ }
} \ No newline at end of file
diff --git a/servers/gpib_server_lin/src/commanalyzer_functions.h b/servers/gpib_server_lin/src/commanalyzer_functions.h
index 9c06e4d..50f1474 100644
--- a/servers/gpib_server_lin/src/commanalyzer_functions.h
+++ b/servers/gpib_server_lin/src/commanalyzer_functions.h
@@ -47,4 +47,10 @@ int commanalyzer_spectrum_analyzer_set_generator_sweep_ascending (char * commana
int commanalyzer_spectrum_analyzer_set_generator_sweep_descending (char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_trace_averaging(float desired_avg_samples, char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_reference_power_level(float desired_reflevel, char * commanalyzerType, int gpibDevice);
-int commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions( char * commanalyzerType, int gpibDevice); \ No newline at end of file
+int commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions( char * commanalyzerType, int gpibDevice);
+int commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions( char * commanalyzerType, int gpibDevice);
+
+double commanalyzer_get_spectrum_analyzer_reference_power_level (double * retval, char * commanalyzerType, int gpibDevice);
+double commanalyzer_get_spectrum_analyzer_scale (double * retval, char * commanalyzerType, int gpibDevice);
+double commanalyzer_get_spectrum_analyzer_center_frequency (double * retval, char * commanalyzerType, int gpibDevice);
+double commanalyzer_get_spectrum_analyzer_span (double * retval, char * commanalyzerType, int gpibDevice); \ No newline at end of file
diff --git a/servers/gpib_server_lin/src/main_server_lin.c b/servers/gpib_server_lin/src/main_server_lin.c
index 7184ab4..9788566 100644
--- a/servers/gpib_server_lin/src/main_server_lin.c
+++ b/servers/gpib_server_lin/src/main_server_lin.c
@@ -694,6 +694,9 @@ int mainserver(int fd) {
bytestosend = bytestosend - return_status;
k++;
}
+ else {
+ bytestosend = 0;
+ }
}
}
else {
@@ -704,7 +707,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK", strlen("NCK"));
}
}
- if (readbuf[0] == 22) { // Want to change horizontal timebase
+ else if (readbuf[0] == 22) { // Want to change horizontal timebase
buffer_lookfor_termdegree(readbuf, 25);
if (scope_set_timebase(atof(readbuf), scopeType, scope_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -713,7 +716,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 23) { // Want to change volts per division
+ else if (readbuf[0] == 23) { // Want to change volts per division
buffer_lookfor_two_termdegree(readbuf, readbuf2, 25);
if (scope_set_volts_div(atoi(readbuf), atof(readbuf2), scopeType, scope_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -722,7 +725,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 24) { // Want to change run status
+ else if (readbuf[0] == 24) { // Want to change run status
buffer_lookfor_termdegree(readbuf, 25);
if (scope_set_acquisition(atoi(readbuf), scopeType, scope_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -731,7 +734,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 25) { // Want to change channel enable
+ else if (readbuf[0] == 25) { // Want to change channel enable
buffer_lookfor_two_termdegree(readbuf, readbuf2, 25);
if (scope_set_channel_state(atoi(readbuf), atoi(readbuf2), scopeType, scope_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -740,7 +743,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 26) { // Want to change trigger channel
+ else if (readbuf[0] == 26) { // Want to change trigger channel
buffer_lookfor_termdegree(readbuf, 25);
if (scope_set_trigger_channel(atoi(readbuf), scopeType, scope_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -749,7 +752,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 27) { // Want to change trigger level
+ else if (readbuf[0] == 27) { // Want to change trigger level
buffer_lookfor_termdegree(readbuf, 25);
if (scope_set_trigger_level(atof(readbuf), scopeType, scope_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -758,7 +761,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 28) { // Want to change channel vertical position
+ else if (readbuf[0] == 28) { // Want to change channel vertical position
buffer_lookfor_two_termdegree(readbuf, readbuf2, 25);
if (scope_set_channel_position(atoi(readbuf), atof(readbuf2), scopeType, scope_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -784,11 +787,11 @@ int mainserver(int fd) {
quiet_write(fd, errorbuf, strlen(errorbuf));
}
}
- if (readbuf[0] == 41) { // Is function generator configured?
+ else if (readbuf[0] == 41) { // Is function generator configured?
// If I'm in state 6 it had *better* be available!!!
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
- if (readbuf[0] == 42) { // Want to change frequency
+ else if (readbuf[0] == 42) { // Want to change frequency
buffer_lookfor_termdegree(readbuf, 25);
if (signal_set_frequency(atof(readbuf), funcgenType, funcgen_board_device, errorbuf) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -797,7 +800,7 @@ int mainserver(int fd) {
quiet_write(fd, errorbuf, strlen(errorbuf));
}
}
- if (readbuf[0] == 43) { // Want to change duty cycle
+ else if (readbuf[0] == 43) { // Want to change duty cycle
buffer_lookfor_termdegree(readbuf, 25);
if (signal_set_duty_cycle(atof(readbuf), funcgenType, funcgen_board_device, errorbuf) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -806,7 +809,7 @@ int mainserver(int fd) {
quiet_write(fd, errorbuf, strlen(errorbuf));
}
}
- if (readbuf[0] == 44) { // Want to set square wave
+ else if (readbuf[0] == 44) { // Want to set square wave
if (signal_set_waveform("SQUARE", funcgenType, funcgen_board_device, errorbuf) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
@@ -814,7 +817,7 @@ int mainserver(int fd) {
quiet_write(fd, errorbuf, strlen(errorbuf));
}
}
- if (readbuf[0] == 45) { // Want to set sine wave
+ else if (readbuf[0] == 45) { // Want to set sine wave
if (signal_set_waveform("SINUSOID", funcgenType, funcgen_board_device, errorbuf) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
@@ -822,7 +825,7 @@ int mainserver(int fd) {
quiet_write(fd, errorbuf, strlen(errorbuf));
}
}
- if (readbuf[0] == 46) { // Want to set triangle wave
+ else if (readbuf[0] == 46) { // Want to set triangle wave
if (signal_set_waveform("RAMP", funcgenType, funcgen_board_device, errorbuf) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
@@ -830,7 +833,7 @@ int mainserver(int fd) {
quiet_write(fd, errorbuf, strlen(errorbuf));
}
}
- if (readbuf[0] == 47) { // Want to set noise wave
+ else if (readbuf[0] == 47) { // Want to set noise wave
if (signal_set_waveform("NOISE", funcgenType, funcgen_board_device, errorbuf) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
@@ -838,7 +841,7 @@ int mainserver(int fd) {
quiet_write(fd, errorbuf, strlen(errorbuf));
}
}
- if (readbuf[0] == 48) { // Want to change P-P voltage
+ else if (readbuf[0] == 48) { // Want to change P-P voltage
buffer_lookfor_termdegree(readbuf, 25);
if (signal_set_peak_peak_voltage(atof(readbuf), funcgenType, funcgen_board_device, errorbuf) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -847,7 +850,7 @@ int mainserver(int fd) {
quiet_write(fd, errorbuf, strlen(errorbuf));
}
}
- if (readbuf[0] == 49) { // Want to change offset voltage
+ else if (readbuf[0] == 49) { // Want to change offset voltage
buffer_lookfor_termdegree(readbuf, 25);
if (signal_set_offset_voltage(atof(readbuf), funcgenType, funcgen_board_device, errorbuf) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -873,39 +876,46 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 41) { // Is communications analyzer configured?
+ else if (readbuf[0] == 41) { // Is communications analyzer configured?
// If I'm in state 7 it had *better* be available!!!
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
- if ((readbuf[0] == 42)) { // Want SA trace
- quiet_write(fd, "ACK", strlen("ACK"));
+ else if ((readbuf[0] == 42)) { // Want SA trace
+ quiet_write(fd, "ACK\r", strlen("ACK\r"));
fsync(fd);
if (commanalyzer_get_spectrum_analyzer_trace(commanalyzerType, commanalyzer_board_device) == 0) {
bytestosend = commanalyzerTraceLength(commanalyzerType)*sizeof(double);
int16_t numbytes = bytestosend;
quiet_write(fd, &numbytes, 2);
+ quiet_write(fd, "\r", 1);
+ fsync(fd);
k=0;
while (bytestosend > 0) {
- return_status = write(fd, commanalyzer_raw_trace_data+k, 1);
+ return_status = write(fd, ((uint8_t*)commanalyzer_raw_trace_data)+k, 1);
if (return_status > 0) {
bytestosend = bytestosend - return_status;
k++;
}
+ else {
+ bytestosend = 0;
+ }
}
+ fsync(fd);
}
else {
quiet_write(fd, "NCK", strlen("NCK"));
}
}
- if (readbuf[0] == 43) { // Want to lock screen
+ else if (readbuf[0] == 43) { // Want to lock screen
if (commanalyzer_lock_screen(commanalyzerType, commanalyzer_board_device) == 0) {
+ commanalyzer_set_display_brightness(0, commanalyzerType, commanalyzer_board_device); // Don't burn in the screen
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
else {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 44) { // Want to set generator to tracking mode
+ else if (readbuf[0] == 44) { // Want to set generator to tracking mode
if (commanalyzer_spectrum_analyzer_set_generator_mode_tracking(commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
@@ -913,7 +923,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 45) { // Want to set generator to fixed mode
+ else if (readbuf[0] == 45) { // Want to set generator to fixed mode
if (commanalyzer_spectrum_analyzer_set_generator_mode_fixed(commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
@@ -921,7 +931,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 46) { // Want to change center frequency
+ else if (readbuf[0] == 46) { // Want to change center frequency
buffer_lookfor_termdegree(readbuf, 25);
if (commanalyzer_set_spectrum_analyzer_center_frequency(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -930,7 +940,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 47) { // Want to change frequency span
+ else if (readbuf[0] == 47) { // Want to change frequency span
buffer_lookfor_termdegree(readbuf, 25);
if (commanalyzer_set_spectrum_analyzer_frequency_span(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -939,7 +949,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 48) { // Want to set RF input to dedicated connector
+ else if (readbuf[0] == 48) { // Want to set RF input to dedicated connector
if (commanalyzer_spectrum_analyzer_set_rf_input_dedicated(commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
@@ -947,7 +957,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 49) { // Want to set RF input to multiplexed connector
+ else if (readbuf[0] == 49) { // Want to set RF input to multiplexed connector
if (commanalyzer_spectrum_analyzer_set_rf_input_muxed(commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
@@ -955,7 +965,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 50) { // Want to set generator output to dedicated connector
+ else if (readbuf[0] == 50) { // Want to set generator output to dedicated connector
if (commanalyzer_spectrum_analyzer_set_generator_output_dedicated(commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
@@ -963,7 +973,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 51) { // Want to set generator output to multiplexed connector
+ else if (readbuf[0] == 51) { // Want to set generator output to multiplexed connector
if (commanalyzer_spectrum_analyzer_set_generator_output_muxed(commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
@@ -971,7 +981,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 52) { // Want to change input attenuation
+ else if (readbuf[0] == 52) { // Want to change input attenuation
buffer_lookfor_termdegree(readbuf, 25);
if (commanalyzer_set_spectrum_analyzer_input_attenuation(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -980,7 +990,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 53) { // Want to change scale
+ else if (readbuf[0] == 53) { // Want to change scale
buffer_lookfor_termdegree(readbuf, 25);
if (commanalyzer_set_spectrum_analyzer_scale(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -989,7 +999,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 54) { // Want to set RF input attenuator mode to automatic
+ else if (readbuf[0] == 54) { // Want to set RF input attenuator mode to automatic
if (commanalyzer_set_spectrum_analyzer_input_attenuator_mode_auto(commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
@@ -997,7 +1007,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 55) { // Want to set RF input attenuator mode to fixed
+ else if (readbuf[0] == 55) { // Want to set RF input attenuator mode to fixed
if (commanalyzer_set_spectrum_analyzer_input_attenuator_mode_fixed(commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
@@ -1005,7 +1015,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 56) { // Want to change generator output power
+ else if (readbuf[0] == 56) { // Want to change generator output power
buffer_lookfor_termdegree(readbuf, 25);
if (commanalyzer_set_spectrum_analyzer_generator_power(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -1014,7 +1024,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 57) { // Want to change generator output frequency
+ else if (readbuf[0] == 57) { // Want to change generator output frequency
buffer_lookfor_termdegree(readbuf, 25);
if (commanalyzer_set_spectrum_analyzer_generator_frequency(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -1023,7 +1033,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 58) { // Want to set generator sweep to ascending
+ else if (readbuf[0] == 58) { // Want to set generator sweep to ascending
if (commanalyzer_spectrum_analyzer_set_generator_sweep_ascending(commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
@@ -1031,7 +1041,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 59) { // Want to set generator sweep to descending
+ else if (readbuf[0] == 59) { // Want to set generator sweep to descending
if (commanalyzer_spectrum_analyzer_set_generator_sweep_descending(commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
}
@@ -1039,7 +1049,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 60) { // Want to set trace averaging
+ else if (readbuf[0] == 60) { // Want to set trace averaging
buffer_lookfor_termdegree(readbuf, 25);
if (commanalyzer_set_spectrum_analyzer_trace_averaging(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -1048,7 +1058,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 61) { // Want to set reference power level
+ else if (readbuf[0] == 61) { // Want to set reference power level
buffer_lookfor_termdegree(readbuf, 25);
if (commanalyzer_set_spectrum_analyzer_reference_power_level(atof(readbuf), commanalyzerType, commanalyzer_board_device) == 0) {
quiet_write(fd, "ACK\r", strlen("ACK\r"));
@@ -1057,7 +1067,7 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
- if (readbuf[0] == 62) { // Want the number of vertical divisions available
+ else if (readbuf[0] == 62) { // Want the number of vertical divisions available
int16_t divisions = commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions(commanalyzerType, commanalyzer_board_device);
if (divisions >= 0) {
quiet_write(fd, &divisions, 2);
@@ -1067,6 +1077,72 @@ int mainserver(int fd) {
quiet_write(fd, "NCK\r", strlen("NCK\r"));
}
}
+ else if (readbuf[0] == 63) { // Want the number of samples in a trace
+ int16_t divisions = commanalyzerTraceLength(commanalyzerType);
+ if (divisions >= 0) {
+ quiet_write(fd, &divisions, 2);
+ quiet_write(fd, "ACK\r", strlen("ACK\r"));
+ }
+ else {
+ quiet_write(fd, &divisions, 2);
+ quiet_write(fd, "NCK\r", strlen("NCK\r"));
+ }
+ }
+ else if (readbuf[0] == 64) { // Want the number of horizontal divisions available
+ int16_t divisions = commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions(commanalyzerType, commanalyzer_board_device);
+ if (divisions >= 0) {
+ quiet_write(fd, &divisions, 2);
+ quiet_write(fd, "ACK\r", strlen("ACK\r"));
+ }
+ else {
+ quiet_write(fd, &divisions, 2);
+ quiet_write(fd, "NCK\r", strlen("NCK\r"));
+ }
+ }
+ else if (readbuf[0] == 65) { // Want the reference power level
+ double rpower;
+ if (commanalyzer_get_spectrum_analyzer_reference_power_level(&rpower, commanalyzerType, commanalyzer_board_device) == 0) {
+ quiet_write(fd, &rpower, sizeof(double));
+ quiet_write(fd, "ACK\r", strlen("ACK\r"));
+ }
+ else {
+ quiet_write(fd, &rpower, sizeof(double));
+ quiet_write(fd, "NCK\r", strlen("NCK\r"));
+ }
+ }
+ else if (readbuf[0] == 66) { // Want the vertical division scale
+ double scale;
+ if (commanalyzer_get_spectrum_analyzer_scale(&scale, commanalyzerType, commanalyzer_board_device) == 0) {
+ quiet_write(fd, &scale, sizeof(double));
+ quiet_write(fd, "ACK\r", strlen("ACK\r"));
+ }
+ else {
+ quiet_write(fd, &scale, sizeof(double));
+ quiet_write(fd, "NCK\r", strlen("NCK\r"));
+ }
+ }
+ else if (readbuf[0] == 67) { // Want to get the center frequency
+ double freq;
+ if (commanalyzer_get_spectrum_analyzer_center_frequency(&freq, commanalyzerType, commanalyzer_board_device) == 0) {
+ quiet_write(fd, &freq, sizeof(double));
+ quiet_write(fd, "ACK\r", strlen("ACK\r"));
+ }
+ else {
+ quiet_write(fd, &freq, sizeof(double));
+ quiet_write(fd, "NCK\r", strlen("NCK\r"));
+ }
+ }
+ else if (readbuf[0] == 68) { // Want to get the frequency span
+ double freq;
+ if (commanalyzer_get_spectrum_analyzer_span(&freq, commanalyzerType, commanalyzer_board_device) == 0) {
+ quiet_write(fd, &freq, sizeof(double));
+ quiet_write(fd, "ACK\r", strlen("ACK\r"));
+ }
+ else {
+ quiet_write(fd, &freq, sizeof(double));
+ quiet_write(fd, "NCK\r", strlen("NCK\r"));
+ }
+ }
}
break;
case 2: // Open the serial port
@@ -1114,6 +1190,9 @@ int main(int argc, char *argv[])
server_multiplexer.tv_sec = 0;
server_multiplexer.tv_usec = 10;
+ // Register signal handler
+ signal(SIGPIPE, signal_handler_IO);
+
printf("RemoteFPGA GPIB Server v%s.%s%s\n\r", SERVER_MAJOR, SERVER_MINOR, SERVER_REVISION);
printf("(c) %s Timothy Pearson\n\r", COPYRIGHT_DATE);
printf("(c) %s Remote Laboratory FOSS Contributors\n\r", FOSS_COPYRIGHT_DATE);