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
tasks/tasks.cpp@9:f943c09d9173, 2018-12-19 (annotated)
- Committer:
- jurica238814
- Date:
- Wed Dec 19 15:12:25 2018 +0100
- Revision:
- 9:f943c09d9173
- Parent:
- 8:2bf886335fd0
Stable version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 8:2bf886335fd0 | 1 | /** |
jurica238814 | 8:2bf886335fd0 | 2 | * Collection of all tasks |
jurica238814 | 8:2bf886335fd0 | 3 | * Made by Jurica @ aconno |
jurica238814 | 8:2bf886335fd0 | 4 | * More info @ aconno.de |
jurica238814 | 8:2bf886335fd0 | 5 | * |
jurica238814 | 8:2bf886335fd0 | 6 | */ |
jurica238814 | 8:2bf886335fd0 | 7 | |
jurica238814 | 8:2bf886335fd0 | 8 | #include "tasks.h" |
jurica238814 | 8:2bf886335fd0 | 9 | #include "aconnoHelpers.h" |
jurica238814 | 8:2bf886335fd0 | 10 | #include "gnss.h" |
jurica238814 | 8:2bf886335fd0 | 11 | #include "aconnoConfig.h" |
jurica238814 | 8:2bf886335fd0 | 12 | |
jurica238814 | 9:f943c09d9173 | 13 | extern volatile MainStates state; |
jurica238814 | 9:f943c09d9173 | 14 | extern char locationGlobal[5*UDP_MSG_SIZE_B]; |
jurica238814 | 9:f943c09d9173 | 15 | extern Thread alarmState; |
jurica238814 | 9:f943c09d9173 | 16 | locationFlag_t locationFlagGlobal = OLD; |
jurica238814 | 8:2bf886335fd0 | 17 | |
jurica238814 | 8:2bf886335fd0 | 18 | void idleCallback() |
jurica238814 | 8:2bf886335fd0 | 19 | { |
jurica238814 | 8:2bf886335fd0 | 20 | while(1) |
jurica238814 | 8:2bf886335fd0 | 21 | { |
jurica238814 | 8:2bf886335fd0 | 22 | Thread::signal_wait(IDLE_SIGNAL); |
jurica238814 | 8:2bf886335fd0 | 23 | Thread::signal_clr(IDLE_SIGNAL); |
jurica238814 | 8:2bf886335fd0 | 24 | printf("In idle thread.\r\n"); |
jurica238814 | 8:2bf886335fd0 | 25 | while(state == STATE_IDLE) |
jurica238814 | 8:2bf886335fd0 | 26 | { |
jurica238814 | 8:2bf886335fd0 | 27 | wait_ms(1000); |
jurica238814 | 8:2bf886335fd0 | 28 | } |
jurica238814 | 8:2bf886335fd0 | 29 | } |
jurica238814 | 8:2bf886335fd0 | 30 | } |
jurica238814 | 8:2bf886335fd0 | 31 | |
jurica238814 | 8:2bf886335fd0 | 32 | void alarmCallback(myParams_t *myParams) |
jurica238814 | 8:2bf886335fd0 | 33 | { |
jurica238814 | 9:f943c09d9173 | 34 | char udpMsg[UDP_MSG_SIZE_B]; |
jurica238814 | 8:2bf886335fd0 | 35 | |
jurica238814 | 8:2bf886335fd0 | 36 | while(1) |
jurica238814 | 8:2bf886335fd0 | 37 | { |
jurica238814 | 8:2bf886335fd0 | 38 | while(state == STATE_ALARM) |
jurica238814 | 8:2bf886335fd0 | 39 | { |
jurica238814 | 9:f943c09d9173 | 40 | Thread::signal_wait(LOCATION_SEARCH_DONE); |
jurica238814 | 9:f943c09d9173 | 41 | Thread::signal_clr(LOCATION_SEARCH_DONE); |
jurica238814 | 9:f943c09d9173 | 42 | if(locationFlagGlobal) |
jurica238814 | 9:f943c09d9173 | 43 | { |
jurica238814 | 9:f943c09d9173 | 44 | sprintf(udpMsg, "$location_flag:%s;$type:NEW;",locationGlobal); |
jurica238814 | 9:f943c09d9173 | 45 | } |
jurica238814 | 9:f943c09d9173 | 46 | else |
jurica238814 | 9:f943c09d9173 | 47 | { |
jurica238814 | 9:f943c09d9173 | 48 | sprintf(udpMsg, "$location_flag:%s;$type:OLD;",locationGlobal); |
jurica238814 | 9:f943c09d9173 | 49 | } |
jurica238814 | 8:2bf886335fd0 | 50 | printf("Sending location on server...\r\n"); |
jurica238814 | 9:f943c09d9173 | 51 | printf("%s\r\n", udpMsg); |
jurica238814 | 9:f943c09d9173 | 52 | myParams->sara->sendUdpMsg(udpMsg); |
jurica238814 | 8:2bf886335fd0 | 53 | wait_ms(5000); |
jurica238814 | 8:2bf886335fd0 | 54 | } |
jurica238814 | 8:2bf886335fd0 | 55 | } |
jurica238814 | 8:2bf886335fd0 | 56 | } |
jurica238814 | 8:2bf886335fd0 | 57 | |
jurica238814 | 8:2bf886335fd0 | 58 | void alarmOffCallback() |
jurica238814 | 8:2bf886335fd0 | 59 | { |
jurica238814 | 8:2bf886335fd0 | 60 | while(1) |
jurica238814 | 8:2bf886335fd0 | 61 | { |
jurica238814 | 8:2bf886335fd0 | 62 | Thread::signal_wait(ALARM_OFF_SIGNAL); |
jurica238814 | 8:2bf886335fd0 | 63 | Thread::signal_clr(ALARM_OFF_SIGNAL); |
jurica238814 | 8:2bf886335fd0 | 64 | printf("In alarm off thread.\r\n"); |
jurica238814 | 8:2bf886335fd0 | 65 | while(state == STATE_ALARM_OFF) |
jurica238814 | 8:2bf886335fd0 | 66 | { |
jurica238814 | 8:2bf886335fd0 | 67 | wait_ms(1000); |
jurica238814 | 8:2bf886335fd0 | 68 | } |
jurica238814 | 8:2bf886335fd0 | 69 | } |
jurica238814 | 8:2bf886335fd0 | 70 | } |
jurica238814 | 8:2bf886335fd0 | 71 | |
jurica238814 | 8:2bf886335fd0 | 72 | void movementCallback() |
jurica238814 | 8:2bf886335fd0 | 73 | { |
jurica238814 | 8:2bf886335fd0 | 74 | while(1) |
jurica238814 | 8:2bf886335fd0 | 75 | { |
jurica238814 | 8:2bf886335fd0 | 76 | while(state == STATE_LIS_DETECTION) |
jurica238814 | 8:2bf886335fd0 | 77 | { |
jurica238814 | 8:2bf886335fd0 | 78 | printf("In movement thread.\r\n"); |
jurica238814 | 8:2bf886335fd0 | 79 | wait_ms(1000); |
jurica238814 | 8:2bf886335fd0 | 80 | } |
jurica238814 | 8:2bf886335fd0 | 81 | } |
jurica238814 | 8:2bf886335fd0 | 82 | } |
jurica238814 | 8:2bf886335fd0 | 83 | |
jurica238814 | 8:2bf886335fd0 | 84 | void gnssLocationCallback(GnssSerial *gnss) |
jurica238814 | 8:2bf886335fd0 | 85 | { |
jurica238814 | 8:2bf886335fd0 | 86 | while(1) |
jurica238814 | 8:2bf886335fd0 | 87 | { |
jurica238814 | 8:2bf886335fd0 | 88 | while(state == STATE_ALARM) |
jurica238814 | 8:2bf886335fd0 | 89 | { |
jurica238814 | 9:f943c09d9173 | 90 | if(getGPSData(locationGlobal, gnss, MAX_TIME_GNSS_WAIT_S)) |
jurica238814 | 9:f943c09d9173 | 91 | { |
jurica238814 | 9:f943c09d9173 | 92 | printf("New location.\r\n"); |
jurica238814 | 9:f943c09d9173 | 93 | locationFlagGlobal = NEW; |
jurica238814 | 9:f943c09d9173 | 94 | } |
jurica238814 | 9:f943c09d9173 | 95 | else |
jurica238814 | 9:f943c09d9173 | 96 | { |
jurica238814 | 9:f943c09d9173 | 97 | printf("Old location.\r\n"); |
jurica238814 | 9:f943c09d9173 | 98 | locationFlagGlobal = OLD; |
jurica238814 | 9:f943c09d9173 | 99 | } |
jurica238814 | 9:f943c09d9173 | 100 | alarmState.signal_set(LOCATION_SEARCH_DONE); |
jurica238814 | 8:2bf886335fd0 | 101 | Thread::wait(UPDATE_LOCATION_TIME_MS); |
jurica238814 | 8:2bf886335fd0 | 102 | } |
jurica238814 | 8:2bf886335fd0 | 103 | } |
jurica238814 | 8:2bf886335fd0 | 104 | } |
jurica238814 | 8:2bf886335fd0 | 105 |