From b11b00d4f815f30c5c1fdc8f58134933ada80d3b Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E9=82=93=E9=9B=AA=E8=8B=B1?= <1731678236@qq.com> Date: Fri, 2 Aug 2024 11:37:51 +0000 Subject: [PATCH] Merge #633 into sdk602patch0626 from refs/changes/633/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 邓雪英 * refs/changes/633/head: (2 commits squashed) - 使用CAT1拨打电话增加DTMF接口 @胡工 BLE端调用这个SendDtfmStrNumberToCat1函数即可:解决.py异常报错问题 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 Signed-off-by: d15521469561 <1731678236@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/633 --- cat1modem/src/cat1Service.py | 8 ++- cat1modem/src/china_mobile_dmp.py | 35 +++++------ cat1modem/src/telecom_dmp.py | 59 ++++++++++--------- .../service/ble_service/blemoder/bletest.cpp | 5 ++ .../service/ble_service/blemoder/bletest.h | 17 +++--- .../slip/cat1Service/cat1_server.cpp | 8 ++- .../peripheral/slip/cat1Service/cat1_server.h | 2 + 7 files changed, 77 insertions(+), 57 deletions(-) diff --git a/cat1modem/src/cat1Service.py b/cat1modem/src/cat1Service.py index dab18dc99..6a02992d8 100644 --- a/cat1modem/src/cat1Service.py +++ b/cat1modem/src/cat1Service.py @@ -303,9 +303,9 @@ class Cat1Service: modem_ver = modem.getDevFwVersion() self.reply_cmd('00',"pyVer:{}@modemVer:{}".format(PROJECT_VERSION,modem_ver)) elif cmd == "01": - print("{}{}".format(cmd,parm)) # UDP_CMD_DIAL_NUMB - voiceCall.callStart(parm) + ret = voiceCall.callStart(str(parm)) + print("ret={} {} {}".format(ret,cmd,parm)) elif cmd == "02": print(cmd) # UDP_CMD_HUNGUP @@ -391,7 +391,9 @@ class Cat1Service: eventMesh.publish("set_factory_status",int(parm)) elif cmd == "18": eventMesh.publish("set_dmp_cm_address",str(parm)) - + elif cmd == "19": #DTMF功能 + voiceCall.startDtmf(str(parm),100) #100ms 持续时间 100-1000 + def telecom_recv_cmd(self,cmd,parm): #电信入库 if cmd == "10": self.software_version = str(parm) diff --git a/cat1modem/src/china_mobile_dmp.py b/cat1modem/src/china_mobile_dmp.py index 23ba189b1..6d353d651 100644 --- a/cat1modem/src/china_mobile_dmp.py +++ b/cat1modem/src/china_mobile_dmp.py @@ -178,22 +178,24 @@ class chinamobile: headers_T ={"Content-Type":"application/json"} print("ujson.dumps(config_data):{}".format(ujson.dumps(config_data))) request_result = 0 + result_json = "" try: response = request.post(url, data=ujson.dumps(config_data),headers =headers_T) request_result = 1 + if response.status_code == 200:#服务器响应成功并返回数据 + content = response.content + c = next(content) + result_json = ujson.loads(c) + print("response.json:{}".format(ujson.loads(c))) except Exception as e: print("response:{}".format(e)) request_result = 0 - result_json = "" + if request_result == 0: #请求出错了 - return result_json + return "" - if response.status_code == 200:#服务器响应成功并返回数据 - content = response.content - c = next(content) - result_json = ujson.loads(c) - print("response.json:{}".format(ujson.loads(c))) + return result_json @@ -380,21 +382,11 @@ class chinamobile: test_data = ujson.dumps(send_autoregist)#需要转义的字符串 print("test_data:{}".format(test_data)) headers_T ={"Content-Type":"application/json"} - response = 0 request_result = 0 print("shangbao address:{}\r\n".format(url)) try: response = request.post(url, data=ujson.dumps(send_autoregist),headers =headers_T) request_result = 1 - print("response success:\r\n") - except Exception as e: - print("response:{}".format(e)) - request_result = 0 - - if request_result == 0:#请求出错了 - dev_autoregist_result = 0 - return dev_autoregist_result - else: result_json = "" if response.status_code == 200: @@ -416,6 +408,15 @@ class chinamobile: else: dev_autoregist_result = 0 return dev_autoregist_result + print("response success:\r\n") + except Exception as e: + print("response:{}".format(e)) + request_result = 0 + + if request_result == 0:#请求出错了 + dev_autoregist_result = 0 + return dev_autoregist_result + def read_config_file(self):#获取配置文件,一开机是没有配置文件的 diff --git a/cat1modem/src/telecom_dmp.py b/cat1modem/src/telecom_dmp.py index 46a7e1056..28c8dc69c 100644 --- a/cat1modem/src/telecom_dmp.py +++ b/cat1modem/src/telecom_dmp.py @@ -264,42 +264,43 @@ class telecomDmp: data_encode = base64.b64encode(json_bytes)#再转换成base64的编码格式 密文 print("data_infor:{} data:{}".format(data_encode,data)) headers_T = {'Content-Type':'application/encrypted-json'} #请求头信息 按照实际要求填写 - request_result = 0 try: response = request.post("http://zzhc.vnet.cn:9998/", data=data_encode,headers =headers_T) request_result = 1 + if response.status_code == 200 : #返回状态码 200服务器正常解析数据 + content = response.content#后台返回的结果 + c = next(content) + + jsload_data = ujson.loads(c) + print("jsload_data:{}".format(ujson.loads(c))) #{"resultCode": "0","resultDesc": "Success"} + if "resultCode" in jsload_data or "resultDesc" in jsload_data:#返回结果码值 + resultCode = jsload_data["resultCode"]#结果解析 "0" 成功 "1" 解码错误 "2" 校验错误 + resultDesc = jsload_data["resultDesc"]#Success 表示自注册成功 + + if resultCode == "0" or resultDesc == "Success":#注册成功退出当前注册 保存当前的ICCID 不在进行自注册了 + iccid = self.get_sim_iccid()#获取当前SIM的ICCID + if iccid != -1:#读到ICCID + self.timer_count = 0 + self.check_timer.stop() + self.isRegistOk = 1#已完成自注册的标识 + iccid_buf =str("ICCID:")+str(str(iccid)) + eventMesh.publish("save_iccid_data",iccid_buf) + self.multiple_day_resend() + #上报成功后 需要29.5或者30.5天后重发 初始值为0.5也就是12小时 30天后再重发一次也是一个月后重发数据自注册域 + print("regist success:!!!!!") + return 1 + if resultCode == "1": + print("Decode error")#解码错误 设备编码不正确 + return 0 + + if resultCode == "2":# + print("Check error")#校验错误 设备里面数据不正确 有些数据不应该为空 + return 0 + except Exception as e: print("response:{}".format(e)) request_result = 0 - print("response.status_code:{}".format(response.status_code)) - if response.status_code == 200 and request_result == 1: #返回状态码 200服务器正常解析数据 - content = response.content#后台返回的结果 - c = next(content) - - jsload_data = ujson.loads(c) - print("jsload_data:{}".format(ujson.loads(c))) #{"resultCode": "0","resultDesc": "Success"} - if "resultCode" in jsload_data or "resultDesc" in jsload_data:#返回结果码值 - resultCode = jsload_data["resultCode"]#结果解析 "0" 成功 "1" 解码错误 "2" 校验错误 - resultDesc = jsload_data["resultDesc"]#Success 表示自注册成功 - - if resultCode == "0" or resultDesc == "Success":#注册成功退出当前注册 保存当前的ICCID 不在进行自注册了 - iccid = self.get_sim_iccid()#获取当前SIM的ICCID - if iccid != -1:#没有读到ICCID - self.timer_count = 0 - self.check_timer.stop() - self.isRegistOk = 1#已完成自注册的标识 - iccid_buf =str("ICCID:")+str(str(iccid)) - eventMesh.publish("save_iccid_data",iccid_buf) - self.multiple_day_resend() - #上报成功后 需要29.5或者30.5天后重发 初始值为0.5也就是12小时 30天后再重发一次也是一个月后重发数据自注册域 - print("regist success:!!!!!") - return 1 - if resultCode == "1": - print("Decode error")#解码错误 设备编码不正确 - - if resultCode == "2":# - print("Check error")#校验错误 设备里面数据不正确 有些数据不应该为空 return 0 def timer_cb(self,data):#定时器回调 diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index 14404c16b..db66e151b 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -22,6 +22,7 @@ #include "phoneaddressmodel.h" #include "LanguageInit.h" #include "ConfigModel.h" +#include "cat1_server.h" // #include "TraingCardPresenter.h" #ifdef FD230 @@ -1838,6 +1839,10 @@ uint32_t ble_get_message_index() OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance(); return p_ConfigModel->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_MESSAGE_INDEX); } +void SendDtfmStrNumberToCat1(char ch) // ble发送单个字符到CAT1 DTMF功能 +{ + send_dtfm_number_toCat1(ch); +} #ifdef __cplusplus #if __cplusplus diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h index 50ee072f7..21893e2e1 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -271,13 +271,13 @@ void ble_app_reply(bool data); typedef struct Tag_Trailer { -char Header[3]; -char Title[30]; -char Artist[30]; -char Album[30]; -char Year[4]; -char Comment[30]; -char Cenre[1]; + char Header[3]; + char Title[30]; + char Artist[30]; + char Album[30]; + char Year[4]; + char Comment[30]; + char Cenre[1]; }Tag_Trailer_t; typedef struct Tag_ID3V2 @@ -333,6 +333,9 @@ void ble_disconnect_ok(void); void hand_watch_first_time_Paired(void); +//////////////////////////////////////// +void SendDtfmStrNumberToCat1(char ch); //ble发送单个字符到CAT1 DTMF功能 + #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp index 916fd37e3..696d4792c 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp @@ -89,6 +89,8 @@ enum UDP_COMMAND_HEAD { UDP_MSG_RECV_DMP_FACTORY = 0x17,//用于入库配置flag 0已经恢复出厂过 1代表没有恢复出厂过 UDP_MSG_SEND_DMP_CM_ADDRESS = 0x18,//用于BLE发送移动入库地址 to CAT1 接收 + + UDP_MSG_SEND_DTMF_NUMBER = 0x19,//DTMF 功能 }; /** 0: old format 1字节cmd, 1: new format 2字节cmd */ static uint8_t g_msg_format_type = 0; @@ -1131,7 +1133,11 @@ void set_dmp_cm_address_toCat1(char *address)//设置保存移动入库下发的 } return; } - +void send_dtfm_number_toCat1(char ch)//发送dtfm +{ + printf("ch:%s\r\n",&ch); + udp_send_msg_toCat1(UDP_MSG_SEND_DTMF_NUMBER,&ch); +} static int udp_packet_parse(char *rx_buffer, int len) { diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.h b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.h index 128cc9b25..119d8a421 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.h +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.h @@ -38,6 +38,8 @@ void get_regist_time_toCat1(void); void ble_get_cat1_at_msg(char *buffer,uint8_t len); +void send_dtfm_number_toCat1(char ch);//发送dtfm + #ifdef __cplusplus #if __cplusplus } -- 2.17.1