Reliapack::Reliapack(char * data, int dataLength, int seqNum, Datapack *resp) { numPackets = (dataLength + MAX_DATA_LENGTH - 1) /MAX_DATA_LENGTH; numPackets = (numPackets == 0) ? 1 : numPackets; //can't have a length of 0 packets = new char *[numPackets]; lengths = new int[numPackets]; sequenceNum = seqNum; int dataOffset = 0; //be careful with this variable int bufLength = MAX_DATA_LENGTH + HEADER_LENGTH; //this can be done to all packets for(int i=0; i<numPackets; i++) { if(i == (numPackets - 1)) //if this is the last packet, change the buffer length bufLength = dataLength - dataOffset + HEADER_LENGTH; int oldDataOffset = dataOffset; //copy into buffer in DatagramPacket packets[i] = new char[bufLength]; lengths[i] = bufLength; for(int bufPlace=HEADER_LENGTH; bufPlace < bufLength; ) packets[i][bufPlace++] = data[dataOffset++]; setSeqNum(packets[i], seqNum); setRetryNum(packets[i], 0); setResponseSeqNum(packets[i], resp == 0 ? 0 : resp->getSequenceNumber()); setResponseRetryNum(packets[i], 0); //the retry number should only be set for ack packets setOffset(packets[i], oldDataOffset); setTotalLength(packets[i], dataLength); } memcpy(&address, resp->getAddress(), sizeof(struct sockaddr_in)); ftime(&lastEventTime); }
// -- CREATE OBJECT --------------------- DisconnectRespose::DisconnectRespose(KnxConnection* connection): KnxPacket::KnxPacket(connection) { // default setType(KNX_PACKET_DISCONNECT_RESPONSE); setTotalLength(8); // 8 bytes conHeaderChanelID = &(connection->chanelId); }