SP1 vers 3
Dependents: SoufflerieSP1-vers2
Revision 0:58ef0c4fba67, committed 2021-06-08
- Comitter:
- petit
- Date:
- Tue Jun 08 10:37:18 2021 +0000
- Commit message:
- SP1 vers 3
Changed in this revision
wifiesp8266.cpp | Show annotated file Show diff for this revision Revisions of this file |
wifiesp8266.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wifiesp8266.cpp Tue Jun 08 10:37:18 2021 +0000 @@ -0,0 +1,73 @@ +#include "mbed.h" +#include "wifiesp8266.h" + +WifiEsp8266::WifiEsp8266(PinName Txd, PinName Rxd, float TimeOut) : RawSerial(Txd,Rxd) +{ + baud(Baud); + _TimeOut = TimeOut; + _DataPtr = 0; + _DataReady = false; + _Canal1Ok = false; + _Canal2Ok = false; + attach(this,&WifiEsp8266::receive, RawSerial::RxIrq); + if (_TimeOut != NULL) TGarde.attach(this,&WifiEsp8266::Tevent,_TimeOut); // pour chien de garde +} +void WifiEsp8266::Tevent(void) // chien de garde +{ + if (!_Canal1Ok) printf("$Y\r\n"); + if (!_Canal2Ok) printf("$y\r\n"); + _Canal1Ok = false; + _Canal2Ok = false; +} +char * WifiEsp8266::read(void) +{ + _DataReady = false; + return _Data; +} + +bool WifiEsp8266::dataready(void) +{ + return _DataReady; +} + +// reception phrase de type '$' "....' "\r\n" +void WifiEsp8266::receive(void) +{ + bool _PhraseComplete = false; + char inChar; + while (readable() && (_PhraseComplete == false)) { + inChar = getc(); + switch (inChar) { + case '$' : + _DataPtr = 0; + _DataTmp[_DataPtr++] = inChar; + _DataTmp[_DataPtr] = 0; + break; + case '\n' : + if (_DataPtr > 1) { + strcpy(_Data,_DataTmp); + _PhraseComplete = true; + if (_TimeOut!=NULL) { + if ((_Data[1] >> 5)==2) _Canal1Ok = true; + if ((_Data[1] >> 5)==3) _Canal2Ok = true; + } + } + _DataTmp[0] = 0; + _DataPtr = 0; + break; + case '\r' : + break; + default : + if (_DataPtr > 0) { + _DataTmp[_DataPtr++] = inChar; + _DataTmp[_DataPtr] = 0; + } + } + if (_DataPtr >= maxdata) { // si phrase trop longue vide phrase + _DataTmp[0] = 0; + _DataPtr = 0; + _PhraseComplete = false; + } + } + _DataReady = _PhraseComplete; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wifiesp8266.h Tue Jun 08 10:37:18 2021 +0000 @@ -0,0 +1,25 @@ +#ifndef _WifiEsp8266_ +#define _WifiEsp8266_ +// taille maximum d'une phrase recue +#define maxdata 100 +#define Baud 921600 +class WifiEsp8266 : public RawSerial +{ +public: + WifiEsp8266(PinName Txd, PinName Rxd,float _TimeOut=NULL); // _TimeOute pour chien de garde en s + void receive(); //recoit les data gps et les stocks puis produit les donnees en cas de reception + bool dataready(void); + char * read(void); +private: +// reception phrase Serial + char _DataTmp[maxdata + 1]; // tableau de donnees pour stocker pendant reception + char _Data[maxdata + 1]; // tableau de donnees lorsque toutes les donnees sont recues + int _DataPtr = 0; // position de stockage de la prochaine donnee a recevoir + bool _Canal1Ok = false; + bool _Canal2Ok = false; + Ticker TGarde; + bool _DataReady = false; + float _TimeOut; + void Tevent(void); +}; +#endif \ No newline at end of file