You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.0 KiB

  1. //
  2. // Copyright © 2020 Thomas A. Early, N7TAE
  3. //
  4. // ----------------------------------------------------------------------------
  5. //
  6. // m17ref is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // m17ref is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // with this software. If not, see <http://www.gnu.org/licenses/>.
  18. // ----------------------------------------------------------------------------
  19. #include <arpa/inet.h>
  20. #include "packet.h"
  21. CPacket::CPacket(const uint8_t *buf, bool is_internal)
  22. {
  23. memcpy(m17.frame.magic, buf, is_internal ? sizeof(SRefM17Frame) : sizeof(SM17Frame));
  24. if (! is_internal)
  25. m17.relayed = false;
  26. destination.CodeIn(m17.frame.lich.addr_dst);
  27. source.CodeIn(m17.frame.lich.addr_src);
  28. }
  29. const CCallsign &CPacket::GetDestCallsign() const
  30. {
  31. return destination;
  32. }
  33. char CPacket::GetDestModule() const
  34. {
  35. return destination.GetModule();
  36. }
  37. const CCallsign &CPacket::GetSourceCallsign() const
  38. {
  39. return source;
  40. }
  41. uint16_t CPacket::GetStreamId() const
  42. {
  43. return ntohs(m17.frame.streamid);
  44. }
  45. uint16_t CPacket::GetCRC() const
  46. {
  47. return ntohs(m17.frame.crc);
  48. }
  49. void CPacket::SetCRC(uint16_t crc)
  50. {
  51. m17.frame.crc = htons(crc);
  52. }
  53. void CPacket::SetRelay(bool state)
  54. {
  55. m17.relayed = state;
  56. }
  57. bool CPacket::GetRelay() const
  58. {
  59. return m17.relayed;
  60. }
  61. std::unique_ptr<CPacket> CPacket::Duplicate(void) const
  62. {
  63. return std::unique_ptr<CPacket>(new CPacket(*this));
  64. }
  65. bool CPacket::IsLastPacket() const
  66. {
  67. return (0x8000u & m17.frame.framenumber == 0x8000u);
  68. }
  69. SRefM17Frame &CPacket::GetFrame()
  70. {
  71. return m17;
  72. }