Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Committer:
jmarkel44
Date:
Wed Oct 19 23:44:38 2016 +0000
Revision:
239:cfb1a917e7f7
Parent:
208:784c46652863
Child:
242:3b0086a6d625
generic failsafe;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jmarkel44 14:cc916fa8dd11 1 /******************************************************************************
jmarkel44 207:55aabde2d4bf 2 *
jmarkel44 207:55aabde2d4bf 3 * File: SetpointControl.cpp
jmarkel44 207:55aabde2d4bf 4 * Desciption: ICE Setpoint Control class implementation
jmarkel44 207:55aabde2d4bf 5 *
jmarkel44 207:55aabde2d4bf 6 *****************************************************************************/
jmarkel44 13:c80c283f9db2 7 #include "SetpointControl.h"
jmarkel44 14:cc916fa8dd11 8 #include "mDot.h"
jmarkel44 20:653923c2f37a 9 #include "MbedJSONValue.h"
davidjhoward 91:0e8d76030598 10 #include "ModbusMasterApi.h"
jmarkel44 51:66b820f203a5 11 #include "global.h"
jmarkel44 28:c410a61238bb 12 #include <string>
jmarkel44 202:d6011a00bfb8 13 #include <iostream>
jmarkel44 202:d6011a00bfb8 14 #include <iomanip>
jmarkel44 13:c80c283f9db2 15
jmarkel44 14:cc916fa8dd11 16 extern mDot *GLOBAL_mdot;
jmarkel44 14:cc916fa8dd11 17
jmarkel44 195:21df85341cb3 18 //
jmarkel44 195:21df85341cb3 19 // method: load
jmarkel44 195:21df85341cb3 20 // description: open the configuration file and assign data to the
jmarkel44 56:225786c56315 21 // setpoint control object
jmarkel44 56:225786c56315 22 //
jmarkel44 56:225786c56315 23 // @param controlFile -> name of the control file
jmarkel44 56:225786c56315 24 // @return true if data is assigned; false on error
jmarkel44 195:21df85341cb3 25 //
jmarkel44 28:c410a61238bb 26 bool SetpointControl::load(string _controlFile)
jmarkel44 20:653923c2f37a 27 {
jmarkel44 51:66b820f203a5 28 MbedJSONValue json_value; // JSON parsing element
jmarkel44 51:66b820f203a5 29 controlFile = _controlFile;
jmarkel44 207:55aabde2d4bf 30
jmarkel44 56:225786c56315 31 // open and read from the control file
jmarkel44 14:cc916fa8dd11 32 mDot::mdot_file file = GLOBAL_mdot->openUserFile(controlFile.c_str(), mDot::FM_RDONLY);
jmarkel44 207:55aabde2d4bf 33 if ( file.fd < 0 ) {
jmarkel44 207:55aabde2d4bf 34 logError("%s: failed to open %s\n", __func__, controlFile.c_str());
jmarkel44 28:c410a61238bb 35 return false;
jmarkel44 207:55aabde2d4bf 36 }
jmarkel44 20:653923c2f37a 37
jmarkel44 20:653923c2f37a 38 // read the data into a buffer
jmarkel44 177:9ec90c8e3ce1 39 char dataBuf[MAX_FILE_SIZE];
jmarkel44 28:c410a61238bb 40
jmarkel44 28:c410a61238bb 41 int bytes_read = GLOBAL_mdot->readUserFile(file, (void *)dataBuf, sizeof(dataBuf));
jmarkel44 28:c410a61238bb 42 if ( bytes_read != sizeof(dataBuf) ) {
jmarkel44 28:c410a61238bb 43 logError("%s: failed to read %d bytes from %s", __func__, sizeof(dataBuf), controlFile.c_str());
jmarkel44 93:1553fb156915 44 // caller should destroy the object
jmarkel44 28:c410a61238bb 45 return false;
jmarkel44 28:c410a61238bb 46 }
jmarkel44 51:66b820f203a5 47
jmarkel44 51:66b820f203a5 48 // close the file
jmarkel44 28:c410a61238bb 49 GLOBAL_mdot->closeUserFile(file);
jmarkel44 28:c410a61238bb 50
jmarkel44 51:66b820f203a5 51 // parse the json data
jmarkel44 28:c410a61238bb 52 parse(json_value, dataBuf);
jmarkel44 51:66b820f203a5 53
jmarkel44 192:052a419837fa 54 if ( !json_value.hasMember("id") ||
jmarkel44 192:052a419837fa 55 !json_value.hasMember("priority") ||
jmarkel44 192:052a419837fa 56 !json_value.hasMember("input") ||
jmarkel44 192:052a419837fa 57 !json_value.hasMember("output") ||
jmarkel44 192:052a419837fa 58 !json_value.hasMember("setpoint") ||
jmarkel44 192:052a419837fa 59 !json_value.hasMember("prodfact") ||
jmarkel44 192:052a419837fa 60 !json_value.hasMember("actingDir") ||
jmarkel44 192:052a419837fa 61 !json_value.hasMember("halert") ||
jmarkel44 192:052a419837fa 62 !json_value.hasMember("lalert") ||
jmarkel44 192:052a419837fa 63 !json_value.hasMember("hfs") ||
jmarkel44 192:052a419837fa 64 !json_value.hasMember("lfs") ||
jmarkel44 192:052a419837fa 65 !json_value.hasMember("tol") ) {
jmarkel44 207:55aabde2d4bf 66 logError("Setpoint Control file is missing expected tags");
jmarkel44 192:052a419837fa 67 return false;
jmarkel44 192:052a419837fa 68 }
jmarkel44 192:052a419837fa 69
jmarkel44 96:807f04bd5256 70 id = json_value ["id"].get<string>();
jmarkel44 28:c410a61238bb 71 priority = atoi(json_value["priority"].get<string>().c_str());
jmarkel44 96:807f04bd5256 72 input = json_value ["input"].get<string>();
jmarkel44 96:807f04bd5256 73 output = json_value ["output"].get<string>();
jmarkel44 89:55ac65d7f206 74 setpoint = atof(json_value["setpoint"].get<string>().c_str());
jmarkel44 28:c410a61238bb 75 productFactor = atof(json_value["prodfact"].get<string>().c_str());
jmarkel44 90:7d9731dec0da 76 actingDir = atoi(json_value["actingDir"].get<string>().c_str());
jmarkel44 28:c410a61238bb 77 highAlert = atof(json_value["halert"].get<string>().c_str());
jmarkel44 28:c410a61238bb 78 lowAlert = atof(json_value["lalert"].get<string>().c_str());
jmarkel44 28:c410a61238bb 79 highFailsafe = atof(json_value["hfs"].get<string>().c_str());
jmarkel44 28:c410a61238bb 80 lowFailsafe = atof(json_value["lfs"].get<string>().c_str());
jmarkel44 96:807f04bd5256 81 tolerance = atof(json_value["tol"].get<string>().c_str());
jmarkel44 20:653923c2f37a 82
jmarkel44 56:225786c56315 83 return true; // object created successfully
jmarkel44 51:66b820f203a5 84 }
jmarkel44 51:66b820f203a5 85
jmarkel44 195:21df85341cb3 86 //
jmarkel44 195:21df85341cb3 87 // method: start
jmarkel44 195:21df85341cb3 88 // description: start the setpoint control
jmarkel44 56:225786c56315 89 //
jmarkel44 56:225786c56315 90 // @param none
jmarkel44 56:225786c56315 91 // @return none
jmarkel44 195:21df85341cb3 92 //
jmarkel44 51:66b820f203a5 93 void SetpointControl::start(void)
jmarkel44 51:66b820f203a5 94 {
jmarkel44 56:225786c56315 95 // this is the initial state; what else needs to be done??
jmarkel44 51:66b820f203a5 96 this->currentState = STATE_STARTUP;
jmarkel44 19:9bc8fabeddfa 97 }
jmarkel44 19:9bc8fabeddfa 98
jmarkel44 195:21df85341cb3 99 //
jmarkel44 195:21df85341cb3 100 // method: update
jmarkel44 195:21df85341cb3 101 // description: based on the state of the control, check for
jmarkel44 56:225786c56315 102 // under limit and over limit values, adjust the
jmarkel44 56:225786c56315 103 // state accordingly
jmarkel44 56:225786c56315 104 //
jmarkel44 56:225786c56315 105 // @param none
jmarkel44 56:225786c56315 106 // @return none
jmarkel44 195:21df85341cb3 107 //
jmarkel44 51:66b820f203a5 108 void SetpointControl::update(void)
jmarkel44 51:66b820f203a5 109 {
jmarkel44 51:66b820f203a5 110 switch (this->currentState) {
jmarkel44 131:a290a3934132 111 case STATE_INIT:
jmarkel44 131:a290a3934132 112 // do nothing
jmarkel44 131:a290a3934132 113 break;
jmarkel44 51:66b820f203a5 114 case STATE_STARTUP:
jmarkel44 51:66b820f203a5 115 if ( this->underLimit() ) {
jmarkel44 51:66b820f203a5 116 // start the feed right away
jmarkel44 51:66b820f203a5 117 this->startFeed();
jmarkel44 51:66b820f203a5 118 this->currentState = STATE_CONTROL_ON;
jmarkel44 51:66b820f203a5 119 } else {
jmarkel44 51:66b820f203a5 120 this->currentState = STATE_CONTROL_OFF;
jmarkel44 143:23a572f084dd 121 this->stopFeed();
jmarkel44 51:66b820f203a5 122 }
jmarkel44 51:66b820f203a5 123 break;
jmarkel44 51:66b820f203a5 124 case STATE_CONTROL_ON:
jmarkel44 51:66b820f203a5 125 if ( this->overLimit() ) {
jmarkel44 51:66b820f203a5 126 // stop the feed
jmarkel44 51:66b820f203a5 127 this->stopFeed();
jmarkel44 51:66b820f203a5 128 this->currentState = STATE_CONTROL_OFF;
jmarkel44 239:cfb1a917e7f7 129 } else if ( this->overFailsafeLimit() ) {
jmarkel44 239:cfb1a917e7f7 130 // TODO: check for a failsafe condition
jmarkel44 239:cfb1a917e7f7 131 printf("\rDEBUG: FAILSAFE ON\n");
jmarkel44 239:cfb1a917e7f7 132 this->currentState = STATE_FAILSAFE_ON;
jmarkel44 51:66b820f203a5 133 }
jmarkel44 51:66b820f203a5 134 break;
jmarkel44 51:66b820f203a5 135 case STATE_CONTROL_OFF:
jmarkel44 51:66b820f203a5 136 if ( this->underLimit() ) {
jmarkel44 51:66b820f203a5 137 // start the feed
jmarkel44 51:66b820f203a5 138 this->startFeed();
jmarkel44 51:66b820f203a5 139 this->currentState = STATE_CONTROL_ON;
jmarkel44 239:cfb1a917e7f7 140 } else if ( this->underFailsafeLimit() ) {
jmarkel44 239:cfb1a917e7f7 141 // TODO: check for a failsafe condition
jmarkel44 239:cfb1a917e7f7 142 printf("\rDEBUG: FAILSAFE OFF\n");
jmarkel44 239:cfb1a917e7f7 143 this->currentState = STATE_FAILSAFE_OFF;
jmarkel44 51:66b820f203a5 144 }
jmarkel44 51:66b820f203a5 145 break;
jmarkel44 239:cfb1a917e7f7 146 case STATE_FAILSAFE_ON:
jmarkel44 239:cfb1a917e7f7 147 case STATE_FAILSAFE_OFF:
jmarkel44 239:cfb1a917e7f7 148 break;
jmarkel44 56:225786c56315 149 //case STATE_CONTROL_DISABLED:
jmarkel44 56:225786c56315 150 //case STATE_CONTROL_PAUSED:
jmarkel44 51:66b820f203a5 151 default:
jmarkel44 51:66b820f203a5 152 break;
jmarkel44 51:66b820f203a5 153 }
jmarkel44 51:66b820f203a5 154 }
jmarkel44 51:66b820f203a5 155
jmarkel44 195:21df85341cb3 156 //
jmarkel44 195:21df85341cb3 157 // method: overLimit
jmarkel44 195:21df85341cb3 158 // description: (see @return)
jmarkel44 56:225786c56315 159 //
jmarkel44 56:225786c56315 160 // @param none
jmarkel44 56:225786c56315 161 // @return true if product is over the upper limit for normal mode
jmarkel44 56:225786c56315 162 // or under the limit for reverse mode; false otherwise
jmarkel44 195:21df85341cb3 163 //
jmarkel44 51:66b820f203a5 164 bool SetpointControl::overLimit(void)
jmarkel44 51:66b820f203a5 165 {
davidjhoward 91:0e8d76030598 166 ModbusValue value;
jmarkel44 92:9a6a1adca19c 167 ModbusMasterReadRegister( input, &value );
jmarkel44 92:9a6a1adca19c 168 float flimit;
davidjhoward 91:0e8d76030598 169
jmarkel44 92:9a6a1adca19c 170 if ( !actingDir ) {
jmarkel44 96:807f04bd5256 171 flimit = setpoint + tolerance;
jmarkel44 92:9a6a1adca19c 172 return (value.value > flimit);
jmarkel44 92:9a6a1adca19c 173 } else {
jmarkel44 115:1558e01d04c6 174 flimit = setpoint - tolerance;
jmarkel44 92:9a6a1adca19c 175 return (value.value < flimit);
davidjhoward 91:0e8d76030598 176 }
jmarkel44 51:66b820f203a5 177 }
jmarkel44 51:66b820f203a5 178
jmarkel44 195:21df85341cb3 179 //
jmarkel44 239:cfb1a917e7f7 180 // method: overFailsafeLimit()
jmarkel44 239:cfb1a917e7f7 181 // description: (see @return)
jmarkel44 239:cfb1a917e7f7 182 //
jmarkel44 239:cfb1a917e7f7 183 // @param none
jmarkel44 239:cfb1a917e7f7 184 // @return true if product is over the upper limit for normal mode
jmarkel44 239:cfb1a917e7f7 185 // or under the limit for reverse mode; false otherwise
jmarkel44 239:cfb1a917e7f7 186 //
jmarkel44 239:cfb1a917e7f7 187 bool SetpointControl::overFailsafeLimit(void)
jmarkel44 239:cfb1a917e7f7 188 {
jmarkel44 239:cfb1a917e7f7 189 ModbusValue value;
jmarkel44 239:cfb1a917e7f7 190 ModbusMasterReadRegister( input, &value );
jmarkel44 239:cfb1a917e7f7 191
jmarkel44 239:cfb1a917e7f7 192 printf("\ractingDir = %d:%f(%f : %f\n", actingDir, value.value, highFailsafe, lowFailsafe);
jmarkel44 239:cfb1a917e7f7 193 if ( !actingDir ) {
jmarkel44 239:cfb1a917e7f7 194 return (value.value > lowFailsafe);
jmarkel44 239:cfb1a917e7f7 195 } else {
jmarkel44 239:cfb1a917e7f7 196 return (value.value < highFailsafe);
jmarkel44 239:cfb1a917e7f7 197 }
jmarkel44 239:cfb1a917e7f7 198 }
jmarkel44 239:cfb1a917e7f7 199
jmarkel44 239:cfb1a917e7f7 200 //
jmarkel44 195:21df85341cb3 201 // method: underLimit
jmarkel44 195:21df85341cb3 202 // description: (see @return)
jmarkel44 56:225786c56315 203 //
jmarkel44 56:225786c56315 204 // @param none
jmarkel44 56:225786c56315 205 // @return true if product is under lower limit for normal mode or
jmarkel44 56:225786c56315 206 // over the upper limit for reverse mode; false otherwise
jmarkel44 195:21df85341cb3 207 //
jmarkel44 51:66b820f203a5 208 bool SetpointControl::underLimit(void)
jmarkel44 51:66b820f203a5 209 {
davidjhoward 91:0e8d76030598 210 ModbusValue value;
jmarkel44 92:9a6a1adca19c 211 ModbusMasterReadRegister( input, &value );
jmarkel44 92:9a6a1adca19c 212 float flimit;
davidjhoward 91:0e8d76030598 213
jmarkel44 92:9a6a1adca19c 214 if ( !actingDir ) {
jmarkel44 115:1558e01d04c6 215 flimit = setpoint - tolerance;
jmarkel44 92:9a6a1adca19c 216 return (value.value < flimit);
jmarkel44 92:9a6a1adca19c 217 } else {
jmarkel44 96:807f04bd5256 218 flimit = setpoint + tolerance;
jmarkel44 92:9a6a1adca19c 219 return (value.value > flimit);
davidjhoward 91:0e8d76030598 220 }
jmarkel44 51:66b820f203a5 221 }
jmarkel44 51:66b820f203a5 222
jmarkel44 195:21df85341cb3 223 //
jmarkel44 239:cfb1a917e7f7 224 // method: underLimit
jmarkel44 239:cfb1a917e7f7 225 // description: (see @return)
jmarkel44 239:cfb1a917e7f7 226 //
jmarkel44 239:cfb1a917e7f7 227 // @param none
jmarkel44 239:cfb1a917e7f7 228 // @return true if product is under lower limit for normal mode or
jmarkel44 239:cfb1a917e7f7 229 // over the upper limit for reverse mode; false otherwise
jmarkel44 239:cfb1a917e7f7 230 //
jmarkel44 239:cfb1a917e7f7 231 bool SetpointControl::underFailsafeLimit(void)
jmarkel44 239:cfb1a917e7f7 232 {
jmarkel44 239:cfb1a917e7f7 233 ModbusValue value;
jmarkel44 239:cfb1a917e7f7 234 ModbusMasterReadRegister( input, &value );
jmarkel44 239:cfb1a917e7f7 235
jmarkel44 239:cfb1a917e7f7 236 if ( !actingDir ) {
jmarkel44 239:cfb1a917e7f7 237 return (value.value < lowFailsafe);
jmarkel44 239:cfb1a917e7f7 238 } else {
jmarkel44 239:cfb1a917e7f7 239 return (value.value > highFailsafe);
jmarkel44 239:cfb1a917e7f7 240 }
jmarkel44 239:cfb1a917e7f7 241 }
jmarkel44 239:cfb1a917e7f7 242
jmarkel44 239:cfb1a917e7f7 243 //
jmarkel44 195:21df85341cb3 244 // method: startFeed()
jmarkel44 195:21df85341cb3 245 // description: send ON indication to Output Master for this control's
jmarkel44 56:225786c56315 246 // relay
jmarkel44 56:225786c56315 247 //
jmarkel44 56:225786c56315 248 // @param none
jmarkel44 56:225786c56315 249 // @return none
jmarkel44 195:21df85341cb3 250 //
jmarkel44 51:66b820f203a5 251 void SetpointControl::startFeed(void)
jmarkel44 51:66b820f203a5 252 {
jmarkel44 56:225786c56315 253 logInfo("%s: %s attempting to start feed on relay %s\n",
jmarkel44 56:225786c56315 254 __func__, controlFile.c_str(), output.c_str());
jmarkel44 56:225786c56315 255
jmarkel44 71:34856d21f2bf 256 OutputControlMsg_t *output_mail = OutputMasterMailBox.alloc();
jmarkel44 71:34856d21f2bf 257 memset(output_mail, 0, sizeof(OutputControlMsg_t));
jmarkel44 115:1558e01d04c6 258
jmarkel44 115:1558e01d04c6 259 output_mail->action = ACTION_CONTROL_ON;
jmarkel44 115:1558e01d04c6 260 output_mail->controlType = CONTROL_SETPOINT;
jmarkel44 115:1558e01d04c6 261 strncpy(output_mail->input_tag, this->input.c_str(), sizeof(output_mail->input_tag)-1);
jmarkel44 115:1558e01d04c6 262 strncpy(output_mail->output_tag, this->output.c_str(), sizeof(output_mail->output_tag)-1);
jmarkel44 71:34856d21f2bf 263 output_mail->priority = this->priority;
jmarkel44 71:34856d21f2bf 264 strncpy(output_mail->id, this->id.c_str(), sizeof(output_mail->id)-1);
jmarkel44 71:34856d21f2bf 265 OutputMasterMailBox.put(output_mail);
jmarkel44 51:66b820f203a5 266 }
jmarkel44 51:66b820f203a5 267
jmarkel44 195:21df85341cb3 268 //
jmarkel44 195:21df85341cb3 269 // method: stopFeed
jmarkel44 195:21df85341cb3 270 // description: send OFF indication to Output Master for this control's
jmarkel44 56:225786c56315 271 // relay
jmarkel44 56:225786c56315 272 //
jmarkel44 56:225786c56315 273 // @param none
jmarkel44 56:225786c56315 274 // @return none
jmarkel44 195:21df85341cb3 275 //
jmarkel44 51:66b820f203a5 276 void SetpointControl::stopFeed(void)
jmarkel44 51:66b820f203a5 277 {
jmarkel44 71:34856d21f2bf 278 logInfo("%s: %s attempting to stop feed on relay %s\n",
jmarkel44 56:225786c56315 279 __func__, controlFile.c_str(), output.c_str());
jmarkel44 56:225786c56315 280
jmarkel44 71:34856d21f2bf 281 OutputControlMsg_t *output_mail = OutputMasterMailBox.alloc();
jmarkel44 71:34856d21f2bf 282 memset(output_mail, 0, sizeof(OutputControlMsg_t));
jmarkel44 115:1558e01d04c6 283
jmarkel44 115:1558e01d04c6 284 output_mail->action = ACTION_CONTROL_OFF;
jmarkel44 115:1558e01d04c6 285 output_mail->controlType = CONTROL_SETPOINT;
jmarkel44 115:1558e01d04c6 286 strncpy(output_mail->input_tag, this->input.c_str(), sizeof(output_mail->input_tag)-1);
jmarkel44 115:1558e01d04c6 287 strncpy(output_mail->output_tag, this->output.c_str(), sizeof(output_mail->output_tag)-1);
jmarkel44 71:34856d21f2bf 288 output_mail->priority = this->priority;
jmarkel44 71:34856d21f2bf 289 strncpy(output_mail->id, this->id.c_str(), sizeof(output_mail->id)-1);
jmarkel44 71:34856d21f2bf 290 OutputMasterMailBox.put(output_mail);
jmarkel44 72:3754b352f156 291 }
jmarkel44 72:3754b352f156 292
jmarkel44 195:21df85341cb3 293 //
jmarkel44 195:21df85341cb3 294 // dethod: unregisterControl
jmarkel44 195:21df85341cb3 295 // description: send OFF indication to Output Master for this control's
jmarkel44 72:3754b352f156 296 // relay
jmarkel44 72:3754b352f156 297 //
jmarkel44 72:3754b352f156 298 // @param none
jmarkel44 72:3754b352f156 299 // @return none
jmarkel44 195:21df85341cb3 300 //
jmarkel44 72:3754b352f156 301 void SetpointControl::unregisterControl(void)
jmarkel44 72:3754b352f156 302 {
jmarkel44 115:1558e01d04c6 303 logInfo("%s: %s attempting to unregister %s\n",
jmarkel44 115:1558e01d04c6 304 __func__, controlFile.c_str());
jmarkel44 72:3754b352f156 305
jmarkel44 72:3754b352f156 306 OutputControlMsg_t *output_mail = OutputMasterMailBox.alloc();
jmarkel44 72:3754b352f156 307 memset(output_mail, 0, sizeof(OutputControlMsg_t));
jmarkel44 192:052a419837fa 308
jmarkel44 115:1558e01d04c6 309 output_mail->action = ACTION_CONTROL_UNREGISTER;
jmarkel44 115:1558e01d04c6 310 output_mail->controlType = CONTROL_MANUAL;
jmarkel44 115:1558e01d04c6 311 output_mail->priority = this->priority;
jmarkel44 115:1558e01d04c6 312 strncpy(output_mail->output_tag, this->output.c_str(), sizeof(output_mail->output_tag)-1);
jmarkel44 72:3754b352f156 313 strncpy(output_mail->id, this->id.c_str(), sizeof(output_mail->id)-1);
jmarkel44 192:052a419837fa 314
jmarkel44 72:3754b352f156 315 OutputMasterMailBox.put(output_mail);
jmarkel44 93:1553fb156915 316 }
jmarkel44 93:1553fb156915 317
jmarkel44 195:21df85341cb3 318 //
jmarkel44 195:21df85341cb3 319 // method: display
jmarkel44 195:21df85341cb3 320 // description: display the control's information
jmarkel44 183:44f7fea6b208 321 //
jmarkel44 183:44f7fea6b208 322 // @param none
jmarkel44 183:44f7fea6b208 323 // @return none
jmarkel44 195:21df85341cb3 324 //
jmarkel44 93:1553fb156915 325 void SetpointControl::display(void)
jmarkel44 93:1553fb156915 326 {
jmarkel44 183:44f7fea6b208 327 // NOTE: this mapping must be 1:1 with "State" enumeration in SetpointControl.h
jmarkel44 131:a290a3934132 328 string mapper[] = { "INIT",
jmarkel44 131:a290a3934132 329 "STARTUP",
jmarkel44 93:1553fb156915 330 "CONTROL_OFF",
jmarkel44 93:1553fb156915 331 "CONTROL_ON",
jmarkel44 239:cfb1a917e7f7 332 "FAILSAFE_ON",
jmarkel44 239:cfb1a917e7f7 333 "FAILSAFE_OFF",
jmarkel44 93:1553fb156915 334 "CONTROL_DISABLE",
jmarkel44 93:1553fb156915 335 "CONTROL_PAUSE",
jmarkel44 115:1558e01d04c6 336 "CONTROL_MAX"
jmarkel44 115:1558e01d04c6 337 };
jmarkel44 115:1558e01d04c6 338
jmarkel44 115:1558e01d04c6 339
jmarkel44 183:44f7fea6b208 340 ModbusValue inputValue;
jmarkel44 183:44f7fea6b208 341 ModbusMasterReadRegister(input, &inputValue);
jmarkel44 192:052a419837fa 342
jmarkel44 93:1553fb156915 343 printf("\r\n");
jmarkel44 205:3c84af5f711f 344 std::cout << left << setw(10) << setfill(' ') << "setpoint: ";
jmarkel44 202:d6011a00bfb8 345 std::cout << left << setw(32) << setfill(' ') << controlFile;
jmarkel44 202:d6011a00bfb8 346 std::cout << left << setw(20) << setfill(' ') << id;
jmarkel44 202:d6011a00bfb8 347 std::cout << left << setw(6) << setfill(' ') << priority;
jmarkel44 202:d6011a00bfb8 348 std::cout << left << setw(20) << setfill(' ') << input;
jmarkel44 202:d6011a00bfb8 349 std::cout << left << setw(20) << setfill(' ') << output;
jmarkel44 202:d6011a00bfb8 350 std::cout << left << setw(8) << setfill(' ') << setpoint;
jmarkel44 202:d6011a00bfb8 351 std::cout << left << setw(12) << setfill(' ') << (actingDir ? "direct" : "indirect");
jmarkel44 202:d6011a00bfb8 352 std::cout << left << setw(16) << setfill(' ') << mapper[currentState];
jmarkel44 202:d6011a00bfb8 353 std::cout << right << setw(8) << setfill(' ') << setpoint + tolerance << " <- ";
jmarkel44 202:d6011a00bfb8 354 std::cout << left << setw(8) << setfill(' ') << inputValue.value << " -> ";
jmarkel44 202:d6011a00bfb8 355 std::cout << left << setw(8) << setfill(' ') << setpoint - tolerance;
jmarkel44 239:cfb1a917e7f7 356 std::cout << left << setw(10) << setfill(' ') << highFailsafe << " : " << lowFailsafe;
jmarkel44 202:d6011a00bfb8 357
jmarkel44 202:d6011a00bfb8 358 std::cout.flush();
jmarkel44 51:66b820f203a5 359 }