123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840 |
- // GpioClassImpl_DistrBusUSB.cpp :
- //
- #include <cstdio>
- #include "GpioClassImpl_DistrBusUSB.h"
- CINIAccess g_iniAccess;
- CHAR g_sIniPath[MAX_PATH] = {0};
- LOG_EXTERN()
- int getFileVer(char* sFile, short &ch1, short &ch2)
- {
- ch1 = 0;
- ch2 = 0;
- char* pFind = strstr(sFile, ".so");
- char* pTemp = pFind;
- while(pTemp)
- {
- pFind = pTemp;
- pTemp = strstr(pFind + 3, ".so");
- }
- if(pFind == nullptr) return 0;
- pTemp = pFind - 1;
- while(isdigit(*pTemp) && pTemp > sFile) pTemp--;
- if(*pTemp == '.')
- ch2 = atoi(pTemp + 1);
- pTemp--;
- while(isdigit(*pTemp) && pTemp > sFile) pTemp--;
- if(*pTemp == '.')
- ch1 = atoi(pTemp + 1);
- return 1;
- }
- //int GetDllPathLocal(std::string& dllPath)
- //{
- // Dl_info path_info;
- // dladdr("load_so",&path_info);
- // dladdr("LoadSDKDll",&path_info);
- // char str_FilePath[256]{0};
- // memcpy(str_FilePath,path_info.dli_fname,strlen(path_info.dli_fname));
- // printf("first_str_FilePath=%s\n",str_FilePath);
- // char *pLastSlath=strrchr(str_FilePath,'/');
- // *(pLastSlath + 1)=0;
- // std::string a(str_FilePath);
- // dllPath = a;
- // return 0;
- //}
- GpioClassImpl::GpioClassImpl():
- m_bDevOpen(false),
- m_bIsUSBOn(false),
- m_nUSBDelay(0),
- m_hDistrBusUSB(NULL),
- PDD_DIO_CATEGORY(40000),
- PDD_DIO_QUERY(CtlCode( PDD_DIO_CATEGORY, (0x900 + 6), Buffered, Any )),
- PDD_DIO_READ(CtlCode( PDD_DIO_CATEGORY, (0x900 + 7), Buffered, Any )),
- PDD_DIO_WRITE_INT(CtlCode( PDD_DIO_CATEGORY, (0x900 + 10), Buffered, Any ))
- {
- KEBA_DevCtrl=new CKEBA_DevCtrl();
- m_wDevStatus = DEVICE_STATUS_NOT_READY;
- }
- GpioClassImpl::~GpioClassImpl()
- {
- LOG_FUNCTION();
- // DevClose();
- if (KEBA_DevCtrl != NULL)
- {
- delete KEBA_DevCtrl;
- KEBA_DevCtrl = NULL;
- }
- }
- //DeviceBaseClass
- ErrorCodeEnum GpioClassImpl::GetDevCategory(DevCategoryInfo &devCategory)
- {
- LOG_FUNCTION();
- // LogM("GpioClassImpl::Entry->Gpio GetDevCategory()!");
- memset(devCategory.szType, 0, MAX_DEV_TYPE_LEN);
- memset(devCategory.szModel, 0, MAX_DEV_MODEL_LEN);
- memset(devCategory.szVendor, 0, MAX_DEV_VENDOR_LEN);
- char sPath[256], sFile[128] = {0};
- GetCurModulePath(sPath, sFile);
- short v1,v2;
- getFileVer(sFile, v1, v2);
- devCategory.version.wMajor = v1;
- devCategory.version.wMinor = v2;
- devCategory.version.wRevision = 0xFFFF;
- devCategory.version.wBuild = 1;
- // memcpy(devCategory.szType, "CMB.GPIO", strlen("CMB.GPIO"));
- memcpy(devCategory.szType, "PVER=KEBA#MID=DistrBusUSB", strlen("PVER=KEBA#MID=DistrBusUSB"));
- // memcpy(devCategory.szModel, "Distribution_Bus_USB", strlen("Distribution_Bus_USB"));
- memcpy(devCategory.szModel, "FWID=V1.0", strlen("FWID=V1.0"));
- memcpy(devCategory.szVendor, "KEBA", strlen("KEBA"));
- devCategory.eState = (DevStateEnum)m_wDevStatus;
- // devCategory.version.wMajor = (WORD)portio_read_version();
- LogM("DevCategoryInfo() outputparameter: szType:%s, szModel:%s,szVendor:%s, eState:%d", devCategory.szType, devCategory.szModel, devCategory.szVendor, devCategory.eState);
- LogM("DevCategoryInfo() outputparameter: wMajor:%d, wMinor:%d,wRevision:%d, wBuild:%d", devCategory.version.wMajor, devCategory.version.wMinor, devCategory.version.wRevision, devCategory.version.wBuild);
- // LogM("DevCategoryInfo() OK!");
- return Error_Succeed;
- }
- ErrorCodeEnum GpioClassImpl::Reset()
- {
- LOG_FUNCTION();
- // LogM("GpioClassImpl::Entry->Gpio Reset()!");
- BYTE inBuffer[8]={0};
- BYTE outBuffer[8]={0};
- ULONG bytesReturned = 0;
- char szErrorMsg[256] = {0};
- if(!m_bDevOpen)
- {
- GpioInitParam initParam;
- initParam.dwPortNum = m_dwPortNum;
- for(int i=0; i<MIN(MAX_PORT_NUM, m_dwPortNum); i++)
- {
- initParam.dir[i] = m_dir[i];
- }
- if(DevOpen(initParam))
- {
- sprintf(szErrorMsg, "打开设备失败");
- SaveErrorInfo(szErrorMsg, DEP_DEV_NOT_OPENED, __FUNCTION__, __LINE__);
- LogM("Reset() return Error_DevNotAvailable");
- m_wDevStatus = DEVICE_STATUS_NOT_READY;
- return Error_DevNotAvailable;
- }
- }
- if(KEBA_DevCtrl->Reset() != FALSE)
- {
- // LogM("Reset() OK!");
- sprintf(szErrorMsg, "复位成功");
- SaveErrorInfo(szErrorMsg, DEP_SUCCESS, __FUNCTION__, __LINE__);
- m_wDevStatus = DEVICE_STATUS_NORMAL;
- return Error_Succeed;
- }
- else
- {
- LogM("Reset() return Error_DevNotAvailable");
- sprintf(szErrorMsg, "复位失败");
- SaveErrorInfo(szErrorMsg, DEP_NO_E_GPIO_IOCONTROL, __FUNCTION__, __LINE__);
- m_wDevStatus = DEVICE_STATUS_FAULT;
- return Error_DevNotAvailable;
- }
- }
- ErrorCodeEnum GpioClassImpl::DevClose()
- {
- LOG_FUNCTION();
- m_wDevStatus = DEVICE_STATUS_NOT_READY;
- // LogM("DevClose() ");
- if(!m_bDevOpen)
- {
- // LogM("DevClose(): Dev is not open.");
- // LogM("DevClose() OK!");
- return Error_Succeed;
- }
- KEBA_DevCtrl->CloseDevice();
- m_bDevOpen = false;
- // LogM("DevClose() OK!");
- return Error_Succeed;
- }
- ErrorCodeEnum GpioClassImpl::GetLastErr(DevErrorInfo &devErrInfo)
- {
- LOG_FUNCTION();
- // LogM("GetLastErr() ");
- devErrInfo.dwErrMsgLen = strlen(m_szErrMsg);
- memset(devErrInfo.szErrMsg, 0, MAX_DEV_ERROR_MSG_LEN);
- memcpy(devErrInfo.szErrMsg, m_szErrMsg, MIN(devErrInfo.dwErrMsgLen, MAX_DEV_ERROR_MSG_LEN));
- LogM("GetLastErr() return: devErrInfo.dwErrMsgLen=%d, devErrInfo.szErrMsg:%s", devErrInfo.dwErrMsgLen, devErrInfo.szErrMsg);
- // LogM("GetLastErr() OK!");
- return Error_Succeed;
- }
- //GpioClass
- //
- // Device initialization.
- // Configure port input/output direction.
- //
- ErrorCodeEnum GpioClassImpl::DevOpen(GpioInitParam initParam)
- {
- LOG_FUNCTION();
- // CHAR sIniPath[MAX_PATH];
- // memset(sIniPath, 0, sizeof(sIniPath));
- // char sPath[256] = {0}, sFile[128] = {0};
- // GetCurModulePath(sPath, sFile);
- // GetCurModulePath(sPath, nullptr);
- // memcpy(g_sIniPath,sPath,sizeof (sPath));
- // sprintf(m_sIniPath, "%s/%s", m_sIniPath, "keba/Adapter_L.keba.INI");
- // strcat(g_sIniPath, "/keba/Adapter_L.keba.INI");
- // LogM("GPIO的配置文件=%s",m_sIniPath);
- // std::string dllPath = "";
- // GetDllPathLocal(dllPath);
- // dllPath += "keba/Adapter_L.keba.INI";
- // memcpy(g_sIniPath, dllPath.c_str(), dllPath.length());
- char szErrorMsg[256] = {0};
- CFileDir::GetFilePathName(
- getpid(), "keba", "Adapter_L.keba.INI",
- g_sIniPath, sizeof(g_sIniPath));
- // strcpy(g_sIniPath, "/opt/Run/version/0.0.3.22/dep/keba/Adapter_L.keba.INI");
- // m_nUSBDelay = g_iniAccess.GetPrivateProfileInt("Gpio", "USBDELAY", 3000, g_sIniPath);
- m_nUSBDelay = 3000;
- //DevOpen():dwPortNum:3, dir:1 1 0 204
- LogM("DevOpen() input parameter:dwPortNum:%d, dir:%d %d %d %d", initParam.dwPortNum, initParam.dir[0], initParam.dir[1],initParam.dir[2],initParam.dir[3] );
- m_dwPortNum = initParam.dwPortNum;
- m_outputPortTotal = 0;
- for(int i = 0; i < MAX_PORT_NUM; i++)
- {
- m_dir[i] = initParam.dir[i];
- if(m_dir[i]==1)
- {
- m_outputPortTotal ++;
- LogM("DevOpen() m_dir[%d] = %d", i,m_dir[i]);
- }
- }
- if(m_bDevOpen)
- {
- m_wDevStatus = DEVICE_STATUS_NORMAL;
- sprintf(szErrorMsg, "已经打开设备成功");
- SaveErrorInfo(szErrorMsg, DEP_SUCCESS, __FUNCTION__, __LINE__);
- // LogM("DevOpen() Dev is open already. Return Error_Succeed;");
- return Error_Succeed;
- }
- DevClose();
- BOOL bRet = KEBA_DevCtrl->InitDevice();
- if (bRet == FALSE)
- {
- LogM("DevOpen()->GetFileType() failed. return Error_DevNotAvailable;");
- DevClose();
- m_wDevStatus = DEVICE_STATUS_NOT_READY;
- sprintf(szErrorMsg, "打开设备失败");
- SaveErrorInfo(szErrorMsg, DEP_DEV_NOT_OPENED, __FUNCTION__, __LINE__);
- return Error_DevNotAvailable;
- }
- m_bDevOpen = true;
- m_wDevStatus = DEVICE_STATUS_NORMAL;
- sprintf(szErrorMsg, "打开设备成功");
- SaveErrorInfo(szErrorMsg, DEP_SUCCESS, __FUNCTION__, __LINE__);
- return Error_Succeed;
- /*
- if(Error_Succeed == LightTurnOn())
- {
- //m_pLog->Print("DevOpen(): OK!" );
- m_wDevStatus = DEVICE_STATUS_NORMAL;
- return Error_Succeed;
- }
- else
- {
- //m_pLog->Print("DevOpen() return Error_DevNotAvailable;");
- m_wDevStatus = DEVICE_STATUS_FAULT;
- return Error_DevNotAvailable;
- }
- */
- }
- //
- // Set ports output.
- // Arguments:
- // - dwPort:port serial number,0~MAX_PORT_NUM-1
- // - btData:output value
- // bit value 1/0 means voltage high or low
- // ex.dwPort=0 btData=10001010 means set port 0's the 2nd,4th,8th pin output high
- //
- ErrorCodeEnum GpioClassImpl::WritePort(DWORD dwPort, BYTE btData)
- {
- LOG_FUNCTION();
- //zouchuang rang jia 50ms
- usleep(50*1000);
- // LogM("WritePort()input parameter:dwPort:%d, btData:0x%02x", dwPort, btData);
- if(dwPort == 0)
- {
- if((btData & 0x02)== 0x02)
- m_bIsUSBOn = true;
- else if (m_bIsUSBOn)
- {
- usleep(m_nUSBDelay*1000);
- m_bIsUSBOn = false;
- }
- }
- char szErrorMsg[256] = {0};
- if(!m_bDevOpen)
- {
- LogM("WritePort() return Error_DevNotAvailable");
- m_wDevStatus = DEVICE_STATUS_NOT_READY;
- sprintf(szErrorMsg, "没有打开设备");
- SaveErrorInfo(szErrorMsg, DEP_DEV_NOT_OPENED, __FUNCTION__, __LINE__);
- return Error_DevNotAvailable;
- }
- if(!m_dir[dwPort])
- {
- LogM("WritePort() input parameter is invalied:Port%d is not output port. return Error_Param",dwPort);
- return Error_Param;
- }
- // CHAR sIniPath[MAX_PATH];
- // memset(sIniPath, 0, sizeof(sIniPath));
- // char sPath[256] = {0}, sFile[128] = {0};
- // GetCurModulePath(sPath, sFile);
- // memcpy(sIniPath,sPath,sizeof (sPath));
- // strcat(sIniPath, "/keba/Adapter_L.keba.INI");
- // strcpy(sIniPath, "/opt/Run/version/0.0.3.22/dep/keba/Adapter_L.keba.INI");
- BYTE inBuffer[8]={0};
- BYTE outBuffer[8]={0};
- ULONG bytesReturned = 0;
- char outputPin[20] = {0};
- int iOutputsNo = 0, iOutputs = 0, iCnt = 0;
- iOutputsNo = 0; //PinNo need change status, will put into buffer[0]~[3]
- iOutputs = 0; //PinStatus need change,will put into buffer[4]~[7]
- BOOL bRet = FALSE;
- bool bIsOn[8] = {FALSE};
- WORD wOutputNobuf[8] = {0};
- int iPin, iOutputNo;
- memset(inBuffer, 0x00, 8);
- for(int i = 1; i<=8; i++)
- {
- iPin = i + dwPort*8;
- sprintf(outputPin, "OUTPUT_PIN%d", iPin);
- iOutputNo = g_iniAccess.GetPrivateProfileInt("Gpio", outputPin, 0, g_sIniPath);
- if (iPin == 1)
- {
- iOutputNo = 11;
- }
- else if (iPin == 2)
- {
- iOutputNo = 28;
- }
- else if (iPin == 3)
- {
- iOutputNo = 26;
- }
- else if (iPin == 4)
- {
- iOutputNo = 15;
- }
- else if (iPin == 5)
- {
- iOutputNo = 16;
- }
- else if (iPin == 6)
- {
- iOutputNo = 17;
- }
- else if (iPin == 7)
- {
- iOutputNo = 21;
- }
- else if (iPin == 8)
- {
- iOutputNo = 29;
- }
- else if (iPin == 9)
- {
- iOutputNo = 25;
- }
- else if (iPin == 10)
- {
- iOutputNo = 24;
- }
- else if (iPin == 11)
- {
- iOutputNo = 27;
- }
- else if (iPin == 12)
- {
- iOutputNo = 13;
- }
- else if (iPin == 13)
- {
- iOutputNo = 19;
- }
- else if (iPin == 14)
- {
- iOutputNo = 18;
- }
- else if (iPin == 15)
- {
- iOutputNo = 12;
- }
- else if (iPin == 16)
- {
- iOutputNo = 22;
- }
- else {
- }
- if ( !iOutputNo ) continue;
- wOutputNobuf[iCnt] = (WORD)iOutputNo;
- if(btData & (1<<(i-1)))
- {
- bIsOn[iCnt] = TRUE;
- }
- else
- {
- bIsOn[iCnt] = FALSE;
- }
- iCnt ++;
- }
- bRet = KEBA_DevCtrl->SetGuidLight(wOutputNobuf, bIsOn, iCnt);
- if (bRet == FALSE)
- {
- sprintf(szErrorMsg, "SetGuidLight() 执行失败,点灯失败");
- SaveErrorInfo(szErrorMsg, DEP_NO_E_GPIO_IOCONTROL, __FUNCTION__, __LINE__);
- LogM("WritePort()input parameter:dwPort:%d, btData:0x%02x", dwPort, btData);
- LogM("WritePort()->SetGuidLight(): %s",szErrorMsg);
- m_wDevStatus = DEVICE_STATUS_FAULT;
- return Error_DevNotAvailable;
- }
- // LogM("WritePort() OK!");
- m_wDevStatus = DEVICE_STATUS_NORMAL;
- return Error_Succeed;
- }
- //
- // Get port input.
- // Arguments:
- // - dwPort:port serial number,0~MAX_PORT_NUM-1
- // - btStatus:input value
- // ex.dwPort=0 btStatus=10001010 means port 0's the 2nd,4th,8th pin with high level
- //
- ErrorCodeEnum GpioClassImpl::ReadPort(DWORD dwPort,BYTE &btStatus)
- {
- LOG_FUNCTION();
- char szErrorMsg[256] = {0};
- // LogM("ReadPort()input parameter:dwPort:%d", dwPort);
- if(!m_bDevOpen)
- {
- sprintf(szErrorMsg, "没有打开设备");
- SaveErrorInfo(szErrorMsg, DEP_DEV_NOT_OPENED, __FUNCTION__, __LINE__);
- LogM("ReadPort() return Error_DevNotAvailable");
- m_wDevStatus = DEVICE_STATUS_NOT_READY;
- return Error_DevNotAvailable;
- }
- // CHAR sIniPath[MAX_PATH];
- // memset(sIniPath, 0, sizeof(sIniPath));
- // strcpy(sIniPath, "/opt/Run/version/0.0.3.22/dep/keba/Adapter_L.keba.INI");
- // char sPath[256] = {0}, sFile[128] = {0};
- // GetCurModulePath(sPath, sFile);
- // memcpy(sIniPath,sPath,sizeof (sPath));
- // strcat(sIniPath, "/keba/Adapter_L.keba.INI");
- BYTE inBuffer[8]={0};
- BYTE outBuffer[8]={0};
- ULONG bytesReturned = 0;
- int iPin = 0, iInputNo = 0;
- int portno = 0;
- BOOL bRet = FALSE, bFailFlag = FALSE;
- WORD wStatus = 0;
- memset(inBuffer, 0x00, 8);
- btStatus = 0x00;
-
- for(int i = 0; i < m_dwPortNum; i ++)
- {
- if(!m_dir[i])
- {
- portno ++;
- if(i == dwPort)
- {
- portno --;
- break;
- }
- }
- }
- char inputPin[20] = {0};
- for(int i = 1; i<=8; i++ )
- {
- iPin = i + portno*8;
- if(m_dir[dwPort])
- {
- sprintf(inputPin, "OUTPUT_PIN%d", iPin%32);
- iInputNo = 32 + g_iniAccess.GetPrivateProfileInt("Gpio", inputPin, 0, g_sIniPath);
- if (g_iniAccess.GetPrivateProfileInt("Gpio", inputPin, 0, g_sIniPath) == 0)
- {
- if (iPin%32 == 1)
- {
- iInputNo = 32 + 11;
- }
- else if (iPin%32 == 2)
- {
- iInputNo = 32 + 28;
- }
- else if (iPin%32 == 3)
- {
- iInputNo = 32 + 26;
- }
- else if (iPin%32 == 4)
- {
- iInputNo = 32 + 15;
- }
- else if (iPin%32 == 5)
- {
- iInputNo = 32 + 16;
- }
- else if (iPin%32 == 6)
- {
- iInputNo = 32 + 17;
- }
- else if (iPin%32 == 7)
- {
- iInputNo = 32 + 21;
- }
- else if (iPin%32 == 8)
- {
- iInputNo = 32 + 29;
- }
- else if (iPin%32 == 9)
- {
- iInputNo = 32 + 25;
- }
- else if (iPin%32 == 10)
- {
- iInputNo = 32 + 24;
- }
- else if (iPin%32 == 11)
- {
- iInputNo = 32 + 27;
- }
- else if (iPin%32 == 12)
- {
- iInputNo = 32 + 13;
- }
- else if (iPin%32 == 13)
- {
- iInputNo = 32 + 19;
- }
- else if (iPin%32 == 14)
- {
- iInputNo = 32 + 18;
- }
- else if (iPin%32 == 15)
- {
- iInputNo = 32 + 12;
- }
- else if (iPin%32 == 16)
- {
- iInputNo = 32 + 22;
- }
- else
- {
- }
- }
- bRet = KEBA_DevCtrl->getChannelStatus(TRUE, iInputNo, wStatus);
- }
- else
- {
- sprintf(inputPin, "INPUT_PIN%d", iPin%32);
- iInputNo = g_iniAccess.GetPrivateProfileInt("Gpio", inputPin, 0, g_sIniPath);
- if (iInputNo == 0)
- {
- if (iPin%32 == 1)
- {
- iInputNo = 7;
- }
- else if (iPin%32 == 2)
- {
- iInputNo = 2;
- }
- else if (iPin%32 == 3)
- {
- iInputNo = 6;
- }
- else if (iPin%32 == 4)
- {
- iInputNo = 5;
- }
- else if (iPin%32 == 5)
- {
- iInputNo = 4;
- }
- else if (iPin%32 == 6)
- {
- iInputNo = 8;
- }
- else if (iPin%32 == 7)
- {
- iInputNo = 3;
- }
- else if (iPin%32 == 8)
- {
- iInputNo = 4;
- }
- else
- {
- }
- }
- bRet = KEBA_DevCtrl->getChannelStatus(FALSE, iInputNo, wStatus);
- }
- if (bRet == FALSE)
- {
- sprintf(szErrorMsg, "getChannelStatus(channel=%d) 执行失败,获取状态失败", iInputNo);
- SaveErrorInfo(szErrorMsg, DEP_NO_E_GPIO_IOCONTROL, __FUNCTION__, __LINE__);
- LogM("ReadPort()input parameter:dwPort:%d", dwPort);
- LogM("WritePort()->SetGuidLight(): %s",szErrorMsg);
- bFailFlag = TRUE;
- }
- if(wStatus)
- {
- btStatus |= 1<<(i-1);
- }
- }
- if (bFailFlag != FALSE)
- {
- m_wDevStatus = DEVICE_STATUS_FAULT;
- return Error_DevNotAvailable;
- }
- // LogM("ReadPort()output parameter:btStatus:0x%02x", btStatus);
- // LogM("ReadPort() OK!");
- m_wDevStatus = DEVICE_STATUS_NORMAL;
- return Error_Succeed;
- }
- //Private
- /*
- void GpioClassImpl::SaveErrorInfo(CHAR* errMsg, int errCode)
- {
- LOG_FUNCTION();
- //memset(m_szErrMsg, 0, MAX_DEV_ERR_MSG);
- LogM("SaveErrorInfo()input parameter:errMsg:%s, errCode:%d", errMsg, errCode);
- memset(m_szErrMsg, 0, MAX_DEV_ERROR_MSG_LEN);
- sprintf(m_szErrMsg, "%s[%d]", errMsg, errCode);
- // LogM("SaveErrorInfo() OK!");
- }
- */
- void GpioClassImpl::SaveErrorInfo(CHAR* errMsg, int errCode, const CHAR* strFunc, int nLine)
- {
- CHAR chJson[MAX_DEV_ERROR_MSG_LEN] = {0};
- sprintf(chJson, "Func:%s,Line:%d,Msg:%s", strFunc, nLine, errMsg);
- memset(m_szErrMsg, 0, MAX_DEV_ERROR_MSG_LEN);
- sprintf(m_szErrMsg, "{\"Errcode\":%d,\"Description\":%s}", errCode,chJson);
- LogM(m_szErrMsg);
- /*
- CHAR chJson[MAX_DEV_ERROR_MSG_LEN] = {0};
- QJsonObject root_Obj;
- QJsonDocument root_Doc;
- sprintf(chJson, "Func:%s,Line:%d,Msg:%s", strFunc, nLine, errMsg);
- root_Obj.insert("ErrCode", errCode);
- root_Obj.insert("Description", chJson);
- root_Doc.setObject(root_Obj);
- QByteArray root_str = root_Doc.toJson(QJsonDocument::Indented); //标准JSON格式 QString strJson(root_str);
- QString strJson(root_str);
- memset(m_szErrMsg, 0, MAX_DEV_ERROR_MSG_LEN);
- sprintf(m_szErrMsg, strJson.toUtf8().data());
- LogM(m_szErrMsg);
- */
- }
- ErrorCodeEnum GpioClassImpl::LightTurnOn()
- {
- LOG_FUNCTION();
- int iOutputNo = 0;
- char outputPin[20] = {0};
- CHAR szErrorMsg[256] = {0};
- if(!m_bDevOpen)
- {
- LogM("LightTurnOn() return Error_DevNotAvailable");
- sprintf(szErrorMsg, "没有打开设备");
- SaveErrorInfo(szErrorMsg, DEP_DEV_NOT_OPENED, __FUNCTION__, __LINE__);
- m_wDevStatus = DEVICE_STATUS_NOT_READY;
- return Error_DevNotAvailable;
- }
- BYTE inBuffer[8]={0};
- BYTE outBuffer[8]={0};
- ULONG bytesReturned = 0;
- BOOL bRet = FALSE;
- int iCnt = 0;
- WORD wOutputNoBuf[16] = {0};
- bool bOnStat[16] = {1};
- // CHAR sIniPath[MAX_PATH];
- // memset(sIniPath, 0, sizeof(sIniPath));
- // strcpy(sIniPath, "/opt/Run/version/0.0.3.22/dep/keba/Adapter_L.keba.INI");
- // char sPath[256] = {0}, sFile[128] = {0};
- // GetCurModulePath(sPath, sFile);
- // memcpy(sIniPath,sPath,sizeof (sPath));
- // strcat(sIniPath, "/keba/Adapter_L.keba.INI");
- for (int i = 1; i < 17; i++)
- {
- sprintf(outputPin, "OUTPUT_PIN%d", i);
- iOutputNo = g_iniAccess.GetPrivateProfileInt("Gpio", outputPin, 0, g_sIniPath);
- if (i == 1)
- {
- iOutputNo = 11;
- }
- else if (i == 2)
- {
- iOutputNo = 28;
- }
- else if (i == 3)
- {
- iOutputNo = 26;
- }
- else if (i == 4)
- {
- iOutputNo = 15;
- }
- else if (i == 5)
- {
- iOutputNo = 16;
- }
- else if (i == 6)
- {
- iOutputNo = 17;
- }
- else if (i == 7)
- {
- iOutputNo = 21;
- }
- else if (i == 8)
- {
- iOutputNo = 29;
- }
- else if (i == 9)
- {
- iOutputNo = 25;
- }
- else if (i == 10)
- {
- iOutputNo = 24;
- }
- else if (i == 11)
- {
- iOutputNo = 27;
- }
- else if (i == 12)
- {
- iOutputNo = 13;
- }
- else if (i == 13)
- {
- iOutputNo = 19;
- }
- else if (i == 14)
- {
- iOutputNo = 18;
- }
- else if (i == 15)
- {
- iOutputNo = 12;
- }
- else if (i == 16)
- {
- iOutputNo = 22;
- }
- else {
- }
- if ( !iOutputNo ) continue;
- wOutputNoBuf[iCnt] = iOutputNo;
- iCnt ++;
- }
- bRet = KEBA_DevCtrl->SetGuidLight(wOutputNoBuf, bOnStat, 16);
- if (bRet == FALSE)
- {
- sprintf(szErrorMsg, "SetGuidLight() 执行失败,点灯失败");
- SaveErrorInfo(szErrorMsg, DEP_NO_E_GPIO_IOCONTROL, __FUNCTION__, __LINE__);
- LogM("WritePort()->SetGuidLight(): %s",szErrorMsg);
- m_wDevStatus = DEVICE_STATUS_FAULT;
- return Error_DevNotAvailable;
- }
- // LogM("LightTurnOn() OK!");
- m_wDevStatus = DEVICE_STATUS_NORMAL;
- return Error_Succeed;
- }
- void GpioClassImpl::intToByte(int i, BYTE* buf, UINT uOffset)
- {
- buf[0 + uOffset] = (BYTE) (0xff & i);
- buf[1 + uOffset] = (BYTE) ((0xff00 & i) >> 8);
- buf[2 + uOffset] = (BYTE) ((0xff0000 & i) >> 16);
- buf[3 + uOffset] = (BYTE) ((0xff000000 & i) >> 24);
- }
- int GpioClassImpl::bytesToInt(BYTE* bytes, UINT uOffset)
- {
- int num = bytes[0 + uOffset] & 0xFF;
- num |= ((bytes[1 + uOffset] << 8) & 0xFF00);
- num |= ((bytes[2 + uOffset] << 16) & 0xFF0000);
- num |= ((bytes[3 + uOffset] << 24) & 0xFF000000);
- return num;
- }
|