Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed
Fork of ICE by
Diff: src/OutputTask/OutputTask.cpp
- Revision:
- 128:534bf29132f8
- Parent:
- 122:4db48b933115
- Child:
- 130:c932494f05b8
--- a/src/OutputTask/OutputTask.cpp Fri Sep 23 16:14:57 2016 +0000 +++ b/src/OutputTask/OutputTask.cpp Fri Sep 23 20:36:04 2016 +0000 @@ -109,11 +109,19 @@ OutputMasterMailBox.free(msg); // refresh the outputs - refreshOutputs(msg->id); + refreshOutputs(msg->output_tag); } } } +/***************************************************************************** + * Function: recordEvent + * Description: send an event to the logger + * + * @param output -> the output channel + * @param control -> the control, this can be null + * @return none + *****************************************************************************/ void recordEvent(std::string output, const Control *control) { @@ -122,6 +130,21 @@ ModbusValue output_value; memset(&ev, 0, sizeof(ev)); + if ( !control ) { + ev.eventReason = EVENT_REASON_NO_CONTROL; + ModbusMasterReadRegister(output, &output_value); + strncpy(ev.outputTag, output.c_str(), sizeof(ev.outputTag)); + ev.outputValue = output_value.value; + + printf("\rEVENT RECORD\n"); + printf("\rev.eventReason = %d\n", ev.eventReason); + printf("\rev.outputTag = %s\n", ev.outputTag); + printf("\rev.outputValue = %.02f\n", ev.outputValue); + + EventLoggerApi(ev); + return; + } + switch ( control->getControlType() ) { case CONTROL_SETPOINT: ev.eventReason = EVENT_REASON_AUTO; @@ -163,24 +186,46 @@ * @param args -> not used * @return none *****************************************************************************/ -static void refreshOutputs(const string id) +static void refreshOutputs(const string output_tag) { //who's in control here? StringOutputVector_t::iterator pos; + pos = outputMap.find(output_tag); + if ( pos != outputMap.end() ) { + if ( pos->second.empty() ) { + // play it safe + ModbusMasterWriteRegister(pos->first, 0.0); + recordEvent(pos->first, NULL); + // TODO: will need to record an event here also if the control is destroyed + } else { + ModbusMasterWriteRegister(pos->first, pos->second.begin()->getState()); + recordEvent(pos->first, (Control*)pos->second.begin()); + } + } else { + logError("%s failed to find the selected output %s", + __func__, output_tag.c_str()); + } + + +#if 0 for ( pos = outputMap.begin(); pos != outputMap.end(); ++pos ) { if ( pos->second.empty() ) { // safeguarding ModbusMasterWriteRegister(pos->first, 0.00); } else { // a control is tied to this output - if ( id == pos->second.begin()->getId() ) { + // TODO: fix this so that only the output for which an action + // occurred is updated + //if ( id == pos->second.begin()->getId() ) + { ModbusMasterWriteRegister(pos->first, pos->second.begin()->getState()); recordEvent(pos->first, (Control*)pos->second.begin()); } } } +#endif } /***************************************************************************** @@ -368,6 +413,7 @@ break; } } + if ( !found ) { logError("%s: failed to find control %s in list", __func__, id); return -1;