zoukankan      html  css  js  c++  java
  • CDT报文分次上传的合并

    对于将一段报文进行分段上传,需要将它合并,并去除其中同步字之前的报文,

    报文分段上传对于多个设备同时连接可能有影响

    char* memstr(char* full_data, int full_data_len, char* substr) {
        if (full_data == NULL || full_data_len <= 0 || substr == NULL) 
            return NULL;
        if (*substr == '') 
            return NULL;
        int sublen = strlen(substr);
        int i;
        char* cur = full_data;
        int last_possible = full_data_len - sublen + 1;
        for (i = 0; i < last_possible; i++) {
            if (*cur == *substr) {
                if (memcmp(cur, substr, sublen) == 0) {
                    return cur;
                }
            }
            cur++;
        }
        return NULL;
    }
    
    int MSGADD(unsigned char* recv_data, signed int recv_size, unsigned char** history_data, int historylen) {//将报文叠加起来
        if ((historylen) == 0) {
            historylen = recv_size;
            (*history_data) = chk_calloc(historylen, sizeof (ST_UCHAR));
            memcpy((*history_data), recv_data, (historylen));
        } else {
            ST_UCHAR *temprecv = chk_calloc(historylen + recv_size, sizeof (ST_UCHAR));
            memcpy(temprecv, (*history_data), (historylen));
            memcpy(temprecv + historylen, recv_data, recv_size);
            chk_free((*history_data));
            (*history_data) = temprecv;
            historylen = historylen + recv_size;
        }
        return historylen;
    }
    ST_INT MSG_superposition(ST_UCHAR *recv_data, ST_INT recv_size){
         static ST_UCHAR needle[7] = {0xeb, 0x90, 0xeb, 0x90, 0xeb, 0x90, ''};
        static ST_UCHAR *history_data = NULL;
        static int historylen = 0;
        ST_UCHAR *indexstr;
        historylen = MSGADD(recv_data, recv_size, &history_data, historylen);
        chk_free(recv_data);
        recv_data=NULL;
        recv_size = 0;if ((indexstr = memstr(history_data, historylen, needle)) == NULL)
            return -2;
        else if (indexstr != history_data) {//去除不正确报文
            int templen = indexstr - history_data;
            memcpy(history_data, history_data + templen, historylen - templen);
            historylen -= templen;
        } else {
            if ((indexstr = memstr(indexstr + 6, historylen - (indexstr - history_data + 6), needle)) == NULL)
                return -2;
            else {
                recv_size = indexstr - history_data;
                recv_data = chk_calloc(recv_size, sizeof (ST_UCHAR));
                memcpy(recv_data, history_data, recv_size);
                memcpy(history_data, history_data + recv_size, historylen - recv_size);
                historylen -= recv_size;
            }
        }


      return recv_size;

      //printf("revvdata: ");
      //printdata(recv_data, recv_size);

    
    }
  • 相关阅读:
    阿里云服务器 FTP配置图文教程和添加两个FTP站点
    SAP 用事务码SQVI 做简单报表 .
    公司间联动权限解决方案
    table合并单元格colspan和rowspan .
    js更改input标签的读写属性
    小div在大div中垂直居中,以及div在页面垂直居中
    UI控件(UITextField)
    node基本理念(事件、多线程、进程)
    MyBatis(跨表查询)
    MyBatis(增删改查)
  • 原文地址:https://www.cnblogs.com/skycandy/p/9086821.html
Copyright © 2011-2022 走看看