-
Notifications
You must be signed in to change notification settings - Fork 0
/
AtCommandsFraschetta.h
54 lines (54 loc) · 1.58 KB
/
AtCommandsFraschetta.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef AtCommandsFraschetta_h
#define AtCommandsFraschetta_h
enum Role{Slave,Master};
class AtCommandsF{
private:
virtual void ReceiveString()=0;
virtual String ReadString()=0;
virtual void Send(String s)=0;
static const String NlCr;
public:
AtCommandsF(){}
bool WaitOk(){
while(ReadString().indexOf("OK")<0){ReceiveString();}
ReceiveString();
return 1;
}
bool ModeAt(){Send("AT"+NlCr); return WaitOk();}
String AtName(){
while(!ModeAt()){}
Send("AT+NAME?"+NlCr);
while(ReadString()==""){ReceiveString();}
String RS=ReadString().substring(6,ReadString().length()-6);
ReceiveString();
return RS;
}
int AtUart(){
while(!ModeAt()){}
Send("AT+UART?"+NlCr);
while(ReadString()==""){ReceiveString();}
String RS=ReadString().substring(6,ReadString().length()-10);
ReceiveString();
return RS.toInt();
}
bool AtRole(){
while(!ModeAt()){}
Send("AT+ROLE?"+NlCr);
while(ReadString()==""){ReceiveString();}
String RS=ReadString();
ReceiveString();
return RS.indexOf('1')>=0;
}
bool AtRole(Role R){
while(!ModeAt()){}
if(R==Master){Send("AT+ROLE=1"+NlCr);}
else{Send("AT+ROLE=0"+NlCr);}
return AtRole();
}
bool AtResetSettings(){while(!ModeAt()){} Send("AT+RESET"+NlCr); return WaitOk();}
bool AtName(String Name){while(!ModeAt()){} Send("AT+NAME="+Name+NlCr); return Name==AtName();}
bool AtUart(int Baud){ while(!ModeAt()){} Send("AT+UART="+String(Baud)+",0,0"+NlCr); return Baud==AtUart();}
bool AtAssociate(uint8_t MacAddress){ while(!ModeAt()){} Send("AT+BIND="+String(MacAddress)+NlCr); return WaitOk();}
};
const String AtCommandsF::NlCr="\r\n";
#endif