|
|
#include "DevLEDScreen.h"
|
|
|
#include "DevLEDScreenStr.h"
|
|
|
#include "WriteLog.h"
|
|
|
|
|
|
list<DevLEDScreenStr *> glist;
|
|
|
static int InitFlag = 0;
|
|
|
|
|
|
DevLEDScreenStr * GetDevLedPtr(LED_HANDLE hHandle , bool isRemove = false)
|
|
|
{
|
|
|
list<DevLEDScreenStr *>::iterator it;
|
|
|
DevLEDScreenStr * ptr;
|
|
|
|
|
|
for (it = glist.begin(); it != glist.end(); it++)
|
|
|
{
|
|
|
ptr = *it;
|
|
|
if (hHandle == ((LED_HANDLE)(ptr)))
|
|
|
{
|
|
|
if (isRemove)
|
|
|
{
|
|
|
glist.erase(it);
|
|
|
}
|
|
|
return ptr;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
int GetIpAndPort(char * pip,int &port,const char * source)
|
|
|
{
|
|
|
int ipos;
|
|
|
int ilen;
|
|
|
int iret;
|
|
|
//int itemp;
|
|
|
char * ptr;
|
|
|
char buf[128];
|
|
|
|
|
|
ilen = strlen(source);
|
|
|
if(ilen >120)
|
|
|
{
|
|
|
return -1;
|
|
|
}
|
|
|
memset(buf,0,sizeof(buf));
|
|
|
strcpy(buf,source);
|
|
|
|
|
|
ptr =NULL;
|
|
|
for(ipos =0; ipos< ilen; ipos++)
|
|
|
{
|
|
|
if(':' == (buf[ipos]))
|
|
|
{
|
|
|
ptr = buf +ipos;
|
|
|
*ptr =0;
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(! ptr)
|
|
|
{
|
|
|
return -2;
|
|
|
}
|
|
|
|
|
|
iret = isIpAddr(buf);
|
|
|
if(iret <0)
|
|
|
{
|
|
|
return -3;
|
|
|
}
|
|
|
strcpy(pip,buf);
|
|
|
ilen -= (ipos+1);
|
|
|
|
|
|
ptr +=1;
|
|
|
iret =0;
|
|
|
for(ipos =0; ipos< ilen; ipos++)
|
|
|
{
|
|
|
if(':' == (ptr[ipos]))
|
|
|
{
|
|
|
ptr[ipos] =0;
|
|
|
iret =1;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
ilen =strlen(ptr);
|
|
|
if((ilen >6) || (ilen <1))
|
|
|
{
|
|
|
return -5;
|
|
|
}
|
|
|
|
|
|
for(ipos =0; ipos< ilen; ipos++)
|
|
|
{
|
|
|
iret = isnumer(ptr[ipos]);
|
|
|
if(iret <0)
|
|
|
{
|
|
|
return -6;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
port = atoi(ptr);
|
|
|
if(iret <0)
|
|
|
{
|
|
|
return -7;
|
|
|
}
|
|
|
|
|
|
iret = IsTcpPort(port);
|
|
|
if(iret <0)
|
|
|
{
|
|
|
return -8;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
int InitSocket()
|
|
|
{
|
|
|
if(0 == InitFlag)
|
|
|
{
|
|
|
WSADATA wsaData;
|
|
|
HRESULT iRet;
|
|
|
|
|
|
iRet = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
|
|
if (iRet != 0)
|
|
|
{
|
|
|
WriteLog("WSAStartup error");
|
|
|
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
if (LOBYTE(wsaData.wVersion) != 2 ||
|
|
|
HIBYTE(wsaData.wVersion) != 2)
|
|
|
{
|
|
|
/* Tell the user that we could not find a usable */
|
|
|
/* WinSock DLL. */
|
|
|
WriteLog("WSAStartup ver error");
|
|
|
WSACleanup();
|
|
|
return -2;
|
|
|
}
|
|
|
WriteLog("WSAStartup <20>ɹ<EFBFBD>");
|
|
|
|
|
|
}
|
|
|
InitFlag =1;
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
extern "C" DEVLEDSCREEN_API LED_HANDLE __stdcall OpenLedScr(const int LSVer, const char* pcIP)
|
|
|
{
|
|
|
int iret;
|
|
|
int ilen;
|
|
|
int iport;
|
|
|
DevLEDScreenStr *ptr;
|
|
|
char buf[32];
|
|
|
|
|
|
iret = InitSocket();
|
|
|
if(iret <0)
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
if(FENGHAI_VER != LSVer)
|
|
|
{
|
|
|
WriteLog("LSVer <20><><EFBFBD><EFBFBD>FENGHAI");
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
if(! pcIP)
|
|
|
{
|
|
|
WriteLog("pcIP Ϊ<><CEAA>");
|
|
|
return NULL;
|
|
|
}
|
|
|
ilen = strlen(pcIP);
|
|
|
if(ilen <IP_MINLEN)
|
|
|
{
|
|
|
WriteLog("pcIP <20><><EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD>");
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
memset(buf,0,sizeof(buf));
|
|
|
iret = GetIpAndPort(buf,iport,pcIP);
|
|
|
if(iret <0)
|
|
|
{
|
|
|
WriteLog(" GetIpAndPort <20><><EFBFBD><EFBFBD>, ip=%s,ret =%d",pcIP,iret);
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
ptr =new DevLEDScreenStr();
|
|
|
if(! ptr)
|
|
|
{
|
|
|
WriteLog("new DevLEDScreenStr ʧ<><CAA7>");
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
ptr->InitStr();
|
|
|
iret = ptr->OpenLedScr(buf,iport);
|
|
|
if(iret <0)
|
|
|
{
|
|
|
WriteLog("OpenLedScr ʧ<><CAA7> ip = %s,ret = %d",pcIP,iret);
|
|
|
delete ptr;
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
WriteLog("OpenLedScr <20>ɹ<EFBFBD>,lsver =%d ,ip = %s, handle is %lu",LSVer,pcIP,(unsigned long )ptr);
|
|
|
|
|
|
glist.push_back(ptr);
|
|
|
return ptr;
|
|
|
}
|
|
|
|
|
|
extern "C" DEVLEDSCREEN_API HRESULT __stdcall CloseLedScr(LED_HANDLE hHandle)
|
|
|
{
|
|
|
|
|
|
int iret;
|
|
|
DevLEDScreenStr * ptr;
|
|
|
if (!hHandle)
|
|
|
{
|
|
|
WriteLog("CloseLedScr hHandle Ϊ<><CEAA>");
|
|
|
return -100;
|
|
|
}
|
|
|
|
|
|
ptr = GetDevLedPtr(hHandle,true);
|
|
|
if (!ptr)
|
|
|
{
|
|
|
WriteLog("CloseLedScr <20><>ȡ DevLEDScreenStr ָ<><D6B8>ʧ<EFBFBD><CAA7> hHandle= %lu",(unsigned long )hHandle);
|
|
|
return -101;
|
|
|
}
|
|
|
|
|
|
iret = ptr->CloseLedScr();
|
|
|
|
|
|
WriteLog("CloseLedScr <20><><EFBFBD>óɹ<C3B3> handle is %lu",(unsigned long)ptr);
|
|
|
delete ptr;
|
|
|
return iret;
|
|
|
}
|
|
|
|
|
|
extern "C" DEVLEDSCREEN_API HRESULT __stdcall LedScrShow(LED_HANDLE hHandle, INT32 iShowId)
|
|
|
{
|
|
|
int iret;
|
|
|
|
|
|
DevLEDScreenStr * ptr;
|
|
|
if (!hHandle)
|
|
|
{
|
|
|
WriteLog("LedScrShow hHandle Ϊ<><CEAA>");
|
|
|
return -100;
|
|
|
}
|
|
|
|
|
|
switch(iShowId)
|
|
|
{
|
|
|
case SHOW_ID_MTC_OPEN:
|
|
|
case SHOW_ID_ETC_OPEN:
|
|
|
case SHOW_ID_MTC_CLOSE:
|
|
|
case SHOW_ID_ETC_CLOSE:
|
|
|
break;
|
|
|
default:
|
|
|
WriteLog("LedScrShow iShowId <20><><EFBFBD><EFBFBD> iShowId =%d",iShowId);
|
|
|
return -102;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
ptr = GetDevLedPtr(hHandle);
|
|
|
if (!ptr)
|
|
|
{
|
|
|
WriteLog("LedScrShow <20><>ȡ DevLEDScreenStr ָ<><D6B8>ʧ<EFBFBD><CAA7> hHandle= %lu",(unsigned long )hHandle);
|
|
|
return -101;
|
|
|
}
|
|
|
|
|
|
iret = ptr->Led_ShowId(iShowId);
|
|
|
if(iret <0)
|
|
|
{
|
|
|
WriteLog("LedScrShow ʧ<><CAA7> hHandle= %lu iret =%d",(unsigned long)ptr,iret);
|
|
|
}
|
|
|
|
|
|
WriteLog("LedScrShow <20>ɹ<EFBFBD> hHandle= %lu id =%d",(unsigned long)ptr,iShowId);
|
|
|
return iret;
|
|
|
|
|
|
}
|
|
|
|
|
|
extern "C" DEVLEDSCREEN_API HRESULT __stdcall LedScrShowText(LED_HANDLE hHandle, char* pcText)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
extern "C" DEVLEDSCREEN_API HRESULT __stdcall LedScrSetLight(LED_HANDLE hHandle, char cValue)
|
|
|
{
|
|
|
|
|
|
int iret;
|
|
|
int ival;
|
|
|
DevLEDScreenStr * ptr;
|
|
|
if (!hHandle)
|
|
|
{
|
|
|
WriteLog("LedScrSetLight hHandle Ϊ<><CEAA>");
|
|
|
return -100;
|
|
|
}
|
|
|
|
|
|
iret = (int)cValue;
|
|
|
/* if( iret <1 )
|
|
|
{
|
|
|
WriteLog("LedScrSetLight value <20><><EFBFBD><EFBFBD> value =%d");
|
|
|
return -101;
|
|
|
}
|
|
|
*/
|
|
|
|
|
|
if(iret >31)
|
|
|
{
|
|
|
iret =31;
|
|
|
}
|
|
|
ival = iret;
|
|
|
|
|
|
ptr = GetDevLedPtr(hHandle);
|
|
|
if (!ptr)
|
|
|
{
|
|
|
WriteLog("LedScrSetLight <20><>ȡ DevLEDScreenStr ָ<><D6B8>ʧ<EFBFBD><CAA7> hHandle= %lu",(unsigned long )hHandle);
|
|
|
return -101;
|
|
|
}
|
|
|
|
|
|
iret = ptr->Led_SetLight(ival);
|
|
|
if(iret <0)
|
|
|
{
|
|
|
WriteLog("LedScrSetLight ʧ<><CAA7> handle = %lu iret =%d",(unsigned long )hHandle,iret);
|
|
|
}
|
|
|
|
|
|
WriteLog("LedScrSetLight <20>ɹ<EFBFBD> handle = %lu ival = %d",(unsigned long )hHandle,(int)cValue);
|
|
|
return iret;
|
|
|
|
|
|
}
|
|
|
|
|
|
extern "C" DEVLEDSCREEN_API HRESULT __stdcall LedScrGetStatus(LED_HANDLE hHandle,INT32 * piValue)
|
|
|
{
|
|
|
int iret;
|
|
|
|
|
|
DevLEDScreenStr * ptr;
|
|
|
if (!hHandle)
|
|
|
{
|
|
|
WriteLog("LedScrGetStatus hHandle Ϊ<><CEAA>");
|
|
|
return -100;
|
|
|
}
|
|
|
|
|
|
ptr = GetDevLedPtr(hHandle);
|
|
|
if (!ptr)
|
|
|
{
|
|
|
WriteLog("LedScrGetStatus <20><>ȡ DevLEDScreenStr ָ<><D6B8>ʧ<EFBFBD><CAA7> hHandle= %lu",(unsigned long )hHandle);
|
|
|
return -101;
|
|
|
}
|
|
|
|
|
|
iret = ptr->GetStates();
|
|
|
if(iret != DEV_OPEN)
|
|
|
{
|
|
|
* piValue =1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
* piValue =0;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|