Browse Source

优化修改海康相机模块代码

niujiuru 2 days ago
parent
commit
1b30ea4ee4
1 changed files with 8 additions and 17 deletions
  1. 8 17
      hk_takephoto/takephoto.c

+ 8 - 17
hk_takephoto/takephoto.c

@@ -7,14 +7,11 @@ static const char MODULE_NAME[] = "TakePhoto";
 static unsigned int device_type =  MV_GIGE_DEVICE | MV_USB_DEVICE;
 
 // 制造厂商
-static const char *manufacturer = "Hikrobot";
+static const char * const manufacturer = "Hikrobot";
 
 // 触发模式
 static MV_CAM_TRIGGER_MODE setTriggerMode = MV_TRIGGER_MODE_ON; /// 默认: 打开
 
-// 网口相机
-#define GIGE_CAMERA_ANY_VENDOR  1 // 支持任意厂商的网口相机, 否则只支持海康机器人
-
 // 曝光取图
 #define AE_WAIT_MAX_MS     180000 // 最大曝光稳定等待的时间, 默认3分钟, 单位: ms
 #define AE_EXP_TIME_EPS_US     50 // 曝光时间稳定判定的误差, 防抖&区间, 单位: us
@@ -39,15 +36,13 @@ typedef struct
   int         rCode;          // 任务结束返回值
 } PthotoProcCtx;
 
-// 网口相机
-// 支持的第三方厂商列表(用海康的SDK操作相机并拍照)
-static const char * const gige_3rd_manu_names[] = {"Huaray Technology", "Machine Vision"};
-static bool gige_3rd_manu_supported(const char *name)
+// 非标准的"Hikrobot"制造商名称, 但也是海康的相机
+static const char * const hikrobot_manu_aliases[] = { NULL };
+static bool is_hikrobot_manu_alias(const char *name)
 {
-  if(0 == GIGE_CAMERA_ANY_VENDOR) return false;
-  for(int i = 0; i < sizeof(gige_3rd_manu_names)/sizeof(gige_3rd_manu_names[0]); i++)
+  for(int i = 0; i < hikrobot_manu_aliases[i] != NULL; i++)
   {
-    if(xstrcasecmp(name, gige_3rd_manu_names[i]) == 0) return true;
+    if(xstrcasecmp(name, hikrobot_manu_aliases[i]) == 0) return true;
   }
   return false;
 }
@@ -183,13 +178,9 @@ findp:
     ctx.camType = MV_GIGE_DEVICE;
     strcpy(imgMark.camModelName, (const char *)pDevInfo->SpecialInfo.stGigEInfo.chModelName);
     strcpy(imgMark.camSerialNum, (const char *)pDevInfo->SpecialInfo.stGigEInfo.chSerialNumber);
-    if(xstrcasecmp(ctx.manuName, manufacturer) != 0 && gige_3rd_manu_supported(ctx.manuName))
-    {
-      setTriggerMode = MV_TRIGGER_MODE_OFF;
-    }
   }
 
-  if(xstrcasecmp(ctx.manuName, manufacturer) != 0 && (ctx.camType != MV_GIGE_DEVICE || !gige_3rd_manu_supported(ctx.manuName)))
+  if(xstrcasecmp(ctx.manuName, manufacturer) != 0 && !is_hikrobot_manu_alias(ctx.manuName))
   {
     if(index < devList.nDeviceNum) goto findp;
     ret = -5;
@@ -418,7 +409,7 @@ findp:
     else if(pDevInfo && pDevInfo->nTLayerType == MV_USB_DEVICE /*U口相机*/) strcpy(name, (const char *)pDevInfo->SpecialInfo.stUsb3VInfo.chManufacturerName);
     else if(pDevInfo && pDevInfo->nTLayerType == MV_GIGE_DEVICE/*G口相机*/) strcpy(name, (const char *)pDevInfo->SpecialInfo.stGigEInfo.chManufacturerName) ;
 
-    if(xstrcasecmp(name, manufacturer) == 0 || (pDevInfo->nTLayerType == MV_GIGE_DEVICE && gige_3rd_manu_supported(name))) cnt++;
+    if(xstrcasecmp(name, manufacturer) == 0 || is_hikrobot_manu_alias(name)) cnt++;
     if(index < devList.nDeviceNum) goto findp;
     else ret = cnt;
   }