From: tho Date: Fri, 3 Aug 2007 11:46:59 +0000 (+0000) Subject: added crc calculation to SNDU Packet X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=f1fc7057fa65a9509651d08c6c134d136fbb0424;p=senf.git added crc calculation to SNDU Packet git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@375 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Examples/DVBAdapter/ULEdec.cc b/Examples/DVBAdapter/ULEdec.cc index 1867d19..140e468 100644 --- a/Examples/DVBAdapter/ULEdec.cc +++ b/Examples/DVBAdapter/ULEdec.cc @@ -22,27 +22,11 @@ // Definition of non-inline non-template functions -#include -#include -#include -#include -#include -#include -#include +#include "ULEdec.hh" -#include "Scheduler/Scheduler.hh" -#include "Packets/DefaultBundle/EthernetPacket.hh" -#include "Packets/MPEGDVBBundle/TransportPacket.hh" -#include "Packets/MPEGDVBBundle/SNDUPacket.hh" -#include "Utils/membind.hh" -#include "Utils/hexdump.hh" -#include "Socket/Protocols/DVB/DVBDemuxHandles.hh" -#include "Packets/ParseInt.hh" -#include "Packets/Packet.hh" #include "Packets/PacketData.hh" -#include "Packets/ParseInt.hh" - -#include "ULEdec.hh" +#include "Utils/hexdump.hh" +#include "Utils/membind.hh" #define PID 271 #define TS_SYNC 0x47 @@ -94,7 +78,10 @@ void ULEdec::handleTSPacket(senf::TransportPacket ts_packet) iterator payload_start = payloadData.begin(); iterator payload_end = payloadData.end(); + std::cout << "New TS Packet:\n" + << "----------------------------------------------------------------------------\n"; senf::hexdump(payload_start, payload_end, std::cout); + std::cout << "----------------------------------------------------------------------------\n"; // Synchronize continuity counter this->priv_tscc = ts_packet->continuity_counter(); @@ -114,7 +101,7 @@ void ULEdec::handleTSPacket(senf::TransportPacket ts_packet) case 1: return; default: - if ( (*payload_start++ | *payload_start++) != ULE_END_INDICATOR ) + if ( (*payload_start++ << 8 | *payload_start++) != ULE_END_INDICATOR ) std::cerr << "delimiting error 1\n"; } else { BOOST_ASSERT( std::distance( payload_start, payload_end ) == 0 ); @@ -157,8 +144,8 @@ void ULEdec::handleTSPacket(senf::TransportPacket ts_packet) this->receiver_state = Idle; } while (std::distance(payload_start, payload_end) < 2 ); } + } // end pusi-switch - } @@ -191,13 +178,13 @@ ULEdec::iterator ULEdec::readNewSNDUPacket(iterator i_start, iterator i_end) switch (std::distance(i_start, i_end)) { case 1: this->priv_sndu_type_1 = true; - this->snduPacket->type() = *i_start++; + this->snduPacket->type() = *i_start++ << 8; this->snduPacketData_iter++; case 0: break; default: - this->snduPacket->type() = *i_start++ | *i_start++; + this->snduPacket->type() = *i_start++ << 8 | *i_start++; this->snduPacketData_iter += 2; i_start = readRawSNDUPacketData(i_start, i_end); } @@ -220,6 +207,8 @@ ULEdec::iterator ULEdec::readRawSNDUPacketData(iterator i_start, iterator i_end) void ULEdec::handleSNDUPacket() { this->snduPacket.dump(std::cout); + std::cout << " calculated CRC: " << this->snduPacket->calcCrc() << "\n"; + std::cout << "----------------------------------------------------------------------------\n\n"; } diff --git a/Examples/DVBAdapter/ULEdec.hh b/Examples/DVBAdapter/ULEdec.hh index 73d6699..f35c7d3 100644 --- a/Examples/DVBAdapter/ULEdec.hh +++ b/Examples/DVBAdapter/ULEdec.hh @@ -1,6 +1,6 @@ // $Id: ULEdec.cc 355 2007-07-26 14:17:02Z tho $ // -// Copyright (C) 2006 +// Copyright (C) 2007 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) // Kompetenzzentrum fuer Satelitenkommunikation (SatCom) // Stefan Bund @@ -26,19 +26,12 @@ #include #include #include -#include #include #include "Scheduler/Scheduler.hh" -#include "Packets/DefaultBundle/EthernetPacket.hh" #include "Packets/MPEGDVBBundle/TransportPacket.hh" #include "Packets/MPEGDVBBundle/SNDUPacket.hh" -#include "Utils/membind.hh" #include "Socket/Protocols/DVB/DVBDemuxHandles.hh" -#include "Packets/ParseInt.hh" -#include "Packets/Packet.hh" -#include "Packets/PacketData.hh" -#include "Packets/ParseInt.hh" class ULEdec diff --git a/Packets/MPEGDVBBundle/SNDUPacket.cc b/Packets/MPEGDVBBundle/SNDUPacket.cc index d2f4546..e55812f 100644 --- a/Packets/MPEGDVBBundle/SNDUPacket.cc +++ b/Packets/MPEGDVBBundle/SNDUPacket.cc @@ -28,6 +28,8 @@ // Custom includes #include +#include "Utils/hexdump.hh" +#include "Packets/PacketData.hh" #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// @@ -47,6 +49,17 @@ prefix_ senf::PacketParserBase::size_type senf::Parse_SNDUPacket::bytes() return 2 + 2 + 4 + 6; // + 6 Byte NPA destination address } +prefix_ boost::uint32_t senf::Parse_SNDUPacket::calcCrc() + const +{ + ule_crc32 result; + senf::PacketData::iterator i (data().begin()); + senf::PacketData::iterator const i_end(boost::prior(data().end(),4)); + for (; i!=i_end; ++i) + result.process_byte(*i); + return result.checksum(); +} + prefix_ void senf::SNDUPacketType::dump(packet p, std::ostream & os) { os << "SNDUPacket:\n" diff --git a/Packets/MPEGDVBBundle/SNDUPacket.hh b/Packets/MPEGDVBBundle/SNDUPacket.hh index 79833c2..4ab5824 100644 --- a/Packets/MPEGDVBBundle/SNDUPacket.hh +++ b/Packets/MPEGDVBBundle/SNDUPacket.hh @@ -1,4 +1,4 @@ -// $Id:DSMCCSection.hh 327 2007-07-20 10:03:44Z tho $ +// $Id$ // // Copyright (C) 2007 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) @@ -28,6 +28,7 @@ // Custom includes #include +#include #include "Packets/PacketType.hh" #include "Packets/ParseInt.hh" #include "Packets/PacketRegistry.hh" @@ -81,6 +82,8 @@ namespace senf { PacketParserBase::size_type bytes() const; static const size_type init_bytes = 2+2+4; // D-Bit + 15 bits length + 16 bits type field + 32 bits crc + + boost::uint32_t calcCrc() const; }; /** \brief ULE SNDU Packet @@ -112,6 +115,9 @@ namespace senf { }; typedef SNDUPacketType::packet SNDUPacket; + + typedef boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0, false, false> ule_crc32; + /*! \def ULE_END_INDICATOR