Bluetooth hc05 library
Diff: hc05.cpp
- Revision:
- 10:2e1538dc2e1a
- Parent:
- 9:a8a96ce56d6e
- Child:
- 11:770663228ced
diff -r a8a96ce56d6e -r 2e1538dc2e1a hc05.cpp --- a/hc05.cpp Sun Aug 19 07:52:06 2018 +0000 +++ b/hc05.cpp Sun Aug 19 17:00:22 2018 +0000 @@ -24,7 +24,7 @@ case UART1 : at0.at_send("AT+VERSION?\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(800); } else { return at0.buffer; } @@ -32,7 +32,7 @@ case UART6 : at1.at_send1("AT+VERSION?\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(800); } else { return at1.buffer; } @@ -47,7 +47,7 @@ case UART1 : at0.at_send("AT+RESET\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(800); } else { return at0.buffer; } @@ -55,7 +55,7 @@ case UART6 : at1.at_send1("AT+RESET\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(800); } else { return at1.buffer; } @@ -70,7 +70,7 @@ case UART1 : at0.at_send("AT+ORGL\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(800); } else { return at0.buffer; } @@ -78,7 +78,7 @@ case UART6 : at1.at_send1("AT+ORGL\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(800); } else { return at1.buffer; } @@ -94,7 +94,7 @@ case UART1 : at0.at_send("AT+ADDR?\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(1); + return at0.getAnswer(600); } else { return at0.buffer; } @@ -102,7 +102,7 @@ case UART6 : at1.at_send1("AT+ADDR?\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(1); + return at1.getAnswer(600); } else { return at1.buffer; } @@ -118,7 +118,7 @@ case UART1 : at0.at_send("AT+NAME?\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(800); } else { return at0.buffer; } @@ -126,7 +126,7 @@ case UART6 : at1.at_send1("AT+NAME?\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(800); } else { return at1.buffer; } @@ -142,7 +142,7 @@ case UART1 : at0.at_send("AT+RNAME?\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(800); } else { return at0.buffer; } @@ -150,7 +150,7 @@ case UART6 : at1.at_send1("AT+RNAME?\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(800); } else { return at1.buffer; } @@ -166,7 +166,7 @@ case UART1 : at0.at_send("AT+ROLE?\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(600); } else { return at0.buffer; } @@ -174,7 +174,7 @@ case UART6 : at1.at_send1("AT+ROLE?\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(600); } else { return at1.buffer; } @@ -190,7 +190,7 @@ case UART1 : at0.at_send("AT+CLASS?\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(600); } else { return at0.buffer; } @@ -198,7 +198,7 @@ case UART6 : at1.at_send1("AT+CLASS?\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(600); } else { return at1.buffer; } @@ -214,7 +214,7 @@ case UART1 : at0.at_send("AT+IAC?\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(600); } else { return at0.buffer; } @@ -222,7 +222,7 @@ case UART6 : at1.at_send1("AT+IAC?\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(600); } else { return at1.buffer; } @@ -238,7 +238,7 @@ case UART1 : at0.at_send("AT+INQM?\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(800); } else { return at0.buffer; } @@ -246,7 +246,7 @@ case UART6 : at1.at_send1("AT+INQM?\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(800); } else { return at1.buffer; } @@ -262,7 +262,7 @@ case UART1 : at0.at_send("AT+PSWD?\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(1); + return at0.getAnswer(600); } else { return at0.buffer; } @@ -270,7 +270,7 @@ case UART6 : at1.at_send1("AT+PSWD?\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(1); + return at1.getAnswer(600); } else { return at1.buffer; } @@ -286,7 +286,7 @@ case UART1 : at0.at_send("AT+UART?\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(600); } else { return at0.buffer; } @@ -294,7 +294,7 @@ case UART6 : at1.at_send1("AT+UART?\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(600); } else { return at1.buffer; } @@ -308,20 +308,19 @@ { switch(num) { case UART1 : - at0.at_send("AT+INQ?\r\n", ""); + at0.at_send("AT+INQ\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(600); } else { return at0.buffer; } - case UART6 : - at1.at_send1("AT+INQ?\r\n", ""); + at1.at_send1("AT+INQ\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(600); } else { return at1.buffer; } @@ -338,7 +337,7 @@ at0.at_send("AT+INIT\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(2); + return at0.getAnswer(800); } else { return at0.buffer; } @@ -348,7 +347,7 @@ at1.at_send("AT+INIT\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(2); + return at1.getAnswer(800); } else { return at1.buffer; } @@ -365,7 +364,7 @@ case UART1 : at0.at_send("AT+STATE?\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(800); } else { return at0.buffer; } @@ -373,7 +372,7 @@ case UART6 : at1.at_send1("AT+STATE?\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(800); } else { return at1.buffer; } @@ -389,7 +388,7 @@ case UART1 : at0.at_send("AT+CMODE?\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(600); } else { return at0.buffer; } @@ -397,7 +396,7 @@ case UART6 : at1.at_send1("AT+CMODE?\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(600); } else { return at1.buffer; } @@ -413,7 +412,7 @@ case UART1 : at0.at_send("AT+BIND?\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(600); } else { return at0.buffer; } @@ -421,7 +420,7 @@ case UART6 : at1.at_send1("AT+BIND?\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(600); } else { return at1.buffer; } @@ -438,7 +437,7 @@ case UART1 : at0.at_send("AT+ROLE=%i\r\n", (char*)role); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(600); } else { return at0.buffer; } @@ -446,7 +445,55 @@ case UART6 : at1.at_send1("AT+ROLE=%i\r\n", (char*)role); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(600); + } else { + return at1.buffer; + } + + } + return 0; + +} + +char *bt_modul_hc05::set_device_class(UART num, int dclass) +{ + switch(num) { + case UART1 : + at0.at_send("AT+CLASS=%i\r\n", (char*) dclass); + if(t_interrupt == OFF) { + return at0.getAnswer(600); + } else { + return at0.buffer; + } + + case UART6 : + at1.at_send1("AT+CLASS=%i\r\n", (char*) dclass); + if(t_interrupt1 == OFF) { + return at1.getAnswer(600); + } else { + return at1.buffer; + } + + } + return 0; + +} + +char *bt_modul_hc05::set_modul_giac(UART num, char *giac) +{ + switch(num) { + case UART1 : + at0.at_send("AT+IAC=%s\r\n", giac); + if(t_interrupt == OFF) { + return at0.getAnswer(600); + } else { + return at0.buffer; + } + + case UART6 : + at1.at_send1("AT+IAC=%s\r\n", giac); + if(t_interrupt1 == OFF) { + return at1.getAnswer(600); } else { return at1.buffer; } @@ -462,7 +509,7 @@ case UART1 : at0.at_send("AT+PSWD=%s\r\n", pin); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(600); } else { return at0.buffer; } @@ -470,7 +517,31 @@ case UART6 : at1.at_send1("AT+PSWD=%s\r\n", pin); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(600); + } else { + return at1.buffer; + } + + } + return 0; + +} + +char *bt_modul_hc05::set_modul_inquiry(UART num, char *inqparams) +{ + switch(num) { + case UART1 : + at0.at_send("AT+INQM=%s\r\n", inqparams); + if(t_interrupt == OFF) { + return at0.getAnswer(800); + } else { + return at0.buffer; + } + + case UART6 : + at1.at_send1("AT+INQM=%s\r\n", inqparams); + if(t_interrupt1 == OFF) { + return at1.getAnswer(800); } else { return at1.buffer; } @@ -486,7 +557,7 @@ case UART1 : at0.at_send("AT+NAME=%s\r\n", name); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(800); } else { return at0.buffer; } @@ -494,7 +565,7 @@ case UART6 : at1.at_send1("AT+NAME=%s\r\n", name); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(800); } else { return at1.buffer; } @@ -510,7 +581,7 @@ case UART1 : at0.at_send("AT+UART=%s\r\n", uartparams); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(600); } else { return at0.buffer; } @@ -518,7 +589,7 @@ case UART6 : at1.at_send1("AT+UART=%s\r\n", uartparams); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(600); } else { return at1.buffer; } @@ -534,7 +605,7 @@ case UART1 : at0.at_send("AT+BIND=\r\n", address); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(600); } else { return at0.buffer; } @@ -542,7 +613,7 @@ case UART6 : at1.at_send1("AT+BIND=\r\n", address); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(600); } else { return at1.buffer; } @@ -559,7 +630,7 @@ case UART1 : at0.at_send("AT+CMODE=%i\r\n", (char*)mode); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(600); } else { return at0.buffer; } @@ -567,7 +638,7 @@ case UART6 : at1.at_send1("AT+CMODE=%i\r\n", (char*)mode); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(600); } else { return at1.buffer; } @@ -582,7 +653,7 @@ case UART1 : at0.at_send("AT+FSAD=%s\r\n", address); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(800); } else { return at0.buffer; } @@ -590,7 +661,7 @@ case UART6 : at1.at_send1("AT+FSAD=%s\r\n", address); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(800); } else { return at1.buffer; } @@ -605,7 +676,7 @@ case UART1 : at0.at_send("AT+PMSAD=%s\r\n", address); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(800); } else { return at0.buffer; } @@ -613,7 +684,7 @@ case UART6 : at1.at_send1("AT+PMSAD=%s\r\n", address); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(800); } else { return at1.buffer; } @@ -628,7 +699,7 @@ case UART1 : at0.at_send("AT+RMAAD\r\n", ""); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(800); } else { return at0.buffer; } @@ -636,7 +707,7 @@ case UART6 : at1.at_send1("AT+RMAAD\r\n", ""); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(800); } else { return at1.buffer; } @@ -651,7 +722,7 @@ case UART1 : at0.at_send("AT+LINK=%s\r\n", address); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(800); } else { return at0.buffer; } @@ -659,7 +730,7 @@ case UART6 : at1.at_send1("AT+LINK=%s\r\n", address); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(800); } else { return at1.buffer; } @@ -674,7 +745,7 @@ case UART1 : at0.at_send("AT+DISC=%s\r\n", address); if(t_interrupt == OFF) { - return at0.getAnswer(3); + return at0.getAnswer(800); } else { return at0.buffer; } @@ -682,7 +753,7 @@ case UART6 : at1.at_send1("AT+DISC=%s\r\n", address); if(t_interrupt1 == OFF) { - return at1.getAnswer(3); + return at1.getAnswer(800); } else { return at1.buffer; } @@ -709,14 +780,14 @@ switch(num) { case UART1 : if(t_interrupt == OFF) { - return at0.getAnswer(2); + return at0.getAnswer(800); } else { return at0.buffer; } case UART6 : if(t_interrupt1 == OFF) { - return at1.getAnswer(2); + return at1.getAnswer(800); } else { return at1.buffer; } @@ -738,4 +809,20 @@ at1.clear(); } } +} + +char *bt_modul_hc05::search(UART num) +{ + // bt_modul_hc05::set_modul_role(UART6, MASTER); + bt_modul_hc05::get_modul_init(num); + bt_modul_hc05::set_modul_giac(num, "9e8b33"); + bt_modul_hc05::set_device_class(num, 0); + bt_modul_hc05::set_modul_inquiry(num, "1,5,10"); + return bt_modul_hc05::get_modul_inqm(num); +} + +char *bt_modul_hc05::link_device(UART num, char *address) +{ + bt_modul_hc05::search_device(num, address); + return bt_modul_hc05::connect_device(num, address); } \ No newline at end of file