Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- MwadimeMakokha
- Date:
- 2019-11-14
- Revision:
- 2:83d03d7148a5
- Parent:
- 1:940070f92554
File content as of revision 2:83d03d7148a5:
#include "BT.h"
Timer t;
char modem_response[255];
int main(){
//Serial modemSerial(PC_6, PC_7);
// BT bt(modemSerial);
// // MDB mdb(huart1);
// DEBUG_PRINTLN("sTART");
// bt.get_bt_status();
// bt.power_bt_device(1);
// bt.bt_unpair_device();
// char id = bt.bt_scan(120000);
// if(id=='0'){
// DEBUG_PRINTLN("Target device not found");
// }
// else{
// ThisThread::sleep_for(4000);
// bt.bt_pair_device(id);
// ThisThread::sleep_for(2000);
// char profile_id = bt.bt_get_profile_id(id);
// DEBUG_PRINTLN("%c",profile_id);
// bt.bt_connect_device(id,profile_id);
// }
BT bt(modemSerial);
DEBUG_PRINTLN("PROGRAM START");
MODEM_PRINTLN("ATE0");
get_response(1000,false);
DEBUG_PRINTLN("%s",modem_response);
MODEM_PRINTLN("AT");
get_response(1000,false);
if((strcmp(modem_response,"OK") != 0)){
DEBUG_PRINTLN("%s",modem_response);
return 0;
}
DEBUG_PRINTLN("%s",modem_response);
bt.get_bt_status();
bt.power_bt_device(1);
char id = bt.bt_scan(120000);
if(id=='0'){
DEBUG_PRINTLN("Target device not found");
}
else{
bt.bt_pair_device(id);
}
while(1){
}
}
void get_response(uint16_t timeout,bool is_multiline){
int arr_index=0;
while(timeout){
if(arr_index >= 254) break;
while(modemSerial.readable()){
char c = modemSerial.getc();
if(c == '\r') continue;
if(c=='\n' && arr_index==0){
continue;
}
if(c=='\n' && !is_multiline){
break;
}
modem_response[arr_index] = c;
arr_index++;
}
timeout--;
wait_ms(1);
}
modem_response[arr_index] = 0;
}