/*
 * ph_rcvr.h
 * Library for back-end receiver of pH data, e.g. back-end mpHox receiving pH data collected by front end mFET
 *
 *  Created on: Nov 19, 2021
 *      Author: Irene
 */

#ifndef PH_BACK_H_
#define PH_BACK_H_

#include "ph_base.h"
#include "uart4.h" // uart driver for rs232 comms - steal ctd's
#include "uartstdio.h" // UARTwrite etc for test menu and writing buffer to screen
#include "fatfs/src/ff.h" // output to file
#include "microsd.h" // some more file output stuff
#include "board_util.h" // to power on phf

// ADC frequencies, khz
#define VRS_MEAS_FREQ 20
#define THERM_MEAS_FREQ 100

// initialize and uart wrapper functions
void phb_init(void);
void phb_openphf(void);
void phb_closephf(void);
int phb_rxBytesAvail(void);
unsigned char _phb_getc(void);
void _phb_putc(unsigned char c);
void _phb_flushRx(void);
void _phb_flushTx(bool bDiscard);
int _phb_write(const char *pcBuf, uint32_t ui32Len);

// workhorse functions
void phb_comm_test(void);
int phb_measOnce(struct pH_ptdata *pHDatStruct);
int phb_measCont(double measFreq_Hz, double measDuration_min, char* fn_append, int txFlg);

// 'public' functions
int phb_readpHThermData(struct pH_ptdata *pHDatStruct);
int phb_startMeas(void);
int phb_getMeas(struct pH_ptdata *pHDatStruct);
int phb_stopMeas(void);

// 'private'
int _phb_sendTwoCharCmd(char *cmdToRcvr);
int _phb_receiveAck(void);
int _phb_sortIncomingDataStruct();


#endif /* PH_BACK_H_ */
