#include "awtk.h" #include "conversation_protocol.h" #include "chip.h" #include "board.h" #include "serial.h" #include "sysinfo.h" #include "user_data.h" #include "data_port.h" #include "universal.h" #define CALL_NUM_SIZE 20 extern uint8_t cmdstr[64]; extern uint8_t cmdlen; // uint8_t cmdstr[64]; // uint8_t cmdlen = 0; uint8_t bt2_call_answer = 0;//接听标志 uint8_t bt2_call_hangup = 0;//挂断标志 uint8_t bt2_recall_answer = 0;//接听2标志 uint8_t bt2_recall_hangup = 0;//挂断2标志 uint8_t bt2_switch = 0;//发送蓝牙开关标志 uint8_t bt2_switch_state = 0;//蓝牙状态标志 uint8_t bt2_switch_time = 0;//开关蓝牙时间限制 uint8_t call_time = 0;//命令延迟限制 uint8_t complex_call = 0;//多重来电标志 static uint8_t error_answer_state =0;//接电话失败,切换命令再次接听电话 static uint8_t error_hang_up_state =0;//挂断电话失败,切换命令再次挂断电话标志 static uint8_t return_call_state = 0;//返回的call标志 static uint8_t call_state_time = 0; static uint8_t test_call_state = 0;//暂停通话标志 static uint8_t bt2_call_state = 0;//查询当前蓝牙状态信息 uint8_t bt2_state = 0; uint8_t bt2_state_now_flag = 0; void uart_test_tx_demo_thread(void *param) { UartPort_t *uap = param; uint8_t uarttx_CH[32] = "AT#CH\r\n";//接听 挂断 uint8_t uarttx_CJ1[32] = "AT#CJ=01\r\n";//挂断 uint8_t uarttx_CJ2[32] = "AT#CJ=02\r\n";//挂断1接听2 uint8_t uarttx_CJ3[32] = "AT#CJ=03\r\n";//挂断2 uint8_t uarttx_CJ4[32] = "AT#CJ=04\r\n";//挂断2 uint8_t uarttx_CJ5[32] = "AT#CJ=05\r\n";//挂断2 uint8_t uarttx_CO[32] = "AT#CO\r\n";//开蓝牙 uint8_t uarttx_CP[32] = "AT#CP\r\n";//关蓝牙 uint8_t uarttx_CT[32] = "AT#CT\r\n";//查询当前状态 for (;;) { if(bt2_switch_time){ bt2_switch_time--; } if(call_time){ call_time--; } if(call_state_time){ call_state_time--; } if(test_call_state){//暂停通话改为正常通话 test_call_state = 0; DEBUG_PRINT("tx >> ------------CJ4\r\n"); iUartWrite(uap, uarttx_CJ4, strlen((char*)uarttx_CJ4), pdMS_TO_TICKS(100)); } if(bt2_call_state || bt2_state){ DEBUG_PRINT("#####AT#CT \r\n"); iUartWrite(uap, uarttx_CT, strlen((char*)uarttx_CT), pdMS_TO_TICKS(100)); bt2_call_state = 0; bt2_state = 0; bt2_state_now_flag = 1; } if(Get_sys_call_key_state()==1 && !call_state_time){//接听电话1 //挂断电话1接听电话2 DEBUG_PRINT("tx >> AT#CT \r\n"); iUartWrite(uap, uarttx_CT, strlen((char*)uarttx_CT), pdMS_TO_TICKS(100)); call_state_time = 5; }else if(Get_sys_call_key_state()==2 && !call_state_time){//挂断电话 //挂断电话2 DEBUG_PRINT("tx >> AT#CT \r\n"); iUartWrite(uap, uarttx_CT, strlen((char*)uarttx_CT), pdMS_TO_TICKS(100)); call_state_time = 5; } switch(return_call_state){ case 1://接听1 DEBUG_PRINT(">>>>>> AT#CH \r\n"); iUartWrite(uap, uarttx_CH, strlen((char*)uarttx_CH), pdMS_TO_TICKS(100)); bt2_call_answer = 1; return_call_state = 0; break; case 2://挂1接2 DEBUG_PRINT(">>>>>> AT#CJ2 \r\n"); iUartWrite(uap, uarttx_CJ2, strlen((char*)uarttx_CJ2), pdMS_TO_TICKS(100)); bt2_recall_answer = 1; return_call_state = 0; break; case 3://挂1 DEBUG_PRINT(">>>>>> AT#CJ1 \r\n"); iUartWrite(uap, uarttx_CJ1, strlen((char*)uarttx_CJ1), pdMS_TO_TICKS(100)); bt2_call_hangup = 1; return_call_state = 0; break; case 4://拒接2 DEBUG_PRINT(">>>>>> AT#CJ3 \r\n"); iUartWrite(uap, uarttx_CJ3, strlen((char*)uarttx_CJ3), pdMS_TO_TICKS(100)); bt2_recall_hangup = 1; return_call_state = 0; break; default://常规 break; } if(bt2_switch == 1 && bt2_switch_time == 0){//关蓝牙 DEBUG_PRINT("\ntx >> AT#CP \r\n"); iUartWrite(uap, uarttx_CP, strlen((char*)uarttx_CP), pdMS_TO_TICKS(100)); bt2_switch_time = 100; }else if (bt2_switch == 2 && bt2_switch_time == 0){//开蓝牙 DEBUG_PRINT("\ntx >> AT#CO \r\n"); iUartWrite(uap, uarttx_CO, strlen((char*)uarttx_CO), pdMS_TO_TICKS(100)); bt2_switch_time = 100; } if(error_hang_up_state == 1){//挂2失败 尝试一次挂1 DEBUG_PRINT("\nerror_hang_up_state == 1 tx >> AT#CJ=1 \r\n"); iUartWrite(uap, uarttx_CJ1, strlen((char*)uarttx_CJ1), pdMS_TO_TICKS(100)); error_hang_up_state = 0; }else if(error_hang_up_state == 2){//挂1失败 尝试一次挂2 DEBUG_PRINT("\nerror_hang_up_state == 2 tx >> AT#CJ=3 \r\n"); iUartWrite(uap, uarttx_CJ3, strlen((char*)uarttx_CJ3), pdMS_TO_TICKS(100)); error_hang_up_state = 0; } if(error_answer_state == 1){//接1失败 尝试挂2接1 DEBUG_PRINT("\nerror_answer_state = 1 tx >> AT#CJ=2 \r\n"); iUartWrite(uap, uarttx_CJ2, strlen((char*)uarttx_CJ2), pdMS_TO_TICKS(100)); error_answer_state = 0; }else if(error_answer_state == 2){//挂2接1失败 尝试接1 DEBUG_PRINT("\nerror_answer_state = 2 tx >> AT#CH \r\n"); iUartWrite(uap, uarttx_CH, strlen((char*)uarttx_CH), pdMS_TO_TICKS(100)); error_answer_state = 0; } vTaskDelay(50); } } void BT2_init_close(void){ DEBUG_PRINT("BT2_init_close >>>>>>> bt2_switch_time = %d .\r\n",bt2_switch_time); if(bt2_switch_time) bt2_switch_time = 0; bt2_switch = 1; } void BT2_init_open(void){ DEBUG_PRINT("BT2_open >>>>>>> bt2_switch_time = %d .\r\n",bt2_switch_time); if(bt2_switch_time) bt2_switch_time = 0; bt2_switch = 2; } void BT2_Switch(int type){ if(bt2_switch_time == 0){ switch(type){ case 0://关闭蓝牙 // if(gpio_get_value(47)){ // gpio_direction_output(47, 0); // } bt2_switch = 1; break; case 1://开启蓝牙 // if(gpio_get_value(47)){ // gpio_direction_output(47, 0); // } bt2_switch = 2; break; default: break; } }else{ DEBUG_PRINT("BT2_Switch error ! bt2_switch_time =%d .\r\n",bt2_switch_time); } } // 解析接收到的 AT 指令 // void parseATCommand(uint8_t cmdstr[],uint8_t cmdlen) { void parseATCommand(void) { uint8_t str[64]; static uint8_t flag = 0; uint8_t j=0; for(uint8_t i=0;i