Ver código fonte

#IQRV #comment [Merge]UPS实体同步

gifur 2 anos atrás
pai
commit
4283256d57

+ 64 - 46
Module/mod_ups/UpsFSM.cpp

@@ -1,64 +1,82 @@
 #include "stdafx.h"
 #include "UpsFSM.h"
 #include "GetDevInfoHelper.h"
+#include "EventCode.h"
+
+#include <map>
+#include "RVCComm.h"
+#include "publicFunExport.h"
+
 const int MAX_UPS_INIT_TRIES = 3;
 
+
+bool isnostr(const char *str)
+{
+	int len = strlen(str);
+	if (len == 0)
+		return true;
+	for (int i = 0; i < len; ++i)
+	{
+		if (*(str+i) != ' ')
+			return false;
+	}
+	return true;
+}
 ErrorCodeEnum CUpsFSM::OnInit()
 {
-    LOG_FUNCTION();
+	LOG_FUNCTION();
+	CSystemStaticInfo sysInfo;
+	GetEntityBase()->GetFunction()->GetSystemStaticInfo(sysInfo);
+	m_csMachineType = sysInfo.strMachineType;
+
 	auto pEntity = GET_DEV_ENTITY_BASE_POINTER();
 	pEntity->InitializeVendorLogSwitch();
-    CSimpleStringA dllName;
-    auto result = pEntity->ExtractVendorLibFullPath(dllName);
-    if (result != Error_Succeed) {
-        return result;
-    }
 	FulfillAdapterInfoFrom(pEntity->vendorLibInfo);
-    HARDWARE_ENTITY_SET_VENDOR_NAME(m_entCode, pEntity->vendorLibInfo.strVendor);
-    DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("vendor library path: %s", (LPCTSTR)dllName);
-	m_adapterInfo.adapterFileName = dllName;
-    result = m_hDevHelper.LoadUp(dllName);
-    if (result != Error_Succeed) {
-        return result;
-    }
-    CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
-    CSmartPointer<IConfigInfo> spConfig;
-	result = spEntityFunction->OpenConfig(Config_Root, spConfig);
-    if (result != Error_Succeed) {
-        DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("open cfg file failed!");
-        return result;
-    }
 
-    int baudRate = 0, port = 0;
-    spConfig->ReadConfigValueInt("Device.Ups", "Baudrate", baudRate);
-    spConfig->ReadConfigValueInt("Device.Ups", "Port", port);
-    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("port: %d, baudrate: %d", port, baudRate);
-	result = m_hDevHelper->DevOpen(port, baudRate);
-    if (result != Error_Succeed) {
-		SetErrPackage("OnInit::DevOpen", m_csDevNo, result, MEC_DEVAPI_UPS_DevOpen);
-		AlarmDEC();
-		return result;
-    }
+	LogWarn(Severity_Low, Error_Unexpect, LOG_ERR_UPS_LOGWARN_ROOTINFO, m_adapterInfo.adapterFilePath.GetData());
+	ToLogRootINIInfo();
+
+	ErrorCodeEnum eErrDev = m_hDevHelper.LoadUp(m_adapterInfo.adapterFilePath);
+	if (eErrDev != Error_Succeed) {
+		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("load vendor dll(%s) failed.", (LPCTSTR)m_adapterInfo.adapterFileName);
+		return Error_DevLoadFileFailed;
+	}
+	int initTries = 0;
+	do {
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%d,%d", m_adapterInfo.GetPortInt(), m_adapterInfo.GetBaudrateInt());
+		eErrDev = m_hDevHelper->DevOpen(m_adapterInfo.GetPortInt(), m_adapterInfo.GetBaudrateInt());
+		if (eErrDev != Error_Succeed) {
+			SetErrPackage("OnInit::DevOpen", m_devSN, eErrDev, MEC_DEVAPI_UPS_DevOpen);
+			AlarmDEC();
+			initTries++;
+			Sleep(200);
+			continue;
+		}
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("open ups succeed.");
+		m_bOpened = true;
+		ZeroMemory(m_devCatInfo.szModel, sizeof(m_devCatInfo.szModel));
+		ZeroMemory(m_devCatInfo.szType, sizeof(m_devCatInfo.szType));
+		ZeroMemory(m_devCatInfo.szVendor, sizeof(m_devCatInfo.szVendor));
+		eErrDev = m_hDevHelper->GetDevCategory(m_devCatInfo);
+		if (eErrDev == Error_Succeed) {
+			m_adapterInfo.FulfillCategoryInfo(m_devCatInfo);
+		} else if (eErrDev == Error_NotImpl) {
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetDevCategory return Error_NotImpl.");
+		} else {
+			SetErrPackage("OnInit::GetDevCategory", m_devSN, eErrDev, MEC_DEVAPI_UPS_GetDevCategory);
+			AlarmDEC();
+		}
+		break;
+	} while (initTries < MAX_UPS_INIT_TRIES);
 
-    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("open ups succeed.");
-    m_bDevOpen = true;
-	ZeroMemory(m_devCatInfo.szModel, sizeof(m_devCatInfo.szModel));
-	ZeroMemory(m_devCatInfo.szType, sizeof(m_devCatInfo.szType));
-	ZeroMemory(m_devCatInfo.szVendor, sizeof(m_devCatInfo.szVendor));
-	result = m_hDevHelper->GetDevCategory(m_devCatInfo);
-    if (result == Error_Succeed) {
-        m_adapterInfo.FulfillCategoryInfo(m_devCatInfo);
-    } else {
-        SetErrPackage("OnInit::GetDevCategory", m_csDevNo, result, MEC_DEVAPI_UPS_GetDevCategory);
-        AlarmDEC();
-    }
 	return Error_Succeed;
 }
 ErrorCodeEnum CUpsFSM::OnExit()
 {
 	ErrorCodeEnum eErr = Error_Succeed;
-	m_hDevHelper.TearDown();
-	m_bDevOpen = false;
+	if (m_hDevHelper != nullptr) {
+		m_hDevHelper.TearDown();
+	}
 	return eErr;
 }
 
