# Incomplete source, for demonstration only # Definitions #define STARTUP EM1 # Startup email sent to this address #define UPDATE EM2 # Periodic updates sent to this address #define ALARMA1 EM3 # Analog 1 alarm # Analog input 1 #define A1_LOLO 400 # Very-low limit #define A1_LO 500 # Low limit #define A1_HI 700 # High limit #define A1_HIHI 800 # Very-high limit #define A1_TIMEA 300 # LO/HI time #define A1_TIMEB 600 # LOLO/HIHI time #define PERIODIC_UPDATE_TIME 300 # How often we call home #define MANUAL_UPDATE OP1 # request a manual status update #define Alarm_Digital_Stucklow # only alarm if digital inputs stuck low (otherwise does both low and high) #------- No user-servicable parts past here. # Map timers to register resources #define A1_TIMERA ram6h # Timer 1A #define A1_TIMERB ram6l # Timer 1B #define ID var1 # Event ID register #define NEXT_MESSAGE_TIME var4 # When to send next refresh email #define scratch var2 # General working register #define ALARM_LL 1 # Alarm code for
hi #define ALARM_HH 4 # Alarm code for >hihi #define ALARM_STARTUP 999 # Signal board is starting up #define ALARM_UPDATE 900 # Signal board is doing a periodic update set A1_TIMERA A1_TIMEA # Preset timers set A1_TIMERB A1_TIMEB delay 5000 # Let things settle set ID ALARM_STARTUP # reboot ID email STARTUP TSYNC: tstlt CYEAR 2015 goto TSYNC add CTS PERIODIC_UPDATE_TIME NEXT_MESSAGE_TIME # send update soon LOOP: set scratch CTS # wait for a second SECOND: tsteq CTS scratch # same? goto SECOND # yes, so loop tsteq MANUAL_UPDATE 1 # is a manual output requested? set NEXT_MESSAGE_TIME 0 set MANUAL_UPDATE 0 # clear request tstlt CTS NEXT_MESSAGE_TIME # time to send status report? goto nosend add CTS PERIODIC_UPDATE_TIME NEXT_MESSAGE_TIME # re-send in another hour set ID ALARM_UPDATE # periodic update ID email UPDATE swu: tstgt emailq 0 # has message gone yet? goto swu # no? So wait. nosend: add AIP1 1 scratch # read analog input to prevent comparison jitter tstlt scratch A1_LO # is analog below LO? goto LO1 tstgt scratch A1_HI # is analog above HI? goto HI1 SET A1_TIMERA A1_TIMEA # reset timer 1A set A1_TIMERB A1_TIMEB # reset timer 1B goto A2 # test next input LO1: tstgt scratch A1_LOLO # is analog above LOLO? goto S1 # set timer A2 goto T1 HI1: tstlt scratch A1_HIHI # is analog below HIHI? S1: set A1_TIMERB A1_TIMEB # reset timer 1B T1: # Test analog alarms tstne A1_TIMERA 1 # is timer 1A about to exire? goto T1A # no, so decrement timer and skip the alarm set ID ALARM_H tstlt scratch A1_LO # less than low limit? set ID ALARM_L # set ID=2 if low or ID=3 if high tstgt emailq 1 # mail queue short enough to send? goto T1B # defer sending mail, retry in a second. add 100 ID ID # add "analog input 1" ID email ALARMA1 # send alarm email swa1: tstgt emailq 0 # has message gone yet? goto swa1 # no? So wait. T1A: tstgt A1_TIMERA 0 # if timer 1A has not exired dec A1_TIMERA # decrement it T1B: tstne A1_TIMERB 1 # is timer 1B about to exire? goto t1c # no, so decrement timer and skip the alarm set ID ALARM_HH tstlt scratch A1_LO # less than low limit? set ID ALARM_LL # set ID for lolo or hihi as appropriate tstgt emailq 1 # mail queue short enough to send? goto A2 # defer sending mail, retry in a second. add 100 ID ID # add "analog input 1" ID email ALARMA1 # send alarm email swa1b: tstgt emailq 0 # has message gone yet? goto swa1b # no? So wait. T1C: tstgt A1_TIMERB 0 # if timer 1B has not exired dec A1_TIMERB # decrement it A2: goto loop
or