ps_copy.cpp

  name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-5572165936844014&dt=1194442938015&lmt=1194190197&format=336x280_as&output=html&correlator=1194442937843&url=file%3A%2F%2F%2FC%3A%2FDocuments%2520and%2520Settings%2Flhh1%2F%E6%A1%8C%E9%9D%A2%2FCLanguage.htm&color_bg=FFFFFF&color_text=000000&color_link=000000&color_url=FFFFFF&color_border=FFFFFF&ad_type=text&ga_vid=583001034.1194442938&ga_sid=1194442938&ga_hid=1942779085&flash=9&u_h=768&u_w=1024&u_ah=740&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="336" scrolling="no" height="280" allowtransparency="allowtransparency"> //  If you use Visual C++, set the compile options to /GX
#ifdef __BCPLUSPLUS__
#include <iostream.h>
#include <vector.h>
#include <algorith.h>
#else
#include <iostream>
#include <vector>
#include <algorithm>
#endif

using namespace std;

void main(void)
{
 const int VECTOR_SIZE = 8;

 //Define a template class vector of int
 typedef vector<int> IntVector;

 //Define an interator for template class vector of strings
 typedef IntVector::iterator IntVectorIt;

 IntVector Numbers(VECTOR_SIZE);
 IntVector Result(4);

 IntVectorIt start, end, it;

 //Initialize vector Numbers
 Numbers[0] = 4;
 Numbers[1] = 10;
 Numbers[2] = 70;
 Numbers[3] = 30;
 Numbers[4] = 10;
 Numbers[5] = 69;
 Numbers[6] = 96;
 Numbers[7] = 7;

 start = Numbers.begin(); //location of first
        //element of Numbers

 end = Numbers.end();  //one past the location
        //last element of Numbers

 cout << "Before calling partial_sort_copy/n" << endl;

 //print content of Numbers
 cout << "Numbers { ";
 for (it = start; it != end; it++)
  cout << *it << " ";
 cout << "/b }/n" << endl;

 //sort the smallest 4 elemetns in the Numbers
 //and copy the results in Result
 partial_sort_copy(start, end, Result.begin(), Result.end());

 cout << "After calling partial_sort_copy/n" << endl;

 cout << "Numbers { ";
 for(it = start; it != end; it++)
  cout << *it << " ";
 cout << "/b }/n" << endl;

 cout << "Result { ";
 for(it = Result.begin(); it != Result.end(); it++)
  cout << *it << " ";
 cout << "/b }/n" << endl;
}

