Преглед изворни кода

Z991239-1267 #comment fix:gpio方法改造

雷志明80280620 пре 4 година
родитељ
комит
1e85063796
2 измењених фајлова са 46 додато и 133 уклоњено
  1. 36 133
      Module/mod_gpio/mod_gpio.cpp
  2. 10 0
      Module/mod_gpio/mod_gpio.h

+ 36 - 133
Module/mod_gpio/mod_gpio.cpp

@@ -6,55 +6,13 @@ const int INPUT_PORT_2 = 2;
 const int MAX_MOVE_HOLD_TIMES = 5000;
 const int LOG_TIME_VALUE = 25;
 
-//enum DeviceSeq{
-//	UNKNOWN_DEVICE,
-//	CARDREADER,
-//	PRINTER,
-//	IDCERTIFICATE,
-//	KEYBOARD,
-//	PHONE
-//};
-//int PinNum2DevNum[19]={ -1, 
-//17,
-//0,
-//1,
-//2,
-//3,
-//4,
-//5,
-//6,
-//7,
-//10,
-//13,
-//9,
-//11,
-//14,
-//8,
-//16,
-//15};
-
-//struct PositivePulseUpTimer : public ITimerListener 
-//{
-//	CGpioEntity* m_pEntity;
-//	PositivePulseUpTimer(CGpioEntity* pEntity)
-//	{
-//		m_pEntity = pEntity;
-//	}
-//};
 int positive_pulse_up_count = 0;
 int negative_pulse_down_count = 0;
 int positive_pulse_both_count = 0;
 int negative_pulse_both_count = 0;
 int positive_level_count = 0;
 int negative_level_count = 0;
-//PositivePulseUpTimer::OnTimeout(DWORD dwTimerID)
-//{
-//	positive_pulse_up_count--;
-//	if (positive_pulse_up_count == 0)
-//	{
-//		m_pEntity->GetFunction()->KillTimer(dwTimerID);
-//	}
-//}
+
 #define SETBIT(x,y) x|=(1<<(y))
 #define CLEARBIT(x,y) x&=((1<<(y))^0xffffff)
 
