本文整理汇总了C++中Connection::ReceivePacketHandler方法的典型用法代码示例。如果您正苦于以下问题:C++ Connection::ReceivePacketHandler方法的具体用法?C++ Connection::ReceivePacketHandler怎么用?C++ Connection::ReceivePacketHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection::ReceivePacketHandler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: messageReceivedCallback
void ConnectionManager::messageReceivedCallback(ble_evt_t* bleEvent)
{
ConnectionManager* cm = ConnectionManager::getInstance();
//Handles BLE_GATTS_EVT_WRITE
//FIXME: must check for reassembly buffer size, if it is bigger, a stack overflow will occur
Connection* connection = cm->GetConnectionFromHandle(bleEvent->evt.gatts_evt.conn_handle);
if (connection != NULL)
{
//TODO: At this point we should check if the write was a valid operation for the mesh
//Invalid actions should cause a disconnect
/*if( bleEvent->evt.gatts_evt.params.write.handle != GATTController::getMeshWriteHandle() ){
connection->Disconnect();
logt("ERROR", "Non mesh device was disconnected");
}*/
connPacketHeader* packet = (connPacketHeader*)bleEvent->evt.gatts_evt.params.write.data;
//At first, some special treatment for out timestamp packet
if(packet->messageType == MESSAGE_TYPE_UPDATE_TIMESTAMP)
{
//Set our time to the received timestamp and update the time when we've received this packet
app_timer_cnt_get(&cm->node->globalTimeSetAt);
cm->node->globalTime = ((connPacketUpdateTimestamp*)packet)->timestamp;
logt("NODE", "time updated at:%u with timestamp:%u", cm->node->globalTimeSetAt, (u32)cm->node->globalTime);
}
u8 t = ((connPacketHeader*)bleEvent->evt.gatts_evt.params.write.data)->messageType;
if( t != 20 && t != 21 && t != 22 && t != 23 && t != 30 && t != 31 && t != 50 && t != 51 && t != 52 && t != 53 && t != 56 && t != 57 && t != 60 && t != 61 && t != 62 && t != 80 && t != 81){
logt("ERROR", "WAAAAAAAAAAAAAHHHHH, WRONG DATAAAAAAAAAAAAAAAAA!!!!!!!!!");
}
//Print packet as hex
char stringBuffer[100];
Logger::getInstance().convertBufferToHexString(bleEvent->evt.gatts_evt.params.write.data, bleEvent->evt.gatts_evt.params.write.len, stringBuffer, 100);
logt("CONN_DATA", "Received type %d, hasMore %d, length %d, reliable %d:", ((connPacketHeader*)bleEvent->evt.gatts_evt.params.write.data)->messageType, ((connPacketHeader*)bleEvent->evt.gatts_evt.params.write.data)->hasMoreParts, bleEvent->evt.gatts_evt.params.write.len, bleEvent->evt.gatts_evt.params.write.op);
logt("CONN_DATA", "%s", stringBuffer);
//Check if we need to reassemble the packet
if(connection->packetReassemblyPosition == 0 && packet->hasMoreParts == 0)
{
//Single packet, no more data
connectionPacket p;
p.connectionHandle = bleEvent->evt.gatts_evt.conn_handle;
p.data = bleEvent->evt.gatts_evt.params.write.data;
p.dataLength = bleEvent->evt.gatts_evt.params.write.len;
p.reliable = bleEvent->evt.gatts_evt.params.write.op == BLE_GATTS_OP_WRITE_CMD ? false : true;
connection->ReceivePacketHandler(&p);
}
//First of a multipart packet, still has more parts
else if(connection->packetReassemblyPosition == 0 && packet->hasMoreParts)
{
//Save at correct position of
memcpy(
connection->packetReassemblyBuffer,
bleEvent->evt.gatts_evt.params.write.data,
bleEvent->evt.gatts_evt.params.write.len
);
connection->packetReassemblyPosition += bleEvent->evt.gatts_evt.params.write.len;
//Do not notify anyone until packet is finished
logt("CM", "Received first part of message");
}
//Multipart packet, intermediate or last frame
else if(connection->packetReassemblyPosition != 0)
{
memcpy(
connection->packetReassemblyBuffer + connection->packetReassemblyPosition,
bleEvent->evt.gatts_evt.params.write.data + SIZEOF_CONN_PACKET_SPLIT_HEADER,
bleEvent->evt.gatts_evt.params.write.len - SIZEOF_CONN_PACKET_SPLIT_HEADER
);
//Intermediate packet
if(packet->hasMoreParts){
connection->packetReassemblyPosition += bleEvent->evt.gatts_evt.params.write.len - SIZEOF_CONN_PACKET_SPLIT_HEADER;
logt("CM", "Received middle part of message");
//Final packet
} else {
logt("CM", "Received last part of message");
//Notify connection
connectionPacket p;
p.connectionHandle = bleEvent->evt.gatts_evt.conn_handle;
p.data = connection->packetReassemblyBuffer;
p.dataLength = bleEvent->evt.gatts_evt.params.write.len + connection->packetReassemblyPosition - SIZEOF_CONN_PACKET_SPLIT_HEADER;
p.reliable = bleEvent->evt.gatts_evt.params.write.op == BLE_GATTS_OP_WRITE_CMD ? false : true;
//Reset the assembly buffer
//.........这里部分代码省略.........