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/ModbusMaster/ModbusMaster.cpp
- Revision:
- 82:f3e495a98877
- Parent:
- 81:d45bfa16953a
- Child:
- 83:0f76cfbb4eba
- Child:
- 87:c466bde76fa0
--- a/src/ModbusMaster/ModbusMaster.cpp Tue Sep 20 13:41:31 2016 +0000
+++ b/src/ModbusMaster/ModbusMaster.cpp Tue Sep 20 15:35:13 2016 +0000
@@ -27,6 +27,7 @@
logInfo("%s ModbusMaster has started...", __func__);
bool status;
bool input;
+ bool move_up = true;
MbedJSONValue json_value;
modbus_init(MB_BAUD_RATE);
@@ -72,6 +73,7 @@
ModbusRegisterMap[id].fmt = json_value["fmt"].get<std::string>().c_str();
ModbusRegisterMap[id].rfreq = atoi(json_value["rfreq"].get<std::string>().c_str());
ModbusRegisterMap[id].input = input;
+ ModbusRegisterMap[id].simulated = false;
}
}
@@ -80,6 +82,30 @@
std::map<std::string, ModbusRegister>::iterator iter;
for (iter = ModbusRegisterMap.begin(); iter != ModbusRegisterMap.end(); ++iter) {
+ if( iter->second.simulated == true ) {
+ std::map<std::string, SimulateInput>::iterator iter;
+ for (iter = SimulateInputMap.begin(); iter != SimulateInputMap.end(); ++iter) {
+ if( (SimulateInputMap[iter->first].min == 0) && (SimulateInputMap[iter->first].max == 0) ) {
+ ModbusRegisterMap[iter->first].float_value = SimulateInputMap[iter->first].start_value;
+ } else {
+ if( ModbusRegisterMap[iter->first].float_value >= SimulateInputMap[iter->first].max ) {
+ move_up = false;
+ ModbusRegisterMap[iter->first].float_value = ModbusRegisterMap[iter->first].float_value - SimulateInputMap[iter->first].step;
+ } else if( ModbusRegisterMap[iter->first].float_value <= SimulateInputMap[iter->first].min ) {
+ move_up = true;
+ ModbusRegisterMap[iter->first].float_value = ModbusRegisterMap[iter->first].float_value + SimulateInputMap[iter->first].step;
+ } else {
+ if( move_up == true ) {
+ ModbusRegisterMap[iter->first].float_value = ModbusRegisterMap[iter->first].float_value + SimulateInputMap[iter->first].step;
+ } else {
+ ModbusRegisterMap[iter->first].float_value = ModbusRegisterMap[iter->first].float_value - SimulateInputMap[iter->first].step;
+ }
+ }
+ logInfo("simulating input=%s, value=%2.2f",iter->first.c_str(), ModbusRegisterMap[iter->first].float_value);
+ }
+ }
+ continue;
+ }
logInfo("Processing node=%d, reg=%d, size=%d, order=%d", iter->second.node, iter->second.reg, iter->second.size, iter->second.order );
SendModbusCommand(iter->second.node, iter->second.reg, iter->second.size);
Thread::wait(30);
@@ -106,16 +132,12 @@
default:
break;
}
-
- if( iter->second.input == false )
- {
- printf("processing output=%s, reg=%d, value=%d\r\n",iter->first.c_str(), ModbusRegisterMap[iter->first].reg, (bool)ModbusRegisterMap[iter->first].float_value);
- if( ModbusRegisterMap[iter->first].reg == 1 )
- {
+
+ if( iter->second.input == false ) {
+ logInfo("processing output=%s, reg=%d, value=%d",iter->first.c_str(), ModbusRegisterMap[iter->first].reg, (bool)ModbusRegisterMap[iter->first].float_value);
+ if( ModbusRegisterMap[iter->first].reg == 1 ) {
dout1 = (bool)ModbusRegisterMap[iter->first].float_value;
- }
- else
- {
+ } else {
dout2 = (bool)ModbusRegisterMap[iter->first].float_value;
}
}
