if (msg_hdr->len > *resp_len) { err = -1; *resp_len = 0;

时间: 2024-02-15 12:46:31 浏览: 25
这段代码看起来像是在处理网络消息的函数中的错误处理部分。根据代码中的注释,如果接收到的消息长度大于预期的响应长度,那么会返回一个错误并将响应长度设置为0。 具体而言,这里的`msg_hdr`是一个指向消息头部的指针,`len`表示消息的长度,`resp_len`是一个指向预期响应长度的指针。如果接收到的消息长度超过了预期的响应长度,那么就会返回一个错误码,并将`resp_len`设置为0,表示没有响应数据。
相关问题

bool serial_port::serial_port_write_read_at(const std::string &at_command, const std::string &resp_prefix, AT_RESPONSE *at_response) { char *read_line; bool ret_value = false; pthread_mutex_lock(&read_write_mutex); if (!serial_port_write_at_cmd(at_command.c_str())) { goto END; } do { read_line = serial_port_read_one_line(); if (read_line) { //LOG_F(INFO, "read one line from serial: %s", read_line); if (!strncmp(read_line, "AT", strlen("AT")) || !strncmp(read_line, "at", strlen("at"))) { //Do nothing } else if (!strncmp(read_line, "OK", strlen("OK"))) { //LOG_F(INFO, "find final response OK"); ret_value = true; if (at_response != nullptr) { at_response->state = RESP_OK; } break; } else if (!strncmp(read_line, "ERROR", strlen("ERROR")) || !strncmp(read_line, "+CME ERROR", strlen("+CME ERROR"))) { //LOG_F(INFO, "find final response ERROR"); ret_value = false; if (at_response != nullptr) { at_response->state = RESP_ERROR; } break; } else { if (at_response != nullptr) { //LOG_F(INFO, "put response string to AT_RESPONSE"); at_response->response_data[at_response->response_lines] = strdup(read_line); at_response->response_lines += 1; if (at_response->response_lines >= MAX_RESPONSE_LENGTH) at_response->response_lines = 0; } } } } while (true); END: pthread_mutex_unlock(&read_write_mutex); return ret_value; } 没有break反复循环的情况下,开头都是从serial_port_read_one_line这里开始吗?也就是do后面开始执行

是的,如果没有`break`语句来跳出循环,那么每次循环开始时都会执行`serial_port_read_one_line`函数来读取一行数据,并根据读取的内容进行相应的处理。所以,在没有`break`的情况下,循环会一直执行,并且每次循环开始都会重新调用`serial_port_read_one_line`函数。在这段代码中,循环体的开头就是从`serial_port_read_one_line`这里开始执行。

<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/> <soapenv:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ESB_CS_QRY_USED_RESUSED_001 xmlns="http://esb-sc. yw.zj.chinamobile.com"> <reqXml xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> <![CDATA[ <?xml version="1.0" encoding="UTF-8"?><RESP_PARAM><PUB_INFO><RETURN_RESULT>0</RETURN_RESULT><RETURN_DESC>操作成功</RETURN_DESC><OSB_SERIAL_NO>gateway-app-zt^16846071330000000001</OSB_SERIAL_NO></PUB_INFO><BUSI_INFO><GPRS_INFO><GPRS_IN>0</GPRS_IN><GPRS_OUT>0</GPRS_OUT><GPRS_OTHER>0</GPRS_OTHER><GPRS_DURA>0</GPRS_DURA><GPRS_FEE>0</GPRS_FEE></GPRS_INFO><MMS_INFO><MMS_AMOUNT>0</MMS_AMOUNT></MMS_INFO><SMS_INFO><TOTAL_MSG_NUM>15</TOTAL_MSG_NUM><OUT_MSG_NUM>0</OUT_MSG_NUM><INNER_MSG_NUM>0</INNER_MSG_NUM><MEN_MSG_NUM>15</MEN_MSG_NUM></SMS_INFO></BUSI_INFO></RESP_PARAM>]]> </reqXml> </ESB_CS_QRY_USED_RESUSED_001> </soapenv:Body> </soapenv:Envelope>

好的,以下是将该返回内容转换为 JSON 的方法: 1. 点击 Postman 中响应 Body 旁边的 `Code` 按钮,在弹出的对话框中选择 `Node.js - request` 代码片段。 2. 将代码片段中的 `body` 变量赋值为返回内容,即替换下面代码中的 `XMLRESPONSE`: ``` var body = `<xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/> <soapenv:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ESB_CS_QRY_USED_RESUSED_001 xmlns="http://esb-sc. yw.zj.chinamobile.com"> <reqXml xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> <![CDATA[ <?xml version="1.0" encoding="UTF-8"?><RESP_PARAM><PUB_INFO><RETURN_RESULT>0</RETURN_RESULT><RETURN_DESC>操作成功</RETURN_DESC><OSB_SERIAL_NO>gateway-app-zt^16846071330000000001</OSB_SERIAL_NO></PUB_INFO><BUSI_INFO><GPRS_INFO><GPRS_IN>0</GPRS_IN><GPRS_OUT>0</GPRS_OUT><GPRS_OTHER>0</GPRS_OTHER><GPRS_DURA>0</GPRS_DURA><GPRS_FEE>0</GPRS_FEE></GPRS_INFO><MMS_INFO><MMS_AMOUNT>0</MMS_AMOUNT></MMS_INFO><SMS_INFO><TOTAL_MSG_NUM>15</TOTAL_MSG_NUM><OUT_MSG_NUM>0</OUT_MSG_NUM><INNER_MSG_NUM>0</INNER_MSG_NUM><MEN_MSG_NUM>15</MEN_MSG_NUM></SMS_INFO></BUSI_INFO></RESP_PARAM> ]]> </reqXml> </ESB_CS_QRY_USED_RESUSED_001> </soapenv:Body> </soapenv:Envelope>`; ``` 3. 在代码片段中添加以下代码来将 XML 转换为 JSON: ``` var parseString = require('xml2js').parseString; parseString(body, function (err, result) { console.log(JSON.stringify(result)); }); ``` 4. 点击 `Send` 按钮,运行代码片段并在控制台中查看转换后的 JSON 结果。 以上就是将该返回内容转换为 JSON 的方法。希望对您有所帮助!

相关推荐

void SerialApp_ProcessMSGCmd( afIncomingMSGPacket_t *pkt ){ uint8 stat; uint8 seqnb; uint8 delay; switch ( pkt->clusterId ) { // A message with a serial data block to be transmitted on the serial port. case SERIALAPP_CLUSTERID1: // Store the address for sending and retrying. osal_memcpy(&SerialApp_RxAddr, &(pkt->srcAddr), sizeof( afAddrType_t )); seqnb = pkt->cmd.Data[0]; // Keep message if not a repeat packet if ( (seqnb > SerialApp_RxSeq) || // Normal ((seqnb < 0x80 ) && ( SerialApp_RxSeq > 0x80)) ) // Wrap-around { // Transmit the data on the serial port. if ( HalUARTWrite( SERIAL_APP_PORT, pkt->cmd.Data+1, (pkt->cmd.DataLength-1) ) ) { // Save for next incoming message SerialApp_RxSeq = seqnb; stat = OTA_SUCCESS; } else { stat = OTA_SER_BUSY; } } else { stat = OTA_DUP_MSG; } // Select approproiate OTA flow-control delay. delay = (stat == OTA_SER_BUSY) ? SERIALAPP_NAK_DELAY : SERIALAPP_ACK_DELAY; // Build & send OTA response message. SerialApp_RspBuf[0] = stat; SerialApp_RspBuf[1] = seqnb; SerialApp_RspBuf[2] = LO_UINT16( delay ); SerialApp_RspBuf[3] = HI_UINT16( delay ); osal_set_event( SerialApp_TaskID, SERIALAPP_RESP_EVT ); osal_stop_timerEx(SerialApp_TaskID, SERIALAPP_RESP_EVT); break; // A response to a received serial data block. case SERIALAPP_CLUSTERID2: if ((pkt->cmd.Data[1] == SerialApp_TxSeq) && ((pkt->cmd.Data[0] == OTA_SUCCESS) || (pkt->cmd.Data[0] == OTA_DUP_MSG))) { SerialApp_TxLen = 0; osal_stop_timerEx(SerialApp_TaskID, SERIALAPP_SEND_EVT); } else { // Re-start timeout according to delay sent from other device. delay = BUILD_UINT16( pkt->cmd.Data[2], pkt->cmd.Data[3] ); osal_start_timerEx( SerialApp_TaskID, SERIALAPP_SEND_EVT, delay ); } break; case SERIALAPP_CONNECTREQ_CLUSTER: SerialApp_ConnectReqProcess((uint8*)pkt->cmd.Data); case SERIALAPP_CONNECTRSP_CLUSTER: SerialApp_DeviceConnectRsp((uint8*)pkt->cmd.Data); default: break; }}每行代码注释

[max_resp_row, max_row] = max(response, [], 1); [init_max_response, max_col] = max(max_resp_row, [], 2); max_row_perm = permute(max_row, [2 3 1]); col = max_col(:)'; row = max_row_perm(sub2ind(size(max_row_perm), col, 1:size(response,3))); trans_row = mod(row - 1 + floor((use_sz(1)-1)/2), use_sz(1)) - floor((use_sz(1)-1)/2); trans_col = mod(col - 1 + floor((use_sz(2)-1)/2), use_sz(2)) - floor((use_sz(2)-1)/2); init_pos_y = permute(2pi * trans_row / use_sz(1), [1 3 2]); init_pos_x = permute(2pi * trans_col / use_sz(2), [1 3 2]); max_pos_y = init_pos_y; max_pos_x = init_pos_x; % pre-compute complex exponential exp_iky = exp(bsxfun(@times, 1i * ky, max_pos_y)); exp_ikx = exp(bsxfun(@times, 1i * kx, max_pos_x)); % gradient_step_size = gradient_step_size / prod(use_sz); ky2 = ky.ky; kx2 = kx.kx; iter = 1; while iter <= iterations % Compute gradient ky_exp_ky = bsxfun(@times, ky, exp_iky); kx_exp_kx = bsxfun(@times, kx, exp_ikx); y_resp = mtimesx(exp_iky, responsef, 'speed'); resp_x = mtimesx(responsef, exp_ikx, 'speed'); grad_y = -imag(mtimesx(ky_exp_ky, resp_x, 'speed')); grad_x = -imag(mtimesx(y_resp, kx_exp_kx, 'speed')); ival = 1i * mtimesx(exp_iky, resp_x, 'speed'); H_yy = real(-mtimesx(bsxfun(@times, ky2, exp_iky), resp_x, 'speed') + ival); H_xx = real(-mtimesx(y_resp, bsxfun(@times, kx2, exp_ikx), 'speed') + ival); H_xy = real(-mtimesx(ky_exp_ky, mtimesx(responsef, kx_exp_kx, 'speed'), 'speed')); det_H = H_yy . H_xx - H_xy . H_xy; % Compute new position using newtons method max_pos_y = max_pos_y - (H_xx .* grad_y - H_xy .* grad_x) ./ det_H; max_pos_x = max_pos_x - (H_yy .* grad_x - H_xy .* grad_y) ./ det_H; % Evaluate maximum exp_iky = exp(bsxfun(@times, 1i * ky, max_pos_y)); exp_ikx = exp(bsxfun(@times, 1i * kx, max_pos_x)); iter = iter + 1; end max_response = 1 / prod(use_sz) * real(mtimesx(mtimesx(exp_iky, responsef, 'speed'), exp_ikx, 'speed')); % check for scales that have not increased in score ind = max_response < init_max_response; max_response(ind) = init_max_response(ind); max_pos_y(ind) = init_pos_y(ind); max_pos_x(ind) = init_pos_x(ind); [max_scale_response, sind] = max(max_response(:)); disp_row = (mod(max_pos_y(1,1,sind) + pi, 2pi) - pi) / (2pi) * use_sz(1); disp_col = (mod(max_pos_x(1,1,sind) + pi, 2pi) - pi) / (2pi) * use_sz(2); end代码详解

最新推荐

recommend-type

java+毕业设计+扫雷(程序).rar

ensp校园网络毕业设计,java+毕业设计+扫雷(程序)
recommend-type

【图像增强】 GUI同态滤波图像增晰(含高斯滤波、一阶、二阶巴特沃斯滤波)【含Matlab源码 4397期】.zip

Matlab领域上传的视频均有对应的完整代码,皆可运行,亲测可用,适合小白; 1、代码压缩包内容 主函数:main.m; 调用函数:其他m文件;无需运行 运行结果效果图; 2、代码运行版本 Matlab 2019b;若运行有误,根据提示修改;若不会,私信博主; 3、运行操作步骤 步骤一:将所有文件放到Matlab的当前文件夹中; 步骤二:双击打开main.m文件; 步骤三:点击运行,等程序运行完得到结果; 4、仿真咨询 如需其他服务,可私信博主或扫描视频QQ名片; 4.1 博客或资源的完整代码提供 4.2 期刊或参考文献复现 4.3 Matlab程序定制 4.4 科研合作
recommend-type

Wox全局搜索工具,一款win下的全局搜索软件

Wox全局搜索工具类似mac的全局搜索功能,在win下可以实时搜索电脑上安装的软件及文档,节省了找文档的时间,可在在不会到桌面的情况下使用Alt+回车搜索需要的内容。
recommend-type

C语言程序判断回文素数

附件是判断回文素数C语言程序,这个程序首先定义了两个函数:isPrime 用于判断一个数是否为素数,isPalindrome 用于判断一个数是否为回文。然后在 main 函数中,通过一个循环来检查从2到999(这里假设我们只需要检查小于1000的数)的所有数,如果一个数既是素数又是回文数,就将其打印出来。 请注意,这个程序只检查了小于1000的数。如果需要检查更大的范围,可以相应地调整循环的上限。此外,素数判断的效率并不是最优的,对于大数的判断,可能需要更高效的算法。
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

云原生架构与soa架构区别?

云原生架构和SOA架构是两种不同的架构模式,主要有以下区别: 1. 设计理念不同: 云原生架构的设计理念是“设计为云”,注重应用程序的可移植性、可伸缩性、弹性和高可用性等特点。而SOA架构的设计理念是“面向服务”,注重实现业务逻辑的解耦和复用,提高系统的灵活性和可维护性。 2. 技术实现不同: 云原生架构的实现技术包括Docker、Kubernetes、Service Mesh等,注重容器化、自动化、微服务等技术。而SOA架构的实现技术包括Web Services、消息队列等,注重服务化、异步通信等技术。 3. 应用场景不同: 云原生架构适用于云计算环境下的应用场景,如容器化部署、微服务
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依