⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 video_oper.c

📁 在LPC2132的ARM处理器上
💻 C
📖 第 1 页 / 共 3 页
字号:
/********************************************************************************************************/

#include "config.h"

const uint8	Video_Syn[6] = {0xaa, 0x0d, 0x00, 0x00, 0x00, 0x00};		// 发射同步信息
const uint8	Video_Syn_Echo[6] = {0xaa, 0x0e, 0x0d, 0x00, 0x00, 0x00};	// 发射同步回应信息
const uint8	Video_Init[6] = {0xaa, 0x01, 0x00, 0x07, 0x07, 0x07};		// 发射初始化信息
const uint8	Video_Pack_Size[6] = {0xaa, 0x06, 0x08, 0x06, 0x01, 0x00};	// 发射包大小信息
const uint8	Video_Snap[6] = {0xaa, 0x05, 0x00, 0x00, 0x00, 0x00};		// 发射快照信息
const uint8	Video_Get_Pic[6] = {0xaa, 0x04, 0x01, 0x00, 0x00, 0x00};	// 发射获取图片信息
const uint8	Video_Echo_End[6] = {0xaa, 0x0e, 0x00, 0x00, 0xf0, 0xf0};	// 发射应答结束信息

const uint8 Start_Code[10] = "$GPRSCDMA";
const uint8 Dev_Code[12] = "13920573398";

/********************************************************************************************************/
void 	SysInit(void)
{	
	
	PINSEL2 = (PINSEL2 & 0xfffffff7);		/* 选择P1.25~P1.16为GPIO */
	
	PINSEL0 &= 0xf3ffffff;					// P0.13连接至GPIO
	IO0DIR &= ~KEY1;		    			/* 设置P0.13为输入*/
	
	PINSEL2 &= 0xfffffff7;			 		/* 设置P1.16~P1.25为基本输入输出*/
	IO1DIR &= ~KEY2;		    			/* 设置P1.22为输入*/
	IO1DIR &= ~KEY3;		    			/* 设置P1.23为输入*/
	
	PINSEL0 &= 0xff3fffff;					// P0.11连接至GPIO
	IO0DIR &= ~KEY4;		    			/* 设置P0.11为输入*/

	IODIR |= 0x80000000;			 		/* 设置P0.31为输出*/
	
	PINSEL1 &= 0xffff3fff;					// P0.23连接至GPIO
	IO0DIR |= PIC_COMU_LED;					/* 设置P0.23为输出*/
	IO0SET |= PIC_COMU_LED;					/* 设置P0.23输出为1*/
	
	PINSEL0 &= 0xffcfffff;					// P0.10连接至GPIO
	IO0DIR |= PIC_LED;						/* 设置P0.10为输出*/
	IO0SET |= PIC_LED;						/* 设置P0.10输出为1*/
	
	PINSEL1 &= 0xf3ffffff;					// P0.29连接至GPIO
	IO0DIR |= SAVECS;						/* 设置P0.29为输出*/
	IO0SET |= SAVECS;				 		/* 设置P0.29输出为1*/
	
	PINSEL1 &= 0xffffcfff;					// P0.22连接至GPIO
	IO0DIR |= CHECK_OUTPUT;					/* 设置P0.22为输出*/
	IO0SET |= CHECK_OUTPUT;				 	/* 设置P0.22输出为1*/
	
	PINSEL1 &= 0xfff3ffff;					// P0.25连接至GPIO
	IO0DIR |= CHECK_OUTPUT1;				/* 设置P0.25为输出*/
	IO0SET |= CHECK_OUTPUT1;				 /* 设置P0.25输出为1*/
		
	PINSEL1 &= 0xfcffffff;					// P0.28连接至GPIO
	IO0DIR |= AT45_RESET;					/* 设置P0.28为输出*/
	IO0SET |= AT45_RESET;				 	/* 设置P0.28输出为1*/
		
	IO1DIR |= UARTCS;						/* 设置P1.25为输出 UARTCS*/
	IO1SET |= UARTCS;				 		/* 设置P1.25输出为1*/
	
	Pic_Rev_Flag = 0x00;
	Pic_Head = NULL;						//初始化链表指针
	Pic_Tail = NULL;
	Alarm_flag = 0x00;
	Login_flag = 0x00;
	Pic_Time_flag = 0x00;
	GPS_Data_Index = 0x00;
	GPS_Data_Size = 0x00;
	
	Rev_GPS_Data.Gps_Flag = 0x00;
	GPS_Send_Index = 0x00;
	Alarm_Status = 0x00;
	
	Voice_Status = 0x00;
	
	voice_page_count = 0x0000;
    voice_index = 0x00;
    pack_count = 0x00;
}

/********************************************************************************************************/
uint8	Read_EEprom_Data(void)
{
	uint8 *buf;
	uint16 i;
	FLASH_INDEX   save_data;
	
	ReadEEROM((uint8 *)(&save_data), 0x00, sizeof(FLASH_INDEX));
	
	if ((save_data.magic_code[0] == 'G') && (save_data.magic_code[1] == 'P')
		&& (save_data.magic_code[2] == 'R') && (save_data.magic_code[3] == 'S')
		&& (save_data.magic_code[4] == 'C') && (save_data.magic_code[5] == 'D')
		&& (save_data.magic_code[6] == 'M') && (save_data.magic_code[7] == 'A')){
		
		Flash_Index_Data = save_data;
		Flash_Index_Data.flash_pic_num = 0x00;
		Flash_Index_Data.flash_free_begin_page = 1024;		// 从1024页开始存储图片
		return	SUCCESS;
	}

	OSTimeDly (OS_TICKS_PER_SEC / 50);		//延时20毫秒
	
	buf = (uint8 *)(&Flash_Index_Data);
	 
	for (i = 0x00; i < sizeof(FLASH_INDEX); i++)
		*buf++ = 0x00;
	
	Flash_Index_Data.magic_code[0] = 'G';
	Flash_Index_Data.magic_code[1] = 'P';
	Flash_Index_Data.magic_code[2] = 'R';
	Flash_Index_Data.magic_code[3] = 'S';
	Flash_Index_Data.magic_code[4] = 'C';
	Flash_Index_Data.magic_code[5] = 'D';
	Flash_Index_Data.magic_code[6] = 'M';
	Flash_Index_Data.magic_code[7] = 'A';
	
	WriteEEROM((uint8 *)(&Flash_Index_Data), 0x00, sizeof(FLASH_INDEX));
	Flash_Index_Data.flash_free_begin_page = 1024;		// 从1024页开始存储图片
		
	return	SUCCESS;  
}

/********************************************************************************************************/
void 	NodeInsert(PIC_STR *node)
{	
	uint8 err;
	
	OSSemPend(ListSem, 0, &err);

	if ((Pic_Head == NULL) && (Pic_Tail == NULL)){
		Pic_Head = node;
		Pic_Tail = Pic_Head;
		Pic_Head -> NextPoint = NULL;
	
	}else {
			
		Pic_Tail -> NextPoint = node;
		Pic_Tail = node;
		Pic_Tail -> NextPoint = NULL;
	}
	
	OSSemPost(ListSem);
}

/********************************************************************************************************/
void 	NodeDel(void)
{	
	uint8 err;
	PIC_STR	*node;
	
	OSSemPend(ListSem, 0, &err);
	
	node = Pic_Head;
	if (Pic_Head -> NextPoint == NULL)			//删除链表
		Pic_Head = Pic_Tail = NULL;
	else 	
		Pic_Head = Pic_Head -> NextPoint;	
			
	OSMemPut(Pic_Mem,(void *)node);				//释放内存
	
	OSSemPost(ListSem);
}