@@ -75,9 +93,9 @@ void CUpsFSM::s0_on_entry()
 
 	if (m_FirstStart) {
 		m_FirstStart = FALSE;
-		ToLogRootINIInfoOnce();
 		ToLogWarnInfoAboutTerm();
 	}
+	m_testResult = Error_Succeed;
 }
 void CUpsFSM::s0_on_exit()
 {
@@ -192,7 +210,7 @@ int CUpsFSM::CheckStatus()
 	int i = 0;
 	while(1)
 	{
-		if (m_hDevHelper)
+		if (m_hDevHelper != nullptr)
 		{
 			UpsStatusEnum eUpsStatus;
 			ErrorCodeEnum eErr;

+ 5 - 3
Module/mod_ups/UpsFSM.h

@@ -16,6 +16,7 @@
 
 #include "Ups_server_g.h"
 #include "UpsClass.h"
+using namespace std;
 using namespace Ups;
 
 class OpenUpsEvent : public FSMEvent
@@ -78,7 +79,8 @@ public:
 		FSM_RULE_ENTRY(s2, s0, USER_EVT_CHECK_FINISHED, 0)
 		END_FSM_RULE()
 
-	CUpsFSM():m_bDevOpen(false),m_testResult(Error_Succeed), m_csDevNo(""){
+	CUpsFSM():m_testResult(Error_Succeed), m_csMachineType(true), m_devSN("")
+	{
 		HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x20E);
 		m_FirstStart = TRUE;
 		ZeroMemory(&m_adapterInfo, sizeof(m_adapterInfo));
@@ -104,10 +106,10 @@ public:
 	int CheckStatus();
 	void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
 private:
-	bool m_bDevOpen;
 	ErrorCodeEnum m_testResult;
-	CSimpleStringA m_csDevNo;
+	CSimpleStringA m_csMachineType;
 	DevCategoryInfo m_devCatInfo;
+	CSimpleStringA m_devSN;
 };
 struct ShutDownTask : public ITaskSp
 {

+ 5 - 0
Module/mod_ups/Ups_def_g.h

@@ -22,6 +22,11 @@ namespace Ups {
 #define UpsService_MethodSignature_Shutdown -315118099
 #define UpsService_MethodSignature_Close -811482585
 
+#define UpsService_LogCode_Open "QLR040220E00"
+#define UpsService_LogCode_GetStatus "QLR040220E01"
+#define UpsService_LogCode_Shutdown "QLR040220E02"
+#define UpsService_LogCode_Close "QLR040220E03"
+
 struct UpsService_Open_Req
 {
 	CSimpleStringA Com;

+ 5 - 3
Module/mod_ups/mod_ups.cpp

@@ -1,7 +1,7 @@
 #include "stdafx.h"
 
 #include "SpBase.h"
-#include "SpTest.h"
+
 #include "modVer.h"
 
 #include "UpsFSM.h"
@@ -39,8 +39,6 @@ public:
 		pTransactionContext->SendAnswer(err);
 	}
 
-	ON_ENTITYT_TEST()
-
 	virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext) 
 	{
 		pTransactionContext->SendAnswer(Error_Succeed); 
@@ -92,21 +90,25 @@ private:
 
 void UpsServerSession::Handle_Open(SpReqAnsContext<UpsService_Open_Req, UpsService_Open_Ans>::Pointer ctx)
 {
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->Open(ctx);
 }
 
 void UpsServerSession::Handle_GetStatus(SpReqAnsContext<UpsService_GetStatus_Req, UpsService_GetStatus_Ans>::Pointer ctx)
 {
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->GetStatus(ctx);
 }
 
 void UpsServerSession::Handle_Shutdown(SpReqAnsContext<UpsService_Shutdown_Req, UpsService_Shutdown_Ans>::Pointer ctx)
 {
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->Shutdown(ctx);
 }
 
 void UpsServerSession::Handle_Close(SpReqAnsContext<UpsService_Close_Req, UpsService_Close_Ans>::Pointer ctx)
 {
+	DbgToBeidou(ctx->link, __FUNCTION__)();
 	m_pEntity->Close(ctx);
 }