Browse Source

优化修改Go代码某些变量的命名, 使其更规范合理

niujiuru 1 week ago
parent
commit
d413db126e

+ 8 - 8
mvs_u_takephoto/bridge.go

@@ -47,20 +47,20 @@ func GetUsbCameraCount() int {
 
 // 单次执行相机拍照, 并保存到文件, 成功返回: 本次拍照图像的水印信息, 失败返回: 错误原因和空的水印信息
 // 参数说明:
-// "imgType"         - 图像保存类型: 1-".bmp", 2-".jpg"
-// "saveImgFilename" - 保存的文件名: 根据所选保存图像的类型, 程序会自动校检和处理文件的扩展名(智能)
-// "timeout"         - 等待超时时间, 单位:秒: < 0 表示无超时; 无论超时怎么设置, 首次尝试拍照一定会
+// "imgType"     - 图像保存类型: 1-".bmp", 2-".jpg"
+// "saveImgPath" - 保存的文件名: 根据所选保存图像的类型, 程序会自动校检和处理文件的扩展名(智能)
+// "timeout"     - 等待超时时间, 单位:秒: < 0 表示无超时; 无论超时怎么设置, 首次尝试拍照一定会
 // 执行, 但时间不确定; 拍照成功、超时(相机持续无数据的时间)或发生错误时会自动结束任务.
-func TakePhoto(imgType int, saveImgFilename string, timeout int) (SImgMark, error) {
-	if (imgType != IMG_TYPE_BMP && imgType != IMG_TYPE_JPG) || len(saveImgFilename) == 0 {
+func TakePhoto(imgType int, saveImgPath string, timeout int) (SImgMark, error) {
+	if (imgType != IMG_TYPE_BMP && imgType != IMG_TYPE_JPG) || len(saveImgPath) == 0 {
 		return SImgMark{}, fmt.Errorf("invalid arguments")
 	}
 
-	filename := C.CString(saveImgFilename)
-	defer C.free(unsafe.Pointer(filename))
+	path := C.CString(saveImgPath)
+	defer C.free(unsafe.Pointer(path))
 
 	var imgMark C.SImgMark
-	ret := int(C.TakePhoto(C.EImgType(imgType), filename, C.int(timeout), &imgMark))
+	ret := int(C.TakePhoto(C.EImgType(imgType), path, C.int(timeout), &imgMark))
 	if ret != 0 {
 		return SImgMark{}, fmt.Errorf("an error occurred while calling the C.TakePhoto() function(%d)", ret)
 	}

+ 11 - 11
mvs_u_takephoto/takephoto.c

@@ -11,7 +11,7 @@ typedef struct
 {
   HANDLE      hCam;
   EImgType    saveImgType;
-  const char *saveImgFilename;
+  const char *saveImgPath;
   bool        isExposureAuto; // 自动曝光:是/否
   struct timespec expTime0;   // 曝光开始的时间
   float       lastExpTime;    // 上次的曝光时长
@@ -59,7 +59,7 @@ getp:
       }
     }
 
-    ret = SavePhoto(ctx->hCam, &frame, ctx->saveImgType, ctx->saveImgFilename);
+    ret = SavePhoto(ctx->hCam, &frame, ctx->saveImgType, ctx->saveImgPath);
     MV_CC_FreeImageBuffer(ctx->hCam, &frame);
   }
 
@@ -76,14 +76,14 @@ getp:
 }
 
 // 单次执行相机拍照, 并保存到文件, 成功返回: 0值, 失败返回:非0值
-// "imgType"         - 获取图像类型
-// "saveImgFilename" - 保存的文件名
-// "timeout"         - 等待超时时间, 单位:秒: < 0 表示无超时;
-//                     无论超时怎么设置, 首次尝试拍照一定会执行
-//                     , 但时间不确定; 拍照成功、超时或发生错误
-//                     时会自动结束任务(相机持续无数据的时间).
-// "pImgMark"        - 输出本次拍照图像的水印信息, 可以设置NULL
-int TakePhoto(EImgType imgType, const char *saveImgFilename, int timeout, SImgMark *pImgMark)
+// "imgType"     - 获取图像类型
+// "saveImgPath" - 保存的文件名
+// "timeout"     - 等待超时时间, 单位:秒: < 0 表示无超时;
+//                 无论超时怎么设置, 首次尝试拍照一定会执行
+//                 , 但时间不确定; 拍照成功、超时或发生错误
+//                 时会自动结束任务(相机持续无数据的时间).
+// "pImgMark"    - 输出本次拍照图像的水印信息, 可以设置NULL
+int TakePhoto(EImgType imgType, const char *saveImgPath, int timeout, SImgMark *pImgMark)
 {
   int fd; char runDir[MAX_PATH_CHARS] = { 0 }, lockFile[MAX_PATH_CHARS+32] = { 0 };
   int ret; SImgMark imgMark = { 0 }; HANDLE hCam = NULL; PthotoProcCtx ctx = { 0 };
@@ -169,7 +169,7 @@ int TakePhoto(EImgType imgType, const char *saveImgFilename, int timeout, SImgMa
 
   ctx.hCam = hCam;
   ctx.saveImgType = imgType;
-  ctx.saveImgFilename = saveImgFilename;
+  ctx.saveImgPath = saveImgPath;
   ctx.hESig = sw_signal_create();
   if(!ctx.hESig)
   {

+ 8 - 8
mvs_u_takephoto/takephoto.h

@@ -37,14 +37,14 @@ int SetSysUsbfsMemSize(int val);
 int GetUsbCameraCount();
 
 // 单次执行相机拍照, 并保存到文件, 成功返回: 0值, 失败返回:非0值
-// "imgType"         - 获取图像类型
-// "saveImgFilename" - 保存的文件名
-// "timeout"         - 等待超时时间, 单位:秒: < 0 表示无超时;
-//                     无论超时怎么设置, 首次尝试拍照一定会执行
-//                     , 但时间不确定; 拍照成功、超时或发生错误
-//                     时会自动结束任务(相机持续无数据的时间).
-// "pImgMark"        - 输出本次拍照图像的水印信息, 可以设置NULL
-int TakePhoto(EImgType imgType, const char *saveImgFilename, int timeout, SImgMark *pImgMark);
+// "imgType"     - 获取图像类型
+// "saveImgPath" - 保存的文件名
+// "timeout"     - 等待超时时间, 单位:秒: < 0 表示无超时;
+//                 无论超时怎么设置, 首次尝试拍照一定会执行
+//                 , 但时间不确定; 拍照成功、超时或发生错误
+//                 时会自动结束任务(相机持续无数据的时间).
+// "pImgMark"    - 输出本次拍照图像的水印信息, 可以设置NULL
+int TakePhoto(EImgType imgType, const char *saveImgPath, int timeout, SImgMark *pImgMark);
 
 #ifdef __cplusplus
 }

+ 1 - 1
mvs_u_takephoto/takephoto_test.c

@@ -27,7 +27,7 @@ int main(int argc,char *argv[])
   sw_log_info("Photo taking...");
   for(int i = 0; i < 9; i++)
   {
-    sprintf(filename, "./test%d.jpg", i+1);
+    sprintf(filename, "test%d.jpg", i+1);
 
     xgettickcount(&stime);
     ret = TakePhoto(IMG_TYPE_JPG, filename, timeout, NULL);

+ 5 - 5
utils/ftpclient/ftpclient.go

@@ -65,15 +65,15 @@ func tryLockFile(file string) (unlock func(), ok bool) {
 
 type progressReader struct {
 	io.Reader
-	filename           string
+	filepath           string
 	total, transferred int64
 	label              string // "上传"或"下载"
 	ctx                context.Context
 	doneLogged         int32
 }
 
-func newProgressReader(r io.Reader, filename string, total, transferred int64, label string, ctx context.Context) *progressReader {
-	pr := &progressReader{Reader: r, filename: filename, total: total, transferred: transferred, label: label, ctx: ctx}
+func newProgressReader(r io.Reader, filepath string, total, transferred int64, label string, ctx context.Context) *progressReader {
+	pr := &progressReader{Reader: r, filepath: filepath, total: total, transferred: transferred, label: label, ctx: ctx}
 	go pr.startProgressLogger()
 	return pr
 }
@@ -85,7 +85,7 @@ func (p *progressReader) Read(buf []byte) (int, error) {
 	}
 	if err == io.EOF && atomic.CompareAndSwapInt32(&p.doneLogged, 0, 1) {
 		transferred := atomic.LoadInt64(&p.transferred)
-		baseapp.Logger.Infof("[%s] 文件%q%s进度: 100.00%%, 剩余: %d字节, 总大小: %d字节", MODULE_NAME, p.filename, p.label, p.total-transferred, p.total)
+		baseapp.Logger.Infof("[%s] 文件%q%s进度: 100.00%%, 剩余: %d字节, 总大小: %d字节", MODULE_NAME, p.filepath, p.label, p.total-transferred, p.total)
 	}
 	return n, err
 }
@@ -107,7 +107,7 @@ func (p *progressReader) startProgressLogger() {
 			}
 
 			progress := float64(transferred) / float64(p.total) * 100
-			baseapp.Logger.Infof("[%s] 文件%q%s进度: %.2f%%, 剩余: %d字节, 总大小: %d字节", MODULE_NAME, p.filename, p.label, progress, p.total-transferred, p.total)
+			baseapp.Logger.Infof("[%s] 文件%q%s进度: %.2f%%, 剩余: %d字节, 总大小: %d字节", MODULE_NAME, p.filepath, p.label, progress, p.total-transferred, p.total)
 		case <-p.ctx.Done():
 			return
 		}