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:
- 84:7b7cad3ba139
- Parent:
- 80:b12b0adfcdc2
- Child:
- 86:189c125d8878
--- a/src/OutputTask/OutputTask.cpp Tue Sep 20 12:49:58 2016 +0000
+++ b/src/OutputTask/OutputTask.cpp Tue Sep 20 13:46:01 2016 +0000
@@ -11,18 +11,32 @@
#include <string>
#include <algorithm>
-// locals
+// local functions
static int createOutput(const char *controlFile);
static void loadPersistentOutputs(void);
-
-// local helpers
+static void refreshOutputs(void);
static int enableOutputReq (const char* id, unsigned int pri, const char* output);
static int disableOutputReq (const char *id, unsigned int pri, const char *output);
static int unregisterControl(const char *id, unsigned int pri, const char *output);
+// The Output Map
+//
+// this is the main data structure used to distinguish which control has
+// priority of an output. the layout is as-follows:
+//
+// outputMap["o_rly1"]-> Control<"ManCtrl_rly1", 100, ON >
+// Control<"SetpointCtrl_rly1", 800, OFF>
+// outputMap["o_rly2"]-> Control<"SetpointCtrl_rly2", 800, ON >
+// outputMap["o_rly3"]-> Control<"TimerControl_rl3", 500, ON>
+//
+// The Control Vector (per relay) is always sorted by priority, whereas
+// the highest priority control is at the beginning (v.begin()) of the
+// list.
+
typedef std::map<string, vector<Control> > StringOutputVector_t;
StringOutputVector_t outputMap;
+// operator for sorting the outputs vectors per output
bool operator<(const Control &control1, const Control &control2)
{
return control1.getPriority() < control2.getPriority();
@@ -45,7 +59,6 @@
loadPersistentOutputs();
osSignalSet(mainThreadId, sig_output_continue);
-
while (true) {
// wait for an event
osEvent evt = OutputMasterMailBox.get();
@@ -83,7 +96,7 @@
rc = unregisterControl(msg->id, msg->priority, msg->output);
if ( rc != 0 ) {
printf("%s: failed to unregister control %s",
- __func__, msg->id);
+ __func__, msg->id);
}
break;
default:
@@ -92,6 +105,34 @@
// free the message
OutputMasterMailBox.free(msg);
+ refreshOutputs();
+ }
+ }
+}
+
+
+/*****************************************************************************
+ * Function: refreshOutputs
+ * Description: send a message to the modbus master of who's in control
+ *
+ *
+ * @param args -> not used
+ * @return none
+ *****************************************************************************/
+static void refreshOutputs(void)
+{
+ //who's in control here?
+ StringOutputVector_t::iterator pos;
+
+ for ( pos = outputMap.begin(); pos != outputMap.end(); ++pos ) {
+ if ( pos->second.empty() ) {
+ printf("\r%s: No controls for %s\n", __func__, pos->first.c_str());
+ } else {
+ // a control is tied to this output
+ printf("\r%s: %s is controlling %s\n",
+ __func__, pos->second.begin()->getId().c_str(), pos->first.c_str());
+ // TODO: send a message to the modbus master of who's in control
+ // foo(pos->second->getId().c_str();
}
}
}
