Example BeagleBone Black Program Code


#include “Tarts.h”


#include “TartsStrings.h”


 


#define GATEWAY_ID  “T08KN4”


#define SENSOR_ID   “T08L10”


 


/**********************************************************************************


*BEAGLEBONE BLACK PLATFORM-SPECIFIC DEFINITIONS


*********************************************************************************/


#ifdef BB_BLACK_ARCH


#define GATEWAY_CHANNELS      0xFFFFFFFF // All Channels


#define GATEWAY_UARTNUMBER    1          //<<your UART Selection>>


#define GATEWAY_PINACTIVITY   P9_23      //<<your Activity Pin location>>


#define GATEWAY_PINPCTS       P8_26      //<<your PCTS Pin location>>


#define GATEWAY_PINPRTS       P8_10      //<<your PRTS Pin location>>


#define GATEWAY_PINRESET      P8_12      //<<your Reset Pin location>>


#endif


 


/**********************************************************************************


*Global Variables


*********************************************************************************/


int AppCalls = 0;   //Keyboard Read Thread callback variable


 


/**********************************************************************************


*Tarts Events


*********************************************************************************/


void onGatewayMessageEvent(const char* id, int stringID){


printf(“TARTS-GWM[%u]-%d: %s\n”, id, stringID, TartsGatewayStringTable[stringID]);


if(stringID == 10) printf(“ACTIVE – Channel: %d\n”, Tarts.FindGateway(GATEWAY_ID)->getOperatingChannel());


}


void onSensorMessageEvent(uint32_t id, Datum* datumList, int countSensorMessage* msg){
printf(“TARTS-SEN[%u]: RSSI: %d dBm, Battery Voltage: %d.%d VDC, Data: “, idmsg->ID, msg->RSSI, msg->BatteryVoltage/100, msg->BatteryVoltage%100);
for(int i=0; iDatumcCount; i++){
if(i != 0) printf(” || “);
printf(“%s | %s | %s”, msg->DdatumList[i].Name, msg->DdatumList[i].Value, msg->DdatumList[i].FormattedValue);
}
printf(“\n”);
}


}


/**********************************************************************************


* Keyboard Thread and Arduino-like setup / loop code


*********************************************************************************/


TARTS_THREAD(AppKeyboardReadThread){


char rxchar = 0;


while(1){


std::cin >> rxchar;


if(rxchar == ‘q’) AppCalls = 1;


rxchar = 0;


}


return 0; //Here to keep the function happy


}


 


int setup() {


printf(“TARTs Basic application running…”);


 


//Prepare all the call-back functions


Tarts.RegisterEvent_GatewayMessage(onGatewayMessageEvent);


Tarts.RegisterEvent_SensorMessage(onSensorMessageEvent);


printf(“All Event Handlers Registered.\n”);


 


//Register Gateway


#ifdef BB_BLACK_ARCH


if(!Tarts.RegisterGateway(TartsGateway::Create(GATEWAY_ID, GATEWAY_CHANNELS, GATEWAY_UARTNUMBER, GATEWAY_PINACTIVITY, GATEWAY_PINPCTS, GATEWAY_PINPRTS, GATEWAY_PINRESET))){


#else


if(!Tarts.RegisterGateway(TartsGateway::Create(GATEWAY_ID))){


#endif


printf(“TARTs Gateway Registration Failed!\n”);


return 1;


}


 


//Lastly Register All Sensors


if(!Tarts.RegisterSensor(GATEWAY_ID, TartsTemperature::Create(SENSOR_ID))){


Tarts.RemoveGateway(GATEWAY_ID);


printf(“TARTs Sensor Registration Failed!\n”);


return 2;


}


 


if(TARTS_THREADSTART(AppKeyboardReadThread) != 0){


printf(“Unable to start Keyboard Read Thread!”);


Tarts.RemoveGateway(GATEWAY_ID);


return 3;


}


 


printf(“–Press q to exit–\n\n”);


return 0;


}


 


void loop() {


Tarts.Process();


if(AppCalls == 1){


AppCalls = 0;


Tarts.RemoveGateway(GATEWAY_ID);


exit(0);


}


}


 


/**********************************************************************************


* Execution entry point for this application


*********************************************************************************/


//Main Application Loop


int main(void){


if(setup() != 0) exit(1);


while(1){


loop();


TARTS_DELAYMS(100);//Allow System Sleep to occur


}


}