📄 camera.c
字号:
#include "mcf5xxx.h"
#include "mcf5222x.h"
#include "m5222x_evb.h"
#include "mwerks.h"
#include "INCLUDES.H"
#include "uart.h"
OS_STK AppTaskCameraStk[256];
const INT8U shoot_photo[9] =
{
0x7E,0x00,0x00,0x00,0x13,0x00,0x13,0x7E //???????
};
static INT8U shoot_photo_back[10] =
{
0x00 //??????????????????
};
static INT8U read_photo[9] =
{
0x7E,0x00,0x02,0x00,0x00,0x00,0x02,0x7E //??????
};
static INT8U read_photo25[10] =
{
0x7E,0x00,0x02,0x00,0x19,0x00,0x1B,0x00,0x7E //??????
};
static INT8U read_photo27[9] =
{
0x7E,0x00,0x02,0x00,0x1B,0x00,0x00,0x1D,0x7E //??????
};
static INT8U read_photo_back[520] =
{
0x00 //??????????????
};
const INT8U resume_camera[9] =
{
0x7E,0x00,0x09,0x00,0x00,0x00,0x09,0x7E //??????
};
static INT8U camera_buf[540] =
{
0x00
};
INT16U camera_bag[43] =
{
0xA5,0xC3,0x00,0x00,0x00,0x00,'h','f','u','t','h','f','u','t','A','0','0','0','0','0','1','I','M','A','G','E',0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
const INT8U last_bag[4] =
{
'#',0xA5,0x99
};
extern OS_EVENT *sem_gps;
extern OS_EVENT *sem_cam;
extern OS_EVENT *sem_lost;
INT8U total_module=0; //???
INT8U image_num = 0; //????
INT8U module = 0; //????
INT8U length1 = 0; //????
INT8U length2 = 0;
INT16U j = 0;
INT8U sl = 0;
INT8U er;
INT8U lost_len = 0;
extern char lost_buffer[20]; //?????????
extern INT8U ReSend_flag;
extern INT8U flag_coutin;
void cdma_send(INT8U buffer[], int num);
void AppTaskCamera (void * pdata)
{
int i = 0;
int k = 0;
int total_length = 0;
int last_frame_count = 0; //???????????pdata = pdata; ????
INT8U err;
INT8U temp;
pdata = pdata;
MCF_GPIO_PTAPAR = MCF_GPIO_PTAPAR_ICOC3_GPIO;
MCF_GPIO_DDRTA = MCF_GPIO_DDRTA_DDRTA3;
while(1)
{
OSSemPend (sem_cam, 0, &err);
ReSend_flag = 10; //flag that is sending IMG
flag_coutin = 0;
for(i=0;i<10000;i++) //?????????????,???????????????4?,????????,?????,??????5??
;
MCF_GPIO_PORTTA = 0x08;
for(i=0;i<8;i++)
uart_putchar(2,shoot_photo[i]);
for(i=0;i<50000;i++) //?????????????,???????????????4?,????????,?????,??????5??
;
MCF_GPIO_PORTTA = 0x00;
for(i=0;i<10;i++)
shoot_photo_back[i] = uart_getchar(2);
total_length = shoot_photo_back[5]*256+shoot_photo_back[6];
total_module = total_length/512;
last_frame_count = total_length%512;
if(last_frame_count != 0)
total_module = total_module+1;
for(i=0;i<1500;i++) //?????????,???3??????????????
;
for(i=0;i<total_module;i++)
{
module = i;
k = 0;
sl = 0;
read_photo[4] = i;
for(j=1;j<5;j++)
sl = sl+read_photo[j];
read_photo[6] = sl;
MCF_GPIO_PORTTA = 0x08;
if(i == 25)
{
for(j=0;j<9;j++)
uart_putchar(2,read_photo25[j]);
}
else if(i == 27)
{
for(j=0;j<9;j++)
uart_putchar(2,read_photo27[j]);
}
else
{
for(j=0;j<8;j++)
uart_putchar(2,read_photo[j]);
}
for(j=0;j<3000;j++) //????????????5??????????????
;
MCF_GPIO_PORTTA = 0x00;
camera_buf[k] = uart_getchar(2);
camera_buf[k] = uart_getchar(2);
do
{
k++;
camera_buf[k] = uart_getchar(2);
}while(camera_buf[k] != 0x7E);
length1 = (k+1)/256;
length2 = (k+1)%256;
cdma_send(camera_buf,k+1);
}
ReSend_flag = 2; // END OF fist IMG send
FD810_Send((INT8U *)"E:WAITTING FOR RESEND CMD\r\n",strlen("E:WAITTING FOR RESEND CMD\r\n"));
OSSemPend (sem_lost, 2000, &er); // 不能无限等待,而是有时间限制
if(er == OS_TIMEOUT)
{
ReSend_flag = 0;
FD810_Send((INT8U *)"E:NO RESEND REQUIRED\r\n",strlen("E:NO RESEND REQUIRED\r\n"));
}
while(ReSend_flag == 1)
{
flag_coutin = 0;
temp = lost_buffer[0]; // 防止lost_buffer[0] = 0 的情况,lost_len =0,如果不这样处理
lost_buffer[0] = 10;
lost_len = strlen ((const char *)lost_buffer);
lost_buffer[0] = temp;
for(i=0;i<lost_len;i++)
{
k = 0;
sl = 0;
module = lost_buffer[i];
read_photo[4] = lost_buffer[i];
for(j=1;j<5;j++)
sl = sl+read_photo[j];
read_photo[6] = sl;
MCF_GPIO_PORTTA = 0x08;
if(module == 25)
{
for(j=0;j<9;j++)
uart_putchar(2,read_photo25[j]);
}
else if(module == 27)
{
for(j=0;j<9;j++)
uart_putchar(2,read_photo27[j]);
}
else
{
for(j=0;j<8;j++)
uart_putchar(2,read_photo[j]);
}
for(j=0;j<3500;j++) //????????????5??????????????
;
MCF_GPIO_PORTTA = 0x00;
camera_buf[k] = uart_getchar(2);
camera_buf[k] = uart_getchar(2);
do
{
k++;
camera_buf[k] = uart_getchar(2);
}while(camera_buf[k] != 0x7E);
length1 = (k+1)/256;
length2 = (k+1)%256;
cdma_send(camera_buf,k+1);
}//end of for(;;)
OSSemPend (sem_lost, 2000, &er); //stop here wait until semphmore
if(er == OS_TIMEOUT)
{
FD810_Send((INT8U *)"C:WAIT IMG TIME OUT\r\n",strlen("C:WAIT IMG TIME OUT\r\n"));
break;
}
}//end of while()
ReSend_flag = 0;
image_num++;
OSTimeDly(1);//
}
}
void cdma_send(INT8U buffer[], int num)
{
int f;
int n1;
int n2;
int tota;
tota = num+45;
n1 = tota/256;
n2 = tota%256;
camera_bag[3] = n1; //???
camera_bag[4] = n2;
camera_bag[28] = shoot_photo_back[5]; //?????
camera_bag[29] = shoot_photo_back[6];
camera_bag[33] = total_module; //???
camera_bag[35] = image_num; //????
camera_bag[37] = module; //????
camera_bag[40] = length1;
camera_bag[41] = length2; //????
for(f=0;f<42;f++)
uart_putchar(1,camera_bag[f]);
for(f=0;f<num;f++)
uart_putchar(1,buffer[f]);
for(f=0;f<3;f++)
uart_putchar(1,last_bag[f]);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -