tcp_pump_client.h 1.83 KB
Newer Older
1 2
#ifndef TCP_PUMP_CLIENT_H
#define TCP_PUMP_CLIENT_H
3 4 5 6 7 8 9 10 11 12 13 14

#include <sys/types.h>
#include <sys/socket.h> /* socket functions */
#include <sys/time.h>  /* FD_SET, FD_ISSET, FD_ZERO, timeval, fd_set */
#include <sys/select.h>/* select() */
#include <stdio.h>
#include <stdlib.h> /* exit, EXIT_FAILURE */
#include <string.h> /* memcpy */
#include <unistd.h>
#include <netdb.h> /* gethostbyname */
#include <netinet/in.h>/* sockaddr_in */
#include <iostream>
15
#include <memory>
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#include "CLA_Logger.h"
#include "rapidjson/document.h"

using namespace rapidjson; /* third party library for parsing json data */
using namespace std;

namespace CLA {
  class tcp_pump_client {
    /* impementation of a non-blocking tcp client to talk
    *  to the rosbridge udp server
    */
    private:
      struct hostent *hp; /* host information */
      struct sockaddr_in servaddr; /* server address information */
      struct timeval timeout;
      string json_message;
      double m_current_rate;
33
      double m_substance_last_sent_rate;
34 35 36 37
      double m_new_rate;
      double m_last_sent_rate;
      string m_topic;
      string m_type;
38
      string m_substance;
39 40 41 42 43 44 45 46 47 48
      static const int BUFF_SIZE = 100;
      char buff[BUFF_SIZE];
      const char* m_host;
      int port;
      int fd, rec_value,recvlen;
      int SOCKET_TIMEOUT_SEC;
      int SOCKET_TIMEOUT_uSEC;
      socklen_t addrlen;
      Document document; /* to parse json data */
      fd_set set; /* descriptor read set*/
49
      std::shared_ptr<CLA::LOGGER> m_logger;
50
    public:
51 52
      tcp_pump_client(const string&, const string&, const string&, \
        std::shared_ptr<CLA::LOGGER>&);
53
      ~tcp_pump_client();
54
      void setup_connection();
55 56 57 58 59 60 61 62
      double getCurrentInfusionRate(const string&);
      double get_new_rate(const string&);
      double waiting_for_new_rate(const string&);
      void clear();
  };
}

#endif