/***************************************************************************/ /***************************************************************************/ /***************************************************************************/ /******* *******/ /******* D H C - 8 S e r i e s 4 0 0 *******/ /******* *******/ /******* F U E L Q U A N T I T Y G A G I N G S Y S T E M *******/ /******* *******/ /***************************************************************************/ /***************************************************************************/ /***************************************************************************/ /* */ /* Program Name : DHC-8 Fuel Quantity Gaging System (FQGS) */ /* Source File Name : ref.c */ /* CPC : Refuel Processing */ /* Engineer : Katherine Monroe /Sucheta Saraph */ /* Criticality Level : Level C */ /* */ /* Contents : ref_refuel_processing */ /* : def_defuel_processing */ /* : refuel_defuel_init */ /* Description : This CPC performs the automatic refuel/defuel */ /* : processing */ /* */ /* */ /* */ /* Contents of this document are propriety information, property of: */ /* PARKER HANNIFIN CORPORATION */ /* GULL ELECTRONIC SYSTEMS DIVISION */ /* SMITHTOWN, NEW YORK 11787 */ /* Any attempt to copy or use the contents of this document in any manner */ /* whatsoever without express written consent of the owner is prohibited. */ /***************************************************************************/ /***************************************************************************/ /***************************************************************************/ #pragma EJECT /***************************************************************************/ /* Revision History */ /***************************************************************************/ /* */ /* Date Rev Engineer Description */ /* ------ --- -------- ------------------------------------------------ */ /* */ /* */ /* */ /***************************************************************************/ #pragma EJECT #pragma DEBUG #pragma LARGE #pragma NOAM #pragma OBJECTEXTEND #pragma SYMBOLS #define EXTRN extern /* declare all global variables external */ #define MAIN_FILE 0 /* used to declare sbits in globals.h to external */ #define TOTAL 0 #define SELECT_TOTAL 2 //#pragma SRC #include "c:\c51\inc\reg51.h" #include "c:\c51\inc\absacc.h" #include #include "asicaddr.h" #include "defines.h" #include "typedefs.h" #pragma LISTINCLUDE #include "globals.h" #include "prototyp.h" #include "fai.h" #define ANTICIPATION_BUFFER_SIZE 5 #define LOW_BYTE_MASK 0x00ff #define TRANSMIT_TIME 2 /* 2 * 2 seconds = 4 seconds */ /* used with transmit_counter */ extern code uint FAI_FAULT_CODES[]; /**************************/ /* Module level variables */ /**************************/ #pragma EJECT /***************************************************************************/ /* */ /* Unit Name : refuel_defuel_init */ /* Description : This unit sets up to command the refuel/defuel valves */ /* closed and resets auto refuel/defuel in progress. */ /* */ /* */ /* Inputs : None */ /* */ /* Outputs : g_valve_cmd */ /* g_refuel_in_prog */ /* g_defuel_in_prog */ /* */ /* Called by : main startup procedure */ /* */ /* Calls : None */ /* */ /***************************************************************************/ void refuel_defuel_init(void) { g_valve_cmd = RESET; // the default state of valve is off g_refuel_in_prog = RESET; g_defuel_in_prog = RESET; } #pragma EJECT /***************************************************************************/ /* */ /* Unit Name : ref_refuel_processing */ /* Description : This unit monitors the refuel process and determines when */ /* to terminate refuel. */ /* */ /* */ /* Inputs : g_refuel_in_prog */ /* g_selected_qty */ /* g_pdm_fuel_qty */ /* g_current_failure */ /* g_own_refuel_status */ /* g_own_refuel_door */ /* g_others_refuel_status */ /* g_others_preselect_qty */ /* g_others_refuel_door */ /* g_own_sys_imb */ /* g_own_proc_id */ /* */ /* Outputs : g_selected_qty */ /* g_own_refuel_status */ /* g_own_abort_refuel */ /* g_valve_cmd */ /* g_refuel_in_prog */ /* g_pdm_abort_variable */ /* g_pdm_third_row */ /* */ /* Called by : main startup procedure (once every 2 seconds) */ /* */ /* Calls : None */ /* */ /***************************************************************************/ void ref_refuel_processing(void) { static xdata uint anticipation_buffer[ANTICIPATION_BUFFER_SIZE]; static xdata uint last_fuel_qty; static xdata uchar closed_cnt ; xdata uint anticipation_avg; xdata uchar anticipation_index ; xdata uchar count ; xdata uchar found ; xdata uchar side ; xdata uchar antic_index; static xdata uchar transmit_counter; /* used to clear the g_own_refuel_status */ /* in the right side after a few transmissions */ /* to the left side */ static xdata uchar status_counter; /* counter used to clear the g_own_refuel_status */ /* in case if right/left side does not enter */ /* into refuel. */ xdata uchar wait_counter; bit otherside_first_fault_read, myside_first_fault_read ; PDM_OUT_DATA_T xdata *p_fault_list_received ; xdata uint nov_switch_fail_status; /*********************************************************************************/ /* L R */ /* */ /* g_others_preselect_qty <========= g_selected_qty */ /* */ /* g_others_refuel_status <========= g_own_refuel_status <=== g_pdm_start_refuel*/ /* */ /* g_others_refuel_door <========= g_own_refuel_door */ /* */ /* */ /*********************************************************************************/ if (!g_refuel_in_prog) { if (g_own_proc_id == RIGHT_PROCESSOR) { g_refuel_in_prog = g_own_refuel_status; transmit_counter= TRANSMIT_TIME; } else { g_refuel_in_prog = g_others_refuel_status; g_selected_qty = g_others_preselect_qty; g_own_refuel_door = g_others_refuel_door; } if (g_refuel_in_prog) { /*************************************************/ /* Clear anticipation buffer and reset index. */ /*************************************************/ memset(&anticipation_buffer, RESET, sizeof(anticipation_buffer)); anticipation_index = ANTICIPATION_BUFFER_SIZE -1; /*******************************************************/ /* if own qty is above preselect/2 kill refuel_in_prog */ /* flag to prevent changes to the valve state. */ /* Wait for few transmissions before resetting */ /* g_own_refuel_status. */ /* check here for 100 lb/ 50 kg */ /* difference between selected and actual quantities. */ /*******************************************************/ if (g_pdm_fuel_qty[OWN_QTY_ENTRY] >= g_selected_qty/2) { g_refuel_in_prog = RESET; status_counter++; if (status_counter == TRANSMIT_TIME) { g_own_refuel_status = RESET; status_counter = RESET; g_pdm_third_row = SELECT_TOTAL; } } else g_pdm_third_row = SELECT_TOTAL; if (g_own_lbs_kgs_mode) { if ((g_pdm_fuel_qty[TOTAL_QTY_ENTRY] + 50) >= g_selected_qty) { g_refuel_in_prog = RESET; g_own_refuel_status = RESET; g_pdm_third_row = TOTAL; } } else { if ((g_pdm_fuel_qty[TOTAL_QTY_ENTRY] + 100) >= g_selected_qty) { g_refuel_in_prog = RESET; g_own_refuel_status = RESET; g_pdm_third_row = TOTAL; } } } } /*********************************/ /* Bookkeep the transmit counter */ /*********************************/ if (transmit_counter) transmit_counter--; else g_own_refuel_status = RESET; /****************************************************/ /* Check for system imbalance. If system imbalance */ /* present and if this tank qty > opposite tank qty,*/ /* do not refuel this tank till imbalance goes off */ /****************************************************/ if (g_own_sys_imb) { if (g_pdm_fuel_qty[OWN_QTY_ENTRY] > g_pdm_fuel_qty[OTHERS_QTY_ENTRY] ) wait_counter = SET; else wait_counter = RESET; } else wait_counter = RESET; /*************************************************/ /* If failure exists on either side except for */ /* nonvolatile memory failure, disable */ /* the refuel process only if in refuel. */ /*************************************************/ if (g_refuel_in_prog || g_others_refuel_in_prog) { // 5/25/95 if (g_current_failure) { /*************************************************/ /* Removed code checking for nonvolatile memory */ /* or switch faults. Testing for these faults is */ /* performed below. 5/23/95 KM */ /*************************************************/ /*************************************************/ /* Repeat until fault other than nov */ /* fault is found */ /*************************************************/ myside_first_fault_read = RESET; found = RESET; while (!found) { if (!myside_first_fault_read) { myside_first_fault_read = SET; side=MY_SIDE; p_fault_list_received = fai_fault_output(MY_SIDE, 1, RESET_LIST); /***********************************************/ /* Read first fault on this side. If null then*/ /* read first fault on other side. If null */; /* return no more faults. */ /***********************************************/ if (p_fault_list_received == NULL) { /***********************************************/ /* No faults found on my side. */ /***********************************************/ p_fault_list_received = fai_fault_output(OTHER_SIDE, 1, RESET_LIST); side=OTHER_SIDE; otherside_first_fault_read = SET; } } else { p_fault_list_received = fai_fault_output(side, 1, NEXT_FAULT); if (p_fault_list_received == NULL) { if (!otherside_first_fault_read) { side=OTHER_SIDE; p_fault_list_received = fai_fault_output(OTHER_SIDE, 1, RESET_LIST); otherside_first_fault_read = SET; } } } if (p_fault_list_received != NULL) { /************************************/ /* Check for nvm failures. */ /* error code = */ /* */ /************************************/ if ((p_fault_list_received->error_code != (uchar) FAI_FAULT_CODES[NOVRAM_TEST_ID])) { g_refuel_in_prog = g_own_refuel_status = RESET; g_valve_cmd = RESET; // refuel abort close valve g_own_abort_refuel = SET; //added 5/25/95 so that left valve closes g_pdm_abort_variable = SET; // display "ABORT" g_pdm_third_row = TOTAL; // third row = total qty found = SET; } } else if (otherside_first_fault_read == SET) found = SET; } } } /*******************************************************/ /* If Repeater indicator door is closed, or switch is */ /* off, disable refuel and set selected qty to total. */ /*******************************************************/ if (g_own_refuel_door == DOOR_CLOSED) { /*****************************************************/ /* Due to possible power serge of maximum 100ms wait */ /* two cycles (two seconds) before disabling refuel */ /* and resetting the refuel selected quantity. */ /* PR 033 */ /*****************************************************/ if (++closed_cnt == 2) { g_refuel_in_prog = g_own_refuel_status = RESET; g_valve_cmd = RESET; /* CLOSE THE VALVE IF REFUEL IN PROGRESS */ g_selected_qty = g_pdm_fuel_qty[TOTAL_QTY_ENTRY]; g_pdm_third_row = TOTAL; //selected = total qty. closed_cnt = 1; } } else closed_cnt=0; if (g_refuel_in_prog || g_others_refuel_in_prog) { /**************************************************************************/ /* if preselect switch has been touched while in refuel then abort refuel */ /* and resume if qty is correct after new preselect value is accepted */ /* Also abort the process if reset pressed or selector switch changed */ /**************************************************************************/ if (g_own_proc_id == RIGHT_PROCESSOR) { if (g_own_abort_refuel) { g_refuel_in_prog = g_own_refuel_status = RESET; g_valve_cmd = RESET; // refuel abort close valve } } else { // left proc if (g_others_abort_refuel) { g_refuel_in_prog = g_own_refuel_status = RESET; g_valve_cmd = RESET; // refuel abort close valve } } } if ((g_refuel_in_prog == SET)) { if (g_pdm_fuel_qty[OWN_QTY_ENTRY] > last_fuel_qty) anticipation_buffer[anticipation_index] = g_pdm_fuel_qty[OWN_QTY_ENTRY] - last_fuel_qty; else anticipation_buffer[anticipation_index] = 0; anticipation_index++; anticipation_index %= ANTICIPATION_BUFFER_SIZE; /*************************************************/ /* Set anticipated average to average of all non */ /* zero entries in the anticipation buffer. */ /*************************************************/ anticipation_avg = count = 0; for (antic_index=0;antic_index < ANTICIPATION_BUFFER_SIZE; antic_index++) { if (anticipation_buffer[antic_index]) { anticipation_avg += anticipation_buffer[antic_index]; count++; } } if (count) anticipation_avg /= count; else anticipation_avg = 0; /*************************************************/ /* Twice the anticipation avgerage yields a four */ /* second look ahead based on pump rates and */ /* valve closure delay. */ /*************************************************/ if (wait_counter == RESET) { if ((g_pdm_fuel_qty[OWN_QTY_ENTRY] + 2 * anticipation_avg) >= g_selected_qty/2) { g_refuel_in_prog = RESET; g_own_refuel_status = RESET; g_valve_cmd = RESET; /*g_pdm_third_row = TOTAL; */ } else g_valve_cmd = SET; /***************************************************/ /* If other tank qty > selected qty /2 and also */ /* > this tank qty, stop refuel when */ /* this tank qty = selected qty - opposite tank qty*/ /***************************************************/ if ( (g_pdm_fuel_qty[OTHERS_QTY_ENTRY] > g_selected_qty/2) && (g_pdm_fuel_qty[OTHERS_QTY_ENTRY] > g_pdm_fuel_qty[OWN_QTY_ENTRY] )) { if ((g_pdm_fuel_qty[OWN_QTY_ENTRY] + 2 * anticipation_avg) >= (g_selected_qty - g_pdm_fuel_qty[OTHERS_QTY_ENTRY])) { g_refuel_in_prog = RESET; g_own_refuel_status = RESET; g_valve_cmd = RESET; /*g_pdm_third_row = TOTAL; */ } else g_valve_cmd = SET; } } else g_valve_cmd = RESET; /* imbalance forces closing of this valve */ } g_others_abort_refuel = RESET; /* ? */ /*************************************************/ /* Unconditionally set the last fuel qty to the */ /* current fuel qty. */ /*************************************************/ last_fuel_qty = g_pdm_fuel_qty[OWN_QTY_ENTRY] ; } /***************************************************************************/ /* */ /* Unit Name : def_defuel_processing */ /* Description : This unit monitors the defuel process and determines when */ /* to terminate defuel. */ /* */ /* */ /* Inputs : g_defuel_in_prog */ /* g_selected_qty */ /* g_pdm_fuel_qty */ /* g_current_failure */ /* g_own_defuel_status */ /* g_own_refuel_door */ /* g_others_defuel_status */ /* g_others_preselect_qty */ /* g_others_refuel_door */ /* g_own_sys_imb */ /* g_own_proc_id */ /* */ /* Outputs : g_selected_qty */ /* g_own_defuel_status */ /* g_own_abort_defuel */ /* g_valve_cmd */ /* g_defuel_in_prog */ /* g_pdm_abort_variable */ /* g_pdm_third_row */ /* */ /* Called by : main startup procedure (once every 2 seconds) */ /* */ /* Calls : None */ /* */ /***************************************************************************/ void def_defuel_processing(void) { static xdata uint anticipation_buffer1[ANTICIPATION_BUFFER_SIZE]; static xdata uint last_fuel_qty1; static xdata uchar closed_cnt1 ; xdata uint anticipation_avg1; xdata uchar anticipation_index1 ; xdata uchar count1 ; xdata uchar found1 ; xdata uchar side1 ; xdata uchar antic_index1; static xdata uchar transmit_counter1; /* used to clear the g_own_defuel_status */ /* in the right side after a few transmissions */ /* to the left side */ static xdata uchar status_counter1; /* counter used to clear the g_own_defuel_status */ /* in case if right/left side does not enter */ /* into defuel. */ xdata uchar wait_counter1; bit otherside_first_fault_read1, myside_first_fault_read1 ; PDM_OUT_DATA_T xdata *p_fault_list_received1 ; xdata uint nov_switch_fail_status1; /*********************************************************************************/ /* L R */ /* */ /* g_others_preselect_qty <========= g_selected_qty */ /* */ /* g_others_defuel_status <========= g_own_defuel_status <=== g_pdm_start_defuel*/ /* */ /* g_others_refuel_door <========= g_own_refuel_door */ /* */ /* */ /*********************************************************************************/ if (!g_defuel_in_prog) { if (g_own_proc_id == RIGHT_PROCESSOR) { g_defuel_in_prog = g_own_defuel_status; transmit_counter1= TRANSMIT_TIME; } else { g_defuel_in_prog = g_others_defuel_status; g_selected_qty = g_others_preselect_qty; g_own_refuel_door = g_others_refuel_door; } if (g_defuel_in_prog) { /*************************************************/ /* Clear anticipation buffer and reset index. */ /*************************************************/ memset(&anticipation_buffer1, RESET, sizeof(anticipation_buffer1)); anticipation_index1 = ANTICIPATION_BUFFER_SIZE -1; /***********************************************************/ /* if own qty is less than preselect/2 kill defuel_in_prog */ /* flag to prevent changes to the valve state */ /* Wait for few transmissions before resetting */ /* g_own_defuel_status. */ /* check here for imbalance and also 100 lb/ 50 kg */ /* difference between selected qty and total. */ /***********************************************************/ if (g_pdm_fuel_qty[OWN_QTY_ENTRY] <= g_selected_qty/2) { g_defuel_in_prog = RESET; status_counter1++; if (status_counter1 == TRANSMIT_TIME) { g_own_defuel_status = RESET; status_counter1 = RESET; g_pdm_third_row = SELECT_TOTAL; } } else g_pdm_third_row = SELECT_TOTAL; if (g_own_lbs_kgs_mode) { if (g_pdm_fuel_qty[TOTAL_QTY_ENTRY] <= (g_selected_qty + 50)) { g_defuel_in_prog = RESET; g_own_defuel_status = RESET; g_pdm_third_row = TOTAL; } } else { if (g_pdm_fuel_qty[TOTAL_QTY_ENTRY] <= (g_selected_qty + 100)) { g_defuel_in_prog = RESET; g_own_defuel_status = RESET; g_pdm_third_row = TOTAL; } } } } /*********************************/ /* Bookkeep the transmit counter */ /*********************************/ if (transmit_counter1) transmit_counter1--; else g_own_defuel_status = RESET; /****************************************************/ /* Check for system imbalance. If system imbalance */ /* present and if this tank qty < opposite tank qty,*/ /* do not defuel this tank till imbalance goes off */ /****************************************************/ if (g_own_sys_imb) { if (g_pdm_fuel_qty[OWN_QTY_ENTRY] < g_pdm_fuel_qty[OTHERS_QTY_ENTRY] ) wait_counter1 = SET; else wait_counter1 = RESET; } else wait_counter1 = RESET; /*************************************************/ /* If failure exists on either side except for */ /* nonvolatile memory failure, disable */ /* the defuel process only if in auto defuel. */ /*************************************************/ if (g_defuel_in_prog || g_others_defuel_in_prog) { // 5/25/95 if (g_current_failure) { /*************************************************/ /* Removed code checking for nonvolatile memory */ /* or switch faults. Testing for these faults is */ /* performed below. 5/23/95 KM */ /*************************************************/ /*************************************************/ /* Repeat until fault other than switch or nov */ /* fault is found */ /*************************************************/ myside_first_fault_read1 = RESET; found1 = RESET; while (!found1) { if (!myside_first_fault_read1) { myside_first_fault_read1 = SET; side1=MY_SIDE; p_fault_list_received1 = fai_fault_output(MY_SIDE, 1, RESET_LIST); /***********************************************/ /* Read first fault on this side. If null then*/ /* read first fault on other side. If null */; /* return no more faults. */ /***********************************************/ if (p_fault_list_received1 == NULL) { /***********************************************/ /* No faults found on my side. */ /***********************************************/ p_fault_list_received1 = fai_fault_output(OTHER_SIDE, 1, RESET_LIST); side1=OTHER_SIDE; otherside_first_fault_read1 = SET; } } else { p_fault_list_received1 = fai_fault_output(side1, 1, NEXT_FAULT); if (p_fault_list_received1 == NULL) { if (!otherside_first_fault_read1) { side1=OTHER_SIDE; p_fault_list_received1 = fai_fault_output(OTHER_SIDE, 1, RESET_LIST); otherside_first_fault_read1 = SET; } } } if (p_fault_list_received1 != NULL) { /************************************/ /* Check for nvm failure. */ /* error code = */ /* */ /************************************/ if ((p_fault_list_received1->error_code != (uchar) FAI_FAULT_CODES[NOVRAM_TEST_ID])) { g_defuel_in_prog = g_own_defuel_status = RESET; g_valve_cmd = RESET; // defuel abort close valve g_own_abort_defuel = SET; //added 5/25/95 so that left valve closes g_pdm_abort_variable = SET; //display "ABORT" g_pdm_third_row = TOTAL; //selected = total qty. found1 = SET; } } else if (otherside_first_fault_read1 == SET) found1 = SET; } } } /*******************************************************/ /* If Repeater indicator door is closed, or switch is */ /* off, disable defuel and set selected qty to total. */ /*******************************************************/ if (g_own_refuel_door == DOOR_CLOSED) { /*****************************************************/ /* Due to possible power serge of maximum 100ms wait */ /* two cycles (two seconds) before disabling defuel */ /* and resetting the defuel selected quantity. */ /* PR 033 */ /*****************************************************/ if (++closed_cnt1 == 2) { g_defuel_in_prog = g_own_defuel_status = RESET; g_valve_cmd = RESET; /* CLOSE THE VALVE IF REFUEL IN PROGRESS */ g_selected_qty = g_pdm_fuel_qty[TOTAL_QTY_ENTRY]; g_pdm_third_row = TOTAL; // selected = total qty. closed_cnt1 = 1; } } else closed_cnt1=0; if (g_defuel_in_prog || g_others_defuel_in_prog) { /**************************************************************************/ /* if preselect switch has been touched while in defuel then abort defuel */ /* and resume if qty is correct after new preselect value is accepted */ /* Also abort the process if reset pressed or selector switch changed */ /**************************************************************************/ if (g_own_proc_id == RIGHT_PROCESSOR) { if (g_own_abort_defuel) { g_defuel_in_prog = g_own_defuel_status = RESET; g_valve_cmd = RESET; // defuel abort close valve } } else { // left proc if (g_others_abort_defuel) { g_defuel_in_prog = g_own_defuel_status = RESET; g_valve_cmd = RESET; // defuel abort close valve } } } if ((g_defuel_in_prog == SET)) { if (g_pdm_fuel_qty[OWN_QTY_ENTRY] < last_fuel_qty1) anticipation_buffer1[anticipation_index1] = last_fuel_qty1 - g_pdm_fuel_qty[OWN_QTY_ENTRY]; else anticipation_buffer1[anticipation_index1] = 0; anticipation_index1++; anticipation_index1 %= ANTICIPATION_BUFFER_SIZE; /*************************************************/ /* Set anticipated average to average of all non */ /* zero entries in the anticipation buffer. */ /*************************************************/ anticipation_avg1 = count1 = 0; for (antic_index1=0;antic_index1 < ANTICIPATION_BUFFER_SIZE; antic_index1++) { if (anticipation_buffer1[antic_index1]) { anticipation_avg1 += anticipation_buffer1[antic_index1]; count1++; } } if (count1) anticipation_avg1 /= count1; else anticipation_avg1 = 0; /*************************************************/ /* Twice the anticipation avgerage yields a four */ /* second look ahead based on pump rates and */ /* valve closure delay. */ /*************************************************/ if (wait_counter1 == RESET) { if ((g_pdm_fuel_qty[OWN_QTY_ENTRY] ) <= ((g_selected_qty/2) + (2 * anticipation_avg1))) { g_defuel_in_prog = RESET; g_own_defuel_status = RESET; g_valve_cmd = RESET; /*g_pdm_third_row = TOTAL; */ } else g_valve_cmd = SET; /***************************************************/ /* If other tank qty < selected qty /2 and also */ /* < this tank qty, stop refuel when */ /* this tank qty = selected qty - opposite tank qty*/ /***************************************************/ if ( (g_pdm_fuel_qty[OTHERS_QTY_ENTRY] < g_selected_qty/2) && (g_pdm_fuel_qty[OTHERS_QTY_ENTRY] < g_pdm_fuel_qty[OWN_QTY_ENTRY] )) { if ((g_pdm_fuel_qty[OWN_QTY_ENTRY] ) <= ((g_selected_qty - g_pdm_fuel_qty[OTHERS_QTY_ENTRY])+ (2 * anticipation_avg1))) { g_defuel_in_prog = RESET; g_own_defuel_status = RESET; g_valve_cmd = RESET; /*g_pdm_third_row = TOTAL; */ } else g_valve_cmd = SET; } } else g_valve_cmd = RESET; /* imbalance forces closing of this valve */ } g_others_abort_defuel = RESET; /*************************************************/ /* Unconditionally set the last fuel qty to the */ /* current fuel qty. */ /*************************************************/ last_fuel_qty1 = g_pdm_fuel_qty[OWN_QTY_ENTRY] ; }