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

Functions

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

Variables

static Ax25Handle handle
 
static string device = "127.0.0.1:10001"
 
static string device_addr = "127.0.0.1"
 
static uint16_t device_port = 10003
 
static string source
 
static string destination
 
static vector< uint8_t > message
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)
47 {
48  PORT_TYPE device_type;
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: ax25_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_data(packet);
95  }
96  if (iretn > 0)
97  {
98  handle.set_raw_packet(packet);
101  printf("%s\n", to_hex_string(handle.get_packetData(), 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
uint8_t get_source_stationID()
Definition: ax25class.cpp:113
Agent socket using Unicast UDP.
PORT_TYPE
Definition: jsondef.h:644
static uint16_t device_port
Definition: ax25_recv.cpp:41
int i
Definition: rw_test.cpp:37
vector< uint8_t > get_packetData()
Definition: ax25class.cpp:145
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_protocolID()
Definition: ax25class.cpp:135
static string device_addr
Definition: ax25_recv.cpp:40
string get_source_callsign()
Definition: ax25class.cpp:97
string to_hex_string(vector< uint8_t > buffer, bool ascii)
Definition: stringlib.cpp:204
Definition: socketlib.h:115
int32_t set_raw_packet(vector< uint8_t > packet)
Definition: ax25class.cpp:156
uint8_t get_control()
Definition: ax25class.cpp:124
Definition: elapsedtime.h:62
int32_t unload_packet()
Definition: ax25class.cpp:172
static Ax25Handle handle
Definition: ax25_recv.cpp:38
int32_t set_timeout(int, double timeout)
Definition: serialclass.cpp:515
#define SOCKET_LISTEN
Listen followed by optional talk (recvfrom INADDRANY)
Definition: socketlib.h:84
static Serial * shandle
Definition: kiss_send.cpp:35
Definition: jsondef.h:645
string get_destination_callsign()
Definition: ax25class.cpp:60
int32_t get_data(vector< uint8_t > &data, size_t size=SIZE_MAX)
Definition: serialclass.cpp:1202
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
uint8_t get_destination_stationID()
Definition: ax25class.cpp:76
static string device
Definition: ax25_recv.cpp:39

Variable Documentation

Ax25Handle handle
static
string device = "127.0.0.1:10001"
static
string device_addr = "127.0.0.1"
static
uint16_t device_port = 10003
static
string source
static
string destination
static
vector<uint8_t> message
static