设为首页 加入收藏

TOP

C:TLV消息编码及常用操作(二)
2015-01-22 20:57:43 来源: 作者: 【 】 浏览:47
Tags:TLV 消息 编码 常用 操作
pMsg1, unsigned int ulMsgLen1, unsigned char *pMsg2, unsigned int ulMsgLen2, unsigned int *ulSameNum) { /*创建有序消息链表1*/ Msg *pMsgList1 = NULL; if (ERR == CreateSortMsgList(pMsg1, ulMsgLen1, pMsgList1)) { DestoryMsgList(pMsgList1); return ERR; } /*创建有序消息链表2*/ Msg *pMsgList2 = NULL; if (ERR == CreateSortMsgList(pMsg2, ulMsgLen2, pMsgList2)) { DestoryMsgList(pMsgList1); DestoryMsgList(pMsgList2); return ERR; } Msg *p = pMsgList1->pNext; Msg *q = NULL; unsigned int iCount = 0; /*比较消息*/ while(NULL != p) { q = pMsgList2->pNext; while(NULL != q) { if (OK == IsSameIE(&(p->ie), &(q->ie))) { iCount++; } q = q->pNext; } p = p->pNext; } DestoryMsgList(pMsgList1); DestoryMsgList(pMsgList2); *ulSameNum = iCount; return OK; } int main(int argc, char* argv[]) { unsigned char pMsg[] = {0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01,0x01,0x01, 0x01, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x02,0x02,0x02, 0x02, 0x02, 0x02, 0x02, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03,0x03,0x03, 0x03, 0x03, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01,0x01,0x01, 0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x08,0x08, 0x01, 0x00, 0x01, 0x00, 0x04, 0x00, 0x09,0x09,0x09, 0x09}; unsigned char pMsg2[] = {0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01,0x01,0x01, 0x01, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x02,0x02,0x02, 0x02, 0x02, 0x02, 0x02, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03,0x03,0x03, 0x03, 0x03, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01,0x01,0x01, 0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x08,0x08, 0x01, 0x00, 0x01, 0x00, 0x04, 0x00, 0x09,0x09,0x09, 0x09}; int iLen = sizeof(pMsg) / sizeof(pMsg[0]); for (int i = 0; i < iLen; i++) { printf("0x%x,", pMsg[i]); } printf("\n\n"); unsigned char *pSortMsg = (unsigned char *)malloc(iLen); if (NULL == pSortMsg) { return ERR; } if (ERR != Sort(pMsg, iLen, pSortMsg)) { for (int i = 0; i < iLen; i++) { printf("0x%x,", pSortMsg[i]); } } int iLen2 = sizeof(pMsg2) / sizeof(pMsg2[0]); unsigned int iSameNum = 0; if (ERR != CompareMsg(pMsg, iLen, pMsg2, iLen2, &iSameNum)) { printf("\nSame Number is %d", iSameNum); } getchar(); return 0; }


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C语言其实不简单:sizeof 下一篇Objective-C调用Swift

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: