void CProfileRepoServerClb::removeProfileImplementationPl(const RepoRequest * req, UInt32 payloadSize, UInt8* const pResponseBuffer, UInt32& bufferSize)
 {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
    UID uid(bufferToString(req->data));
    int pos = stringInBufSize(uid.value);
    std::string platform = bufferToString(req->data + pos);
    CError err = mProfileDB.removeProfileImplementation(uid,platform);
    UInt32 code = err.getCode();
    memcpy (pResponseBuffer, &code, 4);
    bufferSize = 4;
 }
示例#2
0
void PmpPimProtocol::onProfileDied(PMPFrame * pFrame)
{
    assert(pFrame);
    assert(mEventFactory);

    std::string str = bufferToString(pFrame->data,true);
    unsigned int pos = stringInBufSize(str);
    iviLink::Profile::IUid piuid(str);
    str = bufferToString(pFrame->data + pos,true);
    iviLink::Service::Uid sid(str);

    mEventFactory->pimProtocolProfileDied(piuid, sid);
}
 void CProfileRepoServerClb::addProfileImplementation(const RepoRequest * req, UInt32 payloadSize, UInt8* const pResponseBuffer, UInt32& bufferSize)
 {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
    UID uid(bufferToString(req->data));
    int pos = stringInBufSize(uid.value);
    iviLink::LibDescriptor ld;
    ld.libPath = bufferToString(req->data + pos);
    pos += stringInBufSize(ld.libPath);
    ld.platform = bufferToString(req->data + pos);
    CError err = mProfileDB.addProfileImplementation(uid,ld);
    UInt32 code = err.getCode();
    memcpy (pResponseBuffer, &code, 4);
    bufferSize = 4;
 }
示例#4
0
      CError CPmpCoreProtocol::getAvailableProfileComplements(std::list<Profile::Uid> & complements)
      {
         LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
         PMPFrame * pReq = new PMPFrame;
         pReq->size = sizeof(PMPFrame);
         pReq->reqType = PMP_REQ_CORE_GET_COMPLEMENTS;

         PMPFrame * pResp = mpPmpProtocol->makeCoreRequest(*pReq);
         delete pReq;

         if (!pResp)
         {
            LOG4CPLUS_ERROR(msLogger, "Network error");
            return CPmpError(CPmpError::ERROR_NETWORK);
         }

         UInt32 count;
         memcpy(&count,pResp->data,4);
         count = ByteOrder::ntoh32(count);
         int pos = 4;
         LOG4CPLUS_INFO(msLogger, "RES COUNT : " + convertIntegerToString(count));
         for (UInt32 i = 0; i<count; ++i)
         {
            std::string str = bufferToString(pResp->data+pos,true);
            complements.push_back(Profile::Uid(str));
            pos += stringInBufSize(str);
         }

         delete[] pResp;
         return CPmpError::NoPmpError();
      }
