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:
- 282:2dc06137f1ec
- Parent:
- 237:ecf34419ce5d
- Child:
- 283:a09013615589
--- a/src/ModbusMaster/ModbusMaster.cpp Wed Oct 26 21:26:52 2016 +0000
+++ b/src/ModbusMaster/ModbusMaster.cpp Thu Oct 27 21:44:25 2016 +0000
@@ -6,6 +6,8 @@
*****************************************************************************/
#include "global.h"
#include <stdio.h>
+#include <sstream>
+#include <iostream>
#include "MTSLog.h"
#include "BLEDataHandler.h"
#include "ModbusMaster.h"
@@ -101,7 +103,7 @@
osEvent evt = ModbusMasterMailBox.get(50);
if (evt.status == osEventMail) {
- Message_t *mail = (Message_t*)evt.value.p;
+ ModbusMasterReq_t *mail = (ModbusMasterReq_t*)evt.value.p;
printf("Mail Received: Action: %d, New Input File: %s\r\n", mail->action, mail->controlFile);
if( mail->action == ACTION_EXEC_CMD ) {
ModbusMasterExecCmd( mail->controlFile );
@@ -276,7 +278,15 @@
}
status = ReadModbus_32bit_float( &float_value, order, rd_buf );
if( status == true ) {
+ std::ostringstream mb_reply;
printf("CMD: %s:%d: %s value=%2.4f\r\n", __func__, __LINE__, id.c_str(), float_value );
+ BLEHandlerReq_t *mail = BLEHandlerMailBox.alloc();
+ mb_reply << "{ \"mtype\":1001, \"mbreply\":{ \"id\":\"" << id.c_str() << "\"," "\"status\":\"0\"," "\"value\":\"" << float_value << "\"} }";
+ std::string string_reply = mb_reply.str();
+ strncpy( mail->reply, string_reply.c_str(), (sizeof(mail->reply)-1));
+ printf("%s:%d: Reply is: %s\r\n",__func__,__LINE__, mail->reply);
+ BLEHandlerMailBox.put(mail);
+
} else {
printf("CMD: %s:%d: %s failed\r\n", __func__, __LINE__, id.c_str() );
}
@@ -368,7 +378,7 @@
} else {
printf("(%s:%d)loading File: %s\r\n", __func__, __LINE__, fileName );
}
-
+
cJSON * root = cJSON_Parse(ModbusMasterScratchBuf);
std::string tag = cJSON_GetObjectItem(root,"tag")->valuestring;
std::string id = cJSON_GetObjectItem(root,"id")->valuestring;
@@ -402,7 +412,7 @@
} else {
logInfo("(%s:%d)loading File: %s", __func__, __LINE__, fileName );
}
-
+
cJSON * root = cJSON_Parse(ModbusMasterScratchBuf);
std::string id = cJSON_GetObjectItem(root,"id")->valuestring;
ModbusRegisterMap[id].name = cJSON_GetObjectItem(root,"name")->valuestring;
