Bluetooth sending and receiving data too large requires subcontracting-packet processing

Source: Internet
Author: User

{static unsigned char bt_rxdata_merge_status=bt_rxdata_merge_defaul_status;//means an IAP packet is sent by a bt_rxdata if (bt_ Rxdata_merge_status==bt_rxdata_merge_defaul_status && 0x55==bt_rxdata->msgdata[2]) {//detect the length of the IAP packet First// IAP packet: Length field data contains 1 or 3 bytes, depending on the length of the payload//one-byte domain can behave in a single byte 0x02 to 0xFC (2 to 252) load length//Three bytes field data contains 0x00 tag bytes, 2 bytes payload Length field values followed immediately, range from 0X00FD to 0xFFFA (253 to 65529). if (0x00! = bt_rxdata->msgdata[3])//IAP length is single byte {//parsing IAP data bt_iap_cmdlist_typedef * Iap_data = (bt_iap_cmdlist_ TYPEDEF *) malloc (sizeof (BT_IAP_CMDLIST_TYPEDEF)); if (iap_data==null) {return;} memset (iap_data, 0, sizeof (bt_iap_cmdlist_typedef)); Iap_data->len = Bt_rxdata->msgdata[3];iap_data->lingo _id = bt_rxdata->msgdata[4];iap_data->command_id = bt_rxdata->msgdata[5];iap_data->trans_id = (Bt_ RXDATA-&GT;MSGDATA[6] << 8) | (Bt_rxdata->msgdata[7] & 0xff);//bt_rxdata->msglength=start+len+lingo_id+command_id+trans_id+checksum+ paybufmemcpy (Iap_data->rece_buf, & (Bt_rxdata->msgdata[8]), bt_rxdata->MSGDATA[1]-7);//Insert a complete IAP data into the linked list bt_iapcommand_cmdlistinsertcmd (iap_data);//IAP authentication starts processing the EA Channel if ( Getcurbtiapauthenticatedstatus () ==bt_iap_success) {iap_packet_deal ();}       Reset bt_rxdata_merge_status flag bit bt_rxdata_merge_status=bt_rxdata_merge_defaul_status;} else if (0x00==bt_rxdata->msgdata[3])//IAP has a length of three bytes and is marked with 0x00, and the last two bytes are the lengths of the IAP, which is obviously greater than the maximum length of bt_rxdata of 256, Need to subcontract {iap_point = 0;memset (iap_payloadbuf, 0, max_iap_data_buffer);//bt_rxdata->msgdata[1]=start+len+lingo_id+ Command_id+trans_id+checksum+paybuf//0x99 after the opening of the user data length//Save the length of the IAP Packet iap_data_len= (Bt_rxdata->msgdata[4] < < 8) | (Bt_rxdata->msgdata[5] & 0xff); memcpy (Iap_payloadbuf + iap_point, & (Bt_rxdata->msgdata[2]), bt_rxdata- &GT;MSGDATA[1]); iap_point=iap_point+bt_rxdata->msgdata[1];//reset the bt_rxdata_merge_status flag bit requires a subcontracting process Bt_rxdata_ Merge_status=bt_rxdata_merge_middle_status;}} else if (bt_rxdata_merge_status==bt_rxdata_merge_middle_status) {memcpy (Iap_payloadbuf + iap_point, & (Bt_RxData- &GT;MSGDATA[2]), BT_RXDATA-&GT;MSGDATA[1]); iap_point=iap_point+bt_rxdata->msgdata[1];//compare whether the cached data is already able to form a complete IAP packet if ((IAP_ POINT-5) >=iap_data_len) {//iap_point=iap_data_len+sizeof (start) +sizeof (len) +sizeof (checksum) =iap_data_len+5/ /Parse IAP data bt_iap_cmdlist_typedef * iap_data = (Bt_iap_cmdlist_typedef *) malloc (sizeof (BT_IAP_CMDLIST_TYPEDEF)); if (IAP _data==null) {return;} memset (iap_data, 0, sizeof (bt_iap_cmdlist_typedef)); Iap_data->len = (iap_payloadbuf[2] << 8) | (Iap_payloadbuf[3] & 0xff); iap_data->lingo_id =iap_payloadbuf[4];iap_data->command_id = iAP_PayLoadBuf[5] ; iap_data->trans_id = (Iap_payloadbuf[6] << 8) | (Iap_payloadbuf[7] & 0xff);//bt_rxdata->msglength=start+len+lingo_id+command_id+trans_id+checksum+ paybufmemcpy (Iap_data->rece_buf, & (Iap_payloadbuf[8]), iap_point-9);//Insert a complete IAP data into the list Bt_iapcommand_ Cmdlistinsertcmd (iap_data);//IAP authentication starts processing the EA Channel if (Getcurbtiapauthenticatedstatus () ==bt_iap_success) {iap_packet_ Deal ();} Reset the BT_RXDATA_MERGE_STATUS flag bit to initialize the state of BT_rxdata_merge_status=bt_rxdata_merge_defaul_status;} else if ((iap_point-5) <iap_data_len) {//Reset the BT_RXDATA_MERGE_STATUS flag bit requires a subcontracting process Bt_rxdata_merge_status=bt_rxdata_ merge_middle_status;//packet processing Count iap_merge_test++;}}}

Bluetooth sending and receiving data too large requires subcontracting-packet processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.