#if (defined(WIN32))
#include "rfm2g_windows.h"
#endif
#include <stdio.h>
#include <string.h>
#include "rfm2g_api.h"
#include "RFM2G.h"
#if (defined(RFM2G_LINUX))
#ifdef CONFIG_DEVFS_FS
#define DEVICE_PREFIX "/dev/rfm2g/"
#else
#define DEVICE_PREFIX "/dev/rfm2g"
#endif
#define PROCFILE "/proc/rfm2g"
#elif defined(RFM2G_VXWORKS)
#define DEVICE_PREFIX "RFM2G_"
#elif defined(SOLARIS)
#define DEVICE_PREFIX "/dev/rfm2g"
#elif defined(WIN32)
#define DEVICE_PREFIX "\\\\.\\rfm2g"
#else
#error Please define DEVICE_PREFIX for your driver
#endif
//#include <stdio.h>
//#include <stdlib.h>
//#include "RFM2G.h"
//#include "rfm2g_api.h"
RFM2GHANDLE Handle;
RFM2GEVENTINFO EventInfo;
RFM2G_NODE NodeId;
DLL_EXPORT bool openDevice(RFM2G_INT32 numDevice)
{
RFM2G_CHAR device[80];
sprintf((char*)device, "%s%d", DEVICE_PREFIX, numDevice);
RFM2G_STATUS result;
result = RFM2gOpen( (char*)device, &Handle );
if( result != RFM2G_SUCCESS )
{
return false;
}
else
{
return true;
}
}
DLL_EXPORT int RFMNodeId()
{
RFM2G_STATUS result;
result=RFM2gNodeID(Handle,&NodeId);
if(result == RFM2G_SUCCESS)
{
return (int)NodeId;
}
if(result != RFM2G_SUCCESS)
{
return -1;
}
}
DLL_EXPORT bool readData(int offset,void *readBuffer,int sizeBytes)
{
RFM2G_STATUS result;
result = RFM2gRead( Handle, offset, readBuffer, sizeBytes);
if( result != RFM2G_SUCCESS )
{
RFM2gClose( &Handle );
return false;
}
else
{
return true;
}
}
DLL_EXPORT bool writeData(int offset,void *writeBuffer,int sizeBytes)
{
RFM2G_STATUS result;
result=RFM2gWrite(Handle, offset, writeBuffer, sizeBytes);
if( result != RFM2G_SUCCESS )
{
RFM2gClose( &Handle );
return false;
}
else
{
return true;
}
}
DLL_EXPORT bool RFMSendEvent(int nodeID)
{
RFM2G_STATUS result;
result=RFM2gSendEvent(Handle,(RFM2G_NODE)nodeID,RFM2GEVENT_INTR1,0);
if(result != RFM2G_SUCCESS)
{
RFM2gClose(&Handle);
return false;
}
else
{
return true;
}
}
DLL_EXPORT int RFM2GWaitForEvent()
{
RFM2G_STATUS result;
RFM2G_NODE otherNodeID;
EventInfo.Event = RFM2GEVENT_INTR1;
EventInfo.Timeout = RFM2G_INFINITE_TIMEOUT;
result = RFM2gEnableEvent( Handle, RFM2GEVENT_INTR1 );
result = RFM2gWaitForEvent( Handle, &EventInfo );
otherNodeID=EventInfo.NodeId;
if( result == RFM2G_SUCCESS )
{
return otherNodeID;
}
else
{
return -1;
}
}
DLL_EXPORT bool clearEvent()
{
RFM2G_STATUS result;
result=RFM2gClearEvent(Handle,RFM2GEVENT_INTR1);
if(result==RFM2G_SUCCESS)
{
return true;
}
else
{
return false;
}
}
DLL_EXPORT void closeDevice()
{
RFM2gClose( &Handle );
}