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

#ifndef PHFETSOS_CONDO_H_
#define PHFETSOS_CONDO_H_

#include "system.h"

#define CTD_BAUD                9600

/*
 * ASCII characters.
 */
#define SPACE 0x20
#define COMMA 0x2C
#define OPENBRACE 0x7b
#define TAB 0x09

#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);
unsigned char ctd_getc(void);
void ctd_putc(unsigned char c);
int ctd_rxBytesAvail(void);
void ctd_flushRx(void);
void ctd_flushTx(bool discardFlg);
int ctd_write(const char *pcBuf, uint32_t ui32Len);

int ctd_buf_putc(unsigned char inChar);     // write into uart4_prn_buf with size check

uint32_t ctd_waitRx(uint32_t maxWait_10msTick);

void ctd_tx_str(void);
int ctd_rx_buf_size(void);
int ctd_tx_buf_size(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);


//extern void ctd_IntHandler(void);




#endif /* PHFETSOS_CONDO_H_ */
