39 #include "ace/SOCK_Dgram.h"
41 #include "ace/Thread.h"
42 #include "ace/Logging_Strategy.h"
58 #include "OPCprotocolManager.h"
59 #include "OPCprotocolManager_Cfg.h"
80 #define DEFAULT_LOCAL_IP "10.0.1.104"
81 #define DEFAULT_PORT 4444
82 #define PAYLOAD_MAX_SIZE 128
128 static void s_check_seqNum(ACE_INET_Addr src_addr, uint32_t recseqnum);
132 printf(
"\n Received signal to quit %d\n", _signum);
144 ACE_UINT32 ip1,ip2,ip3,ip4;
147 uint16_t payload_size = 0;
149 ACE_thread_t id_recvThread;
151 uint32_t byte2send = 0;
170 for(
int i = 1; i <
argc; i++)
173 if(strcmp(
"--loc-ip", argv[i]) == 0 )
180 if(strcmp(
"--port", argv[i]) == 0 )
183 port = atoi(argv[++i]);
187 if((strcmp(
"-h", argv[i]) == 0) || (strcmp(
"--help", argv[i]) == 0))
200 printf(
"\nConfiguration is : \n\n");
204 sscanf(local.
address_string.c_str(),
"%d.%d.%d.%d",&ip1,&ip2,&ip3,&ip4);
205 local.
addr.set(port, (ip1<<24)|(ip2<<16)|(ip3<<8)|ip4 );
212 printf(
"Error opening socket!!!\n");
217 ACE_socket->get_option(SOL_SOCKET,SO_RCVBUF,(
void *)&
n, &m);
218 printf(
"SO_RCVBUF %d\n",
n);
219 ACE_socket->get_option(SOL_SOCKET,SO_SNDBUF,(
void *)&
n, &m);
220 printf(
"SO_SNDBUF %d\n",
n);
221 ACE_socket->get_option(SOL_SOCKET,SO_RCVLOWAT,(
void *)&
n, &m);
222 printf(
"SO_RCVLOWAT %d\n",
n);
240 printf(
"Launching recvThread\n");
241 if(ACE_Thread::spawn((ACE_THR_FUNC)
recvThread, NULL, THR_CANCEL_ENABLE, &id_recvThread)==-1)
243 printf((
"Error in spawning recvThread\n"));
248 opcMan_ptr = opcprotman_New(OPCprotocolManager_Cfg_getconfig());
251 printf(
"Error in creating opcprotman\n!");
259 char in_cmd[10], aux[2];
263 ret = scanf(
"%s", in_cmd);
265 if((strcmp(
"quit", in_cmd) == 0 ))
272 n_cmd = atoi(in_cmd);
321 printf(
"Command not known!\n");
327 ssize_t sentBytes =
ACE_socket->send(&payload_buffer[0], byte2send, remote.
addr, 0);
328 ACE_TCHAR address[64];
329 remote.
addr.addr_to_string(address, 64);
330 printf(
"payload of size %d is sent to %s!! (sentbytes=%ld)\n", byte2send, address, sentBytes);
334 printf(
"nothing to send");
343 printf(
"mainThraed: exit from while..going to sleep\n");
346 printf(
"mainThraed: exit from sleep\n");
348 ACE_Thread::cancel(id_recvThread);
361 printf(
"recvThread started\n");
365 size_t rec_payload_size = 0;
366 uint16_t replysize = 0;
367 ACE_INET_Addr src_addr;
368 ACE_TCHAR address[64];
369 opcprotman_res_t res;
372 sockaddr sender_addr;
378 src_addr.addr_to_string(address, 64);
379 printf(
"\n\nReceived pkt of size = %ld from %s\n", rec_payload_size, address);
388 res = opcprotman_Parse(
opcMan_ptr, (opcprotman_message_t*)&rec_payload_buffer[0], (opcprotman_message_t*) &replay_payload_buffer[0], &replysize);
389 if(opcprotman_OK != res)
391 printf(
"erron in parser\n");
396 printf(
"recThraed: exit from while\n");
407 printf(
"usage: \t\t--help print this help\n");
408 printf(
"\t\t--loc-ip <xx> set the ip address of the local machine - needed by yarp - by default %s\n",
DEFAULT_LOCAL_IP);
409 printf(
"\t\t--port <xx> set the socket port - by default %d\n",
DEFAULT_PORT);
417 uint32_t addr = src_addr.get_ip_address();
419 board = addr- 0xa000100;
422 printf(
"error in get board: num=%d, addr=%d\n",
board, addr );
428 printf(
"seqnum first board %d num %d\n",
board, recseqnum);
435 printf(
"error in SEQ NUM form board %d: rec %d expected = %d\n",
board, recseqnum,
seqnumList[
board] +1);
440 printf(
"received SEQ NUM from board %d: %d\n",
board, recseqnum);
int main(int argc, char *argv[])
OPCprotocolManager * opcMan_ptr
void * recvThread(void *arg)
ACE_SOCK_Dgram * ACE_socket
static void s_check_seqNum(ACE_INET_Addr src_addr, uint32_t recseqnum)
static void sighandler(int _signum)
opcprotman_cfg_t * get_OPCprotocolManager_cfg(void)
static uint8_t isfirstList[10]
static uint32_t seqnumList[10]