- Adapted indenation to new agreed upon system
- Added support for second generation scriptcontext based counter
This commit is contained in:
230
interface.c
230
interface.c
@@ -45,156 +45,162 @@
|
||||
/*=========================================================================
|
||||
Empty driveable interface functions
|
||||
==========================================================================*/
|
||||
static int EmptyHalt(void *self){
|
||||
static int EmptyHalt(void *self)
|
||||
{
|
||||
return OKOK;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
static int EmptyLimits(void *self, float fVal, char *error, int errLen){
|
||||
static int EmptyLimits(void *self, float fVal, char *error, int errLen)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
static long EmptyValue(void *self, SConnection *pCon, float fVal){
|
||||
SCWrite(pCon,"WARNING: empty SetValue",eWarning);
|
||||
static long EmptyValue(void *self, SConnection * pCon, float fVal)
|
||||
{
|
||||
SCWrite(pCon, "WARNING: empty SetValue", eWarning);
|
||||
return OKOK;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
static int EmptyStatus(void *self, SConnection *pCon){
|
||||
static int EmptyStatus(void *self, SConnection * pCon)
|
||||
{
|
||||
return HWIdle;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
static float EmptyGet(void *self, SConnection *pCon){
|
||||
SCWrite(pCon,"WARNING: empty GetValue",eWarning);
|
||||
static float EmptyGet(void *self, SConnection * pCon)
|
||||
{
|
||||
SCWrite(pCon, "WARNING: empty GetValue", eWarning);
|
||||
return 555.55;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
pIDrivable CreateDrivableInterface(void)
|
||||
{
|
||||
pIDrivable pRes = NULL;
|
||||
|
||||
pRes = (pIDrivable)malloc(sizeof(IDrivable));
|
||||
if(!pRes)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
memset(pRes,0,sizeof(IDrivable));
|
||||
pRes->ID = DRIVEID;
|
||||
pRes->Halt = EmptyHalt;
|
||||
pRes->CheckLimits = EmptyLimits;
|
||||
pRes->SetValue = EmptyValue;
|
||||
pRes->CheckStatus = EmptyStatus;
|
||||
pRes->GetValue = EmptyGet;
|
||||
pRes->drivableStatus=HWIdle;
|
||||
return pRes;
|
||||
pIDrivable CreateDrivableInterface(void)
|
||||
{
|
||||
pIDrivable pRes = NULL;
|
||||
|
||||
pRes = (pIDrivable) malloc(sizeof(IDrivable));
|
||||
if (!pRes) {
|
||||
return NULL;
|
||||
}
|
||||
memset(pRes, 0, sizeof(IDrivable));
|
||||
pRes->ID = DRIVEID;
|
||||
pRes->Halt = EmptyHalt;
|
||||
pRes->CheckLimits = EmptyLimits;
|
||||
pRes->SetValue = EmptyValue;
|
||||
pRes->CheckStatus = EmptyStatus;
|
||||
pRes->GetValue = EmptyGet;
|
||||
pRes->drivableStatus = HWIdle;
|
||||
return pRes;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
pICountable CreateCountableInterface(void)
|
||||
{
|
||||
pICountable pRes = NULL;
|
||||
|
||||
pRes = (pICountable)malloc(sizeof(ICountable));
|
||||
if(!pRes)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
memset(pRes,0,sizeof(ICountable));
|
||||
pRes->ID = COUNTID;
|
||||
return pRes;
|
||||
pICountable CreateCountableInterface(void)
|
||||
{
|
||||
pICountable pRes = NULL;
|
||||
|
||||
pRes = (pICountable) malloc(sizeof(ICountable));
|
||||
if (!pRes) {
|
||||
return NULL;
|
||||
}
|
||||
memset(pRes, 0, sizeof(ICountable));
|
||||
pRes->ID = COUNTID;
|
||||
return pRes;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
pEVInterface CreateEVInterface(void)
|
||||
{
|
||||
pEVInterface pRes = NULL;
|
||||
|
||||
pRes = (pEVInterface)malloc(sizeof(EVInterface));
|
||||
if(!pRes)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
memset(pRes,0,sizeof(EVInterface));
|
||||
pRes->iID = ENVIRINTERFACE;
|
||||
return pRes;
|
||||
pEVInterface CreateEVInterface(void)
|
||||
{
|
||||
pEVInterface pRes = NULL;
|
||||
|
||||
pRes = (pEVInterface) malloc(sizeof(EVInterface));
|
||||
if (!pRes) {
|
||||
return NULL;
|
||||
}
|
||||
memset(pRes, 0, sizeof(EVInterface));
|
||||
pRes->iID = ENVIRINTERFACE;
|
||||
return pRes;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static void *FindInterface(void *pObject, int iID)
|
||||
{
|
||||
pDummy pDum = NULL;
|
||||
|
||||
pDum = (pDummy)pObject;
|
||||
if(!pDum)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if(!pDum->pDescriptor)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pDum->pDescriptor->GetInterface(pDum,iID);
|
||||
static void *FindInterface(void *pObject, int iID)
|
||||
{
|
||||
pDummy pDum = NULL;
|
||||
|
||||
pDum = (pDummy) pObject;
|
||||
if (!pDum) {
|
||||
return NULL;
|
||||
}
|
||||
if (!pDum->pDescriptor) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pDum->pDescriptor->GetInterface(pDum, iID);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
pIDrivable GetDrivableInterface(void *pObject)
|
||||
{
|
||||
return (pIDrivable)FindInterface(pObject,DRIVEID);
|
||||
}
|
||||
pIDrivable GetDrivableInterface(void *pObject)
|
||||
{
|
||||
return (pIDrivable) FindInterface(pObject, DRIVEID);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
int GetDrivablePosition(void *pObject, SConnection *pCon, float *fPos)
|
||||
int GetDrivablePosition(void *pObject, SConnection * pCon, float *fPos)
|
||||
{
|
||||
pIDrivable pDriv = NULL;
|
||||
pMotor pMot = NULL;
|
||||
float value;
|
||||
|
||||
pDriv = GetDrivableInterface(pObject);
|
||||
if(pDriv == NULL)
|
||||
{
|
||||
if (pDriv == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if(iHasType(pObject,"Motor"))
|
||||
{
|
||||
pMot = (pMotor)pObject;
|
||||
return MotorGetSoftPosition(pMot,pCon,fPos);
|
||||
if (iHasType(pObject, "Motor")) {
|
||||
pMot = (pMotor) pObject;
|
||||
return MotorGetSoftPosition(pMot, pCon, fPos);
|
||||
}
|
||||
value = pDriv->GetValue(pObject,pCon);
|
||||
if(value < 9999.99)
|
||||
{
|
||||
value = pDriv->GetValue(pObject, pCon);
|
||||
if (value < 9999.99) {
|
||||
return 0;
|
||||
}
|
||||
*fPos = value;
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
pICountable GetCountableInterface(void *pObject)
|
||||
{
|
||||
return (pICountable)FindInterface(pObject,COUNTID);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int GetCountLock(pICountable self, SConnection *pCon)
|
||||
{
|
||||
if(self->running == 1)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: someone else is already counting!", eError);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
self->running = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void ReleaseCountLock(pICountable self)
|
||||
{
|
||||
self->running = 0;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int isRunning(pICountable self)
|
||||
{
|
||||
return self->running;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
pICallBack GetCallbackInterface(void *pObject)
|
||||
{
|
||||
return (pICallBack)FindInterface(pObject,CALLBACKINTERFACE);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
pICountable GetCountableInterface(void *pObject)
|
||||
{
|
||||
return (pICountable) FindInterface(pObject, COUNTID);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int GetCountLock(pICountable self, SConnection * pCon)
|
||||
{
|
||||
if (self->running == 1) {
|
||||
SCWrite(pCon, "ERROR: someone else is already counting!", eError);
|
||||
return 0;
|
||||
} else {
|
||||
self->running = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void ReleaseCountLock(pICountable self)
|
||||
{
|
||||
self->running = 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int isRunning(pICountable self)
|
||||
{
|
||||
return self->running;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
pICallBack GetCallbackInterface(void *pObject)
|
||||
{
|
||||
return (pICallBack) FindInterface(pObject, CALLBACKINTERFACE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user