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.

Committer:
sgnezdov
Date:
Fri Jul 14 22:02:28 2017 +0000
Revision:
7:c4123a87abe2
Parent:
4:b360d4f0bf34
Child:
9:d6a9210bfd41
ADC reads make it to HE, but values are not correct; ch 7 is supposed to be zero and is filled in; created date is way off

Who changed what in which revision?

UserRevisionLine numberNew 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 4:b360d4f0bf34 9 #include "netstack.h"
sgnezdov 4:b360d4f0bf34 10 #include "lceProxy.h"
sgnezdov 4:b360d4f0bf34 11
sgnezdov 1:eebe442fc126 12 #include "jobTestPrint.h"
sgnezdov 4:b360d4f0bf34 13 #include "jobFakeADC.h"
sgnezdov 1:eebe442fc126 14
sgnezdov 0:2c57ed6943f7 15 // These are necessary only if thread safety is needed
sgnezdov 0:2c57ed6943f7 16 static Mutex TracingLock;
sgnezdov 0:2c57ed6943f7 17 static void tracingWait()
sgnezdov 0:2c57ed6943f7 18 {
sgnezdov 0:2c57ed6943f7 19 TracingLock.lock();
sgnezdov 0:2c57ed6943f7 20 }
sgnezdov 0:2c57ed6943f7 21 static void tracingRelease()
sgnezdov 0:2c57ed6943f7 22 {
sgnezdov 0:2c57ed6943f7 23 TracingLock.unlock();
sgnezdov 0:2c57ed6943f7 24 }
sgnezdov 0:2c57ed6943f7 25
sgnezdov 0:2c57ed6943f7 26 int main()
sgnezdov 0:2c57ed6943f7 27 {
sgnezdov 0:2c57ed6943f7 28 printf("\n==Borsch==\n");
sgnezdov 2:661c545d718e 29
sgnezdov 2:661c545d718e 30 uint8_t mac_addr[6] = {0x00, 0x08, 0xdc, 0x45, 0x56, 0x67};
sgnezdov 2:661c545d718e 31
sgnezdov 0:2c57ed6943f7 32 /* Setup tracing */
sgnezdov 0:2c57ed6943f7 33 mbed_trace_mutex_wait_function_set( tracingWait ); // only if thread safety is needed
sgnezdov 0:2c57ed6943f7 34 mbed_trace_mutex_release_function_set( tracingRelease ); // only if thread safety is needed
sgnezdov 0:2c57ed6943f7 35 mbed_trace_init(); // initialize the trace library
sgnezdov 0:2c57ed6943f7 36
sgnezdov 0:2c57ed6943f7 37 tr_info("**Started**"); //-> "[INFO][main]: this is an info msg"
sgnezdov 2:661c545d718e 38
sgnezdov 2:661c545d718e 39 NetworkInterface* nif = initNetworkStack(mac_addr);
sgnezdov 2:661c545d718e 40 if (nif == NULL) {
sgnezdov 2:661c545d718e 41 tr_error("**Terminated**");
sgnezdov 2:661c545d718e 42 exit(0);
sgnezdov 2:661c545d718e 43 }
sgnezdov 0:2c57ed6943f7 44
sgnezdov 7:c4123a87abe2 45 const char* sn = "Nucleo1";
sgnezdov 7:c4123a87abe2 46 LceProxy lce(*nif, sn);
sgnezdov 4:b360d4f0bf34 47
sgnezdov 1:eebe442fc126 48 JobScheduler::JobService js;
sgnezdov 1:eebe442fc126 49 JobScheduler::Scheduler scheduler(&js);
sgnezdov 1:eebe442fc126 50
sgnezdov 1:eebe442fc126 51 JobTestPrint jtp;
sgnezdov 1:eebe442fc126 52 js.Register(1, JobTestPrint::RunAdapter, &jtp);
sgnezdov 4:b360d4f0bf34 53
sgnezdov 4:b360d4f0bf34 54 JobFakeADC jfa(lce);
sgnezdov 4:b360d4f0bf34 55 js.Register(2, JobFakeADC::RunAdapter, &jfa);
sgnezdov 0:2c57ed6943f7 56
sgnezdov 1:eebe442fc126 57 scheduler.Start();
sgnezdov 1:eebe442fc126 58
sgnezdov 1:eebe442fc126 59 // inject test case
sgnezdov 1:eebe442fc126 60 time_t nowSecs = time(NULL);
sgnezdov 7:c4123a87abe2 61 // NOTE: don't schedule run once with at 0, because 0 means never.
sgnezdov 1:eebe442fc126 62 JobScheduler::Response<JobScheduler::JobID> res =
sgnezdov 7:c4123a87abe2 63 scheduler.JobAdd(2, new JobScheduler::RunOnceSchedule(1), NULL);
sgnezdov 7:c4123a87abe2 64 //scheduler.JobAdd(1, new JobScheduler::RunOnceSchedule(nowSecs + 2), NULL);
sgnezdov 7:c4123a87abe2 65 //res = scheduler.JobAdd(2, new JobScheduler::RunPeriodicSchedule(2, 5), NULL);
sgnezdov 1:eebe442fc126 66
sgnezdov 1:eebe442fc126 67 // block forever unless there is a job that calls scheduler.Stop()
sgnezdov 1:eebe442fc126 68 scheduler.WaitToStop();
sgnezdov 1:eebe442fc126 69
sgnezdov 4:b360d4f0bf34 70 /* we can somehow load new application image here and restart */
sgnezdov 4:b360d4f0bf34 71
sgnezdov 1:eebe442fc126 72 // indicate clean app termination
sgnezdov 0:2c57ed6943f7 73 tr_info("**Finished**"); //-> "[INFO][main]: this is an info msg"
sgnezdov 0:2c57ed6943f7 74 exit(0);
sgnezdov 0:2c57ed6943f7 75 }