1.确保收到mqtt命令后去生效抓图标志。
void CreateOpenDoorJpgName(void *recordData)
{
int i;
int ret;
unsigned char *p;
unsigned char high;
unsigned char low;
if(OpenDoorJpgFlag == 1)
{
printf(".......OpenDoor_TakePicture is busy now.......\n");
return;//还没处理完毕,直接退出
}
if(CanUseUpYunCheck())
{
SetUpYunDelayTime(0);//重新计时
}
else
{
return;//间隔时间符合要求
}
p = (unsigned char *)recordData;
for(i=0; i<10; i++)
{
low = (p[i] >> 0) & 0x0f;
high = (p[i] >> 4) & 0x0f;
if(high <= 9)
{
OpenDoorJpgName[i*2+0] = high+0x30;
}
else
{
OpenDoorJpgName[i*2+0] = 'A'+high-10;
}
if(low <= 9)
{
OpenDoorJpgName[i*2+1] = low+0x30;
}
else
{
OpenDoorJpgName[i*2+1] = 'A'+low-10;
}
}
OpenDoorJpgName[i*2+0] = '.';
OpenDoorJpgName[i*2+1] = 'j';
OpenDoorJpgName[i*2+2] = 'p';
OpenDoorJpgName[i*2+3] = 'g';
OpenDoorJpgName[i*2+4] = '\0';
OpenDoorJpgFlag = 1;//抓图有时候太快了,要放到抓图操作的前面
ret = OpenDoor_TakePicture();
if(ret == -1)
{
}
else
{
}
printf(".......OpenDoor_TakePicture's ret:%d.......\n", ret);
printf("......OpenDoor_TakePicture:%s..............\n\n",OpenDoorJpgName);
}
2.生效抓图标志一定要放在启动摄像机拍照之前,否则有可能抓图的回调函数在抓图标志生效之前就发生了,回调函数中会去判断抓图标志,决定是否上传,导致逻辑错误。
static void jpegCallback(void *data, int size, void* caller, int id)
{
RecordPreview* rp;
printf("........picture call back %d data %p size %d.......\n", id, data, size);
if(caller == NULL)
{
printf(".....caller not initialized.......\n");
return;
}
rp = (RecordPreview*)caller;
UploadOpenDoorJpgDeal(data, size);
rp->takePicFinish(id);
}
3.确保又拍云发送完毕后才失效抓图标志,以便进行下次抓图生效。
void UploadOpenDoorJpgDeal(void *data, int size)
{
char filename[128];
char full_path_file_name[128];
if(GetOpenDoorJpgFlag())
{
printf(".............yes.................\n");
}
else
{
printf(".............no.................\n");
return;
}
if(Xishi_GetConnectSuccessMqttServerStates()!=1)
{
goto NormalEnd;
}
if(Xishi_GetInfoFromMcuIsOK()!=1)
{
printf("qrz upyun error: is not sn \n");
goto NormalEnd;
}
printf("...........UploadOpenDoorJpgDeal end..........\n");
sprintf(filename,"%s", GetOpenDoorJpgName());//文件名
sprintf(full_path_file_name,"/tmp/%s", GetOpenDoorJpgName());//文件全路径名
WirteFile_Qrz(full_path_file_name, (char *)data, size, 0);
uploadFile(full_path_file_name, filename);
NormalEnd:
SetOpenDoorJpgFlag(0);//发送完毕后才清0标志位
printf("...........UploadOpenDoorJpgDeal: clear flag..........\n\n");
}