• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • libbytearraychecksum
  • algorithm
modsum16bytearraychecksumalgorithm.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "modsum16bytearraychecksumalgorithm.h"
24 
25 // Okteta core
26 #include <abstractbytearraymodel.h>
27 // KDE
28 #include <KLocale>
29 // Qt
30 #include <QtCore/QtEndian>
31 
32 
33 ModSum16ByteArrayChecksumAlgorithm::ModSum16ByteArrayChecksumAlgorithm()
34  : AbstractByteArrayChecksumAlgorithm(
35  i18nc("name of the checksum algorithm", "Modular sum 16-bit") )
36 {}
37 
38 AbstractByteArrayChecksumParameterSet* ModSum16ByteArrayChecksumAlgorithm::parameterSet() { return &mParameterSet; }
39 
40 bool ModSum16ByteArrayChecksumAlgorithm::calculateChecksum( QString* result,
41  const Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range ) const
42 {
43  const bool useLittleEndian = ( mParameterSet.endianness() == LittleEndian );
44  quint16 modSum = useLittleEndian ?
45  calculateModSumWithLittleEndian( model, range ) :
46  calculateModSumWithBigEndian( model, range );
47 
48  modSum = ~modSum + 1;
49 
50  if( useLittleEndian )
51  modSum = qbswap( modSum );
52 
53  *result = QString::fromLatin1("%1").arg( modSum, 4, 16, QChar::fromLatin1('0') );
54  return true;
55 }
56 
57 quint16 ModSum16ByteArrayChecksumAlgorithm::calculateModSumWithBigEndian( const Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range ) const
58 {
59  quint16 modSum = 0x0000;
60  Okteta::Address nextBlockEnd = range.start() + CalculatedByteCountSignalLimit;
61 
62  // TODO: move padding checks into extra code before and after loop
63  for( Okteta::Address i = range.start(); i<=range.end(); ++i )
64  {
65  quint16 value = (quint16)( (quint8)(model->byte( i )) ) << 8;
66  ++i;
67  if( i<=range.end() )
68  value |= (quint16)( (quint8)(model->byte( i )) );
69 
70  modSum += value;
71 #if 0
72  const uchar value = (crcBits & 0xFF) + model->byte( i );
73  crcBits >>= 8;
74  crcBits ^= lookupTable[value];
75 #endif
76  if( i >= nextBlockEnd )
77  {
78  nextBlockEnd += CalculatedByteCountSignalLimit;
79  emit calculatedBytes( range.localIndex(i)+1 );
80  }
81  }
82 
83  return modSum;
84 }
85 
86 quint16 ModSum16ByteArrayChecksumAlgorithm::calculateModSumWithLittleEndian( const Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range ) const
87 {
88  quint16 modSum = 0x0000;
89  Okteta::Address nextBlockEnd = range.start() + CalculatedByteCountSignalLimit;
90 
91  // TODO: move padding checks into extra code before and after loop
92  for( Okteta::Address i = range.start(); i<=range.end(); ++i )
93  {
94  quint16 value = (quint16)( (quint8)(model->byte( i )) );
95  ++i;
96  if( i<=range.end() )
97  value |= (quint16)( (quint8)(model->byte( i )) ) << 8;
98 
99  modSum += value;
100 
101  if( i >= nextBlockEnd )
102  {
103  nextBlockEnd += CalculatedByteCountSignalLimit;
104  emit calculatedBytes( range.localIndex(i)+1 );
105  }
106  }
107 
108  return modSum;
109 }
110 
111 ModSum16ByteArrayChecksumAlgorithm::~ModSum16ByteArrayChecksumAlgorithm() {}
Okteta::Address
qint32 Address
Definition: address.h:34
Okteta::AbstractByteArrayModel
could it be useful to hide the data access behind an iterator? * class KDataBufferIterator { public: ...
Definition: abstractbytearraymodel.h:79
abstractbytearraymodel.h
AbstractByteArrayChecksumAlgorithm
Definition: abstractbytearraychecksumalgorithm.h:38
KDE::NumberRange< Address, Size >
KDE::Range::start
T start() const
Definition: range.h:86
AbstractByteArrayChecksumAlgorithm::CalculatedByteCountSignalLimit
static const int CalculatedByteCountSignalLimit
Definition: abstractbytearraychecksumalgorithm.h:43
ModSum16ByteArrayChecksumAlgorithm::calculateModSumWithBigEndian
quint16 calculateModSumWithBigEndian(const Okteta::AbstractByteArrayModel *model, const Okteta::AddressRange &range) const
Definition: modsum16bytearraychecksumalgorithm.cpp:57
ModSum16ByteArrayChecksumAlgorithm::mParameterSet
ModSumByteArrayChecksumParameterSet mParameterSet
Definition: modsum16bytearraychecksumalgorithm.h:47
KDE::NumberRange::localIndex
N localIndex(N index) const
Definition: numberrange.h:199
KDE::Range::end
T end() const
Definition: range.h:88
ModSum16ByteArrayChecksumAlgorithm::parameterSet
virtual AbstractByteArrayChecksumParameterSet * parameterSet()
used by the editor to get write access to the parameters
Definition: modsum16bytearraychecksumalgorithm.cpp:38
Okteta::AbstractByteArrayModel::byte
virtual Byte byte(Address offset) const =0
locates working range The idea behind is to tell buffer which range will be requested in the followin...
AbstractByteArrayChecksumParameterSet
Definition: abstractbytearraychecksumparameterset.h:27
ModSum16ByteArrayChecksumAlgorithm::calculateChecksum
virtual bool calculateChecksum(QString *result, const Okteta::AbstractByteArrayModel *model, const Okteta::AddressRange &range) const
Definition: modsum16bytearraychecksumalgorithm.cpp:40
ModSumByteArrayChecksumParameterSet::endianness
Endianness endianness() const
Definition: modsumbytearraychecksumparameterset.cpp:32
modsum16bytearraychecksumalgorithm.h
ModSum16ByteArrayChecksumAlgorithm::calculateModSumWithLittleEndian
quint16 calculateModSumWithLittleEndian(const Okteta::AbstractByteArrayModel *model, const Okteta::AddressRange &range) const
Definition: modsum16bytearraychecksumalgorithm.cpp:86
LittleEndian
Definition: endianness.h:32
ModSum16ByteArrayChecksumAlgorithm::~ModSum16ByteArrayChecksumAlgorithm
virtual ~ModSum16ByteArrayChecksumAlgorithm()
Definition: modsum16bytearraychecksumalgorithm.cpp:111
ModSum16ByteArrayChecksumAlgorithm::ModSum16ByteArrayChecksumAlgorithm
ModSum16ByteArrayChecksumAlgorithm()
Definition: modsum16bytearraychecksumalgorithm.cpp:33
AbstractByteArrayChecksumAlgorithm::calculatedBytes
void calculatedBytes(int bytes) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal