#ifndef mainH
#define mainH

// MODBUS constants
#define MODBUS_ADDR_BTNEVENT 0x0100
#define MODBUS_ADDR_LEDTOGGLE 0x0000
#define MODBUS_ADDR_BACKLIGHT 0x0001
#define MODBUS_ADDR_LEDS 0x0000


// COM port functions
int COMopen(HANDLE *cporth, char *cportname);
void COMclose(HANDLE *cporth);
bool COMsetBuf(HANDLE cporth, int inlen, int outlen);
void COMsetFormat(HANDLE cporth, int baud, int stopbit);
void COMsetTimeouts(HANDLE cporth, int rxinterval, int rxtime, int rxmult, int txtime, int txmult);
void COMflushInput(HANDLE cporth);
unsigned long COMrxByte(HANDLE cporth, byte *byte);
unsigned long COMtxData(HANDLE cporth, void *data, unsigned long datalen);
unsigned long COMtxData(HANDLE cporth, void *data, unsigned long datalen);
unsigned long COMrxData(HANDLE cporth, void *data, unsigned long datalen);

// MODBUS functions
unsigned short CRC16(unsigned char *puchMsg, unsigned short usDataLen);
void wr16be(unsigned char **str, unsigned int data);
unsigned short rd16be(unsigned char **str);

int SendPushButtonEvent(int btndown, int btnup);
int SendLEDtoggleCmd(int mask);
int SendBacklightCmd(int state);
int GetLEDstate(int *leds);
int GetIdent(char *str, int id);
int GetCommEvents(unsigned int *count);

void WriteHelp(void);
void GetInfo(void);

#endif