![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
research application on sending data to headend
Dependencies: DataStore JobScheduler NetworkServices W5500Interface nanopb protocol
See "main.cpp" documentation on "API Documentation" tab for details about application.
source/main.cpp@1:eebe442fc126, 2017-07-13 (annotated)
- Committer:
- sgnezdov
- Date:
- Thu Jul 13 20:01:25 2017 +0000
- Revision:
- 1:eebe442fc126
- Parent:
- 0:2c57ed6943f7
- Child:
- 2:661c545d718e
decided how to structure jobs and job contexts
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sgnezdov | 0:2c57ed6943f7 | 1 | #include "mbed.h" |
sgnezdov | 0:2c57ed6943f7 | 2 | |
sgnezdov | 0:2c57ed6943f7 | 3 | #include "mbed-trace/mbed_trace.h" |
sgnezdov | 0:2c57ed6943f7 | 4 | #define TRACE_GROUP "main" |
sgnezdov | 0:2c57ed6943f7 | 5 | |
sgnezdov | 1:eebe442fc126 | 6 | #include "scheduler.h" |
sgnezdov | 1:eebe442fc126 | 7 | #include "schedules.h" |
sgnezdov | 1:eebe442fc126 | 8 | #include "jobService.h" |
sgnezdov | 1:eebe442fc126 | 9 | #include "jobTestPrint.h" |
sgnezdov | 1:eebe442fc126 | 10 | |
sgnezdov | 0:2c57ed6943f7 | 11 | // These are necessary only if thread safety is needed |
sgnezdov | 0:2c57ed6943f7 | 12 | static Mutex TracingLock; |
sgnezdov | 0:2c57ed6943f7 | 13 | static void tracingWait() |
sgnezdov | 0:2c57ed6943f7 | 14 | { |
sgnezdov | 0:2c57ed6943f7 | 15 | TracingLock.lock(); |
sgnezdov | 0:2c57ed6943f7 | 16 | } |
sgnezdov | 0:2c57ed6943f7 | 17 | static void tracingRelease() |
sgnezdov | 0:2c57ed6943f7 | 18 | { |
sgnezdov | 0:2c57ed6943f7 | 19 | TracingLock.unlock(); |
sgnezdov | 0:2c57ed6943f7 | 20 | } |
sgnezdov | 0:2c57ed6943f7 | 21 | |
sgnezdov | 0:2c57ed6943f7 | 22 | int main() |
sgnezdov | 0:2c57ed6943f7 | 23 | { |
sgnezdov | 0:2c57ed6943f7 | 24 | printf("\n==Borsch==\n"); |
sgnezdov | 0:2c57ed6943f7 | 25 | |
sgnezdov | 0:2c57ed6943f7 | 26 | /* Setup tracing */ |
sgnezdov | 0:2c57ed6943f7 | 27 | mbed_trace_mutex_wait_function_set( tracingWait ); // only if thread safety is needed |
sgnezdov | 0:2c57ed6943f7 | 28 | mbed_trace_mutex_release_function_set( tracingRelease ); // only if thread safety is needed |
sgnezdov | 0:2c57ed6943f7 | 29 | mbed_trace_init(); // initialize the trace library |
sgnezdov | 0:2c57ed6943f7 | 30 | |
sgnezdov | 0:2c57ed6943f7 | 31 | tr_info("**Started**"); //-> "[INFO][main]: this is an info msg" |
sgnezdov | 0:2c57ed6943f7 | 32 | |
sgnezdov | 1:eebe442fc126 | 33 | JobScheduler::JobService js; |
sgnezdov | 1:eebe442fc126 | 34 | JobScheduler::Scheduler scheduler(&js); |
sgnezdov | 1:eebe442fc126 | 35 | |
sgnezdov | 1:eebe442fc126 | 36 | JobTestPrint jtp; |
sgnezdov | 1:eebe442fc126 | 37 | js.Register(1, JobTestPrint::RunAdapter, &jtp); |
sgnezdov | 0:2c57ed6943f7 | 38 | |
sgnezdov | 1:eebe442fc126 | 39 | scheduler.Start(); |
sgnezdov | 1:eebe442fc126 | 40 | |
sgnezdov | 1:eebe442fc126 | 41 | // inject test case |
sgnezdov | 1:eebe442fc126 | 42 | time_t nowSecs = time(NULL); |
sgnezdov | 1:eebe442fc126 | 43 | JobScheduler::Response<JobScheduler::JobID> res = |
sgnezdov | 1:eebe442fc126 | 44 | scheduler.JobAdd(1, new JobScheduler::RunOnceSchedule(nowSecs + 2), NULL); |
sgnezdov | 1:eebe442fc126 | 45 | |
sgnezdov | 1:eebe442fc126 | 46 | // block forever unless there is a job that calls scheduler.Stop() |
sgnezdov | 1:eebe442fc126 | 47 | scheduler.WaitToStop(); |
sgnezdov | 1:eebe442fc126 | 48 | |
sgnezdov | 1:eebe442fc126 | 49 | // indicate clean app termination |
sgnezdov | 0:2c57ed6943f7 | 50 | tr_info("**Finished**"); //-> "[INFO][main]: this is an info msg" |
sgnezdov | 0:2c57ed6943f7 | 51 | exit(0); |
sgnezdov | 0:2c57ed6943f7 | 52 | } |