/* * LinkCommunication.h * LinkProcessorEmulator * * Created by Stephen Norum. * Copyright 2007 Stanford Linear Accelerator Center. All rights reserved. * */ #ifndef MPSLINKCOMMUNICATION_H #define MPSLINKCOMMUNICATION_H #ifdef __cplusplus extern "C" { #endif #include #include #include "mpsConstantsAndTypes.h" /*---------------------------------------------------------------------- * Special values *----------------------------------------------------------------------*/ enum { /* A fault will be occur when the receiver thread hasn't received * data in MPSLPReceiverTimeoutInMs milliseconds */ MPSLPReceiverTimeoutInMs = 200 }; enum { /* A connection timeout for the MPS Link Processore * will try to connect with this timeout interval (in milliseconds). */ MPSLPConnectionTimeoutInMs = 10000 }; enum MPSLPMsgRcvdCallbackStatus { MPSLPMsgRcvdCallbackStatusValidMessage = 0, MPSLPMsgRcvdCallbackStatusInvalidMessage = 1, MPSLPMsgRcvdCallbackStatusTimeout = 2 }; /*---------------------------------------------------------------------- * Structs and types *----------------------------------------------------------------------*/ struct MPSLPMessageStruct { epicsUInt32 senderIp; epicsUInt16 senderPort; epicsUInt8 protocolVersion; epicsUInt8 type; epicsUInt8 *header; epicsInt8 *data; }; typedef struct MPSLPMessageStruct MPSLPMessage; struct MPSLPMessagePermitStruct { MPSLPMessage message; epicsTimeStamp timestamp; epicsUInt8 timeslot; epicsUInt8 destination; epicsUInt8 estimatedBeamRate; epicsUInt8 beamPermitted[MPSMitigationDeviceCount]; epicsUInt8 rateAfterDevice[MPSMitigationDeviceCount]; epicsUInt8 outputCard; }; typedef struct MPSLPMessagePermitStruct MPSLPMessagePermit; struct MPSLPMessageSyncStruct { MPSLPMessage message; epicsTimeStamp timestamp; epicsUInt8 timeslot; }; typedef struct MPSLPMessageSyncStruct MPSLPMessageSync; union MPSLPMessageTypeAnyUnion { MPSLPMessage standard; MPSLPMessagePermit permit; MPSLPMessageSync sync; }; typedef union MPSLPMessageTypeAnyUnion MPSLPMessageTypeAny; typedef void (*MPSLP_MSG_RCVD_CALLBACK)(int status, MPSLPMessage *message, void *context); /*---------------------------------------------------------------------- * Function Prototypes *----------------------------------------------------------------------*/ int MPSLPSetMpsMsgRcvdCallback(MPSLP_MSG_RCVD_CALLBACK function, void *context); int MPSLPGetMpsMsgRcvdCallback(MPSLP_MSG_RCVD_CALLBACK *function, void **context); int MPSLPSetReceiveTimeoutCallback(epicsUInt8 state); int MPSLPSetReceiveInvalidMessageCallback(epicsUInt8 state); epicsUInt8 MPSLPGetReceiveTimeoutCallback(); epicsUInt8 MPSLPGetReceiveInvalidMessageCallback(); int MPSLPParseHeader(MPSLPMessage *message); int MPSLPParseMessage(MPSLPMessage *message); int MPSLPParsePermitMessage(MPSLPMessagePermit *message); int MPSLPParseSynchronizationMessage(MPSLPMessageSync *message); int MPSMessageSendToLinkProcessor(const void *data, int length); int MPSMessageSendTestMessage(); int MPSLPInitializeCommunication(); int MPSLPStartReceiveThread(unsigned int receiverEpicsThreadPriority); #ifdef __cplusplus } #endif #endif