' ========================================================================= ' ' File....... 21LSD_Wristband.BS2 ' Purpose.... Prototype This: 21st Century Lifesaving, Wristband ' Author..... J. Grand ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' This code is for the wristband component of the 21st Century Lifesaving ' Project. When the button is pushed on the wristband, the GPS coordinates ' (latitude and longitude only) are transmitted via the Aerocomm AC4490 ' radio modem to the base station, cannon, or autonomous drone. ' ' Hardware module reminders: ' ' GPS: Leave /RAW pin unconnected (or pulled HIGH) for "smart" mode. ' ' The GPS must have a clear view of the horizon in order to acquire ' satellites and both GPS and transceiver antennas must be above the water ' line for effective range. ' ' -----[ Revision History ]------------------------------------------------ ' -----[ I/O Definitions ]------------------------------------------------- Alarm_Trigger PIN 0 ' INPUT: active low LED_Ready PIN 2 LED_Active PIN 1 GPS_Sio PIN 12 ' GPS Module serial I/O pin RF_TX PIN 15 ' output to AC4490 radio modem '-[ Constants ]------------------------------------------------------- #SELECT $STAMP #CASE BS2, BS2E, BS2PE T1200 CON 813 T2400 CON 396 T4800 CON 188 T9600 CON 84 T19K2 CON 32 T38K4 CON 6 #CASE BS2SX, BS2P T1200 CON 2063 T2400 CON 1021 T4800 CON 500 T9600 CON 240 T19K2 CON 110 T38K4 CON 45 #ENDSELECT SevenBit CON $2000 Inverted CON $4000 Open CON $8000 GPS_Baud CON T4800 RF_Baud CON T9600 Yes CON 1 No CON 0 ' GPS Module Commands GetInfo CON $00 GetValid CON $01 GetSats CON $02 GetTime CON $03 GetDate CON $04 GetLat CON $05 GetLong CON $06 GetAlt CON $07 GetSpeed CON $08 GetHead CON $09 DegSym CON 176 ' degrees symbol for report MinSym CON 39 ' minutes symbol SecSym CON 34 ' seconds symbol ' -----[ Variables ]------------------------------------------------------- ' --- GPS --- valid VAR BIT ' signal valid? 0 = not valid, 1 = valid degrees VAR BYTE ' degrees minutes VAR BYTE ' minutes minutesD VAR WORD ' decimal minutes dir VAR BYTE ' direction (latitude: 0 = N, 1 = S, longitude: 0 = E, 1 = W) workVal VAR WORD ' for numeric conversions long_degrees VAR BYTE ' degrees long_minutes VAR BYTE ' minutes long_minutesD VAR WORD ' decimal minutes long_dir VAR BYTE ' direction (latitude: 0 = N, 1 = S, longitude: 0 = E, 1 = W) long_workVal VAR WORD ' for numeric conversions ' -----[ EEPROM Data ]----------------------------------------------------- ' -----[ Initialization ]-------------------------------------------------- DEBUG CR, CR, "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*", CR Init: DEBUG CR, "Wristband system ready...", CR INPUT Alarm_Trigger valid = 0 ' GPS signal valid flag HIGH LED_Ready LOW LED_Active PAUSE 1000 ' -----[ Program Code ]---------------------------------------------------- Main: ' check for valid GPS signal - hopefully the person's arm is above the water! Wait_Valid: GOSUB GPS_Get_Valid IF (valid = 0) THEN 'DEBUG "GPS signal not valid!", CR TOGGLE LED_Ready ' blink LED until GPS has acquired satellites PAUSE 250 ' wait a bit and try again GOTO Wait_Valid ENDIF HIGH LED_Ready IF (Alarm_Trigger = 1) THEN GOTO Main ' wristband trigger has been activated DEBUG CR, "Wristband trigger button activated!", CR SendGPSAgain: HIGH LED_Active ' get coordinates of the target GOSUB GPS_Get_Lat GOSUB GPS_Get_Long ' send those to the base station/cannon/autonomous drone ' ASCII version for testing 'SEROUT RF_TX, RF_Baud, ["A", 43 + (dir * 2), DEC degrees, ".", DEC4 workVal, ", ", 43 + (long_dir * 2), DEC long_degrees, ".", DEC4 long_workVal, "B", CR] 'DEBUG HEX degrees, " ", HEX minutes, " ", HEX minutesD.HIGHBYTE, " ", HEX minutesD.LOWBYTE, " ", HEX dir, " ", CR 'DEBUG HEX long_degrees, " ", HEX long_minutes, " ", HEX long_minutesD.HIGHBYTE, " ", HEX long_minutesD.LOWBYTE, " ", HEX long_dir, " ", CR, CR ' Binary version for real use SEROUT RF_TX, RF_Baud, ["A", degrees, minutes, minutesD.HIGHBYTE, minutesD.LOWBYTE, dir, long_degrees, long_minutes, long_minutesD.HIGHBYTE, long_minutesD.LOWBYTE, long_dir, "B"] PAUSE 250 LOW LED_Active PAUSE 1000 IF (Alarm_Trigger = 1) THEN ' keep transmitting until button is pressed GOTO SendGPSAgain ELSE ' if button is held down after transmitting, reset system WaitForDepress: IF (Alarm_Trigger = 0) THEN GOTO WaitForDepress ' wait for button to be released GOTO Init ENDIF END ' -----[ Subroutines ]----------------------------------------------------- GPS_Get_Valid: SEROUT GPS_Sio, GPS_Baud, ["!GPS", GetValid] SERIN GPS_Sio, GPS_Baud, 3000, No_GPS, [valid] ' wait up to 3 seconds for a response RETURN ' ---------------------------------------------------- GPS_Get_Lat: SEROUT GPS_Sio, GPS_Baud, ["!GPS", GetLat] SERIN GPS_Sio, GPS_Baud, 3000, No_GPS, [degrees, minutes, minutesD.HIGHBYTE, minutesD.LOWBYTE, dir] ' convert decimal minutes to tenths of seconds workVal = minutesD ** $0F5C ' minutesD * 0.06 DEBUG "Latitude: ", DEC3 degrees, DegSym, " ", DEC2 minutes, MinSym, " " DEBUG DEC2 (workVal / 10), ".", DEC1 (workVal // 10), SecSym, " " DEBUG "N" + (dir * 5) ' convert to decimal format, too workVal = (minutes * 1000 / 6) + (minutesD / 60) DEBUG " (", " " + (dir * 13), DEC degrees, ".", DEC4 workVal, " ) ", CR RETURN ' ---------------------------------------------------- GPS_Get_Long: SEROUT GPS_Sio, GPS_Baud, ["!GPS", GetLong] SERIN GPS_Sio, GPS_Baud, 3000, No_GPS, [long_degrees, long_minutes, long_minutesD.HIGHBYTE, long_minutesD.LOWBYTE, long_dir] ' convert decimal minutes to tenths of seconds long_workVal = long_minutesD ** $0F5C ' minutesD * 0.06 DEBUG "Longitude: ", DEC3 long_degrees, DegSym, " ", DEC2 long_minutes, MinSym, " " DEBUG DEC2 (long_workVal / 10), ".", DEC1 (long_workVal // 10), SecSym, " " DEBUG "E" + (long_dir * 18) ' convert to decimal format, too long_workVal = (long_minutes * 1000 / 6) + (long_minutesD / 60) DEBUG " (", " " + (long_dir * 13), DEC long_degrees, ".", DEC4 long_workVal, " ) ", CR, CR RETURN ' ---------------------------------------------------- No_GPS: DEBUG "Can't communicate with GPS!", CR ' ruh-roh, Shaggy LOW LED_Ready HIGH LED_Active ' only red LED means error! Wait_Button: IF (Alarm_Trigger = 1) THEN GOTO Wait_Button ' wait for button press to restart the system DEBUG "Resetting system...", CR PAUSE 2000 GOTO Init ' ----------------------------------------------------