/************************************************************************** * Modified by: hcpatel 95s522 95solc 1995/05/18 * Added #ifdef DEBUG conditions which binds printf statements. This changes * were implemented by jcaiani in 94f522 project. This printf statements can * be executed, if DEBUG is defined in header file f93olc.h. **************************************************************************/ /******************************************************/ /* */ /* File : timer.c */ /* Author: Cheng-Lu Yeng */ /* rev by RJL 94/11/14: added comments at //RJL: ... */ /* */ /******************************************************/ # include # include #include "olc96fa.h" # if !defined OLC3COMMON_H # include "olc3common.h" # endif # if !defined TIMER_H # include "timer.h" # endif /* ** TimerFirst ** TimerNext ** TimerDelete */ STANDARDROUTINES(Timer,TI) /****************************************************/ /* */ /* Create Timer */ /* */ /****************************************************/ FUNCTION5( void TimerCreate, hcg_key, TimerActiveInstance, hcg_key, FireFromThisActiveInstance, hcg_key, FireToThisActiveInstance, hcg_key, FireThisTypeOfEvent, int, TimeToGo ) { #ifdef GENV7 char databuffer[BUFSIZE]; KEYBUFFER(TIkey); KEYBUFFER(AI1key); KEYBUFFER(AI2key); KEYBUFFER(AI3key); KEYBUFFER(ET1key); /* ** Get the keys we need */ decode(AI1key, &TimerActiveInstance); decode(AI2key, &FireFromThisActiveInstance); decode(AI3key, &FireToThisActiveInstance); decode(ET1key, &FireThisTypeOfEvent); pr_gen_pkey("JuicePlantTransfer", TI, TIkey); /* ** Form the new table line //RJL: This shows that genv7 was used, NOT genv8: */ sprintf(databuffer, " %s %s %s %s %s %d ", TIkey, AI1key, AI2key, AI3key, ET1key, TimeToGo ); /* ** And add it */ pr_add("JuicePlantTransfer", databuffer); #else struct TI *TI_elt; TI_elt = pr_create(TI); pr_set_key(TI_elt, AIid1, TimerActiveInstance); pr_set_key(TI_elt, AIid2, FireFromThisActiveInstance); pr_set_key(TI_elt, AIid3, FireToThisActiveInstance); pr_set_key(TI_elt, ETid, FireThisTypeOfEvent); pr_set_int(TI_elt, ttg, TimeToGo); #ifdef ORIG pr_add("JuicePlantTransfer", TI, TI_elt); #else gen_pr_add("JuicePlant", "TI", (hcg_ptr)TI_elt); #endif #endif #ifdef DEBUG printf("##### The TimerCreate is done ! #####\n"); #endif } FUNCTION5( void GenerateTimer, const char *, TimerActiveInstance, const char *, FireFromThisActiveInstance, const char *, FireToThisActiveInstance, const char *, FireThisTypeOfEvent, int, TimeToGo ) { hcg_key AIid1; hcg_key AIid2; hcg_key AIid3; hcg_key ETid; int bad; /* ** Convert the names of the Active Instances and the Label of the ** event into keys */ bad = 0; find_str_loop("JuicePlant", AI, Name, FireFromThisActiveInstance) { break; } if (AIcurr == 0) { printf("Could not find an Active Instance named %s.\n", FireFromThisActiveInstance); bad = 1; } else { AIid2 = AIcurr->AIid; } find_str_loop("JuicePlant", AI, Name, FireToThisActiveInstance) { break; } if (AIcurr == 0) { printf("Could not find an Active Instance named %s\n", FireToThisActiveInstance); bad = 1; } else { AIid3 = AIcurr->AIid; } find_str_loop("JuicePlant", AI, Name, TimerActiveInstance) { break; } if (AIcurr == 0) { printf("Could not find an Active Instance named %s\n", TimerActiveInstance); bad = 1; } else { AIid1 = AIcurr->AIid; } find_str_loop("JuicePlant", ET, Label, FireThisTypeOfEvent) { break; } if (ETcurr == 0) { printf("Could not find an Event labeled %s.\n", FireThisTypeOfEvent); bad = 1; } else { ETid = ETcurr->ETid; } if (bad) { printf("Event not generated\n"); return; } TimerCreate( AIid1, AIid2, AIid3, ETid, TimeToGo ); } FUNCTION5( void TICreate, hcg_key , AIid1, hcg_key , AIid2, hcg_key , AIid3, const char *, FireThisTypeOfEvent, int, TimeToGo ) { hcg_key ETid; int bad; /* ** Convert the names of the Active Instances and the Label of the ** event into keys */ bad = 0; find_str_loop("JuicePlant", ET, Label, FireThisTypeOfEvent) { break; } if (ETcurr == 0) { printf("Could not find an Event labeled %s.\n", FireThisTypeOfEvent); bad = 1; } else { ETid = ETcurr->ETid; } if (bad) { printf("Event not generated\n"); return; } TimerCreate( AIid1, AIid2, AIid3, ETid, TimeToGo ); } GETROUTINE(hcg_key, Timer,TI,AIid1) GETROUTINE(hcg_key, Timer,TI,AIid2) GETROUTINE(hcg_key, Timer,TI,AIid3) GETROUTINE(hcg_key, Timer,TI,ETid) GETROUTINE(int, Timer,TI,ttg)