COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
agent_transmitter.cpp File Reference
#include "support/configCosmos.h"
#include <stdio.h>
#include "agent/agentclass.h"
#include "physics/physicslib.h"
#include "support/jsonlib.h"
#include <cstring>
#include "device/general/kisslib.h"
#include "device/general/cssl_lib.h"
Include dependency graph for agent_transmitter.cpp:

Macros

#define SERIAL_USB0   16
 
#define MAXBUFFERSIZE   256
 
#define REQUEST_RUN_PROGRAM   0
 

Functions

int agent_transmitter ()
 
int32_t transmit_kiss (string &request, string &response, Agent *)
 
int main (int argc, char *argv[])
 

Variables

char agentname [COSMOS_MAX_NAME+1] = "gs_tx"
 
char node [50] = "otb"
 
int waitsec = 5
 
unsigned int rx_report_interval
 
Agentagent
 
int32_t diskfree
 
int32_t stateflag
 
int32_t myport
 
cssl_thandle
 

Macro Definition Documentation

#define SERIAL_USB0   16
#define MAXBUFFERSIZE   256
#define REQUEST_RUN_PROGRAM   0

Function Documentation

int agent_transmitter ( )
113 {
114  //FILE *fp;
115 
116  // Start performing the body of the agent
117  while(agent->running())
118  {
119  unsigned int rxcount;
120  unsigned char serial_input[1000];
121 
122 
123  // Read Serial Port(s)
124 // rxcount = RS232_PollComport(SERIAL_USB0, serial_input, 1000);
125  rxcount = cssl_getdata(handle, serial_input, 1000);
126 
127  // Print Inbound Characters if New Input Found
128  if (rxcount)
129  {
130  printf("RX: ");
131  for(unsigned int i=0;i < rxcount;i++)
132  {
133  printf("%c",serial_input[i]);
134  }
135  printf("\n");
136  }
137 
138  COSMOS_USLEEP(100000); // no support in win, sleep for 100ms
139  }
140  return 0;
141 }
Agent * agent
Definition: agent_transmitter.cpp:65
int i
Definition: rw_test.cpp:37
uint16_t running()
Check if we&#39;re supposed to be running.
Definition: agentclass.cpp:391
int32_t cssl_getdata(cssl_t *serial, uint8_t *buffer, int size)
Definition: cssl_lib.cpp:738
cssl_t * handle
Definition: agent_transmitter.cpp:75
int32_t transmit_kiss ( string &  request,
string &  response,
Agent  
)
145 {
146  int32_t iretn = 0;
147  unsigned char packet_buffer[600]; // w/c count will be 529 bytes (18+1+255*2)
148  int payload_size; // Packet Byte Count
149  int input_size; // Request Input Byte Count
150  unsigned char *raw_byte_backdoor;
151 
152  request += 3; // Advance pointer to skip "tx ", transmit the rest
153  raw_byte_backdoor = reinterpret_cast<unsigned char *>(&request[0]);
154 
155  printf("Received Request");
156 
157  // Check Input Length
158  input_size = request.length(); // Get size of null terminated string
159  printf(".");
160  /*
161 if(input_size == -1 || input_size > 255)
162 {
163  memcpy(response,"Error: Input larger than 255 maximum", 36);
164  iretn=1;
165  return iretn;
166 }
167 */
168 
169  printf("TX Input: ");
170  for(int z=0;z<input_size;z++)
171  {
172  printf("%02x ", raw_byte_backdoor[z]);
173  }
174  printf("\n");
175 
176  // Encode KISS Packet
177  payload_size = kissEncode(raw_byte_backdoor,input_size,packet_buffer);
178 
179  // Test Print
180  printf("TX KISS Output: ");
181  for(int z=0;z<payload_size;z++)
182  {
183  printf("%02x ", packet_buffer[z]);
184  }
185  printf("\n\n");
186 
187 
188 // RS232_SendBuf(SERIAL_USB0,packet_buffer,payload_size);
189  cssl_putdata(handle, packet_buffer, payload_size);
190 
191 
192  //#printf("Transmitting: %s\n",request.substr(3));
193 
194 
195  return iretn;
196 }
int kissEncode(uint8_t *input, uint32_t count, uint8_t *packet)
Definition: kisslib.cpp:183
int iretn
Definition: rw_test.cpp:37
int32_t cssl_putdata(cssl_t *serial, uint8_t *data, uint32_t datalen)
Definition: cssl_lib.cpp:553
cssl_t * handle
Definition: agent_transmitter.cpp:75
int main ( int  argc,
char *  argv[] 
)
78 {
79  int32_t iretn;
80 
81  // Check for other instance of this agent
82  if (argc == 2)
83  strcpy(node,argv[1]);
84 
85  // check if we are already running the agent
86  if ((iretn=agent->check_agent(node, "radio", waitsec)) > 0)
87  exit (iretn);
88 
89  // Initialization stuff
90 
91  // RS232 Library Initialization
92 // RS232_OpenComport(SERIAL_USB0,19200); // 16=ttyUSB0, 19200bps
93  handle = cssl_open("/dev/", 19200, 8, 0, 1);
94 
95  // Main Program RX Reporting Interval
96 
97 
98  // Initialize the Agent
99  // near future: support cubesat space protocol
100  // port number = 0 in this case, automatic assignment of port
101  if (!(agent = new Agent(node, "radio", 1., MAXBUFFERSIZE)))
102  exit (iretn);
103 
104  // Add additional requests
105  if ((iretn=agent->add_request("tx",transmit_kiss)))
106  exit (iretn);
107 
108  // Start our own thread
109  iretn = agent_transmitter();
110 }
Agent * agent
Definition: agent_transmitter.cpp:65
int iretn
Definition: rw_test.cpp:37
#define MAXBUFFERSIZE
Definition: agent_transmitter.cpp:67
int32_t check_agent(string node, string agent, double waitsec)
Check agent.
Definition: agentclass.cpp:546
char node[50]
Definition: agent_transmitter.cpp:59
int32_t add_request(string token, external_request_function function, string synopsis="", string description="")
Add internal request to Agent request list with description and synopsis.
Definition: agentclass.cpp:312
Definition: agentclass.h:139
int32_t transmit_kiss(string &request, string &response, Agent *)
Definition: agent_transmitter.cpp:144
int agent_transmitter()
Definition: agent_transmitter.cpp:112
int waitsec
Definition: agent_transmitter.cpp:60
cssl_t * cssl_open(const char *fname, int baud, int bits, int parity, int stop)
Definition: cssl_lib.cpp:108
cssl_t * handle
Definition: agent_transmitter.cpp:75

Variable Documentation

char agentname[COSMOS_MAX_NAME+1] = "gs_tx"
char node[50] = "otb"
int waitsec = 5
unsigned int rx_report_interval
Agent* agent
int32_t diskfree
int32_t stateflag
int32_t myport
cssl_t* handle