@@ -72,27 +30,9 @@ void CGpioServiceSession::Handle_Set(SpOnewayCallContext<GpioService_Set_Info>::
 }
 void CGpioServiceSession::Handle_GetStatus(SpReqAnsContext<GpioService_GetStatus_Req, GpioService_GetStatus_Ans>::Pointer ctx)
 {
-	//Dbg("devseq%s",ctx->Req.devseq);
+	
 	m_pEntity->GetStatus(ctx->Req.devseq,ctx);
-	//CSimpleStringA initDriver = "";
-	//int devicePort;
-	//int deviceSeq = UNKNOWN_DEVICE;
-	//deviceSeq = ctx->Req.devseq;
-	//switch(deviceSeq)
-	//{
-	//case PHONELIFT:
-	//	{
-	//		m_pEntity->GetFunction()->ReadConfigValue("InitDriver","PhoneLift",initDriver);
-	//		m_pEntity->GetFunction()->ReadConfigValueInt("DriverPort","PhoneLift",devicePort);
-	//		ReceivingInfo ri;
-	//		m_pEntity->GetReceivingModInfo(initDriver,ri);
-	//		ri.Port = devicePort;
-	//		m_pEntity->GetReceiving(ri,0,ctx);
-	//		break;
-	//	}
-	//default:
-	//	break;
-	//}
+	
 }
 void CGpioServiceSession::Handle_QueryCurrSet(SpReqAnsContext<GpioService_QueryCurrSet_Req, GpioService_QueryCurrSet_Ans>::Pointer ctx)
 {
@@ -102,16 +42,7 @@ void CGpioServiceSession::Handle_QueryCurrSet(SpReqAnsContext<GpioService_QueryC
 	ctx->Ans.output = m_pEntity->GetOutputStatus(0);
 	ctx->Answer(Error_Succeed);
 }
-//void CGpioEntity::OnLog(ILogListener *pListener, 
-//		unsigned __int64 nLogID, 
-//		LogTypeEnum eLogType, 
-//		SeverityLevelEnum eLevel,
-//		DWORD dwSysError, 
-//		DWORD dwUserCode,
-//		DWORD dwEntityId, 
-//		const char *pszEntityName, 
-//		const char *pszModuleName, 
-//		const char *pszMessage)
+
 bool isnostr(const char *str)
 {
 	int len = strlen(str);
@@ -134,10 +65,10 @@ ErrorCodeEnum CGpioEntity::Initial()
 	if (eErrDev != Error_Succeed)
 	{
 		//oiltest 20130723
-		Dbg("load vendor dll(%s) failed.",(LPCTSTR)dllName);
+		Dbg("load vendor dll or so(%s) failed.",dllName.GetData());
 		return Error_DevLoadFileFailed;
 	}
-	Dbg("%s",(LPCTSTR)dllName);//oiltest 20130723
+	Dbg("%s",dllName.GetData());//oiltest 20130723
 	CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
 	CSmartPointer<IConfigInfo> spConfig;
 	eErrDev = spEntityFunction->OpenConfig(Config_Root, spConfig);
@@ -152,7 +83,7 @@ ErrorCodeEnum CGpioEntity::Initial()
 	spConfig->ReadConfigValue("Device.Gpio","Version",devVer);
 	spConfig->ReadConfigValue("Device.Gpio","Batch",devBatch);
 #if 1
-	Dbg("[%s],[%s],[%s]",(LPCSTR)devVendor,(LPCSTR)devVer,(LPCSTR)devBatch);
+	Dbg("[%s],[%s],[%s]",devVendor.GetData(),devVer.GetData(),devBatch.GetData());
 	if(!_stricmp(devVendor, "Hyosung") || !_stricmp(devVendor, "Keba") || !_stricmp(devVendor, "Kxd")) {
 		if(devVer == "1" && devBatch == "1") {
 			m_bNewVersion = FALSE;
@@ -168,25 +99,7 @@ ErrorCodeEnum CGpioEntity::Initial()
 	m_bNewVersion = TRUE;
 #endif
 
-	
-
-
-	//CSimpleStringA csDepPath,csBackslash("\\");
-	//ErrorCodeEnum eErrDep = GetFunction()->GetPath("Dep", csDepPath);
-	//if (eErrDep != Error_Succeed)
-	//{
-	//	Dbg("GetBasePath failed (%d).",eErrDep);
-	//	return Error_Param;
-	//}
-	//dllName = csDepPath + csBackslash + dllName;
-	//if (!isnostr(devVendor.GetData()))
-	//	dllName = dllName + "." + devVendor;
-	//if (!isnostr(devVer.GetData()))
-	//	dllName = dllName + "." +  devVer;
-	//if (!isnostr(devBatch.GetData()))
-	//	dllName = dllName + "." +  devBatch;
-	//dllName += dllSuffix;
-	//Dbg("dllName:[%s]",dllName);
+#ifdef RVC_OS_WIN
 	m_hVerdorDll = LoadLibraryA(dllName);//oiltest name need to define
 	//m_hVerdorDll = LoadLibraryA("CardIssuer.dll");//oiltest name need to define
 	if (m_hVerdorDll == NULL)
@@ -201,28 +114,45 @@ ErrorCodeEnum CGpioEntity::Initial()
 		Dbg("Get ReleaseDevComponent failed.");
 		return Error_DevLoadFileFailed;
 	}
+#else
+	toolkit_lib_t m_lib;
+	int res = toolkit_dlopen(dllName, &m_lib);
+	if (res != 0) {
+		Dbg("toolkit_dlopen[%s] failed with error %s.", dllName.GetData(), toolkit_dlerror(&m_lib));
+		return Error_DevLoadFileFailed;
+	}
+
+	if ((res = toolkit_dlsym(&m_lib, "CreateDevComponent", (void**)& CreateDevComponent)) != 0)
+	{
+		Dbg("Get 'CreateDevComponent' Func address failed with error: %s", toolkit_dlerror(&m_lib));
+		return Error_DevLoadFileFailed;
+	}
+
+	if ((res = toolkit_dlsym(&m_lib, "ReleaseDevComponent", (void**)& ReleaseDevComponent)) != 0)
+	{
+		Dbg("Get 'ReleaseDevComponent' Func address failed with error: %s", toolkit_dlerror(&m_lib));
+		return Error_DevLoadFileFailed;
+	}
+#endif
+
 	int initTries = 0;
 	do
 	{
 		Dbg("create gpio device.");
+
 		if (m_pGpio == NULL)
 		{
-			if ((err = CreateDevComponent((DeviceBaseClass *&)m_pGpio)) != Error_Succeed)
+			if ((err = CreateDevComponent((DeviceBaseClass * &)m_pGpio)) != Error_Succeed)
 			{
-				LOG_TRACE("create gpio module failed(%d).",err);
+				LOG_TRACE("create gpio module failed(%d).", err);
 				initTries++;
 				continue;
 			}
 			Dbg("create gpio module suc.");
 		}
+
 		Dbg("to open device.");
-		//CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
-		//CSmartPointer<IConfigInfo> spConfig;
-		//err = spEntityFunction->OpenConfig(Config_Software, spConfig);
-		//if (err != Error_Succeed) {
-		//	LOG_TRACE("open cfg file failed!");
-		//	return err;
-		//}
+		
 		int portNum,inOutDir,port,baudRate;
 
 		err = spConfig->ReadConfigValueInt("Device.Gpio","PortNum",portNum);
@@ -279,25 +209,7 @@ ErrorCodeEnum CGpioEntity::Initial()
 		LOG_TRACE("open pinpad failed.");
 		err = Error_DevConnFailed;
 	}
-	//PortStatus psDir,psData;
-	//psDir.dwSize = m_dwPortNum;
-	//psDir.data[0] = 0xff;
-	//psDir.data[1] = 0xff;
-	//psDir.data[2] = 0x00;
-	//psDir.data[3] = 0x00;
-	//err = m_pGpio->SetPortsDirection(psDir);
-	//Dbg("set dirction(%d)",err);
-	//if (err != Error_Succeed)
-	//{
-	//	DevErrorInfo devErrInfo;
-	//	m_pGpio->GetLastErr(devErrInfo);
-	//	Dbg("err:[%s]",devErrInfo.szErrMsg);
-	//}
-	//memset(psData.data,0xff,4);
-	//psData.data[0] = 0x00;
-	//psData.data[1] = 0x00;
-	//psData.data[2] = 0x00;
-	//psData.dwSize = 2;
+	
 	err = m_pGpio->WritePort(0,0x00);
 	Dbg("write ports(%d)",err);
 	err = m_pGpio->WritePort(1,0x00);
@@ -326,16 +238,7 @@ ErrorCodeEnum CGpioEntity::Initial()
 	CSystemStaticInfo sysInfo;
 	GetFunction()->GetSystemStaticInfo(sysInfo);
 	m_csMachineType = sysInfo.strMachineType;
-	//oiltest 20130118 for audiodg handle
-	//BYTE btInput;
-	//int x=0;
-	//while(x<5000)
-	//{
-	//	err = m_pGpio->ReadPort(2,btInput);
-	//	x++;
-	//	Sleep(100);
-	//}
-	//Dbg("audiodg handle test end");
+
 	return err;
 }
 void CGpioEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,

+ 10 - 0
Module/mod_gpio/mod_gpio.h

@@ -6,6 +6,7 @@
 #include "Gpio_server_g.h"
 #include "EventCode.h"
 #include "GetDevInfoHelper.h"
+#include "DevFSMCommBase.hpp"
 using namespace Gpio;
 const int GPIO_INIT_COUNT = 3;
 typedef ErrorCodeEnum (*lpCreateDevCom)(DeviceBaseClass *&baseObj);
@@ -118,6 +119,15 @@ public:
 //		currDir = 0x2007ffff;
 		//m_pPIUT = new PositivePulseUpTimer();
 	}
+#ifdef RVC_OS_WIN
+#else
+	unsigned long GetTickCount()
+	{
+		struct timespec ts;
+		clock_gettime(CLOCK_MONOTONIC, &ts);
+		return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
+	}
+#endif
 	virtual ~CGpioEntity(){}
 	virtual const char* GetEntityName()const {return "Gpio";}
 	virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)