/****************************************************************************/
/* 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 <curl.h>
#include "ourTypes.h";
#include "PeriodicTask.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);

   /* 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();

   /* data */

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

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

   Boolean _recording;

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

#endif