void nfc_ncif_cmd_timeout(void) { DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("nfc_ncif_cmd_timeout(): enter"); #if (NXP_EXTNS == TRUE) DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("Start Middleware Recovery Procedure"); { // TO DO: // Sending command which are core_reset,init,discovery as raw packet (Hard // coding) // and we have to match the RF state between before entering recovery and // after recovery. // finally, executing the last command which is before entering recovery, // and invoking the callback. // step 1. Sending core reset/init command // step 2. deciding to send command whether discovery or not. // step 3. invoking the callback function which is registered at last time // before entering recovery. /* consist of buffer(p_core_init_rsp_params) buffer[0] = Indicators 0:Normal mode 1:Recovery mode 2:core reset was last command 3:core init was last command buffer[1] = Last NFCC NCI RF State, 0:IDLE 1:DISCOVERY buffer[2] = Length of discovery command to be sent as a part of recovery. buffer[3~34] = Last Discovery command(including phase data).(32 byte) buffer[35] = Indicator 0: No command to be sent after Recovery 1: Command available to be sent after recovery buffer[36~294] = Last Command /or Last Command including Data. buffer[295] = Last screen state */ uint8_t* buffer = nullptr; tNFC_CONN_CB* p_cb = nullptr; uint16_t bufflen = 36 + 258 + 2; //Initial data + max command size + 1 extra buffer + 1 screenState uint16_t fw_dwnld_status = NFC_STATUS_FAILED; tNFC_STATUS status = NFC_STATUS_FAILED; tNFC_FWUpdate_Info_t fw_update_inf; nfc_nci_IoctlInOutData_t inpOutData; /*Stop the command timeout timer*/ nfc_stop_timer(&nfc_cb.nci_wait_rsp_timer); buffer = (uint8_t*)malloc(bufflen * sizeof(uint8_t)); if (nullptr == buffer) { LOG(ERROR) << StringPrintf("Recovery MEM Allocation is failed!!"); return; } memset(buffer, 0x00, (bufflen * sizeof(uint8_t))); /*We need to send Core Reset and Core Init as a part of recovery*/ buffer[0] = 0x01; /*Set the last screen state*/ buffer[295] = gScreenState; DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("MW last RF discovery flags 0x%x", nfa_dm_cb.disc_cb.disc_flags); DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("MW last RF discovery state 0x%x", nfa_dm_cb.disc_cb.disc_state); if (nfc_cb.nfc_state == NFC_STATE_CORE_INIT) { #if (NXP_EXTNS == TRUE) if(nfcFL.nfccFL._NFCC_MW_RCVRY_BLK_FW_DNLD) { DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( "MW recovery should abort FW download checking at time of " "cmd_timeout"); } else { DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("Force FW Download !"); nfc_cb.p_hal->ioctl(HAL_NFC_IOCTL_CHECK_FLASH_REQ, &inpOutData); fw_update_inf = *(tNFC_FWUpdate_Info_t*)&inpOutData.out.data.fwUpdateInf; nfc_cb.p_hal->ioctl(HAL_NFC_IOCTL_FW_DWNLD, &inpOutData); fw_dwnld_status = inpOutData.out.data.fwDwnldStatus; DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("FW Download 0x%x", fw_dwnld_status); if (fw_dwnld_status != NFC_STATUS_OK) nfc_enabled(NFC_STATUS_FAILED, nullptr); } #else DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("Force FW Download !"); nfc_cb.p_hal->ioctl(HAL_NFC_IOCTL_CHECK_FLASH_REQ, &fw_update_inf); nfc_cb.p_hal->ioctl(HAL_NFC_IOCTL_FW_DWNLD, &fw_dwnld_status); DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("FW Download 0x%x", fw_dwnld_status); if (fw_dwnld_status != NFC_STATUS_OK) nfc_enabled(NFC_STATUS_FAILED, nullptr); #endif } /*For debug purpose,register dump when CORE_RESET_NTF happens*/ if (core_reset_init_num_buff) { uint8_t stat = 0; stat = nfc_hal_nfcc_get_reset_info(); if (stat != NCI_STATUS_OK) DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("Failed to get reset info"); } /*Prepare the DISCOVERY command*/ if (!(nfa_dm_cb.disc_cb.disc_state > NFA_DM_RFST_IDLE)) { DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("NFCC last NCI RF state is IDLE"); /*NCI stack RF state set to IDLE*/ buffer[1] = 0x00; } else { uint8_t* ps = (uint8_t*)nfc_cb.p_last_disc; DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("NFCC last NCI RF state is DISCOVERY"); /*Last NFCC state set to DISCOVERY*/ buffer[1] = 0x01; /*NCI stack RF state set to DISCOVERY*/ nfa_dm_cb.disc_cb.disc_state = 0x01; /*Listen Mode flags initialized to 0x00*/ nfa_ce_cb.flags = 0x00; if (ps[0]) { /*Set the length of last DISCOVERY packet including header*/ buffer[2] = 2 + 1 + 1 + (ps[0] * 2); /*HDR(2) + Length(1) + Configs(1) + Data(TechnMode(2) * 2)*/ /*Copy the DISCOVERY command header*/ memcpy((uint8_t*)&buffer[3], "\x21\x03", 2); /*Set the length of content of the last DISCOVERY command*/ buffer[5] = 1 + (ps[0] * 2); /*Configs(1) + Data(TechnMode(2) * 2)*/ /*Copy the content of DISCOVERY command*/ memcpy((uint8_t*)&buffer[6], ps, buffer[5]); } else { buffer[2] = 0x1A; /*Length of hard coded recovery discovery command*/ memcpy((uint8_t*)&buffer[3], "\x21\x03\x17\x0B\x00\x01\x01\x01\x02\x01\x03\x01\x80\x01\x81" "\x01\x82\x01\x83\x01\x85\x01\x06\x01\x77\x01", 24); } } /*Prepare the last command sent just before CORE_RESET_NTF*/ if (((nfc_cb.last_hdr[0] == 0x21 && nfc_cb.last_hdr[1] == 0x06) && (nfc_cb.last_cmd_buf[0] == 0x01 && nfc_cb.last_cmd_buf[1] == 0x01)) || /*DEACTIVATE TO SLEEP*/ (nfc_cb.last_hdr[0] == 0x21 && nfc_cb.last_hdr[1] == 0x04) || /**/ (nfc_cb.last_hdr[0] == 0x21 && nfc_cb.last_hdr[1] == 0x08) || /**/ ((nfc_cb.last_hdr[0] == 0x21 && nfc_cb.last_hdr[1] == 0x06) && /*DEACTIVATE TO DISCOVERY*/ (nfc_cb.last_cmd_buf[0] == 0x01 && nfc_cb.last_cmd_buf[1] == 0x03))) { buffer[35] = 0x00; /*No need to send last command*/ } else if ((nfc_cb.last_hdr[0] == 0x20 && (nfc_cb.last_hdr[1] == 0x02 || nfc_cb.last_hdr[1] == 0x03)) || /*SET CONFIG COMMAND*/ (nfc_cb.last_hdr[0] == 0x2F && nfc_cb.last_hdr[1] == 0x15) || /*PROPRIETARY COMMAND*/ (nfc_cb.last_hdr[0] == 0x21 && nfc_cb.last_hdr[1] == 0x01) || /*LISTEN ROUTING COMMAND*/ ((nfc_cb.last_hdr[0] == 0x21 && nfc_cb.last_hdr[1] == 0x06) && (nfc_cb.last_cmd_buf[0] == 0x01 && nfc_cb.last_cmd_buf[1] == 0x00)) /*DEACTIVATE TO IDLE*/ ) { /*Set indicating last command is available to be sent after recovery*/ buffer[35] = 0x01; /*Copy the last HEADER*/ memcpy(&buffer[36], nfc_cb.last_hdr, NFC_SAVED_HDR_SIZE); /*Copy the last command*/ memcpy(&buffer[38], nfc_cb.last_cmd_buf, nfc_cb.cmd_size + 1); } else /*either CORE_RESET or CORE_INIT was the last command*/ { /*Set indicating last command is available to be sent after recovery*/ buffer[35] = 0x01; memcpy(&buffer[36], nfc_cb.last_hdr, NFC_SAVED_HDR_SIZE); buffer[38] = nfc_cb.cmd_size; /*Length of last command*/ if (nfc_cb.cmd_size > 0) /*last command was CORE_RESET*/ memcpy(&buffer[39], nfc_cb.last_cmd, NFC_SAVED_CMD_SIZE); else buffer[35] = 0x00; /*last command was CORE_INIT*/ if (nfc_cb.last_hdr[0] == 0x20 && nfc_cb.last_hdr[1] == 0x00) buffer[0] = 2; /*indicate last command was CORE_RESET*/ else if (nfc_cb.last_hdr[0] == 0x20 && nfc_cb.last_hdr[1] == 0x01) buffer[0] = 3; /*indicate last command was CORE_INIT*/ } /* if HCI state is in wait for response then stop the timer and send the * response timeout event to the upper layer*/ if (nfa_hci_cb.hci_state == NFA_HCI_STATE_WAIT_RSP) { NFC_HDR* p_msg; nfa_sys_stop_timer(&nfa_hci_cb.timer); if ((p_msg = (NFC_HDR*)GKI_getbuf(sizeof(NFC_HDR))) != nullptr) { DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( "nfc_ncif_cmd_timeout(): Sending HCI response timeout to upper " "layer"); p_msg->event = NFA_HCI_RSP_TIMEOUT_EVT; p_msg->layer_specific = 0; nfa_sys_sendmsg(p_msg); } } if (0xFF != nfcc_dh_conn_id) { /* Flush the data if any before proceeding further with the recovery */ p_cb = nfc_find_conn_cb_by_conn_id(nfcc_dh_conn_id); if (nullptr != p_cb) { DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("nfc_ncif_cmd_timeout(): connection id %d", nfcc_dh_conn_id); status = NFC_FlushData(p_cb->conn_id); if (status != NFC_STATUS_OK) { LOG(ERROR) << StringPrintf("nfc_ncif_cmd_timeout(): NFC data flush failed"); } } } DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( "nfc_ncif_cmd_timeout(): Indicator:0x%02X disc cmd len:0x%02X last cmd " "len:0x%02X", buffer[0], buffer[2], buffer[38]); nfc_cb.p_hal->core_initialized(bufflen, buffer); if (buffer != nullptr) free(buffer); DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("nfc_ncif_cmd_timeout(): exit"); } #else /* report an error */ nfc_ncif_event_status(NFC_GEN_ERROR_REVT, NFC_STATUS_HW_TIMEOUT); nfc_ncif_event_status(NFC_NFCC_TIMEOUT_REVT, NFC_STATUS_HW_TIMEOUT); /* if enabling NFC, notify upper layer of failure */ if (nfc_cb.nfc_state == NFC_STATE_CORE_INIT) { nfc_enabled(NFC_STATUS_FAILED, nullptr); } /* XXX maco since this failure is unrecoverable, abort the process */ abort(); #endif }怎么在#if (NXP_EXTNS == TRUE)的外面再加一层(last_cmd.data != nullptr) 的判断
最新发布
09-10
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值