rx serial inturrupt seems to hault code execution,,,
Page last updated 10 Oct 2012, by .
0
replies
#include "mbed.h"
#include "MbedJSONValue.h"
#include "ConfigFile.h"
Serial pc(USBTX, USBRX);
Serial sensor(p28, p27); // tx, rx
DigitalOut pc_activity(LED1);
DigitalOut uart_activity(LED2);
LocalFileSystem local("local");
ConfigFile cfg;
MbedJSONValue SensorData;
std::string s;
Ticker pingTick;
volatile bool pingTicked;
volatile bool pcResponse;
char pcResponseValue[BUFSIZ];
void pingTickFunction( void ) {
pingTicked = true;
}
void pcRecvInterrupt( void ) {
pcResponse = true;
}
bool linkedWithBaseStation = "FALSE";
char *sbNameKey = "SensorBoardName";
char sbNameValue[BUFSIZ];
char *sbFirstStartKey = "FirstStart";
char sbFirstStartValue[BUFSIZ];
char *sbUseBaseStationKey = "UseBaseStation";
char sbUseBaseStationValue[BUFSIZ];
void serializeJSON() {
s = SensorData.serialize();
}
void pingBaseStation() {
printf("{\"sbPing\": \"%s\"}\r\n", sbNameValue);
}
int main()
{
pc.baud(38400);
sensor.baud(38400);
pingTicked = false;
pc.attach(&pcRecvInterrupt);
/*
* Read a configuration file from a mbed.
*/
if (!cfg.read("/local/settings.cfg")) {
printf("Failure to read a configuration file.\n");
}
/*
* Get a configuration value.
* Then attach the sbNameValue to SensorData json
*/
if (cfg.getValue(sbNameKey, &sbNameValue[0], sizeof(sbNameValue))) {
//printf("'%s'='%s'\n", sbNameKey, sbNameValue);
SensorData["name"] = sbNameValue;
}
/*
* Get a configuration value.
* Then attach the sbNameValue to SensorData json
*/
if (cfg.getValue(sbFirstStartKey, &sbFirstStartValue[0], sizeof(sbFirstStartValue))) {
if (strcmp(&sbFirstStartValue[0], "TRUE") == 0) {
pingTick.attach(&pingTickFunction, 10);
pingBaseStation();
while(!pc.readable()) {
if (pingTicked) {
pingBaseStation();
pingTicked = false;
}
}
if(pc.readable()) {
pingTick.detach();
}
cfg.setValue("FirstStart", "FALSE");
cfg.write("/local/settings.cfg");
}
}
while(1) {
wait(0.5);
pc.printf("UHH");
}
}
Please log in to post comments.
