package main

import (
	"fmt"
	"time"

	"hnyfkj.com.cn/rtu/linux/baseapp"
	camera "hnyfkj.com.cn/rtu/linux/camera"
)

func main() {
	baseapp.ModuleInit()
	if !camera.ModuleInit(true, "192.168.100.123/24", "192.168.100.100/24") {
		return
	}

	baseapp.Logger.Infof("Get HK camera count: %d", camera.GetHKCameraCount())
	baseapp.Logger.Infof("Get DH camera count: %d", camera.GetDHCameraCount())

	baseapp.Logger.Infof("开始拍照测试 ...")
	imgType := 0
	imgFile := ""
	for i := range 9 {
		switch i {
		case 0:
			imgType = camera.IMG_TYPE_BMP
			imgFile = fmt.Sprintf("./test%d.bmp", i+1)
		default:
			imgType = camera.IMG_TYPE_JPG
			imgFile = fmt.Sprintf("./test%d.jpg", i+1)
		}

		var imgMark camera.SImgMark
		var err error

		start := time.Now()
		imgMark, err = camera.TakePhoto(imgType, imgFile, 5*60)
		elapsed := time.Since(start).Milliseconds()

		if err == nil {
			baseapp.Logger.Infof("输出: \"%s\", 用时: %dms, 拍照信息: %+v", imgFile, elapsed, imgMark)
		} else {
			baseapp.Logger.Errorf("拍照时发生错误: %v, 用时: %dms, 请修复所有问题后重试!!", err, elapsed)
		}

		time.Sleep(1 * time.Second) // 轮询拍照测试时, 给系统预留一定的相机释放时间
	}
	baseapp.Logger.Info("拍照测试任务结束")
}
