Logo Search packages:      
Sourcecode: garmindev version File versions  Download package

int CSerial::syncup ( int  responseCount = 0  )  [virtual]

sync. up sequence

This must be called prior to any other request.

Parameters:
responseCount Number of response packets to expect
Returns:
Actual retrieved number of response packets to product_request

Definition at line 422 of file CSerial.cpp.

References read(), and write().

{
    Packet_t command;
    Packet_t response;
    /* speed improvement when remembering last numer of packets
       to this request as we will not run in long timeout
       if syncup should be called a second time */
    static int last_response = 0;
    int counter = 0;

    if (!last_response && responseCount > 0)
        last_response = responseCount;

    command.type = 0;
    command.id   = Pid_Product_Rqst;
    command.size = 0;

    CSerial::write(command);

    protocolArraySize = 0;
    while(CSerial::read(response)) {
        if(response.id == Pid_Product_Data) {
            //TODO read data
            Product_Data_t * pData = (Product_Data_t*)response.payload;
            productId       = pData->product_id;
            softwareVersion = pData->software_version;
            productString   = pData->str;
#ifdef DBG
            cout << hex << productId << " " << dec << softwareVersion << " " << productString << endl;
#endif
        }
        /* TODO
                    if(response.id == Pid_Ext_Product_Data){
                        //TODO read data
                    }
        */

        if(response.id == Pid_Protocol_Array) {
            //TODO read data
            Protocol_Data_t * pData = (Protocol_Data_t*)response.payload;
            for(uint32_t i = 0; i < response.size; i += sizeof(Protocol_Data_t)) {
#ifdef DBG
                cout << "Protocol: "<< (char)pData->tag <<  dec << pData->data << endl;
#endif
                ++protocolArraySize;
                protocolArray[protocolArraySize].tag = pData->tag;
                protocolArray[protocolArraySize].data = pData->data;
                ++pData;
            }
            ++protocolArraySize;
#ifdef DBG
            cout << "protocolArraySize:" << protocolArraySize << endl;
#endif
        }

        ++counter;
        if (last_response && counter == last_response)
            break;
    }
    if (!last_response)
        last_response = counter;

    return counter;
}


Generated by  Doxygen 1.6.0   Back to index