From a9c42d32e23ad60de55e901a7ef4bd97c86806f9 Mon Sep 17 00:00:00 2001 From: Nedved SIMAO <109746899+NedSimao@users.noreply.github.com> Date: Wed, 7 Jun 2023 22:00:34 +0200 Subject: [PATCH 01/11] [WIP] Few functions have been implemented; now we need to perform few tests --- .DS_Store | Bin 0 -> 6148 bytes StreamBufferedChannel.ino | 29 ++++++++ src/StreamChannel.cpp | 142 ++++++++++++++++++++++++++++++++++++++ src/StreamChannel.h | 38 ++++++++++ 4 files changed, 209 insertions(+) create mode 100644 .DS_Store create mode 100644 StreamBufferedChannel.ino create mode 100644 src/StreamChannel.cpp create mode 100644 src/StreamChannel.h diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7f240fea7cd76ce717e901b1096db389fed2c316 GIT binary patch literal 6148 zcmeHK!EVz)5S>i|I6JyOzW$g6OoFY8VdO}*p z!-Ilr$WfHZ2t6)m#WG+S_}3ZWcehP3NgC~CwfA=$BOBk9s7Z9`DeclW4e2p(gN`U} zWPE94w5gzJv#z*(dQ>zoCT8{c8cnjaCcD% zm)v_2mgC6S&!o(L*8`(UQ)n@};E9Z^@^W-|0&)qM#KiD#08Tiu-@cQ6F89jrQ zMzwUHQAYq^2W};>)yF^3We3nRSZRa@B6KQHrwVh#5a#S4bUMa86JKf6=_J&hQODd_ zm=lUHM-Snua1x$I+gb)J19b-4y4&adfA{z2|9X<`Sq3Zv{}ltGGYp14reyZk6O-e; u)`cEISvaoJs8Z0F?N}MS72kv^!I;Yi&@)(Rga=|j1QZRnu?+lG27Ul52&6{< literal 0 HcmV?d00001 diff --git a/StreamBufferedChannel.ino b/StreamBufferedChannel.ino new file mode 100644 index 0000000..8ee105f --- /dev/null +++ b/StreamBufferedChannel.ino @@ -0,0 +1,29 @@ +#include "src/StreamChannel.h" + +#define SIZE 3 +uint16_t DATA[SIZE]={200, 128,150}; + + +StreamBuffer Channel; + +void setup() { +// put your setup code here, to run once: +Serial.begin(9600); +Channel.setMaxChannelNumber((uint8_t) SIZE); +} + +void loop() { +// put your main code here, to run repeatedly: +Channel.appendChannelArray(DATA,SIZE); + + + +//Channel.transmitBufferAscii(Serial, "\t"); +//Channel.transmitBufferBinaryRaw8(Serial); +//Channel.transmitBufferBinaryRaw16(Serial); +//Channel.sendBufferAsciiTimeStamp(Serial, 12,"\t"); +//Channel.sendBufferBinaryTimeStamp(Serial, 12); + +delay(100); + +} diff --git a/src/StreamChannel.cpp b/src/StreamChannel.cpp new file mode 100644 index 0000000..22432d8 --- /dev/null +++ b/src/StreamChannel.cpp @@ -0,0 +1,142 @@ +#include "StreamChannel.h" + + + +boolean StreamBuffer::isFull(){ + + return (_currentIndex==_definedSize); +} + + +StreamBuffer::StreamBuffer(){ + _definedSize=0; + _currentIndex=0; +} + + +void StreamBuffer::setMaxChannelNumber(uint8_t channelNo){ + _definedSize=channelNo; + + _buffer=new uint16_t[_definedSize]; + _lsbBuffer=new uint8_t[_definedSize]; + _msbBuffer=new uint8_t[_definedSize]; + + for (uint8_t i=0; i<_definedSize; i++){ + _buffer[i]=0; + _lsbBuffer[i]=0; + _msbBuffer[i]=0; + + } + + +} + + +void StreamBuffer::appendChannelData(uint16_t data){ + _currentIndex=_currentIndex%_definedSize; //set the _currentIndex to 0 when the buffer if full and this function is called to append a new data + + *(_buffer+_currentIndex)=data; + _currentIndex++; + + +} + +void StreamBuffer::Flush(){ + _currentIndex=0; + for (uint8_t i=0; i<_definedSize; i++) _buffer[i]=0; + +} + + +void StreamBuffer::appendChannelArray(uint16_t *dataSet, uint8_t arraySize){ + //the buffer is reset + Flush(); + +if((arraySize<=_definedSize)&&(arraySize>0)){ + //fill the buffer with this datSet + for (uint8_t i=0; iappendChannelData(dataSet[i]); + } + +}else if (arraySize>_definedSize){ + //drop other packets + for (uint8_t i=0; i<_definedSize;i++){ + this->appendChannelData(dataSet[i]); + } + + +}else{ + //dont do anything if the array size if less thant 0 + +} + + +} + + +void StreamBuffer::transmitBufferAscii(Stream &stream, String sepCar){ + +for (uint8_t i=0; i<_currentIndex; i++){ + + stream.print(_buffer[i]); + stream.print(sepCar); +} +stream.println(); + + +} + + +void StreamBuffer::transmitBufferBinaryRaw8(Stream &stream){ +for(uint8_t i=0; i<_currentIndex; i++){ + _lsbBuffer[i]=(_buffer[i] & 0xFF); + _msbBuffer[i]=(_buffer[i] >> 8) & 0xFF; +} + +String header="#"+ String(String(_currentIndex).length())+String(_currentIndex*sizeof(uint8_t)); +//Send MSB AS FIRST PACKET +stream.print(header); +stream.write((uint8_t *) _msbBuffer,_currentIndex*sizeof(uint8_t)); // Send the upper byte first +stream.println(); + +//Send LSB AS SECOND PACKET +stream.print(header); +stream.write((uint8_t *) _lsbBuffer ,_currentIndex*sizeof(uint8_t)); // Send the lower byte +stream.println(); + +} + + +void StreamBuffer::transmitBufferBinaryRaw16(Stream &stream){ + +String header="#"+ String(String(_currentIndex).length())+String(_currentIndex*sizeof(uint8_t)); +stream.print(header); +stream.write((char *) _buffer, (_currentIndex)*sizeof(uint16_t)); + + +} + + +void StreamBuffer::sendBufferAsciiTimeStamp(Stream &stream, unsigned long timeStamp, String sepCar){ +stream.print(timeStamp); +stream.print(sepCar); +this->transmitBufferAscii(stream,sepCar); + +} + + +void StreamBuffer::sendBufferBinaryTimeStamp(Stream &stream, unsigned long timeStamp){ +String header="#"+ String(String(_currentIndex).length())+String(_currentIndex*sizeof(uint8_t)+sizeof(unsigned long)); + +stream.print(header); +stream.write((char *) timeStamp, sizeof(unsigned long)); +stream.write((char *) _buffer, (_currentIndex)*sizeof(uint16_t)); + +} + + +StreamBuffer::~StreamBuffer(){ + delete[] _buffer; + delete[] _lsbBuffer; + delete[] _msbBuffer; +} diff --git a/src/StreamChannel.h b/src/StreamChannel.h new file mode 100644 index 0000000..786d694 --- /dev/null +++ b/src/StreamChannel.h @@ -0,0 +1,38 @@ +#ifndef _STREAMCHANNEL_H_ +#define _STREAMCHANNEL_H_ + +#include +#include + +class StreamBuffer{ + +private: + //Declaring variables being used betwween the functions + uint16_t *_buffer; + uint8_t *_lsbBuffer; + uint8_t *_msbBuffer; + uint8_t _definedSize; + uint8_t _currentIndex; + +private: + boolean isFull(); + +public: + //Declaring API to be implemented and used afterword + StreamBuffer(); + void setMaxChannelNumber(uint8_t channelNo=3); //Allocate a buffer of 8 bit long + void appendChannelData(uint16_t); //insert the value from one channel to the BufferChannelQueue + void appendChannelArray(uint16_t *, uint8_t); //add an array with values from each channels + void transmitBufferAscii(Stream &stream, String sepCar=";"); + void transmitBufferBinaryRaw8(Stream &stream); + void transmitBufferBinaryRaw16(Stream &stream); + void sendBufferAsciiTimeStamp(Stream &stream, unsigned long, String sepCar=";"); + void sendBufferBinaryTimeStamp(Stream &stream, unsigned long); + void Flush(); + ~StreamBuffer(); + +}; + +extern StreamBuffer StreamChannel; + +#endif /*STREAMCHANNEL_H*/ \ No newline at end of file From ef5277ca0053b26a029b50a5531ff95630cfb8c2 Mon Sep 17 00:00:00 2001 From: Nedved SIMAO <109746899+NedSimao@users.noreply.github.com> Date: Wed, 7 Jun 2023 22:11:58 +0200 Subject: [PATCH 02/11] [WIP] Branch examples created --- .DS_Store | Bin 6148 -> 6148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.DS_Store b/.DS_Store index 7f240fea7cd76ce717e901b1096db389fed2c316..4777b1952fc981f74fac6cde10422bd2464fa7c6 100644 GIT binary patch delta 264 zcmZoMXfc@J&&azmU^g=(?_?ep$$EbV1_r(VU;tz>FmN!WGE^`mGUPH8FysK)#hy9& z$w@i+NkBOPAa(@et@zaEq#Fh&=jRpx)xiLUnYsBcE)X+A7&tDUx>MOJaTH`Q7KJHL uh4|GKWFT8Q*?>izaqr|h7O}~BEc}exo9kGd85!4ZKEztfxS5^fFFyb>X-3xo delta 66 zcmZoMXfc@J&&aVcU^g=($7CKBNp4351_r(VU@-Xyi#p@_$qKBhjIuydY;z2&E+gao S&0TD@j1wD9Y-Z>9%MSqP-4? Date: Wed, 7 Jun 2023 23:07:07 +0200 Subject: [PATCH 03/11] [WIP] Creation of 6 sketches for each function implemented in the microcontroller --- .DS_Store | Bin 6148 -> 6148 bytes StreamBufferedChannel.ino | 4 ++-- StreamChannel/.DS_Store | Bin 0 -> 6148 bytes {src => StreamChannel}/StreamChannel.cpp | 8 +++++--- .../StreamChannel.hpp | 13 ++++++------- examples/.DS_Store | Bin 0 -> 8196 bytes examples/TestBufferAscii/TestBufferAscii.ino | 7 +++++++ .../TestBufferAsciiTime.ino | 7 +++++++ .../TestBufferBinary16bits.ino | 7 +++++++ .../TestBufferBinary16bitsTime.ino | 7 +++++++ .../TestBufferBinary8bits.ino | 7 +++++++ .../TestBufferBinary8bitsTime.ino | 7 +++++++ 12 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 StreamChannel/.DS_Store rename {src => StreamChannel}/StreamChannel.cpp (96%) rename src/StreamChannel.h => StreamChannel/StreamChannel.hpp (87%) create mode 100644 examples/.DS_Store create mode 100644 examples/TestBufferAscii/TestBufferAscii.ino create mode 100644 examples/TestBufferAsciiTime/TestBufferAsciiTime.ino create mode 100644 examples/TestBufferBinary16bits/TestBufferBinary16bits.ino create mode 100644 examples/TestBufferBinary16bitsTime/TestBufferBinary16bitsTime.ino create mode 100644 examples/TestBufferBinary8bits/TestBufferBinary8bits.ino create mode 100644 examples/TestBufferBinary8bitsTime/TestBufferBinary8bitsTime.ino diff --git a/.DS_Store b/.DS_Store index 4777b1952fc981f74fac6cde10422bd2464fa7c6..da113b9ed2edae2b5d401f8790ae2f19dccd9c16 100644 GIT binary patch delta 288 zcmZoMXffEJ%ED^Rz`&q2S&K!RbqbKB31rFeB$XEzB<18M0R>J>&R}iO5U;K_F*4Ip zu&}JvQK+^wGSE>lH#DuS<>U}oHMI3i$gQlZuBok?F`17|o^j^nB$nBeJ6QyI%7TmX za`N-if#xty{>7rg#~2P|>i-7=28PKlY_5V=fFfEj5g?m)@*OrQ1<#!PWT*=SfP(LV vSO;AZvNKPDoT({MU2SM?p`&1EY=qaHGePcTodvTE#hnuiwKlVJ{N)D#5+YXo delta 291 zcmZoMXffEJ%EIc;z`&q4S&K!R)e*?r3S`Mlj$>_~%*v+d#jqD7`5z2`ECvQy zhGfs2{N$vZ{3M`=00RS~Hju`mDyh7<0IKTPM8XF_geRdr2m-L%PCtn%X15tfw&7v<&T=cNNh7$=*sxeBfYvUHIgB{;c@ vO-h47k0F_%fS~}@ZA_U!#q*IA^Me%20TpMUDFm4h^~A)&&zspf{_+C=Cc#%O diff --git a/StreamBufferedChannel.ino b/StreamBufferedChannel.ino index 8ee105f..d303941 100644 --- a/StreamBufferedChannel.ino +++ b/StreamBufferedChannel.ino @@ -1,4 +1,4 @@ -#include "src/StreamChannel.h" +#include #define SIZE 3 uint16_t DATA[SIZE]={200, 128,150}; @@ -18,7 +18,7 @@ Channel.appendChannelArray(DATA,SIZE); -//Channel.transmitBufferAscii(Serial, "\t"); +Channel.transmitBufferAscii(Serial, "\t"); //Channel.transmitBufferBinaryRaw8(Serial); //Channel.transmitBufferBinaryRaw16(Serial); //Channel.sendBufferAsciiTimeStamp(Serial, 12,"\t"); diff --git a/StreamChannel/.DS_Store b/StreamChannel/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..72d6c8ae65dc55a6a6515296fa7a922f3237d1d2 GIT binary patch literal 6148 zcmeH~u};H442FM0he|AEW4tG*#2Xx?49tB2XhC8KZG~XZ*2gZt?E?`7Bqj#*Tk`#P zj-5-sAYKm>kIz^sm9US5aK%Fog#(A72sKo=++O$t)gl1Vv%~ESe49jxHOUtWG`_wFl#m>A> z+u7O)#bS5HOQgeUszwnIfgyp@T+Y1z-_UPNu2$VA{T2)qNOp&eZS literal 0 HcmV?d00001 diff --git a/src/StreamChannel.cpp b/StreamChannel/StreamChannel.cpp similarity index 96% rename from src/StreamChannel.cpp rename to StreamChannel/StreamChannel.cpp index 22432d8..286cf48 100644 --- a/src/StreamChannel.cpp +++ b/StreamChannel/StreamChannel.cpp @@ -1,10 +1,12 @@ -#include "StreamChannel.h" +#include "StreamChannel.hpp" -boolean StreamBuffer::isFull(){ +bool StreamBuffer::isFull(){ + + + return ((_currentIndex==_definedSize)? true:false); - return (_currentIndex==_definedSize); } diff --git a/src/StreamChannel.h b/StreamChannel/StreamChannel.hpp similarity index 87% rename from src/StreamChannel.h rename to StreamChannel/StreamChannel.hpp index 786d694..d9bc8eb 100644 --- a/src/StreamChannel.h +++ b/StreamChannel/StreamChannel.hpp @@ -1,5 +1,5 @@ -#ifndef _STREAMCHANNEL_H_ -#define _STREAMCHANNEL_H_ +#ifndef _STREAMCHANNEL_HPP_ +#define _STREAMCHANNEL_HPP_ #include #include @@ -13,9 +13,8 @@ class StreamBuffer{ uint8_t *_msbBuffer; uint8_t _definedSize; uint8_t _currentIndex; - -private: - boolean isFull(); + + bool isFull(); public: //Declaring API to be implemented and used afterword @@ -33,6 +32,6 @@ class StreamBuffer{ }; -extern StreamBuffer StreamChannel; +//extern StreamBuffer StreamChannel; -#endif /*STREAMCHANNEL_H*/ \ No newline at end of file +#endif /*STREAMCHANNEL_H*/ diff --git a/examples/.DS_Store b/examples/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9e3e61687793e076ade7359ee9d1df8085014ef3 GIT binary patch literal 8196 zcmeHM%Wl&^6ur|1aDq@H@rsa;ykQrixCmMnNUkZ1?vNb80#Iu=hFWs%Dt3rU2=bmU zfS=$y_yWF#6`Xlc5ho#ar9x!pMl)wJbI*-^uI%x3h=@6Zo<-CmA_I+M^D?>_#@Bh9 zvK2M624vt9IW(Zx_yp9S^41et0j+>mKr5gX&VHl$h5FAsXtuU7;sE8@62d1b@l^9IYv2JpApsg^MDCxu` zotXM%rYaOBejPkhxD&G_>Rv0L6_{3l*Y0c7Ma7;{Hc`KCVP>B~3U{Jp-;WX>p8Vq4 zLc9Az7)A@({xCgK?63Y&6sB3H^Np>n)-GJUWEc&jai#IfJxGRb=4FG_@%k_Lx2Ilq z;Hz;rNuran=RXUB;coNV<0Q_!Fb?{H9QFdZynG(Uy=3SlgSeN9IIdhUjJi?ZZMH@u zYh$x*TKCq+ZFBT+z0)=~to!3}-MD$jdbG25c>Heke*EE+I5A@CUIT$9?epT(e(Uz* zD2d;|lSjGwXNj>I(jf%}slR~vyVR$QQdP-MdHMzEZ_Je5f#5NDcu#dq7Cj&z-!n=l z6Tm(e5>P5uRnt&PghDcIl}X0ztAc$mB;`yotD2lMiBU+>^@T~=oO8Y0E~KVJq^c&Q zgam~&K+E&BRT;j;>;EV7-~XTQLFnjO0j Date: Wed, 7 Jun 2023 23:20:18 +0200 Subject: [PATCH 04/11] [WIP] Definition and implementation of the sketches --- .DS_Store | Bin 6148 -> 6148 bytes examples/.DS_Store | Bin 8196 -> 10244 bytes examples/TestBufferAscii/TestBufferAscii.ino | 14 +++++++-- .../TestBufferAsciiTime.ino | 28 +++++++++++++++++- .../TestBufferBinary16bits.ino | 14 ++++++++- .../TestBufferBinary16bitsTime.ino | 25 +++++++++++++++- .../TestBufferBinary8bits.ino | 14 ++++++++- .../TestBufferBinary8bitsTime.ino | 15 +++++++++- 8 files changed, 103 insertions(+), 7 deletions(-) diff --git a/.DS_Store b/.DS_Store index da113b9ed2edae2b5d401f8790ae2f19dccd9c16..79e17c21c7d2513a585582a0fc7f6ca5456a9864 100644 GIT binary patch delta 19 acmZoMXffEp#>!@Cp`&1Fu$hPThY$cW&IKL- delta 19 acmZoMXffEp#>!@7rlVkCxtWLchY$cWoCO^K diff --git a/examples/.DS_Store b/examples/.DS_Store index 9e3e61687793e076ade7359ee9d1df8085014ef3..0f1741337bc68ffd716b21df8ed5eea6f26ed50b 100644 GIT binary patch delta 533 zcmZp1XbF&DU|?W$DortDU{C-uIe-{M3-C-V6q~50$SAZiU^hRb&}2tJrOA2%o{T3Z zFA!_s60fc{v9!=pur!$bS6G&D#$-i7dB&MQMJw?u$QRU_d{1aH9!0D(fwqfHRuEI1 zoFKA}kU}Z2!Ve2MoFL+t;x$p#DtjAfmZ4L2Lm9BfdMQf z!Vtoc$&kyCnp9p~kd%|31eCz-X|Qu4MskRWPhKXTxUnIfO^_LE9)kimkah)y=ElPB z%#-Jf%(7UM&#SA43P7I|CX$)xqt9Fg$ delta 400 zcmZn(XmOBWU|?W$DortDU;r^WfEYvza8E20o2aMA$iFdQH$Nl)WCuZ|$$A2wj3*}- z2sdy`R973CTj(el8XHaCBO%K;bFzY?_ k2@8hF@jTN6GZ}IjQj^My3zBm3lYmO`1OnLc + +#define SIZE 3 +uint16_t DATA[SIZE]={200, 128,150}; + +StreamBuffer Channel; + +void setup() { +Serial.begin(9600); +Channel.setMaxChannelNumber((uint8_t) SIZE); } void loop() { - +Channel.appendChannelArray(DATA,SIZE); +Channel.transmitBufferAscii(Serial, "\t"); } diff --git a/examples/TestBufferAsciiTime/TestBufferAsciiTime.ino b/examples/TestBufferAsciiTime/TestBufferAsciiTime.ino index 32f56ba..9ba554d 100644 --- a/examples/TestBufferAsciiTime/TestBufferAsciiTime.ino +++ b/examples/TestBufferAsciiTime/TestBufferAsciiTime.ino @@ -1,7 +1,33 @@ -void setup() { +#include + +#define SIZE 3 +uint16_t DATA[SIZE]={200, 128,150}; + +unsigned long previousTime = 0; +StreamBuffer Channel; + +void setup() { +// put your setup code here, to run once: +Serial.begin(9600); +Channel.setMaxChannelNumber((uint8_t) SIZE); } void loop() { + /* Updates frequently */ + previousTime = millis(); + + Channel.appendChannelArray(DATA,SIZE); + + unsigned long currentTime = millis(); + + Channel.sendBufferAsciiTimeStamp(Serial, (currentTime - previousTime),"\t"); + + /* Update the timing for the next time around */ + previousTime = currentTime; + + } + + diff --git a/examples/TestBufferBinary16bits/TestBufferBinary16bits.ino b/examples/TestBufferBinary16bits/TestBufferBinary16bits.ino index 32f56ba..bee74bf 100644 --- a/examples/TestBufferBinary16bits/TestBufferBinary16bits.ino +++ b/examples/TestBufferBinary16bits/TestBufferBinary16bits.ino @@ -1,7 +1,19 @@ -void setup() { +#include + +#define SIZE 3 +uint16_t DATA[SIZE]={200, 128,150}; + +StreamBuffer Channel; + +void setup() { +Serial.begin(9600); +Channel.setMaxChannelNumber((uint8_t) SIZE); } void loop() { +Channel.appendChannelArray(DATA,SIZE); +Channel.transmitBufferBinaryRaw16(Serial); + } diff --git a/examples/TestBufferBinary16bitsTime/TestBufferBinary16bitsTime.ino b/examples/TestBufferBinary16bitsTime/TestBufferBinary16bitsTime.ino index 32f56ba..1ff358e 100644 --- a/examples/TestBufferBinary16bitsTime/TestBufferBinary16bitsTime.ino +++ b/examples/TestBufferBinary16bitsTime/TestBufferBinary16bitsTime.ino @@ -1,7 +1,30 @@ -void setup() { +#include + +#define SIZE 3 +uint16_t DATA[SIZE]={200, 128,150}; + + +StreamBuffer Channel; +void setup() { +Serial.begin(9600); +Channel.setMaxChannelNumber((uint8_t) SIZE); } void loop() { + Channel.appendChannelArray(DATA,SIZE); + + /* Updates frequently */ + previousTime = millis(); + + Channel.appendChannelArray(DATA,SIZE); + + unsigned long currentTime = millis(); + + Channel.sendBufferBinaryTimeStamp(Serial, (currentTime - previousTime)); + + /* Update the timing for the next time around */ + previousTime = currentTime; + } diff --git a/examples/TestBufferBinary8bits/TestBufferBinary8bits.ino b/examples/TestBufferBinary8bits/TestBufferBinary8bits.ino index 32f56ba..df6a93b 100644 --- a/examples/TestBufferBinary8bits/TestBufferBinary8bits.ino +++ b/examples/TestBufferBinary8bits/TestBufferBinary8bits.ino @@ -1,7 +1,19 @@ -void setup() { +#include + +#define SIZE 3 +uint16_t DATA[SIZE]={200, 128,150}; + +StreamBuffer Channel; + +void setup() { +Serial.begin(9600); +Channel.setMaxChannelNumber((uint8_t) SIZE); } void loop() { +Channel.appendChannelArray(DATA,SIZE); + +Channel.transmitBufferBinaryRaw8(Serial); } diff --git a/examples/TestBufferBinary8bitsTime/TestBufferBinary8bitsTime.ino b/examples/TestBufferBinary8bitsTime/TestBufferBinary8bitsTime.ino index 32f56ba..50ed8e3 100644 --- a/examples/TestBufferBinary8bitsTime/TestBufferBinary8bitsTime.ino +++ b/examples/TestBufferBinary8bitsTime/TestBufferBinary8bitsTime.ino @@ -1,7 +1,20 @@ -void setup() { +#include + +#define SIZE 3 +uint16_t DATA[SIZE]={200, 128,150}; + +StreamBuffer Channel; + +void setup() { +// put your setup code here, to run once: +Serial.begin(9600); +Channel.setMaxChannelNumber((uint8_t) SIZE); } void loop() { +// put your main code here, to run repeatedly: +Channel.appendChannelArray(DATA,SIZE); + } From b065b006a2b493308548bcd5806102d37ff4530c Mon Sep 17 00:00:00 2001 From: Nedved SIMAO <109746899+NedSimao@users.noreply.github.com> Date: Thu, 8 Jun 2023 00:11:33 +0200 Subject: [PATCH 05/11] [WIP] Changes in one sketch file --- .../TestBufferBinary16bitsTime/TestBufferBinary16bitsTime.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/TestBufferBinary16bitsTime/TestBufferBinary16bitsTime.ino b/examples/TestBufferBinary16bitsTime/TestBufferBinary16bitsTime.ino index 1ff358e..bf9f060 100644 --- a/examples/TestBufferBinary16bitsTime/TestBufferBinary16bitsTime.ino +++ b/examples/TestBufferBinary16bitsTime/TestBufferBinary16bitsTime.ino @@ -2,7 +2,7 @@ #define SIZE 3 uint16_t DATA[SIZE]={200, 128,150}; - +unsigned long previousTime; StreamBuffer Channel; From d5d55d1dc8f68fd20d3a532df02a713164cceb06 Mon Sep 17 00:00:00 2001 From: Nedved SIMAO <109746899+NedSimao@users.noreply.github.com> Date: Thu, 8 Jun 2023 00:18:59 +0200 Subject: [PATCH 06/11] [WIP] --- PythonDriver/.DS_Store | Bin 0 -> 6148 bytes PythonDriver/module/ChannelBuffersSerial.py | 73 ++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 PythonDriver/.DS_Store create mode 100644 PythonDriver/module/ChannelBuffersSerial.py diff --git a/PythonDriver/.DS_Store b/PythonDriver/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..40057eca37ebbaaf95a07c3ed288177e762e1f9b GIT binary patch literal 6148 zcmeHK!Ab)$5S`SjX+`Wo&|@y%inO9=55ijY;7wT3gNp9DMHkkMv|EeT%6^9ak$>Rl z=uDCdrFv9UW?=GWCo|d2OGtJAKs38i9iRdL5|yw}!sZj9e$p{1IL`#4Fk>Xp+Dr6B znCNgUnjOE90b08$xCRXobYXP;Xj5#VF25NupFa{C_BuCitzW{MB<^Ij+N&r`6ep*q zr7X+xZ28o`(mg*5vTmmtw2$d&Kgg~^XCG*teAq#F7`J+7mHBO*WuZBSNiHnaH}}r3@9z5# zgU2T`3lO+pjm$Y5!ZR8pbG-H2X`<6h^bd1}v5d?BGr$b|RR-L7CTITY1o*p|0cPOa z7@+e(p%QuybBpHaz{ZpSh(&Z8L7RRXDMvZ<9Of3W2SwOaM4KvHi6Lw{`jw0G9Of2n zItW*M2=`{;DimSfj^is64#Km@Ei=Fjj50vAA4-Mp|J|?ae-p$FGr$b|PX Date: Thu, 8 Jun 2023 00:22:18 +0200 Subject: [PATCH 07/11] [WIP] --- .DS_Store | Bin 0 -> 6148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f8c3b4991bde49392d135a25814cc6635b6b49ac GIT binary patch literal 6148 zcmeHK&2G~`5S~p^SO*X}AhkzdxS*&c2t*@<xfu#y_MrMYD178 z1D>L<(Kq06;M*T6(o%^-g+w(Y&3?19Gh^*%Yu7_WqCZKxL@gqcP>nSY!yiPiYrP^h z=UD;@T|*tjnTj#f_O6iz} zR9wnCL-gw3p) zIf|YAPO0p|j^dqkINfVK+E95JrTMTh$!Rh~$cNoDPt>%pCV4V8bwax!r6;|;*79uj zytmf&d!2dPpY@(~+WyP#i}~D>%a6OSxAqTDPG_IzU%nb9NZ@NX^3dTg_y*%zo{qyJ z&s6>iF*@I)x3o#?VDb%cl@2LcWK!%R>gjJxV#>k{FaylMjWFO&F?sJss&Nr!fEl<= z4CwR0hiVKQRu;|Cfx)x@zy{n#V4I(RpsyXkz+q((9*D51K$|LDiy>U^AZ$9;0~cRe zwCN Date: Thu, 8 Jun 2023 10:12:57 +0200 Subject: [PATCH 08/11] [WIP] Implemented the class serialPort and a litle bit of ReadChannel --- PythonDriver/.DS_Store | Bin 6148 -> 6148 bytes PythonDriver/.vscode/settings.json | 6 ++ PythonDriver/TestBufferAscii.py | 2 + PythonDriver/module/ChannelBuffersSerial.py | 89 ++++++++++++++------ 4 files changed, 70 insertions(+), 27 deletions(-) create mode 100644 PythonDriver/.vscode/settings.json diff --git a/PythonDriver/.DS_Store b/PythonDriver/.DS_Store index 40057eca37ebbaaf95a07c3ed288177e762e1f9b..3bce58209779ea13691ab0b66879a9416d2878f9 100644 GIT binary patch literal 6148 zcmeHK%Wl&^6upy%;shZggh-Jn@`hbhC8$8NKr*H*xYTUf!F2gpv+v;_$vG}oFr^SZ}#PckzeB4YN)?+`VJ$Ux#)ts`4vyq~89 ztEiSsKqfdM3ihJp(2EjpVYF`03TOrXH3j(EU8g=Jz8i|50SRM3lmc>jrGRq zK&|yJ-XIFotlj>~Dr?mX>lY29ZqzT=Uphz0*vZ^%l-lm_Ij=o&vm;NHdr1=gD!bm( zFc|MQu02ZP%njpUD4at-z>pWu!q`v7b~1|nRPZ>m!!T+_ZNJf+PPe-|EwkI6wajVv zPP=8^@7$fuYDV*R=fU1VfAV(vZg%`ZL_rMum9Q%cf5Jx;N-@51hH;d{uhGtZu2PQz zN+}~7dcDFE&=4x6bVwndEgI0Ium?gzwh6zYhSyKw=z*sX-X&c0d5)`jMy}%%**+D1 z-5X2UY|JMn7jaIgL-)u-JwwDx=2zi56=U5z7vrkP`9HBZ*IU2Ed^R06PUYTNr2>0D zr^3y1@U75*eVgM&^$$#~0fX-W+Oz^%0j)q$0lq(&NE|JNxkRybAQM*rU=_{6Q0AWv z+{aXCDa<9J2gal;P`Wa8#bDAM?WP)MDa<8GcVg=D!PJ|Xx}h-fcJP~GI5A72&b0zs zfwBT?vfAM1|KpSI|79m#(+X$>{woDob=TRo5t2Gv7lPwwt%-Di#Ep;3B?=d0>Npk! feiUyY2}7UB3qVU@E)gv-{UIP^(3w`?uPX2Z?_~VW delta 67 zcmZoMXfc=|#>B)qu~2NHo+2aj#(>?7jLe&PSo9e;i*N|DOl;V>nVo~51E^%PAjfy+ V$^0UY91K9f$iTp|IYML&GXN~24*CE9 diff --git a/PythonDriver/.vscode/settings.json b/PythonDriver/.vscode/settings.json new file mode 100644 index 0000000..9ee86e7 --- /dev/null +++ b/PythonDriver/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[python]": { + "editor.defaultFormatter": "ms-python.autopep8" + }, + "python.formatting.provider": "none" +} \ No newline at end of file diff --git a/PythonDriver/TestBufferAscii.py b/PythonDriver/TestBufferAscii.py index 9191c3f..ab86e6f 100644 --- a/PythonDriver/TestBufferAscii.py +++ b/PythonDriver/TestBufferAscii.py @@ -1,6 +1,8 @@ import sys import glob +from module.ChannelBuffersSerial import * if __name__ == '__main__': + pass diff --git a/PythonDriver/module/ChannelBuffersSerial.py b/PythonDriver/module/ChannelBuffersSerial.py index 99607b2..3262355 100644 --- a/PythonDriver/module/ChannelBuffersSerial.py +++ b/PythonDriver/module/ChannelBuffersSerial.py @@ -7,20 +7,18 @@ class SerialPort(serial.Serial): + + global ser # global variable to store the serial object + def __init__(self): super(SerialPort, self).__init__() - pass - def getPorts(self): + def listSerialPorts(self): """ - Lists serial port names - A list of the serial ports available on the system + Lists the serial port names available on the system """ - # Definning variables: - result = [] # Checking the computer operational system: - if sys.platform.startswith('win'): ports = ['COM%s' % (i + 1) for i in range(256)] elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'): @@ -31,43 +29,80 @@ def getPorts(self): else: raise EnvironmentError('Unsupported platform') + # Definning variables: + portsFound = [] for port in ports: try: s = serial.Serial(port) s.close() - result.append(port) + portsFound.append(port) except (OSError, serial.SerialException): pass - return result + return portsFound + + def findDevices(self, device_serial_name="Arduino"): + """ + Look through all the available serial connections, the serial objects with "device_serial_name" + inside + """ + comPorts = [] + portsFound = self.listSerialPorts() + connectionAvailable = len(portsFound) -class Uart(serial.Serial): - def __init__(self): - super(Uart, self).__init__(self) - pass + for curr_device in range(connectionAvailable): + devicePort = str(portsFound[curr_device]) - def config(self): - pass + if device_serial_name in devicePort: + comPorts.append((devicePort.split(' '))[0]) - def write(self): - pass + return comPorts - def print(self): - pass + def connectPort(self, serialPort, baudrate=9600, timeout=-1, xonxoff=False): + if serialPort is not None: + try: + self.ser = serial.Serial( + serialPort, baudrate, timeout, xonxoff) + print("Connected to "+serialPort) + except serial.SerialException as var: + print("Connection issued!\n Exception detail:"+var) - def println(self): - pass + def isComStablished(self, command, readStr="ACK", encoding='ascii', errors='strict'): + command += str('\n') + serialString = val = self.ser.write(command.encode(encoding, errors)) + # inCommingData=self.ser.read_until(b'}') + inCommingData = self.ser.readline() + + if (inCommingData == readStr): + return True + + else: + return False + + +class ReadChannel(SerialPort): + + def __init__(self, channelNumber): + super(SerialPort, self).__init__() + self.channelNo = channelNumber + + # Declaring and implementing all the available functions for the channelBuffer -if __name__ == '__main__': """ - Where test are going to be done + The main functions I want this code to perform are: + Ascii(sepCar); + AsciiTimeStamp(sepCar); + RawData16(); + RawData8(); + RawDataTimeStamp16(); + RawDataTimeStamp8(); + """ - uart = SerialPort() - ports = uart.getPorts() + pass - print(ports) - print(ports[0]) + +if __name__ == '__main__': pass From c783e518858f5bca678e25a9fdcfdf143dd42091 Mon Sep 17 00:00:00 2001 From: Nedved SIMAO <109746899+NedSimao@users.noreply.github.com> Date: Thu, 8 Jun 2023 10:25:57 +0200 Subject: [PATCH 09/11] [WIP] Implemented .Ascii() method --- PythonDriver/module/ChannelBuffersSerial.py | 30 ++++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/PythonDriver/module/ChannelBuffersSerial.py b/PythonDriver/module/ChannelBuffersSerial.py index 3262355..6e3e1fa 100644 --- a/PythonDriver/module/ChannelBuffersSerial.py +++ b/PythonDriver/module/ChannelBuffersSerial.py @@ -90,18 +90,28 @@ def __init__(self, channelNumber): # Declaring and implementing all the available functions for the channelBuffer - """ - The main functions I want this code to perform are: - Ascii(sepCar); - AsciiTimeStamp(sepCar); - RawData16(); - RawData8(); - RawDataTimeStamp16(); - RawDataTimeStamp8(); + def Ascii(self, sepCar="\t", decode='ascii'): + read = self.ser.readline().decode(decode) - """ + def AsciiTimeStamp(self, sepCar="\t"): - pass + pass + + def RawData16(self): + + pass + + def RawData8(self): + + pass + + def RawDataTimeStamp16(self): + + pass + + def RawDataTimeStamp8(self): + + pass if __name__ == '__main__': From 137b2e01733357d9ff4d50b774bc2d17a605b1f5 Mon Sep 17 00:00:00 2001 From: Nedved SIMAO <109746899+NedSimao@users.noreply.github.com> Date: Thu, 8 Jun 2023 10:30:04 +0200 Subject: [PATCH 10/11] [WIP] Modification of .Ascii() methods and Implementation of .AsciiTimeStamp() method --- PythonDriver/module/ChannelBuffersSerial.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/PythonDriver/module/ChannelBuffersSerial.py b/PythonDriver/module/ChannelBuffersSerial.py index 6e3e1fa..7b9d402 100644 --- a/PythonDriver/module/ChannelBuffersSerial.py +++ b/PythonDriver/module/ChannelBuffersSerial.py @@ -91,11 +91,15 @@ def __init__(self, channelNumber): # Declaring and implementing all the available functions for the channelBuffer def Ascii(self, sepCar="\t", decode='ascii'): - read = self.ser.readline().decode(decode) + readData = self.ser.readline().decode(decode).split(sepCar) + + return readData def AsciiTimeStamp(self, sepCar="\t"): - pass + readData = self.Ascii(sepCar) + + return readData def RawData16(self): From 142b0559820d6fd91f36626ac8ae04d8a2e0928c Mon Sep 17 00:00:00 2001 From: Nedved SIMAO <109746899+NedSimao@users.noreply.github.com> Date: Thu, 8 Jun 2023 11:31:58 +0200 Subject: [PATCH 11/11] [WAD] The classes are working fine and the first two methods from ReadChannel too - Base commit for changes --- PythonDriver/module/ChannelBuffersSerial.py | 63 ++++++++++++++++----- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/PythonDriver/module/ChannelBuffersSerial.py b/PythonDriver/module/ChannelBuffersSerial.py index 7b9d402..4274472 100644 --- a/PythonDriver/module/ChannelBuffersSerial.py +++ b/PythonDriver/module/ChannelBuffersSerial.py @@ -17,15 +17,16 @@ def listSerialPorts(self): """ Lists the serial port names available on the system """ - # Checking the computer operational system: if sys.platform.startswith('win'): ports = ['COM%s' % (i + 1) for i in range(256)] - elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'): + elif sys.platform.startswith('linux'): # this excludes your current terminal "/dev/tty" ports = glob.glob('/dev/tty[A-Za-z]*') - elif sys.platform.startswith('darwin'): + elif sys.platform.startswith('cygwin'): # for windows/cygwin ports = glob.glob('/dev/tty.*') + elif sys.platform.startswith('darwin'): + ports = glob.glob('/dev/cu.*') else: raise EnvironmentError('Unsupported platform') @@ -51,29 +52,40 @@ def findDevices(self, device_serial_name="Arduino"): portsFound = self.listSerialPorts() connectionAvailable = len(portsFound) - for curr_device in range(connectionAvailable): - devicePort = str(portsFound[curr_device]) + if (device_serial_name != "All"): + for curr_device in range(connectionAvailable): + devicePort = str(portsFound[curr_device]) + + if device_serial_name in devicePort: + comPorts.append((devicePort.split(' '))[0]) + else: + for curr_device in range(connectionAvailable): + devicePort = str(portsFound[curr_device]) - if device_serial_name in devicePort: comPorts.append((devicePort.split(' '))[0]) return comPorts - def connectPort(self, serialPort, baudrate=9600, timeout=-1, xonxoff=False): + def connect(self, serialPort, baudrate=9600, timeout=10, xonxoff=False): if serialPort is not None: try: self.ser = serial.Serial( - serialPort, baudrate, timeout, xonxoff) - print("Connected to "+serialPort) + port=serialPort, baudrate=baudrate, timeout=timeout, xonxoff=xonxoff) + print("Connected to :") + print(serialPort) except serial.SerialException as var: print("Connection issued!\n Exception detail:"+var) + def disconnect(self): + self.ser.close() + def isComStablished(self, command, readStr="ACK", encoding='ascii', errors='strict'): command += str('\n') - serialString = val = self.ser.write(command.encode(encoding, errors)) + serialString = val = SerialPort.ser.write( + command.encode(encoding, errors)) # inCommingData=self.ser.read_until(b'}') - inCommingData = self.ser.readline() + inCommingData = SerialPort.ser.readline() if (inCommingData == readStr): return True @@ -90,12 +102,13 @@ def __init__(self, channelNumber): # Declaring and implementing all the available functions for the channelBuffer - def Ascii(self, sepCar="\t", decode='ascii'): + def Ascii(self, sepCar='\t', decode='ascii'): readData = self.ser.readline().decode(decode).split(sepCar) + readData.remove("\r\n") return readData - def AsciiTimeStamp(self, sepCar="\t"): + def AsciiTimeStamp(self, sepCar='\t'): readData = self.Ascii(sepCar) @@ -119,4 +132,26 @@ def RawDataTimeStamp8(self): if __name__ == '__main__': - pass + + # uart = SerialPort() + uart = ReadChannel(4) + ports = uart.listSerialPorts() + + devices = uart.findDevices("usbmodem") + # devices = uart.findDevices("Arduino") + # print("Devices available : ", devices) + # print("Comports available : ", ports) + dat = devices[0] + print("dat : "+str(type(dat))) + + uart.connect(dat) + + uart.connect(devices[0]) + + for i in range(10): + # dataRead = uart.Ascii() + dataRead = uart.AsciiTimeStamp() + + print(dataRead) + + uart.disconnect()