|
@@ -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;
|