diff options
-rw-r--r-- | device-functions.c | 46 | ||||
-rw-r--r-- | device-functions.h | 2 | ||||
-rw-r--r-- | dummy_functions.c | 5 | ||||
-rw-r--r-- | dummy_functions.h | 2 | ||||
-rw-r--r-- | flash.c | 7 | ||||
-rw-r--r-- | globals.h | 42 | ||||
-rw-r--r-- | instr-daemon.c | 7 | ||||
-rw-r--r-- | menus.c | 70 | ||||
-rw-r--r-- | parser.c | 137 |
9 files changed, 152 insertions, 166 deletions
diff --git a/device-functions.c b/device-functions.c index 35c2662..26d2a5f 100644 --- a/device-functions.c +++ b/device-functions.c @@ -4621,3 +4621,49 @@ void Main_update_shift_registers() globals.Registers.last_relay_driver_settings[1]=globals.Registers.shift_reg_out[3]; } + +int IO_Setup_RS232(int baud, char parity, char stopbits, char databits, char hardhand, char echo) +{ + // debugging + printf ("baud: %d, parity %d, stop bits %d, data bits %d, handshaking %d, echo %d\n\r", + baud, + parity, // 0 = none, 1 = odd, 2 = even + stopbits, + databits, + hardhand, // 0 = none, 1 = hard + echo); + + // FIXME implement serial port changes here + + if (1) { // FIXME if changes are successful + globals.Flash.baud = baud; + globals.Flash.parity = parity; + globals.Flash.stopbits = stopbits; + globals.Flash.databits = databits; + globals.Flash.hardhand = hardhand; + globals.Flash.echo = echo; + + int eprom_loc = (char *) &(globals.Flash.baud) - (char *) &(globals.Flash.flash_start); + writeUserBlock(&globals.Flash, eprom_loc, sizeof(globals.Flash.baud)); + + eprom_loc = (char *) &(globals.Flash.parity) - (char *) &(globals.Flash.flash_start); + writeUserBlock(&globals.Flash, eprom_loc, sizeof(globals.Flash.parity)); + + eprom_loc = (char *) &(globals.Flash.stopbits) - (char *) &(globals.Flash.flash_start); + writeUserBlock(&globals.Flash, eprom_loc, sizeof(globals.Flash.stopbits)); + + eprom_loc = (char *) &(globals.Flash.databits) - (char *) &(globals.Flash.flash_start); + writeUserBlock(&globals.Flash, eprom_loc, sizeof(globals.Flash.databits)); + + eprom_loc = (char *) &(globals.Flash.hardhand) - (char *) &(globals.Flash.flash_start); + writeUserBlock(&globals.Flash, eprom_loc, sizeof(globals.Flash.hardhand)); + + eprom_loc = (char *) &(globals.Flash.echo) - (char *) &(globals.Flash.flash_start); + writeUserBlock(&globals.Flash, eprom_loc, sizeof(globals.Flash.echo)); + + return OK; + } else { + return HardwareError; + } +} + diff --git a/device-functions.h b/device-functions.h index 27671e5..654c874 100644 --- a/device-functions.h +++ b/device-functions.h @@ -71,4 +71,6 @@ void Set_Sav(int setting_num); void Main_update_shift_registers(); +int IO_Setup_RS232(int baud, char parity, char stopbits, char databits, char handshake, char echo); + #endif diff --git a/dummy_functions.c b/dummy_functions.c index d7c46f4..8f10b94 100644 --- a/dummy_functions.c +++ b/dummy_functions.c @@ -1,11 +1,6 @@ #include "dummy_functions.h" #include "globals.h" -int IO_Setup_RS232() -{ - return 0; -} - void GPIB_Set_Command_Error() {} void GPIB_Set_Query_Error() {} void GPIB_Set_Device_Dependent_Error() {} diff --git a/dummy_functions.h b/dummy_functions.h index 0e9d300..15cfb1b 100644 --- a/dummy_functions.h +++ b/dummy_functions.h @@ -3,8 +3,6 @@ #include "globals.h" -int IO_Setup_RS232(); - void GPIB_Set_Command_Error(); void GPIB_Set_Query_Error(); void GPIB_Set_Device_Dependent_Error(); @@ -337,7 +337,12 @@ static void initFlashValues(FlashStruct *mem) mem->telnet_session_timeout=600; /* ten minutes */ mem->telnet_logon_timeout=30; /* thirty seconds */ - mem->rcl_rs232=52; + mem->baud = 1200; + mem->parity = rs232_parity_none; + mem->stopbits = 1; + mem->databits = 8; + mem->hardhand = 1; + mem->echo = 1; mem->on_off_used=1; @@ -195,23 +195,9 @@ #define ROUTE_PRIMARY 0 #define ROUTE_SECONDARY 1 -/* define RS232 parameters */ -#define rs232_1200_baud 0x00 -#define rs232_2400_baud 0x40 -#define rs232_4800_baud 0xc0 -#define rs232_9600_baud 0x80 -#define rs232_parity_none 0x00 -#define rs232_parity_odd 0x0a -#define rs232_parity_even 0x02 -#define rs232_1stop_bit 0x00 -#define rs232_2stop_bits 0x01 -#define rs232_7data_bits 0x00 -#define rs232_8data_bits 0x04 -#define rs232_hard_off 0x00 -#define rs232_hard_on 0x10 -#define rs232_echo_off 0x00 -#define rs232_echo_on 0x20 - +#define rs232_parity_none 0 +#define rs232_parity_odd 1 +#define rs232_parity_even 2 #define smallest_allowed_number 1.0e-18 #define zero_equiv_timing 1e-10 @@ -343,16 +329,6 @@ typedef struct { typedef struct { - int baud; - int parity; - int stopbits; - int databits; - int hardhand; - int echo; -} Rs232Struct; - - -typedef struct { int channel; int cal_type; int count; @@ -426,7 +402,7 @@ typedef struct { short telnet_session_timeout; /* 56 - timeout in seconds */ - char rcl_rs232; /* 58 */ + char unusedx; /* 58 */ short spare2; /* 59 */ char ChanKey_route; /* 61 */ char on_off_used; /* 62 */ @@ -439,7 +415,14 @@ typedef struct { char warn_even_if_output_off; /* 129 */ - char spare1[32]; /* 130 */ + int baud; /* 130 */ + char parity; + char stopbits; + char databits; + char hardhand; + char echo; + + char spare1[23]; /* 139 */ short copy_max_channels; /* 162 - copy of max_channels macro */ @@ -813,7 +796,6 @@ typedef struct { ChannelStruct ChannelState[max_channels]; FlashStruct Flash; GpibStruct GPIB; - Rs232Struct RS232; HWregStruct Registers; ChangeStruct Changes; ErrorStruct Errors; diff --git a/instr-daemon.c b/instr-daemon.c index 7d21ee7..a302fb9 100644 --- a/instr-daemon.c +++ b/instr-daemon.c @@ -224,6 +224,13 @@ int main(int argc, char **argv) // FIXME - init RS232 + IO_Setup_RS232( globals.Flash.baud, + globals.Flash.parity, + globals.Flash.stopbits, + globals.Flash.databits, + globals.Flash.hardhand, + globals.Flash.echo); + /* start-up delay */ LCD_write(3,0,"Warming up, please wait... "); @@ -1575,6 +1575,7 @@ static void Submenu_Display(int change_selection) title = g_strdup ("Baud Rate:"); Submenu_max_entry=3; + // FIXME: generate structure from valid baud rate list Submenu_Structure[0]=mode_1200; Submenu_Structure[1]=mode_2400; Submenu_Structure[2]=mode_4800; @@ -1953,91 +1954,91 @@ static void Submenu_Display(int change_selection) break; case mode_1200: strcpy(mode_name[i],"1200 baud"); - if (globals.RS232.baud==rs232_1200_baud) { + if (globals.Flash.baud==1200) { current_operating_mode=i; } break; case mode_2400: strcpy(mode_name[i],"2400 baud"); - if (globals.RS232.baud==rs232_2400_baud) { + if (globals.Flash.baud==2400) { current_operating_mode=i; } break; case mode_4800: strcpy(mode_name[i],"4800 baud"); - if (globals.RS232.baud==rs232_4800_baud) { + if (globals.Flash.baud==4800) { current_operating_mode=i; } break; case mode_9600: strcpy(mode_name[i],"9600 baud"); - if (globals.RS232.baud==rs232_9600_baud) { + if (globals.Flash.baud==9600) { current_operating_mode=i; } break; case mode_7bits: strcpy(mode_name[i],"7 bits"); - if (globals.RS232.databits==rs232_7data_bits) { + if (globals.Flash.databits==7) { current_operating_mode=i; } break; case mode_8bits: strcpy(mode_name[i],"8 bits"); - if (globals.RS232.databits==rs232_8data_bits) { + if (globals.Flash.databits==8) { current_operating_mode=i; } break; case mode_par_none: strcpy(mode_name[i],"None"); - if (globals.RS232.parity==rs232_parity_none) { + if (globals.Flash.parity==rs232_parity_none) { current_operating_mode=i; } break; case mode_par_even: strcpy(mode_name[i],"Even"); - if (globals.RS232.parity==rs232_parity_even) { + if (globals.Flash.parity==rs232_parity_even) { current_operating_mode=i; } break; case mode_par_odd: strcpy(mode_name[i],"Odd"); - if (globals.RS232.parity==rs232_parity_odd) { + if (globals.Flash.parity==rs232_parity_odd) { current_operating_mode=i; } break; case mode_1bit: strcpy(mode_name[i],"1 bit"); - if (globals.RS232.stopbits==rs232_1stop_bit) { + if (globals.Flash.stopbits==1) { current_operating_mode=i; } break; case mode_2bits: strcpy(mode_name[i],"2 bits"); - if (globals.RS232.stopbits==rs232_2stop_bits) { + if (globals.Flash.stopbits==2) { current_operating_mode=i; } break; case mode_hand_hard: strcpy(mode_name[i],"Hardware"); - if (globals.RS232.hardhand==rs232_hard_on) { + if (globals.Flash.hardhand) { current_operating_mode=i; } break; case mode_hand_off: strcpy(mode_name[i],"None"); - if (globals.RS232.hardhand==rs232_hard_off) { + if (!globals.Flash.hardhand) { current_operating_mode=i; } break; case mode_echo_on: strcpy(mode_name[i],"On"); - if (globals.RS232.echo==rs232_echo_on) { + if (globals.Flash.echo) { current_operating_mode=i; } break; case mode_echo_off: strcpy(mode_name[i],"Off"); - if (globals.RS232.echo==rs232_echo_off) { + if (!globals.Flash.echo) { current_operating_mode=i; } break; @@ -2765,13 +2766,7 @@ static void Nonstd_menu_default_rs232(void) LCD_write(2,0,"hardware handshaking on, and echo on."); LCD_write(3,0,Press_Change_Message); - globals.RS232.baud = rs232_1200_baud; - globals.RS232.parity = rs232_parity_none; - globals.RS232.stopbits = rs232_1stop_bit; - globals.RS232.databits = rs232_8data_bits; - globals.RS232.hardhand = rs232_hard_on; - globals.RS232.echo = rs232_echo_on; - IO_Setup_RS232(); + IO_Setup_RS232(1200, rs232_parity_none, 1, 8, 1, 1); Menu_Clear_Buttons(); @@ -3290,89 +3285,90 @@ static int Submenu_Implement_Changes(void) globals.MenuStatus.Selected_Submenu=Submenu1_setup; break; case mode_1200: - globals.RS232.baud = rs232_1200_baud; + // FIXME: check that serial menus actually work + IO_Setup_RS232(1200, globals.Flash.parity, globals.Flash.stopbits, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo); globals.MenuStatus.Selected_Submenu=Submenu2_rs232_databits; call_new_submenu=YES; Submenu_Display(NO); break; case mode_2400: - globals.RS232.baud = rs232_2400_baud; + IO_Setup_RS232(2400, globals.Flash.parity, globals.Flash.stopbits, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo); globals.MenuStatus.Selected_Submenu=Submenu2_rs232_databits; call_new_submenu=YES; Submenu_Display(NO); break; case mode_4800: - globals.RS232.baud = rs232_4800_baud; + IO_Setup_RS232(4800, globals.Flash.parity, globals.Flash.stopbits, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo); globals.MenuStatus.Selected_Submenu=Submenu2_rs232_databits; call_new_submenu=YES; Submenu_Display(NO); break; case mode_9600: - globals.RS232.baud = rs232_9600_baud; + IO_Setup_RS232(9600, globals.Flash.parity, globals.Flash.stopbits, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo); globals.MenuStatus.Selected_Submenu=Submenu2_rs232_databits; call_new_submenu=YES; Submenu_Display(NO); break; case mode_7bits: - globals.RS232.databits = rs232_7data_bits; + IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, 7, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo); globals.MenuStatus.Selected_Submenu=Submenu2_rs232_parity; call_new_submenu=YES; Submenu_Display(NO); break; case mode_8bits: - globals.RS232.databits = rs232_8data_bits; + IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, 8, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo); globals.MenuStatus.Selected_Submenu=Submenu2_rs232_parity; call_new_submenu=YES; Submenu_Display(NO); break; case mode_par_none: - globals.RS232.parity = rs232_parity_none; + IO_Setup_RS232(globals.Flash.baud, rs232_parity_none, globals.Flash.stopbits, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo); globals.MenuStatus.Selected_Submenu=Submenu2_rs232_stopbits; call_new_submenu=YES; Submenu_Display(NO); break; case mode_par_odd: - globals.RS232.parity = rs232_parity_odd; + IO_Setup_RS232(globals.Flash.baud, rs232_parity_odd, globals.Flash.stopbits, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo); globals.MenuStatus.Selected_Submenu=Submenu2_rs232_stopbits; call_new_submenu=YES; Submenu_Display(NO); break; case mode_par_even: - globals.RS232.parity = rs232_parity_even; + IO_Setup_RS232(globals.Flash.baud, rs232_parity_even, globals.Flash.stopbits, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo); globals.MenuStatus.Selected_Submenu=Submenu2_rs232_stopbits; call_new_submenu=YES; Submenu_Display(NO); break; case mode_1bit: - globals.RS232.stopbits = rs232_1stop_bit; + IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, 1, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo); globals.MenuStatus.Selected_Submenu=Submenu2_rs232_hardhand; call_new_submenu=YES; Submenu_Display(NO); break; case mode_2bits: - globals.RS232.stopbits = rs232_2stop_bits; + IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, 2, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo); globals.MenuStatus.Selected_Submenu=Submenu2_rs232_hardhand; call_new_submenu=YES; Submenu_Display(NO); break; case mode_hand_hard: - globals.RS232.hardhand = rs232_hard_on; + IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, globals.Flash.stopbits, globals.Flash.databits, 1, globals.Flash.echo); globals.MenuStatus.Selected_Submenu=Submenu2_rs232_echo; call_new_submenu=YES; Submenu_Display(NO); break; case mode_hand_off: - globals.RS232.hardhand = rs232_hard_off; + IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, globals.Flash.stopbits, globals.Flash.databits, 0, globals.Flash.echo); globals.MenuStatus.Selected_Submenu=Submenu2_rs232_echo; call_new_submenu=YES; Submenu_Display(NO); break; case mode_echo_on: - globals.RS232.echo = rs232_echo_on; + IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, globals.Flash.stopbits, globals.Flash.databits, globals.Flash.hardhand, 1); globals.MenuStatus.Selected_Submenu=Submenu1_setup; break; case mode_echo_off: - globals.RS232.echo = rs232_echo_off; + IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, globals.Flash.stopbits, globals.Flash.databits, globals.Flash.hardhand, 0); globals.MenuStatus.Selected_Submenu=Submenu1_setup; break; } @@ -2733,44 +2733,25 @@ static int Go_gpib_addr_59(gchar** response, int channel, char *parameter,char * static int Go_ser_baud_60(gchar** response, int channel, char *parameter,char *units,int command_type) { - int value, status; + int new_baud, status; + int valid_choices[] = {1200, 2400, 4800, 9600}; switch (command_type) { case command_withparam: - if (status=process_four_ints (parameter, &value, 1200, 2400, 4800, 9600)) { + // FIXME - expand this list + // FIXME - hardcoded "4" + if (status = process_int_param (parameter, &new_baud, 4, valid_choices, NO_ON_OFF)) { return status; } - - if (value==1200) { - globals.RS232.baud = rs232_1200_baud; - } else if (value==2400) { - globals.RS232.baud = rs232_2400_baud; - } else if (value==4800) { - globals.RS232.baud = rs232_4800_baud; - } else { - globals.RS232.baud = rs232_9600_baud; - } - - IO_Setup_RS232(); - - return OK; + return IO_Setup_RS232(new_baud, globals.Flash.parity, globals.Flash.stopbits, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo); break; case query_simple: - if (globals.RS232.baud==rs232_1200_baud) { - value=1200; - } else if (globals.RS232.baud==rs232_2400_baud) { - value=2400; - } else if (globals.RS232.baud==rs232_4800_baud) { - value=4800; - } else if (globals.RS232.baud==rs232_9600_baud) { - value=9600; - } - - return query_int (response, value); + return query_int (response, globals.Flash.baud); break; case query_param: + // FIXME - extract min, max from a new baud list return query_min_max_int (response, parameter, 1200, 9600); break; @@ -2785,29 +2766,30 @@ static int Go_ser_baud_60(gchar** response, int channel, char *parameter,char *u static int Go_ser_par_61(gchar** response, int channel, char *parameter,char *units,int command_type) { + + int new_parity; + switch (command_type) { case command_withparam: if (!strcmp(parameter,"even")) { - globals.RS232.parity = rs232_parity_even; + new_parity = rs232_parity_even; } else if (!strcmp(parameter,"odd")) { - globals.RS232.parity = rs232_parity_odd; + new_parity = rs232_parity_odd; } else if (!strcmp(parameter,"none")) { - globals.RS232.parity = rs232_parity_none; + new_parity = rs232_parity_none; } else { return IllegalParameter; } - IO_Setup_RS232(); - - return OK; + return IO_Setup_RS232(globals.Flash.baud, (char) new_parity, globals.Flash.stopbits, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo); break; case query_simple: - if (globals.RS232.parity==rs232_parity_even) { + if (globals.Flash.parity==rs232_parity_even) { return query_string(response, "EVEN"); - } else if (globals.RS232.parity==rs232_parity_odd) { + } else if (globals.Flash.parity==rs232_parity_odd) { return query_string(response, "ODD"); - } else if (globals.RS232.parity==rs232_parity_none) { + } else if (globals.Flash.parity==rs232_parity_none) { return query_string(response, "NONE"); } return OK; @@ -2824,33 +2806,20 @@ static int Go_ser_par_61(gchar** response, int channel, char *parameter,char *un static int Go_ser_bits_62(gchar** response, int channel, char *parameter,char *units,int command_type) { - int value, status; + int new_databits; + int status; switch (command_type) { case command_withparam: - if (status=process_two_ints (parameter, &value, 7, 8)) { + if (status=process_two_ints (parameter, &new_databits, 7, 8)) { return status; } - if (value==7) { - globals.RS232.databits = rs232_7data_bits; - } else { - globals.RS232.databits = rs232_8data_bits; - } - - IO_Setup_RS232(); - - return OK; + return IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, globals.Flash.stopbits, (char) new_databits, globals.Flash.hardhand, globals.Flash.echo); break; case query_simple: - if (globals.RS232.databits==rs232_7data_bits) { - value=7; - } else if (globals.RS232.databits==rs232_8data_bits) { - value=8; - } - - return query_int (response, value); + return query_int (response, globals.Flash.databits); break; case query_param: @@ -2868,33 +2837,20 @@ static int Go_ser_bits_62(gchar** response, int channel, char *parameter,char *u static int Go_ser_sbits_63(gchar** response, int channel, char *parameter,char *units,int command_type) { - int value, status; + int new_stopbits; + int status; switch (command_type) { case command_withparam: - if (status=process_two_ints (parameter, &value, 1, 2)) { + if (status=process_two_ints (parameter, &new_stopbits, 1, 2)) { return status; } - if (value==1) { - globals.RS232.stopbits = rs232_1stop_bit; - } else { - globals.RS232.stopbits = rs232_2stop_bits; - } - - IO_Setup_RS232(); - - return OK; + return IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, (char) new_stopbits, globals.Flash.databits, globals.Flash.hardhand, globals.Flash.echo); break; case query_simple: - if (globals.RS232.stopbits==rs232_1stop_bit) { - value=1; - } else if (globals.RS232.stopbits==rs232_2stop_bits) { - value=2; - } - - return query_int (response, value); + return query_int (response, globals.Flash.stopbits); break; case query_param: @@ -2912,26 +2868,31 @@ static int Go_ser_sbits_63(gchar** response, int channel, char *parameter,char * static int Go_ser_rts_64(gchar** response, int channel, char *parameter,char *units,int command_type) { + char new_hardhand; + switch (command_type) { case command_withparam: if (!strcmp(parameter,"rfr") || !strcmp(parameter,"ibf") || !strcmp(parameter,"ibfull")) { - globals.RS232.hardhand = rs232_hard_on; + // these are valid hardware handshake modes + new_hardhand = 1; } else if (!strcmp(parameter,"on")) { - globals.RS232.hardhand = rs232_hard_off; + // FIXME - confusing: in absence of handware handshaking, + // RTS is supposed to be always ON? Confirm + new_hardhand = 0; } else { return IllegalParameter; } - IO_Setup_RS232(); - - return OK; + return IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, globals.Flash.stopbits, globals.Flash.databits, new_hardhand, globals.Flash.echo); break; case query_simple: - if (globals.RS232.hardhand==rs232_hard_on) { + if (globals.Flash.hardhand) { return query_string(response, "IBF"); - } else if (globals.RS232.hardhand==rs232_hard_off) { + } else { + // FIXME: confirm RTS is always high in BB ports if + // hardware handshaking is not used return query_string(response, "ON"); } return OK; @@ -2948,27 +2909,21 @@ static int Go_ser_rts_64(gchar** response, int channel, char *parameter,char *un static int Go_ser_echo_65(gchar** response, int channel, char *parameter,char *units,int command_type) { - int on_off, status; + int new_echo; + int status; switch (command_type) { case command_withparam: - if (status=process_on_off (parameter, &on_off)) { + if (status=process_on_off (parameter, &new_echo)) { return status; } - - if (on_off) { - globals.RS232.echo = rs232_echo_on; - } else { - globals.RS232.echo = rs232_echo_off; - } - - return OK; + return IO_Setup_RS232(globals.Flash.baud, globals.Flash.parity, globals.Flash.stopbits, globals.Flash.databits, globals.Flash.hardhand, (char) new_echo); break; case query_simple: - if (globals.RS232.echo==rs232_echo_on) { + if (globals.Flash.echo) { return query_int (response, 1); - } else if (globals.RS232.echo==rs232_echo_off) { + } else { return query_int (response, 0); } return OK; |