/****************************************************************************/
/* Copyright 1991 to 1996 MBARI                                             */
/****************************************************************************/
/* Summary  : Client Declarations for RS485 microcontroller serial protocol */
/* Filename : sio32Client.h                                                 */
/* Author   : Andrew Pearce                                                 */
/* Project  : Tiburon ROV VME to Microcontroller Communications Interface     */
/* Version  : 2.1                                                           */
/* Created  : 06/04/92                                                      */
/* Modified : 03/08/96                                                      */
/* Archived :                                                               */
/****************************************************************************/

#ifndef _SIO32_CLIENT_H
#define _SIO32_CLIENT_H

#define MAX_PACKET_LEN     256      /* Maximum length of a single packet    */
#define SRQ_PACKET_LEN     256      /* Maximim length of an SRQ Packet      */

#define SIO32_BAUD_RATE  38400      /* Baud rate for all sio32 channels     */

#define DATA_PACKET       0xfe      /* Data Packet Type                     */
#define SRQ_PACKET        0xfd      /* Service Request Packet Type          */

typedef struct
{
    MSG_Q_ID        replyQId;       /* Server Reply Message Queue           */
    sio32ServerCmd  cmd;            /* Request Command                      */
    Nat16           channel;        /* SIO32 Channel number                 */
    Byte            args[MAX_REQ_MSG_LEN];
} sio32Request;

typedef struct
{
    MSG_Q_ID replyQId;              /* Message Queue for to use for reply   */
    Nat16    type;                  /* Packet Type Field                    */
    Byte     data[MAX_PACKET_LEN];  /* Packet Data Field                    */
} sio32Packet;

typedef struct                      /* Client <==> Server channel structure */
{
    Nat32       channel;            /* Request Command                      */
    Int32       timeout;            /* Microcontroller command timeout      */
    SEM_ID      mutexSem;           /* Micro command mutual exclusion sem   */
    MSG_Q_ID    rxDataQId;          /* Receive Traffic Message Queue        */
    MSG_Q_ID    txDataQId;          /* Transmit Traffic Message Queue       */
    MSG_Q_ID    rxSrqQId;           /* Receive SRQ (Alarm) Traffic Queue    */
} sio32Chan;

#ifdef __STDC__

Void sendCmdArgPacket(sio32Chan *sio32Channel, Word command, Word argument);

Void sendWordPacket(sio32Chan *sio32Channel, Word value);

STATUS readServerPacket(sio32Chan *sio32Channel, Byte *packet, Int16 maxBytes,
     Int32 timeout);

STATUS writeServerPacket( sio32Chan *sio32Channel, Byte *packet, Word length );

STATUS sendPacketToServer( sio32Chan *sio32Channel, Byte *packet, Word length);

STATUS readSRQPacket(sio32Chan *sio32Channel, Byte *packet, Int16 maxBytes,
     Int32 timeout);

STATUS clearSio32Statistics(Nat16 serialChan);

STATUS getSio32Statistics(Nat16 serialChan, pktStat *statistics);

Int32 getSio32PSStatus( sio32ServerId serverId );

STATUS sio32ChanInit(Nat16 serialChannel, char *sio32DevName,
     sio32Chan *sio32DataChan);

STATUS sio32FwdChanInit(Nat16 serialChannel, char *sio32DevName,
     sio32Chan *sio32DataChan, Nat16 attachedChan,
     sio32Chan *attachedDataChan);

STATUS sio32RS232ChanInit(Nat16 serialChannel, char *sio32DevName,
     Nat32 baudRate, Nat32 dataBits, Nat32 stopBits, char *parity,
     sio32Chan *sio32DataChan);

STATUS sio32RS485ChanInit(Nat16 serialChan, char *sio32DevName, Nat32 baudRate,
    Nat32 dataBits, Nat32 stopBits, char *parity, sio32Chan *sio32DataChan);

STATUS sio32ChanDestroy( Nat16 channel, sio32Chan *sio32DataChan);

Void sio32ChanRxFlush( sio32Chan *sio32Channel );

Void sio32ChanSetRxTimeout( sio32Chan *sio32Channel, Int32 timeout );

STATUS sio32ChanSetKeepAliveMode( Nat16 serialChan, Int32 keepAliveTicks,
    Nat32 keepAliveCount );

#endif /* __STDC__ */

#endif /* _SIO32_CLIENT_H */