/********************************************************************************************************/
static uint8 Get_Ch_Pic(api_uart_write uart_write)
{
	REV_DATA 	*revData;
	PIC_STR 	*PicData;
	PIC_FLASH 	flash_buf;
	
	uint8 	err, i, pic_num, pack_num;
	uint16 	pack_res, j;
	uint8 	send_buf[6];
	
	send_buf[0] = 0xaa;
	send_buf[1] = 0x0e;
	send_buf[2] = 0x00;
	send_buf[3] = 0x00;
	send_buf[4] = 0x00;
	send_buf[5] = 0x00;
	
	for ( i = 0x00; i < 10; i++){
	
		uart_write((uint8 *)Video_Syn, 6);
	
		VideoMbox -> OSEventPtr = 0x00;
	
		revData = (REV_DATA *)OSMboxPend(VideoMbox, (OS_TICKS_PER_SEC / 10), &err);
	
		if ((err == OS_NO_ERR) 
			&& (revData -> Video_Order_Type == 0x0e)
			&& (revData -> Video_ID == 0x0d)
			&& (revData -> Mode_Type_Info == 0x0d))		// 收到回应同步信息
				break;

	}// for ( i = 0x00; i < 10; i++)
	
	if (i>= 10)
		return SYN_ERROR;
	
	OSTimeDly (OS_TICKS_PER_SEC / 5);
		
	uart_write((uint8 *)Video_Syn_Echo, 6);	

/*******************************************************************************************/	
	OSTimeDly (OS_TICKS_PER_SEC / 5);
	
	uart_write((uint8 *)Video_Init, 6);	
	
	VideoMbox -> OSEventPtr = 0x00;
	
	revData = (REV_DATA *)OSMboxPend(VideoMbox, (OS_TICKS_PER_SEC / 10), &err);
	
	if ((err != OS_NO_ERR) 
		|| (revData -> Video_Order_Type != 0x0e)
		|| (revData -> Video_ID != 0x01))				// 收到初始化回应信息
			return SYN_ERROR;

/*******************************************************************************************/	
	OSTimeDly (OS_TICKS_PER_SEC / 5);
	
	uart_write((uint8 *)Video_Pack_Size, 6);	
	
	VideoMbox -> OSEventPtr = 0x00;
	
	revData = (REV_DATA *)OSMboxPend(VideoMbox, (OS_TICKS_PER_SEC / 10), &err);
	
	if ((err != OS_NO_ERR) 
		|| (revData -> Video_Order_Type != 0x0e)
		|| (revData -> Video_ID != 0x06))				// 收包大小回应信息
			return SYN_ERROR;

/*******************************************************************************************/			
	OSTimeDly (OS_TICKS_PER_SEC / 5);
	
	uart_write((uint8 *)Video_Snap, 6);	
	
	VideoMbox -> OSEventPtr = 0x00;
	
	revData = (REV_DATA *)OSMboxPend(VideoMbox, (OS_TICKS_PER_SEC / 10), &err);
	
	if ((err != OS_NO_ERR) 
		|| (revData -> Video_Order_Type != 0x0e)
		|| (revData -> Video_ID != 0x05))				// 收快照回应信息
			return SYN_ERROR;

/*******************************************************************************************/			
	OSTimeDly (OS_TICKS_PER_SEC / 5);
	
	uart_write((uint8 *)Video_Get_Pic, 6);	
	
	VideoMbox -> OSEventPtr = 0x00;
	
	revData = (REV_DATA *)OSMboxPend(VideoMbox, (OS_TICKS_PER_SEC / 10), &err);
	
	if ((err != OS_NO_ERR) 
		|| (revData -> Video_Order_Type != 0x0e)
		|| (revData -> Video_ID != 0x04)
		|| (revData -> Mode_Type_Info != 0x0a))			// 收获取图片回应信息
			return SYN_ERROR;
			
	pack_num = revData -> Pic_Size / PACK_SIZE;
	
	pack_res = revData -> Pic_Size % PACK_SIZE;
	
	if (pack_res != 0x0000)
		pack_num += 0x01;
	
	Pic_Rev_Flag = 0x01;
	
	OSTimeDly (OS_TICKS_PER_SEC / 5);
	
	pic_num = Flash_Index_Data.flash_pic_num;
	Flash_Index_Data.pic_str_arry[pic_num].pic_flash_begin_page	= Flash_Index_Data.flash_free_begin_page;
	
	Flash_Index_Data.flash_pic_num += 0x01;
	
	for ( i = 0x00; i < pack_num; i++){
		
		send_buf[4] = i;
		Pic_Index = i;
		uart_write(send_buf, 6);	
		
		VideoMbox -> OSEventPtr = 0x00;
		
		PicData = (PIC_STR *)OSMboxPend(VideoMbox, (OS_TICKS_PER_SEC / 10), &err);
		
		if ((err != OS_NO_ERR) 
		|| (PicData -> pic_index != Pic_Index)){
		
			uart_write((uint8 *)Video_Echo_End, 6);	
			Pic_Rev_Flag = 0x00;
			Flash_Index_Data.flash_pic_num -= 0x01;
			return PACK_ERROR;
		}
		
		PicData -> package_num = pack_num;
				
		flash_buf.pic_index = Flash_Index_Data.flash_pic_num;
		flash_buf.package_num = pack_num;
		flash_buf.package_index = Pic_Index;
		flash_buf.pic_size = PicData -> pic_size;
		flash_buf.rev_data_buf[0] = 0x00;
		flash_buf.rev_data_buf[1] = 0x00;
		flash_buf.rev_data_buf[2] = 0x00;
		
		for (j = 0x00; j < SAVE_SIZE; j++)
			flash_buf.pic_buf[j] = PicData -> pic_buf[j];
		
		Write_Flash_Page((uint8 *)&flash_buf, Flash_Index_Data.flash_free_begin_page++);
			
	}
	
	Flash_Index_Data.pic_str_arry[pic_num].pic_flash_end_page = Flash_Index_Data.flash_free_begin_page - 0x01;
	
/*******************************************************************************************/
	uart_write((uint8 *)Video_Echo_End, 6);	
	
	IOCLR |= PIC_LED;					/* 设置P0.3输出为0 D21 亮*/		
	OSTimeDly (OS_TICKS_PER_SEC);		// 延时1秒
	IO0SET |= PIC_LED;					/* 设置P0.3输出为1 D21 灭*/

	Pic_Rev_Flag = 0x00;						
	return SUCCESS;
	
}

