COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
agent_transmitter2.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_transmitter2.cpp:

Macros

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

Functions

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

Variables

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

Macro Definition Documentation

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

Function Documentation

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

Variable Documentation

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