Serial pour utiliser avec module ESP10 en mode pont

Dependents:   souflerie-sp3-wifi-F411re-2 souflerie-sp2-wifi-F411re-2 souflerie-sp1-wifi-F411re-2 Programme_Final_V6

Committer:
schnf30
Date:
Sun Jun 06 18:09:36 2021 +0000
Revision:
4:55ab98f52d77
3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
schnf30 4:55ab98f52d77 1 #include "mbed.h"
schnf30 4:55ab98f52d77 2 #include "wifiesp8266.h"
schnf30 4:55ab98f52d77 3
schnf30 4:55ab98f52d77 4 WifiEsp8266::WifiEsp8266(PinName Txd, PinName Rxd, float TimeOut) : RawSerial(Txd,Rxd)
schnf30 4:55ab98f52d77 5 {
schnf30 4:55ab98f52d77 6 baud(Baud);
schnf30 4:55ab98f52d77 7 _TimeOut = TimeOut;
schnf30 4:55ab98f52d77 8 _DataPtr = 0;
schnf30 4:55ab98f52d77 9 _DataReady = false;
schnf30 4:55ab98f52d77 10 _Canal1Ok = false;
schnf30 4:55ab98f52d77 11 _Canal2Ok = false;
schnf30 4:55ab98f52d77 12 attach(this,&WifiEsp8266::receive, RawSerial::RxIrq);
schnf30 4:55ab98f52d77 13 if (_TimeOut != NULL) TGarde.attach(this,&WifiEsp8266::Tevent,_TimeOut); // pour chien de garde
schnf30 4:55ab98f52d77 14 }
schnf30 4:55ab98f52d77 15 void WifiEsp8266::Tevent(void) // chien de garde
schnf30 4:55ab98f52d77 16 {
schnf30 4:55ab98f52d77 17 if (!_Canal1Ok) printf("$Y\r\n");
schnf30 4:55ab98f52d77 18 if (!_Canal2Ok) printf("$y\r\n");
schnf30 4:55ab98f52d77 19 _Canal1Ok = false;
schnf30 4:55ab98f52d77 20 _Canal2Ok = false;
schnf30 4:55ab98f52d77 21 }
schnf30 4:55ab98f52d77 22 char * WifiEsp8266::read(void)
schnf30 4:55ab98f52d77 23 {
schnf30 4:55ab98f52d77 24 _DataReady = false;
schnf30 4:55ab98f52d77 25 return _Data;
schnf30 4:55ab98f52d77 26 }
schnf30 4:55ab98f52d77 27
schnf30 4:55ab98f52d77 28 bool WifiEsp8266::dataready(void)
schnf30 4:55ab98f52d77 29 {
schnf30 4:55ab98f52d77 30 return _DataReady;
schnf30 4:55ab98f52d77 31 }
schnf30 4:55ab98f52d77 32
schnf30 4:55ab98f52d77 33 // reception phrase de type '$' "....' "\r\n"
schnf30 4:55ab98f52d77 34 void WifiEsp8266::receive(void)
schnf30 4:55ab98f52d77 35 {
schnf30 4:55ab98f52d77 36 bool _PhraseComplete = false;
schnf30 4:55ab98f52d77 37 char inChar;
schnf30 4:55ab98f52d77 38 while (readable() && (_PhraseComplete == false)) {
schnf30 4:55ab98f52d77 39 inChar = getc();
schnf30 4:55ab98f52d77 40 switch (inChar) {
schnf30 4:55ab98f52d77 41 case '$' :
schnf30 4:55ab98f52d77 42 _DataPtr = 0;
schnf30 4:55ab98f52d77 43 _DataTmp[_DataPtr++] = inChar;
schnf30 4:55ab98f52d77 44 _DataTmp[_DataPtr] = 0;
schnf30 4:55ab98f52d77 45 break;
schnf30 4:55ab98f52d77 46 case '\n' :
schnf30 4:55ab98f52d77 47 if (_DataPtr > 1) {
schnf30 4:55ab98f52d77 48 strcpy(_Data,_DataTmp);
schnf30 4:55ab98f52d77 49 _PhraseComplete = true;
schnf30 4:55ab98f52d77 50 if (_TimeOut!=NULL) {
schnf30 4:55ab98f52d77 51 if ((_Data[1] >> 5)==2) _Canal1Ok = true;
schnf30 4:55ab98f52d77 52 if ((_Data[1] >> 5)==3) _Canal2Ok = true;
schnf30 4:55ab98f52d77 53 }
schnf30 4:55ab98f52d77 54 }
schnf30 4:55ab98f52d77 55 _DataTmp[0] = 0;
schnf30 4:55ab98f52d77 56 _DataPtr = 0;
schnf30 4:55ab98f52d77 57 break;
schnf30 4:55ab98f52d77 58 case '\r' :
schnf30 4:55ab98f52d77 59 break;
schnf30 4:55ab98f52d77 60 default :
schnf30 4:55ab98f52d77 61 if (_DataPtr > 0) {
schnf30 4:55ab98f52d77 62 _DataTmp[_DataPtr++] = inChar;
schnf30 4:55ab98f52d77 63 _DataTmp[_DataPtr] = 0;
schnf30 4:55ab98f52d77 64 }
schnf30 4:55ab98f52d77 65 }
schnf30 4:55ab98f52d77 66 if (_DataPtr >= maxdata) { // si phrase trop longue vide phrase
schnf30 4:55ab98f52d77 67 _DataTmp[0] = 0;
schnf30 4:55ab98f52d77 68 _DataPtr = 0;
schnf30 4:55ab98f52d77 69 _PhraseComplete = false;
schnf30 4:55ab98f52d77 70 }
schnf30 4:55ab98f52d77 71 }
schnf30 4:55ab98f52d77 72 _DataReady = _PhraseComplete;
schnf30 4:55ab98f52d77 73 }