/*========================================================================================================== Copyright (c) 2021, Quectel Wireless Solutions Co., Ltd. All rights reserved. Quectel Wireless Solutions Proprietary and Confidential. ==========================================================================================================*/ /*========================================================================================================== EDIT HISTORY FOR MODULE This section contains comments describing changes made to the module. Notice that changes are listed in reverse chronological order. WHEN WHO WHAT, WHERE, WHY ------------ ------- ------------------------------------------------------------------------------- 09/04/2022 Pony.ma 此文件用于测试SIM卡相关的api 25/06/2022 Sharon.li 增加测试双卡切换 2023/07/13 Sharon.li 增加example使用说明 ===========================================================================================================*/ /** example 使用说明。注意:R07基线的SDK 为单卡协议栈,因此仅支持双卡单待。R07基线SDK 不再支持 xxx_by_simid()类似函数 1、创建ql_sim_test_ctrl_task,并使用Main UART 作为与上位机的交互串口. 2、通过串口向模块发 SWITCH_TO_1 代表切卡到卡1,代码立即执行切卡操作 3、通过串口向模块发 SWITCH_TO_2 代表切卡到卡2,代码立即执行切卡操作 4、通过串口向模块发 SIM_GET_INFO 代表获取当前SIM的信息 5、通过串口向模块发 START_DATACALL 代表使用当前主卡进行数据拨号 **/ #include #include #include #include "ql_type.h" #include "ql_rtos.h" #include "ql_application.h" #include "ql_data_call.h" #include "sockets.h" #include "netdb.h" #include "ql_sim.h" #include "ql_gpio.h" #include "ql_uart.h" //is default,Depending on the project. EC600K-GPIO_PIN_NO_85 #define QL_USIM1_DET_PIN GPIO_PIN_NO_49 #define SIM_HOT_PLUG_MSG_MAX_NUM 10 #define SIM_INSERT_PIN_LEVEL 0 typedef struct { PIN_LEVEL_E pinlevel; unsigned int reserved; }SIM_HOT_PLUG_MSG_T; static ql_queue_t sim_hot_plug_queue = NULL; static void quec_sim_detect_callback(PIN_LEVEL_E pinlevel) { SIM_HOT_PLUG_MSG_T sim_hot_plug_msg = {0}; sim_hot_plug_msg.pinlevel = pinlevel; ql_rtos_queue_release(sim_hot_plug_queue, sizeof(SIM_HOT_PLUG_MSG_T), &sim_hot_plug_msg, QL_NO_WAIT); } static void ql_sim_test_hot_plug_task(void * argv) { int ret = 0; int card_status = 0; char data[64] = {0}; size_t data_len = 32; SIM_HOT_PLUG_MSG_T sim_hot_plug_msg = {0}; ql_rtos_task_sleep_s(5); printf("<--------example_sim.c--ql_sim_test_hot_plug_task----------->\r\n"); ql_rtos_queue_create(&sim_hot_plug_queue, sizeof(SIM_HOT_PLUG_MSG_T), SIM_HOT_PLUG_MSG_MAX_NUM); //set detect gpio, if not use default. ret = ql_sim1_detect_gpio_config(QL_USIM1_DET_PIN); if(ret != QL_SIM_SUCCESS) printf("ql_sim1_detect_gpio_config() fail ret(%d)\r\n",ret); ret = ql_sim_config_hot_plug_detect(1,SIM_INSERT_PIN_LEVEL,quec_sim_detect_callback); if(ret != QL_SIM_SUCCESS) printf("xxxxql_sim_config_hot_plug_detect() fail ret(%d)\r\n",ret); ret = ql_sim_get_card_status(&card_status); printf("ql_sim_get_card_status ret:%d, status:%d\n",ret,card_status); if(QL_SIM_STATUS_READY == card_status) { ret = ql_sim_get_phonenumber(data, data_len); printf("ql_sim_get_phonenumber ret:%d, phonenumber:%s\n",ret,data); } for(;;) { ql_rtos_queue_wait(sim_hot_plug_queue, &sim_hot_plug_msg, sizeof(SIM_HOT_PLUG_MSG_T), QL_WAIT_FOREVER); if(SIM_INSERT_PIN_LEVEL == sim_hot_plug_msg.pinlevel) { printf("[APP] SIM Insert Pin level:%d\r\n",sim_hot_plug_msg.pinlevel); } else { printf("[APP] SIM Unplug Pin level:%d\r\n",sim_hot_plug_msg.pinlevel); } } } //application_init(ql_sim_test_hot_plug_task, "qlsimHot", 4, 0); static void ql_sim_get_info()// before run this app, you need a sim card without lock ,and this ori card pin is 1234 { int i=0; int ret = 0; char data[64] = {0}; size_t data_len = 32; int card_status = 0; ret = ql_sim_get_card_status(&card_status); printf("[APP]ql_sim_get_card_status ret:%d, status:%d\n",ret,card_status); ret = ql_sim_get_imsi(data,data_len); printf("ql_sim_get_imsi ret:%d, imsi:%s\n",ret,data); memset(data,0,sizeof(data)); ret = ql_sim_get_iccid(data, data_len); printf("ql_sim_get_iccid ret:%d, iccid:%s\n",ret,data); memset(data,0,sizeof(data)); ret = ql_sim_get_phonenumber(data, data_len); printf("ql_sim_get_phonenumber ret:%d, phonenumber:%s\n",ret,data); memset(data,0,sizeof(data)); QL_SIM_PHONE_BOOK_RECORDS_INFO records; ret = ql_sim_read_phonebook_record(QL_SIM_PHONE_BOOK_STORAGE_SM,1,5,NULL,&records); for(i=0;i\r\n"); return; } if(0 == memcmp(m_RxBuf_Uart1,"SWITCH_TO_1",11)) { printf("<-%s -->\r\n",m_RxBuf_Uart1); sim_ctrl_msg.ctrl_msg = SIM_SWITCH_TO_1; goto end; } if(0 == memcmp(m_RxBuf_Uart1,"SWITCH_TO_2",11)) { printf("<-%s -->\r\n",m_RxBuf_Uart1); sim_ctrl_msg.ctrl_msg = SIM_SWITCH_TO_2; goto end; } if(0 == memcmp(m_RxBuf_Uart1,"SIM_GET_INFO",12)) { printf("<-%s -->\r\n",m_RxBuf_Uart1); sim_ctrl_msg.ctrl_msg = SIM_GET_INFO; goto end; } if(0 == memcmp(m_RxBuf_Uart1,"START_DATACALL",12)) { printf("<-%s -->\r\n",m_RxBuf_Uart1); sim_ctrl_msg.ctrl_msg = SIM_START_DATACALL; goto end; } end: ql_uart_write(port,m_RxBuf_Uart1,totalBytes); memset(m_RxBuf_Uart1,0,SERIAL_RX_BUFFER_LEN); ql_rtos_queue_release(sim_ctrl_msg_queue, sizeof(SIM_CTRL_MSG_T), &sim_ctrl_msg, QL_NO_WAIT); return; } static unsigned char ControlPortInitFlag = 0; static unsigned char Ql_Control_Port_Open(QL_UART_PORT_NUMBER_E port) { int ires; ires = ql_uart_open(port, QL_UART_BAUD_115200, QL_FC_NONE); if (ires) { printf("ql_open cdc fail\r\n"); return 0xff; } ql_uart_register_cb(port, quec_control_uart_callback); //use callback to read uart data ControlPortInitFlag = 1; return 0; } static void ql_sim_test_ctrl_task(void) { SIM_CTRL_MSG_T sim_ctrl_msg = {0}; struct ql_data_call_info info = {0}; char ip4_addr_str[16] = {0}; static struct in_addr ip4_addr = {0}; ql_rtos_queue_create(&sim_ctrl_msg_queue, sizeof(SIM_CTRL_MSG_T), SIM_CTRL_MSG_MAX_NUM); Ql_Control_Port_Open(QL_MAIN_UART_PORT); while(1) { ql_rtos_queue_wait(sim_ctrl_msg_queue, &sim_ctrl_msg, sizeof(SIM_CTRL_MSG_T), QL_WAIT_FOREVER); switch(sim_ctrl_msg.ctrl_msg) { case SIM_SWITCH_TO_1: ql_sim_switch_card_ex(QL_SIM_0, quec_switch_sim_callback); break; case SIM_SWITCH_TO_2: ql_sim_switch_card_ex(QL_SIM_1, quec_switch_sim_callback); break; case SIM_GET_INFO: ql_sim_get_info(); break; case SIM_START_DATACALL: datacall_satrt(); ql_get_data_call_info(1, 0, &info); printf("info.profile_idx: %d\r\n", info.profile_idx); printf("info.ip_version: %d\r\n", info.ip_version); printf("info.v4.state: %d\r\n", info.v4.state); printf("info.v4.reconnect: %d\r\n", info.v4.reconnect); inet_ntop(AF_INET, &info.v4.addr.ip, ip4_addr_str, sizeof(ip4_addr_str)); printf("info.v4.addr.ip: %s\r\n", ip4_addr_str); inet_ntop(AF_INET, &info.v4.addr.pri_dns, ip4_addr_str, sizeof(ip4_addr_str)); printf("info.v4.addr.pri_dns: %s\r\n", ip4_addr_str); inet_ntop(AF_INET, &info.v4.addr.sec_dns, ip4_addr_str, sizeof(ip4_addr_str)); printf("info.v4.addr.sec_dns: %s\r\n", ip4_addr_str); break; case SIM_START_TCP_CLIENT: ip4_addr = info.v4.addr.ip; if(info.v4.state) { //do_tcp_client_test(ip4_addr); } } } } //application_init(ql_sim_test_ctrl_task, "ql_sim_test_ctrl_task",20, 0);