added crc calculation to SNDU Packet
tho [Fri, 3 Aug 2007 11:46:59 +0000 (11:46 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@375 270642c3-0616-0410-b53a-bc976706d245

Examples/DVBAdapter/ULEdec.cc
Examples/DVBAdapter/ULEdec.hh
Packets/MPEGDVBBundle/SNDUPacket.cc
Packets/MPEGDVBBundle/SNDUPacket.hh

index 1867d19..140e468 100644 (file)
 
 // Definition of non-inline non-template functions
 
-#include <string>
-#include <iostream>
-#include <iomanip>
-#include <algorithm>
-#include <sys/ioctl.h>
-#include <linux/sockios.h>
-#include <linux/dvb/dmx.h> 
+#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";
 }
 
 
index 73d6699..f35c7d3 100644 (file)
@@ -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 <stefan.bund@fokus.fraunhofer.de>
 #include <iostream>
 #include <iomanip>
 #include <sys/ioctl.h>
-#include <linux/sockios.h>
 #include <linux/dvb/dmx.h> 
 
 #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
index d2f4546..e55812f 100644 (file)
@@ -28,6 +28,8 @@
 
 // Custom includes
 #include <iomanip>
+#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"
index 79833c2..4ab5824 100644 (file)
@@ -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 <algorithm>
+#include <boost/crc.hpp>
 #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