 /*
 * David Muller; Germán Alfaro
 * davehmuller@gmail.com; alfaro.germanevera@gmail.com
 *
 * Thom Maughan: MBARI, tm@mbari.org  from 2/2018
 */

#ifndef MPHOX_OPTODE_H_
#define MPHOX_OPTODE_H_

#define OPTODE_BAUD     9600

/*
 * Optode.c function prototypes:
 */

void optode_poll(void);
void parseOptodeData(void);


void optode_init(void);
void optode_open(void);
void optode_close(void);

unsigned char optode_getc(void);
void optode_putc(unsigned char c);
int optode_rxBytesAvail(void);
void optode_flushRx(void);
void optode_flushTx(bool bDiscard);
int optode_write(const char *pcBuf, uint32_t ui32Len);



int optode_stateMachine(int optodeState);
uint32_t optode_qa_test(void);
void optode_print_buf(void);
void optode_comm_test(void);
uint32_t wait_optodeRx(uint32_t maxWait_10msTick);

void optode_IntHandler(void);  //isr

void optode_serial_analyzer(void);




// Serial Connection
//extern void optode_config(uint32_t ui32Port, uint32_t ui32Baud,
//                            uint32_t ui32SrcClock);
//extern int optode_gets(char *pcBuf, uint32_t ui32Len);
//extern unsigned char optode_getc(void);
//extern int optode_write(const char *pcBuf, uint32_t ui32Len);
//extern int optode_peek(unsigned char ucChar);
//extern void optode_flushTx(bool bDiscard);
//extern void optode_flushRx(void);
//extern int optode_rxBytesAvail(void);
//extern int optode_txBytesFree(void);
//extern void optode_echoSet(bool bEnable);


struct optodeDriver
{
             int state;
    unsigned int old_tick10ms;      // for timeout
    unsigned int new_tick10ms;
    unsigned int bufIndx;
    unsigned char buf[OPTODE_BUFFER_SIZE];      // defd in system.h
};


#endif /* SEAPHOX_MFET_OPTODE_H_ */
