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:05:50 2021 +0000
Revision:
2:732f48da2cce
3

Who changed what in which revision?

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