COLD
( GPS.4TH 2.1)
(
( This program is confidential property of Datalink Systems
(
( Revised  11/4/97
( For Novatel
( Revision 12/24/96
( Fixed tail gate switch to reflect the actual state of the tailgate
( on normal timed transmision
( Revision 11/21/96
( moved tail gate to PORTA pin 2 from portc pin 0
( This allows it to be interupt driven in the C program
( The state of this pin is translated to the value 1 in the switch state
(    variable this is to be backward compatible with the first program
( This prevents any other switch from being connected to POERTE pin 0
( Other switch states can be sent by pulling pins of PORTE high.
( moved modem in range to portd pin 4 was porte pin 7
( moved modem conected to portd pin 5 was porte pin 6
(
(  REVISION 11/04/96 2.0
( Change to 8 mph for moving
( AUTO START VERSION
( REQUIRES BATTERY BACKED UP RAM OR SRAM.
( GORDON COUGER 405 624 2855 gcouger@ionet.net )
COLD ( COLD BOOT CLEARS ALL WORDS
6 CONSTANT GPS-TIMEOUT      ( 3 = 1 MINUTE *****  
0  CONSTANT ERR-OK
1  CONSTANT ERR-UNKNOWN
2  CONSTANT ERR-POWER
4  CONSTANT ERR-GPS
8  CONSTANT ERR-NO-GPS
16 CONSTANT ERR-MODEM-COVERAGE
64 CONSTANT  TAILGATE_DOWN
30435 CONSTANT CCC

1 CONSTANT TRUE
0 CONSTANT FALSE
HEX                           ( SWITCH TO HEX NOTATION 
B000 CONSTANT PORTA
B008 CONSTANT PORTD
B00A CONSTANT PORTE           ( DEFINES I/O PORTS
B007 CONSTANT DDRC            ( DATA DIRECTION REGISTER FOR PORT C
DECIMAL                       ( SWITCH TO DECIMAL NOTATION
VARIABLE GPS 50 ALLOT         ( STRING TO STORE INCOMING DATA FROM GPS
VARIABLE IN-STR?              ( FLAG SET TO TRUE WHEN IN VALID GPS STRING
VARIABLE LAST-TIME            ( LAST TIME MESSAGE SENT
VARAIBLE STATUS               ( NOT USED FOR ANYTHING YET
VARIABLE STRLEN               ( USED IN INPUT WORD
VARIABLE SENT
VARIABLE TCOUNT               ( COUNTS NUMBER OF TIMES THROUGH PROGRAM
VARIABLE TC2                  ( 20 SECOND COUNTER 
VARIABLE PORT_STATE
VARIABLE CNT
VARIABLE DONE
VARIABLE SEND-POLL
FALSE SEND-POLL

: W5 120 0 DO 1000 0 DO LOOP LOOP ;    ( WAIT 5 SECONDS

: DIAL                        ( 11/05/97 DIAL REPLACED FOR NOVATEL
  0 DONE !
  BEGIN
    0 CNT !
    BEGIN
     0
     ?TERMINAL IF
            DROP
            
            KEY
            75 = NOT IF
               0
            
            ELSE
               1
               1 DONE !
             THEN
         THEN
      CNT @ 1 + CNT !
      CNT @ 5000 > IF
         ." ATDP209.48.246.16/6000" CR ( *** CHANGE TO PROPER NUMBER
         0 CNT !
         DROP
         1 THEN 
      UNTIL 
    DONE @ UNTIL ;

: DELIMIT 124 EMIT ;                      ( PRINTS | CHARACTER

: STATUS? ( LEAVES STATAUS ON STACK GOOD = TRUE BAD = FALSE 
   GPS 32 + C@                ( PUT AGE OF DATA BIT ON STACK
   31 = NOT ;

: SPEED?  ( LEAVES SPEED ON STACK
  32 GPS 29 + C!              ( PUT SPACE AFTER SPEED
  .0 GPS 26 + CONVERT         ( CONVERT SPEED TO VALUE
  2DROP                       ( CLEAR ADDRESS AND HI DOUBLE OFF STACK
  ;

: TIME? ( LEAVES GPS TIME ON STACK VALUE
  .0 GPS 3 + CONVERT ( ONLY USE INTEGER PART OF TIME NOT INTERESTED IN
  2DROP              ( MORE THAN AN HOUR SO IT DOES NOT AGREE WITH THE 
  ;                  ( VALUE IN THE GPS STRING

: NEED-TO-SEND?
   LAST-TIME @ TIME? > IF TIME? LAST-TIME ! THEN
   SPEED? 8 >                        ( IS IT MOVING faster than 8 MPH
   IF
     TIME? LAST-TIME @ 60 + >     ( IF IT IS SEND AFTER 60 SECONDS
   ELSE
      TIME? LAST-TIME @ 120 + >   ( IF IT NOT MOVING SEND AFTER 120 SECONDS
   THEN
;

HEX


DECIMAL

: SSEND
   TIME? LAST-TIME !        ( STORE CURRENT AS LAST TIME MSG WAS SENT
   STATUS @ TAILGATE_DOWN AND IF ( FIXED ERROR IN TAILGATE DOWN
      1 ELSE 0 THEN             ( 12/24/96 HAD TO LEAVE THESE LINES
   PORTE C@ OR PORT_STATE !       
   PORTA C@ 4 AND IF       ( CHANGE 4 TO MATCH PORT A CONNECTION
                           ( 1 = PORTA.0 2= PORTA.1 4 = PORTA.2
      1 ELSE 0 THEN        ( ADDED THESE 12/24/95
   PORT_STATE @ OR PORT_STATE !
   GPS 38 + 4 TYPE DELIMIT  ( GPS ID
   GPS 26 + 3 TYPE DELIMIT  ( GPS SPEED
   GPS 17 + 9 TYPE DELIMIT  ( GPS LONGATUDE
   GPS 9 + 8 TYPE DELIMIT   ( GPS LATITUDE
   GPS 4 + 5 TYPE DELIMIT   ( GPS TIME 
   PORT_STATE @ . DELIMIT       ( PORT STATE OF DIGITAL INPUTS
   STATUS @ .               ( SEND STATUS 
   CR
   0 STATUS !               ( CLEAR STATUS
   TRUE SENT !
   FALSE SEND-POLL !
   CCC TCOUNT !               ( RESET TCOUNT 20 SECONDS
   GPS-TIMEOUT TC2 !            ( RESET MINUTE COUNTER
   ;

: SEND            ( TRIES TO SEND A MESSAGE TO THE MODEM IF THE MODEM IS UP
   IN-STR? @ FALSE = IF
       SSEND
       THEN
   ;
   
: RUN         ( MAIN PROGRAM
  
  ( 49 45099 C!             (  TO SHIFT TO 4800 BAUD *** REMOVE ( 
                          ( INITIALIZE VARAIABLES
  ERR-POWER STATUS !      ( POWER HAS BEEN DOWN 
  DIAL         
  FALSE IN-STR? !
  0 LAST-TIME !
  0 DDRC C!               ( SET PORT C TO INPUT
 CCC TCOUNT !  ( 20 SEDCONDS
 GPS-TIMEOUT TC2 !            ( RESET MINUTE COUNTER
 
  BEGIN
  TCOUNT @ 1- DUP TCOUNT ! 0 = IF         ( GPS TIME OUT ********
     CCC TCOUNT !
     TC2 @ 1- DUP TC2 ! 0 = IF
        STATUS @ ERR-GPS  OR STATUS ! 
        SEND
        THEN
     THEN
   PORTA C@ 4 AND IF       ( PORT A.2 TAILGATE down
                           ( CHANGE 4 TO MATCH PORT A CONNECTION
                           ( 1 = PORTA.0 2= PORTA.1 4 = PORTA.2
     SENT @ FALSE = IF
        200 0 DO LOOP      ( DEBOUNCE INCREAST THE FIRST NUMBER IF NEEDED ****
        STATUS @ TAILGATE_DOWN  OR STATUS ! 
        SEND THEN 
    ELSE 
      FALSE SENT ! THEN 
   ?TERMINAL IF               ( IF CHARCETER IS RECEIVED
      KEY                     ( GET THE KEY
      DUP                     ( DUPLICATE IT ON STACK
      DUP                     ( POLLING  11/05/97
      87 = IF                 ( IF W
        SSEND
        THEN                  ( END POLLING
      62 = IF                 ( LOOK FOR > AT START OF STRING
        TRUE IN-STR? !        ( SET START FLAG TRUE
        0 STRLEN !            ( SET STRING COUNTER TO 0
        THEN 
      DUP                     ( DUPLICATE RECIEVED CHAR ON STACK
      60 = IF                 ( LOOK FOR < ON END OF GPS STRING
         IN-STR? @ IF
            FALSE IN-STR? !      ( SET START STRING FLAG TO FALSE 
            NEED-TO-SEND? IF
                SEND
                THEN
            
            THEN
         THEN
      IN-STR? @ IF            ( IF START FLAG IS TRUE
         GPS STRLEN @ + C!    ( STORE CHAR IN GPS STRING
         STRLEN @ 1+ STRLEN ! ( INCREMENT STRING LENGTH
      ELSE
         DROP                 ( DISCARD CHARS NOT BETWEEN ><
         THEN
      THEN 
     
   0 UNTIL ;
HEX

( *** REMOVE ( FOR AUTO START
( ' RUN CFA >< B602 EEC!       ( SETS AUTO START PATTER & ADDRESS IN EEPROM


( *** REMOVE ( FOR AUTO START
( ' RUN CFA B603 EEC!


( *** REMOVE ( FOR AUTO START
( A4 B600 EEC!


( *** REMOVE ( FOR AUTO START
( 4A B601 EEC!


DECIMAL
