commit b1c01dca6c18443b18c6d73b28594dbd8cae572d Author: Elivo Date: Thu Apr 18 15:00:41 2024 +0800 AIPV-SDK-20240320 diff --git a/bin/x64/Debug/AIConnectorSDK.dll b/bin/x64/Debug/AIConnectorSDK.dll new file mode 100644 index 0000000..0d748b5 Binary files /dev/null and b/bin/x64/Debug/AIConnectorSDK.dll differ diff --git a/bin/x64/Release/AIConnectorSDK.dll b/bin/x64/Release/AIConnectorSDK.dll new file mode 100644 index 0000000..07c470b Binary files /dev/null and b/bin/x64/Release/AIConnectorSDK.dll differ diff --git a/include/AIConnectorAPI.h b/include/AIConnectorAPI.h new file mode 100644 index 0000000..e8b1f1d --- /dev/null +++ b/include/AIConnectorAPI.h @@ -0,0 +1,30 @@ +#pragma once +#include "AIPVProtocol.h" + +#ifdef __cplusplus +extern "C" { +#endif + bool KVS_API AIPV_Init(); + bool KVS_API AIPV_Clear(); + AIPV::AIPVErrorCode KVS_API AIPV_GetLastError(); + + bool KVS_API AIPV_IsConnected(uint32_t handle); + + uint32_t KVS_API AIPV_Connect(const char* serverIP); + bool KVS_API AIPV_Stop(uint32_t handle); + + bool KVS_API AIPV_UploadImage(uint32_t handle, AIPV::AIPVFrameHeader* imgHeader, uint8_t* imgData); + bool KVS_API AIPV_MonitorDir(uint32_t handle, const wchar_t* dirPath, AIPV::fcbBeforeUpload callback, void* userData); + bool KVS_API AIPV_SubscribeAIResult(uint32_t handle, bool enable, AIPV::fcbAIPVResult callback, void* userData); + + // module settings + bool KVS_API AIPV_SetModuleOperationTimeout(uint32_t handle, uint32_t milliseconds); + uint32_t KVS_API AIPV_LoadAIModule(uint32_t handle, const wchar_t* modulePath); + bool KVS_API AIPV_SetAIModuleParam(uint32_t handle, uint32_t moduleID, const char* jsonSettings, uint32_t jsonLen); + bool KVS_API AIPV_GetAIModuleParam(uint32_t handle, uint32_t moduleID, char* jsonSettings, uint32_t& jsonLen); + + // debug interface + bool KVS_API AIPV_SimulateDir(uint32_t handle, const wchar_t* dirPath, uint32_t milliseconds, AIPV::fcbBeforeUpload callback, void* userData); +#ifdef __cplusplus +} +#endif diff --git a/include/AIPVProtocol.h b/include/AIPVProtocol.h new file mode 100644 index 0000000..ed0fa1d --- /dev/null +++ b/include/AIPVProtocol.h @@ -0,0 +1,132 @@ +#pragma once +#include +#include +#include +#include + +#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64) || defined(_WINDOWS_) + #ifdef KVS_EXPORTS + #define KVS_API __declspec(dllexport) + #else + #define KVS_API __declspec(dllimport) + #endif + #define KVS_STDCALL __stdcall +#else + #define KVS_STDCALL + #define KVS_API +#endif + +namespace AIPV { + static const uint32_t AIPVCommMagic = 0x0053564B; + static const uint32_t AIPVCommVersion = 0x01000001; // 1.0.0.1 + static const uint32_t AIPVServerPort = 12680; + + static const uint32_t AIPVFilePathSize = 128; + static const uint32_t AIPVMaxImgFilePathSize = 128; + static const uint32_t AIPVDetectItemCount = 144; + + enum class AIPVErrorCode { + Success = 0, + InvalidHandle, + NoMem, + InvalidParam, + NetIOError, + FileIOError, + Refuse, + InvalidState, + OperationTimeout, + OperationFailed, + }; + std::string toStr(AIPVErrorCode e); + + enum class AIPVCommand { + Unknown = 0, + + UploadImage = 128, // C -> S, AIPVCommandHeader + AIPVFrame + SubscribeAIResult, // C -> S, AIPVCommandHeader + AIPVSubscribeReq + PushAIResult, // S -> C, AIPVCommandHeader + AIPVResult + + LoadModule, // C -> S, AIPVCommandHeader + AIPVLoadModuleReq + ReleaseModule, // C -> S, AIPVCommandHeader + AIPVModuleIDReq + SetModuleParam, // C -> S, AIPVCommandHeader + AIPVModuleIDReq + json string + GetModuleParam, // C -> S, AIPVCommandHeader + AIPVModuleIDReq + ModuleOperationRet, // S -> C, AIPVCommandHeader + AIPVModuleOperationRet + json string + }; + std::string toStr(AIPVCommand e); + +#pragma pack(push) +#pragma pack(1) + struct AIPVCommandHeader { + uint32_t mMagic; // AIPVCommMagic + uint32_t mVersion; // AIPVCommVersion + AIPVCommand mCommand; + uint32_t mDataLen; + }; + static const uint32_t AIPVCommandHeaderSize = sizeof(AIPVCommandHeader); + AIPVCommandHeader* fillCommandHeader(AIPVCommandHeader* header, AIPVCommand cmd, uint32_t len); + + // Image frame + enum AIPVMarkCode { + KCVA_OK = 0, + KCVA_NG_DEF, + }; + struct AIPVRect { + uint16_t mOffsetX; + uint16_t mOffsetY; + uint16_t mWidth; + uint16_t mHeight; + uint8_t mMark; // is NG + uint8_t mRes[3]; + }; + struct AIPVFrameHeader { + uint16_t mWidth; + uint16_t mHeight; + char mFilePath[AIPVMaxImgFilePathSize]; + uint32_t mFileSize; + AIPVRect mDetect[AIPVDetectItemCount]; + }; + static const uint32_t AIPVFrameHeaderSize = sizeof(AIPVFrameHeader); + struct AIPVFrame { + AIPVFrameHeader* mHeader; + uint8_t* mData; + }; + + // AI begin + // result + struct AIPVSubscribeReq { + uint8_t mEnable; + uint8_t mRes[3]; + }; + static const uint32_t AIPVSubscribeReqSize = sizeof(AIPVSubscribeReq); + using AIPVResult = AIPVFrameHeader; + static const uint32_t AIPVResultSize = sizeof(AIPVResult); + + // module + struct AIPVLoadModuleReq { + char mPath[AIPVFilePathSize]; + }; + static const uint32_t AIPVLoadModuleReqSize = sizeof(AIPVLoadModuleReq); + struct AIPVModuleIDReq { + uint32_t mModuleID; + }; + static const uint32_t AIPVModuleIDReqSize = sizeof(AIPVModuleIDReq); + struct AIPVModuleOperationRet { + // for LoadModule: return mModuleID + mErrorCode, mJsonSize = 0; + // for ReleaseModule: return mErrorCode, mJsonSize = 0; + // for SetModuleParam: return mErrorCode, mJsonSize = 0; + // for GetModuleParam: return mErrorCode + mJsonSize; + uint32_t mModuleID; + AIPVCommand mOperation; + AIPVErrorCode mErrorCode; + uint32_t mJsonSize; // if > 0, json str appended. + }; + static const uint32_t AIPVModuleOperationRetSize = sizeof(AIPVModuleOperationRet); + // AI end +#pragma pack(pop) +#pragma endregion + + using fcbBeforeUpload = std::function; + using fcbAIPVResult = std::function; +} + + diff --git a/lib/x64/Debug/AIConnectorSDK.lib b/lib/x64/Debug/AIConnectorSDK.lib new file mode 100644 index 0000000..0d683e6 Binary files /dev/null and b/lib/x64/Debug/AIConnectorSDK.lib differ diff --git a/lib/x64/Release/AIConnectorSDK.lib b/lib/x64/Release/AIConnectorSDK.lib new file mode 100644 index 0000000..7ba04a0 Binary files /dev/null and b/lib/x64/Release/AIConnectorSDK.lib differ