From 481464d9fcf42026eb495c9c2e32222f0b4b89ce Mon Sep 17 00:00:00 2001 From: RyosukeSasaki Date: Thu, 19 Sep 2019 19:01:03 +0900 Subject: [PATCH 01/11] add pipfile --- Pipfile | 12 ++++++++++++ Pipfile.lock | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 Pipfile create mode 100644 Pipfile.lock diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..37a14c7 --- /dev/null +++ b/Pipfile @@ -0,0 +1,12 @@ +[[source]] +url = "https://pypi.python.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +pigpio = "*" + +[dev-packages] + +[requires] +python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..dcf1a88 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,29 @@ +{ + "_meta": { + "hash": { + "sha256": "b2a6001e701d68485834e2f5423cc0462d40e0a4eba13091a13e22529a2aa3c1" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.7" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.python.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "pigpio": { + "hashes": [ + "sha256:c53c155fac05f855657c794f533cb128a516d041d6560e0fb0ead5247a7ac2fe", + "sha256:df5e430e5c026c95f575cb50ccd18eb37d41be4e0bbbde070ab332dae27fdf58" + ], + "index": "pypi", + "version": "==1.44" + } + }, + "develop": {} +} From 39bf9828c3f2a4ab7c5ac88f64c8a0628e4d01d4 Mon Sep 17 00:00:00 2001 From: RyosukeSasaki Date: Thu, 19 Sep 2019 19:26:11 +0900 Subject: [PATCH 02/11] bit bang uart test --- raspberry_pi/bb_UART/bb_uart_test.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 raspberry_pi/bb_UART/bb_uart_test.py diff --git a/raspberry_pi/bb_UART/bb_uart_test.py b/raspberry_pi/bb_UART/bb_uart_test.py new file mode 100644 index 0000000..5838c72 --- /dev/null +++ b/raspberry_pi/bb_UART/bb_uart_test.py @@ -0,0 +1,11 @@ +import pigpio + +pi = pigpio.pi() +try: + status = pi.bb_serial_read_open(17, 9600) + while True: + count, data = pi.bb_serial_read(17) + print(data) + +finally: + pi.bb_serial_read_close(17) From dada4716f108672676c84f55f870326a0e921d6d Mon Sep 17 00:00:00 2001 From: RyosukeSasaki Date: Thu, 19 Sep 2019 19:34:31 +0900 Subject: [PATCH 03/11] mod --- raspberry_pi/bb_UART/bb_uart_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raspberry_pi/bb_UART/bb_uart_test.py b/raspberry_pi/bb_UART/bb_uart_test.py index 5838c72..a8c9095 100644 --- a/raspberry_pi/bb_UART/bb_uart_test.py +++ b/raspberry_pi/bb_UART/bb_uart_test.py @@ -5,7 +5,7 @@ status = pi.bb_serial_read_open(17, 9600) while True: count, data = pi.bb_serial_read(17) - print(data) + print(count) finally: pi.bb_serial_read_close(17) From db24362324443b5eb7810ed178a3d646f3102870 Mon Sep 17 00:00:00 2001 From: RyosukeSasaki Date: Thu, 19 Sep 2019 19:37:21 +0900 Subject: [PATCH 04/11] mod --- raspberry_pi/bb_UART/bb_uart_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raspberry_pi/bb_UART/bb_uart_test.py b/raspberry_pi/bb_UART/bb_uart_test.py index a8c9095..e0aa8c7 100644 --- a/raspberry_pi/bb_UART/bb_uart_test.py +++ b/raspberry_pi/bb_UART/bb_uart_test.py @@ -5,7 +5,7 @@ status = pi.bb_serial_read_open(17, 9600) while True: count, data = pi.bb_serial_read(17) - print(count) + print(count, end="") finally: pi.bb_serial_read_close(17) From 85098fc50a790a93bcaff6545c55402c3d0f9ffb Mon Sep 17 00:00:00 2001 From: RyosukeSasaki Date: Thu, 19 Sep 2019 19:41:07 +0900 Subject: [PATCH 05/11] modify --- raspberry_pi/bb_UART/bb_uart_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raspberry_pi/bb_UART/bb_uart_test.py b/raspberry_pi/bb_UART/bb_uart_test.py index e0aa8c7..4b04c42 100644 --- a/raspberry_pi/bb_UART/bb_uart_test.py +++ b/raspberry_pi/bb_UART/bb_uart_test.py @@ -5,7 +5,7 @@ status = pi.bb_serial_read_open(17, 9600) while True: count, data = pi.bb_serial_read(17) - print(count, end="") + print(data, end="") finally: pi.bb_serial_read_close(17) From fbcc7988227bd9ac5e772c9be724a2611af0504a Mon Sep 17 00:00:00 2001 From: RyosukeSasaki Date: Thu, 19 Sep 2019 19:54:19 +0900 Subject: [PATCH 06/11] format receiving data --- raspberry_pi/bb_UART/bb_uart_test.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/raspberry_pi/bb_UART/bb_uart_test.py b/raspberry_pi/bb_UART/bb_uart_test.py index 4b04c42..7e3126e 100644 --- a/raspberry_pi/bb_UART/bb_uart_test.py +++ b/raspberry_pi/bb_UART/bb_uart_test.py @@ -2,10 +2,17 @@ pi = pigpio.pi() try: + pi.bb_serial_read_close(17) status = pi.bb_serial_read_open(17, 9600) while True: - count, data = pi.bb_serial_read(17) - print(data, end="") + count = 1 + text = "" + while count: + count, data = pi.bb_serial_read(17) + if count: + text += data + time.sleep(0.01) + print(text) finally: pi.bb_serial_read_close(17) From 8c9f4df6fc197ba364251ee019d5b7ef5df76ea8 Mon Sep 17 00:00:00 2001 From: RyosukeSasaki Date: Thu, 19 Sep 2019 20:13:33 +0900 Subject: [PATCH 07/11] mod --- raspberry_pi/bb_UART/bb_uart_test.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/raspberry_pi/bb_UART/bb_uart_test.py b/raspberry_pi/bb_UART/bb_uart_test.py index 7e3126e..da71d47 100644 --- a/raspberry_pi/bb_UART/bb_uart_test.py +++ b/raspberry_pi/bb_UART/bb_uart_test.py @@ -5,14 +5,9 @@ pi.bb_serial_read_close(17) status = pi.bb_serial_read_open(17, 9600) while True: - count = 1 - text = "" + count, data = pi.bb_serial_read(17) while count: - count, data = pi.bb_serial_read(17) - if count: - text += data - time.sleep(0.01) - print(text) + print(data) finally: pi.bb_serial_read_close(17) From eecae637d48299d915283aa1a4bb10b46e4c86a6 Mon Sep 17 00:00:00 2001 From: RyosukeSasaki Date: Thu, 19 Sep 2019 20:14:06 +0900 Subject: [PATCH 08/11] modify pipfile --- Pipfile | 1 + Pipfile.lock | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/Pipfile b/Pipfile index 37a14c7..98bdc68 100644 --- a/Pipfile +++ b/Pipfile @@ -7,6 +7,7 @@ name = "pypi" pigpio = "*" [dev-packages] +pylint = "*" [requires] python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock index dcf1a88..688857e 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "b2a6001e701d68485834e2f5423cc0462d40e0a4eba13091a13e22529a2aa3c1" + "sha256": "34f89c847ad420c24df2cc885dc53c690713001eed8b62e3d1f2fc6c59511423" }, "pipfile-spec": 6, "requires": { @@ -25,5 +25,92 @@ "version": "==1.44" } }, - "develop": {} + "develop": { + "astroid": { + "hashes": [ + "sha256:6560e1e1749f68c64a4b5dee4e091fce798d2f0d84ebe638cf0e0585a343acf4", + "sha256:b65db1bbaac9f9f4d190199bb8680af6f6f84fd3769a5ea883df8a91fe68b4c4" + ], + "version": "==2.2.5" + }, + "isort": { + "hashes": [ + "sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1", + "sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd" + ], + "version": "==4.3.21" + }, + "lazy-object-proxy": { + "hashes": [ + "sha256:02b260c8deb80db09325b99edf62ae344ce9bc64d68b7a634410b8e9a568edbf", + "sha256:18f9c401083a4ba6e162355873f906315332ea7035803d0fd8166051e3d402e3", + "sha256:1f2c6209a8917c525c1e2b55a716135ca4658a3042b5122d4e3413a4030c26ce", + "sha256:2f06d97f0ca0f414f6b707c974aaf8829c2292c1c497642f63824119d770226f", + "sha256:616c94f8176808f4018b39f9638080ed86f96b55370b5a9463b2ee5c926f6c5f", + "sha256:63b91e30ef47ef68a30f0c3c278fbfe9822319c15f34b7538a829515b84ca2a0", + "sha256:77b454f03860b844f758c5d5c6e5f18d27de899a3db367f4af06bec2e6013a8e", + "sha256:83fe27ba321e4cfac466178606147d3c0aa18e8087507caec78ed5a966a64905", + "sha256:84742532d39f72df959d237912344d8a1764c2d03fe58beba96a87bfa11a76d8", + "sha256:874ebf3caaf55a020aeb08acead813baf5a305927a71ce88c9377970fe7ad3c2", + "sha256:9f5caf2c7436d44f3cec97c2fa7791f8a675170badbfa86e1992ca1b84c37009", + "sha256:a0c8758d01fcdfe7ae8e4b4017b13552efa7f1197dd7358dc9da0576f9d0328a", + "sha256:a4def978d9d28cda2d960c279318d46b327632686d82b4917516c36d4c274512", + "sha256:ad4f4be843dace866af5fc142509e9b9817ca0c59342fdb176ab6ad552c927f5", + "sha256:ae33dd198f772f714420c5ab698ff05ff900150486c648d29951e9c70694338e", + "sha256:b4a2b782b8a8c5522ad35c93e04d60e2ba7f7dcb9271ec8e8c3e08239be6c7b4", + "sha256:c462eb33f6abca3b34cdedbe84d761f31a60b814e173b98ede3c81bb48967c4f", + "sha256:fd135b8d35dfdcdb984828c84d695937e58cc5f49e1c854eb311c4d6aa03f4f1" + ], + "version": "==1.4.2" + }, + "mccabe": { + "hashes": [ + "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", + "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f" + ], + "version": "==0.6.1" + }, + "pylint": { + "hashes": [ + "sha256:5d77031694a5fb97ea95e828c8d10fc770a1df6eb3906067aaed42201a8a6a09", + "sha256:723e3db49555abaf9bf79dc474c6b9e2935ad82230b10c1138a71ea41ac0fff1" + ], + "index": "pypi", + "version": "==2.3.1" + }, + "six": { + "hashes": [ + "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", + "sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73" + ], + "version": "==1.12.0" + }, + "typed-ast": { + "hashes": [ + "sha256:18511a0b3e7922276346bcb47e2ef9f38fb90fd31cb9223eed42c85d1312344e", + "sha256:262c247a82d005e43b5b7f69aff746370538e176131c32dda9cb0f324d27141e", + "sha256:2b907eb046d049bcd9892e3076c7a6456c93a25bebfe554e931620c90e6a25b0", + "sha256:354c16e5babd09f5cb0ee000d54cfa38401d8b8891eefa878ac772f827181a3c", + "sha256:4e0b70c6fc4d010f8107726af5fd37921b666f5b31d9331f0bd24ad9a088e631", + "sha256:630968c5cdee51a11c05a30453f8cd65e0cc1d2ad0d9192819df9978984529f4", + "sha256:66480f95b8167c9c5c5c87f32cf437d585937970f3fc24386f313a4c97b44e34", + "sha256:71211d26ffd12d63a83e079ff258ac9d56a1376a25bc80b1cdcdf601b855b90b", + "sha256:95bd11af7eafc16e829af2d3df510cecfd4387f6453355188342c3e79a2ec87a", + "sha256:bc6c7d3fa1325a0c6613512a093bc2a2a15aeec350451cbdf9e1d4bffe3e3233", + "sha256:cc34a6f5b426748a507dd5d1de4c1978f2eb5626d51326e43280941206c209e1", + "sha256:d755f03c1e4a51e9b24d899561fec4ccaf51f210d52abdf8c07ee2849b212a36", + "sha256:d7c45933b1bdfaf9f36c579671fec15d25b06c8398f113dab64c18ed1adda01d", + "sha256:d896919306dd0aa22d0132f62a1b78d11aaf4c9fc5b3410d3c666b818191630a", + "sha256:ffde2fbfad571af120fcbfbbc61c72469e72f550d676c3342492a9dfdefb8f12" + ], + "markers": "implementation_name == 'cpython'", + "version": "==1.4.0" + }, + "wrapt": { + "hashes": [ + "sha256:565a021fd19419476b9362b05eeaa094178de64f8361e44468f9e9d7843901e1" + ], + "version": "==1.11.2" + } + } } From 8281eeee25648cd9727e8d28285d441b490a79e1 Mon Sep 17 00:00:00 2001 From: RyosukeSasaki Date: Sun, 22 Sep 2019 03:52:02 +0900 Subject: [PATCH 09/11] =?UTF-8?q?=E3=81=A8=E3=82=8A=E3=81=82=E3=81=88?= =?UTF-8?q?=E3=81=9A=E3=83=91=E3=82=B1=E3=83=83=E3=83=88=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- raspberry_pi/bb_UART/include/UART.hpp | 69 +++++++++++++++++++++++++++ raspberry_pi/bb_UART/src/UART.cpp | 47 ++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 raspberry_pi/bb_UART/include/UART.hpp create mode 100644 raspberry_pi/bb_UART/src/UART.cpp diff --git a/raspberry_pi/bb_UART/include/UART.hpp b/raspberry_pi/bb_UART/include/UART.hpp new file mode 100644 index 0000000..e8ac039 --- /dev/null +++ b/raspberry_pi/bb_UART/include/UART.hpp @@ -0,0 +1,69 @@ +#pragma once + +#include +#include +#include + +// +// packet +// +// name : bit +// header ACK : 11xxxxxx (x: sequence_num) +// data : 00xxxxxx (x: sequence_num) +// +// payload_size : xxxxxxxx +// +// hash : xxxxyyyy (x: header's hash, y: payload's hash) +// +// payload : xxxxxxxx +// : xxxxxxxx +// ~~~~~~~~ +// : xxxxxxxx +// + +namespace uart +{ + enum uart_err_t + { + UART_SUCCEEDED = 0, + UART_ERROR_UNKNOWN = -1, + UART_INIT_FAILED = -2, + UART_TRANSMIT_FAILED = -3, + UART_RECEIVE_FAILED = -4, + UART_HASH_NOT_MATCH = -5, + UART_BUFFER_OVER = -6 + }; + + struct uart_conf + { + int TX = -1; // TX pin + int RX = -1; // RX pin + int BAUD = 9600; + int DATA_BIT_LEN = 8; // bits + int MAX_PAYLOAD_SIZE= 32; // ペイロードサイズ(1-255bytes) + int STOP_BIT = 2; + int OFFSET = 0; + bool ENABLE_RESEND = true; // 再送 + }; + + class UART + { + private: + const uart_conf conf; + uint8_t sequence_num; + std::queue transmit_queue; + + public: + UART(uart_conf&); + virtual uart_err_t initialize(); + // パケット送信 + virtual int thrower(const uint8_t*); + // パケット作成→キュー追加 + template uart_err_t transmit(const T&); + virtual int receive(); + uart_err_t get_data(); + + }; + +} + diff --git a/raspberry_pi/bb_UART/src/UART.cpp b/raspberry_pi/bb_UART/src/UART.cpp new file mode 100644 index 0000000..86a724f --- /dev/null +++ b/raspberry_pi/bb_UART/src/UART.cpp @@ -0,0 +1,47 @@ +#include "UART.hpp" + +namespace uart +{ + UART::UART(uart_conf& conf_) : conf(conf_), sequence_num(0) {} + + template + uart_err_t UART::transmit(const T &buf_) + { + if (transmit_queue.size() + (int)sizeof(T) > 1024) { + return(UART_BUFFER_OVER); + + } else { + std::unique_ptr buf(new T(1)); + buf = (uint8_t*)&buf_; + + // キュー追加、dataサイズがペイロード最大サイズを超える場合は分割 + int j = 0; + for (int i=0; i<(float)sizeof(T)/conf.MAX_PAYLOAD_SIZE; i++) { + const uint8_t header = sequence_num & 0b00111111; + transmit_queue.push(header); + if (sequence_num == 63) { + sequence_num = 0; + } else { + sequence_num++; + } + for (j; j Date: Tue, 24 Sep 2019 19:22:50 +0900 Subject: [PATCH 10/11] create pdu --- raspberry_pi/bb_UART/include/UART.hpp | 46 ++++++++++----------- raspberry_pi/bb_UART/src/UART.cpp | 57 ++++++++++++++------------- 2 files changed, 54 insertions(+), 49 deletions(-) diff --git a/raspberry_pi/bb_UART/include/UART.hpp b/raspberry_pi/bb_UART/include/UART.hpp index e8ac039..478f940 100644 --- a/raspberry_pi/bb_UART/include/UART.hpp +++ b/raspberry_pi/bb_UART/include/UART.hpp @@ -3,23 +3,8 @@ #include #include #include - -// -// packet -// -// name : bit -// header ACK : 11xxxxxx (x: sequence_num) -// data : 00xxxxxx (x: sequence_num) -// -// payload_size : xxxxxxxx -// -// hash : xxxxyyyy (x: header's hash, y: payload's hash) -// -// payload : xxxxxxxx -// : xxxxxxxx -// ~~~~~~~~ -// : xxxxxxxx -// +#include +#include namespace uart { @@ -34,16 +19,32 @@ namespace uart UART_BUFFER_OVER = -6 }; + struct pdu + { + struct header + { + uint8_t seq_num; + uint8_t payload_size; + uint8_t checksum; + }; + struct data + { + uint8_t type; + uint8_t* data; + uint8_t checksum; + }; + }; + struct uart_conf { int TX = -1; // TX pin int RX = -1; // RX pin int BAUD = 9600; int DATA_BIT_LEN = 8; // bits - int MAX_PAYLOAD_SIZE= 32; // ペイロードサイズ(1-255bytes) int STOP_BIT = 2; int OFFSET = 0; bool ENABLE_RESEND = true; // 再送 + bool ENABLE_ECC = false; }; class UART @@ -52,14 +53,15 @@ namespace uart const uart_conf conf; uint8_t sequence_num; std::queue transmit_queue; + std::mutex lock; public: UART(uart_conf&); virtual uart_err_t initialize(); - // パケット送信 - virtual int thrower(const uint8_t*); - // パケット作成→キュー追加 - template uart_err_t transmit(const T&); + virtual int thrower(const char*); + // Generate Protocol Data Unit + template uart_err_t create_pdu(const char&, const T&); + template void calc_parity(char*, const T&, size_t&); virtual int receive(); uart_err_t get_data(); diff --git a/raspberry_pi/bb_UART/src/UART.cpp b/raspberry_pi/bb_UART/src/UART.cpp index 86a724f..c122b9c 100644 --- a/raspberry_pi/bb_UART/src/UART.cpp +++ b/raspberry_pi/bb_UART/src/UART.cpp @@ -5,37 +5,40 @@ namespace uart UART::UART(uart_conf& conf_) : conf(conf_), sequence_num(0) {} template - uart_err_t UART::transmit(const T &buf_) + uart_err_t UART::create_pdu(const char &type, const T &data_) { - if (transmit_queue.size() + (int)sizeof(T) > 1024) { - return(UART_BUFFER_OVER); + size_t size = sizeof(T) + std::unique_ptr buf(new pdu); - } else { - std::unique_ptr buf(new T(1)); - buf = (uint8_t*)&buf_; - - // キュー追加、dataサイズがペイロード最大サイズを超える場合は分割 - int j = 0; - for (int i=0; i<(float)sizeof(T)/conf.MAX_PAYLOAD_SIZE; i++) { - const uint8_t header = sequence_num & 0b00111111; - transmit_queue.push(header); - if (sequence_num == 63) { - sequence_num = 0; - } else { - sequence_num++; - } - for (j; j + void UART::calc_parity(char* buf, const T &data_, size_t &size) + { } From 38f96131b80bca99f0eedaa48fa772bb0b9cf74b Mon Sep 17 00:00:00 2001 From: Naoki Yano Date: Wed, 25 Sep 2019 16:36:07 +0900 Subject: [PATCH 11/11] =?UTF-8?q?:truck:=E3=83=87=E3=82=A3=E3=83=AC?= =?UTF-8?q?=E3=82=AF=E3=83=88=E3=83=AA=E3=81=AE=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {raspberry_pi => share}/bb_UART/bb_uart_test.py | 0 {raspberry_pi => share}/bb_UART/include/UART.hpp | 0 {raspberry_pi => share}/bb_UART/src/UART.cpp | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {raspberry_pi => share}/bb_UART/bb_uart_test.py (100%) rename {raspberry_pi => share}/bb_UART/include/UART.hpp (100%) rename {raspberry_pi => share}/bb_UART/src/UART.cpp (100%) diff --git a/raspberry_pi/bb_UART/bb_uart_test.py b/share/bb_UART/bb_uart_test.py similarity index 100% rename from raspberry_pi/bb_UART/bb_uart_test.py rename to share/bb_UART/bb_uart_test.py diff --git a/raspberry_pi/bb_UART/include/UART.hpp b/share/bb_UART/include/UART.hpp similarity index 100% rename from raspberry_pi/bb_UART/include/UART.hpp rename to share/bb_UART/include/UART.hpp diff --git a/raspberry_pi/bb_UART/src/UART.cpp b/share/bb_UART/src/UART.cpp similarity index 100% rename from raspberry_pi/bb_UART/src/UART.cpp rename to share/bb_UART/src/UART.cpp