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

📄 main.c

📁 1、基于韩国at2041芯片开发的Linux环境的DVR代码。 2、以原来代码进行了修改。 3、主要修改网络通讯出现异常问题处理 4、硬盘覆盖录像不起作用
💻 C
📖 第 1 页 / 共 3 页
字号:
/* set tabstop=4 *//******************************************************************************** *                                                                              * * Copyright(C) 2004  Penta-Micro                                               * *                                                                              * * ALL RIGHT RESERVED                                                           * *                                                                              * * This software is the property of Penta-Micro and is furnished under          * * license by Penta-Micro. This software may be used only in accordance         *	 * with the terms of said license. This copyright notice may not be             * * removed, modified or obliterated without the prior written permission        * * of Penta-Micro.                                                              * *                                                                              * * This software may not be copyed, transmitted, provided to or otherwise       * * made available to any other person, company, corporation	or other entity     * * except as specified in the terms of said license.                            * *                                                                              * * No right, title, ownership or other interest in the software is hereby       * * granted or transferred.                                                      * *                                                                              * * The information contained herein is subject to change without notice and     * * should not be construed as a commitment by Penta-Micro.                      * *                                                                              * ********************************************************************************   MODULE NAME:  MAIN.C    REVISION HISTORY:    Date       Ver Name                  Description  ---------- --- --------------------- -----------------------------------------  06/28/2004 2.0 CheulBeck(whitefe)       Created     07/20/2005 2.1 JiGwanKang(xchannel)  Modified    ...............................................................................   DESCRIPTION:    This Module contains MAIN function.   ...............................................................................*/   /** ************************************************************************* **  ** includes ** ************************************************************************* **/#include <ctype.h>#include <dirent.h>#include <fcntl.h>#include <pthread.h>#include <stddef.h>      // offsetof()#include <stdlib.h>#include <stdio.h>#include <string.h>#include <sys/ipc.h>#include <sys/stat.h>#include <sys/types.h>#include <errno.h> /* for error num */#include "main.h"/** ************************************************************************* **  ** defines ** ************************************************************************* **/#define m_DEBUG(format, args...)  printf(format, ## args);fflush(stdout); //#define m_DEBUG(format, args...)  #define m_MSG(format, args...)      printf(format, ## args);fflush(stdout); #define m_ERROR(format, args...)  printf(format, ## args);fflush(stdout);/** ************************************************************************* **  ** typedefs ** ************************************************************************* **/	 /** ************************************************************************* **  ** globals ** ************************************************************************* **/PTHREAD_STATE		*gp_state_thread;SETUP_PARAM			*gp_setup_param;/* file name for search DB */UNS8 MAIN_DB_NAME[32] = "/hdda/main_search.db";UNS8 TEMP_DB_NAME[32] = "/hdda/temp_search.db";UNS32 gv_cur_disk_id = 0; /* 0==hdda, 1=hddb, 2=hddc, 3=hddd */  /** ************************************************************************* **  ** locals ** ************************************************************************* **//** ************************************************************************* **  ** forward declarations ** ************************************************************************* **/ S32 main(S32 argc, S8 **argv){	BOOL			quit_main = FALSE;	UNS16			input_value = 0;	PTHREAD_BUF	signal;	MAIN_LOC		present_location = MAIN_LIVE;		PTHREAD_ID	prev_id;      S32                   record_cnt;	extern S32         errno;      appversionprint();	/* at2041 device open */		at2041_open();	/* ppc405 gpio open */	ppc405_gpio_open();	/* at2041 boot image loading */	at2041_load_image();			/* tw2834 device open */		tw2834_open(); 	/* nvram&rtc device open */	fm31xxx_open();	/* set for current time sync */	time_sync();	/* 2nd. allocate thread state structure object */	if ( !(gp_state_thread = (PTHREAD_STATE *) malloc (sizeof(PTHREAD_STATE))) ) {		m_ERROR("main.c:error In function 'malloc'\n");		return FAILURE;			}	memset(gp_state_thread, 0x00, sizeof(PTHREAD_STATE));	/* check NTSC/PAL */	gp_state_thread->state_main.mode = get_video_mode();// pentamicro 2006.01.11		/* encoding video vertical offset */	set_video_vertical_offset(gp_state_thread->state_main.mode);	/* tw2834 initialize and font upload */		tw2834_initialize(&gp_state_thread->state_main.mode);	/* for motion block */	if(gp_state_thread->state_main.mode == NTSC)		MB_Y_NUM = 8;	else		MB_Y_NUM = 9;	gp_state_thread->state_main.state = IDLE;	gp_state_thread->state_enc.state = IDLE;		gp_state_thread->state_dec.state = IDLE;	/* search db semaphore init : value 1 */	sem_init(&gp_state_thread->state_db.search_sem, 0, 1);		/* 3rd. allocate setup parameter structure object */	if ( !(gp_setup_param = (SETUP_PARAM *) malloc (sizeof(SETUP_PARAM))) ) {		m_ERROR("main.c:error In function 'malloc'\n");		return FAILURE;			}	memset(gp_setup_param, 0x00, sizeof(SETUP_PARAM));		/* 4th. check magic number and set default parameter value to NVRAM */	if ( nvram_check_magic_num(gp_setup_param) == FAILURE ) {		m_ERROR("main.c:error In function 'nvram_check_magic_num'\n");		return FAILURE;			}	#ifdef NVRAM_TEST		/* 5th. load setup parameter value from NVRAM */	if ( nvram_load_setup_value(gp_setup_param) == FAILURE ) {		m_ERROR("main.c:error In function 'nvram_load_setup_value'\n");		return FAILURE;			}#endif		/* tw2834 motion mask init */	tw2834_motion_mask_set(gp_setup_param);      /* all db record count */      record_cnt = db_record_count();	/* 6th. create main db  file (always)*/      if(record_cnt)      	recreate_main_db(record_cnt);	/* 7th. create manager thread : able to check thread state */	if (pthread_create_manager() == FALSE) {		m_ERROR("main.c:error: In function 'pthread_create_input'\n");	} 	/* 8th. create input thread : able to receive input */	if (pthread_create_input() == FALSE) {		m_ERROR("main.c:error: In function 'pthread_create_input'\n");	} 		/* 9th. create live thread : able to monitor live */	if (pthread_create_live() == FALSE) {		m_ERROR("main.c:error: In functi on 'pthread_create_live'\n");	} 		/* 10th. create diskm thread : able to manage disk */	if (pthread_create_diskm() == FALSE) {		m_ERROR("main.c:error: In function 'pthread_create_diskm'\n");	}	/* 11th. create schedule thread : able to record timely */	if (pthread_create_schedule() == FALSE) {		m_ERROR("main.c:error: In function 'pthread_create_schedule'\n");	} 	#ifdef __TRANS_THR__	/* 12th. create trans thread : able to manage disk */	if (pthread_create_trans() == FALSE) {		m_ERROR("main.c:error: In function 'pthread_create_trans'\n");	} 		#endif	/*__TRANS_THR__*/ 	/* 13th. create gpio thread : able to gpio read/write */	if (pthread_create_gpio() == FALSE) {		m_ERROR("main.c:error: In function 'pthread_create_gpio'\n");	} #if 0//org code	/* 14th. create mouse thread : able to mouse support */	if (pthread_create_mouse() == FALSE) {		m_ERROR("main.c:error: In function 'pthread_create_mouse'\n");	} #endif//test code#if 1//for portingsignal.m_value = 0xFF;#endif	while (!quit_main) {		pthread_read_signal(&signal, PTHREAD_MAIN, TRUE); 		m_DEBUG("\tsignal>[main][id:%02d][value:0x%04x]\n", signal.start_id, signal.m_value);		/* check start id : pass only input thread */		if (signal.start_id != PTHREAD_INPUT) {			m_ERROR("main.c:error: Received Invalid Signal ID\n");		}		// swpark#if 0		/* quit main program */		if (signal.m_value == POWER) {			quit_main = TRUE;			m_DEBUG(" !!! PRESS POWER OFF BUTTON !!! \n");			break;		}#endif				/* receive input value */		input_value = signal.m_value;		/* check state : decision for input path */		if (gp_state_thread->state_main.state == IDLE) {			switch (input_value) {				case SETUP :					gp_state_thread->state_main.state = BUSY;										if (pthread_create_setup() == FALSE) {						m_ERROR("main.c:error: In function 'pthread_create_setup'\n");					} 					present_location = MAIN_SETUP;					break;				case REC :						/* display REC monitoring */					prev_id = signal.start_id;								signal.start_id = PTHREAD_MAIN;					if (pthread_send_signal(&signal, PTHREAD_MANAGER) == FALSE) {						m_ERROR("main.c:error: In function 'pthread_send_signal'\n");					} 					signal.start_id = prev_id;					present_location = MAIN_IDLE;						break;					case SEARCH :					gp_state_thread->state_main.state = BUSY;											if (pthread_create_search() == FALSE) {						m_ERROR("main.c:error: In function 'pthread_create_search'\n");					} 										present_location = MAIN_SEARCH;							break;			    case PTZ_CONTROL: /* Pan/Tilt/Zoom Control */					gp_state_thread->state_main.state = BUSY;											/* create ptz thread : able to ptz control */					if (pthread_create_ptz() == FALSE) {						m_ERROR("main.c:error: In function pthread_create_ptz'\n");					} 									present_location = MAIN_PTZ;					break;				default :					present_location = MAIN_LIVE;					break;			}		}		/* proceed next sequence */		else if (gp_state_thread->state_main.state == BUSY) {			switch (present_location) {				case MAIN_SETUP :									if (pthread_send_signal(&signal, PTHREAD_SETUP) == FALSE) {						m_ERROR("main.c:error: In function 'pthread_send_signal'\n");					}					break;				case MAIN_SEARCH :						if (pthread_send_signal(&signal, PTHREAD_SEARCH) == FALSE) {						m_ERROR("main.c:error: In function 'pthread_send_signal'\n");					}										break;			    case MAIN_PTZ :	/* Pan/Tilt/Zoom Control */					if (pthread_send_signal(&signal, PTHREAD_PTZ) == FALSE) {						m_ERROR("main.c:error: In function 'pthread_send_signal'\n");					}										break;				default :					break;								}		}		/* proceed last input */		if (present_location == MAIN_LIVE || gp_state_thread->state_dec.state != IDLE) {			signal.start_id = PTHREAD_INPUT;			if (pthread_send_signal(&signal, PTHREAD_LIVE) == FALSE) {				m_ERROR("main.c:error: In function 'pthread_send_signal'\n");			}				} 	} /* end of while (!QUIT_SDVR_MAIN) */	    if (gp_state_thread->state_enc.state == BUSY) {        gp_state_thread->state_enc.state = IDLE;        usleep(300000);    }	/* hw reset at2041 */#if 1//for porting		ppc405_gpio_at2041_reset();#endif	sleep(1);		m_DEBUG("\n");	m_DEBUG("Closing device...");	/* close devices */	at2041_close();	tw2834_close();	fm31xxx_close();		ppc405_gpio_close();	if(sem_destroy(&gp_state_thread->state_db.search_sem)) {		if(errno == EBUSY)			perror("semaphore err");	}	/* free malloc buffer */	free(gp_state_thread);	free(gp_setup_param);	      m_DEBUG("Ok\n\n");    

⌨️ 快捷键说明

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