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/ConfigurationHandler/Controls/SetpointControl.cpp
- Revision:
- 242:3b0086a6d625
- Parent:
- 239:cfb1a917e7f7
- Child:
- 253:ae850c19cf81
--- a/src/ConfigurationHandler/Controls/SetpointControl.cpp Thu Oct 20 14:13:31 2016 +0000 +++ b/src/ConfigurationHandler/Controls/SetpointControl.cpp Thu Oct 20 15:30:21 2016 +0000 @@ -6,7 +6,7 @@ *****************************************************************************/ #include "SetpointControl.h" #include "mDot.h" -#include "MbedJSONValue.h" +#include "cJSON.h" #include "ModbusMasterApi.h" #include "global.h" #include <string> @@ -25,7 +25,6 @@ // bool SetpointControl::load(string _controlFile) { - MbedJSONValue json_value; // JSON parsing element controlFile = _controlFile; // open and read from the control file @@ -49,36 +48,20 @@ GLOBAL_mdot->closeUserFile(file); // parse the json data - parse(json_value, dataBuf); - - if ( !json_value.hasMember("id") || - !json_value.hasMember("priority") || - !json_value.hasMember("input") || - !json_value.hasMember("output") || - !json_value.hasMember("setpoint") || - !json_value.hasMember("prodfact") || - !json_value.hasMember("actingDir") || - !json_value.hasMember("halert") || - !json_value.hasMember("lalert") || - !json_value.hasMember("hfs") || - !json_value.hasMember("lfs") || - !json_value.hasMember("tol") ) { - logError("Setpoint Control file is missing expected tags"); - return false; - } - - id = json_value ["id"].get<string>(); - priority = atoi(json_value["priority"].get<string>().c_str()); - input = json_value ["input"].get<string>(); - output = json_value ["output"].get<string>(); - setpoint = atof(json_value["setpoint"].get<string>().c_str()); - productFactor = atof(json_value["prodfact"].get<string>().c_str()); - actingDir = atoi(json_value["actingDir"].get<string>().c_str()); - highAlert = atof(json_value["halert"].get<string>().c_str()); - lowAlert = atof(json_value["lalert"].get<string>().c_str()); - highFailsafe = atof(json_value["hfs"].get<string>().c_str()); - lowFailsafe = atof(json_value["lfs"].get<string>().c_str()); - tolerance = atof(json_value["tol"].get<string>().c_str()); + cJSON * root = cJSON_Parse(dataBuf); + + id = cJSON_GetObjectItem(root,"id")->valuestring; + priority = atoi(cJSON_GetObjectItem(root,"priority")->valuestring); + input = cJSON_GetObjectItem(root,"input")->valuestring; + output = cJSON_GetObjectItem(root,"output")->valuestring; + setpoint = atof(cJSON_GetObjectItem(root,"setpoint")->valuestring); + productFactor = atof(cJSON_GetObjectItem(root, "prodfact")->valuestring); + actingDir = atoi(cJSON_GetObjectItem(root, "actingDir")->valuestring); + highAlert = atof(cJSON_GetObjectItem(root, "halert")->valuestring); + lowAlert = atof(cJSON_GetObjectItem(root, "lalert")->valuestring); + highFailsafe = atof(cJSON_GetObjectItem(root, "hfs")->valuestring); + lowFailsafe = atof(cJSON_GetObjectItem(root, "lfs")->valuestring); + tolerance = atof(cJSON_GetObjectItem(root, "tol")->valuestring); return true; // object created successfully } @@ -126,10 +109,8 @@ // stop the feed this->stopFeed(); this->currentState = STATE_CONTROL_OFF; - } else if ( this->overFailsafeLimit() ) { - // TODO: check for a failsafe condition - printf("\rDEBUG: FAILSAFE ON\n"); - this->currentState = STATE_FAILSAFE_ON; + } else { + // do nothing } break; case STATE_CONTROL_OFF: @@ -137,17 +118,12 @@ // start the feed this->startFeed(); this->currentState = STATE_CONTROL_ON; - } else if ( this->underFailsafeLimit() ) { - // TODO: check for a failsafe condition - printf("\rDEBUG: FAILSAFE OFF\n"); - this->currentState = STATE_FAILSAFE_OFF; + } else { + // do nothing } break; - case STATE_FAILSAFE_ON: - case STATE_FAILSAFE_OFF: - break; - //case STATE_CONTROL_DISABLED: - //case STATE_CONTROL_PAUSED: + //case STATE_CONTROL_DISABLED: + //case STATE_CONTROL_PAUSED: default: break; } @@ -177,27 +153,6 @@ } // -// method: overFailsafeLimit() -// description: (see @return) -// -// @param none -// @return true if product is over the upper limit for normal mode -// or under the limit for reverse mode; false otherwise -// -bool SetpointControl::overFailsafeLimit(void) -{ - ModbusValue value; - ModbusMasterReadRegister( input, &value ); - - printf("\ractingDir = %d:%f(%f : %f\n", actingDir, value.value, highFailsafe, lowFailsafe); - if ( !actingDir ) { - return (value.value > lowFailsafe); - } else { - return (value.value < highFailsafe); - } -} - -// // method: underLimit // description: (see @return) // @@ -221,26 +176,6 @@ } // -// method: underLimit -// description: (see @return) -// -// @param none -// @return true if product is under lower limit for normal mode or -// over the upper limit for reverse mode; false otherwise -// -bool SetpointControl::underFailsafeLimit(void) -{ - ModbusValue value; - ModbusMasterReadRegister( input, &value ); - - if ( !actingDir ) { - return (value.value < lowFailsafe); - } else { - return (value.value > highFailsafe); - } -} - -// // method: startFeed() // description: send ON indication to Output Master for this control's // relay @@ -329,8 +264,6 @@ "STARTUP", "CONTROL_OFF", "CONTROL_ON", - "FAILSAFE_ON", - "FAILSAFE_OFF", "CONTROL_DISABLE", "CONTROL_PAUSE", "CONTROL_MAX"