/********************************************************************************************************/
uint8 Send_Get_Pic_Order(void)
{	
	uint8	value;

   value = Get_Ch_Pic(UART2Write);	
   
   return value;			
}

/********************************************************************************************************/
void SendPicData(PIC_STR *list_p, uint8 order, uint8 flag)
{
	uint16 temp, i;
	uint8  type, index, num, check_code = 0x00;
	
	index = list_p -> pic_index;
	temp = list_p -> pic_size;			
	type = list_p -> pic_type;
	num = list_p -> package_num;
	
	for (i = 0x0000; i < 9; i++)
		check_code ^= Start_Code[i];
	
	check_code ^= order;
	
	for (i = 0x0000; i < 6; i++)
		check_code ^= Flash_Index_Data.dev_code[i];
	
	check_code ^= ',';
		
	for (i = 0x0000; i < 11; i++)
		check_code ^= Flash_Index_Data.local_tel_num[i];
	
	check_code ^= ',';	
	
	for (i = 0x0000; i < 8; i++)
		check_code ^= Flash_Index_Data.tag_num[i];	
		
	check_code ^= Flash_Index_Data.mode_type;
	check_code ^= type;	
	check_code ^= num;
	check_code ^= index;
	check_code ^= (uint8)temp;
	check_code ^= (uint8)(temp >> 8);
	
	for (i = 0x0000; i < list_p -> pic_size; i++)
		check_code ^= list_p -> pic_buf[i];
	
	UART0Write((uint8 *)Start_Code, 9);		//引导码 9 bytes
	
	UART0Putch(order);						//命令码 1 byte   
	
	UART0Write((uint8 *)(&Flash_Index_Data.dev_code[0]), 6);		//设备编码 6 bytes
		
	UART0Putch(',');
		
	UART0Write((uint8 *)(&Flash_Index_Data.local_tel_num[0]), 11);	//本机电话号 11 bytes
		
	UART0Putch(',');
		
	UART0Write((uint8 *)(&Flash_Index_Data.tag_num[0]), 8);			//车牌号 8 bytes
	
	UART0Putch(Flash_Index_Data.mode_type);	//模块类型
	
	UART0Putch(type);						//摄像头号 0x01 表示一号摄像头
	
	UART0Putch(num);						//数据包数量

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -