Artemis Teensy Flight Software
The software on the Teensy in the Artemis cubesat.
ax25class.h
1 /********************************************************************
2 * Copyright (C) 2015 by Interstel Technologies, Inc.
3 * and Hawaii Space Flight Laboratory.
4 *
5 * This file is part of the COSMOS/core that is the central
6 * module for COSMOS. For more information on COSMOS go to
7 * <http://cosmos-project.com>
8 *
9 * The COSMOS/core software is licenced under the
10 * GNU Lesser General Public License (LGPL) version 3 licence.
11 *
12 * You should have received a copy of the
13 * GNU Lesser General Public License
14 * If not, go to <http://www.gnu.org/licenses/>
15 *
16 * COSMOS/core is free software: you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public License
18 * as published by the Free Software Foundation, either version 3 of
19 * the License, or (at your option) any later version.
20 *
21 * COSMOS/core is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * Refer to the "licences" folder for further information on the
27 * condititons and terms to use this software.
28 ********************************************************************/
29 
30 #ifndef AX25LIB
31 #define AX25LIB
32 
34 #include "support/cosmos-errno.h"
35 #include "math/bytelib.h"
36 #include "math/crclib.h"
37 
38 #include <cstring>
39 #include <iostream>
40 
41 #define PACKETMAX 1024
42 
43 
44 namespace Cosmos {
45  namespace Support {
46  class Ax25Handle
47  {
48 
49  public:
50  struct __attribute__ ((packed)) packet_header
51  {
52  uint8_t destination_callsign[6];
53  uint8_t destination_stationID;
54  uint8_t source_callsign[6];
55  uint8_t source_stationID;
56  uint8_t control = 0x03;
57  uint8_t protocolID = 0xf0;
58  };
59 
61  {
62  packet_header header;
63  vector <uint8_t> data;
64  };
65 
66  Ax25Handle(string dest_call, string sour_call, uint8_t dest_stat, uint8_t sour_stat, uint8_t cont, uint8_t prot);
67  Ax25Handle();
68 
69  void set_destination_callsign(string destination);
70  string get_destination_callsign();
71  void set_destination_stationID(uint8_t ID);
72  uint8_t get_destination_stationID();
73  void set_source_callsign(string source);
74  string get_source_callsign();
75  void set_source_stationID(uint8_t ID);
76  uint8_t get_source_stationID();
77  void set_control(uint8_t control_number);
78  uint8_t get_control();
79  void set_protocolID(uint8_t protocol);
80  uint8_t get_protocolID();
81  packet_header get_header();
82  vector <uint8_t> get_data();
83  vector <uint8_t> get_ax25_packet();
84  vector <uint8_t> get_hdlc_packet();
85  int32_t set_data(vector <uint8_t> input);
86  int32_t set_ax25_packet(vector <uint8_t> packet);
87  int32_t set_hdlc_packet(vector <uint8_t> packet);
88  int32_t unload(bool checkcrc=true);
89  int32_t load(vector<uint8_t> data={});
90  int32_t stuff(vector<uint8_t> ax25data={}, uint8_t flagcount=2, uint8_t flag=0x7e);
91  int32_t unstuff(vector<uint8_t> hdlcdata={}, uint8_t flag=0x7e);
92  vector<uint8_t> hdlc_packet;
93  vector<uint8_t> ax25_packet;
94 
95  private:
96  packet_header header;
97  uint16_t crc;
98  uint16_t crccalc;
99  vector <uint8_t> data;
100  int32_t error;
101  // vector<uint8_t> flags = {0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e};
102  vector<uint8_t> flags = {0x7e, 0x7e};
103  CRC16 calc_crc;
104 
105 
106  friend ::std::ostream& operator<<(::std::ostream& out, Ax25Handle& K);
107  };
108  }
109 }
110 
111 //Functions to print packets
112 void print_ascii(unsigned char* packet, unsigned int count);
113 void print_hex(unsigned char* packet, unsigned int count);
114 
115 #endif
Definition: crclib.h:43
Definition: ax25class.h:47
Headers and definitions common to all COSMOS Kernel.
COSMOS Error Codes.
PacketComm packet
The packet used throughout the channel.
Definition: pdu_channel.cpp:19