/* Insert packet into head of buffer */ uint8_t insert_packet(can_pkt *pkt, can_pkt *buf, circbuf *count, uint16_t size) { if (count->length == size) {//if buffer is full, delete oldest data can_pkt dummypacket; remove_packet( &dummypacket, buf, count, size); dropped_packet_count++; } uint16_t location; count->length++; //otherwise, let's allocate one spot location = count->start + count->length - 1; //locate the spot if (location > (size-1)) { //trying to reach over the end of array, wrap back to the beginning location = location - size; } buf[location].id = pkt->id; buf[location].payload = pkt->payload; received_packet_count++; return 0; }
virtual void transfer_failure(const generic_packet_type& aPacket, const boost::system::error_code& aError) { orphaned_queue_item failedPacket = remove_packet(static_cast<const packet_type&>(aPacket)); notify_observers(observer_type::NotifyTransferFailure, aError); }
virtual void packet_sent(const generic_packet_type& aPacket) { orphaned_queue_item sentPacket = remove_packet(static_cast<const packet_type&>(aPacket)); notify_observers(observer_type::NotifyPacketSent, *sentPacket); }