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.
Diff: Bcon.cpp
- Revision:
- 0:4e42396b06ed
diff -r 000000000000 -r 4e42396b06ed Bcon.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Bcon.cpp Sat Oct 16 12:39:09 2021 +0000
@@ -0,0 +1,39 @@
+/**
+ * @file Bcon.cpp
+ * @brief Bcontroller送信用FEPライブラリ
+ * @author 安澤瑠
+ * @date 21/10/15
+ */
+#include "Bcon.h"
+
+Bcon::Bcon(PinName tx, PinName rx, uint8_t addr_, int baud) :
+ RawSerial(tx, rx, baud)
+{
+ addr = addr_;
+}
+
+int8_t Bcon::SendData(uint8_t *data)
+{
+ uint8_t sendindex; // index of 'data'
+ printf("@TBN%03d%03d", addr, DATANUM); // send comand
+ for (sendindex=0; sendindex<DATANUM; sendindex++) {
+ putc(data[sendindex]); //
+ }
+ printf("\r\n"); // <cr><lf>
+ return GetResponse(); // check response
+}
+
+int8_t Bcon::GetResponse()
+{
+ char res[256]; // array of storing response
+ for (uint8_t resindex=0; resindex<256; resindex++) {
+ res[resindex] = getc();
+ if (!strncmp(res+resindex-1, "\r\n", 2)) {
+ if (!strncmp(res+resindex-3, "P0", 2)) return 0;
+ else if (!strncmp(res+resindex-3, "N0", 2)) return 2;
+ else if (!strncmp(res+resindex-3, "N1", 2)) return 3;
+ else if (!strncmp(res+resindex-3, "N3", 2)) return 4;
+ }
+ }
+ return -1;
+}
\ No newline at end of file