CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 GPS_PIN_TX = 0 GPS_PIN_RX = 1 GPS_PIN_RST = 2 GSM_Rx = 3 GSM_Tx = 4 GSM_power = 5 GSM_Baud = 9600 Pol_Rx = 6 Pol_Baud = 9600 CLS = 16 CR = 13 QUOTE = 34 DP1 = $42 DP2 = $4d LP1 = $00 LP2 = $14 CON GSM_TIMEOUT = 1000 POSO_TIMEOUT = 100 CON '' '' Parallax Serial Terminal '' Control Character Constants ''───────────────────────────────────── CS = 16 ''CS: Clear Screen CE = 11 ''CE: Clear to End of line CB = 12 ''CB: Clear lines Below HM = 1 ''HM: HoMe cursor PC = 2 ''PC: Position Cursor in x,y PX = 14 ''PX: Position cursor in X PY = 15 ''PY: Position cursor in Y NL = 13 ''NL: New Line LF = 10 ''LF: Line Feed ML = 3 ''ML: Move cursor Left MR = 4 ''MR: Move cursor Right MU = 5 ''MU: Move cursor Up MD = 6 ''MD: Move cursor Down TB = 9 ''TB: TaB BS = 8 ''BS: BackSpace BP = 7 ''BP: BeeP speaker VAR byte AT_Reponse[150], dataSet[150] byte ptr, ptr1, ptr2 Long cog2, cog3, cog4, cog6 Long UTC_Time, Local_Time, Heure_Local, Minutes_Local, Seconde_Local, jour, mois, annee, Altitude, Degre_latitude, Minute_latitude, Seconde_latitude Long Degre_longitude, Minute_longitude, Seconde_longitude, Vitesse, Nbres_satellites Long a, b,a0,c, d,c0,NU1,NU2,NU3, Checksum OBJ pst : "FullDuplexSerial" ' uses one cog GSM : "FullDuplexSerial" ' uses one cog GPS : "gps_basic" ' uses two cogs Pol : "FullDuplexSerial" ' uses one cog Pub main | lat, lon, ok cog2 := pst.start(31, 30, 0, 115200) repeat pst.str(String(13, "Press any key to begin.")) waitcnt(clkfreq / 2 + cnt) result := Pst.RxCheck while result == -1 pst.str(String(CS, HM, NL,"Le cog2 est: ",9)) pst.dec(Cog2) cog3 := Pol.start(Pol_Rx, -1, 0, Pol_Baud) pst.str(String(NL,"Le cog3 est: ",9)) pst.dec(Cog3) cog4 := GPS.startx(GPS_PIN_RX, 2, 9600, 2500) ' this returns the value "(rxcog) and (parsecog)" from the GPS object pst.str(String(NL,"Le cog4 est: ",9)) pst.dec(Cog4) pst.str(String(13, "If cog4 equals -1 then the GPS object launched successfully.")) pst.str(String(13, "If cog4 equals 0 then the GPS object did not launch correctly.")) cog6 := GSM.start(GSM_Rx, GSM_Tx, 0, GSM_Baud) pst.str(String(NL,"Le cog6 est: ",9)) pst.dec(Cog6) pst.str(String(13, 13, "The GSM will now be initialized.")) pst.str(String(13, "This will take a while (likely over 10 seconds).", 13)) GSM_Start pst.str(String(13, "The GSM has been initialized.")) pst.str(String(13, "This program uses cogs #0 through cog #")) pst.dec(Cog6 - 1) pst.tx(".") pst.str(String(13, "This program uses ")) pst.dec(Cog6) pst.str(String(" of the 8 cogs.")) pst.str(String(13, 13, "Press any key to begin main program loop.", 7)) repeat result := Pst.RxCheck while result == -1 MainLoop PUB MainLoop repeat Poso_Check(POSO_TIMEOUT) GPS_Check PUB GSM_Start Start_Module waitcnt(clkfreq*5+cnt) ptr := 0 gsm.str(string("AT",13)) Rx_GSM(GSM_TIMEOUT) pst.Str(String(13)) pst.str(String("La réponse à ta requete est la suivante 0: ",9)) pst.Str(@AT_Reponse) pst.Str(String(13)) gsm.str(string("AT+CPIN=",34,"00000000",34,13)) Rx_GSM(GSM_TIMEOUT) pst.Str(String(13)) pst.str(String("La réponse à ta requete est la suivante 0,4: ",9)) pst.Str(@AT_Reponse) pst.Str(String(13)) gsm.str(string("AT+CGDCONT=1,",34,"IP",34,",",34,"orange",34,13)) Rx_GSM(GSM_TIMEOUT) pst.Str(String(13)) pst.str(String("La réponse à ta requete est la suivante 2: ",9)) pst.Str(@AT_Reponse) pst.Str(String(13)) waitcnt(clkfreq*30+cnt) gsm.str(string("AT+CGATT=1",13)) Rx_GSM(GSM_TIMEOUT) pst.Str(String(13)) pst.str(String("La réponse à ta requete est la suivante 1: ",9)) pst.Str(@AT_Reponse) pst.Str(String(13)) gsm.str(String("AT+SAPBR=3,1,",34,"Contype",34,",",34,"GPRS",34,13)) Rx_GSM(GSM_TIMEOUT) pst.Str(String(13)) pst.str(String("La réponse à ta requete est la suivante 3: ",9)) pst.Str(@AT_Reponse) pst.Str(String(13)) gsm.str(String("AT+SAPBR=3,1,",34,"APN",34,",",34,"orange.fr",34,13)) Rx_GSM(GSM_TIMEOUT) pst.Str(String(13)) pst.str(String("La réponse à ta requete est la suivante 4: ",9)) pst.Str(@AT_Reponse) pst.Str(String(13)) gsm.str(String("AT+SAPBR=3,1,",34,"USER",34,",",34,"orange",34,13)) Rx_GSM(GSM_TIMEOUT) pst.Str(String(13)) pst.str(String("La réponse à ta requete est la suivante 5: ",9)) pst.Str(@AT_Reponse) pst.Str(String(13)) gsm.str(String("AT+SAPBR=3,1,",34,"PWD",34,",",34,"orange",34,13)) Rx_GSM(GSM_TIMEOUT) pst.Str(String(13)) pst.str(String("La réponse à ta requete est la suivante 6: ",9)) pst.Str(@AT_Reponse) pst.Str(String(13)) gsm.str(String("AT+SAPBR=1,1",13)) Rx_GSM(GSM_TIMEOUT) pst.Str(String(13)) pst.str(String("La réponse à ta requete est la suivante 7: ",9)) pst.Str(@AT_Reponse) pst.Str(String(13)) PUB Start_Module dira[GSM_power]~~ outa[GSM_power]~ waitcnt(clkfreq/5+cnt) outa[GSM_power]~~ Pub Rx_GSM(timeout) | localChar GSM.RxFlush repeat localChar := GSM.RxTime(timeout) if localChar <> -1 SafeTx(localChar) else pst.str(string(13, "ERROR: Rx_GSM timeout")) quit while (localChar <> 10) and localChar <> 0 RxPacketNow_GSM(timeout) PUB SafeTx(localChar) case localChar " ".."~", 191..255: pst.tx(localChar) other: pst.tx("<") pst.tx("$") pst.hex(localChar, 2) pst.tx(">") Pri RxPacketNow_GSM(timeout) | valeur, localChar ptr := 0 ptr1 := 0 Repeat localChar := GSM.RxTime(timeout) if localChar <> -1 SafeTx(localChar) AT_Reponse[ptr++] := localChar while localChar <> 13 and localChar <> -1 and localChar <> 0 if localChar <> -1 AT_Reponse[--ptr] := 0 else pst.str(string(13, "ERROR: RxPacketNow_GSM timeout")) PUB GPS_Check | ok if (gps.hasgps == false) pst.str(string("No GPS")) else pst.str(String(CR,"OK")) pst.dec(gps.s_gpsfix) ' gps quality (fix) ok := gps.n_gpsfix ' flag for other fields pst.str(String(CR,"Nbre satellite est: ")) Nbres_satellites := GPS.n_satellites pst.dec(Nbres_satellites) pst.str(String(CR,"UTC Time: ")) UTC_Time := GPS.fs_utc_time pst.str(UTC_Time) pst.str(String(CR,"Local Time: ")) Local_Time := GPS.fs_local_time pst.str(Local_Time) pst.str(String(CR,"Local Time: ")) Heure_Local := GPS.s_local_hrs Heure_Local := StrToDec(Heure_Local) pst.dec(Heure_Local) Minutes_Local := GPS.s_mins Minutes_Local := StrToDec(Minutes_Local) pst.dec(Minutes_Local) Seconde_Local := GPS.s_secs Seconde_Local := StrToDec(Seconde_Local) pst.dec(Seconde_Local) pst.str(String(CR,"Date: ")) pst.str(GPS.fs_date) pst.str(String(CR,"Date: ")) jour := GPS.s_day jour := StrToDec(jour) pst.dec(jour) mois := GPS.s_month mois := StrToDec(mois) pst.dec(mois) annee := GPS.s_year annee := StrToDec(annee) pst.dec(annee) pst.str(String(CR,"La latitude est: ")) Degre_latitude := GPS.n_latd pst.dec(Degre_latitude) pst.str(String("°")) Minute_latitude := GPS.n_latm pst.dec(Minute_latitude) pst.str(String("'")) Seconde_latitude := GPS.n_lats pst.dec(Seconde_latitude) pst.str(String(QUOTE)) pst.str(String(CR,"La longitude est: ")) Degre_longitude := GPS.n_lond pst.dec(Degre_longitude) pst.str(String("°")) Minute_longitude := GPS.n_lonm pst.dec(Minute_longitude) pst.str(String("'")) Seconde_longitude := GPS.n_lons pst.dec(Seconde_longitude) pst.str(String(QUOTE)) pst.str(String(CR,"L'altitude est: ")) Altitude := GPS.n_altm pst.dec(Altitude) pst.str(String(CR,"La vitesse est de: ")) Vitesse := GPS.n_speedm*1.609344 pst.dec(Vitesse) pst.str(String(" Km/h ")) waitcnt(clkfreq + cnt) pst.Str(String(CLS)) PUB StrToDec(stringptr) : value | index, multiply, localChar '' Converts a zero terminated string representation of a decimal number to a value value := index := 0 repeat until ((localChar := byte[stringptr][index++]) == 0) if localChar => "0" and localChar =< "9" value := value * 10 + (localChar - "0") if byte[stringptr] == "-" value := - value PUB Poso_Check(timeout) result := Poso_Rx(timeout) pst.str(string(NL,"a = ")) pst.Dec(a) pst.str(string(NL,"b = ")) pst.Dec(b) pst.str(string(NL,"a0 = ")) pst.Dec(a0) pst.str(string(NL,"c = ")) pst.Dec(c) pst.str(string(NL,"d = ")) pst.Dec(d) pst.str(string(NL,"c0 = ")) pst.Dec(c0) pst.str(string(NL)) pst.dec(NU1) pst.str(string(NL)) pst.dec(NU2) pst.str(string(NL)) pst.dec(NU3) pst.str(string(NL,"Check Sum:")) pst.hex(checksum,4) Pub Poso_Rx(timeout)| DP_char1, DP_char2, LP_char1, LP_char2 {{ Wait for incoming packet until packet identifer found ($7E) Then process packet. XB.API_RX Once data is received, the type of packet can be checked for processing: IF XB.RxData == $ 83 ' message string ... See RxPacket Now for more information }} ' pst.str(string(NL, "Debut reception:", NL)) ' pst.Hex(_SrcAddr16,2) repeat DP_char1 := Pol.RxTime(timeout) SafeTx(DP_char1) if DP_char1 == -1 or DP_char1 == 0 Roso_Error(DP_char1) quit ' pst.hex(DP_char1,2) ' pst.Str(String(NL,"ok DP_char1", NL)) if ( DP_char1 == DP1) DP_char2 := Pol.RxTime(timeout) SafeTx(DP_char2) if DP_char2 == -1 or DP_char2 == 0 Roso_Error(DP_char2) quit ' pst.hex(DP_char2,2) ' pst.Str(String(NL,"good DP_char2", NL)) if (DP_char2 == DP2) LP_char1 := Pol.RxTime(timeout) SafeTx(LP_char1) if LP_char1 == -1 Roso_Error(LP_char1) quit ' pst.hex(LP_char1,2) ' pst.Str(String(NL,"parfait LP_char1", NL)) if (LP_char1 == LP1) LP_char2 := Pol.RxTime(timeout) SafeTx(LP_char2) if LP_char2 == -1 Roso_Error(LP_char2) quit ' pst.hex(LP_char2,2) ' pst.Str(String(NL,"genial LP_char2", NL)) while (LP_char2 <> LP2) ' pst.Str(String(NL)) ' pst.str(char) ' pst.str(string(NL, "Debut Analyze paquet reçu:", NL)) RxPacketNow(timeout) ' Analyze received packet PRI Roso_Error(localChar) pst.str(string(NL,"ERROR: Poso_Rx ")) case localChar 0: pst.str(string("received null character (or framing error)")) -1: pst.str(string("timeout")) other: pst.str(string("unknown error")) Pri RxPacketNow(timeout) | chan, prt2, localChar {{ Process incoming frame based on Identifier See individual cases for data returned. Check ident with : IF XB.rxIdent == value and process data accordingly as shown below }} ' pst.str(string("Recup caractere transmis : ")) ptr := 0 Repeat 20 ' pst.str(string("Recup caractere transmis : ")) localChar := Pol.RxTime(timeout) ' accept remainder of data ' pst.hex(Char,2) ' pst.str(string (NL)) dataSet[ptr++] := localChar ptr := 0 a := dataSet[ptr++] << 8 + dataSet[ptr++] b := dataSet[ptr++] << 8 + dataSet[ptr++] a0 := dataSet[ptr++] << 8 + dataSet[ptr++] c := dataSet[ptr++] << 8 + dataSet[ptr++] d := dataSet[ptr++] << 8 + dataSet[ptr++] c0 := dataSet[ptr++] << 8 + dataSet[ptr++] NU1 := dataSet[ptr++] << 8 + dataSet[ptr++] NU2 := dataSet[ptr++] << 8 + dataSet[ptr++] NU3 := dataSet[ptr++] << 8 + dataSet[ptr++] Checksum := dataSet[ptr++] << 8 + dataSet[ptr++]