SP1 vers 3

Dependents:   SoufflerieSP1-vers2

Committer:
petit
Date:
Tue Jun 08 10:37:18 2021 +0000
Revision:
0:58ef0c4fba67
SP1 vers 3

Who changed what in which revision?

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