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

Classes

struct  channelstruc
 

Functions

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

Variables

static vector< channelstrucout_comm_channel
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)
68 {
69  int32_t iretn;
70 
71  Agent *agent = new Agent();
72 
73  string message = argv[2];
74 
75  out_comm_channel.resize(1);
76  if((iretn = socket_open(&out_comm_channel[0].chansock, NetworkType::UDP, "", AGENTRECVPORT, SOCKET_LISTEN, SOCKET_BLOCKING, 5000000)) < 0)
77  {
78  fprintf(agent->get_debug_fd(), "%16.10f Main: Node: %s Agent: %s - Listening socket failure\n", currentmjd(), agent->nodeName.c_str(), agent->agentName.c_str());
79  agent->shutdown();
80  exit (-errno);
81  }
82 
83  inet_ntop(out_comm_channel[0].chansock.caddr.sin_family, &out_comm_channel[0].chansock.caddr.sin_addr, out_comm_channel[0].chansock.address, sizeof(out_comm_channel[0].chansock.address));
84  out_comm_channel[0].chanip = out_comm_channel[0].chansock.address;
85  out_comm_channel[0].nmjd = currentmjd();
86  out_comm_channel[0].limjd = out_comm_channel[0].nmjd;
87  out_comm_channel[0].lomjd = out_comm_channel[0].nmjd;
88  out_comm_channel[0].fmjd = out_comm_channel[0].nmjd;
89  out_comm_channel[0].node = "";
90  out_comm_channel[0].throughput = 1000;
91  out_comm_channel[0].packet_size = (200-(PACKET_DATA_OFFSET_HEADER_TOTAL+28));
92  fprintf(agent->get_debug_fd(), "%16.10f Node: %s Agent: %s - Listening socket open\n", currentmjd(), agent->nodeName.c_str(), agent->agentName.c_str());
93  fflush(agent->get_debug_fd()); // Ensure this gets printed before blocking call
94 
95  out_comm_channel.resize(2);
96  out_comm_channel[1].node = argv[1];
97  size_t tloc = out_comm_channel[1].node.find(":");
98  if (tloc != string::npos)
99  {
100  out_comm_channel[1].chanip = out_comm_channel[1].node.substr(tloc+1, out_comm_channel[1].node.size()-tloc+1);
101  out_comm_channel[1].node = out_comm_channel[1].node.substr(0, tloc);
102  }
103  vector<PACKET_BYTE> packet;
104  make_message_packet(packet, static_cast <PACKET_NODE_ID_TYPE>(lookup_node_id(out_comm_channel[1].node)), message);
105 
107  {
108  fprintf(agent->get_debug_fd(), "%16.10f Node: %s IP: %s - Sending socket failure\n", currentmjd(), out_comm_channel[1].node.c_str(), out_comm_channel[1].chanip.c_str());
109  agent->shutdown();
110  exit (-errno);
111  }
112  out_comm_channel[1].nmjd = currentmjd();
113  out_comm_channel[1].limjd = out_comm_channel[1].nmjd;
114  out_comm_channel[1].lomjd = out_comm_channel[1].nmjd;
115  out_comm_channel[1].fmjd = out_comm_channel[1].nmjd;
116  out_comm_channel[1].throughput = 1000;
117  out_comm_channel[1].packet_size = (200-(PACKET_DATA_OFFSET_HEADER_TOTAL+28));
118  fprintf(agent->get_debug_fd(), "%16.10f Network: Old: %u %s %s %u\n", currentmjd(), 1, out_comm_channel[1].node.c_str(), out_comm_channel[1].chanip.c_str(), ntohs(out_comm_channel[1].chansock.caddr.sin_port));
119  fflush(agent->get_debug_fd());
120 
121  iretn = sendto(out_comm_channel[1].chansock.cudp, reinterpret_cast<const char*>(&packet[0]), packet.size(), 0, reinterpret_cast<sockaddr*>(&out_comm_channel[1].chansock.caddr), sizeof(struct sockaddr_in));
122 
123 }
FILE * get_debug_fd(double mjd=0.)
Definition: agentclass.cpp:2645
Agent socket using Unicast UDP.
string nodeName
Definition: agentclass.h:367
int32_t lookup_node_id(string node_name)
Definition: transferlib.cpp:514
int iretn
Definition: rw_test.cpp:37
#define SOCKET_TALK
Talk followed by optional listen (sendto address)
Definition: socketlib.h:82
#define PACKET_DATA_OFFSET_HEADER_TOTAL
Definition: transferlib.h:289
#define AGENTRECVPORT
Default RECV port.
Definition: agentclass.h:200
static Agent * agent
ensure the Agent constructor creates only one instance per process
Definition: agent_001.cpp:45
uint8_t message[300]
Definition: kpc9612p_send.cpp:36
Definition: agentclass.h:139
void make_message_packet(vector< PACKET_BYTE > &packet, PACKET_NODE_ID_TYPE node_id, string message)
Definition: transferlib.cpp:325
#define SOCKET_BLOCKING
Blocking Agent.
Definition: socketlib.h:78
int32_t shutdown()
Shutdown agent gracefully.
Definition: agentclass.cpp:366
static vector< channelstruc > out_comm_channel
Definition: file_send_message.cpp:65
#define AGENTRCVTIMEO
Default AGENT socket RCVTIMEO (100 msec)
Definition: agentclass.h:208
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
#define SOCKET_LISTEN
Listen followed by optional talk (recvfrom INADDRANY)
Definition: socketlib.h:84
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 node
Definition: agent_monitor.cpp:126
string agentName
Definition: agentclass.h:368

Variable Documentation

vector<channelstruc> out_comm_channel
static