示例#5
0
void PmpSessionProtocol::onReceivedServicesList(PMPFrame * frame)
{
    LOG4CPLUS_TRACE_METHOD(mLogger, __PRETTY_FUNCTION__ );
    assert(mEventFactory);

    if (!frame)
    {
        LOG4CPLUS_ERROR(mLogger, "No frame");
        return;
    }

    UInt32 count;
    memcpy(&count,frame->data,sizeof(count));
    count = ByteOrder::ntoh32(count);
    int pos = sizeof(count);
    LOG4CPLUS_INFO(mLogger, "RES COUNT : " + convertIntegerToString(count));
    std::list<Service::Uid> services;

    for (UInt32 i = 0; i<count; ++i)
    {
        std::string str = bufferToString(frame->data+pos,true);
        services.push_back(Service::Uid(str));
        pos += stringInBufSize(str);
    }
    mEventFactory->receiveRemoteWaitingServiceList(services);
}
void CharacteristicsEditor::updateCharacteristicValue(const uint8_t *value, uint16_t length)
{
    const QString textValue = bufferToString(value, length);

    setCharacteristicValue(textValue);
    setCharacteristicValueText(textValue);
}
void CharacteristicsEditor::readCharacteristicValue()
{
    if ((m_characteristicProperties & GATT_CHARACTERISTIC_PROP_READ) == 0) {
        setErrorMessage("GATT descriptors: Read not permitted");
        return;
    }

    uint8_t *characteristicBuffer = (uint8_t *)alloca(m_characteristicMTU);
    if (!characteristicBuffer) {
        setErrorMessage("GATT characteristic: Not enough memory");
        bt_gatt_disconnect_instance(m_gattInstance);
        return;
    }

    QString descriptorString;

    int byteCount = 0;
    uint8_t more = 1;
    for (int offset = 0; more; offset += byteCount) {
        byteCount = bt_gatt_read_value(m_gattInstance, m_characteristicValueHandle.toUShort(), offset, characteristicBuffer, m_characteristicMTU, &more);
        if (byteCount < 0) {
            setErrorMessage(QString("Unable to read characteristic value: %1 (%2)").arg(errno).arg(strerror(errno)));
            break;
        }

        descriptorString += bufferToString(characteristicBuffer, byteCount);
    }

    setCharacteristicValue(descriptorString);
    setCharacteristicValueText(descriptorString);
}
 void CProfileRepoServerClb::getManifest(const RepoRequest * req, UInt32 payloadSize, UInt8* const pResponseBuffer, UInt32& bufferSize)
 {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
    UID uid(bufferToString(req->data));
    std::string strRes = mProfileDB.getManifest(uid);
    stringToBuffer(strRes,pResponseBuffer);
    bufferSize = stringInBufSize(strRes);
 }
 void CProfileRepoServerClb::addProfile(const RepoRequest * req, UInt32 payloadSize, UInt8* const pResponseBuffer, UInt32& bufferSize)
 {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
    CError err = mProfileDB.addProfile(bufferToString(req->data));
    UInt32 code = err.getCode();
    memcpy (pResponseBuffer, &code,4);
    bufferSize = 4;
 }
示例#10
0
      void CPmpPimClbCtrl::onProfileDied(PMPFrame * pFrame)
      {
         std::string str = bufferToString(pFrame->data,true);
         unsigned int pos = stringInBufSize(str);
         iviLink::Profile::IUid piuid(str);
         str = bufferToString(pFrame->data + pos,true);
         iviLink::Service::Uid sid(str);

         mpPimClb->onProfileDied(piuid,sid);

         PMPFrame pResp;
         pResp.size = sizeof(PMPFrame);
         pResp.frameType = PMP_FRAME_TYPE_RESPONSE;
         pResp.id = pFrame->id;
         pResp.client = pFrame->client;
         pResp.reqType = pFrame->reqType;

         mpProtocol->makeResponse(pResp);
      }
      void CProfileRepoServerClb::findProfiles(const RepoRequest * req, UInt32 payloadSize, UInt8* const pResponseBuffer, UInt32& bufferSize)
      {
         LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
         UID uid(bufferToString(req->data));
         int pos = stringInBufSize(uid.value);
         std::string platform = bufferToString(req->data + pos);
         pos += stringInBufSize(platform);
         UInt32 count;
         memcpy (&count,req->data+pos, 4);
         pos += 4;
         std::map <std::string, std::string> args;

         for (UInt32 i=0; i<count; ++i)
         {
            std::string key = bufferToString(req->data+pos);
            pos += stringInBufSize(key);
            std::string val = bufferToString(req->data+pos);
            pos += stringInBufSize(val);
            args[key] = val;
         }

         std::list<LibInfo> inf = mProfileDB.findProfiles(uid,args,platform);

         UInt32 rCount = inf.size();
         memcpy (pResponseBuffer,&rCount,sizeof(rCount));
         int outPos = sizeof(rCount);

         for (std::list<LibInfo>::const_iterator it = inf.begin(); inf.end() != it; ++it)
         {
            LOG4CPLUS_INFO(msLogger, "CProfileRepoServerClb::findProfiles() : FoundLib : " +
                  it->path);
            stringToBuffer(it->uid.value,pResponseBuffer + outPos);
            outPos += stringInBufSize(it->uid.value);
            stringToBuffer(it->platform,pResponseBuffer + outPos);
            outPos += stringInBufSize(it->platform);
            stringToBuffer(it->path,pResponseBuffer + outPos);
            outPos += stringInBufSize(it->path);
            memcpy (pResponseBuffer + outPos, &it->relevance,4);
            outPos += 4;
         }
         bufferSize = outPos;
      }
