COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
kiss_recv.cpp File Reference
Include dependency graph for kiss_recv.cpp:

Functions

int main (int argc, char *argv[])
 

Variables

static KissHandle handle
 
static string device ="/dev/tty_tnc"
 
static string source
 
static string destination
 
static vector< uint8_t > message
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)
45 {
46  PORT_TYPE device_type;
47  uint16_t device_port;
48  string device_addr;
49  Serial *shandle = nullptr;
50  socket_channel schannel;
51 
52  int32_t iretn;
53  size_t tcount = 2000;
54 
55  switch (argc)
56  {
57  case 3:
58  tcount = static_cast <size_t>(atol(argv[2]));
59  case 2:
60  device = argv[1];
61  if (device.find(':') != string::npos)
62  {
63  device_type = PORT_TYPE_ETHERNET;
64  device_port = static_cast <uint16_t>(stoi(device.substr(device.find(':')+1)));
65  device_addr = device.substr(0, device.find(':'));
66  iretn = socket_open(&schannel, NetworkType::UDP, "", device_port, SOCKET_LISTEN, true, 5000000);
67  }
68  else
69  {
70  device_type = PORT_TYPE_RS232;
71  device_addr = device;
72  shandle = new Serial(device_addr, 19200);
73  shandle->set_timeout(5.);
74  }
75  break;
76  default:
77  printf("Usage: kiss_recv [device [tcount]]\n");
78  exit(-1);
79  }
80 
81 
82 
83  for (size_t i=0; i<tcount; ++i)
84  {
86  vector <uint8_t> packet;
87 
88  if (device_type == PORT_TYPE_ETHERNET)
89  {
90  iretn = socket_recvfrom(schannel, packet, 1500);
91  }
92  else
93  {
94  iretn = shandle->get_slip(packet);
95  }
96  if (iretn > 0)
97  {
98  handle.set_slip_packet(packet);
101  printf("%s\n", to_hex_string(handle.get_data(), true).c_str());
102  }
103  else
104  {
105  printf("Timeout: [%d] %s\n", iretn, cosmos_error_string(iretn).c_str());
106  }
107 
108  fflush(stdout);
109  }
110 }
Definition: jsondef.h:647
Agent socket using Unicast UDP.
uint8_t get_port_number()
Definition: kisslib.cpp:52
PORT_TYPE
Definition: jsondef.h:644
static uint16_t device_port
Definition: ax25_recv.cpp:41
int i
Definition: rw_test.cpp:37
int32_t socket_recvfrom(socket_channel &channel, string &buffer, size_t maxlen, int flags)
Definition: socketlib.cpp:710
Definition: serialclass.h:43
int iretn
Definition: rw_test.cpp:37
ElapsedTime et
Definition: agent_cpu_device_test.cpp:51
uint8_t get_source_stationID()
Definition: kisslib.cpp:138
static string device_addr
Definition: ax25_recv.cpp:40
uint8_t get_command()
Definition: kisslib.cpp:63
string cosmos_error_string(int32_t cosmos_errno)
Definition: cosmos-errno.cpp:45
string to_hex_string(vector< uint8_t > buffer, bool ascii)
Definition: stringlib.cpp:204
int32_t unload_packet()
Definition: kisslib.cpp:292
int32_t set_slip_packet(vector< uint8_t > packet)
Definition: kisslib.cpp:270
Definition: socketlib.h:115
static KissHandle handle
Definition: kiss_recv.cpp:38
string get_destination_callsign()
Definition: kisslib.cpp:85
Definition: elapsedtime.h:62
int32_t set_timeout(int, double timeout)
Definition: serialclass.cpp:515
string get_source_callsign()
Definition: kisslib.cpp:122
#define SOCKET_LISTEN
Listen followed by optional talk (recvfrom INADDRANY)
Definition: socketlib.h:84
uint8_t get_protocolID()
Definition: kisslib.cpp:160
static Serial * shandle
Definition: kiss_send.cpp:35
Definition: jsondef.h:645
uint8_t get_destination_stationID()
Definition: kisslib.cpp:101
vector< uint8_t > get_data()
Definition: kisslib.cpp:276
int32_t socket_open(socket_channel *channel, NetworkType ntype, const char *address, uint16_t port, uint16_t role, bool blocking, uint32_t usectimeo, uint32_t rcvbuf, uint32_t sndbuf)
Open UDP socket.
Definition: socketlib.cpp:51
static string device
Definition: kiss_recv.cpp:39
uint8_t get_control()
Definition: kisslib.cpp:149
int32_t get_slip(vector< uint8_t > &data, size_t size=SIZE_MAX)
Read SLIP frame.
Definition: serialclass.cpp:1322

Variable Documentation

KissHandle handle
static
string device ="/dev/tty_tnc"
static
string source
static
string destination
static
vector<uint8_t> message
static