Browse Source

split packet to h and cpp

master
Tom Early 1 year ago
parent
commit
8255cfb55c
  1. 11
      crc.cpp
  2. 3
      crc.h
  3. 72
      packet.cpp

11
crc.cpp

@ -39,8 +39,8 @@
#include "crc.h"
#define CRC_POLY_16 0x5935U
#define CRC_START_16 0xFFFFU
#define CRC_POLY_16 0x5935u
#define CRC_START_16 0xFFFFu
CCRC::CCRC()
{
@ -62,15 +62,14 @@ CCRC::CCRC()
}
}
uint16_t CCRC::CalcCRC( const uint8_t *input_str, size_t num_bytes )
uint16_t CCRC::CalcCRC( const uint8_t *input_str, size_t num_bytes ) const
{
uint16_t crc = CRC_START_16;
const uint8_t *ptr = input_str;
if ( ptr )
if ( input_str )
for (size_t a=0; a<num_bytes; a++)
{
crc = (crc << 8) ^ crc_tab16[ ((crc >> 8) ^ (uint16_t) *ptr++) & 0x00FF ];
crc = (crc << 8) ^ crc_tab16[ ((crc >> 8) ^ uint16_t(input_str[a])) & 0x00FF ];
}
return crc;

3
crc.h

@ -41,9 +41,8 @@ class CCRC
{
public:
CCRC();
uint16_t CalcCRC(const uint8_t *buf, size_t len);
uint16_t CalcCRC(const uint8_t *buf, size_t len) const;
private:
uint16_t crc_tab16[256];
};

72
packet.cpp

@ -0,0 +1,72 @@
//
// Copyright © 2020 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
//
// m17ref is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// m17ref is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// with this software. If not, see <http://www.gnu.org/licenses/>.
// ----------------------------------------------------------------------------
#include "packet.h"
CPacket::CPacket(const uint8_t *buf)
{
memcpy(m17.magic, buf, sizeof(AM17Frame));
destination.DecodeCallsign(m17.lich.addr_dst);
source.DecodeCallsign(m17.lich.addr_src);
}
const CCallsign &CPacket::GetDestCallsign() const
{
return destination;
}
char CPacket::GetDestModule() const
{
return destination.GetModule();
}
const CCallsign &CPacket::GetSourceCallsign() const
{
return source;
}
uint16_t CPacket::GetStreamId() const
{
return ntohs(m17.streamid);
}
uint16_t CPacket::GetCRC() const
{
return ntohs(m17.crc);
}
void CPacket::SetCRC(uint16_t crc)
{
m17.crc = htons(crc);
}
std::unique_ptr<CPacket> CPacket::Duplicate(void) const
{
return std::unique_ptr<CPacket>(new CPacket(*this));
}
bool CPacket::IsLastPacket() const
{
return (0x8000u & m17.framenumber == 0x8000u);
}
AM17Frame &CPacket::GetFrame()
{
return m17;
}
Loading…
Cancel
Save