示例#12
0
      void CPmpCoreClbCtrl::onEnableByClient(PMPFrame * pFrame)
      {
         LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
         CUid id(bufferToString(pFrame->data,true));
         bool res = mpCoreClb->onEnableByClient(id);

         PMPFrame * pResp = reinterpret_cast<PMPFrame*>(new UInt8[sizeof(PMPFrame)+1]);
         pResp->size = sizeof(PMPFrame)+1;
         pResp->frameType = PMP_FRAME_TYPE_RESPONSE;
         pResp->id = pFrame->id;
         pResp->client = pFrame->client;
         pResp->reqType = pFrame->reqType;
         pResp->data[0] = static_cast<UInt8>(res);

         mpProtocol->makeResponse(*pResp);
         delete [] pResp;
      }
示例#13
0
 void CAppManPmpIpcClient::OnRequest(iviLink::Ipc::MsgID id, UInt8 const* pPayload,
       UInt32 payloadSize, UInt8* const pResponseBuffer, UInt32& bufferSize,
       iviLink::Ipc::DirectionID dirId)
 {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);
    if (mpHandler)
    {
       UInt32 size = 0;
       memcpy(&size,pPayload,sizeof(size));
       UInt32 pos = sizeof(size);
       UInt32 type = 0;
       memcpy(&type,pPayload+pos,sizeof(type));
       pos += sizeof(type);
       mpHandler->appRequestError(iviLink::Service::SessionUid(bufferToString(pPayload+pos,false)));
       memcpy(pResponseBuffer,&type,sizeof(type));
       bufferSize = sizeof(type);
    }
 }
void CharacteristicsEditor::readCharacteristicDescriptor(int row)
{
    if (row < 0 || row >= m_descriptorsModel->size())
        return;

    uint8_t *descriptorBuffer;
    if (m_characteristicMTU < MIN_GATT_MTU) {
        m_characteristicMTU = bt_gatt_get_mtu(m_gattInstance);
        if (m_characteristicMTU < MIN_GATT_MTU) {
            m_characteristicMTU = MIN_GATT_MTU;
        }
    }

    descriptorBuffer = (uint8_t *)alloca(m_characteristicMTU);
    if (0 == descriptorBuffer) {
        setErrorMessage("GATT descriptors: Not enough memory");
        bt_gatt_disconnect_instance(m_gattInstance);
        return;
    }

    QVariantMap currentMap = m_descriptorsModel->value(row).toMap();

    QString descriptorString;

    int byteCount = 0;
    uint8_t more = 1;
    for (int offset = 0; more; offset += byteCount) {
        byteCount = bt_gatt_read_value(m_gattInstance, currentMap["handle"].toInt(), offset, descriptorBuffer, m_characteristicMTU, &more);
        if (byteCount < 0) {
            setErrorMessage(QString("Unable to read descriptor value: %1 (%2)").arg(errno).arg(strerror(errno)));
            break;
        }

        descriptorString += bufferToString(descriptorBuffer, byteCount);
    }

    currentMap["value"] = descriptorString;

    m_descriptorsModel->replace(row, currentMap);
}
示例#15
0
 refObject makingType(refChar name, int align, int size)
 { return
    makePair(hooks[strTypeHook],
     makePair(bufferToString(name),
      makePair(makeInteger(align),
       makePair(makeInteger(size), nil)))); }
示例#16
0
// writes data to serial line
bool CPlatform::TxD8Buffer(byte*buffer, int len) {
#ifdef SHOWPACKETS
    char strbuffer[1024];
    bufferToString(strbuffer, buffer, len);
    char strbuffer2[1024];
    sprintf(strbuffer2, "TXD: %s\n", strbuffer);
    CUtil::cout(strbuffer2, TEXT_DEBUG);
#endif

#ifdef INCLUDETCP
    if(global.useTcp) {
        // connect to client
        if(pcOut == NULL) {
            try {
                // Establish connection with the clients
                TCPSocket*newSocket = new TCPSocket(global.tcpHostname, global.tcpPortOut);
                pcOut = newSocket;

                CUtil::cout("pcServerSend() connected.\n", TEXT_DEBUG);
                unify_tcp_ports(); // mdda

            }
            catch(SocketException &e) {
                CUtil::cout("pcServerSend() failed (not connected).\n", TEXT_DEBUG);
                pcOut = NULL;
            }
        }

        if(pcOut != NULL) {
            try {
                //printf("sending: %d\n", getTickCount());
                pcOut->send(buffer, len);
            }
            catch(SocketException &e) {
                CUtil::cout("pcServerSend() failed.\n", TEXT_DEBUG);
                pcOut = NULL;
            }
        }
    }
#endif
    if(global.useSerial) {
#ifdef WIN32
        DWORD dwBytesWritten;
        ::WriteFile(hSerialPort, buffer, len, &dwBytesWritten, NULL);

        return dwBytesWritten == len;

#else
//	Linux


#ifdef SERIALSIMPLE

#ifdef USE_FTDI
        //ftdi_usb_purge_buffers (&ftdi);
        int ftdi_result = ftdi_write_data(&ftdi,buffer, len);
        if (ftdi_result != len)
        {
            char strbuffer[1024];
            bufferToString(strbuffer, buffer, ftdi_result);
            char strbuffer2[1024];
            sprintf(strbuffer2, "TXD: %s\n", strbuffer);
            CUtil::cout(strbuffer2, TEXT_DEBUG);
        }
        //usleep(1000);
        //printf("txd: %d\n", ftdi_result);
        return ftdi_result == len;
#endif
        // testing -->
        return write(fdSerialPort, buffer, len) == len;

        // <-- testing
#endif

        int n, error;
        byte b;
        n = error = 0;
        int cur;
        int max_fd = fdSerialPort + 1;
        struct timeval timeout;
        fd_set input;
        FD_ZERO(&input);
        FD_SET(fdSerialPort, &input);

        while(n<len && error < MAXSERIALERROR) {
            timeout.tv_sec = 0;
            timeout.tv_usec = SERIALTIMEOUTWRITE;
            select(max_fd, NULL, &input, NULL, &timeout);
            if(FD_ISSET(fdSerialPort, &input) ) {
                cur= write(fdSerialPort, buffer, len - n);
                if(cur >= 0) {
                    n+=cur;
                    buffer+=cur;
                }
                else {
                    error++;
                }
            }
            else {
                FD_ZERO(&input);
                FD_SET(fdSerialPort, &input);
            }
        }

        if(n != len) {
            char str[255];
            sprintf(str, "TxD8Buffer: write() failed (tries: %d).\n", error);
            CUtil::cout(str, TEXT_ERROR);
            return false;
        }
#endif
    }
    return true;
}
void CharacteristicsEditor::setCharacteristic(bt_gatt_characteristic_t *characteristic)
{
    m_characteristicStruct = characteristic;

    m_characteristicUUID = m_characteristicStruct->uuid;
    m_characteristicHandle = QString::number(m_characteristicStruct->handle);
    m_characteristicName = Util::parse_characteristic_uuid(m_characteristicStruct->uuid);
    m_characteristicValueHandle = QString::number(m_characteristicStruct->value_handle);
    m_characteristicProperties = m_characteristicStruct->properties;
    m_characteristicFlags.sprintf("0x%.2x", m_characteristicProperties);
    m_characteristicValue.clear();
    m_characteristicValueText.clear();
    m_characteristicNotificationsEnabled = false;
    m_characteristicIndicationsEnabled = false;

    int count = bt_gatt_descriptors_count(m_gattInstance, m_characteristicStruct);
    if (count == -1) {
        qWarning() << "GATT descriptors count failed:" << errno << "(" << strerror(errno) << ")";
        bt_gatt_disconnect_instance(m_gattInstance);
        return;
    }

    bt_gatt_descriptor_t *descriptorList = 0;
    if (count > 0) {
        descriptorList = (bt_gatt_descriptor_t*)alloca(count * sizeof(bt_gatt_descriptor_t));
        if (!descriptorList) {
            setErrorMessage("GATT descriptors: Not enough memory");
            bt_gatt_disconnect_instance(m_gattInstance);
            return;
        }

        /* BEGIN WORKAROUND - Temporary fix to address race condition */
        int number = 0;
        do {
            number = bt_gatt_descriptors(m_gattInstance, m_characteristicStruct, descriptorList, count);
        } while ((number == -1) && (errno == EBUSY));

        count = number;
        /* END WORKAROUND */
    }

    if (count == -1) {
        setErrorMessage(QString("GATT descriptors failed: %1 (%2)").arg(errno).arg(strerror(errno)));
        bt_gatt_disconnect_instance(m_gattInstance);
        return;
    }

    m_characteristicMTU = bt_gatt_get_mtu(m_gattInstance);
    if (m_characteristicMTU < MIN_GATT_MTU)
        m_characteristicMTU = MIN_GATT_MTU;

    uint8_t *descriptorBuffer = (uint8_t *)alloca(m_characteristicMTU);
    if (!descriptorBuffer) {
        setErrorMessage("GATT descriptors: Not enough memory");
        bt_gatt_disconnect_instance(m_gattInstance);
        return;
    }

    m_descriptorsModel->clear();

    for (int i = 0; i < count; i++) {
        QVariantMap map;

        map["uuid"] = QString(descriptorList[i].uuid).arg(i);
        map["name"] = QString(Util::parse_descriptor_uuid( descriptorList[i].uuid )).arg(i);
        map["handle"] = descriptorList[i].handle;

        QString descriptorString;
        uint8_t more = 1;
        int byteCount;
        for (int offset = 0; more; offset += byteCount) {
            byteCount = bt_gatt_read_value(m_gattInstance, descriptorList[i].handle, offset, descriptorBuffer, m_characteristicMTU, &more);
            if (byteCount < 0) {
                setErrorMessage(QString("Unable to read descriptor value: %1 (%2)").arg(errno).arg(strerror(errno)));
                break;
            }

            descriptorString += bufferToString(descriptorBuffer, byteCount);
        }

        map["value"] = descriptorString;

        m_descriptorsModel->append(map);

        // Check for the Client Characteristic Configuration - are notifications on already?
        if (strcmp(descriptorList[i].uuid, "0x2902" ) == 0) {
            // Parse the value into host byte order
            uint16_t value = 0;
            if (sscanf(descriptorString.toAscii().constData(), "%04hx", &value) == 1) {
                value = htons(value);
                setCharacteristicNotificationsEnabled(value & 0x01);
                setCharacteristicIndicationsEnabled(value & 0x02);
            }
        }
    }
}
示例#18
0
//reads data from serial line
bool CPlatform::RxD8Buffer(byte*buffer, int len) {
    bool bResult = false;

#ifdef INCLUDETCP
    if(global.useTcp && !global.useSerial) {
        //CUtil::cout("pcServerReceive() entered\n", TEXT_DEBUG);
        int result = 0;
        // connect to client
        if(pcIn == NULL) {
            try  {
                TCPSocket*newSocket = new TCPSocket(global.tcpHostname, global.tcpPortIn);
                pcIn = newSocket;

                CUtil::cout("pcServerReceive() connected.\n", TEXT_DEBUG);
                unify_tcp_ports(); // mdda

            }
            catch(SocketException &e) {
                CUtil::cout("pcServerSend() failed (not connected).\n", TEXT_DEBUG);
                pcIn = NULL;
                bResult = false;
            }
        }

        if(pcIn != NULL) {
            try {
                result = pcIn->recv(buffer, len);
            }
            catch(SocketException &e) {
                CUtil::cout("pcServerReceive() failed.\n", TEXT_DEBUG);
                pcIn = NULL;
                bResult = false;
            }
            //CUtil::cout("pcServerReceive() returned ok\n", TEXT_DEBUG);
            bResult = (result == len);
        }
    }
#endif

    if(global.useSerial) {
#ifdef WIN32
        DWORD dwBytesRead = 0;
        ReadFile(hSerialPort, buffer, len, &dwBytesRead, NULL);

        if(dwBytesRead != len) {
            //CUtil::cout("RxD8Buffer: ReadFile() failed.\n", TEXT_ERROR);
            bResult = false;
        }
        bResult = true;
#else

#ifdef SERIALSIMPLE

        int counter = 0;
        int retries = 0;

#ifdef USE_FTDI

        /* Still testing */

        while (counter < 2)
        {
            int ftdi_result = ftdi_read_data(&ftdi, &buffer[counter], 1);
            if (ftdi_result < 1)
            {
                CUtil::cout("Read 1\n", TEXT_DEBUG);
                return false;
            }

            if (buffer[counter] == 0xFF)
                counter++;
            else
            {
                counter--;
                if (counter < 0)
                    counter = 0;

                retries++;
                if (retries > 10)
                {
                    CUtil::cout("Retries\n", TEXT_DEBUG);
                    return false;
                }
            }

        }

        int ftdi_result = ftdi_read_data(&ftdi, &buffer[2], len-2) ;
        if (len - 2 != ftdi_result)
        {
            char strbuffer[1024];
            bufferToString(strbuffer, buffer, ftdi_result);
            char strbuffer2[1024];
            sprintf(strbuffer2, "RXD: %s\n", strbuffer);
            CUtil::cout(strbuffer2, TEXT_DEBUG);

            printf("rxd: %d (%d)\n", ftdi_result, len);
        }
        return ftdi_result == len-2;
#endif
        // testing -->
        counter = 0;
        retries = 0;
        while (counter < 2)
        {
            if (read(fdSerialPort, &buffer[counter], 1) < 1)
            {
                CUtil::cout("Read 1\n", TEXT_DEBUG);
                return false;
            }

            if (buffer[counter] == 0xFF)
                counter++;
            else
            {
                counter--;
                if (counter < 0)
                    counter = 0;

                retries++;
                if (retries > 10)
                {
                    CUtil::cout("Retries\n", TEXT_DEBUG);
                    return false;
                }
            }

        }

        int res = read(fdSerialPort, &buffer[2], len-2);

        char strbuffer[1024];
        bufferToString(strbuffer, buffer, len);
        char strbuffer2[1024];
        sprintf(strbuffer2, "RXD: %s\n", strbuffer);
        CUtil::cout(strbuffer2, TEXT_DEBUG);
        return res == len-2;
        //return len == read(fdSerialPort, buffer, len);

        // <-- testing
#endif


        int n = 0;
        int error = 0;
        byte b;
        int cur;
        int max_fd = fdSerialPort + 1;
        struct timeval timeout;
        fd_set input;
        FD_ZERO(&input);
        FD_SET(fdSerialPort, &input);

        while(n<len && error < MAXSERIALERROR) {
            timeout.tv_sec = 0;
            timeout.tv_usec = SERIALTIMEOUTREAD;
            select(max_fd, &input, NULL, NULL, &timeout);
            if(FD_ISSET(fdSerialPort, &input) ) {
                cur= read(fdSerialPort, buffer, len - n);
                if(cur >= 0) {
                    n+=cur;
                    buffer+=cur;
                }
                else {
                    error++;
                }
                FD_CLR(fdSerialPort, &input);
            }
            else {
                error++;
                FD_ZERO(&input);
                FD_SET(fdSerialPort, &input);
            }
        }

        if(n != len) {
            char str[255];
            sprintf(str, "RxD8Buffer: read() failed (tries: %d).\n", error);
            CUtil::cout(str, TEXT_ERROR);
        }
        bResult = (n == len);
#endif
    }

#ifdef SHOWPACKETS
    char strbuffer[1024];
    bufferToString(strbuffer, buffer, len);
    char strbuffer2[1024];
    sprintf(strbuffer2, "RXD: %s\n", strbuffer);
    CUtil::cout(strbuffer2, TEXT_DEBUG);
#endif

    return bResult;
}