/****************************************************************************/
/* Copyright (c) 2014 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  : Interface to the Cathx M12 camera.                            */
/* Filename : CathxM12.h                                                    */
/* Author   : Henthorn                                                      */
/* Project  : Iceberg AUV                                                   */
/* Version  : 1.0                                                           */
/* Created  : 05/13/2015                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#ifndef _CATHXM12_H
#define _CATHXM12_H

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <curl.h>
#include "ourTypes.h";
#include "PeriodicTask.h"
#include "NavigationIF.h"

class CathxM12Msg;
class CathxM12Log;
class CathxM12Output;

// Simple libcurl interface for use with the M12 camera from Cathx.
//
class CathxM12 : public PeriodicTask
{
   friend CathxM12Log;

public:
   // Create an interface to the server. The connection is only opened
   // when posting and getting.
   //
   CathxM12(const char* name, const char* server_ip,
            unsigned long port, int period = 1000);
   ~CathxM12();


protected:

   struct State {
      Boolean capture;
      int     profile;
   };

   // Called periodically to get messages from server
   //
   void m12_callback(void);
   int initialize_socket();

   /* Interface to the Cathx web server */
   CURL *_curl;
   static char   _response[];
   static size_t _response_size;
   static size_t read_response(void *buffer, size_t size, size_t nmemb, void *userp);
   int curl_setup();
   int curl_cleanup();
   int curl_execute();

   int capture(char* True_or_False);
   int profile(int profile_number);
   int status();
   void send_nav_data();

   /* data and such */

   CathxM12Msg    *_msgQ;
   CathxM12Log    *_log;
   CathxM12Output *_output;

   NavigationIF   *_navif;

   char _buf[1025];
   char _errorbuf[CURL_ERROR_SIZE];

   Boolean _recording;

   char* _name;
   char* _server_ip;
   unsigned long _port;
   int _period;

   /* UDP comms */
   int _sockfd;
   struct sockaddr_in _server_addr;
   Boolean _errmsg;
};

#endif
