The program sends the current location over the cellular network.
Dependencies: aconno_I2C ublox-at-cellular-interface gnss ublox-cellular-base Lis2dh12 ublox-cellular-base-n2xx ublox-at-cellular-interface-n2xx low-power-sleep
Fork of example-gnss by
Diff: tasks/tasks.cpp
- Revision:
- 9:f943c09d9173
- Parent:
- 8:2bf886335fd0
diff -r 2bf886335fd0 -r f943c09d9173 tasks/tasks.cpp
--- a/tasks/tasks.cpp Fri Nov 30 16:19:41 2018 +0100
+++ b/tasks/tasks.cpp Wed Dec 19 15:12:25 2018 +0100
@@ -10,8 +10,10 @@
#include "gnss.h"
#include "aconnoConfig.h"
-extern MainStates state;
-extern char locationGlobal[UDP_MSG_SIZE_B];
+extern volatile MainStates state;
+extern char locationGlobal[5*UDP_MSG_SIZE_B];
+extern Thread alarmState;
+locationFlag_t locationFlagGlobal = OLD;
void idleCallback()
{
@@ -29,17 +31,25 @@
void alarmCallback(myParams_t *myParams)
{
- //char udpMsg[UDP_MSG_SIZE_B];
+ char udpMsg[UDP_MSG_SIZE_B];
while(1)
{
- Thread::signal_wait(ALARM_SIGNAL);
- Thread::signal_clr(ALARM_SIGNAL);
- printf("Alarm thread.\r\n");
while(state == STATE_ALARM)
{
+ Thread::signal_wait(LOCATION_SEARCH_DONE);
+ Thread::signal_clr(LOCATION_SEARCH_DONE);
+ if(locationFlagGlobal)
+ {
+ sprintf(udpMsg, "$location_flag:%s;$type:NEW;",locationGlobal);
+ }
+ else
+ {
+ sprintf(udpMsg, "$location_flag:%s;$type:OLD;",locationGlobal);
+ }
printf("Sending location on server...\r\n");
- myParams->sara->sendUdpMsg(locationGlobal);
+ printf("%s\r\n", udpMsg);
+ myParams->sara->sendUdpMsg(udpMsg);
wait_ms(5000);
}
}
@@ -77,7 +87,17 @@
{
while(state == STATE_ALARM)
{
- getGPSData(locationGlobal, gnss);
+ if(getGPSData(locationGlobal, gnss, MAX_TIME_GNSS_WAIT_S))
+ {
+ printf("New location.\r\n");
+ locationFlagGlobal = NEW;
+ }
+ else
+ {
+ printf("Old location.\r\n");
+ locationFlagGlobal = OLD;
+ }
+ alarmState.signal_set(LOCATION_SEARCH_DONE);
Thread::wait(UPDATE_LOCATION_TIME_MS);
}
}
