📄 main.c
字号:
psp->enc_ch[ii].sensor.flag_out_duration= get_nvram_para( offsetof(SETUP_PARAM, enc_ch[ii].sensor.flag_out_duration), sizeof(psp->enc_ch[ii].sensor.flag_out_duration) ); /* SCHEDULE FLAG : '0' OFF, '1' ON, default is '0' */ psp->enc_ch[ii].schedule.flag = get_nvram_para( offsetof(SETUP_PARAM, enc_ch[ii].schedule.flag), sizeof(psp->enc_ch[ii].schedule.flag) ); /* SCHEDULE TIME : from->2005-01-01 00:00, to->2005-01-01 00:00 */ for (kk = 0; kk < MAX_DAY_OF_WEEK; kk ++) { psp->enc_ch[ii].schedule.from_time[kk].tm_year = get_nvram_para( offsetof(SETUP_PARAM, enc_ch[ii].schedule.from_time[kk].tm_year), sizeof(psp->enc_ch[ii].schedule.from_time[kk].tm_year) ); psp->enc_ch[ii].schedule.from_time[kk].tm_mon = get_nvram_para( offsetof(SETUP_PARAM, enc_ch[ii].schedule.from_time[kk].tm_mon), sizeof(psp->enc_ch[ii].schedule.from_time[kk].tm_mon) ); psp->enc_ch[ii].schedule.from_time[kk].tm_mday = get_nvram_para( offsetof(SETUP_PARAM, enc_ch[ii].schedule.from_time[kk].tm_mday), sizeof(psp->enc_ch[ii].schedule.from_time[kk].tm_mday) ); psp->enc_ch[ii].schedule.from_time[kk].tm_hour = get_nvram_para( offsetof(SETUP_PARAM, enc_ch[ii].schedule.from_time[kk].tm_hour), sizeof(psp->enc_ch[ii].schedule.from_time[kk].tm_hour) ); psp->enc_ch[ii].schedule.from_time[kk].tm_min = get_nvram_para( offsetof(SETUP_PARAM, enc_ch[ii].schedule.from_time[kk].tm_min), sizeof(psp->enc_ch[ii].schedule.from_time[kk].tm_min) ); psp->enc_ch[ii].schedule.from_time[kk].tm_sec = get_nvram_para( offsetof(SETUP_PARAM, enc_ch[ii].schedule.from_time[kk].tm_sec), sizeof(psp->enc_ch[ii].schedule.from_time[kk].tm_sec) ); psp->enc_ch[ii].schedule.to_time[kk].tm_year = get_nvram_para( offsetof(SETUP_PARAM, enc_ch[ii].schedule.to_time[kk].tm_year), sizeof(psp->enc_ch[ii].schedule.to_time[kk].tm_year) ); psp->enc_ch[ii].schedule.to_time[kk].tm_mon = get_nvram_para( offsetof(SETUP_PARAM, enc_ch[ii].schedule.to_time[kk].tm_mon), sizeof(psp->enc_ch[ii].schedule.to_time[kk].tm_mon) ); psp->enc_ch[ii].schedule.to_time[kk].tm_mday = get_nvram_para( offsetof(SETUP_PARAM, enc_ch[ii].schedule.to_time[kk].tm_mday), sizeof(psp->enc_ch[ii].schedule.to_time[kk].tm_mday) ); psp->enc_ch[ii].schedule.to_time[kk].tm_hour = get_nvram_para( offsetof(SETUP_PARAM, enc_ch[ii].schedule.to_time[kk].tm_hour), sizeof(psp->enc_ch[ii].schedule.to_time[kk].tm_hour) ); psp->enc_ch[ii].schedule.to_time[kk].tm_min = get_nvram_para( offsetof(SETUP_PARAM, enc_ch[ii].schedule.to_time[kk].tm_min), sizeof(psp->enc_ch[ii].schedule.to_time[kk].tm_min) ); psp->enc_ch[ii].schedule.to_time[kk].tm_sec = get_nvram_para( offsetof(SETUP_PARAM, enc_ch[ii].schedule.to_time[kk].tm_sec), sizeof(psp->enc_ch[ii].schedule.to_time[kk].tm_sec) ); } }// pentamicro 2006.01.11 /* load encoding type ( 0=JPEG, 1=MPEG1, 2=MPEG2, 3=H.263, 4=MPEG4 ) */ psp->enc_attr.encoding_type = get_nvram_para( offsetof(SETUP_PARAM, enc_attr.encoding_type), sizeof(psp->enc_attr.encoding_type) ); /* load for water marker attribute */ psp->enc_attr.wm.flag_wm = get_nvram_para( offsetof(SETUP_PARAM, enc_attr.wm.flag_wm), sizeof(psp->enc_attr.wm.flag_wm) ); psp->enc_attr.wm.strength = get_nvram_para( offsetof(SETUP_PARAM, enc_attr.wm.strength), sizeof(psp->enc_attr.wm.strength) ); psp->enc_attr.wm.key = get_nvram_para( offsetof(SETUP_PARAM, enc_attr.wm.key), sizeof(psp->enc_attr.wm.key) ); /* * DECODER PARAMETER */ /* play_conti : '0' single file play, '1' continuous file play */#if 1//xchannel psp->dec.play_conti = 1;#else//org psp->dec.play_conti = get_nvram_para( offsetof(SETUP_PARAM, dec.play_conti), sizeof(psp->dec.play_conti) ); #endif /* * SYSTEM PARAMETER */ /* network ip configuration : default 192.168.1.100 */ psp->sys.network.ipaddr = get_nvram_para( offsetof(SETUP_PARAM, sys.network.ipaddr), sizeof(psp->sys.network.ipaddr) ); /* network netmask configuration : default 255.255.255.0 */ psp->sys.network.netmask = get_nvram_para( offsetof(SETUP_PARAM, sys.network.netmask), sizeof(psp->sys.network.netmask) ); /* network gateway configuration : default 192.168.1.1 */ psp->sys.network.gateway = get_nvram_para( offsetof(SETUP_PARAM, sys.network.gateway), sizeof(psp->sys.network.gateway) ); /* password configuration : default 0000 */ for (ii = 0; ii < USER_NUM; ii ++) { psp->sys.password[ii].id = get_nvram_para( offsetof(SETUP_PARAM, sys.password[ii].id), sizeof(psp->sys.password[ii].id) ); psp->sys.password[ii].value = get_nvram_para( offsetof(SETUP_PARAM, sys.password[ii].value), sizeof(psp->sys.password[ii].value) ); } /* hdd management configuration : default 10 min( cut time ) */ psp->sys.disk.slice_time = get_nvram_para( offsetof(SETUP_PARAM, sys.disk.slice_time), sizeof(psp->sys.disk.slice_time) ); /* hdd management configuration : default overwrite true ( continuous save ) */ psp->sys.disk.over_wt_flag = get_nvram_para( offsetof(SETUP_PARAM, sys.disk.over_wt_flag), sizeof(psp->sys.disk.over_wt_flag) ); if(psp->sys.disk.over_wt_flag) gp_state_thread->state_diskm.state = ENOUGH; /* camera configuration : default brightness=0, contrast=0, hue=0, sharpness=0 */ for (ii = 0; ii < MAX_CH_NUM; ii ++) { psp->sys.camera[ii].brightness = get_nvram_para( offsetof(SETUP_PARAM, sys.camera[ii].brightness), sizeof(psp->sys.camera[ii].brightness) ); tw2834_write_reg(TW2834_PAGE0, 0x12 + 0x40 * ii, (UNS8)(psp->sys.camera[ii].brightness+128)); // brightness psp->sys.camera[ii].contrast = get_nvram_para( offsetof(SETUP_PARAM, sys.camera[ii].contrast), sizeof(psp->sys.camera[ii].contrast) ); tw2834_write_reg(TW2834_PAGE0, 0x11 + 0x40 * ii, (UNS8)(psp->sys.camera[ii].contrast+128)); // contrast psp->sys.camera[ii].color = get_nvram_para( offsetof(SETUP_PARAM, sys.camera[ii].color), sizeof(psp->sys.camera[ii].color) ); tw2834_write_reg(TW2834_PAGE0, 0x0f + 0x40 * ii, (UNS8)(psp->sys.camera[ii].color+128)); // color } /* ptz configuration : default cam_vendor=scc--641, cam_speed=2, cam_ch=1 */ psp->sys.ptz.cam_vendor = get_nvram_para( offsetof(SETUP_PARAM, sys.ptz.cam_vendor), sizeof(psp->sys.ptz.cam_vendor) ); psp->sys.ptz.cam_speed = get_nvram_para( offsetof(SETUP_PARAM, sys.ptz.cam_speed), sizeof(psp->sys.ptz.cam_speed) ); psp->sys.ptz.cam_ch = get_nvram_para( offsetof(SETUP_PARAM, sys.ptz.cam_ch), sizeof(psp->sys.ptz.cam_ch) ); return SUCCESS;}#if 0//org codeRETURN set_sys_network(SETUP_PARAM *psp){ UNS8 ip[12]; UNS8 netmask[12]; UNS8 gateway[12]; UNS16 value_u16; S8 str_net[80]; S8 str_ip[20]; S8 str_netmask[20]; S8 str_gw[20];#if 1//test printf("\n set network\n");#endif strcpy(str_net, "ifconfig eth0 "); /* network ip configuration : default 192.168.1.100 */#if 1//big endian sprintf(str_ip, "%ld.%ld.%ld.%ld ",(psp->sys.network.ipaddr>>24)&0xff,(psp->sys.network.ipaddr>>16)&0xff,(psp->sys.network.ipaddr>>8)&0xff, (psp->sys.network.ipaddr&0xff));#else//little endian sprintf(str_ip, "%ld.%ld.%ld.%ld ",(psp->sys.network.ipaddr&0xff),(psp->sys.network.ipaddr>>8)&0xff,(psp->sys.network.ipaddr>>16)&0xff,(psp->sys.network.ipaddr>>24)&0xff);#endif strcat(str_net, str_ip); /* network netmask configuration : default 255.255.255.0 */#if 1//big endian sprintf(str_ip, "netmask %ld.%ld.%ld.%ld",(psp->sys.network.netmask>>24)&0xff,(psp->sys.network.netmask>>16)&0xff,(psp->sys.network.netmask>>8)&0xff, (psp->sys.network.netmask&0xff));#else//litile endian sprintf(str_ip, "netmask %ld.%ld.%ld.%ld",(psp->sys.network.netmask&0xff),(psp->sys.network.netmask>>8)&0xff,(psp->sys.network.netmask>>16)&0xff,(psp->sys.network.netmask>>24)&0xff);#endif strcat(str_net, str_ip); if (system(str_net) != 0) { m_ERROR("main.c:error: In function 'system'\n"); } strcpy(str_net, "route "); strcat(str_net, "add default gw "); /* network gateway configuration : default 192.168.1.1 */#if 1//big endian sprintf(str_ip, "%ld.%ld.%ld.%ld",(psp->sys.network.gateway>>24)&0xff, (psp->sys.network.gateway>>16)&0xff, (psp->sys.network.gateway>>8)&0xff, (psp->sys.network.gateway&0xff));#else//little endian sprintf(str_ip, "%ld.%ld.%ld.%ld",(psp->sys.network.gateway&0xff),(psp->sys.network.gateway>>8)&0xff,(psp->sys.network.gateway>>16)&0xff,(psp->sys.network.gateway>>24)&0xff);#endif strcat(str_net, str_ip); if (system(str_net) != 0) { m_ERROR("main.c:error: In function 'system'\n"); } printf("\n"); return SUCCESS; }#endifS32 db_record_count(void) { UNS8 db_name[32]; UNS32 i, file_size=0; FILE *fd; STATE_DB *psdb; psdb = &gp_state_thread->state_db; /* LOCK "SUB DB" file */ sem_wait(&psdb->search_sem); for(i=0; i < MAX_DISK_NUM; i++) { SUB_SEARCH_DB(&db_name, i); if ( !(fd = fopen(db_name, "rb")) ) {// m_MSG("DISK HDD%c, NO DB FILE\n", 'A' + i); continue; } fseek(fd, 0, SEEK_END); file_size += ftell(fd); fclose(fd); /* sub db file verify */ if(file_size%sizeof(DB_RECORD)) { m_ERROR("\nWarnning: Invalid DB Format !!= %s\n", db_name); /* UNLOCK "SUB DB" file */ sem_post(&psdb->search_sem); return 0; } } /* UNLOCK "SUB DB" file */ sem_post(&psdb->search_sem); return (file_size / sizeof(DB_RECORD));}/* recreation for main db */RETURN recreate_main_db(UNS32 all_record_cnt) { UNS32 i, idx=0, count=0; UNS8 temp_str1[32], temp_str2[32], disk_id; FILE *fd_maindb, *fd_subdb; DB_RECORD dr; UNS8 sort_table[all_record_cnt][MAX_FILENAME_SIZE]; STATE_DB *psdb; static BOOL first_find_disk = FALSE; psdb = &gp_state_thread->state_db; /* initializing sort_table */ for(i=0;i < all_record_cnt;i++) memset(sort_table[i], 0x00, sizeof(MAX_FILENAME_SIZE)); /* LOCK "ALL DB" file */ sem_wait(&psdb->search_sem); /* From inside the DB_RECORD which lines up only filename extraction */ for(i=0;i < MAX_DISK_NUM;i++) { SUB_SEARCH_DB(&temp_str1, i); if ( fd_subdb=fopen(temp_str1, "rb") ) { /* In the disk which it searches in the first, main db creation */ if(!first_find_disk) { sprintf(MAIN_DB_NAME, "/hdd%c/main_search.db", 'a'+i); sprintf(TEMP_DB_NAME, "/hdd%c/temp_search.db", 'a'+i); first_find_disk = TRUE; } /* get struct(DB_RECORD) Info */ while(fread(&dr, sizeof(S8), sizeof(DB_RECORD), fd_subdb) > 0) { memset(temp_str1, 0x00, sizeof(temp_str1)); /* disk location information string addition for alignment. ex) 20050310_100000_nCm.ps -> 20050310_100000a_nCm.ps */ strncpy(temp_str1, dr.fname, 15); sprintf(temp_str1+15, "%c", 'a'+i); strncat(temp_str1+16, dr.fname+15, 7); strncpy(sort_table[idx++], temp_str1, strlen(temp_str1)); } fclose(fd_subdb); } } /* quick sorting */ qsort(sort_table, all_record_cnt, MAX_FILENAME_SIZE, compare); /* warnning : It has a stream filename and the sort it does. When it is like that and the stream filename type is changed, also the correspondence code must be exchanged. */ /* When the program starts, it creates always. */ if ( !(fd_maindb = fopen(MAIN_DB_NAME, "wb")) ) { m_ERROR("main.c:error In function 'fopen'\n"); return FAILURE; } idx = 0; /* The main DB creation which becomes the sorted */ while(idx < all_record_cnt) { /* get disk location string */ disk_id = *(sort_table[idx]+15); /* zero base : 0==HDDA, 1==HDDB, 2==HDDC, 3==HDDD */ disk_id -= 'a'; memset(temp_str1, 0x00, sizeof(temp_str1)); /* source stream file name restoring */ strncpy(temp_str1, sort_table[idx], 15); strncpy(temp_str1+15, sort_table[idx]+16, 7); SUB_SEARCH_DB(&temp_str2, disk_id); if ( fd_subdb = fopen(temp_str2, "rb") ) { /* get sub db struct Info*/ while(fread(&dr, sizeof(S8), sizeof(DB_RECORD), fd_subdb) > 0) { if (!strncmp(temp_str1, dr.fname, 22)) { /* When with sub db filename being same in the list which becomes the sorted */ GET_DIR_NAME(&temp_str2, disk_id); /* With the absolute path together store (in only main DB) */ strncat(temp_str2, dr.fname, strlen(dr.fname)); strncpy(dr.fname, temp_str2, strlen(temp_str2)); /* The update for record file pointer */ if(count <= 1) dr.prev_db_fp = 0; else dr.prev_db_fp = (count-1) * sizeof(DB_RECORD); dr.next_db_fp = (count+1) * sizeof(DB_RECORD);#ifndef LOOPTHROUGH_MODE fwrite(&dr, sizeof(DB_RECORD), sizeof(S8), fd_maindb);#endif count++; break; } } fclose(fd_subdb); } idx++; } fclose(fd_maindb); /* UNLOCK "ALL DB" file */ sem_post(&psdb->search_sem); return SUCCESS;}/* for qsort() funtion */S32 compare(const void *a, const void *b){ return strcmp((char *)a, (char *)b);}void appversionprint(void){ UNS32 version = MPEG4_MAGICNUM;#if 1/* big endian code */ m_MSG("\n\n\t!!! SDVR LC Version %d.%d.%d !!!\n\n", (version>>16)&0xff, (version>>8)&0xff, version&0xff);#else/* little endian code */ m_MSG("\n\n\t!!! SDVR LC Version %d.%d.%d !!!\n\n", version&0xff, (version>>8)&0xff, (version>>16)&0xff);#endif}#if 0//org codevoid set_timesync(void){ struct tm cur_time; struct timeval tv = { 0L, 0L }; get_cur_time(&cur_time); cur_time.tm_year -= 1900; cur_time.tm_mon -= 1; tv.tv_sec = mktime(&cur_time); settimeofday(&tv, NULL);}#endifvoid tw2834_motion_mask_set(SETUP_PARAM *psp){ UNS32 ii, jj, kk, x, y; UNS32 x_start; UNS32 y_start; for(ii=0; ii < MAX_CH_NUM; ii++) { for(jj=0; jj < (MB_X_NUM * MB_Y_NUM); jj++) { for(kk=0; kk < MAX_CH_NUM; kk++) { if(psp->gp.resolution == D1) { /* size(2X2 bitmap block) for D1 */ x_start = jj%MB_X_NUM*MB_2X2_SIZE; y_start = jj/MB_X_NUM*MB_2X2_SIZE; } else { /* size(1X1 bitmap block) for CIF */ x_start = jj%MB_X_NUM; y_start = jj/MB_X_NUM; } if(psp->enc_ch[ii].motion.area[y_start] & (1 << x_start)) { /* update motion table for display area(TW2834) */ tw2834_cursor_select(ii, jj%MB_X_NUM, jj/MB_X_NUM, YELLOW, TRUE); } } } }}// pentamicro 2006.01.11void set_video_vertical_offset(VIDEO_MODE mode){ switch(mode) { case NTSC: /* default is NTSC */ break; case PAL: /* This is valid only if input video sync mode = 0 * mode : '0' don't care the vertical offset value * '1' use the verical offset value * default is 1 */ enc_vertical_offset_mode(1); /* voff_e : vertical offset for even field from FSYNC, default is 22 * voff_o : vertical offset for odd field from FSYNC, default is 21 */ enc_vertical_offset(24, 23); /* format : '0' NTSC, '1' PAL, default is '0' */ output_video_format(PAL); break; } }/* end of main.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -