|
|
@@ -37,7 +37,8 @@ assert(DeviceBaseHelper::GetCurVendorType("chinavision") == Vendor_ChinaVision);
|
|
|
|
|
|
*/
|
|
|
|
|
|
-enum VendorNameType {
|
|
|
+enum VendorNameType
|
|
|
+{
|
|
|
Vendor_Invalide,
|
|
|
Vendor_Sankyo,
|
|
|
Vendor_ChinaVision,
|
|
|
@@ -74,27 +75,36 @@ static const char* VendorNameStr[] = {
|
|
|
"hx"
|
|
|
};
|
|
|
|
|
|
+
|
|
|
inline static VendorNameType GetCurVendorType(LPCTSTR vendorName)
|
|
|
{
|
|
|
- if (vendorName == NULL || strlen(vendorName) == 0) {
|
|
|
+ if (vendorName == NULL || strlen(vendorName) == 0)
|
|
|
+ {
|
|
|
return Vendor_Invalide;
|
|
|
}
|
|
|
+
|
|
|
int idx = -1;
|
|
|
- for (int i = 0; i < sizeof(VendorNameStr) / sizeof(VendorNameStr[0]); ++i) {
|
|
|
- if (strnicmp(vendorName, VendorNameStr[i], strlen(VendorNameStr[i])) == 0) {
|
|
|
+
|
|
|
+ for (int i = 0; i < sizeof(VendorNameStr) / sizeof(VendorNameStr[0]); ++i)
|
|
|
+ {
|
|
|
+ if (strnicmp(vendorName, VendorNameStr[i], strlen(VendorNameStr[i])) == 0)
|
|
|
+ {
|
|
|
idx = i;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- if (idx == -1) {
|
|
|
+
|
|
|
+ if (idx == -1)
|
|
|
+ {
|
|
|
/*历史遗留原因,怡化厂商有两个适配器名字*/
|
|
|
if (strnicmp(vendorName, "yihua", strlen("yihua")) == 0) {
|
|
|
idx = Vendor_YiHua;
|
|
|
- }
|
|
|
- else {
|
|
|
+
|
|
|
+ } else {
|
|
|
idx = Vendor_Invalide;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return (VendorNameType)idx;
|
|
|
}
|
|
|
|
|
|
@@ -106,6 +116,7 @@ struct DevAdptLibHelper
|
|
|
ErrorCodeEnum erroCode = Error_Succeed;
|
|
|
|
|
|
do {
|
|
|
+
|
|
|
int res = toolkit_dlopen(strFullLibPath, &m_lib);
|
|
|
if (res != 0) {
|
|
|
Dbg("toolkit_dlopen[%s] failed with error %s.", strFullLibPath.GetData(), toolkit_dlerror(&m_lib));
|
|
|
@@ -113,12 +124,15 @@ struct DevAdptLibHelper
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- if ((res = toolkit_dlsym(&m_lib, "CreateDevComponent", (void**)&pFuncCreateAdapt)) != 0) {
|
|
|
+ if ((res = toolkit_dlsym(&m_lib, "CreateDevComponent", (void**)&pFuncCreateAdapt)) != 0)
|
|
|
+ {
|
|
|
Dbg("Get 'CreateDevComponent' Func address failed with error: %s", toolkit_dlerror(&m_lib));
|
|
|
erroCode = Error_DevLoadFileFailed;
|
|
|
break;
|
|
|
}
|
|
|
- if ((res = toolkit_dlsym(&m_lib, "ReleaseDevComponent", (void**)&pFuncReleaseAdapt)) != 0) {
|
|
|
+
|
|
|
+ if ((res = toolkit_dlsym(&m_lib, "ReleaseDevComponent", (void**)&pFuncReleaseAdapt)) != 0)
|
|
|
+ {
|
|
|
Dbg("Get 'ReleaseDevComponent' Func address failed with error: %s", toolkit_dlerror(&m_lib));
|
|
|
erroCode = Error_DevLoadFileFailed;
|
|
|
break;
|
|
|
@@ -126,7 +140,8 @@ struct DevAdptLibHelper
|
|
|
|
|
|
} while (false);
|
|
|
|
|
|
- if (IS_FAILURED(erroCode)) {
|
|
|
+ if (IS_FAILURED(erroCode))
|
|
|
+ {
|
|
|
TearDown();
|
|
|
}
|
|
|
|
|
|
@@ -142,8 +157,7 @@ struct DevAdptLibHelper
|
|
|
return Error_NotInit;
|
|
|
}
|
|
|
|
|
|
- ErrorCodeEnum erroCode = Error_Succeed;
|
|
|
- erroCode = pFuncCreateAdapt((DeviceBaseClass*&)m_AdptObjPtr);
|
|
|
+ ErrorCodeEnum erroCode = pFuncCreateAdapt((DeviceBaseClass*&)m_AdptObjPtr);
|
|
|
if (IS_FAILURED(erroCode)) {
|
|
|
Dbg("Create device adapter object failed! EC=%s", SpStrError(erroCode));
|
|
|
return erroCode;
|
|
|
@@ -166,9 +180,11 @@ struct DevAdptLibHelper
|
|
|
|
|
|
void TearDown()
|
|
|
{
|
|
|
- if (m_AdptObjPtr != nullptr) {
|
|
|
+ if (m_AdptObjPtr != nullptr)
|
|
|
+ {
|
|
|
m_AdptObjPtr->DevClose();
|
|
|
- if (nullptr != pFuncReleaseAdapt) {
|
|
|
+ if (nullptr != pFuncReleaseAdapt)
|
|
|
+ {
|
|
|
DeviceBaseClass* devBasePtr = static_cast<DeviceBaseClass*>(m_AdptObjPtr);
|
|
|
#if DEVICE_BASE_INTERFACE_FILE_VERSION == 2
|
|
|
pFuncReleaseAdapt(0, devBasePtr);
|
|
|
@@ -189,11 +205,9 @@ struct DevAdptLibHelper
|
|
|
|
|
|
TSubAdpt* operator->()
|
|
|
{
|
|
|
-
|
|
|
if (m_AdptObjPtr == nullptr) {
|
|
|
throw std::runtime_error("the dev class pointer is nullptr!!");
|
|
|
}
|
|
|
-
|
|
|
return m_AdptObjPtr;
|
|
|
}
|
|
|
|
|
|
@@ -208,12 +222,13 @@ struct DevAdptLibHelper
|
|
|
TearDown();
|
|
|
}
|
|
|
|
|
|
- DevAdptLibHelper(const DevAdptLibHelper&) = delete; /** forbid copy*/
|
|
|
- DevAdptLibHelper& operator=(const DevAdptLibHelper&) = delete; /** forbid assignment*/
|
|
|
+ DevAdptLibHelper(const DevAdptLibHelper&) = delete;
|
|
|
+ DevAdptLibHelper& operator=(const DevAdptLibHelper&) = delete;
|
|
|
|
|
|
private:
|
|
|
|
|
|
toolkit_lib_t m_lib;
|
|
|
+
|
|
|
DevAdaptObjCreateFunc pFuncCreateAdapt;
|
|
|
DevAdaptObjReleaseFunc pFuncReleaseAdapt;
|
|
|
|
|
|
@@ -246,11 +261,13 @@ struct DevEntityErrorCode {
|
|
|
dwVendorId = dwVendorID;
|
|
|
}
|
|
|
|
|
|
- DWORD GetCompleteErrorCode() const {
|
|
|
+ DWORD GetCompleteErrorCode() const
|
|
|
+ {
|
|
|
return MAKE_SLV_ERRORCODE(dwEntityId, dwVendorId, dwVendorErroCode);
|
|
|
}
|
|
|
|
|
|
- DWORD GetCompleteErrorCode2Business() const {
|
|
|
+ DWORD GetCompleteErrorCode2Business() const
|
|
|
+ {
|
|
|
return MAKE_SLV_ERRORCODE_TO_BUSINESS(dwEntityId, dwVendorErroCode, dwReserved);
|
|
|
}
|
|
|
|
|
|
@@ -259,9 +276,12 @@ struct DevEntityErrorCode {
|
|
|
template<class TFSM, class TDevClass>
|
|
|
class CCommDevFSM : public FSMImpl<TFSM>
|
|
|
{
|
|
|
+
|
|
|
public:
|
|
|
- ErrorCodeEnum GetAndSplitDevErrInfo(CSimpleStringA& csErrMsg,
|
|
|
- WORD& wdDevErrCode, LPCTSTR lpszFuncNameForDisplay = "");
|
|
|
+
|
|
|
+ ErrorCodeEnum GetAndSplitDevErrInfo(
|
|
|
+ CSimpleStringA& csErrMsg, WORD& wdDevErrCode, LPCTSTR lpszFuncNameForDisplay = "");
|
|
|
+
|
|
|
ErrorCodeEnum LogDevErrInfo(LPCTSTR lpszFuncName = "")
|
|
|
{
|
|
|
CSimpleStringA csMsg;
|
|
|
@@ -274,10 +294,13 @@ public:
|
|
|
ErrorCodeEnum eRet = GetAndSplitDevErrInfo(csMsg, wdErrorCode);
|
|
|
return (eRet == Error_Succeed);
|
|
|
}
|
|
|
+
|
|
|
protected:
|
|
|
+
|
|
|
DevAdptLibHelper<TDevClass> m_hDevHelper;
|
|
|
|
|
|
DevEntityErrorCode m_entCode;
|
|
|
+
|
|
|
CSimpleStringA m_csAlarmMsg = "No more information";
|
|
|
|
|
|
void UpdateEntityID()
|
|
|
@@ -285,6 +308,7 @@ protected:
|
|
|
CEntityStaticInfo esi = { 0 };
|
|
|
ErrorCodeEnum ec = this->GetEntityBase()->GetFunction()->GetEntityStaticInfo(
|
|
|
this->GetEntityBase()->GetEntityName(), esi);
|
|
|
+
|
|
|
if (ec == Error_Succeed) {
|
|
|
Dbg("wEntityDevelopID: 0x%X", esi.wEntityDevelopID);
|
|
|
m_entCode.ResetWithEntityID(esi.wEntityDevelopID);
|
|
|
@@ -301,45 +325,55 @@ protected:
|
|
|
m_entCode.SetDevCode(dwVal, reserved);
|
|
|
return GetDEC();
|
|
|
}
|
|
|
+
|
|
|
DWORD GetDEC() const
|
|
|
{
|
|
|
return m_entCode.GetCompleteErrorCode();
|
|
|
}
|
|
|
- //DWORD AlarmDEC() const {
|
|
|
- // return GetDEC();
|
|
|
- //}
|
|
|
- DWORD AlarmDECToBusiness(DWORD dwVal = 0) {
|
|
|
- if (dwVal > 0)
|
|
|
+
|
|
|
+ DWORD AlarmDECToBusiness(DWORD dwVal = 0)
|
|
|
+ {
|
|
|
+ if (dwVal > 0) {
|
|
|
UpdateDEC(dwVal);
|
|
|
+ }
|
|
|
+
|
|
|
//oilyang@20200528 according the meeting result,throw a LogError while answering ctx
|
|
|
//oilyang@20200525 if have been set ErrorCode of entity defined (not device),use it directly
|
|
|
DWORD dwCode = 0;
|
|
|
- if ((m_entCode.dwVendorErroCode >> 20) == m_entCode.dwEntityId)
|
|
|
+ if ((m_entCode.dwVendorErroCode >> 20) == m_entCode.dwEntityId) {
|
|
|
dwCode = m_entCode.dwVendorErroCode;
|
|
|
- else
|
|
|
+
|
|
|
+ } else {
|
|
|
dwCode = m_entCode.GetCompleteErrorCode2Business();
|
|
|
+ }
|
|
|
+
|
|
|
LogError(Severity_Middle, Error_Unexpect, dwCode, "TODO:");
|
|
|
+
|
|
|
return dwCode;
|
|
|
}
|
|
|
+
|
|
|
void ClearRelatedDEC()
|
|
|
{
|
|
|
UpdateDEC();
|
|
|
m_csAlarmMsg = "No more information";
|
|
|
}
|
|
|
+
|
|
|
void LogErrMsg(const char* pMsgHead, ErrorCodeEnum eErrCode, DWORD defaultDevCode = 0, BOOL bAlarm = FALSE);
|
|
|
};
|
|
|
|
|
|
|
|
|
template<class TFSM, class TDevClass>
|
|
|
inline ErrorCodeEnum CCommDevFSM<TFSM, TDevClass>::GetAndSplitDevErrInfo(
|
|
|
- CSimpleStringA& csErrMsg, WORD& wdDevErrCode, LPCTSTR lpszFuncNameForDisplay)
|
|
|
+ CSimpleStringA& csErrMsg, WORD& wdDevErrCode, LPCTSTR lpszFuncNameForDisplay)
|
|
|
{
|
|
|
csErrMsg = "";
|
|
|
wdDevErrCode = 0;
|
|
|
|
|
|
BOOL bDisplayFunName = TRUE;
|
|
|
if (lpszFuncNameForDisplay == NULL || strlen(lpszFuncNameForDisplay) == 0)
|
|
|
+ {
|
|
|
bDisplayFunName = FALSE;
|
|
|
+ }
|
|
|
|
|
|
if (!m_hDevHelper) {
|
|
|
Dbg("inst occurs nullptr !!!");
|
|
|
@@ -349,7 +383,8 @@ inline ErrorCodeEnum CCommDevFSM<TFSM, TDevClass>::GetAndSplitDevErrInfo(
|
|
|
DevErrorInfo devErrInfo;
|
|
|
ZeroMemory(&devErrInfo, sizeof(DevErrorInfo));
|
|
|
ErrorCodeEnum erroCode = m_hDevHelper->GetLastErr(devErrInfo);
|
|
|
- if (erroCode == Error_Succeed) {
|
|
|
+ if (erroCode == Error_Succeed)
|
|
|
+ {
|
|
|
if (strlen(devErrInfo.szErrMsg) > 0) {
|
|
|
csErrMsg = devErrInfo.szErrMsg;
|
|
|
}
|
|
|
@@ -358,25 +393,26 @@ inline ErrorCodeEnum CCommDevFSM<TFSM, TDevClass>::GetAndSplitDevErrInfo(
|
|
|
//oiltmp@20200520 comment the following line
|
|
|
//wdDevErrCode = (WORD)((devErrInfo.dwErrMsgLen >> 16) & 0x0000FFFF);
|
|
|
}
|
|
|
+
|
|
|
if (bDisplayFunName) {
|
|
|
Dbg("Invoke <%s> failed, Dev_GLE: DevErrCode[%d], ErrMsg[%s]",
|
|
|
- lpszFuncNameForDisplay, wdDevErrCode, (LPCTSTR)csErrMsg);
|
|
|
- }
|
|
|
- else {
|
|
|
+ lpszFuncNameForDisplay, wdDevErrCode, (LPCTSTR)csErrMsg);
|
|
|
+
|
|
|
+ } else {
|
|
|
Dbg("Dev_GLE: DevErrCode[%d], ErrMsg[%s]", wdDevErrCode, (LPCTSTR)csErrMsg);
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
+
|
|
|
+ } else {
|
|
|
if (bDisplayFunName) {
|
|
|
Dbg("Invoke <%s> failed, and unfortunately Dev_GLE failed returned EC: %d(0x%X)",
|
|
|
- lpszFuncNameForDisplay, erroCode, erroCode);
|
|
|
+ lpszFuncNameForDisplay, erroCode, erroCode);
|
|
|
csErrMsg = CSimpleStringA::Format("Invoke <%s> failed", lpszFuncNameForDisplay);
|
|
|
- }
|
|
|
- else {
|
|
|
- Dbg("Dev_GLE failed returned EC: %d(0x%X)",
|
|
|
- erroCode, erroCode);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Dbg("Dev_GLE failed returned EC: %d(0x%X)", erroCode, erroCode);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return erroCode;
|
|
|
}
|
|
|
|
|
|
@@ -385,24 +421,29 @@ inline void CCommDevFSM<TFSM, TDevClass>::LogErrMsg(
|
|
|
const char* pMsgHead, ErrorCodeEnum eErrCode, DWORD defaultDevCode, BOOL bAlarm)
|
|
|
{
|
|
|
Dbg("%s failed, EC = %s(0x%x)", pMsgHead, SpStrError(eErrCode), eErrCode);
|
|
|
+
|
|
|
WORD wdErrCode = 0;
|
|
|
CSimpleStringA csErrMsg(true);
|
|
|
ErrorCodeEnum ec = GetAndSplitDevErrInfo(csErrMsg, wdErrCode);
|
|
|
+
|
|
|
if (ec == Error_Succeed && wdErrCode != 0) {
|
|
|
//oilyang@20200525 if have been set ErrorCode of entity defined (not device),use it directly
|
|
|
if ((defaultDevCode >> 20) == m_entCode.dwEntityId)
|
|
|
UpdateDEC(defaultDevCode);
|
|
|
else
|
|
|
UpdateDEC(wdErrCode);
|
|
|
- }
|
|
|
- else if (defaultDevCode != 0) {
|
|
|
+
|
|
|
+ } else if (defaultDevCode != 0) {
|
|
|
UpdateDEC(defaultDevCode);
|
|
|
}
|
|
|
+
|
|
|
m_csAlarmMsg = CSimpleStringA::Format("%s failed EC= %s : %s",
|
|
|
pMsgHead, SpStrError(eErrCode), (LPCTSTR)csErrMsg);
|
|
|
+
|
|
|
if (bAlarm) {
|
|
|
LogWarn(Severity_High, eErrCode, AlarmDECToBusiness(), (LPCTSTR)m_csAlarmMsg);
|
|
|
}
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
|