Official support library for using mbed as a programmable coprocessor in the Innomatix DAP-III+ telematics platform

Committer:
Innomatix
Date:
Wed Sep 06 19:17:07 2017 +0000
Revision:
10:5fbe72ffb725
Parent:
4:fd93c4cb05df
Innomatix Support Library v1.0.7

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Innomatix 0:b9e1003fbee7 1 /*******************************************************************
Innomatix 0:b9e1003fbee7 2 *
Innomatix 0:b9e1003fbee7 3 * File: main.cpp
Innomatix 0:b9e1003fbee7 4 *
Innomatix 0:b9e1003fbee7 5 * Description: Example of using Innomatix Coprocessor Support functionality
Innomatix 0:b9e1003fbee7 6 *
Innomatix 0:b9e1003fbee7 7 * Copyright 2015 Innomatix, LLC., All Rights Reserved
Innomatix 0:b9e1003fbee7 8 *
Innomatix 0:b9e1003fbee7 9 * THIS DOCUMENT AND ITS CONTENTS ARE INTELLECTUAL PROPERTY
Innomatix 0:b9e1003fbee7 10 * OF INNOMATIX, LLC. ANY DUPLICATION IN PART OR WHOLE
Innomatix 0:b9e1003fbee7 11 * WITHOUT PRIOR WRITTEN CONSENT IS STRICTLY PROHIBITED.
Innomatix 0:b9e1003fbee7 12 *
Innomatix 0:b9e1003fbee7 13 *******************************************************************/
Innomatix 0:b9e1003fbee7 14 #include "mbed.h"
Innomatix 0:b9e1003fbee7 15 #include "Timer.h"
Innomatix 0:b9e1003fbee7 16 #include "RemoteDataStoreAPI.h"
Innomatix 0:b9e1003fbee7 17
Innomatix 0:b9e1003fbee7 18 // Name of the data bins we'll use
Innomatix 0:b9e1003fbee7 19 char PCopVersBinName[] = "CoprocVersion";
Innomatix 0:b9e1003fbee7 20 char PCopStatusBinName[] = "CoprocStatus";
Innomatix 10:5fbe72ffb725 21 char VehiclePowerBinName[] = "VehiclePower";
Innomatix 10:5fbe72ffb725 22 char PowerStatusBinName[] = "PowerStatus";
Innomatix 0:b9e1003fbee7 23
Innomatix 0:b9e1003fbee7 24 // Data bin identifiers returned from GetDataBinInfo()
Innomatix 0:b9e1003fbee7 25 unsigned int VersBin = BinId_None;
Innomatix 0:b9e1003fbee7 26 unsigned int StatusBin = BinId_None;
Innomatix 10:5fbe72ffb725 27 unsigned int PowerValueBin = BinId_None;
Innomatix 10:5fbe72ffb725 28 unsigned int PowerStatusBin = BinId_None;
Innomatix 0:b9e1003fbee7 29
Innomatix 0:b9e1003fbee7 30
Innomatix 0:b9e1003fbee7 31 /*************************************************************************/
Innomatix 0:b9e1003fbee7 32 unsigned int GetDBinInfo( const char * name )
Innomatix 0:b9e1003fbee7 33 {
Innomatix 0:b9e1003fbee7 34 unsigned int id = BinId_None;
Innomatix 0:b9e1003fbee7 35 RdsResults_e result = rdsNoConnection;
Innomatix 0:b9e1003fbee7 36 BinInfoStruct_t info;
Innomatix 0:b9e1003fbee7 37
Innomatix 0:b9e1003fbee7 38 printf( "RemoteDataStore getting info for databin %s...", name );
Innomatix 10:5fbe72ffb725 39 fflush( NULL );
Innomatix 10:5fbe72ffb725 40
Innomatix 10:5fbe72ffb725 41
Innomatix 0:b9e1003fbee7 42 result = GetDataBinInfo( name, &info );
Innomatix 0:b9e1003fbee7 43 if( rdsSuccess == result )
Innomatix 0:b9e1003fbee7 44 {
Innomatix 10:5fbe72ffb725 45 // We only care about the databin ID for this example
Innomatix 10:5fbe72ffb725 46 // Check RemoteDataStoreAPI.h for info on other fields
Innomatix 0:b9e1003fbee7 47 id = info.BinId;
Innomatix 0:b9e1003fbee7 48 printf( "SUCCESS, ID is %d\r\n", id );
Innomatix 0:b9e1003fbee7 49 }else
Innomatix 0:b9e1003fbee7 50 {
Innomatix 0:b9e1003fbee7 51 printf( "FAILED (%d)\r\n", result );
Innomatix 0:b9e1003fbee7 52 }
Innomatix 0:b9e1003fbee7 53 return( id );
Innomatix 0:b9e1003fbee7 54 }
Innomatix 0:b9e1003fbee7 55
Innomatix 0:b9e1003fbee7 56 /*************************************************************************/
Innomatix 10:5fbe72ffb725 57 RdsResults_e ExampleInit()
Innomatix 0:b9e1003fbee7 58 {
Innomatix 10:5fbe72ffb725 59 RdsResults_e result = rdsNoConnection;
Innomatix 0:b9e1003fbee7 60
Innomatix 10:5fbe72ffb725 61 result = DataStoreInit( "usb", 0 );
Innomatix 10:5fbe72ffb725 62 printf( "Innomatix RemoteDataStore API initialization: %s\r\n", (rdsSuccess == result ? "INITIALIZED" : "FAILED") );
Innomatix 10:5fbe72ffb725 63
Innomatix 10:5fbe72ffb725 64 if( rdsSuccess == result )
Innomatix 0:b9e1003fbee7 65 {
Innomatix 0:b9e1003fbee7 66 VersBin = GetDBinInfo( PCopVersBinName );
Innomatix 0:b9e1003fbee7 67 StatusBin = GetDBinInfo( PCopStatusBinName );
Innomatix 0:b9e1003fbee7 68
Innomatix 10:5fbe72ffb725 69 PowerValueBin = GetDBinInfo( VehiclePowerBinName );
Innomatix 10:5fbe72ffb725 70 PowerStatusBin = GetDBinInfo( PowerStatusBinName );
Innomatix 4:fd93c4cb05df 71 }
Innomatix 10:5fbe72ffb725 72 return( result );
Innomatix 0:b9e1003fbee7 73 }
Innomatix 0:b9e1003fbee7 74
Innomatix 0:b9e1003fbee7 75 /*************************************************************************/
Innomatix 0:b9e1003fbee7 76 /*************************************************************************/
Innomatix 0:b9e1003fbee7 77 int DoExample( char *zVersion )
Innomatix 0:b9e1003fbee7 78 {
Innomatix 10:5fbe72ffb725 79 RdsResults_e result = rdsNoConnection;
Innomatix 10:5fbe72ffb725 80 int delay_msec = 10 * 1000;
Innomatix 4:fd93c4cb05df 81
Innomatix 10:5fbe72ffb725 82 DigitalOut led1( LED1 );
Innomatix 4:fd93c4cb05df 83
Innomatix 10:5fbe72ffb725 84 double PowerValue = 0.0;
Innomatix 10:5fbe72ffb725 85 double PowerThreshold = 13.0;
Innomatix 10:5fbe72ffb725 86 unsigned int Timestamp = 0;
Innomatix 10:5fbe72ffb725 87 unsigned int PrevTimestamp = 0;
Innomatix 0:b9e1003fbee7 88
Innomatix 0:b9e1003fbee7 89 // Init the Support Library subsystems we'll use for this example
Innomatix 10:5fbe72ffb725 90 result = ExampleInit();
Innomatix 10:5fbe72ffb725 91 if( rdsSuccess == result )
Innomatix 10:5fbe72ffb725 92 {
Innomatix 10:5fbe72ffb725 93 /*-----------------------------------------------*/
Innomatix 10:5fbe72ffb725 94 // Update the DAP informational data bins
Innomatix 10:5fbe72ffb725 95 PutString( StatusBin, "Starting PCop Example" );
Innomatix 10:5fbe72ffb725 96 PutString( VersBin, zVersion );
Innomatix 4:fd93c4cb05df 97
Innomatix 10:5fbe72ffb725 98 /*-----------------------------------------------*/
Innomatix 10:5fbe72ffb725 99 // Use the Remote DataStore's special "debug" API
Innomatix 10:5fbe72ffb725 100 // The DAP will update a pre-determined data bin with the string.
Innomatix 10:5fbe72ffb725 101 // Typically the debug data bin is shown on the diagnostic display
Innomatix 10:5fbe72ffb725 102 // and is included in the data stream to the host.
Innomatix 10:5fbe72ffb725 103 PutDebug( "Entering example loop" );
Innomatix 4:fd93c4cb05df 104
Innomatix 10:5fbe72ffb725 105 while( 1 )
Innomatix 10:5fbe72ffb725 106 {
Innomatix 10:5fbe72ffb725 107 // Get a value from the VehiclePower data bin
Innomatix 10:5fbe72ffb725 108 result = GetDouble( PowerValueBin, &PowerValue, &Timestamp);
Innomatix 0:b9e1003fbee7 109
Innomatix 10:5fbe72ffb725 110 // Check the timestamp to see if the value has been updated since
Innomatix 10:5fbe72ffb725 111 // last time we checked. Only test/publish if it has.
Innomatix 10:5fbe72ffb725 112 if( Timestamp != PrevTimestamp )
Innomatix 0:b9e1003fbee7 113 {
Innomatix 10:5fbe72ffb725 114 // Apply a threshold
Innomatix 10:5fbe72ffb725 115 int status = (PowerValue >= PowerThreshold ? 1 : 0);
Innomatix 10:5fbe72ffb725 116
Innomatix 10:5fbe72ffb725 117 // Publish the results back to the PowerOkay data bin
Innomatix 10:5fbe72ffb725 118 PutUnsignedInteger( PowerStatusBin, status );
Innomatix 10:5fbe72ffb725 119 led1 = status;
Innomatix 0:b9e1003fbee7 120
Innomatix 10:5fbe72ffb725 121 // Save the timestamp so we know if it is updated
Innomatix 10:5fbe72ffb725 122 PrevTimestamp = Timestamp;
Innomatix 4:fd93c4cb05df 123 }
Innomatix 10:5fbe72ffb725 124
Innomatix 10:5fbe72ffb725 125 // Wait for the next go-around
Innomatix 10:5fbe72ffb725 126 wait_ms( delay_msec );
Innomatix 0:b9e1003fbee7 127 }
Innomatix 4:fd93c4cb05df 128
Innomatix 0:b9e1003fbee7 129
Innomatix 0:b9e1003fbee7 130
Innomatix 0:b9e1003fbee7 131 /*-----------------------------------------------*/
Innomatix 10:5fbe72ffb725 132 DataStoreClose();
Innomatix 0:b9e1003fbee7 133 }
Innomatix 0:b9e1003fbee7 134 return( 0 );
Innomatix 0:b9e1003fbee7 135 }
Innomatix 0:b9e1003fbee7 136