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.
Revision 0:329c1b1d6e65, committed 2020-07-30
- Comitter:
- YSI
- Date:
- Thu Jul 30 12:57:09 2020 +0000
- Commit message:
- Example bug Serial com with USB3
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Thu Jul 30 12:57:09 2020 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Jul 30 12:57:09 2020 +0000
@@ -0,0 +1,75 @@
+#include "mbed.h"
+#include <sstream>
+
+#define MBED_PROJECT "USB3Bug"
+
+UnbufferedSerial pc(USBTX, USBRX, 230400);
+
+struct typeTRANSMISSION { string buffer; string serial; volatile bool SERIAL; } message = { "", "", false };
+
+void serial_event(void);
+void fn_processing(string);
+
+int main()
+{
+ message.buffer.reserve(1024);
+ message.serial.reserve(1024);
+ pc.attach(callback(&serial_event));
+ while(1)
+ {
+ if(message.SERIAL)
+ {
+ fn_processing(message.serial);
+ message.SERIAL = false;
+ }
+ }
+}
+
+void serial_event(void)
+{
+ char c;
+ pc.read(&c, 1);
+ if(c == '\n')
+ {
+ message.buffer += ';';
+ message.serial = message.buffer;
+ message.buffer.clear();
+ message.SERIAL = true;
+ }
+ else if((c < 128) && (message.buffer.size() < message.buffer.capacity()-2)) message.buffer += c;
+}
+
+void fn_processing(string cmd)
+{
+ stringstream srecv(cmd), ssend;
+ ssend.precision(3);
+ while(getline(srecv, cmd, ';'))
+ {
+ for (unsigned int i = 0; i < cmd.size(); i++) if ((cmd[i] >= 'a') && (cmd[i] <= 'z')) cmd[i] += 'A' - 'a';
+ if(ssend.str().size() > 0) ssend << ' ';
+ if(cmd.empty());
+ else if(cmd == "*IDN?")
+ {
+ ssend << MBED_PROJECT << ", Mbed OS " << MBED_VERSION << ", Version dated, " << __DATE__ << ", " << __TIME__;
+ }
+ else if(cmd == "M?")
+ {
+ ssend << "Motor[" << 0 << "][" << "STOP" << "]";
+ }
+ else if(cmd == "TRIG?")
+ {
+ ssend << "Trigger(" << 0 << ")(" << NAN << "V)";
+ }
+ else if(cmd == "TARG?")
+ {
+ ssend << "Target[" << 0 << "](" << 4294967295 << ")[" << 0 << "]{" << 0 << "}";
+ }
+ else if(cmd == "POS?")
+ {
+ ssend << "Position[" << 0 << "][" << "UNKNOWN" << "](" << 4294967295 << ")";
+ }
+ else if(cmd.find("?")!=string::npos) ssend << "incorrect requeste [" << cmd << "]";
+ }
+ if(!ssend.str().empty()) ssend << "\n";
+ pc.write(ssend.str().c_str(), ssend.str().length());
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Thu Jul 30 12:57:09 2020 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#a2ada74770f043aff3e61e29d164a8e78274fcd4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json Thu Jul 30 12:57:09 2020 +0000
@@ -0,0 +1,7 @@
+{
+ "target_overrides": {
+ "*": {
+ "target.printf_lib": "std"
+ }
+ }
+}
\ No newline at end of file