Add serial port instrument support

master
Timothy Pearson 12 years ago
parent d8ef27cb45
commit b0fcdb64bd

@ -1,11 +1,11 @@
INCLUDES= $(all_includes) $(KDE_INCLUDES)/tde -I/usr/include/sasl
KDE_CXXFLAGS = $(USE_EXCEPTIONS)
bin_PROGRAMS = remotefpga_fpgaprogserver
bin_PROGRAMS = remotefpga_gpibserver
remotefpga_fpgaprogserver_SOURCES = main.cpp fpga_conn.cpp
remotefpga_gpibserver_SOURCES = commanalyzer_functions.cpp gpib_functions.cpp scope_functions.cpp signal_functions.cpp main.cpp gpib_conn.cpp
remotefpga_fpgaprogserver_METASOURCES = AUTO
remotefpga_fpgaprogserver_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_KIO) -lktexteditor -ltdekrbsocket -ltqtrla
remotefpga_gpibserver_METASOURCES = AUTO
remotefpga_gpibserver_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_KIO) -lktexteditor -ltdekrbsocket -ltqtrla -lgpib
KDE_OPTIONS = nofinal

@ -21,6 +21,7 @@
*/
#include <ctype.h>
#include <ctime>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
@ -28,15 +29,14 @@
#include <stdint.h>
#include <string.h>
#include <getopt.h>
#include <allegro.h>
#include "parameters.h"
#include "gpib_functions.h"
#include "gpib/ib.h"
char falpha[1024];
extern char falpha[1024];
double commanalyzer_raw_trace_data[1024];
unsigned long commanalyzerTraceLength (char * commanalyzerType) {
unsigned long commanalyzerTraceLength (const char * commanalyzerType) {
if (strcmp("HP8924C", commanalyzerType) == 0) {
return 417;
}
@ -45,7 +45,7 @@ unsigned long commanalyzerTraceLength (char * commanalyzerType) {
}
}
int commanalyzer_set_date(struct tm * datetime, char * commanalyzerType, int gpibDevice) {
int commanalyzer_set_date(struct tm * datetime, const char * commanalyzerType, int gpibDevice) {
char datebuffer [80];
strftime(datebuffer,80,"CONF:DATE %m%d%y",datetime);
@ -62,13 +62,16 @@ int commanalyzer_set_date(struct tm * datetime, char * commanalyzerType, int gpi
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_set_time(struct tm * datetime, char * commanalyzerType, int gpibDevice) {
int commanalyzer_set_time(struct tm * datetime, const char * commanalyzerType, int gpibDevice) {
char timebuffer [80];
strftime(timebuffer,80,"CONF:TIME +%H.%M",datetime); // FIXME wrong format
@ -85,13 +88,16 @@ int commanalyzer_set_time(struct tm * datetime, char * commanalyzerType, int gpi
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_switch_to_spectrum_analyzer_mode(char * commanalyzerType, int gpibDevice) {
int commanalyzer_switch_to_spectrum_analyzer_mode(const char * commanalyzerType, int gpibDevice) {
if (strcmp("HP8924C", commanalyzerType) == 0) {
printf("[INFO] Setting communications analyzer to spectrum anayzer mode\n\r");
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -106,13 +112,16 @@ int commanalyzer_switch_to_spectrum_analyzer_mode(char * commanalyzerType, int g
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_lock_screen (char * commanalyzerType, int gpibDevice) {
int commanalyzer_lock_screen (const char * commanalyzerType, int gpibDevice) {
if (strcmp("HP8924C", commanalyzerType) == 0) {
printf("[INFO] Locking communications analyzer screen\n\r");
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -127,13 +136,16 @@ int commanalyzer_lock_screen (char * commanalyzerType, int gpibDevice) {
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_spectrum_analyzer_set_generator_mode_tracking (char * commanalyzerType, int gpibDevice) {
int commanalyzer_spectrum_analyzer_set_generator_mode_tracking (const char * commanalyzerType, int gpibDevice) {
if (strcmp("HP8924C", commanalyzerType) == 0) {
printf("[INFO] Setting spectrum analyzer generator to tracking mode\n\r");
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -148,13 +160,16 @@ int commanalyzer_spectrum_analyzer_set_generator_mode_tracking (char * commanaly
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_spectrum_analyzer_set_generator_mode_fixed (char * commanalyzerType, int gpibDevice) {
int commanalyzer_spectrum_analyzer_set_generator_mode_fixed (const char * commanalyzerType, int gpibDevice) {
if (strcmp("HP8924C", commanalyzerType) == 0) {
printf("[INFO] Setting spectrum analyzer generator to fixed mode\n\r");
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -169,13 +184,16 @@ int commanalyzer_spectrum_analyzer_set_generator_mode_fixed (char * commanalyzer
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_spectrum_analyzer_set_rf_input_dedicated (char * commanalyzerType, int gpibDevice) {
int commanalyzer_spectrum_analyzer_set_rf_input_dedicated (const char * commanalyzerType, int gpibDevice) {
if (strcmp("HP8924C", commanalyzerType) == 0) {
printf("[INFO] Setting spectrum analyzer RF input to dedicated connector\n\r");
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -190,13 +208,16 @@ int commanalyzer_spectrum_analyzer_set_rf_input_dedicated (char * commanalyzerTy
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_spectrum_analyzer_set_rf_input_muxed (char * commanalyzerType, int gpibDevice) {
int commanalyzer_spectrum_analyzer_set_rf_input_muxed (const char * commanalyzerType, int gpibDevice) {
if (strcmp("HP8924C", commanalyzerType) == 0) {
printf("[INFO] Setting spectrum analyzer RF input to multiplexed connector\n\r");
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -211,13 +232,16 @@ int commanalyzer_spectrum_analyzer_set_rf_input_muxed (char * commanalyzerType,
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_spectrum_analyzer_set_generator_output_dedicated (char * commanalyzerType, int gpibDevice) {
int commanalyzer_spectrum_analyzer_set_generator_output_dedicated (const char * commanalyzerType, int gpibDevice) {
if (strcmp("HP8924C", commanalyzerType) == 0) {
printf("[INFO] Setting spectrum analyzer generator output to dedicated connector\n\r");
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -232,13 +256,16 @@ int commanalyzer_spectrum_analyzer_set_generator_output_dedicated (char * comman
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_spectrum_analyzer_set_generator_output_muxed (char * commanalyzerType, int gpibDevice) {
int commanalyzer_spectrum_analyzer_set_generator_output_muxed (const char * commanalyzerType, int gpibDevice) {
if (strcmp("HP8924C", commanalyzerType) == 0) {
printf("[INFO] Setting spectrum analyzer generator output to multiplexed connector\n\r");
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -253,25 +280,25 @@ int commanalyzer_spectrum_analyzer_set_generator_output_muxed (char * commanalyz
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_get_spectrum_analyzer_trace(char * commanalyzerType, int gpibDevice) {
int commanalyzer_get_spectrum_analyzer_trace(const char * commanalyzerType, int gpibDevice) {
int max_num_bytes = 0;
unsigned char segarray[4194304];
unsigned char floatstring[1024];
char segarray[4194304];
char floatstring[1024];
long array_pointer;
long ai;
long left_char;
long right_char;
int x;
int y;
if ((strcmp("HP8924C", commanalyzerType) == 0)) {
// Send request
printf("[INFO] Getting spectrum analyzer trace [Stage 1]\n\r");
@ -331,9 +358,12 @@ int commanalyzer_get_spectrum_analyzer_trace(char * commanalyzerType, int gpibDe
return 0;
}
else {
return 1;
}
}
int commanalyzer_set_spectrum_analyzer_center_frequency(float desired_frequency, char * commanalyzerType, int gpibDevice) {
int commanalyzer_set_spectrum_analyzer_center_frequency(float desired_frequency, const char * commanalyzerType, int gpibDevice) {
if ((strcmp("HP8924C", commanalyzerType) == 0)) {
printf("[INFO] Setting spectrum analyzer center frequency to %f\n\r", desired_frequency);
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -348,13 +378,16 @@ int commanalyzer_set_spectrum_analyzer_center_frequency(float desired_frequency,
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_set_spectrum_analyzer_frequency_span(float desired_frequency, char * commanalyzerType, int gpibDevice) {
int commanalyzer_set_spectrum_analyzer_frequency_span(float desired_frequency, const char * commanalyzerType, int gpibDevice) {
if ((strcmp("HP8924C", commanalyzerType) == 0)) {
printf("[INFO] Setting spectrum analyzer span frequency to %f\n\r", desired_frequency);
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -369,13 +402,16 @@ int commanalyzer_set_spectrum_analyzer_frequency_span(float desired_frequency, c
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_set_spectrum_analyzer_input_attenuation(float desired_attenuation, char * commanalyzerType, int gpibDevice) {
int commanalyzer_set_spectrum_analyzer_input_attenuation(float desired_attenuation, const char * commanalyzerType, int gpibDevice) {
int instrument_att;
if ((strcmp("HP8924C", commanalyzerType) == 0)) {
@ -391,6 +427,9 @@ int commanalyzer_set_spectrum_analyzer_input_attenuation(float desired_attenuati
instrument_att = 40;
}
}
else {
return 1;
}
printf("[INFO] Setting spectrum analyzer attenuation to %d dB\n\r", instrument_att);
if (strcmp("HP8924C", commanalyzerType) == 0) {
sprintf(falpha,"SAN:ATT '%d DB'", instrument_att);
@ -404,13 +443,16 @@ int commanalyzer_set_spectrum_analyzer_input_attenuation(float desired_attenuati
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_set_spectrum_analyzer_scale(float desired_scale, char * commanalyzerType, int gpibDevice) {
int commanalyzer_set_spectrum_analyzer_scale(float desired_scale, const char * commanalyzerType, int gpibDevice) {
int instrument_scale;
if ((strcmp("HP8924C", commanalyzerType) == 0)) {
@ -426,6 +468,9 @@ int commanalyzer_set_spectrum_analyzer_scale(float desired_scale, char * commana
instrument_scale = 10;
}
}
else {
return 1;
}
printf("[INFO] Setting spectrum analyzer scale to %d dB/div\n\r", instrument_scale);
if (strcmp("HP8924C", commanalyzerType) == 0) {
sprintf(falpha,"SAN:DISP:SCAL '%d DB/DIV'", instrument_scale);
@ -439,13 +484,16 @@ int commanalyzer_set_spectrum_analyzer_scale(float desired_scale, char * commana
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_set_spectrum_analyzer_input_attenuator_mode_auto( char * commanalyzerType, int gpibDevice) {
int commanalyzer_set_spectrum_analyzer_input_attenuator_mode_auto( const char * commanalyzerType, int gpibDevice) {
if ((strcmp("HP8924C", commanalyzerType) == 0)) {
printf("[INFO] Setting spectrum analyzer attenuation mode to automatic\n\r");
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -460,13 +508,16 @@ int commanalyzer_set_spectrum_analyzer_input_attenuator_mode_auto( char * comman
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_set_spectrum_analyzer_input_attenuator_mode_fixed( char * commanalyzerType, int gpibDevice) {
int commanalyzer_set_spectrum_analyzer_input_attenuator_mode_fixed( const char * commanalyzerType, int gpibDevice) {
if ((strcmp("HP8924C", commanalyzerType) == 0)) {
printf("[INFO] Setting spectrum analyzer attenuation mode to fixed\n\r");
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -481,13 +532,16 @@ int commanalyzer_set_spectrum_analyzer_input_attenuator_mode_fixed( char * comma
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_set_spectrum_analyzer_generator_power(float desired_power, char * commanalyzerType, int gpibDevice) {
int commanalyzer_set_spectrum_analyzer_generator_power(float desired_power, const char * commanalyzerType, int gpibDevice) {
if ((strcmp("HP8924C", commanalyzerType) == 0)) {
printf("[INFO] Setting spectrum analyzer generator power to %f\n\r", desired_power);
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -502,13 +556,16 @@ int commanalyzer_set_spectrum_analyzer_generator_power(float desired_power, char
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_set_spectrum_analyzer_generator_frequency(float desired_frequency, char * commanalyzerType, int gpibDevice) {
int commanalyzer_set_spectrum_analyzer_generator_frequency(float desired_frequency, const char * commanalyzerType, int gpibDevice) {
if ((strcmp("HP8924C", commanalyzerType) == 0)) {
printf("[INFO] Setting spectrum analyzer generator frequency to %f\n\r", desired_frequency);
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -523,13 +580,16 @@ int commanalyzer_set_spectrum_analyzer_generator_frequency(float desired_frequen
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_spectrum_analyzer_set_generator_sweep_ascending (char * commanalyzerType, int gpibDevice) {
int commanalyzer_spectrum_analyzer_set_generator_sweep_ascending (const char * commanalyzerType, int gpibDevice) {
if (strcmp("HP8924C", commanalyzerType) == 0) {
printf("[INFO] Setting spectrum analyzer generator output sweep to ascending\n\r");
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -544,13 +604,16 @@ int commanalyzer_spectrum_analyzer_set_generator_sweep_ascending (char * commana
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_spectrum_analyzer_set_generator_sweep_descending (char * commanalyzerType, int gpibDevice) {
int commanalyzer_spectrum_analyzer_set_generator_sweep_descending (const char * commanalyzerType, int gpibDevice) {
if (strcmp("HP8924C", commanalyzerType) == 0) {
printf("[INFO] Setting spectrum analyzer generator output sweep to descending\n\r");
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -565,13 +628,16 @@ int commanalyzer_spectrum_analyzer_set_generator_sweep_descending (char * comman
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_set_spectrum_analyzer_trace_averaging(float desired_avg_samples, char * commanalyzerType, int gpibDevice) {
int commanalyzer_set_spectrum_analyzer_trace_averaging(float desired_avg_samples, const char * commanalyzerType, int gpibDevice) {
if ((strcmp("HP8924C", commanalyzerType) == 0)) {
int instrument_samples;
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -598,6 +664,9 @@ int commanalyzer_set_spectrum_analyzer_trace_averaging(float desired_avg_samples
}
}
}
else {
return 1;
}
printf("[INFO] Setting spectrum analyzer generator trace averaging to %d\n\r", instrument_samples);
if (strcmp("HP8924C", commanalyzerType) == 0) {
if (instrument_samples > 0) {
@ -619,13 +688,16 @@ int commanalyzer_set_spectrum_analyzer_trace_averaging(float desired_avg_samples
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_set_spectrum_analyzer_reference_power_level(float desired_reflevel, char * commanalyzerType, int gpibDevice) {
int commanalyzer_set_spectrum_analyzer_reference_power_level(float desired_reflevel, const char * commanalyzerType, int gpibDevice) {
if ((strcmp("HP8924C", commanalyzerType) == 0)) {
printf("[INFO] Setting spectrum analyzer generator reference level to %f dBm\n\r", desired_reflevel);
if (strcmp("HP8924C", commanalyzerType) == 0) {
@ -640,13 +712,16 @@ int commanalyzer_set_spectrum_analyzer_reference_power_level(float desired_refle
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
int commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions( char * commanalyzerType, int gpibDevice) {
int commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions( const char * commanalyzerType, int gpibDevice) {
if ((strcmp("HP8924C", commanalyzerType) == 0)) {
return 8;
}
@ -655,7 +730,7 @@ int commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions( char * comm
}
}
int commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions( char * commanalyzerType, int gpibDevice) {
int commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions( const char * commanalyzerType, int gpibDevice) {
if ((strcmp("HP8924C", commanalyzerType) == 0)) {
return 10;
}
@ -664,9 +739,9 @@ int commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions( char * co
}
}
double commanalyzer_get_spectrum_analyzer_reference_power_level(double * retval, char * commanalyzerType, int gpibDevice) {
unsigned char segarray[4194304];
unsigned char floatstring[1024];
double commanalyzer_get_spectrum_analyzer_reference_power_level(double * retval, const char * commanalyzerType, int gpibDevice) {
char segarray[4194304];
char floatstring[1024];
long array_pointer;
long ai;
long left_char;
@ -689,6 +764,9 @@ double commanalyzer_get_spectrum_analyzer_reference_power_level(double * retval,
return 2;
}
}
else {
return 1;
}
// Read response
#ifdef ENABLE_EXTRA_DEBUGGING
@ -725,9 +803,9 @@ double commanalyzer_get_spectrum_analyzer_reference_power_level(double * retval,
}
}
double commanalyzer_get_spectrum_analyzer_scale(double * retval, char * commanalyzerType, int gpibDevice) {
unsigned char segarray[4194304];
unsigned char floatstring[1024];
double commanalyzer_get_spectrum_analyzer_scale(double * retval, const char * commanalyzerType, int gpibDevice) {
char segarray[4194304];
char floatstring[1024];
long array_pointer;
long ai;
long left_char;
@ -750,6 +828,9 @@ double commanalyzer_get_spectrum_analyzer_scale(double * retval, char * commanal
return 2;
}
}
else {
return 1;
}
// Read response
#ifdef ENABLE_EXTRA_DEBUGGING
@ -795,13 +876,16 @@ double commanalyzer_get_spectrum_analyzer_scale(double * retval, char * commanal
}
}
int commanalyzer_set_display_brightness(float percent, char * commanalyzerType, int gpibDevice) {
int commanalyzer_set_display_brightness(float percent, const 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;
}
else {
return 1;
}
printf("[INFO] Setting display brightness to %d\n\r", instrument_scale);
if (strcmp("HP8924C", commanalyzerType) == 0) {
sprintf(falpha,"CONF:INT %d", instrument_scale);
@ -815,15 +899,18 @@ int commanalyzer_set_display_brightness(float percent, char * commanalyzerType,
return 2;
}
}
else {
return 1;
}
}
else {
return 1;
}
}
double commanalyzer_get_spectrum_analyzer_center_frequency(double * retval, char * commanalyzerType, int gpibDevice) {
unsigned char segarray[4194304];
unsigned char floatstring[1024];
double commanalyzer_get_spectrum_analyzer_center_frequency(double * retval, const char * commanalyzerType, int gpibDevice) {
char segarray[4194304];
char floatstring[1024];
long array_pointer;
long ai;
long left_char;
@ -846,6 +933,9 @@ double commanalyzer_get_spectrum_analyzer_center_frequency(double * retval, char
return 2;
}
}
else {
return 1;
}
// Read response
#ifdef ENABLE_EXTRA_DEBUGGING
@ -891,9 +981,9 @@ double commanalyzer_get_spectrum_analyzer_center_frequency(double * retval, char
}
}
double commanalyzer_get_spectrum_analyzer_span(double * retval, char * commanalyzerType, int gpibDevice) {
unsigned char segarray[4194304];
unsigned char floatstring[1024];
double commanalyzer_get_spectrum_analyzer_span(double * retval, const char * commanalyzerType, int gpibDevice) {
char segarray[4194304];
char floatstring[1024];
long array_pointer;
long ai;
long left_char;

@ -22,35 +22,35 @@
extern double commanalyzer_raw_trace_data[1024];
unsigned long commanalyzerTraceLength (char * commanalyzerType);
int commanalyzer_set_date(struct tm * datetime, char * commanalyzerType, int gpibDevice);
int commanalyzer_set_time(struct tm * datetime, char * commanalyzerType, int gpibDevice);
int commanalyzer_switch_to_spectrum_analyzer_mode (char * commanalyzerType, int gpibDevice);
int commanalyzer_lock_screen (char * commanalyzerType, int gpibDevice);
unsigned long commanalyzerTraceLength (const char * commanalyzerType);
int commanalyzer_set_date(struct tm * datetime, const char * commanalyzerType, int gpibDevice);
int commanalyzer_set_time(struct tm * datetime, const char * commanalyzerType, int gpibDevice);
int commanalyzer_switch_to_spectrum_analyzer_mode (const char * commanalyzerType, int gpibDevice);
int commanalyzer_lock_screen (const char * commanalyzerType, int gpibDevice);
int commanalyzer_get_spectrum_analyzer_trace (char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_center_frequency(float desired_frequency, char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_frequency_span(float desired_frequency, char * commanalyzerType, int gpibDevice);
int commanalyzer_spectrum_analyzer_set_generator_mode_tracking (char * commanalyzerType, int gpibDevice);
int commanalyzer_spectrum_analyzer_set_generator_mode_fixed (char * commanalyzerType, int gpibDevice);
int commanalyzer_spectrum_analyzer_set_rf_input_dedicated (char * commanalyzerType, int gpibDevice);
int commanalyzer_spectrum_analyzer_set_rf_input_muxed (char * commanalyzerType, int gpibDevice);
int commanalyzer_spectrum_analyzer_set_generator_output_dedicated (char * commanalyzerType, int gpibDevice);
int commanalyzer_spectrum_analyzer_set_generator_output_muxed (char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_input_attenuation(float desired_attenuation, char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_scale(float desired_scale, char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_input_attenuator_mode_auto( char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_input_attenuator_mode_fixed( char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_generator_power(float desired_power, char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_generator_frequency(float desired_frequency, char * commanalyzerType, int gpibDevice);
int commanalyzer_spectrum_analyzer_set_generator_sweep_ascending (char * commanalyzerType, int gpibDevice);
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);
int commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions( char * commanalyzerType, int gpibDevice);
int commanalyzer_get_spectrum_analyzer_trace (const char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_center_frequency(float desired_frequency, const char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_frequency_span(float desired_frequency, const char * commanalyzerType, int gpibDevice);
int commanalyzer_spectrum_analyzer_set_generator_mode_tracking (const char * commanalyzerType, int gpibDevice);
int commanalyzer_spectrum_analyzer_set_generator_mode_fixed (const char * commanalyzerType, int gpibDevice);
int commanalyzer_spectrum_analyzer_set_rf_input_dedicated (const char * commanalyzerType, int gpibDevice);
int commanalyzer_spectrum_analyzer_set_rf_input_muxed (const char * commanalyzerType, int gpibDevice);
int commanalyzer_spectrum_analyzer_set_generator_output_dedicated (const char * commanalyzerType, int gpibDevice);
int commanalyzer_spectrum_analyzer_set_generator_output_muxed (const char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_input_attenuation(float desired_attenuation, const char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_scale(float desired_scale, const char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_input_attenuator_mode_auto( const char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_input_attenuator_mode_fixed( const char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_generator_power(float desired_power, const char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_generator_frequency(float desired_frequency, const char * commanalyzerType, int gpibDevice);
int commanalyzer_spectrum_analyzer_set_generator_sweep_ascending (const char * commanalyzerType, int gpibDevice);
int commanalyzer_spectrum_analyzer_set_generator_sweep_descending (const char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_trace_averaging(float desired_avg_samples, const char * commanalyzerType, int gpibDevice);
int commanalyzer_set_spectrum_analyzer_reference_power_level(float desired_reflevel, const char * commanalyzerType, int gpibDevice);
int commanalyzer_get_spectrum_analyzer_number_of_vertical_divisions( const char * commanalyzerType, int gpibDevice);
int commanalyzer_get_spectrum_analyzer_number_of_horizontal_divisions( const 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);
double commanalyzer_get_spectrum_analyzer_reference_power_level (double * retval, const char * commanalyzerType, int gpibDevice);
double commanalyzer_get_spectrum_analyzer_scale (double * retval, const char * commanalyzerType, int gpibDevice);
double commanalyzer_get_spectrum_analyzer_center_frequency (double * retval, const char * commanalyzerType, int gpibDevice);
double commanalyzer_get_spectrum_analyzer_span (double * retval, const char * commanalyzerType, int gpibDevice);

@ -0,0 +1,489 @@
/*
* Remote Laboratory GPIB Server
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (c) 2012 Timothy Pearson
* Raptor Engineering
* http://www.raptorengineeringinc.com
*/
#include <stdio.h> /* perror() */
#include <stdlib.h> /* atoi() */
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h> /* read() */
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <sys/signal.h>
#include <sys/types.h>
#include <tqtimer.h>
#include <tqfile.h>
#include <klocale.h>
#include <gpib/ib.h>
#include "gpib_functions.h"
#include "scope_functions.h"
#include "signal_functions.h"
#include "commanalyzer_functions.h"
#include "gpib_conn.h"
#define ABORT_SOCKET(s) s->close(); \
s->disconnect(); \
delete s; \
s = NULL;
#define NETWORK_COMM_TIMEOUT_MS 5000
/* exception handling */
struct exit_exception {
int c;
exit_exception(int c):c(c) { }
};
/*
The GPIBSocket class provides a socket that is connected with a client.
For every client that connects to the server, the server creates a new
instance of this class.
*/
GPIBSocket::GPIBSocket(int sock, TQObject *parent, const char *name) :
TDEKerberosServerSocket(parent, name), m_criticalSection(0), m_loopTimer(NULL), m_config(static_cast<GPIBServer*>(parent)->m_config),
m_serverParent(static_cast<GPIBServer*>(parent)), m_commandLoopState(0)
{
// Initialize timers
m_kerberosInitTimer = new TQTimer();
connect(m_kerberosInitTimer, SIGNAL(timeout()), this, SLOT(finishKerberosHandshake()));
m_servClientTimeout = new TQTimer();
setServiceName("remotefpga");
line = 0;
connect(this, SIGNAL(connectionClosed()), SLOT(connectionClosedHandler()));
connect(this, SIGNAL(connectionClosed()), parent, SLOT(remoteConnectionClosed()));
setSocket(sock);
}
GPIBSocket::~GPIBSocket() {
if (m_servClientTimeout) {
m_servClientTimeout->stop();
delete m_servClientTimeout;
m_servClientTimeout = NULL;
}
if (m_kerberosInitTimer) {
m_kerberosInitTimer->stop();
delete m_kerberosInitTimer;
m_kerberosInitTimer = NULL;
}
if (m_loopTimer) {
m_loopTimer->stop();
delete m_loopTimer;
m_loopTimer = NULL;
}
}
void GPIBSocket::close() {
if (state() == TQSocket::Connected) {
TDEKerberosServerSocket::close();
connectionClosedHandler();
TQTimer::singleShot(0, parent(), SLOT(remoteConnectionClosed()));
}
}
void GPIBSocket::connectionClosedHandler() {
printf("[DEBUG] Connection from %s closed\n\r", m_remoteHost.ascii());
if (m_criticalSection > 0) {
throw exit_exception(-1);
}
}
void GPIBSocket::initiateKerberosHandshake() {
setUsingKerberos(true);
m_kerberosInitTimer->start(100, TRUE);
}
void GPIBSocket::finishKerberosHandshake() {
if (kerberosStatus() == TDEKerberosServerSocket::KerberosInitializing) {
m_kerberosInitTimer->start(100, TRUE);
return;
}
if (kerberosStatus() == TDEKerberosServerSocket::KerberosInUse) {
m_config->setGroup("Security");
TQString masterUser = m_config->readEntry("masteruser");
TQString masterRealm = m_config->readEntry("masterrealm");
if (masterRealm == "") {
masterRealm = "(NULL)";
}
if ((m_authenticatedUserName != masterUser) || (m_authenticatedRealmName != masterRealm)) {
printf("[DEBUG] Connection from %s closed due to authentication failure (attempted connection as user %s@%s)\n\r", m_remoteHost.ascii(), masterUser.ascii(), masterRealm.ascii());
close();
return;
}
setDataTimeout(NETWORK_COMM_TIMEOUT_MS);
TQDataStream ds(this);
ds.setPrintableData(true);
ds << TQString("OK");
writeEndOfFrame();
enterCommandLoop();
return;
}
else {
printf("[DEBUG] Connection from %s closed due to Kerberos failure\n\r", m_remoteHost.ascii()); fflush(stdout);
close();
return;
}
}
void GPIBSocket::commandLoop() {
bool transferred_data;
m_criticalSection++;
try {
transferred_data = false;
if (state() == TQSocket::Connected) {
if (m_commandLoopState == 0) {
if (canReadLine()) {
processPendingData();
}
if (canReadFrame()) {
TQDataStream ds(this);
ds.setPrintableData(true);
TQString instrumentRequest;
ds >> instrumentRequest;
clearFrameTail();
m_activeDeviceType = 0;
if (instrumentRequest == "LIST") {
TQStringList deviceList;
if (m_serverParent->m_serialDevice != "") {
deviceList.append("SERIAL PORT");
}
if (m_serverParent->m_scopeType != "") {
deviceList.append("OSCILLOSCOPE");
}
if (m_serverParent->m_funcgenType != "") {
deviceList.append("FUNCTION GENERATOR");
}
if (m_serverParent->m_commanalyzerType != "") {
deviceList.append("COMMUNICATIONS ANALYZER");
}
ds << deviceList;
writeEndOfFrame();
}
else if (instrumentRequest == "SERIAL PORT") {
m_activeDeviceType = 1;
}
else if (instrumentRequest == "OSCILLOSCOPE") {
m_activeDeviceType = 2;
}
else if (instrumentRequest == "FUNCTION GENERATOR") {
m_activeDeviceType = 3;
}
else if (instrumentRequest == "COMMUNICATIONS ANALYZER") {
m_activeDeviceType = 4;
}
if (m_activeDeviceType != 0) {
m_servClientTimeout->start(NETWORK_COMM_TIMEOUT_MS, TRUE);
transferred_data = true;
m_commandLoopState = 1;
}
}
}
else if (m_commandLoopState == 1) {
if (canReadLine()) {
processPendingData();
}
if (m_activeDeviceType == 1) {
// Serial port
if (canReadFrame()) {
TQDataStream ds(this);
ds.setPrintableData(true);
TQByteArray recData;
ds >> recData;
if (recData.size() > 0) {
if (write(m_serverParent->m_serialDeviceSocket, recData.data(), recData.size()) < 0) {
// ERROR
}
transferred_data = true;
printf("[DEBUG] Got %d bytes from the network interface\n\r", recData.size()); fflush(stdout);
}
}
TQByteArray txData;
txData.resize(10000);
int cc = read(m_serverParent->m_serialDeviceSocket, txData.data(), txData.size());
if (cc > 0) {
TQDataStream ds(this);
ds.setPrintableData(true);
ds << txData;
writeEndOfFrame();
transferred_data = true;
printf("[DEBUG] Got %d bytes from the serial port\n\r", cc); fflush(stdout);
}
}
else {
if (canReadFrame()) {
TQDataStream ds(this);
ds.setPrintableData(true);
ds >> m_instrumentCommand;
clearFrameTail();
if (m_instrumentCommand != "") {
m_servClientTimeout->start(NETWORK_COMM_TIMEOUT_MS, TRUE);
transferred_data = true;
m_commandLoopState = 2;
}
}
}
}
else if (m_commandLoopState == 2) {
if (canReadLine()) {
processPendingData();
}
if (canReadFrame()) {
if (m_activeDeviceType == 2) {
// Oscilloscope
}
else if (m_activeDeviceType == 3) {
// Function generator
}
else if (m_activeDeviceType == 4) {
// Communications analyzer
}
else {
// Unknown
transferred_data = true;
m_commandLoopState = 0;
}
}
}
}
m_criticalSection--;
if (transferred_data) {
if (m_loopTimer) m_loopTimer->start(0, TRUE);
}
else {
if (m_loopTimer) m_loopTimer->start(100, TRUE);
}
return;
}
catch (...) {
m_criticalSection--;
return;
}
}
int GPIBSocket::enterCommandLoop() {
m_commandLoopState = 0;
if (!m_loopTimer) {
m_loopTimer = new TQTimer();
connect(m_loopTimer, SIGNAL(timeout()), this, SLOT(commandLoop()));
}
if (m_loopTimer) m_loopTimer->start(0, TRUE);
return 0;
}
/*
The GPIBServer class handles new connections to the server. For every
client that connects, it creates a new GPIBSocket -- that instance is now
responsible for the communication with that client.
*/
GPIBServer::GPIBServer(TQObject* parent, int port, KSimpleConfig* config) :
TQServerSocket( port, 1, parent ), m_config(config), m_numberOfConnections(0),
m_scopeDeviceSocket(-1), m_funcgenDeviceSocket(-1), m_commanalyzerDeviceSocket(-1) {
if ( !ok() ) {
printf("[ERROR] Failed to bind to port %d\n\r", port);
exit(1);
}
if (readConfig() != 0) {
exit(-1);
}
printf("[INFO] Server started on port %d\n\r", port); fflush(stdout);
}
GPIBServer::~GPIBServer() {
//
}
void GPIBServer::newConnection(int socket) {
GPIBSocket *s = new GPIBSocket(socket, this);
s->m_remoteHost = s->peerAddress().toString();
printf("[DEBUG] New connection from %s\n\r", s->m_remoteHost.ascii());
connect(s, SIGNAL(connectionClosed()), s, SLOT(deleteLater()));
s->initiateKerberosHandshake();
emit newConnect(s);
}
void GPIBServer::remoteConnectionClosed() {
m_numberOfConnections--;
}
int GPIBServer::readConfig() {
// Serial port
m_config->setGroup("Serial Port");
m_serialDevice = m_config->readEntry("device", "");
TQString desiredBaudRate = m_config->readEntry("baudrate", "9600");
if (desiredBaudRate == "1200") {
m_serialBaud = B1200;
}
else if (desiredBaudRate == "9600") {
m_serialBaud = B9600;
}
else if (desiredBaudRate == "19200") {
m_serialBaud = B19200;
}
else if (desiredBaudRate == "115200") {
m_serialBaud = B115200;
}
else {
printf("[WARNING] Invalid baudrate %s specified, selecting 9600 instead\n\r", desiredBaudRate.ascii()); fflush(stdout);
desiredBaudRate = "9600";
m_serialBaud = B9600;
}
// Oscilloscope
m_config->setGroup("Oscilloscope");
m_scopeType = m_config->readEntry("type", "");
m_scopeConnection = m_config->readEntry("connection", "gpib");
m_scopeBoard = m_config->readNumEntry("board", 0);
m_scopeDevice = m_config->readNumEntry("device", 0);
// Function generator
m_config->setGroup("Function Generator");
m_funcgenType = m_config->readEntry("type", "");
m_funcgenConnection = m_config->readEntry("connection", "gpib");
m_funcgenBoard = m_config->readNumEntry("board", 0);
m_funcgenDevice = m_config->readNumEntry("device", 0);
// Communications analyzer
m_config->setGroup("Communications Analyzer");
m_commanalyzerType = m_config->readEntry("type", "");
m_commanalyzerConnection = m_config->readEntry("connection", "gpib");
m_commanalyzerBoard = m_config->readNumEntry("board", 0);
m_commanalyzerDevice = m_config->readNumEntry("device", 0);
if (m_serialDevice != "") {
struct termios oldtio, newtio;
m_serialDeviceSocket = ::open(m_serialDevice.ascii(), O_RDWR | O_NOCTTY | O_NONBLOCK | O_APPEND);
if (m_serialDeviceSocket < 0) {
printf("[FAIL] Unable to open serial device %s\n\r", m_serialDevice.ascii()); fflush(stdout);
return 1;
}
tcgetattr(m_serialDeviceSocket, &oldtio); // Save current port settings
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = m_serialBaud | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
// Set input mode (non-canonical, no echo,...)
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0; // Inter-character timer unused
newtio.c_cc[VMIN] = 0; // Blocking read unused
tcflush(m_serialDeviceSocket, TCIFLUSH);
tcsetattr(m_serialDeviceSocket, TCSANOW, &newtio);
printf("[INFO] Serial port on node %s activated at %s baud\n\r", m_serialDevice.ascii(), desiredBaudRate.ascii());
}
if (m_scopeType != "") {
printf("[INFO] Oscilloscope conjectured to be on GPIB address %d:%d\n\r", m_scopeBoard, m_scopeDevice);
m_scopeDeviceSocket = open_gpib_device(m_scopeBoard, m_scopeDevice);
if (m_scopeDeviceSocket < 0) {
// return -1;
}
else {
time_t rawtime;
struct tm * timeinfo;
char datebuffer [80];
char timebuffer [80];
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime(timebuffer,80,"TIME \"%H:%M:%S\"",timeinfo);
strftime(datebuffer,80,"DATE \"%Y-%m-%d\"",timeinfo);
printf("[INFO] Configuring %s oscilloscope\n\r", scopeLongDescription(m_scopeType.ascii()));
printf("[INFO] %s\n\r", datebuffer);
printf("[INFO] %s\n\r", timebuffer);
if (gpib_write(m_scopeDeviceSocket, timebuffer) == 0) {
gpib_write(m_scopeDeviceSocket, datebuffer);
printf("[INFO] Communication verified\n\r");
}
else {
printf("[WARN] Communication failed!\n\r");
}
}
}
if (m_funcgenType != "") {
printf("[INFO] Function generator conjectured to be on GPIB address %d:%d\n\r", m_funcgenBoard, m_funcgenDevice);
m_funcgenDeviceSocket = open_gpib_device(m_funcgenBoard, m_funcgenDevice);
if (m_funcgenDeviceSocket < 0) {
//return 1;
}
else {
printf("[INFO] Configuring %s function generator\n\r", funcgenLongDescription(m_funcgenType.ascii()));
if (gpib_write(m_funcgenDeviceSocket, "RESET") == 0) {
printf("[INFO] Communication verified\n\r");
}
else {
printf("[WARN] Communication failed!\n\r");
}
}
}
if (m_commanalyzerType != "") {
printf("[INFO] Communications analyzer conjectured to be on GPIB address %d:%d\n\r", m_commanalyzerBoard, m_commanalyzerDevice);
m_commanalyzerDeviceSocket = open_gpib_device(m_commanalyzerBoard, m_commanalyzerDevice);
if (m_commanalyzerDeviceSocket < 0) {
//return 1;
}
else {
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf("[INFO] Configuring %s communications analyzer\n\r", commanalyzerLongDescription(m_commanalyzerType.ascii()));
if (commanalyzer_set_time(timeinfo, m_commanalyzerType.ascii(), m_commanalyzerDeviceSocket) == 0) {
commanalyzer_set_date(timeinfo, m_commanalyzerType.ascii(), m_commanalyzerDeviceSocket);
printf("[INFO] Communication verified\n\r");
}
else {
printf("[WARN] Communication failed!\n\r");
}
}
}
return 0;
}

@ -0,0 +1,126 @@
/*
* Remote Laboratory GPIB Server
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (c) 2012 Timothy Pearson
* Raptor Engineering
* http://www.raptorengineeringinc.com
*/
#include <tqsocket.h>
#include <tqserversocket.h>
#include <tqapplication.h>
#include <tqvbox.h>
#include <tqtextview.h>
#include <tqlabel.h>
#include <tqpushbutton.h>
#include <tqtextstream.h>
#include <ksimpleconfig.h>
#include <tdekrbserversocket.h>
#include <tqtrla.h>
#define MAGIC_NUMBER 1
#define PROTOCOL_VERSION 1
class GPIBServer;
class GPIBSocket : public TDEKerberosServerSocket
{
Q_OBJECT
public:
GPIBSocket(int sock, TQObject *parent=0, const char *name=0);
~GPIBSocket();
public:
void close();
void initiateKerberosHandshake();
int enterCommandLoop();
private slots:
void finishKerberosHandshake();
void connectionClosedHandler();
void commandLoop();
private:
int line;
int m_criticalSection;
TQString m_remoteHost;
TQTimer* m_kerberosInitTimer;
TQTimer* m_loopTimer;
TQTimer* m_servClientTimeout;
KSimpleConfig* m_config;
GPIBServer* m_serverParent;
int m_commandLoopState;
int m_activeDeviceType;
TQString m_instrumentCommand;
friend class GPIBServer;
};
class GPIBServer : public TQServerSocket
{
Q_OBJECT
public:
GPIBServer(TQObject* parent=0, int port=0, KSimpleConfig* config=0);
~GPIBServer();
void newConnection(int socket);
private slots:
void remoteConnectionClosed();
private:
int readConfig(void);
signals:
void newConnect(GPIBSocket*);
private:
KSimpleConfig* m_config;
int m_numberOfConnections;
TQString m_serialDevice;
long m_serialBaud;
int m_serialDeviceSocket;
TQString m_scopeType;
TQString m_scopeConnection;
int m_scopeBoard;
int m_scopeDevice;
int m_scopeDeviceSocket;
TQString m_funcgenType;
TQString m_funcgenConnection;
int m_funcgenBoard;
int m_funcgenDevice;
int m_funcgenDeviceSocket;
TQString m_commanalyzerType;
TQString m_commanalyzerConnection;
int m_commanalyzerBoard;
int m_commanalyzerDevice;
int m_commanalyzerDeviceSocket;
friend class GPIBSocket;
};

@ -1,40 +0,0 @@
/*
* Remote Laboratory Instrumentation Server
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (c) 2009 Timothy Pearson
* Raptor Engineering
* http://www.raptorengineeringinc.com
*/
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <getopt.h>
#include <allegro.h>
#include "gpib/ib.h"
int gpib_write(int ud, char * buffer){
if( ibwrt(ud, buffer, strlen(buffer)) & ERR )
{
return -1;
}
return 0;
}

@ -0,0 +1,122 @@
/*
* Remote Laboratory Instrumentation Server
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (c) 2009 Timothy Pearson
* Raptor Engineering
* http://www.raptorengineeringinc.com
*/
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <getopt.h>
#include "gpib/ib.h"
char falpha[1024];
char * scopeLongDescription (const char * scopeType) {
if (strcmp("HP54600OS", scopeType) == 0) {
return "Hewlett Packard 54600 series";
}
else if (strcmp("TDS744AOS", scopeType) == 0) {
return "Tektronix 744A series";
}
else {
return "UNKNOWN";
}
}
char * commanalyzerLongDescription (const char * commanalyzerType) {
if (strcmp("HP8924C", commanalyzerType) == 0) {
return "Hewlett Packard 8924 series";
}
else {
return "UNKNOWN";
}
}
char * funcgenLongDescription (const char * funcgenType) {
if (strcmp("AG33250A", funcgenType) == 0) {
return "Agilent AG33250A";
}
else {
return "UNKNOWN";
}
}
/* returns a device descriptor after prompting user for primary address */
int open_gpib_device(int minor, int pad) {
int ud;
const int sad = 0;
const int send_eoi = 1;
const int eos_mode = 0;
const int timeout = T1s;
printf("[INFO] Trying to open GPIB device %i on board /dev/gpib%i...\n\r", pad, minor);
ud = ibdev(minor, pad, sad, timeout, send_eoi, eos_mode);
if(ud < 0)
{
printf("[WARN] GPIB interface error\n\r");
return -1;
}
return ud;
}
int gpib_write(int ud, char * buffer) {
if( ibwrt(ud, buffer, strlen(buffer)) & ERR )
{
return -1;
}
return 0;
}
int gpib_read_array(int ud, int max_num_bytes, char * segarray) {
int br;
ibrd(ud, segarray, max_num_bytes-1);
br = ThreadIbcntl();
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Number of bytes read from GPIB device: %li\n", br);
#endif
if ((ThreadIbsta() & ERR) && (br == 0)) {
return -1;
}
return br;
}
int gpib_read_binary(int ud, int max_num_bytes) {
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
#endif
//ibrd(ud, scope_raw_screenshot_data, max_num_bytes-1);
system("rm -f /tmp/current_scope_screenshot.bmp");
ibrdf(ud, "/tmp/current_scope_screenshot.bmp");
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Number of bytes read from GPIB device: %li\n", ThreadIbcntl());
#endif
if (ThreadIbsta() & ERR) {
return -1;
}
return 0;
}

@ -20,4 +20,11 @@
* http://www.raptorengineeringinc.com
*/
char * scopeLongDescription (const char * scopeType);
char * commanalyzerLongDescription (const char * scopeType);
char * funcgenLongDescription (const char * funcgenType);
int open_gpib_device(int minor, int pad);
int gpib_write(int ud, char * buffer);
int gpib_read_array(int ud, int max_num_bytes, char * segarray);
int gpib_read_binary(int ud, int max_num_bytes);

@ -0,0 +1,64 @@
/***************************************************************************
* Copyright (C) 2012 by Timothy Pearson *
* kb9vqf@pearsoncomputing.net *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <pwd.h>
#include <limits.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <tqdatetime.h>
#include <tqfile.h>
#include <tqdir.h>
#include <kapplication.h>
#include <kstartupinfo.h>
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <ksimpleconfig.h>
#include "gpib_conn.h"
static const char description[] = I18N_NOOP("RemoteFPGA GPIB Server");
static const char version[] = "v0.0.1";
int main(int argc, char *argv[])
{
KAboutData aboutData( "remotefpga_gpib_server", I18N_NOOP("RemoteFPGA GPIB Server"),
version, description, KAboutData::License_GPL,
"(c) 2012, Timothy Pearson");
aboutData.addAuthor("Timothy Pearson",0, "kb9vqf@pearsoncomputing.net");
KCmdLineArgs::init( argc, argv, &aboutData );
KApplication::disableAutoDcopRegistration();
KApplication app(false, false);
KStartupInfo::appStarted();
KSimpleConfig config(TQDir::currentDirPath() + "/remotefpga_gpibserver.conf", false);
config.setGroup("Server");
GPIBServer fpgasvr(0, config.readNumEntry("port", 4013), &config);
return app.exec();
}

@ -28,12 +28,13 @@
#include <stdint.h>
#include <string.h>
#include <getopt.h>
#include <allegro.h>
#include "parameters.h"
#include "gpib_functions.h"
#include "gpib/ib.h"
char falpha[1024];
#include <tqimage.h>
extern char falpha[1024];
unsigned char scope_raw_screenshot_data[4194304];
unsigned long scopeScreenWidth (char * scopeType) {
@ -74,7 +75,7 @@ unsigned long scopeScreenSize (char * scopeType) {
int gpib_read_binblock(int ud, int max_num_bytes, char * scopeType)
{
unsigned char segarray[4194304];
char segarray[4194304];
long array_pointer;
long ai;
@ -126,40 +127,6 @@ int gpib_read_binblock(int ud, int max_num_bytes, char * scopeType)
return 0;
}
int gpib_read_array(int ud, int max_num_bytes, unsigned char * segarray)
{
int br;
ibrd(ud, segarray, max_num_bytes-1);
br = ThreadIbcntl();
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Number of bytes read from GPIB device: %li\n", br);
#endif
if ((ThreadIbsta() & ERR) && (br == 0)) {
return -1;
}
return br;
}
int gpib_read_binary(int ud, int max_num_bytes)
{
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
#endif
//ibrd(ud, scope_raw_screenshot_data, max_num_bytes-1);
system("rm -f /tmp/current_scope_screenshot.bmp");
ibrdf(ud, "/tmp/current_scope_screenshot.bmp");
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Number of bytes read from GPIB device: %li\n", ThreadIbcntl());
#endif
if (ThreadIbsta() & ERR) {
return -1;
}
return 0;
}
int scope_get_screenshot_stage2(char * scopeType, int gpibDevice) {
long bytestosend;
int k;
@ -178,32 +145,29 @@ int scope_get_screenshot_stage2(char * scopeType, int gpibDevice) {
else if (strcmp("TDS744AOS", scopeType) == 0) {
gpib_read_binary(gpibDevice, scopeScreenSize(scopeType));
BITMAP *bmp;
PALETTE palette;
int bpp;
install_allegro(SYSTEM_AUTODETECT, &errno, atexit);
bmp = load_bmp("/tmp/current_scope_screenshot.bmp", palette);
if (!bmp) {
TQImage bmp;
bmp.load("/tmp/current_scope_screenshot.bmp");
if (bmp.isNull()) {
printf("[WARN] Unable to load screenshot bitmap\n\r");
return 1;
}
set_palette(palette);
bpp = bitmap_color_depth(bmp);
bpp = bmp.depth();
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Found BPP of %d\n\r", bpp);
#endif
bytestosend = 0;
for (m=0;m<scopeScreenWidth(scopeType);m++) {
for (k=0;k<scopeScreenHeight(scopeType);k++) {
scope_raw_screenshot_data[bytestosend] = getr_depth(bpp, getpixel(bmp, m, k));
TQRgb pixel = bmp.pixel(m, k);
scope_raw_screenshot_data[bytestosend] = tqRed(pixel);
bytestosend = bytestosend + 1;
scope_raw_screenshot_data[bytestosend] = getg_depth(bpp, getpixel(bmp, m, k));
scope_raw_screenshot_data[bytestosend] = tqGreen(pixel);
bytestosend = bytestosend + 1;
scope_raw_screenshot_data[bytestosend] = getb_depth(bpp, getpixel(bmp, m, k));
scope_raw_screenshot_data[bytestosend] = tqBlue(pixel);
bytestosend = bytestosend + 1;
}
}
destroy_bitmap(bmp);
return 0;
}
}
@ -215,7 +179,7 @@ int scope_get_screenshot(char * scopeType, int gpibDevice) {
if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) {
printf("[INFO] Getting scope screenshot [Stage 1]\n\r");
if (strcmp("HP54600OS", scopeType) == 0) {
sprintf(falpha,"PRINT?");
sprintf(falpha, "PRINT?");
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
@ -227,27 +191,27 @@ int scope_get_screenshot(char * scopeType, int gpibDevice) {
}
}
else if (strcmp("TDS744AOS", scopeType) == 0) {
sprintf(falpha,"HARDCOPY:FORMAT BMPCOLOR");
sprintf(falpha, "HARDCOPY:FORMAT BMPCOLOR");
if (gpib_write(gpibDevice, falpha) == 0) {
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Wrote: %s\n\r", falpha);
#endif
sprintf(falpha,"HARDCOPY:LAYOUT PORTRAIT");
sprintf(falpha, "HARDCOPY:LAYOUT PORTRAIT");
if (gpib_write(gpibDevice, falpha) == 0) {
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Wrote: %s\n\r", falpha);
#endif
sprintf(falpha,"HARDCOPY:PALETTE HARDCOPY");
sprintf(falpha, "HARDCOPY:PALETTE HARDCOPY");
if (gpib_write(gpibDevice, falpha) == 0) {
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Wrote: %s\n\r", falpha);
#endif
sprintf(falpha,"HARDCOPY:PORT GPIB");
sprintf(falpha, "HARDCOPY:PORT GPIB");
if (gpib_write(gpibDevice, falpha) == 0) {
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Wrote: %s\n\r", falpha);
#endif
sprintf(falpha,"HARDCOPY START");
sprintf(falpha, "HARDCOPY START");
if (gpib_write(gpibDevice, falpha) == 0) {
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Wrote: %s\n\r", falpha);
@ -267,7 +231,7 @@ int scope_set_timebase(float desired_timebase, char * scopeType, int gpibDevice)
if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) {
printf("[INFO] Setting scope timebase to %E\n\r", desired_timebase);
if (strcmp("HP54600OS", scopeType) == 0) {
sprintf(falpha,"TIM:RANG %E", desired_timebase);
sprintf(falpha, "TIM:RANG %E", desired_timebase);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
@ -279,7 +243,7 @@ int scope_set_timebase(float desired_timebase, char * scopeType, int gpibDevice)
}
}
else if (strcmp("TDS744AOS", scopeType) == 0) {
sprintf(falpha,"HORIZONTAL:MAIN:SCALE %E", desired_timebase/10);
sprintf(falpha, "HORIZONTAL:MAIN:SCALE %E", desired_timebase/10);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
@ -300,7 +264,7 @@ int scope_set_volts_div(int desired_channel, float desired_volts, char * scopeTy
if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) {
printf("[INFO] Setting scope volts/div on channel %d to %f\n\r", desired_channel, desired_volts/8);
if (strcmp("HP54600OS", scopeType) == 0) {
sprintf(falpha,"CHAN%d:RANG %E", desired_channel, desired_volts);
sprintf(falpha, "CHAN%d:RANG %E", desired_channel, desired_volts);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
@ -312,7 +276,7 @@ int scope_set_volts_div(int desired_channel, float desired_volts, char * scopeTy
}
}
else if (strcmp("TDS744AOS", scopeType) == 0) {
sprintf(falpha,"CH%d:SCALE %f", desired_channel, desired_volts/8);
sprintf(falpha, "CH%d:SCALE %f", desired_channel, desired_volts/8);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
@ -334,10 +298,10 @@ int scope_set_acquisition(int status, char * scopeType, int gpibDevice) {
printf("[INFO] Setting scope run status to %d\n\r", status);
if (strcmp("HP54600OS", scopeType) == 0) {
if (status == 0) {
sprintf(falpha,"STOP");
sprintf(falpha, "STOP");
}
else {
sprintf(falpha,"RUN");
sprintf(falpha, "RUN");
}
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
@ -350,7 +314,7 @@ int scope_set_acquisition(int status, char * scopeType, int gpibDevice) {
}
}
else if (strcmp("TDS744AOS", scopeType) == 0) {
sprintf(falpha,"ACQUIRE:STATE %d", status);
sprintf(falpha, "ACQUIRE:STATE %d", status);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
@ -372,10 +336,10 @@ int scope_set_channel_state(int desired_channel, int status, char * scopeType, i
printf("[INFO] Setting channel %d state to %i\n\r", desired_channel, status);
if (strcmp("HP54600OS", scopeType) == 0) {
if (status == 0) {
sprintf(falpha,"BLAN CHAN%d", desired_channel);
sprintf(falpha, "BLAN CHAN%d", desired_channel);
}
else if (status == 1) {
sprintf(falpha,"VIEW CHAN%d", desired_channel);
sprintf(falpha, "VIEW CHAN%d", desired_channel);
}
else {
return 2;
@ -392,10 +356,10 @@ int scope_set_channel_state(int desired_channel, int status, char * scopeType, i
}
else if (strcmp("TDS744AOS", scopeType) == 0) {
if (status == 0) {
sprintf(falpha,"SELECT:CH%d OFF", desired_channel);
sprintf(falpha, "SELECT:CH%d OFF", desired_channel);
}
else if (status == 1) {
sprintf(falpha,"SELECT:CH%d ON", desired_channel);
sprintf(falpha, "SELECT:CH%d ON", desired_channel);
}
else {
return 2;
@ -420,7 +384,7 @@ int scope_set_trigger_channel(int desired_channel, char * scopeType, int gpibDev
if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) {
printf("[INFO] Setting scope trigger channel to %d\n\r", desired_channel);
if (strcmp("HP54600OS", scopeType) == 0) {
sprintf(falpha,"TRIG:SOUR CHAN%d", desired_channel);
sprintf(falpha, "TRIG:SOUR CHAN%d", desired_channel);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
@ -432,7 +396,7 @@ int scope_set_trigger_channel(int desired_channel, char * scopeType, int gpibDev
}
}
else if (strcmp("TDS744AOS", scopeType) == 0) {
sprintf(falpha,"TRIGGER:MAIN:EDGE:SOURCE CH%d", desired_channel);
sprintf(falpha, "TRIGGER:MAIN:EDGE:SOURCE CH%d", desired_channel);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
@ -453,7 +417,7 @@ int scope_set_trigger_level(float desired_level, char * scopeType, int gpibDevic
if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) {
printf("[INFO] Setting scope trigger level to %f\n\r", desired_level);
if (strcmp("HP54600OS", scopeType) == 0) {
sprintf(falpha,"TRIG:LEV %E", desired_level);
sprintf(falpha, "TRIG:LEV %E", desired_level);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
@ -465,7 +429,7 @@ int scope_set_trigger_level(float desired_level, char * scopeType, int gpibDevic
}
}
else if (strcmp("TDS744AOS", scopeType) == 0) {
sprintf(falpha,"TRIGGER:MAIN:LEVEL %f", desired_level);
sprintf(falpha, "TRIGGER:MAIN:LEVEL %f", desired_level);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
@ -486,7 +450,7 @@ int scope_set_channel_position(int desired_channel, float desired_level, char *
if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) {
printf("[INFO] Setting scope channel %d level to %f\n\r", desired_channel, desired_level);
if (strcmp("HP54600OS", scopeType) == 0) {
sprintf(falpha,"CHAN%d:OFFS %E", desired_channel, desired_level);
sprintf(falpha, "CHAN%d:OFFS %E", desired_channel, desired_level);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
@ -498,7 +462,7 @@ int scope_set_channel_position(int desired_channel, float desired_level, char *
}
}
else if (strcmp("TDS744AOS", scopeType) == 0) {
sprintf(falpha,"CH%d:POSITION %f", desired_channel, desired_level);
sprintf(falpha, "CH%d:POSITION %f", desired_channel, desired_level);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif

@ -32,7 +32,7 @@
#include "parameters.h"
#include "gpib/ib.h"
char falpha[1024];
extern char falpha[1024];
int signal_get_last_error(char * funcgenType, int gpibDevice, char * extendedError) {
char error_array[1024];
Loading…
Cancel
Save