COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
kisslib.h
Go to the documentation of this file.
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 KISSLIB
31 #define KISSLIB
32 
33 #include "support/configCosmos.h"
34 #include "support/cosmos-errno.h"
35 #include "support/sliplib.h"
36 
37 #include <cstring>
38 #include <iostream>
39 
40 //#define FEND 0xC0
41 //#define FESC 0xDB
42 //#define TFEND 0xDC
43 //#define TFESC 0xDD
44 
45 #define PACKETMAX 1024
46 
47 
49 {
50 
51 public:
52  KissHandle(string dest_call="", string sour_call="", uint8_t port=0, uint8_t comm=0, uint8_t dest_stat=0x60, uint8_t sour_stat=0x61, uint8_t cont=0x03, uint8_t prot=0xf0);
53 
54  void set_port_number(uint8_t P);
55  uint8_t get_port_number();
56  void set_command(uint8_t C);
57  uint8_t get_command();
59  string get_destination_callsign();
60  void set_destination_stationID(uint8_t ID);
61  uint8_t get_destination_stationID();
62  void set_source_callsign(string source);
63  string get_source_callsign();
64  void set_source_stationID(uint8_t ID);
65  uint8_t get_source_stationID();
66  void set_control(uint8_t control_number);
67  uint8_t get_control();
68  void set_protocolID(uint8_t protocol);
69  uint8_t get_protocolID();
70  int32_t set_data(vector <uint8_t> input);
71  vector <uint8_t> get_data();
72  int32_t load_packet();
73  int32_t unload_packet();
74  int32_t set_raw_packet(vector <uint8_t> packet);
75  int32_t set_slip_packet(vector <uint8_t> packet);
76  vector <uint8_t> get_raw_packet();
77  vector <uint8_t> get_slip_packet();
78  int32_t get_error();
79 
80  struct __attribute__ ((packed)) packet_header
81  {
82  unsigned command : 4;
83  unsigned port_number : 4;
84  uint8_t destination_callsign[6];
85  uint8_t destination_stationID;
86  uint8_t source_callsign[6];
87  uint8_t source_stationID;
88  uint8_t control = 0x03;
89  uint8_t protocolID = 0xf0;
90  };
91 
93  {
94  packet_header header;
95  uint8_t data;
96  };
97 
98 private:
99  packet_header header;
100  vector <uint8_t> data;
101  vector <uint8_t> raw_packet;
102  vector <uint8_t> slip_packet;
103  int32_t error;
104 
105  friend std::ostream& operator<<(std::ostream& out, KissHandle& K);
106 };
107 
108 //old load_packet (to be deleted)**********************************************
109 int kissEncode(uint8_t *input, uint32_t count, uint8_t *packet);
110 
111 //int kissDecode(uint8_t *input, uint32_t count, uint8_t *unload_packetd_packet);
112 
113 int kissDecode(uint8_t* kissed_input, uint32_t count, uint8_t* unload_packetd_payload);
114 int kissDecode(vector <uint8_t> kissed_input, KissHandle &handle);
115 
116 KissHandle kissInspect(const unsigned char* input);
117 
118 //Functions to print packets
119 void print_ascii(unsigned char* packet, unsigned int count);
120 void print_hex(unsigned char* packet, unsigned int count);
121 
122 #endif
static string port
Definition: add_radio.cpp:16
void set_command(uint8_t C)
Definition: kisslib.cpp:57
int32_t error
Definition: kisslib.h:103
uint8_t get_port_number()
Definition: kisslib.cpp:52
COSMOS SLIP support include file.
int count
Definition: rw_test.cpp:36
void set_source_callsign(string source)
Definition: kisslib.cpp:106
friend std::ostream & operator<<(std::ostream &out, KissHandle &K)
Definition: kisslib.cpp:165
static string destination
Definition: ax25_recv.cpp:43
void set_source_stationID(uint8_t ID)
Definition: kisslib.cpp:132
void set_port_number(uint8_t P)
Definition: kisslib.cpp:46
void print_ascii(unsigned char *packet, unsigned int count)
uint8_t get_source_stationID()
Definition: kisslib.cpp:138
vector< uint8_t > get_slip_packet()
Definition: kisslib.cpp:311
Definition: pic_lib.h:128
KissHandle kissInspect(const unsigned char *input)
Definition: kisslib.cpp:316
uint8_t get_command()
Definition: kisslib.cpp:63
void print_hex(unsigned char *packet, unsigned int count)
int kissDecode(uint8_t *kissed_input, uint32_t count, uint8_t *unload_packetd_payload)
Definition: kisslib.cpp:391
packet_header header
Definition: kisslib.h:99
int32_t unload_packet()
Definition: kisslib.cpp:292
vector< uint8_t > data
Definition: kisslib.h:100
void set_protocolID(uint8_t protocol)
Definition: kisslib.cpp:154
int32_t set_slip_packet(vector< uint8_t > packet)
Definition: kisslib.cpp:270
void set_destination_callsign(string destination)
Definition: kisslib.cpp:69
Headers and definitions common to all COSMOS.
KissHandle(string dest_call="", string sour_call="", uint8_t port=0, uint8_t comm=0, uint8_t dest_stat=0x60, uint8_t sour_stat=0x61, uint8_t cont=0x03, uint8_t prot=0xf0)
Definition: kisslib.cpp:33
COSMOS Error Codes.
uint8_t data
Definition: kisslib.h:95
string command
Definition: add_radio.cpp:27
gige_handle * handle
Definition: kpc9612p_recv.cpp:33
string get_destination_callsign()
Definition: kisslib.cpp:85
int32_t set_data(vector< uint8_t > input)
Definition: kisslib.cpp:258
string get_source_callsign()
Definition: kisslib.cpp:122
int kissEncode(uint8_t *input, uint32_t count, uint8_t *packet)
Definition: kisslib.cpp:183
static string source
Definition: ax25_recv.cpp:42
uint8_t get_protocolID()
Definition: kisslib.cpp:160
vector< uint8_t > raw_packet
Definition: kisslib.h:101
vector< uint8_t > get_raw_packet()
Definition: kisslib.cpp:306
uint8_t get_destination_stationID()
Definition: kisslib.cpp:101
Definition: kisslib.h:92
vector< uint8_t > get_data()
Definition: kisslib.cpp:276
Definition: kisslib.h:48
int32_t set_raw_packet(vector< uint8_t > packet)
Definition: kisslib.cpp:264
vector< uint8_t > slip_packet
Definition: kisslib.h:102
packet_header header
Definition: kisslib.h:94
void set_control(uint8_t control_number)
Definition: kisslib.cpp:143
void set_destination_stationID(uint8_t ID)
Definition: kisslib.cpp:95
int32_t get_error()
Definition: kisslib.cpp:301
uint8_t get_control()
Definition: kisslib.cpp:149
int32_t load_packet()
Definition: kisslib.cpp:281