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

Committer:
sgnezdov
Date:
2017-07-14
Revision:
4:b360d4f0bf34
Parent:
2:661c545d718e
Child:
7:c4123a87abe2

File content as of revision 4:b360d4f0bf34:

#include "mbed.h"

#include "mbed-trace/mbed_trace.h"
#define TRACE_GROUP  "main"

#include "scheduler.h"
#include "schedules.h"
#include "jobService.h"
#include "netstack.h"
#include "lceProxy.h"

#include "jobTestPrint.h"
#include "jobFakeADC.h"

 // These are necessary only if thread safety is needed
static Mutex TracingLock;
static void tracingWait()
{
    TracingLock.lock();
}
static void tracingRelease()
{
    TracingLock.unlock();
}

int main()
{
    printf("\n==Borsch==\n");
 
     uint8_t mac_addr[6] = {0x00, 0x08, 0xdc, 0x45, 0x56, 0x67};
   
    /* Setup tracing */
    mbed_trace_mutex_wait_function_set( tracingWait ); // only if thread safety is needed
    mbed_trace_mutex_release_function_set( tracingRelease ); // only if thread safety is needed
    mbed_trace_init();       // initialize the trace library
    
    tr_info("**Started**");    //-> "[INFO][main]: this is an info msg"    

    NetworkInterface* nif = initNetworkStack(mac_addr);
    if (nif == NULL) {
        tr_error("**Terminated**");
        exit(0);
    }
    
    LceProxy lce(*nif);
    
    JobScheduler::JobService js;   
    JobScheduler::Scheduler scheduler(&js);
   
    JobTestPrint jtp;
    js.Register(1, JobTestPrint::RunAdapter, &jtp);
    
    JobFakeADC jfa(lce);
    js.Register(2, JobFakeADC::RunAdapter, &jfa);

    scheduler.Start();
    
    // inject test case
    time_t nowSecs = time(NULL);
    JobScheduler::Response<JobScheduler::JobID> res =
        scheduler.JobAdd(1, new JobScheduler::RunOnceSchedule(nowSecs + 2), NULL);
    res = scheduler.JobAdd(2, new JobScheduler::RunPeriodicSchedule(2, 5), NULL);
    
    // block forever unless there is a job that calls scheduler.Stop()
    scheduler.WaitToStop();   
    
    /* we can somehow load new application image here and restart */
    
    // indicate clean app termination
    tr_info("**Finished**");    //-> "[INFO][main]: this is an info msg"    
    exit(0);
}