 /*
 *
 * Thom Maughan: MBARI, tm@mbari.org  from 2/2018
 */

#ifndef MPHOX_CONDO_H_
#define MPHOX_CONDO_H_

#include "system.h"

#define CTD_BAUD                9600

#define TYPE_CTD_NOTDEFD            0
#define TYPE_SBE37_MICROCAT         1
#define TYPE_AANDERAA_5860          2


#define COMMA 0x2C
#define TAB   '\t'  //0x09   //CTRL-I

#define ST_CTD_NADA             0
#define ST_CTD_INIT             1
#define ST_CTD_SBE_PWR_RESP     2
#define ST_CTD_SBE_GET_DATA     3
#define ST_CTD_AAND_PWR_RESP    4
#define ST_CTD_GET_AAND_DATA    5

void ctd_init(void);   // mphox board CTD port
void ctd_open(void);
void ctd_close(void);
int  ctd_stateMachine(int condoState);
uint32_t wait_ctdRx(uint32_t maxWait_10msTick);
uint32_t ctd_qa_test(void);
void ctd_print_buf(void);


void ctd_aanderaa_serial_analyzer(void);
void ctd_microcat_serial_analyzer(void);

struct ctdDriver
{
             int state;
    unsigned int old_tick10ms;      // for timeout
    unsigned int new_tick10ms;
    unsigned int type;          // which type of CTD
    float        condo;
    float        salt;
    float        tempC;
    float        pressure;
    float        depth;
    unsigned int bufIndx;
    unsigned char buf[CTD_BUFFER_SIZE];      // defd in system.h
};


unsigned char ctd_getc(void);
void ctd_putc(unsigned char c);
int ctd_rxBytesAvail(void);
void ctd_flushRx(void);
int ctd_write(const char *pcBuf, uint32_t ui32Len);



#ifdef NOCODE
// Serial Connection
void ctd_config(uint32_t ui32Port, uint32_t ui32Baud,
                            uint32_t ui32SrcClock);
int ctd_gets(char *pcBuf, uint32_t ui32Len);
unsigned char ctd_getc(void);
int ctd_write(const char *pcBuf, uint32_t ui32Len);
int ctd_peek(unsigned char ucChar);
void ctd_flushTx(bool bDiscard);
void ctd_flushRx(void);
uint32_t wait_ctdRx(uint32_t maxWait_10msTick);
int ctd_rxBytesAvail(void);
int ctd_txBytesFree(void);
void ctd_echoSet(bool bEnable);
//int ctd_putc(const char c);
void ctd_putc(unsigned char c);
#endif


//extern void ctd_IntHandler(void);




#endif /* MPHOX_CONDO_H_ */
