diff --git a/gynet b/gynet index 74bd501..6464c36 100644 Binary files a/gynet and b/gynet differ diff --git a/libdarknet.a b/libdarknet.a index 6b6f748..8bc0255 100644 Binary files a/libdarknet.a and b/libdarknet.a differ diff --git a/obj/detector.o b/obj/detector.o index a33bdd9..83ede71 100644 Binary files a/obj/detector.o and b/obj/detector.o differ diff --git a/obj/nweb.o b/obj/nweb.o index 8595f22..7d71c66 100644 Binary files a/obj/nweb.o and b/obj/nweb.o differ diff --git a/src/detector.c b/src/detector.c index dc42137..1407ac6 100644 --- a/src/detector.c +++ b/src/detector.c @@ -21225,7 +21225,11 @@ int reload_dataset_from_jsonfile(void) strcpy(SystemSetting.enable_python, enable_python->valuestring); enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); - strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); + if (enable_python_file) + { + strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); + } + enable_low_cpu_usage = cJSON_GetObjectItem(system_setting, "enable_low_cpu_usage"); strcpy(SystemSetting.enable_low_cpu_usage, enable_low_cpu_usage->valuestring); @@ -22345,6 +22349,7 @@ void stop_server() pthread_mutex_destroy(&mutex_remotesnap_image); // Ken 2022-09-26 pthread_mutex_destroy(&mutex_radar_json); pthread_mutex_destroy(&mutex_tof_json); + pthread_mutex_destroy(&mutex_buffer); #endif pthread_mutex_destroy(&mutex_get_image); pthread_mutex_destroy(&mutex_get_image_HD); @@ -22468,7 +22473,6 @@ void write_to_enable_tracking(char *enable_tracking) { cJSON_ReplaceItemInObject(camera01, "ptz_enable_tracking", cJSON_CreateString(enable_tracking)); - char* JsonString = cJSON_Print(root); FILE *fp; @@ -22643,20 +22647,20 @@ void *start_run_python_thread(void* pythonpath) { while (python_check_webstatus == 0) { - // python_check_webstatus = 0 網頁關閉 - // python_check_webstatus = 1 網頁開啟 + // python_check_webstatus = 0 Web close + // python_check_webstatus = 1 Web open printf("[start_run_python_thread] Wait Web server run... %d \n", python_check_webstatus); continue; } // printf("[start_run_python_thread] Wait Web server run... %d \n", python_check_webstatus); - sleep(15); // 暫停 15 秒,等待 Web thread 開啟 + sleep(15); // sleep 15 sec,wait Web thread open if (value == NULL) { printf("Failed to retrieve enable_python_file value\n"); pthread_exit(NULL); } // 抓取 python 檔案 if (strstr(value, ".py") != NULL) { - printf("enable_python_file is a Python file: %s\n", value); + // printf("enable_python_file is a Python file: %s\n", value); const char *prefix = "lifile_liname="; char pythonfile[256]; snprintf(pythonfile, sizeof(pythonfile), "%s%s", prefix, value); @@ -22911,6 +22915,8 @@ void run_server(int argc, char **argv) pthread_mutex_init(&mutex_remotesnap_image, NULL); // Ken 2022-09-26 pthread_mutex_init(&mutex_radar_json, NULL); pthread_mutex_init(&mutex_tof_json, NULL); + pthread_mutex_init(&mutex_buffer, NULL); + #endif pthread_mutex_init(&mutex_get_image, NULL); pthread_mutex_init(&mutex_get_image_HD, NULL); @@ -25923,15 +25929,22 @@ void run_server(int argc, char **argv) strcpy(SystemSetting.enable_python, "No"); new_data_write_to_config_file_flag = 1; } - if (enable_python_file) + if (enable_python_file) { - strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); - - if (pthread_create(&runpython_thread, NULL, start_run_python_thread, (void*)configPATH) != 0) { - perror("check current runpython thread failed\n"); - exit(EXIT_FAILURE); + // check python file + if (strstr(enable_python_file->valuestring, ".py") == + enable_python_file->valuestring + strlen(enable_python_file->valuestring) - 3) { + + strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); + + if (pthread_create(&runpython_thread, NULL, start_run_python_thread, (void*)configPATH) != 0) { + printf("check current runpython thread failed\n"); + } + } else { + printf("File is not a Python file.\n"); } } + else { strcpy(SystemSetting.enable_python_file, "No python running."); new_data_write_to_config_file_flag = 1; diff --git a/src/detector_Ming.c b/src/detector_Ming.c deleted file mode 100644 index cc6dbc9..0000000 --- a/src/detector_Ming.c +++ /dev/null @@ -1,32092 +0,0 @@ - -#include "darknet.h" -#include "utils.h" -#include "demo.h" -#include "blas.h" -#include "option_list.h" -#include "setting.h" -#include "utility.h" -#include "libgen.h" -#include "iniReader.h" -#include "network.h" -#include "cJSON.h" -#include "cryptionPlus.h" -#include "nweb.h" -#include "gettest.h" -#include "test_nnctrl_live.h" -#include "fflpr_plate_db.h" -#ifdef GY_OS_AMBA -//#include "websocket_client.h" -#endif -#include "url_encode.h" -#ifdef GY_OS_AMBA -//#include "tof.h" -#include "ptz.h" -#endif -#include "cold_zone.h" -#include "cgicmd.h" -#include -#include "pns.h" -#include -#include "fork_pipe_lib.h" -#include -#include -#include "net_curl.h" -#include -#include "structures.h" - -#if defined GY_OS_AMBA -#include "ir_control.h" -#endif - -#ifdef GY_OS_AMBA -#include "send_osd_data.h" - -//#include "radar.h" -//#include "radar_driver.h" -//#include "radar_receive.h" -//#include "radar_parser.h" -#include "cv_point_transform.hpp" -//#include "cv_point_transform.h" -#include "cv.h" -//#include "face_parser.h" -#include "levenshtein.h" -#endif - - -///Steven MARK TEMP -//#include "zlog.h" -//===================== -//sophia add 2020/09/24 -#if defined GY_OS_AMBA || defined GY_OS_NOVA -#include "alm_queue.h" -#endif -//===================== - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#ifdef GY_OS_NOVA -#include "bbox_receive.h" -#endif - -#include "onvif_data.h" -#include "anpr_rule.h" - -//pthread_mutex_t mutex_tcp_layer[MAX_LAYER_NUM]; -//pthread_mutex_t mutex_http_layer[MAX_LAYER_NUM]; -//pthread_mutex_t mutex_post_notification; -//pthread_mutex_t mutex_post_notification_push; -pthread_mutex_t mutex_post_notification_pop; -pthread_mutex_t mutex_getalarmmotion; -pthread_mutex_t mutex_alm; -pthread_mutex_t mutex_curl; -pthread_mutex_t mutex_dn; -pthread_mutex_t mutex_websocket; -pthread_mutex_t mutex_enable_lpr_db; -#ifdef GY_OS_AMBA -pthread_mutex_t mutex_enable_face_db; -#endif -pthread_mutex_t mutex_username; -pthread_mutex_t mutex_pns; -pthread_mutex_t mutex_snap; -//pthread_mutex_t mutex_get_canvas; -//pthread_mutex_t mutex_cropped_roi; -pthread_mutex_t mutex_config_json; -#if defined GY_OS_AMBA -//pthread_mutex_t mutex_jvc_config_json; -#endif -pthread_mutex_t mutex_events_json; -pthread_mutex_t mutex_web; -pthread_mutex_t mutex_http_connection_handler; -pthread_mutex_t mutex_base64; -pthread_mutex_t mutex_run_one_net; -#ifdef GY_OS_NOVA -pthread_mutex_t mutex_run_parse_json; -#endif -pthread_mutex_t mutex_send_jpeg; -pthread_mutex_t mutex_heatmap_jpeg; -//pthread_mutex_t mutex_strsplit; -#ifdef GY_OS_AMBA -pthread_mutex_t mutex_perspective_transform; -#endif -//pthread_mutex_t mutex_snap_hd_image; -pthread_mutex_t mutex_snap_image; -pthread_mutex_t mutex_get_image; -pthread_mutex_t mutex_get_image_HD; - -pthread_mutex_t mutex_if_enable_lpr_db_is_Yes; -pthread_mutex_t mutex_get_network_input; -pthread_mutex_t mutex_differ_image; - -pthread_mutex_t mutex_run_one_net_anpr; - -pthread_mutex_t mutex_check_license; -pthread_mutex_t mutex_read_ipcam; - -pthread_mutex_t mutex_update_candidate; -pthread_mutex_t mutex_send_cgi; - -//pthread_mutex_t mutex_parse_bbox; - -pthread_mutex_t mutex_compute_median; -//pthread_mutex_t mutex_long_term; -//pthread_mutex_t mutex_short_term; - -//pthread_mutex_t mutex_long_term_yuv; -//pthread_mutex_t mutex_short_term_yuv; - -pthread_mutex_t mutex_set_http_request; -pthread_mutex_t mutex_reset_counter; - -#ifdef GY_OS_AMBA - -pthread_mutex_t mutex_get_depth; -//pthread_mutex_t mutex_tof_data; -pthread_mutex_t mutex_write_pcd_data; -pthread_mutex_t mutex_write_pcd_data_L; -pthread_mutex_t mutex_write_pcd_data_M; -pthread_mutex_t mutex_write_pcd_data_S; - - -pthread_mutex_t mutex_remotesnap_image; // Ken 2022-09-26 -pthread_mutex_t mutex_radar_json; // Ken 2022-09-22 -pthread_mutex_t mutex_tof_json; // Ken 2022-12-13 -pthread_mutex_t mutex_buffer; // Ming 2022-08-28 -pthread_mutex_t mutex_run_osd; -#endif - -#ifdef GY_OS_NOVA -pthread_mutex_t mutex_pre_bbox_receive; -pthread_mutex_t mutex_pre_connection; -pthread_mutex_t mutex_pre_image_receive; -#endif - -//pthread_mutex_t mutex_color_detect; - -int g_match_mac = 0; -char g_mac_address[256] = { 0 }; - -int g_sdk_version = -1; - -int g_parking_space_check_table[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; -int g_temp_parking_space_check_table[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; -float g_parking_space_recording_x[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; -float g_parking_space_recording_y[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; -time_t g_parking_space_update_time[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; -time_t g_parking_space_status_change_time[MAX_DETECTION_ZONE][MAX_SIZE_PARKING_SPACE] = { 0 }; - -long g_osdSysTimeStamp = 0; -int check_if_run_post = -1; -int check_if_correct_post = 0; - -int check_if_start_run_server = 0; -char record_process_note[MAX_RECORD_PROCESS][MAX_PROCESS_LENGTH] = { 0 }; -int current_index_record = 0; -int size_record_process_note = 0; - -//http server parameters -SocketInfo socketRecords[MAX_CLIENT_SOCKET] = { 0 }; -ChannelInfo viewChannelData[MAX_AI_ENGINE_VIEW] = { 0 }; -DetectionZoneInfo viewDetectionZone[MAX_AI_ENGINE_VIEW][MAX_DETECTION_ZONE] = { 0 }; -SystemSettingInfo SystemSetting; -PostEventInfo postEventList[MAX_POST_EVENTS] = { 0 }; -#ifdef GY_OS_V_SERIES - -#else -EventCounterInfo eventCounterList[MAX_EVENT_COUNTERS] = { 0 }; -ReportCounterInfo reportCounterList[MAX_REPORT_COUNTERS] = { 0 }; -SNMPManagementInfo SNMPManagementList[MAX_SNMP_MANAGEMENT] = { 0 }; -#endif - -AccountDataInfo accountData[MAX_ACCOUNT_DATA_NUM] = { 0 }; //20201027 sophia add -IPCAMServiceInfo IPCAMService; -SnapHDInfo snapHDList[MAX_SNAP_HD_LIST] = { 0 }; -EmailInfo emailData; -WeightFileInfo weightfileList[MAX_WEIGHT_FILE_LIST] = { 0 }; -char WeightFileModeName[35] = { 0 }; -HeartbeatInfo heartbeatData; -#ifdef GY_OS_AMBA -TofInfo tofData; -#endif - -int g_check_if_set_no_preset_no_autopan = 0; - -#if defined GY_OS_AMBA || defined GY_OS_NOVA -PlateRecoder g_PlateRecorderList[MAX_PLATE_RECORDER] = {0}; -#endif -ObjectRecoder g_ObjectRecorderList[MAX_OBJECT_RECORDER] = { 0 }; -PostRecoder g_PostRecorderList[MAX_POST_RECODER_SIZE] = { 0 }; -PostRecoder g_longterm_PostRecorderList[MAX_POST_RECODER_SIZE] = { 0 }; - -//MotionAreaInfo g_Motion_Area_Data[MAX_MOTION_AREA] = { 0 }; - -#if defined GY_OS_AMBA || defined GY_OS_NOVA -ImageDn imageDnData; -#endif -#ifdef GY_OS_AMBA -OSDInfo OSDData[MAX_SIZE_OSD_ARRAY] = { 0 }; -SpeedInfo SpeedData[MAX_SIZE_SP_ARRAY] = { 0 }; -#endif -int g_PlateFilterTimes; //Times -int g_PlateFilterTime; //Second -int g_PlateRecorderFreeTime; //Second - -struct tm *cgi_reload_start_Time; -struct tm *cgi_startTime_buff; -struct tm *cgi_whenTime_buff; - -struct amba_content stAMBAcontent; - -static int protected_sqlite_fflpr_db_close = 0; - -int g_check_ping_OK = 1; - -int g_check_if_no_brand = 0; - -//static unsigned char g_snapshot_addr_to_post[MAX_IMG_SIZE] = { 0 }; - -int g_control_read_ipcam = 0; -#ifdef GY_OS_AMBA -int g_sensors_type = 0;//type 0:MAX_SENSOR_TYPE0 type 1:MAX_SENSOR_TYPE1 -#endif -#ifdef GY_OS_NOVA -int g_sensors_type = 1;//type 0:MAX_SENSOR_TYPE0 type 1:MAX_SENSOR_TYPE1 -#endif -int g_max_sensor_size = MAX_SENSOR_TYPE0; - -int g_IsRadarDevice = 0; -int g_IsPTZDevice = 0; -int g_IsRadarFake = 0; -int g_check_if_OK_thermal = 0; - -int unlockingKeyInnoFR = 0; -int unlockingKeyInnoFR_success = 0; -#ifdef GY_OS_AMBA -char radar_json_data[4096]; -#endif -int g_check_if_OK_to_start_osd_server = 0; - -int g_IsSDK_3_0 = 0; -int g_IsToFDevice = 0; -int g_IsCustomWeight = 0; -int g_IsHelm_without_car = 0; - -float g_thres_bbox_stability = 0.02;//0.02 0.1 -float g_thres_bbox_stability_plate = 0.01; -float g_thres_bbox_stability_predict = 0.32; - -float g_initial_background_learning_rate_x = 0.5; -float g_initial_background_learning_rate_y = 0.5; -float g_initial_background_learning_rate_error_x = 0.0; -float g_initial_background_learning_rate_error_y = 0.0; - -float g_initial_background_mean_diff_x = 0.0; -float g_initial_background_mean_diff_y = 0.0; -float g_initial_background_error_diff_x = 0.0; -float g_initial_background_error_diff_y = 0.0; - -int g_check_current_resolution = 1; - -#if defined GY_OS_AMBA || defined GY_OS_NOVA -cJSON *g_config_root = NULL; -char* get_enable_python_file_value(const char *filename); -#endif - -/*typedef struct { - network net; - layer layer; - char *datacfg; - char *cfgfile; - char *weightfile; - float nms; - float thresh; - float hier_thresh; - int dont_show; - int ext_output; - int save_labels; -} NetworkInfo;*/ - -/*typedef struct { - NetworkInfo networkLayer[2]; - int layerCount; - char **alphabet; - ServerType serverType; - LicenseType licenseType; - AuthFailStatusCode afsCode; - unsigned int featureType; -} NetworkPool;*/ - -//static int coco_ids[] = {1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,17,18,19,20,21,22,23,24,25,27,28,31,32,33,34,35,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,67,70,72,73,74,75,76,77,78,79,80,81,82,84,85,86,87,88,89,90}; - -short td_weight_num = 0; -ThirdPartyWeight td_weight_info[MAX_LAYER_NUM]; - -//CURLM* g_multi_handle; -//int g_handle_count; -CURL* g_http_handle = NULL; - -bool isGYNetReady; - -extern int reload_dataset_from_jsonfile(void); -//extern int default_dataset_for_jsonfile(void); - -//#define DISAPPEAR_FRAME_MAX 8 -static int DISAPPEAR_FRAME_MAX = 8; - -void set_DISAPPEAR_FRAME_MAX(int disappear_frame_max_temp) { - DISAPPEAR_FRAME_MAX = disappear_frame_max_temp; -} - -void setPthreadName(char *p_name) -{ - if (p_name != NULL) - { - (void)prctl(PR_SET_NAME, (unsigned long)p_name);//lname 最多16?字符 - } -} - -//static NetworkPool networkPool[MAX_NETWORK_POOL_NUM]; -//static int layer_count; -static int dont_show; -static int show; -static int tcp_port; -//static char *out_filename; -//static char *outfile; -//static char *prefix; -static float thresh; -static float hier_thresh; -static int cam_index; -static int frame_skip; -static int num_of_clusters; -static int yuv_width; -static int yuv_height; -static int ext_output; -static int save_labels; -static int http_port; -//static char* unlocking_key; - -static int gpu_idx; -//static char* c_cnn_type; - -pthread_t http_thread; -#ifdef GY_OS_NOVA -pthread_t http_thread_parse_json_data; -pthread_t http_thread_pre_image_receive; -#endif -pthread_t post_notification_thread; -pthread_t runpython_thread; -pthread_t getalarmmotion_thread; - -pthread_t delete_jpg_in_seven_days_detector_thread_id; -pthread_t send_udp_thread; -pthread_t test_nnctrl_live_thread; - -pthread_t fps_loading_thread; - -pthread_t getimage_thread; - -pthread_t resolution_changed_thread; - -#ifdef GY_OS_V_SERIES - -#else -pthread_t counter_thread; -#endif - -#ifdef GY_OS_AMBA -pthread_t getimage_hd_thread; -pthread_t gettofdata_thread; - -pthread_t getstream_thread; -pthread_t get_face_websocket_thread; -pthread_t parse_face_thread; -pthread_t radar_reciever_id; -pthread_t render_radar_thread; -pthread_t radar_parser_thread; -pthread_t thread_id_run_osd_server; -#endif -#ifdef GY_OS_NOVA -pthread_t thread_id_get_nova_driver; -#endif -//pthread_t thread_id_run_system_time_sync; -static int check_if_is_existing_weight = 0; - -float overlap_ratio_limit; -extern float confidence_limit; - -int input_resizable; -char* custom_cpu_library; -char* custom_cldnn; -int performance_counter; - -static CNNType cnn_type; -//static image **alphabet=NULL; -//static network nets[MAX_LAYER_NUM]; -//static layer layers[MAX_LAYER_NUM]; -//static list *options[MAX_LAYER_NUM]; -//static char *name_list[MAX_LAYER_NUM]; -//static char **names[MAX_LAYER_NUM]; -//static network net2; -//static layer L2; -//static list *options2; -//static char *name_list2; -//static char **names2; -//static float nms[MAX_LAYER_NUM]; -//static float nms2; -//ini -static char ppIniKeyValue[MAX_LAYER_NUM][MAX_SECTION_VARIABLE][50] = { 0 }; -//http server parameters -//static CNNType http_cnn_type; -//static network http_nets[MAX_LAYER_NUM]; -//static network http_net2; -//static char **http_names[MAX_LAYER_NUM]; -//static char **http_names2; -//static image **http_alphabet; -//static float http_nms[MAX_LAYER_NUM]; -//static float http_nms2; -//static float http_thresh; -//static float http_hier_thresh; -//static int http_dont_show; -//static int http_ext_output; -//static int http_save_labels; -//static char *http_ip_address; -//static char *http_mac_address; -//static int http_http_port; -//static int http_layer_count; -//static char http_dataset_version; -//static LicenseType http_licenseType; -//static LicenseType http_advLicenseType; -//static AuthFailStatusCode http_afsCode; -//static size_t http_featureType; -static size_t layerFeatureType[MAX_LAYER_NUM] = { 0 }; -static size_t layerFeatureType2[MAX_LAYER_NUM] = { 0 }; -//static char* layerUTF8Country[MAX_LAYER_NUM]; -static char strLicenseType[MAX_MSG_LEN] = { 0 }; -char strLicenseStatus[MAX_MSG_LEN] = { 0 }; -char strUnlockingKey[MAX_MSG_LEN] = { 0 }; -int bHttpServerThreadStart = 0; -double http_license_fps; -int http_sleep_interval = 2; -int bPreloadHttpServerThreadStart = 0; - -//#ifdef GY_OS_WIN -//static char msgText[MAX_MSG_LEN]; -//#elif _DEBUG_AMBA -//static char msgText[MAX_MSG_LEN]; -//#endif - -int nIsCompatibleCPU = 0; -int nIsCompatibleGPU = 0; -int nIsCompatibleVPU = 0; -int nIsHardwareOK = 1; - -size_t featureType; -size_t featureType2; -size_t advancedType; - -CPoint trafficLightPoint = { 0 }; -int traffic_light_zone_width = 0; -int traffic_light_zone_height = 0; - -LicenseType licenseType; -AdvanceLicenseType advLicenseType; -AuthFailStatusCode afsCode; -HttpCode httpCode; - -MYBOOL activeDisplayDash; -MYBOOL activeDisplayProperties; -MYBOOL activePostNotification; -MYBOOL activeSNMPPost; -MYBOOL testPostNotification; - -char g_device_name[512] = { 0 }; - -int check_if_correct_mail = 0; -int check_if_fe_fail = 0; - -int g_enable_person_for_metadata[MAX_DETECTION_ZONE] = { 0 }; - -//struct amba_content stAMBAcontent; - -int protect_set_record_process_note = 0; -void set_record_process_note(char *process_note) { - if (check_if_start_run_server == 1 && protect_set_record_process_note == 0) { - protect_set_record_process_note = 1; - memset(record_process_note[current_index_record], 0x00, sizeof(record_process_note[current_index_record])); - snprintf(record_process_note[current_index_record], sizeof(record_process_note[current_index_record]), "%s", process_note); - - current_index_record++; - if (current_index_record >= MAX_RECORD_PROCESS) { - current_index_record = 0; - } - - if (size_record_process_note < MAX_RECORD_PROCESS) { - size_record_process_note++; - } - protect_set_record_process_note = 0; - } -} - -void record_process_note_write_to_log() { - if (check_if_start_run_server == 0) { - - char temp_msg[8192] = { 0 }; - for (int count_record = size_record_process_note - 1; count_record >= 0; count_record--) { - int index_record = current_index_record - 1 - count_record; - if (index_record < 0) { - index_record += size_record_process_note; - } - - if (count_record == 0) { - char temp_temp_msg[8192] = { 0 }; - snprintf(temp_temp_msg, sizeof(temp_temp_msg), "%s", record_process_note[index_record]); - } - else { - if (count_record == size_record_process_note - 1) { - char temp_temp_msg[8192] = { 0 }; - snprintf(temp_temp_msg, sizeof(temp_temp_msg), "free:%d,%s,", get_free_mem_data(), record_process_note[index_record]); - strcpy(temp_msg, temp_temp_msg); - } - else { - char temp_temp_msg[8192] = { 0 }; - snprintf(temp_temp_msg, sizeof(temp_temp_msg), "%s,", record_process_note[index_record]); - strcat(temp_msg, temp_temp_msg); - } - } - } - write_to_logs_html(temp_msg, "record process", "ERROR", "Yes"); - } -} - - -int get_check_if_correct_mail() { - return check_if_correct_mail; -} -#ifdef GY_OS_NOVA -void *thread_get_nova_driver(void *ptr) { - pthread_detach(pthread_self()); - setPthreadName("start nova driver"); - usSleep(12000000); - while (bHttpServerThreadStart) - { - start_nova_driver(); - usSleep(3000000); - } - pthread_exit(NULL); -} -#endif -void *thread_getimage(void *ptr) { - pthread_detach(pthread_self()); - setPthreadName("getimage"); - while (bHttpServerThreadStart) - { - //printf("\n---------thread getimage start\n"); - if (atoi(SystemSetting.getimage_encoder_id) - 1 >= 0) { - get_snap_with_profile_id(atoi(SystemSetting.getimage_encoder_id) - 1, 1); - }else if(unlockingKeyInnoFR_success == 1){ - get_snap_with_profile_id(0, 1); - } - //printf("\n---------thread getimage end\n"); - usSleep(3000000); - } - pthread_exit(NULL); -} - -void *thread_getimage_hd(void *ptr) { - pthread_detach(pthread_self()); - setPthreadName("getimage_hd"); - while (bHttpServerThreadStart) - { - if (atoi(SystemSetting.getimage_encoder_id_HD) - 1 >= 0 && atoi(SystemSetting.getimage_encoder_id_HD) != atoi(SystemSetting.getimage_encoder_id)) { - get_snap_with_profile_id(atoi(SystemSetting.getimage_encoder_id_HD) - 1, 0); - } - usSleep(3000000); - } - pthread_exit(NULL); -} - -void *run_http_server_thread(void *ptr) -{ - //printf("[run http server thread]Pthread started and detached. No new addr.\n"); - pthread_detach(pthread_self()); - - setPthreadName("run_http"); - -//#ifdef _DEBUG_AMBA - //printf("\n[run_http_server_thread] start\n"); -//#endif - - bHttpServerThreadStart = 1; - printf("[run_http_server_thread] !! \n"); - while (bHttpServerThreadStart) - { - bHttpServerMainStart = 1; - - run_http_server("", zc, cnn_type/*, layer_count, http_nets, names, alphabet, nms*/, thresh, hier_thresh, dont_show, ext_output, save_labels, NULL, NULL, http_port, licenseType, advLicenseType, afsCode, layerFeatureType, strLicenseType); - - //printf("\n[run http server thread] in while bHttpServerThreadStart-1 bHttpServerThreadStart:%d\n", bHttpServerThreadStart); - //printf("\n[run http server thread] in while bHttpServerThreadStart-2 :%d\n", bHttpServerThreadStart); - //printf("\nerr_count: %u\n",err_count); - - //usSleep(SLEEP_HTTP_CONNECTION_HANDLER*1000); - usSleep(1000); - } - //printf("\n[run http server thread] while out :%d\n", bHttpServerThreadStart); - - bHttpServerThreadStart = 0; - bHttpServerMainStart = 0; - - //printf("\n-----------run http server thread:exit\n"); - - //20201014 - sophia add for restart - pthread_exit(NULL); -} - -extern int run_preload_http_server(int http_port); -void *run_preload_http_server_thread(void *ptr) -{ - pthread_detach(pthread_self()); - setPthreadName("run_preload"); - - -#if 1 - - bPreloadHttpServerThreadStart = 1; - - while (bPreloadHttpServerThreadStart) - { - bPreloadHttpServerMainStart = 1; -#if 1 - run_preload_http_server(http_port); -#endif - bPreloadHttpServerThreadStart = 0; - - //printf("\n**********************\n"); - //printf("preload server close"); - //printf("\n**********************\n"); - - usSleep(100000); - } - - bPreloadHttpServerThreadStart = 0; - bPreloadHttpServerMainStart = 0; - -#endif - - //20210617-Steven add for preload - - - - pthread_exit(NULL); -} - -#ifdef GY_OS_V_SERIES - -#else -void reset_counter(int index_counter, time_t now_time) -{ - time_t ori_now_time = now_time; - struct tm *nowTime = localtime(&now_time); - int current_year = nowTime->tm_year + 1900; - int current_month = nowTime->tm_mon + 1; - int current_month_day = nowTime->tm_mday; - int current_week_day = nowTime->tm_wday + 1; - int current_hour = nowTime->tm_hour; - int current_min = nowTime->tm_min; - int current_sec = nowTime->tm_sec; - - if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 minute") == 0) - { - nowTime->tm_min = nowTime->tm_min + 1; - } - else if (strcmp(eventCounterList[index_counter].reset_time_interval, "5 minutes") == 0) - { - nowTime->tm_min = nowTime->tm_min + 5; - } - else if (strcmp(eventCounterList[index_counter].reset_time_interval, "30 minutes") == 0) - { - nowTime->tm_min = nowTime->tm_min + 30; - } - else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 hour") == 0) - { - nowTime->tm_hour = nowTime->tm_hour + 1; - } - else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 day") == 0) - { - nowTime->tm_mday = nowTime->tm_mday + 1; - } - else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 week") == 0) - { - - nowTime->tm_mday = nowTime->tm_mday + 7; - } - else if (strcmp(eventCounterList[index_counter].reset_time_interval, "1 month") == 0) - { - nowTime->tm_mon = nowTime->tm_mon + 1; - } - - time_t next_time = mktime(nowTime); - - int next_year = current_year; - int next_month = current_month; - int next_month_day = current_month_day; - int next_week_day = current_week_day; - int next_hour = current_hour; - int next_min = current_min; - int next_sec = current_sec; - - if (next_time != -1) { - struct tm *nextTime = localtime(&next_time); - next_year = nextTime->tm_year + 1900; - next_month = nextTime->tm_mon + 1; - next_month_day = nextTime->tm_mday; - next_week_day = nextTime->tm_wday + 1; - next_hour = nextTime->tm_hour; - next_min = nextTime->tm_min; - next_sec = nextTime->tm_sec; - } - else { - next_time = ori_now_time; - } - - struct tm * gmtTime = gmtime(&next_time); - int gmt_year = gmtTime->tm_year + 1900; - int gmt_month = gmtTime->tm_mon + 1; - int gmt_month_day = gmtTime->tm_mday; - int gmt_week_day = gmtTime->tm_wday + 1; - int gmt_hour = gmtTime->tm_hour; - int gmt_min = gmtTime->tm_min; - int gmt_sec = gmtTime->tm_sec; - - eventCounterList[index_counter].reset_year = current_year; - eventCounterList[index_counter].reset_month = current_month; - eventCounterList[index_counter].reset_month_day = current_month_day; - eventCounterList[index_counter].reset_week_day = current_week_day; - eventCounterList[index_counter].reset_hour = current_hour; - eventCounterList[index_counter].reset_min = current_min; - eventCounterList[index_counter].reset_sec = current_sec; - - eventCounterList[index_counter].gmt_year = gmt_year; - eventCounterList[index_counter].gmt_month = gmt_month; - eventCounterList[index_counter].gmt_month_day = gmt_month_day; - eventCounterList[index_counter].gmt_week_day = gmt_week_day; - eventCounterList[index_counter].gmt_hour = gmt_hour; - eventCounterList[index_counter].gmt_min = gmt_min; - eventCounterList[index_counter].gmt_sec = gmt_sec; - - eventCounterList[index_counter].next_year = next_year; - eventCounterList[index_counter].next_month = next_month; - eventCounterList[index_counter].next_month_day = next_month_day; - eventCounterList[index_counter].next_week_day = next_week_day; - eventCounterList[index_counter].next_hour = next_hour; - eventCounterList[index_counter].next_min = next_min; - eventCounterList[index_counter].next_sec = next_sec; - - eventCounterList[index_counter].timetResetAt = ori_now_time; - eventCounterList[index_counter].next_timetResetAt = next_time; - - time_t temp_next_time = next_time; - time_t temp_gmt_time = mktime(gmtTime); - if (temp_gmt_time != -1) { - double dTime = 0.0; - char sign_of_dtime[2] = { 0 }; - if (temp_next_time > temp_gmt_time) { - dTime = difftime(temp_next_time, temp_gmt_time); - strcpy(sign_of_dtime,"+"); - } - else if (temp_next_time < temp_gmt_time) { - dTime = difftime(temp_gmt_time, temp_next_time); - strcpy(sign_of_dtime, "-"); - } - else { - strcpy(sign_of_dtime, "+"); - } - - int iHour = (int)(dTime / 60.0 / 60.0); - int iMin = (int)((dTime - (double)iHour * 60.0 * 60.0) / 60.0); - - char ResetTime[50] = { 0 }; - sprintf(ResetTime,"%02d:%02d:%02d%s%02d:%02d", gmt_hour, gmt_min, gmt_sec, sign_of_dtime, iHour, iMin); - - strcpy(eventCounterList[index_counter].ResetTime, ResetTime); - } - else { - strcpy(eventCounterList[index_counter].ResetTime, ""); - } - - eventCounterList[index_counter].counter_count = eventCounterList[index_counter].reset_value; - eventCounterList[index_counter].already_reset = 1; - - //printf("\nreset time:%04d-%02d-%02dT%02d:%02d:%02d\n" - //, eventCounterList[index_counter].reset_year - //, eventCounterList[index_counter].reset_month - //, eventCounterList[index_counter].reset_month_day - //, eventCounterList[index_counter].reset_hour - //, eventCounterList[index_counter].reset_min - //, eventCounterList[index_counter].reset_sec - //); - - //printf("\nnext time:%04d-%02d-%02dT%02d:%02d:%02d\n" - // , eventCounterList[index_counter].next_year - // , eventCounterList[index_counter].next_month - // , eventCounterList[index_counter].next_month_day - // , eventCounterList[index_counter].next_hour - // , eventCounterList[index_counter].next_min - // , eventCounterList[index_counter].next_sec - //); -} - -void set_counter_zone() { - for (int j = 0; j < MAX_EVENT_COUNTERS; j++) - { - eventCounterList[j].counter_zone = 0; - } - - int tracking_channel_idx = 0; - int base_zone = 1; - for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) - { - if (index_zone >= 1) { - base_zone = base_zone * 2; - } - - for (int trigger_idx = 0; trigger_idx < MAX_TRIGGER_EVENT; trigger_idx++) - { - if (viewDetectionZone[tracking_channel_idx][index_zone].trigger_event[trigger_idx].checked >= 1) { - unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][index_zone].trigger_event[trigger_idx].detect_event_id); - - if (trigger_event_type == TRIGGER_GO_STRAIGHT || - trigger_event_type == TRIGGER_QUEUING_VIOLATION) - { - char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; - char Temp[MAX_MSG_LEN * 10] = { 0 }; - strcpy(Temp, viewDetectionZone[tracking_channel_idx][index_zone].trigger_event[trigger_idx].counter_name); - int event_counter_num = StrSplit(Temp, eachEventCounter, ","); - - for (int index_event_counter = 0; index_event_counter < event_counter_num; index_event_counter++) - { - for (int index_event_list = 0; index_event_list < MAX_EVENT_COUNTERS; index_event_list++) - { - if (strlen(eachEventCounter[index_event_counter]) >= 1 && strcmp(eachEventCounter[index_event_counter], eventCounterList[index_event_list].counter_name) == 0) - { - eventCounterList[index_event_list].counter_zone += base_zone; - break; - } - } - } - - } - - break; - } - } - } - -} - -#endif - - - -//原本名稱是check_http_socket_thread,現在改成run_event_counter_thread -void *run_event_counter_thread(void *ptr) -{ - pthread_detach(pthread_self()); - setPthreadName("run_counter"); -#ifdef GY_OS_V_SERIES - -#else - //printf("\n[run event counter thread]pthread create\n"); - - time_t now_time = g_osdSysTimeStamp; - if (now_time < 1000000000) { - now_time = time(0); - } - struct tm *nowTime = localtime(&now_time); - //int reset_year = nowTime->tm_year + 1900; - int reset_month = nowTime->tm_mon + 1; - int reset_month_day = nowTime->tm_mday; - int reset_week_day = nowTime->tm_wday + 1; - int reset_hour = nowTime->tm_hour; - int reset_min = nowTime->tm_min; - //int reset_sec = nowTime->tm_sec; - - //struct tm * gmtTime = gmtime(&now_time); - //int gmt_year = gmtTime->tm_year + 1900; - //int gmt_month = gmtTime->tm_mon + 1; - //int gmt_month_day = gmtTime->tm_mday; - //int gmt_week_day = gmtTime->tm_wday + 1; - //int gmt_hour = gmtTime->tm_hour; - //int gmt_min = gmtTime->tm_min; - //int gmt_sec = gmtTime->tm_sec; - - for (int j = 0; j < MAX_EVENT_COUNTERS; j++) - { - reset_counter(j, now_time); - } - - set_counter_zone(); - - while (bHttpServerThreadStart) - { - //printf("\n-----run event counter thread start\n"); - //if (strcmp(eventCounterList[j].enable_reset_only_cloud, "No") == 0) - if (//(strcmp(SystemSetting.cloud_enable_notification, "No") == 0) && - (strcmp(SystemSetting.enable_email_notification, "No") == 0 || (strcmp(SystemSetting.enable_email_notification, "Yes") == 0 && Get_mail_post_interval() == -1)) - ) - { - set_record_process_note("counter_start"); - now_time = g_osdSysTimeStamp; - if (now_time < 1000000000) { - now_time = time(0); - } - nowTime = localtime(&now_time); - //int current_year = nowTime->tm_year + 1900; - int current_month = nowTime->tm_mon + 1; - int current_month_day = nowTime->tm_mday; - int current_week_day = nowTime->tm_wday + 1; - int current_hour = nowTime->tm_hour; - int current_min = nowTime->tm_min; - int current_sec = nowTime->tm_sec; - -#if 1 - pthread_mutex_lock(&mutex_reset_counter); - for (int j = 0; j < MAX_EVENT_COUNTERS; j++) - { - //reset_year = eventCounterList[j].reset_year; - reset_month = eventCounterList[j].reset_month; - reset_month_day = eventCounterList[j].reset_month_day; - reset_week_day = eventCounterList[j].reset_week_day; - reset_hour = eventCounterList[j].reset_hour; - reset_min = eventCounterList[j].reset_min; - //reset_sec = eventCounterList[j].reset_sec; - - //gmt_year = eventCounterList[j].gmt_year; - //gmt_month = eventCounterList[j].gmt_month; - //gmt_month_day = eventCounterList[j].gmt_month_day; - //gmt_week_day = eventCounterList[j].gmt_week_day; - //gmt_hour = eventCounterList[j].gmt_hour; - //gmt_min = eventCounterList[j].gmt_min; - //gmt_sec = eventCounterList[j].gmt_sec; - - if (strcmp(eventCounterList[j].enable_reset_time_interval, "Yes") == 0) - { - if (strcmp(eventCounterList[j].reset_time_interval, "1 minute") == 0) - { - eventCounterList[j].dwell_time = current_sec; - strcpy(eventCounterList[j].dwell_unit, "sec"); - strcpy(eventCounterList[j].ReportTimeInterval, "PT1S"); - - if (eventCounterList[j].already_reset == 1 && current_sec >= 30) { - eventCounterList[j].already_reset = 0; - } - - if (eventCounterList[j].already_reset == 0 && current_sec < 30 && current_min != reset_min) - { - reset_counter(j, now_time); - } - } - else if (strcmp(eventCounterList[j].reset_time_interval, "5 minutes") == 0) - { - eventCounterList[j].dwell_time = current_min; - strcpy(eventCounterList[j].dwell_unit, "min"); - strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); - - if (eventCounterList[j].already_reset == 1 && current_min % 5 != 0) { - eventCounterList[j].already_reset = 0; - } - - if (eventCounterList[j].already_reset == 0 && current_min % 5 == 0 && current_min != reset_min) - { - reset_counter(j, now_time); - } - } - else if (strcmp(eventCounterList[j].reset_time_interval, "30 minutes") == 0) - { - eventCounterList[j].dwell_time = current_min; - strcpy(eventCounterList[j].dwell_unit, "min"); - strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); - - if (eventCounterList[j].already_reset == 1 && current_min % 30 != 0) { - eventCounterList[j].already_reset = 0; - } - - if (eventCounterList[j].already_reset == 0 && current_min % 30 == 0 && current_min != reset_min) - { - reset_counter(j, now_time); - } - } - else if (strcmp(eventCounterList[j].reset_time_interval, "1 hour") == 0) - { - eventCounterList[j].dwell_time = current_min; - strcpy(eventCounterList[j].dwell_unit, "min"); - strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); - - if (eventCounterList[j].already_reset == 1 && current_min != 0) { - eventCounterList[j].already_reset = 0; - } - - if (eventCounterList[j].already_reset == 0 && current_min == 0 && current_hour != reset_hour) - { - reset_counter(j, now_time); - } - } - else if (strcmp(eventCounterList[j].reset_time_interval, "1 day") == 0) - { - eventCounterList[j].dwell_time = current_hour; - strcpy(eventCounterList[j].dwell_unit, "hour"); - strcpy(eventCounterList[j].ReportTimeInterval, "PT1H"); - - if (eventCounterList[j].already_reset == 1 && current_hour % 24 != 0) { - eventCounterList[j].already_reset = 0; - } - - if (eventCounterList[j].already_reset == 0 && current_hour % 24 == 0 && current_week_day != reset_week_day) - { - reset_counter(j, now_time); - } - } - else if (strcmp(eventCounterList[j].reset_time_interval, "1 week") == 0) - { - eventCounterList[j].dwell_time = current_week_day; - strcpy(eventCounterList[j].dwell_unit, "wday"); - strcpy(eventCounterList[j].ReportTimeInterval, "P1D"); - - if (eventCounterList[j].already_reset == 1 && current_week_day != 1) { - eventCounterList[j].already_reset = 0; - } - - if (eventCounterList[j].already_reset == 0 && current_month == 1 && current_month_day != reset_month_day) - { - reset_counter(j, now_time); - } - } - else if (strcmp(eventCounterList[j].reset_time_interval, "1 month") == 0) - { - eventCounterList[j].dwell_time = current_month_day; - strcpy(eventCounterList[j].dwell_unit, "mday"); - strcpy(eventCounterList[j].ReportTimeInterval, "P1D"); - - if (eventCounterList[j].already_reset == 1 && current_month_day != 1) { - eventCounterList[j].already_reset = 0; - } - - if (eventCounterList[j].already_reset == 0 && current_month_day == 1 && current_month != reset_month) - { - reset_counter(j, now_time); - } - } - else { - eventCounterList[j].dwell_time = current_min; - strcpy(eventCounterList[j].dwell_unit, "min"); - strcpy(eventCounterList[j].ReportTimeInterval, "PT1M"); - } - } - - } - pthread_mutex_unlock(&mutex_reset_counter); -#endif - set_record_process_note("counter_end"); - usSleep(1000000); - } - else { - usSleep(5000000); - } - //printf("\n-----run event counter thread end\n"); - } - //printf("\n[run event counter thread] end\n"); -#endif - pthread_exit(NULL); -} - -struct timeval currtime_control_alarm_gpio; -static long last_ms_control_alarm_gpio = 0; -//post the notification back to the origianl socket -void *run_post_notification_thread(void *ptr) -{ - //printf("\n[run post notification thread]pthread create\n"); - - pthread_detach(pthread_self()); - setPthreadName("run_post"); - QueueInfo q_info_copy = { 0 }; - - char sendLargeBuffer[BUFSIZE_V2] = { 0 }; - - pthread_mutex_lock(&mutex_curl); - if (g_http_handle != NULL) { - curl_easy_cleanup(g_http_handle); - curl_global_cleanup(); - curl_global_init(CURL_GLOBAL_SSL); - g_http_handle = NULL; - g_http_handle = curl_easy_init(); - } - pthread_mutex_unlock(&mutex_curl); - - int count_g_http_handle = 0; - - unsigned int count_to_refresh_smtp_service = 0; - int count_delay = 0; - - int count_initial_global_curl = 0; - -#ifdef GY_OS_AMBA - int count_ptz = 0; -#endif - - while (bHttpServerThreadStart) - { - //printf("\n-----run post notification start\n"); - set_record_process_note("run_post_start"); - //printf("out que size = %d \n", QueueSize(_POST_NOTIFICATION)); - if (!QueueIsEmpty(_POST_NOTIFICATION) && QueueSize(_POST_NOTIFICATION) >= 1) - { - //printf("\n-----------QueueSize(_POST_NOTIFICATION) = %d \n", QueueSize(_POST_NOTIFICATION)); - //測試 -#if 1 - pthread_mutex_lock(&mutex_post_notification_pop); - q_info_copy = QueueFront(_POST_NOTIFICATION); - - QueuePop(_POST_NOTIFICATION); - pthread_mutex_unlock(&mutex_post_notification_pop); - - memset(sendLargeBuffer, 0x00, BUFSIZE_V2); - -//推播AA -#if 1 - //以下為推播----------- - if (strcmp(q_info_copy.post_url,"post_to_cloud")==0) { - - - //printf("\n----------------\n"); - //printf("\nq_info_copy.cloud_aiengine:%s\n", q_info_copy.cloud_aiengine); - //printf("\n----------------\n"); - char behavior_ID_temp[50] = {0}; - sprintf(behavior_ID_temp,"%d", q_info_copy.behavior_ID); - - char behavior_ID_16_temp[50] = { 0 }; - sprintf(behavior_ID_16_temp, "0x%08X", q_info_copy.behavior_ID); - - //printf("\n-------%s\n", behavior_ID_16_temp); - - /* - printf("\n----------------\n"); - printf("\nbehavior_name:%s,behavior_ID_temp:%s,behavior_desc:%s\n", q_info_copy.behavior_name, behavior_ID_temp, q_info_copy.behavior_desc); - printf("\n----------------\n");*/ - //if 0 No PNS_Send_Multipart_POST 最大增長162,000byte -#if 1 - - char returned_msg[MEMORY_SIZE] = { 0 }; - PNS_Send_Multipart_POST(q_info_copy.cloud_aiengine, q_info_copy.behavior_name, behavior_ID_temp, behavior_ID_16_temp, q_info_copy.behavior_desc, SystemSetting.cloud_account, SystemSetting.cloud_password, "https://cloud.ddnsipcam.com/pns/" , returned_msg, q_info_copy.image_buff, q_info_copy.image_buff_size, q_info_copy.rawtime); - strcpy(SystemSetting.cloud_statue,returned_msg); - - - //printf("\n------------Segmentation fault:%d\n",1); - - //怕PNS_Send_Multipart_POST的記憶體洩漏太多,定期清理,清理完後重新初始化 - //curl_global_cleanup(); - //curl_global_init(CURL_GLOBAL_SSL); -#endif - } - else if (strcmp(q_info_copy.post_url, "post_to_mail") == 0) - { - //printf("\n-----------q_info_copy.behavior_desc:%s\n", q_info_copy.behavior_desc); -#if defined GY_OS_AMBA || defined GY_OS_NOVA - SendMailEventCondition(q_info_copy.behavior_desc, q_info_copy.content, q_info_copy.image_buff, q_info_copy.image_buff_size); -#endif - //curl_global_cleanup(); - //curl_global_init(CURL_GLOBAL_SSL); - } - else if (strcmp(q_info_copy.post_url, "curl_to_ftp") == 0) - { - //printf("\n-----------q_info_copy.behavior_desc:%s\n", q_info_copy.behavior_desc); -//#if defined GY_OS_AMBA - net_curl_ftp_post_push_info_attached_image(q_info_copy.image_buff, q_info_copy.image_buff_size); -//#endif - //curl_global_cleanup(); - //curl_global_init(CURL_GLOBAL_SSL); - } -#if defined GY_OS_AMBA - else if (strlen(q_info_copy.snmp_host_ip) >= 1) - { - //printf("\n-----------q_info_copy.behavior_desc:%s\n", q_info_copy.behavior_desc); - - SetSNMPRequest(&q_info_copy); - - //curl_global_cleanup(); - //curl_global_init(CURL_GLOBAL_SSL); - } -#endif - else { - if (strlen(q_info_copy.post_url) >= 1) { - - char *temp_post_url = StrReplace(q_info_copy.post_url, "space", "%20"); - strcpy(q_info_copy.post_url, temp_post_url); - if (temp_post_url != NULL) { - free(temp_post_url); - temp_post_url = NULL; - } - - //printf("\n----------q_info_copy.post_url:%s\n", q_info_copy.post_url); - - pthread_mutex_lock(&mutex_set_http_request); -#ifdef GY_OS_NOVA - if (strcmp(q_info_copy.host_name, "127.0.0.1") != 0 && strcmp(q_info_copy.host_name, "localhost") != 0) { - SetHttpRequest(&q_info_copy, sendLargeBuffer, q_info_copy.post_method); - } - else { - SetHttpRequest_sock(&q_info_copy, sendLargeBuffer, q_info_copy.post_method); - } -#endif - -#ifdef GY_OS_AMBA - SetHttpRequest(&q_info_copy, sendLargeBuffer, q_info_copy.post_method); -#endif - - pthread_mutex_unlock(&mutex_set_http_request); - } - } - //以上為推播----------- -#endif - //printf("\n------------Segmentation fault:%d\n", 2); -#endif - } - -#ifdef GY_OS_AMBA - if (g_IsPTZDevice == 1 && get_try_once_ptz() == 1) { - if (IsTracking() == 1) { - if (count_ptz % 15 == 0) { - count_ptz = 0; - UpdatePTZIPcamSetting(); - } - else if (count_ptz % 15 == 4) { - UpdatePTZCurPos(); - } - else if (count_ptz % 15 == 7) { - update_PTZ_limits(); - } - else if (count_ptz % 15 == 10) { - UpdateRecoveryTime(); - } - } - else { - if (count_ptz % 40 == 0) { - count_ptz = 0; - UpdatePTZIPcamSetting(); - } - } - count_ptz++; - } -#endif - - if (count_delay % 200 == 0) { - count_delay = 0; - update_system_time(); - } - count_delay++; - - if (count_initial_global_curl % 15 == 0) { - count_initial_global_curl = 0; - - pthread_mutex_lock(&mutex_curl); - if (g_http_handle != NULL) { - curl_easy_cleanup(g_http_handle); - curl_global_cleanup(); - curl_global_init(CURL_GLOBAL_SSL); - g_http_handle = NULL; - g_http_handle = curl_easy_init(); - } - else { - curl_global_cleanup(); - curl_global_init(CURL_GLOBAL_SSL); - g_http_handle = curl_easy_init(); - } - pthread_mutex_unlock(&mutex_curl); - } - count_initial_global_curl++; - - if (g_IsSDK_3_0 == 0) { - if (count_to_refresh_smtp_service % MAX_COUNT_TO_REFRESH_SMTP_SERVICE * 5 == 0) { - count_to_refresh_smtp_service = 0; - copy_ipcam_smtp_service_to_gynet(); - } - count_to_refresh_smtp_service++; - } - - if (g_IsPTZDevice == 0 && g_dual_sensor == 0) { - if (strcmp(viewChannelData[0].enable_lpr_upon_triggered, "Yes") == 0) { - gettimeofday(&currtime_control_alarm_gpio, NULL); - long current_ms_control_alarm_gpio = (currtime_control_alarm_gpio.tv_sec * 1000) + (currtime_control_alarm_gpio.tv_usec / 1000); - - if (last_ms_control_alarm_gpio == 0) { - last_ms_control_alarm_gpio = current_ms_control_alarm_gpio; - } - - if (current_ms_control_alarm_gpio >= last_ms_control_alarm_gpio + atoi(viewChannelData[0].dwell_lpr_upon_triggered) * 1000) { - copy_control_io_to_gynet(); - last_ms_control_alarm_gpio = current_ms_control_alarm_gpio; - } - } - } - - if (count_g_http_handle >= 5) { - //printf("\n------------Segmentation fault:%d\n", 3); - count_g_http_handle = 0; - pthread_mutex_lock(&mutex_curl); - if (g_http_handle != NULL) { - curl_easy_cleanup(g_http_handle); - - //curl_global_cleanup(); - //curl_global_init(CURL_GLOBAL_SSL); - - g_http_handle = NULL; - g_http_handle = curl_easy_init(); - } - else { - g_http_handle = curl_easy_init(); - } - pthread_mutex_unlock(&mutex_curl); - //printf("\n------------Segmentation fault:%d\n", 4); - } - else if (g_http_handle == NULL) { - count_g_http_handle = 0; - pthread_mutex_lock(&mutex_curl); - if (g_http_handle == NULL) { - g_http_handle = curl_easy_init(); - } - pthread_mutex_unlock(&mutex_curl); - } - - count_g_http_handle++; - set_record_process_note("run_post_end"); - //printf("\n-----run post notification end\n"); - usSleep(SLEEP_QUEUE_POP_POST*1000); - } - - pthread_mutex_lock(&mutex_curl); - curl_easy_cleanup(g_http_handle); - g_http_handle = NULL; - pthread_mutex_unlock(&mutex_curl); - - pthread_mutex_lock(&mutex_post_notification_pop); - QueueClear(_POST_NOTIFICATION); - pthread_mutex_unlock(&mutex_post_notification_pop); - - //printf("\n-------[run post notification thread] pthread_exit\n"); - - pthread_exit(NULL); -} - -//post the getalarmmotion back to the origianl socket -static char MultiPartBuffer[CONTENT_BUFSIZE] = { 0 }; -static char contentBuffer[CONTENT_BUFSIZE] = { 0 }; -static char contentBuffer_websocket[CONTENT_BUFSIZE] = { 0 }; -void *run_getalarmmotion_thread(void *ptr) -{ - //printf("\n[run getalarmmotion thread]pthread create\n"); - - pthread_detach(pthread_self()); - setPthreadName("run_getalarm"); - char sendBuffer[ALMBUFSIZE] = {0}; - //int nmlocsendBufferSize = 1024; - //int PAD_BUFFERSIZE = 512; - char l_send_buf[ALMBUFSIZE] = { 0 }; - UNIX_MESSAGE_V1_T l_unix_msg; - int l_packet_len = 0; - char tempStr[MAX_MSG_LEN] = { 0 }; - - QueueInfo q_info_copy = { 0 }; - - while (bHttpServerThreadStart) - { - //printf("\n getalarmmotion out que size = %d \n", QueueSize(_GETALARMMOTION)); - if (!QueueIsEmpty(_GETALARMMOTION)) - { - //printf("\n-------run getalarmmotion start\n"); - set_record_process_note("run_getalarm_start"); - //memset(sendBuffer, 0x00, sizeof(sendBuffer)); //20201104 sophia add - memset(MultiPartBuffer, 0x00, sizeof(MultiPartBuffer)); - memset(contentBuffer, 0x00, sizeof(contentBuffer)); - memset(contentBuffer_websocket, 0x00, sizeof(contentBuffer_websocket)); - memset(websocket_alarm, 0x00, sizeof(websocket_alarm)); - - pthread_mutex_lock(&mutex_getalarmmotion); - - q_info_copy = QueueFront(_GETALARMMOTION); - QueuePop(_GETALARMMOTION); - - pthread_mutex_unlock(&mutex_getalarmmotion); - - time_t now = time(0); - //struct tm tm = *gmtime(&now); - struct tm tm = *localtime(&now); - - struct timeval curTime; - gettimeofday(&curTime, NULL); - - strcpy(contentBuffer, "CamTime: "); - - memset(tempStr, 0x00, sizeof(tempStr)); - strftime(tempStr, sizeof(tempStr) - 1, "%Y-%m-%d %H:%M:%S", &tm); - strcat(contentBuffer, tempStr); - - int milli = curTime.tv_usec / 1000; - memset(tempStr, 0x00, sizeof(tempStr)); - snprintf(tempStr, sizeof(tempStr) - 1, " %s%d", "ms:", milli); - strcat(contentBuffer, tempStr); - strcat(contentBuffer, "\r\n"); - strcat(contentBuffer, "\r\n"); - - strcpy(contentBuffer_websocket, contentBuffer); - - strcat(contentBuffer, q_info_copy.content); - strcat(contentBuffer, "\r\n"); - strcat(contentBuffer, "\r\n"); - - strcat(contentBuffer_websocket, q_info_copy.content_no_base64_image); - strcat(contentBuffer_websocket, "\r\n"); - strcat(contentBuffer_websocket, "\r\n"); - - //strcat(contentBuffer, "--myboundary\r\n"); - //strcat(contentBuffer, "\r\n"); - - //修正成g_IsRadarDevice和g_IsToFDevice支援content和content_no_base64_image,因為websocket的getalarmmotion要走no_base64_image。 - //而一般getalarmmotion,則是使用content。 - //memcpy(websocket_alarm, contentBuffer, strlen(contentBuffer)); - memcpy(websocket_alarm, contentBuffer_websocket, strlen(contentBuffer_websocket)); - - long int contentLen_buffer = strlen(q_info_copy.content); - - strcpy(MultiPartBuffer, "--myboundary\r\n"); - //strcat(MultiPartBuffer, "\r\n"); - - //strcat(MultiPartBuffer, "Host: localhost:8592\r\n"); - //strcat(MultiPartBuffer, "Connection: keep-alive\r\n"); - //strcat(MultiPartBuffer, "Pragma: no-cache\r\n"); - //strcat(MultiPartBuffer, "Cache-Control: no-cache"); - //strcat(MultiPartBuffer, "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36\r\n"); - //strcat(MultiPartBuffer, "Accept: */*\r\n"); - //strcat(MultiPartBuffer, "Referer: \r\n"); - //strcat(MultiPartBuffer, "Accept-Encoding: gzip, deflate\r\n"); - //strcat(MultiPartBuffer, "Accept-Language: zh-TW,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6\r\n"); - //strcat(MultiPartBuffer, "Cookie: \r\n"); - //strcat(MultiPartBuffer, "Content-Type: multipart/form-data; boundary=----WebKitFormBoundarylilinboundary\r\n"); - - strcat(MultiPartBuffer, "Content-Type: text/plain\r\n"); - //strcat(MultiPartBuffer, "Content-Type: text/plain; charset=utf-8;\r\n"); - - memset(tempStr, 0x00, sizeof(tempStr)); - snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", contentLen_buffer); - strcat(MultiPartBuffer, tempStr); - strcat(MultiPartBuffer, "\r\n"); - //strcat(MultiPartBuffer, "Content-Type: text/html; charset=utf-8\r\n"); - - - strcat(MultiPartBuffer, contentBuffer); - //getalarmmotion doesn't need to append --myboundary END - size_t MultiPartLen = strlen(MultiPartBuffer); - - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - int sock_idx = i; - if (socketRecords[i].used == 1 && socketRecords[i].sock != -1 && socketRecords[i].isGetAlarmMotion) - { - //memset(sendBuffer, 0x00, nmlocsendBufferSize); //20201104 sophia add - ////檢查是否重複迴圈,如果是,則關閉第一次的alarm。 - - //printf("\n[run getalarmmotion thread] socketRecords[%d].sock:%ld contentLen_buffer:%d MultiPartLen:%d\n", i, socketRecords[i].sock, contentLen_buffer, MultiPartLen); - - if (socketRecords[i].isUdpSocket == TRUE) - { - //printf("\n----------%d\n", strlen(q_info_copy.udp_aiengine)); - ///getalarmmotion looping -#if 1 - if(strlen(q_info_copy.udp_aiengine) >= 1 && strlen(q_info_copy.udp_aiengine) <= 15000) - { - memset(sendBuffer, 0x00, sizeof(sendBuffer)); - - unsigned int UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING = 0x0000; //type - unsigned int contentlen = strlen(q_info_copy.udp_aiengine); //len - size_t sendBufferSize = 0; - - //================================================================ - //get sendBuffer - //if sendBuffer size too small, refresh a new one - - //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) - { - //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; - //memset(sendBuffer, 0x00, nmlocsendBufferSize); - } - - //start code - { - strcat(sendBuffer, "UMV01"); - sendBufferSize = sendBufferSize + 5; - } - - //type - { - memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING, sizeof(UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING)); - sendBufferSize = sendBufferSize + 4; - } - //len - { - memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); - sendBufferSize = sendBufferSize + 4; - } - - //#ifdef _DEBUG_AMBA - /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); - printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); - for (int pp = 0;pp < sendBufferSize;pp++) - { - printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); - }*/ - //#endif - - //content - memcpy(sendBuffer + sendBufferSize, q_info_copy.udp_aiengine, contentlen); - sendBufferSize = sendBufferSize + contentlen; -#ifdef _DEBUG_AMBA - printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); -#endif - //================================================================ - - //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) - { - - ALMQueueInfo alm_q_info = { 0 }; - - memset(alm_q_info.pszContent, 0x00, sendBufferSize + 1); - memcpy(alm_q_info.pszContent, sendBuffer, sendBufferSize + 1); - //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); - alm_q_info.nSize = sendBufferSize + 1; - alm_q_info.infoType = 1; - //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); - if (AI_fps >= 1) { - pthread_mutex_lock(&mutex_alm); - if(ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) - ALMQueuePush(alm_q_info, sock_idx); - pthread_mutex_unlock(&mutex_alm); - //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d",1); - } - - /*#ifdef _DEBUG_AMBA - for (int bb = 0;bb < 15;bb++) - { - printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); - } - printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); - #endif*/ - } - } - else if(strlen(q_info_copy.udp_aiengine) > 15000 && strlen(q_info_copy.udp_aiengine) <= 30000) - { - memset(sendBuffer, 0x00, sizeof(sendBuffer)); - - //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 1); - /////////////////start - unsigned int UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING = 0x0000; - unsigned int UDP_PACKAGE_TYPE = 0x0000; //start type 0x0000 body type 0x0001 end type 0x0002 - unsigned int contentlen = 15000; //len - size_t sendBufferSize = 0; - - //================================================================ - //get sendBuffer - //if sendBuffer size too small, refresh a new one - - //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 2); - //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) - { - //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; - //memset(sendBuffer, 0x00, ALMBUFSIZE); - } - - //start code - { - strcat(sendBuffer, "UMV02"); - sendBufferSize = sendBufferSize + 5; - } - //type - { - memcpy(sendBuffer + sendBufferSize, &UDP_PACKAGE_TYPE, sizeof(UDP_PACKAGE_TYPE)); - sendBufferSize = sendBufferSize + 4; - } - //type - { - memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING, sizeof(UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING)); - sendBufferSize = sendBufferSize + 4; - } - //len - { - memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); - sendBufferSize = sendBufferSize + 4; - } - //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 3); - //#ifdef _DEBUG_AMBA - /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); - printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); - for (int pp = 0;pp < sendBufferSize;pp++) - { - printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); - }*/ - //#endif - - //content - memcpy(sendBuffer + sendBufferSize, q_info_copy.udp_aiengine, contentlen); - sendBufferSize = sendBufferSize + contentlen; -#ifdef _DEBUG_AMBA - printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); -#endif - //================================================================ - //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 4); - ALMQueueInfo alm_q_info_1 = { 0 }; - //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) - { - - - - memset(alm_q_info_1.pszContent, 0x00, sendBufferSize + 1); - memcpy(alm_q_info_1.pszContent, sendBuffer, sendBufferSize + 1); - //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); - alm_q_info_1.nSize = sendBufferSize + 1; - alm_q_info_1.infoType = 1; - //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); - - /*#ifdef _DEBUG_AMBA - for (int bb = 0;bb < 15;bb++) - { - printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); - } - printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); - #endif*/ - } - - //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 5); - /////////////////end - UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING = 0x0000; - UDP_PACKAGE_TYPE = 0x0002; //start type 0x0000 body type 0x0001 end type 0x0002 - contentlen = strlen(q_info_copy.udp_aiengine) - 15000; //len - sendBufferSize = 0; - - //================================================================ - //get sendBuffer - //if sendBuffer size too small, refresh a new one - - //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 6); - //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) - { - //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; - //memset(sendBuffer, 0x00, ALMBUFSIZE); - } - - //start code - { - strcat(sendBuffer, "UMV02"); - sendBufferSize = sendBufferSize + 5; - } - //type - { - memcpy(sendBuffer + sendBufferSize, &UDP_PACKAGE_TYPE, sizeof(UDP_PACKAGE_TYPE)); - sendBufferSize = sendBufferSize + 4; - } - //type - { - memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING, sizeof(UNIX_MESSAGE_TYPE_GETALARMMOTION_LOOPING)); - sendBufferSize = sendBufferSize + 4; - } - //len - { - memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); - sendBufferSize = sendBufferSize + 4; - } - //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 7); - //#ifdef _DEBUG_AMBA - /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); - printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); - for (int pp = 0;pp < sendBufferSize;pp++) - { - printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); - }*/ - //#endif - - //content - memcpy(sendBuffer + sendBufferSize, q_info_copy.udp_aiengine + 15000, contentlen); - sendBufferSize = sendBufferSize + contentlen; -#ifdef _DEBUG_AMBA - printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); -#endif - //================================================================ - //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 8); - //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) - { - - ALMQueueInfo alm_q_info_2 = { 0 }; - - memset(alm_q_info_2.pszContent, 0x00, sendBufferSize + 1); - memcpy(alm_q_info_2.pszContent, sendBuffer, sendBufferSize + 1); - //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); - alm_q_info_2.nSize = sendBufferSize + 1; - alm_q_info_2.infoType = 1; - //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); - - if (AI_fps >= 1) { - pthread_mutex_lock(&mutex_alm); - if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) { - ALMQueuePush(alm_q_info_1, sock_idx); - ALMQueuePush(alm_q_info_2, sock_idx); - } - pthread_mutex_unlock(&mutex_alm); - //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d",1); - } - - /*#ifdef _DEBUG_AMBA - for (int bb = 0;bb < 15;bb++) - { - printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); - } - printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); - #endif*/ - //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 9); - - } - } -#endif - //getalarmmotion cloud - if(strcmp(SystemSetting.enable_cloud_v2,"Yes")==0 && strcmp(q_info_copy.post_url,"cloud_v2")==0 && strlen(q_info_copy.cloud_v2_aiengine)>=1) - { - memset(sendBuffer, 0x00, sizeof(sendBuffer)); - - unsigned int UNIX_MESSAGE_TYPE_POST_CLOUD = 0x0001; //type - unsigned int contentlen = strlen(q_info_copy.cloud_v2_aiengine); //len - - //printf("\n-----------q_info_copy.cloud_v2_aiengine:%s\n", q_info_copy.cloud_v2_aiengine); - - size_t sendBufferSize = 0; - - //================================================================ - //get sendBuffer - //if sendBuffer size too small, refresh a new one - - //if ((contentlen + PAD_BUFFERSIZE) >= nmlocsendBufferSize) - { - //nmlocsendBufferSize = contentlen + PAD_BUFFERSIZE; - //memset(sendBuffer, 0x00, nmlocsendBufferSize); - } - - //start code - { - strcat(sendBuffer, "UMV01"); - sendBufferSize = sendBufferSize + 5; - } - - //type - { - memcpy(sendBuffer + sendBufferSize, &UNIX_MESSAGE_TYPE_POST_CLOUD, sizeof(UNIX_MESSAGE_TYPE_POST_CLOUD)); - sendBufferSize = sendBufferSize + 4; - } - //len - { - memcpy(sendBuffer + sendBufferSize, &contentlen, sizeof(contentlen)); - sendBufferSize = sendBufferSize + 4; - } - - //#ifdef _DEBUG_AMBA - /*printf("\n[run getalarmmotion thread] sizeof(contentlen):%d \n", sizeof(contentlen)); - printf("\n[run getalarmmotion thread] contentlen:%d %x\n", contentlen, contentlen); - for (int pp = 0;pp < sendBufferSize;pp++) - { - printf("\npp:%d %d %x", pp, sendBuffer[pp], sendBuffer[pp]); - }*/ - //#endif - - //content - memcpy(sendBuffer + sendBufferSize, q_info_copy.cloud_v2_aiengine, contentlen); - sendBufferSize = sendBufferSize + contentlen; -#ifdef _DEBUG_AMBA - printf("\n[run getalarmmotion thread] sendBufferSize:%d strlen(sendBuffer):%d\n", sendBufferSize, strlen(sendBuffer)); -#endif - //================================================================ - - //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) - { - - ALMQueueInfo alm_q_info = { 0 }; - - memset(alm_q_info.pszContent, 0x00, sendBufferSize + 1); - memcpy(alm_q_info.pszContent, sendBuffer, sendBufferSize + 1); - //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); - alm_q_info.nSize = sendBufferSize + 1; - alm_q_info.infoType = 2; - //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); - if (AI_fps >= 1) { - pthread_mutex_lock(&mutex_alm); - if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) - ALMQueuePush(alm_q_info, sock_idx); - pthread_mutex_unlock(&mutex_alm); - //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d",1); - } - - /*#ifdef _DEBUG_AMBA - for (int bb = 0;bb < 15;bb++) - { - printf("\npp:%d %d %x", bb, alm_q_info.pszContent[bb], alm_q_info.pszContent[bb]); - } - printf("\n [run getalarmmotion thread] ALMQueueSize:%d\n", ALMQueueSize(sock_idx)); - #endif*/ - - } - } - - if (strcmp(SystemSetting.enable_onvif_profile_m, "Yes") == 0 && (g_sdk_version >= 5058 || strcmp(SystemSetting.enable_cloud, "Yes") == 0)) - { - //send_count = 0; - //printf("UDP 0003 \n"); - - memset(&l_unix_msg, 0, sizeof(UNIX_MESSAGE_V1_T)); - l_unix_msg.type = UNIX_MESSAGE_TYPE_RTSP_META; - - { - //printf("onvif lx, ty, rx, by = %.2f, %.2f, %.2f, %.2f \n", q_info_copy.onvif_object[0].left_x, q_info_copy.onvif_object[0].top_y, q_info_copy.onvif_object[0].right_x, q_info_copy.onvif_object[0].bottom_y); - //printf("onvif cx, cy= %.2f, %.2f \n", q_info_copy.onvif_object[0].center_x, q_info_copy.onvif_object[0].center_y); - - create_onvif_packet(&l_unix_msg, q_info_copy.onvif_object, q_info_copy.onvif_object_num,q_info_copy.onvif_counter); - //printf("l_unix_msg.buf = %s \n", l_unix_msg.buf); - } - - l_unix_msg.length = strlen(l_unix_msg.buf); - if (l_unix_msg.length >= 1) - { - //printf("[%s]\n", l_unix_msg.buf); - l_packet_len = l_unix_msg.length + sizeof(unsigned int) + sizeof(unsigned int); - - memset(l_send_buf, 0, sizeof(l_send_buf)); - - memcpy(l_send_buf, UNIX_MESSAGE_V1, sizeof(UNIX_MESSAGE_V1)); - memcpy(l_send_buf + sizeof(UNIX_MESSAGE_V1) - 1, (char *)&l_unix_msg, l_packet_len); - l_packet_len += sizeof(UNIX_MESSAGE_V1); - - { - ALMQueueInfo alm_q_info = { 0 }; - - memset(alm_q_info.pszContent, 0x00, l_packet_len + 1); - memcpy(alm_q_info.pszContent, l_send_buf, l_packet_len + 1); - //printf("\n[run getalarmmotion thread] first strlen(alm_q_info.pszContent):%d\n", strlen(alm_q_info.pszContent)); - alm_q_info.nSize = l_packet_len + 1; - alm_q_info.infoType = 6; - //printf("\n[run getalarmmotion thread] first alm_q_info.nSize:%d\n", alm_q_info.nSize); - if (AI_fps >= 1) { - pthread_mutex_lock(&mutex_alm); - if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) - ALMQueuePush(alm_q_info, sock_idx); - pthread_mutex_unlock(&mutex_alm); - } - } - } - } - - } - else if(socketRecords[i].isWebSocketConnect == TRUE) - { - //printf("\n------ALMQueueSize(sock_idx):%d\n", ALMQueueSize(sock_idx)); - //printf("\n[run getalarmmotion thread] MultiPartLen:%d\n", MultiPartLen); - //if (ALMQueueSize(sock_idx) < MAX_QUEUE_SIZE) - if(strlen(websocket_alarm) >= 1) - { - ALMQueueInfo alm_q_info = { 0 }; - //strcpy(alm_q_info.pszContent,MultiPartBuffer); - strcpy(alm_q_info.pszContent, websocket_alarm); - //strcpy(alm_q_info.websocket_content, websocket_alarm); - //alm_q_info.nSize = strlen(alm_q_info.pszContent); - alm_q_info.nSize = MultiPartLen; - alm_q_info.infoType = 5; - //printf("\n[run getalarmmotion thread] alm_q_info.nSize:%d\n", alm_q_info.nSize); - if (AI_fps >= 1) { - pthread_mutex_lock(&mutex_alm); - if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) - ALMQueuePush(alm_q_info, sock_idx); - pthread_mutex_unlock(&mutex_alm); - //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 3); - } - } - } - else if(socketRecords[i].isGetAlarmMotion == TRUE) - { - if (strlen(MultiPartBuffer) >= 1) - { - ALMQueueInfo alm_q_info = { 0 }; - strcpy(alm_q_info.pszContent, MultiPartBuffer); - //strcpy(alm_q_info.websocket_content, websocket_alarm); - //alm_q_info.nSize = strlen(alm_q_info.pszContent); - alm_q_info.nSize = MultiPartLen; - alm_q_info.infoType = 5; - //printf("\n[run getalarmmotion thread] alm_q_info.nSize:%d\n", alm_q_info.nSize); - if (AI_fps >= 1) { - pthread_mutex_lock(&mutex_alm); - if (ALMQueueSize(sock_idx) <= 10 && socketRecords[i].sock != -1) - ALMQueuePush(alm_q_info, sock_idx); - pthread_mutex_unlock(&mutex_alm); - //printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n:%d", 3); - } - } - } - } - } - set_record_process_note("run_getalarm_end"); - usSleep(10000); - //printf("\n-------run getalarmmotion end\n"); - } - else { - usSleep(10000); - } - } - - pthread_mutex_lock(&mutex_getalarmmotion); - QueueClear(_GETALARMMOTION); - pthread_mutex_unlock(&mutex_getalarmmotion); - - //printf("[run getalarmmotion thread] pthread_exit\n"); - - pthread_exit(NULL); -} - - - -#if 1 -void *run_send_udp_thread(void *ptr) -{ - pthread_detach(pthread_self()); - setPthreadName("run_udp"); - //printf("\n[run_send_udp_thread]pthread create\n"); - //printf("\n[run_send_udp_thread]no new address\n"); -#ifdef _DEBUG_AMBA - printf("\n[run_send_udp_thread] start\n"); -#endif //_DEBUG_AMBA - - //int thread_id = (int)ptr; - - int l_sockfd; - struct sockaddr_un serveraddr; - char path[64] = "/tmp/udp_unix"; - - // Creating socket file descriptor - bzero(&serveraddr, sizeof(serveraddr)); - //memset(&serveraddr, 0, sizeof(serveraddr)); - serveraddr.sun_family = AF_UNIX; - strcpy(serveraddr.sun_path, path); - - l_sockfd = socket(AF_UNIX, SOCK_DGRAM, 0); - if (l_sockfd < 0) - { - printf("\nudp socket creation failed\n"); - printf("\n[run_send_udp_thread] udp socket creation failed\n"); - } - else - { - //20210714 ADD - - int reuse = 1; - setsockopt(l_sockfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); - setsockopt(l_sockfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); - - int qlen = 5; - setsockopt(l_sockfd, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); - - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - - if (socketRecords[i].used == 0 && socketRecords[i].sock == -1) - { - socketRecords[i].sock = l_sockfd; - - //memset(&(socketRecords[i].recent_sec_data), 0x00, sizeof(SecData)); - //socketRecords[i].thread_id = 0; - socketRecords[i].channel_id = -1; - //socketRecords[i].last_recv_time = time(0); - //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; - socketRecords[i].isGetAlarmMotion = TRUE; - //socketRecords[i].isFirstAlarmMotion = FALSE; - socketRecords[i].isUdpSocket = TRUE; - socketRecords[i].isWebSocketConnect = FALSE; - socketRecords[i].isNvrRequest = 0; - socketRecords[i].isCredentialRequest = 0; - socketRecords[i].debug_type = 2; -#if defined GY_OS_AMBA - //socketRecords[i].iIsAIRelay = 0; -#endif - //printf("\n(%d) [run_send_udp_thread] socketRecords[%d].sock:%d\n", l_sockfd, i, socketRecords[i].sock); - socketRecords[i].used = 1; - break; - } - } - - while (bHttpServerThreadStart) - { - //printf("\n----------run send udp thread start\n"); - - int sock_idx = -1; - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - //if (socketRecord_ALM[i].sock == l_sockfd) { - //sock_idx = i; - //} - if (socketRecords[i].used == 1) { - if (socketRecords[i].sock == l_sockfd) - { - socketRecords[i].debug_type = 2; - //socketRecords[i].last_recv_time = time(0); - //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; - sock_idx = i; - break; - } - } - } - -#ifdef _DEBUG_AMBA - printf("\n(%d) [run_send_udp_thread] sock_idx:%d\n", l_sockfd, sock_idx); -#endif - - if (sock_idx >= 0) - { - pthread_mutex_lock(&mutex_alm); - int len = ALMQueueSize(sock_idx); - pthread_mutex_unlock(&mutex_alm); - //printf("\n(%d) [run_send_udp_thread] ALMQueueSize:%d\n", l_sockfd, len); - if (len > 0) - { - set_record_process_note("udp_start"); - //printf("\nKKKKKKKKK 1\n"); - int l_ret = 1; - - for (int index_len = 0; index_len < len; index_len++) { - pthread_mutex_lock(&mutex_alm); - ALMQueueInfo alm_q_info = ALMQueueFront(sock_idx); - int dupstr_len = alm_q_info.nSize; - //char dupstr[ALMBUFSIZE] = { 0 }; - - //memset(dupstr, 0x00, dupstr_len); - //memcpy(dupstr, alm_q_info.pszContent, dupstr_len); - - - ALMQueuePop(sock_idx); - pthread_mutex_unlock(&mutex_alm); - //printf("\nKKKKKKKKK 2\n"); - if (dupstr_len >= 1) - { - //printf("\nKKKKKKKKK 3\n"); - int l_len = strlen(serveraddr.sun_path) + sizeof(serveraddr.sun_family); - l_ret = sendto(l_sockfd, alm_q_info.pszContent, dupstr_len, 0, (struct sockaddr*)&serveraddr, l_len); - - if (l_ret <= 0) - { - printf("\n(%d) [run_send_udp_thread] send error\n", l_sockfd); - printf("\nsendto error\n"); - - if (alm_q_info.infoType == 2) { - memset(SystemSetting.cloud_v2_statue, 0x00, sizeof(SystemSetting.cloud_v2_statue)); - strcpy(SystemSetting.cloud_v2_statue, "send to ipcam: UDP fail."); - write_to_logs_html(SystemSetting.cloud_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); - } - else if (alm_q_info.infoType == 3) { - memset(SystemSetting.cloud_record_v2_statue, 0x00, sizeof(SystemSetting.cloud_record_v2_statue)); - strcpy(SystemSetting.cloud_record_v2_statue, "send to ipcam: UDP fail."); - write_to_logs_html(SystemSetting.cloud_record_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); - } - - //closesocket(l_sockfd); - break; - } - else { - if (alm_q_info.infoType == 2) { - memset(SystemSetting.cloud_v2_statue, 0x00, sizeof(SystemSetting.cloud_v2_statue)); - strcpy(SystemSetting.cloud_v2_statue, "send to ipcam: UDP OK."); - write_to_logs_html(SystemSetting.cloud_v2_statue, "send udp", "INFO", SystemSetting.enable_system_logs); - } - else if (alm_q_info.infoType == 3) { - memset(SystemSetting.cloud_record_v2_statue, 0x00, sizeof(SystemSetting.cloud_record_v2_statue)); - strcpy(SystemSetting.cloud_record_v2_statue, "send to ipcam: UDP OK."); - write_to_logs_html(SystemSetting.cloud_record_v2_statue, "send udp", "INFO", SystemSetting.enable_system_logs); - } - } - } - else { - if (alm_q_info.infoType == 2) { - memset(SystemSetting.cloud_v2_statue, 0x00, sizeof(SystemSetting.cloud_v2_statue)); - strcpy(SystemSetting.cloud_v2_statue, "send to ipcam: nSize could not be zero."); - write_to_logs_html(SystemSetting.cloud_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); - } - else if (alm_q_info.infoType == 3) { - memset(SystemSetting.cloud_record_v2_statue, 0x00, sizeof(SystemSetting.cloud_record_v2_statue)); - strcpy(SystemSetting.cloud_record_v2_statue, "send to ipcam: nSize could not be zero."); - write_to_logs_html(SystemSetting.cloud_record_v2_statue, "send udp", "ERROR", SystemSetting.enable_system_logs); - } - } - - if (index_len < len - 1) { - usSleep(10000); - } - } - - set_record_process_note("udp_end"); - if (l_ret <= 0) - { - break; - } - usSleep(10000); - } - else { - usSleep(10000); - } - } - else { - usSleep(1000000); - } - //printf("\n----------run send udp thread end\n"); - - } - - closesocket(l_sockfd); - - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - if (socketRecords[i].used == 1 && socketRecords[i].sock == l_sockfd) - { - socketRecords[i].sock = -1; - - //socketRecords[i].thread_id = 0; - socketRecords[i].channel_id = -1; - //socketRecords[i].last_recv_time = time(0); - //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; - socketRecords[i].isGetAlarmMotion = FALSE; - //socketRecords[i].isFirstAlarmMotion = FALSE; - socketRecords[i].isWebSocketConnect = FALSE; - socketRecords[i].isUdpSocket = FALSE; - socketRecords[i].isNvrRequest = 0; - socketRecords[i].isCredentialRequest = 0; - socketRecords[i].debug_type = 0; -#if defined GY_OS_AMBA - //socketRecords[i].iIsAIRelay = 0; -#endif - pthread_mutex_lock(&mutex_alm); - ALMQueueClear(i); - pthread_mutex_unlock(&mutex_alm); - - socketRecords[i].used = 0; - break; - } - } - } - - //printf("\n[run_send_udp_thread]pthread exit\n"); - pthread_exit(NULL); -} -#endif //GY_OS_AMBA - -#if GY_OS_WIN -int UpdateTrafficLightZone(int tracking_channel_idx) -{ - CPoint zone_polygon[DETECTION_POINTS_COUNT] = { 0 }; - int b_IsInsideZone = 0; - int b_ZoneExist = 0; - - int point_x = 0; - int point_y = 0; - int diagonal_x = 0; - int diagonal_y = 0; - //int zone_width = 0; - //int zone_height = 0; - int traffic_light_zone_idx = viewChannelData[tracking_channel_idx].enable_traffic_light_zone - 1; - int min_x = 1920 * 4; - int point_idx = 0; - int diagonal_idx = 0; - for (int k = 0; k < DETECTION_POINTS_COUNT; k++) - { - if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].x < min_x) - { - point_idx = k; - min_x = viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].x; - } - else if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].x == min_x) - { - if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[k].y < viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].y) - { - point_idx = k; - } - } - } - - if (point_idx + 2 >= DETECTION_POINTS_COUNT) - diagonal_idx = point_idx + 2 - DETECTION_POINTS_COUNT; - else - diagonal_idx = point_idx + 2; - - if (viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].x > 0 || viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].y > 0) - b_ZoneExist = 1; - - if (b_ZoneExist) - { - point_x = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio); - point_y = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[point_idx].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio); - diagonal_x = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[diagonal_idx].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio); - diagonal_y = (int)(viewDetectionZone[tracking_channel_idx][traffic_light_zone_idx].Points[diagonal_idx].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio); - //zone_width = diagonal_x - point_x; - //zone_height = diagonal_y - point_y; - trafficLightPoint.x = point_x; - trafficLightPoint.y = point_y; - traffic_light_zone_width = diagonal_x - point_x; - traffic_light_zone_height = diagonal_y - point_y; - } -} -#endif //GY_OS_WIN - UpdateTrafficLightZone - -#if defined GY_OS_AMBA || defined GY_OS_NOVA -void linear_regression(detection_pos** p, int pointCount, double* a, double* b) -{ - double sum_x, sum_x_sqare, sum_y, sum_xy; - double a11, a12, a21, a22, b1, b2; - - sum_x = sum_x_sqare = sum_y = sum_xy = 0.0; - - int validCount = 0; - - double count_top = 0; - double count_middle = 0; - double count_bottom = 0; - - for (int i = 0; i < pointCount; ++i) - { - if (p[i]->left_x < 1 || p[i]->top_y < 1) - continue; - else - { - if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() / 3) { - count_top++; - } - else if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() * 2 / 3) { - count_middle++; - } - else { - count_bottom++; - } - } - } - - double multi_ratio = 1; - if (count_top >= 1.0) { - multi_ratio *= count_top; - } - if (count_middle >= 1.0) { - multi_ratio *= count_middle; - } - if (count_bottom >= 1.0) { - multi_ratio *= count_bottom; - } - - //printf("\n-------count_top:%lf,count_middle:%lf,count_bottom:%lf\n", count_top, count_middle, count_bottom); - - for (int i = 0; i < pointCount; ++i) - { - if (p[i]->left_x < 1 || p[i]->top_y < 1) - continue; - else - { - double temp_multi_ratio = 1.0; - - if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() / 3) { - temp_multi_ratio = multi_ratio / count_top; - } - else if ((p[i]->top_y + p[i]->height / 2) <= (double)get_g_ori_yuv_height() * 2 / 3) { - temp_multi_ratio = multi_ratio / count_middle; - } - else { - temp_multi_ratio = multi_ratio / count_bottom; - } - - //sum_x += p[i]->left_x + p[i]->width / 2; - //sum_x_sqare += (p[i]->left_x + p[i]->width / 2) * (p[i]->left_x + p[i]->width / 2); - //sum_y += p[i]->top_y + p[i]->height / 2; - //sum_xy += (p[i]->left_x + p[i]->width / 2) * (p[i]->top_y + p[i]->height / 2); - - //printf("[%d] x,y, w,h = %f, %f, %f, %f \n", i, p[i]->left_x, p[i]->top_y, p[i]->width, p[i]->height); - - sum_x += (p[i]->left_x + p[i]->width / 2) * temp_multi_ratio; - sum_x_sqare += (p[i]->left_x + p[i]->width / 2) * (p[i]->left_x + p[i]->width / 2) * temp_multi_ratio; - //sum_y += p[i]->center_y + p[i]->height / 2; - sum_y += (p[i]->top_y + p[i]->height / 2) * temp_multi_ratio; - //sum_y += p[i]->center_y; - sum_xy += (p[i]->left_x + p[i]->width / 2) * (p[i]->top_y + p[i]->height / 2) * temp_multi_ratio; - - validCount += temp_multi_ratio; - } - } - - a11 = sum_x; - //a12 = pointCount; - a12 = validCount; - a21 = sum_x_sqare; - a22 = sum_x; - b1 = sum_y; - b2 = sum_xy; - - *a = (b1 * a22 - a12 * b2) / (a11 * a22 - a12 * a21); - *b = (a11 * b2 - a21 * b1) / (a11 * a22 - a12 * a21); - - //printf("the line is y = %lf x + %lf\n", *a, *b); -} - -void assign_row_number(detection_pos* PosInfo, detection_pos* pNext1, detection_pos* pNext2, int total_element_size, int element_size2, int parent_idx, float* arc) -{ - detection_pos *detPoints[32]; - double a = 0; - double c = 0; - double dist_tmp = 0; - double dist_up = 0; - double dist_down = 0; - float height_up = 0; - int n_lr = 0; - int element_size_lr2 = element_size2; - int name_len = 0; - - for (int n = 0; n < element_size2; n++) - { - pNext2 = PosInfo + total_element_size + n; - - //printf("\n[assign_row_number] _prefix1 pNext2->name:%s class_id:%d %d+%d=%d", pNext2->name, pNext2->class_id,total_element_size,n, total_element_size + n); - - //n_lr = n; - name_len = strlen(pNext2->name); - if (memcmp(pNext2->name, MOVE_FORWARD_PREFIX, strlen(MOVE_FORWARD_PREFIX)) == 0) - { - //printf("\n[assign_row_number] _prefix1 pNext2->name:%s", pNext2->name); - memmove(pNext2->name, pNext2->name + strlen(MOVE_FORWARD_PREFIX), name_len - strlen(MOVE_FORWARD_PREFIX)); - pNext2->name[name_len - strlen(MOVE_FORWARD_PREFIX)] = '\0'; - pNext2->number_row = 0; - pNext2->obj_type = _PREFIX; - element_size_lr2--; - continue; - } - - detPoints[n_lr] = pNext2; - n_lr++; - } - - linear_regression(detPoints, element_size_lr2, &a, &c); - *arc = atan(a); - //float degree = arch * 180 / MATH_PI; - //printf("XXXXXXXXXXXXXXXXX element_size2 = %d \n", element_size2); - - for (int j = 0; j < element_size2; j++) - { - //printf("total_element_size = %d \n", total_element_size); - - pNext2 = PosInfo + total_element_size + j; - pNext2->arc = *arc; - - //printf("\n[assign_row_number] _prefix2 pNext2->name:%s class_id:%d %d+%d=%d", pNext2->name, pNext2->class_id, total_element_size, j, total_element_size + j); - - if (pNext2->number_row == 0) - { - //printf("\n[assign_row_number] _prefix2 pNext2->name:%s", pNext2->name); - - pNext2->left_x += pNext1->left_x; - pNext2->top_y += pNext1->top_y; - pNext2->parent_idx = parent_idx; - pNext2->obj_type = _PREFIX; - continue; - } - else - { - if (featureType & FEATURE_LPR_CNT && strcmp(pNext1->name, "L._Plate_CNT_VERTICAL") == 0) { - if ((pNext2->left_x + pNext2->width / 2) <= (pNext2->top_y + pNext2->height / 2) * a + c) - { - pNext2->number_row = 1; - //double sq = sqrt(a*a + (-1)*(-1)); - dist_tmp = abs(a * (pNext2->top_y + pNext2->height / 2) - ((pNext2->left_x + pNext2->width / 2)) + c) / sqrt(a*a + 1); - if (dist_tmp > dist_up) - { - dist_up = dist_tmp; - height_up = pNext2->width; - } - } - else - { - pNext2->number_row = 2; - dist_tmp = abs(a * (pNext2->top_y + pNext2->height / 2) - ((pNext2->left_x + pNext2->width / 2)) + c) / sqrt(a*a + (-1)*(-1)); - if (dist_tmp > dist_down) - { - dist_down = dist_tmp; - height_up = pNext2->width; - } - } - } - else { - if ((pNext2->top_y + pNext2->height / 2) <= (pNext2->left_x + pNext2->width / 2) * a + c) - { - pNext2->number_row = 1; - //double sq = sqrt(a*a + (-1)*(-1)); - dist_tmp = abs(a * (pNext2->left_x + pNext2->width / 2) - ((pNext2->top_y + pNext2->height / 2)) + c) / sqrt(a*a + 1); - if (dist_tmp > dist_up) - { - dist_up = dist_tmp; - height_up = pNext2->height; - } - } - else - { - pNext2->number_row = 2; - dist_tmp = abs(a * (pNext2->left_x + pNext2->width / 2) - ((pNext2->top_y + pNext2->height / 2)) + c) / sqrt(a*a + (-1)*(-1)); - if (dist_tmp > dist_down) - { - dist_down = dist_tmp; - height_up = pNext2->height; - } - } - } - - pNext2->left_x += pNext1->left_x; - pNext2->top_y += pNext1->top_y; - pNext2->parent_idx = parent_idx; - pNext2->obj_type = _NUMBER; - //printf("Set [%d] parent idx = %d \n", j, parent_idx); - } - } - - if ((dist_up + dist_down) < height_up * 0.5 || (dist_up == 0 && dist_down == 0 && height_up == 0)) - { - for (int j = 0; j < element_size2; j++) - { - pNext2 = PosInfo + total_element_size + j; - if (pNext2->number_row == 0) - { - continue; - } - else - { - pNext2->number_row = 1; - } - } - } -} -#endif - -#if defined GY_OS_AMBA || defined GY_OS_NOVA -int SortObjects(detection_pos* PosInfo, int total_element_size) -{ - - detection_pos *pNext = NULL, *pFirstNumber = NULL; - int pre_parent_idx = -1; - int sortLogicUSA = 0; - - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - if ((pNext->engine_type == FEATURE_LPR_USA) && pNext->obj_type == _NUMBER) - { - sortLogicUSA = 1; - if (pNext->parent_idx != pre_parent_idx) - { - pFirstNumber = pNext; - pNext->visual_left_x = pNext->left_x; - pre_parent_idx = pNext->parent_idx; - } - else - { - for (int j = 0; j < pNext - pFirstNumber; j++) - { - if ((pFirstNumber + j)->obj_type == _PREFIX) - continue; - if (pNext->left_x + pNext->width / 2 > (pFirstNumber + j)->left_x && pNext->left_x + pNext->width / 2 < (pFirstNumber + j)->left_x + (pFirstNumber + j)->width) - { - pNext->visual_left_x = (pFirstNumber + j)->visual_left_x; - break; - } - else { - pNext->visual_left_x = pNext->left_x; - } - } - } - } - else - { - pNext->visual_left_x = pNext->left_x; - } - } - return sortLogicUSA; - -} -#endif //GY_OS_WIN - SortObjects - -#if 1 -void SetCorrectClassID(detection_pos *PosInfo, int total_element_size, int element_size1) -{ - detection_pos *pNext = NULL, *pNext2 = NULL; - - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - int nDistance_y = 2160; - - if (g_IsToFDevice == 1) { - if (pNext->class_id == 1) {//hand - pNext->class_id = 250; - } - } - else if (strcmp(pNext->name, "person")==0) { - pNext->class_id = 0; - } - else if (strcmp(pNext->name, "bicycle")==0) { - pNext->class_id = 1; - } - else if (strcmp(pNext->name, "car")==0) { - pNext->class_id = 2; - } - else if (strcmp(pNext->name, "motorbike")==0) { - pNext->class_id = 3; - } - else if (strcmp(pNext->name, "bus")==0) { - pNext->class_id = 5; - } - else if (strcmp(pNext->name, "truck")==0) { - pNext->class_id = 7; - } - else if(IsANPRCategory_L_Plate(pNext->name)){ - if (strcmp(pNext->name, "ambulance") == 0) { - pNext->class_id = 104; - } - - if (strcmp(pNext->name, "stop_sign") == 0) { - pNext->class_id = 11; - } - - if (strncmp(pNext->name, "L._Plate_",9) == 0) { - pNext->class_id = 900; - } - - if (strcmp(pNext->name, "face") == 0) { - pNext->class_id = 0; - } - } - else if (IsANPRCategory(pNext->engine_type)) { - if ((pNext->engine_type & FEATURE_LPR_THA)) { - //泰國車牌 特殊1到9的class_id變成一般的1到9 - if (pNext->class_id >= 39 && pNext->class_id <= 47) - { - pNext->class_id -= 38; - } - } - } - else { - -#ifdef GY_OS_AMBA - if (strcmp(WeightFileModeName, "mod004") == 0) - { - if ((pNext->engine_type & FEATURE_TRAF_DET) && - ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) - )) ///Steven TEMP MARK - { - if (pNext->class_id == 15)//cat - { - pNext->class_id = 247; - } - else if (pNext->class_id == 16)//dog - { - pNext->class_id = 248; - } - else if (pNext->class_id == 8)//boat - { - pNext->class_id = 158; - } - } - } - else { - if (strcmp(heartbeatData.events_default_version, "4") == 0) { - if ((pNext->engine_type & FEATURE_TRAF_DET) && - ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) - )) ///Steven TEMP MARK - { - if (pNext->class_id == 15)//cat - { - pNext->class_id = 247; - } - else if (pNext->class_id == 16)//dog - { - pNext->class_id = 248; - } - else if (pNext->class_id == 5)//bus - { - pNext->class_id = 2; - } - else if (pNext->class_id == 6)//train - { - pNext->class_id = 2; - } - else if (pNext->class_id == 7)//truck - { - pNext->class_id = 2; - } - } - } - else { - if ((pNext->engine_type & FEATURE_TRAF_DET) && - ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) - )) ///Steven TEMP MARK - { - if (pNext->class_id == 15)//cat - { - pNext->class_id = 247; - } - else if (pNext->class_id == 16)//dog - { - pNext->class_id = 248; - } - } - } - } -#else - if ((pNext->engine_type & FEATURE_TRAF_DET) && - ((pNext->engine_type2 & FEATURE_AIFLOW) || (pNext->engine_type2 & FEATURE_AIAREA) || (pNext->engine_type2 & FEATURE_AICAP) - )) ///Steven TEMP MARK - { - if (pNext->class_id == 15)//cat - { - pNext->class_id = 247; - } - else if (pNext->class_id == 16)//dog - { - pNext->class_id = 248; - } - } -#endif - - if ((pNext->engine_type & FEATURE_TRAF_DET) && (pNext->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0) - { - if (pNext->class_id == 39 || - pNext->class_id == 40 || - pNext->class_id == 114) { - pNext->class_id = 39; - } - else if (pNext->class_id == 41 || - pNext->class_id == 45) { - pNext->class_id = 41; - } - else if (pNext->class_id == 110 || - pNext->class_id == 115) { - pNext->class_id = 433; - } - else if (pNext->class_id == 111 || - pNext->class_id == 112) { - pNext->class_id = 19; - } - else if (pNext->class_id == 116 || - pNext->class_id == 117) { - pNext->class_id = 102; - } - else if (pNext->class_id == 118 || - pNext->class_id == 120) { - pNext->class_id = 99; - } - } - - if ((pNext->engine_type & FEATURE_AIFIRE)) - { - //printf("fire id = %d \n", pNext->class_id); - - if (pNext->class_id <= 3) - { - pNext->class_id += 105; - } - else if (pNext->class_id == 6 || pNext->class_id == 7) - { - pNext->class_id += 314; - } - else { - pNext->class_id += 141; - } - } - - if ((pNext->engine_type & FEATURE_TRAF_DET) && (pNext->engine_type2 & FEATURE_AIAREO)) - { - pNext->class_id += 136; - } - - //printf("\nFEATURE_HUM_DET---1\n"); - - if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIMASK)) - { - //printf("fire id = %d \n", pNext->class_id); - if (strcmp(WeightFileModeName, "mod003") != 0) { - if (pNext->class_id == 88) - { - pNext->class_id = 80; //face - } - else if (pNext->class_id == 89) - { - pNext->class_id = 81; //half_mask - } - else if (pNext->class_id == 90) - { - pNext->class_id = 82; //mask - } - } - else { - pNext->class_id += 140; - } - } - - if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIHELM)) - { - if (pNext->class_id >= 95 && pNext->class_id <= 97) { - pNext->class_id += 1; - } - else if(pNext->class_id == 98){ - pNext->class_id = 318; - } - else if (pNext->class_id >= 99) { - pNext->class_id += 271; - } - } - - if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AISHIP)) - { - //printf("fire id = %d \n", pNext->class_id); - pNext->class_id += 150; - } - - if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIPRODUCTION)) - { - //printf("fire id = %d \n", pNext->class_id); - - pNext->class_id += 430; - } - - if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIAML)) - { - if (strcmp(WeightFileModeName, "mod003") != 0) { - //printf("fire id = %d \n", pNext->class_id); - pNext->class_id += 167; - } - else { - pNext->class_id += 340; - } - } - - if ((pNext->engine_type & FEATURE_HUM_DET) && (pNext->engine_type2 & FEATURE_AIRADAR)) - { - // printf("radar id = %d \n", pNext->class_id); - pNext->class_id += 950; - } - - if ((pNext->engine_type & FEATURE_AIRAIL) && (pNext->engine_type2 & FEATURE_AIFLOW)) - { - if (pNext->class_id >= 3) { - pNext->class_id += 111; - } - else if (pNext->class_id == 9) { - pNext->class_id = 129; - } - else { - pNext->class_id += 110; - } - } - - if ((pNext->engine_type & FEATURE_TRAF_DET) && (pNext->engine_type2 & FEATURE_AISPORTS) && strcmp(WeightFileModeName, "mod002") == 0) - { - pNext->class_id += 400; - } - - if ((pNext->engine_type & FEATURE_TRAF_DET)) - { -/*#ifdef GY_OS_AMBA - if (pNext->class_id == 80) - { - pNext->class_id = 88; // TUK TUK - } - else if (pNext->class_id == 81) - { - pNext->class_id = 89; // Truck trailer - } - else if (pNext->class_id == 82) - { - pNext->class_id = 90; // Pickup truck - } -#else - if ( - pNext->class_id == 81 || - pNext->class_id == 82 || - pNext->class_id == 85 - ) - { - pNext->class_id = 2; - } - else if ( - pNext->class_id == 6 || - pNext->class_id == 80 || - pNext->class_id == 83 || - pNext->class_id == 131 || - pNext->class_id == 132 || - pNext->class_id == 133 || - pNext->class_id == 134 - ) { - pNext->class_id = 7; - } -#endif*/ - } - - if ((pNext->engine_type & FEATURE_LPR_LOGO)) - { - pNext->class_id += 500; - - detection_pos* pDistance = NULL; - for (int j = 0; j < total_element_size; j++) - { - pNext2 = PosInfo + j; - if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) - { - if (pNext->left_x > pNext2->left_x && (pNext->left_x + pNext->width) < (pNext2->left_x + pNext2->width) && pNext->top_y < pNext2->top_y) - { - if (pNext2->top_y - pNext->top_y < nDistance_y) - { - nDistance_y = pNext2->top_y - pNext->top_y; - pDistance = pNext2; - } - } - } - } - if (pDistance) { - - char temp_buf[50] = { 0 }; - int index_temp_buf = 0; - - for (int m = 0; m < (int)strlen(pNext->name); m++) { - if (m < (int)strlen(pNext->name) - 1 && pNext->name[m] == 'l' && pNext->name[m + 1] == '_') { - m++; - } - else { - temp_buf[index_temp_buf] = pNext->name[m]; - index_temp_buf++; - } - } - temp_buf[index_temp_buf] = '\0'; - - snprintf(pDistance->properties.logo, sizeof(pDistance->properties.logo), "%s", temp_buf); - snprintf(pDistance->logo, sizeof(pDistance->logo), "%s", temp_buf); - } - } - } - } - -} -#endif //GY_OS_WIN - SetCorrectClassID - -#if defined GY_OS_AMBA || defined GY_OS_NOVA -int IsMatchAUSPattern(char* PlatePattern, char* area) -{ - int nMatchPattern = 0; - if (RegexMatch(PlatePattern, REGEX_LPR_AUS_ACT_VEH)) - { - char *local = "ACT"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NSW_VEH)) - { - char *local = "NSW"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NSW_SLI)) - { - char *local = "NSW"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NTE_VEH)) - { - char *local = "NT"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_QUE_VEH)) - { - char *local = "QUEENSLAND"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_SAU_VEH)) - { - char *local = "SA"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_TAS_VEH)) - { - char *local = "Tasmania"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_VIC_VEH)) - { - char *local = "VICTORIA"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_WAU_VEH)) - { - char *local = "WA"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_ACT_VEH_PRE)) - { - char *local = "ACT"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_AUS_NSW_VEH_PRE)) - { - char *local = "NSW"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else - { - char *local = ""; - memcpy(area, local, strlen(local)); - nMatchPattern = 0; - } - - return nMatchPattern; -} -#endif //GY_OS_WIN - IsMatchAUSPattern - -#if defined GY_OS_AMBA || defined GY_OS_NOVA -int IsMatchGBRPattern(char* PlatePattern, char* area) -{ - int nMatchPattern = 0; - if (RegexMatch(PlatePattern, REGEX_LPR_GBR_CUR_VEH)) - { - char *local = ""; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH)) - { - char *local = ""; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH2)) - { - char *local = ""; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else - { - for (int i = 0; i < strlen(PlatePattern); i++) - { - if (*(PlatePattern + i) == '-') - memmove(PlatePattern + i, PlatePattern + i + 1, strlen(PlatePattern) - i); - } - - if (RegexMatch(PlatePattern, REGEX_LPR_GBR_CUR_VEH_)) - { - char *local = ""; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH_)) - { - char *local = ""; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_GBR_OLD_VEH2_)) - { - char *local = ""; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else - { - char *local = ""; - memcpy(area, local, strlen(local)); - nMatchPattern = 0; - } - } - - return nMatchPattern; -} -#endif //GY_OS_WIN - IsMatchGBRPattern - -#if defined GY_OS_AMBA || defined GY_OS_NOVA -int IsMatchIDNPattern(char* PlatePattern, char* area) -{ - int nMatchPattern = 0; - if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BANT_VEH)) - { - char *local = "Banten"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA1_VEH)) - { - char *local = "Central Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_YOG1_VEH)) - { - char *local = "Yogyakarta"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA2_VEH)) - { - char *local = "Central Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA1_VEH)) - { - char *local = "East Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA2_VEH)) - { - char *local = "East Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_JAKA_VEH)) - { - char *local = "Jakarta"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WSUM_VEH)) - { - char *local = "West Sumatra"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WCNS_VEH)) - { - char *local = "West coast of North Sumatra"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BENG_VEH)) - { - char *local = "Bengkulu"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_LAMP_VEH)) - { - char *local = "Lampung"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSUM_VEH)) - { - char *local = "South Sumatra"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_JAMB_VEH)) - { - char *local = "Jambi"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ECNS_VEH)) - { - char *local = "East coast of North Sumatra"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ACEH_VEH)) - { - char *local = "Aceh"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_RIAU_VEH)) - { - char *local = "Riau"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BBEL_VEH)) - { - char *local = "Bangka Belitung"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_RISL_VEH)) - { - char *local = "Riau Islands"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA1_VEH)) - { - char *local = "West Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SKAL_VEH)) - { - char *local = "South Kalimantan"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NSU1_VEH)) - { - char *local = "North Sulawesi"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WSUL_VEH)) - { - char *local = "West Sulawesi"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSU1_VEH)) - { - char *local = "South Sulawesi"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_MALU_VEH)) - { - char *local = "Maluku"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NMAL_VEH)) - { - char *local = "North Maluku"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ENTT_VEH)) - { - char *local = "East Nusa Tenggara"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_BALI_VEH)) - { - char *local = "Bali"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NSU2_VEH)) - { - char *local = "North Sulawesi"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_GORO_VEH)) - { - char *local = "Gorontalo"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CSUL_VEH)) - { - char *local = "Central Sulawesi"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSU2_VEH)) - { - char *local = "South Sulawesi"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WNTL_VEH)) - { - char *local = "West Nusa Tenggara"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SESU_VEH)) - { - char *local = "Southeast Sulawesi"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SSU3_VEH)) - { - char *local = "South Sulawesi"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA2_VEH)) - { - char *local = "West Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WNTS_VEH)) - { - char *local = "West Nusa Tenggara"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ENTF_VEH)) - { - char *local = "East Nusa Tenggara"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_ENTS_VEH)) - { - char *local = "East Nusa Tenggara"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA3_VEH)) - { - char *local = "West Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA3_VEH)) - { - char *local = "Central Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA4_VEH)) - { - char *local = "Central Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA5_VEH)) - { - char *local = "Central Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WKAL_VEH)) - { - char *local = "West Kalimantan"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CKAL_VEH)) - { - char *local = "Central Kalimantan"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EKAL_VEH)) - { - char *local = "East Kalimantan"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_NKAL_VEH)) - { - char *local = "North Kalimantan"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA3_VEH)) - { - char *local = "East Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA4_VEH)) - { - char *local = "East Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA5_VEH)) - { - char *local = "East Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA6_VEH)) - { - char *local = "East Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_PAPU_VEH)) - { - char *local = "Papua"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WPAP_VEH)) - { - char *local = "West Papua"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_CJA6_VEH)) - { - char *local = "Central Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA7_VEH)) - { - char *local = "East Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_SURA_VEH)) - { - char *local = "Surabaya"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA4_VEH)) - { - char *local = "West Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_EJA8_VEH)) - { - char *local = "East Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_YOG2_VEH)) - { - char *local = "Yogyakarta"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_YOG3_VEH)) - { - char *local = "Yogyakarta"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else if (RegexMatch(PlatePattern, REGEX_LPR_IDN_WJA5_VEH)) - { - char *local = "West Java"; - memcpy(area, local, strlen(local)); - nMatchPattern = 1; - } - else - { - char *local = ""; - memcpy(area, local, strlen(local)); - nMatchPattern = 0; - } - - return nMatchPattern; -} -#endif //GY_OS_WIN - IsMatchIDNPattern - -#if defined GY_OS_AMBA || defined GY_OS_NOVA -int PlatePatternParser(detection_pos* PosInfo, int total_element_size, size_t featureType/*, float arc*/) -{ - //printf("\n[PlatePatternParser] start\n"); - detection_pos *pNext = PosInfo; - //detection_pos *pBeginIndex = NULL; - int nNumCount = 0; - int result = 0; - char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; - char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; - char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; - /*char country[30] = { 0 }; - char area[30] = { 0 };*/ - int Index0orO = 0, Index1orI = 0, IndexPattern = 0; - //char *dash = "-"; - - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - - if (pNext->engine_type & FEATURE_LPR_TWN) - { - char country[30] = { 0 }; - char area[30] = { 0 }; - sprintf(country, "%s", "TWN"); - //detection_pos *pNext = PosInfo; - //int nNumCount = 0; - - //測試用假資料 - //for (int i = 0; i < total_element_size; i++) - //{ - //pNext = PosInfo + i; - //sprintf(pNext->name, "%s", "1"); - //pNext->confidence = 35; - //pNext->left_x = 165; - //pNext->top_y = 127; - //pNext->width = 4; - //pNext->height = 26; - //pNext->obj_type == _NUMBER; - //} - - if (pNext->obj_type == _NUMBER) - nNumCount++; - else - continue; - - if (nNumCount == 1) - { - snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - - //if (strcmp(pNext->name, "1") == 0) - { - //Taiwan plates have max 7 numbers, if the most left number's width is smaller than half normal width, remove it. - if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 18 || pNext->width < 5) && - (pNext->left_x - (PosInfo + pNext->parent_idx)->left_x < (PosInfo + pNext->parent_idx)->width / 18)) - { - //pNext->obj_type = _MISTAKE; - //result++; - } - } - } - else - { - pNext->arc = (pNext->arc > 0) ? pNext->arc : -pNext->arc; - //float angle = arc * 180 / MATH_PI; -#if 0 - if (activeDisplayDash) - { - if (pNext->arc > 5 * (2 * MATH_PI / 360)) //angle is greater than 5 degrees, caculate number distances more precisely - { - float distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - ((pNext - 1)->left_x + (pNext - 1)->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - ((pNext - 1)->top_y + (pNext - 1)->height / 2), 2)); - //float distWidth1 = ((pNext - 1)->width - (pNext - 1)->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); - //float distWidth2 = (pNext->width - pNext->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); - float distWidth1 = (pNext - 1)->width / 2; - float distWidth2 = pNext->width / 2; - - if (distCenter > (distWidth1 + distWidth2)*1.22) - { - pNext->obj_type = _DASH; - pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; - } - } - else - { - float distCenter = pNext->left_x + pNext->width / 2 - ((pNext - 1)->left_x + (pNext - 1)->width / 2); - float distWidth1 = (pNext - 1)->width / 2; - float distWidth2 = pNext->width / 2; - - if (distCenter > (distWidth1 + distWidth2)*1.22) - { - pNext->obj_type = _DASH; - pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; - } - } - } -#endif - - if ((i < total_element_size - 1 && pNext->parent_idx != (pNext + 1)->parent_idx) || i == total_element_size - 1) - { - //snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); - //snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - - //if (strcmp(pNext->name, "1") == 0) - { - //Taiwan plates have max 7 + 1 numbers(plus dash), if the most right number's width is smaller than 1/3 normal width, remove it. - if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 24 || pNext->width < 4) && - ((PosInfo + pNext->parent_idx)->left_x + (PosInfo + pNext->parent_idx)->width - (pNext->left_x + pNext->width) < (PosInfo + pNext->parent_idx)->width / 24)) - { - //pNext->obj_type = _MISTAKE; - //result++; - } - } - nNumCount = 0; - } - } - } -#if 0 - else if (pNext->engine_type & FEATURE_LPR_EUR) - { - char country[30] = { 0 }; - char area[30] = { 0 }; - sprintf(country, "%s", "EUR");//European //EU/UK/IN - //detection_pos *pNext = PosInfo; - //int nNumCount = 0; - - //測試用假資料 - /*for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - sprintf(pNext->name, "%s", "1"); - pNext->confidence = 35; - pNext->left_x = 165; - pNext->top_y = 127; - pNext->width = 4; - pNext->height = 26; - pNext->obj_type == _NUMBER; - }*/ - - if (pNext->obj_type == _NUMBER) - nNumCount++; - else - continue; - - if (nNumCount == 1) - { - snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - - //if (strcmp(pNext->name, "1") == 0) - { - //Taiwan plates have max 7 numbers, if the most left number's width is smaller than half normal width, remove it. - if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 18 || pNext->width < 5) && - (pNext->left_x - (PosInfo + pNext->parent_idx)->left_x < (PosInfo + pNext->parent_idx)->width / 18)) - { - //pNext->obj_type = _MISTAKE; - //result++; - } - } - } - else - { - arc = (arc > 0) ? arc : -arc; - //float angle = arc * 180 / MATH_PI; - if (activeDisplayDash) - { - if (arc > 5 * (2 * MATH_PI / 360)) //angle is greater than 5 degrees, caculate number distances more precisely - { - float distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - ((pNext - 1)->left_x + (pNext - 1)->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - ((pNext - 1)->top_y + (pNext - 1)->height / 2), 2)); - //float distWidth1 = ((pNext - 1)->width - (pNext - 1)->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); - //float distWidth2 = (pNext->width - pNext->height*tan(arc)) / (cos(arc) - sin(arc)*tan(arc)); - float distWidth1 = (pNext - 1)->width / 2; - float distWidth2 = pNext->width / 2; - - if (distCenter > (distWidth1 + distWidth2)*1.22) - { - pNext->obj_type = _DASH; - pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; - } - } - else - { - float distCenter = pNext->left_x + pNext->width / 2 - ((pNext - 1)->left_x + (pNext - 1)->width / 2); - float distWidth1 = (pNext - 1)->width / 2; - float distWidth2 = pNext->width / 2; - - if (distCenter > (distWidth1 + distWidth2)*1.22) - { - pNext->obj_type = _DASH; - pNext->dash_left_x = (((pNext - 1)->left_x + (pNext - 1)->width / 2) + (pNext->left_x + pNext->width / 2)) / 2 - pNext->width / 2; - } - } - } - - if ((i < total_element_size - 1 && pNext->parent_idx != (pNext + 1)->parent_idx) || i == total_element_size - 1) - { - //snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); - //snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - - //if (strcmp(pNext->name, "1") == 0) - { - //Taiwan plates have max 7 + 1 numbers(plus dash), if the most right number's width is smaller than 1/3 normal width, remove it. - if ((pNext->width < (PosInfo + pNext->parent_idx)->width / 24 || pNext->width < 4) && - ((PosInfo + pNext->parent_idx)->left_x + (PosInfo + pNext->parent_idx)->width - (pNext->left_x + pNext->width) < (PosInfo + pNext->parent_idx)->width / 24)) - { - //pNext->obj_type = _MISTAKE; - //result++; - } - } - nNumCount = 0; - } - } - } -#endif -#if 0 - else if (pNext->engine_type & FEATURE_LPR_AUS) - { - /*char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; - char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; - char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; - int Index0orO = 0, Index1orI = 0, IndexPattern = 0; - char *dash = "-"; - detection_pos *pNext = PosInfo*/ - //for (int i = 0; i < total_element_size; i++) - //{ - pNext = PosInfo + i; - if (pNext->parent_idx < 0) - continue; - - if (IndexPattern == 0) - { - PossiblePlate[IndexPattern] = pNext->name; - IndexPattern++; - //pBeginIndex = PosInfo + i; - if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) - { - ElementPos0orO[Index0orO] = pNext->name; - Index0orO++; - } - /*if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) - { - ElementPos1orI[Index1orI] = pNext->name; - Index1orI++; - }*/ - } - else - { - if ((pNext->left_x - (pNext - 1)->left_x) > (pNext->width / 2 + (pNext - 1)->width / 2)*1.2) - { - PossiblePlate[IndexPattern] = dash; - IndexPattern++; - } - PossiblePlate[IndexPattern] = pNext->name; - IndexPattern++; - if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) - { - ElementPos0orO[Index0orO] = pNext->name; - Index0orO++; - } - /*if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) - { - ElementPos1orI[Index1orI] = pNext->name; - Index1orI++; - }*/ - - if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) - { - if (Index0orO <= 0 && Index1orI <= 0) - { - int m = 0; - char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; - while (PossiblePlate[m] != NULL) - { - PlatePattern[m] = *PossiblePlate[m]; - m++; - } - - char area[30] = { 0 }; - int bMatch = IsMatchAUSPattern(PlatePattern, area); - if (bMatch) - { - snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "AUS"); - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - } - } - else if (Index0orO > 0) - { - int rows = pow(2, Index0orO); - int **array; - array = malloc(rows * sizeof *array); - for (int i = 0; i < rows; i++) - { - array[i] = malloc(Index0orO * sizeof *array[i]); - } - int *each = malloc(Index0orO * sizeof(int)); - int c = 0; - BinaryDFS(0, Index0orO, each, array, &c); - for (int i = 0; i < rows; i++) - { - for (int j = 0; j < Index0orO; j++) - { - if (array[i][j] == _0) - *ElementPos0orO[j] = '0'; - else if (array[i][j] == _O) - *ElementPos0orO[j] = 'O'; - } - //printf("\n"); - if (Index0orO > 0 && Index1orI <= 0) - { - int m = 0; - char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; - while (PossiblePlate[m] != NULL) - { - PlatePattern[m] = *PossiblePlate[m]; - m++; - } - - char area[30] = { 0 }; - int bMatch = IsMatchAUSPattern(PlatePattern, area); - if (bMatch) - { - snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "AUS"); - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - break; - } - } - } - if (each) { - free(each); - each = NULL; - } - for (int i = 0; i < rows; i++) { - if (array[i]) { - free(array[i]); - array[i] = NULL; - } - } - if (array) { - free(array); - array = NULL; - } - } - - for (int i = 0; i < MAX_PLATE_NUMBER; i++) - { - ElementPos0orO[i] = NULL; - ElementPos1orI[i] = NULL; - PossiblePlate[i] = NULL; - IndexPattern = 0; - Index0orO = 0; - Index1orI = 0; - } - } - } - //} - } -#endif -#if 0 - else if (pNext->engine_type & FEATURE_LPR_EUR)//FEATURE_LPR_GBR - { - /*char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; - char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; - char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; - int Index0orO = 0, Index1orI = 0, IndexPattern = 0; - char *dash = "-"; - detection_pos *pNext = PosInfo*/ - //for (int i = 0; i < total_element_size; i++) - //{ - pNext = PosInfo + i; - if (pNext->parent_idx < 0) - continue; - - if (IndexPattern == 0) - { - PossiblePlate[IndexPattern] = pNext->name; - IndexPattern++; - //pBeginIndex = PosInfo + i; - if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) - { - ElementPos0orO[Index0orO] = pNext->name; - Index0orO++; - } - if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) - { - ElementPos1orI[Index1orI] = pNext->name; - Index1orI++; - } - } - else - { - /*if ((pNext->left_x - (pNext - 1)->left_x) > (pNext->width / 2 + (pNext - 1)->width / 2)*1.2) - { - PossiblePlate[IndexPattern] = dash; - IndexPattern++; - }*/ - PossiblePlate[IndexPattern] = pNext->name; - IndexPattern++; - if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) - { - ElementPos0orO[Index0orO] = pNext->name; - Index0orO++; - } - if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) - { - ElementPos1orI[Index1orI] = pNext->name; - Index1orI++; - } - - if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) - { - if (Index0orO <= 0 && Index1orI <= 0) - { - int m = 0; - char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; - while (PossiblePlate[m] != NULL) - { - PlatePattern[m] = *PossiblePlate[m]; - m++; - } - - char area[30] = { 0 }; - int bMatch = IsMatchGBRPattern(PlatePattern, area); - snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - /*for (int i = 0; i < (pNext - (pBeginIndex - 1)); i++) - { - snprintf((pBeginIndex + i)->properties.country, sizeof(area), "%s", "GBR"); - snprintf((pBeginIndex + i)->properties.area, sizeof(area), "%s", area); - }*/ - if (bMatch) - break; - } - else if (Index0orO > 0) - { - int rows = pow(2, Index0orO); - int **array; - array = malloc(rows * sizeof *array); - for (int i = 0; i < rows; i++) - { - array[i] = malloc(Index0orO * sizeof *array[i]); - } - int *each = malloc(Index0orO * sizeof(int)); - int c = 0; - BinaryDFS(0, Index0orO, each, array, &c); - for (int i = 0; i < rows; i++) - { - for (int j = 0; j < Index0orO; j++) - { - if (array[i][j] == _0) - *ElementPos0orO[j] = '0'; - else if (array[i][j] == _O) - *ElementPos0orO[j] = 'O'; - } - - if (Index0orO > 0 && Index1orI <= 0) - { - int m = 0; - char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; - while (PossiblePlate[m] != NULL) - { - PlatePattern[m] = *PossiblePlate[m]; - m++; - } - - char area[30] = { 0 }; - int bMatch = IsMatchGBRPattern(PlatePattern, area); - if (bMatch) - { - snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - break; - } - - } - else if (Index0orO > 0 && Index1orI > 0) - { - int rows2 = pow(2, Index1orI); - int **array2; - array2 = malloc(rows2 * sizeof *array2); - for (int index_i = 0; index_i < rows2; index_i++) - { - array2[index_i] = malloc(Index1orI * sizeof *array2[index_i]); - } - - int *each2 = malloc(Index1orI * sizeof(int)); - int c = 0; - BinaryDFS(0, Index1orI, each2, array2, &c); - for (int index_i = 0; index_i < rows2; index_i++) - { - for (int index_j = 0; index_j < Index1orI; index_j++) - { - if (array2[index_i][index_j] == _1) - *ElementPos1orI[index_j] = '1'; - else if (array2[index_i][index_j] == _I) - *ElementPos1orI[index_j] = 'I'; - } - - int m = 0; - char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; - while (PossiblePlate[m] != NULL) - { - PlatePattern[m] = *PossiblePlate[m]; - m++; - } - - char area[30] = { 0 }; - int bMatch = IsMatchGBRPattern(PlatePattern, area); - if (bMatch) - { - snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - break; - } - } - - for (int index_i = 0; index_i < rows2; index_i++) { - if (array2[index_i] != NULL) { - free(array2[index_i]); - array2[index_i] = NULL; - } - } - if (array2 != NULL) { - free(array2); - array2 = NULL; - } - - if (each2 != NULL) { - free(each2); - each2 = NULL; - } - } - } - - for (int i = 0; i < rows; i++) { - if (array[i] != NULL) { - free(array[i]); - array[i] = NULL; - } - } - if (array != NULL) { - free(array); - array = NULL; - } - - if (each != NULL) { - free(each); - each = NULL; - } - } - else if (Index1orI > 0) - { - int rows = pow(2, Index1orI); - int **array; - array = malloc(rows * sizeof *array); - for (int i = 0; i < rows; i++) - { - array[i] = malloc(Index1orI * sizeof *array[i]); - } - int *each = malloc(Index1orI * sizeof(int)); - int c = 0; - BinaryDFS(0, Index1orI, each, array, &c); - for (int i = 0; i < rows; i++) - { - for (int j = 0; j < Index1orI; j++) - { - if (array[i][j] == _1) - *ElementPos1orI[j] = '1'; - else if (array[i][j] == _I) - *ElementPos1orI[j] = 'I'; - //printf("%d", array[i][j]); - } - //printf("\n"); - int m = 0; - char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; - while (PossiblePlate[m] != NULL) - { - PlatePattern[m] = *PossiblePlate[m]; - m++; - } - - char area[30] = { 0 }; - int bMatch = IsMatchGBRPattern(PlatePattern, area); - if (bMatch) - { - snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "EUR"); - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - break; - } - } - - for (int i = 0; i < rows; i++) { - if (array[i] != NULL) { - free(array[i]); - array[i] = NULL; - } - } - if (array != NULL) { - free(array); - array = NULL; - } - - if (each != NULL) { - free(each); - each = NULL; - } - } - - for (int i = 0; i < MAX_PLATE_NUMBER; i++) - { - ElementPos0orO[i] = NULL; - ElementPos1orI[i] = NULL; - PossiblePlate[i] = NULL; - IndexPattern = 0; - Index0orO = 0; - Index1orI = 0; - } - } - } - //} - } -#endif -#if 1 - else if (pNext->engine_type & FEATURE_LPR_GBR) - { - /*char *ElementPos0orO[MAX_PLATE_NUMBER] = { 0 }; - char *ElementPos1orI[MAX_PLATE_NUMBER] = { 0 }; - char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; - int Index0orO = 0, Index1orI = 0, IndexPattern = 0; - char *dash = "-"; - detection_pos *pNext = PosInfo*/ - //for (int i = 0; i < total_element_size; i++) - //{ - pNext = PosInfo + i; - if (pNext->parent_idx < 0) - continue; - - if (IndexPattern == 0) - { - PossiblePlate[IndexPattern] = pNext->name; - IndexPattern++; - //pBeginIndex = PosInfo + i; - if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) - { - ElementPos0orO[Index0orO] = pNext->name; - Index0orO++; - } - if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) - { - ElementPos1orI[Index1orI] = pNext->name; - Index1orI++; - } - } - else - { - /*if ((pNext->left_x - (pNext - 1)->left_x) > (pNext->width / 2 + (pNext - 1)->width / 2)*1.2) - { - PossiblePlate[IndexPattern] = dash; - IndexPattern++; - }*/ - PossiblePlate[IndexPattern] = pNext->name; - IndexPattern++; - if (strcmp(pNext->name, "0") == 0 || strcmp(pNext->name, "O") == 0) - { - ElementPos0orO[Index0orO] = pNext->name; - Index0orO++; - } - if (strcmp(pNext->name, "1") == 0 || strcmp(pNext->name, "I") == 0) - { - ElementPos1orI[Index1orI] = pNext->name; - Index1orI++; - } - - if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) - { - if (Index0orO <= 0 && Index1orI <= 0) - { - int m = 0; - char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; - while (PossiblePlate[m] != NULL) - { - PlatePattern[m] = *PossiblePlate[m]; - m++; - } - - char area[30] = { 0 }; - int bMatch = IsMatchGBRPattern(PlatePattern, area); - snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - /*for (int i = 0; i < (pNext - (pBeginIndex - 1)); i++) - { - snprintf((pBeginIndex + i)->properties.country, sizeof(area), "%s", "GBR"); - snprintf((pBeginIndex + i)->properties.area, sizeof(area), "%s", area); - }*/ - if (bMatch) - break; - } - else if (Index0orO > 0) - { - int rows = pow(2, Index0orO); - int **array; - array = malloc(rows * sizeof *array); - for (int i = 0; i < rows; i++) - { - array[i] = malloc(Index0orO * sizeof *array[i]); - } - int *each = malloc(Index0orO * sizeof(int)); - int c = 0; - BinaryDFS(0, Index0orO, each, array, &c); - for (int i = 0; i < rows; i++) - { - for (int j = 0; j < Index0orO; j++) - { - if (array[i][j] == _0) - *ElementPos0orO[j] = '0'; - else if (array[i][j] == _O) - *ElementPos0orO[j] = 'O'; - } - - if (Index0orO > 0 && Index1orI <= 0) - { - int m = 0; - char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; - while (PossiblePlate[m] != NULL) - { - PlatePattern[m] = *PossiblePlate[m]; - m++; - } - - char area[30] = { 0 }; - int bMatch = IsMatchGBRPattern(PlatePattern, area); - if (bMatch) - { - snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - break; - } - - } - else if (Index0orO > 0 && Index1orI > 0) - { - int rows2 = pow(2, Index1orI); - int **array2; - array2 = malloc(rows2 * sizeof *array2); - for (int index_i = 0; index_i < rows2; index_i++) - { - array2[index_i] = malloc(Index1orI * sizeof *array2[index_i]); - } - - int *each2 = malloc(Index1orI * sizeof(int)); - int c = 0; - BinaryDFS(0, Index1orI, each2, array2, &c); - for (int index_i = 0; index_i < rows2; index_i++) - { - for (int index_j = 0; index_j < Index1orI; index_j++) - { - if (array2[index_i][index_j] == _1) - *ElementPos1orI[index_j] = '1'; - else if (array2[index_i][index_j] == _I) - *ElementPos1orI[index_j] = 'I'; - } - - int m = 0; - char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; - while (PossiblePlate[m] != NULL) - { - PlatePattern[m] = *PossiblePlate[m]; - m++; - } - - char area[30] = { 0 }; - int bMatch = IsMatchGBRPattern(PlatePattern, area); - if (bMatch) - { - snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - break; - } - } - - for (int index_i = 0; index_i < rows2; index_i++) { - if (array2[index_i] != NULL) { - free(array2[index_i]); - array2[index_i] = NULL; - } - } - if (array2 != NULL) { - free(array2); - array2 = NULL; - } - - if (each2 != NULL) { - free(each2); - each2 = NULL; - } - } - } - - for (int i = 0; i < rows; i++) { - if (array[i] != NULL) { - free(array[i]); - array[i] = NULL; - } - } - if (array != NULL) { - free(array); - array = NULL; - } - - if (each != NULL) { - free(each); - each = NULL; - } - } - else if (Index1orI > 0) - { - int rows = pow(2, Index1orI); - int **array; - array = malloc(rows * sizeof *array); - for (int i = 0; i < rows; i++) - { - array[i] = malloc(Index1orI * sizeof *array[i]); - } - int *each = malloc(Index1orI * sizeof(int)); - int c = 0; - BinaryDFS(0, Index1orI, each, array, &c); - for (int i = 0; i < rows; i++) - { - for (int j = 0; j < Index1orI; j++) - { - if (array[i][j] == _1) - *ElementPos1orI[j] = '1'; - else if (array[i][j] == _I) - *ElementPos1orI[j] = 'I'; - //printf("%d", array[i][j]); - } - //printf("\n"); - int m = 0; - char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; - while (PossiblePlate[m] != NULL) - { - PlatePattern[m] = *PossiblePlate[m]; - m++; - } - - char area[30] = { 0 }; - int bMatch = IsMatchGBRPattern(PlatePattern, area); - if (bMatch) - { - snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "GBR"); - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - break; - } - } - - for (int i = 0; i < rows; i++) { - if (array[i] != NULL) { - free(array[i]); - array[i] = NULL; - } - } - if (array != NULL) { - free(array); - array = NULL; - } - - if (each != NULL) { - free(each); - each = NULL; - } - } - - for (int i = 0; i < MAX_PLATE_NUMBER; i++) - { - ElementPos0orO[i] = NULL; - ElementPos1orI[i] = NULL; - PossiblePlate[i] = NULL; - IndexPattern = 0; - Index0orO = 0; - Index1orI = 0; - } - } - } - //} - } -#endif - -#if 0 - else if (pNext->engine_type & FEATURE_LPR_IDN) - { - /*char *PossiblePlate[MAX_PLATE_NUMBER] = { 0 }; - int Index0orO = 0, Index1orI = 0, IndexPattern = 0; - char *dash = "-"; - detection_pos *pNext = PosInfo*/ - //for (int i = 0; i < total_element_size; i++) - //{ - pNext = PosInfo + i; - if (pNext->obj_type == _NUMBER) - { - - if (IndexPattern == 0) - { - PossiblePlate[IndexPattern] = pNext->name; - IndexPattern++; - //pBeginIndex = PosInfo + i; - } - else - { - if (strlen(pNext->name) > 5) - printf("Test number"); - PossiblePlate[IndexPattern] = pNext->name; - IndexPattern++; - - if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) - { - if (Index0orO <= 0 && Index1orI <= 0) - { - int m = 0; - char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; - while (PossiblePlate[m] != NULL) - { - PlatePattern[m] = *PossiblePlate[m]; - m++; - } - - char area[30] = { 0 }; - int bMatch = IsMatchIDNPattern(PlatePattern, area); - if (bMatch) - { - snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(area), "%s", "IDN"); - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - } - } - - for (int i = 0; i < MAX_PLATE_NUMBER; i++) - { - //ElementPos0orO[i] = NULL; - //ElementPos1orI[i] = NULL; - PossiblePlate[i] = NULL; - IndexPattern = 0; - Index0orO = 0; - Index1orI = 0; - } - } - } - } - //} - } -#endif - else - { - //if (pNext->engine_type & FEATURE_LPR_TWN) - // sprintf(country, "%s", "TWN"); - char country[30] = { 0 }; - char area[30] = { 0 }; - int area_id = -1; - pNext->properties.area_id = area_id; - - /*if (pNext->engine_type & FEATURE_LPR_CNA) - sprintf(country, "%s", "CNA");*/ - if (pNext->engine_type & FEATURE_LPR_USA) - sprintf(country, "%s", "USA/CA"); - else if (pNext->engine_type & FEATURE_LPR_EUR) - sprintf(country, "%s", "EUR"); - /*else if (pNext->engine_type & FEATURE_LPR_TWN) - sprintf(country, "%s", "TWN");*/ - else if (pNext->engine_type & FEATURE_LPR_JPN) - sprintf(country, "%s", "JPN"); - else if (pNext->engine_type & FEATURE_LPR_BGD) - sprintf(country, "%s", "BGD"); - else if (pNext->engine_type & FEATURE_LPR_MEA) - sprintf(country, "%s", "MEA"); - else if (pNext->engine_type & FEATURE_LPR_SEA || - pNext->engine_type & FEATURE_LPR_IDN || - pNext->engine_type & FEATURE_LPR_VNM) - sprintf(country, "%s", "SEA"); - else if (pNext->engine_type & FEATURE_LPR_THA) - sprintf(country, "%s", "THA"); - else if (pNext->engine_type & FEATURE_LPR_LAO) - sprintf(country, "%s", "LAO"); - else if (pNext->engine_type & FEATURE_LPR_PHL) - sprintf(country, "%s", "PHL"); - else if (pNext->engine_type & FEATURE_LPR_CNT) - sprintf(country, "%s", "CNT"); - else if (pNext->engine_type & FEATURE_LPR_AUS) - sprintf(country, "%s", "AUS"); - else - sprintf(country, "%s", ""); - - if (IsANPRCategory(pNext->engine_type)) - { - //pNext = PosInfo + i; - - /*if (pNext->class_id >= 0) - { - if (strcmp(ppIniKeyValue[pNext->class_id], "") != 0) - { - strcpy(pNext->name, ppIniKeyValue[pNext->class_id]); - } - }*/ - - if (pNext->obj_type == _PLATE || pNext->obj_type == _LOGO) - continue; - - - if (pNext->obj_type == _PREFIX) - { - //printf("\n[PlatePatternParser]pNext->obj_type == _PREFIX area:%s area_id:%d\n", pNext->name, pNext->class_id); - sprintf(area, "%s", pNext->name); - area_id = pNext->class_id; - - // JPN and China should show thier area name in front of properties.plate, and set properties.area to empty - - if (featureType & FEATURE_LPR_JPN /*|| featureType & FEATURE_LPR_CNA*/) - { - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", ""); - (PosInfo + pNext->parent_idx)->properties.area_id = area_id; - } - else - { - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - (PosInfo + pNext->parent_idx)->properties.area_id = area_id; - } - } - - - - if (IndexPattern == 0) - { - PossiblePlate[IndexPattern] = pNext->name; - IndexPattern++; - } - else - { - PossiblePlate[IndexPattern] = pNext->name; - IndexPattern++; - - if (((i < total_element_size - 1) && (pNext->parent_idx != (pNext + 1)->parent_idx)) || i == total_element_size - 1) - { - if (Index0orO <= 0 && Index1orI <= 0) - { - int m = 0; - //char PlatePattern[MAX_PLATE_NUMBER] = { 0 }; - while (PossiblePlate[m] != NULL) - { - //PlatePattern[m] = *PossiblePlate[m]; - m++; - } - - snprintf((PosInfo + pNext->parent_idx)->properties.country, sizeof(country), "%s", country); - // JPN and China should show thier area name in front of properties.plate, and set properties.area to empty - /*if (featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_CNA) - { - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", ""); - (PosInfo + pNext->parent_idx)->properties.area_id = area_id; - } - else - { - snprintf((PosInfo + pNext->parent_idx)->properties.area, sizeof(area), "%s", area); - (PosInfo + pNext->parent_idx)->properties.area_id = area_id; - }*/ - - //break; - } - - for (int j = 0; j < MAX_PLATE_NUMBER; j++) - { - //ElementPos0orO[i] = NULL; - //ElementPos1orI[i] = NULL; - PossiblePlate[j] = NULL; - IndexPattern = 0; - Index0orO = 0; - Index1orI = 0; - } - } - } - } - } - } - //printf("\n[PlatePatternParser] end\n"); - return result; -} -#endif //GY_OS_WIN - PlatePatternParser - -#if defined GY_OS_AMBA || defined GY_OS_NOVA -void ReplaceWithUTF8(detection_pos* PosInfo, int total_element_size) -{ - detection_pos *pNext = NULL; - int layer_idx = 0; - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - - if (i > 0 && pNext->parent_idx >= 0) - { - //printf("\npNext->engine_type\n") - - - //if ( ((pNext->engine_type == (pNext - 1)->engine_type) && IsANPRCategory(pNext->engine_type) && IsANPRCategory((pNext - 1)->engine_type) && pNext->obj_type == _NUMBER && (pNext - 1)->obj_type == _PLATE) ) - if (((pNext->engine_type == (PosInfo + pNext->parent_idx)->engine_type) && IsANPRCategory(pNext->engine_type) && IsANPRCategory((PosInfo + pNext->parent_idx)->engine_type) && (pNext->obj_type == _NUMBER || pNext->obj_type == _PREFIX) && (PosInfo + pNext->parent_idx)->obj_type == _PLATE)) - { - - for (int j = 0; j < MAX_LAYER_NUM; j++) - { - if (j > 0) - { - if (layerFeatureType[j - 1] == pNext->engine_type && layerFeatureType[j] == pNext->engine_type) - { - layer_idx = j; - break; - } - } - } - - if (pNext->class_id >= 0) - { - if (strcmp(ppIniKeyValue[layer_idx][pNext->class_id], "") != 0) - { - strcpy(pNext->name, ppIniKeyValue[layer_idx][pNext->class_id]); - } - } - } - } - - if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) - { - for (int j = 0; j < MAX_LAYER_NUM - 1; j++) - { - if (layerFeatureType[j] == pNext->engine_type && layerFeatureType[j + 1] == pNext->engine_type) - { - layer_idx = j + 1; - break; - } - } - - if (pNext->properties.area_id >= 0) - { - if (strcmp(ppIniKeyValue[layer_idx][pNext->properties.area_id], "") != 0) - { - strcpy(pNext->properties.area, ppIniKeyValue[layer_idx][pNext->properties.area_id]); - } - } - } - } -} - -void AssignPlateNumber(detection_pos* PosInfo, int total_element_size, int featureType) -{ - detection_pos* pNext = NULL; - detection_pos* pNext2 = NULL; - detection_pos* pNext_correct = NULL; - int differ_top_y = 20; - - int mea_record_idx = 0; - -#if 0 - int record_correct_PosInfo_i_order[256]; - int record_first_PosInfo_i = 0; - int min_top_y = 100000; - - for (int i = 0; i < 256; i++) { - if (i < total_element_size) { - record_correct_PosInfo_i_order[i] = i; - } - else { - record_correct_PosInfo_i_order[i] = -1; - } - } - - //Selection Sort: pNext->left_x - for (int i = 0; i < total_element_size; i = i + 1) - { - pNext = PosInfo + i; - for (int j = i + 1; j < total_element_size; j = j + 1) - { - pNext2 = PosInfo + j; - if (pNext->left_x > pNext2->left_x) - { - //變數交換 - int tmp_record_i = record_correct_PosInfo_i_order[i]; - record_correct_PosInfo_i_order[i] = record_correct_PosInfo_i_order[j]; - record_correct_PosInfo_i_order[j] = tmp_record_i; - } - } - - if (pNext->top_y < min_top_y) - { - min_top_y = pNext->top_y; - } - } - - for (int i = 0; i < total_element_size; i = i + 1) - { - pNext = PosInfo + record_correct_PosInfo_i_order[i]; - if (abs((int)((pNext->top_y - min_top_y) / min_top_y * 100)) <= differ_top_y) { - record_first_PosInfo_i = i; - break; - } - } -#endif - int enable_the_first_word = 0; - - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - - if (IsANPRCategory(pNext->engine_type)) - { - - if (pNext->obj_type == _PREFIX || pNext->obj_type == _NUMBER || pNext->obj_type == _DASH) - { - if (pNext->obj_type == _PREFIX) - { - if (!(featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_TWN)) - continue; - } -#if 0 - if (featureType & FEATURE_LPR_TWN) { - if (activeDisplayDash) - { - if (pNext->obj_type == _DASH) - { - if (strstr((PosInfo + pNext->parent_idx)->properties.plate, "-") == NULL) { - strcat((PosInfo + pNext->parent_idx)->properties.plate, "-"); - } - } - } - } -#endif - //printf("\n------pNext->width:%f\n", pNext->width); - -#if 0 - if (featureType & FEATURE_LPR_SEA) { - if (pNext->width < 1) - continue; - } - else { - if (get_g_ori_yuv_width() <= 1280) { - if (pNext->width < 70) - continue; - } - else { - if (pNext->width < 100) - continue; - } - } -#endif - //if (strcmp(pNext->name, "_") == 0) - // strcpy(pNext->name, " "); - - //printf("\n----------area:%s\n", (PosInfo + pNext->parent_idx)->properties.area); - - if (featureType & FEATURE_LPR_USA) { - if (strlen((PosInfo + pNext->parent_idx)->properties.area)>=1) { - differ_top_y = 20; - } - else { - differ_top_y = 200; - } - } - else if (featureType & FEATURE_LPR_TWN) { - differ_top_y = 20; - //printf("\n---------TW\n"); - } - else { - differ_top_y = 20; - } - - int check_if_the_first_word = 0; - if (enable_the_first_word == 0) { - for (int j = i + 1; j < total_element_size; j++) { - pNext2 = PosInfo + j; - //printf("\n-----yyyy:%d,%f,%f\n", abs((int)((pNext->top_y - pNext2->top_y) / pNext2->top_y * 100)), pNext->top_y, pNext2->top_y); - if (abs((int)((pNext->top_y - pNext2->top_y) / pNext2->top_y * 100)) <= differ_top_y) { - - } - else { - if (pNext->top_y <= pNext2->top_y) { - - } - else { - check_if_the_first_word = 1; - } - } - - enable_the_first_word = 1; - break; - } - } - - int check_the_same_left_x = 0; - - for (int j = i - 1; j < i && j >= 0; j++) { - pNext2 = PosInfo + j; - if (detection_overlap_ratio_union(pNext, pNext2) > 0.7) { - if ((j - 1) >= 0) { - pNext_correct = PosInfo + (j - 1); - if (detection_overlap_ratio_union(pNext, pNext_correct) > detection_overlap_ratio_union(pNext2, pNext_correct)) { - (PosInfo + pNext->parent_idx)->properties.plate[strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1] = '\0'; - strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext_correct->name); - } - } - check_the_same_left_x = 1; - } - break; - } - - - if (check_the_same_left_x == 0 && check_if_the_first_word == 0) { - if (strlen((PosInfo + pNext->parent_idx)->properties.plate) == 0) { - if (featureType & FEATURE_LPR_MEA) { - //printf("area: %s, country: %s \n", (PosInfo + pNext->parent_idx)->properties.area, (PosInfo + pNext->parent_idx)->properties.country); - - //check number level - //printf("B level: %d , s = %s\n", pNext->number_row, pNext->name); - - memset((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name, '\0', sizeof((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name)); - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsAlpha = 0; - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsDigit = 0; - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_h = 0; - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_w = 0; - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_x = 0; - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_y = 0; - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].number_row = 0; - - - ///record mea number - (PosInfo + pNext->parent_idx)->plate_number_count = 0; - mea_record_idx = (PosInfo + pNext->parent_idx)->plate_number_count; - - if (isdigit(pNext->name[0]) != 0) - { - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsDigit = 1; - //printf("isdigit: %s \n", pNext->name); - } - - if (isalpha(pNext->name[0]) != 0) - { - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsAlpha = 1; - //printf("isalpht: %s \n", pNext->name); - } - - strcat((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name, pNext->name); - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].number_row = pNext->number_row; - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_h = pNext->box_h; - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_w = pNext->box_w; - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_x = pNext->box_x; - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_y = pNext->box_y; - - //printf("recoder name = %s \n", (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name); - - (PosInfo + pNext->parent_idx)->plate_number_count++; - - strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); - (PosInfo + pNext->parent_idx)->plate_char_top_y = pNext->top_y; - } - else { - strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); - (PosInfo + pNext->parent_idx)->plate_char_top_y = pNext->top_y; - } - - //float temp = pNext->confidence; - //(PosInfo + pNext->parent_idx)->confidence = temp; - //printf("%d plate %d name = %s - %d ; confidence: %f\n", i, pNext->parent_idx, (PosInfo + pNext->parent_idx)->properties.plate, (int)pNext->top_y, (PosInfo + pNext->parent_idx)->confidence); - } - else { - if (featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_BGD || featureType & FEATURE_LPR_MEA || featureType & FEATURE_LPR_EUR || featureType & FEATURE_LPR_TWN) - { - if (featureType & FEATURE_LPR_MEA) - { - - //check number level - //printf("A level: %d , s = %s, box_x = %f\n", pNext->number_row, pNext->name, pNext->box_x); - - ///record mea number - mea_record_idx = (PosInfo + pNext->parent_idx)->plate_number_count; - - if (isdigit(pNext->name[0]) != 0) - { - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsDigit = 1; - //printf("isdigit: %s \n", pNext->name); - } - - if (isalpha(pNext->name[0]) != 0) - { - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].iIsAlpha = 1; - //printf("isalpht: %s \n", pNext->name); - } - - strcat((PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name, pNext->name); - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].number_row = pNext->number_row; - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_h = pNext->box_h; - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_w = pNext->box_w; - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_x = pNext->box_x; - (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].box_y = pNext->box_y; - - //printf("recoder name = %s \n", (PosInfo + pNext->parent_idx)->mea_sub_properties[mea_record_idx].name); - - (PosInfo + pNext->parent_idx)->plate_number_count++; - - strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); - //printf("plate %d name = %s, y = %f, plate_y = %f, row = %d\n", i, (PosInfo + pNext->parent_idx)->properties.plate, pNext->top_y, (PosInfo + pNext->parent_idx)->plate_char_top_y, pNext->number_row); - } - else { - if (abs((int)((pNext->top_y - (PosInfo + pNext->parent_idx)->plate_char_top_y) / (PosInfo + pNext->parent_idx)->plate_char_top_y * 100)) <= differ_top_y) { - strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); - - //float temp = (PosInfo + pNext->parent_idx)->confidence; - //(PosInfo + pNext->parent_idx)->confidence = (temp * ((float)strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1) + pNext->confidence) / (float)strlen((PosInfo + pNext->parent_idx)->properties.plate); - } - } - } - else { - strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); - //float temp = (PosInfo + pNext->parent_idx)->confidence; - //(PosInfo + pNext->parent_idx)->confidence = (temp * ((float)strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1) + pNext->confidence) / (float)strlen((PosInfo + pNext->parent_idx)->properties.plate); - } - //printf("%d plate %d name = %s - %d ; confidence: %f\n", i, pNext->parent_idx, (PosInfo + pNext->parent_idx)->properties.plate, (int)pNext->top_y, (PosInfo + pNext->parent_idx)->confidence); - } - } - - - } - } - } - - enable_the_first_word = 0; - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - - if (IsANPRCategory(pNext->engine_type)) - { - if (pNext->obj_type == _PREFIX || pNext->obj_type == _NUMBER || pNext->obj_type == _DASH) - { - - if (pNext->obj_type == _PREFIX) - { - if (!(featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_TWN)) - continue; - } -#if 0 - if (featureType & FEATURE_LPR_TWN) { - if (activeDisplayDash) - { - if (pNext->obj_type == _DASH) - { - if (strstr((PosInfo + pNext->parent_idx)->properties.plate, "-") == NULL) { - strcat((PosInfo + pNext->parent_idx)->properties.plate, "-"); - } - } - } - } -#endif -#if 0 - if (get_g_ori_yuv_width() <= 1280) { - if (pNext->width < 70) - continue; - } - else { - if (pNext->width < 100) - continue; - } -#endif - - if (featureType & FEATURE_LPR_USA) { - if (strlen((PosInfo + pNext->parent_idx)->properties.area) >= 1) { - differ_top_y = 20; - } - else { - differ_top_y = 200; - } - } - else if (featureType & FEATURE_LPR_TWN) { - differ_top_y = 20; - } - else { - differ_top_y = 20; - } - - int check_if_the_first_word = 0; - if (enable_the_first_word == 0) { - for (int j = i + 1; j < total_element_size; j++) { - pNext2 = PosInfo + j; - - if (abs((int)((pNext->top_y - pNext2->top_y) / pNext2->top_y * 100)) <= differ_top_y) { - check_if_the_first_word = 1; - } - else { - if (pNext->top_y <= pNext2->top_y) { - check_if_the_first_word = 1; - } - else { - - } - } - - enable_the_first_word = 1; - break; - } - } - - int check_the_same_left_x = 0; - - for (int j = i - 1; j < i && j >= 0; j++) { - pNext2 = PosInfo + j; - if (detection_overlap_ratio_union(pNext, pNext2) > 0.7) { - if ((j - 1) >= 0) { - pNext_correct = PosInfo + (j - 1); - if (detection_overlap_ratio_union(pNext, pNext_correct) > detection_overlap_ratio_union(pNext2, pNext_correct)) { - (PosInfo + pNext->parent_idx)->properties.plate[strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1] = '\0'; - strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext_correct->name); - } - } - check_the_same_left_x = 1; - - } - break; - } - - if (check_the_same_left_x == 0 && check_if_the_first_word == 0) { - if (strlen((PosInfo + pNext->parent_idx)->properties.plate) >= 0) { - if (featureType & FEATURE_LPR_JPN || featureType & FEATURE_LPR_BGD || featureType & FEATURE_LPR_MEA || featureType & FEATURE_LPR_EUR || featureType & FEATURE_LPR_TWN) - { - if (abs((int)((pNext->top_y - (PosInfo + pNext->parent_idx)->plate_char_top_y) / (PosInfo + pNext->parent_idx)->plate_char_top_y * 100)) <= differ_top_y) { - - } - else { - strcat((PosInfo + pNext->parent_idx)->properties.plate, pNext->name); - //float temp = (PosInfo + pNext->parent_idx)->confidence; - //(PosInfo + pNext->parent_idx)->confidence = (temp * ((float)strlen((PosInfo + pNext->parent_idx)->properties.plate) - 1) + pNext->confidence) / (float)strlen((PosInfo + pNext->parent_idx)->properties.plate); - } - } - //printf("[2]%d plate %d name = %s - %d ; confidence: %f\n", i, pNext->parent_idx, (PosInfo + pNext->parent_idx)->properties.plate, (int)pNext->top_y, (PosInfo + pNext->parent_idx)->confidence); - } - } - } - } - } -} -#endif -void ReplacePlateWithDB(detection_pos* PosInfo, int total_element_size, int featureType, int tracking_channel_idx) { - detection_pos *pNext = NULL; - - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - - if (pNext->obj_type != _PLATE) - { - continue; - } - - if (strlen(pNext->properties.plate) <= 0) - { - continue; - } - - if (pNext->confidence <= 0.0) - { - continue; - } - - if (IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name)) - { - for (int index_levenshtein = 0; index_levenshtein <= atoi(viewChannelData[tracking_channel_idx].levenshtein_distance); index_levenshtein++) { - int check_if_OK = 0; - - char afterBuf[256] = { 0 }; - strcpy(afterBuf, pNext->properties.plate); - - char afterBuf_dest[256] = { 0 }; - - if (check_if_in_white(afterBuf, pNext->properties.area, index_levenshtein, afterBuf_dest)) { - if (index_levenshtein >= 1 && strlen(afterBuf_dest) >= 1) { - strcpy(pNext->properties.plate, afterBuf_dest); - } - check_if_OK = 1; - break; - } - else if (check_if_in_black(afterBuf, pNext->properties.area, index_levenshtein, afterBuf_dest)) { - if (index_levenshtein >= 1 && strlen(afterBuf_dest) >= 1) { - strcpy(pNext->properties.plate, afterBuf_dest); - } - check_if_OK = 1; - break; - } - - if (check_if_OK == 1) - break; - } - } - else if (IsANPRCategory(pNext->engine_type) && !IsANPRCategory_L_Plate(pNext->name)) - { - pNext->confidence = 0.0; - } - } -} - -void PlateFilterForParkingPlot(detection_pos* PosInfo, int total_element_size, int featureType,int tracking_channel_idx) { - detection_pos *pNext = NULL,*pNext1 = NULL; - detection_pos pNext_plate; - double iDiffSec = 0.0; - //float diff_box_y = 0; - - //g_PlateFilterTime = 3; - //g_PlateFilterTimes = 10; - //g_PlateRecorderFreeTime = 6; - g_PlateFilterTimes = viewChannelData[tracking_channel_idx].i_plate_filter_times; - g_PlateFilterTime = viewChannelData[tracking_channel_idx].i_plate_filter_time; - //g_PlateRecorderFreeTime = viewChannelData[tracking_channel_idx].i_plate_free_time; - - g_PlateRecorderFreeTime = g_PlateFilterTime; //g_PlateRecorderFreeTime 5 - if (g_PlateRecorderFreeTime == 0) { - g_PlateRecorderFreeTime = 1; - } - - if (g_PlateFilterTime == 0) { - g_PlateFilterTime = 1; - } - - if (g_PlateFilterTimes == 0) { - g_PlateFilterTimes = 1; - } - - //停車場,相同車牌只做1次。 - //printf("%d, %d, %d \n", g_PlateFilterTimes, g_PlateFilterTime, g_PlateRecorderFreeTime); - - //Free over Recoder time - for (int j = 0; j < MAX_PLATE_RECORDER; j++) - { - if (g_PlateRecorderList[j].iIfUse == 1) - { - iDiffSec = difftime(time(0),g_PlateRecorderList[j].t_UpdateTime); - //printf("\nFFF------------[%d]iDiffSec:%lf,g_PlateRecorderFreeTime:%d\n",j, iDiffSec, g_PlateRecorderFreeTime); - if (g_PlateRecorderFreeTime >= 1 && iDiffSec > (double)g_PlateRecorderFreeTime) - { - g_PlateRecorderList[j].iGetCounter = 0; - g_PlateRecorderList[j].t_UpdateTime = 0; - g_PlateRecorderList[j].t_FirstGetTime = 0; - g_PlateRecorderList[j].t_LoopTime = 0; - for (int m = 0; m < MAX_DETECTION_ZONE; m++) { - g_PlateRecorderList[j].check_if_counted[m] = 0; - } - g_PlateRecorderList[j].iIfUse = 0; - } - } - } - - //printf("---------> ver EEE \n"); - - //Filter plate by time and frequency - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - - if (pNext->confidence <= 0.0) - { - continue; - } - - if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) - { -#if 1 - for (int j = 0; j < MAX_PLATE_RECORDER; j++) - { - if (g_PlateRecorderList[j].iIfUse == 1) - { - pNext_plate.left_x = g_PlateRecorderList[j].box_x; - pNext_plate.top_y = g_PlateRecorderList[j].box_y; - pNext_plate.width = g_PlateRecorderList[j].box_w; - pNext_plate.height = g_PlateRecorderList[j].box_h; - pNext_plate.center_x = g_PlateRecorderList[j].box_x + g_PlateRecorderList[j].box_w / 2.0; - pNext_plate.center_y = g_PlateRecorderList[j].box_y + g_PlateRecorderList[j].box_h / 2.0; - - - - if ((detection_overlap_ratio(&pNext_plate, pNext) > 0.0 && (strcmp(pNext->name, "exhaust_ok") == 0 || strcmp(pNext->name, "exhaust_ng") == 0)) || detection_overlap_ratio(&pNext_plate, pNext) > (90.0 / 100.0) || ((pNext_plate.center_x <= pNext->left_x + pNext->width && pNext_plate.center_x >= pNext->left_x) && - (pNext_plate.center_y <= pNext->top_y + pNext->height && pNext_plate.center_y >= pNext->top_y)) - ) - { - pNext->linked_plate_length = Modify_Plate_and_Recount_Length(g_PlateRecorderList[j].sPlateNumber, pNext->linked_plate); - strcpy(pNext->car_type_name, pNext->name); - break; - } - } - } -#endif - } - else if(IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name)) - { - char afterBuf[256] = { 0 }; - - strcpy(afterBuf, pNext->properties.plate); - - //printf("\n-----------afterBuf:%s\n", afterBuf); - - pNext->properties.plate_length = Modify_Plate_and_Recount_Length(afterBuf, pNext->properties.plate); - - //printf("\n-----------[fff]pNext->properties.plate:%s\n", pNext->properties.plate); - - pNext->linked_plate_length = pNext->properties.plate_length; - strcpy(pNext->linked_plate, pNext->properties.plate); - - if ((pNext->properties.plate_length < atoi(viewChannelData[0].min_characters) || - pNext->properties.plate_length > atoi(viewChannelData[0].max_characters)) && strcmp(pNext->name, "ambulance") != 0 && strcmp(pNext->name, "blank") != 0 && strcmp(pNext->name, "stop_sign") != 0 && strcmp(pNext->name, "face") != 0) - { - - } - else - { - if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET) { - if (viewChannelData[0].enable_traffic) { - for (int m = 0; m < total_element_size; m++) { - pNext1 = PosInfo + m; - if (IsVehicleCategory(pNext1) || IsMotorbikeCategory(pNext1)) { - if (detection_overlap_ratio(pNext, pNext1) > (90.0 / 100.0) || ((pNext->center_x <= pNext1->left_x + pNext1->width && pNext->center_x >= pNext1->left_x) && - (pNext->center_y <= pNext1->top_y + pNext1->height && pNext->center_y >= pNext1->top_y)) - ) - { - strcpy(pNext->car_type_name, pNext1->name); - break; - } - } - } - } - } - - int iFindMatchPlate = 0; - int index_g_PlateRecorderList_max = -1; - int iGetCounter_max = 0; - int record_plate_index[MAX_PLATE_RECORDER] = { 0 }; - int size_record_plate = 0; - - //printf("\n-----------Plate:%s\n", pNext->properties.plate); - - for (int j = 0; j < MAX_PLATE_RECORDER; j++) - { - if (g_PlateRecorderList[j].iIfUse == 1) - { - if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 - && strcmp(pNext->properties.plate, g_PlateRecorderList[j].sPlateNumber) == 0) - { - iFindMatchPlate = 1; - g_PlateRecorderList[j].t_UpdateTime = time(0); - g_PlateRecorderList[j].iGetCounter++; - - if (strlen(pNext->car_type_name) >= 1) { - strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); - } - else { - strcpy(pNext->car_type_name, g_PlateRecorderList[j].car_type_name); - } - - g_PlateRecorderList[j].last_box_x = g_PlateRecorderList[j].box_x; - g_PlateRecorderList[j].last_box_y = g_PlateRecorderList[j].box_y; - g_PlateRecorderList[j].last_box_w = g_PlateRecorderList[j].box_w; - g_PlateRecorderList[j].last_box_h = g_PlateRecorderList[j].box_h; - - g_PlateRecorderList[j].last_box_center_x = g_PlateRecorderList[j].box_x + g_PlateRecorderList[j].box_w / 2; - g_PlateRecorderList[j].last_box_center_y = g_PlateRecorderList[j].box_y + g_PlateRecorderList[j].box_h / 2; - - g_PlateRecorderList[j].box_x = pNext->left_x; - g_PlateRecorderList[j].box_y = pNext->top_y; - g_PlateRecorderList[j].box_w = pNext->width; - g_PlateRecorderList[j].box_h = pNext->height; - - if (g_PlateFilterTimes >= 1 && g_PlateFilterTime >= 1) { - if (g_PlateRecorderList[j].iGetCounter >= g_PlateFilterTimes + 100) - { - g_PlateRecorderList[j].iGetCounter = g_PlateFilterTimes + 100; - } - } - break; - } - } - } - - if (iFindMatchPlate == 0) - { - for (int j = 0; j < MAX_PLATE_RECORDER; j++) - { - if (g_PlateRecorderList[j].iIfUse == 0) - { - if (activeDisplayDash && (featureType & FEATURE_LPR_TWN)) { - if (strstr(pNext->properties.plate, "-") != NULL) { - g_PlateRecorderList[j].existing_dash = 1; - } - else { - g_PlateRecorderList[j].existing_dash = 0; - } - } - else { - g_PlateRecorderList[j].existing_dash = 0; - } - - if (strcmp(pNext->name, "ambulance") == 0) { - sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); - } - else if (strcmp(pNext->name, "blank") == 0) { - sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); - } - else if (strcmp(pNext->name, "stop_sign") == 0) { - sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); - } - else { - sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->properties.plate); - } - - g_PlateRecorderList[j].t_FirstGetTime = time(0); - g_PlateRecorderList[j].t_LoopTime = 0; - g_PlateRecorderList[j].t_UpdateTime = time(0); - g_PlateRecorderList[j].iGetCounter = 1; - for (int m = 0; m < MAX_DETECTION_ZONE; m++) { - g_PlateRecorderList[j].check_if_counted[m] = 0; - } - - g_PlateRecorderList[j].box_x = pNext->left_x; - g_PlateRecorderList[j].box_y = pNext->top_y; - g_PlateRecorderList[j].box_w = pNext->width; - g_PlateRecorderList[j].box_h = pNext->height; - - g_PlateRecorderList[j].last_box_x = pNext->left_x; - g_PlateRecorderList[j].last_box_y = pNext->top_y; - g_PlateRecorderList[j].last_box_w = pNext->width; - g_PlateRecorderList[j].last_box_h = pNext->height; - - g_PlateRecorderList[j].last_box_center_x = pNext->left_x + pNext->width / 2; - g_PlateRecorderList[j].last_box_center_y = pNext->top_y + pNext->height / 2; - - g_PlateRecorderList[j].iPlateZoomOutCounter = 0; - g_PlateRecorderList[j].iPlateZoomInCounter = 0; - - g_PlateRecorderList[j].iTrackingID = pNext->obj_tracking_id; - strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); - - g_PlateRecorderList[j].iIfUse = 1; - iFindMatchPlate = 1; - break; - } - } - - if (iFindMatchPlate == 0) { - for (int j = 0; j < MAX_PLATE_RECORDER; j++) - { - if (g_PlateRecorderList[j].iGetCounter <= 0) - { - if (activeDisplayDash && (featureType & FEATURE_LPR_TWN)) { - if (strstr(pNext->properties.plate, "-") != NULL) { - g_PlateRecorderList[j].existing_dash = 1; - } - else { - g_PlateRecorderList[j].existing_dash = 0; - } - } - else { - g_PlateRecorderList[j].existing_dash = 0; - } - - if (strcmp(pNext->name, "ambulance") == 0) { - sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); - } - else if (strcmp(pNext->name, "blank") == 0) { - sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); - } - else if (strcmp(pNext->name, "stop_sign") == 0) { - sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->name); - } - else { - sprintf(g_PlateRecorderList[j].sPlateNumber, "%s", pNext->properties.plate); - } - - g_PlateRecorderList[j].t_FirstGetTime = time(0); - g_PlateRecorderList[j].t_LoopTime = 0; - g_PlateRecorderList[j].t_UpdateTime = time(0); - g_PlateRecorderList[j].iGetCounter = 1; - for (int m = 0; m < MAX_DETECTION_ZONE; m++) { - g_PlateRecorderList[j].check_if_counted[m] = 0; - } - - g_PlateRecorderList[j].box_x = pNext->left_x; - g_PlateRecorderList[j].box_y = pNext->top_y; - g_PlateRecorderList[j].box_w = pNext->width; - g_PlateRecorderList[j].box_h = pNext->height; - - g_PlateRecorderList[j].last_box_x = pNext->left_x; - g_PlateRecorderList[j].last_box_y = pNext->top_y; - g_PlateRecorderList[j].last_box_w = pNext->width; - g_PlateRecorderList[j].last_box_h = pNext->height; - - g_PlateRecorderList[j].last_box_center_x = pNext->left_x + pNext->width / 2; - g_PlateRecorderList[j].last_box_center_y = pNext->top_y + pNext->height / 2; - - g_PlateRecorderList[j].iPlateZoomOutCounter = 0; - g_PlateRecorderList[j].iPlateZoomInCounter = 0; - - g_PlateRecorderList[j].iTrackingID = pNext->obj_tracking_id; - strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); - - g_PlateRecorderList[j].iIfUse = 1; - iFindMatchPlate = 1; - break; - } - } - } - } - - time_t early_t_FirstGetTime = time(0); - for (int j = 0; j < MAX_PLATE_RECORDER; j++) - { - if (g_PlateRecorderList[j].iIfUse == 1) - { - //printf("\n-----sPlateNumber:%s,plate:%s,levenshtein_distance:%d\n", g_PlateRecorderList[j].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - - if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 && - LevenshteinDistance(pNext->properties.plate, g_PlateRecorderList[j].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { - - if (g_PlateRecorderList[j].t_FirstGetTime < early_t_FirstGetTime) { - early_t_FirstGetTime = g_PlateRecorderList[j].t_FirstGetTime; - } - - record_plate_index[size_record_plate] = j; - size_record_plate++; - } - } - } - - for (int temp_j = 0; temp_j < size_record_plate; temp_j++) - { - int j = record_plate_index[temp_j]; - g_PlateRecorderList[j].t_FirstGetTime = early_t_FirstGetTime; - - if (g_PlateRecorderList[j].iGetCounter > iGetCounter_max || - (index_g_PlateRecorderList_max >= 0 && iGetCounter_max >= 1 && g_PlateRecorderList[j].iGetCounter == iGetCounter_max && g_PlateRecorderList[j].t_UpdateTime > g_PlateRecorderList[index_g_PlateRecorderList_max].t_UpdateTime)) { - - iDiffSec = difftime(time(0), g_PlateRecorderList[j].t_FirstGetTime); - if (iDiffSec >= (double)g_PlateFilterTime || g_PlateRecorderList[j].iGetCounter >= g_PlateFilterTimes) - { - index_g_PlateRecorderList_max = j; - iGetCounter_max = g_PlateRecorderList[j].iGetCounter; - } - } - - //printf("\n---iGetCounter:%d,iGetCounter_max:%d,%s\n", g_PlateRecorderList[j].iGetCounter, iGetCounter_max, g_PlateRecorderList[j].sPlateNumber); - } - - if (index_g_PlateRecorderList_max >= 0) { - int j = index_g_PlateRecorderList_max; - iDiffSec = difftime(time(0),g_PlateRecorderList[j].t_FirstGetTime); - - if (g_PlateFilterTimes >= 1 && g_PlateFilterTime >= 1) { - - if (strlen(pNext->car_type_name) >= 1) { - strcpy(g_PlateRecorderList[j].car_type_name, pNext->car_type_name); - } - else { - strcpy(pNext->car_type_name, g_PlateRecorderList[j].car_type_name); - } - - g_PlateRecorderList[j].last_box_x = g_PlateRecorderList[j].box_x; - g_PlateRecorderList[j].last_box_y = g_PlateRecorderList[j].box_y; - g_PlateRecorderList[j].last_box_w = g_PlateRecorderList[j].box_w; - g_PlateRecorderList[j].last_box_h = g_PlateRecorderList[j].box_h; - - g_PlateRecorderList[j].last_box_center_x = g_PlateRecorderList[j].box_x + g_PlateRecorderList[j].box_w / 2; - g_PlateRecorderList[j].last_box_center_y = g_PlateRecorderList[j].box_y + g_PlateRecorderList[j].box_h / 2; - - g_PlateRecorderList[j].box_x = pNext->left_x; - g_PlateRecorderList[j].box_y = pNext->top_y; - g_PlateRecorderList[j].box_w = pNext->width; - g_PlateRecorderList[j].box_h = pNext->height; - - //printf("\n-----------[%d]pNext->properties.plate up:%s,g_Plate:%s\n",j, pNext->properties.plate, g_PlateRecorderList[j].sPlateNumber); - pNext->properties.plate_length = Modify_Plate_and_Recount_Length(g_PlateRecorderList[j].sPlateNumber, pNext->properties.plate); - //printf("\n-----------pNext->properties.plate down:%s\n", pNext->properties.plate); - pNext->linked_plate_length = pNext->properties.plate_length; - strcpy(pNext->linked_plate, pNext->properties.plate); - - if((int)iDiffSec > 0 && ((int)iDiffSec) % g_PlateFilterTime == 0){ - for (int index_record = 0; index_record < size_record_plate; index_record++) { - if (record_plate_index[index_record] != j) { - g_PlateRecorderList[index_record].iGetCounter = (g_PlateRecorderList[index_record].iGetCounter / 2) - 1; - if(g_PlateRecorderList[index_record].iGetCounter <= 0) - g_PlateRecorderList[index_record].iGetCounter = 0; - } - } - } - - if (strcmp(heartbeatData.enable_only_once_to_post, "Yes") == 0) { - if (g_PlateRecorderList[j].t_LoopTime == 0) { - g_PlateRecorderList[j].t_LoopTime = time(0); - } - - double iDiffLoopSec = difftime(time(0), g_PlateRecorderList[j].t_LoopTime); - if ((int)iDiffLoopSec > 0 && ((int)iDiffLoopSec) % g_PlateFilterTime == 0) { - for (int k = 0; k < MAX_TRACKING_NUM; k++) - { - if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1 && - strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, g_PlateRecorderList[j].sPlateNumber) == 0) - { - for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { - pNext->check_if_having_been_counted[index_zone] = 0; - g_TrackingRecords[tracking_channel_idx][k].check_if_having_been_counted[index_zone] = 0; - g_PlateRecorderList[j].check_if_counted[index_zone] = 0; - } - g_TrackingRecords[tracking_channel_idx][k].disappear_count = 0; - break; - } - } - - for (int k = 0; k < MAX_POST_RECODER_SIZE; k++) - { - if (g_PostRecorderList[k].iIfUse == 0 && g_longterm_PostRecorderList[k].iIfUse == 0) { - break; - } - - if (g_PostRecorderList[k].iIfUse == 1) - { - if (strlen(g_PlateRecorderList[j].sPlateNumber) >= 1 && LevenshteinDistance(g_PlateRecorderList[j].sPlateNumber, g_PostRecorderList[k].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) - { - g_PostRecorderList[k].iIfUse = 0; - g_PostRecorderList[k].t_FirstGetTime = 0; - g_PostRecorderList[k].t_FirstGetTime_total = 0; - g_PostRecorderList[k].t_UpdateTime = 0; - - for (int m = 0; m < MAX_DETECTION_ZONE; m++) { - g_PostRecorderList[k].check_if_post[m] = 0; - } - g_PostRecorderList[k].check_if_cloud = 0; - g_PostRecorderList[k].check_if_cloud_v2 = 0; - g_PostRecorderList[k].check_if_cloud_record_v2 = 0; - g_PostRecorderList[k].check_if_email = 0; - g_PostRecorderList[k].check_if_ftp = 0; - g_PostRecorderList[k].check_if_getalarmmotion = 0; - - g_PostRecorderList[k].box_x = 0; - g_PostRecorderList[k].box_y = 0; - g_PostRecorderList[k].box_w = 0; - g_PostRecorderList[k].box_h = 0; - - g_PostRecorderList[k].object_id = 0; - g_PostRecorderList[k].zone_idx = 0; - strcpy(g_PostRecorderList[k].sPlateNumber, ""); - - g_PostRecorderList[k].count_trigger = 0; - //g_PostRecorderList[k].the_same_id = 0; - } - } - - if (g_longterm_PostRecorderList[k].iIfUse == 1) - { - if (strlen(g_PlateRecorderList[j].sPlateNumber) >= 1 && LevenshteinDistance(g_PlateRecorderList[j].sPlateNumber, g_longterm_PostRecorderList[k].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) - { - g_longterm_PostRecorderList[k].iIfUse = 0; - g_longterm_PostRecorderList[k].t_FirstGetTime = 0; - g_longterm_PostRecorderList[k].t_FirstGetTime_total = 0; - g_longterm_PostRecorderList[k].t_UpdateTime = 0; - - for (int m = 0; m < MAX_DETECTION_ZONE; m++) { - g_longterm_PostRecorderList[k].check_if_post[m] = 0; - } - g_longterm_PostRecorderList[k].check_if_cloud = 0; - g_longterm_PostRecorderList[k].check_if_cloud_v2 = 0; - g_longterm_PostRecorderList[k].check_if_cloud_record_v2 = 0; - g_longterm_PostRecorderList[k].check_if_email = 0; - g_longterm_PostRecorderList[k].check_if_ftp = 0; - g_longterm_PostRecorderList[k].check_if_getalarmmotion = 0; - - g_longterm_PostRecorderList[k].box_x = 0; - g_longterm_PostRecorderList[k].box_y = 0; - g_longterm_PostRecorderList[k].box_w = 0; - g_longterm_PostRecorderList[k].box_h = 0; - - g_longterm_PostRecorderList[k].object_id = 0; - g_longterm_PostRecorderList[k].zone_idx = 0; - strcpy(g_longterm_PostRecorderList[k].sPlateNumber, ""); - - g_longterm_PostRecorderList[k].count_trigger = 0; - //g_longterm_PostRecorderList[k].the_same_id = 0; - } - } - } - - g_PlateRecorderList[j].t_LoopTime = time(0); - } - } - - g_PlateRecorderList[j].t_UpdateTime = time(0); - for (int index_record = 0; index_record < size_record_plate; index_record++) { - if (record_plate_index[index_record] != j) { - g_PlateRecorderList[index_record].t_UpdateTime = time(0); - } - } - } - } - else { - pNext->confidence = 0; - } - } - - } - else if (IsANPRCategory(pNext->engine_type) && !IsANPRCategory_L_Plate(pNext->name)) - { - pNext->confidence = 0.0; - } - } - - qsort(&g_PlateRecorderList, MAX_PLATE_RECORDER, sizeof(PlateRecoder), sort_record_plate); -} - -void ObjectFilterForParkingPlot(detection_pos* PosInfo, int total_element_size, int featureType, int tracking_channel_idx) { - - detection_pos *pNext = NULL/*, *pNext1 = NULL*/; - //detection_pos pNext_plate; - double iDiffSec = 0.0; - //float diff_box_y = 0; - - //g_PlateFilterTime = 3; - //g_PlateFilterTimes = 10; - //g_PlateRecorderFreeTime = 6; - //g_PlateFilterTimes = viewChannelData[tracking_channel_idx].i_plate_filter_times; - //g_PlateFilterTime = viewChannelData[tracking_channel_idx].i_plate_filter_time; - //g_PlateRecorderFreeTime = viewChannelData[tracking_channel_idx].i_plate_free_time; - - //g_PlateRecorderFreeTime = g_PlateFilterTime; //g_PlateRecorderFreeTime 5 - //if (g_PlateRecorderFreeTime == 0) { - //g_PlateRecorderFreeTime = 2; - //} - - int object_free_time = atoi(SystemSetting.tracking_id_dwell) + 1;//2 - - //停車場,相同車牌只做1次。 - //printf("%d, %d, %d \n", g_PlateFilterTimes, g_PlateFilterTime, g_PlateRecorderFreeTime); - - //Free over Recoder time - for (int j = 0; j < MAX_OBJECT_RECORDER; j++) - { - if (g_ObjectRecorderList[j].iIfUse == 1) - { - iDiffSec = difftime(time(0),g_ObjectRecorderList[j].t_UpdateTime); - //printf("\nEEE------------iDiffSec:%d\n", iDiffSec); - if (object_free_time >= 1 && iDiffSec > (double)object_free_time) - { - g_ObjectRecorderList[j].iIfUse = 0; - g_ObjectRecorderList[j].iGetCounter = 0; - g_ObjectRecorderList[j].t_UpdateTime = 0; - g_ObjectRecorderList[j].t_FirstGetTime = 0; - for (int m = 0; m < MAX_DETECTION_ZONE; m++) { - g_ObjectRecorderList[j].check_if_counted[m] = 0; - } - g_ObjectRecorderList[j].box_x = 0; - g_ObjectRecorderList[j].box_y = 0; - g_ObjectRecorderList[j].box_w = 0; - g_ObjectRecorderList[j].box_h = 0; - g_ObjectRecorderList[j].iTrackingID = 0; - } - } - } - - //printf("---------> ver EEE \n"); - - //Filter plate by time and frequency - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - - if (pNext->obj_tracking_id_idx < 0 || pNext->obj_tracking_id <= 0) { - - } - else { - if (IsANPRCategory(pNext->engine_type)) { - - } - else { - if (strlen(pNext->name) >= 1) - { - int iFindMatchObject = 0; - - for (int j = 0; j < MAX_OBJECT_RECORDER; j++) - { - //printf("if %d use = %d \n", j, g_ObjectRecorderList[j].iIfUse); - if (g_ObjectRecorderList[j].iIfUse == 1) - { - if (g_ObjectRecorderList[j].iTrackingID == pNext->obj_tracking_id) - { - //printf("find match id \n"); - iFindMatchObject = 1; - g_ObjectRecorderList[j].t_UpdateTime = time(0); - //g_ObjectRecorderList[j].iGetCounter++; - - //g_ObjectRecorderList[j].left_x = pNext->left_x; - //g_ObjectRecorderList[j].top_y = pNext->top_y; - g_ObjectRecorderList[j].box_x = pNext->left_x; - g_ObjectRecorderList[j].box_y = pNext->top_y; - g_ObjectRecorderList[j].box_w = pNext->width; - g_ObjectRecorderList[j].box_h = pNext->height; - - //printf("%d history data, x = %f \n", j, g_ObjectRecorderList[j].box_x); - //printf("y = %f ", g_ObjectRecorderList[j].box_y); - //printf("h = %f ", g_ObjectRecorderList[j].box_h); - //printf("w = %f ", g_ObjectRecorderList[j].box_w); - //printf("ob_id = %d \n", g_ObjectRecorderList[j].iTrackingID); - break; - } - } - } - - //printf("iFindMatch = %d \n", iFindMatchObject); - - if (iFindMatchObject == 0) - { - for (int j = 0; j < MAX_OBJECT_RECORDER; j++) - { - if (g_ObjectRecorderList[j].iIfUse == 0) - { - g_ObjectRecorderList[j].iIfUse = 1; - g_ObjectRecorderList[j].t_FirstGetTime = time(0); - g_ObjectRecorderList[j].t_UpdateTime = time(0); - g_ObjectRecorderList[j].iGetCounter = 1; - for (int m = 0; m < MAX_DETECTION_ZONE; m++) { - g_ObjectRecorderList[j].check_if_counted[m] = 0; - } - g_ObjectRecorderList[j].box_x = pNext->left_x; - g_ObjectRecorderList[j].box_y = pNext->top_y; - g_ObjectRecorderList[j].box_w = pNext->width; - g_ObjectRecorderList[j].box_h = pNext->height; - - g_ObjectRecorderList[j].iTrackingID = pNext->obj_tracking_id; - //g_ObjectRecorderList[j].iTrackingIDidx = pNext->obj_tracking_id_idx; - - break; - } - //else if (j == MAX_OBJECT_RECORDER - 1) { - //printf("\n---------MAX_OBJECT_RECORDER - 1\n"); - //} - } - } - - } - } - } - } - - qsort(&g_ObjectRecorderList, MAX_OBJECT_RECORDER, sizeof(ObjectRecoder), sort_record_object); -} -#if defined GY_OS_AMBA || defined GY_OS_NOVA -void AddTWPlateDASH(detection_pos* PosInfo, int total_element_size, int featureType) -{ - if (activeDisplayDash && (featureType & FEATURE_LPR_TWN)) { - detection_pos* pNext = NULL; - - int iPlate_len = 0; - - int iFront_alpha_num = 0; - int iFront_digit_num = 0; - int iBack_alpha_num = 0; - int iBack_digit_num = 0; - - //for TWN plate, add dash if miss the dash. - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - - if (pNext->obj_type != _PLATE) - { - continue; - } - - if (strlen(pNext->properties.plate) <= 0) - { - continue; - } - - if (pNext->confidence <= 0.0) - { - continue; - } - - if (IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(pNext->name)) { - //Plate miss "-" - if (strstr(pNext->properties.plate, "-") == NULL) - { - iPlate_len = strlen(pNext->properties.plate); - - if (iPlate_len == 7) - { - insert_string(pNext->properties.plate, "-", 3); - } - else if (iPlate_len == 6) - { - iFront_alpha_num = 0; - iFront_digit_num = 0; - iBack_alpha_num = 0; - iBack_digit_num = 0; - int iFront_digit_num_length_4 = 0; - int iBack_digit_num_length_4 = 0; - int iFront_alpha_num_length_2 = 0; - int iBack_alpha_num_length_2 = 0; - - - for (int j = 0; j < 4; j++) - { - if (j <= 2 && isdigit(pNext->properties.plate[j]) != 0) - { - iFront_digit_num++; - } - - if (j <= 2 && isdigit(pNext->properties.plate[iPlate_len - 1 - j]) != 0) - { - iBack_digit_num++; - } - - if (j <= 3 && isdigit(pNext->properties.plate[j]) != 0) - { - iFront_digit_num_length_4++; - } - - if (j <= 3 && isdigit(pNext->properties.plate[iPlate_len - 1 - j]) != 0) - { - iBack_digit_num_length_4++; - } - - if (j <= 2 && isalpha(pNext->properties.plate[j]) != 0) - { - iFront_alpha_num++; - } - - if (j <= 2 && isalpha(pNext->properties.plate[iPlate_len - 1 - j]) != 0) - { - iBack_alpha_num++; - } - - if (j <= 1 && isalpha(pNext->properties.plate[j]) != 0) - { - iFront_alpha_num_length_2++; - } - - if (j <= 1 && isalpha(pNext->properties.plate[iPlate_len - 1 - j]) != 0) - { - iBack_alpha_num_length_2++; - } - } - - if ((iFront_digit_num == 3 && iBack_alpha_num == 3) || - (iFront_alpha_num == 3 && iBack_digit_num == 3)) { - insert_string(pNext->properties.plate, "-", 3); - } - else if ((iFront_digit_num_length_4 == 4 && iBack_alpha_num_length_2 == 2) || - (iFront_digit_num_length_4 == 4 && iBack_alpha_num_length_2 == 1)) { - insert_string(pNext->properties.plate, "-", 4); - } - else if (iFront_alpha_num_length_2 <= 2 && iFront_alpha_num_length_2 >= 1 && iBack_digit_num_length_4 == 4) { - insert_string(pNext->properties.plate, "-", 2); - } - else if (iFront_alpha_num <= 2 && iFront_alpha_num >= 1 && iBack_digit_num == 3) { - insert_string(pNext->properties.plate, "-", 3); - } - } - else if (iPlate_len == 5) - { - iFront_alpha_num = 0; - iFront_digit_num = 0; - iBack_alpha_num = 0; - iBack_digit_num = 0; - - for (int j = 0; j < 3; j++) - { - if (j <= 2 && isdigit(pNext->properties.plate[j]) != 0) - { - iFront_digit_num++; - } - - if (j <= 2 && isdigit(pNext->properties.plate[iPlate_len - 1 - j]) != 0) - { - iBack_digit_num++; - } - - if (j <= 1 && isalpha(pNext->properties.plate[j]) != 0) - { - iFront_alpha_num++; - } - - if (j <= 1 && isalpha(pNext->properties.plate[iPlate_len - 1 - j]) != 0) - { - iBack_alpha_num++; - } - } - - if ((iFront_digit_num == 3 && iBack_alpha_num == 2) || - (iFront_digit_num == 3 && iBack_digit_num == 1 && iBack_alpha_num == 1)) { - insert_string(pNext->properties.plate, "-", 3); - } - else if ((iFront_alpha_num == 2 && iBack_digit_num == 3) || - (iFront_alpha_num == 1 && iFront_digit_num == 1 && iBack_digit_num == 3)) { - insert_string(pNext->properties.plate, "-", 2); - } - } - else if (iPlate_len == 4) - { - insert_string(pNext->properties.plate, "-", 2); - } - - //printf(">>>>>>>>>>>>>>>>>>>>>>>> plate: %s \n", pNext->properties.plate); - } - - if (strstr(pNext->properties.plate, "-") == NULL) - { - pNext->confidence = 0.0; - } - } - else if (IsANPRCategory(pNext->engine_type) && !IsANPRCategory_L_Plate(pNext->name)) - { - pNext->confidence = 0.0; - } - } - } -} - -void MEAPlateRule(detection_pos* PosInfo, int total_element_size) -{ - detection_pos* pNext = NULL; - - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - if (IsANPRCategory_L_Plate(pNext->name)) - { - //printf("%d plate %d name = %s \n", i, pNext->parent_idx, pNext->properties.plate); - check_rule(pNext); - } - } - //printf("**************************************** \n"); -} -#endif - -#if 1 -int CheckTriggerCondition(detection_pos* pNext, int tracking_channel_idx, int detection_zone_idx, int trigger_idx, int tracking_obj_idx, int trigger_type, int total_element_size, detection_pos* PosInfo, int result_idx) -{ - //int nNotChecked = 0; - int nNeedTrigger = 0; - double diffSecs = 0; - double diffSecs2 = 0; - int detection_count = 0; - //char MetaData1[BUFSIZE] = { 0 }; - //char MetaData2[BUFSIZE] = { 0 }; - //char MetaOut1[512][50] = { 0 }; - //char MetaOut2[512][50] = { 0 }; - double d_no_parking_time = (double)viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time; - - if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute >= 1) { - d_no_parking_time = (double)(viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute * 60); - } - - detection_count = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; - - detection_pos* pNext_b; - - //for (int i = 0; i < MAX_TRIGGER_EVENT; i++) - //{ - -#if 0 - if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].checked <= 0) - return nNeedTrigger; -#endif - - char ObjectName[30] = { 0 }; - sprintf(ObjectName, "%s", pNext->name); - UpperToLower(ObjectName); - - //char metadata1[512][STRSPLIT_SIZE] = { 0 }; //for vehicle - //strcpy(MetaData1, viewDetectionZone[tracking_channel_idx][detection_zone_idx].metadata1); - - //printf("\n----CheckTriggerCondition--- start\n"); - int metadata1_num = get_metadata1_num(detection_zone_idx); - //printf("\n----CheckTriggerCondition--- end\n"); - - int temp_enable_person_for_metadata = person_if_existing_in_metaout(detection_zone_idx); - //for (int i = 0; i < metadata1_num; i++) - //{ - //UpperToLower(metadata1[i]); - //TrimSpace(MetaOut1[i], sizeof(MetaOut1[i]), metadata1[i], 0); - - //if (strcmp("person", MetaOut1[i]) == 0) { - //temp_enable_person_for_metadata = 1; - //} - //} - - g_enable_person_for_metadata[detection_zone_idx] = temp_enable_person_for_metadata; - -#if 0 - char metadata2[10][STRSPLIT_SIZE] = { 0 }; //for person - strcpy(MetaData2, viewDetectionZone[tracking_channel_idx][detection_zone_idx].metadata2); - int metadata2_num = StrSplit(MetaData2, metadata2, ","); - for (int i = 0; i < metadata2_num; i++) - { - UpperToLower(metadata2[i]); - TrimSpace(MetaOut2[i], sizeof(MetaOut2[i]), metadata2[i], 0); - } -#endif - -#if 0 - unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); -#endif - //for name comparison without case sensitive - - //float dewell_time = 2.78;//2.78 //4.2 - //float dewell_time2 = 4.2; - - if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) { -#if defined GY_OS_AMBA || defined GY_OS_NOVA - if (trigger_type == TRIGGER_ALLOW_LIST) - { - if ((pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && - pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) || - (strcmp(pNext->name, "ambulance") == 0) - || (strcmp(pNext->name, "blank") == 0) - || (strcmp(pNext->name, "stop_sign") == 0) - //|| (strcmp(pNext->name, "face") == 0) - ) - { - char afterBuf[256] = { 0 }; - if (strcmp(pNext->name, "ambulance") == 0) { - strcpy(afterBuf, pNext->name); - LowerToUpper(afterBuf); - } - else if (strcmp(pNext->name, "blank") == 0) { - strcpy(afterBuf, pNext->name); - LowerToUpper(afterBuf); - } - else if (strcmp(pNext->name, "stop_sign") == 0) { - strcpy(afterBuf, pNext->name); - LowerToUpper(afterBuf); - } - else - strcpy(afterBuf, pNext->properties.plate); - - if (check_if_in_white(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL) -#ifdef GY_OS_AMBA - //|| check_if_in_white_face(pNext->FDFR.face_name) -#endif - ) { - char schedule_start[50] = { 0 }; - char schedule_end[50] = { 0 }; - char detect_endtime[50] = { 0 }; - - /*if (strcmp(pNext->name, "face") == 0) - { -#ifdef GY_OS_AMBA - get_schedule_start_in_white_face(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - get_schedule_end_in_white_face(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - get_detect_endtime_in_white_face(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); -#endif - } - else */{ - get_schedule_start_in_white(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - get_schedule_end_in_white(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - get_detect_endtime_in_white(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - } - if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { - char c_start_hour[10] = { 0 }; - char c_start_minute[10] = { 0 }; - - char c_end_hour[10] = { 0 }; - char c_end_minute[10] = { 0 }; - - c_start_hour[0] = schedule_start[0]; - c_start_hour[1] = schedule_start[1]; - c_start_hour[2] = '\0'; - - c_start_minute[0] = schedule_start[3]; - c_start_minute[1] = schedule_start[4]; - c_start_minute[2] = '\0'; - - int i_start_hour = atoi(c_start_hour); - int i_start_minute = atoi(c_start_minute); - int i_total_start_minute = i_start_hour * 60 + i_start_minute; - - c_end_hour[0] = schedule_end[0]; - c_end_hour[1] = schedule_end[1]; - c_end_hour[2] = '\0'; - - c_end_minute[0] = schedule_end[3]; - c_end_minute[1] = schedule_end[4]; - c_end_minute[2] = '\0'; - - int i_end_hour = atoi(c_end_hour); - int i_end_minute = atoi(c_end_minute); - int i_total_end_minute = i_end_hour * 60 + i_end_minute; - - time_t rawtime = time(0); - struct tm * timeinfo; - timeinfo = localtime(&rawtime); - - int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; - - ///////////////////////// - - char c_year_endtime[10] = { 0 }; - c_year_endtime[0] = detect_endtime[0]; - c_year_endtime[1] = detect_endtime[1]; - c_year_endtime[2] = detect_endtime[2]; - c_year_endtime[3] = detect_endtime[3]; - c_year_endtime[4] = '\0'; - int i_year_endtime = atoi(c_year_endtime); - - char c_month_endtime[10] = { 0 }; - c_month_endtime[0] = detect_endtime[5]; - c_month_endtime[1] = detect_endtime[6]; - c_month_endtime[2] = '\0'; - int i_month_endtime = atoi(c_month_endtime); - - char c_day_endtime[10] = { 0 }; - c_day_endtime[0] = detect_endtime[8]; - c_day_endtime[1] = detect_endtime[9]; - c_day_endtime[2] = '\0'; - int i_day_endtime = atoi(c_day_endtime); - - char c_hour_endtime[10] = { 0 }; - c_hour_endtime[0] = detect_endtime[11]; - c_hour_endtime[1] = detect_endtime[12]; - c_hour_endtime[2] = '\0'; - int i_hour_endtime = atoi(c_hour_endtime); - - char c_minute_endtime[10] = { 0 }; - c_minute_endtime[0] = detect_endtime[14]; - c_minute_endtime[1] = detect_endtime[15]; - c_minute_endtime[2] = '\0'; - int i_minute_endtime = atoi(c_minute_endtime); - - int check_if_OK = 0; - if (1900 + timeinfo->tm_year < i_year_endtime) - check_if_OK = 1; - else if (1900 + timeinfo->tm_year == i_year_endtime) { - if (1 + timeinfo->tm_mon < i_month_endtime) - check_if_OK = 1; - else if (1 + timeinfo->tm_mon == i_month_endtime) { - if (timeinfo->tm_mday < i_day_endtime) - check_if_OK = 1; - else if (timeinfo->tm_mday == i_day_endtime) { - if (timeinfo->tm_hour < i_hour_endtime) - check_if_OK = 1; - else if (timeinfo->tm_hour == i_hour_endtime) { - if (timeinfo->tm_min < i_minute_endtime) - check_if_OK = 1; - } - } - } - } - - if (((i_total_start_minute < i_total_end_minute && - i_total_current_minute >= i_total_start_minute && - i_total_current_minute <= i_total_end_minute) || - (i_total_start_minute > i_total_end_minute && - (i_total_current_minute >= i_total_start_minute || - i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { - - //printf("trigger type 2 \n"); - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - { - //lasting time since enter zone - //printf("trigger type 3 \n"); - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - if (detection_count > 1) - diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - - - - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } -#if 0 - else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { - if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) - { - nNeedTrigger = 2; //post: yes, counter: no - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } -#endif - - //printf("trigger type 4 \n"); - /* - printf("\nnNeedTrigger:%d\n", nNeedTrigger); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - */ - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - - } - } - } - } - } - } - else if (trigger_type == TRIGGER_BLOCK_LIST) - { - if ((pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && - pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) || (strcmp(pNext->name, "ambulance") == 0) - || (strcmp(pNext->name, "blank") == 0) - || (strcmp(pNext->name, "stop_sign") == 0) - //|| (strcmp(pNext->name, "face") == 0) - ) - { - char afterBuf[256] = { 0 }; - if (strcmp(pNext->name, "ambulance") == 0) { - strcpy(afterBuf, pNext->name); - LowerToUpper(afterBuf); - } - else if (strcmp(pNext->name, "blank") == 0) { - strcpy(afterBuf, pNext->name); - LowerToUpper(afterBuf); - } - else if (strcmp(pNext->name, "stop_sign") == 0) { - strcpy(afterBuf, pNext->name); - LowerToUpper(afterBuf); - } - else - strcpy(afterBuf, pNext->properties.plate); - //printf("trigger type 1111 : %s\n", afterBuf); - - if (check_if_in_black(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL) -#ifdef GY_OS_AMBA - //|| check_if_in_black_face(pNext->FDFR.face_name) -#endif - ) { - //printf("trigger type 2 \n"); - char schedule_start[50] = { 0 }; - char schedule_end[50] = { 0 }; - char detect_endtime[50] = { 0 }; - - /*if (strcmp(pNext->name, "face") == 0) - { -#ifdef GY_OS_AMBA - get_schedule_start_in_black_face(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - get_schedule_end_in_black_face(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - get_detect_endtime_in_black_face(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); -#endif - } - else */{ - get_schedule_start_in_black(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - get_schedule_end_in_black(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - get_detect_endtime_in_black(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - } - - //printf("\n--------schedule_start:%s,schedule_end:%s\n", schedule_start, schedule_end); - if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { - char c_start_hour[10] = { 0 }; - char c_start_minute[10] = { 0 }; - - char c_end_hour[10] = { 0 }; - char c_end_minute[10] = { 0 }; - - c_start_hour[0] = schedule_start[0]; - c_start_hour[1] = schedule_start[1]; - c_start_hour[2] = '\0'; - - c_start_minute[0] = schedule_start[3]; - c_start_minute[1] = schedule_start[4]; - c_start_minute[2] = '\0'; - - int i_start_hour = atoi(c_start_hour); - int i_start_minute = atoi(c_start_minute); - int i_total_start_minute = i_start_hour * 60 + i_start_minute; - - c_end_hour[0] = schedule_end[0]; - c_end_hour[1] = schedule_end[1]; - c_end_hour[2] = '\0'; - - c_end_minute[0] = schedule_end[3]; - c_end_minute[1] = schedule_end[4]; - c_end_minute[2] = '\0'; - - int i_end_hour = atoi(c_end_hour); - int i_end_minute = atoi(c_end_minute); - int i_total_end_minute = i_end_hour * 60 + i_end_minute; - - time_t rawtime = time(0); - struct tm * timeinfo; - timeinfo = localtime(&rawtime); - - int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; - - /////////////////// - - char c_year_endtime[10] = { 0 }; - c_year_endtime[0] = detect_endtime[0]; - c_year_endtime[1] = detect_endtime[1]; - c_year_endtime[2] = detect_endtime[2]; - c_year_endtime[3] = detect_endtime[3]; - c_year_endtime[4] = '\0'; - int i_year_endtime = atoi(c_year_endtime); - - char c_month_endtime[10] = { 0 }; - c_month_endtime[0] = detect_endtime[5]; - c_month_endtime[1] = detect_endtime[6]; - c_month_endtime[2] = '\0'; - int i_month_endtime = atoi(c_month_endtime); - - char c_day_endtime[10] = { 0 }; - c_day_endtime[0] = detect_endtime[8]; - c_day_endtime[1] = detect_endtime[9]; - c_day_endtime[2] = '\0'; - int i_day_endtime = atoi(c_day_endtime); - - char c_hour_endtime[10] = { 0 }; - c_hour_endtime[0] = detect_endtime[11]; - c_hour_endtime[1] = detect_endtime[12]; - c_hour_endtime[2] = '\0'; - int i_hour_endtime = atoi(c_hour_endtime); - - char c_minute_endtime[10] = { 0 }; - c_minute_endtime[0] = detect_endtime[14]; - c_minute_endtime[1] = detect_endtime[15]; - c_minute_endtime[2] = '\0'; - int i_minute_endtime = atoi(c_minute_endtime); - - int check_if_OK = 0; - if (1900 + timeinfo->tm_year < i_year_endtime) - check_if_OK = 1; - else if (1900 + timeinfo->tm_year == i_year_endtime) { - if (1 + timeinfo->tm_mon < i_month_endtime) - check_if_OK = 1; - else if (1 + timeinfo->tm_mon == i_month_endtime) { - if (timeinfo->tm_mday < i_day_endtime) - check_if_OK = 1; - else if (timeinfo->tm_mday == i_day_endtime) { - if (timeinfo->tm_hour < i_hour_endtime) - check_if_OK = 1; - else if (timeinfo->tm_hour == i_hour_endtime) { - if (timeinfo->tm_min < i_minute_endtime) - check_if_OK = 1; - } - } - } - } - - if (((i_total_start_minute < i_total_end_minute && - i_total_current_minute >= i_total_start_minute && - i_total_current_minute <= i_total_end_minute) || - (i_total_start_minute > i_total_end_minute && - (i_total_current_minute >= i_total_start_minute || - i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { - - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - { - //lasting time since enter zone - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - if (detection_count > 1) - diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - - - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } -#if 0 - else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { - if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) - { - nNeedTrigger = 2; //post: yes, counter: no - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } -#endif - - - //printf("\nnNeedTrigger:%d\n", nNeedTrigger); - //printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - } - } - } - } - } - } - else if (trigger_type == TRIGGER_GUEST_LIST) - { - if ((pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && - pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) || (strcmp(pNext->name, "ambulance") == 0) - || (strcmp(pNext->name, "blank") == 0) - || (strcmp(pNext->name, "stop_sign") == 0) - //|| (strcmp(pNext->name, "face") == 0) - ) - { - char afterBuf[256] = { 0 }; - if (strcmp(pNext->name, "ambulance") == 0) { - strcpy(afterBuf, pNext->name); - LowerToUpper(afterBuf); - } - else if (strcmp(pNext->name, "blank") == 0) { - strcpy(afterBuf, pNext->name); - LowerToUpper(afterBuf); - } - else if (strcmp(pNext->name, "stop_sign") == 0) { - strcpy(afterBuf, pNext->name); - LowerToUpper(afterBuf); - } - else - strcpy(afterBuf, pNext->properties.plate); - int check_if_white_or_black_within_lifetime = 0; - -#if 1 - if (check_if_in_white(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL)) { - char schedule_start[50] = { 0 }; - char schedule_end[50] = { 0 }; - char detect_endtime[50] = { 0 }; - - get_schedule_start_in_white(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - get_schedule_end_in_white(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - get_detect_endtime_in_white(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - - if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { - char c_start_hour[10] = { 0 }; - char c_start_minute[10] = { 0 }; - - char c_end_hour[10] = { 0 }; - char c_end_minute[10] = { 0 }; - - c_start_hour[0] = schedule_start[0]; - c_start_hour[1] = schedule_start[1]; - c_start_hour[2] = '\0'; - - c_start_minute[0] = schedule_start[3]; - c_start_minute[1] = schedule_start[4]; - c_start_minute[2] = '\0'; - - int i_start_hour = atoi(c_start_hour); - int i_start_minute = atoi(c_start_minute); - int i_total_start_minute = i_start_hour * 60 + i_start_minute; - - c_end_hour[0] = schedule_end[0]; - c_end_hour[1] = schedule_end[1]; - c_end_hour[2] = '\0'; - - c_end_minute[0] = schedule_end[3]; - c_end_minute[1] = schedule_end[4]; - c_end_minute[2] = '\0'; - - int i_end_hour = atoi(c_end_hour); - int i_end_minute = atoi(c_end_minute); - int i_total_end_minute = i_end_hour * 60 + i_end_minute; - - time_t rawtime = time(0); - struct tm * timeinfo; - timeinfo = localtime(&rawtime); - - int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; - - ///////////////////////// - - char c_year_endtime[10] = { 0 }; - c_year_endtime[0] = detect_endtime[0]; - c_year_endtime[1] = detect_endtime[1]; - c_year_endtime[2] = detect_endtime[2]; - c_year_endtime[3] = detect_endtime[3]; - c_year_endtime[4] = '\0'; - int i_year_endtime = atoi(c_year_endtime); - - char c_month_endtime[10] = { 0 }; - c_month_endtime[0] = detect_endtime[5]; - c_month_endtime[1] = detect_endtime[6]; - c_month_endtime[2] = '\0'; - int i_month_endtime = atoi(c_month_endtime); - - char c_day_endtime[10] = { 0 }; - c_day_endtime[0] = detect_endtime[8]; - c_day_endtime[1] = detect_endtime[9]; - c_day_endtime[2] = '\0'; - int i_day_endtime = atoi(c_day_endtime); - - char c_hour_endtime[10] = { 0 }; - c_hour_endtime[0] = detect_endtime[11]; - c_hour_endtime[1] = detect_endtime[12]; - c_hour_endtime[2] = '\0'; - int i_hour_endtime = atoi(c_hour_endtime); - - char c_minute_endtime[10] = { 0 }; - c_minute_endtime[0] = detect_endtime[14]; - c_minute_endtime[1] = detect_endtime[15]; - c_minute_endtime[2] = '\0'; - int i_minute_endtime = atoi(c_minute_endtime); - - int check_if_OK = 0; - if (1900 + timeinfo->tm_year < i_year_endtime) - check_if_OK = 1; - else if (1900 + timeinfo->tm_year == i_year_endtime) { - if (1 + timeinfo->tm_mon < i_month_endtime) - check_if_OK = 1; - else if (1 + timeinfo->tm_mon == i_month_endtime) { - if (timeinfo->tm_mday < i_day_endtime) - check_if_OK = 1; - else if (timeinfo->tm_mday == i_day_endtime) { - if (timeinfo->tm_hour < i_hour_endtime) - check_if_OK = 1; - else if (timeinfo->tm_hour == i_hour_endtime) { - if (timeinfo->tm_min < i_minute_endtime) - check_if_OK = 1; - } - } - } - } - - if (((i_total_start_minute < i_total_end_minute && - i_total_current_minute >= i_total_start_minute && - i_total_current_minute <= i_total_end_minute) || - (i_total_start_minute > i_total_end_minute && - (i_total_current_minute >= i_total_start_minute || - i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { - check_if_white_or_black_within_lifetime = 1; - } - } - } - - if (check_if_in_black(afterBuf, pNext->properties.area, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance),NULL)) { - //printf("trigger type 2 \n"); - char schedule_start[50] = { 0 }; - char schedule_end[50] = { 0 }; - char detect_endtime[50] = { 0 }; - - get_schedule_start_in_black(afterBuf, pNext->properties.area, schedule_start, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - get_schedule_end_in_black(afterBuf, pNext->properties.area, schedule_end, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - get_detect_endtime_in_black(afterBuf, pNext->properties.area, detect_endtime, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)); - - if ((int)strlen(schedule_start) >= 5 && (int)strlen(schedule_end) >= 5) { - char c_start_hour[10] = { 0 }; - char c_start_minute[10] = { 0 }; - - char c_end_hour[10] = { 0 }; - char c_end_minute[10] = { 0 }; - - c_start_hour[0] = schedule_start[0]; - c_start_hour[1] = schedule_start[1]; - c_start_hour[2] = '\0'; - - c_start_minute[0] = schedule_start[3]; - c_start_minute[1] = schedule_start[4]; - c_start_minute[2] = '\0'; - - int i_start_hour = atoi(c_start_hour); - int i_start_minute = atoi(c_start_minute); - int i_total_start_minute = i_start_hour * 60 + i_start_minute; - - c_end_hour[0] = schedule_end[0]; - c_end_hour[1] = schedule_end[1]; - c_end_hour[2] = '\0'; - - c_end_minute[0] = schedule_end[3]; - c_end_minute[1] = schedule_end[4]; - c_end_minute[2] = '\0'; - - int i_end_hour = atoi(c_end_hour); - int i_end_minute = atoi(c_end_minute); - int i_total_end_minute = i_end_hour * 60 + i_end_minute; - - time_t rawtime = time(0); - struct tm * timeinfo; - timeinfo = localtime(&rawtime); - - int i_total_current_minute = ((int)timeinfo->tm_hour) * 60 + (int)timeinfo->tm_min; - - /////////////////// - - char c_year_endtime[10] = { 0 }; - c_year_endtime[0] = detect_endtime[0]; - c_year_endtime[1] = detect_endtime[1]; - c_year_endtime[2] = detect_endtime[2]; - c_year_endtime[3] = detect_endtime[3]; - c_year_endtime[4] = '\0'; - int i_year_endtime = atoi(c_year_endtime); - - char c_month_endtime[10] = { 0 }; - c_month_endtime[0] = detect_endtime[5]; - c_month_endtime[1] = detect_endtime[6]; - c_month_endtime[2] = '\0'; - int i_month_endtime = atoi(c_month_endtime); - - char c_day_endtime[10] = { 0 }; - c_day_endtime[0] = detect_endtime[8]; - c_day_endtime[1] = detect_endtime[9]; - c_day_endtime[2] = '\0'; - int i_day_endtime = atoi(c_day_endtime); - - char c_hour_endtime[10] = { 0 }; - c_hour_endtime[0] = detect_endtime[11]; - c_hour_endtime[1] = detect_endtime[12]; - c_hour_endtime[2] = '\0'; - int i_hour_endtime = atoi(c_hour_endtime); - - char c_minute_endtime[10] = { 0 }; - c_minute_endtime[0] = detect_endtime[14]; - c_minute_endtime[1] = detect_endtime[15]; - c_minute_endtime[2] = '\0'; - int i_minute_endtime = atoi(c_minute_endtime); - - int check_if_OK = 0; - if (1900 + timeinfo->tm_year < i_year_endtime) - check_if_OK = 1; - else if (1900 + timeinfo->tm_year == i_year_endtime) { - if (1 + timeinfo->tm_mon < i_month_endtime) - check_if_OK = 1; - else if (1 + timeinfo->tm_mon == i_month_endtime) { - if (timeinfo->tm_mday < i_day_endtime) - check_if_OK = 1; - else if (timeinfo->tm_mday == i_day_endtime) { - if (timeinfo->tm_hour < i_hour_endtime) - check_if_OK = 1; - else if (timeinfo->tm_hour == i_hour_endtime) { - if (timeinfo->tm_min < i_minute_endtime) - check_if_OK = 1; - } - } - } - } - - if (((i_total_start_minute < i_total_end_minute && - i_total_current_minute >= i_total_start_minute && - i_total_current_minute <= i_total_end_minute) || - (i_total_start_minute > i_total_end_minute && - (i_total_current_minute >= i_total_start_minute || - i_total_current_minute <= i_total_end_minute))) && check_if_OK == 1) { - check_if_white_or_black_within_lifetime = 1; - } - } - } -#endif - if (check_if_white_or_black_within_lifetime == 0) { - //printf("trigger type 2 \n"); - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - { - //lasting time since enter zone - //printf("trigger type 3 \n"); - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - if (detection_count > 1) - diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - - - - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } -#if 0 - else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { - if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) - { - nNeedTrigger = 2; //post: yes, counter: no - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } -#endif - - //printf("trigger type 4 \n"); - /* - printf("\nnNeedTrigger:%d\n", nNeedTrigger); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - */ - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - - } - } - } - } - else if (trigger_type == TRIGGER_GO_STRAIGHT) - { - int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); - //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; - //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; - //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; - - //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); - //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) - { - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); - int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; - - /* - printf("\n----center direction queue:"); - for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { - printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); - } - printf("----center direction end--\n");*/ - - - - int check_if_stability = 1; - - - if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { - if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { - float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); - if (diff_angle > 180.0) - diff_angle = 360.0 - diff_angle; - - if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { - check_if_stability = 0; - //printf("\ndrop out\n"); - } - } - } - - if(check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx)==1) - { - if (IsANPRCategory_L_Plate(pNext->name)==1) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); - nNeedTrigger = 1; - pNext->zone_violation_idx[detection_zone_idx] = 1; - } - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - } - } - else if (trigger_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) - { - if (get_g_check_if_current_light_is_red() == 1) { - int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); - //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; - //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; - //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; - - //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); - //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) - { - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); - int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; - /* - printf("\n----center direction queue:"); - for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { - printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); - } - printf("----center direction end--\n"); - */ - - int check_if_stability = 1; - if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { - if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { - float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); - if (diff_angle > 180.0) - diff_angle = 360.0 - diff_angle; - - if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { - check_if_stability = 0; - //printf("\ndrop out\n"); - } - } - } - - if (check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) - { - if (IsANPRCategory_L_Plate(pNext->name) == 1) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); - nNeedTrigger = 1; - pNext->zone_violation_idx[detection_zone_idx] = 1; - } - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - } - } - } - else if (trigger_type == TRIGGER_TURN_LEFT_RED_LIGHT) - { - if (get_g_check_if_current_light_is_red() == 1) { - int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); - int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; - //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; - //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; - - //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); - //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) - { - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); - int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; - /* - printf("\n----center direction queue:"); - for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { - printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); - } - printf("----center direction end--\n"); - */ - - int check_if_stability = 1; - if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { - if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { - float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); - if (diff_angle > 180.0) - diff_angle = 360.0 - diff_angle; - - if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { - check_if_stability = 0; - //printf("\ndrop out\n"); - } - } - } - - if (check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) - { - if (IsANPRCategory_L_Plate(pNext->name) == 1) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); - nNeedTrigger = 1; - pNext->zone_violation_idx[detection_zone_idx] = 1; - } - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - } - } - } - else if (trigger_type == TRIGGER_TURN_RIGHT_RED_LIGHT) - { - if (get_g_check_if_current_light_is_red() == 1) { - int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); - //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; - //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; - int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; - - //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); - //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) - { - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); - int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; - /* - printf("\n----center direction queue:"); - for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { - printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); - } - printf("----center direction end--\n"); - */ - - int check_if_stability = 1; - if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { - if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { - float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); - if (diff_angle > 180.0) - diff_angle = 360.0 - diff_angle; - - if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { - check_if_stability = 0; - //printf("\ndrop out\n"); - } - } - } - - if (check_if_stability == 1 && check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) - { - if (IsANPRCategory_L_Plate(pNext->name) == 1) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); - nNeedTrigger = 1; - pNext->zone_violation_idx[detection_zone_idx] = 1; - } - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - } - } - } - else if (trigger_type == TRIGGER_PARKING_VIOLATION) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) { - //printf("1111 \n"); - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) - // printf("1111-1 \n"); - - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - // printf("1111-2 \n"); - - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) - { - //lasting time since enter zone - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - if (detection_count > 1) - diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - int nDiffSecs = (int)diffSecs; - int nDiffSecs2 = (int)diffSecs2; - float distCenter = 0; - pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[0]; - distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); - - if (/*(strcmp(ObjectName, "car") == 0 || (strcmp(ObjectName, "truck") == 0)) - && */distCenter > 1) - { - //printf("distCenter = %f \n", distCenter); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; - } - - //printf("park time: %d, det time: %d \n", diffSecs, d_no_parking_time); - //printf("\ndiffSecs: %d\n",(int)diffSecs); - //printf("\nd_no_parking_time: %d\n", (int)d_no_parking_time); - - int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; - if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) - { - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] += diff_secs_in_zone; - - //printf("%d, %d, diffSecs = %f \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, diffSecs); - //for (int j = 0; j < metadata1_num; j++) - { - //if (strcmp(ObjectName, MetaOut1[j]) == 0 /*|| strstr(ObjectName, "plate") != NULL*/) - { - if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { -#if 0 //Open for 華電 避免塞車誤報 - //printf("AAAAAAA %s \n", "nNeedTrigger 1"); - //nNeedTrigger = 1; - //pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1]; - //distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); - - //printf("center diff = %d \n", distCenter); - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1] - //check prev iou > 60 - //printf("iou self 1 = %d \n", pNext->iou_prev_self); - if (pNext->iou_prev_self >= 98) - { - if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) - { - if (pNext->near_iou_count[detection_zone_idx] <= 1) - { - //printf("[%d]wwww %d \n", detection_zone_idx, pNext->near_iou_count[detection_zone_idx]); - nNeedTrigger = 1; - - //pNext->trigger_type = trigger_type; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - else - { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; - } -#else - //printf("33334444 \n"); - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; -#endif - } - else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { -#if 0 //Open for 華電 避免塞車誤報 - //printf("iou self 2 = %d \n", pNext->iou_prev_self); - //check prev iou > 60 - - if (pNext->iou_prev_self >= 98) - { - if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) - { - if (pNext->near_iou_count[detection_zone_idx] <= 1) - { - //printf("[%d]xxxx %d \n", pNext->obj_tracking_id_idx, pNext->near_iou_count[detection_zone_idx]); - nNeedTrigger = 2; - - //pNext->trigger_type = trigger_type; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - else - { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; - } -#else //Normal - if ((nDiffSecs - nDiffSecs2) >= 1 /*&& nDiffSecs % TRIGGER_INTERVAL == 0*/) - { - nNeedTrigger = 2; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } -#endif - } -#if 0 //Open for 華電 避免塞車誤報 - if (pNext->iou_prev_self >= 98 && pNext->near_iou_count[detection_zone_idx] <= 1) - { - - pNext->trigger_type = trigger_type; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - break; - } - else - break; -#else - //printf("33338888 \n"); - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - pNext->zone_violation_idx[detection_zone_idx] = 1; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - if (diff_secs_in_zone < d_no_parking_time + 5) { - viewDetectionZone[0][detection_zone_idx].det_time = time(0); - } -#endif - - } - } - } - } - - //printf("4444 \n"); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) - { - //for (int j = 0; j < metadata1_num; j++) - { - //if (strcmp(ObjectName, MetaOut1[j]) == 0) - { - nNeedTrigger = 0; - //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - - } - } - else if (trigger_type == TRIGGER_ZONE_VIOLATION) - { - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - if(check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1) - { - //lasting time since enter zone - //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //if (detection_count > 1) - //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - - //if ((int)pNext->obj_dwell_time % 2 == 0) - { - //for (int j = 0; j < metadata1_num; j++) - { - //if (strcmp(ObjectName, MetaOut1[j]) == 0) - { - //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); - //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); - /* - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); - printf("\ntrigger_type:%d\n",trigger_type); - */ - - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //nNeedTrigger = 1; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { - //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) - { - //nNeedTrigger = 2; //post: yes, counter: no - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - - /* - printf("\nnNeedTrigger:%d\n", nNeedTrigger); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - */ - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } -#ifdef GY_OS_AMBA - else if (trigger_type == TRIGGER_SPEED_HIGH) - { - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - if (pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed > viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) - { - //lasting time since enter zone - //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //if (detection_count > 1) - //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - - //if ((int)pNext->obj_dwell_time % 2 == 0) - { - //for (int j = 0; j < metadata1_num; j++) - { - //if (strcmp(ObjectName, MetaOut1[j]) == 0) - { - //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); - //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); - /* - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); - printf("\ntrigger_type:%d\n",trigger_type); - */ - - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //nNeedTrigger = 1; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { - //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) - { - //nNeedTrigger = 2; //post: yes, counter: no - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - - /* - printf("\nnNeedTrigger:%d\n", nNeedTrigger); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - */ - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } - else if (trigger_type == TRIGGER_SPEED_LOW) - { - - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - if (pNext->adjust_obj_speed != -1 && pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed < viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) - { - //lasting time since enter zone - //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //if (detection_count > 1) - //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - - //if ((int)pNext->obj_dwell_time % 2 == 0) - { - //for (int j = 0; j < metadata1_num; j++) - { - //if (strcmp(ObjectName, MetaOut1[j]) == 0) - { - //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); - //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); - /* - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); - printf("\ntrigger_type:%d\n",trigger_type); - */ - - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //nNeedTrigger = 1; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { - //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) - { - //nNeedTrigger = 2; //post: yes, counter: no - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - - /* - printf("\nnNeedTrigger:%d\n", nNeedTrigger); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - */ - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } -#endif - else if (trigger_type == TRIGGER_ALL_OBJECTS) - { - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && - ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP - )) && - ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[detection_zone_idx] == 1) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) - ) { - - //printf("\nAAAAAAAAAAA: 1\n"); - - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1 && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { - - int nearest_index = -1; - float nearest_distance = (float)INF; - - for (int j = 0; j < total_element_size; j++) - { - if (j != result_idx) { - detection_pos *pNext_bring = PosInfo + j; - - if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0) { - if (check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx) && IsGarbageCategory(pNext_bring)) - { - //nNeedTrigger = 1; - //printf("\n-----plate(%f,%f),object(%f,%f)\n", pNext->center_x, pNext->center_y, pNext_bring->center_x, pNext_bring->center_y); - - float temp_nearest_distance = sqrt(pow(pNext->center_x- pNext_bring->center_x,2)+ pow(pNext->center_y - pNext_bring->center_y,2)); - if (temp_nearest_distance < nearest_distance) { - nearest_index = j; - nearest_distance = temp_nearest_distance; - } - } - } - } - } - - if (nearest_index >= 0) { - - detection_pos *pNext_bring = PosInfo + nearest_index; - - pNext_bring->trigger_type = trigger_type | pNext_bring->trigger_type; - pNext_bring->trigger_idx[detection_zone_idx] = trigger_idx; - pNext_bring->zone_violation_idx[detection_zone_idx] = 1; - - strcpy(pNext_bring->linked_plate, pNext->properties.plate); - pNext_bring->linked_plate_length = pNext->properties.plate_length; - - if (pNext_bring->obj_tracking_id_idx >= 0) { - g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_zone_id = detection_zone_idx + 1; - g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_type = pNext_bring->trigger_type; - g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext_bring->det_time; - //viewDetectionZone[0][detection_zone_idx].det_time = pNext_bring->det_time; - - strcpy(g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate, pNext->properties.plate); - g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate_length = pNext->properties.plate_length; - } - } - } - } - } - else { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx) == 1 /*&& ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)*/) { - - int nearest_index = -1; - float nearest_distance = (float)INF; - - for (int j = 0; j < total_element_size; j++) - { - if (j != result_idx) { - detection_pos *pNext_bring = PosInfo + j; - - if (check_if_object_in_zone_simple_version_not_plate(pNext_bring, detection_zone_idx) /*&& IsGarbageCategory(pNext_bring)*/) - { - float temp_nearest_distance = sqrt(pow(pNext->center_x - pNext_bring->center_x, 2) + pow(pNext->center_y - pNext_bring->center_y, 2)); - if (temp_nearest_distance < nearest_distance) { - nearest_index = j; - nearest_distance = temp_nearest_distance; - } - } - } - } - - if (nearest_index >= 0) { - - detection_pos *pNext_bring = PosInfo + nearest_index; - - pNext_bring->trigger_type = trigger_type | pNext_bring->trigger_type; - pNext_bring->trigger_idx[detection_zone_idx] = trigger_idx; - pNext_bring->zone_violation_idx[detection_zone_idx] = 1; - - strcpy(pNext_bring->linked_plate, pNext->properties.plate); - pNext_bring->linked_plate_length = pNext->properties.plate_length; - - if (pNext_bring->obj_tracking_id_idx >= 0) { - g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_zone_id = detection_zone_idx + 1; - g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_type = pNext_bring->trigger_type; - g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext_bring->det_time; - //viewDetectionZone[0][detection_zone_idx].det_time = pNext_bring->det_time; - - strcpy(g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate, pNext->properties.plate); - g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].linked_plate_length = pNext->properties.plate_length; - } - } - } - } - } - } -#endif - } - else{ - if (trigger_type == TRIGGER_MISSING_UNATTENDED) - { - //printf("1111 \n"); - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) - // printf("1111-1 \n"); - - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - // printf("1111-2 \n"); - - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) - { - //lasting time since enter zone - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - if (detection_count > 1) - diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - int nDiffSecs = (int)diffSecs; - int nDiffSecs2 = (int)diffSecs2; - float distCenter = 0; - pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[0]; - distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); - - if ((strcmp(ObjectName, "object") == 0) && distCenter > 1) - { - //printf("distCenter = %f \n", distCenter); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; - } - - //printf("park time: %d, det time: %d \n", diffSecs, d_no_parking_time); - //printf("\ndiffSecs: %d\n",(int)diffSecs); - //printf("\nd_no_parking_time: %d\n", (int)d_no_parking_time); - int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; - if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) - { - - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] += diff_secs_in_zone; - //printf("%d, %d, diffSecs = %f \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, diffSecs); - - if (strcmp(ObjectName,"object")==0) - { - if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { -#if 0 //Open for 華電 避免塞車誤報 - //printf("AAAAAAA %s \n", "nNeedTrigger 1"); - //nNeedTrigger = 1; - //pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1]; - //distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); - - //printf("center diff = %d \n", distCenter); - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1] -//check prev iou > 60 - //printf("iou self 1 = %d \n", pNext->iou_prev_self); - if (pNext->iou_prev_self >= 98) - { - if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) - { - if (pNext->near_iou_count[detection_zone_idx] <= 1) - { - //printf("[%d]wwww %d \n", detection_zone_idx, pNext->near_iou_count[detection_zone_idx]); - nNeedTrigger = 1; - - //pNext->trigger_type = trigger_type; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - else - { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; - } -#else - //printf("33334444 \n"); - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; -#endif - } - else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { -#if 0 //Open for 華電 避免塞車誤報 - //printf("iou self 2 = %d \n", pNext->iou_prev_self); - //check prev iou > 60 - - if (pNext->iou_prev_self >= 98) - { - if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) - { - if (pNext->near_iou_count[detection_zone_idx] <= 1) - { - //printf("[%d]xxxx %d \n", pNext->obj_tracking_id_idx, pNext->near_iou_count[detection_zone_idx]); - nNeedTrigger = 2; - - //pNext->trigger_type = trigger_type; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - else - { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; - } -#else //Normal - if ((nDiffSecs - nDiffSecs2) >= 1 /*&& nDiffSecs % TRIGGER_INTERVAL == 0*/) - { - nNeedTrigger = 2; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } -#endif - } -#if 0 //Open for 華電 避免塞車誤報 - if (pNext->iou_prev_self >= 98 && pNext->near_iou_count[detection_zone_idx] <= 1) - { - - pNext->trigger_type = trigger_type; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - } -#else - //printf("33338888 \n"); - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; -#endif - - } - } - } - //printf("4444 \n"); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) - { - if (strcmp(ObjectName, "object") == 0) - { - nNeedTrigger = 0; - //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - } - } - } - else if (trigger_type == TRIGGER_GO_STRAIGHT) - { - int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); - //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; - //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; - //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; - - //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); - //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) - { - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); - int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; - /* - printf("\n----center direction queue:"); - for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { - printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); - } - printf("----center direction end--\n"); - */ - - int check_if_stability = 1; - if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { - if ( (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { - float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); - if (diff_angle > 180.0) - diff_angle = 360.0 - diff_angle; - - if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { - check_if_stability = 0; - //printf("\ndrop out\n"); - } - } - } - - if (check_if_stability == 1) { - //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); - //for (int j = 0; j < metadata1_num; j++) - { - - - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); - nNeedTrigger = 1; - pNext->zone_violation_idx[detection_zone_idx] = 1; - } - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - //break; - - } - } - } - } - } - else if (trigger_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) - { - if (get_g_check_if_current_light_is_red() == 1) { - int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); - //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; - //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; - //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; - - //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); - //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0) - { - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); - int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; - /* - printf("\n----center direction queue:"); - for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { - printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); - } - printf("----center direction end--\n"); - */ - - int check_if_stability = 1; - if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { - if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { - float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); - if (diff_angle > 180.0) - diff_angle = 360.0 - diff_angle; - - if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { - check_if_stability = 0; - //printf("\ndrop out\n"); - } - } - } - - if (check_if_stability == 1) { - //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); - //for (int j = 0; j < metadata1_num; j++) - { - - - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); - nNeedTrigger = 1; - pNext->zone_violation_idx[detection_zone_idx] = 1; - } - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - //break; - - } - } - } - } - } - } - else if (trigger_type == TRIGGER_TURN_LEFT_RED_LIGHT) - { - if (get_g_check_if_current_light_is_red() == 1) { - int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); - int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; - //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; - //int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; - - //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); - //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) - { - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); - int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; - /* - printf("\n----center direction queue:"); - for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { - printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); - } - printf("----center direction end--\n"); - */ - - int check_if_stability = 1; - if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { - if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { - float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); - if (diff_angle > 180.0) - diff_angle = 360.0 - diff_angle; - - if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { - check_if_stability = 0; - //printf("\ndrop out\n"); - } - } - } - - if (check_if_stability == 1) { - //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); - //for (int j = 0; j < metadata1_num; j++) - { - - - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); - nNeedTrigger = 1; - pNext->zone_violation_idx[detection_zone_idx] = 1; - } - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - //break; - - } - } - } - } - } - } - else if (trigger_type == TRIGGER_TURN_RIGHT_RED_LIGHT) - { - if (get_g_check_if_current_light_is_red() == 1) { - int forward_line = atoi(viewDetectionZone[tracking_channel_idx][detection_zone_idx].direction1); - //int left_line = ((forward_line + 1) > DETECTION_POINTS_COUNT) ? (forward_line + 1) - DETECTION_POINTS_COUNT : forward_line + 1; - //int backward_line = ((forward_line + 2) > DETECTION_POINTS_COUNT) ? (forward_line + 2) - DETECTION_POINTS_COUNT : forward_line + 2; - int right_line = ((forward_line + 3) > DETECTION_POINTS_COUNT) ? (forward_line + 3) - DETECTION_POINTS_COUNT : forward_line + 3; - - //printf("\n---------------------TRIGGER GO STRAIGHT: 2\n"); - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d\n", detection_zone_idx+1,g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line); - //printf("\n---------------------TRIGGER GO STRAIGHT: 2: enter_zone_line[detection_zone_idx]: %d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx]); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) - { - //printf("\nTo check the direction: leave_zone_line(%dth): %d ; forward_line: %d; center_direction: %d;\n", detection_zone_idx + 1, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx], forward_line,(int)pNext->center_direction); - int detection_count_temp = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].detection_count; - /* - printf("\n----center direction queue:"); - for (int index_detect = 0; index_detect < detection_count_temp; index_detect++) { - printf("%d,", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[index_detect]); - } - printf("----center direction end--\n"); - */ - - int check_if_stability = 1; - if (detection_count_temp >= 2 && (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] != 404) { - if ((int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2] != 404) { - float diff_angle = fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 1] - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_center_direction[detection_count_temp - 2]); - if (diff_angle > 180.0) - diff_angle = 360.0 - diff_angle; - - if (diff_angle >= DIFF_ANGLE_TO_DROP_OUT) { - check_if_stability = 0; - //printf("\ndrop out\n"); - } - } - } - - if (check_if_stability == 1) { - //printf("\n---------------------TRIGGER GO STRAIGHT: 3: ObjectName: %s\n", ObjectName); - //for (int j = 0; j < metadata1_num; j++) - { - - - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 4\n"); - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //printf("\n---------------------TRIGGER GO STRAIGHT: 5\n"); - nNeedTrigger = 1; - pNext->zone_violation_idx[detection_zone_idx] = 1; - } - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - //break; - - } - } - } - } - } - } - else if (trigger_type == TRIGGER_PARKING_VIOLATION) - { - //printf("1111 \n"); - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) - // printf("1111-1 \n"); - - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - // printf("1111-2 \n"); - - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0) - { - //lasting time since enter zone - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - if (detection_count > 1) - diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - int nDiffSecs = (int)diffSecs; - int nDiffSecs2 = (int)diffSecs2; - float distCenter = 0; - pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[0]; - distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); - - if (/*(strcmp(ObjectName, "car") == 0 || strcmp(ObjectName, "truck") == 0 || strcmp(ObjectName, "car_front_back") == 0)*/ - (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) - && distCenter > 1) - { - //printf("distCenter = %f \n", distCenter); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; - } - - //printf("park time: %d, det time: %d \n", diffSecs, d_no_parking_time); - //printf("\ndiffSecs: %d\n",(int)diffSecs); - //printf("\nd_no_parking_time: %d\n", (int)d_no_parking_time); - - int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; - if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) - { - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] += diff_secs_in_zone; - - //printf("%d, %d, diffSecs = %f \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, diffSecs); - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx) /*|| strstr(ObjectName, "plate") != NULL*/) - { - if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { -#if 0 //Open for 華電 避免塞車誤報 - //printf("AAAAAAA %s \n", "nNeedTrigger 1"); - //nNeedTrigger = 1; - //pNext_b = &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1]; - //distCenter = sqrt(pow((pNext->left_x + pNext->width / 2) - (pNext_b->left_x + pNext_b->width / 2), 2) + pow((pNext->top_y + pNext->height / 2) - (pNext_b->top_y + pNext_b->height / 2), 2)); - - //printf("center diff = %d \n", distCenter); - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1] -//check prev iou > 60 - //printf("iou self 1 = %d \n", pNext->iou_prev_self); - if (pNext->iou_prev_self >= 98) - { - if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) - { - if (pNext->near_iou_count[detection_zone_idx] <= 1) - { - //printf("[%d]wwww %d \n", detection_zone_idx, pNext->near_iou_count[detection_zone_idx]); - nNeedTrigger = 1; - - //pNext->trigger_type = trigger_type; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - else - { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; - } -#else - //printf("33334444 \n"); - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; -#endif - } - else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { -#if 0 //Open for 華電 避免塞車誤報 - //printf("iou self 2 = %d \n", pNext->iou_prev_self); - //check prev iou > 60 - - if (pNext->iou_prev_self >= 98) - { - if ((nDiffSecs - nDiffSecs2) >= 1 && nDiffSecs % TRIGGER_INTERVAL == 0) - { - if (pNext->near_iou_count[detection_zone_idx] <= 1) - { - //printf("[%d]xxxx %d \n", pNext->obj_tracking_id_idx, pNext->near_iou_count[detection_zone_idx]); - nNeedTrigger = 2; - - //pNext->trigger_type = trigger_type; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - else - { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time; - } -#else //Normal - if ((nDiffSecs - nDiffSecs2) >= 1 /*&& nDiffSecs % TRIGGER_INTERVAL == 0*/) - { - nNeedTrigger = 2; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } -#endif - } -#if 0 //Open for 華電 避免塞車誤報 - if (pNext->iou_prev_self >= 98 && pNext->near_iou_count[detection_zone_idx] <= 1) - { - - pNext->trigger_type = trigger_type; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - //else - //break; -#else - //printf("33338888 \n"); - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - pNext->zone_violation_idx[detection_zone_idx] = 1; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - if (diff_secs_in_zone < d_no_parking_time + 5) { - viewDetectionZone[0][detection_zone_idx].det_time = time(0); - } -#endif - - } - } - } - } - - //printf("4444 \n"); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - nNeedTrigger = 0; - //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - else if (trigger_type == TRIGGER_ZONE_VIOLATION) - { - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - { - //lasting time since enter zone - //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //if (detection_count > 1) - //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - - //if ((int)pNext->obj_dwell_time % 2 == 0) - //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; - //if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") != 0 || strcmp("person", pNext->name) == 0 || - // (diff_secs_in_zone >= 1 && diff_secs_in_zone > 0 && (int)(pNext->center_stability) != DIRECTION_DEFAULT)) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); - //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); - /* - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); - printf("\ntrigger_type:%d\n",trigger_type); - */ - - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //nNeedTrigger = 1; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { - //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) - { - //nNeedTrigger = 2; //post: yes, counter: no - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - - /* - printf("\nnNeedTrigger:%d\n", nNeedTrigger); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - */ - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } -#ifdef GY_OS_AMBA - else if (trigger_type == TRIGGER_DISTANCE_VIOLATION) - { - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - //printf("\n--------g_max_tof_range:%f\n", g_max_tof_range); - //printf("\n-------atof(tofData.distance_threshold):%f\n", atof(tofData.distance_threshold)); - - int check_if_OK_tof = 0; - - if (strcmp(tofData.distance_options, "gt") == 0) { - if (strcmp(tofData.distance_min_max, "min") == 0) { - if (g_min_tof_distance > atof(tofData.distance_threshold) && pNext->min_distance != 0) { - check_if_OK_tof = 1; - } - } - else if (strcmp(tofData.distance_min_max, "max") == 0) { - if (g_max_tof_distance > atof(tofData.distance_threshold) && pNext->max_distance != 0) { - check_if_OK_tof = 1; - } - } - } - else if (strcmp(tofData.distance_options, "lt") == 0) { - if (strcmp(tofData.distance_min_max, "min") == 0) { - if (g_min_tof_distance < atof(tofData.distance_threshold) && pNext->min_distance != 0) { - check_if_OK_tof = 1; - } - } - else if (strcmp(tofData.distance_min_max, "max") == 0) { - if (g_max_tof_distance < atof(tofData.distance_threshold) && pNext->max_distance != 0) { - check_if_OK_tof = 1; - } - } - } - - if(check_if_OK_tof == 1) - { - //lasting time since enter zone - //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //if (detection_count > 1) - //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - - //if ((int)pNext->obj_dwell_time % 2 == 0) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (strcmp(ObjectName,"tof_point") == 0) - { - //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); - //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); - /* - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); - printf("\ntrigger_type:%d\n",trigger_type); - */ - - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //nNeedTrigger = 1; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { - //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) - { - //nNeedTrigger = 2; //post: yes, counter: no - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - - /* - printf("\nnNeedTrigger:%d\n", nNeedTrigger); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - */ - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } - else if (trigger_type == TRIGGER_HIGH_VIOLATION) - { - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - - int check_if_OK_tof = 0; - - if (strcmp(tofData.height_options, "gt") == 0) { - if (strcmp(tofData.height_min_max, "min") == 0) { - if (g_min_tof_height > atof(tofData.height_threshold) && pNext->min_height != 0) { - check_if_OK_tof = 1; - } - } - else if (strcmp(tofData.height_min_max, "max") == 0) { - if (g_max_tof_height > atof(tofData.height_threshold) && pNext->max_height != 0) { - check_if_OK_tof = 1; - } - } - } - else if (strcmp(tofData.height_options, "lt") == 0) { - if (strcmp(tofData.height_min_max, "min") == 0) { - if (g_min_tof_height < atof(tofData.height_threshold) && pNext->min_height != 0) { - check_if_OK_tof = 1; - } - } - else if (strcmp(tofData.height_min_max, "max") == 0) { - if (g_max_tof_height < atof(tofData.height_threshold) && pNext->max_height != 0) { - check_if_OK_tof = 1; - } - } - } - - if (check_if_OK_tof == 1) - { - //lasting time since enter zone - //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //if (detection_count > 1) - //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - - //if ((int)pNext->obj_dwell_time % 2 == 0) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (strcmp(ObjectName, "tof_point") == 0) - { - //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); - //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); - /* - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); - printf("\ntrigger_type:%d\n",trigger_type); - */ - - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //nNeedTrigger = 1; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { - //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) - { - //nNeedTrigger = 2; //post: yes, counter: no - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - - /* - printf("\nnNeedTrigger:%d\n", nNeedTrigger); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - */ - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } -#endif - else if (trigger_type == TRIGGER_FORGET_TO_GIVE_WAY) - { - - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - { - //lasting time since enter zone - //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //if (detection_count > 1) - //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - - //if ((int)pNext->obj_dwell_time % 2 == 0) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); - //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); - /* - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); - printf("\ntrigger_type:%d\n",trigger_type); - */ - - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //nNeedTrigger = 1; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { - //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) - { - //nNeedTrigger = 2; //post: yes, counter: no - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - - /* - printf("\nnNeedTrigger:%d\n", nNeedTrigger); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - */ - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - //pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_check_giveway[detection_zone_idx] = 1; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } - else if (trigger_type == TRIGGER_SPEED_HIGH) - { - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - if(pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed > viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) - { - //lasting time since enter zone - //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //if (detection_count > 1) - //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - - //if ((int)pNext->obj_dwell_time % 2 == 0) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); - //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); - /* - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); - printf("\ntrigger_type:%d\n",trigger_type); - */ - - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //nNeedTrigger = 1; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { - //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) - { - //nNeedTrigger = 2; //post: yes, counter: no - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - - /* - printf("\nnNeedTrigger:%d\n", nNeedTrigger); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - */ - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } - else if (trigger_type == TRIGGER_SPEED_LOW) - { - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - if (pNext->adjust_obj_speed != -1 && pNext->adjust_obj_speed >= 0.5 && pNext->adjust_obj_speed < viewDetectionZone[tracking_channel_idx][detection_zone_idx].set_distance) - { - //lasting time since enter zone - //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //if (detection_count > 1) - //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - - //if ((int)pNext->obj_dwell_time % 2 == 0) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); - //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); - /* - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); - printf("\ntrigger_type:%d\n",trigger_type); - */ - - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - //nNeedTrigger = 1; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { - //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) - { - //nNeedTrigger = 2; //post: yes, counter: no - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - - /* - printf("\nnNeedTrigger:%d\n", nNeedTrigger); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - */ - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } - else if (trigger_type == TRIGGER_TAMPERING) - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - { - //lasting time since enter zone - //diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //if (detection_count > 1) - //diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - //int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - - //if ((int)pNext->obj_dwell_time % 2 == 0) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (strcmp(ObjectName, "tampering") == 0) - { - //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); - //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); - /* - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); - printf("\ntrigger_type:%d\n",trigger_type); - */ - - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - //{ - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - //} - //else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - //{ - //if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) - //{ - //nNeedTrigger = 2; //post: yes, counter: no - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - //} - //} - - /* - printf("\nnNeedTrigger:%d\n", nNeedTrigger); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - */ - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - } - } - } - } - } - else if (trigger_type == TRIGGER_ALL_OBJECTS) - { - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && - ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP - )) && - ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[detection_zone_idx] == 1) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) - ) { - - //printf("\nAAAAAAAAAAA: 1\n"); - - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - { - if (strcmp(ObjectName, "person") == 0 && ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM))) { - int temp_count_meta = 0; - temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; - - for (int j = 0; j < total_element_size; j++) - { - if (j != result_idx) - { - detection_pos *pNext_bring = PosInfo + j; - char BringName[30] = { 0 }; - sprintf(BringName, "%s", pNext_bring->name); - UpperToLower(BringName); - if (strcmp(BringName, "person") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { - - //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); - if (detection_overlap_ratio(pNext, pNext_bring) > (0.0 / 100.0)) - { - if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { - int check_if_not_bring = 1; - for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { - if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { - check_if_not_bring = 0; - break; - } - } - - if (check_if_not_bring) { - //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) - { - //if(check_if_existing_in_metaout(BringName, detection_zone_idx)) - { - strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); - strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); - temp_count_meta++; - pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; - //break; - } - } - } - } - } - } - } - } - - int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; - if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { - //int count_correct_meta = 0; - //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) - { - //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) - //{ - //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) - //if(check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) - { - //count_correct_meta++; - //break; - } - //} - } - - //if (count_correct_meta == metadata1_num - 1) - if (pNext->num_bring_with_object[detection_zone_idx] == metadata1_num - 1) - { - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - } - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; - //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; - pNext->num_bring_with_object[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; - } - } - else if ((strcmp(ObjectName, "person") == 0) && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { - int temp_count_meta = 0; - temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; - - for (int j = 0; j < total_element_size; j++) - { - if (j != result_idx) { - detection_pos *pNext_bring = PosInfo + j; - char BringName[30] = { 0 }; - sprintf(BringName, "%s", pNext_bring->name); - UpperToLower(BringName); - if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { - - //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); - //if (detection_overlap_ratio(pNext, pNext_bring) > (30.0 / 100.0)) - { - if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { - int check_if_not_bring = 1; - for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { - if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { - check_if_not_bring = 0; - break; - } - } - - if (check_if_not_bring) { - //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) - { - //if (check_if_existing_in_metaout(BringName, detection_zone_idx)) - { - strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); - strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); - temp_count_meta++; - pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; - //break; - } - } - } - } - } - } - } - } - - int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; - if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { - //int count_correct_meta = 0; - //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) - { - //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) - //{ - //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) - //if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) - { - //count_correct_meta++; - //break; - } - //} - } - - //if (count_correct_meta >= 1) - if (pNext->num_bring_with_object[detection_zone_idx] >= 1) - { - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - } - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; - //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; - pNext->num_bring_with_object[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; - } - } - else if ((IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { - - for (int j = 0; j < total_element_size; j++) - { - if (j != result_idx) { - detection_pos *pNext_bring = PosInfo + j; - char BringName[30] = { 0 }; - sprintf(BringName, "%s", pNext_bring->name); - UpperToLower(BringName); - if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { - - //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); - //if (detection_overlap_ratio(pNext, pNext_bring) > (30.0 / 100.0)) - - //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) - { - //if (check_if_existing_in_metaout(BringName, detection_zone_idx) && IsGarbageCategory(pNext_bring)) - if (IsGarbageCategory(pNext_bring)) - { - //nNeedTrigger = 1; - - pNext->trigger_type = trigger_type | pNext->trigger_type; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - pNext->zone_violation_idx[detection_zone_idx] = 1; - - if (pNext->obj_tracking_id_idx >= 0) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; - //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; - } - } - } - - } - } - } - } - } - } - else { - - //printf("\nAAAAAAAAAAA: 2\n"); - - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - { - //lasting time since enter zone - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - if (detection_count > 1) - diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - //printf("\nAAAAAAAAAAA: 2-1------%d\n", get_g_check_if_all_existing(detection_zone_idx)); - //if ((int)pNext->obj_dwell_time % 2 == 0) - if (get_g_check_if_all_existing(detection_zone_idx) == 1) - { - //printf("\nAAAAAAAAAAA: 2-2\n"); - //for (int j = 0; j < metadata1_num; j++) - { - if(check_if_object_in_zone_simple_version_not_plate(pNext, detection_zone_idx)) - { - //printf("\nAAAAAAAAAAA: 2-3\n"); - //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); - //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); - /* - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); - printf("\ntrigger_type:%d\n",trigger_type); - */ - - if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { - if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) - { - nNeedTrigger = 2; //post: yes, counter: no - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - - /* - printf("\nnNeedTrigger:%d\n", nNeedTrigger); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - */ - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } - } - else if (trigger_type == TRIGGER_LACK_OF_ANY_OBJECT) - { - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && - ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP - )) && - ((((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM)) && g_enable_person_for_metadata[detection_zone_idx] == 1) || ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) - ) { - - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - { - if (strcmp(ObjectName, "person") == 0 && ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE || ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM))) { - int temp_count_meta = 0; - - temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; - - for (int j = 0; j < total_element_size; j++) - { - if (j != result_idx) { - detection_pos *pNext_bring = PosInfo + j; - char BringName[30] = { 0 }; - sprintf(BringName, "%s", pNext_bring->name); - UpperToLower(BringName); - if (strcmp(BringName, "person") != 0 && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { - - //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); - if (detection_overlap_ratio(pNext, pNext_bring) > (0.0 / 100.0)) - { - if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { - int check_if_not_bring = 1; - for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { - if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { - check_if_not_bring = 0; - break; - } - } - - if (check_if_not_bring) { - //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) - { - //if (strcmp(BringName, MetaOut1[index_meta]) == 0) - //if (check_if_existing_in_metaout(BringName, detection_zone_idx)) - { - strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); - strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); - temp_count_meta++; - pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; - //break; - } - } - } - } - } - } - } - } - - int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; - if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { - //int count_correct_meta = 0; - //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) - { - //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) { - //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) - //if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) - { - //count_correct_meta++; - //break; - } - //} - } - - //if (count_correct_meta == metadata1_num - 1) - if (pNext->num_bring_with_object[detection_zone_idx] == metadata1_num - 1) - { - - } - else { - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - } - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; - //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; - pNext->num_bring_with_object[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; - } - } - else if ((strcmp(ObjectName, "person") == 0 || IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0)) { - int temp_count_meta = 0; - - temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; - - for (int j = 0; j < total_element_size; j++) - { - if (j != result_idx) { - detection_pos *pNext_bring = PosInfo + j; - char BringName[30] = { 0 }; - sprintf(BringName, "%s", pNext_bring->name); - UpperToLower(BringName); - if ((pNext_bring->engine_type & FEATURE_TRAF_DET) && (pNext_bring->engine_type2 & FEATURE_AIGARBAGE) && strcmp(WeightFileModeName, "mod003") != 0 - && check_if_object_in_zone_simple_version(pNext_bring, detection_zone_idx)) { - - //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); - //if (detection_overlap_ratio(pNext, pNext_bring) > (30.0 / 100.0)) - { - if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { - int check_if_not_bring = 1; - for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { - if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { - check_if_not_bring = 0; - break; - } - } - - if (check_if_not_bring) { - //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) - { - //if (strcmp(BringName, MetaOut1[index_meta]) == 0) - //if (check_if_existing_in_metaout(BringName, detection_zone_idx)) - { - strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); - strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); - temp_count_meta++; - pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; - //break; - } - } - } - } - } - } - } - } - - int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; - if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { - //int count_correct_meta = 0; - //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) - { - //for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) { - //if (strcmp(pNext->bring_with_object[detection_zone_idx][index_bring], MetaOut1[index_meta]) == 0) - //if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) - { - //count_correct_meta++; - //break; - } - //} - } - - //if (count_correct_meta >= 1) - if (pNext->num_bring_with_object[detection_zone_idx] >= 1) - { - - } - else { - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - } - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; - //viewDetectionZone[0][detection_zone_idx].det_time = pNext->det_time; - pNext->num_bring_with_object[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; - } - } - } - } - else - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - { - //lasting time since enter zone - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - if (detection_count > 1) - diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - - //if ((int)pNext->obj_dwell_time % 2 == 0) - - //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; - /*if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0)*/ { - if (get_g_check_if_NAND(detection_zone_idx) == 1) - { - //for (int j = 0; j < metadata1_num; j++) - { - //if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - if (check_if_object_in_zone_simple_version(pNext, detection_zone_idx)) - { - //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); - //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); - /* - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\ng_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type:%d\n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type); - printf("\ntrigger_type:%d\n",trigger_type); - */ - - if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { - if (/*(nDiffSecs - nDiffSecs2) >= 1 && */nDiffSecs % TRIGGER_INTERVAL == 0) - { - nNeedTrigger = 2; //post: yes, counter: no - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - - /* - printf("\nnNeedTrigger:%d\n", nNeedTrigger); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - */ - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - - - } - - } - } - } - } - else if (trigger_type == TRIGGER_QUEUING_VIOLATION) - { - if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_space >= 1 && viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_line >= 1) { - - - } - else { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - { - int check_if_enable_linked_to_dwell_time = 0; -#ifdef GY_OS_V_SERIES - -#else -#if 1 - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || - g_IsCustomWeight == 1) { - char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; - char Temp[MAX_MSG_LEN * 10] = { 0 }; - strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_name); - int event_counter_num = StrSplit(Temp, eachEventCounter, ","); - //printf("\n------UU:4\n"); - - for (int i = 0; i < event_counter_num; i++) - { - for (int j = 0; j < MAX_EVENT_COUNTERS; j++) - { - if (strlen(eachEventCounter[i]) >= 1 && strcmp(eachEventCounter[i], eventCounterList[j].counter_name) == 0) - { - if (strcmp(eventCounterList[j].enable_linked_to_dwell_time, "Yes") == 0) { - check_if_enable_linked_to_dwell_time = 1; - break; - } - } - } - if (check_if_enable_linked_to_dwell_time == 1) - break; - } - } -#endif -#endif - - if(check_if_enable_linked_to_dwell_time == 0) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - //pNext->trigger_type = trigger_type; - pNext->zone_violation_idx[detection_zone_idx] = 1; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - else if (check_if_enable_linked_to_dwell_time == 1) { - - int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time) % MAX_OBJ_DWELL_TIME; - if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - //if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - //pNext->trigger_type = trigger_type; - pNext->zone_violation_idx[detection_zone_idx] = 1; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - - //break; - } - } - } - } - } - } - } -#if 0 - else if (trigger_type == TRIGGER_MISSING_OBJECT_DETECTION) - { - /* - printf("\n----------------------------------\n"); - printf("\nobj_first_dwell_time: %lf\n",pNext->obj_first_dwell_time); - printf("\nobj_last_dwell_time: %lf\n", pNext->obj_last_dwell_time); - printf("\n----------------------------------\n");*/ - - /*if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time > 0) { - int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; - if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) { - - } - }*/ - if (pNext->obj_dwell_time > g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time + d_no_parking_time) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - { - nNeedTrigger = 1; - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time = 0.0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time = 0.0; - } - - pNext->trigger_type = trigger_type; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 2; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - //break; - - } - } - } - else - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - nNeedTrigger = 0; - //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //if (diffSecs >= dewell_time2) - { - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - //break; - } - } - } - } - -#endif -#if 0 - if (trigger_event_type == TRIGGER_TURN_LEFT) - { - if (trigger_type == TRIGGER_TURN_LEFT) - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) - { - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); - if (diffSecs < dewell_time) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - } - pNext->trigger_type = trigger_type; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - - } - } - } - else - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - nNeedTrigger = 0; - //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } - } - - if (trigger_event_type == TRIGGER_TURN_RIGHT) - { - if (trigger_type == TRIGGER_TURN_RIGHT) - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) - { - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); - if (diffSecs < dewell_time) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - } - pNext->trigger_type = trigger_type; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - - } - } - } - else - { - //for (int j = 0; j < metadata1_num; j++) - { - //if (strcmp(ObjectName, MetaOut1[j]) == 0) - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - nNeedTrigger = 0; - //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } - } - - if (trigger_event_type == TRIGGER_WRONG_WAY) - { - if (trigger_type == TRIGGER_WRONG_WAY) - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == backward_line && forward_line > 0) - { - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); - if (diffSecs < dewell_time) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - } - pNext->trigger_type = trigger_type; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - - } - } - } - else - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - nNeedTrigger = 0; - //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } - } - - if (trigger_event_type == TRIGGER_TURN_LEFT_VIOLATION) - { - if (trigger_type == TRIGGER_TURN_LEFT_VIOLATION) - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0) - { - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); - if (diffSecs < dewell_time) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - } - pNext->trigger_type = trigger_type; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - - } - } - } - else - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - nNeedTrigger = 0; - //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } - } - - if (trigger_event_type == TRIGGER_TURN_RIGHT_VIOLATION) - { - if (trigger_type == TRIGGER_TURN_RIGHT_VIOLATION) - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0) - { - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); - if (diffSecs < dewell_time) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - } - pNext->trigger_type = trigger_type; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - - } - } - } - else - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - nNeedTrigger = 0; - //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } - } - - if (trigger_event_type == TRIGGER_U_TURN_VIOLATION) - { - if (trigger_type == TRIGGER_U_TURN_VIOLATION) - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == backward_line /*&& g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[detection_zone_idx] == backward_line*/ && forward_line > 0) - { - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); - if (diffSecs < dewell_time) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - } - pNext->trigger_type = trigger_type; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - - } - } - } - else - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - nNeedTrigger = 0; - //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } - } - /* - if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) - { - if (trigger_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == forward_line && forward_line > 0 && strcmp(viewChannelData[tracking_channel_idx].traffic_light_color, "Red") == 0) - { - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); - if (diffSecs < dewell_time) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - } - pNext->trigger_type = trigger_type; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - - } - } - } - else - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - nNeedTrigger = 0; - //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } - } - - if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) - { - if (trigger_type == TRIGGER_TURN_LEFT_RED_LIGHT) - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == left_line && forward_line > 0 && strcmp(viewChannelData[tracking_channel_idx].traffic_light_color, "Red") == 0) - { - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); - if (diffSecs < dewell_time) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - } - pNext->trigger_type = trigger_type; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - - } - } - } - else - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - nNeedTrigger = 0; - //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } - } - - if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) - { - if (trigger_type == TRIGGER_TURN_RIGHT_RED_LIGHT) - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[detection_zone_idx] == right_line && forward_line > 0 && strcmp(viewChannelData[tracking_channel_idx].traffic_light_color, "Red") == 0) - { - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time); - if (diffSecs < dewell_time) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - } - pNext->trigger_type = trigger_type; - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - - } - } - } - else - { - //for (int j = 0; j < metadata1_num; j++) - { - if (check_if_existing_in_metaout(ObjectName, detection_zone_idx)) - { - nNeedTrigger = 0; - //pNext->trigger_type = (pNext->trigger_type ^ trigger_type); - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } - } - */ -#endif - - /* - if (trigger_event_type == TRIGGER_BG_LEARNING) - { - if (trigger_type == TRIGGER_BG_LEARNING) - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time > 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[detection_zone_idx][1].det_time == 0) - { - //lasting time since enter zone - diffSecs = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - if (detection_count > 1) - diffSecs2 = difftime(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 2].det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[detection_zone_idx][1].det_time); - int nDiffSecs = (int)diffSecs; - //int nDiffSecs2 = (int)diffSecs2; - - //if ((int)pNext->obj_dwell_time % 2 == 0) - { - //for (int j = 0; j < metadata1_num; j++) - { - if (strcmp(ObjectName, "bg_learning") == 0) - { - //printf("check metadata & ObjectName [%s][%s] \n", ObjectName, MetaOut1[j]); - //printf("trigger type = %d, %d \n", g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type, trigger_type); - - if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type) == 0) - { - nNeedTrigger = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - else if ((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type & trigger_type)) - { - if (nDiffSecs % TRIGGER_INTERVAL == 0) - { - nNeedTrigger = 2; //post: yes, counter: no - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - } - } - - //printf("pNext->trigger_type1 = %d \n", pNext->trigger_type); - - pNext->trigger_type = trigger_type; - - //printf("pNext->trigger_type2 = %d \n", pNext->trigger_type); - - pNext->zone_violation_idx[detection_zone_idx] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - } - } - } - } - } - }*/ - - } - - if (strcmp(SystemSetting.enable_person_independent, "Yes") == 0) { - //printf("\nTTTTTTTTTT : 1\n"); - if (strcmp(ObjectName, "person") == 0) { - int temp_count_meta = 0; - temp_count_meta = pNext->num_bring_with_object[detection_zone_idx]; - //printf("\nTTTTTTTTTT : 2\n"); - for (int j = 0; j < total_element_size; j++) - { - if (j != result_idx) { - detection_pos *pNext_bring = PosInfo + j; - if (!IsANPRCategory(pNext_bring->engine_type)) { - char BringName[30] = { 0 }; - sprintf(BringName, "%s", pNext_bring->name); - UpperToLower(BringName); - if (strcmp(BringName, "person") != 0) { - //printf("\nTTTTTTTTTT : 3\n"); - //printf("\n-----------f:%f\n", detection_overlap_ratio(pNext, pNext_bring)); - if (detection_overlap_ratio(pNext, pNext_bring) > (0.0 / 100.0)) - { - { - - //nNeedTrigger = 0; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - pNext_bring->trigger_type = 0; - //pNext->detection_zone_idx = detection_zone_idx; - pNext_bring->trigger_idx[detection_zone_idx] = trigger_idx; - pNext_bring->zone_violation_idx[detection_zone_idx] = 0; - pNext_bring->check_person_inter = 1; - if (pNext_bring->obj_tracking_id_idx >= 0) { - g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].trigger_type = 0; - int det_count_temp = g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].detection_count; - if(det_count_temp >= 1) - g_TrackingRecords[tracking_channel_idx][pNext_bring->obj_tracking_id_idx].prev_detections[det_count_temp - 1].check_person_inter = 1; - } - } - //printf("\nTTTTTTTTTT : 4\n"); - if (temp_count_meta < MAX_NUM_BRING_WITH_OBJECT) { - int check_if_not_bring = 1; - for (int index_bring = 0; index_bring < temp_count_meta; index_bring++) { - if (strcmp(BringName, pNext->bring_with_object[detection_zone_idx][index_bring]) == 0) { - check_if_not_bring = 0; - break; - } - } - - if (check_if_not_bring) { - //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) - { - if (check_if_existing_in_metaout(BringName, detection_zone_idx)) - { - strcpy(pNext->bring_with_object[detection_zone_idx][temp_count_meta], BringName); - if (detection_count >= 1) - strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].bring_with_object[detection_zone_idx][temp_count_meta], BringName); - temp_count_meta++; - pNext->num_bring_with_object[detection_zone_idx] = temp_count_meta; - if (detection_count >= 1) - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = pNext->num_bring_with_object[detection_zone_idx]; - //break; - } - } - } - } - //printf("\nTTTTTTTTTT : 5\n"); - } - } - } - } - } - //printf("\nTTTTTTTTTT : 6\n"); - //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; - //if (diff_secs_in_zone > d_no_parking_time && diff_secs_in_zone > 0) - { - int count_correct_meta = 0; - //for (int index_meta = 0; index_meta < metadata1_num; index_meta++) - { - for (int index_bring = 0; index_bring < pNext->num_bring_with_object[detection_zone_idx]; index_bring++) { - if (check_if_existing_in_metaout(pNext->bring_with_object[detection_zone_idx][index_bring], detection_zone_idx)) - { - count_correct_meta++; - //break; - } - } - } - - if (count_correct_meta >= 1) { - nNeedTrigger = 0; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - pNext->trigger_type = 0; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - pNext->zone_violation_idx[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = 0; - - pNext->check_person_inter = 1; - if (detection_count >= 1) - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 1; - //nNeedTrigger = 1; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - //pNext->trigger_type = trigger_type | pNext->trigger_type; - //pNext->detection_zone_idx = detection_zone_idx; - //pNext->trigger_idx[detection_zone_idx] = trigger_idx; - //pNext->zone_violation_idx[detection_zone_idx] = 1; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - } - else { - pNext->check_person_inter = 0; - if (detection_count >= 1) - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 0; - } - - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; - //pNext->num_bring_with_object[detection_zone_idx] = 0; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].num_bring_with_object[detection_zone_idx] = 0; - } - //printf("\nTTTTTTTTTT : 7\n"); - } - else { - - if (!IsANPRCategory(pNext->engine_type)) { - //printf("\nTTTTTTTTTT : 8\n"); - if (pNext->check_person_inter == 1) { - nNeedTrigger = 0; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - pNext->trigger_type = 0; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - pNext->zone_violation_idx[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = 0; - //printf("\nTTTTTTTTTT : 9\n"); - } - else { - //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx]) % MAX_OBJ_DWELL_TIME; - //if (diff_secs_in_zone < d_no_parking_time && diff_secs_in_zone > 0) - { - nNeedTrigger = 0; - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = detection_zone_idx + 1; - pNext->trigger_type = 0; - //pNext->detection_zone_idx = detection_zone_idx; - pNext->trigger_idx[detection_zone_idx] = trigger_idx; - pNext->zone_violation_idx[detection_zone_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = 0; - - pNext->check_person_inter = 1; - if (detection_count >= 1) - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 1; - - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[detection_zone_idx] = pNext->det_time; - } - //printf("\nTTTTTTTTTT : 10\n"); - } - } - else { - pNext->check_person_inter = 0; - if (detection_count >= 1) - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[detection_count - 1].check_person_inter = 0; - //printf("\nTTTTTTTTTT : 11\n"); - } - } - } - - return nNeedTrigger; -} -#endif -#if 1 -char g_last_token_name[256] = { 0 }; -char g_last_token_confidence[10] = { 0 }; -char g_last_token_left_x[10] = { 0 }; -char g_last_token_top_y[10] = { 0 }; -char g_last_token_width[10] = { 0 }; -char g_last_token_height[10] = { 0 }; -char g_last_token_center_x[10] = { 0 }; -char g_last_token_center_y[10] = { 0 }; -char g_last_token_center_speed[35] = { 0 }; -char g_last_token_center_direction[10] = { 0 }; -char g_last_token_center_stability[10] = { 0 }; -char g_last_token_obj_tracking_id[10] = { 0 }; -char g_last_token_obj_dwell_time[20] = { 0 }; -char g_last_token_class_id[10] = { 0 }; -char g_last_token_color[20] = { 0 }; -char g_last_token_plate[256] = { 0 }; -char g_last_token_country[256] = { 0 }; -char g_last_token_area[256] = { 0 }; -char g_last_token_plate_list[256] = { 0 }; -char g_last_token_logo[256] = { 0 }; -char g_last_token_behavior_id[1024] = { 0 }; -char g_last_token_zone_id[10] = { 0 }; -char g_last_token_behavior_name[256] = { 0 }; -char g_last_token_linked_plate[256] = { 0 }; - -size_t ReplaceKeyWords(detection_pos* pNext, int space_zone,int space_id,char* InputString,char *OutputString,int tracking_channel_idx, int detection_zone_idx, int trigger_idx, char* image_buff_base64, int image_buff_size_base64,int enable_base64_image, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64, int show_large_bbox) -{ - char *replacement = NULL; - char *replacement_t = NULL; - char msg[MAX_MSG_LEN] = { 0 }; - - replacement = InputString; - - //避免後面的replacement沒有辦法做free。 - replacement_t = StrReplace(replacement, "<|test_token|>", "Hello"); - replacement = replacement_t; - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - sprintf(msg, "%s", pNext->name); - strcpy(g_last_token_name, pNext->name); - - replacement_t = StrReplace(replacement, "<|name|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - sprintf(msg, "%s", g_last_token_name); - - replacement_t = StrReplace(replacement, "<|name|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - sprintf(msg, "%d", (int)pNext->confidence); - sprintf(g_last_token_confidence, "%d", (int)pNext->confidence); - - replacement_t = StrReplace(replacement, "<|confidence|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - sprintf(msg, "%s", g_last_token_confidence); - - replacement_t = StrReplace(replacement, "<|confidence|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - if (show_large_bbox == 1) { - sprintf(msg, "%d", (int)(pNext->left_x - pNext->width / 3.0)); - sprintf(g_last_token_left_x, "%d", (int)(pNext->left_x - pNext->width / 3.0)); - } - else { - sprintf(msg, "%d", (int)pNext->left_x); - sprintf(g_last_token_left_x, "%d", (int)pNext->left_x); - } - - replacement_t = StrReplace(replacement, "<|left_x|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - sprintf(msg, "%s", g_last_token_left_x); - - replacement_t = StrReplace(replacement, "<|left_x|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - if (show_large_bbox == 1) { - sprintf(msg, "%d", (int)(pNext->top_y - pNext->height / 3.0)); - sprintf(g_last_token_top_y, "%d", (int)(pNext->top_y - pNext->height / 3.0)); - } - else { - sprintf(msg, "%d", (int)pNext->top_y); - sprintf(g_last_token_top_y, "%d", (int)pNext->top_y); - } - - replacement_t = StrReplace(replacement, "<|top_y|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - sprintf(msg, "%s", g_last_token_top_y); - - replacement_t = StrReplace(replacement, "<|top_y|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - if (show_large_bbox == 1) { - sprintf(msg, "%d", (int)(pNext->width * 5.0 / 3.0)); - sprintf(g_last_token_width, "%d", (int)(pNext->width * 5.0 / 3.0)); - } - else { - sprintf(msg, "%d", (int)pNext->width); - sprintf(g_last_token_width, "%d", (int)pNext->width); - } - - replacement_t = StrReplace(replacement, "<|width|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - sprintf(msg, "%s", g_last_token_width); - - replacement_t = StrReplace(replacement, "<|width|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - if (show_large_bbox == 1) { - sprintf(msg, "%d", (int)(pNext->height * 5.0 / 3.0)); - sprintf(g_last_token_height, "%d", (int)(pNext->height * 5.0 / 3.0)); - } - else { - sprintf(msg, "%d", (int)pNext->height); - sprintf(g_last_token_height, "%d", (int)pNext->height); - } - - replacement_t = StrReplace(replacement, "<|height|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - sprintf(msg, "%s", g_last_token_height); - - replacement_t = StrReplace(replacement, "<|height|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - sprintf(msg, "%d", (int)pNext->center_x); - sprintf(g_last_token_center_x, "%d", (int)pNext->center_x); - - replacement_t = StrReplace(replacement, "<|center_x|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - sprintf(msg, "%s", g_last_token_center_x); - - replacement_t = StrReplace(replacement, "<|center_x|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - sprintf(msg, "%d", (int)pNext->center_y); - sprintf(g_last_token_center_y, "%d", (int)pNext->center_y); - - replacement_t = StrReplace(replacement, "<|center_y|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - sprintf(msg, "%s", g_last_token_center_y); - - replacement_t = StrReplace(replacement, "<|center_y|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - char msg_center_speed[35] = { 0 }; - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - if (pNext->adjust_obj_speed != -1 && pNext->adjust_obj_speed >= 0.5) { - sprintf(msg_center_speed, "%.1f", pNext->adjust_obj_speed); - - if (strcmp(viewDetectionZone[tracking_channel_idx][0].world_time_unit, "KPH") == 0) { - strcat(msg_center_speed, " km/h"); - } - else { - strcat(msg_center_speed, " mi/h"); - } - } - else { - sprintf(msg_center_speed, "%s", ""); - } - sprintf(g_last_token_center_speed, "%s", msg_center_speed); - - replacement_t = StrReplace(replacement, "<|center_speed|>", msg_center_speed); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - sprintf(msg_center_speed, "%s", g_last_token_center_speed); - - replacement_t = StrReplace(replacement, "<|center_speed|>", msg_center_speed); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - if ((int)(pNext->center_direction) != DIRECTION_DEFAULT) { - sprintf(msg, "%d", (int)pNext->center_direction); - sprintf(g_last_token_center_direction, "%d", (int)pNext->center_direction); - } - else { - sprintf(msg, "%s", ""); - sprintf(g_last_token_center_direction, "%s", ""); - } - - replacement_t = StrReplace(replacement, "<|center_direction|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - sprintf(msg, "%s", g_last_token_center_direction); - - replacement_t = StrReplace(replacement, "<|center_direction|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - if ((int)(pNext->center_stability) != DIRECTION_DEFAULT) { - sprintf(msg, "%d", (int)pNext->center_stability); - sprintf(g_last_token_center_stability, "%d", (int)pNext->center_stability); - } - else { - sprintf(msg, "%s", ""); - sprintf(g_last_token_center_stability, "%s", ""); - } - - replacement_t = StrReplace(replacement, "<|center_stability|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - sprintf(msg, "%s", g_last_token_center_stability); - - replacement_t = StrReplace(replacement, "<|center_stability|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - sprintf(msg, "%d", (int)pNext->obj_tracking_id); - sprintf(g_last_token_obj_tracking_id, "%d", (int)pNext->obj_tracking_id); - - replacement_t = StrReplace(replacement, "<|obj_tracking_id|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - sprintf(msg, "%s", g_last_token_obj_tracking_id); - - replacement_t = StrReplace(replacement, "<|obj_tracking_id|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - sprintf(msg, "%d", (int)(pNext->obj_dwell_time * 100) / 100); - sprintf(g_last_token_obj_dwell_time, "%d", (int)(pNext->obj_dwell_time * 100) / 100); - - replacement_t = StrReplace(replacement, "<|obj_dwell_time|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - sprintf(msg, "%s", g_last_token_obj_dwell_time); - - replacement_t = StrReplace(replacement, "<|obj_dwell_time|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - sprintf(msg, "%d", pNext->class_id); - sprintf(g_last_token_class_id, "%d", pNext->class_id); - - replacement_t = StrReplace(replacement, "<|class_id|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - sprintf(msg, "%s", g_last_token_class_id); - - replacement_t = StrReplace(replacement, "<|class_id|>", msg); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - -#ifdef GY_OS_AMBA - char mycolor[20] = { 0 }; - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - if (strcmp(SystemSetting.enable_display_properties, "Yes") == 0) { - if (!IsANPRCategory(pNext->engine_type)) { - if (pNext->image_id != -1 && get_check_first_downsized_cropped_roi_for_object() == 1) { - if (pNext->color_id == 1) - strcpy(mycolor, "Red"); - else if (pNext->color_id == 2) - strcpy(mycolor, "Orange"); - else if (pNext->color_id == 3) - strcpy(mycolor, "Yellow"); - else if (pNext->color_id == 4) - strcpy(mycolor, "Green"); - else if (pNext->color_id == 5) - strcpy(mycolor, "Blue"); - else if (pNext->color_id == 6) - strcpy(mycolor, "Cyan"); - else if (pNext->color_id == 7) - strcpy(mycolor, "Purple"); - else if (pNext->color_id == 8) - strcpy(mycolor, "Black"); - else if (pNext->color_id == 9) - strcpy(mycolor, "White"); - else if (pNext->color_id == 11) - strcpy(mycolor, "Darkgray"); - else if (pNext->color_id == 10) - strcpy(mycolor, "Gray");//Silver - } - } - } - } - else { - sprintf(mycolor, "%s", ""); - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0) { - sprintf(g_last_token_color, "%s", mycolor); - - replacement_t = StrReplace(replacement, "<|color|>", mycolor); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - sprintf(mycolor, "%s", g_last_token_color); - - replacement_t = StrReplace(replacement, "<|color|>", mycolor); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - -#endif - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - replacement_t = StrReplace(replacement, "<|plate|>", pNext->properties.plate); - sprintf(g_last_token_plate, "%s", pNext->properties.plate); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - replacement_t = StrReplace(replacement, "<|plate|>", g_last_token_plate); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - replacement_t = StrReplace(replacement, "<|country|>", pNext->properties.country); - sprintf(g_last_token_country, "%s", pNext->properties.country); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - replacement_t = StrReplace(replacement, "<|country|>", g_last_token_country); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - replacement_t = StrReplace(replacement, "<|area|>", pNext->properties.area); - sprintf(g_last_token_area, "%s", pNext->properties.area); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - replacement_t = StrReplace(replacement, "<|area|>", g_last_token_area); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - replacement_t = StrReplace(replacement, "<|plate_list|>", pNext->properties.plate_list); - sprintf(g_last_token_plate_list, "%s", pNext->properties.plate_list); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - replacement_t = StrReplace(replacement, "<|plate_list|>", g_last_token_plate_list); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL) { - replacement_t = StrReplace(replacement, "<|logo|>", pNext->logo); - sprintf(g_last_token_logo, "%s", pNext->logo); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - replacement_t = StrReplace(replacement, "<|logo|>", g_last_token_logo); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } -#ifdef GY_OS_AMBA - int hex_token_base = 1; - int sum_hex = 0; - for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) - { - if (index_zone >= 1) { - hex_token_base *= 2; - } - - if (viewDetectionZone[tracking_channel_idx][index_zone].prev_queuing_num >= 1) { - sum_hex += hex_token_base; - } - } - - char buf_hex[50] = { 0 }; - sprintf(buf_hex, "%d", sum_hex); - replacement_t = StrReplace(replacement, "<|hextoint|>", buf_hex); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; -#endif - - int behavior_ID = 0; - if (detection_zone_idx >= 0 && trigger_idx >= 0) - behavior_ID = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); - - sprintf(msg, "%d", behavior_ID);//(int)pNext->trigger_type - if (detection_zone_idx >= 0 && trigger_idx >= 0) { - replacement_t = StrReplace(replacement, "<|behavior_id|>", msg); - sprintf(g_last_token_behavior_id, "%s", msg); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - replacement_t = StrReplace(replacement, "<|behavior_id|>", g_last_token_behavior_id); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL && pNext->obj_tracking_id_idx >= 0) { - sprintf(msg, "%d", (int)g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_zone_id); - sprintf(g_last_token_zone_id, "%d", (int)g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_zone_id); - replacement_t = StrReplace(replacement, "<|zone_id|>", msg); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - replacement_t = StrReplace(replacement, "<|zone_id|>", g_last_token_zone_id); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - - char behavior_name[256] = { 0 }; - if ((behavior_ID & TRIGGER_ZONE_VIOLATION) == TRIGGER_ZONE_VIOLATION) { - strcpy(behavior_name, "Prohibit_zone"); - } - else if ((behavior_ID & TRIGGER_DISTANCE_VIOLATION) == TRIGGER_DISTANCE_VIOLATION) { - strcpy(behavior_name, "Distance_violation"); - } - else if ((behavior_ID & TRIGGER_HIGH_VIOLATION) == TRIGGER_HIGH_VIOLATION) { - strcpy(behavior_name, "Height_detection"); - } - else if ((behavior_ID & TRIGGER_FORGET_TO_GIVE_WAY) == TRIGGER_FORGET_TO_GIVE_WAY) { - strcpy(behavior_name, "Forget_to_give_way_detection");//不禮讓偵測 - } - else if ((behavior_ID & TRIGGER_SPEED_HIGH) == TRIGGER_SPEED_HIGH) { - strcpy(behavior_name, "Max_speed_detection"); - } - else if ((behavior_ID & TRIGGER_SPEED_LOW) == TRIGGER_SPEED_LOW) { - strcpy(behavior_name, "Min_speed_detection"); - } - else if ((behavior_ID & TRIGGER_PARKING_VIOLATION) == TRIGGER_PARKING_VIOLATION) { - strcpy(behavior_name, "Zone_with_dwell_Parking_violation");//禁區限時偵測 / 違規停車 - } - else if ((behavior_ID & TRIGGER_GO_STRAIGHT) == TRIGGER_GO_STRAIGHT) { - strcpy(behavior_name, "Tripwire_Traffic_flow");//警戒線 / 直行偵測 - } - else if ((behavior_ID & TRIGGER_GO_STRAIGHT_RED_LIGHT) == TRIGGER_GO_STRAIGHT_RED_LIGHT) { - strcpy(behavior_name, "Tripwire_on_red_Running_red_lights");//紅燈警戒線 / 紅燈直行 - } - else if ((behavior_ID & TRIGGER_TURN_LEFT_RED_LIGHT) == TRIGGER_TURN_LEFT_RED_LIGHT) { - strcpy(behavior_name, "Turning_left_on_red");//紅燈左轉 - } - else if ((behavior_ID & TRIGGER_TURN_RIGHT_RED_LIGHT) == TRIGGER_TURN_RIGHT_RED_LIGHT) { - strcpy(behavior_name, "Turning_right_on_red");//紅燈右轉 - } - else if ((behavior_ID & TRIGGER_TURN_LEFT) == TRIGGER_TURN_LEFT) { - strcpy(behavior_name, "Turn_left");//左轉偵測 - } - else if ((behavior_ID & TRIGGER_TURN_RIGHT) == TRIGGER_TURN_RIGHT) { - strcpy(behavior_name, "Turn_right");//右轉偵測 - } - else if ((behavior_ID & TRIGGER_ALLOW_LIST) == TRIGGER_ALLOW_LIST) { - strcpy(behavior_name, "LPR_allowed_list_detection_in_zone");//白名單警戒區偵測 - } - else if ((behavior_ID & TRIGGER_GUEST_LIST) == TRIGGER_GUEST_LIST) { - strcpy(behavior_name, "LPR_visitor_list_detection_in_zone");//訪客名單警戒區偵測 - } - else if ((behavior_ID & TRIGGER_BLOCK_LIST) == TRIGGER_BLOCK_LIST) { - strcpy(behavior_name, "LPR_denial_list_detection_in_zone");//黑名單警戒區偵測 - } - else if ((behavior_ID & TRIGGER_QUEUING_VIOLATION) == TRIGGER_QUEUING_VIOLATION) { - strcpy(behavior_name, "Density_detection");//密度偵測 - } - else if ((behavior_ID & TRIGGER_MISSING_OBJECT_DETECTION) == TRIGGER_MISSING_OBJECT_DETECTION) { - strcpy(behavior_name, "AI_missing_object_detection");//AI遺失物偵測 - } - else if ((behavior_ID & TRIGGER_MISSING_UNATTENDED) == TRIGGER_MISSING_UNATTENDED) { - strcpy(behavior_name, "Unattended_or_missing_object");//遺失物及遺留物偵測 - } - else if ((behavior_ID & TRIGGER_TAMPERING) == TRIGGER_TAMPERING) { - strcpy(behavior_name, "Tampering_detection");//防破壞偵測 - } - else if ((behavior_ID & TRIGGER_ALL_OBJECTS) == TRIGGER_ALL_OBJECTS) { - strcpy(behavior_name, "All_objects_detection_AND");//物種同時存在偵測 (AND) - } - else if ((behavior_ID & TRIGGER_LACK_OF_ANY_OBJECT) == TRIGGER_LACK_OF_ANY_OBJECT) { - strcpy(behavior_name, "Lack_of_any_object_detection_NAND");//缺少任一物種同時存在偵測 (NAND) - } - if (detection_zone_idx >= 0 && trigger_idx >= 0) { - replacement_t = StrReplace(replacement, "<|behavior_name|>", behavior_name); - sprintf(g_last_token_behavior_name, "%s", behavior_name); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - replacement_t = StrReplace(replacement, "<|behavior_name|>", g_last_token_behavior_name); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - if (detection_zone_idx >= 0 && trigger_idx >= 0 && pNext != NULL && pNext->obj_tracking_id_idx >= 0) { - replacement_t = StrReplace(replacement, "<|linked_plate|>", g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].linked_plate); - sprintf(g_last_token_linked_plate, "%s", g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].linked_plate); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - else { - if (strcmp(SystemSetting.enable_display_OSD, "Yes") == 0 /*&& strcmp(SystemSetting.enable_cloud, "Yes") == 0*/) { - replacement_t = StrReplace(replacement, "<|linked_plate|>", g_last_token_linked_plate); - - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - - //time_t rawtime = time(0); - time_t rawtime = g_osdSysTimeStamp; - struct tm * timeinfo; - timeinfo = localtime(&rawtime); - - //printf("\n---g_osdSysTimeStamp:%ld,%04d-%02d-%02dT%02d:%02d:%02d\n", g_osdSysTimeStamp, 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, - //timeinfo->tm_min, timeinfo->tm_sec); - - /* - char buf_time_info[256] = { 0 }; - sprintf(buf_time_info, "%04d-%02d-%02dT%02d:%02d:%02d", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, - timeinfo->tm_min, timeinfo->tm_sec); - */ - - char buf_time_t[50] = { 0 }; - sprintf(buf_time_t, "%ld", rawtime); - replacement_t = StrReplace(replacement, "<|time_t|>", buf_time_t); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_year[20] = { 0 }; - sprintf(buf_year, "%04d", 1900 + timeinfo->tm_year); - replacement_t = StrReplace(replacement, "<|YYYY|>", buf_year); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_month[20] = { 0 }; - sprintf(buf_month, "%02d", 1 + timeinfo->tm_mon); - replacement_t = StrReplace(replacement, "<|MM|>", buf_month); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_date[10] = { 0 }; - sprintf(buf_date, "%02d", timeinfo->tm_mday); - replacement_t = StrReplace(replacement, "<|DD|>", buf_date); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_hour[10] = { 0 }; - sprintf(buf_hour, "%02d", timeinfo->tm_hour); - replacement_t = StrReplace(replacement, "<|hh|>", buf_hour); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_minute[10] = { 0 }; - sprintf(buf_minute, "%02d", timeinfo->tm_min); - replacement_t = StrReplace(replacement, "<|mm|>", buf_minute); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_second[10] = { 0 }; - sprintf(buf_second, "%02d", timeinfo->tm_sec); - replacement_t = StrReplace(replacement, "<|ss|>", buf_second); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - struct tm * gmtinfo; - gmtinfo = gmtime(&rawtime); - - char buf_gmthour[10] = { 0 }; - sprintf(buf_gmthour, "%02d", gmtinfo->tm_hour); - replacement_t = StrReplace(replacement, "<|GMThh|>", buf_gmthour); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - -#ifdef GY_OS_V_SERIES - -#else - for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) - { - char temp_label[30] = { 0 }; - sprintf(temp_label, "<|counter%02d_count|>", index_counter + 1); - - char temp_counter_count[30] = { 0 }; - sprintf(temp_counter_count,"%d", eventCounterList[index_counter].counter_count); - - replacement_t = StrReplace(replacement, temp_label, temp_counter_count); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char temp_label_dwell[30] = { 0 }; - sprintf(temp_label_dwell, "<|counter%02d_dwell|>", index_counter + 1); - - char temp_counter_timetResetAt[50] = { 0 }; - sprintf(temp_counter_timetResetAt, "%d", eventCounterList[index_counter].dwell_time); - - replacement_t = StrReplace(replacement, temp_label_dwell, temp_counter_timetResetAt); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char temp_label_dwell_unit[50] = { 0 }; - sprintf(temp_label_dwell_unit, "<|counter%02d_dwell_unit|>", index_counter + 1); - - replacement_t = StrReplace(replacement, temp_label_dwell_unit, eventCounterList[index_counter].dwell_unit); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - } -#endif - char fetch_mac_addr[30] = { 0 }; - if (g_match_mac) - strcpy(fetch_mac_addr, g_mac_address); - else - { - GetMACAddress(fetch_mac_addr); - //printf("mac addr = %s \n", fetch_mac_addr); - int i = 0; - while (fetch_mac_addr[i] != '\0') - { - if (fetch_mac_addr[i] == '\n') - { - fetch_mac_addr[i] = '\0'; - break; - } - i++; - } - } - replacement_t = StrReplace(replacement, "<|mac_address|>", fetch_mac_addr); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - replacement_t = StrReplace(replacement, "<|device_name|>", g_device_name); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - replacement_t = StrReplace(replacement, "<|dataset_ver|>", Buffer_ver); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char temp_soft_ver[50] = { 0 }; - strcat(temp_soft_ver, APP_VERSION); - strcat(temp_soft_ver, "-"); - strcat(temp_soft_ver, WeightFileModeName); - replacement_t = StrReplace(replacement, "<|soft_ver|>", temp_soft_ver); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_frame_id[50] = { 0 }; - sprintf(buf_frame_id, "%u", get_frame_id()); - replacement_t = StrReplace(replacement, "<|frame_id|>", buf_frame_id); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_parking_space[50] = { 0 }; - sprintf(buf_parking_space, "%d", viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_space); - replacement_t = StrReplace(replacement, "<|total_space|>", buf_parking_space); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - if (space_zone >= 0 && space_id >= 0) { - - int temp_space_id = space_id; - for (int index_zone = 0; index_zone < space_zone; index_zone++) { - temp_space_id += (viewDetectionZone[tracking_channel_idx][space_zone].parking_space + 1); - } - - char buf_space_id[50] = { 0 }; - sprintf(buf_space_id, "%02d", temp_space_id + 1); - replacement_t = StrReplace(replacement, "<|space_id|>", buf_space_id); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_space_zone[50] = { 0 }; - sprintf(buf_space_zone, "%d", space_zone + 1); - replacement_t = StrReplace(replacement, "<|space_zone|>", buf_space_zone); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_space_status[50] = { 0 }; - sprintf(buf_space_status, "%d", g_parking_space_check_table[space_zone][space_id]); - replacement_t = StrReplace(replacement, "<|space_status|>", buf_space_status); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - time_t rawtime_space = g_parking_space_status_change_time[space_zone][space_id]; - - struct tm * timeinfo_space; - struct tm * gmtinfo_space; - timeinfo_space = localtime(&rawtime_space); - gmtinfo_space = gmtime(&rawtime_space); - - char buf_time_t_space[50] = { 0 }; - sprintf(buf_time_t_space, "%ld", rawtime_space); - replacement_t = StrReplace(replacement, "<|space_time_t|>", buf_time_t_space); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_year_space[20] = { 0 }; - sprintf(buf_year_space, "%04d", 1900 + timeinfo_space->tm_year); - replacement_t = StrReplace(replacement, "<|space_YYYY|>", buf_year_space); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_month_space[20] = { 0 }; - sprintf(buf_month_space, "%02d", 1 + timeinfo_space->tm_mon); - replacement_t = StrReplace(replacement, "<|space_MM|>", buf_month_space); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_date_space[10] = { 0 }; - sprintf(buf_date_space, "%02d", timeinfo_space->tm_mday); - replacement_t = StrReplace(replacement, "<|space_DD|>", buf_date_space); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_gmthour_space[10] = { 0 }; - sprintf(buf_gmthour_space, "%02d", gmtinfo_space->tm_hour); - replacement_t = StrReplace(replacement, "<|space_GMThh|>", buf_gmthour_space); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_hour_space[10] = { 0 }; - sprintf(buf_hour, "%02d", timeinfo_space->tm_hour); - replacement_t = StrReplace(replacement, "<|space_hh|>", buf_hour_space); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_minute_space[10] = { 0 }; - sprintf(buf_minute_space, "%02d", timeinfo_space->tm_min); - replacement_t = StrReplace(replacement, "<|space_mm|>", buf_minute_space); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_second_space[10] = { 0 }; - sprintf(buf_second_space, "%02d", timeinfo_space->tm_sec); - replacement_t = StrReplace(replacement, "<|space_ss|>", buf_second_space); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - char buf_difftime_space[10] = { 0 }; - sprintf(buf_difftime_space, "%d", (int)difftime(g_osdSysTimeStamp, rawtime_space)); - replacement_t = StrReplace(replacement, "<|difftime|>", buf_difftime_space); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - - if (enable_base64_image == 1) { - - char buf_image_size[50] = { 0 }; - sprintf(buf_image_size, "%d", image_buff_size_base64); - replacement_t = StrReplace(replacement, "<|snap_size|>", buf_image_size); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - replacement_t = StrReplace(replacement, "<|snap_image|>", image_buff_base64); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - if (pNext != NULL && IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE && pNext->image_id >= 0 && pNext->image_id < MAX_PLATE_BUF_NUM && cropped_image_size_base64[pNext->image_id] >= 1) { - if (cropped_image_base64 != NULL && cropped_image_base64[pNext->image_id] != NULL) { - char buf_image_size[50] = { 0 }; - sprintf(buf_image_size, "%d", cropped_image_size_base64[pNext->image_id]); - replacement_t = StrReplace(replacement, "<|cropped_size|>", buf_image_size); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - - cropped_image_base64[pNext->image_id][cropped_image_size_base64[pNext->image_id]] = '\0'; - replacement_t = StrReplace(replacement, "<|cropped_image|>", cropped_image_base64[pNext->image_id]); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - replacement = replacement_t; - } - } - } - - strcpy(OutputString, replacement); - if (replacement != NULL) { - free(replacement); - replacement = NULL; - } - //printf("\n-----%s\n", OutputString); - return strlen(OutputString); - -} -//ReplaceKeyWords// - -size_t ReplaceKeyWords_space(detection_pos* pNext,char *SequenceString, int space_zone, int space_id, char* InputString, char *OutputString, int tracking_channel_idx, int detection_zone_idx, int trigger_idx, char* image_buff_base64, int image_buff_size_base64, int enable_base64_image, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64, int show_large_bbox) -{ - //printf("\n-------ReplaceKeyWords space----0\n"); - size_t content_size = 0; - //printf("\n-------ReplaceKeyWords space----1\n"); - if (pNext != NULL && SequenceString != NULL && strcmp(SequenceString,"<|space_zone|><|space_id|>")==0 && strstr(InputString,"<|space_zone|>")!=NULL && strstr(InputString, "<|space_id|>") != NULL && space_zone >= 0 && space_id >= 0) - { - //printf("\n-------ReplaceKeyWords space----2\n"); - char content_temp[BUFSIZE_V3] = { 0 }; - strcpy(content_temp,"["); - for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { - for (int index_parking = 0; index_parking < viewDetectionZone[tracking_channel_idx][index_zone].parking_space; index_parking++) { - char content_current[BUFSIZE_V3] = { 0 }; - ReplaceKeyWords(pNext, index_zone, index_parking, InputString, content_current, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, enable_base64_image, cropped_image_base64, cropped_image_size_base64, show_large_bbox); - - if (index_zone == (viewChannelData[tracking_channel_idx].count_zone - 1) && index_parking == (viewDetectionZone[tracking_channel_idx][index_zone].parking_space - 1)) { - strcat(content_temp, content_current); - } - else { - strcat(content_temp, content_current); - strcat(content_temp, ","); - } - } - } - strcat(content_temp, "]"); - content_size = strlen(content_temp); - strcpy(OutputString, content_temp); - //printf("\n-------ReplaceKeyWords space----3\n"); - //printf("\n-------OutputString:%s\n", OutputString); - } - else if (pNext != NULL && SequenceString != NULL && strcmp(SequenceString, "<|space_id|>") == 0 && strstr(InputString, "<|space_id|>") != NULL && space_zone >= 0 && space_id >= 0) - { - //printf("\n-------ReplaceKeyWords space----4\n"); - char content_temp[BUFSIZE_V3] = { 0 }; - strcpy(content_temp, "["); - for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) - { - for (int index_parking = 0; index_parking < viewDetectionZone[tracking_channel_idx][index_zone].parking_space; index_parking++) - { - char content_current[BUFSIZE_V3] = { 0 }; - ReplaceKeyWords(pNext, index_zone, index_parking, InputString, content_current, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, enable_base64_image, cropped_image_base64, cropped_image_size_base64, show_large_bbox); - - if (index_zone == (viewChannelData[tracking_channel_idx].count_zone - 1) && index_parking == (viewDetectionZone[tracking_channel_idx][index_zone].parking_space - 1)) - { - strcat(content_temp, content_current); - } - else - { - strcat(content_temp, content_current); - strcat(content_temp, ","); - } - } - } - strcat(content_temp, "]"); - content_size = strlen(content_temp); - strcpy(OutputString, content_temp); - //viewDetectionZone[tracking_channel_idx][detection_zone_idx].parking_space - //printf("\n-------OutputString:%s\n", OutputString); - //printf("\n-------ReplaceKeyWords space----5\n"); - } - else if(pNext != NULL) - { - //printf("\n-------ReplaceKeyWords space----6\n"); - char content_temp[BUFSIZE_V3] = { 0 }; - ReplaceKeyWords(pNext, space_zone, space_id, InputString, content_temp, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, enable_base64_image, cropped_image_base64, cropped_image_size_base64, show_large_bbox); - content_size = strlen(content_temp); - strcpy(OutputString, content_temp); - //printf("\n-------ReplaceKeyWords space----7\n"); - } - else - { - content_size = 0; - } - - return content_size; -} - -#endif - -//會用到UTF8 Encoder -void UpdateBehaviorData(QueueInfo* q_info, int tracking_channel_idx, int detection_zone_idx,int trigger_idx, int enable_lang) { - q_info->behavior_ID = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); - if ((q_info->behavior_ID & TRIGGER_ZONE_VIOLATION) == TRIGGER_ZONE_VIOLATION) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe7\xa6\x81\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//禁區偵測 UTF8 Encoder - else//en_gb - strcpy(q_info->behavior_desc, "Prohibit zone");//禁區偵測 UTF8 Encoder - strcpy(q_info->behavior_name, "TRIGGER_ZONE_VIOLATION"); - } - else if ((q_info->behavior_ID & TRIGGER_DISTANCE_VIOLATION) == TRIGGER_DISTANCE_VIOLATION) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe8\xb7\x9d\xe9\x9b\xa2\xe9\x81\x95\xe8\xa6\x8f\xe5\x81\xb5\xe6\xb8\xac");//距離違規偵測 UTF8 Encoder - else//en_gb - strcpy(q_info->behavior_desc, "Distance violation");//距離違規偵測 UTF8 Encoder - strcpy(q_info->behavior_name, "TRIGGER_DISTANCE_VIOLATION"); - } - else if ((q_info->behavior_ID & TRIGGER_HIGH_VIOLATION) == TRIGGER_HIGH_VIOLATION) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe9\xab\x98\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//高度偵測 UTF8 Encoder - else//en_gb - strcpy(q_info->behavior_desc, "Height detection");//高度偵測 UTF8 Encoder - strcpy(q_info->behavior_name, "TRIGGER_HIGH_VIOLATION"); - } - else if ((q_info->behavior_ID & TRIGGER_FORGET_TO_GIVE_WAY) == TRIGGER_FORGET_TO_GIVE_WAY) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe4\xb8\x8d\xe7\xa6\xae\xe8\xae\x93\xe5\x81\xb5\xe6\xb8\xac");//不禮讓偵測 UTF8 Encoder - else//en_gb - strcpy(q_info->behavior_desc, "Forget to give way detection");//不禮讓偵測 UTF8 Encoder - strcpy(q_info->behavior_name, "TRIGGER_FORGET_TO_GIVE_WAY"); - } - else if ((q_info->behavior_ID & TRIGGER_SPEED_HIGH) == TRIGGER_SPEED_HIGH) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe6\x9c\x80\xe5\xa4\xa7\xe9\x80\x9f\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//最大速度偵測 UTF8 Encoder - else//en_gb - strcpy(q_info->behavior_desc, "Max speed detection");//最大速度偵測 UTF8 Encoder - strcpy(q_info->behavior_name, "TRIGGER_SPEED_HIGH"); - } - else if ((q_info->behavior_ID & TRIGGER_SPEED_LOW) == TRIGGER_SPEED_LOW) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe6\x9c\x80\xe4\xbd\x8e\xe9\x80\x9f\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//最低速度偵測 UTF8 Encoder - else//en_gb - strcpy(q_info->behavior_desc, "Min speed detection");//最低速度偵測 UTF8 Encoder - strcpy(q_info->behavior_name, "TRIGGER_SPEED_LOW"); - } - else if ((q_info->behavior_ID & TRIGGER_PARKING_VIOLATION) == TRIGGER_PARKING_VIOLATION) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe7\xa6\x81\xe5\x8d\x80\xe9\x99\x90\xe6\x99\x82\xe5\x81\xb5\xe6\xb8\xac\x20\x2f\x20\xe9\x81\x95\xe8\xa6\x8f\xe5\x81\x9c\xe8\xbb\x8a");//禁區限時偵測 / 違規停車 - else//en_gb - strcpy(q_info->behavior_desc, "Zone with dwell / Parking violation");//禁區限時偵測 / 違規停車 - strcpy(q_info->behavior_name, "TRIGGER_PARKING_VIOLATION"); - } - else if ((q_info->behavior_ID & TRIGGER_GO_STRAIGHT) == TRIGGER_GO_STRAIGHT) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe8\xad\xa6\xe6\x88\x92\xe7\xb7\x9a\x20\x2f\x20\xe7\x9b\xb4\xe8\xa1\x8c\xe5\x81\xb5\xe6\xb8\xac");//警戒線 / 直行偵測 - else//en_gb - strcpy(q_info->behavior_desc, "Tripwire / Traffic flow");//警戒線 / 直行偵測 - strcpy(q_info->behavior_name, "TRIGGER_GO_STRAIGHT"); - } - else if ((q_info->behavior_ID & TRIGGER_GO_STRAIGHT_RED_LIGHT) == TRIGGER_GO_STRAIGHT_RED_LIGHT) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe7\xb4\x85\xe7\x87\x88\xe8\xad\xa6\xe6\x88\x92\xe7\xb7\x9a\x20\x2f\x20\xe7\xb4\x85\xe7\x87\x88\xe7\x9b\xb4\xe8\xa1\x8c");//紅燈警戒線 / 紅燈直行 - else//en_gb - strcpy(q_info->behavior_desc, "Tripwire on red / Running red lights");//紅燈警戒線 / 紅燈直行 - strcpy(q_info->behavior_name, "TRIGGER_GO_STRAIGHT_RED_LIGHT"); - } - else if ((q_info->behavior_ID & TRIGGER_TURN_LEFT_RED_LIGHT) == TRIGGER_TURN_LEFT_RED_LIGHT) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe7\xb4\x85\xe7\x87\x88\xe5\xb7\xa6\xe8\xbd\x89");//紅燈左轉 - else//en_gb - strcpy(q_info->behavior_desc, "Turning left on red");//紅燈左轉 - strcpy(q_info->behavior_name, "TRIGGER_TURN_LEFT_RED_LIGHT"); - } - else if ((q_info->behavior_ID & TRIGGER_TURN_RIGHT_RED_LIGHT) == TRIGGER_TURN_RIGHT_RED_LIGHT) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe7\xb4\x85\xe7\x87\x88\xe5\x8f\xb3\xe8\xbd\x89");//紅燈右轉 - else//en_gb - strcpy(q_info->behavior_desc, "Turning right on red");//紅燈右轉 - strcpy(q_info->behavior_name, "TRIGGER_TURN_RIGHT_RED_LIGHT"); - } - else if ((q_info->behavior_ID & TRIGGER_TURN_LEFT) == TRIGGER_TURN_LEFT) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe5\xb7\xa6\xe8\xbd\x89\xe5\x81\xb5\xe6\xb8\xac");//左轉偵測 - else//en_gb - strcpy(q_info->behavior_desc, "Turn left");//左轉偵測 - strcpy(q_info->behavior_name, "TRIGGER_TURN_LEFT"); - } - else if ((q_info->behavior_ID & TRIGGER_TURN_RIGHT) == TRIGGER_TURN_RIGHT) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe5\x8f\xb3\xe8\xbd\x89\xe5\x81\xb5\xe6\xb8\xac");//右轉偵測 - else//en_gb - strcpy(q_info->behavior_desc, "Turn right");//右轉偵測 - strcpy(q_info->behavior_name, "TRIGGER_TURN_RIGHT"); - } - else if ((q_info->behavior_ID & TRIGGER_ALLOW_LIST) == TRIGGER_ALLOW_LIST) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe7\x99\xbd\xe5\x90\x8d\xe5\x96\xae\xe8\xad\xa6\xe6\x88\x92\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//白名單警戒區偵測 - else//en_gb - strcpy(q_info->behavior_desc, "LPR allowed list detection in zone");//白名單警戒區偵測 - strcpy(q_info->behavior_name, "TRIGGER_ALLOW_LIST"); - } - else if ((q_info->behavior_ID & TRIGGER_GUEST_LIST) == TRIGGER_GUEST_LIST) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe8\xa8\xaa\xe5\xae\xa2\xe5\x90\x8d\xe5\x96\xae\xe8\xad\xa6\xe6\x88\x92\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//訪客名單警戒區偵測 - else//en_gb - strcpy(q_info->behavior_desc, "LPR visitor list detection in zone");//訪客名單警戒區偵測 - strcpy(q_info->behavior_name, "TRIGGER_GUEST_LIST"); - } - else if ((q_info->behavior_ID & TRIGGER_BLOCK_LIST) == TRIGGER_BLOCK_LIST) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe9\xbb\x91\xe5\x90\x8d\xe5\x96\xae\xe8\xad\xa6\xe6\x88\x92\xe5\x8d\x80\xe5\x81\xb5\xe6\xb8\xac");//黑名單警戒區偵測 - else//en_gb - strcpy(q_info->behavior_desc, "LPR denial list detection in zone");//黑名單警戒區偵測 - strcpy(q_info->behavior_name, "TRIGGER_BLOCK_LIST"); - } - else if ((q_info->behavior_ID & TRIGGER_QUEUING_VIOLATION) == TRIGGER_QUEUING_VIOLATION) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe5\xaf\x86\xe5\xba\xa6\xe5\x81\xb5\xe6\xb8\xac");//密度偵測 - else//en_gb - strcpy(q_info->behavior_desc, "Density detection");//密度偵測 - strcpy(q_info->behavior_name, "TRIGGER_QUEUING_VIOLATION"); - } - else if ((q_info->behavior_ID & TRIGGER_MISSING_OBJECT_DETECTION) == TRIGGER_MISSING_OBJECT_DETECTION) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\x41\x49\xe9\x81\xba\xe5\xa4\xb1\xe7\x89\xa9\xe5\x81\xb5\xe6\xb8\xac");//AI遺失物偵測 - else//en_gb - strcpy(q_info->behavior_desc, "AI missing object detection");//AI遺失物偵測 - strcpy(q_info->behavior_name, "TRIGGER_MISSING_OBJECT_DETECTION"); - } - else if ((q_info->behavior_ID & TRIGGER_MISSING_UNATTENDED) == TRIGGER_MISSING_UNATTENDED) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe9\x81\xba\xe5\xa4\xb1\xe7\x89\xa9\xe5\x8f\x8a\xe9\x81\xba\xe7\x95\x99\xe7\x89\xa9\xe5\x81\xb5\xe6\xb8\xac");//遺失物及遺留物偵測 - else//en_gb - strcpy(q_info->behavior_desc, "Unattended or missing object");//遺失物及遺留物偵測 - strcpy(q_info->behavior_name, "TRIGGER_MISSING_UNATTENDED"); - } - else if ((q_info->behavior_ID & TRIGGER_TAMPERING) == TRIGGER_TAMPERING) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe9\x98\xb2\xe7\xa0\xb4\xe5\xa3\x9e\xe5\x81\xb5\xe6\xb8\xac");//防破壞偵測 - else//en_gb - strcpy(q_info->behavior_desc, "Tampering detection");//防破壞偵測 - strcpy(q_info->behavior_name, "TRIGGER_TAMPERING"); - } - else if ((q_info->behavior_ID & TRIGGER_ALL_OBJECTS) == TRIGGER_ALL_OBJECTS) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe7\x89\xa9\xe7\xa8\xae\xe5\x90\x8c\xe6\x99\x82\xe5\xad\x98\xe5\x9c\xa8\xe5\x81\xb5\xe6\xb8\xac\x20\x28\x41\x4e\x44\x29");//同樣物種同時存在偵測 - else//en_gb - strcpy(q_info->behavior_desc, "All objects detection (AND)");//物種同時存在偵測 (AND) - strcpy(q_info->behavior_name, "TRIGGER_ALL_OBJECTS"); - } - else if ((q_info->behavior_ID & TRIGGER_LACK_OF_ANY_OBJECT) == TRIGGER_LACK_OF_ANY_OBJECT) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe7\xbc\xba\xe5\xb0\x91\xe4\xbb\xbb\xe4\xb8\x80\xe7\x89\xa9\xe7\xa8\xae\xe5\x90\x8c\xe6\x99\x82\xe5\xad\x98\xe5\x9c\xa8\xe5\x81\xb5\xe6\xb8\xac\x20\x28\x4e\x41\x4e\x44\x29");//缺少任一物種同時存在偵測 (NAND) - else//en_gb - strcpy(q_info->behavior_desc, "Lack of any object detection (NAND)");//缺少任一物種同時存在偵測 (NAND) - strcpy(q_info->behavior_name, "TRIGGER_LACK_OF_ANY_OBJECT"); - } - - //TRIGGER_SPEED_HIGH和TRIGGER_SPEED_LOW前面就有了 - - /* - else if (q_info->behavior_ID & TRIGGER_BG_LEARNING) { - if (strcmp(SystemSetting.language, "zh_tw") == 0 && enable_lang == 1) - strcpy(q_info->behavior_desc, "\xe5\xad\xb8\xe7\xbf\x92\xe8\x83\x8c\xe6\x99\xaf\xe4\xb8\xad");//學習背景中 - else//en_gb - strcpy(q_info->behavior_desc, "BG learning");//學習背景中 - strcpy(q_info->behavior_name, "TRIGGER_BG_LEARNING"); - }*/ -} - -long Get_eventCounterList_post_interval(int index_counter) { -#ifdef GY_OS_V_SERIES - - -#else - if (strcmp(eventCounterList[index_counter].post_interval,"1 minute") == 0) { - return 60; - } - else if (strcmp(eventCounterList[index_counter].post_interval, "5 minutes") == 0) { - return 60 * 5; - } - else if (strcmp(eventCounterList[index_counter].post_interval, "30 minutes") == 0) { - return 60 * 30; - } - else if (strcmp(eventCounterList[index_counter].post_interval, "1 hour") == 0) { - return 60 * 60; - } - else if (strcmp(eventCounterList[index_counter].post_interval, "1 day") == 0) { - return 60 * 60 * 24; - } - else if (strcmp(eventCounterList[index_counter].post_interval, "1 week") == 0) { - return 60 * 60 * 24 * 7; - } - else if (strcmp(eventCounterList[index_counter].post_interval, "1 month") == 0) { - return 60 * 60 * 24 * 30; - } - else -#endif - return -1; -} - -long Get_mail_post_interval() { - if (strcmp(SystemSetting.email_reset_time_interval, "1 minute") == 0) { - return 60; - } - else if (strcmp(SystemSetting.email_reset_time_interval, "5 minutes") == 0) { - return 60 * 5; - } - else if (strcmp(SystemSetting.email_reset_time_interval, "30 minutes") == 0) { - return 60 * 30; - } - else if (strcmp(SystemSetting.email_reset_time_interval, "1 hour") == 0) { - return 60 * 60; - } - else if (strcmp(SystemSetting.email_reset_time_interval, "1 day") == 0) { - return 60 * 60 * 24; - } - else if (strcmp(SystemSetting.email_reset_time_interval, "1 week") == 0) { - return 60 * 60 * 24 * 7; - } - else if (strcmp(SystemSetting.email_reset_time_interval, "1 month") == 0) { - return 60 * 60 * 24 * 30; - } - else - return -1; -} - -struct timeval currtime_CheckPostEventCondition[MAX_DETECTION_ZONE]; -static long last_ms_CheckPostEventCondition[MAX_DETECTION_ZONE] = { 0 }; -#ifdef GY_OS_AMBA -struct timeval currtime_CheckPostEventCondition_snmp[MAX_DETECTION_ZONE]; -static long last_ms_CheckPostEventCondition_snmp[MAX_DETECTION_ZONE] = { 0 }; -#endif -struct timeval currtime_CheckPostEventCondition_cloud; -static long last_ms_CheckPostEventCondition_cloud = 0; - -struct timeval currtime_CheckPostEventCondition_cloud_v2; -static long last_ms_CheckPostEventCondition_cloud_v2 = 0; - -//struct timeval currtime_CheckPostEventCondition_cloud_record_v2; -//static long last_ms_CheckPostEventCondition_cloud_record_v2 = 0; - -struct timeval currtime_CheckPostEventCondition_counter[MAX_DETECTION_ZONE]; -static long last_ms_CheckPostEventCondition_counter[MAX_DETECTION_ZONE] = { 0 }; - -struct timeval currtime_CheckPostEventCondition_email; -static long last_ms_CheckPostEventCondition_email = 0; - -//#ifdef GY_OS_AMBA -struct timeval currtime_CheckPostEventCondition_ftp; -static long last_ms_CheckPostEventCondition_ftp = 0; -//#endif - -void initial_g_PostRecorderList() { - for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) - { - g_PostRecorderList[i].iIfUse = 0; - g_PostRecorderList[i].t_FirstGetTime = 0; - g_PostRecorderList[i].t_FirstGetTime_total = 0; - g_PostRecorderList[i].t_UpdateTime = 0; - - for (int m = 0; m < MAX_DETECTION_ZONE; m++) { - g_PostRecorderList[i].check_if_post[m] = 0; - } - g_PostRecorderList[i].check_if_cloud = 0; - g_PostRecorderList[i].check_if_cloud_v2 = 0; - g_PostRecorderList[i].check_if_cloud_record_v2 = 0; - g_PostRecorderList[i].check_if_email = 0; - g_PostRecorderList[i].check_if_ftp = 0; - g_PostRecorderList[i].check_if_getalarmmotion = 0; - - g_PostRecorderList[i].box_x = 0.0; - g_PostRecorderList[i].box_y = 0.0; - g_PostRecorderList[i].box_w = 0.0; - g_PostRecorderList[i].box_h = 0.0; - - g_PostRecorderList[i].object_id = 0.0; - g_PostRecorderList[i].zone_idx = 0.0; - - strcpy(g_PostRecorderList[i].sPlateNumber, ""); - strcpy(g_PostRecorderList[i].name, ""); - - g_PostRecorderList[i].count_trigger = 0; - //g_PostRecorderList[i].the_same_id = 0; - //-------------------------------- - - g_longterm_PostRecorderList[i].iIfUse = 0; - g_longterm_PostRecorderList[i].t_FirstGetTime = 0; - g_longterm_PostRecorderList[i].t_FirstGetTime_total = 0; - g_longterm_PostRecorderList[i].t_UpdateTime = 0; - - for (int m = 0; m < MAX_DETECTION_ZONE; m++) { - g_longterm_PostRecorderList[i].check_if_post[m] = 0; - } - g_longterm_PostRecorderList[i].check_if_cloud = 0; - g_longterm_PostRecorderList[i].check_if_cloud_v2 = 0; - g_longterm_PostRecorderList[i].check_if_cloud_record_v2 = 0; - g_longterm_PostRecorderList[i].check_if_email = 0; - g_longterm_PostRecorderList[i].check_if_ftp = 0; - g_longterm_PostRecorderList[i].check_if_getalarmmotion = 0; - - g_longterm_PostRecorderList[i].box_x = 0.0; - g_longterm_PostRecorderList[i].box_y = 0.0; - g_longterm_PostRecorderList[i].box_w = 0.0; - g_longterm_PostRecorderList[i].box_h = 0.0; - - g_longterm_PostRecorderList[i].object_id = 0.0; - g_longterm_PostRecorderList[i].zone_idx = 0.0; - - strcpy(g_longterm_PostRecorderList[i].sPlateNumber, ""); - strcpy(g_longterm_PostRecorderList[i].name, ""); - - g_longterm_PostRecorderList[i].count_trigger = 0; - //g_longterm_PostRecorderList[i].the_same_id = 0; - } -} - -void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int detection_zone_idx, int trigger_idx,int force_to_push,char* aiengine_data,int counter_idx, char* image_buff,int image_buff_size, char* image_buff_base64, int image_buff_size_base64, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64) -{ - long d_no_parking_time = (long)viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time; - - if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute >= 1) { - d_no_parking_time = (long)(viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute * 60); - } - - gettimeofday(&currtime_CheckPostEventCondition[detection_zone_idx], NULL); - long current_ms_CheckPostEventCondition = (currtime_CheckPostEventCondition[detection_zone_idx].tv_sec * 1000) + (currtime_CheckPostEventCondition[detection_zone_idx].tv_usec / 1000); - - gettimeofday(&currtime_CheckPostEventCondition_cloud, NULL); - long current_ms_CheckPostEventCondition_cloud = (currtime_CheckPostEventCondition_cloud.tv_sec * 1000) + (currtime_CheckPostEventCondition_cloud.tv_usec / 1000); - - gettimeofday(&currtime_CheckPostEventCondition_cloud_v2, NULL); - long current_ms_CheckPostEventCondition_cloud_v2 = (currtime_CheckPostEventCondition_cloud_v2.tv_sec * 1000) + (currtime_CheckPostEventCondition_cloud_v2.tv_usec / 1000); - - //gettimeofday(&currtime_CheckPostEventCondition_cloud_record_v2, NULL); - //long current_ms_CheckPostEventCondition_cloud_record_v2 = (currtime_CheckPostEventCondition_cloud_record_v2.tv_sec * 1000) + (currtime_CheckPostEventCondition_cloud_record_v2.tv_usec / 1000); - - - gettimeofday(&currtime_CheckPostEventCondition_counter[detection_zone_idx], NULL); - long current_ms_CheckPostEventCondition_counter = (currtime_CheckPostEventCondition_counter[detection_zone_idx].tv_sec * 1000) + (currtime_CheckPostEventCondition_counter[detection_zone_idx].tv_usec / 1000); - - gettimeofday(&currtime_CheckPostEventCondition_email, NULL); - long current_ms_CheckPostEventCondition_email = (currtime_CheckPostEventCondition_email.tv_sec * 1000) + (currtime_CheckPostEventCondition_email.tv_usec / 1000); - - gettimeofday(&currtime_CheckPostEventCondition_ftp, NULL); - long current_ms_CheckPostEventCondition_ftp = (currtime_CheckPostEventCondition_ftp.tv_sec * 1000) + (currtime_CheckPostEventCondition_ftp.tv_usec / 1000); - -#ifdef GY_OS_AMBA - gettimeofday(&currtime_CheckPostEventCondition_snmp[detection_zone_idx], NULL); - long current_ms_CheckPostEventCondition_snmp = (currtime_CheckPostEventCondition_snmp[detection_zone_idx].tv_sec * 1000) + (currtime_CheckPostEventCondition_snmp[detection_zone_idx].tv_usec / 1000); -#endif - - //printf("\n--------------QueueSize:%d\n",(int)QueueSize(_POST_NOTIFICATION)); - - int check_if_ok_for_location = 0; - int index_g_PostRecorderList[MAX_POST_RECODER_SIZE] = { 0 }; - int size_g_PostRecorderList = 0; - - //int check_if_ok_for_location_longterm = 0; - int index_g_PostRecorderList_longterm[MAX_POST_RECODER_SIZE] = { 0 }; - int size_g_PostRecorderList_longterm = 0; - - unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); - - if (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0) { - //printf("\nFFFFFFF : 1\n"); - if (pNext != NULL /*&& aiengine_data != NULL && strlen(aiengine_data) >= 1*/ && counter_idx == -1) { - //printf("\nFFFFFFF : 2\n"); - if (strlen(pNext->name) >= 1 && pNext->width > 0 && pNext->height > 0 /*&& !(IsANPRCategory_L_Plate(pNext->name))*/) - { - //printf("\nFFFFFFF : 3\n"); - //Free over Recoder time - - - int iFindMatchPost = 0; - int iFindMatchPost_longterm = 0; - time_t now_time = time(0); - - double max_dwell_short = 0.0; - - for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) - { - if (g_PostRecorderList[i].iIfUse == 0 && g_longterm_PostRecorderList[i].iIfUse == 0) { - break; - } - - if (g_PostRecorderList[i].iIfUse == 1 /*&& g_PostRecorderList[i].zone_idx == detection_zone_idx*/) - { - if (g_PostRecorderList[i].box_w > 0 && g_PostRecorderList[i].box_h > 0 && pNext->width > 0 && pNext->height > 0) { - detection_pos temp_A = { 0 }; - temp_A.left_x = g_PostRecorderList[i].box_x; - temp_A.top_y = g_PostRecorderList[i].box_y; - temp_A.width = g_PostRecorderList[i].box_w; - temp_A.height = g_PostRecorderList[i].box_h; - strcpy(temp_A.name, g_PostRecorderList[i].name); - - float temp_A_iou = detection_overlap_ratio_union(&temp_A, pNext); - //float compare_ratio = (temp_A.height / temp_A.width) / (pNext->height / pNext->width); - float compare_height_ratio = pNext->height / temp_A.height; - float compare_width_ratio = pNext->width / temp_A.width; - - if (strlen(g_PostRecorderList[i].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) - { - if (strlen(g_PostRecorderList[i].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_PostRecorderList[i].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) - { - double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); - if (temp_dTime > max_dwell_short) { - max_dwell_short = temp_dTime; - } - - iFindMatchPost = 1; - //g_PostRecorderList[i].t_UpdateTime = now_time; - //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; - g_PostRecorderList[i].zone_idx = detection_zone_idx; - - check_if_ok_for_location = 1; - - if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { - index_g_PostRecorderList[size_g_PostRecorderList] = i; - size_g_PostRecorderList++; - } - } - } - else if (IsGarbageCategory(&temp_A) || IsGarbageCategory(pNext)) - { - if (temp_A_iou > 0.0 && IsGarbageCategory(&temp_A) && IsGarbageCategory(pNext)) { - double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); - if (temp_dTime > max_dwell_short) { - max_dwell_short = temp_dTime; - } - - iFindMatchPost = 1; - //g_PostRecorderList[i].t_UpdateTime = now_time; - //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; - g_PostRecorderList[i].zone_idx = detection_zone_idx; - - check_if_ok_for_location = 1; - - if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { - index_g_PostRecorderList[size_g_PostRecorderList] = i; - size_g_PostRecorderList++; - } - } - } - else { - if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 - && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) - { - if (strcmp(g_PostRecorderList[i].name, pNext->name) == 0) { - if (strcmp(pNext->name, "person") == 0) { - //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) - { - if (/*g_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { - double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); - if (temp_dTime > max_dwell_short) { - max_dwell_short = temp_dTime; - } - - iFindMatchPost = 1; - //g_PostRecorderList[i].t_UpdateTime = now_time; - //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; - g_PostRecorderList[i].zone_idx = detection_zone_idx; - - check_if_ok_for_location = 1; - - if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { - index_g_PostRecorderList[size_g_PostRecorderList] = i; - size_g_PostRecorderList++; - } - } - } - } - else { - if (/*g_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { - double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total); - if (temp_dTime > max_dwell_short) { - max_dwell_short = temp_dTime; - } - - iFindMatchPost = 1; - //g_PostRecorderList[i].t_UpdateTime = now_time; - //g_PostRecorderList[i].object_id = pNext->obj_tracking_id; - g_PostRecorderList[i].zone_idx = detection_zone_idx; - - check_if_ok_for_location = 1; - - if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { - index_g_PostRecorderList[size_g_PostRecorderList] = i; - size_g_PostRecorderList++; - } - } - } - } - } - } - } - } - - if (g_longterm_PostRecorderList[i].iIfUse == 1 /*&& g_longterm_PostRecorderList[i].zone_idx == detection_zone_idx*/) - { - if (g_longterm_PostRecorderList[i].box_w > 0 && g_longterm_PostRecorderList[i].box_h > 0 && pNext->width > 0 && pNext->height > 0) { - detection_pos temp_A = { 0 }; - temp_A.left_x = g_longterm_PostRecorderList[i].box_x; - temp_A.top_y = g_longterm_PostRecorderList[i].box_y; - temp_A.width = g_longterm_PostRecorderList[i].box_w; - temp_A.height = g_longterm_PostRecorderList[i].box_h; - strcpy(temp_A.name, g_longterm_PostRecorderList[i].name); - - float temp_A_iou = detection_overlap_ratio_union(&temp_A, pNext); - //float compare_ratio = (temp_A.height / temp_A.width) / (pNext->height / pNext->width); - float compare_height_ratio = pNext->height / temp_A.height; - float compare_width_ratio = pNext->width / temp_A.width; - - if (strlen(g_longterm_PostRecorderList[i].sPlateNumber) >= 1 || IsANPRCategory_L_Plate(pNext->name)) - { - if (strlen(g_longterm_PostRecorderList[i].sPlateNumber) >= 1 && IsANPRCategory_L_Plate(pNext->name) && LevenshteinDistance(g_longterm_PostRecorderList[i].sPlateNumber, pNext->properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) - { - iFindMatchPost_longterm = 1; - //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; - //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; - g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; - - //check_if_ok_for_location_longterm = 1; - - if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { - index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; - size_g_PostRecorderList_longterm++; - } - } - } - else if (IsGarbageCategory(&temp_A) || IsGarbageCategory(pNext)) - { - if (temp_A_iou > 0.0 && IsGarbageCategory(&temp_A) && IsGarbageCategory(pNext)) { - iFindMatchPost_longterm = 1; - //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; - //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; - g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; - - //check_if_ok_for_location_longterm = 1; - - if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { - index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; - size_g_PostRecorderList_longterm++; - } - } - } - else { - if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0 - && compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) - { - if (strcmp(g_longterm_PostRecorderList[i].name, pNext->name) == 0) { - if (strcmp(pNext->name, "person") == 0) { - //if (compare_ratio <= 1.1 && compare_ratio >= 0.9) - { - if (/*g_longterm_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { - iFindMatchPost_longterm = 1; - //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; - //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; - g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; - - //check_if_ok_for_location_longterm = 1; - - if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { - index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; - size_g_PostRecorderList_longterm++; - } - } - } - } - else { - if (/*g_longterm_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) { - iFindMatchPost_longterm = 1; - //g_longterm_PostRecorderList[i].t_UpdateTime = now_time; - //g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; - g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; - - //check_if_ok_for_location_longterm = 1; - - if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { - index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; - size_g_PostRecorderList_longterm++; - } - } - } - } - } - } - } - } - } - -#if 1 - if (strcmp(pNext->name, "object") != 0 && strcmp(pNext->name, "person") != 0) { - if (iFindMatchPost_longterm == 0) - { - //printf("\nFFFFFFF : 4\n"); - for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) - { - if (g_longterm_PostRecorderList[i].iIfUse == 0) - { - g_longterm_PostRecorderList[i].iIfUse = 1; - g_longterm_PostRecorderList[i].t_FirstGetTime = now_time; - g_longterm_PostRecorderList[i].t_FirstGetTime_total = now_time; - g_longterm_PostRecorderList[i].t_UpdateTime = now_time; - - for (int m = 0; m < MAX_DETECTION_ZONE; m++) { - g_longterm_PostRecorderList[i].check_if_post[m] = 0; - } - g_longterm_PostRecorderList[i].check_if_cloud = 0; - g_longterm_PostRecorderList[i].check_if_cloud_v2 = 0; - g_longterm_PostRecorderList[i].check_if_cloud_record_v2 = 0; - g_longterm_PostRecorderList[i].check_if_email = 0; - g_longterm_PostRecorderList[i].check_if_ftp = 0; - g_longterm_PostRecorderList[i].check_if_getalarmmotion = 0; - - g_longterm_PostRecorderList[i].box_x = pNext->left_x + pNext->width / 3.0; - g_longterm_PostRecorderList[i].box_y = pNext->top_y + pNext->height / 3.0; - g_longterm_PostRecorderList[i].box_w = pNext->width / 3.0; - g_longterm_PostRecorderList[i].box_h = pNext->height / 3.0; - - g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id; - g_longterm_PostRecorderList[i].zone_idx = detection_zone_idx; - - //memcpy(&g_PostRecorderList[i].ori_Data, pNext, sizeof(detection_pos)); - - if (IsANPRCategory_L_Plate(pNext->name)) { - strcpy(g_longterm_PostRecorderList[i].sPlateNumber, pNext->properties.plate); - } - else { - strcpy(g_longterm_PostRecorderList[i].sPlateNumber, ""); - } - strcpy(g_longterm_PostRecorderList[i].name, pNext->name); - - g_longterm_PostRecorderList[i].count_trigger = 1; - //g_longterm_PostRecorderList[i].the_same_id = 0; - - //check_if_ok_for_location_longterm = 1; - - if (size_g_PostRecorderList_longterm < MAX_POST_RECODER_SIZE) { - index_g_PostRecorderList_longterm[size_g_PostRecorderList_longterm] = i; - size_g_PostRecorderList_longterm++; - } - break; - } - } - - } - } -#endif - - if (iFindMatchPost == 0) - { - //printf("\nFFFFFFF : 4\n"); - for (int i = 0; i < MAX_POST_RECODER_SIZE; i++) - { - if (g_PostRecorderList[i].iIfUse == 0) - { - g_PostRecorderList[i].iIfUse = 1; - g_PostRecorderList[i].t_FirstGetTime = now_time; - g_PostRecorderList[i].t_FirstGetTime_total = now_time; - g_PostRecorderList[i].t_UpdateTime = now_time; - - for (int m = 0; m < MAX_DETECTION_ZONE; m++) { - g_PostRecorderList[i].check_if_post[m] = 0; - } - g_PostRecorderList[i].check_if_cloud = 0; - g_PostRecorderList[i].check_if_cloud_v2 = 0; - g_PostRecorderList[i].check_if_cloud_record_v2 = 0; - g_PostRecorderList[i].check_if_email = 0; - g_PostRecorderList[i].check_if_ftp = 0; - g_PostRecorderList[i].check_if_getalarmmotion = 0; - - g_PostRecorderList[i].box_x = pNext->left_x + pNext->width / 3.0; - g_PostRecorderList[i].box_y = pNext->top_y + pNext->height / 3.0; - g_PostRecorderList[i].box_w = pNext->width / 3.0; - g_PostRecorderList[i].box_h = pNext->height / 3.0; - - g_PostRecorderList[i].object_id = pNext->obj_tracking_id; - g_PostRecorderList[i].zone_idx = detection_zone_idx; - - //memcpy(&g_PostRecorderList[i].ori_Data, pNext, sizeof(detection_pos)); - - if (IsANPRCategory_L_Plate(pNext->name)){ - strcpy(g_PostRecorderList[i].sPlateNumber, pNext->properties.plate); - } - else { - strcpy(g_PostRecorderList[i].sPlateNumber, ""); - } - strcpy(g_PostRecorderList[i].name, pNext->name); - - g_PostRecorderList[i].count_trigger = 1; - //g_PostRecorderList[i].the_same_id = 0; - - check_if_ok_for_location = 1; - - if (size_g_PostRecorderList < MAX_POST_RECODER_SIZE) { - index_g_PostRecorderList[size_g_PostRecorderList] = i; - size_g_PostRecorderList++; - } - break; - } - } - - } - } - - } - } - - //printf("\n--------check_if_ok_for_location :%d\n", check_if_ok_for_location); - -#ifdef GY_OS_AMBA - if (pNext == NULL || strcmp(SystemSetting.enable_post_only_if_both_detected, "No") == 0 || - (strcmp(SystemSetting.enable_post_only_if_both_detected, "Yes") == 0 && - pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && - pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) || - !(viewChannelData[0].enable_anpr) || - !(viewChannelData[0].enable_face) || - !(viewChannelData[0].enable_traffic) || - !IsANPRCategory(featureType) || - !(featureType & FEATURE_TRAF_DET)) -#endif - { - - if (activePostNotification && counter_idx == -1 && - (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || - (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1) || - ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { - - //printf("\n----------------check_if_post:%d,size_g_PostRecorderList:%d\n", g_PostRecorderList[index_g_PostRecorderList[0]].check_if_post[detection_zone_idx], size_g_PostRecorderList); - //printf("\n--------CheckPostEventCondition:1\n"); - if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || - (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_post[detection_zone_idx] == 0 && - (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_post[detection_zone_idx] == 0)))) { - //printf("\n--------CheckPostEventCondition:2\n"); - if (last_ms_CheckPostEventCondition[detection_zone_idx] == 0 || (current_ms_CheckPostEventCondition - last_ms_CheckPostEventCondition[detection_zone_idx]) > d_no_parking_time * 1000 || force_to_push == 1) { - - - - //printf("\n--------CheckPostEventCondition:3\n"); - char eachPostEvent[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; - char Temp[MAX_MSG_LEN * 10] = { 0 }; - strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].post_event_name); - int post_event_num = StrSplit(Temp, eachPostEvent, ","); - //printf("\n------UU:5\n"); - //char *replacement = NULL; - //char *replacement_t = NULL; - - int check_if_SD_recording_post = 0; - int index_SD_post = -1; - - int check_if_white_LED_post = 0; - int index_LED_post = -1; - - int index_first_post = -1; - - if (post_event_num >= 1 && strcmp(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].post_event_name,"Null")!=0) { - - for (int i = 0; i < post_event_num; i++) - { - for (int j = 0; j < MAX_POST_EVENTS; j++) - { - if (strlen(eachPostEvent[i]) >= 1 && strcmp(eachPostEvent[i], postEventList[j].post_event_name) == 0) - { - if (((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) && postEventList[j].check_if_delivering == 0) - { - if (index_first_post == -1) { - index_first_post = j; - } - - if (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && strstr(postEventList[j].post_event_name, "SD recording") != NULL && g_check_if_no_brand == 0) { - index_SD_post = j; - check_if_SD_recording_post = 1; - } - - if (g_camera_white_LED == 1 && strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && strstr(postEventList[j].post_event_name, "White LED") != NULL && g_check_if_no_brand == 0) { - index_LED_post = j; - check_if_white_LED_post = 1; - } - } - else - { - /* - printf("Post queue is full!\n"); - pthread_mutex_lock(&mutex_post_notification_pop); - pthread_mutex_lock(&mutex_curl); - if(QueueSize(_POST_NOTIFICATION) >= 1) - QueueClear(_POST_NOTIFICATION); - pthread_mutex_unlock(&mutex_curl); - pthread_mutex_unlock(&mutex_post_notification_pop); - printf("Post queue is full!end\n");*/ - } - //break; - } - } - } - - if (index_SD_post == -1 && index_LED_post >= 0) { - index_SD_post = index_LED_post; - } - - if (index_SD_post == -1) { - index_SD_post = index_first_post; - } - - //printf("\n-----------index_SD_post:%d\n", index_SD_post); - - int check_if_status_cloud = 0; - - if (index_SD_post >= 0) { - time_t rawtime_temp = g_post_SysTimeStamp; - - //printf("\n------------cloud_enable_notification:%s\n", SystemSetting.cloud_enable_notification); - //if(aiengine_data != NULL) - //printf("\n------------aiengine_data:%s\n", aiengine_data); - //printf("\n------------enable_location_once_to_post:%s\n", heartbeatData.enable_location_once_to_post); - //printf("\n------------check_if_ok_for_location:%d\n", check_if_ok_for_location); - - if (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && aiengine_data != NULL && strlen(aiengine_data) >= 1 && g_check_if_no_brand == 0 && - (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || - (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1) || - ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL)) - ) - { - - if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || - (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud == 0 && - (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_cloud == 0)))) { - if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) { - check_if_status_cloud = 1; - } - } - } - - //printf("\n---------check_if_SD_recording_post:%d,check_if_status_cloud:%d\n", check_if_SD_recording_post, check_if_status_cloud); - - if ((check_if_SD_recording_post == 0 && check_if_white_LED_post == 0) || check_if_status_cloud == 1) { - - last_ms_CheckPostEventCondition[detection_zone_idx] = current_ms_CheckPostEventCondition; - - for (int i = 0; i < size_g_PostRecorderList; i++) { - g_PostRecorderList[index_g_PostRecorderList[i]].check_if_post[detection_zone_idx] = 1; - } - - for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { - g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_post[detection_zone_idx] = 1; - } - - //printf("\n--------CheckPostEventCondition:4\n"); - for (int post_times = 0; post_times < 2; post_times++) { - - int temp_index_post = 0; - if (post_times == 0 && index_SD_post >= 0) { - temp_index_post = index_SD_post; - } - else { - if (check_if_SD_recording_post == 1 && check_if_white_LED_post == 1 && index_LED_post >= 0) { - temp_index_post = index_LED_post; - } - else { - break; - } - } - - pthread_mutex_lock(&mutex_post_notification_pop); - postEventList[temp_index_post].check_if_delivering = 1; - - QueueInfo q_info = { 0 }; - strcpy(q_info.post_event_name, postEventList[temp_index_post].post_event_name); - strcpy(q_info.post_protocol, postEventList[temp_index_post].post_protocol); - strcpy(q_info.post_method, postEventList[temp_index_post].post_event_method); - strcpy(q_info.host_name, postEventList[temp_index_post].post_host_ip); - strcpy(q_info.host_port, postEventList[temp_index_post].post_host_port); - strcpy(q_info.post_timeout, postEventList[temp_index_post].post_timeout); - - if (pNext != NULL) { - strcpy(q_info.q_name, pNext->name); - if (pNext->linked_plate_length >= 1) { - strcpy(q_info.q_plate, pNext->linked_plate); - } - else { - strcpy(q_info.q_plate, pNext->properties.plate); - } - } - - if (strlen(postEventList[temp_index_post].post_url) >= 1) { - //if (pNext != NULL) { - size_t url_size = ReplaceKeyWords(pNext, -1, -1, postEventList[temp_index_post].post_url, q_info.post_url, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64, 0); - //} - //else { - //strcpy(q_info.post_url, postEventList[temp_index_post].post_url); - //} - q_info.post_url[url_size] = '\0'; - } - else - q_info.post_url[0] = '\0'; - - //printf("\n------ q_info.post_url #1:%s\n", q_info.post_url); - - strcpy(q_info.post_username, postEventList[temp_index_post].post_username); - strcpy(q_info.post_password, postEventList[temp_index_post].post_password); - strcpy(q_info.post_jpeg_file_name, postEventList[temp_index_post].post_jpeg_file_name); - - if (image_buff_size >= 1) { - memcpy(q_info.image_buff, image_buff, image_buff_size); - q_info.image_buff_size = image_buff_size; - } - else { - q_info.image_buff_size = 0; - } - - if (strcmp(postEventList[temp_index_post].post_jpeg_file_name_format, "fixed")) { - q_info.enable_filename_fixed = 1; - } - else { - q_info.enable_filename_fixed = 0; - } - - - if (strlen(postEventList[temp_index_post].post_customized_header) >= 1) { - strcpy(q_info.post_customized_header, postEventList[temp_index_post].post_customized_header); - } - else - q_info.post_customized_header[0] = '\0'; - - if (strcmp(postEventList[temp_index_post].post_file_format, "text") == 0) { - q_info.enable_attached_image = 0; - - if (strlen(postEventList[temp_index_post].post_content) >= 1) { - - //if (pNext != NULL) { - //printf("\n------check post 2--------6------3\n"); - q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[temp_index_post].post_sequence, 0, 0, postEventList[temp_index_post].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); - //q_info.content_size = 0; - //printf("\n-----size:%lu\n", q_info.content_size); - //printf("\n------check post 2--------6------4\n"); - //} - //else { - //strcpy(q_info.content, postEventList[temp_index_post].post_content); - //} - q_info.content[q_info.content_size] = '\0'; - } - else - q_info.content[0] = '\0'; - } - else if (strcmp(postEventList[temp_index_post].post_file_format, "jpeg") == 0) { - q_info.enable_attached_image = 1; - if (strlen(postEventList[temp_index_post].post_content) >= 1) { - //if (pNext != NULL) { - q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[temp_index_post].post_sequence, 0, 0, postEventList[temp_index_post].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); - //} - //else { - //strcpy(q_info.content, postEventList[temp_index_post].post_content); - //} - q_info.content[q_info.content_size] = '\0'; - } - else - q_info.content[0] = '\0'; - } - else { - q_info.enable_attached_image = 0; - q_info.content[0] = '\0'; - } - - //printf("\n----------_POST_NOTIFICATION\n"); - //printf("\n------check post 3\n"); - if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { - //printf("\n------check post 3--------1\n"); - if (force_to_push == 1) { - //printf("\n------check post 3--------2\n"); - for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { - if(g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) - QueuePush(q_info, _POST_NOTIFICATION); - } - //printf("\n------check post 3--------3\n"); - } - else { - //printf("\n------check post 3--------4\n"); - if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) - QueuePush(q_info, _POST_NOTIFICATION); - //printf("\n------check post 3--------5\n"); - } - } - //printf("\n------check post 4\n"); - pthread_mutex_unlock(&mutex_post_notification_pop); - } - - //if (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && aiengine_data != NULL && strlen(aiengine_data) >= 1 && check_if_SD_recording_post == 1 && - //(strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || - //(strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1))) - - if (check_if_status_cloud == 1) - { - //if (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud == 0) - { - //if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) - { - //if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) - { - //printf("\n------------Segmentation fault:%d\n", 5); - - QueueInfo q_info = { 0 }; - strcpy(q_info.post_url, "post_to_cloud"); - strcpy(q_info.cloud_aiengine, aiengine_data); - if (pNext != NULL) { - strcpy(q_info.q_name, pNext->name); - if (pNext->linked_plate_length >= 1) { - strcpy(q_info.q_plate, pNext->linked_plate); - } - else { - strcpy(q_info.q_plate, pNext->properties.plate); - } - } - - q_info.rawtime = rawtime_temp; - - if (image_buff_size >= 1) { - memcpy(q_info.image_buff, image_buff, image_buff_size); - q_info.image_buff_size = image_buff_size; - } - else { - q_info.image_buff_size = 0; - } - - UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 1); - - /** - printf("\n-------------\n"); - printf("\nbehavior_ID: %d\n", q_info.behavior_ID); - printf("\n-------------\n");*/ - - - QueuePush(q_info, _POST_NOTIFICATION); - - //printf("\n------------Segmentation fault:%d\n", 6); - } - last_ms_CheckPostEventCondition_cloud = current_ms_CheckPostEventCondition_cloud; - for (int i = 0; i < size_g_PostRecorderList; i++) { - g_PostRecorderList[index_g_PostRecorderList[i]].check_if_cloud = 1; - g_PostRecorderList[index_g_PostRecorderList[i]].check_if_getalarmmotion = 1; - } - - for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { - g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_cloud = 1; - g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_getalarmmotion = 1; - } - } - } - } - - } - } - - for (int i = 0; i < post_event_num; i++) - { - for (int j = 0; j < MAX_POST_EVENTS; j++) - { - if (strlen(eachPostEvent[i]) >= 1 && strcmp(eachPostEvent[i], postEventList[j].post_event_name) == 0) - { - if (((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) && postEventList[j].check_if_delivering == 0) - { - if (index_SD_post != j && index_LED_post != j) { - - last_ms_CheckPostEventCondition[detection_zone_idx] = current_ms_CheckPostEventCondition; - - for (int k = 0; k < size_g_PostRecorderList; k++) { - g_PostRecorderList[index_g_PostRecorderList[k]].check_if_post[detection_zone_idx] = 1; - } - - for (int k = 0; k < size_g_PostRecorderList_longterm; k++) { - g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[k]].check_if_post[detection_zone_idx] = 1; - } - - pthread_mutex_lock(&mutex_post_notification_pop); - postEventList[j].check_if_delivering = 1; - - QueueInfo q_info = { 0 }; - strcpy(q_info.post_event_name, postEventList[j].post_event_name); - strcpy(q_info.post_protocol, postEventList[j].post_protocol); - strcpy(q_info.post_method, postEventList[j].post_event_method); - strcpy(q_info.host_name, postEventList[j].post_host_ip); - strcpy(q_info.host_port, postEventList[j].post_host_port); - strcpy(q_info.post_timeout, postEventList[j].post_timeout); - if (pNext != NULL) { - strcpy(q_info.q_name, pNext->name); - if (pNext->linked_plate_length >= 1) { - strcpy(q_info.q_plate, pNext->linked_plate); - } - else { - strcpy(q_info.q_plate, pNext->properties.plate); - } - } - - - if (strlen(postEventList[j].post_url) >= 1) { - //if (pNext != NULL) { - size_t url_size = ReplaceKeyWords(pNext, -1, -1, postEventList[j].post_url, q_info.post_url, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64, 0); - //} - //else { - //strcpy(q_info.post_url, postEventList[j].post_url); - //} - q_info.post_url[url_size] = '\0'; - } - else - q_info.post_url[0] = '\0'; - - //printf("\n------ q_info.post_url #1:%s\n", q_info.post_url); - - strcpy(q_info.post_username, postEventList[j].post_username); - strcpy(q_info.post_password, postEventList[j].post_password); - strcpy(q_info.post_jpeg_file_name, postEventList[j].post_jpeg_file_name); - if (image_buff_size >= 1) { - memcpy(q_info.image_buff, image_buff, image_buff_size); - q_info.image_buff_size = image_buff_size; - } - else { - q_info.image_buff_size = 0; - } - - if (strcmp(postEventList[j].post_jpeg_file_name_format, "fixed")) { - q_info.enable_filename_fixed = 1; - } - else { - q_info.enable_filename_fixed = 0; - } - - - if (strlen(postEventList[j].post_customized_header) >= 1) { - strcpy(q_info.post_customized_header, postEventList[j].post_customized_header); - } - else - q_info.post_customized_header[0] = '\0'; - - - if (strcmp(postEventList[j].post_file_format, "text") == 0) { - q_info.enable_attached_image = 0; - if (strlen(postEventList[j].post_content) >= 1) { - //if (pNext != NULL) { - q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); - //} - //else { - //strcpy(q_info.content, postEventList[j].post_content); - //} - q_info.content[q_info.content_size] = '\0'; - } - else - q_info.content[0] = '\0'; - } - else if (strcmp(postEventList[j].post_file_format, "jpeg") == 0) { - q_info.enable_attached_image = 1; - if (strlen(postEventList[j].post_content) >= 1) { - //if (pNext != NULL) { - q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 0); - //} - //else { - //strcpy(q_info.content, postEventList[j].post_content); - //} - q_info.content[q_info.content_size] = '\0'; - } - else - q_info.content[0] = '\0'; - } - else { - q_info.enable_attached_image = 0; - q_info.content[0] = '\0'; - } - - //printf("\n----------_POST_NOTIFICATION\n"); - - if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { - if (force_to_push == 1) { - for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { - if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) - QueuePush(q_info, _POST_NOTIFICATION); - } - } - else { - if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) - QueuePush(q_info, _POST_NOTIFICATION); - } - } - pthread_mutex_unlock(&mutex_post_notification_pop); - } - } - } - } - } - } - else { - time_t rawtime_temp = g_post_SysTimeStamp; - - int check_if_status_cloud = 0; - //printf("\n--------CheckPostEventCondition:4\n"); - //printf("\n------------cloud_enable_notification:%s\n", SystemSetting.cloud_enable_notification); - //if(aiengine_data != NULL) - //printf("\n------------aiengine_data:%s\n", aiengine_data); - //printf("\n------------enable_location_once_to_post:%s\n", heartbeatData.enable_location_once_to_post); - //printf("\n------------check_if_ok_for_location:%d\n", check_if_ok_for_location); - /* - if (aiengine_data != NULL) { - printf("\n--------strlen(aiengine_data):%d\n", strlen(aiengine_data)); - } - else { - printf("\n-------strlen(aiengine_data):NULL\n"); - } - - if (pNext == NULL) { - printf("\n--------pNext:NULL\n"); - } - else { - printf("\n--------pNext:not NUll\n"); - }*/ - - if (aiengine_data != NULL && strlen(aiengine_data) >= 1 && - (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || - (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1)|| - ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { - //printf("\n--------CheckPostEventCondition:5--1\n"); - if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || - (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud == 0 && - (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_cloud == 0)))) { - - //printf("\n--------CheckPostEventCondition:5--2\n"); - if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) { - check_if_status_cloud = 1; - } - } - } - //printf("\n--------check_if_status_cloud:%d\n", check_if_status_cloud); - if (check_if_status_cloud == 1 && strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0 && g_check_if_no_brand == 0) - { - //printf("\n--------CheckPostEventCondition:6\n"); - //if (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud == 0) - { - //if (last_ms_CheckPostEventCondition_cloud == 0 || (current_ms_CheckPostEventCondition_cloud - last_ms_CheckPostEventCondition_cloud) >= atoi(SystemSetting.cloud_notification_dwell) * 1000) - { - //if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) - { - //printf("\n------------Segmentation fault:%d\n", 5); - - QueueInfo q_info = { 0 }; - strcpy(q_info.post_url, "post_to_cloud"); - strcpy(q_info.cloud_aiengine, aiengine_data); - - if (pNext != NULL) { - strcpy(q_info.q_name, pNext->name); - if (pNext->linked_plate_length >= 1) { - strcpy(q_info.q_plate, pNext->linked_plate); - } - else { - strcpy(q_info.q_plate, pNext->properties.plate); - } - } - - q_info.rawtime = rawtime_temp; - - if (image_buff_size >= 1) { - memcpy(q_info.image_buff, image_buff, image_buff_size); - q_info.image_buff_size = image_buff_size; - } - else { - q_info.image_buff_size = 0; - } - - UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 1); - - /** - printf("\n-------------\n"); - printf("\nbehavior_ID: %d\n", q_info.behavior_ID); - printf("\n-------------\n");*/ - - - QueuePush(q_info, _POST_NOTIFICATION); - - //printf("\n------------Segmentation fault:%d\n", 6); - } - last_ms_CheckPostEventCondition_cloud = current_ms_CheckPostEventCondition_cloud; - for (int i = 0; i < size_g_PostRecorderList; i++) { - g_PostRecorderList[index_g_PostRecorderList[i]].check_if_cloud = 1; - g_PostRecorderList[index_g_PostRecorderList[i]].check_if_getalarmmotion = 1; - } - - for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { - g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_cloud = 1; - g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_getalarmmotion = 1; - } - } - } - } - } - } - } - } - - if (strcmp(SystemSetting.enable_cloud_v2, "Yes") == 0 && counter_idx == -1 && - (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || - (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1)|| - ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { - if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || - (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_cloud_v2 == 0 && - (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_cloud_v2)))) { - if (last_ms_CheckPostEventCondition_cloud_v2 == 0 || (current_ms_CheckPostEventCondition_cloud_v2 - last_ms_CheckPostEventCondition_cloud_v2) >= atoi(SystemSetting.cloud_v2_notification_dwell) * 1000) { - //if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) - { - //printf("\n------------Segmentation fault:%d\n", 5); - - QueueInfo q_info = { 0 }; - strcpy(q_info.post_url, "cloud_v2"); - - if (pNext != NULL) { - strcpy(q_info.q_name, pNext->name); - if (pNext->linked_plate_length >= 1) { - strcpy(q_info.q_plate, pNext->linked_plate); - } - else { - strcpy(q_info.q_plate, pNext->properties.plate); - } - } - - if (strlen(SystemSetting.cloud_v2_content) >= 1) { - //if (pNext != NULL) { - size_t v2_size = ReplaceKeyWords(pNext, -1, -1, SystemSetting.cloud_v2_content, q_info.cloud_v2_aiengine, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 1, cropped_image_base64, cropped_image_size_base64, 1); - //} - //else { - //strcpy(q_info.cloud_v2_aiengine, SystemSetting.cloud_v2_content); - //} - q_info.cloud_v2_aiengine[v2_size] = '\0'; - } - else - q_info.cloud_v2_aiengine[0] = '\0'; - - //strcpy(q_info.cloud_v2_aiengine, aiengine_data); - - if (image_buff_size >= 1) { - memcpy(q_info.image_buff, image_buff, image_buff_size); - q_info.image_buff_size = image_buff_size; - } - else { - q_info.image_buff_size = 0; - } - - UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 1); - - /** - printf("\n-------------\n"); - printf("\nbehavior_ID: %d\n", q_info.behavior_ID); - printf("\n-------------\n");*/ - - - QueuePush(q_info, _GETALARMMOTION); - - //printf("\n------------Segmentation fault:%d\n", 6); - } - last_ms_CheckPostEventCondition_cloud_v2 = current_ms_CheckPostEventCondition_cloud_v2; - - for (int i = 0; i < size_g_PostRecorderList; i++) { - g_PostRecorderList[index_g_PostRecorderList[i]].check_if_cloud_v2 = 1; - } - - for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { - g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_cloud_v2 = 1; - } - } - } - } - -#ifdef GY_OS_AMBA - if (activeSNMPPost && /*strcmp(SystemSetting.enable_cloud, "Yes") == 0 &&*/ counter_idx == -1) { - - //printf("\n--------CheckPostEventCondition:2\n"); - if (last_ms_CheckPostEventCondition_snmp[detection_zone_idx] == 0 || (current_ms_CheckPostEventCondition_snmp - last_ms_CheckPostEventCondition_snmp[detection_zone_idx]) > d_no_parking_time * 1000 || force_to_push == 1) { - - //printf("\n--------CheckPostEventCondition:3\n"); - char eachPostEvent[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; - char Temp[MAX_MSG_LEN * 10] = { 0 }; - strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].post_event_name); - int post_event_num = StrSplit(Temp, eachPostEvent, ","); - //printf("\n------UU:10\n"); - //char *replacement = NULL; - //char *replacement_t = NULL; - - for (int i = 0; i < post_event_num; i++) - { - for (int j = 0; j < MAX_SNMP_MANAGEMENT; j++) - { - if (strlen(eachPostEvent[i]) >= 1 && strcmp(eachPostEvent[i], SNMPManagementList[j].snmp_event_name) == 0) - { - if (((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) && SNMPManagementList[j].check_if_delivering == 0) - { - //printf("\n--------CheckPostEventCondition:4\n"); - pthread_mutex_lock(&mutex_post_notification_pop); - SNMPManagementList[j].check_if_delivering = 1; - - QueueInfo q_info = { 0 }; - - strcpy(q_info.snmp_event_name, SNMPManagementList[j].snmp_event_name); - strcpy(q_info.snmp_version, SNMPManagementList[j].snmp_version); - strcpy(q_info.snmp_group_name, SNMPManagementList[j].snmp_group_name); - strcpy(q_info.snmp_host_ip, SNMPManagementList[j].snmp_host_ip); - strcpy(q_info.snmp_host_port, SNMPManagementList[j].snmp_host_port); - strcpy(q_info.snmp_oid, SNMPManagementList[j].snmp_oid); - strcpy(q_info.snmp_type, SNMPManagementList[j].snmp_type); - - if (strcmp(q_info.snmp_type, "integer") == 0 && strcmp(SNMPManagementList[j].snmp_value,"<|hextoint|>")==0){ - size_t snmp_size = ReplaceKeyWords(pNext, -1, -1, SNMPManagementList[j].snmp_value, q_info.snmp_value, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64, 0); - q_info.snmp_value[snmp_size] = '\0'; - } - else { - strcpy(q_info.snmp_value, SNMPManagementList[j].snmp_value); - } - - //printf("\n------q_info.snmp_value:%s\n", q_info.snmp_value); - - if (pNext != NULL) { - strcpy(q_info.q_name, pNext->name); - if (pNext->linked_plate_length >= 1) { - strcpy(q_info.q_plate, pNext->linked_plate); - } - else { - strcpy(q_info.q_plate, pNext->properties.plate); - } - } - - //printf("\n----------_POST_NOTIFICATION\n"); - - if (AI_fps >= 1 && strlen(q_info.snmp_oid) >= 1 && strlen(q_info.snmp_host_ip) >= 1) { - if (force_to_push == 1) { - for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { - if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) - QueuePush(q_info, _POST_NOTIFICATION); - } - } - else { - if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) - QueuePush(q_info, _POST_NOTIFICATION); - } - } - pthread_mutex_unlock(&mutex_post_notification_pop); - } - else - { - /* - printf("Post queue is full!\n"); - pthread_mutex_lock(&mutex_post_notification_pop); - pthread_mutex_lock(&mutex_curl); - if(QueueSize(_POST_NOTIFICATION) >= 1) - QueueClear(_POST_NOTIFICATION); - pthread_mutex_unlock(&mutex_curl); - pthread_mutex_unlock(&mutex_post_notification_pop); - printf("Post queue is full!end\n");*/ - } - break; - } - } - } - last_ms_CheckPostEventCondition_snmp[detection_zone_idx] = current_ms_CheckPostEventCondition_snmp; - } - } -#endif - -#ifdef GY_OS_V_SERIES - -#else - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || -#ifdef GY_OS_NOVA - IsANPRCategory(featureType) || -#endif - g_IsCustomWeight == 1) { - if (activePostNotification && counter_idx >= 0 && Get_eventCounterList_post_interval(counter_idx) != -1) { - if (last_ms_CheckPostEventCondition_counter[detection_zone_idx] == 0 || (Get_eventCounterList_post_interval(counter_idx) != -1 && (current_ms_CheckPostEventCondition_counter - last_ms_CheckPostEventCondition_counter[detection_zone_idx]) >= Get_eventCounterList_post_interval(counter_idx) * 1000)) { - for (int j = 0; j < MAX_POST_EVENTS; j++) - { - if (strlen(postEventList[j].post_event_name) >= 1 && strcmp(eventCounterList[counter_idx].link_to_post_event_name, postEventList[j].post_event_name) == 0) - { - if (postEventList[j].check_if_delivering == 0) - { - pthread_mutex_lock(&mutex_post_notification_pop); - postEventList[j].check_if_delivering = 1; - - QueueInfo q_info = { 0 }; - strcpy(q_info.post_event_name, postEventList[j].post_event_name); - strcpy(q_info.post_protocol, postEventList[j].post_protocol); - strcpy(q_info.post_method, postEventList[j].post_event_method); - strcpy(q_info.host_name, postEventList[j].post_host_ip); - strcpy(q_info.host_port, postEventList[j].post_host_port); - strcpy(q_info.post_timeout, postEventList[j].post_timeout); - - if (pNext != NULL) { - strcpy(q_info.q_name, pNext->name); - if (pNext->linked_plate_length >= 1) { - strcpy(q_info.q_plate, pNext->linked_plate); - } - else { - strcpy(q_info.q_plate, pNext->properties.plate); - } - } - - if (strlen(postEventList[j].post_url) >= 1) { - //if (pNext != NULL) { - size_t url_size = ReplaceKeyWords(pNext, -1, -1, postEventList[j].post_url, q_info.post_url, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64,0); - //} - //else { - //strcpy(q_info.post_url, postEventList[j].post_url); - //} - q_info.post_url[url_size] = '\0'; - } - else - q_info.post_url[0] = '\0'; - - //printf("\n------ q_info.post_url #2:%s\n", q_info.post_url); - - strcpy(q_info.post_username, postEventList[j].post_username); - strcpy(q_info.post_password, postEventList[j].post_password); - strcpy(q_info.post_jpeg_file_name, postEventList[j].post_jpeg_file_name); - if (image_buff_size >= 1) { - memcpy(q_info.image_buff, image_buff, image_buff_size); - q_info.image_buff_size = image_buff_size; - } - else { - q_info.image_buff_size = 0; - } - - if (strcmp(postEventList[j].post_jpeg_file_name_format, "fixed")) { - q_info.enable_filename_fixed = 1; - } - else { - q_info.enable_filename_fixed = 0; - } - - - if (strlen(postEventList[j].post_customized_header) >= 1) { - strcpy(q_info.post_customized_header, postEventList[j].post_customized_header); - } - else - q_info.post_customized_header[0] = '\0'; - - - if (strcmp(postEventList[j].post_file_format, "text") == 0) { - q_info.enable_attached_image = 0; - if (strlen(postEventList[j].post_content) >= 1) { - //if (pNext != NULL) { - q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64,1, cropped_image_base64, cropped_image_size_base64,0); - //} - //else { - //strcpy(q_info.content, postEventList[j].post_content); - //} - q_info.content[q_info.content_size] = '\0'; - } - else - q_info.content[0] = '\0'; - } - else if (strcmp(postEventList[j].post_file_format, "jpeg") == 0) { - q_info.enable_attached_image = 1; - if (strlen(postEventList[j].post_content) >= 1) { - //if (pNext != NULL) { - q_info.content_size = ReplaceKeyWords_space(pNext, postEventList[j].post_sequence, 0, 0, postEventList[j].post_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64,1, cropped_image_base64, cropped_image_size_base64,0); - //} - //else { - //strcpy(q_info.content, postEventList[j].post_content); - //} - q_info.content[q_info.content_size] = '\0'; - } - else - q_info.content[0] = '\0'; - } - else { - q_info.enable_attached_image = 0; - q_info.content[0] = '\0'; - } - - /*if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || - - g_IsCustomWeight == 1) { - char buf_content[256] = { '\0' }; - sprintf(buf_content, "{\"counter_name\":\"%s\",\"counter_count\":%d}", eventCounterList[counter_idx].counter_name, eventCounterList[counter_idx].counter_count); - - strcpy(q_info.content, buf_content); - }*/ - - if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { - if (force_to_push == 1) { - for (int k = 0; k < MAX_REPEAT_PUSH_THE_FORCED; k++) { - if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) - QueuePush(q_info, _POST_NOTIFICATION); - } - } - else { - if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) - QueuePush(q_info, _POST_NOTIFICATION); - } - } - pthread_mutex_unlock(&mutex_post_notification_pop); - } - else - { - /* - printf("Post queue is full!\n"); - pthread_mutex_lock(&mutex_post_notification_pop); - pthread_mutex_lock(&mutex_curl); - if(QueueSize(_POST_NOTIFICATION) >= 1) - QueueClear(_POST_NOTIFICATION); - pthread_mutex_unlock(&mutex_curl); - pthread_mutex_unlock(&mutex_post_notification_pop); - printf("Post queue is full!end\n");*/ - } - break; - } - } - - last_ms_CheckPostEventCondition_counter[detection_zone_idx] = current_ms_CheckPostEventCondition_counter; - } - } - } -#endif - - if (strcmp(SystemSetting.enable_email_notification, "Yes") == 0 && counter_idx == -1 && - (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || - (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1) || - ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { - if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || - (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_email == 0 && - (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_email == 0)))) { - if (last_ms_CheckPostEventCondition_email == 0 || - (Get_mail_post_interval() == -1 && (current_ms_CheckPostEventCondition_email - last_ms_CheckPostEventCondition_email) > d_no_parking_time * 1000) || - (Get_mail_post_interval() != -1 && (current_ms_CheckPostEventCondition_email - last_ms_CheckPostEventCondition_email) > Get_mail_post_interval() * 1000) || - force_to_push == 1) { - if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) - { - QueueInfo q_info = { 0 }; - - if (pNext != NULL) { - strcpy(q_info.q_name, pNext->name); - if (pNext->linked_plate_length >= 1) { - strcpy(q_info.q_plate, pNext->linked_plate); - } - else { - strcpy(q_info.q_plate, pNext->properties.plate); - } - } - - if (image_buff_size_base64 >= 1) { - memcpy(q_info.image_buff, image_buff_base64, image_buff_size_base64); - q_info.image_buff_size = image_buff_size_base64; - } - else { - q_info.image_buff_size = 0; - } - - if (strlen(emailData.email_content) >= 1) { - //if (pNext != NULL) { - q_info.content_size = ReplaceKeyWords(pNext, -1, -1, emailData.email_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64,1); - //} - //else { - //strcpy(q_info.content, emailData.email_content); - //} - q_info.content[q_info.content_size] = '\0'; - } - else { - q_info.content[0] = ' '; - q_info.content[1] = '\0'; - } - - strcpy(q_info.post_url, "post_to_mail"); - UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 0); - - - QueuePush(q_info, _POST_NOTIFICATION); - -#if 1 -#ifdef GY_OS_V_SERIES - -#else - if (Get_mail_post_interval() != -1) { - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || -#ifdef GY_OS_NOVA - IsANPRCategory(featureType) || -#endif - g_IsCustomWeight == 1) { - pthread_mutex_lock(&mutex_reset_counter); - time_t now_time = g_osdSysTimeStamp; - if (now_time < 1000000000) { - now_time = time(0); - } - for (int j = 0; j < MAX_EVENT_COUNTERS; j++) - { - reset_counter(j, now_time); - } - pthread_mutex_unlock(&mutex_reset_counter); - } - } -#endif -#endif - } - last_ms_CheckPostEventCondition_email = current_ms_CheckPostEventCondition_email; - - for (int i = 0; i < size_g_PostRecorderList; i++) { - g_PostRecorderList[index_g_PostRecorderList[i]].check_if_email = 1; - } - - for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { - g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_email = 1; - } - } - } - } -//#ifdef GY_OS_AMBA - if (strcmp(SystemSetting.enable_ftp, "Yes") == 0 && counter_idx == -1 && - (strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || - (strcmp(heartbeatData.enable_location_once_to_post, "Yes") == 0 && check_if_ok_for_location == 1)|| - ((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL))) { - if (((trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION || trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT || trigger_event_type == TRIGGER_ALL_OBJECTS) && pNext == NULL) || strcmp(heartbeatData.enable_location_once_to_post, "Yes") != 0 || - (size_g_PostRecorderList >= 1 && g_PostRecorderList[index_g_PostRecorderList[0]].check_if_ftp == 0 && - (size_g_PostRecorderList_longterm == 0 || (size_g_PostRecorderList_longterm >= 1 && g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[0]].check_if_ftp == 0)))){ - if (last_ms_CheckPostEventCondition_ftp == 0 || (current_ms_CheckPostEventCondition_ftp - last_ms_CheckPostEventCondition_ftp) > d_no_parking_time * 1000 || force_to_push == 1) - { - if ((QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) || force_to_push == 1) - { - QueueInfo q_info = { 0 }; - - if (pNext != NULL) { - strcpy(q_info.q_name, pNext->name); - if (pNext->linked_plate_length >= 1) { - strcpy(q_info.q_plate, pNext->linked_plate); - } - else { - strcpy(q_info.q_plate, pNext->properties.plate); - } - } - - if (image_buff_size_base64 >= 1) { - memcpy(q_info.image_buff, image_buff, image_buff_size); - q_info.image_buff_size = image_buff_size; - } - else { - q_info.image_buff_size = 0; - } - - /* - if (strlen(emailData.email_content) >= 1) { - if (pNext != NULL) { - ReplaceKeyWords(pNext,-1,-1, emailData.email_content, q_info.content, tracking_channel_idx, detection_zone_idx, trigger_idx, image_buff_base64, image_buff_size_base64, 0, cropped_image_base64, cropped_image_size_base64,1); - } - else { - strcpy(q_info.content, emailData.email_content); - } - } - else*/ - { - q_info.content[0] = ' '; - q_info.content[1] = '\0'; - } - - strcpy(q_info.post_url, "curl_to_ftp"); - //UpdateBehaviorData(&q_info, tracking_channel_idx, detection_zone_idx, trigger_idx, 0); - - if (q_info.image_buff_size >= 1) { - QueuePush(q_info, _POST_NOTIFICATION); - } - } - last_ms_CheckPostEventCondition_ftp = current_ms_CheckPostEventCondition_ftp; - - for (int i = 0; i < size_g_PostRecorderList; i++) { - g_PostRecorderList[index_g_PostRecorderList[i]].check_if_ftp = 1; - } - - for (int i = 0; i < size_g_PostRecorderList_longterm; i++) { - g_longterm_PostRecorderList[index_g_PostRecorderList_longterm[i]].check_if_ftp = 1; - } - } - } - } -//#endif - } -} - -struct timeval currtime_HeartbeatPost; -static long last_ms_HeartbeatPost = 0; -#if defined GY_OS_AMBA -struct timeval currtime_snmp_HeartbeatPost; -static long last_ms_snmp_HeartbeatPost = 0; -#endif -void HeartbeatPost() -{ - if (activePostNotification && strcmp(heartbeatData.enable_heartbeat,"Yes")==0) { - gettimeofday(&currtime_HeartbeatPost, NULL); - long current_ms_HeartbeatPost = (currtime_HeartbeatPost.tv_sec * 1000) + (currtime_HeartbeatPost.tv_usec / 1000); - if (last_ms_HeartbeatPost == 0 || (current_ms_HeartbeatPost - last_ms_HeartbeatPost) >= atoi(heartbeatData.heartbeat_dwell) * 1000 * 60) { - - for (int j = 0; j < MAX_POST_EVENTS; j++) - { - if (strcmp(heartbeatData.heartbeat_link_to_post_event_name, postEventList[j].post_event_name) == 0) - { - if (postEventList[j].check_if_delivering == 0) - { - pthread_mutex_lock(&mutex_post_notification_pop); - int index_j = j; - - postEventList[index_j].check_if_delivering = 1; - - QueueInfo q_info = { 0 }; - strcpy(q_info.post_event_name, postEventList[index_j].post_event_name); - strcpy(q_info.post_protocol, postEventList[index_j].post_protocol); - strcpy(q_info.post_method, postEventList[index_j].post_event_method); - strcpy(q_info.host_name, postEventList[index_j].post_host_ip); - strcpy(q_info.host_port, postEventList[index_j].post_host_port); - strcpy(q_info.post_url, postEventList[index_j].post_url); - strcpy(q_info.post_username, postEventList[index_j].post_username); - strcpy(q_info.post_password, postEventList[index_j].post_password); - strcpy(q_info.post_jpeg_file_name, postEventList[index_j].post_jpeg_file_name); - strcpy(q_info.post_timeout, postEventList[index_j].post_timeout); - - if (strcmp(postEventList[index_j].post_jpeg_file_name_format, "fixed")) { - q_info.enable_filename_fixed = 1; - } - else { - q_info.enable_filename_fixed = 0; - } - - - if (strlen(postEventList[index_j].post_customized_header) >= 1) { - strcpy(q_info.post_customized_header, postEventList[index_j].post_customized_header); - } - else - q_info.post_customized_header[0] = '\0'; - - - if (strcmp(postEventList[index_j].post_file_format, "text") == 0) { - q_info.enable_attached_image = 0; - if (strlen(postEventList[index_j].post_content) >= 1) { - strcpy(q_info.content, postEventList[index_j].post_content); - q_info.content_size = strlen(postEventList[index_j].post_content); - } - else - q_info.content[0] = '\0'; - } - else if (strcmp(postEventList[index_j].post_file_format, "jpeg") == 0) { - q_info.enable_attached_image = 1; - if (strlen(postEventList[index_j].post_content) >= 1) { - strcpy(q_info.content, postEventList[index_j].post_content); - q_info.content_size = strlen(postEventList[index_j].post_content); - } - else - q_info.content[0] = '\0'; - } - else { - q_info.enable_attached_image = 0; - q_info.content[0] = '\0'; - } - - if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { - if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) - QueuePush(q_info, _POST_NOTIFICATION); - } - pthread_mutex_unlock(&mutex_post_notification_pop); - } - break; - } - } - last_ms_HeartbeatPost = current_ms_HeartbeatPost; - } - } -#if defined GY_OS_AMBA - if (activeSNMPPost && strcmp(heartbeatData.enable_snmp_heartbeat, "Yes") == 0) { - gettimeofday(&currtime_snmp_HeartbeatPost, NULL); - long current_ms_snmp_HeartbeatPost = (currtime_snmp_HeartbeatPost.tv_sec * 1000) + (currtime_snmp_HeartbeatPost.tv_usec / 1000); - if (last_ms_snmp_HeartbeatPost == 0 || (current_ms_snmp_HeartbeatPost - last_ms_snmp_HeartbeatPost) >= (long)(atof(heartbeatData.snmp_heartbeat_dwell) * 1000.0)) { - for (int j = 0; j < MAX_SNMP_MANAGEMENT; j++) - { - if (strcmp(heartbeatData.snmp_heartbeat_link_to_post_event_name, SNMPManagementList[j].snmp_event_name) == 0) - { - if (SNMPManagementList[j].check_if_delivering == 0) { - pthread_mutex_lock(&mutex_post_notification_pop); - - SNMPManagementList[j].check_if_delivering = 1; - - QueueInfo q_info = { 0 }; - - strcpy(q_info.snmp_event_name, SNMPManagementList[j].snmp_event_name); - strcpy(q_info.snmp_version, SNMPManagementList[j].snmp_version); - strcpy(q_info.snmp_group_name, SNMPManagementList[j].snmp_group_name); - strcpy(q_info.snmp_host_ip, SNMPManagementList[j].snmp_host_ip); - strcpy(q_info.snmp_host_port, SNMPManagementList[j].snmp_host_port); - strcpy(q_info.snmp_oid, SNMPManagementList[j].snmp_oid); - strcpy(q_info.snmp_value, SNMPManagementList[j].snmp_value); - strcpy(q_info.snmp_type, SNMPManagementList[j].snmp_type); - - if (strcmp(q_info.snmp_type, "integer") == 0 && strcmp(SNMPManagementList[j].snmp_value, "<|hextoint|>") == 0) { - size_t snmp_size = ReplaceKeyWords(NULL, -1, -1, SNMPManagementList[j].snmp_value, q_info.snmp_value, 0, 0, 0, NULL, 0, 0, NULL, 0, 0); - q_info.snmp_value[snmp_size] = '\0'; - } - else { - strcpy(q_info.snmp_value, SNMPManagementList[j].snmp_value); - } - - if (AI_fps >= 1 && strlen(q_info.snmp_oid) >= 1 && strlen(q_info.snmp_host_ip) >= 1) { - if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) - QueuePush(q_info, _POST_NOTIFICATION); - } - pthread_mutex_unlock(&mutex_post_notification_pop); - } - break; - } - } - last_ms_snmp_HeartbeatPost = current_ms_snmp_HeartbeatPost; - } - } -#endif -} -#ifdef GY_OS_AMBA -struct timeval currtime_check_start_PTZ_autotracking_Post; -static long last_ms_check_start_PTZ_autotracking_Post = 0; -int last_state_PTZ_autotracking_for_start = 0; -int current_state_PTZ_autotracking_for_start = 0; -void check_start_PTZ_autotracking_Post() -{ - if (g_stPTZ_Handle.iIsInAutopan == 1 && g_stPTZ_Handle.iIsInAutoTracking == 1) { - current_state_PTZ_autotracking_for_start = 1; - } - else { - current_state_PTZ_autotracking_for_start = 0; - } - - gettimeofday(&currtime_check_start_PTZ_autotracking_Post, NULL); - long current_ms_check_start_PTZ_autotracking_Post = (currtime_check_start_PTZ_autotracking_Post.tv_sec * 1000) + (currtime_check_start_PTZ_autotracking_Post.tv_usec / 1000); - - if (activePostNotification && strcmp(heartbeatData.enable_check_ptz_start_autotracking, "Yes") == 0) { - if (last_ms_check_start_PTZ_autotracking_Post == 0 || (current_ms_check_start_PTZ_autotracking_Post - last_ms_check_start_PTZ_autotracking_Post) >= 2000) { - if (last_state_PTZ_autotracking_for_start == 0 && current_state_PTZ_autotracking_for_start == 1) { - for (int j = 0; j < MAX_POST_EVENTS; j++) - { - if (strcmp(heartbeatData.ptz_start_autotracking_link_to_post_event_name, postEventList[j].post_event_name) == 0) - { - if (postEventList[j].check_if_delivering == 0) - { - pthread_mutex_lock(&mutex_post_notification_pop); - int index_j = j; - - postEventList[index_j].check_if_delivering = 1; - - QueueInfo q_info = { 0 }; - strcpy(q_info.post_event_name, postEventList[index_j].post_event_name); - strcpy(q_info.post_protocol, postEventList[index_j].post_protocol); - strcpy(q_info.post_method, postEventList[index_j].post_event_method); - strcpy(q_info.host_name, postEventList[index_j].post_host_ip); - strcpy(q_info.host_port, postEventList[index_j].post_host_port); - strcpy(q_info.post_url, postEventList[index_j].post_url); - strcpy(q_info.post_username, postEventList[index_j].post_username); - strcpy(q_info.post_password, postEventList[index_j].post_password); - strcpy(q_info.post_jpeg_file_name, postEventList[index_j].post_jpeg_file_name); - strcpy(q_info.post_timeout, postEventList[index_j].post_timeout); - - if (strcmp(postEventList[index_j].post_jpeg_file_name_format, "fixed")) { - q_info.enable_filename_fixed = 1; - } - else { - q_info.enable_filename_fixed = 0; - } - - - if (strlen(postEventList[index_j].post_customized_header) >= 1) { - strcpy(q_info.post_customized_header, postEventList[index_j].post_customized_header); - } - else - q_info.post_customized_header[0] = '\0'; - - - if (strcmp(postEventList[index_j].post_file_format, "text") == 0) { - q_info.enable_attached_image = 0; - if (strlen(postEventList[index_j].post_content) >= 1) { - strcpy(q_info.content, postEventList[index_j].post_content); - q_info.content_size = strlen(postEventList[index_j].post_content); - } - else - q_info.content[0] = '\0'; - } - else if (strcmp(postEventList[index_j].post_file_format, "jpeg") == 0) { - q_info.enable_attached_image = 1; - if (strlen(postEventList[index_j].post_content) >= 1) { - strcpy(q_info.content, postEventList[index_j].post_content); - q_info.content_size = strlen(postEventList[index_j].post_content); - } - else - q_info.content[0] = '\0'; - } - else { - q_info.enable_attached_image = 0; - q_info.content[0] = '\0'; - } - - if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { - if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) - QueuePush(q_info, _POST_NOTIFICATION); - } - pthread_mutex_unlock(&mutex_post_notification_pop); - } - break; - } - } - last_ms_check_start_PTZ_autotracking_Post = current_ms_check_start_PTZ_autotracking_Post; - last_state_PTZ_autotracking_for_start = current_state_PTZ_autotracking_for_start; - } - else{ - last_ms_check_start_PTZ_autotracking_Post = current_ms_check_start_PTZ_autotracking_Post; - last_state_PTZ_autotracking_for_start = current_state_PTZ_autotracking_for_start; - } - } - } -} - -struct timeval currtime_check_end_PTZ_autotracking_Post; -static long last_ms_check_end_PTZ_autotracking_Post = 0; -int last_state_PTZ_autotracking_for_end = 0; -int current_state_PTZ_autotracking_for_end = 0; -void check_end_PTZ_autotracking_Post() -{ - if (g_stPTZ_Handle.iIsInAutopan == 1 && g_stPTZ_Handle.iIsInAutoTracking == 1) { - current_state_PTZ_autotracking_for_end = 1; - } - else { - current_state_PTZ_autotracking_for_end = 0; - } - - gettimeofday(&currtime_check_end_PTZ_autotracking_Post, NULL); - long current_ms_check_end_PTZ_autotracking_Post = (currtime_check_end_PTZ_autotracking_Post.tv_sec * 1000) + (currtime_check_end_PTZ_autotracking_Post.tv_usec / 1000); - - if (activePostNotification && strcmp(heartbeatData.enable_check_ptz_end_autotracking, "Yes") == 0) { - if (last_ms_check_end_PTZ_autotracking_Post == 0 || (current_ms_check_end_PTZ_autotracking_Post - last_ms_check_end_PTZ_autotracking_Post) >= 2000) { - if (last_state_PTZ_autotracking_for_end == 1 && current_state_PTZ_autotracking_for_end == 0) { - for (int j = 0; j < MAX_POST_EVENTS; j++) - { - if (strcmp(heartbeatData.ptz_end_autotracking_link_to_post_event_name, postEventList[j].post_event_name) == 0) - { - if (postEventList[j].check_if_delivering == 0) - { - pthread_mutex_lock(&mutex_post_notification_pop); - int index_j = j; - - postEventList[index_j].check_if_delivering = 1; - - QueueInfo q_info = { 0 }; - strcpy(q_info.post_event_name, postEventList[index_j].post_event_name); - strcpy(q_info.post_protocol, postEventList[index_j].post_protocol); - strcpy(q_info.post_method, postEventList[index_j].post_event_method); - strcpy(q_info.host_name, postEventList[index_j].post_host_ip); - strcpy(q_info.host_port, postEventList[index_j].post_host_port); - strcpy(q_info.post_url, postEventList[index_j].post_url); - strcpy(q_info.post_username, postEventList[index_j].post_username); - strcpy(q_info.post_password, postEventList[index_j].post_password); - strcpy(q_info.post_jpeg_file_name, postEventList[index_j].post_jpeg_file_name); - strcpy(q_info.post_timeout, postEventList[index_j].post_timeout); - - if (strcmp(postEventList[index_j].post_jpeg_file_name_format, "fixed")) { - q_info.enable_filename_fixed = 1; - } - else { - q_info.enable_filename_fixed = 0; - } - - - if (strlen(postEventList[index_j].post_customized_header) >= 1) { - strcpy(q_info.post_customized_header, postEventList[index_j].post_customized_header); - } - else - q_info.post_customized_header[0] = '\0'; - - - if (strcmp(postEventList[index_j].post_file_format, "text") == 0) { - q_info.enable_attached_image = 0; - if (strlen(postEventList[index_j].post_content) >= 1) { - strcpy(q_info.content, postEventList[index_j].post_content); - q_info.content_size = strlen(postEventList[index_j].post_content); - } - else - q_info.content[0] = '\0'; - } - else if (strcmp(postEventList[index_j].post_file_format, "jpeg") == 0) { - q_info.enable_attached_image = 1; - if (strlen(postEventList[index_j].post_content) >= 1) { - strcpy(q_info.content, postEventList[index_j].post_content); - q_info.content_size = strlen(postEventList[index_j].post_content); - } - else - q_info.content[0] = '\0'; - } - else { - q_info.enable_attached_image = 0; - q_info.content[0] = '\0'; - } - - if (AI_fps >= 1 && strlen(q_info.post_url) >= 1) { - if (g_http_handle != NULL && QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && bHttpServerThreadStart) - QueuePush(q_info, _POST_NOTIFICATION); - } - pthread_mutex_unlock(&mutex_post_notification_pop); - } - break; - } - } - last_ms_check_end_PTZ_autotracking_Post = current_ms_check_end_PTZ_autotracking_Post; - last_state_PTZ_autotracking_for_end = current_state_PTZ_autotracking_for_end; - } - else{ - last_ms_check_end_PTZ_autotracking_Post = current_ms_check_end_PTZ_autotracking_Post; - last_state_PTZ_autotracking_for_end = current_state_PTZ_autotracking_for_end; - } - } - } -} -#endif -curl_information_smtp_t user_smtp; -void SendMailEventCondition(char *my_subject,char * my_content, char* image_buff, int image_buff_size) { - - char snapshot_addr[MAX_IMG_SIZE] = { 0 }; - size_t snapshot_size = 0; - if (image_buff_size >= 1) { - snapshot_size = (size_t)image_buff_size; - memcpy(snapshot_addr, image_buff, snapshot_size); - } - - strcpy(user_smtp.receiver[0], IPCAMService.email_address1); - strcpy(user_smtp.receiver[1], IPCAMService.email_address2); - strcpy(user_smtp.receiver[2], IPCAMService.email_address3); - strcpy(user_smtp.receiver[3], IPCAMService.email_address4); - strcpy(user_smtp.receiver[4], IPCAMService.email_address5); - - strcpy(user_smtp.address, IPCAMService.email_address); - strcpy(user_smtp.server, IPCAMService.smtp_server); - sprintf(user_smtp.auth_mode, "%d", IPCAMService.smtp_auth_mode); - strcpy(user_smtp.port, IPCAMService.smtp_port); - sprintf(user_smtp.auth, "%d", IPCAMService.smtp_auth); - strcpy(user_smtp.user, IPCAMService.auth_account); - strcpy(user_smtp.password, IPCAMService.auth_password); - - strcpy(user_smtp.subject, my_subject); - strcpy(user_smtp.memory_data.memory, my_content); - user_smtp.memory_data.size = strlen(my_content); - - strcpy(user_smtp.attachment, "snap.jpg"); - - - if (net_curl_smtp_data(&user_smtp, snapshot_addr,(int)snapshot_size) < 0) { - printf("\nSMTP Fail\n"); - } - else { - printf("\nSMTP OK\n"); - } -} - -void ResetCheckIfDelivering() { - for (int i = 0; i < MAX_POST_EVENTS; i++) - { - postEventList[i].check_if_delivering = 0; - } -//#ifdef GY_OS_AMBA - //for (int i = 0; i < MAX_SNMP_MANAGEMENT; i++) - //{ - //SNMPManagementList[i].check_if_delivering = 0; - //} -//#endif -} - -#ifdef GY_OS_V_SERIES - -#else -//struct timeval last_t_CheckEventCounterCondition[MAX_DETECTION_ZONE], now_t_CheckEventCounterCondition; -//static long s_last_t_CheckEventCounterCondition[MAX_DETECTION_ZONE] = { 0 }; -//static long s_now_t_CheckEventCounterCondition = 0; -int g_record_counter_count[MAX_EVENT_COUNTERS] = { 0 }; -long g_record_counter_time[MAX_EVENT_COUNTERS] = { 0 }; - -#endif - -struct timeval currtime_CheckEventCounterCondition[MAX_EVENT_COUNTERS]; -static long last_ms_CheckEventCounterCondition[MAX_EVENT_COUNTERS] = { 0 }; - -void CheckEventCounterCondition(detection_pos* pNext, int tracking_channel_idx, int detection_zone_idx, int trigger_idx, int enable_counter_post, char* image_buff, int image_buff_size, char* image_buff_base64, int image_buff_size_base64, char cropped_image_base64[][MAX_IMG_SIZE], int* cropped_image_size_base64) -{ -#ifdef GY_OS_V_SERIES - -#else - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || -#ifdef GY_OS_NOVA - IsANPRCategory(featureType) || -#endif - g_IsCustomWeight == 1 || unlockingKeyInnoFR_success == 1 ) { - char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; - char Temp[MAX_MSG_LEN * 10] = { 0 }; - strcpy(Temp, viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_name); - int event_counter_num = StrSplit(Temp, eachEventCounter, ","); - //printf("\n------UU:11\n"); - - //gettimeofday(&now_t_CheckEventCounterCondition, NULL); - //s_now_t_CheckEventCounterCondition = now_t_CheckEventCounterCondition.tv_sec; //單位為秒 - - float dwell_time_event_counter = (float)viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time; - - if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute >= 1) { - dwell_time_event_counter = (float)(viewDetectionZone[tracking_channel_idx][detection_zone_idx].no_parking_time_in_minute * 60); - } - - - - unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].detect_event_id); - - /////////////////////////// - - char ObjectName[30] = { 0 }; - - if (pNext != NULL) { - sprintf(ObjectName, "%s", pNext->name); - UpperToLower(ObjectName); - } - - - //char metadata1[512][STRSPLIT_SIZE] = {0}; //for vehicle - //char MetaData1[BUFSIZE] = { 0 }; - //char MetaOut1[512][50] = { 0 }; - //strcpy(MetaData1, viewDetectionZone[tracking_channel_idx][detection_zone_idx].metadata1); - - //int metadata1_num = get_metadata1_num(detection_zone_idx); - - - //for (int i = 0; i < metadata1_num; i++) - //{ - //UpperToLower(metadata1[i]); - //TrimSpace(MetaOut1[i], sizeof(MetaOut1[i]), metadata1[i], 0); - //} - - //////////////////////// - - for (int i = 0; i < event_counter_num; i++) - { - for (int j = 0; j < MAX_EVENT_COUNTERS; j++) - { - if (strcmp(eachEventCounter[i], eventCounterList[j].counter_name) == 0) - { - gettimeofday(&currtime_CheckEventCounterCondition[j], NULL); - long current_ms_CheckEventCounterCondition = (currtime_CheckEventCounterCondition[j].tv_sec * 1000) + (currtime_CheckEventCounterCondition[j].tv_usec / 1000); - - if (strcmp(eventCounterList[j].enable_linked_to_dwell_time, "Yes") != 0 || (strcmp(eventCounterList[j].enable_linked_to_dwell_time, "Yes") == 0 && - (last_ms_CheckEventCounterCondition[j] == 0 || (current_ms_CheckEventCounterCondition - last_ms_CheckEventCounterCondition[j]) > dwell_time_event_counter * 1000))) - { - last_ms_CheckEventCounterCondition[j] = current_ms_CheckEventCounterCondition; - //eventCounterList[j].metadata1_num = metadata1_num; - - //for (int m = 0; m < metadata1_num; m++) { - //strcpy(eventCounterList[j].MetaOut1[m], get_meta_class(m, detection_zone_idx)); - //} - - if (pNext == NULL) { - if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 1) { - eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; - if (eventCounterList[j].counter_count > 2000000000) { - eventCounterList[j].counter_count = 2000000000; - } - } - else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == -1) { - //printf("\neventCounterList[j].counter_count: %d\n", eventCounterList[j].counter_count); - eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; - if (eventCounterList[j].counter_count < 0) { - eventCounterList[j].counter_count = 0;//eventCounterList[j].reset_value - } - } - else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 0) { - //eventCounterList[j].counter_count = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; - - if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num > g_record_counter_count[j]) { - g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; - g_record_counter_time[j] = g_osdSysTimeStamp; - } - else { - if (difftime(g_osdSysTimeStamp, g_record_counter_time[j]) >= dwell_time_event_counter) { - - eventCounterList[j].counter_count = g_record_counter_count[j]; - - g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; - g_record_counter_time[j] = g_osdSysTimeStamp; - } - } - } - } - else if ((strcmp(eventCounterList[j].enable_time_range, "Yes") != 0 && - (((!((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT))) ) || - (pNext != NULL && !(IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT))) || - (pNext != NULL && (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && ((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT)) )) - ) || - (pNext != NULL && strcmp(eventCounterList[j].enable_time_range, "Yes") == 0 && pNext->det_time >= eventCounterList[j].timetTimeRangeFrom && pNext->det_time < eventCounterList[j].timetTimeRangeTo)) - { - - //printf("\n----------eventCounterList[j].counter_count:%d\n", eventCounterList[j].counter_count); - //printf("\n----------viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num:%d\n", viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num); - - if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 1) { - eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; - if (eventCounterList[j].counter_count > 2000000000) { - eventCounterList[j].counter_count = 2000000000; - } - } - else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == -1) { - //printf("\neventCounterList[j].counter_count: %d\n", eventCounterList[j].counter_count); - eventCounterList[j].counter_count += viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment; - if (eventCounterList[j].counter_count < 0) { - eventCounterList[j].counter_count = 0;//eventCounterList[j].reset_value - } - } - else if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment == 0) { - - if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num > g_record_counter_count[j]) { - g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; - g_record_counter_time[j] = g_osdSysTimeStamp; - } - else { - if (difftime(g_osdSysTimeStamp, g_record_counter_time[j]) >= dwell_time_event_counter) { - - eventCounterList[j].counter_count = g_record_counter_count[j]; - - g_record_counter_count[j] = viewDetectionZone[tracking_channel_idx][detection_zone_idx].prev_queuing_num; - g_record_counter_time[j] = g_osdSysTimeStamp; - } - } - } - - //printf("\neventCounterList[%d].counter_count:%d\n",j, eventCounterList[j].counter_count); - } - } - - if (enable_counter_post == 1) { - if (viewDetectionZone[tracking_channel_idx][detection_zone_idx].trigger_event[trigger_idx].counter_increment != -2) - CheckPostEventCondition(pNext, tracking_channel_idx, detection_zone_idx, trigger_idx, 0, "", j, image_buff, image_buff_size, image_buff_base64, image_buff_size_base64, cropped_image_base64, cropped_image_size_base64); - } - - - break; - } - } - - } - - //printf("\n-------------------\n"); - } -#endif -} - -void Record_Point_Touch_and_IsInsideZone(detection_pos* pNext, int tracking_channel_idx, int tracking_obj_idx, int det_count_idx, CPoint* zone_polygon,int side_number,int zone_index,int iSource_ori_w, int iSource_ori_h) { - - CPoint p_person[MAX_SENSOR_TYPE0]; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[zone_index][det_count_idx] = 0; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[zone_index][det_count_idx] = 0; - int count_four_points_touch = 0; - int count_touch = 0; - - for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { - - if (g_sensors_type == 0) { - p_person[index_p].x = (int)((pNext->center_x - pNext->width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / iSource_ori_w); - p_person[index_p].y = (int)((pNext->center_y - pNext->height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / iSource_ori_h); - } - else { - p_person[index_p].x = (int)((pNext->center_x - pNext->width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / iSource_ori_w); - p_person[index_p].y = (int)((pNext->center_y - pNext->height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / iSource_ori_h); - } - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch[zone_index][det_count_idx][index_p] = isInside(zone_polygon, side_number, p_person[index_p]); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch[zone_index][det_count_idx][index_p] == 1) { - count_touch++; - } - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[zone_index][det_count_idx][index_p] = isInside(zone_polygon, 4, p_person[index_p]); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[zone_index][det_count_idx][index_p] == 1) { - count_four_points_touch++; - } - } - - //printf("\n----------count_four_points_touch:%d\n", count_four_points_touch); - //printf("\n----------count_touch:%d\n", count_touch); - - int threahold_div = g_sensors_type == 0 ? 1 : 7; - - if (count_four_points_touch >= 45/threahold_div) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[zone_index][det_count_idx] = 1; - } - - if (count_touch >= 1) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[zone_index][det_count_idx] = 1; - pNext->IsInsideZone[zone_index] = 1; - } - -} - -struct timeval last_t_UpdateZoneStatus, now_t_UpdateZoneStatus; -static long s_last_t_UpdateZoneStatus[MAX_DETECTION_ZONE] = {0}; -static long s_now_t_UpdateZoneStatus = 0; -void MissingObjectDetection_VanishInZone(int tracking_channel_idx) { - - for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) { - if (s_last_t_UpdateZoneStatus[j] == 0) { - gettimeofday(&last_t_UpdateZoneStatus, NULL); - s_last_t_UpdateZoneStatus[j] = last_t_UpdateZoneStatus.tv_sec; - } - } - - gettimeofday(&now_t_UpdateZoneStatus, NULL); - s_now_t_UpdateZoneStatus = now_t_UpdateZoneStatus.tv_sec; //單位為秒 - - int check_if_missing = 0; - - for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) - { - for (int k = 0; k < MAX_TRIGGER_EVENT; k++) - { - if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].checked >= 1) { - unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[k].detect_event_id); - if (trigger_event_type == TRIGGER_MISSING_OBJECT_DETECTION) { - - float dwell_time_missing_object_detection = viewDetectionZone[tracking_channel_idx][j].no_parking_time; - - if ((s_now_t_UpdateZoneStatus - s_last_t_UpdateZoneStatus[j]) > dwell_time_missing_object_detection) { - s_last_t_UpdateZoneStatus[j] = s_now_t_UpdateZoneStatus; - - for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { - if (viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) - break; - else { - int check_if_ever_existing = 0; - for (int index_obj_tracking_id_in_zone_temp = 0; index_obj_tracking_id_in_zone_temp < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone_temp++) { - if (viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) - break; - else if (viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]) { - check_if_ever_existing = 1; - break; - } - } - - if (check_if_ever_existing == 1) { - - for (int index_obj_tracking_id_in_zone_temp = 0; index_obj_tracking_id_in_zone_temp < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone_temp++) { - if (viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp]) - break; - else if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp] == 0 || - index_obj_tracking_id_in_zone_temp == MAX_OBJ_TRACKING_ID_IN_ZONE - 1) { - check_if_missing = 1; - break; - } - } - if (check_if_missing == 1) { - printf("\n-------------TRIGGER_MISSING_OBJECT_DETECTION check_if_missing: Yes------------\n"); - break; - } - } - } - } - - //TRIGGER_MISSING_OBJECT_DETECTION -#if 0 - printf("\n----------TRIGGER_MISSING_OBJECT_DETECTION\n"); - for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { - printf("%d,", viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]); - - } - printf("\n-----------------------------------------\n"); - - printf("\n----------TRIGGER_MISSING_OBJECT_DETECTION_last\n"); - for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { - printf("%d,", viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]); - - } - printf("\n-----------------------------------------\n"); - - printf("\n----------TRIGGER_MISSING_OBJECT_DETECTION_last_two\n"); - for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { - printf("%d,", viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]); - - } - printf("\n-----------------------------------------\n"); -#endif - - int k = 0; - for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { - for (int index_obj_tracking_id_in_zone_temp = 0; index_obj_tracking_id_in_zone_temp < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone_temp++) { - if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) - break; - else if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]!= 0 && viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp]) { - viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[k] = viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]; - k++; - } - } - } - for (int index_obj_tracking_id_in_zone = k; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) - viewDetectionZone[tracking_channel_idx][j].last_two_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = 0; - - for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { - viewDetectionZone[tracking_channel_idx][j].last_obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone]; - viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = 0; - } - - if (check_if_missing == 1) { - viewDetectionZone[tracking_channel_idx][j].check_if_missing = check_if_missing; - } - else { - viewDetectionZone[tracking_channel_idx][j].check_if_missing = check_if_missing; - } - } - } - } - } - } -} - - -void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracking_obj_idx, int det_count_idx, float fInSourceOri_w, float fInSourceOri_h, int total_element_size, detection_pos* PosInfo, int result_idx) -{ - - int side_number; - CPoint zone_polygon[6] = { 0 }; - //CPoint temp_zone_polygon[6] = { 0 }; - int b_ZoneExist = 0; - - detection_pos* pNext2 = NULL; - int BindNewLicensePlateOk = 0; - - /*//MAX_OBJ_DWELL_TIME - if (pNext->obj_dwell_time >= 20) { - pNext->obj_dwell_time = 21474830; - }*/ - - //for name comparison without case sensitive - char ObjectName[30] = { 0 }; - sprintf(ObjectName, "%s", pNext->name); - UpperToLower(ObjectName); - - //char MetaData1[BUFSIZE] = { 0 }; - //char MetaOut1[512][50] = { 0 }; - - if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) - { - if (pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && - pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { - strcpy(pNext->linked_plate, pNext->properties.plate); - pNext->linked_plate_length = pNext->properties.plate_length; - } - if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && - pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) { - strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext->linked_plate); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext->linked_plate_length; - } - - - if (viewChannelData[0].enable_traffic) { - for (int m = 0; m < total_element_size; m++) - { - pNext2 = PosInfo + m; - if (IsVehicleCategory(pNext2) || IsMotorbikeCategory(pNext2)) { - - if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext2->name, "exhaust_ok") == 0 || strcmp(pNext2->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext->center_x <= pNext2->left_x + pNext2->width && pNext->center_x >= pNext2->left_x) && - (pNext->center_y <= pNext2->top_y + pNext2->height && pNext->center_y >= pNext2->top_y)) - ) - { - strcpy(pNext->car_type_name, pNext2->name); - strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].car_type_name, pNext->car_type_name); - - break; - } - } - } - } - } - else { -#if 1 - //BindLicensePlateToVehicle - if (IsANPRCategory(featureType)) { - if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) - { - //test levenshtein_distance - //int dst = levenshtein_distance("Saturday", "Sunday"); //dst = 3 - //printf("dst = %d\n", dst); - - //pUpdateZoneNext = PosInfo + result_idx; - for (int k = 0/*result_idx + 1*/; k < total_element_size; k++) - { - pNext2 = PosInfo + k; - if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) - { -#ifdef _DEBUG_ZONE - printf("[%d]pNext2->engine_type == _PLATE \n", k); -#endif - - if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext2->name, "exhaust_ok") == 0 || strcmp(pNext2->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext2->center_x <= pNext->left_x + pNext->width && pNext2->center_x >= pNext->left_x) && - (pNext2->center_y <= pNext->top_y + pNext->height && pNext2->center_y >= pNext->top_y)) - ) - { -#ifdef _DEBUG_ZONE - printf("[%d]detection_overlap_ratio > 0.95 \n", k); -#endif - pNext2->car_logo_idx = result_idx; - strcpy(pNext2->car_type_name, pNext->name); - if (pNext2->obj_tracking_id_idx >= 0) { - strcpy(g_TrackingRecords[tracking_channel_idx][pNext2->obj_tracking_id_idx].car_type_name, pNext2->car_type_name); - } - //Steven MARK 20200930 - //printf("track_obj_id[%d]Plate = %s \n", tracking_obj_idx, pNext2->properties.plate); - - if (strlen(pNext2->properties.plate) > strlen(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate)) - { - //if (levenshtein_distance(pNext2->properties.plate, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate) <= 3) - //{ - - if (pNext2->properties.plate_length >= atoi(viewChannelData[0].min_characters) && - pNext2->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { - strcpy(pNext->linked_plate, pNext2->properties.plate); - pNext->linked_plate_length = pNext2->properties.plate_length; -#ifdef _DEBUG_ZONE - printf("=[%d] 11 set- [0x%x] pNext->link_plate = %s, name = %s, type = %d \n", j, pNext, pNext->linked_plate, pNext->name, pNext->obj_type); -#endif - strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext2->properties.plate); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext2->properties.plate_length; - //printf("track_obj_id[%d]linkPlate = %s \n", tracking_obj_idx, pUpdateZoneNext->linked_plate); - BindNewLicensePlateOk = 1; - } - //} - } - break; - } - - } - } - - if (!BindNewLicensePlateOk) - { - if (strlen(pNext->linked_plate) == 0) { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length >= atoi(viewChannelData[0].min_characters) && - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length <= atoi(viewChannelData[0].max_characters)) { - strcpy(pNext->linked_plate, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate); - pNext->linked_plate_length = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length; - } - } - else { - if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && - pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) { - strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext->linked_plate); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext->linked_plate_length; - } - } -#ifdef _DEBUG_ZONE - printf("=[%d] 22 set [0x%x] pUpdateZoneNext->link_plate = %s \n", j, pNext, pNext->linked_plate); -#endif - } - } - } -#endif //Steven TEMP MARK 20201012 - } - - - for (int j = 0; j < viewChannelData[tracking_channel_idx].count_zone; j++) - { - side_number = viewDetectionZone[tracking_channel_idx][j].point_num; - side_number = 6; - - int check_existing_in_metaout = 0; - check_existing_in_metaout = check_if_existing_in_metaout(ObjectName, j); - //int metadata1_num = get_metadata1_num(j); - - if (check_existing_in_metaout == 0 && strcmp(ObjectName, "object") != 0 && strcmp(ObjectName, "tampering") != 0 && strcmp(ObjectName, "tof_point") != 0 && strcmp(ObjectName, "face") != 0 && IsANPRCategory_L_Plate(pNext->name) == 0) - { - continue; - } - - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || /*|| (featureType & FEATURE_LPR_TWN) != 0*/ - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) - ) { - if (check_existing_in_metaout == 1 || (check_existing_in_metaout == 0 && strcmp(pNext->name, "blank") == 0)) { - if (viewDetectionZone[tracking_channel_idx][j].parking_space >= 1 && viewDetectionZone[tracking_channel_idx][j].parking_line >= 1) { - for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { - unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[k].detect_event_id); - if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) { - if (viewDetectionZone[tracking_channel_idx][j].trigger_event[k].checked >= 1) { - viewDetectionZone[tracking_channel_idx][j].queuing_trigger_event_idx = k; - int index_plot = -1; - float min_parking_distance = 10000; - for (int index_parking = 0; index_parking < viewDetectionZone[tracking_channel_idx][j].parking_space; index_parking++) { - /* - detection_pos pNext_plot; - pNext_plot.left_x = g_parking_space_recording_x[j][index_parking] - pNext->width * 0.25; - pNext_plot.top_y = g_parking_space_recording_y[j][index_parking] - pNext->height * 0.25; - pNext_plot.width = pNext->width * 0.5; - pNext_plot.height = pNext->height * 0.5;*/ - - if (g_parking_space_recording_x[j][index_parking] != 0 && g_parking_space_recording_y[j][index_parking] != 0) { - - if (g_parking_space_recording_x[j][index_parking] >= pNext->left_x - pNext->width * 0.25 && g_parking_space_recording_x[j][index_parking] <= (pNext->left_x + pNext->width*1.25) && - g_parking_space_recording_y[j][index_parking] >= pNext->top_y - pNext->height * 0.25 && g_parking_space_recording_y[j][index_parking] <= (pNext->top_y + pNext->height*1.25) && - g_temp_parking_space_check_table[j][index_parking] == 0 /*&& detection_overlap_ratio_union(pNext,&pNext_plot) >= 0.9*/) - { - if (index_plot == -1) { - index_plot = index_parking; - min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); - } - else { - float temp_min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); - if (temp_min_parking_distance < min_parking_distance) { - index_plot = index_parking; - min_parking_distance = temp_min_parking_distance; - } - } - } - else if (strcmp(pNext->name, "blank") == 0) { - if (index_plot == -1) { - index_plot = index_parking; - min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); - } - else { - float temp_min_parking_distance = sqrt(pow((pNext->left_x + pNext->width / 2.0) - g_parking_space_recording_x[j][index_parking], 2.0) + pow((pNext->top_y + pNext->height / 2.0) - g_parking_space_recording_y[j][index_parking], 2.0)); - if (temp_min_parking_distance < min_parking_distance) { - index_plot = index_parking; - min_parking_distance = temp_min_parking_distance; - } - } - } - } - } - - if (index_plot >= 0) { - g_temp_parking_space_check_table[j][index_plot] = 1; - pNext->zone_violation_idx[j] = 1; - } - } - } - } - } - } - } - - if (strlen(viewChannelData[tracking_channel_idx].red_light_zone) >= 1 && strcmp(viewChannelData[tracking_channel_idx].red_light_zone, "NULL") != 0) { - if (j == atoi(viewChannelData[tracking_channel_idx].red_light_zone)) { - continue; - } - } - - b_ZoneExist = 0; - //zone_polygon 在client端寫入設定檔時已轉為 889*500 - - for (int k = 0; k < 6; k++) - { - if (viewDetectionZone[tracking_channel_idx][j].Points[k].x > 0 || viewDetectionZone[tracking_channel_idx][j].Points[k].y > 0) - b_ZoneExist = 1; - - zone_polygon[k].x = (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio); - zone_polygon[k].y = (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio); - - //temp_zone_polygon[k].x = zone_polygon[k].x; - //temp_zone_polygon[k].y = zone_polygon[k].y; - } - - if (!b_ZoneExist || j == viewChannelData[tracking_channel_idx].enable_traffic_light_zone - 1) - continue; - - if (g_IsRadarDevice != 1) // 2022-10-20 Ken - { - if (strcmp(ObjectName, "tampering") != 0 && strcmp(ObjectName, "tof_point") != 0) { - if ((((pNext->width * pNext->height) / ((float)fInSourceOri_w * (float)fInSourceOri_h)) > ((float)atoi(viewDetectionZone[tracking_channel_idx][j].obj_max_proportion_in_zone) / 100.0)) || - (((pNext->width * pNext->height) / ((float)fInSourceOri_w *(float)fInSourceOri_h)) < ((float)atoi(viewDetectionZone[tracking_channel_idx][j].obj_min_proportion_in_zone) / 100.0)) - ) { - continue; - } - } - } - - int check_if_go_straight_existing = 0; - int check_if_speed_existing = 0; - float ratio_area_zone_polygon = 0.0; - int index_of_trigger_event_to_checked = -1; - unsigned int trigger_event_type = 0; -#ifdef GY_OS_AMBA - //int check_if_forget_to_give_way = -1; -#endif - for (int m = 0; m < MAX_TRIGGER_EVENT; m++) - { - if (viewDetectionZone[tracking_channel_idx][j].trigger_event[m].checked >= 1) { - trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[m].detect_event_id); - - if ((trigger_event_type == TRIGGER_GO_STRAIGHT) || (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) || (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT)) { - check_if_go_straight_existing = 1; - } - else { - if (!(IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE)) { - ratio_area_zone_polygon = polygon_area(zone_polygon, 6) / (float)(CANVAS_WIDTH * CANVAS_HEIGHT); - - - if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) { -#ifdef GY_OS_AMBA - //check_if_forget_to_give_way = 1; -#endif - } - else if (trigger_event_type == TRIGGER_SPEED_HIGH || - trigger_event_type == TRIGGER_SPEED_LOW) { - check_if_speed_existing = 1; - } - } - else if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) { - if (trigger_event_type == TRIGGER_SPEED_HIGH || - trigger_event_type == TRIGGER_SPEED_LOW) { - check_if_speed_existing = 1; - } - } - - } - - index_of_trigger_event_to_checked = m; - break; - } - } - - if (g_IsPTZDevice == 0 && trigger_event_type == 0) - continue; - - if (check_if_go_straight_existing == 0 && check_if_speed_existing == 1 && strncmp(viewDetectionZone[tracking_channel_idx][j].enable_speed, "No", strlen("No")) == 0) { - continue; - } - -#if 0 - if (AI_fps >= 1 && bHttpServerThreadStart) - { - - int iIsDoDestoryDetected = 0; - for (int m = 0; m < MAX_TRIGGER_EVENT; m++) - { - if (viewDetectionZone[tracking_channel_idx][j].trigger_event[m].checked >= 1) { - unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][j].trigger_event[m].detect_event_id); - - if ((trigger_event_type == TRIGGER_MISSING_UNATTENDED) || - (trigger_event_type == TRIGGER_TAMPERING)) //TRIGGER_ALL_OBJECTS - { - iIsDoDestoryDetected = 1; - } - } - } - - ///不能在這擋, 否則其他trigger也會受影響 - //iIsDoDestoryDetected: 判斷是否開啟破壞偵測(在PTZ上, 只能在PRESET點才能使用此功能) - //if (iIsDoDestoryDetected == 0) - //{ - //是否有設定ZoneToPreset, 有: 參考Preset, 沒有: 不看預設點, 任意位置皆可觸發. - //int iZoneMapPresetIdx = 0; - //iZoneMapPresetIdx = atoi(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset); - - // if (IsPTZEnableAlarm(iZoneMapPresetIdx) == 0 - //&& IsTracking() != 1 - // ) - // continue; - //} - //else if (iIsDoDestoryDetected == 1) - //{ - // if (IsPTZinPreset() == 0) - // { - // continue; - // } - //} - } -#endif - //Check zone_to_preset and is_ptz_device - - int iIfDoZone = 1; -#ifdef GY_OS_AMBA -#if 0 - { - int iZoneMapPresetIdx = 0; - int iIsSetZoneToPreset = 0; - - if (g_IsPTZDevice == 1 && check_if_forget_to_give_way != 1) - { - if (!(IsPTZinAutoTracking() == 0 && IsPTZinAutoPan() == 1)) { - - if (viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset != NULL - && strlen(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset) != 0) - { - iZoneMapPresetIdx = atoi(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset); - if (iZoneMapPresetIdx != 0) - { - iIsSetZoneToPreset = 1; - } - else - { - iIsSetZoneToPreset = 0; - } - } - else - { - iIsSetZoneToPreset = 0; - } - - //if (IsPTZinAutoTracking() == 1) - //{ - if (iIsSetZoneToPreset == 1) - { - //iZoneMapPresetIdx = atoi(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset); - iZoneMapPresetIdx = IsPTZinPreset(); //1. 不綁定zone link preset, 只要在preset點上都會進行追蹤判斷 - if (IsPTZEnableAlarm(iZoneMapPresetIdx) == 0) - { - iIfDoZone = 0; - } - } - - //} - } - } //IsPTZ() == 1 - } -#endif -#endif - - - - int do_event_trigger = 1; -#ifdef GY_OS_AMBA -#if 0 - { - int iZoneMapPresetIdx = 0; - int iIsSetZoneToPreset = 0; - - if (g_IsPTZDevice == 1 && check_if_forget_to_give_way != 1) - { - if (IsPTZinAutoTracking() == 0 && IsPTZinAutoPan() == 0) { - do_event_trigger = 0; - - if (viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset != NULL - && strlen(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset) != 0) - { - iZoneMapPresetIdx = atoi(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset); - if (iZoneMapPresetIdx != 0) - { - iIsSetZoneToPreset = 1; - } - else - { - iIsSetZoneToPreset = 0; - } - } - else - { - iIsSetZoneToPreset = 0; - } - - //if (IsPTZinAutoTracking() == 1) - //{ - if (iIsSetZoneToPreset == 1) - { - iZoneMapPresetIdx = atoi(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset); - if (IsPTZEnableAlarm(iZoneMapPresetIdx) == 1) - { - do_event_trigger = 1; - } - } - - if (strcmp(ObjectName, "tampering") == 0) { - do_event_trigger = 1; - } - } - else if (IsPTZinAutoTracking() == 1 && IsPTZinAutoPan() == 1) - { - do_event_trigger = 0; - - if (viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset != NULL - && strlen(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset) != 0) - { - iZoneMapPresetIdx = atoi(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset); - if (iZoneMapPresetIdx != 0) - { - iIsSetZoneToPreset = 1; - } - else - { - iIsSetZoneToPreset = 0; - } - } - else - { - iIsSetZoneToPreset = 0; - } - - if (iIsSetZoneToPreset == 1) - { - iZoneMapPresetIdx = atoi(viewDetectionZone[tracking_channel_idx][j].ptz_zone_to_preset); - if (IsPTZEnableAlarm(iZoneMapPresetIdx) == 1) - { - do_event_trigger = 1; - } - } - } - //} - } //IsPTZ() == 1 - } -#endif -#endif - //int poly_num = sizeof(zone_polygon) / sizeof(zone_polygon[0]); - - if (iIfDoZone == 1 || g_check_if_set_no_preset_no_autopan == 1) - { - //printf("\n------------ratio_area_zone_polygon:%f\n", ratio_area_zone_polygon); - Record_Point_Touch_and_IsInsideZone(pNext, tracking_channel_idx, tracking_obj_idx, det_count_idx, zone_polygon, side_number, j, fInSourceOri_w, fInSourceOri_h); - } -#ifdef GY_OS_AMBA -#if 0 - if (g_IsPTZDevice == 1) - { - if (IsPTZinAutoTracking() == 1) - { - continue; - } - - } -#endif -#endif - if (g_check_if_metadata_stop_happened[j] == 1) { - continue; - } - - //printf("\n------------get_g_check_if_current_light_is_red:%d\n", get_g_check_if_current_light_is_red()); - - if(do_event_trigger == 1 || g_check_if_set_no_preset_no_autopan == 1){ - if (det_count_idx > 0 && index_of_trigger_event_to_checked >= 0) - { - //printf("\n---BBB------pNext->engine_type:%d\n", pNext->engine_type); - //printf("\n---BBB------pNext->obj_type:%d\n", pNext->obj_type); - if (IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) - { - //printf("\n--CCC-------pNext->engine_type:%d\n", pNext->engine_type); - //printf("\n--CCC-------pNext->obj_type:%d\n", pNext->obj_type); - - if (check_if_go_straight_existing == 1 && check_if_speed_existing == 0) { - - //printf("\n-----------------B2\n"); - - int current_count_touch = 0; - int last_count_touch = 0; - float threshold_for_count_touch = 0.77; - int threshold_for_last_count_touch = 55; - int threahold_div = g_sensors_type == 0 ? 1 : 7;//1 7 - - if (ratio_area_zone_polygon >= 0.75) { - threshold_for_count_touch = 0.67; - threshold_for_last_count_touch = 560 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.65 && ratio_area_zone_polygon < 0.75) { - threshold_for_count_touch = 0.67; - threshold_for_last_count_touch = 480 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.55 && ratio_area_zone_polygon < 0.65) { - threshold_for_count_touch = 0.68; - threshold_for_last_count_touch = 420 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.45 && ratio_area_zone_polygon < 0.55) { - threshold_for_count_touch = 0.68; - threshold_for_last_count_touch = 360 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.35 && ratio_area_zone_polygon < 0.45) { - threshold_for_count_touch = 0.69; - threshold_for_last_count_touch = 300 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.3 && ratio_area_zone_polygon < 0.35) { - threshold_for_count_touch = 0.69; - threshold_for_last_count_touch = 260 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.25 && ratio_area_zone_polygon < 0.3) { - threshold_for_count_touch = 0.7; - threshold_for_last_count_touch = 220 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.185 && ratio_area_zone_polygon < 0.25) { - threshold_for_count_touch = 0.7; - threshold_for_last_count_touch = 190 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.15 && ratio_area_zone_polygon < 0.185) { - threshold_for_count_touch = 0.71; - threshold_for_last_count_touch = 170 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.12 && ratio_area_zone_polygon < 0.15) { - threshold_for_count_touch = 0.71; - threshold_for_last_count_touch = 150 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.09 && ratio_area_zone_polygon < 0.12) { - threshold_for_count_touch = 0.73; - threshold_for_last_count_touch = 105 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.0625 && ratio_area_zone_polygon < 0.09) { - threshold_for_count_touch = 0.74; - threshold_for_last_count_touch = 85 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.0312 && ratio_area_zone_polygon < 0.0625) { - threshold_for_count_touch = 0.76; - threshold_for_last_count_touch = 65 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.0156 && ratio_area_zone_polygon < 0.0312) { - threshold_for_count_touch = 0.77; - threshold_for_last_count_touch = 55 / threahold_div; - } - else { - threshold_for_count_touch = 0.78; - threshold_for_last_count_touch = 45 / threahold_div; - } - - for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { - current_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][index_p]; - last_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][index_p]; - } - //printf("\n------------current_count_touch:%d\n", current_count_touch); - //printf("\n------------last_count_touch:%d\n", last_count_touch); - - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1) { - if (current_count_touch < (int)(((float)last_count_touch) * threshold_for_count_touch) && last_count_touch >= threshold_for_last_count_touch) { - - //printf("\ncurrent_count_touch: %d ; last_count_touch: %d\n", current_count_touch, last_count_touch); - - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; - - CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; - - for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { - if (g_sensors_type == 0) { - p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); - p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); - - q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); - q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); - } - else { - p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); - p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); - - q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); - q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); - } - } - - if(strcmp(pNext->name,"person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) - { - int m = 0; - int array_zone_count[4] = { 0 }; - for (int k = 0; k < 4; k++) { - array_zone_count[k] = 0; - } - for (int k = 0; k < 4; k++) - { - if (k == 4 - 1) - m = 0; - else - m = k + 1; - CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - - { - for (int kl = 0; kl < g_max_sensor_size; kl++) { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { - //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); - if (doIntersect(p1[kl], q1[kl], p2, q2)) - { - array_zone_count[k]++; - } - } - } - } - } - - for (int k = g_max_sensor_size; k >= 1; k--) { //zone 個數 * doIntersect次數 - for (int kl = 0; kl < 4; kl++) { //zone個數 - if (array_zone_count[kl] >= k) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; - break; - } - } - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { - break; - } - } - - #if 1 - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { - int m = 0; - - float object_mean_x = 0.0; - float object_mean_y = 0.0; - float object_count = 0.0; - - for (int k = 0; k < g_max_sensor_size; k++) { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { - object_count++; - object_mean_x += (float)q1[k].x; - object_mean_y += (float)q1[k].y; - } - } - - if (object_count >= 1.0) { - object_mean_x /= object_count; - object_mean_y /= object_count; - - float min_distance = 0; - float min_zone_line = 0; - for (int k = 0; k < 4; k++) - { - if (k == 4 - 1) - m = 0; - else - m = k + 1; - CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - - printf("\n[p==q | p!=q error]------------------\n"); - printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); - - float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; - float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - } - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; - } - } - #endif - } - - { - { - //printf("\n-------------GO STRAIGHT: start------------\n"); - int nNeedTrigger = 0; - if (trigger_event_type == TRIGGER_GO_STRAIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); - - if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; - - } - } - } - - } - } - else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) - { - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; - - CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; - - for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { - if (g_sensors_type == 0) { - p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); - p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); - - q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); - q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); - } - else { - p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); - p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); - - q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); - q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); - } - } - - - if (strcmp(pNext->name, "person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) { - if ((p1[4].x == q1[4].x && p1[4].y == q1[4].y) || - (p1[7].x == q1[7].x && p1[7].y == q1[7].y)) { - - int m = 0; - - float object_mean_x = 0.0; - float object_mean_y = 0.0; - float object_count = 0.0; - - for (int k = 0; k < g_max_sensor_size; k++) { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { - object_count++; - object_mean_x += (float)q1[k].x; - object_mean_y += (float)q1[k].y; - } - } - - if (object_count >= 1.0) { - object_mean_x /= object_count; - object_mean_y /= object_count; - - printf("\n[p=q error]------------------\n"); - printf("\n[%f,%f],zone:[%d,%d],[%d,%d],[%d,%d],[%d,%d],\n", object_mean_x, object_mean_y, - viewDetectionZone[tracking_channel_idx][j].Points[0].x, viewDetectionZone[tracking_channel_idx][j].Points[0].y, - viewDetectionZone[tracking_channel_idx][j].Points[1].x, viewDetectionZone[tracking_channel_idx][j].Points[1].y, - viewDetectionZone[tracking_channel_idx][j].Points[2].x, viewDetectionZone[tracking_channel_idx][j].Points[2].y, - viewDetectionZone[tracking_channel_idx][j].Points[3].x, viewDetectionZone[tracking_channel_idx][j].Points[3].y); - - float min_distance = 0; - float min_zone_line = 0; - for (int k = 0; k < 4; k++) - { - if (k == 4 - 1) - m = 0; - else - m = k + 1; - CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - //printf("\n-------------------[doIntersect]1: p1[%d,%d],q1[%d,%d],p2[%d,%d],q2[%d,%d]\n", p1.x, p1.y, q1.x, q1.y, p2.x, p2.y, q2.x, q2.y); - - float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; - float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; - float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; - float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; - float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; - float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; - float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; - float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - } - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; - } - } - else { - int m = 0; - int array_zone_count[4] = { 0 }; - for (int k = 0; k < 4; k++) { - array_zone_count[k] = 0; - } - for (int k = 0; k < 4; k++) - { - if (k == 4 - 1) - m = 0; - else - m = k + 1; - CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - - /*if (strcmp(pNext->name, "person") == 0) { - for (int kl = 0; kl < g_max_sensor_size; kl++) { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 2][kl] == 1) { - if (doIntersect(p1[kl], q1[kl], p2, q2)) - { - array_zone_count[k]++; - } - } - } - } - else*/ { - for (int kl = 0; kl < g_max_sensor_size; kl++) { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { - //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); - if (doIntersect(p1[kl], q1[kl], p2, q2)) - { - array_zone_count[k]++; - } - } - } - } - } - - for (int k = g_max_sensor_size; k >= 1; k--) { //zone 個數 * doIntersect次數 - for (int kl = 0; kl < 4; kl++) { //zone個數 - if (array_zone_count[kl] >= k) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; - break; - } - } - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { - break; - } - } - - -#if 1 - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { - int m = 0; - - float object_mean_x = 0.0; - float object_mean_y = 0.0; - float object_count = 0.0; - - for (int k = 0; k < g_max_sensor_size; k++) { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { - object_count++; - object_mean_x += (float)q1[k].x; - object_mean_y += (float)q1[k].y; - } - } - - if (object_count >= 1.0) { - object_mean_x /= object_count; - object_mean_y /= object_count; - - float min_distance = 0; - float min_zone_line = 0; - for (int k = 0; k < 4; k++) - { - if (k == 4 - 1) - m = 0; - else - m = k + 1; - CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - - printf("\n[p!=q error]------------------\n"); - printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); - - float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; - float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; - float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; - float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; - float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; - float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; - float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; - float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - } - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; - } - } -#endif - /* - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { - //printf("\n------------YYYYYYYYYYYYYYYYY\n"); - for (int kl = 0; kl < g_max_sensor_size; kl++) { - //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { - //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); - } - } - }*/ - } - } - //printf("\n-------------------[doIntersect]: end\n"); - //printf("\nFEATURE_HUM_DET---4\n"); - { - //printf("\n-------------GO STRAIGHT: start------------\n"); - int nNeedTrigger = 0; - if (trigger_event_type == TRIGGER_GO_STRAIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); - /* - else if (trigger_event_type == TRIGGER_TURN_LEFT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_RIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_WRONG_WAY) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_WRONG_WAY, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_LEFT_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_VIOLATION, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_RIGHT_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_VIOLATION, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_U_TURN_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_U_TURN_VIOLATION, total_element_size, PosInfo, result_idx); - */ - if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; - - } - } - - } - //會造成誤報,如果ID不對的話 - else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id > 0) - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) - continue; - - memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], 0x00, sizeof(detection_pos)); - memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], 0x00, sizeof(detection_pos)); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[j] = 0; - memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); - memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; - - } - } - } - else if (check_if_go_straight_existing == 0 && check_if_speed_existing == 1) { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1) { - //printf("\n------------obj_tracking_id:%d\n", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id); - //第一次進到zone 紀錄時間 - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = pNext->det_time; - - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time < pNext->det_time) { - //pNext->det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; - //} - //else { - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; - //} - - viewDetectionZone[0][j].det_time = pNext->det_time; - - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); - } - - //printf("\n----------------A:2\n"); - - memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); - memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; - - int nNeedTrigger = 0; - - if (trigger_event_type == TRIGGER_SPEED_HIGH) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_HIGH, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_SPEED_LOW) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_LOW, total_element_size, PosInfo, result_idx); - - if (nNeedTrigger == 1) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; - } - - } - else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0) { - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; - } - else { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; - } - } - else { - - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1) { - - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = pNext->det_time; - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time < pNext->det_time) { - //pNext->det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; - //} - //else { - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; - //} - viewDetectionZone[0][j].det_time = pNext->det_time; - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); - } - - int nNeedTrigger = 0; - //printf("\n-----------In_zone\n"); - if (trigger_event_type == TRIGGER_ALLOW_LIST) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALLOW_LIST, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_BLOCK_LIST) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_BLOCK_LIST, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_GUEST_LIST) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GUEST_LIST, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_PARKING_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_PARKING_VIOLATION, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_ZONE_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_ALL_OBJECTS) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALL_OBJECTS, total_element_size, PosInfo, result_idx); - - if (nNeedTrigger) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; - } - - } - else { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; - } - } - } - else { - - //TRIGGER_SPEED_HIGH和TRIGGER_SPEED_LOW後面有放。 - - if (check_if_go_straight_existing == 0 && check_if_speed_existing == 0) - { - #if 1 - { - if (trigger_event_type == TRIGGER_TAMPERING) { - if (strcmp(ObjectName, "tampering") == 0) - { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; - pNext->trigger_type = TRIGGER_TAMPERING | pNext->trigger_type; - //pNext->detection_zone_idx = j; - pNext->trigger_idx[j] = index_of_trigger_event_to_checked; - pNext->zone_violation_idx[j] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - } - } - } - - - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1 && - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx - 1] == 1) { - //printf("\n------------obj_tracking_id:%d\n", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id); - //第一次進到zone 紀錄時間 - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = pNext->det_time; - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time < pNext->det_time) { - //pNext->det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; - //} - //else { - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; - //} - viewDetectionZone[0][j].det_time = pNext->det_time; - - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); - } - - //printf("\n----------------A:2\n"); - - memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); - memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; - - - { - //TRIGGER_MISSING_OBJECT_DETECTION - float dwell_time_missing_object_detection = viewDetectionZone[tracking_channel_idx][j].no_parking_time; - if (check_if_existing_in_metaout(ObjectName, j)) - { - int check_obj_tracking_id_in_zone = 0; - for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { - if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id) { - check_obj_tracking_id_in_zone = 1; - break; - } - } - -#if 1 - if (check_obj_tracking_id_in_zone == 0) { - for (int index_obj_tracking_id_in_zone = 0; index_obj_tracking_id_in_zone < MAX_OBJ_TRACKING_ID_IN_ZONE; index_obj_tracking_id_in_zone++) { - if (viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] == 0) { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time < 1.0 || - (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time) > dwell_time_missing_object_detection) - viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone] = (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id; - break; - } - if (index_obj_tracking_id_in_zone == MAX_OBJ_TRACKING_ID_IN_ZONE - 1) { - for (int index_obj_tracking_id_in_zone_temp = MAX_OBJ_TRACKING_ID_IN_ZONE - 1; index_obj_tracking_id_in_zone_temp >= 1; index_obj_tracking_id_in_zone_temp--) { - viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp] = viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[index_obj_tracking_id_in_zone_temp - 1]; - } - viewDetectionZone[tracking_channel_idx][j].obj_tracking_id_in_zone[0] = (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id; - } - } - } -#endif - - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time < 1.0) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time = pNext->obj_dwell_time; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time; - - pNext->obj_first_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time; - pNext->obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time; - } - else { - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time = pNext->obj_dwell_time; - pNext->obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_last_dwell_time; - } - } - } - - - int nNeedTrigger = 0; - if (trigger_event_type == TRIGGER_ZONE_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_DISTANCE_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_DISTANCE_VIOLATION, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_HIGH_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_HIGH_VIOLATION, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_PARKING_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_PARKING_VIOLATION, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_MISSING_UNATTENDED) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_MISSING_UNATTENDED, total_element_size, PosInfo, result_idx); - //else if (trigger_event_type == TRIGGER_BG_LEARNING) - //nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_BG_LEARNING, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_ALL_OBJECTS) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALL_OBJECTS, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_LACK_OF_ANY_OBJECT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_LACK_OF_ANY_OBJECT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_FORGET_TO_GIVE_WAY, total_element_size, PosInfo, result_idx); - - if (nNeedTrigger == 1) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; - } - - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || - g_IsCustomWeight == 1) - { - { - int nNeedTrigger = 0; - if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_QUEUING_VIOLATION, total_element_size, PosInfo, result_idx); - - if (nNeedTrigger) - viewDetectionZone[tracking_channel_idx][j].queuing_trigger_event_idx = index_of_trigger_event_to_checked; - } - } - } - else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1 && - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx - 1] == 0) { - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; - - { - //CPoint zone_polygon_temp[MAX_DETECTION_ZONE][6]; - //for (int m = 0; m < viewChannelData[tracking_channel_idx].count_zone; m++) { - - /* - for (int k = 0; k < 6; k++) - { - zone_polygon_temp[j][k].x = (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio); - zone_polygon_temp[j][k].y = (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio); - } - */ - //if (polygon_area(zone_polygon_temp[j], 6) <= (float)(CANVAS_WIDTH * CANVAS_HEIGHT * THRESHOLD_POLYGON_AREA)) - { - int nNeedTrigger = 0; - if (trigger_event_type == TRIGGER_ZONE_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); - - if (nNeedTrigger == 1) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; - } - } - //} - - - } - } - else { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; - } - - /* - else { - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_first_dwell_time >= 1.0) - { - int nNeedTrigger = 0; - for (int k = 0; k < MAX_TRIGGER_EVENT; k++) - { - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, k, tracking_obj_idx, TRIGGER_MISSING_OBJECT_DETECTION, total_element_size, PosInfo, result_idx); - - if (nNeedTrigger) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; - } - } - } - } - }*/ - #endif - } - else if (check_if_go_straight_existing == 0 && check_if_speed_existing == 1){ - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1) { - //printf("\n------------obj_tracking_id:%d\n", (int)g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id); - //第一次進到zone 紀錄時間 - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] == -1) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = pNext->det_time; - //if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time < pNext->det_time) { - //pNext->det_time = g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time; - //} - //else { - //g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time = pNext->det_time; - //} - viewDetectionZone[0][j].det_time = pNext->det_time; - - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], pNext, sizeof(detection_pos)); - } - - //printf("\n----------------A:2\n"); - - memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); - memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; - - int nNeedTrigger = 0; - - if (trigger_event_type == TRIGGER_SPEED_HIGH) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_HIGH, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_SPEED_LOW) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_SPEED_LOW, total_element_size, PosInfo, result_idx); - - if (nNeedTrigger == 1) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; - } - - } - else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1 && - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0) { - - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; - } - else { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j] = -1; - } - } - else if (check_if_go_straight_existing == 1 && check_if_speed_existing == 0){ - - //printf("\n-----------------B2\n"); - - int current_count_touch = 0; - int last_count_touch = 0; - float threshold_for_count_touch = 0.77; - int threshold_for_last_count_touch = 55; - int threahold_div = g_sensors_type == 0 ? 1 : 7;//1 7 - - if (ratio_area_zone_polygon >= 0.75) { - threshold_for_count_touch = 0.67; - threshold_for_last_count_touch = 560 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.65 && ratio_area_zone_polygon < 0.75) { - threshold_for_count_touch = 0.67; - threshold_for_last_count_touch = 480 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.55 && ratio_area_zone_polygon < 0.65) { - threshold_for_count_touch = 0.68; - threshold_for_last_count_touch = 420 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.45 && ratio_area_zone_polygon < 0.55) { - threshold_for_count_touch = 0.68; - threshold_for_last_count_touch = 360 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.35 && ratio_area_zone_polygon < 0.45) { - threshold_for_count_touch = 0.69; - threshold_for_last_count_touch = 300 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.3 && ratio_area_zone_polygon < 0.35) { - threshold_for_count_touch = 0.69; - threshold_for_last_count_touch = 260 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.25 && ratio_area_zone_polygon < 0.3) { - threshold_for_count_touch = 0.7; - threshold_for_last_count_touch = 220 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.185 && ratio_area_zone_polygon < 0.25) { - threshold_for_count_touch = 0.7; - threshold_for_last_count_touch = 190 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.15 && ratio_area_zone_polygon < 0.185) { - threshold_for_count_touch = 0.71; - threshold_for_last_count_touch = 170 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.12 && ratio_area_zone_polygon < 0.15) { - threshold_for_count_touch = 0.71; - threshold_for_last_count_touch = 150 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.09 && ratio_area_zone_polygon < 0.12) { - threshold_for_count_touch = 0.73; - threshold_for_last_count_touch = 105 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.0625 && ratio_area_zone_polygon < 0.09) { - threshold_for_count_touch = 0.74; - threshold_for_last_count_touch = 85 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.0312 && ratio_area_zone_polygon < 0.0625) { - threshold_for_count_touch = 0.76; - threshold_for_last_count_touch = 65 / threahold_div; - } - else if (ratio_area_zone_polygon >= 0.0156 && ratio_area_zone_polygon < 0.0312) { - threshold_for_count_touch = 0.77; - threshold_for_last_count_touch = 55 / threahold_div; - } - else{ - threshold_for_count_touch = 0.78; - threshold_for_last_count_touch = 45 / threahold_div; - } - - for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { - current_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][index_p]; - last_count_touch += g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][index_p]; - } - //printf("\n------------current_count_touch:%d\n", current_count_touch); - //printf("\n------------last_count_touch:%d\n", last_count_touch); - - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 1) { - if (current_count_touch < (int)(((float)last_count_touch) * threshold_for_count_touch) && last_count_touch >= threshold_for_last_count_touch) { - - //printf("\ncurrent_count_touch: %d ; last_count_touch: %d\n", current_count_touch, last_count_touch); - - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx-1], sizeof(detection_pos)); - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; - - CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; - - for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { - if (g_sensors_type == 0) { - p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); - p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); - - q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); - q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); - } - else { - p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); - p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); - - q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); - q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); - } - } - - if (strcmp(pNext->name, "person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) - { - int m = 0; - int array_zone_count[4] = { 0 }; - for (int k = 0; k < 4; k++) { - array_zone_count[k] = 0; - } - for (int k = 0; k < 4; k++) - { - if (k == 4 - 1) - m = 0; - else - m = k + 1; - CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - - { - for (int kl = 0; kl < g_max_sensor_size; kl++) { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx-1][kl] == 1) { - //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); - if (doIntersect(p1[kl], q1[kl], p2, q2)) - { - array_zone_count[k]++; - } - } - } - } - } - - for (int k = g_max_sensor_size; k >= 1; k--) { //zone 個數 * doIntersect次數 - for (int kl = 0; kl < 4; kl++) { //zone個數 - if (array_zone_count[kl] >= k) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; - break; - } - } - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { - break; - } - } - - #if 1 - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { - int m = 0; - - float object_mean_x = 0.0; - float object_mean_y = 0.0; - float object_count = 0.0; - - for (int k = 0; k < g_max_sensor_size; k++) { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { - object_count++; - object_mean_x += (float)q1[k].x; - object_mean_y += (float)q1[k].y; - } - } - - if (object_count >= 1.0) { - object_mean_x /= object_count; - object_mean_y /= object_count; - - float min_distance = 0; - float min_zone_line = 0; - for (int k = 0; k < 4; k++) - { - if (k == 4 - 1) - m = 0; - else - m = k + 1; - CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - - printf("\n[p==q | p!=q error]------------------\n"); - printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); - - float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; - float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - } - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; - } - } - #endif - } - - { - { - //printf("\n-------------GO STRAIGHT: start------------\n"); - int nNeedTrigger = 0; - if (trigger_event_type == TRIGGER_GO_STRAIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); - - if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; - - } - } - } - - } - } - else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 1 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) - { - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], &g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1], sizeof(detection_pos)); - memcpy(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], pNext, sizeof(detection_pos)); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; - - CPoint p1[MAX_SENSOR_TYPE0], q1[MAX_SENSOR_TYPE0]; - - for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { - if (g_sensors_type == 0) { - p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); - p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); - - q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(25 - 1 * ((int)index_p % 51))) / 50) * CANVAS_WIDTH / fInSourceOri_w); - q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(55 - 1 * ((int)index_p / 51))) / 110) * CANVAS_HEIGHT / fInSourceOri_h); - } - else { - p1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); - p1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); - - q1[index_p].x = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_x - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].width * ((float)(5 - 1 * ((int)index_p % 11))) / 10) * CANVAS_WIDTH / fInSourceOri_w); - q1[index_p].y = (int)((g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].center_y - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1].height * ((float)(9 - 1 * ((int)index_p / 11))) / 18) * CANVAS_HEIGHT / fInSourceOri_h); - } - } - - if (strcmp(pNext->name, "person") != 0 || abs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 5) { - if ((p1[4].x == q1[4].x && p1[4].y == q1[4].y) || - (p1[7].x == q1[7].x && p1[7].y == q1[7].y)) { - - int m = 0; - - float object_mean_x = 0.0; - float object_mean_y = 0.0; - float object_count = 0.0; - - for (int k = 0; k < g_max_sensor_size; k++) { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { - object_count++; - object_mean_x += (float)q1[k].x; - object_mean_y += (float)q1[k].y; - } - } - - if (object_count >= 1.0) { - object_mean_x /= object_count; - object_mean_y /= object_count; - - printf("\n[p=q error]------------------\n"); - printf("\n[%f,%f],zone:[%d,%d],[%d,%d],[%d,%d],[%d,%d],\n", object_mean_x, object_mean_y, - viewDetectionZone[tracking_channel_idx][j].Points[0].x, viewDetectionZone[tracking_channel_idx][j].Points[0].y, - viewDetectionZone[tracking_channel_idx][j].Points[1].x, viewDetectionZone[tracking_channel_idx][j].Points[1].y, - viewDetectionZone[tracking_channel_idx][j].Points[2].x, viewDetectionZone[tracking_channel_idx][j].Points[2].y, - viewDetectionZone[tracking_channel_idx][j].Points[3].x, viewDetectionZone[tracking_channel_idx][j].Points[3].y); - - float min_distance = 0; - float min_zone_line = 0; - for (int k = 0; k < 4; k++) - { - if (k == 4 - 1) - m = 0; - else - m = k + 1; - CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - //printf("\n-------------------[doIntersect]1: p1[%d,%d],q1[%d,%d],p2[%d,%d],q2[%d,%d]\n", p1.x, p1.y, q1.x, q1.y, p2.x, p2.y, q2.x, q2.y); - - float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; - float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; - float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; - float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; - float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; - float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; - float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; - float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - } - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; - } - } - else { - int m = 0; - int array_zone_count[4] = { 0 }; - for (int k = 0; k < 4; k++) { - array_zone_count[k] = 0; - } - for (int k = 0; k < 4; k++) - { - if (k == 4 - 1) - m = 0; - else - m = k + 1; - CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - - /*if (strcmp(pNext->name, "person") == 0) { - for (int kl = 0; kl < g_max_sensor_size; kl++) { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 2][kl] == 1) { - if (doIntersect(p1[kl], q1[kl], p2, q2)) - { - array_zone_count[k]++; - } - } - } - } - else*/ { - for (int kl = 0; kl < g_max_sensor_size; kl++) { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { - //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); - if (doIntersect(p1[kl], q1[kl], p2, q2)) - { - array_zone_count[k]++; - } - } - } - } - } - - for (int k = g_max_sensor_size; k >= 1; k--) { //zone 個數 * doIntersect次數 - for (int kl = 0; kl < 4; kl++) { //zone個數 - if (array_zone_count[kl] >= k) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = kl + 1; - break; - } - } - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] != 0) { - break; - } - } - - -#if 1 - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { - int m = 0; - - float object_mean_x = 0.0; - float object_mean_y = 0.0; - float object_count = 0.0; - - for (int k = 0; k < g_max_sensor_size; k++) { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx][k] == 1) { - object_count++; - object_mean_x += (float)q1[k].x; - object_mean_y += (float)q1[k].y; - } - } - - if (object_count >= 1.0) { - object_mean_x /= object_count; - object_mean_y /= object_count; - - float min_distance = 0; - float min_zone_line = 0; - for (int k = 0; k < 4; k++) - { - if (k == 4 - 1) - m = 0; - else - m = k + 1; - CPoint p2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[k].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - CPoint q2 = { (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].x * viewChannelData[tracking_channel_idx].tab_view_width_ratio), (int)((float)viewDetectionZone[tracking_channel_idx][j].Points[m].y * viewChannelData[tracking_channel_idx].tab_view_height_ratio) }; - - printf("\n[p!=q error]------------------\n"); - printf("\n-------------------[doIntersect]1: object_mean_x: %f,object_mean_y: %f,p2[%d,%d],q2[%d,%d]\n", object_mean_x, object_mean_y, p2.x, p2.y, q2.x, q2.y); - - float zone_mean_x = ((float)p2.x + (float)q2.x) / 2.0; - float zone_mean_y = ((float)p2.y + (float)q2.y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x)*(object_mean_x - zone_mean_x) + (object_mean_y - zone_mean_y)*(object_mean_y - zone_mean_y)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x1 = ((float)p2.x + (float)zone_mean_x) / 2.0; - float zone_mean_y1 = ((float)p2.y + (float)zone_mean_y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x1)*(object_mean_x - zone_mean_x1) + (object_mean_y - zone_mean_y1)*(object_mean_y - zone_mean_y1)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x2 = ((float)zone_mean_x + (float)q2.x) / 2.0; - float zone_mean_y2 = ((float)zone_mean_y + (float)q2.y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x2)*(object_mean_x - zone_mean_x2) + (object_mean_y - zone_mean_y2)*(object_mean_y - zone_mean_y2)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x3 = ((float)p2.x + (float)zone_mean_x1) / 2.0; - float zone_mean_y3 = ((float)p2.y + (float)zone_mean_y1) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x3)*(object_mean_x - zone_mean_x3) + (object_mean_y - zone_mean_y3)*(object_mean_y - zone_mean_y3)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x4 = ((float)zone_mean_x1 + (float)zone_mean_x) / 2.0; - float zone_mean_y4 = ((float)zone_mean_y1 + (float)zone_mean_y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x4)*(object_mean_x - zone_mean_x4) + (object_mean_y - zone_mean_y4)*(object_mean_y - zone_mean_y4)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x5 = ((float)zone_mean_x + (float)zone_mean_x2) / 2.0; - float zone_mean_y5 = ((float)zone_mean_y + (float)zone_mean_y2) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x5)*(object_mean_x - zone_mean_x5) + (object_mean_y - zone_mean_y5)*(object_mean_y - zone_mean_y5)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - - float zone_mean_x6 = ((float)zone_mean_x2 + (float)q2.x) / 2.0; - float zone_mean_y6 = ((float)zone_mean_y2 + (float)q2.y) / 2.0; - - if (min_zone_line == 0) { - min_distance = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); - min_zone_line = k + 1; - } - else { - float distance_temp = sqrt((object_mean_x - zone_mean_x6)*(object_mean_x - zone_mean_x6) + (object_mean_y - zone_mean_y6)*(object_mean_y - zone_mean_y6)); - if (distance_temp < min_distance) { - min_zone_line = k + 1; - } - } - } - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = min_zone_line; - } - } -#endif - /* - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) { - //printf("\n------------YYYYYYYYYYYYYYYYY\n"); - for (int kl = 0; kl < g_max_sensor_size; kl++) { - //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].point_touch_four_points[j][det_count_idx - 1][kl] == 1) { - //printf("\np1[kl].x:%d,p1[kl].y:%d, q1[kl].x:%d,q1[kl].y:%d\n", p1[kl].x, p1[kl].y, q1[kl].x, q1[kl].y); - } - } - }*/ - } - } - //printf("\n-------------------[doIntersect]: end\n"); - //printf("\nFEATURE_HUM_DET---4\n"); - { - //printf("\n-------------GO STRAIGHT: start------------\n"); - int nNeedTrigger = 0; - if (trigger_event_type == TRIGGER_GO_STRAIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); - /* - else if (trigger_event_type == TRIGGER_TURN_LEFT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_RIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_WRONG_WAY) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_WRONG_WAY, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_LEFT_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_VIOLATION, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_RIGHT_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_VIOLATION, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_U_TURN_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_U_TURN_VIOLATION, total_element_size, PosInfo, result_idx); - */ - if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; - - } - } - - } - //會造成誤報,如果ID不對的話 - else if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx - 1] == 0 && g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone_four_points[j][det_count_idx] == 0) - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].obj_tracking_id > 0) - { - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] == 0) - continue; - - //printf("\nFEATURE_HUM_DET---5\n"); - { - #if 0 - { - int nNeedTrigger = 0; - if (trigger_event_type == TRIGGER_GO_STRAIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT, total_element_size, PosInfo, result_idx); - /* - else if (trigger_event_type == TRIGGER_TURN_LEFT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_RIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_WRONG_WAY) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_WRONG_WAY, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_LEFT_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_VIOLATION, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_RIGHT_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_VIOLATION, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_U_TURN_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_U_TURN_VIOLATION, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_GO_STRAIGHT_RED_LIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GO_STRAIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_LEFT_RED_LIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_LEFT_RED_LIGHT, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_TURN_RIGHT_RED_LIGHT) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_TURN_RIGHT_RED_LIGHT, total_element_size, PosInfo, result_idx); - */ - - if (nNeedTrigger == 1 /*|| g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_survive[j] >= 1*/) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; - - } - } - #endif - } - - memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][0], 0x00, sizeof(detection_pos)); - memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_detection_zone[j][1], 0x00, sizeof(detection_pos)); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].enter_zone_line[j] = 0; - memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][0], 0x00, sizeof(detection_pos)); - memset(&g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_detection_zone[j][1], 0x00, sizeof(detection_pos)); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].leave_zone_line[j] = 0; - - } - } - } - } - } - else if(det_count_idx == 0 && index_of_trigger_event_to_checked >= 0) - { - if (IsANPRCategory_L_Plate(pNext->name)==1 && IsANPRCategory(pNext->engine_type) && pNext->obj_type == _PLATE) - { - if (pNext->properties.plate_length >= atoi(viewChannelData[0].min_characters) && - pNext->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { - strcpy(pNext->linked_plate, pNext->properties.plate); - pNext->linked_plate_length = pNext->properties.plate_length; - } - if (pNext->linked_plate_length >= atoi(viewChannelData[0].min_characters) && - pNext->linked_plate_length <= atoi(viewChannelData[0].max_characters)) { - strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate, pNext->linked_plate); - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].linked_plate_length = pNext->linked_plate_length; - } - - if (viewChannelData[0].enable_traffic) { - for (int m = 0; m < total_element_size; m++) - { - pNext2 = PosInfo + m; - if (IsVehicleCategory(pNext2) || IsMotorbikeCategory(pNext2)) { - if (detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext->center_x <= pNext2->left_x + pNext2->width && pNext->center_x >= pNext2->left_x) && - (pNext->center_y <= pNext2->top_y + pNext2->height && pNext->center_y >= pNext2->top_y)) - ) - { - strcpy(pNext->car_type_name, pNext2->name); - strcpy(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].car_type_name, pNext->car_type_name); - - break; - } - } - } - } - - //printf("\n--CCC-------pNext->engine_type:%d\n", pNext->engine_type); - //printf("\n--CCC-------pNext->obj_type:%d\n", pNext->obj_type); - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1) { - int nNeedTrigger = 0; - //printf("\n-----------In_zone\n"); - if (trigger_event_type == TRIGGER_ALLOW_LIST) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ALLOW_LIST, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_BLOCK_LIST) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_BLOCK_LIST, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_GUEST_LIST) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_GUEST_LIST, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_PARKING_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_PARKING_VIOLATION, total_element_size, PosInfo, result_idx); - else if (trigger_event_type == TRIGGER_ZONE_VIOLATION) - nNeedTrigger = CheckTriggerCondition(pNext, tracking_channel_idx, j, index_of_trigger_event_to_checked, tracking_obj_idx, TRIGGER_ZONE_VIOLATION, total_element_size, PosInfo, result_idx); - - if (nNeedTrigger) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; - } - - } - } - else if (check_if_go_straight_existing == 0 && check_if_speed_existing == 0) { -#ifdef GY_OS_AMBA - if (trigger_event_type == TRIGGER_TAMPERING) { - if (strcmp(ObjectName, "tampering") == 0) - { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; - pNext->trigger_type = TRIGGER_TAMPERING | pNext->trigger_type; - //pNext->detection_zone_idx = j; - pNext->trigger_idx[j] = index_of_trigger_event_to_checked; - pNext->zone_violation_idx[j] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - } - } -#endif -#if 1 - if (g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].IsInsideZone[j][det_count_idx] == 1) { - //int diff_secs_in_zone = (int)difftime(pNext->det_time, g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].first_det_time_to_enter_zone[j]) % MAX_OBJ_DWELL_TIME; - //if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") != 0 || strcmp("person", pNext->name) == 0 || - //(diff_secs_in_zone >= 1 && diff_secs_in_zone > 0 && (int)(pNext->center_stability) != DIRECTION_DEFAULT)) - { - if (trigger_event_type == TRIGGER_ZONE_VIOLATION) - { - //for (int k = 0; k < metadata1_num; k++) - { - if (check_if_existing_in_metaout(ObjectName, j)) { - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_zone_id = j + 1; - pNext->trigger_type = TRIGGER_ZONE_VIOLATION | pNext->trigger_type; - //pNext->detection_zone_idx = j; - pNext->trigger_idx[j] = index_of_trigger_event_to_checked; - pNext->zone_violation_idx[j] = 1; - g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].trigger_type = pNext->trigger_type; - //break; - } - } - } - } - } -#endif - } - } - } - } - -} - - -void ApplyTrackingTableAndPrevDetection(detection_pos* PosInfo, int total_element_size,int tracking_channel_idx,int id_idx,int obj_idx) { - - //printf("\n--------%d,%d\n", (int)(PosInfo + obj_idx)->width, (int)(PosInfo + obj_idx)->height); - - if ((PosInfo + obj_idx)->width > 0 && (PosInfo + obj_idx)->height > 0) { - int det_count = 0; - int plate_len = 0, old_plate_len = 0; - det_count = g_TrackingRecords[tracking_channel_idx][id_idx].detection_count; - det_count++; - if (det_count > TRACKING_BUFFER_SIZE) - { - det_count = TRACKING_BUFFER_SIZE; - } - - if (det_count >= 2) {//第二次frame以上 - - if (IsANPRCategory((PosInfo + obj_idx)->engine_type) && strlen((PosInfo + obj_idx)->properties.plate) >= 1) { - - for (int j = 0; j < MAX_PLATE_RECORDER; j++) - { - if (g_PlateRecorderList[j].iIfUse == 1) - { - if (strlen(g_PlateRecorderList[j].sPlateNumber) > 0 - //&& strcmp((PosInfo + obj_idx)->properties.plate, g_PlateRecorderList[j].sPlateNumber) == 0) - && LevenshteinDistance((PosInfo + obj_idx)->properties.plate, g_PlateRecorderList[j].sPlateNumber, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) - { - float ratio_y = ((PosInfo + obj_idx)->center_y - g_PlateRecorderList[j].last_box_center_y) / (float)get_g_ori_yuv_height(); - float ratio_x = ((PosInfo + obj_idx)->center_x - g_PlateRecorderList[j].last_box_center_x) / (float)get_g_ori_yuv_width(); - float ratio_x_y = (float)sqrt(ratio_y * ratio_y + ratio_x * ratio_x); - - - - if (fabs(ratio_x_y) <= g_thres_bbox_stability_plate) - { - (PosInfo + obj_idx)->top_y = g_PlateRecorderList[j].last_box_y; - (PosInfo + obj_idx)->height = g_PlateRecorderList[j].last_box_h; - (PosInfo + obj_idx)->left_x = g_PlateRecorderList[j].last_box_x; - (PosInfo + obj_idx)->width = g_PlateRecorderList[j].last_box_w; - (PosInfo + obj_idx)->center_y = g_PlateRecorderList[j].last_box_center_y; - (PosInfo + obj_idx)->center_x = g_PlateRecorderList[j].last_box_center_x; - (PosInfo + obj_idx)->center_direction = (float)DIRECTION_DEFAULT; - (PosInfo + obj_idx)->center_stability = (float)DIRECTION_DEFAULT; - } - else - { - float delta_y = (PosInfo + obj_idx)->center_y - g_PlateRecorderList[j].last_box_center_y; - float delta_x = (PosInfo + obj_idx)->center_x - g_PlateRecorderList[j].last_box_center_x;; - (PosInfo + obj_idx)->center_direction = atan2(delta_y, delta_x) * 180.0 / PI; - (PosInfo + obj_idx)->center_stability = fabs(ratio_x_y); - } - - break; - } - } - } - - } - else { - - float ratio_y = ((PosInfo + obj_idx)->center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y) / (float)get_g_ori_yuv_height(); - float ratio_x = ((PosInfo + obj_idx)->center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x) / (float)get_g_ori_yuv_width(); - float ratio_x_y = (float)sqrt(ratio_y * ratio_y + ratio_x * ratio_x); - - if (fabs(ratio_x_y) <= g_thres_bbox_stability) - { - (PosInfo + obj_idx)->top_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].top_y; - (PosInfo + obj_idx)->height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height; - (PosInfo + obj_idx)->left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].left_x; - (PosInfo + obj_idx)->width = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width; - (PosInfo + obj_idx)->center_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y; - (PosInfo + obj_idx)->center_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x; - (PosInfo + obj_idx)->center_direction = (float)DIRECTION_DEFAULT; - (PosInfo + obj_idx)->center_stability = (float)DIRECTION_DEFAULT; - } - else - { - float delta_y = (PosInfo + obj_idx)->center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y; - float delta_x = (PosInfo + obj_idx)->center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x; - (PosInfo + obj_idx)->center_direction = atan2(delta_y, delta_x) * 180.0 / PI; - (PosInfo + obj_idx)->center_stability = fabs(ratio_x_y); - } - } - - (PosInfo + obj_idx)->check_person_inter = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_person_inter; - - - for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { - - (PosInfo + obj_idx)->num_bring_with_object[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[index_zone]; - for (int index_bring = 0; index_bring < g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[index_zone] && index_bring < MAX_NUM_BRING_WITH_OBJECT; index_bring++) { - strcpy((PosInfo + obj_idx)->bring_with_object[index_zone][index_bring], g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].bring_with_object[index_zone][index_bring]); - } - - (PosInfo + obj_idx)->check_if_having_been_counted[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].check_if_having_been_counted[index_zone]; - //(PosInfo + obj_idx)->s_last_t_Counter[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].s_last_t_Counter[index_zone]; - } - - g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count = 0; - - (PosInfo + obj_idx)->obj_tracking_id_idx = id_idx; - (PosInfo + obj_idx)->obj_tracking_id = g_TrackingRecords[tracking_channel_idx][id_idx].obj_tracking_id; - - (PosInfo + obj_idx)->obj_dwell_time = (int)difftime((PosInfo + obj_idx)->det_time, g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time) % MAX_OBJ_DWELL_TIME; - (PosInfo + obj_idx)->obj_first_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].obj_first_dwell_time; - (PosInfo + obj_idx)->obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].obj_last_dwell_time; - - //strcpy((PosInfo + obj_idx)->replaced_name, g_TrackingRecords[tracking_channel_idx][id_idx].replaced_name); - } - else if (det_count == 1) {//第一次frame初始化 - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x = g_initial_background_learning_rate_x; - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y = g_initial_background_learning_rate_y; - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x = g_initial_background_learning_rate_error_x; - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y = g_initial_background_learning_rate_error_y; - - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x = g_initial_background_mean_diff_x; - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y = g_initial_background_mean_diff_y; - g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_x = g_initial_background_error_diff_x; - g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_y = g_initial_background_error_diff_y; - - (PosInfo + obj_idx)->center_direction = (float)DIRECTION_DEFAULT; - (PosInfo + obj_idx)->center_stability = (float)DIRECTION_DEFAULT; - - (PosInfo + obj_idx)->check_person_inter = 0; - - for (int index_zone = 0; index_zone < viewChannelData[tracking_channel_idx].count_zone; index_zone++) { - (PosInfo + obj_idx)->num_bring_with_object[index_zone] = 0; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[index_zone] = 0; - (PosInfo + obj_idx)->check_if_having_been_counted[index_zone] = 0; - //(PosInfo + obj_idx)->s_last_t_Counter[index_zone] = 0; - g_TrackingRecords[tracking_channel_idx][id_idx].check_if_having_been_counted[index_zone] = 0; - //g_TrackingRecords[tracking_channel_idx][id_idx].s_last_t_Counter[index_zone] = 0; - } - - if (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].disappear_count != 0) - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].disappear_count = 0; - if (g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count != 0) - g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count = 0; - - - g_TrackingIDAndChannel[tracking_channel_idx]++; - if (td_weight_num >= 1 && check_if_correct_mail == 1) - { - if (g_TrackingIDAndChannel[tracking_channel_idx] > 19999 || g_TrackingIDAndChannel[tracking_channel_idx] < 10001) - g_TrackingIDAndChannel[tracking_channel_idx] = 10001; - } - else - { - if (g_TrackingIDAndChannel[tracking_channel_idx] > 9999) - g_TrackingIDAndChannel[tracking_channel_idx] = 1; - } - - (PosInfo + obj_idx)->obj_tracking_id_idx = id_idx; - (PosInfo + obj_idx)->obj_tracking_id = g_TrackingIDAndChannel[tracking_channel_idx]; - g_TrackingRecords[tracking_channel_idx][id_idx].obj_tracking_id = g_TrackingIDAndChannel[tracking_channel_idx]; - - g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time = (PosInfo + obj_idx)->det_time; - - //g_TrackingRecords[tracking_channel_idx][id_idx].frame_count = 0; - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].name, (PosInfo + obj_idx)->name); - //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].replaced_name, (PosInfo + obj_idx)->replaced_name); - for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) { - g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time_to_enter_zone[index_zone] = -1; - g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[index_zone] = -1; - (PosInfo + obj_idx)->obj_speed[index_zone] = -1; - - g_TrackingRecords[tracking_channel_idx][id_idx].check_if_within_zone[index_zone] = (PosInfo + obj_idx)->check_if_within_zone[index_zone]; - if ((PosInfo + obj_idx)->check_if_within_zone[index_zone] == 1 && index_zone < viewChannelData[tracking_channel_idx].count_zone && - viewDetectionZone[0][index_zone].det_time > 0 && - g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time > viewDetectionZone[0][index_zone].det_time) { - - int diff_secs_in_zone = (int)difftime(g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time, viewDetectionZone[0][index_zone].det_time) % MAX_OBJ_DWELL_TIME; - if (diff_secs_in_zone < 60 && diff_secs_in_zone >= 2){ - if (diff_secs_in_zone >= 2) { - g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time = viewDetectionZone[0][index_zone].det_time - diff_secs_in_zone; - (PosInfo + obj_idx)->det_time = viewDetectionZone[0][index_zone].det_time - diff_secs_in_zone; - } - else { - g_TrackingRecords[tracking_channel_idx][id_idx].first_det_time = viewDetectionZone[0][index_zone].det_time - 30; - (PosInfo + obj_idx)->det_time = viewDetectionZone[0][index_zone].det_time - 30; - } - } - } - } - //g_TrackingRecords[tracking_channel_idx][id_idx].avg_det_interval = 1.1; - } - - g_TrackingRecords[tracking_channel_idx][id_idx].bAssign_flag = 1; - g_TrackingRecords[tracking_channel_idx][id_idx].Assign_obj_idx = obj_idx; - g_TrackingRecords[tracking_channel_idx][id_idx].detection_count = det_count; - //g_TrackingRecords[tracking_channel_idx][id_idx].fake_detection_count = 0; - - if (det_count >= 1) { - if ((PosInfo + obj_idx)->obj_type == _PLATE && strlen((PosInfo + obj_idx)->properties.plate) >= 1) - { - plate_len = strlen((PosInfo + obj_idx)->properties.plate); - old_plate_len = strlen(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate); - - //printf("[%d] plate1 = %s, %s \n", (PosInfo + obj_idx)->obj_tracking_id, (PosInfo + obj_idx)->properties.plate, g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].properties.plate); - if (plate_len >= old_plate_len) - { - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate, (PosInfo + obj_idx)->properties.plate); - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_type_name, (PosInfo + obj_idx)->car_type_name); - } - else if (plate_len < old_plate_len) - { - //strcpy((PosInfo + obj_idx)->properties.plate, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate); - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate, (PosInfo + obj_idx)->properties.plate); - strcpy((PosInfo + obj_idx)->car_type_name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_type_name); - } - - //printf("[%d] plate2 = %s \n", (PosInfo + obj_idx)->obj_tracking_id, (PosInfo + obj_idx)->properties.plate); - } - } -#if 1 - for (int n = 0; n < det_count - 1; n++) - { - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].name); - //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].replaced_name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].replaced_name); - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].confidence = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].confidence; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].confidence2 = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].confidence2; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].progress_bar = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].progress_bar; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].engine_type = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].engine_type; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].engine_type2 = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].engine_type2; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].left_x; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].top_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].top_y; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_x; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_y; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_direction = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_direction; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].center_stability = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].center_stability; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].width = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].width; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].height; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].plate_char_top_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].plate_char_top_y; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].parent_idx = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].parent_idx; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].car_logo_idx = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].car_logo_idx; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].number_row = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].number_row; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_type = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_type; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].visual_left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].visual_left_x; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].class_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].class_id; - - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].color, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].color); - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].color_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].color_id; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].sec_color_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].sec_color_id; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].trigger_type = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].trigger_type; -#ifdef GY_OS_AMBA - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].min_distance = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].min_distance; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].max_distance = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].max_distance; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].min_height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].min_height; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].max_height = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].max_height; -#endif - for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) { - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].trigger_idx[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].trigger_idx[index_zone]; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].zone_violation_idx[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].zone_violation_idx[index_zone]; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].zone_check_giveway[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].zone_check_giveway[index_zone]; - - //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].near_iou_count[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].near_iou_count[index_zone]; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].IsInsideZone[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].IsInsideZone[index_zone]; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].IsInsideZone_four_points[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].IsInsideZone_four_points[index_zone]; - - if (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_tracking_id == g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_tracking_id) { - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_if_having_been_counted[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].check_if_having_been_counted[index_zone]; - } - else { - //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_if_having_been_counted[index_zone] = 0; - } - - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_speed[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_speed[index_zone]; - //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].s_last_t_Counter[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].s_last_t_Counter[index_zone]; - - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_if_within_zone[index_zone] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].check_if_within_zone[index_zone]; - } - - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_tracking_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_tracking_id; - - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_x; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_y; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_w = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_w; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].box_h = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].box_h; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].dash_left_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].dash_left_x; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].det_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].det_time; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].det_milli_sec = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].det_milli_sec; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_dwell_time; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_first_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_first_dwell_time; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_last_dwell_time = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_last_dwell_time; - - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].linked_plate, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].linked_plate); - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].linked_plate_length = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].linked_plate_length; - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].car_type_name, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].car_type_name); - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].logo, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].logo); - - memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.plate, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate)); - memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.country, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.country, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.country)); - memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.area, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.area, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.area)); - memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.logo, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.logo, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.logo)); - memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.color, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.color, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.color)); - memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.pose, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.pose, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.pose)); - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.area_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.area_id; - //for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) { - //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.counter_count[index_counter] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.counter_count[index_counter]; - //} - memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.plate_list, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate_list, sizeof(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate_list)); - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].properties.plate_length = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].properties.plate_length; - - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].obj_tracking_id_idx = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].obj_tracking_id_idx; - //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].vote_value = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].vote_value; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].disappear_count = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].disappear_count; - - //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].iou_prev_self = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].iou_prev_self; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].test_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].test_id; - //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].image_id = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].image_id; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].adjust_obj_speed = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].adjust_obj_speed; - - //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].sPlateDirection, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].sPlateDirection); - - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].check_person_inter = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].check_person_inter; - - for (int k = 0; k < viewChannelData[tracking_channel_idx].count_zone; k++) { - - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].num_bring_with_object[k] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].num_bring_with_object[k]; - for (int index_bring = 0; index_bring < g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].num_bring_with_object[k] && index_bring < MAX_NUM_BRING_WITH_OBJECT; index_bring++) { - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n].bring_with_object[k][index_bring], g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[n + 1].bring_with_object[k][index_bring]); - } - - g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone[k][n] = g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone[k][n + 1]; - g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone_four_points[k][n] = g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone_four_points[k][n + 1]; - for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { - g_TrackingRecords[tracking_channel_idx][id_idx].point_touch[k][n][index_p] = g_TrackingRecords[tracking_channel_idx][id_idx].point_touch[k][n + 1][index_p]; - g_TrackingRecords[tracking_channel_idx][id_idx].point_touch_four_points[k][n][index_p] = g_TrackingRecords[tracking_channel_idx][id_idx].point_touch_four_points[k][n + 1][index_p]; - } - } - g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_direction[n] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_direction[n + 1]; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_stability[n] = g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_stability[n + 1]; - } - - if (det_count >= 1) { - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].name, (PosInfo + obj_idx)->name); - //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].replaced_name, (PosInfo + obj_idx)->replaced_name); - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].confidence = (PosInfo + obj_idx)->confidence; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].confidence2 = (PosInfo + obj_idx)->confidence2; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].progress_bar = (PosInfo + obj_idx)->progress_bar; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].engine_type = (PosInfo + obj_idx)->engine_type; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].engine_type2 = (PosInfo + obj_idx)->engine_type2; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].left_x = (PosInfo + obj_idx)->left_x; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].top_y = (PosInfo + obj_idx)->top_y; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x = (PosInfo + obj_idx)->center_x; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y = (PosInfo + obj_idx)->center_y; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_direction = (PosInfo + obj_idx)->center_direction; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_stability = (PosInfo + obj_idx)->center_stability; - //printf("\n-------prev #2:%d,%f,%f\n", det_count, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height); - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width = (PosInfo + obj_idx)->width; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height = (PosInfo + obj_idx)->height; - //printf("\n-------prev #3:%d,%f,%f\n", det_count, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height); - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].plate_char_top_y = (PosInfo + obj_idx)->plate_char_top_y; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].parent_idx = (PosInfo + obj_idx)->parent_idx; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_logo_idx = (PosInfo + obj_idx)->car_logo_idx; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].number_row = (PosInfo + obj_idx)->number_row; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_type = (PosInfo + obj_idx)->obj_type; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].visual_left_x = (PosInfo + obj_idx)->visual_left_x; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].class_id = (PosInfo + obj_idx)->class_id; - - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].color, (PosInfo + obj_idx)->color); - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].color_id = (PosInfo + obj_idx)->color_id; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].sec_color_id = (PosInfo + obj_idx)->sec_color_id; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].trigger_type = (PosInfo + obj_idx)->trigger_type; -#ifdef GY_OS_AMBA - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].min_distance = (PosInfo + obj_idx)->min_distance; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].max_distance = (PosInfo + obj_idx)->max_distance; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].min_height = (PosInfo + obj_idx)->min_height; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].max_height = (PosInfo + obj_idx)->max_height; -#endif - for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) { - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].trigger_idx[index_zone] = (PosInfo + obj_idx)->trigger_idx[index_zone]; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].zone_violation_idx[index_zone] = (PosInfo + obj_idx)->zone_violation_idx[index_zone]; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].zone_check_giveway[index_zone] = (PosInfo + obj_idx)->zone_check_giveway[index_zone]; - - //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].near_iou_count[index_zone] = (PosInfo + obj_idx)->near_iou_count[index_zone]; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].IsInsideZone[index_zone] = (PosInfo + obj_idx)->IsInsideZone[index_zone]; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].IsInsideZone_four_points[index_zone] = (PosInfo + obj_idx)->IsInsideZone_four_points[index_zone]; - - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_if_having_been_counted[index_zone] = (PosInfo + obj_idx)->check_if_having_been_counted[index_zone]; - - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_speed[index_zone] = (PosInfo + obj_idx)->obj_speed[index_zone]; - //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].s_last_t_Counter[index_zone] = (PosInfo + obj_idx)->s_last_t_Counter[index_zone]; - - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_if_within_zone[index_zone] = (PosInfo + obj_idx)->check_if_within_zone[index_zone]; - } - - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_tracking_id = (PosInfo + obj_idx)->obj_tracking_id; - - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_x = (PosInfo + obj_idx)->box_x; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_y = (PosInfo + obj_idx)->box_y; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_w = (PosInfo + obj_idx)->box_w; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].box_h = (PosInfo + obj_idx)->box_h; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].dash_left_x = (PosInfo + obj_idx)->dash_left_x; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].det_time = (PosInfo + obj_idx)->det_time; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].det_milli_sec = (PosInfo + obj_idx)->det_milli_sec; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_dwell_time = (PosInfo + obj_idx)->obj_dwell_time; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_first_dwell_time = (PosInfo + obj_idx)->obj_first_dwell_time; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_last_dwell_time = (PosInfo + obj_idx)->obj_last_dwell_time; - - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].linked_plate, (PosInfo + obj_idx)->linked_plate); - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].linked_plate_length = (PosInfo + obj_idx)->linked_plate_length; - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].car_type_name, (PosInfo + obj_idx)->car_type_name); - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].logo, (PosInfo + obj_idx)->logo); - - memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate, (PosInfo + obj_idx)->properties.plate, sizeof((PosInfo + obj_idx)->properties.plate)); - memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.country, (PosInfo + obj_idx)->properties.country, sizeof((PosInfo + obj_idx)->properties.country)); - memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.area, (PosInfo + obj_idx)->properties.area, sizeof((PosInfo + obj_idx)->properties.area)); - memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.logo, (PosInfo + obj_idx)->properties.logo, sizeof((PosInfo + obj_idx)->properties.logo)); - memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.color, (PosInfo + obj_idx)->properties.color, sizeof((PosInfo + obj_idx)->properties.color)); - memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.pose, (PosInfo + obj_idx)->properties.pose, sizeof((PosInfo + obj_idx)->properties.pose)); - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.area_id = (PosInfo + obj_idx)->properties.area_id; - //for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++) { - //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.counter_count[index_counter] = (PosInfo + obj_idx)->properties.counter_count[index_counter]; - //} - memcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate_list, (PosInfo + obj_idx)->properties.plate_list, sizeof((PosInfo + obj_idx)->properties.plate_list)); - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].properties.plate_length = (PosInfo + obj_idx)->properties.plate_length; - - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].obj_tracking_id_idx = (PosInfo + obj_idx)->obj_tracking_id_idx; - //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].vote_value = (PosInfo + obj_idx)->vote_value; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].disappear_count = (PosInfo + obj_idx)->disappear_count; - - //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].iou_prev_self = (PosInfo + obj_idx)->iou_prev_self; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].test_id = (PosInfo + obj_idx)->test_id; - //g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].image_id = (PosInfo + obj_idx)->image_id; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].adjust_obj_speed = (PosInfo + obj_idx)->adjust_obj_speed; - - //strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].sPlateDirection, (PosInfo + obj_idx)->sPlateDirection); - - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].check_person_inter = (PosInfo + obj_idx)->check_person_inter; - - - - for (int k = 0; k < viewChannelData[tracking_channel_idx].count_zone; k++) { - - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[k] = (PosInfo + obj_idx)->num_bring_with_object[k]; - for (int index_bring = 0; index_bring < g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].num_bring_with_object[k] && index_bring < MAX_NUM_BRING_WITH_OBJECT; index_bring++) { - strcpy(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].bring_with_object[k][index_bring], (PosInfo + obj_idx)->bring_with_object[k][index_bring]); - } - - g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone[k][det_count - 1] = 0; - g_TrackingRecords[tracking_channel_idx][id_idx].IsInsideZone_four_points[k][det_count - 1] = 0; - for (size_t index_p = 0; index_p < g_max_sensor_size; index_p++) { - g_TrackingRecords[tracking_channel_idx][id_idx].point_touch[k][det_count - 1][index_p] = 0; - g_TrackingRecords[tracking_channel_idx][id_idx].point_touch_four_points[k][det_count - 1][index_p] = 0; - } - } - g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_direction[det_count - 1] = (PosInfo + obj_idx)->center_direction; - g_TrackingRecords[tracking_channel_idx][id_idx].prev_center_stability[det_count - 1] = (PosInfo + obj_idx)->center_stability; - } -#endif - - if (det_count >= 1) { - //printf("\n-----www----%f,%f\n", g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y); - if (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width > 0.0 && g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].height > 0.0) { - - float diff_x = 0; - float diff_y = 0; - //float diff_time = 0; - if (det_count >= 2) { - diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2].center_x; - diff_y = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2].center_y; - - if (strcmp((PosInfo + obj_idx)->name, "person")==0 && diff_x > g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5) { - diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5; - } - - //diff_time = difftime(g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].det_time, g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2].det_time); -#ifdef GY_OS_AMBA - if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { - if (((int)(PosInfo + obj_idx)->center_direction) != DIRECTION_DEFAULT && det_count >= 3) { - float obj_speed; - float obj_speed_old; - float obj_speed_very_old; - detection_pos *PosInfo_very_old, *PosInfo_old, *PosInfo_new; - - PosInfo_new = &g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1]; - PosInfo_old = &g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 2]; - PosInfo_very_old = &g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 3]; - - float fIou_union_1 = detection_overlap_ratio_union(PosInfo_new, PosInfo_old); - float fIou_union_2 = detection_overlap_ratio_union(PosInfo_new, PosInfo_very_old); - if (fIou_union_1 < 0.85 && fIou_union_2 < 0.85) { - - pthread_mutex_lock(&mutex_perspective_transform); - g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg = -1; - int count_speed_zone = 0; - - for (int social_zone_idx = 0; social_zone_idx < viewChannelData[tracking_channel_idx].count_zone; social_zone_idx++) { - if (strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_speed, "Yes", strlen("Yes")) == 0 /*&& - strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_radar_speed, "No", strlen("No")) == 0*/) { - if (viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray != NULL) { - obj_speed = SetPerspectiveTransform_GetObjSpeed(PosInfo_old, PosInfo_new, viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray, social_zone_idx, 1, 1); - obj_speed_old = SetPerspectiveTransform_GetObjSpeed(PosInfo_very_old, PosInfo_new, viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray, social_zone_idx, 1, 1); - obj_speed_very_old = SetPerspectiveTransform_GetObjSpeed(PosInfo_very_old, PosInfo_old, viewDetectionZone[tracking_channel_idx][social_zone_idx].PerspectiveTransformArray, social_zone_idx, 1, 1); - - float temp_obj_speed = pow(obj_speed * obj_speed_old * obj_speed_very_old, 1.0 / 3.0); - if (temp_obj_speed < 0.1) - temp_obj_speed = 0.1; - - if (g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] == -1) - { - g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] = temp_obj_speed; - } - else if (g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] >= 0) - { - //if (temp_obj_speed < g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] * 1.5) - //if (temp_obj_speed < g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] * 1.5) - - g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] = sqrt(g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] * temp_obj_speed); - } - - (PosInfo + obj_idx)->obj_speed[social_zone_idx] = g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; - - if (g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg == -1) { - g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg = g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; - } - else { - g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg += g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; - } - count_speed_zone++; - } - }/* - else if (strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_speed, "Yes", strlen("Yes")) == 0 && - strncmp(viewDetectionZone[tracking_channel_idx][social_zone_idx].enable_radar_speed, "Yes", strlen("Yes")) == 0) { - - for (int i = 0; i < MAX_SIZE_SP_ARRAY; i++) { - if (SpeedData[i].flag_protected == 1) { // get_g_ori_yuv_height() get_g_ori_yuv_width(); - - float point_x = SpeedData[i].x * get_g_ori_yuv_width() / SpeedData[i].res_width; - float point_y = SpeedData[i].y * get_g_ori_yuv_height() / SpeedData[i].res_height; - - float bbox_min_x = (PosInfo + obj_idx)->left_x; - float bbox_min_y = (PosInfo + obj_idx)->top_y; - float bbox_max_x = (PosInfo + obj_idx)->left_x + (PosInfo + obj_idx)->width; - float bbox_max_y = (PosInfo + obj_idx)->top_y + (PosInfo + obj_idx)->height; - - if (point_x > bbox_min_x && point_x < bbox_max_x && - point_y > bbox_min_y && point_y < bbox_max_y) { - - g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx] = SpeedData[i].speed; - (PosInfo + obj_idx)->obj_speed[social_zone_idx] = g_TrackingRecords[tracking_channel_idx][id_idx].obj_speed_avg[social_zone_idx]; - count_speed_zone++; - - SpeedData[i].flag_protected = 0; - break; - } - } - } - } - */ - } - - if (count_speed_zone >= 1) { - g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg /= count_speed_zone; - (PosInfo + obj_idx)->adjust_obj_speed = g_TrackingRecords[tracking_channel_idx][id_idx].adjust_obj_speed_avg; - } - - pthread_mutex_unlock(&mutex_perspective_transform); - } - } - } -#endif - } - - float temp_diff_x = diff_x; - float temp_diff_y = diff_y; - - diff_x = diff_x + diff_x * g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x; - diff_y = diff_y + diff_y * g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y; - - if (strcmp((PosInfo + obj_idx)->name, "person") == 0 && diff_x > g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5) { - diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5; - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x = 0; - } - - if (strcmp((PosInfo + obj_idx)->name, "person") == 0 && diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x > g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5) { - diff_x = g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - 1].width * 5; - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x = 0; - } - - g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.center_x = (PosInfo + obj_idx)->center_x + diff_x; - g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.center_y = (PosInfo + obj_idx)->center_y + diff_y; - //g_TrackingRecords[tracking_channel_idx][id_idx].det_interval = diff_time; - - g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.left_x = (PosInfo + obj_idx)->left_x + diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x; - g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.top_y = (PosInfo + obj_idx)->top_y + diff_y - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y; - g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.width = (PosInfo + obj_idx)->width + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x * 2;//* (ratio_w) - g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.height = (PosInfo + obj_idx)->height + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y * 2;//* (ratio_h) - - g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_x = (PosInfo + obj_idx)->box_x + diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x; - g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_y = (PosInfo + obj_idx)->box_y + diff_y - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y; - g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_w = (PosInfo + obj_idx)->box_w + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x * 2; - g_TrackingRecords[tracking_channel_idx][id_idx].predict_detection.box_h = (PosInfo + obj_idx)->box_h + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y * 2; - - float sum_diff_x = 0; - float sum_diff_y = 0; - for (int index_det_count = 2; index_det_count <= det_count; index_det_count++) { - sum_diff_x += (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_x); - sum_diff_y += (g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_y); - } - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x = sum_diff_x / (float)det_count; - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y = sum_diff_y / (float)det_count; - float sum_2_diff_x = 0; - float sum_2_diff_y = 0; - for (int index_det_count = 2; index_det_count <= det_count; index_det_count++) { - sum_2_diff_x += pow((g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_x - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_x) - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x, 2.0); - sum_2_diff_y += pow((g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - (index_det_count - 1)].center_y - g_TrackingRecords[tracking_channel_idx][id_idx].prev_detections[det_count - index_det_count].center_y) - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y, 2.0); - } - - g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_x = sqrt(sum_2_diff_x); - g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_y = sqrt(sum_2_diff_y); - - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x = (temp_diff_x - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x) / (g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_x + 1.0); - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y = (temp_diff_y - g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y) / (g_TrackingRecords[tracking_channel_idx][id_idx].mean_diff_y + 1.0); - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x = g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_x * 1.0; - g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y = g_TrackingRecords[tracking_channel_idx][id_idx].error_diff_y * 1.0; - - g_initial_background_learning_rate_x = g_initial_background_learning_rate_x * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_x * 0.01; - g_initial_background_learning_rate_y = g_initial_background_learning_rate_y * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_y * 0.01; - g_initial_background_learning_rate_error_x = g_initial_background_learning_rate_error_x * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_x * 0.01; - g_initial_background_learning_rate_error_y = g_initial_background_learning_rate_error_y * 0.99 + g_TrackingRecords[tracking_channel_idx][id_idx].learning_rate_error_y * 0.01; - } - } - - } -} - -//#ifdef GY_OS_WIN -//#define CHAO_METH -#define METH_1 - -#define IOU_HISTORY_FRAMES 3 - -//VOTE number -#define VOTE_NAME 20 -#define VOTE_PERSON 25 - -#define VOTE_WITHIN_ZONE 70 - -#define VOTE_MAX_UNION_PREDICT_IOU 100 -#define VOTE_MAX_PREDICT_IOU 100 -#define VOTE_MAX_UNION_PREV_IOU 90 -#define VOTE_MAX_PREV_IOU 90 - -#define VOTE_MAX_UNION_PREDICT_IOU_BONUS 50 -#define VOTE_MAX_PREDICT_IOU_BONUS 50 -#define VOTE_MAX_UNION_PREV_IOU_BONUS 45 -#define VOTE_MAX_PREV_IOU_BONUS 45 - -#define VOTE_SIZE_AVOID_PUNISH 25 //30 -#define VOTE_WRONG_NAME_PUNISH 25 //30 - -#define VOTE_NEIGHBOR 150 -#define VOTE_THE_SAME_SIZE 45 -#define VOTE_PLATE 350 //50 -#define VOTE_PLATE_MIN_SCORE 50 - -//#endif //GY_OS_WIN - DEFINE - -//#ifdef GY_OS_WIN -void reset_id_obj(int tracking_channel_idx, int id_idx) -{ - int disappearCount = g_TrackingRecords[tracking_channel_idx][id_idx].disappear_count; - - if (strlen(g_TrackingRecords[tracking_channel_idx][id_idx].name) >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][id_idx].name) == 1) - { - if (disappearCount >= DISAPPEAR_FRAME_MAX * 20) - { - memset(&g_TrackingRecords[tracking_channel_idx][id_idx], 0x00, sizeof(ObjectTracking)); - } - } - else { - if (disappearCount >= DISAPPEAR_FRAME_MAX) - { - memset(&g_TrackingRecords[tracking_channel_idx][id_idx], 0x00, sizeof(ObjectTracking)); - } - } -} -//#endif //GY_OS_WIN - reset_id_obj - -//#ifdef GY_OS_WIN -float prev_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; -float predit_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; -float union_predit_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; -float union_iou_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; -int vote_table[MAX_TRACKING_NUM][MAX_TRACKING_NUM] = { 0 }; -//#endif //GY_OS_WIN - -//#ifdef GY_OS_WIN -void update_iou_table(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx) -{ - float fIOU, predit_IOU, union_IOU, union_predit_IOU; - detection_pos* pNext = NULL; - int det_count; - - // iou about obj to obj. - //detection_pos* pNext_b = NULL; - //float fIou_union; - - for (int i = 0; i < MAX_TRACKING_NUM; i++) - { - //iou_count = 0; - det_count = g_TrackingRecords[tracking_channel_idx][i].detection_count; - //frame_count = g_TrackingRecords[tracking_channel_idx][i].frame_count; - - if (det_count == 0) - continue; - - for (int j = 0; j < total_element_size; j++) - { - pNext = PosInfo + j; - - fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1]); //與上一次 - union_IOU = detection_overlap_ratio_union(pNext, &g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1]); //與上一次 - - predit_IOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][i].predict_detection); //與預測點 - union_predit_IOU = detection_overlap_ratio_union(pNext, &g_TrackingRecords[tracking_channel_idx][i].predict_detection); //與預測點 - - if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][i].name) == 1) { - if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][i].prev_detections[det_count - 1].properties.plate) == 0*/) { - fIOU = 1.0; - predit_IOU = 1.0; - union_predit_IOU = 1.0; - union_IOU = 1.0; - } - else{ - fIOU = 0.0; - predit_IOU = 0.0; - union_predit_IOU = 0.0; - union_IOU = 0.0; - } - } - else { - if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1) { - fIOU = 0.0; - predit_IOU = 0.0; - union_predit_IOU = 0.0; - union_IOU = 0.0; - } - } - - if (IsVehicleCategory(pNext) || (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "car") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bus") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "truck") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "tuktuk") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "trailer") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "pickup") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "SUV") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "dual_headlight") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "single_headlight") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "van"))) { - if (IsVehicleCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "car") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bus") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "truck") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "tuktuk") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "trailer") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "pickup") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "SUV") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "dual_headlight") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "single_headlight") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "van"))) { - - } - else { - if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 1)) { - fIOU = 0.0; - predit_IOU = 0.0; - union_predit_IOU = 0.0; - union_IOU = 0.0; - } - } - } - - if (IsMotorbikeCategory(pNext) || (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "motorbike") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ok") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ng"))) { - if (IsMotorbikeCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "motorbike") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ok") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "exhaust_ng"))) { - - } - else { - if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 1)) { - fIOU = 0.0; - predit_IOU = 0.0; - union_predit_IOU = 0.0; - union_IOU = 0.0; - } - } - } - - if (strcmp(pNext->name,"person")==0 || strstr(g_TrackingRecords[tracking_channel_idx][i].name, "person")) { - if (strcmp(pNext->name, "person") == 0 && strstr(g_TrackingRecords[tracking_channel_idx][i].name, "person")) { - - } - else { - if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 1)) { - fIOU = 0.0; - predit_IOU = 0.0; - union_predit_IOU = 0.0; - union_IOU = 0.0; - } - } - } - - if (IsGarbageCategory(pNext) || (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bag") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bottle") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cup") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cigarette") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "paper_sheet") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "box"))) { - if (IsGarbageCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bag") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "bottle") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cup") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "cigarette") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "paper_sheet") || - strstr(g_TrackingRecords[tracking_channel_idx][i].name, "box"))) { - - } - else { - fIOU = 0.0; - predit_IOU = 0.0; - union_predit_IOU = 0.0; - union_IOU = 0.0; - } - } - - prev_iou_table[i][j] = fIOU; - predit_iou_table[i][j] = predit_IOU; - union_predit_iou_table[i][j] = union_predit_IOU; - union_iou_table[i][j] = union_IOU; - } - } -} -//#endif //GY_OS_WIN - update_iou_table - -//#ifdef GY_OS_WIN -void update_vote_table(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx) -{ - detection_pos* pNext = NULL; - detection_pos* pNext2 = NULL; - - int det_count; - int vote_value = 0; - - int max_iou_idx = -1; - float max_iou = 0.0; - - int max_predict_iou_idx = -1; - float max_predict_iou = 0.0; - - int max_union_iou_idx = -1; - float max_union_iou = 0.0; - - int max_union_predict_iou_idx = -1; - float max_union_predict_iou = 0.0; - - - float pre_H, pre_W; - float delta_w, delta_h; - //int old_confidence; - - if (IsANPRCategory(featureType)) { - for (int m = 0; m < total_element_size; m++) - { - pNext = PosInfo + m; - if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) { - for (int k = 0; k < total_element_size; k++) - { - pNext2 = PosInfo + k; - if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) - { - if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext->name, "exhaust_ok") == 0 || strcmp(pNext->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0) || ((pNext2->center_x <= pNext->left_x + pNext->width && pNext2->center_x >= pNext->left_x) && - (pNext2->center_y <= pNext->top_y + pNext->height && pNext2->center_y >= pNext->top_y)) - ) - { - strcpy(pNext2->car_type_name, pNext->name); - - if (strlen(pNext2->properties.plate) > strlen(pNext->linked_plate)) - { - if (pNext2->properties.plate_length >= atoi(viewChannelData[0].min_characters) && - pNext2->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { - - strcpy(pNext->linked_plate, pNext2->properties.plate); - pNext->linked_plate_length = pNext2->properties.plate_length; - } - } - - break; - } - } - } - } - } - } - - for (int k = 0; k < MAX_TRACKING_NUM; k++) - { - max_iou = 0.0; - max_iou_idx = -1; - - max_predict_iou = 0.0; - max_predict_iou_idx = -1; - - max_union_iou = 0.0; - max_union_iou_idx = -1; - - max_union_predict_iou = 0.0; - max_union_predict_iou_idx = -1; - - det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; - - if (det_count == 0) - continue; - - for (int m = 0; m < total_element_size; m++) - { - pNext = PosInfo + m; - - vote_value = 0; - vote_table[k][m] = vote_value; - - ////與歷史和預測點的面積,分數加權 - { - vote_table[k][max_iou_idx] += (int)((float)VOTE_MAX_PREV_IOU * prev_iou_table[k][m]); - if (prev_iou_table[k][m] > max_iou) - { - max_iou = prev_iou_table[k][m]; - max_iou_idx = m; - } - - vote_table[k][max_predict_iou_idx] += (int)((float)VOTE_MAX_PREDICT_IOU * predit_iou_table[k][m]); - if (predit_iou_table[k][m] > max_predict_iou) - { - max_predict_iou = predit_iou_table[k][m]; - max_predict_iou_idx = m; - } - - vote_table[k][max_union_iou_idx] += (int)((float)VOTE_MAX_UNION_PREV_IOU * union_iou_table[k][m]); - //與上次歷史點的聯集面積為分母的IOU - if (union_iou_table[k][m] > max_union_iou) - { - max_union_iou = union_iou_table[k][m]; - max_union_iou_idx = m; - } - - vote_table[k][max_union_predict_iou_idx] += (int)((float)VOTE_MAX_UNION_PREDICT_IOU * union_predit_iou_table[k][m]); - //與預測點聯集面積為分母的 IOU - if (union_predit_iou_table[k][m] > max_union_predict_iou) - { - max_union_predict_iou = union_predit_iou_table[k][m]; - max_union_predict_iou_idx = m; - } - } - - if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { - //printf("\n-------pNext->properties.plate:%s,prev_detections:%s\n", pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate); - - if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { - vote_table[k][m] += VOTE_PLATE_MIN_SCORE; - - if (prev_iou_table[k][m] > max_iou) - { - max_iou = prev_iou_table[k][m]; - max_iou_idx = m; - } - - if (predit_iou_table[k][m] > max_predict_iou) - { - max_predict_iou = predit_iou_table[k][m]; - max_predict_iou_idx = m; - } - - //與上次歷史點的聯集面積為分母的IOU - if (union_iou_table[k][m] > max_union_iou) - { - max_union_iou = union_iou_table[k][m]; - max_union_iou_idx = m; - } - - //與預測點聯集面積為分母的 IOU - if (union_predit_iou_table[k][m] > max_union_predict_iou) - { - max_union_predict_iou = union_predit_iou_table[k][m]; - max_union_predict_iou_idx = m; - } - //printf("\n-------same plate #1\n"); - } - else { - vote_table[k][m] = 0; - //printf("\n-------not same plate #2\n"); - } - } - else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && - (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && - LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 - /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { - //printf("\n----#2---pNext->properties.plate:%s,prev_detections:%s\n", pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate); - //printf("\n---------same car\n"); - vote_table[k][m] += VOTE_PLATE_MIN_SCORE; - //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); - } - } - - //個別項目加入對應權重 - //max_iou_idx - - if (max_iou_idx != -1) - { - vote_table[k][max_iou_idx] += (int)((float)VOTE_MAX_PREV_IOU_BONUS); - //obj name same - pNext = PosInfo + max_iou_idx; - if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) - { - if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { - if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { - vote_table[k][max_iou_idx] += VOTE_PLATE; - //printf("\n-------same plate #1\n"); - } - } - else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && - (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && - LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 - /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { - - vote_table[k][max_iou_idx] += VOTE_PLATE; - //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); - } - } - } - - if (max_union_iou_idx != -1) - { - vote_table[k][max_union_iou_idx] += (int)((float)VOTE_MAX_UNION_PREV_IOU_BONUS); - //obj name same - pNext = PosInfo + max_union_iou_idx; - if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) - { - if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { - if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { - vote_table[k][max_union_iou_idx] += VOTE_PLATE; - //printf("\n-------same plate #2\n"); - } - } - else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && - (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && - LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 - /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { - - vote_table[k][max_union_iou_idx] += VOTE_PLATE; - //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); - } - } - } - - - if (max_predict_iou_idx != -1) - { - vote_table[k][max_predict_iou_idx] += (int)((float)VOTE_MAX_PREDICT_IOU_BONUS); - //obj name same - pNext = PosInfo + max_predict_iou_idx; - if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) - { - if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { - if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { - vote_table[k][max_predict_iou_idx] += VOTE_PLATE; - //printf("\n-------same plate #1\n"); - } - } - else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && - (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && - LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 - /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { - - vote_table[k][max_predict_iou_idx] += VOTE_PLATE; - //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); - } - } - } - - if (max_union_predict_iou_idx != -1) - { - vote_table[k][max_union_predict_iou_idx] += (int)((float)VOTE_MAX_UNION_PREDICT_IOU_BONUS); - pNext = PosInfo + max_union_predict_iou_idx; - if (strcmp(g_TrackingRecords[tracking_channel_idx][k].name, pNext->name) == 0) - { - if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { - if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { - vote_table[k][max_union_predict_iou_idx] += VOTE_PLATE; - //printf("\n-------same plate #3\n"); - } - } - else if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= 1 && - (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 0 && - LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 - /*strcmp(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext->linked_plate) == 0*/) { - - vote_table[k][max_union_predict_iou_idx] += VOTE_PLATE; - //printf("\n------g_TrackingRecords[tracking_channel_idx][k].linked_plate_length:%d\n", g_TrackingRecords[tracking_channel_idx][k].linked_plate_length); - } - } - } - - for (int m = 0; m < total_element_size; m++) - { - pNext = PosInfo + m; - - if (IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][k].name) == 1) { - if (IsANPRCategory(pNext->engine_type) && strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].properties.plate) == 0*/) { - - } - else { - vote_table[k][m] = 0; - continue; - } - } - - if (IsVehicleCategory(pNext)) { - if (strstr(g_TrackingRecords[tracking_channel_idx][k].name, "car") || - strstr(g_TrackingRecords[tracking_channel_idx][k].name, "bus") || - strstr(g_TrackingRecords[tracking_channel_idx][k].name, "truck") || - strstr(g_TrackingRecords[tracking_channel_idx][k].name, "tuktuk") || - strstr(g_TrackingRecords[tracking_channel_idx][k].name, "trailer") || - strstr(g_TrackingRecords[tracking_channel_idx][k].name, "pickup") || - strstr(g_TrackingRecords[tracking_channel_idx][k].name, "SUV") || - strstr(g_TrackingRecords[tracking_channel_idx][k].name, "dual_headlight") || - strstr(g_TrackingRecords[tracking_channel_idx][k].name, "single_headlight") || - strstr(g_TrackingRecords[tracking_channel_idx][k].name, "van")) { - - - - } - else { - if (!(strcmp(g_TrackingRecords[tracking_channel_idx][k].name, "object") == 0 && pNext->number_row == 2)) { - vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; - } - } - } - else if (IsMotorbikeCategory(pNext)) { - if (strstr(g_TrackingRecords[tracking_channel_idx][k].name, "motorbike") || - strstr(g_TrackingRecords[tracking_channel_idx][k].name, "exhaust_ok") || - strstr(g_TrackingRecords[tracking_channel_idx][k].name, "exhaust_ng")) { - - } - else { - if (!(strcmp(g_TrackingRecords[tracking_channel_idx][k].name, "object") == 0 && pNext->number_row == 2)) { - vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; - } - } - } - else { - /*if (strcmp(pNext->name,"new_object")==0) { - int checkisInside = check_if_object_in_zone(pNext->center_x, pNext->center_y, pNext->width, pNext->height, get_g_ori_yuv_width(), get_g_ori_yuv_height(), 0); - if (checkisInside == 1) { - vote_table[k][m] += VOTE_PERSON; - } - else { - if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) != 0) { - vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; - } - } - } - else */ - //if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) != 0) { - //if (!(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2)) { - //vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH; - //} - //else if (strcmp(pNext->name, "object") == 0 && pNext->number_row == 2) { - //vote_table[k][m] -= VOTE_WRONG_NAME_PUNISH * 10; - //} - //} - } - - if (get_g_check_if_show_parking() == 1) { - for (int index_zone = 0; index_zone < MAX_DETECTION_ZONE; index_zone++) - { - if (g_TrackingRecords[tracking_channel_idx][k].check_if_within_zone[index_zone] == PosInfo->check_if_within_zone[index_zone]) - { - vote_table[k][m] += VOTE_WITHIN_ZONE; - } - } - } - - //if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) == 0) { - //vote_table[k][m] += VOTE_NAME; - //if (strcmp("person", pNext->name) == 0) - //{ - //vote_table[k][m] += VOTE_PERSON; - //} - //} -#if 1 - //與預測點比較長寬 - pre_H = g_TrackingRecords[tracking_channel_idx][k].predict_detection.height; - pre_W = g_TrackingRecords[tracking_channel_idx][k].predict_detection.width; - - delta_h = 1.0 - fabs(pNext->height / pre_H - 1.0); - delta_w = 1.0 - fabs(pNext->width / pre_W - 1.0); - - vote_table[k][m] += VOTE_THE_SAME_SIZE * delta_h; - vote_table[k][m] += VOTE_THE_SAME_SIZE * delta_w; - - double new_width = 0.0; - double new_height = 0.0; - double new_slide = 0.0; - - double new_pred_vec_x = pNext->left_x - g_TrackingRecords[tracking_channel_idx][k].predict_detection.left_x; - double new_pred_vec_y = pNext->top_y - g_TrackingRecords[tracking_channel_idx][k].predict_detection.top_y; - double new_pred_vec = sqrt(new_pred_vec_x*new_pred_vec_x + new_pred_vec_y * new_pred_vec_y); - - if (strcmp(pNext->name, "person") == 0 && strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][k].name) == 0) { - new_width = pre_W * 5.5; - new_height = pre_H * 5.5; - new_slide = sqrt(new_width*new_width + new_height * new_height); - } - else { - new_width = pre_W * 2.5; - new_height = pre_H * 2.5; - new_slide = sqrt(new_width*new_width + new_height * new_height); - } - - //鄰近的預測點 - if (new_pred_vec <= new_slide) { - vote_table[k][m] += VOTE_NEIGHBOR * (new_slide - new_pred_vec) / (new_slide); - } -#endif -#if 1 - //跟歷史軌跡比較方向 - if (det_count >= 2) - { - double new_vec_x = pNext->left_x - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].left_x; - double new_vec_y = pNext->top_y - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].top_y; - - //double new_vec = sqrt(new_vec_x*new_vec_x + new_vec_y* new_vec_y); - - double old_vec_x = 0.0; - double old_vec_y = 0.0; - - old_vec_x = g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].left_x - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 2].left_x; - old_vec_y = g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].top_y - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 2].top_y; - - //位移方向相反 - if (old_vec_x < 0) - { - if (new_vec_x > 0 && abs(new_vec_x) > (g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].width / 2)) //3 - { - vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; - } - else { - - } - } - - if (old_vec_x > 0) - { - if (new_vec_x < 0 && abs(new_vec_x) >(g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].width / 2))//3 - { - vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; - } - else { - - } - } - - if (old_vec_y < 0) - { - if (new_vec_y > 0 && abs(new_vec_y) > (g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].height / 2))//3 - { - vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; - } - else { - - } - } - - if (old_vec_y > 0) - { - if (new_vec_y < 0 && abs(new_vec_y) >(g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].height / 2))//3 - { - vote_table[k][m] -= VOTE_SIZE_AVOID_PUNISH; - } - else { - - } - } - } -#endif - } - } -} -//#endif //GY_OS_WIN - update_vote_table - -int find_possible_obj(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx, int id_idx,int use_high_or_low_score) -{ - int max_vote_value = 0; - int obj_idx = -1; - detection_pos* pNext = NULL; - - //printf("\n-------id_idx:%d\n", id_idx); - - if(use_high_or_low_score == 0) - max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_0; - else if(use_high_or_low_score == 1) - max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_1; - else if (use_high_or_low_score == 2) - max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_2; - else if (use_high_or_low_score == 3) - max_vote_value = MAX_VOTE_VALUE_FIND_POSSIBLE_OBJ_3; - - for (int j = 0; j < total_element_size; j++) - { - pNext = PosInfo + j; - if (pNext->obj_tracking_id > 0) - continue; - - //printf("\n---------vote_table[id_idx][%d]:%d\n",j, vote_table[id_idx][j]); - if (vote_table[id_idx][j] > max_vote_value) - { - max_vote_value = vote_table[id_idx][j]; - obj_idx = j; - } - } - - ///if bbox j already assign id, check vote_value - //printf("\n------id_idx:%d---obj_idx:%d\n", id_idx, obj_idx); - if (obj_idx != -1) - { - //printf("\n---------obj_idx:%d\n", obj_idx); - - pNext = PosInfo + obj_idx; - - //pNext->vote_value = max_vote_value; - pNext->obj_tracking_id = g_TrackingRecords[tracking_channel_idx][id_idx].obj_tracking_id; - pNext->obj_tracking_id_idx = id_idx; - } - //if bbox j already assign id, check vote_value - - return obj_idx; -} -//#endif //GY_OS_WIN - find_possible_obj - -int Modify_Plate_and_Recount_Length(char *input_plate,char *output_plate) { - char afterBuf[256] = { 0 }; - strcpy(afterBuf, input_plate); - - char buf[64] = { 0 }; - memset(buf, 0x00, sizeof(buf)); - strcpy(buf, afterBuf); - - int k = 0; - int plate_length = 0; - - //printf("\n------1\n"); - //printf("\nbuf:%s\n",buf); - //printf("\n------2\n"); - for (int m = 0; m < strlen(buf); m++) - { - //printf("[%x]",buf[m]); - if (buf[m] >= 65 && buf[m] <= 90) { - - if (buf[m] == 73 && strcmp(SystemSetting.force_i_to_one, "Yes") == 0) { - afterBuf[m] = '1'; - } - else if (buf[m] == 79 && strcmp(SystemSetting.force_o_to_zero, "Yes") == 0) { - afterBuf[m] = '0'; - } - - //alphabets++; - afterBuf[k] = afterBuf[m]; - k++; - - plate_length++; - } - else if (buf[m] >= 97 && buf[m] <= 122) { - if (buf[m] == 105 && strcmp(SystemSetting.force_i_to_one, "Yes") == 0) { - afterBuf[m] = '1'; - } - else if (buf[m] == 111 && strcmp(SystemSetting.force_o_to_zero, "Yes") == 0) { - afterBuf[m] = '0'; - } - - if ((featureType & FEATURE_LPR_TWN) <= 0) { - //alphabets++; - afterBuf[k] = afterBuf[m]; - k++; - - plate_length++; - } - } - else if (buf[m] >= 48 && buf[m] <= 57) { - //digits++; - afterBuf[k] = afterBuf[m]; - k++; - - plate_length++; - } - else { - //specialcharacters++; - if ((featureType & FEATURE_LPR_JPN) > 0) { - //參考日文表UTF-8,三個c組成一個日文,第一個c,會介於227-239之間。 - if (buf[m] >= 227 && buf[m] <= 239 && (m + 2) < strlen(buf)) { - afterBuf[k] = afterBuf[m]; - k++; - afterBuf[k] = afterBuf[m + 1]; - k++; - afterBuf[k] = afterBuf[m + 2]; - k++; - m = m + 2; - - plate_length++; - } - } - else if ((featureType & FEATURE_LPR_THA) > 0 || (featureType & FEATURE_LPR_BGD) > 0) { - //參考泰文表或孟加拉文UTF-8,三個c組成一個泰文或孟加拉文,第一個c,會是224。 - if (buf[m] == 224 && (m + 2) < strlen(buf)) { - afterBuf[k] = afterBuf[m]; - k++; - afterBuf[k] = afterBuf[m + 1]; - k++; - afterBuf[k] = afterBuf[m + 2]; - k++; - m = m + 2; - - plate_length++; - } - } - else if ((featureType & FEATURE_LPR_MEA) > 0) { - //參考阿拉伯UTF-8,兩個c組成一個阿拉伯,第一個c,會是6或7。 - if (buf[m] >= 216 && buf[m] <= 217 && (m + 1) < strlen(buf)) { - - //if (strcmp(SystemSetting.enable_special_char, "Yes") == 0) - { - //afterBuf[k] = afterBuf[m]; - //k++; - //afterBuf[k] = afterBuf[m + 1]; - //k++; - m = m + 1; - - //plate_length++; - } - //else { - //m = m + 1; - //} - } - //支援減號, 空白 - else if (buf[m] == 45 - || buf[m] == 32) { - afterBuf[k] = afterBuf[m]; - k++; - - plate_length++; - } - } - else if ((featureType & FEATURE_LPR_TWN) > 0) { - //支援部分中文字UTF-8,三個c組成一個中文,第一個c,會介於228-233之間。 - if (buf[m] >= 228 && buf[m] <= 233 && (m + 2) < strlen(buf)) { - - if (strcmp(SystemSetting.enable_special_char, "Yes") == 0) { - afterBuf[k] = afterBuf[m]; - k++; - afterBuf[k] = afterBuf[m + 1]; - k++; - afterBuf[k] = afterBuf[m + 2]; - k++; - m = m + 2; - - plate_length++; - } - else { - m = m + 2; - } - } - else if (buf[m] == 45) {//支援減號 - if (activeDisplayDash) - { - afterBuf[k] = afterBuf[m]; - k++; - - plate_length++; - } - } - } - } - } - //printf("\n------\n"); - afterBuf[k] = '\0'; - //printf("\nafterBuf:%s\n", afterBuf); - - if (((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION && strcmp(WeightFileModeName, "mod003") == 0)) { - strcpy(afterBuf, input_plate); - k = strlen(input_plate); - afterBuf[k] = '\0'; - plate_length = k; - } - - if (plate_length >= atoi(viewChannelData[0].min_characters) && - plate_length <= atoi(viewChannelData[0].max_characters)) - strcpy(output_plate, afterBuf); - else - plate_length = 0; - return plate_length; -} - -void set_logo_to_plate_or_vehicle(detection_pos* PosInfo, int total_element_size) -{ -#ifdef GY_OS_AMBA - detection_pos* pNext = NULL; - for (int i = 0; i < total_element_size; i++) - { - //printf("\n[start all nets] while 10-1\n"); - pNext = PosInfo + i; /** sizeof(detection_pos)*/ - - - if (strlen(pNext->name) == 0) { - continue; - } - char c_logo[50] = { 0 }; - - int iCar_idx = pNext->car_logo_idx;//pNext->car_logo_idx - detection_pos *pNext_car; - - if (iCar_idx >= 0) - { - pNext_car = PosInfo + iCar_idx;//iCar_idx - int iLogo_idx = pNext_car->car_logo_idx; - detection_pos *pNext_logo = NULL; - //printf("\n----------iLogo_idx:%d\n", iLogo_idx); - if (IsVehicleCategory(pNext_car)) { - if (iLogo_idx >= 0) - { - pNext_logo = PosInfo + iLogo_idx; - //printf("\n---------pNext_logo->name:%s\n", pNext_logo->name); - if (pNext_logo->name - && strlen(pNext_logo->name) > 0 - && !IsANPRCategory_L_Plate(pNext_logo->name) - && !IsVehicleCategory(pNext_logo) - && strcmp(pNext_logo->name, "person") != 0 - && (pNext_logo->name[0] != '0' && - pNext_logo->name[0] != '1' && - pNext_logo->name[0] != '2' && - pNext_logo->name[0] != '3' && - pNext_logo->name[0] != '4' && - pNext_logo->name[0] != '5' && - pNext_logo->name[0] != '6' && - pNext_logo->name[0] != '7' && - pNext_logo->name[0] != '8' && - pNext_logo->name[0] != '9') - ) { - char temp_buf[50] = { 0 }; - int index_temp_buf = 0; - - for (int m = 0; m < (int)strlen(pNext_logo->name); m++) { - if (m < (int)strlen(pNext_logo->name) - 1 && pNext_logo->name[m] == 'l' && pNext_logo->name[m + 1] == '_') { - m++; - } - else { - temp_buf[index_temp_buf] = pNext_logo->name[m]; - index_temp_buf++; - } - } - temp_buf[index_temp_buf] = '\0'; - - sprintf(c_logo, "%s", temp_buf); - } - else { - sprintf(c_logo, "%s", ""); - } - strcpy(pNext_logo->logo, c_logo); - } - else { - sprintf(c_logo, "%s", ""); - } - strcpy(pNext_car->logo, c_logo); - } - else { - sprintf(c_logo, "%s", ""); - } - strcpy(pNext->properties.logo, c_logo); - } - - int check_if_logo = 0; - char temp_name[30] = { 0 }; - int index_temp_name = 0; - for (int index_name = 0; index_name < (int)strlen(pNext->name); index_name++) { - if (index_name < (int)strlen(pNext->name) - 1 && pNext->name[index_name] == 'l' && pNext->name[index_name + 1] == '_') { - index_name++; - check_if_logo = 1; - } - else { - temp_name[index_temp_name] = pNext->name[index_name]; - index_temp_name++; - } - } - temp_name[index_temp_name] = '\0'; - if (check_if_logo == 1) { - strcpy(pNext->name, temp_name); - strcpy(pNext->properties.logo, temp_name); - } - } -#endif -} - -void GetObjectTrackingIDNew(detection_pos* PosInfo, int * total_element_size_temp, int tracking_channel_idx, time_t curr_det_time, int i_InSourceOri_w, int i_InSourceOri_h) -{ - int total_element_size = * total_element_size_temp; - /*double dur; - clock_t start, end; - start = clock();*/ -#ifdef GY_OS_NOVA - g_sensors_type = 1; -#endif - -#ifdef GY_OS_AMBA - g_sensors_type = atoi(SystemSetting.sensors_type); -#endif - g_max_sensor_size = g_sensors_type == 0 ? MAX_SENSOR_TYPE0 : MAX_SENSOR_TYPE1; - - float ratio_w = (float)i_InSourceOri_w;//0.25f - float ratio_h = (float)i_InSourceOri_h;//0.3f - - //printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - //printf("\nGetObjectTrackingIDNew: %d\n",10); - //printf("\nratio_w: %f\n", ratio_w); - //printf("\nratio_h: %f\n", ratio_h); - //printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - - detection_pos* pNext = NULL; - //detection_pos* pNext_temp = NULL; - - for (int k = 0; k < MAX_DETECTION_ZONE; k++) - { - //eventCounterList[j].counter_count = 0; - viewDetectionZone[tracking_channel_idx][k].queuing_trigger_event_idx = -1; - } - - struct timeval currtime; - gettimeofday(&currtime, NULL); - int det_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); - //printf("----det time = %d ms\n", det_ms); - - //2020-04-10 Updated - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - pNext->obj_tracking_id = 0; - //pNext->vote_value = 0; - pNext->det_time = curr_det_time; - pNext->det_milli_sec = det_ms; - pNext->trigger_type = 0; - //pNext->disappear_count = 0; - pNext->obj_tracking_id_idx = -1; - - pNext->replaced_id = 0; - pNext->replaced_id_idx = -1; - - //printf("[%d] p_name 10 = %s \n", i, pNext->name); - //pNext->iou_prev_self = 0; - pNext->adjust_obj_speed = -1; - pNext->check_if_replaced_in_zone = 0; - //strcpy(pNext->replaced_name, ""); - - //pNext->image_id = -1; - } - - memset(prev_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); - memset(predit_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); - memset(union_predit_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); - memset(union_iou_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); - - memset(vote_table, 0, MAX_TRACKING_NUM * MAX_TRACKING_NUM); - - for (int i = 0; i < MAX_TRACKING_NUM; i++) - { - reset_id_obj(tracking_channel_idx, i); - g_TrackingRecords[tracking_channel_idx][i].bAssign_flag = 0; - //g_TrackingRecords[tracking_channel_idx][i].vote_value = 0; - g_TrackingRecords[tracking_channel_idx][i].Assign_obj_idx = -1; - } - - /// - update_iou_table(PosInfo, total_element_size, tracking_channel_idx); - update_vote_table(PosInfo, total_element_size, tracking_channel_idx); - /// - - int det_count = 0; -#if 1 - ///Search Multi connection bbox - int closest_obj_idx = -1; - int bFindTrackingObjects = 0; - - for (int index_score = 0; index_score < 4; index_score++) { - for (int i = 0; i < MAX_TRACKING_NUM; i++) - { - //reset_id_obj(&g_TrackingRecords[tracking_channel_idx][i],i); - - det_count = g_TrackingRecords[tracking_channel_idx][i].detection_count; - if (det_count == 0) - continue; - - if (g_TrackingRecords[tracking_channel_idx][i].bAssign_flag == 1) - continue; - - //first time : find_possible_obj for high score - //second time : find_possible_obj for low score - //more time : find_possible_obj for lower score - closest_obj_idx = find_possible_obj(PosInfo, total_element_size, tracking_channel_idx, i, index_score); - - bFindTrackingObjects = 0; - if (closest_obj_idx != -1) - bFindTrackingObjects = 1; - - //printf("\n-------i:%d-------closest_obj_idx:%d\n",i, closest_obj_idx); - - if (bFindTrackingObjects) - { - ApplyTrackingTableAndPrevDetection(PosInfo, total_element_size, tracking_channel_idx, i, closest_obj_idx); - } - } - } -#endif - - ///Assign New obj ID to new bounding box - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - det_count = 0; - - if (pNext->obj_tracking_id <= 0) - { - ///Check prev data again - float max_prev_iou = 0.0; - int closest_id_idx = -1; - for (int j = 0; j < MAX_TRACKING_NUM; j++) - { - if (g_TrackingRecords[tracking_channel_idx][j].bAssign_flag) - continue; - - det_count = g_TrackingRecords[tracking_channel_idx][j].detection_count; - - if (det_count >= 1) - { - float fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 1]); - - if (IsANPRCategory(pNext->engine_type) && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][j].name) == 1) { - if (strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 1].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 1].properties.plate) == 0*/) { - //if (fIOU > max_prev_iou) - { - max_prev_iou = fIOU; - closest_id_idx = j; - break; - } - } - else if (strcmp(pNext->name, "ambulance") == 0) { - if (fIOU > max_prev_iou) - { - max_prev_iou = fIOU; - closest_id_idx = j; - //break; - } - } - else if (strcmp(pNext->name, "blank") == 0) { - if (fIOU > max_prev_iou) - { - max_prev_iou = fIOU; - closest_id_idx = j; - //break; - } - } - else if (strcmp(pNext->name, "stop_sign") == 0) { - if (fIOU > max_prev_iou) - { - max_prev_iou = fIOU; - closest_id_idx = j; - //break; - } - } - else if (strcmp(pNext->name, "face") == 0) { - if (fIOU > max_prev_iou) - { - max_prev_iou = fIOU; - closest_id_idx = j; - //break; - } - } - else if (det_count >= 2) { - fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); - if (strlen(pNext->properties.plate) >= 1 && LevenshteinDistance(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].properties.plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0 /*strcmp(pNext->properties.plate, g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].properties.plate) == 0*/) { - //if (fIOU > max_prev_iou) - { - max_prev_iou = fIOU; - closest_id_idx = j; - break; - } - } - } - } - else if (g_TrackingRecords[tracking_channel_idx][j].linked_plate_length >= 1 && - (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][j].name) == 0 && - LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][j].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) - { - //if (fIOU > max_prev_iou) - { - max_prev_iou = fIOU; - closest_id_idx = j; - break; - } - - } - else if (det_count >= 2 && - g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].linked_plate_length >= 1 && - (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) && pNext->linked_plate_length >= 1 && IsANPRCategory_L_Plate(g_TrackingRecords[tracking_channel_idx][j].name) == 0 && - LevenshteinDistance(g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2].linked_plate, pNext->linked_plate, atoi(viewChannelData[tracking_channel_idx].levenshtein_distance)) > 0) { - fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); - //if (fIOU > max_prev_iou) - { - max_prev_iou = fIOU; - closest_id_idx = j; - break; - } - } - else if (strcmp(pNext->name, g_TrackingRecords[tracking_channel_idx][j].name) == 0) { - if (fIOU > max_prev_iou) - { - - max_prev_iou = fIOU; - closest_id_idx = j; - } - else if (det_count >= 2) { - fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); - if (fIOU > max_prev_iou) - { - max_prev_iou = fIOU; - closest_id_idx = j; - } - } - //printf("\n---------max_prev_iou:%f,top_y:%f\n", max_prev_iou,pNext->top_y); - } - else if (IsVehicleCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][j].name, "car") || - strstr(g_TrackingRecords[tracking_channel_idx][j].name, "bus") || - strstr(g_TrackingRecords[tracking_channel_idx][j].name, "truck") || - strstr(g_TrackingRecords[tracking_channel_idx][j].name, "tuktuk") || - strstr(g_TrackingRecords[tracking_channel_idx][j].name, "trailer") || - strstr(g_TrackingRecords[tracking_channel_idx][j].name, "pickup") || - strstr(g_TrackingRecords[tracking_channel_idx][j].name, "SUV") || - strstr(g_TrackingRecords[tracking_channel_idx][j].name, "dual_headlight") || - strstr(g_TrackingRecords[tracking_channel_idx][j].name, "single_headlight") || - strstr(g_TrackingRecords[tracking_channel_idx][j].name, "van"))) { - if (fIOU > max_prev_iou) - { - max_prev_iou = fIOU; - closest_id_idx = j; - } - else if (det_count >= 2) { - fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); - if (fIOU > max_prev_iou) - { - max_prev_iou = fIOU; - closest_id_idx = j; - } - } - } - else if (IsMotorbikeCategory(pNext) && (strstr(g_TrackingRecords[tracking_channel_idx][j].name, "motorbike") || - strstr(g_TrackingRecords[tracking_channel_idx][j].name, "exhaust_ok") || - strstr(g_TrackingRecords[tracking_channel_idx][j].name, "exhaust_ng"))) { - if (fIOU > max_prev_iou) - { - max_prev_iou = fIOU; - closest_id_idx = j; - } - else if (det_count >= 2) { - fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); - if (fIOU > max_prev_iou) - { - max_prev_iou = fIOU; - closest_id_idx = j; - } - } - } - else if (strcmp(pNext->name, "object") == 0 && pNext->number_row == 1 && strcmp(heartbeatData.events_default_version, "4") == 0) - { - if (fIOU > max_prev_iou) - { - max_prev_iou = fIOU; - closest_id_idx = j; - } - else if (det_count >= 2) { - fIOU = detection_overlap_ratio(pNext, &g_TrackingRecords[tracking_channel_idx][j].prev_detections[det_count - 2]); - if (fIOU > max_prev_iou) - { - max_prev_iou = fIOU; - closest_id_idx = j; - } - } - } - - } - } - - if (closest_id_idx != -1) - { - //pNext->vote_value = max_prev_iou; - pNext->obj_tracking_id = g_TrackingRecords[tracking_channel_idx][closest_id_idx].obj_tracking_id; - pNext->obj_tracking_id_idx = closest_id_idx; - - ApplyTrackingTableAndPrevDetection(PosInfo, total_element_size, tracking_channel_idx, closest_id_idx, i); - } - else { - for (int m = 0; m < MAX_TRACKING_NUM; m++) - { - if (g_TrackingRecords[tracking_channel_idx][m].bAssign_flag) - continue; - - det_count = g_TrackingRecords[tracking_channel_idx][m].detection_count; - if (det_count == 0) - { - //pNext->vote_value = 0; - pNext->obj_tracking_id = 0; - pNext->obj_tracking_id_idx = m; - - ApplyTrackingTableAndPrevDetection(PosInfo, total_element_size, tracking_channel_idx, m, i); - - break; - } - } - } - } - } - - if (strcmp(viewChannelData[0].enable_unknown_object, "Yes") == 0) - { - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - - if (pNext->obj_tracking_id >= 1 && pNext->obj_tracking_id_idx >= 0 && pNext->obj_dwell_time >= 1 && strcmp(pNext->name, "object") == 0 && pNext->number_row == 1 && - pNext->height >= 1 && pNext->width >= 1) - { - int checkisInside = check_if_object_in_zone(pNext->center_x, pNext->center_y, pNext->width * 1.5, pNext->height * 1.5, g_ori_yuv_width, g_ori_yuv_height, 0); - - if (checkisInside == 1 && (pNext->width * pNext->height) / ((float)g_ori_yuv_width * (float)g_ori_yuv_height) < 0.2 - && pNext->width / (float)g_ori_yuv_width < 0.2 && pNext->height / (float)g_ori_yuv_height < 0.2) { - - det_count = g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].detection_count; - for (int index_det = det_count - 1 - 1; index_det >= 0; index_det--) { - if (strlen(g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].prev_detections[index_det].name) >= 1 && - strcmp(g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].prev_detections[index_det].name, "object") != 0) - { - memset(pNext->name, 0x00, sizeof(pNext->name)); - strcpy(pNext->name, g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].prev_detections[index_det].name); - break; - } - } - - if (strcmp(heartbeatData.events_default_version, "4") == 0) { - if (pNext->height / pNext->width >= 1.15 && (pNext->width * pNext->height) / ((float)g_ori_yuv_width * (float)g_ori_yuv_height) < 0.05 && - pNext->width / (float)g_ori_yuv_width <= 0.05) { - memset(pNext->name, 0x00, sizeof(pNext->name)); - strcpy(pNext->name, "person"); - pNext->check_if_replaced_in_zone = 1; - } - else if (pNext->height / pNext->width <= 0.95 || ((float)g_ori_yuv_width * (float)g_ori_yuv_height) >= 0.05 || - pNext->width / (float)g_ori_yuv_width > 0.05) { - memset(pNext->name, 0x00, sizeof(pNext->name)); - strcpy(pNext->name, "car"); - pNext->check_if_replaced_in_zone = 1; - } - } - } - } - } - } - - ///開始做事件觸發UpdateZoneStatus - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - if (pNext->obj_tracking_id >= 1 && pNext->obj_tracking_id_idx >= 0 && !(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2)) - { - //if (strcmp(pNext->name, "object") == 0) - //{ - //if (strlen(pNext->replaced_name) >= 1) { - //strcpy(pNext->name, pNext->replaced_name); - //} - //} - - { - int k = pNext->obj_tracking_id_idx; - det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; - UpdateZoneStatus(pNext, tracking_channel_idx, k, det_count - 1, ratio_w, ratio_h, total_element_size, PosInfo, i); - } - } - } - - /////////-------------- - - for (int k = 0; k < MAX_TRACKING_NUM; k++) { - if (g_TrackingRecords[tracking_channel_idx][k].bAssign_flag == 0) { - det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; - if (det_count >= 1) { - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].disappear_count++; - } - g_TrackingRecords[tracking_channel_idx][k].disappear_count++; - } - } - -#if 1 - - int ZoneQueuingCount[MAX_DETECTION_ZONE] = { 0 }; - int ZoneGivewayCount[MAX_DETECTION_ZONE] = { 0 }; - for (int i = 0; i < MAX_DETECTION_ZONE; i++) { - ZoneQueuingCount[i] = 0; - ZoneGivewayCount[i] = 0; - } - - ////////----------Forget to give way detection 不禮讓偵測 - int index_zone_protect = -1; - int index_zone_keep_away = -1; - int index_zone_protect_2 = -1; - int index_zone_keep_away_2 = -1; - - if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect) == 1) { - index_zone_protect = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect); - } - - if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away) == 1) { - index_zone_keep_away = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away); - } - - if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect_2) == 1) { - index_zone_protect_2 = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_protect_2); - } - - if (strlen(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away_2) == 1) { - index_zone_keep_away_2 = atoi(viewChannelData[tracking_channel_idx].no_give_way_zone_to_keep_away_2); - } - - - if ((index_zone_protect >= 0 && index_zone_keep_away >= 0) || (index_zone_protect_2 >= 0 && index_zone_keep_away_2 >= 0)) { - for (int i = 0; i < viewChannelData[tracking_channel_idx].count_zone; i++) - { - for (int j = 0; j < total_element_size; j++) - { - pNext = PosInfo + j; - if (pNext->zone_check_giveway[i] == 1) - { - ZoneGivewayCount[i]++; - } - } - } - - if (index_zone_protect >= 0 && index_zone_keep_away >= 0) { - if (ZoneGivewayCount[index_zone_protect] >= 1 && ZoneGivewayCount[index_zone_keep_away] >= 1) { - for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { - unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][index_zone_keep_away].trigger_event[k].detect_event_id); - if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) { - for (int j = 0; j < total_element_size; j++) - { - pNext = PosInfo + j; - if (pNext->zone_check_giveway[index_zone_keep_away] == 1) - { - pNext->zone_violation_idx[index_zone_keep_away] = 1; - pNext->trigger_type = TRIGGER_FORGET_TO_GIVE_WAY | pNext->trigger_type; - pNext->trigger_idx[index_zone_keep_away] = k; - if (pNext->obj_tracking_id_idx >= 0) { - g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_type = pNext->trigger_type; - } - } - } - break; - } - } - } - } - - if (index_zone_protect_2 >= 0 && index_zone_keep_away_2 >= 0) { - if (ZoneGivewayCount[index_zone_protect_2] >= 1 && ZoneGivewayCount[index_zone_keep_away_2] >= 1) { - for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { - unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][index_zone_keep_away_2].trigger_event[k].detect_event_id); - if (trigger_event_type == TRIGGER_FORGET_TO_GIVE_WAY) { - for (int j = 0; j < total_element_size; j++) - { - pNext = PosInfo + j; - if (pNext->zone_check_giveway[index_zone_keep_away_2] == 1) - { - pNext->zone_violation_idx[index_zone_keep_away_2] = 1; - pNext->trigger_type = TRIGGER_FORGET_TO_GIVE_WAY | pNext->trigger_type; - pNext->trigger_idx[index_zone_keep_away_2] = k; - if (pNext->obj_tracking_id_idx >= 0) { - g_TrackingRecords[tracking_channel_idx][pNext->obj_tracking_id_idx].trigger_type = pNext->trigger_type; - } - } - } - break; - } - } - } - } - } - - ///計數器計算 - - /*end = clock(); - dur = (double)(end - start); - printf("\nGet Object Tracking ID New[5]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); - start = clock();*/ - for (int i = 0; i < viewChannelData[tracking_channel_idx].count_zone; i++) - { - for (int j = 0; j < total_element_size; j++) - { - pNext = PosInfo + j; - if (pNext->zone_violation_idx[i] == 1) - { - ZoneQueuingCount[i]++; - } - } - } - /* - end = clock(); - dur = (double)(end - start); - printf("\nGet Object Tracking ID New[6]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC)); - start = clock();*/ - for (int i = 0; i < viewChannelData[tracking_channel_idx].count_zone; i++) - { - /* - if (ZoneQueuingCount[i]>0) { - printf("\n---------------\n"); - printf("\nZoneQueuingCount[%d]:%d\n",i, ZoneQueuingCount[i]); - printf("\n---------------\n"); - }*/ - -#ifdef GY_OS_V_SERIES - int check_if_enable_linked_to_dwell_time = 0; - viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; -#else - int check_if_enable_linked_to_dwell_time = 0; - -#if 1 - for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { - if (viewDetectionZone[tracking_channel_idx][i].trigger_event[k].checked >= 1 && k == viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx) { - - char eachEventCounter[MAX_POST_EVENTS][STRSPLIT_SIZE] = { 0 }; - char Temp[MAX_MSG_LEN * 10] = { 0 }; - strcpy(Temp, viewDetectionZone[tracking_channel_idx][i].trigger_event[k].counter_name); - int event_counter_num = StrSplit(Temp, eachEventCounter, ","); - //printf("\n------UU:14\n"); - - for (int w = 0; w < event_counter_num; w++) - { - for (int m = 0; m < MAX_EVENT_COUNTERS; m++) - { - if (strlen(eachEventCounter[w]) >= 1 && strcmp(eachEventCounter[w], eventCounterList[m].counter_name) == 0) - { - if (strcmp(eventCounterList[m].enable_linked_to_dwell_time, "Yes") == 0) { - check_if_enable_linked_to_dwell_time = 1; - break; - } - } - } - if (check_if_enable_linked_to_dwell_time == 1) - break; - } - } - } -#endif -#endif - - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || - g_IsCustomWeight == 1) { - - if (viewDetectionZone[tracking_channel_idx][i].parking_space >= 1 && viewDetectionZone[tracking_channel_idx][i].parking_line >= 1) { - for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { - unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][i].trigger_event[k].detect_event_id); - if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) { - - if (viewDetectionZone[tracking_channel_idx][i].trigger_event[k].checked >= 1) { - viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx = k; - - int count_plot = 0; - for (int index_plot = 0; index_plot < viewDetectionZone[tracking_channel_idx][i].parking_space; index_plot++) - { - if (g_parking_space_check_table[i][index_plot] == 1) { - count_plot++; - } - } - - viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = count_plot; - - if (viewDetectionZone[tracking_channel_idx][i].prev_queuing_num >= viewDetectionZone[tracking_channel_idx][i].queuing_count - && viewDetectionZone[tracking_channel_idx][i].queuing_count >= 0) - { - for (int j = 0; j < total_element_size; j++) - { - pNext = PosInfo + j; - - int temp_m = -1; - if (pNext->zone_violation_idx[i] == 1) { - //pNext->trigger_type = (pNext->trigger_type | TRIGGER_QUEUING_VIOLATION); - pNext->trigger_type = TRIGGER_QUEUING_VIOLATION | pNext->trigger_type; - //pNext->detection_zone_idx = i; - pNext->trigger_idx[i] = k; - - for (int m = 0; m < MAX_TRACKING_NUM; m++) - { - if (g_TrackingRecords[tracking_channel_idx][m].obj_tracking_id == pNext->obj_tracking_id && pNext->obj_tracking_id > 0) - { - g_TrackingRecords[tracking_channel_idx][m].trigger_type = pNext->trigger_type; - g_TrackingRecords[tracking_channel_idx][m].trigger_zone_id = i + 1; - temp_m = m; - break; - } - } - } - - pNext->check_if_having_been_counted[i] = 0; - if(temp_m >= 0) - g_TrackingRecords[tracking_channel_idx][temp_m].check_if_having_been_counted[i] = 0; - } - } - else { - for (int j = 0; j < total_element_size; j++) - { - pNext = PosInfo + j; - if (pNext->zone_violation_idx[i] == 1) { - pNext->zone_violation_idx[i] = 0; - } - } - } - } - } - } - } - else{ - - if (check_if_enable_linked_to_dwell_time == 0) - { - viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; - } - - for (int k = 0; k < MAX_TRIGGER_EVENT; k++) { - unsigned int trigger_event_type = HexStringToInt(viewDetectionZone[tracking_channel_idx][i].trigger_event[k].detect_event_id); - if (trigger_event_type == TRIGGER_QUEUING_VIOLATION) { - - if (viewDetectionZone[tracking_channel_idx][i].trigger_event[k].checked >= 1 && k == viewDetectionZone[tracking_channel_idx][i].queuing_trigger_event_idx) { - - if (ZoneQueuingCount[i] >= viewDetectionZone[tracking_channel_idx][i].queuing_count - && viewDetectionZone[tracking_channel_idx][i].queuing_count >= 0) - { - viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; - - for (int j = 0; j < total_element_size; j++) - { - pNext = PosInfo + j; - if (pNext->zone_violation_idx[i] == 1) { - //pNext->trigger_type = (pNext->trigger_type | TRIGGER_QUEUING_VIOLATION); - pNext->trigger_type = TRIGGER_QUEUING_VIOLATION | pNext->trigger_type; - //pNext->detection_zone_idx = i; - pNext->trigger_idx[i] = k; - - for (int m = 0; m < MAX_TRACKING_NUM; m++) - { - if (g_TrackingRecords[tracking_channel_idx][m].obj_tracking_id == pNext->obj_tracking_id && pNext->obj_tracking_id > 0) - { - g_TrackingRecords[tracking_channel_idx][m].trigger_type = pNext->trigger_type; - break; - } - } - } - } - } - } - } - } - - } - } - else { - viewDetectionZone[tracking_channel_idx][i].prev_queuing_num = ZoneQueuingCount[i]; - } - } - /** - end = clock(); - dur = (double)(end - start); - printf("\nGet Object Tracking ID New[7]--------Use Time:%f\n", (dur / CLOCKS_PER_SEC));*/ -#endif - - check_record_if_overtime(); - if (get_g_check_if_show_parking() == 1) { - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - if (pNext->obj_tracking_id >= 1 && pNext->obj_tracking_id_idx >= 0 && !(strcmp(pNext->name, "object") == 0 && pNext->number_row == 2) - && pNext->check_if_replaced_in_zone == 1 && (int)pNext->obj_dwell_time >= 10) - { - if (strcmp(pNext->name, "object") != 0) { - if ((pNext->trigger_type & (unsigned int)TRIGGER_PARKING_VIOLATION) == (unsigned int)TRIGGER_PARKING_VIOLATION || - (pNext->trigger_type & (unsigned int)TRIGGER_MISSING_UNATTENDED) == (unsigned int)TRIGGER_MISSING_UNATTENDED || - (pNext->trigger_type & (unsigned int)TRIGGER_TAMPERING) == (unsigned int)TRIGGER_TAMPERING || - (pNext->trigger_type & (unsigned int)TRIGGER_QUEUING_VIOLATION) == (unsigned int)TRIGGER_QUEUING_VIOLATION || - (pNext->trigger_type & (unsigned int)TRIGGER_MISSING_OBJECT_DETECTION) == (unsigned int)TRIGGER_MISSING_OBJECT_DETECTION || - (pNext->trigger_type & (unsigned int)TRIGGER_ALL_OBJECTS) == (unsigned int)TRIGGER_ALL_OBJECTS || - (pNext->trigger_type & (unsigned int)TRIGGER_LACK_OF_ANY_OBJECT) == (unsigned int)TRIGGER_LACK_OF_ANY_OBJECT || - (pNext->trigger_type & (unsigned int)TRIGGER_FORGET_TO_GIVE_WAY) == (unsigned int)TRIGGER_FORGET_TO_GIVE_WAY) - { - clear_a_record_locked_ivs(pNext->left_x, pNext->top_y, pNext->width, pNext->height, g_ori_yuv_width, g_ori_yuv_height, pNext->name); - } - else { - set_a_record_locked_ivs(pNext->left_x, pNext->top_y, pNext->width, pNext->height, g_ori_yuv_width, g_ori_yuv_height, pNext->name); - } - } - } - } - } - - *total_element_size_temp = total_element_size; -} - -#ifdef GY_OS_WIN -unsigned int GetObjectSocialDistance(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx, IplImage* ipl_img, float distance_heigh, float distance_width) -{ - float x1 = viewDetectionZone[tracking_channel_idx][0].Points[0].x; - float y1 = viewDetectionZone[tracking_channel_idx][0].Points[0].y; - - float x2 = viewDetectionZone[tracking_channel_idx][0].Points[1].x; - float y2 = viewDetectionZone[tracking_channel_idx][0].Points[1].y; - - float x3 = viewDetectionZone[tracking_channel_idx][0].Points[2].x; - float y3 = viewDetectionZone[tracking_channel_idx][0].Points[2].y; - - float x4 = viewDetectionZone[tracking_channel_idx][0].Points[3].x; - float y4 = viewDetectionZone[tracking_channel_idx][0].Points[3].y; - - float d_x1, d_y1, d_x2, d_y2, d_x3, d_y3, d_x4, d_y4; - -#if 1 - CvPoint2D32f src_points[4]; - CvPoint2D32f dst_points[4]; - - float ratio_window_h, ratio_window_w; - ratio_window_h = ipl_img->height / CANVAS_HEIGHT; - ratio_window_w = ipl_img->width / CANVAS_WIDTH; - - - //window size -> real resultion of camera - x1 = x1 * ratio_window_w; - y1 = y1 * ratio_window_h; - - x2 = x2 * ratio_window_w; - y2 = y2 * ratio_window_h; - - x3 = x3 * ratio_window_w; - y3 = y3 * ratio_window_h; - - x4 = x4 * ratio_window_w; - y4 = y4 * ratio_window_h; - - - //x1 = (x1 / CANVAS_WIDTH) * 3840; - //y1 = (y1 / CANVAS_HEIGHT) * 2160; - - //x2 = (x2 / CANVAS_WIDTH) * 3840; - //y2 = (y2 / CANVAS_HEIGHT) * 2160; - - //x3 = (x3 / CANVAS_WIDTH) * 3840; - //y3 = (y3 / CANVAS_HEIGHT) * 2160; - - //x4 = (x4 / CANVAS_WIDTH) * 3840; - //y4 = (y4 / CANVAS_HEIGHT) * 2160; - - //d_x1 = (d_x1 / CANVAS_WIDTH) * 3840; - //d_y1 = (d_y1 / CANVAS_HEIGHT) * 2160; - //d_x2 = (d_x2 / CANVAS_WIDTH) * 3840; - //d_y2 = (d_y2 / CANVAS_HEIGHT) * 2160; - - //d_x3 = (d_x3 / CANVAS_WIDTH) * 3840; - //d_y3 = (d_y3 / CANVAS_HEIGHT) * 2160; - //d_x4 = (d_x4 / CANVAS_WIDTH) * 3840; - //d_y4 = (d_y4 / CANVAS_HEIGHT) * 2160; - - d_x1 = 0; - d_y1 = 0; - d_x2 = distance_width; - d_y2 = 0; - d_x3 = distance_width; - d_y3 = distance_heigh; - d_x4 = 0; - d_y4 = distance_heigh; - - src_points[0].x = x1; - src_points[0].y = y1; - src_points[1].x = x2; - src_points[1].y = y2; - - src_points[2].x = x3; - src_points[2].y = y3; - src_points[3].x = x4; - src_points[3].y = y4; - - - dst_points[0].x = d_x1; - dst_points[0].y = d_y1; - dst_points[1].x = d_x2; - dst_points[1].y = d_y2; - - dst_points[2].x = d_x3; - dst_points[2].y = d_y3; - dst_points[3].x = d_x4; - dst_points[3].y = d_y4; - - CvMat *M = cvCreateMat(3, 3, CV_32FC1); - cvGetPerspectiveTransform(src_points, dst_points, M); - - PerspectiveTransform(PosInfo, total_element_size, M, distance_heigh, distance_width, ipl_img->height, ipl_img->width); - -#if 0 - IplImage* dst = NULL; - CvSize ImageSize1 = cvSize(994, 364); - dst = cvCreateImage(ImageSize1, IPL_DEPTH_8U, 3); - cvZero(dst); - - CvScalar fillval = cvScalarAll(0); - - cvWarpPerspective(ipl_img, dst, M, CV_INTER_LINEAR, fillval); - cvNamedWindow("Affine_Transform", 1); - cvShowImage("Affine_Transform", dst); - - cvWaitKey(1); -#endif - //cvReleaseImage(&dst); - //cvReleaseMat(M); - cvReleaseMat(&M); -#endif -} -#endif //GY_OS_WIN - GetObjectSocialDistance - -void BindLicensePlateToVehicle(detection_pos* PosInfo, int total_element_size, int tracking_channel_idx) -{ - detection_pos* pNext = NULL; - detection_pos* pNext2 = NULL; - int BindNewLicensePlateOk = 0; - for (int i = 0; i < total_element_size; i++) - { - pNext = PosInfo + i; - - if (i == total_element_size - 1) - break; - - if (IsVehicleCategory(pNext) || IsMotorbikeCategory(pNext)) - { - //printf("tracking_channel_idx ==== %d \n", tracking_channel_idx); - for (int k = 0; k < MAX_TRACKING_NUM; k++) - { - if (g_TrackingRecords[tracking_channel_idx][k].obj_tracking_id == pNext->obj_tracking_id) - { - for (int j = i + 1; j < total_element_size; j++) - { - pNext2 = PosInfo + j; - if (IsANPRCategory(pNext2->engine_type) && pNext2->obj_type == _PLATE) - { - - if ((detection_overlap_ratio(pNext, pNext2) > 0.0 && (strcmp(pNext->name, "exhaust_ok") == 0 || strcmp(pNext->name, "exhaust_ng") == 0)) || detection_overlap_ratio(pNext, pNext2) > (90.0 / 100.0)) - { - if (strlen(pNext2->properties.plate) > strlen(g_TrackingRecords[tracking_channel_idx][k].linked_plate)) - { - int det_count = g_TrackingRecords[tracking_channel_idx][k].detection_count; - //StrReplace(pNext2->properties.plate, "-", ""); - - if (pNext2->properties.plate_length >= atoi(viewChannelData[0].min_characters) && - pNext2->properties.plate_length <= atoi(viewChannelData[0].max_characters)) { - strcpy(pNext->linked_plate, pNext2->properties.plate); - pNext->linked_plate_length = pNext2->properties.plate_length; - strcpy(g_TrackingRecords[tracking_channel_idx][k].linked_plate, pNext2->properties.plate); - g_TrackingRecords[tracking_channel_idx][k].linked_plate_length = pNext2->properties.plate_length; - - if (det_count > 0) - { - strcpy(g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].linked_plate, pNext2->properties.plate); - g_TrackingRecords[tracking_channel_idx][k].prev_detections[det_count - 1].linked_plate_length = pNext2->properties.plate_length; - } - - BindNewLicensePlateOk = 1; - } - } - break; - } - } - } - - if (!BindNewLicensePlateOk) { - if (g_TrackingRecords[tracking_channel_idx][k].linked_plate_length >= atoi(viewChannelData[0].min_characters) && - g_TrackingRecords[tracking_channel_idx][k].linked_plate_length <= atoi(viewChannelData[0].max_characters)) { - strcpy(pNext->linked_plate, g_TrackingRecords[tracking_channel_idx][k].linked_plate); - pNext->linked_plate_length = g_TrackingRecords[tracking_channel_idx][k].linked_plate_length; - } - } - } - } - } - } -} - -int number_of_digits(long long n) -{ - int count = 0; - while (n != 0) - { - // n = n/10 - n /= 10; - ++count; - } - return count; -} - -void check_license(int license, int adv_license, int bMacMatch, time_t start_time, time_t end_time, char* filename) -{ - pthread_mutex_lock(&mutex_check_license); - //printf("\n[check_license] start\n"); - //printf("\n[check_license] filename:%s\n", filename); - - //memset(strLicenseStatus, 0x00, sizeof(strLicenseStatus)); - - //#ifdef GY_OS_WIN - char* fileBuf = ReadAllBytes(filename); - if (fileBuf) { - cJSON *s_root, *tlt_code; - s_root = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - - if (s_root) { - tlt_code = cJSON_GetObjectItem(s_root, "TLT code"); //trial launch time - //cJSON* virtual_mac = cJSON_GetObjectItem(s_root, "VM code"); //virtual MAC - - //解碼上次執行時間 - step 1:base64 decode - size_t base64_decode_length = 0; - char EncryptKeyData[256]; - char DecryptKeyData[256]; - memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); - memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); - unsigned char OriEncryptData[512] = { 0 }; - - base64_decode(tlt_code->valuestring, strlen(tlt_code->valuestring), &base64_decode_length, OriEncryptData); - memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); - - //解碼上次執行時間 - step 2:AES descrytion - KeyExpansion(key, expandedKey); - AESDecryptArrayToArray(EncryptKeyData, base64_decode_length, expandedKey, DecryptKeyData, sizeof(DecryptKeyData)); - - //取得上次執行時間明碼資訊 - time_t last_launch_time = atoll(DecryptKeyData); - - //檢查本次與上次執行時間是否正確 - time_t now_time = g_osdSysTimeStamp; - - if (now_time < 1000000000) { - now_time = time(0); - } - - while (number_of_digits(last_launch_time) > number_of_digits(now_time)) { - last_launch_time /= 10; - } - - char strLaunchTime[16] = { 0 }; -#ifdef GY_OS_WIN - snprintf(strLaunchTime, sizeof(strLaunchTime), "%I64d", now_time); -#endif -#if defined GY_OS_AMBA || defined GY_OS_NOVA - //這邊要用lld,不能用ld,會有問題 - snprintf(strLaunchTime, sizeof(strLaunchTime), "%lld", (long long int)now_time); -#endif - //printf("\nstrLaunchTime:%s", strLaunchTime); -//#endif - - /*{ - char buff[20]; - struct tm * timeinfo; - timeinfo = localtime(&now_time); - strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); - printf("\nnow_time:%s", buff); - } - { - char buff[20]; - struct tm * timeinfo; - timeinfo = localtime(&start_time); - strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); - printf("\nstart_time:%s", buff); - } - { - char buff[20]; - struct tm * timeinfo; - timeinfo = localtime(&end_time); - strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); - printf("\nend_time:%s", buff); - } - { - char buff[20]; - struct tm * timeinfo; - timeinfo = localtime(&last_launch_time); - strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo); - printf("\nlast_launch_time:%s", buff); - }*/ - - //printf("\n--------------license:%d\n", license); - - if (license == 0 && check_if_fe_fail == 0) - { - licenseType = _NO_LICENSE; - afsCode = _NOT_LICENSED; - strcpy(strLicenseStatus, "Invalid license"); - printf("\n[check_license] Invalid license:%d\n", licenseType); - } - else if (check_if_fe_fail == 1 || license == _PERMANENT_LICENSE_MULTI || license == _PERMANENT_LICENSE_SINGLE || license == _PERMANENT_LICENSE_MULTI_POST || license == _PERMANENT_LICENSE_SINGLE_POST || - license == _LICENSE_FPS06 || license == _LICENSE_FPS12 || license == _LICENSE_FPS18 || license == _LICENSE_FPS24 || license == _LICENSE_FPS30 || - license == _LICENSE_FPS36 || license == _LICENSE_FPS42 || license == _LICENSE_FPS48 || license == _LICENSE_FPS54 || license == _LICENSE_FPS60) - { - - switch (license) - { - case _PERMANENT_LICENSE_MULTI: - licenseType = _PERMANENT_LICENSE_MULTI; - http_license_fps = 60; - break; - case _PERMANENT_LICENSE_SINGLE: - licenseType = _PERMANENT_LICENSE_SINGLE; - break; - case _PERMANENT_LICENSE_MULTI_POST: - licenseType = _PERMANENT_LICENSE_MULTI_POST; - break; - case _PERMANENT_LICENSE_SINGLE_POST: - licenseType = _PERMANENT_LICENSE_SINGLE_POST; - break; - case _LICENSE_FPS06: - licenseType = _LICENSE_FPS06; - http_license_fps = 6; - break; - case _LICENSE_FPS12: - licenseType = _LICENSE_FPS12; - http_license_fps = 12; - break; - case _LICENSE_FPS18: - licenseType = _LICENSE_FPS18; - http_license_fps = 18; - break; - case _LICENSE_FPS24: - licenseType = _LICENSE_FPS24; - http_license_fps = 24; - break; - case _LICENSE_FPS30: - licenseType = _LICENSE_FPS30; - http_license_fps = 30; - break; - case _LICENSE_FPS36: - licenseType = _LICENSE_FPS36; - http_license_fps = 36; - break; - case _LICENSE_FPS42: - licenseType = _LICENSE_FPS42; - http_license_fps = 42; - break; - case _LICENSE_FPS48: - licenseType = _LICENSE_FPS48; - http_license_fps = 48; - break; - case _LICENSE_FPS54: - licenseType = _LICENSE_FPS54; - http_license_fps = 54; - break; - case _LICENSE_FPS60: - licenseType = _LICENSE_FPS60; - http_license_fps = 60; - break; - default: - licenseType = _LICENSE_FPS06; - http_license_fps = 6; - } - - switch (adv_license) - { - case _AD_LICENSE_BASIC: - advLicenseType = _AD_LICENSE_BASIC; - break; - case _AD_LICENSE_01: - advLicenseType = _AD_LICENSE_01; - break; - default: - advLicenseType = _AD_LICENSE_BASIC; - } - - if (!bMacMatch) - { - afsCode = _MAC_MISMATCH; - strcpy(strLicenseStatus, "License mismatch the system ID"); - } - else - { - afsCode = _LICENSED; - strcpy(strLicenseStatus, "Licensed."); - } - } - else if (license == _TRIAL_LICENSE_MULTI || license == _TRIAL_LICENSE_SINGLE || - license == _TRIAL_LICENSE_FPS06 || license == _TRIAL_LICENSE_FPS12 || license == _TRIAL_LICENSE_FPS18 || license == _TRIAL_LICENSE_FPS24 || license == _TRIAL_LICENSE_FPS30 || - license == _TRIAL_LICENSE_FPS36 || license == _TRIAL_LICENSE_FPS42 || license == _TRIAL_LICENSE_FPS48 || license == _TRIAL_LICENSE_FPS54 || license == _TRIAL_LICENSE_FPS60) - { - - switch (license) - { - case _TRIAL_LICENSE_MULTI: - licenseType = _TRIAL_LICENSE_MULTI; - http_license_fps = 60; - break; - case _TRIAL_LICENSE_SINGLE: - licenseType = _TRIAL_LICENSE_SINGLE; - break; - case _TRIAL_LICENSE_FPS06: - licenseType = _TRIAL_LICENSE_FPS06; - http_license_fps = 6; - break; - case _TRIAL_LICENSE_FPS12: - licenseType = _TRIAL_LICENSE_FPS12; - http_license_fps = 12; - break; - case _TRIAL_LICENSE_FPS18: - licenseType = _TRIAL_LICENSE_FPS18; - http_license_fps = 18; - break; - case _TRIAL_LICENSE_FPS24: - licenseType = _TRIAL_LICENSE_FPS24; - http_license_fps = 24; - break; - case _TRIAL_LICENSE_FPS30: - licenseType = _TRIAL_LICENSE_FPS30; - http_license_fps = 30; - break; - case _TRIAL_LICENSE_FPS36: - licenseType = _TRIAL_LICENSE_FPS36; - http_license_fps = 36; - break; - case _TRIAL_LICENSE_FPS42: - licenseType = _TRIAL_LICENSE_FPS42; - http_license_fps = 42; - break; - case _TRIAL_LICENSE_FPS48: - licenseType = _TRIAL_LICENSE_FPS48; - http_license_fps = 48; - break; - case _TRIAL_LICENSE_FPS54: - licenseType = _TRIAL_LICENSE_FPS54; - http_license_fps = 54; - break; - case _TRIAL_LICENSE_FPS60: - licenseType = _TRIAL_LICENSE_FPS60; - http_license_fps = 60; - break; - default: - licenseType = _TRIAL_LICENSE_FPS06; - http_license_fps = 6; - } - - switch (adv_license) - { - case _AD_LICENSE_BASIC: - advLicenseType = _AD_LICENSE_BASIC; - break; - case _AD_LICENSE_01: - advLicenseType = _AD_LICENSE_01; - break; - default: - advLicenseType = _AD_LICENSE_BASIC; - } - - if (!bMacMatch) - { - afsCode = _MAC_MISMATCH; - strcpy(strLicenseStatus, "Trial mismatch the system ID"); - } - else if (now_time < start_time-3600*24) - { - afsCode = _UNINITIALIZED; - strcpy(strLicenseStatus, "Trial has expired. Trial not initialized."); //Trial not initialized - } - else if (last_launch_time- 3600 * 24 > now_time) //若前次時間大於本次時間, 表示系統時間被修改過 - { - printf("\n------------------[Incorrect system time detected]-------------------\n"); - char msg_temp[512] = { 0 }; - printf("\nlast_launch_time: %lld , now_time: %lld\n", (long long int)last_launch_time, (long long int)now_time); - sprintf(msg_temp,"last_launch_time: %lld , now_time: %lld", (long long int)last_launch_time, (long long int)now_time); - afsCode = _EXPIRED; - strcpy(strLicenseStatus, "Trial has expired. Incorrect system time detected."); - strcat(strLicenseStatus, msg_temp); - now_time = last_launch_time; - } - else if (now_time > end_time+3600*24) - { - afsCode = _EXPIRED; - strcpy(strLicenseStatus, "Trial has expired"); - } - else - { - afsCode = _LICENSED; - char Msg[256] = { 0 }; - double diffDays = difftime(end_time, now_time) / (60 * 60 * 24); - if (diffDays < 0) - diffDays = 0; - snprintf(Msg, sizeof(Msg), "Licensed(%d days left)", (int)diffDays); - strcpy(strLicenseStatus, Msg); - } - } - - //#ifdef GY_OS_WIN - //將本次執行時間加密, 寫入檔案 - if (!(last_launch_time > now_time)) - { - //printf("\n[check_license] write file\n"); - KeyExpansion(key, expandedKey); - unsigned char EncryptData[1 * 1024]; - memset(EncryptData, 0x00, sizeof(EncryptData)); - int encryptSize = AESEncryptArrayToArray(strLaunchTime, strlen(strLaunchTime), expandedKey, EncryptData, sizeof(EncryptData)); - - size_t base64_encode_length = 0; - char launchTime[1024] = { 0 }; - base64_encode(EncryptData, encryptSize, &base64_encode_length, launchTime); - *(launchTime + base64_encode_length) = '\0'; - - cJSON_ReplaceItemInObject(s_root, "TLT code", cJSON_CreateString(launchTime)); - char* JsonString = cJSON_Print(s_root); - - FILE *f = fopen(filename, "w"); - if (f == NULL) - { - printf("---------------------------Error opening setting file!-----------------------------\n"); -#if 1 - stop_test_nn_cavalry("Error opening setting file!"); - //stop_server(); - -#endif - //exit(EXIT_FAILURE); - } - else { - fprintf(f, "%s\n", JsonString); - fclose(f); - } - - if (JsonString) { - free(JsonString); - JsonString = NULL; - } - } - - if (s_root) { - cJSON_Delete(s_root); - s_root = NULL; - } - //#endif - - stAMBAcontent.licenseType = licenseType; - stAMBAcontent.afsCode = afsCode; - stAMBAcontent.advLicenseType = advLicenseType; - - //printf("\n-------strLicenseStatus:%s\n", strLicenseStatus); - - //printf("\n[check_license] licenseType:%d %d %d\n", licenseType, afsCode,advLicenseType); - } - } - - pthread_mutex_unlock(&mutex_check_license); -} - -void SetDatasetCategory(int licenseType, char* strDatasetCategory) -{ - switch (licenseType) - { - case _PERMANENT_LICENSE_MULTI: - case _LICENSE_FPS06: - case _LICENSE_FPS12: - case _LICENSE_FPS18: - case _LICENSE_FPS24: - case _LICENSE_FPS30: - case _LICENSE_FPS36: - case _LICENSE_FPS42: - case _LICENSE_FPS48: - case _LICENSE_FPS54: - case _LICENSE_FPS60: - sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI - break; - case _PERMANENT_LICENSE_SINGLE: - sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI - break; - case _TRIAL_LICENSE_MULTI: - case _TRIAL_LICENSE_FPS06: - case _TRIAL_LICENSE_FPS12: - case _TRIAL_LICENSE_FPS18: - case _TRIAL_LICENSE_FPS24: - case _TRIAL_LICENSE_FPS30: - case _TRIAL_LICENSE_FPS36: - case _TRIAL_LICENSE_FPS42: - case _TRIAL_LICENSE_FPS48: - case _TRIAL_LICENSE_FPS54: - case _TRIAL_LICENSE_FPS60: - sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI - break; - case _TRIAL_LICENSE_SINGLE: - sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI - break; - case _PERMANENT_LICENSE_MULTI_POST: - sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI - break; - case _PERMANENT_LICENSE_SINGLE_POST: - sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI - break; - default: - sprintf(strDatasetCategory, "%s", "EDGELPR");//06AI - } -} - -void check_feature() -{ - char strDatasetCategory[MAX_MSG_LEN] = { 0 }; - char *strDatasetCountry = NULL; - memset(strLicenseType, 0x00, sizeof(strLicenseType)); - int nHasFeature = 0; - - if (!(td_weight_num >= 1 && check_if_correct_mail == 1) && - g_IsRadarDevice == 0 && - g_IsToFDevice == 0 && - unlockingKeyInnoFR_success == 0) { - if (!IsExistingWeight(featureType, featureType2)) { - sprintf(strLicenseType, " Weight Error:"); - } - } - - if (g_match_mac == 1 || unlockingKeyInnoFR == 1) { - - if (g_IsHelm_without_car == 1) { - - } - else { - - if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA)) - { -#ifdef GY_OS_NOVA - sprintf(strDatasetCategory, "%s", "EDGEFENCE (Home Security)");//01AI -#endif -#ifdef GY_OS_AMBA - sprintf(strDatasetCategory, "%s", "EDGEFLOW (Home Security)");//01AI -#endif - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) - { -#ifdef GY_OS_NOVA - sprintf(strDatasetCategory, "%s", "EDGEDENSITY (Flow Counter)");//03AI -#endif -#ifdef GY_OS_AMBA - sprintf(strDatasetCategory, "%s", "EDGECAP (Flow Counter)");//03AI -#endif - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - - } - - if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0){ - sprintf(strDatasetCategory, "%s", "EDGEGARBAGE (Garbage Recognition)"); - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - - if ((featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) - { - sprintf(strDatasetCategory, "%s", "EDGERAIL (Rail Security)"); - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) - { - sprintf(strDatasetCategory, "%s", "EDGESPORTS (Sports Recognition)"); - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE) - { - sprintf(strDatasetCategory, "%s", "EDGEFIRE (Environment Safety)");//05AI - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) - { - sprintf(strDatasetCategory, "%s", "EDGEAERO (Aero Recognition)"); - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - //printf("\nFEATURE_HUM_DET---6\n"); - if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) - { - sprintf(strDatasetCategory, "%s", "EDGESAFTY (Construction Site Safety)");//04AI - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - //printf("\nFEATURE_HUM_DET---7\n"); - if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) - { - if (strcmp(WeightFileModeName, "mod003") != 0) { - sprintf(strDatasetCategory, "%s", "EDGEMASK (Health Care)");//02AI - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - else { - sprintf(strDatasetCategory, "%s", "EDGEGENDER (Human gender)");//02AI - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - } - - if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) - { - sprintf(strDatasetCategory, "%s", "EDGEVESSEL (Vessel Recognition)");//08AI - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - - if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) - { - - sprintf(strDatasetCategory, "%s", "EDGEPRODUCTION (Production Line)"); - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - - if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) - { - if (strcmp(WeightFileModeName, "mod003") != 0) { - sprintf(strDatasetCategory, "%s", "EDGEANIMAL (Animal Recognition)");//09AI - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - else { - sprintf(strDatasetCategory, "%s", "EDGEFRONTBACK (Car Front & Back)");//09AI - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - } - - //printf("\nFEATURE_HUM_DET---8\n"); - if ((featureType & FEATURE_POK_DET) != 0) - { - sprintf(strDatasetCategory, "%s", "Poker pattern recognition"); - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_HUM_POS) != 0) - { - sprintf(strDatasetCategory, "%s", "Human pose estimator"); - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_LED_DGT) != 0) - { - sprintf(strDatasetCategory, "%s", "LED digits recognition"); - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_SHOES_DET) != 0) - { - sprintf(strDatasetCategory, "%s", "Shoes recognition"); - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_LPR_LOGO) != 0) - { - sprintf(strDatasetCategory, "%s", "EDGECARMAKE (Car Make)");//07AI - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_LPR_TWN) != 0) - { - SetDatasetCategory(licenseType, strDatasetCategory); - strDatasetCountry = "TW/EC (Taiwan, Ecuador)"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, "-"); - strcat(strLicenseType, strDatasetCountry); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_LPR_EUR) != 0) - { - SetDatasetCategory(licenseType, strDatasetCategory); - strDatasetCountry = "EU (Belgium, Italy, Croatia, France, Turkey, Germany, Spain, Portugal, Slovenia)"; //European //EU/UK/IN - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, "-"); - strcat(strLicenseType, strDatasetCountry); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_LPR_SEA) != 0 || - (featureType & FEATURE_LPR_VNM) != 0 || - (featureType & FEATURE_LPR_IDN) != 0) - { - SetDatasetCategory(licenseType, strDatasetCategory); - strDatasetCountry = "MY/HK/SG/VN/ID (Malaysia, Hong Kong, Singapore, Vietnam, Indonesia)";//South East Asia - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, "-"); - strcat(strLicenseType, strDatasetCountry); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - - /* - if ((featureType & FEATURE_LPR_CNA) != 0) - { - SetDatasetCategory(licenseType, strDatasetCategory); - strDatasetCountry = "China"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, "-"); - strcat(strLicenseType, strDatasetCountry); - strcat(strLicenseType, ","); - nHasFeature = 1; - }*/ - if ((featureType & FEATURE_LPR_MEA) != 0) - { - SetDatasetCategory(licenseType, strDatasetCategory); - strDatasetCountry = "AE/SA (UAE, Saudi Arabia)";//Middle East Asia - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, "-"); - strcat(strLicenseType, strDatasetCountry); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_LPR_USA) != 0) - { - SetDatasetCategory(licenseType, strDatasetCategory); - strDatasetCountry = "US/CA (50 states, Guam, Canada)"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, "-"); - strcat(strLicenseType, strDatasetCountry); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_LPR_AUS) != 0) - { - SetDatasetCategory(licenseType, strDatasetCategory); - strDatasetCountry = "AU (Australia)"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, "-"); - strcat(strLicenseType, strDatasetCountry); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_LPR_GBR) != 0) - { - SetDatasetCategory(licenseType, strDatasetCategory); - strDatasetCountry = "GB/IN (UK, India)"; //UK/IN //United Kingdom - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, "-"); - strcat(strLicenseType, strDatasetCountry); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_LPR_JPN) != 0) - { - SetDatasetCategory(licenseType, strDatasetCategory); - strDatasetCountry = "JP (Japan)"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, "-"); - strcat(strLicenseType, strDatasetCountry); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - - - if ((featureType & FEATURE_LPR_THA) != 0) - { - SetDatasetCategory(licenseType, strDatasetCategory); - strDatasetCountry = "TH (Thailand)"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, "-"); - strcat(strLicenseType, strDatasetCountry); - strcat(strLicenseType, ","); - nHasFeature = 1; - }/* - if ((featureType & FEATURE_LPR_LAO) != 0) - { - SetDatasetCategory(licenseType, strDatasetCategory); - strDatasetCountry = "Laos"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, "-"); - strcat(strLicenseType, strDatasetCountry); - strcat(strLicenseType, ","); - nHasFeature = 1; - }*/ - if ((featureType & FEATURE_LPR_BGD) != 0) - { - SetDatasetCategory(licenseType, strDatasetCategory); - strDatasetCountry = "BD (Bangladesh)"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, "-"); - strcat(strLicenseType, strDatasetCountry); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - if ((featureType & FEATURE_LPR_PHL) != 0) - { - SetDatasetCategory(licenseType, strDatasetCategory); - strDatasetCountry = "PH (Philippines)"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, "-"); - strcat(strLicenseType, strDatasetCountry); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - - if ((featureType & FEATURE_LPR_CNT) != 0) - { - SetDatasetCategory(licenseType, strDatasetCategory); - strDatasetCountry = "CNT (Container)"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, "-"); - strcat(strLicenseType, strDatasetCountry); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - - if (td_weight_num >= 1 && check_if_correct_mail == 1) { - char *strDatasetCategory = "Third Party"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - - if (g_IsRadarDevice == 1) { - char *strDatasetCategory = "EDGERADAR (Radar Recognition)"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - - if (g_IsToFDevice == 1) - { - char *strDatasetCategory = "EDGETOF (ToF Recognition)"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - nHasFeature = 1; - } - - if (unlockingKeyInnoFR_success == 1) { - char *strDatasetCategory = "EDGEFACE (Face Recognition)"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - //printf("setting License Type : EDGEFACE (Face Recognition)\n"); - //printf("srtLicenseType = %s\n", strLicenseType); - - nHasFeature = 1; - } - - if (!nHasFeature) - { - char *strDatasetCategory = "No license"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - } - //printf("srtLicenseType = %s\n", strLicenseType); - //printf("featureType = %d\n", featureType); - //printf("featureType2 = %d\n", featureType2); - } - else{ - char *strDatasetCategory = "Mac address is not supported"; - strcat(strLicenseType, " "); - strcat(strLicenseType, strDatasetCategory); - strcat(strLicenseType, ","); - } -} - -//void stop_detector() -//{ -// bHttpServerThreadStart = 0; -//} - -//20201027 sophia add -/* -command: -/usr/local/bin/nvclient -k user.password0 -/usr/local/bin/nvclient -k user.account0 -... -/usr/local/bin/nvclient -k user.password9 -/usr/local/bin/nvclient -k user.account9 - -return : -NVRAM Client, Version:1.0.0 -Get nvram data, ret:0 -Key=user.account0 -Data=admin -TStamp=172 -Max data size=32 -*/ - -//#if defined GY_OS_AMBA - -void get_image_dn() { - - { - if (imageDnData.color_mode == 1) { - imageDnData.last_day_or_night_mode = imageDnData.current_day_or_night_mode; - imageDnData.current_day_or_night_mode = 1; - - for (int i = MAX_SIZE_SWITCH_HAPPENED - 1; i >= 1; i--) { - imageDnData.check_if_switch_happened[i] = imageDnData.check_if_switch_happened[i - 1]; - } - if (imageDnData.last_day_or_night_mode >= 1 && imageDnData.last_day_or_night_mode != imageDnData.current_day_or_night_mode) { - imageDnData.check_if_switch_happened[0] = 1; - usSleep(2500000); - } - else { - imageDnData.check_if_switch_happened[0] = 0; - } - } - else if (imageDnData.color_mode == 2) { - imageDnData.last_day_or_night_mode = imageDnData.current_day_or_night_mode; - imageDnData.current_day_or_night_mode = 2; - - for (int i = MAX_SIZE_SWITCH_HAPPENED - 1; i >= 1; i--) { - imageDnData.check_if_switch_happened[i] = imageDnData.check_if_switch_happened[i - 1]; - } - if (imageDnData.last_day_or_night_mode >= 1 && imageDnData.last_day_or_night_mode != imageDnData.current_day_or_night_mode) { - imageDnData.check_if_switch_happened[0] = 1; - usSleep(2500000); - } - else { - imageDnData.check_if_switch_happened[0] = 0; - } - } - - //printf("\n-----------imageDnData.check_if_switch_happened[0]:%d\n", imageDnData.check_if_switch_happened[0]); - } -} - -int get_check_if_existing_any_switch_happened() { - int rtn = 0; - for (int i = 0; i < MAX_SIZE_SWITCH_HAPPENED; i++) { - if (imageDnData.check_if_switch_happened[i] == 1) { - rtn = 1; - break; - } - } - return rtn; -} - -//#endif - -//20201027 sophia add -void update_config_account_setting(void) -{ - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - //printf("Program binary path is: %s\n", buf); - - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char configPATH[1024] = { 0 }; - char config_bakPATH[1024] = { 0 }; - - strcpy(configPATH, exePath); - strcpy(config_bakPATH, exePath); - - strcat(configPATH, "config.json"); - strcat(config_bakPATH, "config_bak.json"); - - //post events setting - //char filename[] = "config.json"; - char* filename; - filename = configPATH; - if (!FileExist(filename)) - { - printf("%s doesn't exist.\n", filename); - } - else { - //printf("read config.json.\n"); - -#if 1 - char* fileBuf = ReadAllBytes(filename); - if (fileBuf) { - cJSON* root, *account_setting; - root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } -#if 1 - account_setting = cJSON_GetObjectItem(root, "account_setting"); - if (root) { - //printf("config.json parse OK.1\n"); - cJSON* account_data_array, *content; - cJSON* account_username, *account_password, *account_type, *account_status; - account_data_array = cJSON_CreateArray(); - -#if 1 - for (int i = 0; i < MAX_ACCOUNT_DATA_NUM; i++) - { - content = cJSON_CreateObject(); - cJSON_AddItemToArray(account_data_array, content); - - char buf_account[512] = { 0 }; - urldecode((unsigned char *)accountData[i].account_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)accountData[i].account_password, (unsigned char *)buf_account2); - - account_username = cJSON_CreateString(buf_account); - cJSON_AddItemToObject(content, "account_username", account_username); - account_password = cJSON_CreateString(buf_account2); - cJSON_AddItemToObject(content, "account_password", account_password); - account_type = cJSON_CreateNumber(accountData[i].account_type); - cJSON_AddItemToObject(content, "account_type", account_type); - account_status = cJSON_CreateNumber(accountData[i].account_status); - cJSON_AddItemToObject(content, "account_status", account_status); - - } - usSleep(2000); - size_t base64_encode_length = 0; - unsigned char EncryptKeyData[MAX_ACCOUNT_DATA_BUFF_SIZE]; - memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); - - char* AccountJsonString = cJSON_Print(account_data_array); - //printf("\n--------------AccountJsonString: %s\n", AccountJsonString); - - KeyExpansion(key, expandedKey); - size_t encryptSize = AESEncryptArrayToArray(AccountJsonString, strlen(AccountJsonString), expandedKey, EncryptKeyData, sizeof(EncryptKeyData)); - - char ResultEncryptData[MAX_ACCOUNT_DATA_BUFF_SIZE] = { 0 }; - base64_encode(EncryptKeyData, encryptSize, &base64_encode_length, ResultEncryptData); - *(ResultEncryptData + base64_encode_length) = '\0'; - - usSleep(2000); - - cJSON_ReplaceItemInObject(account_setting, "account_data", cJSON_CreateString((const char *)ResultEncryptData)); - - if (AccountJsonString) { - free(AccountJsonString); - AccountJsonString = NULL; - } - - //save back to config.json & bak - char* JsonString = cJSON_Print(root); - FILE* fp; - if ((fp = fopen(filename, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - - //copy config.json to config_bak.json - CopyFileTo(filename, config_bakPATH); - } - else - { - //fclose(fp); - printf("Fail to open Config.json \n"); - } -#endif - if (root) { - //cJSON_Delete(root); - cJSON_Delete(root); - root = NULL; - } -#if 1 - - if (account_data_array != NULL) { - for (int i = 0; i < MAX_ACCOUNT_DATA_NUM; i++) - { - cJSON_DeleteItemFromArray(account_data_array,i); - } - cJSON_free(account_data_array); - account_data_array = NULL; - } -#endif -#if 1 - if (JsonString != NULL) { - free(JsonString); - JsonString = NULL; - } -#endif - usSleep(2000); - } - else - printf("config.json parse FAIL.1\n"); -#endif - } -#endif - } -} - -void update_accountData() { - int count_username = 0; -#ifdef GY_OS_AMBA - for (int i = 0; i < MAX_ACCOUNT_DATA_NUM * 2 + 4; i++) -#else - for (int i = 0; i < MAX_ACCOUNT_DATA_NUM * 2 + 5; i++) -#endif - { - if (i == MAX_ACCOUNT_DATA_NUM) - count_username = 0; - - FILE *fp = NULL; - char path[1024] = { 0 }; - char command[1024] = { 0 }; - const char *find = "Data="; - int find_len = 5; - - memset(path, 0, sizeof(path)); - memset(command, 0, sizeof(command)); -#ifdef GY_OS_AMBA - if (i < MAX_ACCOUNT_DATA_NUM) - sprintf(command, "timeout 3s /usr/local/bin/nvclient -k user.account%d", i); - else if (i >= MAX_ACCOUNT_DATA_NUM && i < MAX_ACCOUNT_DATA_NUM * 2) - sprintf(command, "timeout 3s /usr/local/bin/nvclient -k user.password%d", i - MAX_ACCOUNT_DATA_NUM); - else if (i == MAX_ACCOUNT_DATA_NUM * 2) - sprintf(command, "timeout 3s /usr/local/bin/nvclient -k image.mirror"); - else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 1) - sprintf(command, "timeout 3s /usr/local/bin/nvclient -k image.flip"); - else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 2) - sprintf(command, "timeout 3s /usr/local/bin/nvclient -k image.rotate"); - else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 3) - sprintf(command, "timeout 3s /usr/local/bin/nvclient -k FEATURE_SYS_DUAL_SENSOR"); -#else - if (i < MAX_ACCOUNT_DATA_NUM) - sprintf(command, "/usr/local/bin/nvclient -k user.account%d", i); - else if (i >= MAX_ACCOUNT_DATA_NUM && i < MAX_ACCOUNT_DATA_NUM * 2) - sprintf(command, "/usr/local/bin/nvclient -k user.password%d", i - MAX_ACCOUNT_DATA_NUM); - else if (i == MAX_ACCOUNT_DATA_NUM * 2) - sprintf(command, "/usr/local/bin/nvclient -k image.mirror"); - else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 1) - sprintf(command, "/usr/local/bin/nvclient -k image.flip"); - else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 2) - sprintf(command, "/usr/local/bin/nvclient -k image.rotate"); - else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 3) - sprintf(command, "/usr/local/bin/nvclient -k features.irled.type"); - else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 4) - sprintf(command, "/usr/local/bin/nvclient -k features.irled2.type"); -#endif - - - -#ifdef _DEBUG_AMBA - printf("\n[read_ipcam_account_setting] i:%d - command:%s", i, command); -#endif - - /* Open the command for reading.*/ - fp = vpopen(command, "r"); - if (fp == NULL) { - fp = vpopen(command, "r"); - } - - if (fp == NULL) - { - - printf("\nFailed to run command: %s\n", command); - printf("Error opening file unexist.ent: %s\n", strerror(errno)); - - char fail_buffer[2048] = { 0 }; - sprintf(fail_buffer, "\nFailed to run command: %s\n", command); - write_to_log_if_error_nvclient(fail_buffer); - - //write_to_log_if_error(fail_buffer); - /* - pthread_t auto_reboot_thread_id; - if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) - { - printf("create auto reboot thread faile \n"); - }*/ - } - else { - /* Read the output a line at a time - output it.*/ - while (fgets(path, sizeof(path), fp) != NULL) - { - char *p = strstr(path, find); - int cpy_len = (strlen(path) - find_len - 1);//avoid copy \n - //printf("\n(%d):cpylen:%d\n",i,cpy_len); - if (p != NULL && cpy_len >= 1) - { - char *cpy_start = p + find_len; - -#ifdef _DEBUG_AMBA - printf("\n%s strlen(path):%d", p + find_len, strlen(path)); -#endif - - if (cpy_len >= 1) { - char temp_cpy[100] = { 0 }; - strncpy(temp_cpy, cpy_start, cpy_len); - temp_cpy[cpy_len] = '\0'; - - if (i < MAX_ACCOUNT_DATA_NUM) { - if (strstr(temp_cpy, " ") == NULL) { - char temp_account[512] = { 0 }; - urlencode((unsigned char *)temp_cpy, cpy_len, (unsigned char *)temp_account,512); - memcpy(accountData[count_username].account_username, temp_account, strlen(temp_account)); - accountData[count_username].account_username[strlen(temp_account)] = '\0'; - } - count_username++; - } - else if (i >= MAX_ACCOUNT_DATA_NUM && i < MAX_ACCOUNT_DATA_NUM * 2) { - if (strstr(temp_cpy, " ") == NULL) { - char temp_account[512] = { 0 }; - urlencode((unsigned char *)temp_cpy, cpy_len, (unsigned char *)temp_account, 512); - memcpy(accountData[count_username].account_password, temp_account, strlen(temp_account)); - accountData[count_username].account_password[strlen(temp_account)] = '\0'; - } - count_username++; - } - else if (i == MAX_ACCOUNT_DATA_NUM * 2) { - //if (g_IsPTZDevice == 0) - { - if (strstr(temp_cpy, " ") == NULL) { - strncpy(accountData[0].account_mirror, temp_cpy, cpy_len); - accountData[0].account_mirror[cpy_len] = '\0'; - } - } - } - else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 1) { - //if (g_IsPTZDevice == 0) - { - if (strstr(temp_cpy, " ") == NULL) { - strncpy(accountData[0].account_flip, temp_cpy, cpy_len); - accountData[0].account_flip[cpy_len] = '\0'; - } - } - } - else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 2) { - //if (g_IsPTZDevice == 0) - { - if (strstr(temp_cpy, " ") == NULL) { - strncpy(accountData[0].account_rotate, temp_cpy, cpy_len); - accountData[0].account_rotate[cpy_len] = '\0'; - } - } - } - else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 3) { - //if (g_IsPTZDevice == 0) - if(strstr(temp_cpy,"1") != NULL) - { -#ifdef GY_OS_AMBA - g_dual_sensor = 1; -#else - g_camera_white_LED = 1; -#endif - } - } - else if (i == MAX_ACCOUNT_DATA_NUM * 2 + 4) { - //if (g_IsPTZDevice == 0) - if (strstr(temp_cpy, "1") != NULL) - { - g_camera_white_LED = 1; - } - } - } - - break; - } - - memset(path, 0, sizeof(path)); - } - if (fp != NULL) { - if (vpclose(fp) < 0) - printf("\nupdate accountData: vpclose fail\n"); - fp = NULL; - } - } - - usSleep(1000); - } -} - -void update_accountData_port() { - char read_port_cmd[1024]; - memset(&read_port_cmd, 0, sizeof(read_port_cmd)); - -#ifdef GY_OS_AMBA - char read_port_cmd_1[256] = "timeout 3s /usr/local/bin/nvclient -k http.port"; -#else - char read_port_cmd_1[256] = "/usr/local/bin/nvclient -k http.port"; -#endif - strcat(read_port_cmd, read_port_cmd_1); - - FILE *read_port = vpopen(read_port_cmd, "r"); - if (read_port == NULL) - { - printf("\n[read_ipcam_account_setting]:Error to read port"); - } - else - { - const char *find = "Data="; - int find_len = 5; - char path[1024] = { 0 }; - - /* Read the output a line at a time - output it.*/ - while (fgets(path, sizeof(path), read_port) != NULL) - { - char *p = strstr(path, find); - int cpy_len = (strlen(path) - find_len - 1);//avoid copy \n - - if (p != NULL && cpy_len > 0) - { - char *cpy_start = p + find_len; - - if (cpy_len >= 1) { - strncpy(accountData[0].account_port, cpy_start, cpy_len); - accountData[0].account_port[cpy_len] = '\0'; - } - - //printf("\n[read_ipcam_account_setting]:Correct to read port %s\n",accountData[0].account_port); - break; - } - memset(path, 0, sizeof(path)); - } - if (read_port != NULL) - vpclose(read_port); - - } -} - -void accountData_written_to_events_json() { - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char eventsPATH[1024] = { 0 }; - strcpy(eventsPATH, exePath); - - strcat(eventsPATH, "events.json"); - - char *filename_events; - filename_events = eventsPATH; - if (!FileExist(filename_events)) - { - printf("%s doesn't exist.\n", filename_events); - } - else { - //size_t nfileSize_events = ReadFileSize(filename_events); - char *fileBuf_events = ReadAllBytes(filename_events); - if (fileBuf_events) { - //printf("\n[read_ipcam_account_setting]\n"); - //printf("\nfileBuf_events: %s\n", fileBuf_events); - cJSON *root, *notification, *http_post_events, *http_post; - root = cJSON_Parse(fileBuf_events); - if (fileBuf_events) { - free(fileBuf_events); - fileBuf_events = NULL; - } - - if (root == NULL) - { - printf("root is NULL\n"); - - int del = remove(filename_events); - if (!del) { - //printf("events.json is deleted successfully."); - } - else { - printf("events.json cannot be deleted.\n"); - } -#if 1 - stop_test_nn_cavalry("events json not exist"); - //stop_server(); - -#endif - pthread_exit(NULL); - } - else - { - notification = cJSON_GetObjectItem(root, "notification"); - { - http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); - - int i = 0; - cJSON_ArrayForEach(http_post, http_post_events) - { - if (i <= 3) { - if (strlen(accountData[0].account_port) >= 1) - cJSON_ReplaceItemInObject(http_post, "post_host_port", cJSON_CreateString(accountData[0].account_port)); - if (strlen(accountData[0].account_username) >= 1) { - char buf_account[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); - cJSON_ReplaceItemInObject(http_post, "post_username", cJSON_CreateString(buf_account)); - } - if (strlen(accountData[0].account_password) >= 1) { - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); - cJSON_ReplaceItemInObject(http_post, "post_password", cJSON_CreateString(buf_account2)); - } - } - else - break; - - i++; - } - } - - char *filename = eventsPATH; - char* JsonString = cJSON_Print(root); - FILE *fp; - - if ((fp = fopen(filename, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - } - else - { - fclose(fp); - printf("Fail to open events.json \n"); - } - - - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - if (root) { - cJSON_Delete(root); - root = NULL; - } - } - } - } -} - -static char events_port[512] = { 0 }; -static char events_username[512] = {0}; -static char events_password[512] = { 0 }; -void get_current_events_json_data() { - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char eventsPATH[1024] = { 0 }; - char events_bakPATH[1024] = { 0 }; - - strcpy(eventsPATH, exePath); - strcat(eventsPATH, "events.json"); - - strcpy(events_bakPATH, exePath); - strcat(events_bakPATH, "events_bak.json"); - - char *filename_events; - filename_events = eventsPATH; - if (!FileExist(filename_events)) - { - printf("%s doesn't exist.\n", filename_events); - } - else { - //size_t nfileSize_events = ReadFileSize(filename_events); - char *fileBuf_events = ReadAllBytes(filename_events); - if (fileBuf_events) { - //printf("\n[read_ipcam_account_setting]\n"); - //printf("\nfileBuf_events: %s\n", fileBuf_events); - cJSON *root, *notification, *http_post_events, *http_post, *post_host_port, *post_username, *post_password; - root = cJSON_Parse(fileBuf_events); - if (fileBuf_events) { - free(fileBuf_events); - fileBuf_events = NULL; - } - - if (root == NULL) - { - printf("root is NULL\n"); - - int del = remove(filename_events); - if (!del) { - //printf("events.json is deleted successfully."); - } - else { - printf("events.json cannot be deleted.\n"); - } - - if (FileExist(events_bakPATH)) { - printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_bakPATH to main_0 events <<<<<<<<<<<<<<<<<<<<<<<\n"); - CopyFileTo(events_bakPATH, eventsPATH); - } - else { -#if 1 - stop_test_nn_cavalry("events_bak json not exist"); - //stop_server(); -#endif - } - pthread_exit(NULL); - } - else - { - notification = cJSON_GetObjectItem(root, "notification"); - { - http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); - - int i = 0; - cJSON_ArrayForEach(http_post, http_post_events) - { - - post_host_port = cJSON_GetObjectItem(http_post, "post_host_port"); - post_username = cJSON_GetObjectItem(http_post, "post_username"); - post_password = cJSON_GetObjectItem(http_post, "post_password"); - - strcpy(events_port, post_host_port->valuestring); - - char temp_account[512] = { 0 }; - urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); - memcpy(events_username, temp_account, strlen(temp_account)); - events_username[strlen(temp_account)] = '\0'; - - - char temp_account2[512] = { 0 }; - urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); - memcpy(events_password, temp_account2, strlen(temp_account2)); - events_password[strlen(temp_account2)] = '\0'; - - //strcpy(events_username, post_username->valuestring); - //strcpy(events_password, post_password->valuestring); - - break; - i++; - } - } - if (root) { - cJSON_Delete(root); - root = NULL; - } - } - } - } -} - -/*void *run_osd_time_sync_thread() { - pthread_detach(pthread_self()); - setPthreadName("run_osd_time"); - //update_system_time(); - //int count_delay = 0; - int count_post = 0; - - while (bHttpServerThreadStart) - { - //if (count_delay >= 10) - { - //count_delay = 0; - //update_system_time(); - } - //else - { - //count_delay++; - g_osdSysTimeStamp++; - } - -#if 1 - if (count_post >= 14400) { - count_post = 0; - if (check_if_correct_post == 1) { - if (check_if_run_post == 1) { - - } - else if(check_if_run_post == 0){ - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "There is cloud post error existing for 4 hours. Reboot the camera to restart gynet."); - write_to_logs_html(temp_msg, "run osd time sync thread", "CGI_REBOOT", "Yes"); - //printf("\n-----------------------There is no post for 4 hours.: exit-----------------------\n"); - write_to_log_if_error(temp_msg, "run osd time sync thread", "CGI_REBOOT"); - pthread_t auto_reboot_thread_id; - if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) - { - printf("create auto reboot thread faile \n"); - } - } - } - } - else { - if (check_if_run_post != 0) { - count_post = 0; - } - - count_post++; - } -#endif - - usSleep(1000000); - } - - pthread_exit(NULL); -}*/ -#ifdef GY_OS_AMBA -#define SHELLSCRIPT "sh /emmc/plugin/Aida_data/run_osd_server.sh" -#define SHELLSCRIPT_TOF_DRIVER "sh /emmc/plugin/Aida_data/run_tof_driver.sh" - - -void *run_osd_server_thread(void* ptr) { - pthread_detach(pthread_self()); - setPthreadName("osd_server"); - if (strcmp(SystemSetting.enable_display_OSD, "Yes")==0 /*&& strcmp(SystemSetting.enable_cloud,"Yes")==0*/) { - pthread_t auto_system_thread_id; - if (pthread_create(&auto_system_thread_id, 0, auto_system, NULL)) - { - printf("\ncreate auto system thread faile \n"); - } - pthread_join(auto_system_thread_id, NULL); - //usSleep(2000000); - - g_check_if_OK_to_start_osd_server = 1; - - pthread_mutex_lock(&mutex_run_osd); - close_udp_socket(); - init_udp_socket(); - pthread_mutex_unlock(&mutex_run_osd); - - usSleep(2000000); - char cmd_1[256] = "killall -15 osd_server"; - - FILE *read_port = vpopen(cmd_1, "r"); - if (read_port != NULL) - vpclose(read_port); - - usSleep(2000000); - - g_check_if_OK_to_start_osd_server = 0; -#if 1 - system(SHELLSCRIPT); -#endif - -#if 0 - char cmd_2[256] = "/emmc/plugin/Aida_data/osd_server server"; - - read_port = vpopen(cmd_2, "r"); - if (read_port != NULL) - vpclose(read_port); -#endif - usSleep(2000000); - } - else{ - g_check_if_OK_to_start_osd_server = 1; - close_udp_socket(); - - usSleep(2000000); - - char cmd_2[256] = "killall -15 osd_server"; - FILE *read_port = vpopen(cmd_2, "r"); - if (read_port != NULL) - vpclose(read_port); - - usSleep(2000000); - g_check_if_OK_to_start_osd_server = 0; - } - - pthread_exit(NULL); -} -#endif -struct timeval currtime_read_ipcam_account_setting_thread; -static long last_ms_currtime_read_ipcam_account_setting_thread = 0; -void *read_ipcam_account_setting_thread(void* ptr) { - pthread_detach(pthread_self()); - setPthreadName("read_ipcam"); - - //printf("\n----------read ipcam account setting thread start\n"); - - gettimeofday(&currtime_read_ipcam_account_setting_thread, NULL); - long current_ms_currtime_read_ipcam_account_setting_thread = (currtime_read_ipcam_account_setting_thread.tv_sec * 1000) + (currtime_read_ipcam_account_setting_thread.tv_usec / 1000); - - - if (last_ms_currtime_read_ipcam_account_setting_thread == 0 || current_ms_currtime_read_ipcam_account_setting_thread - last_ms_currtime_read_ipcam_account_setting_thread >= 5000) { - - if (g_control_read_ipcam == 0) { - - pthread_mutex_lock(&mutex_read_ipcam); - g_control_read_ipcam = 1; - - get_current_events_json_data(); - - /*while (bHttpServerThreadStart)*/ { - read_ipcam_account_setting(); - //usSleep(READ_IPCAM_SETTING*1000); - } - - - int get_OK = 0; - char temp_device_name[512] = { 0 }; - get_OK = PNS_Get_Device_Name(1, temp_device_name); - //int len_device = 0; - if (get_OK >= 1) { - url_decode(temp_device_name,strlen(temp_device_name)); - strcpy(g_device_name, temp_device_name); - } - g_control_read_ipcam = 0; - pthread_mutex_unlock(&mutex_read_ipcam); - - } - - last_ms_currtime_read_ipcam_account_setting_thread = current_ms_currtime_read_ipcam_account_setting_thread; - } - - //printf("\n----------read ipcam account setting thread end\n"); - - pthread_exit(NULL); -} - -int g_start_update_config = 0; -void read_ipcam_account_setting() -{ - - update_accountData(); - update_accountData_port(); - - if (g_start_update_config == 0) { - update_config_account_setting(); - g_start_update_config = 1; - } - if (strlen(accountData[0].account_port) >= 1 && strlen(accountData[0].account_username) >= 1 && - strlen(events_port) >= 1 && strlen(events_username) >= 1) - { - if (strcmp(accountData[0].account_port, events_port) != 0 || - strcmp(accountData[0].account_username, events_username) != 0 || - strcmp(accountData[0].account_password, events_password) != 0) - { - if (g_start_update_config == 1) { - update_config_account_setting(); - } - accountData_written_to_events_json(); - for (int i = 0; i < 4; i++) { - strcpy(postEventList[i].post_host_port, accountData[0].account_port); - strcpy(postEventList[i].post_username, accountData[0].account_username); - strcpy(postEventList[i].post_password, accountData[0].account_password); - } - get_current_events_json_data(); - } - } -#if 0 - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\naccountData[0].account_mirror: %s\n", accountData[0].account_mirror); - printf("\naccountData[0].account_flip: %s\n", accountData[0].account_flip); - printf("\naccountData[0].account_rotate: %s\n", accountData[0].account_rotate); - printf("\naccountData[0].account_port: %s\n", accountData[0].account_port); - printf("\naccountData[0].account_username: %s\n", accountData[0].account_username); - printf("\naccountData[0].account_password: %s\n", accountData[0].account_password); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); -#endif -} - -int external_memory_fragmentation_management() { - - FILE * pPipe = NULL; - char cmd[256] = { 0 }; - int size_psBuffer = 256; - char psBuffer[256] = { 0 }; - - int chunk_number = -1; - - memset(cmd, 0x00, sizeof(cmd)); -#ifdef GY_OS_AMBA - sprintf(cmd, "timeout 3s echo 1 > /proc/sys/vm/compact_memory"); -#else - sprintf(cmd, "echo 1 > /proc/sys/vm/compact_memory"); -#endif - - pPipe = vpopen(cmd, "r"); - - if (pPipe != NULL) - { - - } - else { - printf("\nFail: external memory fragmentation management #1\n"); - } - if (pPipe != NULL) - vpclose(pPipe); - - memset(cmd, 0x00, sizeof(cmd)); -#ifdef GY_OS_AMBA - sprintf(cmd, "timeout 3s cat /proc/buddyinfo | awk -F ' ' '{print $(NF)}'"); -#else - sprintf(cmd, "cat /proc/buddyinfo | awk -F ' ' '{print $(NF)}'"); -#endif - - - pPipe = vpopen(cmd, "r"); - - if (pPipe != NULL) - { - //printf("Run: external memory fragmetation\n"); - char* temp; - memset(psBuffer, 0x00, sizeof(psBuffer)); - temp = fgets(psBuffer, size_psBuffer, pPipe); - if (temp != NULL) { - chunk_number = atoi(psBuffer); - printf("\n[buddyinfo] chunk_number:%d\n", chunk_number); - } - } - else { - printf("\nFail: external memory fragmentation management #2\n"); - } - if (pPipe != NULL) - vpclose(pPipe); - - return chunk_number; -} - -// 2020.11.23 Sophia added. -// 2021.05.12 Cayman modified returned values. -extern char* strptime_c(const char* buf, const char* fmt, struct tm* tm); -int reload_dataset_from_jsonfile(void) -{ - time_t start_time = 0; - time_t now_time = 0; - now_time = (time_t)time(0); - - struct tm *localnowTime = localtime(&now_time); - int diffSecs = 0; - if (cgi_whenTime_buff != NULL && cgi_startTime_buff != NULL) { - memcpy(cgi_whenTime_buff, localnowTime, sizeof(struct tm)); - diffSecs = cgi_whenTime_buff->tm_sec - cgi_startTime_buff->tm_sec; - } - - if (abs(diffSecs) < 2) - return 1; - - start_time = time(0); - cgi_reload_start_Time = localtime(&start_time); - - if (cgi_startTime_buff != NULL) { - memcpy(cgi_startTime_buff, cgi_reload_start_Time, sizeof(struct tm)); - } - - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char configPATH[1024] = { 0 }; - char eventsPATH[1024] = { 0 }; - - strcpy(configPATH, exePath); - strcpy(eventsPATH, exePath); - - strcat(configPATH, "config.json"); - strcat(eventsPATH, "events.json"); - - char *filename_event; - filename_event = eventsPATH; - - if (!FileExist(filename_event)) - { - printf("%s doesn't exist.\n", filename_event); - return 1; - } - size_t nfileSize_event = ReadFileSize(filename_event); - printf("nfileSize_event:%ld\n", (long int)nfileSize_event); - char *fileBuf_event = ReadAllBytes(filename_event); - if (fileBuf_event == NULL) { - printf("fileBuf_event is NULL\n"); - return 1; - } - - cJSON /* *n_root,*/ *notification, *events_default_version,*enable_post,*enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content, - *post_customized_header; - cJSON *post_sequence,*post_file_format, *post_jpeg_file_name_format, *post_jpeg_file_name,*post_timeout; - cJSON *enable_heartbeat, *heartbeat_dwell, *heartbeat_link_to_post_event_name, *dwell_to_the_same_location, - *enable_snmp_heartbeat, *snmp_heartbeat_dwell, *snmp_heartbeat_link_to_post_event_name, - *enable_only_once_to_post,*enable_obj_once_to_post,*enable_location_once_to_post,*enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion,*heatmap_max,*enable_heatmap,*heatmap_frequency,*lpr_title,*enable_counter_snap, *enable_barcode_qr,*enable_check_ptz_start_autotracking, - *enable_check_ptz_end_autotracking,*ptz_start_autotracking_link_to_post_event_name,*ptz_end_autotracking_link_to_post_event_name; - - //n_root = cJSON_Parse(fileBuf_event); - cJSON *root; - root = cJSON_Parse(fileBuf_event); - if (fileBuf_event) { - free(fileBuf_event); - fileBuf_event = NULL; - } - - if (root == NULL) - { - printf("root is NULL\n"); - return 1; - } - notification = cJSON_GetObjectItem(root, "notification"); - events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); - enable_post = cJSON_GetObjectItem(notification, "enable_post"); - enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); - http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); - enable_heartbeat = cJSON_GetObjectItem(notification, "enable_heartbeat"); - - enable_snmp_heartbeat = cJSON_GetObjectItem(notification, "enable_snmp_heartbeat"); - snmp_heartbeat_dwell = cJSON_GetObjectItem(notification, "snmp_heartbeat_dwell"); - snmp_heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "snmp_heartbeat_link_to_post_event_name"); - - enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); - enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); - ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); - ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); - - enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); - enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); - enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); - dwell_to_the_same_location = cJSON_GetObjectItem(notification, "dwell_to_the_same_location"); - enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); - enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); - heartbeat_dwell = cJSON_GetObjectItem(notification, "heartbeat_dwell"); - heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "heartbeat_link_to_post_event_name"); - heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); - enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); - heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); - lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); - enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); - enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); - - activePostNotification = strcmp(enable_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; - - if (events_default_version) { - strcpy(heartbeatData.events_default_version, events_default_version->valuestring); - } - else { - strcpy(heartbeatData.events_default_version, "1"); - } - - if (enable_post) - activeSNMPPost = strcmp(enable_snmp_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; - else - activeSNMPPost = _FALSE; - if (enable_heartbeat) { - strcpy(heartbeatData.enable_heartbeat, enable_heartbeat->valuestring); - } - else { - strcpy(heartbeatData.enable_heartbeat, "No"); - } - - if (enable_snmp_heartbeat) { - strcpy(heartbeatData.enable_snmp_heartbeat, enable_snmp_heartbeat->valuestring); - } - else { - strcpy(heartbeatData.enable_snmp_heartbeat, "No"); - } - - if (snmp_heartbeat_dwell) { - strcpy(heartbeatData.snmp_heartbeat_dwell, snmp_heartbeat_dwell->valuestring); - } - else { - strcpy(heartbeatData.snmp_heartbeat_dwell, "5"); - } - - if (snmp_heartbeat_link_to_post_event_name) { - strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, snmp_heartbeat_link_to_post_event_name->valuestring); - } - else { - strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, "Heartbeat"); - } - - if (enable_check_ptz_start_autotracking) { - strcpy(heartbeatData.enable_check_ptz_start_autotracking, enable_check_ptz_start_autotracking->valuestring); - } - else { - strcpy(heartbeatData.enable_check_ptz_start_autotracking, "No"); - } - - if (enable_check_ptz_end_autotracking) { - strcpy(heartbeatData.enable_check_ptz_end_autotracking, enable_check_ptz_end_autotracking->valuestring); - } - else { - strcpy(heartbeatData.enable_check_ptz_end_autotracking, "No"); - } - - if (enable_only_once_to_post) { - strcpy(heartbeatData.enable_only_once_to_post, enable_only_once_to_post->valuestring); - } - else { - strcpy(heartbeatData.enable_only_once_to_post, "Yes"); - } - - if (enable_obj_once_to_post) { - strcpy(heartbeatData.enable_obj_once_to_post, enable_obj_once_to_post->valuestring); - } - else { - strcpy(heartbeatData.enable_obj_once_to_post, "Yes"); - } - - if (enable_location_once_to_post) { - strcpy(heartbeatData.enable_location_once_to_post, enable_location_once_to_post->valuestring); - } - else { - strcpy(heartbeatData.enable_location_once_to_post, "Yes"); - } - - if (enable_nvr_once_to_getalarmmotion) { - strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, enable_nvr_once_to_getalarmmotion->valuestring); - } - else { - strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes"); - } - - if (enable_8592_once_to_getalarmmotion) { - strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, enable_8592_once_to_getalarmmotion->valuestring); - } - else { - strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, "Yes"); - } - - if (dwell_to_the_same_location) { - strcpy(heartbeatData.dwell_to_the_same_location, dwell_to_the_same_location->valuestring); - } - else { - strcpy(heartbeatData.dwell_to_the_same_location, "5"); - } - - if (heartbeat_dwell) { - strcpy(heartbeatData.heartbeat_dwell, heartbeat_dwell->valuestring); - } - else { - strcpy(heartbeatData.heartbeat_dwell, "10"); - } - - if (heatmap_max) { - strcpy(heartbeatData.heatmap_max, heatmap_max->valuestring); - } - else { - strcpy(heartbeatData.heatmap_max, "100"); - } - - if (enable_heatmap) { - strcpy(heartbeatData.enable_heatmap, enable_heatmap->valuestring); - } - else { - strcpy(heartbeatData.enable_heatmap, "No"); - } - - if (heatmap_frequency) { - strcpy(heartbeatData.heatmap_frequency, heatmap_frequency->valuestring); - } - else { - strcpy(heartbeatData.heatmap_frequency, "5"); - } - - if (lpr_title) { - strcpy(heartbeatData.lpr_title, lpr_title->valuestring); - } - else { - strcpy(heartbeatData.lpr_title, "My Car Park"); - } - - if (heartbeat_link_to_post_event_name) { - strcpy(heartbeatData.heartbeat_link_to_post_event_name, heartbeat_link_to_post_event_name->valuestring); - } - else { - strcpy(heartbeatData.heartbeat_link_to_post_event_name, ""); - } - - if (ptz_start_autotracking_link_to_post_event_name) { - strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ptz_start_autotracking_link_to_post_event_name->valuestring); - } - else { - strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ""); - } - - if (ptz_end_autotracking_link_to_post_event_name) { - strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ptz_end_autotracking_link_to_post_event_name->valuestring); - } - else { - strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ""); - } - - if (enable_counter_snap) { - strcpy(heartbeatData.enable_counter_snap, enable_counter_snap->valuestring); - } - else { - strcpy(heartbeatData.enable_counter_snap, "No"); - } - - if (enable_barcode_qr) { - strcpy(heartbeatData.enable_barcode_qr, enable_barcode_qr->valuestring); - } - else { - strcpy(heartbeatData.enable_barcode_qr, "No"); - } - - int i = 0; - cJSON_ArrayForEach(detect2, http_post_events) - { - post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); - post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); - post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); - post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); - post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); - post_url = cJSON_GetObjectItem(detect2, "post_url"); - post_username = cJSON_GetObjectItem(detect2, "post_username"); - post_password = cJSON_GetObjectItem(detect2, "post_password"); - post_content = cJSON_GetObjectItem(detect2, "post_content"); - post_customized_header = cJSON_GetObjectItem(detect2, "post_customized_header"); - post_sequence = cJSON_GetObjectItem(detect2, "post_sequence"); - post_timeout = cJSON_GetObjectItem(detect2, "post_timeout"); - post_file_format = cJSON_GetObjectItem(detect2, "post_file_format"); - post_jpeg_file_name_format = cJSON_GetObjectItem(detect2, "post_jpeg_file_name_format"); - post_jpeg_file_name = cJSON_GetObjectItem(detect2, "post_jpeg_file_name"); - - char temp_account[512] = { 0 }; - urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); - memcpy(postEventList[i].post_username, temp_account, strlen(temp_account)); - postEventList[i].post_username[strlen(temp_account)] = '\0'; - - char temp_account2[512] = { 0 }; - urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); - memcpy(postEventList[i].post_password, temp_account2, strlen(temp_account2)); - postEventList[i].post_password[strlen(temp_account2)] = '\0'; - - strcpy(postEventList[i].post_protocol, post_protocol->valuestring); - strcpy(postEventList[i].post_event_method, post_event_method->valuestring); - strcpy(postEventList[i].post_event_name, post_event_name2->valuestring); - strcpy(postEventList[i].post_host_ip, post_host_ip->valuestring); - strcpy(postEventList[i].post_host_port, post_host_port->valuestring); - strcpy(postEventList[i].post_url, post_url->valuestring); - //strcpy(postEventList[i].post_username, post_username->valuestring); - //strcpy(postEventList[i].post_password, post_password->valuestring); - strcpy(postEventList[i].post_content, post_content->valuestring); - strcpy(postEventList[i].post_customized_header, post_customized_header->valuestring); - - if (post_sequence) - strcpy(postEventList[i].post_sequence, post_sequence->valuestring); - else { - strcpy(postEventList[i].post_sequence, ""); - } - - if (post_timeout) - strcpy(postEventList[i].post_timeout, post_timeout->valuestring); - else { - strcpy(postEventList[i].post_timeout, "5"); - } - - if(post_file_format) - strcpy(postEventList[i].post_file_format, post_file_format->valuestring); - else { - strcpy(postEventList[i].post_file_format, "text"); - } - - if(post_jpeg_file_name_format) - strcpy(postEventList[i].post_jpeg_file_name_format, post_jpeg_file_name_format->valuestring); - else { - strcpy(postEventList[i].post_jpeg_file_name_format, "fixed"); - } - - if(post_jpeg_file_name) - strcpy(postEventList[i].post_jpeg_file_name, post_jpeg_file_name->valuestring); - else { - strcpy(postEventList[i].post_jpeg_file_name, "snap"); - } - i++; - } - -#ifdef GY_OS_V_SERIES - cJSON *counter_name; -#else - cJSON *event_counter_setting, *detect3, *event_counters, *counter_name,*counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *reset_at, *enable_time_range, *time_range_from, *time_range_to,*enable_reset_only_cloud,*enable_linked_to_dwell_time; - cJSON *link_to_post_event_name, *post_interval; - - event_counter_setting = cJSON_GetObjectItem(root, "event_counter_setting"); - event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); - - i = 0; - cJSON_ArrayForEach(detect3, event_counters) - { - counter_name = cJSON_GetObjectItem(detect3, "counter_name"); - counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); - counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); - reset_value = cJSON_GetObjectItem(detect3, "reset_value"); - enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); - reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); - reset_at = cJSON_GetObjectItem(detect3, "reset_at"); - enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); - time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); - time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); - enable_reset_only_cloud = cJSON_GetObjectItem(detect3, "enable_reset_only_cloud"); - enable_linked_to_dwell_time = cJSON_GetObjectItem(detect3, "enable_linked_to_dwell_time"); - - link_to_post_event_name = cJSON_GetObjectItem(detect3, "link_to_post_event_name"); - post_interval = cJSON_GetObjectItem(detect3, "post_interval"); - - strcpy(eventCounterList[i].counter_name, counter_name->valuestring); - strcpy(eventCounterList[i].counter_cust_name, counter_cust_name->valuestring); - strcpy(eventCounterList[i].counter_unit, counter_unit->valuestring); - - if (reset_value) - eventCounterList[i].reset_value = atoi(reset_value->valuestring); - else - eventCounterList[i].reset_value = 0; - strcpy(eventCounterList[i].enable_reset_time_interval, enable_reset_time_interval->valuestring); - strcpy(eventCounterList[i].reset_time_interval, reset_time_interval->valuestring); - strcpy(eventCounterList[i].reset_at, reset_at->valuestring); - strcpy(eventCounterList[i].enable_time_range, enable_time_range->valuestring); - strcpy(eventCounterList[i].time_range_from, time_range_from->valuestring); - strcpy(eventCounterList[i].time_range_to, time_range_to->valuestring); - struct tm tm; - strptime_c(eventCounterList[i].reset_at, "%Y-%m-%d %H:%M:%S", &tm); -#if 0 - eventCounterList[i].timetResetAt = mktime(&tm); - - struct tm *resetTime = localtime(&eventCounterList[i].timetResetAt); - eventCounterList[i].reset_month = resetTime->tm_mon; - eventCounterList[i].reset_month_day = resetTime->tm_mday; - eventCounterList[i].reset_week_day = resetTime->tm_wday; - eventCounterList[i].reset_hour = resetTime->tm_hour; - eventCounterList[i].reset_min = resetTime->tm_min; - eventCounterList[i].reset_sec = resetTime->tm_sec; -#endif - strptime_c(eventCounterList[i].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); - eventCounterList[i].timetTimeRangeFrom = mktime(&tm); - strptime_c(eventCounterList[i].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); - eventCounterList[i].timetTimeRangeTo = mktime(&tm); - - if (link_to_post_event_name) { - strcpy(eventCounterList[i].link_to_post_event_name, link_to_post_event_name->valuestring); - } - else { - strcpy(eventCounterList[i].link_to_post_event_name, ""); - } - - if (post_interval) { - strcpy(eventCounterList[i].post_interval, post_interval->valuestring); - } - else { - strcpy(eventCounterList[i].post_interval, "5 minutes"); - } - - if (enable_reset_only_cloud) { - strcpy(eventCounterList[i].enable_reset_only_cloud, enable_reset_only_cloud->valuestring); - } - else { - strcpy(eventCounterList[i].enable_reset_only_cloud, "No"); - } - - if (enable_linked_to_dwell_time) { - strcpy(eventCounterList[i].enable_linked_to_dwell_time, enable_linked_to_dwell_time->valuestring); - } - else { - strcpy(eventCounterList[i].enable_linked_to_dwell_time, "No"); - } - - i++; - } - - cJSON *a_report, *report_counters, *counter_a, *counter_a_name, *counter_b, *counter_b_name, *counter_a_zone, *counter_b_zone, *counter_c_name, - *enable_report, *report_max_value, *initial_icon, *detection_output, *output_icon,*counter_mode; - - report_counters = cJSON_GetObjectItem(event_counter_setting, "report_counters"); - if (report_counters) { - i = 0; - cJSON_ArrayForEach(a_report, report_counters) - { - if (a_report) { - counter_a = cJSON_GetObjectItem(a_report, "counter_a"); - counter_a_name = cJSON_GetObjectItem(a_report, "counter_a_name"); - counter_a_zone = cJSON_GetObjectItem(a_report, "counter_a_zone"); - counter_b = cJSON_GetObjectItem(a_report, "counter_b"); - counter_b_name = cJSON_GetObjectItem(a_report, "counter_b_name"); - counter_b_zone = cJSON_GetObjectItem(a_report, "counter_b_zone"); - counter_c_name = cJSON_GetObjectItem(a_report, "counter_c_name"); - report_max_value = cJSON_GetObjectItem(a_report, "report_max_value"); - enable_report = cJSON_GetObjectItem(a_report, "enable_report"); - counter_mode = cJSON_GetObjectItem(a_report, "counter_mode"); - initial_icon = cJSON_GetObjectItem(a_report, "initial_icon"); - detection_output = cJSON_GetObjectItem(a_report, "detection_output"); - output_icon = cJSON_GetObjectItem(a_report, "output_icon"); - - if (counter_a) { - strcpy(reportCounterList[i].counter_a, counter_a->valuestring); - } - else { - strcpy(reportCounterList[i].counter_a, "Counter01"); - } - - if (counter_a_name) { - strcpy(reportCounterList[i].counter_a_name, counter_a_name->valuestring); - } - else { - strcpy(reportCounterList[i].counter_a_name, "Name"); - } - - if (counter_a_zone) { - strcpy(reportCounterList[i].counter_a_zone, counter_a_zone->valuestring); - } - else { - strcpy(reportCounterList[i].counter_a_zone, "1"); - } - - if (counter_b) { - strcpy(reportCounterList[i].counter_b, counter_b->valuestring); - } - else { - strcpy(reportCounterList[i].counter_b, ""); - } - - if (counter_b_name) { - strcpy(reportCounterList[i].counter_b_name, counter_b_name->valuestring); - } - else { - strcpy(reportCounterList[i].counter_b_name, ""); - } - - if (counter_b_zone) { - strcpy(reportCounterList[i].counter_b_zone, counter_b_zone->valuestring); - } - else { - strcpy(reportCounterList[i].counter_b_zone, "0"); - } - - if (counter_c_name) { - strcpy(reportCounterList[i].counter_c_name, counter_c_name->valuestring); - } - else { - strcpy(reportCounterList[i].counter_c_name, ""); - } - - if (report_max_value) { - strcpy(reportCounterList[i].report_max_value, report_max_value->valuestring); - } - else { - strcpy(reportCounterList[i].report_max_value, "100"); - } - - if (enable_report) { - strcpy(reportCounterList[i].enable_report, enable_report->valuestring); - } - else { - strcpy(reportCounterList[i].enable_report, "No"); - } - - if (counter_mode) { - strcpy(reportCounterList[i].counter_mode, counter_mode->valuestring); - } - else { - strcpy(reportCounterList[i].counter_mode, "0"); - } - - if (initial_icon) { - strcpy(reportCounterList[i].initial_icon, initial_icon->valuestring); - } - else { - strcpy(reportCounterList[i].initial_icon, "car_300X300_white"); - } - - if (detection_output) { - strcpy(reportCounterList[i].detection_output, detection_output->valuestring); - } - else { - strcpy(reportCounterList[i].detection_output, "No entry for cars"); - } - - if (output_icon) { - strcpy(reportCounterList[i].output_icon, output_icon->valuestring); - } - else { - strcpy(reportCounterList[i].output_icon, "car_1_300X300_red"); - } - - i++; - } - } - - if (i < MAX_REPORT_COUNTERS) { - for (int index_report = i; index_report < MAX_REPORT_COUNTERS; index_report++) { - strcpy(reportCounterList[index_report].counter_a, "Counter01"); - strcpy(reportCounterList[index_report].counter_a_name, "Name"); - strcpy(reportCounterList[index_report].counter_a_zone, "1"); - strcpy(reportCounterList[index_report].counter_b, ""); - strcpy(reportCounterList[index_report].counter_b_name, ""); - strcpy(reportCounterList[index_report].counter_b_zone, "0"); - strcpy(reportCounterList[index_report].counter_c_name, ""); - strcpy(reportCounterList[index_report].report_max_value, "100"); - strcpy(reportCounterList[index_report].enable_report, "No"); - strcpy(reportCounterList[index_report].counter_mode, "0"); - strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); - strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); - strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); - } - } - } - else { - for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { - strcpy(reportCounterList[index_report].counter_a, "Counter01"); - strcpy(reportCounterList[index_report].counter_a_name, "Name"); - strcpy(reportCounterList[index_report].counter_a_zone, "1"); - strcpy(reportCounterList[index_report].counter_b, ""); - strcpy(reportCounterList[index_report].counter_b_name, ""); - strcpy(reportCounterList[index_report].counter_b_zone, "0"); - strcpy(reportCounterList[index_report].counter_c_name, ""); - strcpy(reportCounterList[index_report].report_max_value, "100"); - strcpy(reportCounterList[index_report].enable_report, "No"); - strcpy(reportCounterList[index_report].counter_mode, "0"); - strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); - strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); - strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); - } - } - - cJSON *a_snmp, *snmp_management, *snmp_event_name, *snmp_version, *snmp_group_name, *snmp_host_ip, *snmp_host_port, - *snmp_oid, *snmp_value, *snmp_type; - - snmp_management = cJSON_GetObjectItem(event_counter_setting, "snmp_management"); - if (snmp_management) { - i = 0; - cJSON_ArrayForEach(a_snmp, snmp_management) - { - if (a_snmp) { - snmp_event_name = cJSON_GetObjectItem(a_snmp, "snmp_event_name"); - snmp_version = cJSON_GetObjectItem(a_snmp, "snmp_version"); - snmp_group_name = cJSON_GetObjectItem(a_snmp, "snmp_group_name"); - snmp_host_ip = cJSON_GetObjectItem(a_snmp, "snmp_host_ip"); - snmp_host_port = cJSON_GetObjectItem(a_snmp, "snmp_host_port"); - snmp_oid = cJSON_GetObjectItem(a_snmp, "snmp_oid"); - snmp_value = cJSON_GetObjectItem(a_snmp, "snmp_value"); - snmp_type = cJSON_GetObjectItem(a_snmp, "snmp_type"); - - if (snmp_event_name) { - strcpy(SNMPManagementList[i].snmp_event_name, snmp_event_name->valuestring); - } - else { - char temp_name[20] = { 0 }; - sprintf(temp_name,"SNMP %d",i+1); - strcpy(SNMPManagementList[i].snmp_event_name, temp_name); - } - - if (snmp_version) { - strcpy(SNMPManagementList[i].snmp_version, snmp_version->valuestring); - } - else { - strcpy(SNMPManagementList[i].snmp_version, "v1"); - } - - if (snmp_group_name) { - strcpy(SNMPManagementList[i].snmp_group_name, snmp_group_name->valuestring); - } - else { - strcpy(SNMPManagementList[i].snmp_group_name, "public"); - } - - if (snmp_host_ip) { - strcpy(SNMPManagementList[i].snmp_host_ip, snmp_host_ip->valuestring); - } - else { - strcpy(SNMPManagementList[i].snmp_host_ip, "192.168.0.200"); - } - - if (snmp_host_port) { - strcpy(SNMPManagementList[i].snmp_host_port, snmp_host_port->valuestring); - } - else { - strcpy(SNMPManagementList[i].snmp_host_port, "161"); - } - - if (snmp_oid) { - strcpy(SNMPManagementList[i].snmp_oid, snmp_oid->valuestring); - } - else { - strcpy(SNMPManagementList[i].snmp_oid, ".1.3.6.1.2.1.1.6.0"); - } - - if (snmp_value) { - strcpy(SNMPManagementList[i].snmp_value, snmp_value->valuestring); - } - else { - strcpy(SNMPManagementList[i].snmp_value, "mylocation"); - } - - if (snmp_type) { - strcpy(SNMPManagementList[i].snmp_type, snmp_type->valuestring); - } - else { - strcpy(SNMPManagementList[i].snmp_type, "string"); - } - - i++; - } - } - - if (i < MAX_SNMP_MANAGEMENT) { - for (int index_snmp = i; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { - char temp_name[10] = { 0 }; - if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { - sprintf(temp_name, "SNMP %d", index_snmp + 1); - strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); - strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); - strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); - strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); - strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); - strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); - strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); - strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); - } - else { - sprintf(temp_name, "%s", "Heartbeat"); - strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); - strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); - strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); - strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); - strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); - strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); - strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); - strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); - } - } - } - } - else { - for (int index_snmp = i; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { - char temp_name[10] = { 0 }; - if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { - sprintf(temp_name, "SNMP %d", index_snmp + 1); - strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); - strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); - strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); - strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); - strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); - strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); - strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); - strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); - } - else { - sprintf(temp_name, "%s", "Heartbeat"); - strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); - strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); - strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); - strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); - strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); - strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); - strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); - strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); - } - } - } -#endif - - -#if 0 - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || -#ifdef GY_OS_NOVA - IsANPRCategory(featureType) || -#endif - g_IsCustomWeight == 1) { - pthread_mutex_lock(&mutex_reset_counter); - time_t now_time = g_osdSysTimeStamp; - if (now_time < 1000000000) { - now_time = time(0); - } - for (int j = 0; j < MAX_EVENT_COUNTERS; j++) - { - reset_counter(j, now_time); - } - pthread_mutex_unlock(&mutex_reset_counter); - } -#endif - - cJSON *email_setting,*email_content; - email_setting = cJSON_GetObjectItem(root, "email_setting"); - if (email_setting) { - email_content = cJSON_GetObjectItem(email_setting, "email_content"); - if (email_content) - strcpy(emailData.email_content, email_content->valuestring); - else - strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); - } - else { - strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); - } - - //trigger events settings - char *filename_config; - filename_config = configPATH; - if (!FileExist(filename_config)) - { - printf("%s doesn't exist.\n", filename_config); - return 1; - } - - size_t nfileSize_config = ReadFileSize(filename_config); - printf("nfileSize_config:%ld\n", (long int)nfileSize_config); - char *fileBuf_config = ReadAllBytes(filename_config); - - if (fileBuf_config == NULL) { - printf("fileBuf_config is NULL\n"); - return 1; - } - - //cJSON* cam_ip, * http_port, * video_port, * cam_username, * cam_pwd, * channel_id; - cJSON* view_setting, * camera, * camera_name, * enable_anpr, *enable_face, * enable_traffic, * enable_logo, * tab_view_size, * enable_lpr_db, *enable_downsized_cropped_roi,*enable_zone_crop_1, *enable_add_face_frequent_list, - *enable_track,*enable_PTZ,*ptz_tracking_fov_min,*ptz_tracking_fov_max,*ptz_enable_tracking, *ptz_tracking_mode, *ptz_tracking_by_enter_zone, *ptz_tracking_resume_dwell,*ptz_sensitivity,*enable_unknown_object, *enable_ivs_person_detection, *assign_ivs_object_to,*enable_ambulance, *enable_blank_plate, *enable_stop_sign, - *cJSON_enable_only_show_metadata1,*count_zone, *ivs_mode, * detection_zone, * detect, - *levenshtein_distance, *obj_min_proportion, *obj_max_proportion,*min_characters, *max_characters, *confidence, *confidence2, *confidence3, *confidence4, *enable_traffic_light, *detection_time, *metadata1, *metadata2, *metadata_stop, *link_to_counter, - *enable_direction1, *enable_direction2, *direction1, *direction2, *no_parking_time,*no_parking_time_in_minute,*queuing_count, *ptz_zone_to_preset,*trigger_events[MAX_DETECTION_ZONE], *checked, *detect_event_id, *detect_event_name, *counter_increment, *post_event_name, - *point_number, - *x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4, *x5, *y5, *x6, *y6, - *enable_speed,*set_distance,*world_distance_unit,*world_distance_side1,*world_distance_side2, *world_time_unit,*enable_radar_speed, *enable_ivs_zone,*parking_space, *parking_line, - *enable_show_unknown_object, *enable_ivs_fix_mode, *enable_ivs_and_ai,*enable_lpr_upon_triggered, *dwell_lpr_upon_triggered,*unknown_object_max_proportion,*unknown_object_min_proportion,*confidence_unknown_object, *confidence2_unknown_object,*dwell_unknown_object,*dwell_minute_focus_on, *person_obj_fov,*getnetwork_buffer_id, - *plate_filter_times,*plate_filter_time,*plate_free_time,*obj_max_proportion_in_zone,*obj_min_proportion_in_zone,*red_light_zone,*no_give_way_zone_to_protect,*no_give_way_zone_to_keep_away, *no_give_way_zone_to_protect_2, *no_give_way_zone_to_keep_away_2, - *enable_tracking_limits,*ptz_pan_left_limit,*ptz_pan_right_limit,*ptz_tilt_up_limit,*ptz_tilt_down_limit,*ptz_speed; - - //cJSON* root = cJSON_Parse(fileBuf_config); - //printf("\n-----------------reload: %s\n", fileBuf_config); - - if (g_config_root == NULL) { - g_config_root = cJSON_Parse(fileBuf_config); - if (fileBuf_config) { - free(fileBuf_config); - fileBuf_config = NULL; - } - if (g_config_root == NULL) - { - printf("root is NULL\n"); - return 1; - } - } - view_setting = cJSON_GetObjectItem(g_config_root, "view_setting"); - - for (int n = 0; n < MAX_AI_ENGINE_VIEW; n++) - { - char CameraID[20] = { 0 }; - sprintf(CameraID, "camera%02d", n + 1); - camera = cJSON_GetObjectItem(view_setting, CameraID); - - /*cam_ip = cJSON_GetObjectItem(camera, "ip"); - http_port = cJSON_GetObjectItem(camera, "http_port"); - video_port = cJSON_GetObjectItem(camera, "video_port"); - cam_username = cJSON_GetObjectItem(camera, "username"); - cam_pwd = cJSON_GetObjectItem(camera, "password"); - channel_id = cJSON_GetObjectItem(camera, "channel_id");*/ - camera_name = cJSON_GetObjectItem(camera, "camera_name"); - levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); - obj_min_proportion = cJSON_GetObjectItem(camera, "obj_min_proportion"); - obj_max_proportion = cJSON_GetObjectItem(camera, "obj_max_proportion"); - min_characters = cJSON_GetObjectItem(camera, "min_characters"); - max_characters = cJSON_GetObjectItem(camera, "max_characters"); - - plate_filter_times = cJSON_GetObjectItem(camera, "PlateFilterTimes"); - plate_filter_time = cJSON_GetObjectItem(camera, "PlateFilterTime"); - plate_free_time = cJSON_GetObjectItem(camera, "PlateRecorderFreeTime"); - - confidence = cJSON_GetObjectItem(camera, "confidence"); //Plate 車牌 - confidence2 = cJSON_GetObjectItem(camera, "confidence2"); //Traffic 交通 - confidence3 = cJSON_GetObjectItem(camera, "confidence3"); //None 沒有用到 - confidence4 = cJSON_GetObjectItem(camera, "confidence4"); //None 沒有用到 - count_zone = cJSON_GetObjectItem(camera, "count_zone"); - - strcpy(viewChannelData[n].camera_name, camera_name->valuestring); - strcpy(viewChannelData[n].levenshtein_distance, levenshtein_distance->valuestring); - strcpy(viewChannelData[n].obj_min_proportion, obj_min_proportion->valuestring); - strcpy(viewChannelData[n].obj_max_proportion, obj_max_proportion->valuestring); - strcpy(viewChannelData[n].min_characters, min_characters->valuestring); - strcpy(viewChannelData[n].max_characters, max_characters->valuestring); - - if (plate_filter_times) - viewChannelData[n].i_plate_filter_times = atoi(plate_filter_times->valuestring); - else - viewChannelData[n].i_plate_filter_times = 4; - - if (plate_filter_time) - viewChannelData[n].i_plate_filter_time = atoi(plate_filter_time->valuestring); - else - viewChannelData[n].i_plate_filter_time = 3; - - if (plate_free_time) - viewChannelData[n].i_plate_free_time = atoi(plate_free_time->valuestring); - else - viewChannelData[n].i_plate_free_time = 3; - - strcpy(viewChannelData[n].confidence, confidence->valuestring); - strcpy(viewChannelData[n].confidence2, confidence2->valuestring); - strcpy(viewChannelData[n].confidence3, confidence3->valuestring); - strcpy(viewChannelData[n].confidence4, confidence4->valuestring); - //printf("\nenable_lpr_db-----6\n"); - pthread_mutex_lock(&mutex_enable_lpr_db); - enable_lpr_db = cJSON_GetObjectItem(camera, "enable_lpr_db"); - strcpy(viewChannelData[n].enable_lpr_db, enable_lpr_db->valuestring); - pthread_mutex_unlock(&mutex_enable_lpr_db); - - enable_downsized_cropped_roi = cJSON_GetObjectItem(camera, "enable_downsized_cropped_roi"); - set_enable_downsized_cropped_roi(enable_downsized_cropped_roi->valueint); - - enable_zone_crop_1 = cJSON_GetObjectItem(camera, "enable_zone_crop_1"); - set_enable_zone_crop_1(enable_zone_crop_1->valueint); - - viewChannelData[n].count_zone = count_zone->valueint; - - tab_view_size = cJSON_GetObjectItem(camera, "tab_view_size"); - //printf("\n[reload_dataset_from_jsonfile]tab_view_size: %s\n", tab_view_size->valuestring); - - char temp_array[256] = { 0 }; - strcpy(temp_array, tab_view_size->valuestring); - - char outArray[2][STRSPLIT_SIZE] = {0}; - StrSplit(temp_array, outArray, "x"); - //printf("\n------UU:15\n"); - viewChannelData[n].channel_idx = n; - if (outArray[0]) - viewChannelData[n].tab_view_width = atoi(outArray[0]); - if (outArray[1]) - viewChannelData[n].tab_view_height = atoi(outArray[1]); - - //printf("\n[reload_dataset_from_jsonfile]end:tab_view_size: %s\n", tab_view_size->valuestring); - - enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); - if (strcmp(enable_anpr->valuestring, "Yes") == 0) - viewChannelData[n].enable_anpr = 1; - else - viewChannelData[n].enable_anpr = 0; - - enable_face = cJSON_GetObjectItem(camera, "enable_face"); - if (strcmp(enable_face->valuestring, "Yes") == 0) - viewChannelData[n].enable_face = 1; - else - viewChannelData[n].enable_face = 0; - - enable_traffic = cJSON_GetObjectItem(camera, "enable_traffic"); - if (strcmp(enable_traffic->valuestring, "Yes") == 0) - viewChannelData[n].enable_traffic = 1; - else - viewChannelData[n].enable_traffic = 0; - - enable_logo = cJSON_GetObjectItem(camera, "enable_logo"); - if (strcmp(enable_logo->valuestring, "Yes") == 0) - viewChannelData[n].enable_logo = 1; - else - viewChannelData[n].enable_logo = 0; - - enable_add_face_frequent_list = cJSON_GetObjectItem(camera, "enable_add_face_frequent_list"); - if (enable_add_face_frequent_list) - if (strcmp(enable_add_face_frequent_list->valuestring, "Yes") == 0) - viewChannelData[n].enable_add_face_frequent_list = 1; - else - viewChannelData[n].enable_add_face_frequent_list = 0; - else { - viewChannelData[n].enable_add_face_frequent_list = 0; - } - - enable_PTZ = cJSON_GetObjectItem(camera, "enable_PTZ"); - strcpy(viewChannelData[n].enable_PTZ ,enable_PTZ->valuestring); - - ptz_tracking_fov_min = cJSON_GetObjectItem(camera, "ptz_tracking_fov_min"); - strcpy(viewChannelData[n].ptz_tracking_fov_min, ptz_tracking_fov_min->valuestring); - - ptz_tracking_fov_max = cJSON_GetObjectItem(camera, "ptz_tracking_fov_max"); - strcpy(viewChannelData[n].ptz_tracking_fov_max, ptz_tracking_fov_max->valuestring); - - ptz_enable_tracking = cJSON_GetObjectItem(camera, "ptz_enable_tracking"); - strcpy(viewChannelData[n].ptz_enable_tracking, ptz_enable_tracking->valuestring); - - //Tracking MODE - //1: First in First out - //2: Bigger first - //3: All - ptz_tracking_mode = cJSON_GetObjectItem(camera, "ptz_tracking_mode"); - if (ptz_tracking_mode) - viewChannelData[n].ptz_tracking_mode = atoi(ptz_tracking_mode->valuestring); - else - { - viewChannelData[n].ptz_tracking_mode = 1; - } - - ptz_tracking_by_enter_zone = cJSON_GetObjectItem(camera, "ptz_tracking_by_enter_zone"); - if (ptz_tracking_by_enter_zone) { - if (strcmp(ptz_tracking_by_enter_zone->valuestring, "Yes") == 0) - viewChannelData[n].ptz_tracking_by_enter_zone = 1; - else - viewChannelData[n].ptz_tracking_by_enter_zone = 0; - } - else { - viewChannelData[n].ptz_tracking_by_enter_zone = 1; - } - - enable_track = cJSON_GetObjectItem(camera, "enable_track"); - if (enable_track) - strcpy(viewChannelData[n].enable_track, enable_track->valuestring); - else { - strcpy(viewChannelData[n].enable_track, "No"); - } - - enable_tracking_limits = cJSON_GetObjectItem(camera, "enable_tracking_limits"); - if (enable_tracking_limits) - strcpy(viewChannelData[n].enable_tracking_limits, enable_tracking_limits->valuestring); - else { - strcpy(viewChannelData[n].enable_tracking_limits, "No"); - } - - ptz_pan_left_limit = cJSON_GetObjectItem(camera, "ptz_pan_left_limit"); - if (ptz_pan_left_limit) - strcpy(viewChannelData[n].ptz_pan_left_limit, ptz_pan_left_limit->valuestring); - else { - strcpy(viewChannelData[n].ptz_pan_left_limit, "0"); - } - - ptz_pan_right_limit = cJSON_GetObjectItem(camera, "ptz_pan_right_limit"); - if (ptz_pan_right_limit) - strcpy(viewChannelData[n].ptz_pan_right_limit, ptz_pan_right_limit->valuestring); - else { - strcpy(viewChannelData[n].ptz_pan_right_limit, "360"); - } - - ptz_tilt_up_limit = cJSON_GetObjectItem(camera, "ptz_tilt_up_limit"); - if (ptz_tilt_up_limit) - strcpy(viewChannelData[n].ptz_tilt_up_limit, ptz_tilt_up_limit->valuestring); - else { - strcpy(viewChannelData[n].ptz_tilt_up_limit, "0"); - } - - ptz_tilt_down_limit = cJSON_GetObjectItem(camera, "ptz_tilt_down_limit"); - if (ptz_tilt_down_limit) - strcpy(viewChannelData[n].ptz_tilt_down_limit, ptz_tilt_down_limit->valuestring); - else { - strcpy(viewChannelData[n].ptz_tilt_down_limit, "210"); - } - - ptz_speed = cJSON_GetObjectItem(camera, "ptz_speed"); - if (ptz_speed) - strcpy(viewChannelData[n].ptz_speed, ptz_speed->valuestring); - else { - strcpy(viewChannelData[n].ptz_speed, "3"); - } - - enable_unknown_object = cJSON_GetObjectItem(camera, "enable_unknown_object"); - if (enable_unknown_object) - strcpy(viewChannelData[n].enable_unknown_object, enable_unknown_object->valuestring); - else { - strcpy(viewChannelData[n].enable_unknown_object, "No"); - } - - enable_ivs_person_detection = cJSON_GetObjectItem(camera, "enable_ivs_person_detection"); - if (enable_ivs_person_detection) - strcpy(viewChannelData[n].enable_ivs_person_detection, enable_ivs_person_detection->valuestring); - else { - strcpy(viewChannelData[n].enable_ivs_person_detection, "No"); - } - - assign_ivs_object_to = cJSON_GetObjectItem(camera, "assign_ivs_object_to"); - if (assign_ivs_object_to) - strcpy(viewChannelData[n].assign_ivs_object_to, assign_ivs_object_to->valuestring); - else { - strcpy(viewChannelData[n].assign_ivs_object_to, ""); - } - - enable_ambulance = cJSON_GetObjectItem(camera, "enable_ambulance"); - if (enable_ambulance) - strcpy(viewChannelData[n].enable_ambulance, enable_ambulance->valuestring); - else { - strcpy(viewChannelData[n].enable_ambulance, "No"); - } - - enable_blank_plate = cJSON_GetObjectItem(camera, "enable_blank_plate"); - if (enable_blank_plate) - strcpy(viewChannelData[n].enable_blank_plate, enable_blank_plate->valuestring); - else { - strcpy(viewChannelData[n].enable_blank_plate, "No"); - } - - enable_stop_sign = cJSON_GetObjectItem(camera, "enable_stop_sign"); - if (enable_stop_sign) - strcpy(viewChannelData[n].enable_stop_sign, enable_stop_sign->valuestring); - else { - strcpy(viewChannelData[n].enable_stop_sign, "No"); - } - - enable_show_unknown_object = cJSON_GetObjectItem(camera, "enable_show_unknown_object"); - if (enable_show_unknown_object) - strcpy(viewChannelData[n].enable_show_unknown_object, enable_show_unknown_object->valuestring); - else { - strcpy(viewChannelData[n].enable_show_unknown_object, "No"); - } - - enable_ivs_fix_mode = cJSON_GetObjectItem(camera, "enable_ivs_fix_mode"); - if (enable_ivs_fix_mode) - strcpy(viewChannelData[n].enable_ivs_fix_mode, enable_ivs_fix_mode->valuestring); - else { - strcpy(viewChannelData[n].enable_ivs_fix_mode, "No"); - } - - enable_ivs_and_ai = cJSON_GetObjectItem(camera, "enable_ivs_and_ai"); - if (enable_ivs_and_ai) - strcpy(viewChannelData[n].enable_ivs_and_ai, enable_ivs_and_ai->valuestring); - else { - strcpy(viewChannelData[n].enable_ivs_and_ai, "No"); - } - - enable_lpr_upon_triggered = cJSON_GetObjectItem(camera, "enable_lpr_upon_triggered"); - if (enable_lpr_upon_triggered) - strcpy(viewChannelData[n].enable_lpr_upon_triggered, enable_lpr_upon_triggered->valuestring); - else { - strcpy(viewChannelData[n].enable_lpr_upon_triggered, "No"); - } - - dwell_lpr_upon_triggered = cJSON_GetObjectItem(camera, "dwell_lpr_upon_triggered"); - if (dwell_lpr_upon_triggered) - strcpy(viewChannelData[n].dwell_lpr_upon_triggered, dwell_lpr_upon_triggered->valuestring); - else { - strcpy(viewChannelData[n].dwell_lpr_upon_triggered, "10"); - } - - unknown_object_max_proportion = cJSON_GetObjectItem(camera, "unknown_object_max_proportion"); - if(unknown_object_max_proportion) - strcpy(viewChannelData[n].unknown_object_max_proportion, unknown_object_max_proportion->valuestring); - else - strcpy(viewChannelData[n].unknown_object_max_proportion, "20"); - - unknown_object_min_proportion = cJSON_GetObjectItem(camera, "unknown_object_min_proportion"); - if (unknown_object_min_proportion) - strcpy(viewChannelData[n].unknown_object_min_proportion, unknown_object_min_proportion->valuestring); - else - strcpy(viewChannelData[n].unknown_object_min_proportion, "0"); - - confidence_unknown_object = cJSON_GetObjectItem(camera, "confidence_unknown_object"); - if (confidence_unknown_object) - strcpy(viewChannelData[n].confidence_unknown_object, confidence_unknown_object->valuestring); - else - strcpy(viewChannelData[n].confidence_unknown_object, "0"); - - confidence2_unknown_object = cJSON_GetObjectItem(camera, "confidence2_unknown_object"); - if (confidence2_unknown_object) - strcpy(viewChannelData[n].confidence2_unknown_object, confidence2_unknown_object->valuestring); - else - strcpy(viewChannelData[n].confidence2_unknown_object, "0"); - - dwell_unknown_object = cJSON_GetObjectItem(camera, "dwell_unknown_object"); - if(dwell_unknown_object) - strcpy(viewChannelData[n].dwell_unknown_object, dwell_unknown_object->valuestring); - else - strcpy(viewChannelData[n].dwell_unknown_object, "30"); - - dwell_minute_focus_on = cJSON_GetObjectItem(camera, "dwell_minute_focus_on"); - if (dwell_minute_focus_on) - strcpy(viewChannelData[n].dwell_minute_focus_on, dwell_minute_focus_on->valuestring); - else - strcpy(viewChannelData[n].dwell_minute_focus_on, "5"); - - - person_obj_fov = cJSON_GetObjectItem(camera, "person_obj_fov"); - if (person_obj_fov) - strcpy(viewChannelData[n].person_obj_fov, person_obj_fov->valuestring); - else - strcpy(viewChannelData[n].person_obj_fov, "100"); - - - ivs_mode = cJSON_GetObjectItem(detect, "ivs_mode"); - if (ivs_mode) - strcpy(viewChannelData[n].ivs_mode, ivs_mode->valuestring); - else - strcpy(viewChannelData[n].ivs_mode, "3"); - - getnetwork_buffer_id = cJSON_GetObjectItem(camera, "getnetwork_buffer_id"); - if (getnetwork_buffer_id) { - if (strlen(viewChannelData[n].getnetwork_buffer_id)>=1 && strcmp(viewChannelData[n].getnetwork_buffer_id, getnetwork_buffer_id->valuestring) != 0) { -#ifdef GY_OS_AMBA - printf("\n-----------------------get network buffer id: exit-----------------------\n"); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "getnetwork_buffer_id change"); - write_to_logs_html(temp_msg, "reload dataset", "CGI_REBOOT", "Yes"); - write_to_log_if_error(temp_msg, "reload dataset", "CGI_REBOOT"); - - pthread_t auto_reboot_thread_id; - if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) - { - printf("\ncreate auto reboot thread faile \n"); - } -#else - -#endif - } - } - else - strcpy(viewChannelData[n].getnetwork_buffer_id, "1"); - - red_light_zone = cJSON_GetObjectItem(camera, "red_light_zone"); - if (red_light_zone) - strcpy(viewChannelData[n].red_light_zone, red_light_zone->valuestring); - else - strcpy(viewChannelData[n].red_light_zone, ""); - - no_give_way_zone_to_protect = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect"); - if (no_give_way_zone_to_protect) - strcpy(viewChannelData[n].no_give_way_zone_to_protect, no_give_way_zone_to_protect->valuestring); - else - strcpy(viewChannelData[n].no_give_way_zone_to_protect, ""); - - no_give_way_zone_to_keep_away = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away"); - if (no_give_way_zone_to_keep_away) - strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, no_give_way_zone_to_keep_away->valuestring); - else - strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, ""); - - no_give_way_zone_to_protect_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect_2"); - if (no_give_way_zone_to_protect_2) - strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, no_give_way_zone_to_protect_2->valuestring); - else - strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, ""); - - no_give_way_zone_to_keep_away_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away_2"); - if (no_give_way_zone_to_keep_away_2) - strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, no_give_way_zone_to_keep_away_2->valuestring); - else - strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, ""); - - ptz_sensitivity = cJSON_GetObjectItem(camera, "ptz_sensitivity"); - if (ptz_sensitivity) - viewChannelData[n].ptz_sensitivity = atoi(ptz_sensitivity->valuestring); - else - { - viewChannelData[n].ptz_sensitivity = 6; - } - //printf("\n-------------ptz_sensitivity:%d\n", viewChannelData[n].ptz_sensitivity); - - ptz_tracking_resume_dwell = cJSON_GetObjectItem(camera, "ptz_tracking_resume_dwell"); - strcpy(viewChannelData[n].ptz_tracking_resume_dwell, ptz_tracking_resume_dwell->valuestring); - - cJSON_enable_only_show_metadata1 = cJSON_GetObjectItem(camera, "enable_only_show_metadata1"); - enable_only_show_metadata1 = cJSON_enable_only_show_metadata1->valueint; - - detection_zone = cJSON_GetObjectItem(camera, "detection_zone"); - - viewChannelData[n].enable_traffic_light_zone = 0; - - int i = 0; - cJSON_ArrayForEach(detect, detection_zone) - { - obj_max_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_max_proportion_in_zone"); - obj_min_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_min_proportion_in_zone"); - - enable_traffic_light = cJSON_GetObjectItem(detect, "enable_traffic_light"); - - detection_time = cJSON_GetObjectItem(detect, "detection_time"); - metadata1 = cJSON_GetObjectItem(detect, "metadata1"); - metadata2 = cJSON_GetObjectItem(detect, "metadata2"); - metadata_stop = cJSON_GetObjectItem(detect, "metadata_stop"); - link_to_counter = cJSON_GetObjectItem(detect, "link_to_counter"); - enable_direction1 = cJSON_GetObjectItem(detect, "enable_direction1"); - enable_direction2 = cJSON_GetObjectItem(detect, "enable_direction2"); - direction1 = cJSON_GetObjectItem(detect, "direction1"); - direction2 = cJSON_GetObjectItem(detect, "direction2"); - no_parking_time = cJSON_GetObjectItem(detect, "no_parking_time"); - no_parking_time_in_minute = cJSON_GetObjectItem(detect, "no_parking_time_in_minute"); - queuing_count = cJSON_GetObjectItem(detect, "queuing_count"); - - enable_speed = cJSON_GetObjectItem(detect, "enable_speed"); - enable_radar_speed = cJSON_GetObjectItem(detect, "enable_radar_speed"); - enable_ivs_zone = cJSON_GetObjectItem(detect, "enable_ivs_zone"); - world_time_unit = cJSON_GetObjectItem(detect, "world_time_unit"); - - ptz_zone_to_preset = cJSON_GetObjectItem(detect, "ptz_zone_to_preset"); - strcpy(viewDetectionZone[n][i].ptz_zone_to_preset, ptz_zone_to_preset->valuestring); - - trigger_events[i] = cJSON_GetObjectItem(detect, "trigger_events"); - - point_number = cJSON_GetObjectItem(detect, "point_number"); - - parking_space = cJSON_GetObjectItem(detect, "parking_space"); - parking_line = cJSON_GetObjectItem(detect, "parking_line"); - - //Social Distance - set_distance = cJSON_GetObjectItem(detect, "set_distance"); - world_distance_unit = cJSON_GetObjectItem(detect, "world_distance_unit"); - world_distance_side1 = cJSON_GetObjectItem(detect, "world_distance_side1"); - world_distance_side2 = cJSON_GetObjectItem(detect, "world_distance_side2"); - //Social Distance - - /* - if(point_number) - printf("load point number = %d \n", point_number->valueint); -*/ - x1 = cJSON_GetObjectItem(detect, "x1"); - y1 = cJSON_GetObjectItem(detect, "y1"); - x2 = cJSON_GetObjectItem(detect, "x2"); - y2 = cJSON_GetObjectItem(detect, "y2"); - x3 = cJSON_GetObjectItem(detect, "x3"); - y3 = cJSON_GetObjectItem(detect, "y3"); - x4 = cJSON_GetObjectItem(detect, "x4"); - y4 = cJSON_GetObjectItem(detect, "y4"); - - x5 = cJSON_GetObjectItem(detect, "x5"); - y5 = cJSON_GetObjectItem(detect, "y5"); - x6 = cJSON_GetObjectItem(detect, "x6"); - y6 = cJSON_GetObjectItem(detect, "y6"); - - strcpy(viewDetectionZone[n][i].detection_time, detection_time->valuestring); - strcpy(viewDetectionZone[n][i].metadata1, metadata1->valuestring); - strcpy(viewDetectionZone[n][i].metadata2, metadata2->valuestring); - if(metadata_stop) - strcpy(viewDetectionZone[n][i].metadata_stop, metadata_stop->valuestring); - strcpy(viewDetectionZone[n][i].link_to_counter, link_to_counter->valuestring); - strcpy(viewDetectionZone[n][i].enable_direction1, enable_direction1->valuestring); - strcpy(viewDetectionZone[n][i].enable_direction2, enable_direction2->valuestring); - strcpy(viewDetectionZone[n][i].direction1, direction1->valuestring); - strcpy(viewDetectionZone[n][i].direction2, direction2->valuestring); - if (no_parking_time) - viewDetectionZone[n][i].no_parking_time = atoi(no_parking_time->valuestring); - if (no_parking_time_in_minute) - viewDetectionZone[n][i].no_parking_time_in_minute = atoi(no_parking_time_in_minute->valuestring); - if (queuing_count) - viewDetectionZone[n][i].queuing_count = atoi(queuing_count->valuestring); - - if (parking_space) - { - viewDetectionZone[n][i].parking_space = atoi(parking_space->valuestring); - } - - if (parking_line) - { - viewDetectionZone[n][i].parking_line = atoi(parking_line->valuestring); - } - - //Social Distance - if (set_distance) - { - viewDetectionZone[n][i].set_distance = atof(set_distance->valuestring); - } - - if (world_distance_unit) - { - strcpy(viewDetectionZone[n][i].world_distance_unit, world_distance_unit->valuestring); - } - if (world_distance_side1) - { - viewDetectionZone[n][i].world_distance[0] = atof(world_distance_side1->valuestring); - viewDetectionZone[n][i].world_distance[2] = atof(world_distance_side1->valuestring); - } - - - //Fake data - //viewDetectionZone[n][i].world_distance[0] = 1000; - //viewDetectionZone[n][i].world_distance[2] = 1000; - - if (world_distance_side2) - { - viewDetectionZone[n][i].world_distance[1] = atof(world_distance_side2->valuestring); - viewDetectionZone[n][i].world_distance[3] = atof(world_distance_side2->valuestring); - } - //Social Distance - if(obj_max_proportion_in_zone) - strcpy(viewDetectionZone[n][i].obj_max_proportion_in_zone, obj_max_proportion_in_zone->valuestring); - if(obj_min_proportion_in_zone) - strcpy(viewDetectionZone[n][i].obj_min_proportion_in_zone, obj_min_proportion_in_zone->valuestring); - - if (point_number) - { - viewDetectionZone[n][i].point_num = point_number->valueint; - } - - if (enable_speed) - strcpy(viewDetectionZone[n][i].enable_speed, enable_speed->valuestring); - if (enable_radar_speed) - strcpy(viewDetectionZone[n][i].enable_radar_speed, enable_radar_speed->valuestring); - if (enable_ivs_zone) - strcpy(viewDetectionZone[n][i].enable_ivs_zone, enable_ivs_zone->valuestring); - if (world_time_unit) - strcpy(viewDetectionZone[n][i].world_time_unit, world_time_unit->valuestring); - - viewDetectionZone[n][i].Points[0].x = x1->valueint; - viewDetectionZone[n][i].Points[0].y = y1->valueint; - viewDetectionZone[n][i].Points[1].x = x2->valueint; - viewDetectionZone[n][i].Points[1].y = y2->valueint; - viewDetectionZone[n][i].Points[2].x = x3->valueint; - viewDetectionZone[n][i].Points[2].y = y3->valueint; - viewDetectionZone[n][i].Points[3].x = x4->valueint; - viewDetectionZone[n][i].Points[3].y = y4->valueint; - - viewDetectionZone[n][i].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)x1->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)y1->valueint, CANVAS_HEIGHT / 2); - viewDetectionZone[n][i].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)x2->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)y2->valueint, CANVAS_HEIGHT / 2); - viewDetectionZone[n][i].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)x3->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)y3->valueint, CANVAS_HEIGHT / 2); - viewDetectionZone[n][i].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)x4->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)y4->valueint, CANVAS_HEIGHT / 2); - - if (x5 && x6) - { - viewDetectionZone[n][i].Points[4].x = x5->valueint; - viewDetectionZone[n][i].Points[4].y = y5->valueint; - viewDetectionZone[n][i].Points[5].x = x6->valueint; - viewDetectionZone[n][i].Points[5].y = y6->valueint; - - viewDetectionZone[n][i].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)x5->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)y5->valueint, CANVAS_HEIGHT / 2); - viewDetectionZone[n][i].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)x6->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)y6->valueint, CANVAS_HEIGHT / 2); - } - - - viewChannelData[n].tab_view_width_ratio = (float)1; - viewChannelData[n].tab_view_height_ratio = (float)1; - - viewChannelData[n].speed_view_width_ratio = (float)(1920 / 889); - viewChannelData[n].speed_view_height_ratio = (float)(1080 / 500); - - //viewChannelData[n].tab_view_height = 1; - - - strcpy(viewDetectionZone[n][i].enable_traffic_light, enable_traffic_light->valuestring); - if (strncmp(viewDetectionZone[n][i].enable_traffic_light, "Yes", strlen("Yes")) == 0) - { - viewChannelData[n].enable_traffic_light_zone = i + 1; - //UpdateTrafficLightZone(n); - } - -#ifdef GY_OS_AMBA - if (strncmp(viewDetectionZone[n][i].enable_speed, "Yes", strlen("Yes")) == 0) - { - int social_zone_idx = i; - if (social_zone_idx >= 0) - { - pthread_mutex_lock(&mutex_perspective_transform); - if (viewDetectionZone[n][i].PerspectiveTransformArray != NULL) - cvReleaseMat(&viewDetectionZone[n][i].PerspectiveTransformArray); - viewDetectionZone[n][i].PerspectiveTransformArray = GetPerspectiveTransformArray(n, social_zone_idx); - pthread_mutex_unlock(&mutex_perspective_transform); - } - } -#endif - - i++; - - if (i < MAX_DETECTION_ZONE) { - - } - else { - break; - } - } - - //int arraySize = cJSON_GetArraySize(detection_zone); - int k = 0; - for (int j = 0; j < MAX_DETECTION_ZONE; j++) - { - k = 0; - cJSON_ArrayForEach(detect, trigger_events[j]) - { - checked = cJSON_GetObjectItem(detect, "checked"); - detect_event_id = cJSON_GetObjectItem(detect, "detect_event_id"); - detect_event_name = cJSON_GetObjectItem(detect, "detect_event_name"); - post_event_name = cJSON_GetObjectItem(detect, "post_event_name"); - counter_name = cJSON_GetObjectItem(detect, "counter_name"); - counter_increment = cJSON_GetObjectItem(detect, "counter_increment"); - - viewDetectionZone[n][j].trigger_event[k].checked = checked->valueint; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, detect_event_id->valuestring); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, detect_event_name->valuestring); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, post_event_name->valuestring); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, counter_name->valuestring); - - if (counter_increment) { - if (strcmp(counter_increment->valuestring, "counter_increment_add") == 0) - viewDetectionZone[n][j].trigger_event[k].counter_increment = 1; - else if (strcmp(counter_increment->valuestring, "counter_increment_minus") == 0) - viewDetectionZone[n][j].trigger_event[k].counter_increment = -1; - else if (strcmp(counter_increment->valuestring, "counter_increment_equal") == 0) - viewDetectionZone[n][j].trigger_event[k].counter_increment = 0; - else - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - } - else - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - } - } - - cJSON *system_setting,*enable_cloud,*enable_special_edition, *enable_python, *enable_python_file, *enable_low_cpu_usage,*nms_thres, *tracking_id_dwell,*enable_person_independent,*enable_onvif_profile_m,*cloud_enable_snap,*cloud_enable_notification, *cloud_account, *cloud_password, *cloud_notification_dwell, *cloud_statue,*language,*display_properties,*display_OSD, - *enable_bounding_box,*enable_dwell_bounding_box,*enable_special_char,*force_i_to_one, *force_o_to_zero, *enable_plate_angle_correction,*enable_ai_mirror,*ai_mirror_feature,*enable_post_only_if_both_detected,*enable_getalarmmotion_snap, *getimage_encoder_id, *getimage_encoder_id_HD, *osd_encoder_id, *osd_font_size, *osd_outline_lilin,*enable_osd_bottom,*osd_bottom_bg_tran, *osd_bottom_content,*enable_sync_external_lpr_db, *external_lpr_db_IP, *external_lpr_db_port, *external_lpr_db_username, *external_lpr_db_password, - *enable_email_notification,*email_reset_time_interval,*enable_system_logs,*enable_email_jpeg,*display_dash,*sensors_type,*enable_ftp,*ftp_url,*ftp_port,*ftp_username,*ftp_password,*ftp_remote_directory,*ftp_jpeg_file_name_format,*ftp_jpeg_file_name; - cJSON *enable_cloud_v2, *cloud_v2_notification_dwell, *cloud_v2_content, *enable_cloud_record_v2, *cloud_record_v2_notification_dwell, *cloud_record_v2_content,*cloud_v2_statue,*cloud_record_v2_statue; - - system_setting = cJSON_GetObjectItem(g_config_root, "system_setting"); - - enable_person_independent = cJSON_GetObjectItem(system_setting, "enable_person_independent"); - strcpy(SystemSetting.enable_person_independent, enable_person_independent->valuestring); - - enable_onvif_profile_m = cJSON_GetObjectItem(system_setting, "enable_onvif_profile_m"); - strcpy(SystemSetting.enable_onvif_profile_m, enable_onvif_profile_m->valuestring); - - nms_thres = cJSON_GetObjectItem(system_setting, "nms_thres"); - strcpy(SystemSetting.nms_thres, nms_thres->valuestring); - - tracking_id_dwell = cJSON_GetObjectItem(system_setting, "tracking_id_dwell"); - strcpy(SystemSetting.tracking_id_dwell, tracking_id_dwell->valuestring); - - enable_cloud = cJSON_GetObjectItem(system_setting, "enable_cloud"); - strcpy(SystemSetting.enable_cloud, enable_cloud->valuestring); - - enable_special_edition = cJSON_GetObjectItem(system_setting, "enable_special_edition"); - strcpy(SystemSetting.enable_special_edition, enable_special_edition->valuestring); - - enable_python = cJSON_GetObjectItem(system_setting, "enable_python"); - strcpy(SystemSetting.enable_python, enable_python->valuestring); - - enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); - strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); - - enable_low_cpu_usage = cJSON_GetObjectItem(system_setting, "enable_low_cpu_usage"); - strcpy(SystemSetting.enable_low_cpu_usage, enable_low_cpu_usage->valuestring); - - cloud_enable_notification = cJSON_GetObjectItem(system_setting, "cloud_enable_notification"); - strcpy(SystemSetting.cloud_enable_notification, cloud_enable_notification->valuestring); - - cloud_enable_snap = cJSON_GetObjectItem(system_setting, "cloud_enable_snap"); - strcpy(SystemSetting.cloud_enable_snap, cloud_enable_snap->valuestring); - - cloud_account = cJSON_GetObjectItem(system_setting, "cloud_account"); - strcpy(SystemSetting.cloud_account, cloud_account->valuestring); - - cloud_password = cJSON_GetObjectItem(system_setting, "cloud_password"); - strcpy(SystemSetting.cloud_password, cloud_password->valuestring); - - cloud_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_notification_dwell"); - strcpy(SystemSetting.cloud_notification_dwell, cloud_notification_dwell->valuestring); - - cloud_statue = cJSON_GetObjectItem(system_setting, "cloud_statue"); - strcpy(SystemSetting.cloud_statue, cloud_statue->valuestring); - - cloud_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_v2_statue"); - strcpy(SystemSetting.cloud_v2_statue, cloud_v2_statue->valuestring); - - cloud_record_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_record_v2_statue"); - strcpy(SystemSetting.cloud_record_v2_statue, cloud_record_v2_statue->valuestring); - - language = cJSON_GetObjectItem(system_setting, "language"); - strcpy(SystemSetting.language, language->valuestring); - - display_dash = cJSON_GetObjectItem(system_setting, "display dash"); - activeDisplayDash = (strcmp(display_dash->valuestring, "Yes") == 0) ? _TRUE : _FALSE; - - display_properties = cJSON_GetObjectItem(system_setting, "display properties"); - strcpy(SystemSetting.enable_display_properties, display_properties->valuestring); - - display_OSD = cJSON_GetObjectItem(system_setting, "display OSD"); - strcpy(SystemSetting.enable_display_OSD, display_OSD->valuestring); - - enable_special_char = cJSON_GetObjectItem(system_setting, "enable_special_char"); - strcpy(SystemSetting.enable_special_char, enable_special_char->valuestring); - - enable_bounding_box = cJSON_GetObjectItem(system_setting, "enable_bounding_box"); - strcpy(SystemSetting.enable_bounding_box, enable_bounding_box->valuestring); - - enable_dwell_bounding_box = cJSON_GetObjectItem(system_setting, "enable_dwell_bounding_box"); - strcpy(SystemSetting.enable_dwell_bounding_box, enable_dwell_bounding_box->valuestring); - - force_i_to_one = cJSON_GetObjectItem(system_setting, "force_i_to_one"); - strcpy(SystemSetting.force_i_to_one, force_i_to_one->valuestring); - - force_o_to_zero = cJSON_GetObjectItem(system_setting, "force_o_to_zero"); - strcpy(SystemSetting.force_o_to_zero, force_o_to_zero->valuestring); - - enable_plate_angle_correction = cJSON_GetObjectItem(system_setting, "enable_plate_angle_correction"); - strcpy(SystemSetting.enable_plate_angle_correction, enable_plate_angle_correction->valuestring); - - enable_ai_mirror = cJSON_GetObjectItem(system_setting, "enable_ai_mirror"); - strcpy(SystemSetting.enable_ai_mirror, enable_ai_mirror->valuestring); - - ai_mirror_feature = cJSON_GetObjectItem(system_setting, "ai_mirror_feature"); - strcpy(SystemSetting.ai_mirror_feature, ai_mirror_feature->valuestring); - - enable_cloud_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_v2"); - strcpy(SystemSetting.enable_cloud_v2, enable_cloud_v2->valuestring); - - cloud_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_v2_notification_dwell"); - strcpy(SystemSetting.cloud_v2_notification_dwell, cloud_v2_notification_dwell->valuestring); - - cloud_v2_content = cJSON_GetObjectItem(system_setting, "cloud_v2_content"); - strcpy(SystemSetting.cloud_v2_content, cloud_v2_content->valuestring); - - enable_cloud_record_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_record_v2"); - strcpy(SystemSetting.enable_cloud_record_v2, enable_cloud_record_v2->valuestring); - - cloud_record_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_record_v2_notification_dwell"); - strcpy(SystemSetting.cloud_record_v2_notification_dwell, cloud_record_v2_notification_dwell->valuestring); - - cloud_record_v2_content = cJSON_GetObjectItem(system_setting, "cloud_record_v2_content"); - strcpy(SystemSetting.cloud_record_v2_content, cloud_record_v2_content->valuestring); - - enable_post_only_if_both_detected = cJSON_GetObjectItem(system_setting, "enable_post_only_if_both_detected"); - strcpy(SystemSetting.enable_post_only_if_both_detected, enable_post_only_if_both_detected->valuestring); - - enable_getalarmmotion_snap = cJSON_GetObjectItem(system_setting, "enable_getalarmmotion_snap"); - strcpy(SystemSetting.enable_getalarmmotion_snap, enable_getalarmmotion_snap->valuestring); - - getimage_encoder_id = cJSON_GetObjectItem(system_setting, "getimage_encoder_id"); - strcpy(SystemSetting.getimage_encoder_id, getimage_encoder_id->valuestring); - - getimage_encoder_id_HD = cJSON_GetObjectItem(system_setting, "getimage_encoder_id_HD"); - strcpy(SystemSetting.getimage_encoder_id_HD, getimage_encoder_id_HD->valuestring); - - osd_encoder_id = cJSON_GetObjectItem(system_setting, "osd_encoder_id"); - strcpy(SystemSetting.osd_encoder_id, osd_encoder_id->valuestring); - - osd_font_size = cJSON_GetObjectItem(system_setting, "osd_font_size"); - strcpy(SystemSetting.osd_font_size, osd_font_size->valuestring); - - osd_outline_lilin = cJSON_GetObjectItem(system_setting, "osd_outline_lilin"); - strcpy(SystemSetting.osd_outline_lilin, osd_outline_lilin->valuestring); - - enable_osd_bottom = cJSON_GetObjectItem(system_setting, "enable_osd_bottom"); - strcpy(SystemSetting.enable_osd_bottom, enable_osd_bottom->valuestring); - - osd_bottom_bg_tran = cJSON_GetObjectItem(system_setting, "osd_bottom_bg_tran"); - strcpy(SystemSetting.osd_bottom_bg_tran, osd_bottom_bg_tran->valuestring); - - osd_bottom_content = cJSON_GetObjectItem(system_setting, "osd_bottom_content"); - strcpy(SystemSetting.osd_bottom_content, osd_bottom_content->valuestring); - - sensors_type = cJSON_GetObjectItem(system_setting, "sensors_type"); - strcpy(SystemSetting.sensors_type, sensors_type->valuestring); - - enable_sync_external_lpr_db = cJSON_GetObjectItem(system_setting, "enable_sync_external_lpr_db"); - strcpy(SystemSetting.enable_sync_external_lpr_db, enable_sync_external_lpr_db->valuestring); - - external_lpr_db_IP = cJSON_GetObjectItem(system_setting, "external_lpr_db_IP"); - strcpy(SystemSetting.external_lpr_db_IP, external_lpr_db_IP->valuestring); - - external_lpr_db_port = cJSON_GetObjectItem(system_setting, "external_lpr_db_port"); - strcpy(SystemSetting.external_lpr_db_port, external_lpr_db_port->valuestring); - - external_lpr_db_username = cJSON_GetObjectItem(system_setting, "external_lpr_db_username"); - strcpy(SystemSetting.external_lpr_db_username, external_lpr_db_username->valuestring); - - external_lpr_db_password = cJSON_GetObjectItem(system_setting, "external_lpr_db_password"); - strcpy(SystemSetting.external_lpr_db_password, external_lpr_db_password->valuestring); - - enable_email_notification = cJSON_GetObjectItem(system_setting, "enable_email_notification"); - strcpy(SystemSetting.enable_email_notification, enable_email_notification->valuestring); - - enable_system_logs = cJSON_GetObjectItem(system_setting, "enable_system_logs"); - strcpy(SystemSetting.enable_system_logs, enable_system_logs->valuestring); - - enable_email_jpeg = cJSON_GetObjectItem(system_setting, "enable_email_jpeg"); - strcpy(SystemSetting.enable_email_jpeg, enable_email_jpeg->valuestring); - - email_reset_time_interval = cJSON_GetObjectItem(system_setting, "email_reset_time_interval"); - strcpy(SystemSetting.email_reset_time_interval, email_reset_time_interval->valuestring); - - enable_ftp = cJSON_GetObjectItem(system_setting, "enable_ftp"); - strcpy(SystemSetting.enable_ftp, enable_ftp->valuestring); - - ftp_url = cJSON_GetObjectItem(system_setting, "ftp_url"); - strcpy(SystemSetting.ftp_url, ftp_url->valuestring); - - ftp_port = cJSON_GetObjectItem(system_setting, "ftp_port"); - strcpy(SystemSetting.ftp_port, ftp_port->valuestring); - - ftp_username = cJSON_GetObjectItem(system_setting, "ftp_username"); - strcpy(SystemSetting.ftp_username, ftp_username->valuestring); - - ftp_password = cJSON_GetObjectItem(system_setting, "ftp_password"); - strcpy(SystemSetting.ftp_password, ftp_password->valuestring); - - ftp_remote_directory = cJSON_GetObjectItem(system_setting, "ftp_remote_directory"); - strcpy(SystemSetting.ftp_remote_directory, ftp_remote_directory->valuestring); - - ftp_jpeg_file_name_format = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name_format"); - strcpy(SystemSetting.ftp_jpeg_file_name_format, ftp_jpeg_file_name_format->valuestring); - - ftp_jpeg_file_name = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name"); - strcpy(SystemSetting.ftp_jpeg_file_name, ftp_jpeg_file_name->valuestring); - - cJSON *about_box,*cJSON_strUnlockingKey; - about_box = cJSON_GetObjectItem(g_config_root, "about_box"); - if (about_box) { - cJSON_strUnlockingKey = cJSON_GetObjectItem(about_box, "unlocking key"); - if (cJSON_strUnlockingKey && strlen(cJSON_strUnlockingKey->valuestring)>=1 && strcmp(strUnlockingKey, cJSON_strUnlockingKey->valuestring)!=0) { - memset(strUnlockingKey,0x00,sizeof(strUnlockingKey)); - strcpy(strUnlockingKey, cJSON_strUnlockingKey->valuestring); - - char buf_exe[1024] = {}; - readlink("/proc/self/exe", buf_exe, sizeof(buf_exe)); - - char exePath_temp[1024] = {}; - getFilePath(buf_exe, exePath_temp, 1024); - - char keyPATH[1024] = { 0 }; - strcpy(keyPATH, exePath_temp); - strcat(keyPATH, "key.txt"); - if (FileExist(keyPATH) == 1) { - FILE *pFile; - - if ((pFile = fopen(keyPATH, "w")) != NULL) - { - fprintf(pFile, strUnlockingKey); - fclose(pFile); - - } - else - printf("Fail to open key.txt \n"); - } - - memset(strLicenseStatus, 0x00, sizeof(strLicenseStatus)); - strcpy(strLicenseStatus, "Please restart gynet to run AI with new key."); - } - } - - if (root) { - cJSON_Delete(root); - root = NULL; - } - - if (g_config_root) { - cJSON_Delete(g_config_root); - g_config_root = NULL; - } -#ifdef GY_OS_AMBA - /*int zone_to_preset[MAX_DETECTION_ZONE]; - - for (int i = 0; i < MAX_DETECTION_ZONE; i++) - { - zone_to_preset[i] = 0; - - if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL - && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) - { - zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); - } - }*/ - - //Update PTZ - /*UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, - viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, - viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, viewChannelData[0].ptz_tracking_resume_dwell, - viewDetectionZone[0][0].metadata1, zone_to_preset);*/ - if (g_IsPTZDevice == 1) { - UpdatePTZConfigSetting(); - - SetPtzSensitivity(viewChannelData[0].ptz_sensitivity); - } - -#endif - //Reload cold zone - /*int iReadCodeZoneRet = */ReadColdZoneJsonFile(); - -#ifdef GY_OS_AMBA - if (!g_IsPTZDevice && get_g_PTZ_model() != 659 && get_g_PTZ_model() != 715 && get_g_PTZ_model() != 714 && get_g_PTZ_model() != 731 && get_g_PTZ_model() != 716) { - if (enable_ai_mirror && ai_mirror_feature) { - if (strcmp(SystemSetting.enable_ai_mirror, "Yes") == 0) { - - if (strcmp(SystemSetting.ai_mirror_feature, "1") == 0) - { - FILE * pPipe; - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - -#ifdef GY_OS_AMBA - sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 2"); -#else - sprintf(cmd, "/usr/local/bin/test_vin -m 2"); -#endif - - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); - } - else { - FILE * pPipe; - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - -#ifdef GY_OS_AMBA - sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 0"); -#else - sprintf(cmd, "/usr/local/bin/test_vin -m 0"); -#endif - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); - } - } - } - } -#endif - - return 0; -} - -// 2021.01.21 Jim added. -// 2021.05.12 Cayman fixed returned values. -#if 0 -int default_dataset_for_jsonfile(void) -{ - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char configPATH[1024] = { 0 }; - char config_bakPATH[1024] = { 0 }; - char eventsPATH[1024] = { 0 }; - - strcpy(configPATH, exePath); - strcpy(config_bakPATH, exePath); - strcpy(eventsPATH, exePath); - - strcat(configPATH, "config.json"); - strcat(config_bakPATH, "config_bak.json"); - strcat(eventsPATH, "events.json"); - - - char *filename; - //filename = config_bakPATH; - filename = configPATH; - - if (!FileExist(filename)) - { - printf("%s doesn't exist.\n", filename); - return 1; - } - - //printf("read config.json. %s\n", filename); - - //size_t nfileSize = ReadFileSize(filename); - char* fileBuf = ReadAllBytes(filename); - if (fileBuf == NULL) { - printf("fileBuf FAIL.\n"); - return 1; - } - - cJSON *root = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - - if (root) { - //printf("config.json parse OK.\n"); - } - else - { - printf("config.json parse FAIL.\n"); - return 1; - } - - cJSON* about_box = cJSON_GetObjectItem(root, "about_box"); - cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString(strUnlockingKey)); - - char* JsonString = cJSON_Print(root); - FILE *fp; - - if ((fp = fopen(filename, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - - CopyFileTo(filename, config_bakPATH); - } - else - { - printf("Fail to open Config.json \n"); - return 1; - } - - //copy config.json to config_bak.json - - - if (JsonString != NULL) { - free(JsonString); - JsonString = NULL; - } - if (root) { - cJSON_Delete(root); - root = NULL; - } - return 0; -} -#endif //GY_OS_AMBA - - -#ifdef GY_OS_AMBA -static long delete_now_heatmap = 0; -struct timeval delete_currtime_heatmap; -void delete_heatmap_image() { - gettimeofday(&delete_currtime_heatmap, NULL); - delete_now_heatmap = (delete_currtime_heatmap.tv_sec * 1000) + (delete_currtime_heatmap.tv_usec / 1000); //單位為毫秒 - delete_now_heatmap = delete_now_heatmap / 1000 * 1000; - - pthread_mutex_lock(&mutex_heatmap_jpeg); - DIR *d_file; - struct dirent *dir_file; - d_file = opendir("/emmc/plugin/Aida_data/playback"); - if (d_file) { - while ((dir_file = readdir(d_file)) != NULL) { - if (strlen(dir_file->d_name) >= 17) { - char temp_d_name[50] = { 0 }; - for (int i = 0; i < strlen(dir_file->d_name)-4; i++) { - temp_d_name[i] = dir_file->d_name[i]; - } - - if (atol(temp_d_name) <= delete_now_heatmap - 15 * 24 * 60 * 60 * 1000 / 2) {//15/2=7.5 - FILE * pPipe; - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); -#ifdef GY_OS_AMBA - sprintf(cmd, "timeout 10s rm -rf /emmc/plugin/Aida_data/playback/%ld.jpg", atol(temp_d_name)); -#else - sprintf(cmd, "rm -rf /emmc/plugin/Aida_data/playback/%ld.jpg", atol(temp_d_name)); -#endif - - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); - } - - //usSleep(10000); - - //printf("\n-------temp_d_name:%ld\n", atol(temp_d_name)); - } - } - closedir(d_file); - } - pthread_mutex_unlock(&mutex_heatmap_jpeg); - - //printf("\n-------delete_now_heatmap:%ld\n", delete_now_heatmap); -} -#endif - -#if defined GY_OS_AMBA || defined GY_OS_NOVA -void * delete_jpg_in_seven_days_detector(void *ptr) { - pthread_detach(pthread_self()); - setPthreadName("delete_seven"); - int check_delete = 0; - int delete_time = 1; - int delete_time2 = 7; - int delete_time3 = 13; - int delete_time4 = 19; - - delete_jpg_in_seven_days(); -#ifdef GY_OS_AMBA - delete_heatmap_image(); -#endif - - while (bHttpServerThreadStart) { - - //printf("\n------delete jpg in seven days detector start\n"); - - if (iFeature_lpr_layer_index >= 0) { - - time_t rawtime = time(0); - struct tm * timeinfo; - time(&rawtime); - timeinfo = localtime(&rawtime); - - if ((timeinfo->tm_hour == delete_time || - timeinfo->tm_hour == delete_time2 || - timeinfo->tm_hour == delete_time3 || - timeinfo->tm_hour == delete_time4) - && check_delete == 0) { - if (unlockingKeyInnoFR == 1) { -#ifdef GY_OS_AMBA - //delete_jpg_in_seven_days_face(); -#endif - } - else { - delete_jpg_in_seven_days(); - } -#ifdef GY_OS_AMBA - delete_heatmap_image(); -#endif - check_delete = 1; - } - else if (timeinfo->tm_hour != delete_time && timeinfo->tm_hour != delete_time2 && timeinfo->tm_hour != delete_time3 && timeinfo->tm_hour != delete_time4) { - check_delete = 0; - } - - //printf("\n------delete jpg in seven days detector end\n"); - - //usSleep(60000000); - usSleep(1000000); - } - else { - usSleep(10000000); - } - } - - //printf("\n---------delete jpg in seven days detector:exit\n"); - - pthread_exit(NULL); -} -#endif -//CURLM* g_multi_handle; -//int g_handle_count; - -//modified the input from file to memory based on test_detector() -#ifdef TEST_DETECTOR_MEM -void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, float thresh, float hier_thresh, int ext_output, int save_labels, char* model, char* target_device, int input_resizable, char* custom_cpu_library, char* custom_cldnn, int performance_counter, int IsHardwareOK) -{ - - //printf("\n[test detector mem]------------------------:1\n"); - //UTF8 trans.name table - char buff[MAX_MSG_LEN] = { 0 }; - //char strKeyValue[MAX_MSG_LEN] = { 0 }; // Assign ini file key value - char section[16] = { 0 }; - -#ifdef GY_OS_V_SERIES - -#else - for (int n = 0; n < MAX_LAYER_NUM; n++) - { - for (int i = 0; i < MAX_SECTION_VARIABLE; i++) - { - //if (section) - if (layerFeatureType[n] == FEATURE_LPR_MEA - || layerFeatureType[n] == FEATURE_LPR_SEA - || layerFeatureType[n] == FEATURE_LPR_VNM - || layerFeatureType[n] == FEATURE_LPR_IDN - || layerFeatureType[n] == FEATURE_LPR_USA - || layerFeatureType[n] == FEATURE_LPR_JPN - || layerFeatureType[n] == FEATURE_LPR_THA - || layerFeatureType[n] == FEATURE_LPR_LAO - || layerFeatureType[n] == FEATURE_LPR_BGD - || layerFeatureType[n] == FEATURE_LPR_TWN - || layerFeatureType[n] == FEATURE_LPR_EUR - ) - { - if (layerFeatureType[n] == FEATURE_LPR_MEA && layerFeatureType[n - 1] == FEATURE_LPR_MEA && n > 0) - strcpy(section, "[MEA]"); - if ((layerFeatureType[n] == FEATURE_LPR_SEA && layerFeatureType[n - 1] == FEATURE_LPR_SEA && n > 0) || - (layerFeatureType[n] == FEATURE_LPR_VNM && layerFeatureType[n - 1] == FEATURE_LPR_VNM && n > 0) || - (layerFeatureType[n] == FEATURE_LPR_IDN && layerFeatureType[n - 1] == FEATURE_LPR_IDN && n > 0)) - strcpy(section, "[SEA]"); - if (layerFeatureType[n] == FEATURE_LPR_USA && layerFeatureType[n - 1] == FEATURE_LPR_USA && n > 0) - strcpy(section, "[USA]"); - if (layerFeatureType[n] == FEATURE_LPR_JPN && layerFeatureType[n - 1] == FEATURE_LPR_JPN && n > 0) - strcpy(section, "[JPN]"); - if (layerFeatureType[n] == FEATURE_LPR_THA && layerFeatureType[n - 1] == FEATURE_LPR_THA && n > 0) - strcpy(section, "[THA]"); - if (layerFeatureType[n] == FEATURE_LPR_LAO && layerFeatureType[n - 1] == FEATURE_LPR_LAO && n > 0) - strcpy(section, "[LAO]"); - if (layerFeatureType[n] == FEATURE_LPR_BGD && layerFeatureType[n - 1] == FEATURE_LPR_BGD && n > 0) - strcpy(section, "[BGD]"); - if (layerFeatureType[n] == FEATURE_LPR_TWN && layerFeatureType[n - 1] == FEATURE_LPR_TWN && n > 0) - strcpy(section, "[TWN]"); - if (layerFeatureType[n] == FEATURE_LPR_EUR && layerFeatureType[n - 1] == FEATURE_LPR_EUR && n > 0) - strcpy(section, "[EUR]"); - - sprintf(buff, "%d", i); - char* value = GetIniKeyString(section, buff, INI_FILE_PATH); - if (value != NULL) { - if (strlen(value) > 0) { - strcpy(ppIniKeyValue[n][i], value); - } - else { - strcpy(ppIniKeyValue[n][i], ""); - } - } - else { - strcpy(ppIniKeyValue[n][i], ""); - } - } - else { - strcpy(ppIniKeyValue[n][i], ""); - } - } - } -#endif - -#ifdef GY_OS_AMBA - memset_snapshot_addr(); -#endif - //===================== - //sophia add 2020/09/24 - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - //memset(&(socketRecords[i].recent_sec_data), 0x00, sizeof(SecData)); - - socketRecords[i].sock = -1; - //socketRecords[i].thread_id = 0; - socketRecords[i].channel_id = -1; - //socketRecords[i].last_recv_time = time(0); - //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; - socketRecords[i].isGetAlarmMotion = FALSE; - //socketRecords[i].isFirstAlarmMotion = FALSE; - socketRecords[i].isWebSocketConnect = FALSE; - socketRecords[i].isUdpSocket = FALSE; - socketRecords[i].isNvrRequest = 0; - socketRecords[i].isCredentialRequest = 0; - socketRecords[i].debug_type = 0; -#if defined GY_OS_AMBA - //socketRecords[i].iIsAIRelay = 0; -#endif -// -//#ifdef GY_OS_WIN - // socketRecords[i].prev_frame_data = NULL; - /*if (socketRecords[i].prev_frame_data) - free(socketRecords[i].prev_frame_data);*/ -//#endif - socketRecords[i].used = 0; - - //socketRecord_ALM[i].sock = -1; - } - //printf("\nKKKKKKKKKKKKKKKK:3\n"); - - //for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - //{ - //socketRecord_ALM[i].sock = -1; - - /*socketRecord_ALM[i].head = NULL; - socketRecord_ALM[i].tail = NULL;*/ - //} - - mtrace(); - set_metadata(); - reset_onvif(); - initial_ivs(); - initial_g_PostRecorderList(); - check_if_is_existing_weight = 0; - - //===================== - // Create a HTTP thread - -#if 1 - //printf("\nKKKKKKKKKKKKKKKK:4\n"); - if (http_port > 0) - { - // HTTP server - //printf("\nKKKKKKKKKKKKKKKK:5\n"); - g_write_config_file_dirty_flag = 0; - protected_sqlite_fflpr_db_close = 1; -#if defined GY_OS_AMBA || defined GY_OS_NOVA - fflpr_log_db_init(); -#ifdef GY_OS_AMBA - if(unlockingKeyInnoFR == 1) - { - //face_log_db_init(); - } -#endif -#endif - isGYNetReady = TRUE; //Set GYNet is ready! - - //printf("\nKKKKKKKKKKKKKKKK:6\n"); - //run_server有做過,但是這邊要再做一次,因為要更新g_IsPTZDevice。 - pthread_t thread_id_getipcamsettings; - if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { - printf("\ngetipcamsettings thread creation failed #1\n"); - } - pthread_join(thread_id_getipcamsettings, NULL); - - - - -#if 1 - //329個Memory not freed 正常背景值洩漏 - if (pthread_create(&http_thread, 0, run_http_server_thread, 0)) - error("HTTP server thread creation failed\n"); - -#endif - - //printf("\nKKKKKKKKKKKKKKKK:8\n"); - //printf("\n[test detector mem]------------------------:2\n"); - -#ifdef GY_OS_AMBA -#if 0 - if ( g_IsToFDevice == 1) - { - // 建立記憶體共享區 - long data_size = sizeof(frameimage) + sizeof(rbuf_t); - tof_depth_shmid = Initial_ShareMemory(data_size, 888); - if (tof_depth_shmid == -1) { - perror("Create shared memory failed !\n"); - } - else { - // 初始化緩衝區 - ringbuf_init(&tof_ring_buffer); - - bTofDataStart = 1; - - if (pthread_create(&gettofdata_thread, 0, thread_getTofData, 0)) - error("thread gettofdata creation failed\n"); - } - } -#endif -#endif - -#ifdef GY_OS_AMBA - if (!g_IsPTZDevice && get_g_PTZ_model() != 659 && get_g_PTZ_model() != 715 && get_g_PTZ_model() != 714 && get_g_PTZ_model() != 731 && get_g_PTZ_model() != 716) { - - if (strcmp(SystemSetting.enable_ai_mirror, "Yes") == 0) { - if (strcmp(SystemSetting.ai_mirror_feature, "1") == 0) - { - FILE * pPipe; - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); -#ifdef GY_OS_AMBA - sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 2"); -#else - sprintf(cmd, "/usr/local/bin/test_vin -m 2"); -#endif - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); - } - else { - FILE * pPipe; - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); -#ifdef GY_OS_AMBA - sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 0"); -#else - sprintf(cmd, "/usr/local/bin/test_vin -m 0"); -#endif - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); - } - } - } -#endif - - //printf("\nKKKKKKKKKKKKKKKK:7\n"); - int check_if_setting_general_mode = 1; - if (g_IsPTZDevice == 0) - { - if (strcmp(accountData[0].account_flip, "1") == 0 || - strcmp(accountData[0].account_mirror, "1") == 0 || - strcmp(accountData[0].account_rotate, "1") == 0) - { - check_if_setting_general_mode = 0; - } - } - else if (g_IsPTZDevice == 1) - { - if (strcmp(accountData[0].account_rotate, "1") == 0 || - strcmp(accountData[0].account_mirror, "1") == 0) - { - check_if_setting_general_mode = 0; - } - } - -#if 1 - //除了delete_jpg_in_seven_days_detector沒開,合計10,878,464byte產生1983個記憶體洩漏(正常推播:只有一個zone,且output只設定一個虛擬輸入端,dwell time6秒) - //除了delete_jpg_in_seven_days_detector和run_post_notification_thread的推播AA沒開,合計11,276,800byte產生1978個記憶體洩漏 - //除了delete_jpg_in_seven_days_detector和run_post_notification_thread沒開,合計11,232,112byte產生1467個記憶體洩漏,大約1983-1467=516個記憶體洩漏是run_post_notification_thread造成的 - //除了delete_jpg_in_seven_days_detector沒開,合計10,891,264byte產生1500個記憶體洩漏(暴力推播:只有一個zone,但output設定四個虛擬輸入端,dwell time6秒) - //除了delete_jpg_in_seven_days_detector沒開,合計11,190,784byte產生1568個記憶體洩漏(四個zone暴力推播:4個zone,且每個output設定四個虛擬輸入端,dwell time6秒) - //除了delete_jpg_in_seven_days_detector沒開,合計11,518,976byte產生1992個記憶體洩漏(四個zone暴力推播:4個zone,且每個output設定四個虛擬輸入端,dwell time1秒) - //除了delete_jpg_in_seven_days_detector沒開,合計11,319,296byte產生1697個記憶體洩漏(四個zone暴力推播:4個zone,且每個output8個都開,dwell time1秒)//推不對的IP,不會影響記憶體洩漏 - - bHttpServerThreadStart = 1; - - if (pthread_create(&post_notification_thread, 0, run_post_notification_thread, NULL)) - error("Post notification thread creation failed\n"); -#endif - -#ifdef GY_OS_NOVA - if (pthread_create(&resolution_changed_thread, 0, auto_resolution_changed, NULL)) - error("resolution changed thread failed\n"); -#else - if (get_run_check_current_resolution() == -1) { - set_run_check_current_resolution(0); - if (pthread_create(&resolution_changed_thread, 0, check_current_resolution, NULL)) - error("check current resolution thread failed\n"); - } -#endif - - if (IsExistingWeight(featureType, featureType2) && check_if_setting_general_mode == 1) - { - // printf("\n[test detector mem] IsExistingWeight(featureType, featureType2) && check_if_setting_general_mode == 1)\n"); - check_if_is_existing_weight = 1; - bHttpServerThreadStart = 1; - - /* - if (g_IsToFDevice == 1) { - system(SHELLSCRIPT_TOF_DRIVER); - }*/ -#if 1 - if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) - { - printf("\n[gynet] g_IsRadarDevice || g_IsToFDevice\n"); - if (pthread_create(&getimage_thread, 0, thread_getimage, 0)) - error("thread getimage creation failed\n"); -#ifdef GY_OS_AMBA - if (pthread_create(&getimage_hd_thread, 0, thread_getimage_hd, 0)) - error("thread getimage creation failed\n"); -#endif - } - -#endif -#ifdef GY_OS_AMBA -#if 0 - if (g_IsRadarDevice == 1) - { - if (pthread_create(&render_radar_thread, 0, thread_render_radar_img, 0)) - error("thread render_radar creation failed\n"); - - if (g_IsRadarFake == 1) - { - if (pthread_create(&radar_reciever_id, NULL, RADAR_recieve, (void *)&radar_json_data) < 0) - error("RADAR_recieve creation failed\n"); - } - else - { - if (pthread_create(&getstream_thread, 0, thread_getstream, 0)) - error("thread getimage creation failed\n"); - - if (pthread_create(&radar_parser_thread, 0, thread_parse_radar, 0)) - error("thread radar parser creation failed\n"); - } - } -#endif - // unlockingKeyInnoFR_success = faceengine_start_and_check_license(); - // unlockingKeyInnoFR_success = 1; -#if 0 - if (unlockingKeyInnoFR_success == 1) { -#ifdef GY_OS_AMBA - faceengine_start(); -#endif - } -#endif -#if 0 - //目前先關掉與faceengine的互動 - if(unlockingKeyInnoFR_success == 1){ -#ifdef GY_OS_AMBA - if (pthread_create(&get_face_websocket_thread, 0, thread_get_face_websocket, 0)) - error("thread get_face_websocket creation failed\n"); - if (pthread_create(&parse_face_thread, 0, thread_parse_face, 0)) - error("thread parse_face creation failed\n"); -#endif - } -#endif - -#endif - - //printf("\nKKKKKKKKKKKKKKKK:9\n"); - -#if 1 - //test_nn_main & run_send_udp_thread & run_getalarmmotion_thread output.log 8,532,480byte -> 產生1167個記憶體洩漏 大約1167-1072=95個記憶體洩漏是run_getalarmmotion_thread造成的 - if (pthread_create(&getalarmmotion_thread, 0, run_getalarmmotion_thread, NULL)) - error("Getalarmmotion thread creation failed\n"); -#endif - -#ifdef GY_OS_V_SERIES - -#else - //329個Memory not freed 正常背景值洩漏 - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || -#ifdef GY_OS_NOVA - IsANPRCategory(featureType) || -#endif - g_IsCustomWeight == 1) { -#if 1 - ////原本名稱是check_http_socket_thread,現在改成run_event_counter_thread - if (pthread_create(&counter_thread, 0, run_event_counter_thread, NULL)) - error("check http socket thread creation failed\n"); -#endif - } -#endif - -#ifdef GY_OS_V_SERIES - -#else -#if 1 - //329個Memory not freed 正常背景值洩漏 - if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) { - if (pthread_create(&delete_jpg_in_seven_days_detector_thread_id, 0, delete_jpg_in_seven_days_detector, NULL)) - printf("create delete_jpg_in_seven_days_detector thread faile \n"); - } -#endif -#endif - //printf("\nKKKKKKKKKKKKKKKK:10\n"); - // UDP thread to send getalarmotion -#if 1 - //test_nn_main & run_send_udp_thread output.log 8,579,969byte -> 產生1072個記憶體洩漏 大約1072-875=197個記憶體洩漏是run_send_udp_thread造成的 - if (pthread_create(&send_udp_thread, 0, run_send_udp_thread, NULL)) - error("check http socket thread creation failed\n"); -#endif - -#ifdef GY_OS_AMBA - //**這邊還會記憶體洩漏 - //output.log 8,392,192byte ->產生934個記憶體洩漏 output.log增長幅度變成40,000byte - //不開start_all_nets 105,984byte->產生343個記憶體洩漏 比背景值洩漏一點點 正常OK - //不開while (live_mode_flag) 119,808byte->產生337個記憶體洩漏 比背景值洩漏一點點 正常OK - //if (g_IsRadarDevice == 0) - { -#if 1 - if (pthread_create(&test_nnctrl_live_thread, 0, test_nn_main, &stAMBAcontent)) - error("Test nnctrl live thread creation failed\n"); -#endif - } -#endif - -#ifdef GY_OS_NOVA - if (pthread_create(&test_nnctrl_live_thread, 0, nnctrl_main, &stAMBAcontent)) - error("Test nnctrl live thread creation failed\n"); -#endif - -#if 1 - //329個Memory not freed 正常背景值洩漏 - //Get CPU/VPU loading & AI FPS - if (pthread_create(&fps_loading_thread, 0, run_fps_loading_thread, NULL)) - error("fps loading thread creation failed\n"); -#endif -#ifdef GY_OS_AMBA -#if 1 - //OSD server 建立 - if (pthread_create(&thread_id_run_osd_server, 0, run_osd_server_thread, NULL)) { - printf("\nrun osd server thread creation failed\n"); - } -#endif -#endif - -#ifdef GY_OS_NOVA - if (pthread_create(&thread_id_get_nova_driver, 0, thread_get_nova_driver, 0)) - error("thread get nova driver creation failed\n"); -#endif - - //System time sync - //if (pthread_create(&thread_id_run_system_time_sync, 0, run_osd_time_sync_thread, NULL)) { - //printf("\nrun osd server thread creation failed\n"); - //} - } - else - bHttpServerThreadStart = 1; - - //printf("\nKKKKKKKKKKKKKKKK:12\n"); - //printf("\n[test_detector_mem] &stAMBAcontent:%x\n", &stAMBAcontent); - //printf("\n[test_detector_mem] stAMBAcontent.licenseType:%d\n", stAMBAcontent.licenseType); - RefreshCheckExistingWeight(); - int count_timeout = 0; - while (bHttpServerThreadStart) - { - if (AI_fps >= 1) - break; - else if (count_timeout >= 30) //count_timeout 100會沒載完 - { - printf("\n[Error]: Not Ready to run test_nn_main\n"); - break; - } - count_timeout++; - usSleep(1000000); - } - } - -#endif - - //muntrace(); - - //這邊會影響CPU的效能Sleep不能太低// - - while (bHttpServerThreadStart) - { - //printf("while bHttpServerThreadStart :%d\n", bHttpServerThreadStart); -#if defined GY_OS_NOVA - usSleep(3600000000);//3600000000 -#else - usSleep(1500000); -#endif - } - ////////////////////後面可能會沒有free到 - - printf("\n------------test detector mem:1\n"); - - -#if 0 - for (int n = 0; n < MAX_LAYER_NUM; n++) - { - if (layer_count > 0) - { - if (tcp_port > 0) - free_ptrs((void**)names[n], nets[n].layers[nets[n].n - 1].classes); - else if (http_port > 0) - free_ptrs((void**)names[n], http_nets[n].layers[http_nets[n].n - 1].classes); -#ifdef GY_OS_WIN - if (tcp_port > 0) - free_network(nets[n]); - - if (http_port > 0) - free_network(http_nets[n]); -#endif - //free_list_contents_kvp(options[n]); - free_list(options[n]); - } - } -#endif - - //free_ptrs(pPosInfo, element_size); - printf("\n------------test detector mem:2\n"); - - /* - if (alphabet != NULL) //20201015 sophia add - { - const int nsize = 8; - for (int j = 0; j < nsize; ++j) - { - for (int i = 32; i < 127; ++i) - { - free_image(alphabet[j][i]); - } - if (alphabet[j]) { - free(alphabet[j]); - alphabet[j] = NULL; - } - } - if (alphabet) { - free(alphabet); - alphabet = NULL; - } - }*/ - - printf("\n[test detector mem] end\n"); - - stop_server(); -} -#endif - -void stop_btHttpServer() { - // share_memory_stop(); -#if 0 - bTofDataStart = 0; -#endif - - bHttpServerThreadStart = 0; - bHttpServerMainStart = 0; - //printf("\n----------stop_btHttpServer:%d\n",1); - if (cgi_startTime_buff) { - free(cgi_startTime_buff); - cgi_startTime_buff = NULL; - } - if (cgi_whenTime_buff) { - free(cgi_whenTime_buff); - cgi_whenTime_buff = NULL; - } - //printf("\n----------stop_btHttpServer:%d\n", 2); -#ifdef GY_OS_AMBA - //if (g_IsPTZDevice == 1) { - //Free_PTZ_g_curl_connect(); - //} -#endif - //printf("\n----------stop_btHttpServer:%d\n", 3); - curl_global_cleanup(); - //printf("\n----------stop_btHttpServer:%d\n", 4); - base64_cleanup(); - //printf("\n----------stop_btHttpServer:%d\n", 5); -#if defined GY_OS_AMBA || defined GY_OS_NOVA - sqlite_fflpr_db_close(); -#ifdef GY_OS_AMBA - if (unlockingKeyInnoFR == 1) { - //sqlite_face_db_close(); - } -#endif -#endif - //printf("\n----------stop_btHttpServer:%d\n", 6); - //printf("Stop btHttpServer - finished. \n"); -} - -int get_bHttpServerThreadStart() { - return bHttpServerThreadStart; -} - -void stop_server() -{ - printf("Stop Server - started.\n"); - //pthread_mutex_lock(&mutex_run_one_net); - //bHttpServerThreadStart = 0; - //bHttpServerMainStart = 0; - //pthread_mutex_unlock(&mutex_run_one_net); - - stop_btHttpServer(); - //printf("\n----------stop server 1\n"); -#if 1 -#ifdef GY_OS_AMBA - StopPTZupdateStatusThread(); -#endif - //printf("\n----------stop server 2\n"); -//#ifdef GY_OS_AMBA - - //close 4 threads - //http server - run_http_server_thread() - //post notification - run_post_notification_thread() - //run event counter thread - run_event_counter_thread() - //test nnctrl live - test_nn_main() - -//#endif //GY_OS_AMBA -#endif - printf("Stop Server - finished. \n"); -#if 0 -#ifdef GY_OS_AMBA - if (http_port > 0) { - if (check_if_is_existing_weight == 1) { - printf("\n---------------pthread join:1\n"); - pthread_join(http_thread, NULL); - if (g_IsRadarDevice == 0 || g_IsToFDevice == 1) - { - printf("\n---------------pthread join:1.1\n"); - pthread_join(getimage_thread, NULL); -#ifdef GY_OS_AMBA - pthread_join(getimage_hd_thread, NULL); - pthread_join(gettofdata_thread, NULL); -#endif -#if defined GY_OS_AMBA || defined GY_OS_NOVA - printf("\n---------------pthread join:1.2\n"); - pthread_join(delete_jpg_in_seven_days_detector_thread_id, NULL); -#endif - } - - printf("\n---------------pthread join:1.3\n"); - -#ifdef GY_OS_AMBA - if (g_IsRadarDevice == 1) - { - pthread_join(render_radar_thread, NULL); - printf("\n---------------pthread join:1.4\n"); - if (g_IsRadarFake == 1) - { - pthread_join(radar_reciever_id, NULL); - } - else - { - pthread_join(getstream_thread, NULL); - printf("\n---------------pthread join:1.5\n"); - pthread_join(radar_parser_thread, NULL); - } - } - if(unlockingKeyInnoFR_success == 1) - { -#ifdef GY_OS_AMBA - pthread_join(get_face_websocket_thread, NULL); - - pthread_join(parse_face_thread, NULL); -#endif - } -#endif -#ifdef GY_OS_NOVA - pthread_join(http_thread_parse_json_data, NULL); -#endif - printf("\n---------------pthread join:2\n"); - pthread_join(post_notification_thread, NULL); - printf("\n---------------pthread join:3\n"); - pthread_join(getalarmmotion_thread, NULL); - printf("\n---------------pthread join:4\n"); - - pthread_join(resolution_changed_thread, NULL); - -#ifdef GY_OS_V_SERIES - -#else - pthread_join(counter_thread, NULL); -#endif - printf("\n---------------pthread join:5\n"); - pthread_join(send_udp_thread, NULL); - printf("\n---------------pthread join:6\n"); - pthread_join(test_nnctrl_live_thread, NULL); - printf("\n---------------pthread join:7\n"); - pthread_join(fps_loading_thread, NULL); - printf("\n---------------pthread join:8\n"); - -#ifdef GY_OS_AMBA - pthread_join(thread_id_run_osd_server, NULL); -#endif - //pthread_join(thread_id_run_system_time_sync, NULL); -#ifdef GY_OS_NOVA - pthread_join(thread_id_get_nova_driver, NULL); -#endif - } - else { - pthread_join(post_notification_thread, NULL); - pthread_join(resolution_changed_thread, NULL); - pthread_join(http_thread, NULL); - } - } -#endif -#endif - //destroy pthread_mutex -#if 1 - //pthread_mutex_destroy(&mutex_post_notification); - //pthread_mutex_destroy(&mutex_post_notification_push); - pthread_mutex_destroy(&mutex_post_notification_pop); - //printf("\n----------stop server 3\n"); - pthread_mutex_destroy(&mutex_getalarmmotion); - pthread_mutex_destroy(&mutex_alm); - pthread_mutex_destroy(&mutex_curl); - pthread_mutex_destroy(&mutex_dn); - - pthread_mutex_destroy(&mutex_websocket); - pthread_mutex_destroy(&mutex_enable_lpr_db); -#ifdef GY_OS_AMBA - pthread_mutex_destroy(&mutex_enable_face_db); -#endif - pthread_mutex_destroy(&mutex_username); - pthread_mutex_destroy(&mutex_pns); - //pthread_mutex_destroy(&mutex_get_canvas); - - //printf("\n----------stop server 4\n"); - pthread_mutex_destroy(&mutex_snap); - //pthread_mutex_destroy(&mutex_cropped_roi); - //pthread_mutex_destroy(&mutex_snap_hd_image); - pthread_mutex_destroy(&mutex_snap_image); -#ifdef GY_OS_AMBA - pthread_mutex_destroy(&mutex_remotesnap_image); // Ken 2022-09-26 - pthread_mutex_destroy(&mutex_radar_json); - pthread_mutex_destroy(&mutex_tof_json); -#endif - pthread_mutex_destroy(&mutex_get_image); - pthread_mutex_destroy(&mutex_get_image_HD); - - pthread_mutex_destroy(&mutex_config_json); -#if defined GY_OS_AMBA - //pthread_mutex_destroy(&mutex_jvc_config_json); -#endif - pthread_mutex_destroy(&mutex_events_json); - pthread_mutex_destroy(&mutex_web); - //printf("\n----------stop server 5\n"); - //pthread_mutex_destroy(&mutex_http_connection_handler); - pthread_mutex_destroy(&mutex_base64); - pthread_mutex_destroy(&mutex_run_one_net); -#ifdef GY_OS_NOVA - pthread_mutex_destroy(&mutex_run_parse_json); -#endif - pthread_mutex_destroy(&mutex_send_jpeg); - pthread_mutex_destroy(&mutex_heatmap_jpeg); - //pthread_mutex_destroy(&mutex_strsplit); - -#ifdef GY_OS_AMBA - pthread_mutex_destroy(&mutex_perspective_transform); -#endif - //printf("\n----------stop server 6\n"); - pthread_mutex_destroy(&mutex_get_network_input); - pthread_mutex_destroy(&mutex_differ_image); - - pthread_mutex_destroy(&mutex_run_one_net_anpr); - pthread_mutex_destroy(&mutex_check_license); - pthread_mutex_destroy(&mutex_read_ipcam); - - pthread_mutex_destroy(&mutex_update_candidate); - pthread_mutex_destroy(&mutex_send_cgi); - - //pthread_mutex_destroy(&mutex_parse_bbox); - //pthread_mutex_destroy(&mutex_color_detect); - - pthread_mutex_destroy(&mutex_compute_median); - //pthread_mutex_destroy(&mutex_long_term); - //pthread_mutex_destroy(&mutex_short_term); - - //pthread_mutex_destroy(&mutex_long_term_yuv); - //pthread_mutex_destroy(&mutex_short_term_yuv); - - pthread_mutex_destroy(&mutex_set_http_request); - pthread_mutex_destroy(&mutex_reset_counter); -#ifdef GY_OS_AMBA - pthread_mutex_destroy(&mutex_run_osd); - - pthread_mutex_destroy(&mutex_get_depth); - //pthread_mutex_destroy(&mutex_tof_data); - pthread_mutex_destroy(&mutex_write_pcd_data); - pthread_mutex_destroy(&mutex_write_pcd_data_L); - pthread_mutex_destroy(&mutex_write_pcd_data_M); - pthread_mutex_destroy(&mutex_write_pcd_data_S); -#endif -#ifdef GY_OS_NOVA - pthread_mutex_destroy(&mutex_pre_bbox_receive); - pthread_mutex_destroy(&mutex_pre_connection); - pthread_mutex_destroy(&mutex_pre_image_receive); -#endif - -#endif - - - printf("Stop Server - pthread finished. #2\n"); -} - -#ifdef GY_OS_AMBA -void write_to_enable_tracking(char *enable_tracking) { - //printf("\n--------------[enable tracking]-----------------: %s\n", enable_tracking); - - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - - char exePath[1024] = {}; - //printf("exePath:%s\n", exePath); - getFilePath(buf, exePath, 1024); - //printf("exePath:%s\n", exePath); - - char configPATH[1024] = { 0 }; - strcpy(configPATH, exePath); - strcat(configPATH, "config.json"); - - char config_bakPATH[1024] = { 0 }; - strcpy(config_bakPATH, exePath); - strcat(config_bakPATH, "config_bak.json"); - - char *filename_config = configPATH; - if (!FileExist(filename_config)) - { - printf("%s doesn't exist.\n", filename_config); - } - else - { - //size_t nfileSize_cofnig = ReadFileSize(filename_config); - char *fileBuf_config = ReadAllBytes(filename_config); - if (fileBuf_config) { - cJSON *root = NULL; - root = cJSON_Parse(fileBuf_config); - if (fileBuf_config) { - free(fileBuf_config); - fileBuf_config = NULL; - } - - if (root == NULL) - { - printf("root_config is NULL\n"); - } - else - { - cJSON *view_setting, *camera01, *ptz_enable_tracking; - - view_setting = cJSON_GetObjectItem(root, "view_setting"); - camera01 = cJSON_GetObjectItem(view_setting, "camera01"); - ptz_enable_tracking = cJSON_GetObjectItem(camera01, "ptz_enable_tracking"); - - - if (ptz_enable_tracking) { - - cJSON_ReplaceItemInObject(camera01, "ptz_enable_tracking", cJSON_CreateString(enable_tracking)); - - - char* JsonString = cJSON_Print(root); - FILE *fp; - - if ((fp = fopen(filename_config, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - - CopyFileTo(configPATH, config_bakPATH); - } - else - { - printf("Fail to open config.json \n"); - } - - if (JsonString) { - free(JsonString); - JsonString = NULL; - } - } - } - if (root) { - cJSON_Delete(root); - root = NULL; - } - } - } -} -#endif -#ifdef GY_OS_AMBA -int read_bin(char *fileDir, unsigned char *addr) -{ - //fread - printf("read_bin \n"); - - //int rval = 0; - int lSize = 0; - -#if 0 - FILE *fp = NULL; - - - //lSize = ftell(fileDir); - lSize = 460800; - - printf("read_bin return\n"); - return lSize; - - if (lSize > 0) - { - fp = fopen(fileDir, "r"); - //char addr[500000]; - //int readCnt = fread(addr, 1, lSize, fp); /* return 0*/ - //int readCnt = fread(buffer,1,sizeof(buffer),fp); /* return 11 */ - //printf("readCnt = %d\n", readCnt); - fclose(fp); - } - else - return 0; -#endif - printf("read_bin return\n"); - return lSize; -} - -int teststoreYUV(char *file, int size, void *addr) -{ - FILE *fp = NULL; - int rval = 0; - - do { - if ((fp = fopen(file, "wb")) == NULL) { - printf("\n%s\n", file); - rval = -1; - break; - } - - - - if (fwrite(addr, 1, size, fp) != size) { - printf("\nfwrite]n"); - rval = -1; - break; - } - - fclose(fp); - fp = NULL; - - } while (0); - - if (fp) { - fclose(fp); - fp = NULL; - } - - return rval; -} - -int testbinfile(char *filename, char *buffer) -{ - printf("file name: %s \n", filename); - - int lSize = 0; - - FILE *fp = NULL; - - fp = fopen(filename, "r"); - - fseek(fp, 0, SEEK_END); - lSize = ftell(fp); - - rewind(fp); //set read point to start - /*size_t read_result = */fread(buffer, 1, lSize, fp); - - //char img_name[512] = { 0 }; - //sprintf(img_name, "/emmc/plugin/Aida_data/storage/hello_tofyuv.bin"); //same - ////store_bin(img_name, yuv2rgb_out_mem.size, yuv2rgb_out_mem.virt); - - //teststoreYUV(img_name, lSize, buffer); - //int readCnt = fread(buffer, 1, sizeof(buffer), fp); - - fclose(fp); - - return lSize; -} -#endif - -void move_file() { - - for(int i = 0 ; i < 13 ; i++) - { - FILE * pPipe; - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - - if( i == 0 ) - sprintf(cmd, "mkdir /emmc/plugin/Aida_data/storage"); - else if( i == 1 ) - sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/storage/default.jpg"); - else if( i == 2 ) - sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/storage/default.jpg"); - else if (i == 3) - sprintf(cmd, "mkdir /emmc/plugin/Aida_data/storage/face"); - else if (i == 4) - sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/storage/face/default.jpg"); - else if (i == 5) - sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/storage/face/default.jpg"); - else if (i == 6) - sprintf(cmd, "mkdir /emmc/plugin/Aida_data/storage/template"); - else if (i == 7) - sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/storage/template/default.jpg"); - else if (i == 8) - sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/storage/template/default.jpg"); - else if (i == 9) - sprintf(cmd, "mkdir /emmc/plugin/Aida_data/playback"); - else if (i == 10) - sprintf(cmd, "cp /emmc/plugin/Aida_data/default.jpg /emmc/plugin/Aida_data/playback/default.jpg"); - else if (i == 11) - sprintf(cmd, "chmod 777 /emmc/plugin/Aida_data/playback/default.jpg"); - else if (i == 12) - sprintf(cmd, "mkdir /emmc/plugin/Aida_data/sfe/storage"); - - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); - } - -} -void *start_run_python_thread(void* pythonpath) { - pthread_detach(pthread_self()); - setPthreadName("run_python"); - char *value = get_enable_python_file_value((const char*)pythonpath); - - while (python_check_webstatus == 0) - { - // python_check_webstatus = 0 網頁關閉 - // python_check_webstatus = 1 網頁開啟 - printf("[start_run_python_thread] Wait Web server run... %d \n", python_check_webstatus); - continue; - } - // printf("[start_run_python_thread] Wait Web server run... %d \n", python_check_webstatus); - sleep(15); // 暫停 15 秒,等待 Web thread 開啟 - if (value == NULL) { - printf("Failed to retrieve enable_python_file value\n"); - pthread_exit(NULL); - } - // 抓取 python 檔案 - if (strstr(value, ".py") != NULL) { - printf("enable_python_file is a Python file: %s\n", value); - const char *prefix = "lifile_liname="; - char pythonfile[256]; - snprintf(pythonfile, sizeof(pythonfile), "%s%s", prefix, value); - runPython(pythonfile); - } else { - printf("enable_python_file is not a Python file: %s\n", value); - } - pthread_exit(NULL); -} -char* get_enable_python_file_value(const char *filename) { - FILE *file = fopen(filename, "r"); - if (file == NULL) { - printf("Could not open file %s\n", filename); - return NULL; - } - - // 獲取文件大小 - fseek(file, 0, SEEK_END); - long file_size = ftell(file); - fseek(file, 0, SEEK_SET); - - // 讀取文件內容到內存中 - char *file_content = (char *)malloc(file_size + 1); - if (file_content == NULL) { - printf("Memory allocation failed\n"); - fclose(file); - return NULL; - } - fread(file_content, 1, file_size, file); - file_content[file_size] = '\0'; - fclose(file); - - // 解析 JSON - cJSON *json = cJSON_Parse(file_content); - free(file_content); - if (json == NULL) { - printf("Error parsing JSON file\n"); - return NULL; - } - - // 獲取 system_setting 的值 - cJSON *system_setting = cJSON_GetObjectItem(json, "system_setting"); - if (system_setting == NULL) { - printf("system_setting not found in JSON\n"); - cJSON_Delete(json); - return NULL; - } - - // 獲取 enable_python_file 的值 - cJSON *enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); - char *result = NULL; - if (enable_python_file != NULL && cJSON_IsString(enable_python_file)) { - result = strdup(enable_python_file->valuestring); // 複製字符串值 - } - - // 清理 cJSON 對象 - cJSON_Delete(json); - printf("[get_enable_python_file_value] result : %s \n",result); - // 返回結果 - return result; -} -void run_server(int argc, char **argv) -{ - //以下沒有記憶體洩漏------------------------20210803 - - check_if_start_run_server = 1; - - { - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "The start of gynet."); - write_to_logs_html(temp_msg, "run server", "INFO", "Yes"); - write_to_log_for_start(temp_msg, "run server", "INFO"); - } - -#ifdef _DEBUG_AMBA - printf("\n[run_server] start\n"); - for (int i = 0;i < argc;i++) - printf("[run_server] argv[%d]:%s\n", i, argv[i]); -#endif // _DEBUG_AMBA - - file_management(); - initial_weight_settings(); - - getCameraPlugInInfo(); - update_accountData(); - update_accountData_port(); - - move_file(); - - g_IsRadarFake = 0; - - setlocale(LC_ALL, "en_US.UTF-8"); - - g_match_mac = 0; - - char init_CPU_usage[256] = "20"; - char init_GPU_usage[256] = "20"; - - sprintf(CPU_usage, "%s", init_CPU_usage); - sprintf(GPU_usage, "%s", init_GPU_usage);//psBuffer_send2 - -#ifdef REBOOT_BY_CPU_GPU_USAGE - CPU_usage_int = atoi(CPU_usage); - GPU_usage_int = atoi(GPU_usage); -#endif - - ColdZoneInit(); - - /*int iReadCodeZoneRet = */ReadColdZoneJsonFile(); - - char buf[1024] = { 0 }; - readlink("/proc/self/exe", buf, sizeof(buf)); - //printf("Program binary path is: %s\n", buf); - - char exePath[1024] = { 0 }; - getFilePath(buf, exePath, 1024); - - char configPATH[1024] = { 0 }; -#ifdef GY_OS_NOVA - char config_smallPATH[1024] = { 0 }; -#endif - char config_installPATH[1024] = { 0 }; - -#ifdef GY_OS_NOVA - char config_small_installPATH[1024] = { 0 }; -#endif - char config_bakPATH[1024] = { 0 }; - - char events_installPATH[1024] = { 0 }; - char eventsPATH[1024] = { 0 }; - char events_bakPATH[1024] = { 0 }; - - char tof_installPATH[1024] = { 0 }; - char tofPATH[1024] = { 0 }; - char tof_bakPATH[1024] = { 0 }; - - char emails_installPATH[1024] = { 0 }; - char emailsPATH[1024] = { 0 }; - char emails_bakPATH[1024] = { 0 }; - - char cold_objects_installPATH[1024] = { 0 }; - char cold_objectsPATH[1024] = { 0 }; - - strcpy(configPATH, exePath); -#ifdef GY_OS_NOVA - strcpy(config_smallPATH, exePath); -#endif - strcpy(config_installPATH, exePath); -#ifdef GY_OS_NOVA - strcpy(config_small_installPATH, exePath); -#endif - strcpy(config_bakPATH, exePath); - - strcpy(eventsPATH, exePath); - strcpy(events_installPATH, exePath); - strcpy(events_bakPATH, exePath); - - strcpy(tofPATH, exePath); - strcpy(tof_installPATH, exePath); - strcpy(tof_bakPATH, exePath); - - strcpy(emailsPATH, exePath); - strcpy(emails_installPATH, exePath); - strcpy(emails_bakPATH, exePath); - - strcpy(cold_objectsPATH, exePath); - strcpy(cold_objects_installPATH, exePath); - - strcat(configPATH, "config.json"); -#ifdef GY_OS_NOVA - strcat(config_smallPATH, "config_small.json"); -#endif - strcat(config_installPATH, "config_install.json"); - -#ifdef GY_OS_NOVA - strcat(config_small_installPATH, "config_small_install.json"); -#endif - strcat(config_bakPATH, "config_bak.json"); - // if (pthread_create(&runpython_thread, NULL, start_run_python_thread, (void*)configPATH) != 0) { - // perror("check current runpython thread failed\n"); - // exit(EXIT_FAILURE); - // } - strcat(eventsPATH, "events.json"); - strcat(events_installPATH, "events_install.json"); - strcat(events_bakPATH, "events_bak.json"); - - strcat(tofPATH, "tof.json"); - strcat(tof_installPATH, "tof_install.json"); - strcat(tof_bakPATH, "tof_bak.json"); - - strcat(emailsPATH, "emails.json"); - strcat(emails_installPATH, "emails_install.json"); - strcat(emails_bakPATH, "emails_bak.json"); - - strcat(cold_objectsPATH, "cold_objects.json"); - strcat(cold_objects_installPATH, "cold_objects_install.json"); - - //arguments - dont_show = find_arg(argc, argv, "-dont_show"); - show = find_arg(argc, argv, "-show"); - tcp_port = find_int_arg(argc, argv, "-tcp_port", -1); - //out_filename = find_char_arg(argc, argv, "-out_filename", 0); - //outfile = find_char_arg(argc, argv, "-out", 0); - //prefix = find_char_arg(argc, argv, "-prefix", 0); - thresh = find_float_arg(argc, argv, "-thresh", .24); - hier_thresh = find_float_arg(argc, argv, "-hier", .5); - cam_index = find_int_arg(argc, argv, "-c", 0); - frame_skip = find_int_arg(argc, argv, "-s", 0); - num_of_clusters = find_int_arg(argc, argv, "-num_of_clusters", 5); - yuv_width = find_int_arg(argc, argv, "-width", -1); - yuv_height = find_int_arg(argc, argv, "-height", -1); - ext_output = find_arg(argc, argv, "-ext_output"); - save_labels = find_arg(argc, argv, "-save_labels"); - http_port = find_int_arg(argc, argv, "-http_port", 0); - //unlocking_key = find_char_arg(argc, argv, "-unlocking_key", 0); - //char *ip_address = find_char_arg(argc, argv, "-ip_address", 0); - gpu_idx = find_int_arg(argc, argv, "-gpu_idx", 0); - //c_cnn_type = find_char_arg(argc, argv, "-cnn_type", 0); -#if 0 - radar_log = find_arg(argc, argv, "-radar_log"); // 10-19 leo -#endif - // radar_log = 1; // 2022-10-28 Ken for V1 classification testing info - //printf("radar_log:%d\n", radar_log); - - //char* model = find_char_arg(argc, argv, "-m", ""); - input_resizable = find_int_arg(argc, argv, "-auto_resize", 0); - custom_cpu_library = find_char_arg(argc, argv, "-l", ""); - custom_cldnn = find_char_arg(argc, argv, "-c", ""); - performance_counter = find_int_arg(argc, argv, "-pc", 0); - - isGYNetReady = FALSE; - - //pthread_mutex_init(&mutex_post_notification, NULL); - //pthread_mutex_init(&mutex_post_notification_push, NULL); - pthread_mutex_init(&mutex_post_notification_pop, NULL); - pthread_mutex_init(&mutex_getalarmmotion, NULL); - pthread_mutex_init(&mutex_alm, NULL); - pthread_mutex_init(&mutex_curl, NULL); - pthread_mutex_init(&mutex_dn, NULL); - - pthread_mutex_init(&mutex_websocket, NULL); - pthread_mutex_init(&mutex_enable_lpr_db,NULL); -#ifdef GY_OS_AMBA - pthread_mutex_init(&mutex_enable_face_db,NULL); -#endif - pthread_mutex_init(&mutex_username, NULL); - pthread_mutex_init(&mutex_pns, NULL); - pthread_mutex_init(&mutex_snap, NULL); - //pthread_mutex_init(&mutex_get_canvas, NULL); - - //pthread_mutex_init(&mutex_cropped_roi, NULL); - //pthread_mutex_init(&mutex_snap_hd_image, NULL); - pthread_mutex_init(&mutex_snap_image, NULL); -#ifdef GY_OS_AMBA - pthread_mutex_init(&mutex_remotesnap_image, NULL); // Ken 2022-09-26 - pthread_mutex_init(&mutex_radar_json, NULL); - pthread_mutex_init(&mutex_tof_json, NULL); -#endif - pthread_mutex_init(&mutex_get_image, NULL); - pthread_mutex_init(&mutex_get_image_HD, NULL); - - pthread_mutex_init(&mutex_config_json, NULL); -#if defined GY_OS_AMBA - //pthread_mutex_init(&mutex_jvc_config_json, NULL); -#endif - pthread_mutex_init(&mutex_events_json, NULL); - pthread_mutex_init(&mutex_web, NULL); - //pthread_mutex_init(&mutex_http_connection_handler, NULL); - pthread_mutex_init(&mutex_base64, NULL); - pthread_mutex_init(&mutex_run_one_net, NULL); -#ifdef GY_OS_NOVA - pthread_mutex_init(&mutex_run_parse_json, NULL); -#endif - pthread_mutex_init(&mutex_send_jpeg, NULL); - pthread_mutex_init(&mutex_heatmap_jpeg, NULL); - //pthread_mutex_init(&mutex_strsplit, NULL); - -#ifdef GY_OS_AMBA - pthread_mutex_init(&mutex_perspective_transform, NULL); -#endif - pthread_mutex_init(&mutex_get_network_input, NULL); - pthread_mutex_init(&mutex_differ_image, NULL); - - pthread_mutex_init(&mutex_run_one_net_anpr, NULL); - pthread_mutex_init(&mutex_check_license, NULL); - pthread_mutex_init(&mutex_read_ipcam, NULL); - pthread_mutex_init(&mutex_update_candidate, NULL); - - pthread_mutex_init(&mutex_send_cgi, NULL); - //pthread_mutex_init(&mutex_parse_bbox, NULL); - //pthread_mutex_init(&mutex_color_detect, NULL); - pthread_mutex_init(&mutex_compute_median, NULL); - //pthread_mutex_init(&mutex_long_term, NULL); - //pthread_mutex_init(&mutex_short_term, NULL); - - //pthread_mutex_init(&mutex_long_term_yuv, NULL); - //pthread_mutex_init(&mutex_short_term_yuv, NULL); - - pthread_mutex_init(&mutex_set_http_request, NULL); - pthread_mutex_init(&mutex_reset_counter, NULL); -#ifdef GY_OS_AMBA - pthread_mutex_init(&mutex_run_osd, NULL); - - pthread_mutex_init(&mutex_get_depth, NULL); - //pthread_mutex_init(&mutex_tof_data, NULL); - pthread_mutex_init(&mutex_write_pcd_data, NULL); - pthread_mutex_init(&mutex_write_pcd_data_L, NULL); - pthread_mutex_init(&mutex_write_pcd_data_M, NULL); - pthread_mutex_init(&mutex_write_pcd_data_S, NULL); -#endif -#ifdef GY_OS_NOVA - pthread_mutex_init(&mutex_pre_bbox_receive, NULL); - pthread_mutex_init(&mutex_pre_connection, NULL); - pthread_mutex_init(&mutex_pre_image_receive, NULL); -#endif - //g_multi_handle = curl_multi_init(); //Curl init - - //QueueLockInit(); - - //以上沒有記憶體洩漏------------------------20210803 - - //100個左右記憶體洩漏 - memset(&accountData, 0, sizeof(accountData)); - -#if defined GY_OS_AMBA || defined GY_OS_NOVA - - pthread_mutex_lock(&mutex_curl); - curl_global_init(CURL_GLOBAL_SSL); - g_http_handle = NULL; - g_http_handle = curl_easy_init(); - pthread_mutex_unlock(&mutex_curl); - - pthread_t thread_id_getipcamsettings; - if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { - printf("\ngetipcamsettings thread creation failed\n"); - } - pthread_join(thread_id_getipcamsettings, NULL); - //StartPTZupdateStatusThread(); - -#ifdef GY_OS_NOVA - ipcam_getfeatures(); -#else - if (strcmp(WeightFileModeName, "mod004") == 0) { - ipcam_getfeatures(); - } -#endif - - ///讀取SMTP service資料 - - copy_ipcam_smtp_service_to_gynet(); - - //printf("000 get password = %s \n", accountData[0].account_password); - -#if 1 - - //1個記憶體洩漏 - if (http_port > 0) - { - //printf("\n**********************\n"); - //printf("preload server open"); - //printf("\n**********************\n"); - - pthread_t preload_http_thread; - if (pthread_create(&preload_http_thread, 0, run_preload_http_server_thread, 0)) - error("preload http server thread creation failed\n"); - - } - - //0個左右記憶體洩漏 - //char returned_msg[MEMORY_SIZE] = { 0 }; - //PNS_Query_Service_Status(returned_msg); - -#endif - - //**半OK記憶體洩漏 - //output.log 138,240byte ->產生330個記憶體洩漏 output.log增長幅度顯著變比較慢 - //get_current_events_json_data 會記憶體洩漏,但是不常進去。 - g_IsPTZDevice = 0; - - - -#endif - - //init CGI CMD time - - //兩個記憶體洩漏 在stop_server才會釋放 - cgi_startTime_buff = (struct tm*)malloc(sizeof(struct tm)); - cgi_whenTime_buff = (struct tm*)malloc(sizeof(struct tm)); - - //printf("GyNet is starting......\n"); - - td_weight_num = 0; - - char customWeightPATH[1024] = { 0 }; - strcpy(customWeightPATH, exePath); - strcat(customWeightPATH, "customWeight.json"); - - cJSON* root_third, * weight_number; - cJSON *third_party_weight_list, *td_party_weight, *weight_name,*anchor_name,*label_name, *encryption; - - //printf("111 get password = %s \n", accountData[0].account_password); - - if (!FileExist(customWeightPATH)) - { - td_weight_num = 0; - printf("%s doesn't exist.\n", customWeightPATH); - } - else - { - //printf("read customWeight.json.\n"); - - char* fileBuf_third = ReadAllBytes(customWeightPATH); - if (fileBuf_third) { - root_third = cJSON_Parse(fileBuf_third); - - if (fileBuf_third) { - free(fileBuf_third); - fileBuf_third = NULL; - } - weight_number = cJSON_GetObjectItem(root_third, "Weight Number"); - if (weight_number) - td_weight_num = (short)weight_number->valueint; - - third_party_weight_list = cJSON_GetObjectItem(root_third, "Third party weight"); - - if (third_party_weight_list) - { - int k = 0; - cJSON_ArrayForEach(td_party_weight, third_party_weight_list) - { - if (td_party_weight && k < MAX_LAYER_NUM) - { - weight_name = cJSON_GetObjectItem(td_party_weight, "Weight Name"); - if (weight_name) - sprintf(td_weight_info[k].weight_name, "%s", weight_name->valuestring); - - anchor_name = cJSON_GetObjectItem(td_party_weight, "Anchor Name"); - if (anchor_name) - sprintf(td_weight_info[k].anchor_name, "%s", anchor_name->valuestring); - - label_name = cJSON_GetObjectItem(td_party_weight, "Label Name"); - if (label_name) - sprintf(td_weight_info[k].label_name, "%s", label_name->valuestring); - - encryption = cJSON_GetObjectItem(td_party_weight, "Encryption"); - if (encryption && strcmp(encryption->valuestring,"Yes")==0) - td_weight_info[k].is_encryption = 1; - else - td_weight_info[k].is_encryption = 0; - k++; - } - } - } - - if (root_third) { - cJSON_Delete(root_third); - root_third = NULL; - } - } - } - -#if 0 - for (int i = 0; i < td_weight_num; i++) { - printf("\nWeight Name: %s\n", td_weight_info[i].weight_name); - printf("\nis_encryption: %hd\n", td_weight_info[i].is_encryption); - } -#endif - - int new_data_write_to_config_file_flag = 0; - int new_data_write_to_events_file_flag = 0; - int new_data_write_to_tof_file_flag = 0; - //printf("\n-------------------http_port: %d\n", http_port); - sprintf(accountData[0].account_aida_port, "%d", http_port); - - if (tcp_port > 0 || http_port > 0) - { - - //read settings from config.json - //char filename[] = config_bakPATH; - char *filename = configPATH; - //char *filename = config_bakPATH; - - if (!FileExist(filename)) - { - printf("%s doesn't exist.\n", filename); - return; - } - - //printf("read config.json. %s\n", filename); - //size_t nfileSize = ReadFileSize(filename); - - char* fileBuf = ReadAllBytes(filename); - - if(fileBuf){ - - cJSON *root = cJSON_Parse(fileBuf); - //g_config_root = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (root) - { - //printf("config.json parse OK.\n"); - cJSON* about_box = cJSON_GetObjectItem(root, "about_box"); - //cJSON* nic_name = cJSON_GetObjectItem(about_box, "NIC name"); - cJSON* unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); - //printf(">>>>>>>>>>> uk key = %s \n", unlock_key->valuestring); - - /* - if (td_weight_num >= 1) { - cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString("Third_party")); - unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); - }*/ - - if (unlock_key && (int)strlen(unlock_key->valuestring) == 0) { - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char keyPATH[1024] = { 0 }; - strcpy(keyPATH, exePath); - strcat(keyPATH, "key.txt"); - if (FileExist(keyPATH) == 1) { - - char key_buff[1024] = { 0 };//creating char array to store data of file - - FILE *pFile; - - if ((pFile = fopen(keyPATH, "r")) != NULL) - { - fscanf(pFile, "%s", key_buff); - fclose(pFile); - - cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString(key_buff)); - unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); - - - char* JsonString = cJSON_Print(root); - - FILE *f = fopen(configPATH, "w"); - if (f == NULL) - { - printf("Error opening config.json!\n"); - } - else { - fprintf(f, "%s\n", JsonString); - fclose(f); - CopyFileTo(configPATH, config_bakPATH); - } - if (JsonString) { - free(JsonString); - JsonString = NULL; - } - } - else - printf("Fail to open key.txt \n"); - } - } - - //解碼unlockingKey - step 1:base64 decode - size_t base64_decode_length = 0; - unsigned char EncryptKeyData[256]; - char DecryptKeyData[256]; - memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); - memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); - unsigned char OriEncryptData[512] = { 0 }; - - - base64_decode(unlock_key->valuestring, strlen(unlock_key->valuestring), &base64_decode_length, OriEncryptData); - memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); - - //printf("\n--------------OriEncryptData:%s\n", OriEncryptData); - //printf("\n--------------EncryptKeyData:%s\n", EncryptKeyData); - - //解碼unlockingKey - step 2:AES descrytion - KeyExpansion(key, expandedKey); - //printf("\n---------expandedKey:%s\n", expandedKey); - AESDecryptArrayToArray((char *)EncryptKeyData, base64_decode_length, expandedKey, DecryptKeyData, sizeof(DecryptKeyData)); - //printf("unlocking_key descrytion OK.\n"); - - //printf("key info = %s \n", DecryptKeyData); - - //printf("\n--------------DecryptKeyData:%s\n", DecryptKeyData); - - //取得unlockingKey明碼資訊 - cJSON *keyRoot, *fe, *fe2, *li, *ad, *st, *et, *id; - keyRoot = cJSON_Parse(DecryptKeyData); - fe = cJSON_GetObjectItem(keyRoot, "fe"); - fe2 = cJSON_GetObjectItem(keyRoot, "fe2"); - li = cJSON_GetObjectItem(keyRoot, "li"); - ad = cJSON_GetObjectItem(keyRoot, "ad"); - st = cJSON_GetObjectItem(keyRoot, "st"); - et = cJSON_GetObjectItem(keyRoot, "et"); - id = cJSON_GetObjectItem(keyRoot, "id"); - - - unsigned char first_half_char_key[512] = { 0 }; - unsigned char mykey_custom[512] = { 0 }; - - //unsigned char expandedmykey_custom[176] = { 0 }; - char mygmail_after_ddDec[512] = { 0 }; - - // If lilin ID and independent face license are not consistent, the verification will fail. - if (!id && unlock_key && strlen(unlock_key->valuestring) >= 4 && strncmp(unlock_key->valuestring, "face", 4) != 0) - { - printf("[ERROR] Null System ID\n"); - - //printf("\n--------------unlock_key->valuestring:%s\n", unlock_key->valuestring); - - memcpy(first_half_char_key, unlock_key->valuestring, 16); - if ((int)strlen((char *)first_half_char_key) < 16) { - for (int i = (int)strlen((char *)first_half_char_key); i < 16; i++) { - first_half_char_key[i] = '0'; - } - } - //printf("\n--------------first_half_char_key:%s\n", first_half_char_key); - - ddDec(unlock_key->valuestring, mygmail_after_ddDec); - //printf("\n---------------mygmail_after_ddDec: %s\n", mygmail_after_ddDec); - - if (strstr(mygmail_after_ddDec, "@") != NULL && - strstr(mygmail_after_ddDec, "email:") != NULL) { - - for (int i = 0; i < 16; i++) { - //mykey_custom[i] = first_half_char_key[i]; - sprintf((char*)mykey_custom + i * 2, "%02x", (char*)first_half_char_key[i]); - } - - //printf("\n---------------mykey_custom: %s\n", mykey_custom); - check_if_correct_mail = 1; - } - - } - else { - //printf("System ID: %s\n", id->valuestring); - } - - //取得隱藏資訊 - strcpy(g_filename_TLT, TLT_FILE_NAME); - //strcpy(filename2, exePath); - //first time - if (!FileExist(g_filename_TLT) || ReadFileSize(g_filename_TLT) == 0) - { - printf("TLT file doesn't exist.\n"); - - //create gysetting.json with current time - { - time_t now_time = time(0); - char strLaunchTime[16] = { 0 }; - snprintf(strLaunchTime, sizeof(strLaunchTime), "%lld", (long long int)now_time); - - //將本次執行時間加密, 寫入檔案 - //if (!(last_launch_time > now_time)) - { - KeyExpansion(key, expandedKey); - unsigned char EncryptData[1 * 1024]; - memset(EncryptData, 0x00, sizeof(EncryptData)); - int encryptSize = AESEncryptArrayToArray(strLaunchTime, strlen(strLaunchTime), expandedKey, EncryptData, sizeof(EncryptData)); - - size_t base64_encode_length = 0; - char launchTime[1024] = { 0 }; - base64_encode(EncryptData, encryptSize, &base64_encode_length, launchTime); - *(launchTime + base64_encode_length) = '\0'; - - cJSON *s_root = cJSON_CreateObject(); - cJSON_AddItemToObject(s_root, "TLT code", cJSON_CreateString(launchTime)); - cJSON_AddItemToObject(s_root, "VM code", cJSON_CreateString("%")); - - char* JsonString = cJSON_Print(s_root); - - FILE *f = fopen(g_filename_TLT, "w"); - if (f == NULL) - { - printf("Error opening setting file!\n"); - } - else { - fprintf(f, "%s\n", JsonString); - fclose(f); - } - if (JsonString) { - free(JsonString); - JsonString = NULL; - } - if (s_root) { - free(s_root); - s_root = NULL; - } - } - } - } - - //printf("\n----------------mode: %s\n", WeightFileModeName); - - int bMacMatch = 0; - if (g_match_mac == 1) { - bMacMatch = 1; - } - //int nEnableNIC = 0; - char * find; - - - ///取得mac - { - char fetch_mac_addr[64] = { 0 }; - memset(fetch_mac_addr, 0x00, sizeof(fetch_mac_addr)); - GetMACAddress(fetch_mac_addr); - //printf("\n--------------------------:25\n"); - //http_mac_address = fetch_mac_addr; - - //printf("\nfetch_mac_addr:%s\n", fetch_mac_addr); - //printf("\nid->valuestring:%s\n", id->valuestring); - - find = strchr(fetch_mac_addr, '\n'); - if (find) - *find = '\0'; - - strcpy(g_mac_address, fetch_mac_addr); - } - - //printf("111-9 get password = %s \n", accountData[0].account_password); - // Check SDK3.0 and independent face license -#ifdef GY_OS_AMBA -#if 0 - if (g_IsSDK_3_0 == 1 && unlock_key && strncmp(unlock_key->valuestring, "face", 4) == 0) { - unlockingKeyInnoFR = 1; - // printf("unlocking key : %s\n", unlock_key->valuestring); - - char temp_key[512] = { 0 }; - //memcpy(temp_key, unlock_key->valuestring + 4, strlen(unlock_key->valuestring) - 4); - char formatted_mac[30] = { 0 }; -#if 0 - char fetch_mac_addr[30] = { 0 }; - //printf("\n--------g_mac_address:%s\n", g_mac_address); - strcpy(fetch_mac_addr, g_mac_address); - char* new_mac_addr = StrReplace(fetch_mac_addr, "-", ""); - //printf("\n--------new_mac_addr:%s\n", new_mac_addr); - - //sprintf(formatted_mac, "%s", new_mac_addr + 2); - if (new_mac_addr) { - free(new_mac_addr); - new_mac_addr = NULL; - } -#endif - - getContractSignature(temp_key, formatted_mac); - - //printf("\n--------formatted_mac:%s\n", formatted_mac); - //printf("\n--------temp_key:%s\n", temp_key); - - memset(strUnlockingKey, 0x00, sizeof(strUnlockingKey)); - strcpy(strUnlockingKey,"face"); - strcat(strUnlockingKey, temp_key); - - char object_key[512] = { 0 }; - strcpy(object_key, unlock_key->valuestring+4); - if (strcmp(temp_key, object_key)!=0) { - //printf("\nAAAAAAAAAA:Diff\n"); - char buffer_content[1024] = { 0 }; - strcpy(buffer_content,"{\"unlocking_key\":\""); - strcat(buffer_content,strUnlockingKey); - strcat(buffer_content,"\"}"); - update_config(buffer_content); - } - else { - //printf("\nAAAAAAAAAA:OK\n"); - } - - unlockingKeyInnoFR_success = faceengine_start_and_check_license(); // if strat faceengine earlily(when getContractSignature), faceengine will stuck - - //unlockingKeyInnoFR_success = 1;//不啟動faceengine,看能不能進去網頁 - //if (unlockingKeyInnoFR_success == 1) - //{ - - //} - } -#endif -#endif - - -#ifdef GY_OS_AMBA - if (strcmp(WeightFileModeName, "mod001") == 0 || - strcmp(WeightFileModeName, "mod002") == 0 || - strcmp(WeightFileModeName, "mod003") == 0 || - strcmp(WeightFileModeName, "mod004") == 0) { - if (!(fe && fe2) && unlock_key && strcmp(unlock_key->valuestring, "auto") == 0) { - check_if_fe_fail = 1; - } - } -#else - if (!(fe && fe2) && unlock_key && strcmp(unlock_key->valuestring,"auto")==0) { - check_if_fe_fail = 1; - } -#endif - - if ((fe && fe2 && li && st && et && id && td_weight_num == 0) || (td_weight_num >= 1 && check_if_correct_mail == 1) || g_IsRadarDevice == 1 || g_IsToFDevice == 1 || unlockingKeyInnoFR_success == 1 || check_if_fe_fail == 1) - { - //取得授權時間 - time_t start_time; - time_t end_time; - struct tm* m_time; - - if (fe && fe2) { - featureType = fe->valueint; - featureType2 = fe2->valueint; - - stAMBAcontent.featureType = featureType; - stAMBAcontent.featureType2 = featureType2; - } - /*else if (unlockingKeyInnoFR_success == 1) { - featureType = FEATURE_EMPTY; - featureType2 = FEATURE_AIFACE; - stAMBAcontent.featureType = FEATURE_EMPTY; - stAMBAcontent.featureType2 = FEATURE_AIFACE; - }*/ - else if (check_if_fe_fail == 1) { - featureType = FEATURE_TRAF_DET; -#ifdef GY_OS_V_SERIES - featureType2 = FEATURE_AIFLOW; -#elif GY_OS_NOVA - featureType2 = FEATURE_AIFLOW | FEATURE_AICAP; -#else - /*if (g_check_if_OK_getfeatures == 0) { - featureType2 = FEATURE_AIFLOW; - } - else*/ - if(strcmp(WeightFileModeName, "mod004") == 0){ - featureType2 = FEATURE_AIFLOW | FEATURE_AICAP; - } - else if (strcmp(WeightFileModeName, "mod001") == 0 || - strcmp(WeightFileModeName, "mod002") == 0 || - strcmp(WeightFileModeName, "mod003") == 0) { - featureType2 = FEATURE_AIFLOW; - } -#endif - stAMBAcontent.featureType = featureType; - stAMBAcontent.featureType2 = featureType2; - } - else { - featureType = 0x0000; - featureType2 = 0x0000; - stAMBAcontent.featureType = 0x0000; - stAMBAcontent.featureType2 = 0x0000; - } - - if (li && st && et && id) { - start_time = st->valueint; - m_time = gmtime(&start_time); - m_time->tm_mday += et->valueint; - end_time = mktime(m_time); - g_start_time = start_time; - g_end_time = end_time; - } - else { - start_time = 0; - end_time = 0; - g_start_time = start_time; - g_end_time = end_time; - } - - if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIRADAR) == FEATURE_AIRADAR) - { - g_IsRadarDevice = 1; - printf("g_IsRadarDevice : %d\n", g_IsRadarDevice); - printf("g_IsRadarFake : %d\n", g_IsRadarFake); - } - - if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AITOF) == FEATURE_AITOF) - { - g_IsToFDevice = 1; - printf("\ng_IsToFDevice : %d\n", g_IsToFDevice); - } - - if (td_weight_num >= 1 && check_if_correct_mail == 1) { - g_IsCustomWeight = 1; - printf("\ng_IsCustomWeight : %d\n", g_IsCustomWeight); - //featureType = FEATURE_ACCESS_CTRL; - //featureType2 = 0x0000; - //stAMBAcontent.featureType = FEATURE_ACCESS_CTRL; - //stAMBAcontent.featureType2 = 0x0000; - } - - //printf("111-8 get password = %s \n", accountData[0].account_password); - - // printf("Check licence:\n"); - //printf("--------------featureType = 0x%x \n", featureType); - //printf("--------------featureType2 = 0x%x \n", featureType2); - // printf("--------------li->valueint: %d\n", li->valueint); - // printf("--------------st->valueint: %d\n", st->valueint); - // printf("--------------et->valueint: %d\n", et->valueint); - // printf("--------------id->valueint: %d\n", id->valueint); - - ///////////////////////////////////////////////////////以上為featuretype 取得的地方 - /* - if (strstr(EncryptKeyData, "@") == NULL) { - printf("\nThere is no @.\n"); - } - else { - printf("\nThere is existing @.\n"); - }*/ - - //取得MAC Address - //20201111 sophia add - - if (g_match_mac == 0) - { - char fetch_mac_addr[30] = { 0 }; - strcpy(fetch_mac_addr, g_mac_address); - - char* new_mac_addr = StrReplace(fetch_mac_addr, "-", ""); - //printf("new_mac_addr = %s\n", new_mac_addr); - - //char* find_lilin_mac = strstr((const char*)new_mac_addr, "000FFC"); //begin 00-0f-fc //000FFC - - if (strstr(new_mac_addr, "000FFC") != NULL || strstr(new_mac_addr, "142FFD") != NULL) - { - if (!(td_weight_num >= 1 && check_if_correct_mail == 1)) { - if (id && strcmp(id->valuestring, new_mac_addr) == 0) - { - //printf("find_lilin_mac = 0x%x\n", find_lilin_mac); - bMacMatch = 1; //找到符合的MAC address - g_match_mac = 1; - g_bMacMatch = bMacMatch; - } - else if (unlockingKeyInnoFR_success == 1 || check_if_fe_fail == 1) { - bMacMatch = 1; - g_match_mac = 1; - g_bMacMatch = bMacMatch; - } - else - { - bMacMatch = 0; - g_match_mac = 0; - g_bMacMatch = bMacMatch; - } - } - else if (unlockingKeyInnoFR_success == 1 || check_if_fe_fail == 1) { - bMacMatch = 1; - g_match_mac = 1; - g_bMacMatch = bMacMatch; - } - else if(check_if_correct_mail == 1){ - bMacMatch = 1; - g_match_mac = 1; - g_bMacMatch = bMacMatch; - } - /*else if (g_IsRadarDevice == 1) {//現在有key了,就需要找到符合的MAC address - bMacMatch = 1; - g_match_mac = 1; - } - else if (g_IsToFDevice == 1)//現在有key了,就需要找到符合的MAC address - { - bMacMatch = 1; - g_match_mac = 1; - }*/ - else { - bMacMatch = 0; - g_match_mac = 0; - g_bMacMatch = bMacMatch; - } - } - else - { - g_match_mac = 0; - printf("\n============This is not LILIN mac address.\n"); - } - /* - printf("\ng_match_mac: %d\n", g_match_mac); - printf("\ng_mac_address: %s\n", g_mac_address); - */ - if (new_mac_addr) { - free(new_mac_addr); - new_mac_addr = NULL; - } - } - - //printf("111-711 0 get password = %s \n", accountData[0].account_password); - - update_system_time(); - - if (!(td_weight_num >= 1 && check_if_correct_mail == 1) && g_IsRadarDevice == 0 && unlockingKeyInnoFR_success == 0) { - if (li) - g_li = li->valueint; - else - g_li = 0; - - if (ad) - g_ad = ad->valueint; - else - g_ad = 0; - - if (ad && li) - check_license(li->valueint, ad->valueint, bMacMatch, start_time, end_time, g_filename_TLT); - else if(li) - check_license(li->valueint, 0, bMacMatch, start_time, end_time, g_filename_TLT); - else - check_license(0, 0, bMacMatch, start_time, end_time, g_filename_TLT); - } - - check_feature(); - //printf("111-7 0 get password = %s \n", accountData[0].account_password); - //post events setting - //char filename2[] = "events.json"; - char *filename2 = eventsPATH; - char *filename_tof = tofPATH; - if (!FileExist(filename2)) - { - printf("%s doesn't exist.\n", filename2); - printf("Press any key to exit...\n"); - getchar(); - return; - } - if (!FileExist(filename_tof)) - { - printf("%s doesn't exist.\n", filename_tof); - printf("Press any key to exit...\n"); - getchar(); - return; - } - //printf("111-7 1 get password = %s \n", accountData[0].account_password); - cJSON *tof_root; - cJSON *tof_version,*tof_debug,*tof_install_angle,*tof_enable_camera,*enable_tof_ground,*enable_tof_wall,*tof_camera; - cJSON *tof_camera_ip,*tof_camera_port,*tof_camera_sub_url,*tof_auth_key,*tof_ip_setting,*tof_camera_username,*tof_camera_password; - cJSON *distance_options, *distance_threshold, *height_options, *height_threshold,*distance_min_max,*height_min_max; - cJSON *ground_x, *ground_y; - - fileBuf = ReadAllBytes(filename_tof); - if (fileBuf) { - tof_root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - - tof_version = cJSON_GetObjectItem(tof_root, "version"); - tof_debug = cJSON_GetObjectItem(tof_root, "debug"); - tof_install_angle = cJSON_GetObjectItem(tof_root, "install_angle"); - tof_enable_camera = cJSON_GetObjectItem(tof_root, "enable_camera"); - enable_tof_ground = cJSON_GetObjectItem(tof_root, "enable_tof_ground"); - enable_tof_wall = cJSON_GetObjectItem(tof_root, "enable_tof_wall"); - tof_camera = cJSON_GetObjectItem(tof_root, "camera"); - distance_options = cJSON_GetObjectItem(tof_root, "distance_options"); - distance_threshold = cJSON_GetObjectItem(tof_root, "distance_threshold"); - height_options = cJSON_GetObjectItem(tof_root, "height_options"); - height_threshold = cJSON_GetObjectItem(tof_root, "height_threshold"); - distance_min_max = cJSON_GetObjectItem(tof_root, "distance_min_max"); - height_min_max = cJSON_GetObjectItem(tof_root, "height_min_max"); - - ground_x = cJSON_GetObjectItem(tof_root, "ground_x"); - ground_y = cJSON_GetObjectItem(tof_root, "ground_y"); - -#ifdef GY_OS_AMBA - if (tof_version) { - tofData.tof_version = tof_version->valueint; - } - else { - new_data_write_to_tof_file_flag = 1; - tofData.tof_version = 1; - } - - - if (tof_debug) { - if (cJSON_IsTrue(tof_debug)) - { - tofData.tof_debug = true; - } - else - { - tofData.tof_debug = false; - } - } - else { - new_data_write_to_tof_file_flag = 1; - tofData.tof_debug = false; - } - - - if (tof_install_angle) { - tofData.tof_install_angle = tof_install_angle->valueint; - } - else { - new_data_write_to_tof_file_flag = 1; - tofData.tof_install_angle = 90; - } - - if (tof_enable_camera) { - if (cJSON_IsTrue(tof_enable_camera)) - { - tofData.tof_enable_camera = true; - } - else - { - tofData.tof_enable_camera = false; - } - } - else { - new_data_write_to_tof_file_flag = 1; - tofData.tof_enable_camera = false; - } - - if (enable_tof_ground) { - if (cJSON_IsTrue(enable_tof_ground)) - { - tofData.enable_tof_ground = true; - } - else - { - tofData.enable_tof_ground = false; - } - } - else { - new_data_write_to_tof_file_flag = 1; - tofData.enable_tof_ground = false; - } - - if (enable_tof_wall) { - if (cJSON_IsTrue(enable_tof_wall)) - { - tofData.enable_tof_wall = true; - } - else - { - tofData.enable_tof_wall = false; - } - } - else { - new_data_write_to_tof_file_flag = 1; - tofData.enable_tof_wall = false; - } - - if (distance_options) { - strcpy(tofData.distance_options, distance_options->valuestring); - } - else { - new_data_write_to_tof_file_flag = 1; - strcpy(tofData.distance_options, "lt"); - } - - if (distance_min_max) { - strcpy(tofData.distance_min_max, distance_min_max->valuestring); - } - else { - new_data_write_to_tof_file_flag = 1; - strcpy(tofData.distance_min_max, "min"); - } - - if (distance_threshold) { - strcpy(tofData.distance_threshold, distance_threshold->valuestring); - } - else { - new_data_write_to_tof_file_flag = 1; - strcpy(tofData.distance_threshold, "0.5"); - } - - if (height_options) { - strcpy(tofData.height_options, height_options->valuestring); - } - else { - new_data_write_to_tof_file_flag = 1; - strcpy(tofData.height_options, "gt"); - } - - if (height_min_max) { - strcpy(tofData.height_min_max, height_min_max->valuestring); - } - else { - new_data_write_to_tof_file_flag = 1; - strcpy(tofData.height_min_max, "max"); - } - - if (ground_x) { - strcpy(tofData.ground_x, ground_x->valuestring); - } - else { - new_data_write_to_tof_file_flag = 1; - strcpy(tofData.ground_x, "320"); - } - - if (ground_y) { - strcpy(tofData.ground_y, ground_y->valuestring); - } - else { - new_data_write_to_tof_file_flag = 1; - strcpy(tofData.ground_y, "240"); - } - - if (height_threshold) { - strcpy(tofData.height_threshold, height_threshold->valuestring); - } - else { - new_data_write_to_tof_file_flag = 1; - strcpy(tofData.height_threshold, "1.5"); - } - - if (tof_camera) { - tof_camera_ip = cJSON_GetObjectItem(tof_camera, "camera_ip"); - tof_camera_port = cJSON_GetObjectItem(tof_camera, "camera_port"); - tof_camera_sub_url = cJSON_GetObjectItem(tof_camera, "camera_sub_url"); - tof_auth_key = cJSON_GetObjectItem(tof_camera, "auth_key"); - tof_ip_setting = cJSON_GetObjectItem(tof_camera, "ip_setting"); - tof_camera_username = cJSON_GetObjectItem(tof_camera, "camera_username"); - tof_camera_password = cJSON_GetObjectItem(tof_camera, "camera_password"); - - if (tof_camera_ip) { - strcpy(tofData.tof_camera_ip, tof_camera_ip->valuestring); - } - else { - new_data_write_to_tof_file_flag = 1; - strcpy(tofData.tof_camera_ip, "192.168.50.200"); - } - - if (tof_camera_port) { - strcpy(tofData.tof_camera_port, tof_camera_port->valuestring); - } - else { - new_data_write_to_tof_file_flag = 1; - strcpy(tofData.tof_camera_port, "80"); - } - - if (tof_camera_sub_url) { - strcpy(tofData.tof_camera_sub_url, tof_camera_sub_url->valuestring); - } - else { - new_data_write_to_tof_file_flag = 1; - strcpy(tofData.tof_camera_sub_url, "/stream0"); - } - - if (tof_auth_key) { - strcpy(tofData.tof_auth_key, tof_auth_key->valuestring); - } - else { - new_data_write_to_tof_file_flag = 1; - strcpy(tofData.tof_auth_key, "Basic YWRtaW46bXNwbHNpZ25hbA=="); - } - - if (tof_ip_setting) { - if (cJSON_IsTrue(tof_ip_setting)) - { - tofData.tof_ip_setting = true; - } - else - { - tofData.tof_ip_setting = false; - } - } - else { - new_data_write_to_tof_file_flag = 1; - tofData.tof_ip_setting = false; - } - - if (tof_camera_username) { - char temp_account[512] = { 0 }; - urlencode((unsigned char *)tof_camera_username->valuestring, strlen(tof_camera_username->valuestring), (unsigned char *)temp_account, 512); - memcpy(tofData.tof_camera_username, temp_account, strlen(temp_account)); - tofData.tof_camera_username[strlen(temp_account)] = '\0'; - } - else { - new_data_write_to_tof_file_flag = 1; - strcpy(tofData.tof_camera_username, "admin"); - } - - if (tof_camera_password) { - char temp_account[512] = { 0 }; - urlencode((unsigned char *)tof_camera_password->valuestring, strlen(tof_camera_password->valuestring), (unsigned char *)temp_account, 512); - memcpy(tofData.tof_camera_password, temp_account, strlen(temp_account)); - tofData.tof_camera_password[strlen(temp_account)] = '\0'; - } - else { - new_data_write_to_tof_file_flag = 1; - strcpy(tofData.tof_camera_password, "pass"); - } - } - else { - new_data_write_to_tof_file_flag = 1; - strcpy(tofData.tof_camera_ip, "192.168.50.200"); - strcpy(tofData.tof_camera_port, "80"); - strcpy(tofData.tof_camera_sub_url, "/stream0"); - strcpy(tofData.tof_auth_key, "Basic YWRtaW46bXNwbHNpZ25hbA=="); - tofData.tof_ip_setting = false; - strcpy(tofData.tof_camera_username, "admin"); - strcpy(tofData.tof_camera_password, "pass"); - } -#endif - } - } - //printf("111-7 2 get password = %s \n", accountData[0].account_password); - cJSON *n_root, *notification, *events_default_version, *enable_post,*enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content - ,*post_customized_header; - cJSON *event_counter_setting, *detect3, *event_counters, *counter_name,*counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *reset_at, *enable_time_range, *time_range_from, *time_range_to,*enable_reset_only_cloud,*enable_linked_to_dwell_time; - cJSON *a_report, *report_counters, *counter_a, *counter_a_name, *counter_b, *counter_b_name, *counter_a_zone, *counter_b_zone,*counter_c_name, - *enable_report,*report_max_value, *initial_icon, *detection_output, *output_icon,*counter_mode; - cJSON *a_snmp, *snmp_management, *snmp_event_name, *snmp_version, *snmp_group_name, *snmp_host_ip, *snmp_host_port, - *snmp_oid, *snmp_value, *snmp_type; - - cJSON *link_to_post_event_name, *post_interval; - cJSON *email_setting,*email_content; - cJSON *post_sequence,*post_file_format, *post_jpeg_file_name_format, *post_jpeg_file_name,*post_timeout; - cJSON *enable_heartbeat, *heartbeat_dwell, *heartbeat_link_to_post_event_name, *dwell_to_the_same_location, - *enable_snmp_heartbeat, *snmp_heartbeat_dwell, *snmp_heartbeat_link_to_post_event_name, - *enable_only_once_to_post,*enable_obj_once_to_post,*enable_location_once_to_post,*enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion,*heatmap_max,*enable_heatmap,*heatmap_frequency,*lpr_title,*enable_counter_snap, *enable_barcode_qr, - *enable_check_ptz_start_autotracking,*enable_check_ptz_end_autotracking,*ptz_start_autotracking_link_to_post_event_name,*ptz_end_autotracking_link_to_post_event_name; - - fileBuf = ReadAllBytes(filename2); - if (fileBuf) { - n_root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - notification = cJSON_GetObjectItem(n_root, "notification"); - events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); - enable_post = cJSON_GetObjectItem(notification, "enable_post"); - - http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); - enable_heartbeat = cJSON_GetObjectItem(notification, "enable_heartbeat"); - enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); - enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); - ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); - ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); - enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); - enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); - enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); - dwell_to_the_same_location = cJSON_GetObjectItem(notification, "dwell_to_the_same_location"); - enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); - enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); - heartbeat_dwell = cJSON_GetObjectItem(notification, "heartbeat_dwell"); - heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "heartbeat_link_to_post_event_name"); - heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); - enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); - heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); - lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); - enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); - enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); - - enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); - enable_snmp_heartbeat = cJSON_GetObjectItem(notification, "enable_snmp_heartbeat"); - snmp_heartbeat_dwell = cJSON_GetObjectItem(notification, "snmp_heartbeat_dwell"); - snmp_heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "snmp_heartbeat_link_to_post_event_name"); - - activePostNotification = strcmp(enable_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; - - if (events_default_version) { - strcpy(heartbeatData.events_default_version, events_default_version->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.events_default_version, "1"); - } - - if (enable_snmp_post) - activeSNMPPost = strcmp(enable_snmp_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; - else { - new_data_write_to_events_file_flag = 1; - activeSNMPPost = _FALSE; - } - - if (enable_heartbeat) { - strcpy(heartbeatData.enable_heartbeat, enable_heartbeat->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.enable_heartbeat, "No"); - } - - if (enable_snmp_heartbeat) { - strcpy(heartbeatData.enable_snmp_heartbeat, enable_snmp_heartbeat->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.enable_snmp_heartbeat, "No"); - } - - if (snmp_heartbeat_dwell) { - strcpy(heartbeatData.snmp_heartbeat_dwell, snmp_heartbeat_dwell->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.snmp_heartbeat_dwell, "5"); - } - - if (snmp_heartbeat_link_to_post_event_name) { - strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, snmp_heartbeat_link_to_post_event_name->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, "Heartbeat"); - } - - if (enable_check_ptz_start_autotracking) { - strcpy(heartbeatData.enable_check_ptz_start_autotracking, enable_check_ptz_start_autotracking->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.enable_check_ptz_start_autotracking, "No"); - } - - if (enable_check_ptz_end_autotracking) { - strcpy(heartbeatData.enable_check_ptz_end_autotracking, enable_check_ptz_end_autotracking->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.enable_check_ptz_end_autotracking, "No"); - } - - if (enable_only_once_to_post) { - strcpy(heartbeatData.enable_only_once_to_post, enable_only_once_to_post->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.enable_only_once_to_post, "Yes"); - } - - if (enable_obj_once_to_post) { - strcpy(heartbeatData.enable_obj_once_to_post, enable_obj_once_to_post->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.enable_obj_once_to_post, "Yes"); - } - - if (enable_location_once_to_post) { - strcpy(heartbeatData.enable_location_once_to_post, enable_location_once_to_post->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.enable_location_once_to_post, "Yes"); - } - - if (enable_nvr_once_to_getalarmmotion) { - strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, enable_nvr_once_to_getalarmmotion->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, "Yes"); - } - - if (enable_8592_once_to_getalarmmotion) { - strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, enable_8592_once_to_getalarmmotion->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, "Yes"); - } - - if (dwell_to_the_same_location) { - strcpy(heartbeatData.dwell_to_the_same_location, dwell_to_the_same_location->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.dwell_to_the_same_location, "5"); - } - - if (heartbeat_dwell) { - strcpy(heartbeatData.heartbeat_dwell, heartbeat_dwell->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.heartbeat_dwell, "10"); - } - - if (heatmap_max) { - strcpy(heartbeatData.heatmap_max, heatmap_max->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.heatmap_max, "100"); - } - - if (enable_heatmap) { - strcpy(heartbeatData.enable_heatmap, enable_heatmap->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.enable_heatmap, "No"); - } - - if (heatmap_frequency) { - strcpy(heartbeatData.heatmap_frequency, heatmap_frequency->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.heatmap_frequency, "5"); - } - - if (lpr_title) { - strcpy(heartbeatData.lpr_title, lpr_title->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.lpr_title, "My Car Park"); - } - - if (heartbeat_link_to_post_event_name) { - strcpy(heartbeatData.heartbeat_link_to_post_event_name, heartbeat_link_to_post_event_name->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.heartbeat_link_to_post_event_name, ""); - } - - if (ptz_start_autotracking_link_to_post_event_name) { - strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ptz_start_autotracking_link_to_post_event_name->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ""); - } - - if (ptz_end_autotracking_link_to_post_event_name) { - strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ptz_end_autotracking_link_to_post_event_name->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ""); - } - - if (enable_counter_snap) { - strcpy(heartbeatData.enable_counter_snap, enable_counter_snap->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.enable_counter_snap, "No"); - } - - if (enable_barcode_qr) { - strcpy(heartbeatData.enable_barcode_qr, enable_barcode_qr->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(heartbeatData.enable_barcode_qr, "No"); - } - - int i = 0; - cJSON_ArrayForEach(detect2, http_post_events) - { - post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); - post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); - post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); - post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); - post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); - post_url = cJSON_GetObjectItem(detect2, "post_url"); - post_username = cJSON_GetObjectItem(detect2, "post_username"); - post_password = cJSON_GetObjectItem(detect2, "post_password"); - post_content = cJSON_GetObjectItem(detect2, "post_content"); - post_customized_header = cJSON_GetObjectItem(detect2, "post_customized_header"); - post_sequence = cJSON_GetObjectItem(detect2, "post_sequence"); - post_timeout = cJSON_GetObjectItem(detect2, "post_timeout"); - post_file_format = cJSON_GetObjectItem(detect2, "post_file_format"); - post_jpeg_file_name_format = cJSON_GetObjectItem(detect2, "post_jpeg_file_name_format"); - post_jpeg_file_name = cJSON_GetObjectItem(detect2, "post_jpeg_file_name"); - - char temp_account[512] = { 0 }; - urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); - memcpy(postEventList[i].post_username, temp_account, strlen(temp_account)); - postEventList[i].post_username[strlen(temp_account)] = '\0'; - - char temp_account2[512] = { 0 }; - urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); - memcpy(postEventList[i].post_password, temp_account2, strlen(temp_account2)); - postEventList[i].post_password[strlen(temp_account2)] = '\0'; - - strcpy(postEventList[i].post_protocol, post_protocol->valuestring); - strcpy(postEventList[i].post_event_method, post_event_method->valuestring); - strcpy(postEventList[i].post_event_name, post_event_name2->valuestring); - - if (g_camera_white_LED == 1 && i == 2 && strcmp(postEventList[i].post_event_name, "Camera virtual 3 / White LED") != 0) { - new_data_write_to_events_file_flag = 1; - strcpy(postEventList[i].post_event_name, "Camera virtual 3 / White LED"); - } - - strcpy(postEventList[i].post_host_ip, post_host_ip->valuestring); - strcpy(postEventList[i].post_host_port, post_host_port->valuestring); - strcpy(postEventList[i].post_url, post_url->valuestring); - //strcpy(postEventList[i].post_username, post_username->valuestring); - //strcpy(postEventList[i].post_password, post_password->valuestring); - strcpy(postEventList[i].post_content, post_content->valuestring); - strcpy(postEventList[i].post_customized_header, post_customized_header->valuestring); - - if (post_sequence) - strcpy(postEventList[i].post_sequence, post_sequence->valuestring); - else { - strcpy(postEventList[i].post_sequence, ""); - new_data_write_to_events_file_flag = 1; - } - - if (post_timeout) - strcpy(postEventList[i].post_timeout, post_timeout->valuestring); - else { - strcpy(postEventList[i].post_timeout, "5"); - new_data_write_to_events_file_flag = 1; - } - - if (post_file_format) - strcpy(postEventList[i].post_file_format, post_file_format->valuestring); - else { - strcpy(postEventList[i].post_file_format, "text"); - new_data_write_to_events_file_flag = 1; - } - - if (post_jpeg_file_name_format) - strcpy(postEventList[i].post_jpeg_file_name_format, post_jpeg_file_name_format->valuestring); - else { - strcpy(postEventList[i].post_jpeg_file_name_format, "fixed"); - new_data_write_to_events_file_flag = 1; - } - - if (post_jpeg_file_name) - strcpy(postEventList[i].post_jpeg_file_name, post_jpeg_file_name->valuestring); - else { - strcpy(postEventList[i].post_jpeg_file_name, "snap"); - new_data_write_to_events_file_flag = 1; - } - - postEventList[i].check_if_delivering = 0;//其他地方不須再初始化 - i++; - } - if (i < 9) { - strcpy(postEventList[i].post_protocol, "HTTP"); - strcpy(postEventList[i].post_event_method, "GET"); - strcpy(postEventList[i].post_event_name, "Go to PTZ preset"); - strcpy(postEventList[i].post_host_ip, "localhost"); - strcpy(postEventList[i].post_host_port, accountData[0].account_aida_port); - strcpy(postEventList[i].post_url, "/ptzpreset?camid=1&ai_goto_preset=1"); - strcpy(postEventList[i].post_username, "admin"); - strcpy(postEventList[i].post_password, "Pass1234"); - strcpy(postEventList[i].post_content, ""); - strcpy(postEventList[i].post_customized_header, ""); - strcpy(postEventList[i].post_sequence, ""); - strcpy(postEventList[i].post_file_format, "text"); - strcpy(postEventList[i].post_jpeg_file_name_format, "fixed"); - strcpy(postEventList[i].post_jpeg_file_name, "snap"); - strcpy(postEventList[i].post_timeout, "5"); - - new_data_write_to_events_file_flag = 1; - } - -#ifdef GY_OS_V_SERIES - -#else - event_counter_setting = cJSON_GetObjectItem(n_root, "event_counter_setting"); - event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); - i = 0; - cJSON_ArrayForEach(detect3, event_counters) - { - counter_name = cJSON_GetObjectItem(detect3, "counter_name"); - counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); - counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); - reset_value = cJSON_GetObjectItem(detect3, "reset_value"); - enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); - reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); - reset_at = cJSON_GetObjectItem(detect3, "reset_at"); - enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); - time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); - time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); - enable_reset_only_cloud = cJSON_GetObjectItem(detect3, "enable_reset_only_cloud"); - enable_linked_to_dwell_time = cJSON_GetObjectItem(detect3, "enable_linked_to_dwell_time"); - - link_to_post_event_name = cJSON_GetObjectItem(detect3, "link_to_post_event_name"); - post_interval = cJSON_GetObjectItem(detect3, "post_interval"); - - strcpy(eventCounterList[i].counter_name, counter_name->valuestring); - - if (counter_cust_name) - strcpy(eventCounterList[i].counter_cust_name, counter_cust_name->valuestring); - else { - strcpy(eventCounterList[i].counter_cust_name, eventCounterList[i].counter_name); - new_data_write_to_events_file_flag = 1; - } - strcpy(eventCounterList[i].counter_unit, counter_unit->valuestring); - if (reset_value) - eventCounterList[i].reset_value = atoi(reset_value->valuestring); - else { - eventCounterList[i].reset_value = 0; - new_data_write_to_events_file_flag = 1; - } - strcpy(eventCounterList[i].enable_reset_time_interval, enable_reset_time_interval->valuestring); - strcpy(eventCounterList[i].reset_time_interval, reset_time_interval->valuestring); - strcpy(eventCounterList[i].reset_at, reset_at->valuestring); - strcpy(eventCounterList[i].enable_time_range, enable_time_range->valuestring); - strcpy(eventCounterList[i].time_range_from, time_range_from->valuestring); - strcpy(eventCounterList[i].time_range_to, time_range_to->valuestring); - struct tm tm; - strptime_c(eventCounterList[i].reset_at, "%Y-%m-%d %H:%M:%S", &tm); - eventCounterList[i].timetResetAt = mktime(&tm); - - struct tm *resetTime = localtime(&eventCounterList[i].timetResetAt); - eventCounterList[i].reset_month = resetTime->tm_mon; - eventCounterList[i].reset_month_day = resetTime->tm_mday; - eventCounterList[i].reset_week_day = resetTime->tm_wday; - eventCounterList[i].reset_hour = resetTime->tm_hour; - eventCounterList[i].reset_min = resetTime->tm_min; - eventCounterList[i].reset_sec = resetTime->tm_sec; - strptime_c(eventCounterList[i].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); - eventCounterList[i].timetTimeRangeFrom = mktime(&tm); - strptime_c(eventCounterList[i].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); - eventCounterList[i].timetTimeRangeTo = mktime(&tm); - - if (link_to_post_event_name) { - strcpy(eventCounterList[i].link_to_post_event_name, link_to_post_event_name->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(eventCounterList[i].link_to_post_event_name, ""); - } - - if (post_interval) { - strcpy(eventCounterList[i].post_interval, post_interval->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(eventCounterList[i].post_interval, "5 minutes"); - } - - if (enable_reset_only_cloud) { - strcpy(eventCounterList[i].enable_reset_only_cloud, enable_reset_only_cloud->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(eventCounterList[i].enable_reset_only_cloud, "No"); - } - - if (enable_linked_to_dwell_time) { - strcpy(eventCounterList[i].enable_linked_to_dwell_time, enable_linked_to_dwell_time->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(eventCounterList[i].enable_linked_to_dwell_time, "No"); - } - - i++; - } - if (i < 8) { - new_data_write_to_events_file_flag = 1; - } - - report_counters = cJSON_GetObjectItem(event_counter_setting, "report_counters"); - - if (report_counters) { - i = 0; - cJSON_ArrayForEach(a_report, report_counters) - { - if (a_report) { - counter_a = cJSON_GetObjectItem(a_report, "counter_a"); - counter_a_name = cJSON_GetObjectItem(a_report, "counter_a_name"); - counter_a_zone = cJSON_GetObjectItem(a_report, "counter_a_zone"); - counter_b = cJSON_GetObjectItem(a_report, "counter_b"); - counter_b_name = cJSON_GetObjectItem(a_report, "counter_b_name"); - counter_b_zone = cJSON_GetObjectItem(a_report, "counter_b_zone"); - counter_c_name = cJSON_GetObjectItem(a_report, "counter_c_name"); - report_max_value = cJSON_GetObjectItem(a_report, "report_max_value"); - enable_report = cJSON_GetObjectItem(a_report, "enable_report"); - counter_mode = cJSON_GetObjectItem(a_report, "counter_mode"); - initial_icon = cJSON_GetObjectItem(a_report, "initial_icon"); - detection_output = cJSON_GetObjectItem(a_report, "detection_output"); - output_icon = cJSON_GetObjectItem(a_report, "output_icon"); - - if (counter_a) { - strcpy(reportCounterList[i].counter_a, counter_a->valuestring); - } - else { - strcpy(reportCounterList[i].counter_a, "Counter01"); - new_data_write_to_events_file_flag = 1; - } - - if (counter_a_name) { - strcpy(reportCounterList[i].counter_a_name, counter_a_name->valuestring); - } - else { - strcpy(reportCounterList[i].counter_a_name, "Name"); - new_data_write_to_events_file_flag = 1; - } - - if (counter_a_zone) { - strcpy(reportCounterList[i].counter_a_zone, counter_a_zone->valuestring); - } - else { - strcpy(reportCounterList[i].counter_a_zone, "1"); - new_data_write_to_events_file_flag = 1; - } - - if (counter_b) { - strcpy(reportCounterList[i].counter_b, counter_b->valuestring); - } - else { - strcpy(reportCounterList[i].counter_b, ""); - new_data_write_to_events_file_flag = 1; - } - - if (counter_b_name) { - strcpy(reportCounterList[i].counter_b_name, counter_b_name->valuestring); - } - else { - strcpy(reportCounterList[i].counter_b_name, ""); - new_data_write_to_events_file_flag = 1; - } - - if (counter_b_zone) { - strcpy(reportCounterList[i].counter_b_zone, counter_b_zone->valuestring); - } - else { - strcpy(reportCounterList[i].counter_b_zone, "0"); - new_data_write_to_events_file_flag = 1; - } - - if (counter_c_name) { - strcpy(reportCounterList[i].counter_c_name, counter_c_name->valuestring); - } - else { - strcpy(reportCounterList[i].counter_c_name, ""); - new_data_write_to_events_file_flag = 1; - } - - if (report_max_value) { - strcpy(reportCounterList[i].report_max_value, report_max_value->valuestring); - } - else { - strcpy(reportCounterList[i].report_max_value, "100"); - new_data_write_to_events_file_flag = 1; - } - - if (enable_report) { - strcpy(reportCounterList[i].enable_report, enable_report->valuestring); - } - else { - strcpy(reportCounterList[i].enable_report, "No"); - new_data_write_to_events_file_flag = 1; - } - - if (counter_mode) { - strcpy(reportCounterList[i].counter_mode, counter_mode->valuestring); - } - else { - strcpy(reportCounterList[i].counter_mode, "0"); - new_data_write_to_events_file_flag = 1; - } - - if (initial_icon) { - strcpy(reportCounterList[i].initial_icon, initial_icon->valuestring); - } - else { - strcpy(reportCounterList[i].initial_icon, "car_300X300_white"); - new_data_write_to_events_file_flag = 1; - } - - if (detection_output) { - strcpy(reportCounterList[i].detection_output, detection_output->valuestring); - } - else { - strcpy(reportCounterList[i].detection_output, "No entry for cars"); - new_data_write_to_events_file_flag = 1; - } - - if (output_icon) { - strcpy(reportCounterList[i].output_icon, output_icon->valuestring); - } - else { - strcpy(reportCounterList[i].output_icon, "car_1_300X300_red"); - new_data_write_to_events_file_flag = 1; - } - - i++; - } - } - - if (i < MAX_REPORT_COUNTERS) { - for (int index_report = i; index_report < MAX_REPORT_COUNTERS; index_report++) { - strcpy(reportCounterList[index_report].counter_a, "Counter01"); - strcpy(reportCounterList[index_report].counter_a_name, "Name"); - strcpy(reportCounterList[index_report].counter_a_zone, "1"); - strcpy(reportCounterList[index_report].counter_b, ""); - strcpy(reportCounterList[index_report].counter_b_name, ""); - strcpy(reportCounterList[index_report].counter_b_zone, "0"); - strcpy(reportCounterList[index_report].counter_c_name, ""); - strcpy(reportCounterList[index_report].report_max_value, "100"); - strcpy(reportCounterList[index_report].enable_report, "No"); - strcpy(reportCounterList[index_report].counter_mode, "0"); - strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); - strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); - strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); - } - - new_data_write_to_events_file_flag = 1; - } - } - else { - for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { - strcpy(reportCounterList[index_report].counter_a, "Counter01"); - strcpy(reportCounterList[index_report].counter_a_name, "Name"); - strcpy(reportCounterList[index_report].counter_a_zone, "1"); - strcpy(reportCounterList[index_report].counter_b, ""); - strcpy(reportCounterList[index_report].counter_b_name, ""); - strcpy(reportCounterList[index_report].counter_b_zone, "0"); - strcpy(reportCounterList[index_report].counter_c_name, ""); - strcpy(reportCounterList[index_report].report_max_value, "100"); - strcpy(reportCounterList[index_report].enable_report, "No"); - strcpy(reportCounterList[index_report].counter_mode, "0"); - strcpy(reportCounterList[index_report].initial_icon, "car_300X300_white"); - strcpy(reportCounterList[index_report].detection_output, "No entry for cars"); - strcpy(reportCounterList[index_report].output_icon, "car_1_300X300_red"); - } - - new_data_write_to_events_file_flag = 1; - } - - - snmp_management = cJSON_GetObjectItem(event_counter_setting, "snmp_management"); - - if (snmp_management) { - i = 0; - cJSON_ArrayForEach(a_snmp, snmp_management) - { - if (a_snmp) { - snmp_event_name = cJSON_GetObjectItem(a_snmp, "snmp_event_name"); - snmp_version = cJSON_GetObjectItem(a_snmp, "snmp_version"); - snmp_group_name = cJSON_GetObjectItem(a_snmp, "snmp_group_name"); - snmp_host_ip = cJSON_GetObjectItem(a_snmp, "snmp_host_ip"); - snmp_host_port = cJSON_GetObjectItem(a_snmp, "snmp_host_port"); - snmp_oid = cJSON_GetObjectItem(a_snmp, "snmp_oid"); - snmp_value = cJSON_GetObjectItem(a_snmp, "snmp_value"); - snmp_type = cJSON_GetObjectItem(a_snmp, "snmp_type"); - - if (snmp_event_name) { - strcpy(SNMPManagementList[i].snmp_event_name, snmp_event_name->valuestring); - } - else { - char temp_name[10] = { 0 }; - sprintf(temp_name, "SNMP %d", i + 1); - strcpy(SNMPManagementList[i].snmp_event_name, temp_name); - new_data_write_to_events_file_flag = 1; - } - - if (snmp_version) { - strcpy(SNMPManagementList[i].snmp_version, snmp_version->valuestring); - } - else { - strcpy(SNMPManagementList[i].snmp_version, "v1"); - new_data_write_to_events_file_flag = 1; - } - - if (snmp_group_name) { - strcpy(SNMPManagementList[i].snmp_group_name, snmp_group_name->valuestring); - } - else { - strcpy(SNMPManagementList[i].snmp_group_name, "public"); - new_data_write_to_events_file_flag = 1; - } - - if (snmp_host_ip) { - strcpy(SNMPManagementList[i].snmp_host_ip, snmp_host_ip->valuestring); - } - else { - strcpy(SNMPManagementList[i].snmp_host_ip, "192.168.0.200"); - new_data_write_to_events_file_flag = 1; - } - - if (snmp_host_port) { - strcpy(SNMPManagementList[i].snmp_host_port, snmp_host_port->valuestring); - } - else { - strcpy(SNMPManagementList[i].snmp_host_port, "161"); - new_data_write_to_events_file_flag = 1; - } - - if (snmp_oid) { - strcpy(SNMPManagementList[i].snmp_oid, snmp_oid->valuestring); - } - else { - strcpy(SNMPManagementList[i].snmp_oid, ".1.3.6.1.2.1.1.6.0"); - new_data_write_to_events_file_flag = 1; - } - - if (snmp_value) { - strcpy(SNMPManagementList[i].snmp_value, snmp_value->valuestring); - } - else { - strcpy(SNMPManagementList[i].snmp_value, "mylocation"); - new_data_write_to_events_file_flag = 1; - } - - if (snmp_type) { - strcpy(SNMPManagementList[i].snmp_type, snmp_type->valuestring); - } - else { - strcpy(SNMPManagementList[i].snmp_type, "string"); - new_data_write_to_events_file_flag = 1; - } - - SNMPManagementList[i].check_if_delivering = 0;//其他地方不須再初始化 - i++; - } - } - - if (i < MAX_SNMP_MANAGEMENT) { - for (int index_snmp = i; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { - char temp_name[10] = { 0 }; - if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { - sprintf(temp_name, "SNMP %d", index_snmp + 1); - strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); - strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); - strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); - strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); - strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); - strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); - strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); - strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); - } - else { - sprintf(temp_name, "%s", "Heartbeat"); - strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); - strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); - strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); - strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); - strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); - strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); - strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); - strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); - } - - SNMPManagementList[index_snmp].check_if_delivering = 0;//其他地方不須再初始化 - } - - new_data_write_to_events_file_flag = 1; - } - } - else { - for (int index_snmp = 0; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { - char temp_name[10] = { 0 }; - if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { - sprintf(temp_name, "SNMP %d", index_snmp + 1); - strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); - strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); - strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); - strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); - strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); - strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); - strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); - strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); - } - else { - sprintf(temp_name, "%s", "Heartbeat"); - strcpy(SNMPManagementList[index_snmp].snmp_event_name, temp_name); - strcpy(SNMPManagementList[index_snmp].snmp_version, "v1"); - strcpy(SNMPManagementList[index_snmp].snmp_group_name, "public"); - strcpy(SNMPManagementList[index_snmp].snmp_host_ip, "192.168.0.200"); - strcpy(SNMPManagementList[index_snmp].snmp_host_port, "161"); - strcpy(SNMPManagementList[index_snmp].snmp_oid, ".1.3.6.1.2.1.1.6.0"); - strcpy(SNMPManagementList[index_snmp].snmp_value, "mylocation"); - strcpy(SNMPManagementList[index_snmp].snmp_type, "string"); - } - - SNMPManagementList[index_snmp].check_if_delivering = 0;//其他地方不須再初始化 - } - - new_data_write_to_events_file_flag = 1; - } - -#endif - - email_setting = cJSON_GetObjectItem(n_root, "email_setting"); - if (email_setting) { - email_content = cJSON_GetObjectItem(email_setting, "email_content"); - if (email_content) { - strcpy(emailData.email_content, email_content->valuestring); - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); - } - } - else { - new_data_write_to_events_file_flag = 1; - strcpy(emailData.email_content, "Date Time: <|MM|>/<|DD|>/<|YYYY|> <|hh|>:<|mm|>:<|ss|>\nCamera Name: <|device_name|>\nObject ID: <|obj_tracking_id|>\nObject Name: <|name|>\nEvent: <|behavior_name|>\nDwell Time: <|obj_dwell_time|> sec.\nMAC: <|mac_address|>"); - } - } - //printf("111-7 3 get password = %s \n", accountData[0].account_password); - //trigger events settings - //cJSON* cam_ip, * http_port, * video_port, * cam_pwd, * channel_id; - cJSON *view_setting, *camera, *camera_name, *enable_anpr, *enable_face, *enable_traffic, *enable_logo, *tab_view_size, *enable_lpr_db, *enable_downsized_cropped_roi,*enable_zone_crop_1, *enable_add_face_frequent_list, - *enable_track,*enable_PTZ, *ptz_tracking_fov_min, *ptz_tracking_fov_max, *ptz_enable_tracking, *ptz_tracking_by_enter_zone, *ptz_tracking_resume_dwell,*ptz_sensitivity,*enable_unknown_object, *enable_ivs_person_detection, *assign_ivs_object_to,*enable_ambulance, *enable_blank_plate, *enable_stop_sign, - *enable_tracking_limits,*ptz_pan_left_limit,*ptz_pan_right_limit,*ptz_tilt_up_limit,*ptz_tilt_down_limit,*ptz_speed, - *cJSON_enable_only_show_metadata1, - *count_zone, *ivs_mode, *detection_zone, *detect, *ptz_tracking_mode, - *levenshtein_distance, *min_characters, *max_characters, *obj_min_proportion, *obj_max_proportion, *confidence, *confidence2, *confidence3, *confidence4, *enable_traffic_light, *detection_time, *metadata1, *metadata2, *metadata_stop, *link_to_counter, - *enable_direction1, *enable_direction2, *direction1, *direction2, *no_parking_time,*no_parking_time_in_minute, *queuing_count, *trigger_events[MAX_DETECTION_ZONE], *checked, *detect_event_id, *detect_event_name, *counter_increment, *post_event_name, - *point_number, *x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4, *x5 = NULL, *y5, *x6 = NULL, *y6, - *ptz_zone_to_preset = NULL, - *enable_speed, *set_distance, *world_distance_unit, *world_distance_side1, *world_distance_side2, *world_time_unit,*enable_radar_speed, *enable_ivs_zone,*parking_space, *parking_line, - *enable_show_unknown_object, *enable_ivs_fix_mode, *enable_ivs_and_ai,*enable_lpr_upon_triggered, *dwell_lpr_upon_triggered, *unknown_object_max_proportion, *unknown_object_min_proportion, *confidence_unknown_object, *confidence2_unknown_object, *dwell_unknown_object,*dwell_minute_focus_on, *person_obj_fov,*getnetwork_buffer_id, - *plate_filter_times, *plate_filter_time, *plate_free_time, *obj_max_proportion_in_zone, *obj_min_proportion_in_zone, *red_light_zone, *no_give_way_zone_to_protect, *no_give_way_zone_to_keep_away, *no_give_way_zone_to_protect_2, *no_give_way_zone_to_keep_away_2; - - //root = cJSON_Parse(fileBuf); - view_setting = cJSON_GetObjectItem(root, "view_setting"); - - //printf("111-7 get password = %s \n", accountData[0].account_password); - - for (int n = 0; n < MAX_AI_ENGINE_VIEW; n++) - { - char CameraID[20] = { 0 }; - sprintf(CameraID, "camera%02d", n + 1); - camera = cJSON_GetObjectItem(view_setting, CameraID); - - /*cam_ip = cJSON_GetObjectItem(camera, "ip"); - http_port = cJSON_GetObjectItem(camera, "http_port"); - video_port = cJSON_GetObjectItem(camera, "video_port"); - cam_username = cJSON_GetObjectItem(camera, "username"); - cam_pwd = cJSON_GetObjectItem(camera, "password"); - channel_id = cJSON_GetObjectItem(camera, "channel_id");*/ - camera_name = cJSON_GetObjectItem(camera, "camera_name"); - levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); - min_characters = cJSON_GetObjectItem(camera, "min_characters"); - max_characters = cJSON_GetObjectItem(camera, "max_characters"); - obj_min_proportion = cJSON_GetObjectItem(camera, "obj_min_proportion"); - obj_max_proportion = cJSON_GetObjectItem(camera, "obj_max_proportion"); - - plate_filter_times = cJSON_GetObjectItem(camera, "PlateFilterTimes"); - plate_filter_time = cJSON_GetObjectItem(camera, "PlateFilterTime"); - plate_free_time = cJSON_GetObjectItem(camera, "PlateRecorderFreeTime"); - - confidence = cJSON_GetObjectItem(camera, "confidence"); //Plate 車牌 - confidence2 = cJSON_GetObjectItem(camera, "confidence2"); //Traffic 交通 - confidence3 = cJSON_GetObjectItem(camera, "confidence3"); - confidence4 = cJSON_GetObjectItem(camera, "confidence4"); - count_zone = cJSON_GetObjectItem(camera, "count_zone"); - strcpy(viewChannelData[n].camera_name, camera_name->valuestring); - strcpy(viewChannelData[n].levenshtein_distance, levenshtein_distance->valuestring); - strcpy(viewChannelData[n].min_characters, min_characters->valuestring); - strcpy(viewChannelData[n].max_characters, max_characters->valuestring); - strcpy(viewChannelData[n].obj_min_proportion, obj_min_proportion->valuestring); - strcpy(viewChannelData[n].obj_max_proportion, obj_max_proportion->valuestring); - - if (plate_filter_times) - viewChannelData[n].i_plate_filter_times = atoi(plate_filter_times->valuestring); - else { - viewChannelData[n].i_plate_filter_times = 4; - new_data_write_to_config_file_flag = 1; - } - - if (plate_filter_time) - viewChannelData[n].i_plate_filter_time = atoi(plate_filter_time->valuestring); - else { - viewChannelData[n].i_plate_filter_time = 3; - new_data_write_to_config_file_flag = 1; - } - - if (plate_free_time) - viewChannelData[n].i_plate_free_time = atoi(plate_free_time->valuestring); - else { - viewChannelData[n].i_plate_free_time = 3; - new_data_write_to_config_file_flag = 1; - } - - strcpy(viewChannelData[n].confidence, confidence->valuestring); - strcpy(viewChannelData[n].confidence2, confidence2->valuestring); - strcpy(viewChannelData[n].confidence3, confidence3->valuestring); - strcpy(viewChannelData[n].confidence4, confidence4->valuestring); - - if (count_zone) - viewChannelData[n].count_zone = count_zone->valueint; - else { - viewChannelData[n].count_zone = 1; - new_data_write_to_config_file_flag = 1; - } - //printf("\nenable_lpr_db-----8\n"); - pthread_mutex_lock(&mutex_enable_lpr_db); - enable_lpr_db = cJSON_GetObjectItem(camera, "enable_lpr_db"); - if (enable_lpr_db) - strcpy(viewChannelData[n].enable_lpr_db, enable_lpr_db->valuestring); - else { - strcpy(viewChannelData[n].enable_lpr_db, "Yes"); - new_data_write_to_config_file_flag = 1; - } - pthread_mutex_unlock(&mutex_enable_lpr_db); - - enable_downsized_cropped_roi = cJSON_GetObjectItem(camera, "enable_downsized_cropped_roi"); - if (enable_downsized_cropped_roi) { - set_enable_downsized_cropped_roi(enable_downsized_cropped_roi->valueint); - } - else { - set_enable_downsized_cropped_roi(1); - new_data_write_to_config_file_flag = 1; - } - - enable_zone_crop_1 = cJSON_GetObjectItem(camera, "enable_zone_crop_1"); - if (enable_zone_crop_1) { - set_enable_zone_crop_1(enable_zone_crop_1->valueint); - } - else { - set_enable_zone_crop_1(0); - new_data_write_to_config_file_flag = 1; - } - - enable_add_face_frequent_list = cJSON_GetObjectItem(camera, "enable_add_face_frequent_list"); - if (enable_add_face_frequent_list) - if (strcmp(enable_add_face_frequent_list->valuestring, "Yes") == 0) - viewChannelData[n].enable_add_face_frequent_list = 1; - else - viewChannelData[n].enable_add_face_frequent_list = 0; - else { - viewChannelData[n].enable_add_face_frequent_list = 1; - new_data_write_to_config_file_flag = 1; - } - enable_PTZ = cJSON_GetObjectItem(camera, "enable_PTZ"); - if (enable_PTZ) - strcpy(viewChannelData[n].enable_PTZ, enable_PTZ->valuestring); - else { - strcpy(viewChannelData[n].enable_PTZ, "No"); - new_data_write_to_config_file_flag = 1; - } - - enable_track = cJSON_GetObjectItem(camera, "enable_track"); - if (enable_track) - strcpy(viewChannelData[n].enable_track, enable_track->valuestring); - else { - strcpy(viewChannelData[n].enable_track, "No"); - new_data_write_to_config_file_flag = 1; - } - - ptz_tracking_fov_min = cJSON_GetObjectItem(camera, "ptz_tracking_fov_min"); - if (ptz_tracking_fov_min) - strcpy(viewChannelData[n].ptz_tracking_fov_min, ptz_tracking_fov_min->valuestring); - else { - strcpy(viewChannelData[n].ptz_tracking_fov_min, "0"); - new_data_write_to_config_file_flag = 1; - } - - ptz_tracking_fov_max = cJSON_GetObjectItem(camera, "ptz_tracking_fov_max"); - if (ptz_tracking_fov_max) - strcpy(viewChannelData[n].ptz_tracking_fov_max, ptz_tracking_fov_max->valuestring); - else { - strcpy(viewChannelData[n].ptz_tracking_fov_max, "40"); - new_data_write_to_config_file_flag = 1; - } - - ptz_enable_tracking = cJSON_GetObjectItem(camera, "ptz_enable_tracking"); - if (ptz_enable_tracking) - strcpy(viewChannelData[n].ptz_enable_tracking, ptz_enable_tracking->valuestring); - else { - strcpy(viewChannelData[n].ptz_enable_tracking, "Yes"); - new_data_write_to_config_file_flag = 1; - } - - //Tracking MODE - //1: First in First out - //2: Bigger first - //3: All - ptz_tracking_mode = cJSON_GetObjectItem(camera, "ptz_tracking_mode"); - if (ptz_tracking_mode) - viewChannelData[n].ptz_tracking_mode = atoi(ptz_tracking_mode->valuestring); - else - { - viewChannelData[n].ptz_tracking_mode = 1; - new_data_write_to_config_file_flag = 1; - } - - ptz_tracking_by_enter_zone = cJSON_GetObjectItem(camera, "ptz_tracking_by_enter_zone"); - if (ptz_tracking_by_enter_zone) { - if (strcmp(ptz_tracking_by_enter_zone->valuestring, "Yes") == 0) - viewChannelData[n].ptz_tracking_by_enter_zone = 1; - else - viewChannelData[n].ptz_tracking_by_enter_zone = 0; - } - else { - viewChannelData[n].ptz_tracking_by_enter_zone = 1; - new_data_write_to_config_file_flag = 1; - } - - enable_tracking_limits = cJSON_GetObjectItem(camera, "enable_tracking_limits"); - if (enable_tracking_limits) - strcpy(viewChannelData[n].enable_tracking_limits, enable_tracking_limits->valuestring); - else { - strcpy(viewChannelData[n].enable_tracking_limits, "No"); - new_data_write_to_config_file_flag = 1; - } - - ptz_pan_left_limit = cJSON_GetObjectItem(camera, "ptz_pan_left_limit"); - if (ptz_pan_left_limit) - strcpy(viewChannelData[n].ptz_pan_left_limit, ptz_pan_left_limit->valuestring); - else { - strcpy(viewChannelData[n].ptz_pan_left_limit, "0"); - new_data_write_to_config_file_flag = 1; - } - - ptz_pan_right_limit = cJSON_GetObjectItem(camera, "ptz_pan_right_limit"); - if (ptz_pan_right_limit) - strcpy(viewChannelData[n].ptz_pan_right_limit, ptz_pan_right_limit->valuestring); - else { - strcpy(viewChannelData[n].ptz_pan_right_limit, "360"); - new_data_write_to_config_file_flag = 1; - } - - ptz_tilt_up_limit = cJSON_GetObjectItem(camera, "ptz_tilt_up_limit"); - if (ptz_tilt_up_limit) - strcpy(viewChannelData[n].ptz_tilt_up_limit, ptz_tilt_up_limit->valuestring); - else { - strcpy(viewChannelData[n].ptz_tilt_up_limit, "0"); - new_data_write_to_config_file_flag = 1; - } - - ptz_tilt_down_limit = cJSON_GetObjectItem(camera, "ptz_tilt_down_limit"); - if (ptz_tilt_down_limit) - strcpy(viewChannelData[n].ptz_tilt_down_limit, ptz_tilt_down_limit->valuestring); - else { - strcpy(viewChannelData[n].ptz_tilt_down_limit, "210"); - new_data_write_to_config_file_flag = 1; - } - - ptz_speed = cJSON_GetObjectItem(camera, "ptz_speed"); - if (ptz_speed) - strcpy(viewChannelData[n].ptz_speed, ptz_speed->valuestring); - else { - strcpy(viewChannelData[n].ptz_speed, "3"); - new_data_write_to_config_file_flag = 1; - } - - enable_unknown_object = cJSON_GetObjectItem(camera, "enable_unknown_object"); - if (enable_unknown_object) - strcpy(viewChannelData[n].enable_unknown_object, enable_unknown_object->valuestring); - else { - strcpy(viewChannelData[n].enable_unknown_object, "No"); - new_data_write_to_config_file_flag = 1; - } - - enable_ivs_person_detection = cJSON_GetObjectItem(camera, "enable_ivs_person_detection"); - if (enable_ivs_person_detection) - strcpy(viewChannelData[n].enable_ivs_person_detection, enable_ivs_person_detection->valuestring); - else { - strcpy(viewChannelData[n].enable_ivs_person_detection, "No"); - new_data_write_to_config_file_flag = 1; - } - - assign_ivs_object_to = cJSON_GetObjectItem(camera, "assign_ivs_object_to"); - if (assign_ivs_object_to) - strcpy(viewChannelData[n].assign_ivs_object_to, assign_ivs_object_to->valuestring); - else { - strcpy(viewChannelData[n].assign_ivs_object_to, ""); - new_data_write_to_config_file_flag = 1; - } - - enable_ambulance = cJSON_GetObjectItem(camera, "enable_ambulance"); - if (enable_ambulance) - strcpy(viewChannelData[n].enable_ambulance, enable_ambulance->valuestring); - else { - strcpy(viewChannelData[n].enable_ambulance, "No"); - new_data_write_to_config_file_flag = 1; - } - - enable_blank_plate = cJSON_GetObjectItem(camera, "enable_blank_plate"); - if (enable_blank_plate) - strcpy(viewChannelData[n].enable_blank_plate, enable_blank_plate->valuestring); - else { - strcpy(viewChannelData[n].enable_blank_plate, "No"); - new_data_write_to_config_file_flag = 1; - } - - enable_stop_sign = cJSON_GetObjectItem(camera, "enable_stop_sign"); - if (enable_stop_sign) - strcpy(viewChannelData[n].enable_stop_sign, enable_stop_sign->valuestring); - else { - strcpy(viewChannelData[n].enable_stop_sign, "No"); - new_data_write_to_config_file_flag = 1; - } - - enable_show_unknown_object = cJSON_GetObjectItem(camera, "enable_show_unknown_object"); - if (enable_show_unknown_object) - strcpy(viewChannelData[n].enable_show_unknown_object, enable_show_unknown_object->valuestring); - else { - strcpy(viewChannelData[n].enable_show_unknown_object, "No"); - new_data_write_to_config_file_flag = 1; - } - - enable_ivs_fix_mode = cJSON_GetObjectItem(camera, "enable_ivs_fix_mode"); - if (enable_ivs_fix_mode) - strcpy(viewChannelData[n].enable_ivs_fix_mode, enable_ivs_fix_mode->valuestring); - else { - strcpy(viewChannelData[n].enable_ivs_fix_mode, "No"); - new_data_write_to_config_file_flag = 1; - } - - enable_ivs_and_ai = cJSON_GetObjectItem(camera, "enable_ivs_and_ai"); - if (enable_ivs_and_ai) - strcpy(viewChannelData[n].enable_ivs_and_ai, enable_ivs_and_ai->valuestring); - else { - strcpy(viewChannelData[n].enable_ivs_and_ai, "No"); - new_data_write_to_config_file_flag = 1; - } - - enable_lpr_upon_triggered = cJSON_GetObjectItem(camera, "enable_lpr_upon_triggered"); - if (enable_lpr_upon_triggered) - strcpy(viewChannelData[n].enable_lpr_upon_triggered, enable_lpr_upon_triggered->valuestring); - else { - strcpy(viewChannelData[n].enable_lpr_upon_triggered, "No"); - new_data_write_to_config_file_flag = 1; - } - - dwell_lpr_upon_triggered = cJSON_GetObjectItem(camera, "dwell_lpr_upon_triggered"); - if (dwell_lpr_upon_triggered) - strcpy(viewChannelData[n].dwell_lpr_upon_triggered, dwell_lpr_upon_triggered->valuestring); - else { - strcpy(viewChannelData[n].dwell_lpr_upon_triggered, "10"); - new_data_write_to_config_file_flag = 1; - } - - ivs_mode = cJSON_GetObjectItem(detect, "ivs_mode"); - if (ivs_mode) - strcpy(viewChannelData[n].ivs_mode, ivs_mode->valuestring); - else { - strcpy(viewChannelData[n].ivs_mode, "3"); - new_data_write_to_config_file_flag = 1; - } - - unknown_object_max_proportion = cJSON_GetObjectItem(camera, "unknown_object_max_proportion"); - if (unknown_object_max_proportion) - strcpy(viewChannelData[n].unknown_object_max_proportion, unknown_object_max_proportion->valuestring); - else { - strcpy(viewChannelData[n].unknown_object_max_proportion, "20"); - new_data_write_to_config_file_flag = 1; - } - - unknown_object_min_proportion = cJSON_GetObjectItem(camera, "unknown_object_min_proportion"); - if (unknown_object_min_proportion) - strcpy(viewChannelData[n].unknown_object_min_proportion, unknown_object_min_proportion->valuestring); - else { - strcpy(viewChannelData[n].unknown_object_min_proportion, "0"); - new_data_write_to_config_file_flag = 1; - } - - confidence_unknown_object = cJSON_GetObjectItem(camera, "confidence_unknown_object"); - if (confidence_unknown_object) - strcpy(viewChannelData[n].confidence_unknown_object, confidence_unknown_object->valuestring); - else { - strcpy(viewChannelData[n].confidence_unknown_object, "0"); - new_data_write_to_config_file_flag = 1; - } - - confidence2_unknown_object = cJSON_GetObjectItem(camera, "confidence2_unknown_object"); - if (confidence2_unknown_object) - strcpy(viewChannelData[n].confidence2_unknown_object, confidence2_unknown_object->valuestring); - else { - strcpy(viewChannelData[n].confidence2_unknown_object, "0"); - new_data_write_to_config_file_flag = 1; - } - - dwell_unknown_object = cJSON_GetObjectItem(camera, "dwell_unknown_object"); - if (dwell_unknown_object) - strcpy(viewChannelData[n].dwell_unknown_object, dwell_unknown_object->valuestring); - else { - strcpy(viewChannelData[n].dwell_unknown_object, "30"); - new_data_write_to_config_file_flag = 1; - } - - dwell_minute_focus_on = cJSON_GetObjectItem(camera, "dwell_minute_focus_on"); - if (dwell_minute_focus_on) - strcpy(viewChannelData[n].dwell_minute_focus_on, dwell_minute_focus_on->valuestring); - else { - strcpy(viewChannelData[n].dwell_minute_focus_on, "5"); - new_data_write_to_config_file_flag = 1; - } - - person_obj_fov = cJSON_GetObjectItem(camera, "person_obj_fov"); - if (person_obj_fov) - strcpy(viewChannelData[n].person_obj_fov, person_obj_fov->valuestring); - else { - strcpy(viewChannelData[n].person_obj_fov, "100"); - new_data_write_to_config_file_flag = 1; - } - - getnetwork_buffer_id = cJSON_GetObjectItem(camera, "getnetwork_buffer_id"); - if (getnetwork_buffer_id) - strcpy(viewChannelData[n].getnetwork_buffer_id, getnetwork_buffer_id->valuestring); - else { - strcpy(viewChannelData[n].getnetwork_buffer_id, "1"); - new_data_write_to_config_file_flag = 1; - } - - red_light_zone = cJSON_GetObjectItem(camera, "red_light_zone"); - if (red_light_zone) - strcpy(viewChannelData[n].red_light_zone, red_light_zone->valuestring); - else { - strcpy(viewChannelData[n].red_light_zone, ""); - new_data_write_to_config_file_flag = 1; - } - - no_give_way_zone_to_protect = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect"); - if (no_give_way_zone_to_protect) - strcpy(viewChannelData[n].no_give_way_zone_to_protect, no_give_way_zone_to_protect->valuestring); - else { - strcpy(viewChannelData[n].no_give_way_zone_to_protect, ""); - new_data_write_to_config_file_flag = 1; - } - - no_give_way_zone_to_keep_away = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away"); - if (no_give_way_zone_to_keep_away) - strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, no_give_way_zone_to_keep_away->valuestring); - else { - strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, ""); - new_data_write_to_config_file_flag = 1; - } - - - no_give_way_zone_to_protect_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect_2"); - if (no_give_way_zone_to_protect_2) - strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, no_give_way_zone_to_protect_2->valuestring); - else { - strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, ""); - new_data_write_to_config_file_flag = 1; - } - - no_give_way_zone_to_keep_away_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away_2"); - if (no_give_way_zone_to_keep_away_2) - strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, no_give_way_zone_to_keep_away_2->valuestring); - else { - strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, ""); - new_data_write_to_config_file_flag = 1; - } - - ptz_sensitivity = cJSON_GetObjectItem(camera, "ptz_sensitivity"); - if (ptz_sensitivity) - viewChannelData[n].ptz_sensitivity = atoi(ptz_sensitivity->valuestring); - else - { - viewChannelData[n].ptz_sensitivity = 6; - new_data_write_to_config_file_flag = 1; - } - - ptz_tracking_resume_dwell = cJSON_GetObjectItem(camera, "ptz_tracking_resume_dwell"); - if (ptz_tracking_resume_dwell) - strcpy(viewChannelData[n].ptz_tracking_resume_dwell, ptz_tracking_resume_dwell->valuestring); - else { - strcpy(viewChannelData[n].ptz_tracking_resume_dwell, "3"); - new_data_write_to_config_file_flag = 1; - } - - cJSON_enable_only_show_metadata1 = cJSON_GetObjectItem(camera, "enable_only_show_metadata1"); - if (cJSON_enable_only_show_metadata1) - enable_only_show_metadata1 = cJSON_enable_only_show_metadata1->valueint; - else { - enable_only_show_metadata1 = 0; - new_data_write_to_config_file_flag = 1; - } - - tab_view_size = cJSON_GetObjectItem(camera, "tab_view_size"); - //printf("\n[run_server]tab_view_size: %s\n", tab_view_size->valuestring); - char outArray[2][STRSPLIT_SIZE]={0}; - char temp_tab[50] = { 0 }; - strcpy(temp_tab, tab_view_size->valuestring); - StrSplit(temp_tab, outArray, "x"); - //printf("\n------UU:16\n"); - viewChannelData[n].channel_idx = n; - if (outArray[0]) - viewChannelData[n].tab_view_width = atoi(outArray[0]); - else - new_data_write_to_config_file_flag = 1; - if (outArray[1]) - viewChannelData[n].tab_view_height = atoi(outArray[1]); - else - new_data_write_to_config_file_flag = 1; - - enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); - if (strcmp(enable_anpr->valuestring, "Yes") == 0) - viewChannelData[n].enable_anpr = 1; - else - viewChannelData[n].enable_anpr = 0; - - - enable_face = cJSON_GetObjectItem(camera, "enable_face"); - if (enable_face) { - if (strcmp(enable_face->valuestring, "Yes") == 0) - viewChannelData[n].enable_face = 1; - else - viewChannelData[n].enable_face = 0; - } - else { - new_data_write_to_config_file_flag = 1; - viewChannelData[n].enable_face = 1; - } - - enable_traffic = cJSON_GetObjectItem(camera, "enable_traffic"); - if (strcmp(enable_traffic->valuestring, "Yes") == 0) - viewChannelData[n].enable_traffic = 1; - else - viewChannelData[n].enable_traffic = 0; - - enable_logo = cJSON_GetObjectItem(camera, "enable_logo"); - if (strcmp(enable_logo->valuestring, "Yes") == 0) - viewChannelData[n].enable_logo = 1; - else - viewChannelData[n].enable_logo = 0; - - detection_zone = cJSON_GetObjectItem(camera, "detection_zone"); - - viewChannelData[n].enable_traffic_light_zone = 0; - - int i = 0; - - cJSON_ArrayForEach(detect, detection_zone) - { - enable_traffic_light = cJSON_GetObjectItem(detect, "enable_traffic_light"); - - detection_time = cJSON_GetObjectItem(detect, "detection_time"); - metadata1 = cJSON_GetObjectItem(detect, "metadata1"); - metadata2 = cJSON_GetObjectItem(detect, "metadata2"); - metadata_stop = cJSON_GetObjectItem(detect, "metadata_stop"); - link_to_counter = cJSON_GetObjectItem(detect, "link_to_counter"); - enable_direction1 = cJSON_GetObjectItem(detect, "enable_direction1"); - enable_direction2 = cJSON_GetObjectItem(detect, "enable_direction2"); - direction1 = cJSON_GetObjectItem(detect, "direction1"); - direction2 = cJSON_GetObjectItem(detect, "direction2"); - no_parking_time = cJSON_GetObjectItem(detect, "no_parking_time"); - no_parking_time_in_minute = cJSON_GetObjectItem(detect, "no_parking_time_in_minute"); - queuing_count = cJSON_GetObjectItem(detect, "queuing_count"); - ptz_zone_to_preset = cJSON_GetObjectItem(detect, "ptz_zone_to_preset"); - obj_max_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_max_proportion_in_zone"); - obj_min_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_min_proportion_in_zone"); - - enable_speed = cJSON_GetObjectItem(detect, "enable_speed"); - enable_radar_speed = cJSON_GetObjectItem(detect, "enable_radar_speed"); - enable_ivs_zone = cJSON_GetObjectItem(detect, "enable_ivs_zone"); - parking_space = cJSON_GetObjectItem(detect, "parking_space"); - parking_line = cJSON_GetObjectItem(detect, "parking_line"); - set_distance = cJSON_GetObjectItem(detect, "set_distance"); - world_distance_unit = cJSON_GetObjectItem(detect, "world_distance_unit"); - world_distance_side1 = cJSON_GetObjectItem(detect, "world_distance_side1"); - world_distance_side2 = cJSON_GetObjectItem(detect, "world_distance_side2"); - world_time_unit = cJSON_GetObjectItem(detect, "world_time_unit"); - - if (obj_max_proportion_in_zone) - strcpy(viewDetectionZone[n][i].obj_max_proportion_in_zone, obj_max_proportion_in_zone->valuestring); - else { - strcpy(viewDetectionZone[n][i].obj_max_proportion_in_zone, "80"); - new_data_write_to_config_file_flag = 1; - } - - if (obj_min_proportion_in_zone) - strcpy(viewDetectionZone[n][i].obj_min_proportion_in_zone, obj_min_proportion_in_zone->valuestring); - else { - strcpy(viewDetectionZone[n][i].obj_min_proportion_in_zone, "0"); - new_data_write_to_config_file_flag = 1; - } - - if (ptz_zone_to_preset) - strcpy(viewDetectionZone[n][i].ptz_zone_to_preset, ptz_zone_to_preset->valuestring); - else { - strcpy(viewDetectionZone[n][i].ptz_zone_to_preset, "0"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_speed) - strcpy(viewDetectionZone[n][i].enable_speed, enable_speed->valuestring); - else { - strcpy(viewDetectionZone[n][i].enable_speed, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_radar_speed) - strcpy(viewDetectionZone[n][i].enable_radar_speed, enable_radar_speed->valuestring); - else { - strcpy(viewDetectionZone[n][i].enable_radar_speed, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_ivs_zone) - strcpy(viewDetectionZone[n][i].enable_ivs_zone, enable_ivs_zone->valuestring); - else { - strcpy(viewDetectionZone[n][i].enable_ivs_zone, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (parking_space) { - viewDetectionZone[n][i].parking_space = atoi(parking_space->valuestring); - } - else { - viewDetectionZone[n][i].parking_space = 0; - new_data_write_to_config_file_flag = 1; - } - - if (parking_line) { - viewDetectionZone[n][i].parking_line = atoi(parking_line->valuestring); - } - else { - viewDetectionZone[n][i].parking_line = 0; - new_data_write_to_config_file_flag = 1; - } - - if (set_distance) { - viewDetectionZone[n][i].set_distance = atof(set_distance->valuestring); - } - else { - viewDetectionZone[n][i].set_distance = 10; - new_data_write_to_config_file_flag = 1; - } - - if (world_distance_unit) - strcpy(viewDetectionZone[n][i].world_distance_unit, world_distance_unit->valuestring); - else { - strcpy(viewDetectionZone[n][i].world_distance_unit, "meter"); - new_data_write_to_config_file_flag = 1; - } - - if (world_distance_side1) - { - viewDetectionZone[n][i].world_distance_side1 = atof(world_distance_side1->valuestring); - viewDetectionZone[n][i].world_distance[0] = atof(world_distance_side1->valuestring); - viewDetectionZone[n][i].world_distance[2] = atof(world_distance_side1->valuestring); - } - else { - viewDetectionZone[n][i].world_distance_side1 = 10; - viewDetectionZone[n][i].world_distance[0] = viewDetectionZone[n][i].world_distance_side1; - viewDetectionZone[n][i].world_distance[2] = viewDetectionZone[n][i].world_distance_side1; - - new_data_write_to_config_file_flag = 1; - } - //printf("[%d]World dis 1 = %f \n", i, viewDetectionZone[n][i].world_distance_side1); - - if (world_distance_side2) - { - viewDetectionZone[n][i].world_distance_side2 = atof(world_distance_side2->valuestring); - viewDetectionZone[n][i].world_distance[1] = atof(world_distance_side2->valuestring); - viewDetectionZone[n][i].world_distance[3] = atof(world_distance_side2->valuestring); - } - else { - viewDetectionZone[n][i].world_distance_side2 = 10; - viewDetectionZone[n][i].world_distance[1] = viewDetectionZone[n][i].world_distance_side2; - viewDetectionZone[n][i].world_distance[3] = viewDetectionZone[n][i].world_distance_side2; - new_data_write_to_config_file_flag = 1; - } - //printf("[%d]World dis 2 = %f \n", i, viewDetectionZone[n][i].world_distance_side2); - - viewChannelData[n].speed_view_width_ratio = (float)(1920 / 889); - viewChannelData[n].speed_view_height_ratio = (float)(1080 / 500); - - if (world_time_unit) - strcpy(viewDetectionZone[n][i].world_time_unit, world_time_unit->valuestring); - else { - strcpy(viewDetectionZone[n][i].world_time_unit, "KPH"); - new_data_write_to_config_file_flag = 1; - } - - trigger_events[i] = cJSON_GetObjectItem(detect, "trigger_events"); - - point_number = cJSON_GetObjectItem(detect, "point_number"); - /* - if (point_number) - printf("load point number 2 = %d \n", point_number->valueint); - */ - x1 = cJSON_GetObjectItem(detect, "x1"); - y1 = cJSON_GetObjectItem(detect, "y1"); - x2 = cJSON_GetObjectItem(detect, "x2"); - y2 = cJSON_GetObjectItem(detect, "y2"); - x3 = cJSON_GetObjectItem(detect, "x3"); - y3 = cJSON_GetObjectItem(detect, "y3"); - x4 = cJSON_GetObjectItem(detect, "x4"); - y4 = cJSON_GetObjectItem(detect, "y4"); - x5 = cJSON_GetObjectItem(detect, "x5"); - y5 = cJSON_GetObjectItem(detect, "y5"); - x6 = cJSON_GetObjectItem(detect, "x6"); - y6 = cJSON_GetObjectItem(detect, "y6"); - - strcpy(viewDetectionZone[n][i].detection_time, detection_time->valuestring); - strcpy(viewDetectionZone[n][i].metadata1, metadata1->valuestring); - strcpy(viewDetectionZone[n][i].metadata2, metadata2->valuestring); - strcpy(viewDetectionZone[n][i].link_to_counter, link_to_counter->valuestring); - strcpy(viewDetectionZone[n][i].enable_direction1, enable_direction1->valuestring); - strcpy(viewDetectionZone[n][i].enable_direction2, enable_direction2->valuestring); - strcpy(viewDetectionZone[n][i].direction1, direction1->valuestring); - strcpy(viewDetectionZone[n][i].direction2, direction2->valuestring); - - if (metadata_stop) - strcpy(viewDetectionZone[n][i].metadata_stop, metadata_stop->valuestring); - else { - strcpy(viewDetectionZone[n][i].metadata_stop, ""); - new_data_write_to_config_file_flag = 1; - } - - if (no_parking_time) - viewDetectionZone[n][i].no_parking_time = atoi(no_parking_time->valuestring); - else { - viewDetectionZone[n][i].no_parking_time = 5; - new_data_write_to_config_file_flag = 1; - } - - if (no_parking_time_in_minute) - viewDetectionZone[n][i].no_parking_time_in_minute = atoi(no_parking_time_in_minute->valuestring); - else { - viewDetectionZone[n][i].no_parking_time_in_minute = 0; - new_data_write_to_config_file_flag = 1; - } - - if (queuing_count && strlen(queuing_count->valuestring) >= 1) - viewDetectionZone[n][i].queuing_count = atoi(queuing_count->valuestring); - else { - viewDetectionZone[n][i].queuing_count = 1; - new_data_write_to_config_file_flag = 1; - } - - if (point_number) - viewDetectionZone[n][i].point_num = point_number->valueint; - else { - viewDetectionZone[n][i].point_num = 6; - new_data_write_to_config_file_flag = 1; - } - viewDetectionZone[n][i].Points[0].x = x1->valueint; - viewDetectionZone[n][i].Points[0].y = y1->valueint; - viewDetectionZone[n][i].Points[1].x = x2->valueint; - viewDetectionZone[n][i].Points[1].y = y2->valueint; - viewDetectionZone[n][i].Points[2].x = x3->valueint; - viewDetectionZone[n][i].Points[2].y = y3->valueint; - viewDetectionZone[n][i].Points[3].x = x4->valueint; - viewDetectionZone[n][i].Points[3].y = y4->valueint; - - viewDetectionZone[n][i].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)x1->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)y1->valueint, CANVAS_HEIGHT / 2); - viewDetectionZone[n][i].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)x2->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)y2->valueint, CANVAS_HEIGHT / 2); - viewDetectionZone[n][i].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)x3->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)y3->valueint, CANVAS_HEIGHT / 2); - viewDetectionZone[n][i].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)x4->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)y4->valueint, CANVAS_HEIGHT / 2); - - if (x5 && x6) - { - viewDetectionZone[n][i].Points[4].x = x5->valueint; - viewDetectionZone[n][i].Points[4].y = y5->valueint; - viewDetectionZone[n][i].Points[5].x = x6->valueint; - viewDetectionZone[n][i].Points[5].y = y6->valueint; - - viewDetectionZone[n][i].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)x5->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)y5->valueint, CANVAS_HEIGHT / 2); - viewDetectionZone[n][i].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)x6->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)y6->valueint, CANVAS_HEIGHT / 2); - } - else - new_data_write_to_config_file_flag = 1; - - strcpy(viewDetectionZone[n][i].enable_traffic_light, enable_traffic_light->valuestring); - if (strncmp(viewDetectionZone[n][i].enable_traffic_light, "Yes", strlen("Yes")) == 0) - { - viewChannelData[n].enable_traffic_light_zone = i + 1; - //UpdateTrafficLightZone(n); - } - -#ifdef GY_OS_AMBA - if (strncmp(viewDetectionZone[n][i].enable_speed, "Yes", strlen("Yes")) == 0) - { - int social_zone_idx = i; - if (social_zone_idx >= 0) - { - pthread_mutex_lock(&mutex_perspective_transform); - if (viewDetectionZone[n][i].PerspectiveTransformArray != NULL) - cvReleaseMat(&viewDetectionZone[n][i].PerspectiveTransformArray); - viewDetectionZone[n][i].PerspectiveTransformArray = GetPerspectiveTransformArray(n, social_zone_idx); - pthread_mutex_unlock(&mutex_perspective_transform); - } - } -#endif - - i++; - - if (i < MAX_DETECTION_ZONE) { - - } - else { - break; - } - } - - int original_zone_size = i; - - //int arraySize = cJSON_GetArraySize(detection_zone); - - int k = 0; - for (int j = 0; j < MAX_DETECTION_ZONE && j < original_zone_size; j++) - { - k = 0; - - cJSON_ArrayForEach(detect, trigger_events[j]) - { - checked = cJSON_GetObjectItem(detect, "checked"); - detect_event_id = cJSON_GetObjectItem(detect, "detect_event_id"); - detect_event_name = cJSON_GetObjectItem(detect, "detect_event_name"); - post_event_name = cJSON_GetObjectItem(detect, "post_event_name"); - counter_name = cJSON_GetObjectItem(detect, "counter_name"); - counter_increment = cJSON_GetObjectItem(detect, "counter_increment"); - - if (!detect_event_id || !detect_event_name || strlen(detect_event_id->valuestring) == 0 || strlen(detect_event_name->valuestring) == 0) { - new_data_write_to_config_file_flag = 1; - } - else { - viewDetectionZone[n][j].trigger_event[k].checked = checked->valueint; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, detect_event_id->valuestring); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, detect_event_name->valuestring); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, post_event_name->valuestring); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, counter_name->valuestring); - - if (counter_increment) { - if (strcmp(counter_increment->valuestring, "counter_increment_add") == 0) - viewDetectionZone[n][j].trigger_event[k].counter_increment = 1; - else if (strcmp(counter_increment->valuestring, "counter_increment_minus") == 0) - viewDetectionZone[n][j].trigger_event[k].counter_increment = -1; - else if (strcmp(counter_increment->valuestring, "counter_increment_equal") == 0) - viewDetectionZone[n][j].trigger_event[k].counter_increment = 0; - else - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - } - else - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - } - k++; - } - if (k < MAX_TRIGGER_EVENT) { - - if(k < 10) { - viewDetectionZone[n][j].trigger_event[k].checked = 0; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00800000"); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Visitor list"); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - - if (k < 11) { - viewDetectionZone[n][j].trigger_event[k].checked = 0; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x01000000"); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Unattended object or missing object"); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - - if (k < 12) { - viewDetectionZone[n][j].trigger_event[k].checked = 0; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x02000000"); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "BG learning"); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - - if (k < 13) { - viewDetectionZone[n][j].trigger_event[k].checked = 0; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x04000000"); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Tampering detection"); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - - if (k < 14) { - viewDetectionZone[n][j].trigger_event[k].checked = 0; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x40000000"); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "All objects detection"); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - - if (k < 15) { - viewDetectionZone[n][j].trigger_event[k].checked = 0; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x80000000"); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Lack of any object detection"); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - - if (k < 16) { - viewDetectionZone[n][j].trigger_event[k].checked = 0; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00002000"); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Over speed detection"); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - - if (k < 17) { - viewDetectionZone[n][j].trigger_event[k].checked = 0; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00004000"); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Lower speed detection"); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - - if (k < 18) { - viewDetectionZone[n][j].trigger_event[k].checked = 0; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00000400"); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Running red lights"); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - - if (k < 19) { - viewDetectionZone[n][j].trigger_event[k].checked = 0; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00000800"); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Turning left on red"); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - - if (k < 20) { - viewDetectionZone[n][j].trigger_event[k].checked = 0; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00001000"); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Turning right on red"); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - - if (k < 21) { - viewDetectionZone[n][j].trigger_event[k].checked = 0; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00008000"); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Forget to give way detection"); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - - if (k < 22) { - viewDetectionZone[n][j].trigger_event[k].checked = 0; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x00040000"); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Distance violation"); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - - if (k < 23) { - viewDetectionZone[n][j].trigger_event[k].checked = 0; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, "0x08000000"); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, "Height detection"); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, ""); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, ""); - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - - new_data_write_to_config_file_flag = 1; - } - } - - if (original_zone_size < MAX_DETECTION_ZONE) { - for (int index_zone = original_zone_size; index_zone < MAX_DETECTION_ZONE; index_zone++) { - strcpy(viewDetectionZone[n][index_zone].obj_max_proportion_in_zone, "80"); - strcpy(viewDetectionZone[n][index_zone].obj_min_proportion_in_zone, "0"); - strcpy(viewDetectionZone[n][index_zone].ptz_zone_to_preset, "0"); - strcpy(viewDetectionZone[n][index_zone].enable_speed, "No"); - strcpy(viewDetectionZone[n][index_zone].enable_radar_speed, "No"); - strcpy(viewDetectionZone[n][index_zone].enable_ivs_zone, "No"); - viewDetectionZone[n][index_zone].parking_space = 0; - viewDetectionZone[n][index_zone].parking_line = 0; - viewDetectionZone[n][index_zone].set_distance = 10; - strcpy(viewDetectionZone[n][index_zone].world_distance_unit, "meter"); - viewDetectionZone[n][index_zone].world_distance_side1 = 10; - viewDetectionZone[n][index_zone].world_distance[0] = viewDetectionZone[n][index_zone].world_distance_side1; - viewDetectionZone[n][index_zone].world_distance[2] = viewDetectionZone[n][index_zone].world_distance_side1; - viewDetectionZone[n][index_zone].world_distance_side2 = 10; - viewDetectionZone[n][index_zone].world_distance[1] = viewDetectionZone[n][index_zone].world_distance_side2; - viewDetectionZone[n][index_zone].world_distance[3] = viewDetectionZone[n][index_zone].world_distance_side2; - strcpy(viewDetectionZone[n][index_zone].world_time_unit, "KPH"); - strcpy(viewDetectionZone[n][index_zone].detection_time, ""); - strcpy(viewDetectionZone[n][index_zone].metadata1, ""); - strcpy(viewDetectionZone[n][index_zone].metadata2, ""); - strcpy(viewDetectionZone[n][index_zone].metadata_stop, ""); - strcpy(viewDetectionZone[n][index_zone].link_to_counter, ""); - strcpy(viewDetectionZone[n][index_zone].enable_direction1, "No"); - strcpy(viewDetectionZone[n][index_zone].enable_direction2, ""); - strcpy(viewDetectionZone[n][index_zone].direction1, "1"); - strcpy(viewDetectionZone[n][index_zone].direction2, ""); - viewDetectionZone[n][index_zone].no_parking_time = 5; - viewDetectionZone[n][index_zone].no_parking_time_in_minute = 0; - viewDetectionZone[n][index_zone].queuing_count = 1; - viewDetectionZone[n][index_zone].point_num = 6; - - viewDetectionZone[n][index_zone].Points[0].x = 19; - viewDetectionZone[n][index_zone].Points[0].y = 16; - viewDetectionZone[n][index_zone].Points[1].x = 19; - viewDetectionZone[n][index_zone].Points[1].y = 250; - viewDetectionZone[n][index_zone].Points[2].x = 19; - viewDetectionZone[n][index_zone].Points[2].y = 484; - viewDetectionZone[n][index_zone].Points[3].x = 870; - viewDetectionZone[n][index_zone].Points[3].y = 484; - viewDetectionZone[n][index_zone].Points[4].x = 870; - viewDetectionZone[n][index_zone].Points[4].y = 250; - viewDetectionZone[n][index_zone].Points[5].x = 870; - viewDetectionZone[n][index_zone].Points[5].y = 16; - - viewDetectionZone[n][index_zone].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[0].x, CANVAS_WIDTH / 2); - viewDetectionZone[n][index_zone].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[0].y, CANVAS_HEIGHT / 2); - viewDetectionZone[n][index_zone].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[1].x, CANVAS_WIDTH / 2); - viewDetectionZone[n][index_zone].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[1].y, CANVAS_HEIGHT / 2); - viewDetectionZone[n][index_zone].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[2].x, CANVAS_WIDTH / 2); - viewDetectionZone[n][index_zone].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[2].y, CANVAS_HEIGHT / 2); - viewDetectionZone[n][index_zone].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[3].x, CANVAS_WIDTH / 2); - viewDetectionZone[n][index_zone].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[3].y, CANVAS_HEIGHT / 2); - viewDetectionZone[n][index_zone].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[4].x, CANVAS_WIDTH / 2); - viewDetectionZone[n][index_zone].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[4].y, CANVAS_HEIGHT / 2); - viewDetectionZone[n][index_zone].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[5].x, CANVAS_WIDTH / 2); - viewDetectionZone[n][index_zone].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)viewDetectionZone[n][index_zone].Points[5].y, CANVAS_HEIGHT / 2); - - strcpy(viewDetectionZone[n][index_zone].enable_traffic_light, ""); - - for (int index_trigger = 0; index_trigger < MAX_TRIGGER_EVENT; index_trigger++) { - viewDetectionZone[n][index_zone].trigger_event[index_trigger].checked = 0; - strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].detect_event_id, viewDetectionZone[n][0].trigger_event[index_trigger].detect_event_id); - strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].detect_event_name, viewDetectionZone[n][0].trigger_event[index_trigger].detect_event_name); - strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].post_event_name, ""); - strcpy(viewDetectionZone[n][index_zone].trigger_event[index_trigger].counter_name, ""); - viewDetectionZone[n][index_zone].trigger_event[index_trigger].counter_increment = -2; - } - } - - new_data_write_to_config_file_flag = 1; - } - } - - //cJSON* cnn_device[MAX_LAYER_NUM]; - cJSON* system_setting/*, *load_cnn_type*/, *display_dash, *display_properties,*display_OSD/*, *enable_log*/, *overlap_thresh, *confidence_thresh,*nms_thres, *tracking_id_dwell, *enable_cloud, *enable_special_edition, *enable_python, *enable_python_file, *enable_low_cpu_usage, - *enable_person_independent,*enable_onvif_profile_m,*cloud_enable_snap,*cloud_enable_notification, *cloud_account, *cloud_password, *cloud_notification_dwell, *cloud_statue,*language, - *enable_bounding_box, *enable_dwell_bounding_box,*enable_special_char,*force_i_to_one, *force_o_to_zero, *enable_plate_angle_correction,*enable_ai_mirror, *ai_mirror_feature, *enable_post_only_if_both_detected,*enable_getalarmmotion_snap, *getimage_encoder_id, *getimage_encoder_id_HD, *osd_encoder_id, *osd_font_size, *osd_outline_lilin,*enable_osd_bottom,*osd_bottom_bg_tran,*osd_bottom_content, *enable_sync_external_lpr_db, *external_lpr_db_IP, *external_lpr_db_port, *external_lpr_db_username, *external_lpr_db_password, - *enable_email_notification,*enable_system_logs,*enable_email_jpeg,*email_reset_time_interval,*sensors_type, *enable_ftp, *ftp_url, *ftp_port, *ftp_username, *ftp_password, *ftp_remote_directory,*ftp_jpeg_file_name_format,*ftp_jpeg_file_name; - cJSON *enable_cloud_v2, *cloud_v2_notification_dwell, *cloud_v2_content, *enable_cloud_record_v2, *cloud_record_v2_notification_dwell, *cloud_record_v2_content,*cloud_v2_statue,*cloud_record_v2_statue; - - - system_setting = cJSON_GetObjectItem(root, "system_setting"); - //cJSON* api_version = cJSON_GetObjectItem(system_setting, "api version"); - //load_cnn_type = cJSON_GetObjectItem(system_setting, "cnn type"); - overlap_thresh = cJSON_GetObjectItem(system_setting, "overlap thresh"); - confidence_thresh = cJSON_GetObjectItem(system_setting, "confidence thresh"); - enable_person_independent = cJSON_GetObjectItem(system_setting, "enable_person_independent"); - enable_onvif_profile_m = cJSON_GetObjectItem(system_setting, "enable_onvif_profile_m"); - nms_thres = cJSON_GetObjectItem(system_setting, "nms_thres"); - tracking_id_dwell = cJSON_GetObjectItem(system_setting, "tracking_id_dwell"); - cloud_enable_snap = cJSON_GetObjectItem(system_setting, "cloud_enable_snap"); - enable_cloud = cJSON_GetObjectItem(system_setting, "enable_cloud"); - enable_special_edition = cJSON_GetObjectItem(system_setting, "enable_special_edition"); - enable_python = cJSON_GetObjectItem(system_setting, "enable_python"); - enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); - enable_low_cpu_usage = cJSON_GetObjectItem(system_setting, "enable_low_cpu_usage"); - cloud_enable_notification = cJSON_GetObjectItem(system_setting, "cloud_enable_notification"); - cloud_account = cJSON_GetObjectItem(system_setting, "cloud_account"); - cloud_password = cJSON_GetObjectItem(system_setting, "cloud_password"); - cloud_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_notification_dwell"); - cloud_statue = cJSON_GetObjectItem(system_setting, "cloud_statue"); - cloud_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_v2_statue"); - cloud_record_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_record_v2_statue"); - language = cJSON_GetObjectItem(system_setting, "language"); - enable_special_char = cJSON_GetObjectItem(system_setting, "enable_special_char"); - enable_bounding_box = cJSON_GetObjectItem(system_setting, "enable_bounding_box"); - enable_dwell_bounding_box = cJSON_GetObjectItem(system_setting, "enable_dwell_bounding_box"); - force_i_to_one = cJSON_GetObjectItem(system_setting, "force_i_to_one"); - force_o_to_zero = cJSON_GetObjectItem(system_setting, "force_o_to_zero"); - enable_plate_angle_correction = cJSON_GetObjectItem(system_setting, "enable_plate_angle_correction"); - enable_ai_mirror = cJSON_GetObjectItem(system_setting, "enable_ai_mirror"); - ai_mirror_feature = cJSON_GetObjectItem(system_setting, "ai_mirror_feature"); - - enable_cloud_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_v2"); - cloud_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_v2_notification_dwell"); - cloud_v2_content = cJSON_GetObjectItem(system_setting, "cloud_v2_content"); - enable_cloud_record_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_record_v2"); - cloud_record_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_record_v2_notification_dwell"); - cloud_record_v2_content = cJSON_GetObjectItem(system_setting, "cloud_record_v2_content"); - - enable_post_only_if_both_detected = cJSON_GetObjectItem(system_setting, "enable_post_only_if_both_detected"); - enable_getalarmmotion_snap = cJSON_GetObjectItem(system_setting, "enable_getalarmmotion_snap"); - getimage_encoder_id = cJSON_GetObjectItem(system_setting, "getimage_encoder_id"); - getimage_encoder_id_HD = cJSON_GetObjectItem(system_setting, "getimage_encoder_id_HD"); - osd_encoder_id = cJSON_GetObjectItem(system_setting, "osd_encoder_id"); - osd_font_size = cJSON_GetObjectItem(system_setting, "osd_font_size"); - osd_outline_lilin = cJSON_GetObjectItem(system_setting, "osd_outline_lilin"); - enable_osd_bottom = cJSON_GetObjectItem(system_setting, "enable_osd_bottom"); - osd_bottom_bg_tran = cJSON_GetObjectItem(system_setting, "osd_bottom_bg_tran"); - osd_bottom_content = cJSON_GetObjectItem(system_setting, "osd_bottom_content"); - sensors_type = cJSON_GetObjectItem(system_setting, "sensors_type"); - enable_sync_external_lpr_db = cJSON_GetObjectItem(system_setting, "enable_sync_external_lpr_db"); - external_lpr_db_IP = cJSON_GetObjectItem(system_setting, "external_lpr_db_IP"); - external_lpr_db_port = cJSON_GetObjectItem(system_setting, "external_lpr_db_port"); - external_lpr_db_username = cJSON_GetObjectItem(system_setting, "external_lpr_db_username"); - external_lpr_db_password = cJSON_GetObjectItem(system_setting, "external_lpr_db_password"); - enable_system_logs = cJSON_GetObjectItem(system_setting, "enable_system_logs"); - enable_email_jpeg = cJSON_GetObjectItem(system_setting, "enable_email_jpeg"); - email_reset_time_interval = cJSON_GetObjectItem(system_setting, "email_reset_time_interval"); - enable_email_notification = cJSON_GetObjectItem(system_setting, "enable_email_notification"); - - enable_ftp = cJSON_GetObjectItem(system_setting, "enable_ftp"); - ftp_url = cJSON_GetObjectItem(system_setting, "ftp_url"); - ftp_port = cJSON_GetObjectItem(system_setting, "ftp_port"); - ftp_username = cJSON_GetObjectItem(system_setting, "ftp_username"); - ftp_password = cJSON_GetObjectItem(system_setting, "ftp_password"); - ftp_remote_directory = cJSON_GetObjectItem(system_setting, "ftp_remote_directory"); - ftp_jpeg_file_name_format = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name_format"); - ftp_jpeg_file_name = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name"); - - if (enable_person_independent) - strcpy(SystemSetting.enable_person_independent, enable_person_independent->valuestring); - else { - strcpy(SystemSetting.enable_person_independent, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_onvif_profile_m) - strcpy(SystemSetting.enable_onvif_profile_m, enable_onvif_profile_m->valuestring); - else { - strcpy(SystemSetting.enable_onvif_profile_m, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (nms_thres) - strcpy(SystemSetting.nms_thres, nms_thres->valuestring); - else { - strcpy(SystemSetting.nms_thres, "10"); - new_data_write_to_config_file_flag = 1; - } - - if (tracking_id_dwell) - strcpy(SystemSetting.tracking_id_dwell, tracking_id_dwell->valuestring); - else { - strcpy(SystemSetting.tracking_id_dwell, "5"); - new_data_write_to_config_file_flag = 1; - } - - if (cloud_enable_snap) - strcpy(SystemSetting.cloud_enable_snap, cloud_enable_snap->valuestring); - else { - strcpy(SystemSetting.cloud_enable_snap, "Yes"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_cloud) - strcpy(SystemSetting.enable_cloud, enable_cloud->valuestring); - else { - strcpy(SystemSetting.enable_cloud, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_special_edition) - strcpy(SystemSetting.enable_special_edition, enable_special_edition->valuestring); - else { - strcpy(SystemSetting.enable_special_edition, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_python) - strcpy(SystemSetting.enable_python, enable_python->valuestring); - else { - strcpy(SystemSetting.enable_python, "No"); - new_data_write_to_config_file_flag = 1; - } - if (enable_python_file) - { - strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); - - if (pthread_create(&runpython_thread, NULL, start_run_python_thread, (void*)configPATH) != 0) { - perror("check current runpython thread failed\n"); - exit(EXIT_FAILURE); - } - } - else { - strcpy(SystemSetting.enable_python_file, "No python running."); - new_data_write_to_config_file_flag = 1; - } - if (enable_low_cpu_usage) - strcpy(SystemSetting.enable_low_cpu_usage, enable_low_cpu_usage->valuestring); - else { - strcpy(SystemSetting.enable_low_cpu_usage, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (cloud_enable_notification) - strcpy(SystemSetting.cloud_enable_notification, cloud_enable_notification->valuestring); - else { - strcpy(SystemSetting.cloud_enable_notification, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (cloud_account) - strcpy(SystemSetting.cloud_account, cloud_account->valuestring); - else { - strcpy(SystemSetting.cloud_account, "myaccount@mail.com"); - new_data_write_to_config_file_flag = 1; - } - - if (cloud_password) - strcpy(SystemSetting.cloud_password, cloud_password->valuestring); - else { - strcpy(SystemSetting.cloud_password, "mypass"); - new_data_write_to_config_file_flag = 1; - } - - if (cloud_notification_dwell) - strcpy(SystemSetting.cloud_notification_dwell, cloud_notification_dwell->valuestring); - else { - strcpy(SystemSetting.cloud_notification_dwell, "60"); - new_data_write_to_config_file_flag = 1; - } - - if (cloud_statue) - strcpy(SystemSetting.cloud_statue, cloud_statue->valuestring); - else { - strcpy(SystemSetting.cloud_statue, ""); - new_data_write_to_config_file_flag = 1; - } - - if (cloud_v2_statue) - strcpy(SystemSetting.cloud_v2_statue, cloud_v2_statue->valuestring); - else { - strcpy(SystemSetting.cloud_v2_statue, ""); - new_data_write_to_config_file_flag = 1; - } - - if (cloud_record_v2_statue) - strcpy(SystemSetting.cloud_record_v2_statue, cloud_record_v2_statue->valuestring); - else { - strcpy(SystemSetting.cloud_record_v2_statue, ""); - new_data_write_to_config_file_flag = 1; - } - - if (enable_special_char) - strcpy(SystemSetting.enable_special_char, enable_special_char->valuestring); - else - { - strcpy(SystemSetting.enable_special_char, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_bounding_box) - strcpy(SystemSetting.enable_bounding_box, enable_bounding_box->valuestring); - else - { - strcpy(SystemSetting.enable_bounding_box, "Yes"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_dwell_bounding_box) - strcpy(SystemSetting.enable_dwell_bounding_box, enable_dwell_bounding_box->valuestring); - else - { - strcpy(SystemSetting.enable_dwell_bounding_box, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (force_i_to_one) - strcpy(SystemSetting.force_i_to_one, force_i_to_one->valuestring); - else - { - strcpy(SystemSetting.force_i_to_one, "Yes"); - new_data_write_to_config_file_flag = 1; - } - - if (force_o_to_zero) - strcpy(SystemSetting.force_o_to_zero, force_o_to_zero->valuestring); - else - { - strcpy(SystemSetting.force_o_to_zero, "Yes"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_plate_angle_correction) - strcpy(SystemSetting.enable_plate_angle_correction, enable_plate_angle_correction->valuestring); - else - { - strcpy(SystemSetting.enable_plate_angle_correction, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_ai_mirror) - strcpy(SystemSetting.enable_ai_mirror, enable_ai_mirror->valuestring); - else - { - strcpy(SystemSetting.enable_ai_mirror, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (ai_mirror_feature) - strcpy(SystemSetting.ai_mirror_feature, ai_mirror_feature->valuestring); - else - { - strcpy(SystemSetting.ai_mirror_feature, "0"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_cloud_v2) - strcpy(SystemSetting.enable_cloud_v2, enable_cloud_v2->valuestring); - else - { - strcpy(SystemSetting.enable_cloud_v2, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (cloud_v2_notification_dwell) - strcpy(SystemSetting.cloud_v2_notification_dwell, cloud_v2_notification_dwell->valuestring); - else - { - strcpy(SystemSetting.cloud_v2_notification_dwell, "60"); - new_data_write_to_config_file_flag = 1; - } - - if (cloud_v2_content) - strcpy(SystemSetting.cloud_v2_content, cloud_v2_content->valuestring); - else - { - strcpy(SystemSetting.cloud_v2_content, "{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_cloud_record_v2) - strcpy(SystemSetting.enable_cloud_record_v2, enable_cloud_record_v2->valuestring); - else - { - strcpy(SystemSetting.enable_cloud_record_v2, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (cloud_record_v2_notification_dwell) - strcpy(SystemSetting.cloud_record_v2_notification_dwell, cloud_record_v2_notification_dwell->valuestring); - else - { - strcpy(SystemSetting.cloud_record_v2_notification_dwell, "60"); - new_data_write_to_config_file_flag = 1; - } - - if (cloud_record_v2_content) - strcpy(SystemSetting.cloud_record_v2_content, cloud_record_v2_content->valuestring); - else - { - strcpy(SystemSetting.cloud_record_v2_content, "{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_post_only_if_both_detected) - strcpy(SystemSetting.enable_post_only_if_both_detected, enable_post_only_if_both_detected->valuestring); - else - { - strcpy(SystemSetting.enable_post_only_if_both_detected, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_getalarmmotion_snap) - strcpy(SystemSetting.enable_getalarmmotion_snap, enable_getalarmmotion_snap->valuestring); - else - { - strcpy(SystemSetting.enable_getalarmmotion_snap, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (getimage_encoder_id) - strcpy(SystemSetting.getimage_encoder_id, getimage_encoder_id->valuestring); - else - { -#ifdef GY_OS_NOVA - strcpy(SystemSetting.getimage_encoder_id, "3"); -#endif - -#ifdef GY_OS_AMBA - strcpy(SystemSetting.getimage_encoder_id, "4"); -#endif - new_data_write_to_config_file_flag = 1; - } - - if (getimage_encoder_id_HD) - strcpy(SystemSetting.getimage_encoder_id_HD, getimage_encoder_id_HD->valuestring); - else - { -#ifdef GY_OS_NOVA - strcpy(SystemSetting.getimage_encoder_id_HD, "0"); -#endif -#ifdef GY_OS_AMBA - strcpy(SystemSetting.getimage_encoder_id_HD, "4"); -#endif - - new_data_write_to_config_file_flag = 1; - } - - if (osd_encoder_id) - strcpy(SystemSetting.osd_encoder_id, osd_encoder_id->valuestring); - else - { - strcpy(SystemSetting.osd_encoder_id, "2"); - new_data_write_to_config_file_flag = 1; - } - - if (osd_font_size) - strcpy(SystemSetting.osd_font_size, osd_font_size->valuestring); - else - { - strcpy(SystemSetting.osd_font_size, "26"); - new_data_write_to_config_file_flag = 1; - } - - if (osd_outline_lilin) - strcpy(SystemSetting.osd_outline_lilin, osd_outline_lilin->valuestring); - else - { - strcpy(SystemSetting.osd_outline_lilin, "4"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_osd_bottom) - strcpy(SystemSetting.enable_osd_bottom, enable_osd_bottom->valuestring); - else - { - strcpy(SystemSetting.enable_osd_bottom, "Yes"); - new_data_write_to_config_file_flag = 1; - } - - if (osd_bottom_bg_tran) - strcpy(SystemSetting.osd_bottom_bg_tran, osd_bottom_bg_tran->valuestring); - else - { - strcpy(SystemSetting.osd_bottom_bg_tran, "255"); - new_data_write_to_config_file_flag = 1; - } - - if (osd_bottom_content) - strcpy(SystemSetting.osd_bottom_content, osd_bottom_content->valuestring); - else - { - strcpy(SystemSetting.osd_bottom_content, "Location: <|device_name|> Time: <|YYYY|>-<|MM|>-<|DD|> <|hh|>:<|mm|>:<|ss|> Plate : <|linked_plate|>\nEvent: <|behavior_name|> Vehicle Color: <|color|> Vehicle Type: <|name|> Brand: <|logo|>"); - new_data_write_to_config_file_flag = 1; - } - - if (sensors_type) - strcpy(SystemSetting.sensors_type, sensors_type->valuestring); - else - { - strcpy(SystemSetting.sensors_type, "0"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_sync_external_lpr_db) - strcpy(SystemSetting.enable_sync_external_lpr_db, enable_sync_external_lpr_db->valuestring); - else - { - strcpy(SystemSetting.enable_sync_external_lpr_db, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (external_lpr_db_IP) - strcpy(SystemSetting.external_lpr_db_IP, external_lpr_db_IP->valuestring); - else - { - strcpy(SystemSetting.external_lpr_db_IP, "192.168.0.200"); - new_data_write_to_config_file_flag = 1; - } - - if (external_lpr_db_port) - strcpy(SystemSetting.external_lpr_db_port, external_lpr_db_port->valuestring); - else - { - strcpy(SystemSetting.external_lpr_db_port, accountData[0].account_aida_port); - new_data_write_to_config_file_flag = 1; - } - - if (external_lpr_db_username) - strcpy(SystemSetting.external_lpr_db_username, external_lpr_db_username->valuestring); - else - { - strcpy(SystemSetting.external_lpr_db_username, "admin"); - new_data_write_to_config_file_flag = 1; - } - - if (external_lpr_db_password) - strcpy(SystemSetting.external_lpr_db_password, external_lpr_db_password->valuestring); - else - { - strcpy(SystemSetting.external_lpr_db_password, "pass"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_system_logs) - strcpy(SystemSetting.enable_system_logs, enable_system_logs->valuestring); - else - { - strcpy(SystemSetting.enable_system_logs, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_email_jpeg) - strcpy(SystemSetting.enable_email_jpeg, enable_email_jpeg->valuestring); - else - { - strcpy(SystemSetting.enable_email_jpeg, "Yes"); - new_data_write_to_config_file_flag = 1; - } - - if (email_reset_time_interval) - strcpy(SystemSetting.email_reset_time_interval, email_reset_time_interval->valuestring); - else - { - strcpy(SystemSetting.email_reset_time_interval, ""); - new_data_write_to_config_file_flag = 1; - } - - if (enable_ftp) - strcpy(SystemSetting.enable_ftp, enable_ftp->valuestring); - else - { - strcpy(SystemSetting.enable_ftp, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (ftp_url) - strcpy(SystemSetting.ftp_url, ftp_url->valuestring); - else - { - strcpy(SystemSetting.ftp_url, "ftp.example.com"); - new_data_write_to_config_file_flag = 1; - } - - if (ftp_port) - strcpy(SystemSetting.ftp_port, ftp_port->valuestring); - else - { - strcpy(SystemSetting.ftp_port, "21"); - new_data_write_to_config_file_flag = 1; - } - - if (ftp_username) - strcpy(SystemSetting.ftp_username, ftp_username->valuestring); - else - { - strcpy(SystemSetting.ftp_username, ""); - new_data_write_to_config_file_flag = 1; - } - - if (ftp_password) - strcpy(SystemSetting.ftp_password, ftp_password->valuestring); - else - { - strcpy(SystemSetting.ftp_password, ""); - new_data_write_to_config_file_flag = 1; - } - - if (ftp_remote_directory) - strcpy(SystemSetting.ftp_remote_directory, ftp_remote_directory->valuestring); - else - { - strcpy(SystemSetting.ftp_remote_directory, "myfolder/myfile"); - new_data_write_to_config_file_flag = 1; - } - - if (ftp_jpeg_file_name_format) - strcpy(SystemSetting.ftp_jpeg_file_name_format, ftp_jpeg_file_name_format->valuestring); - else - { - strcpy(SystemSetting.ftp_jpeg_file_name_format, "fixed"); - new_data_write_to_config_file_flag = 1; - } - - if (ftp_jpeg_file_name) - strcpy(SystemSetting.ftp_jpeg_file_name, ftp_jpeg_file_name->valuestring); - else - { - strcpy(SystemSetting.ftp_jpeg_file_name, "snap"); - new_data_write_to_config_file_flag = 1; - } - - if (enable_email_notification) - strcpy(SystemSetting.enable_email_notification, enable_email_notification->valuestring); - else - { - strcpy(SystemSetting.enable_email_notification, "No"); - new_data_write_to_config_file_flag = 1; - } - - if (language) - strcpy(SystemSetting.language, language->valuestring); - else { - strcpy(SystemSetting.language, "en_gb"); - new_data_write_to_config_file_flag = 1; - } - - - display_properties = cJSON_GetObjectItem(system_setting, "display properties"); - if (display_properties) - strcpy(SystemSetting.enable_display_properties, display_properties->valuestring); - else { - strcpy(SystemSetting.enable_display_properties, "No"); - new_data_write_to_config_file_flag = 1; - } - - display_OSD = cJSON_GetObjectItem(system_setting, "display OSD"); - if (display_OSD) - strcpy(SystemSetting.enable_display_OSD, display_OSD->valuestring); - else { - strcpy(SystemSetting.enable_display_OSD, "No"); - new_data_write_to_config_file_flag = 1; - } - - //enable_log = cJSON_GetObjectItem(system_setting, "enable log"); - //api_format_ver = atoi(api_version->valuestring); - - overlap_ratio_limit = 75; - if (overlap_thresh) - overlap_ratio_limit = overlap_thresh->valuedouble; - - confidence_limit = 0; - stAMBAcontent.confidence_plate = 0; - stAMBAcontent.confidence_traffic = 0; - if (confidence_thresh) - { - confidence_limit = confidence_thresh->valuedouble; - stAMBAcontent.confidence_plate = confidence_thresh->valuedouble; - stAMBAcontent.confidence_traffic = confidence_thresh->valuedouble; - } - - display_dash = cJSON_GetObjectItem(system_setting, "display dash"); - activeDisplayDash = (strcmp(display_dash->valuestring, "Yes") == 0) ? _TRUE : _FALSE; - - activeDisplayProperties = (strcmp(display_properties->valuestring, "Yes") == 0) ? _TRUE : _FALSE; - - //printf("111-6 get password = %s \n", accountData[0].account_password); - - //20201027 sophia add - //account settings - cJSON *account_setting, *account_data; - account_setting = cJSON_GetObjectItem(root, "account_setting"); - account_data = cJSON_GetObjectItem(account_setting, "account_data"); - -#if 1 - { - //解碼account_data - step 1:base64 decode - size_t base64_decode_length = 0; - unsigned char EncryptKeyData[MAX_ACCOUNT_DATA_BUFF_SIZE]; - char DecryptKeyData[MAX_ACCOUNT_DATA_BUFF_SIZE]; - memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); - memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); - unsigned char OriEncryptData[512] = { 0 }; - base64_decode(account_data->valuestring, strlen(account_data->valuestring), &base64_decode_length, OriEncryptData); - memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); - - //解碼account_data - step 2:AES descrytion - KeyExpansion(key, expandedKey); - AESDecryptArrayToArray((char *)EncryptKeyData, base64_decode_length, expandedKey, DecryptKeyData, sizeof(DecryptKeyData)); - //printf("account_data descrytion OK.\n"); -#ifdef _DEBUG_AMBA - printf("account_data = %s \n", DecryptKeyData); -#endif - - //取得account_data明碼資訊 - cJSON *keyRoot, *detect; - cJSON *account_username, *account_password, *account_type, *account_status; - keyRoot = cJSON_Parse(DecryptKeyData); - int i = 0; - cJSON_ArrayForEach(detect, keyRoot) - { - account_username = cJSON_GetObjectItem(detect, "account_username"); - account_password = cJSON_GetObjectItem(detect, "account_password"); - account_type = cJSON_GetObjectItem(detect, "account_type"); - account_status = cJSON_GetObjectItem(detect, "account_status"); - - char temp_account[512] = { 0 }; - urlencode((unsigned char *)account_username->valuestring, strlen(account_username->valuestring), (unsigned char *)temp_account, 512); - - memcpy(accountData[i].account_username, temp_account, strlen(temp_account)); - accountData[i].account_username[strlen(temp_account)] = '\0'; - - char temp_account2[512] = { 0 }; - urlencode((unsigned char *)account_password->valuestring, strlen(account_password->valuestring), (unsigned char *)temp_account2, 512); - memcpy(accountData[i].account_password, temp_account2, strlen(temp_account2)); - accountData[i].account_password[strlen(temp_account2)] = '\0'; - - - //printf("111-6-0 get password = %s \n", account_password->valuestring); - //printf("111-6-0 password size = %d \n", strlen(account_password->valuestring)); - - //printf("111-6-1 get password = %s \n", accountData[i].account_password); - //printf("111-6-1 password size = %d \n", strlen(accountData[i].account_password)); - - //strcpy(accountData[i].account_username, account_username->valuestring); - //strcpy(accountData[i].account_password, account_password->valuestring); - accountData[i].account_type = account_type->valueint; - accountData[i].account_status = account_status->valueint; - - //printf("111-6-2 get password = %s \n", accountData[i].account_password); - -#ifdef _DEBUG_AMBA - printf("\naccountData[%d].account_username:%s", i, accountData[i].account_username); - printf("\naccountData[%d].account_password:%s", i, accountData[i].account_password); - printf("\naccountData[%d].account_type:%d", i, accountData[i].account_type); - printf("\naccountData[%d].account_status:%d", i, accountData[i].account_status); -#endif - - i++; - } - if (keyRoot) { - cJSON_Delete(keyRoot); - keyRoot = NULL; - } - } -#endif - - overlap_ratio_limit = 75; - if (overlap_thresh) - overlap_ratio_limit = overlap_thresh->valuedouble; - - confidence_limit = 0; - stAMBAcontent.confidence_plate = 0; - stAMBAcontent.confidence_traffic = 0; - if (confidence_thresh) - { - confidence_limit = confidence_thresh->valuedouble; - stAMBAcontent.confidence_plate = confidence_thresh->valuedouble; - stAMBAcontent.confidence_traffic = confidence_thresh->valuedouble; - } - - { - char* fileBuf = ReadAllBytes(emailsPATH); - - if (fileBuf) { - - cJSON *root = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - - if (root) - { - cJSON *auth_password; - auth_password = cJSON_GetObjectItem(root, "auth_password"); - - if (auth_password && strlen(auth_password->valuestring) >= 1) - { - size_t base64_decode_length = 0; - char EncryptKeyData[256]; - char DecryptKeyData[256]; - memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); - memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); - unsigned char OriEncryptData[512] = { 0 }; - - char temp_auth_password[256] = { 0 }; - memcpy(temp_auth_password, auth_password->valuestring, strlen(auth_password->valuestring)); - - //KeyExpansion(key_email, expandedKey_email); - //int decryptSize = AESDecryptArrayToArray(temp_auth_password, strlen(temp_auth_password), expandedKey_email, DecryptKeyData, sizeof(DecryptKeyData)); - - base64_decode(temp_auth_password, strlen(temp_auth_password), &base64_decode_length, OriEncryptData); - memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); - - strcpy(IPCAMService.auth_password, EncryptKeyData); - - //printf("\n-------------temp_auth_password:%s\n", temp_auth_password); - //printf("\n-------------DecryptKeyData:%s\n", DecryptKeyData); - //printf("\n-------------IPCAMService.auth_password:%s\n", IPCAMService.auth_password); - - } - } - - if (root) { - cJSON_Delete(root); - root = NULL; - } - } - else { - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - printf("\nFail to read emailsPATH or emails.json\n"); - } - } - - //printf("\n---------IPCAMService.auth_password:%s\n", IPCAMService.auth_password); - - //printf("GYNet Version=%s\n", APP_VERSION); - //printf("LicenseType=%s\n", strLicenseType);// - //printf("LicenseStatus=%s\n", strLicenseStatus); - //printf("111-5 get password = %s \n", accountData[0].account_password); - //printf("\n----------g_match_mac:%d\n", g_match_mac); - if (!(td_weight_num >= 1 && check_if_correct_mail == 1)) { - if (strcmp(strLicenseStatus, "Trial mismatch the system ID") != 0) { - if (strcmp(strLicenseStatus, "License mismatch the system ID") != 0) { - if (IsExistingWeight(featureType, featureType2)) { - if (strncmp(strUnlockingKey, "face", 4) == 0) { - - } - else { - strcpy(strUnlockingKey, unlock_key->valuestring); - } - - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char keyPATH[1024]; - - strcpy(keyPATH, exePath); - - strcat(keyPATH, "key.txt"); - - - FILE *pFile; - if ((pFile = fopen(keyPATH, "w")) != NULL) - { - fprintf(pFile, strUnlockingKey); - fclose(pFile); - } - else - { - printf("Fail to open key.txt \n"); - } - - } - else - strcpy(strUnlockingKey, "Trial_or_license_mismatch_the_feature_type"); - } - else - strcpy(strUnlockingKey, "License_mismatch_the_system_ID"); - } - else - strcpy(strUnlockingKey, "Trial_mismatch_the_system_ID"); - } - else { - if (g_match_mac == 1) { - strcpy(strUnlockingKey, "Third_party"); - } - else { - strcpy(strUnlockingKey, "License_mismatch_the_system_ID"); - } - } - - //printf("\nUnlockingKey=%s\n", strUnlockingKey); - //printf("111-4 get password = %s \n", accountData[0].account_password); - if (new_data_write_to_config_file_flag == 1 - || strcmp(strUnlockingKey, "Trial_or_license_mismatch_the_feature_type") == 0 - || strcmp(strUnlockingKey, "License_mismatch_the_system_ID") == 0 - || strcmp(strUnlockingKey, "Trial_mismatch_the_system_ID") == 0 - || strcmp(strUnlockingKey, "License_mismatch_the_system_ID") == 0) - { - - cJSON *new_data_root, *ai_server, *view_setting, *camera01, *detection_zone, *detect, *trigger_events, *trigger, *system_setting, *account_setting, *about_box; - new_data_root = cJSON_CreateObject(); - ai_server = cJSON_CreateObject(); - view_setting = cJSON_CreateObject(); - camera01 = cJSON_CreateObject(); - detection_zone = cJSON_CreateArray(); - system_setting = cJSON_CreateObject(); - account_setting = cJSON_CreateObject(); - about_box = cJSON_CreateObject(); - - cJSON_AddItemToObject(new_data_root, "ai_server", ai_server); - cJSON_AddItemToObject(ai_server, "ip", cJSON_CreateString("127.0.0.1")); - - cJSON_AddItemToObject(ai_server, "http_port", cJSON_CreateString(accountData[0].account_aida_port)); - cJSON_AddItemToObject(ai_server, "video_port", cJSON_CreateString("8591")); - - cJSON_AddItemToObject(new_data_root, "view_setting", view_setting); - cJSON_AddItemToObject(view_setting, "camera01", camera01); - cJSON_AddItemToObject(camera01, "ip", cJSON_CreateString("47.176.29.11")); - cJSON_AddItemToObject(camera01, "http_port", cJSON_CreateString("80")); - cJSON_AddItemToObject(camera01, "video_port", cJSON_CreateString("80")); - cJSON_AddItemToObject(camera01, "username", cJSON_CreateString("guest")); - cJSON_AddItemToObject(camera01, "password", cJSON_CreateString("GP12345")); - cJSON_AddItemToObject(camera01, "channel_id", cJSON_CreateString("")); - cJSON_AddItemToObject(camera01, "enable_repeat", cJSON_CreateNumber(0)); - cJSON_AddItemToObject(camera01, "camera_name", cJSON_CreateString("")); - cJSON_AddItemToObject(camera01, "obj_max_proportion", cJSON_CreateString(obj_max_proportion->valuestring)); - cJSON_AddItemToObject(camera01, "obj_min_proportion", cJSON_CreateString(obj_min_proportion->valuestring)); - - if (plate_filter_times) - cJSON_AddItemToObject(camera01, "PlateFilterTimes", cJSON_CreateString(plate_filter_times->valuestring)); - else - cJSON_AddItemToObject(camera01, "PlateFilterTimes", cJSON_CreateString("4")); - - if (plate_filter_time) - cJSON_AddItemToObject(camera01, "PlateFilterTime", cJSON_CreateString(plate_filter_time->valuestring)); - else - cJSON_AddItemToObject(camera01, "PlateFilterTime", cJSON_CreateString("3")); - - if (plate_free_time) - cJSON_AddItemToObject(camera01, "PlateRecorderFreeTime", cJSON_CreateString(plate_free_time->valuestring)); - else - cJSON_AddItemToObject(camera01, "PlateRecorderFreeTime", cJSON_CreateString("3")); - - cJSON_AddItemToObject(camera01, "enable_anpr", cJSON_CreateString(enable_anpr->valuestring)); - cJSON_AddItemToObject(camera01, "enable_face", cJSON_CreateString("Yes")); - cJSON_AddItemToObject(camera01, "enable_traffic", cJSON_CreateString(enable_traffic->valuestring)); - cJSON_AddItemToObject(camera01, "enable_logo", cJSON_CreateString("No")); - cJSON_AddItemToObject(camera01, "enable_human", cJSON_CreateString("No")); - cJSON_AddItemToObject(camera01, "enable_helmet", cJSON_CreateString("No")); - cJSON_AddItemToObject(camera01, "levenshtein_distance", cJSON_CreateString(levenshtein_distance->valuestring)); - cJSON_AddItemToObject(camera01, "min_characters", cJSON_CreateString(min_characters->valuestring)); - cJSON_AddItemToObject(camera01, "max_characters", cJSON_CreateString(max_characters->valuestring)); - cJSON_AddItemToObject(camera01, "confidence", cJSON_CreateString(confidence->valuestring)); - cJSON_AddItemToObject(camera01, "confidence2", cJSON_CreateString(confidence2->valuestring)); - cJSON_AddItemToObject(camera01, "confidence3", cJSON_CreateString(confidence3->valuestring)); - cJSON_AddItemToObject(camera01, "confidence4", cJSON_CreateString(confidence4->valuestring)); - cJSON_AddItemToObject(camera01, "tab_view_size", cJSON_CreateString("889x500")); - cJSON_AddItemToObject(camera01, "count_zone", cJSON_CreateNumber(viewChannelData[0].count_zone)); - - //printf("\nenable_lpr_db-----9\n"); - if (enable_lpr_db) { - cJSON_AddItemToObject(camera01, "enable_lpr_db", cJSON_CreateString(enable_lpr_db->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "enable_lpr_db", cJSON_CreateString("Yes")); - } - - if (enable_track) { - cJSON_AddItemToObject(camera01, "enable_track", cJSON_CreateString(enable_track->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "enable_track", cJSON_CreateString("No")); - } - - if (enable_PTZ) { - cJSON_AddItemToObject(camera01, "enable_PTZ", cJSON_CreateString(enable_PTZ->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "enable_PTZ", cJSON_CreateString("No")); - } - - if (ptz_tracking_fov_min) { - cJSON_AddItemToObject(camera01, "ptz_tracking_fov_min", cJSON_CreateString(ptz_tracking_fov_min->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "ptz_tracking_fov_min", cJSON_CreateString("0")); - } - - if (ptz_tracking_fov_max) { - cJSON_AddItemToObject(camera01, "ptz_tracking_fov_max", cJSON_CreateString(ptz_tracking_fov_max->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "ptz_tracking_fov_max", cJSON_CreateString("40")); - } - - if (ptz_enable_tracking) { - cJSON_AddItemToObject(camera01, "ptz_enable_tracking", cJSON_CreateString(ptz_enable_tracking->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "ptz_enable_tracking", cJSON_CreateString("Yes")); - } - - if (ptz_tracking_mode) { - cJSON_AddItemToObject(camera01, "ptz_tracking_mode", cJSON_CreateString(ptz_tracking_mode->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "ptz_tracking_mode", cJSON_CreateString("1")); - } - - if (ptz_tracking_by_enter_zone) { - cJSON_AddItemToObject(camera01, "ptz_tracking_by_enter_zone", cJSON_CreateString(ptz_tracking_by_enter_zone->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "ptz_tracking_by_enter_zone", cJSON_CreateString("Yes")); - } - - if (enable_tracking_limits) { - cJSON_AddItemToObject(camera01, "enable_tracking_limits", cJSON_CreateString(enable_tracking_limits->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "enable_tracking_limits", cJSON_CreateString("No")); - } - - if (ptz_pan_left_limit) { - cJSON_AddItemToObject(camera01, "ptz_pan_left_limit", cJSON_CreateString(ptz_pan_left_limit->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "ptz_pan_left_limit", cJSON_CreateString("0")); - } - - if (ptz_pan_right_limit) { - cJSON_AddItemToObject(camera01, "ptz_pan_right_limit", cJSON_CreateString(ptz_pan_right_limit->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "ptz_pan_right_limit", cJSON_CreateString("360")); - } - - if (ptz_tilt_up_limit) { - cJSON_AddItemToObject(camera01, "ptz_tilt_up_limit", cJSON_CreateString(ptz_tilt_up_limit->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "ptz_tilt_up_limit", cJSON_CreateString("0")); - } - - if (ptz_tilt_down_limit) { - cJSON_AddItemToObject(camera01, "ptz_tilt_down_limit", cJSON_CreateString(ptz_tilt_down_limit->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "ptz_tilt_down_limit", cJSON_CreateString("210")); - } - - if (ptz_speed) { - cJSON_AddItemToObject(camera01, "ptz_speed", cJSON_CreateString(ptz_speed->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "ptz_speed", cJSON_CreateString("3")); - } - - if (ptz_sensitivity) { - cJSON_AddItemToObject(camera01, "ptz_sensitivity", cJSON_CreateString(ptz_sensitivity->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "ptz_sensitivity", cJSON_CreateString("6")); - } - if (ptz_tracking_resume_dwell) { - cJSON_AddItemToObject(camera01, "ptz_tracking_resume_dwell", cJSON_CreateString(ptz_tracking_resume_dwell->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "ptz_tracking_resume_dwell", cJSON_CreateString("3")); - } - - if (cJSON_enable_only_show_metadata1) { - cJSON_AddItemToObject(camera01, "enable_only_show_metadata1", cJSON_CreateNumber(cJSON_enable_only_show_metadata1->valueint)); - } - else { - cJSON_AddItemToObject(camera01, "enable_only_show_metadata1", cJSON_CreateNumber(enable_only_show_metadata1)); - } - - if (enable_downsized_cropped_roi) { - cJSON_AddItemToObject(camera01, "enable_downsized_cropped_roi", cJSON_CreateNumber(enable_downsized_cropped_roi->valueint)); - } - else { - cJSON_AddItemToObject(camera01, "enable_downsized_cropped_roi", cJSON_CreateNumber(1)); - } - - if (enable_zone_crop_1) { - cJSON_AddItemToObject(camera01, "enable_zone_crop_1", cJSON_CreateNumber(enable_zone_crop_1->valueint)); - } - else { - cJSON_AddItemToObject(camera01, "enable_zone_crop_1", cJSON_CreateNumber(0)); - } - - if (enable_unknown_object) { - cJSON_AddItemToObject(camera01, "enable_unknown_object", cJSON_CreateString(enable_unknown_object->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "enable_unknown_object", cJSON_CreateString("No")); - } - - if (enable_ivs_person_detection) { - cJSON_AddItemToObject(camera01, "enable_ivs_person_detection", cJSON_CreateString(enable_ivs_person_detection->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "enable_ivs_person_detection", cJSON_CreateString("No")); - } - - if (assign_ivs_object_to) { - cJSON_AddItemToObject(camera01, "assign_ivs_object_to", cJSON_CreateString(assign_ivs_object_to->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "assign_ivs_object_to", cJSON_CreateString("")); - } - - if (enable_ambulance) { - cJSON_AddItemToObject(camera01, "enable_ambulance", cJSON_CreateString(enable_ambulance->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "enable_ambulance", cJSON_CreateString("No")); - } - - if (enable_blank_plate) { - cJSON_AddItemToObject(camera01, "enable_blank_plate", cJSON_CreateString(enable_blank_plate->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "enable_blank_plate", cJSON_CreateString("No")); - } - - if (enable_stop_sign) { - cJSON_AddItemToObject(camera01, "enable_stop_sign", cJSON_CreateString(enable_stop_sign->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "enable_stop_sign", cJSON_CreateString("No")); - } - - if (enable_show_unknown_object) { - cJSON_AddItemToObject(camera01, "enable_show_unknown_object", cJSON_CreateString(enable_show_unknown_object->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "enable_show_unknown_object", cJSON_CreateString("No")); - } - - if (enable_ivs_fix_mode) { - cJSON_AddItemToObject(camera01, "enable_ivs_fix_mode", cJSON_CreateString(enable_ivs_fix_mode->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "enable_ivs_fix_mode", cJSON_CreateString("No")); - } - - if (enable_ivs_and_ai) { - cJSON_AddItemToObject(camera01, "enable_ivs_and_ai", cJSON_CreateString(enable_ivs_and_ai->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "enable_ivs_and_ai", cJSON_CreateString("No")); - } - - if (enable_add_face_frequent_list) { - cJSON_AddItemToObject(camera01, "enable_add_face_frequent_list", cJSON_CreateString(enable_add_face_frequent_list->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "enable_add_face_frequent_list", cJSON_CreateString("No")); - } - - if (enable_lpr_upon_triggered) { - cJSON_AddItemToObject(camera01, "enable_lpr_upon_triggered", cJSON_CreateString(enable_lpr_upon_triggered->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "enable_lpr_upon_triggered", cJSON_CreateString("No")); - } - - if (dwell_lpr_upon_triggered) { - cJSON_AddItemToObject(camera01, "dwell_lpr_upon_triggered", cJSON_CreateString(dwell_lpr_upon_triggered->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "dwell_lpr_upon_triggered", cJSON_CreateString("10")); - } - - if (unknown_object_max_proportion) { - cJSON_AddItemToObject(camera01, "unknown_object_max_proportion", cJSON_CreateString(unknown_object_max_proportion->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "unknown_object_max_proportion", cJSON_CreateString("20")); - } - - if (unknown_object_min_proportion) { - cJSON_AddItemToObject(camera01, "unknown_object_min_proportion", cJSON_CreateString(unknown_object_min_proportion->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "unknown_object_min_proportion", cJSON_CreateString("0")); - } - - if (confidence_unknown_object) { - cJSON_AddItemToObject(camera01, "confidence_unknown_object", cJSON_CreateString(confidence_unknown_object->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "confidence_unknown_object", cJSON_CreateString("0")); - } - - if (confidence2_unknown_object) { - cJSON_AddItemToObject(camera01, "confidence2_unknown_object", cJSON_CreateString(confidence2_unknown_object->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "confidence2_unknown_object", cJSON_CreateString("0")); - } - - if (dwell_unknown_object) { - cJSON_AddItemToObject(camera01, "dwell_unknown_object", cJSON_CreateString(dwell_unknown_object->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "dwell_unknown_object", cJSON_CreateString("30")); - } - - if (dwell_minute_focus_on) { - cJSON_AddItemToObject(camera01, "dwell_minute_focus_on", cJSON_CreateString(dwell_minute_focus_on->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "dwell_minute_focus_on", cJSON_CreateString("5")); - } - - if (person_obj_fov) { - cJSON_AddItemToObject(camera01, "person_obj_fov", cJSON_CreateString(person_obj_fov->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "person_obj_fov", cJSON_CreateString("100")); - } - - if (ivs_mode) { - cJSON_AddItemToObject(camera01, "ivs_mode", cJSON_CreateString(ivs_mode->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "ivs_mode", cJSON_CreateString("3")); - } - - if (getnetwork_buffer_id) { - cJSON_AddItemToObject(camera01, "getnetwork_buffer_id", cJSON_CreateString(getnetwork_buffer_id->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "getnetwork_buffer_id", cJSON_CreateString("1")); - } - - if (red_light_zone) { - cJSON_AddItemToObject(camera01, "red_light_zone", cJSON_CreateString(red_light_zone->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "red_light_zone", cJSON_CreateString("")); - } - - if (no_give_way_zone_to_protect) { - cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect", cJSON_CreateString(no_give_way_zone_to_protect->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect", cJSON_CreateString("")); - } - - if (no_give_way_zone_to_keep_away) { - cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away", cJSON_CreateString(no_give_way_zone_to_keep_away->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away", cJSON_CreateString("")); - } - - if (no_give_way_zone_to_protect_2) { - cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect_2", cJSON_CreateString(no_give_way_zone_to_protect_2->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "no_give_way_zone_to_protect_2", cJSON_CreateString("")); - } - - if (no_give_way_zone_to_keep_away_2) { - cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away_2", cJSON_CreateString(no_give_way_zone_to_keep_away_2->valuestring)); - } - else { - cJSON_AddItemToObject(camera01, "no_give_way_zone_to_keep_away_2", cJSON_CreateString("")); - } - - cJSON_AddItemToObject(camera01, "detection_zone", detection_zone); - - for (int index_i = 0; index_i < MAX_DETECTION_ZONE; index_i++) - { - detect = cJSON_CreateObject(); - cJSON_AddItemToArray(detection_zone, detect); - cJSON_AddItemToObject(detect, "enable_direction1", cJSON_CreateString(viewDetectionZone[0][index_i].enable_direction1)); - cJSON_AddItemToObject(detect, "enable_direction2", cJSON_CreateString("")); - cJSON_AddItemToObject(detect, "direction1", cJSON_CreateString(viewDetectionZone[0][index_i].direction1)); - cJSON_AddItemToObject(detect, "direction2", cJSON_CreateString("")); - cJSON_AddItemToObject(detect, "enable_tripwire", cJSON_CreateString("")); - cJSON_AddItemToObject(detect, "enable_traffic_light", cJSON_CreateString("")); - cJSON_AddItemToObject(detect, "enable_social_distance", cJSON_CreateString("")); - - cJSON_AddItemToObject(detect, "metadata1", cJSON_CreateString(viewDetectionZone[0][index_i].metadata1)); - cJSON_AddItemToObject(detect, "metadata2", cJSON_CreateString(viewDetectionZone[0][index_i].metadata2)); - cJSON_AddItemToObject(detect, "metadata_stop", cJSON_CreateString(viewDetectionZone[0][index_i].metadata_stop)); - - char str[25] = { 0 }; - sprintf(str, "%d", viewDetectionZone[0][index_i].no_parking_time); - cJSON_AddItemToObject(detect, "no_parking_time", cJSON_CreateString(str)); - - memset(str, 0x00, sizeof(str)); - sprintf(str, "%d", viewDetectionZone[0][index_i].no_parking_time_in_minute); - cJSON_AddItemToObject(detect, "no_parking_time_in_minute", cJSON_CreateString(str)); - - memset(str,0x00,sizeof(str)); - sprintf(str, "%d", viewDetectionZone[0][index_i].queuing_count); - - cJSON_AddItemToObject(detect, "queuing_count", cJSON_CreateString(str)); - cJSON_AddItemToObject(detect, "distance_violation_count", cJSON_CreateString("")); - cJSON_AddItemToObject(detect, "detection_time", cJSON_CreateString(viewDetectionZone[0][index_i].detection_time)); - cJSON_AddItemToObject(detect, "link_to_counter", cJSON_CreateString(viewDetectionZone[0][index_i].link_to_counter)); - - if (obj_max_proportion_in_zone) - cJSON_AddItemToObject(detect, "obj_max_proportion_in_zone", cJSON_CreateString(viewDetectionZone[0][index_i].obj_max_proportion_in_zone)); - else { - cJSON_AddItemToObject(detect, "obj_max_proportion_in_zone", cJSON_CreateString("80")); - } - - if (obj_min_proportion_in_zone) - cJSON_AddItemToObject(detect, "obj_min_proportion_in_zone", cJSON_CreateString(viewDetectionZone[0][index_i].obj_min_proportion_in_zone)); - else { - cJSON_AddItemToObject(detect, "obj_min_proportion_in_zone", cJSON_CreateString("0")); - } - - if (ptz_zone_to_preset) - cJSON_AddItemToObject(detect, "ptz_zone_to_preset", cJSON_CreateString(viewDetectionZone[0][index_i].ptz_zone_to_preset)); - else { - cJSON_AddItemToObject(detect, "ptz_zone_to_preset", cJSON_CreateString("0")); - } - - if (enable_speed) - cJSON_AddItemToObject(detect, "enable_speed", cJSON_CreateString(viewDetectionZone[0][index_i].enable_speed)); - else { - cJSON_AddItemToObject(detect, "enable_speed", cJSON_CreateString("No")); - } - - if (enable_radar_speed) - cJSON_AddItemToObject(detect, "enable_radar_speed", cJSON_CreateString(viewDetectionZone[0][index_i].enable_radar_speed)); - else { - cJSON_AddItemToObject(detect, "enable_radar_speed", cJSON_CreateString("No")); - } - - if (enable_ivs_zone) - cJSON_AddItemToObject(detect, "enable_ivs_zone", cJSON_CreateString(viewDetectionZone[0][index_i].enable_ivs_zone)); - else { - cJSON_AddItemToObject(detect, "enable_ivs_zone", cJSON_CreateString("No")); - } - - if (parking_space) { - char buf_temp[20] = { 0 }; - sprintf(buf_temp, "%d", viewDetectionZone[0][index_i].parking_space); - cJSON_AddItemToObject(detect, "parking_space", cJSON_CreateString(buf_temp)); - } - else { - cJSON_AddItemToObject(detect, "parking_space", cJSON_CreateString("0")); - } - - if (parking_line) { - char buf_temp[20] = { 0 }; - sprintf(buf_temp, "%d", viewDetectionZone[0][index_i].parking_line); - cJSON_AddItemToObject(detect, "parking_line", cJSON_CreateString(buf_temp)); - } - else { - cJSON_AddItemToObject(detect, "parking_line", cJSON_CreateString("0")); - } - - if (set_distance) { - char buf_temp[20] = { 0 }; - sprintf(buf_temp,"%f", viewDetectionZone[0][index_i].set_distance); - cJSON_AddItemToObject(detect, "set_distance", cJSON_CreateString(buf_temp)); - } - else { - cJSON_AddItemToObject(detect, "set_distance", cJSON_CreateString("10")); - } - - if (world_distance_unit) - cJSON_AddItemToObject(detect, "world_distance_unit", cJSON_CreateString(viewDetectionZone[0][index_i].world_distance_unit)); - else { - cJSON_AddItemToObject(detect, "world_distance_unit", cJSON_CreateString("meter")); - } - - if (world_distance_side1) { - char buf_temp[20] = { 0 }; - sprintf(buf_temp, "%f", viewDetectionZone[0][index_i].world_distance_side1); - cJSON_AddItemToObject(detect, "world_distance_side1", cJSON_CreateString(buf_temp)); - } - else { - cJSON_AddItemToObject(detect, "world_distance_side1", cJSON_CreateString("10")); - } - - if (world_distance_side2) { - char buf_temp[20] = { 0 }; - sprintf(buf_temp, "%f", viewDetectionZone[0][index_i].world_distance_side2); - cJSON_AddItemToObject(detect, "world_distance_side2", cJSON_CreateString(buf_temp)); - } - else { - cJSON_AddItemToObject(detect, "world_distance_side2", cJSON_CreateString("10")); - } - - if (world_time_unit) { - cJSON_AddItemToObject(detect, "world_time_unit", cJSON_CreateString(viewDetectionZone[0][index_i].world_time_unit)); - } - else { - cJSON_AddItemToObject(detect, "world_time_unit", cJSON_CreateString("KPH")); - } - - trigger_events = cJSON_CreateArray(); - cJSON_AddItemToObject(detect, "trigger_events", trigger_events); - - for (int index_j = 0; index_j < MAX_TRIGGER_EVENT; index_j++) - { - trigger = cJSON_CreateObject(); - cJSON_AddItemToArray(trigger_events, trigger); - - char str_counter_increment[50] = { 0 }; - if (viewDetectionZone[0][index_i].trigger_event[index_j].counter_increment==1) { - strcpy(str_counter_increment,"counter_increment_add"); - } - else if (viewDetectionZone[0][index_i].trigger_event[index_j].counter_increment == -1) { - strcpy(str_counter_increment, "counter_increment_minus"); - } - else if (viewDetectionZone[0][index_i].trigger_event[index_j].counter_increment == 0) { - strcpy(str_counter_increment, "counter_increment_equal"); - } - else { - strcpy(str_counter_increment,""); - } - - cJSON_AddItemToObject(trigger, "checked", cJSON_CreateNumber(viewDetectionZone[0][index_i].trigger_event[index_j].checked)); - - if (index_j == 0) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000001")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Prohibit zone (AIAREA)")); - } - else if (index_j == 1) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000004")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Parking violation (AIAREA/AICAP)")); - } - else if (index_j == 2) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00200000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Allowed list")); - } - else if (index_j == 3) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00400000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Denial list")); - } - else if (index_j == 4) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000008")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Traffic flow (AIFLOW/AICAP)")); - } - else if (index_j == 5) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000010")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turn left (AIFLOW)")); - } - else if (index_j == 6) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000020")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turn right (AIFLOW)")); - } - else if (index_j == 7) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x10000000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Density detection (03AI)")); - } - else if (index_j == 8) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x20000000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Missing object detection (01AI)")); - } - else if (index_j == 9) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00800000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Visitor list")); - } - else if (index_j == 10) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x01000000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Unattended object or missing object")); - } - else if (index_j == 11) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x02000000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("BG learning")); - } - else if (index_j == 12) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x04000000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Tampering detection")); - } - else if (index_j == 13) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x40000000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("All objects detection")); - } - else if (index_j == 14) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x80000000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Lack of any object detection")); - } - else if (index_j == 15) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00002000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Over speed detection")); - } - else if (index_j == 16) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00004000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Lower speed detection")); - } - else if (index_j == 17) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000400")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Running red lights")); - } - else if (index_j == 18) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00000800")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turning left on red")); - } - else if (index_j == 19) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00001000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Turning right on red")); - } - else if (index_j == 20) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00008000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Forget to give way detection")); - } - else if (index_j == 21) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x00040000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Distance violation")); - } - else if (index_j == 22) { - cJSON_AddItemToObject(trigger, "detect_event_id", cJSON_CreateString("0x08000000")); - cJSON_AddItemToObject(trigger, "detect_event_name", cJSON_CreateString("Height detection")); - } - - cJSON_AddItemToObject(trigger, "post_event_name", cJSON_CreateString(viewDetectionZone[0][index_i].trigger_event[index_j].post_event_name)); - cJSON_AddItemToObject(trigger, "counter_name", cJSON_CreateString(viewDetectionZone[0][index_i].trigger_event[index_j].counter_name)); - cJSON_AddItemToObject(trigger, "counter_increment", cJSON_CreateString(str_counter_increment)); - - } - cJSON_AddItemToObject(detect, "point_number", cJSON_CreateNumber(6)); - cJSON_AddItemToObject(detect, "x1", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[0].x)); - cJSON_AddItemToObject(detect, "y1", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[0].y)); - cJSON_AddItemToObject(detect, "x2", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[1].x)); - cJSON_AddItemToObject(detect, "y2", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[1].y)); - cJSON_AddItemToObject(detect, "x3", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[2].x)); - cJSON_AddItemToObject(detect, "y3", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[2].y)); - cJSON_AddItemToObject(detect, "x4", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[3].x)); - cJSON_AddItemToObject(detect, "y4", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[3].y)); - if (x5 && x6) - { - cJSON_AddItemToObject(detect, "x5", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[4].x)); - cJSON_AddItemToObject(detect, "y5", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[4].y)); - cJSON_AddItemToObject(detect, "x6", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[5].x)); - cJSON_AddItemToObject(detect, "y6", cJSON_CreateNumber(viewDetectionZone[0][index_i].Points[5].y)); - } - else - { - cJSON_AddItemToObject(detect, "x5", cJSON_CreateNumber(579)); - cJSON_AddItemToObject(detect, "y5", cJSON_CreateNumber(250)); - cJSON_AddItemToObject(detect, "x6", cJSON_CreateNumber(579)); - cJSON_AddItemToObject(detect, "y6", cJSON_CreateNumber(100)); - } - } - - cJSON_AddItemToObject(new_data_root, "system_setting", system_setting); - cJSON_AddItemToObject(system_setting, "AI dataset", cJSON_CreateString("")); - cJSON_AddItemToObject(system_setting, "dataset category", cJSON_CreateString("; Total 60 FPS")); - cJSON_AddItemToObject(system_setting, "snapshot folder", cJSON_CreateString("D:\\\\")); - if (language) { - cJSON_AddItemToObject(system_setting, "language", cJSON_CreateString(language->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "language", cJSON_CreateString("en_gb")); - } - cJSON_AddItemToObject(system_setting, "enable log", cJSON_CreateString("No")); - cJSON_AddItemToObject(system_setting, "auto reconnect", cJSON_CreateString("Yes")); - cJSON_AddItemToObject(system_setting, "auto start", cJSON_CreateString("Yes")); - cJSON_AddItemToObject(system_setting, "enable watchdog", cJSON_CreateString("Yes")); - cJSON_AddItemToObject(system_setting, "enable watchdog UI", cJSON_CreateString("Yes")); - cJSON_AddItemToObject(system_setting, "cpu usage limit", cJSON_CreateString("80")); - cJSON_AddItemToObject(system_setting, "display OSD", cJSON_CreateString("No")); - - if (activeDisplayDash) { - cJSON_AddItemToObject(system_setting, "display dash", cJSON_CreateString(display_dash->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "display dash", cJSON_CreateString("No")); - } - - if (display_properties) - cJSON_AddItemToObject(system_setting, "display properties", cJSON_CreateString(display_properties->valuestring)); - else { - cJSON_AddItemToObject(system_setting, "display properties", cJSON_CreateString("No")); - } - - - cJSON_AddItemToObject(system_setting, "display tracking ID", cJSON_CreateString("Yes")); - cJSON_AddItemToObject(system_setting, "overlap thresh", cJSON_CreateNumber(70)); - cJSON_AddItemToObject(system_setting, "confidence thresh", cJSON_CreateNumber(0)); - cJSON_AddItemToObject(system_setting, "cnn type", cJSON_CreateString("CUDA")); - cJSON_AddItemToObject(system_setting, "cnn device1", cJSON_CreateString("GPU")); - cJSON_AddItemToObject(system_setting, "cnn device2", cJSON_CreateString("GPU")); - cJSON_AddItemToObject(system_setting, "cnn device3", cJSON_CreateString("GPU")); - cJSON_AddItemToObject(system_setting, "cnn device4", cJSON_CreateString("GPU")); - cJSON_AddItemToObject(system_setting, "cnn device5", cJSON_CreateString("GPU")); - cJSON_AddItemToObject(system_setting, "cnn device6", cJSON_CreateString("GPU")); - cJSON_AddItemToObject(system_setting, "cnn device7", cJSON_CreateString("GPU")); - cJSON_AddItemToObject(system_setting, "cnn device8", cJSON_CreateString("GPU")); - cJSON_AddItemToObject(system_setting, "whitelist", cJSON_CreateString("No")); - cJSON_AddItemToObject(system_setting, "blacklist", cJSON_CreateString("No")); - - - if (enable_person_independent) { - cJSON_AddItemToObject(system_setting, "enable_person_independent", cJSON_CreateString(enable_person_independent->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "enable_person_independent", cJSON_CreateString("No")); - } - - if (enable_onvif_profile_m) { - cJSON_AddItemToObject(system_setting, "enable_onvif_profile_m", cJSON_CreateString(enable_onvif_profile_m->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "enable_onvif_profile_m", cJSON_CreateString("No")); - } - - if (nms_thres) { - cJSON_AddItemToObject(system_setting, "nms_thres", cJSON_CreateString(nms_thres->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "nms_thres", cJSON_CreateString("10")); - } - - if (tracking_id_dwell) { - cJSON_AddItemToObject(system_setting, "tracking_id_dwell", cJSON_CreateString(tracking_id_dwell->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "tracking_id_dwell", cJSON_CreateString("5")); - } - - if (enable_cloud) { - cJSON_AddItemToObject(system_setting, "enable_cloud", cJSON_CreateString(enable_cloud->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "enable_cloud", cJSON_CreateString("No")); - } - - if (enable_special_edition) { - cJSON_AddItemToObject(system_setting, "enable_special_edition", cJSON_CreateString(enable_special_edition->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "enable_special_edition", cJSON_CreateString("No")); - } - - if (enable_python) { - cJSON_AddItemToObject(system_setting, "enable_python", cJSON_CreateString(enable_python->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "enable_python", cJSON_CreateString("No")); - } - - if (enable_python_file) { - cJSON_AddItemToObject(system_setting, "enable_python_file", cJSON_CreateString(enable_python_file->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "enable_python_file", cJSON_CreateString("No python running.")); - } - - if (enable_low_cpu_usage) { - cJSON_AddItemToObject(system_setting, "enable_low_cpu_usage", cJSON_CreateString(enable_low_cpu_usage->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "enable_low_cpu_usage", cJSON_CreateString("No")); - } - - if (cloud_enable_snap) { - cJSON_AddItemToObject(system_setting, "cloud_enable_snap", cJSON_CreateString(cloud_enable_snap->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "cloud_enable_snap", cJSON_CreateString("Yes")); - } - - if (cloud_enable_notification) { - cJSON_AddItemToObject(system_setting, "cloud_enable_notification", cJSON_CreateString(cloud_enable_notification->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "cloud_enable_notification", cJSON_CreateString("No")); - } - - if (cloud_account) { - cJSON_AddItemToObject(system_setting, "cloud_account", cJSON_CreateString(cloud_account->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "cloud_account", cJSON_CreateString("myaccount@mail.com")); - } - - if (cloud_password) { - cJSON_AddItemToObject(system_setting, "cloud_password", cJSON_CreateString(cloud_password->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "cloud_password", cJSON_CreateString("mypass")); - } - - if (cloud_notification_dwell) { - cJSON_AddItemToObject(system_setting, "cloud_notification_dwell", cJSON_CreateString(cloud_notification_dwell->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "cloud_notification_dwell", cJSON_CreateString("60")); - } - - if (cloud_statue) { - cJSON_AddItemToObject(system_setting, "cloud_statue", cJSON_CreateString(cloud_statue->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "cloud_statue", cJSON_CreateString("")); - } - - if (cloud_v2_statue) { - cJSON_AddItemToObject(system_setting, "cloud_v2_statue", cJSON_CreateString(cloud_v2_statue->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "cloud_v2_statue", cJSON_CreateString("")); - } - - if (cloud_record_v2_statue) { - cJSON_AddItemToObject(system_setting, "cloud_record_v2_statue", cJSON_CreateString(cloud_record_v2_statue->valuestring)); - } - else { - cJSON_AddItemToObject(system_setting, "cloud_record_v2_statue", cJSON_CreateString("")); - } - - if (enable_special_char) - cJSON_AddItemToObject(system_setting, "enable_special_char", cJSON_CreateString(enable_special_char->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "enable_special_char", cJSON_CreateString("No")); - } - - if (enable_bounding_box) - cJSON_AddItemToObject(system_setting, "enable_bounding_box", cJSON_CreateString(enable_bounding_box->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "enable_bounding_box", cJSON_CreateString("Yes")); - } - - if (enable_dwell_bounding_box) - cJSON_AddItemToObject(system_setting, "enable_dwell_bounding_box", cJSON_CreateString(enable_bounding_box->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "enable_dwell_bounding_box", cJSON_CreateString("No")); - } - - if (force_i_to_one) - cJSON_AddItemToObject(system_setting, "force_i_to_one", cJSON_CreateString(force_i_to_one->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "force_i_to_one", cJSON_CreateString("Yes")); - } - - if (force_o_to_zero) - cJSON_AddItemToObject(system_setting, "force_o_to_zero", cJSON_CreateString(force_o_to_zero->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "force_o_to_zero", cJSON_CreateString("Yes")); - } - - if (enable_plate_angle_correction) - cJSON_AddItemToObject(system_setting, "enable_plate_angle_correction", cJSON_CreateString(enable_plate_angle_correction->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "enable_plate_angle_correction", cJSON_CreateString("No")); - } - - if (enable_ai_mirror) - cJSON_AddItemToObject(system_setting, "enable_ai_mirror", cJSON_CreateString(enable_ai_mirror->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "enable_ai_mirror", cJSON_CreateString("No")); - } - - if (ai_mirror_feature) - cJSON_AddItemToObject(system_setting, "ai_mirror_feature", cJSON_CreateString(ai_mirror_feature->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "ai_mirror_feature", cJSON_CreateString("0")); - } - - if (enable_cloud_v2) - cJSON_AddItemToObject(system_setting, "enable_cloud_v2", cJSON_CreateString(enable_cloud_v2->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "enable_cloud_v2", cJSON_CreateString("No")); - } - - if (cloud_v2_notification_dwell) - cJSON_AddItemToObject(system_setting, "cloud_v2_notification_dwell", cJSON_CreateString(cloud_v2_notification_dwell->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "cloud_v2_notification_dwell", cJSON_CreateString("60")); - } - - if (cloud_v2_content) - cJSON_AddItemToObject(system_setting, "cloud_v2_content", cJSON_CreateString(cloud_v2_content->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "cloud_v2_content", cJSON_CreateString("{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}")); - } - - if (enable_cloud_record_v2) - cJSON_AddItemToObject(system_setting, "enable_cloud_record_v2", cJSON_CreateString(enable_cloud_record_v2->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "enable_cloud_record_v2", cJSON_CreateString("No")); - } - - if (cloud_record_v2_notification_dwell) - cJSON_AddItemToObject(system_setting, "cloud_record_v2_notification_dwell", cJSON_CreateString(cloud_record_v2_notification_dwell->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "cloud_record_v2_notification_dwell", cJSON_CreateString("60")); - } - - if (cloud_record_v2_content) - cJSON_AddItemToObject(system_setting, "cloud_record_v2_content", cJSON_CreateString(cloud_record_v2_content->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "cloud_record_v2_content", cJSON_CreateString("{\"apiKey\": \"<|api_key|>\",\"type\": \"AI_EVENT\",\"createdAt\": \"<|YYYY|>-<|MM|>-<|DD|>T<|GMThh|>:<|mm|>:<|ss|>.000000Z\",\"data\": {\"status\": {\"value\": \"string\",\"type\": \"text\",\"res_width\": \"1280\",\"res_height\": \"720\",\"object_name\": \"<|name|>\",\"left_x\": \"<|left_x|>\",\"top_y\": \"<|top_y|>\",\"width\": \"<|width|>\",\"height\": \"<|height|>\",\"behavior_id\": \"<|behavior_id|>\",\"behavior_name\": \"<|behavior_name|>\"},\"snapshot\": {\"value\": \"<|jpeg_image|>\",\"type\": \"image/base64\"}}}")); - } - - if (enable_post_only_if_both_detected) - cJSON_AddItemToObject(system_setting, "enable_post_only_if_both_detected", cJSON_CreateString(enable_post_only_if_both_detected->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "enable_post_only_if_both_detected", cJSON_CreateString("No")); - } - - if (enable_getalarmmotion_snap) - cJSON_AddItemToObject(system_setting, "enable_getalarmmotion_snap", cJSON_CreateString(enable_getalarmmotion_snap->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "enable_getalarmmotion_snap", cJSON_CreateString("No")); - } - - if (getimage_encoder_id) - cJSON_AddItemToObject(system_setting, "getimage_encoder_id", cJSON_CreateString(getimage_encoder_id->valuestring)); - else - { -#ifdef GY_OS_NOVA - cJSON_AddItemToObject(system_setting, "getimage_encoder_id", cJSON_CreateString("3")); -#endif -#ifdef GY_OS_AMBA - cJSON_AddItemToObject(system_setting, "getimage_encoder_id", cJSON_CreateString("4")); -#endif - } - - if (getimage_encoder_id_HD) - cJSON_AddItemToObject(system_setting, "getimage_encoder_id_HD", cJSON_CreateString(getimage_encoder_id_HD->valuestring)); - else - { -#ifdef GY_OS_NOVA - cJSON_AddItemToObject(system_setting, "getimage_encoder_id_HD", cJSON_CreateString("0")); -#endif -#ifdef GY_OS_AMBA - cJSON_AddItemToObject(system_setting, "getimage_encoder_id_HD", cJSON_CreateString("4")); -#endif - } - - if (osd_encoder_id) - cJSON_AddItemToObject(system_setting, "osd_encoder_id", cJSON_CreateString(osd_encoder_id->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "osd_encoder_id", cJSON_CreateString("2")); - } - - if (osd_font_size) - cJSON_AddItemToObject(system_setting, "osd_font_size", cJSON_CreateString(osd_font_size->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "osd_font_size", cJSON_CreateString("26")); - } - - if (osd_outline_lilin) - cJSON_AddItemToObject(system_setting, "osd_outline_lilin", cJSON_CreateString(osd_outline_lilin->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "osd_outline_lilin", cJSON_CreateString("4")); - } - - if (enable_osd_bottom) - cJSON_AddItemToObject(system_setting, "enable_osd_bottom", cJSON_CreateString(enable_osd_bottom->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "enable_osd_bottom", cJSON_CreateString("Yes")); - } - - if (osd_bottom_bg_tran) - cJSON_AddItemToObject(system_setting, "osd_bottom_bg_tran", cJSON_CreateString(osd_bottom_bg_tran->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "osd_bottom_bg_tran", cJSON_CreateString("255")); - } - - if (osd_bottom_content) - cJSON_AddItemToObject(system_setting, "osd_bottom_content", cJSON_CreateString(osd_bottom_content->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "osd_bottom_content", cJSON_CreateString("Location: <|device_name|> Time: <|YYYY|>-<|MM|>-<|DD|> <|hh|>:<|mm|>:<|ss|> Plate : <|linked_plate|>\nEvent: <|behavior_name|> Vehicle Color: <|color|> Vehicle Type: <|name|> Brand: <|logo|>")); - } - - if (sensors_type) - cJSON_AddItemToObject(system_setting, "sensors_type", cJSON_CreateString(sensors_type->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "sensors_type", cJSON_CreateString("0")); - } - - if (enable_sync_external_lpr_db) - cJSON_AddItemToObject(system_setting, "enable_sync_external_lpr_db", cJSON_CreateString(enable_sync_external_lpr_db->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "enable_sync_external_lpr_db", cJSON_CreateString("No")); - } - - if (external_lpr_db_IP) - cJSON_AddItemToObject(system_setting, "external_lpr_db_IP", cJSON_CreateString(external_lpr_db_IP->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "external_lpr_db_IP", cJSON_CreateString("192.168.0.200")); - } - - if (external_lpr_db_port) - cJSON_AddItemToObject(system_setting, "external_lpr_db_port", cJSON_CreateString(external_lpr_db_port->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "external_lpr_db_port", cJSON_CreateString(accountData[0].account_aida_port)); - } - - if (external_lpr_db_username) - cJSON_AddItemToObject(system_setting, "external_lpr_db_username", cJSON_CreateString(external_lpr_db_username->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "external_lpr_db_username", cJSON_CreateString("admin")); - } - - if (external_lpr_db_password) - cJSON_AddItemToObject(system_setting, "external_lpr_db_password", cJSON_CreateString(external_lpr_db_password->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "external_lpr_db_password", cJSON_CreateString("pass")); - } - - if (enable_system_logs) - cJSON_AddItemToObject(system_setting, "enable_system_logs", cJSON_CreateString(enable_system_logs->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "enable_system_logs", cJSON_CreateString("No")); - } - - if (enable_email_jpeg) - cJSON_AddItemToObject(system_setting, "enable_email_jpeg", cJSON_CreateString(enable_email_jpeg->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "enable_email_jpeg", cJSON_CreateString("Yes")); - } - - if (email_reset_time_interval) - cJSON_AddItemToObject(system_setting, "email_reset_time_interval", cJSON_CreateString(email_reset_time_interval->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "email_reset_time_interval", cJSON_CreateString("")); - } - - if (enable_ftp) - cJSON_AddItemToObject(system_setting, "enable_ftp", cJSON_CreateString(enable_ftp->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "enable_ftp", cJSON_CreateString("No")); - } - - if (ftp_url) - cJSON_AddItemToObject(system_setting, "ftp_url", cJSON_CreateString(ftp_url->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "ftp_url", cJSON_CreateString("ftp.example.com")); - } - - if (ftp_port) - cJSON_AddItemToObject(system_setting, "ftp_port", cJSON_CreateString(ftp_port->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "ftp_port", cJSON_CreateString("21")); - } - - if (ftp_username) - cJSON_AddItemToObject(system_setting, "ftp_username", cJSON_CreateString(ftp_username->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "ftp_username", cJSON_CreateString("")); - } - - if (ftp_password) - cJSON_AddItemToObject(system_setting, "ftp_password", cJSON_CreateString(ftp_password->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "ftp_password", cJSON_CreateString("")); - } - - if (ftp_remote_directory) - cJSON_AddItemToObject(system_setting, "ftp_remote_directory", cJSON_CreateString(ftp_remote_directory->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "ftp_remote_directory", cJSON_CreateString("myfolder/myfile")); - } - - - if (ftp_jpeg_file_name_format) - cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name_format", cJSON_CreateString(ftp_jpeg_file_name_format->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name_format", cJSON_CreateString("fixed")); - } - - - if (ftp_jpeg_file_name) - cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name", cJSON_CreateString(ftp_jpeg_file_name->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "ftp_jpeg_file_name", cJSON_CreateString("snap")); - } - - if (enable_email_notification) - cJSON_AddItemToObject(system_setting, "enable_email_notification", cJSON_CreateString(enable_email_notification->valuestring)); - else - { - cJSON_AddItemToObject(system_setting, "enable_email_notification", cJSON_CreateString("No")); - } - - cJSON_AddItemToObject(new_data_root, "account_setting", account_setting); - cJSON_AddItemToObject(account_setting, "account_data", cJSON_CreateString(account_data->valuestring)); - - cJSON_AddItemToObject(new_data_root, "about_box", about_box); - cJSON_AddItemToObject(about_box, "dataset version", cJSON_CreateString("")); - cJSON_AddItemToObject(about_box, "software version", cJSON_CreateString("2.0.2")); - cJSON_AddItemToObject(about_box, "system id", cJSON_CreateString("")); - cJSON_AddItemToObject(about_box, "NIC name", cJSON_CreateString("乙太網路")); - - if(strcmp(strUnlockingKey, "Trial_or_license_mismatch_the_feature_type") != 0) - { - if (strcmp(strUnlockingKey, "License_mismatch_the_system_ID") != 0) { - if (strcmp(strUnlockingKey, "Trial_mismatch_the_system_ID") != 0) { - if (strcmp(strUnlockingKey, "License_mismatch_the_system_ID") != 0) { - - if (strncmp(strUnlockingKey, "face", 4) == 0) { - cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString(strUnlockingKey)); - } - else { - cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString(unlock_key->valuestring)); - } - } - else - cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("License_mismatch_the_system_ID")); - } - else - cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("Trial_mismatch_the_system_ID")); - } - else - cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("License_mismatch_the_system_ID")); - } - else - cJSON_AddItemToObject(about_box, "unlocking key", cJSON_CreateString("Trial_or_license_mismatch_the_feature_type")); - - - char *filename; - filename = configPATH; - - int del = remove(filename); - if (!del) { - //printf("config is Deleted successfully."); - } - else { - printf("config cannot be Deleted.\n"); - } - - char* JsonString = cJSON_Print(new_data_root); - FILE *fp; - - if ((fp = fopen(filename, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - } - else - { - fclose(fp); - printf("Fail to open config.json \n"); - } - if (JsonString) { - free(JsonString); - JsonString = NULL; - } - if (new_data_root) { - cJSON_Delete(new_data_root); - new_data_root = NULL; - } - new_data_write_to_config_file_flag = 0; - } - - //printf("111-3 get password = %s \n", accountData[0].account_password); - if (new_data_write_to_events_file_flag == 1) { - cJSON *new_data_root, *notification, *event_counter_setting/*,*enable_post*//*,*enable_snmp_post*/,*http_post_events,*a_http_post_event,*event_counters, - *a_event_counter; - cJSON *a_report, *report_counters; - cJSON *a_snmp, *snmp_management; - cJSON *email_setting; - new_data_root = cJSON_CreateObject(); - notification = cJSON_CreateObject(); - event_counter_setting = cJSON_CreateObject(); - email_setting = cJSON_CreateObject(); -; - cJSON_AddItemToObject(new_data_root, "notification", notification); - cJSON_AddItemToObject(new_data_root, "event_counter_setting", event_counter_setting); - cJSON_AddItemToObject(new_data_root, "email_setting", email_setting); - - if(activePostNotification) - cJSON_AddItemToObject(notification, "enable_post", cJSON_CreateString("Yes")); - else - cJSON_AddItemToObject(notification, "enable_post", cJSON_CreateString("No")); - - if (activeSNMPPost) - cJSON_AddItemToObject(notification, "enable_snmp_post", cJSON_CreateString("Yes")); - else - cJSON_AddItemToObject(notification, "enable_snmp_post", cJSON_CreateString("No")); - - cJSON_AddItemToObject(notification, "events_default_version", cJSON_CreateString(heartbeatData.events_default_version)); - cJSON_AddItemToObject(notification, "enable_heartbeat", cJSON_CreateString(heartbeatData.enable_heartbeat)); - - cJSON_AddItemToObject(notification, "enable_snmp_heartbeat", cJSON_CreateString(heartbeatData.enable_snmp_heartbeat)); - cJSON_AddItemToObject(notification, "snmp_heartbeat_dwell", cJSON_CreateString(heartbeatData.snmp_heartbeat_dwell)); - cJSON_AddItemToObject(notification, "snmp_heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.snmp_heartbeat_link_to_post_event_name)); - - cJSON_AddItemToObject(notification, "enable_check_ptz_start_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_start_autotracking)); - cJSON_AddItemToObject(notification, "enable_check_ptz_end_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_end_autotracking)); - cJSON_AddItemToObject(notification, "ptz_start_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_start_autotracking_link_to_post_event_name)); - cJSON_AddItemToObject(notification, "ptz_end_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_end_autotracking_link_to_post_event_name)); - cJSON_AddItemToObject(notification, "enable_only_once_to_post", cJSON_CreateString(heartbeatData.enable_only_once_to_post)); - cJSON_AddItemToObject(notification, "enable_obj_once_to_post", cJSON_CreateString(heartbeatData.enable_obj_once_to_post)); - cJSON_AddItemToObject(notification, "enable_location_once_to_post", cJSON_CreateString(heartbeatData.enable_location_once_to_post)); - cJSON_AddItemToObject(notification, "dwell_to_the_same_location", cJSON_CreateString(heartbeatData.dwell_to_the_same_location)); - cJSON_AddItemToObject(notification, "enable_nvr_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_nvr_once_to_getalarmmotion)); - cJSON_AddItemToObject(notification, "enable_8592_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_8592_once_to_getalarmmotion)); - cJSON_AddItemToObject(notification, "heartbeat_dwell", cJSON_CreateString(heartbeatData.heartbeat_dwell)); - cJSON_AddItemToObject(notification, "heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.heartbeat_link_to_post_event_name)); - cJSON_AddItemToObject(notification, "heatmap_max", cJSON_CreateString(heartbeatData.heatmap_max)); - cJSON_AddItemToObject(notification, "enable_heatmap", cJSON_CreateString(heartbeatData.enable_heatmap)); - cJSON_AddItemToObject(notification, "heatmap_frequency", cJSON_CreateString(heartbeatData.heatmap_frequency)); - cJSON_AddItemToObject(notification, "lpr_title", cJSON_CreateString(heartbeatData.lpr_title)); - cJSON_AddItemToObject(notification, "enable_counter_snap", cJSON_CreateString(heartbeatData.enable_counter_snap)); - cJSON_AddItemToObject(notification, "enable_barcode_qr", cJSON_CreateString(heartbeatData.enable_barcode_qr)); - - http_post_events = cJSON_CreateArray(); - cJSON_AddItemToObject(notification, "http_post_events", http_post_events); - - for (int index_http_post = 0; index_http_post < MAX_POST_EVENTS; index_http_post++) { - a_http_post_event = cJSON_CreateObject(); - cJSON_AddItemToArray(http_post_events, a_http_post_event); - - cJSON_AddItemToObject(a_http_post_event, "post_protocol", cJSON_CreateString(postEventList[index_http_post].post_protocol)); - cJSON_AddItemToObject(a_http_post_event, "post_event_method", cJSON_CreateString(postEventList[index_http_post].post_event_method)); - cJSON_AddItemToObject(a_http_post_event, "post_event_name", cJSON_CreateString(postEventList[index_http_post].post_event_name)); - cJSON_AddItemToObject(a_http_post_event, "post_host_ip", cJSON_CreateString(postEventList[index_http_post].post_host_ip)); - cJSON_AddItemToObject(a_http_post_event, "post_host_port", cJSON_CreateString(postEventList[index_http_post].post_host_port)); - cJSON_AddItemToObject(a_http_post_event, "post_url", cJSON_CreateString(postEventList[index_http_post].post_url)); - cJSON_AddItemToObject(a_http_post_event, "post_content_type", cJSON_CreateString("text/html; charset=utf-8")); - - char buf_account[512] = { 0 }; - urldecode((unsigned char *)postEventList[index_http_post].post_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)postEventList[index_http_post].post_password, (unsigned char *)buf_account2); - - cJSON_AddItemToObject(a_http_post_event, "post_username", cJSON_CreateString(buf_account)); - cJSON_AddItemToObject(a_http_post_event, "post_password", cJSON_CreateString(buf_account2)); - cJSON_AddItemToObject(a_http_post_event, "post_customized_header", cJSON_CreateString(postEventList[index_http_post].post_customized_header)); - cJSON_AddItemToObject(a_http_post_event, "post_content", cJSON_CreateString(postEventList[index_http_post].post_content)); - cJSON_AddItemToObject(a_http_post_event, "post_sequence", cJSON_CreateString(postEventList[index_http_post].post_sequence)); - cJSON_AddItemToObject(a_http_post_event, "post_file_format", cJSON_CreateString(postEventList[index_http_post].post_file_format)); - cJSON_AddItemToObject(a_http_post_event, "post_jpeg_file_name_format", cJSON_CreateString(postEventList[index_http_post].post_jpeg_file_name_format)); - cJSON_AddItemToObject(a_http_post_event, "post_jpeg_file_name", cJSON_CreateString(postEventList[index_http_post].post_jpeg_file_name)); - cJSON_AddItemToObject(a_http_post_event, "post_timeout", cJSON_CreateString(postEventList[index_http_post].post_timeout)); - } - event_counters = cJSON_CreateArray(); - cJSON_AddItemToObject(event_counter_setting, "event_counters", event_counters); - report_counters = cJSON_CreateArray(); - cJSON_AddItemToObject(event_counter_setting, "report_counters", report_counters); - snmp_management = cJSON_CreateArray(); - cJSON_AddItemToObject(event_counter_setting, "snmp_management", snmp_management); - -#ifdef GY_OS_V_SERIES - for (int index_event_counter = 0; index_event_counter < MAX_EVENT_COUNTERS; index_event_counter++) { - a_event_counter = cJSON_CreateObject(); - cJSON_AddItemToArray(event_counters, a_event_counter); - - char str_name[50] = { 0 }; - sprintf(str_name, "Counter0%d", index_event_counter+1); - - cJSON_AddItemToObject(a_event_counter, "counter_name", cJSON_CreateString(str_name)); - cJSON_AddItemToObject(a_event_counter, "counter_cust_name", cJSON_CreateString(str_name)); - cJSON_AddItemToObject(a_event_counter, "counter_unit", cJSON_CreateString("Times")); - cJSON_AddItemToObject(a_event_counter, "reset_value", cJSON_CreateString("0")); - cJSON_AddItemToObject(a_event_counter, "enable_reset_time_interval", cJSON_CreateString("Yes")); - cJSON_AddItemToObject(a_event_counter, "reset_time_interval", cJSON_CreateString("1 minute")); - cJSON_AddItemToObject(a_event_counter, "reset_at", cJSON_CreateString("2021-02-08 17:01:13")); - cJSON_AddItemToObject(a_event_counter, "enable_time_range", cJSON_CreateString("No")); - cJSON_AddItemToObject(a_event_counter, "time_range_from", cJSON_CreateString("2021-02-08 17:01:12")); - cJSON_AddItemToObject(a_event_counter, "time_range_to", cJSON_CreateString("2021-02-08 17:01:13")); - cJSON_AddItemToObject(a_event_counter, "link_to_post_event_name", cJSON_CreateString("Camera virtual 4")); - cJSON_AddItemToObject(a_event_counter, "post_interval", cJSON_CreateString("5 minutes")); - cJSON_AddItemToObject(a_event_counter, "enable_reset_only_cloud", cJSON_CreateString("No")); - cJSON_AddItemToObject(a_event_counter, "enable_linked_to_dwell_time", cJSON_CreateString("No")); - } - - for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { - a_report = cJSON_CreateObject(); - cJSON_AddItemToArray(report_counters, a_report); - - cJSON_AddItemToObject(a_report, "counter_a", cJSON_CreateString("Counter01")); - cJSON_AddItemToObject(a_report, "counter_a_name", cJSON_CreateString("Name")); - cJSON_AddItemToObject(a_report, "counter_a_zone", cJSON_CreateString("1")); - cJSON_AddItemToObject(a_report, "counter_b", cJSON_CreateString("")); - cJSON_AddItemToObject(a_report, "counter_b_name", cJSON_CreateString("")); - cJSON_AddItemToObject(a_report, "counter_b_zone", cJSON_CreateString("0")); - cJSON_AddItemToObject(a_report, "counter_c_name", cJSON_CreateString("")); - cJSON_AddItemToObject(a_report, "report_max_value", cJSON_CreateString("100")); - cJSON_AddItemToObject(a_report, "enable_report", cJSON_CreateString("No")); - cJSON_AddItemToObject(a_report, "counter_mode", cJSON_CreateString("0")); - cJSON_AddItemToObject(a_report, "initial_icon", cJSON_CreateString("car_300X300_white")); - cJSON_AddItemToObject(a_report, "detection_output", cJSON_CreateString("No entry for cars")); - cJSON_AddItemToObject(a_report, "output_icon", cJSON_CreateString("car_1_300X300_red")); - } - - for (int index_snmp = 0; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { - a_snmp = cJSON_CreateObject(); - cJSON_AddItemToArray(snmp_management, a_snmp); - - - char str_name[50] = { 0 }; - - if (index_snmp < MAX_SNMP_MANAGEMENT - 1) { - sprintf(str_name, "SNMP %d", index_snmp + 1); - } - else { - sprintf(str_name, "%s", "Heartbeat"); - } - - cJSON_AddItemToObject(a_snmp, "snmp_event_name", cJSON_CreateString(str_name)); - cJSON_AddItemToObject(a_snmp, "snmp_version", cJSON_CreateString("v1")); - cJSON_AddItemToObject(a_snmp, "snmp_group_name", cJSON_CreateString("public")); - cJSON_AddItemToObject(a_snmp, "snmp_host_ip", cJSON_CreateString("192.168.0.200")); - cJSON_AddItemToObject(a_snmp, "snmp_host_port", cJSON_CreateString("161")); - cJSON_AddItemToObject(a_snmp, "snmp_oid", cJSON_CreateString(".1.3.6.1.2.1.1.6.0")); - cJSON_AddItemToObject(a_snmp, "snmp_value", cJSON_CreateString("mylocation")); - cJSON_AddItemToObject(a_snmp, "snmp_type", cJSON_CreateString("string")); - } -#else - for (int index_event_counter = 0; index_event_counter < MAX_EVENT_COUNTERS; index_event_counter++) { - a_event_counter = cJSON_CreateObject(); - cJSON_AddItemToArray(event_counters, a_event_counter); - - char str_reset_value[50] = { 0 }; - sprintf(str_reset_value,"%d", eventCounterList[index_event_counter].reset_value); - - cJSON_AddItemToObject(a_event_counter, "counter_name", cJSON_CreateString(eventCounterList[index_event_counter].counter_name)); - cJSON_AddItemToObject(a_event_counter, "counter_cust_name", cJSON_CreateString(eventCounterList[index_event_counter].counter_cust_name)); - cJSON_AddItemToObject(a_event_counter, "counter_unit", cJSON_CreateString("Times")); - cJSON_AddItemToObject(a_event_counter, "reset_value", cJSON_CreateString(str_reset_value)); - cJSON_AddItemToObject(a_event_counter, "enable_reset_time_interval", cJSON_CreateString(eventCounterList[index_event_counter].enable_reset_time_interval)); - cJSON_AddItemToObject(a_event_counter, "reset_time_interval", cJSON_CreateString(eventCounterList[index_event_counter].reset_time_interval)); - cJSON_AddItemToObject(a_event_counter, "reset_at", cJSON_CreateString("2021-02-08 17:01:13")); - cJSON_AddItemToObject(a_event_counter, "enable_time_range", cJSON_CreateString("No")); - cJSON_AddItemToObject(a_event_counter, "time_range_from", cJSON_CreateString("2021-02-08 17:01:12")); - cJSON_AddItemToObject(a_event_counter, "time_range_to", cJSON_CreateString("2021-02-08 17:01:13")); - cJSON_AddItemToObject(a_event_counter, "link_to_post_event_name", cJSON_CreateString(eventCounterList[index_event_counter].link_to_post_event_name)); - cJSON_AddItemToObject(a_event_counter, "post_interval", cJSON_CreateString(eventCounterList[index_event_counter].post_interval)); - cJSON_AddItemToObject(a_event_counter, "enable_reset_only_cloud", cJSON_CreateString(eventCounterList[index_event_counter].enable_reset_only_cloud)); - cJSON_AddItemToObject(a_event_counter, "enable_linked_to_dwell_time", cJSON_CreateString(eventCounterList[index_event_counter].enable_linked_to_dwell_time)); - } - - for (int index_report = 0; index_report < MAX_REPORT_COUNTERS; index_report++) { - a_report = cJSON_CreateObject(); - cJSON_AddItemToArray(report_counters, a_report); - - cJSON_AddItemToObject(a_report, "counter_a", cJSON_CreateString(reportCounterList[index_report].counter_a)); - cJSON_AddItemToObject(a_report, "counter_a_name", cJSON_CreateString(reportCounterList[index_report].counter_a_name)); - cJSON_AddItemToObject(a_report, "counter_a_zone", cJSON_CreateString(reportCounterList[index_report].counter_a_zone)); - cJSON_AddItemToObject(a_report, "counter_b", cJSON_CreateString(reportCounterList[index_report].counter_b)); - cJSON_AddItemToObject(a_report, "counter_b_name", cJSON_CreateString(reportCounterList[index_report].counter_b_name)); - cJSON_AddItemToObject(a_report, "counter_b_zone", cJSON_CreateString(reportCounterList[index_report].counter_b_zone)); - cJSON_AddItemToObject(a_report, "counter_c_name", cJSON_CreateString(reportCounterList[index_report].counter_c_name)); - cJSON_AddItemToObject(a_report, "report_max_value", cJSON_CreateString(reportCounterList[index_report].report_max_value)); - cJSON_AddItemToObject(a_report, "enable_report", cJSON_CreateString(reportCounterList[index_report].enable_report)); - cJSON_AddItemToObject(a_report, "counter_mode", cJSON_CreateString(reportCounterList[index_report].counter_mode)); - cJSON_AddItemToObject(a_report, "initial_icon", cJSON_CreateString(reportCounterList[index_report].initial_icon)); - cJSON_AddItemToObject(a_report, "detection_output", cJSON_CreateString(reportCounterList[index_report].detection_output)); - cJSON_AddItemToObject(a_report, "output_icon", cJSON_CreateString(reportCounterList[index_report].output_icon)); - } - - for (int index_snmp = 0; index_snmp < MAX_SNMP_MANAGEMENT; index_snmp++) { - a_snmp = cJSON_CreateObject(); - cJSON_AddItemToArray(snmp_management, a_snmp); - - cJSON_AddItemToObject(a_snmp, "snmp_event_name", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_event_name)); - cJSON_AddItemToObject(a_snmp, "snmp_version", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_version)); - cJSON_AddItemToObject(a_snmp, "snmp_group_name", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_group_name)); - cJSON_AddItemToObject(a_snmp, "snmp_host_ip", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_host_ip)); - cJSON_AddItemToObject(a_snmp, "snmp_host_port", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_host_port)); - cJSON_AddItemToObject(a_snmp, "snmp_oid", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_oid)); - cJSON_AddItemToObject(a_snmp, "snmp_value", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_value)); - cJSON_AddItemToObject(a_snmp, "snmp_type", cJSON_CreateString(SNMPManagementList[index_snmp].snmp_type)); - } -#endif - cJSON_AddItemToObject(email_setting, "email_content", cJSON_CreateString(emailData.email_content)); - - char *filename; - filename = eventsPATH; - - int del = remove(filename); - if (!del) { - //printf("events is Deleted successfully."); - } - else { - printf("events cannot be Deleted.\n"); - } - - char* JsonString = cJSON_Print(new_data_root); - FILE *fp; - - if ((fp = fopen(filename, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - } - else - { - fclose(fp); - printf("Fail to open events.json \n"); - } - if (JsonString) { - free(JsonString); - JsonString = NULL; - } - if (new_data_root) { - cJSON_Delete(new_data_root); - new_data_root = NULL; - } - new_data_write_to_events_file_flag = 0; - } - - //printf("111-2 get password = %s \n", accountData[0].account_password); -#ifdef GY_OS_AMBA - if (new_data_write_to_tof_file_flag == 1) { - cJSON *new_data_root,*new_tof_camera; - - new_data_root = cJSON_CreateObject(); - new_tof_camera = cJSON_CreateObject(); - - cJSON_AddItemToObject(new_data_root, "version", cJSON_CreateNumber(tofData.tof_version)); - cJSON_AddItemToObject(new_data_root, "debug", cJSON_CreateBool(tofData.tof_debug)); - cJSON_AddItemToObject(new_data_root, "install_angle", cJSON_CreateNumber(tofData.tof_install_angle)); - cJSON_AddItemToObject(new_data_root, "enable_camera", cJSON_CreateBool(tofData.tof_enable_camera)); - cJSON_AddItemToObject(new_data_root, "enable_tof_ground", cJSON_CreateBool(tofData.enable_tof_ground)); - cJSON_AddItemToObject(new_data_root, "enable_tof_wall", cJSON_CreateBool(tofData.enable_tof_wall)); - - cJSON_AddItemToObject(new_data_root, "distance_options", cJSON_CreateString(tofData.distance_options)); - cJSON_AddItemToObject(new_data_root, "distance_min_max", cJSON_CreateString(tofData.distance_min_max)); - cJSON_AddItemToObject(new_data_root, "distance_threshold", cJSON_CreateString(tofData.distance_threshold)); - cJSON_AddItemToObject(new_data_root, "height_options", cJSON_CreateString(tofData.height_options)); - cJSON_AddItemToObject(new_data_root, "height_min_max", cJSON_CreateString(tofData.height_min_max)); - cJSON_AddItemToObject(new_data_root, "height_threshold", cJSON_CreateString(tofData.height_threshold)); - - cJSON_AddItemToObject(new_data_root, "ground_x", cJSON_CreateString(tofData.ground_x)); - cJSON_AddItemToObject(new_data_root, "ground_y", cJSON_CreateString(tofData.ground_y)); - - cJSON_AddItemToObject(new_data_root, "camera", new_tof_camera); - - cJSON_AddItemToObject(new_tof_camera, "camera_ip", cJSON_CreateString(tofData.tof_camera_ip)); - cJSON_AddItemToObject(new_tof_camera, "camera_port", cJSON_CreateString(tofData.tof_camera_port)); - cJSON_AddItemToObject(new_tof_camera, "camera_sub_url", cJSON_CreateString(tofData.tof_camera_sub_url)); - cJSON_AddItemToObject(new_tof_camera, "auth_key", cJSON_CreateString(tofData.tof_auth_key)); - cJSON_AddItemToObject(new_tof_camera, "ip_setting", cJSON_CreateBool(tofData.tof_ip_setting)); - - char buf_account[512] = { 0 }; - urldecode((unsigned char *)tofData.tof_camera_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)tofData.tof_camera_password, (unsigned char *)buf_account2); - - cJSON_AddItemToObject(new_tof_camera, "camera_username", cJSON_CreateString(buf_account)); - cJSON_AddItemToObject(new_tof_camera, "camera_password", cJSON_CreateString(buf_account2)); - - char *filename; - filename = tofPATH; - - int del = remove(filename); - if (!del) { - //printf("tof is Deleted successfully."); - } - else { - printf("tof cannot be Deleted.\n"); - } - - char* JsonString = cJSON_Print(new_data_root); - FILE *fp; - - if ((fp = fopen(filename, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - } - else - { - fclose(fp); - printf("Fail to open events.json \n"); - } - if (JsonString) { - free(JsonString); - JsonString = NULL; - } - if (new_data_root) { - cJSON_Delete(new_data_root); - new_data_root = NULL; - } - new_data_write_to_tof_file_flag = 0; - } -#endif - //20201123 sophia add - if (root) { - cJSON_Delete(root); - root = NULL; - } - if (tof_root) { - cJSON_Delete(tof_root); - tof_root = NULL; - } - if (n_root) { - cJSON_Delete(n_root); - n_root = NULL; - } - if (keyRoot) { - cJSON_Delete(keyRoot); - keyRoot = NULL; - } - - //http_ip_address = (ip_address) ? ip_address : NULL; - //http_http_port = http_port; - - http_sleep_interval = 2; - //http_dataset_version = dataset_version; - //set base time for reload - struct tm* b_time = localtime(&start_time);; - memset(b_time, 0, sizeof(struct tm)); - b_time->tm_hour = 0; // 24 hour format, 0 = midnight, 23 = 11pm - b_time->tm_min = 0; - b_time->tm_sec = 0; - b_time->tm_mon = 0; // 0 based, 0 = jan, 11 = dec - b_time->tm_mday = 1; - b_time->tm_year = 100; // current - 1900 - - //time_t base_time = mktime(b_time); - - //initialize socketRecords - /*for (int i = 0; i < sizeof(socketRecords); i++) - { - socketRecords[i].sock = INVALID_SOCKET; - socketRecords[i].last_recv_time = 0; - }*/ - - int layer_idx = 0; -#ifdef GY_OS_NOVA - cJSON *root_weight,*net_number,*net_info_list,*net_info,*weight_name,*anc_name,*label_name,*feature_type; - root_weight = cJSON_CreateObject(); - net_info_list = cJSON_CreateArray(); - cJSON_AddItemToObject(root_weight, "net_info_list", net_info_list); -#endif - /*for (int i = 0; i < MAX_LAYER_NUM; i++) - { - if (layerUTF8Country[i] != NULL) - { - free(layerUTF8Country[i]); - layerUTF8Country[i] = NULL; - } - - layerUTF8Country[i] = malloc(128); - strcpy(layerUTF8Country[layer_idx], ""); - }*/ - - ///Steven MARK TEMP - ////按照license key載入不同網路 //MAX_IMG_BUFF_SIZE * MAX_CLIENT_SOCKET - - //printf("\nKKKKKKKKKKKKKKKK:1\n"); - /* - printf("\n--------------------\n"); - printf("\nfeatureType: 0x%x\n", featureType); - printf("\nfeatureType2: 0x%x\n", featureType2); - printf("\n--------------------\n");*/ - - //printf("\n--------------------------:5\n"); - - //printf("111-1 get password = %s \n", accountData[0].account_password); - - if (IsExistingWeight(featureType, featureType2)) { - -#ifdef GY_OS_AMBA - //AMBA Weight - if (strcmp(WeightFileModeName, "mod004") == 0) { - if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && - ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP - )) ///Steven TEMP MARK - { - if (layer_idx < MAX_LAYER_NUM) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AITHERMAL/AMB_GYNet_AITHERMAL_WGT.aes", "/emmc/plugin/Aida/AITHERMAL/cavalry_GYNet_AITHERMAL_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITHERMAL/cavalry_GYNet_AITHERMAL_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AITHERMAL/AMB_GYNet_AITHERMAL_ANC.aes", "/emmc/plugin/Aida/AITHERMAL/anchors_GYNet_AITHERMAL_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITHERMAL/anchors_GYNet_AITHERMAL_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITHERMAL/GYNet_AITHERMAL_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITHERMAL/AMB_AITHERMAL_VER.txt,"); - - if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AIFLOW; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - } - else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AIAREA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - } - else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AICAP; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - } - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITHERMAL/cavalry_GYNet_AITHERMAL_WGT.bin"); - } - } - - //if (g_check_if_OK_thermal == 1 && g_IsPTZDevice == 1) - if(g_dual_sensor == 1) - { - if (layer_idx < MAX_LAYER_NUM) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); - - if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AIFLOW; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - } - else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AIAREA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - } - else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AICAP; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - } - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); - } - } - } - } - } - else { - if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && - ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP - )) ///Steven TEMP MARK - { - if (layer_idx < MAX_LAYER_NUM) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); - - if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AIFLOW; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - } - else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AIAREA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - } - else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AICAP; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - } - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); - } - } - } - else { - if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) { - featureType = featureType | FEATURE_TRAF_DET; - featureType2 = featureType2 | FEATURE_AICAP; - stAMBAcontent.featureType = featureType; - stAMBAcontent.featureType2 = featureType2; - - if (layer_idx < MAX_LAYER_NUM) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); - - if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AICAP; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - - g_IsHelm_without_car = 1; - } - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); - } - } - } - - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - (strcmp(WeightFileModeName, "mod003") == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK)) { - featureType = featureType | FEATURE_TRAF_DET; - featureType2 = featureType2 | FEATURE_AIFLOW; - stAMBAcontent.featureType = featureType; - stAMBAcontent.featureType2 = featureType2; - - if (layer_idx < MAX_LAYER_NUM) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_WGT.aes", "/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AITRAFFIC/AMB_GYNet_Traffic_Tiny_ANC.aes", "/emmc/plugin/Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/anchors_GYNet_Traffic_Tiny_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/GYNet_Traffic_Tiny_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/AMB_Traffic_Tiny_VER.txt,"); - - - if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AIFLOW; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - - g_IsHelm_without_car = 1; - } - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITRAFFIC/cavalry_GYNet_Traffic_Tiny_WGT.bin"); - } - } - } - } - } - //AMBA Weight - if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0) { - if (layer_idx < MAX_LAYER_NUM) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AIGARBAGE/AMB_GYNet_AIGARBAGE_WGT.aes", "/emmc/plugin/Aida/AIGARBAGE/cavalry_GYNet_AIGARBAGE_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIGARBAGE/cavalry_GYNet_AIGARBAGE_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIGARBAGE/AMB_GYNet_AIGARBAGE_ANC.aes", "/emmc/plugin/Aida/AIGARBAGE/anchors_GYNet_AIGARBAGE_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIGARBAGE/anchors_GYNet_AIGARBAGE_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIGARBAGE/GYNet_AIGARBAGE_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIGARBAGE/AMB_AIGARBAGE_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AIGARBAGE; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIGARBAGE; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIGARBAGE/cavalry_GYNet_AIGARBAGE_WGT.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_LPR_LOGO) == FEATURE_LPR_LOGO) - { - if (layer_idx < MAX_LAYER_NUM) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AICarMake/AMB_GYNet_LOGO_WGT.aes", "/emmc/plugin/Aida/AICarMake/cavalry_GYNet_LOGO_WGT.bin", key, 0, false); - - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AICarMake/cavalry_GYNet_LOGO_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AICarMake/AMB_GYNet_LOGO_ANC.aes", "/emmc/plugin/Aida/AICarMake/anchors_GYNet_LOGO_ANC.txt", key, 0, false); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AICarMake/anchors_GYNet_LOGO_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AICarMake/GYNet_LOGO_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AICarMake/AMB_LOGO_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_LOGO; - layerFeatureType2[layer_idx] = FEATURE_LPR_LOGO; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_LOGO; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_LOGO; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AICarMake/cavalry_GYNet_LOGO_WGT.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE /*&& (featureType2 & FEATURE_DET_AIFIRE) == FEATURE_DET_AIFIRE*/) - { - if (layer_idx < MAX_LAYER_NUM) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AIFIRE/AMB_GYNet_AIFIRE_WGT.aes", "/emmc/plugin/Aida/AIFIRE/cavalry_GYNet_AIFIRE_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIFIRE/cavalry_GYNet_AIFIRE_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIFIRE/AMB_GYNet_AIFIRE_ANC.aes", "/emmc/plugin/Aida/AIFIRE/anchors_GYNet_AIFIRE_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIFIRE/anchors_GYNet_AIFIRE_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIFIRE/GYNet_AIFIRE_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIFIRE/AMB_AIFIRE_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_AIFIRE; - layerFeatureType2[layer_idx] = FEATURE_DET_AIFIRE; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_AIFIRE; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_DET_AIFIRE; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIFIRE/cavalry_GYNet_AIFIRE_WGT.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) ///Steven TEMP MARK - { - if (layer_idx < MAX_LAYER_NUM) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AIAERO/AMB_GYNet_AIAERO_WGT.aes", "/emmc/plugin/Aida/AIAERO/cavalry_GYNet_AIAERO_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIAERO/cavalry_GYNet_AIAERO_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIAERO/AMB_GYNet_AIAERO_ANC.aes", "/emmc/plugin/Aida/AIAERO/anchors_GYNet_AIAERO_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIAERO/anchors_GYNet_AIAERO_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIAERO/GYNet_AIAERO_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIAERO/AMB_AIAERO_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AIAREO; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREO; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIAERO/cavalry_GYNet_AIAERO_WGT.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) ///Steven TEMP MARK FEATURE_HUM_DET - { - if (layer_idx < MAX_LAYER_NUM) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AISAFTY/AMB_GYNet_AISAFTY_WGT.aes", "/emmc/plugin/Aida/AISAFTY/cavalry_GYNet_AISAFTY_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AISAFTY/cavalry_GYNet_AISAFTY_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AISAFTY/AMB_GYNet_AISAFTY_ANC.aes", "/emmc/plugin/Aida/AISAFTY/anchors_GYNet_AISAFTY_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AISAFTY/anchors_GYNet_AISAFTY_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AISAFTY/GYNet_AISAFTY_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AISAFTY/AMB_AISAFTY_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_HUM_DET; - layerFeatureType2[layer_idx] = FEATURE_AIHELM; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIHELM; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AISAFTY/cavalry_GYNet_AISAFTY_WGT.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) ///Steven TEMP MARK FEATURE_HUM_DET - { - if (layer_idx < MAX_LAYER_NUM) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AIRAILWAY/AMB_GYNet_AIRAILWAY_WGT.aes", "/emmc/plugin/Aida/AIRAILWAY/cavalry_GYNet_AIRAILWAY_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIRAILWAY/cavalry_GYNet_AIRAILWAY_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIRAILWAY/AMB_GYNet_AIRAILWAY_ANC.aes", "/emmc/plugin/Aida/AIRAILWAY/anchors_GYNet_AIRAILWAY_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIRAILWAY/anchors_GYNet_AIRAILWAY_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIRAILWAY/GYNet_AIRAILWAY_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIRAILWAY/AMB_AIRAILWAY_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_AIRAIL; - layerFeatureType2[layer_idx] = FEATURE_AIFLOW; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_AIRAIL; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIRAILWAY/cavalry_GYNet_AIRAILWAY_WGT.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) ///Steven TEMP MARK FEATURE_HUM_DET - { - if (layer_idx < MAX_LAYER_NUM) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AISPORTS/AMB_GYNet_AISPORTS_WGT.aes", "/emmc/plugin/Aida/AISPORTS/cavalry_GYNet_AISPORTS_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AISPORTS/cavalry_GYNet_AISPORTS_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AISPORTS/AMB_GYNet_AISPORTS_ANC.aes", "/emmc/plugin/Aida/AISPORTS/anchors_GYNet_AISPORTS_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AISPORTS/anchors_GYNet_AISPORTS_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AISPORTS/GYNet_AISPORTS_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AISPORTS/AMB_AISPORTS_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AISPORTS; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AISPORTS; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AISPORTS/cavalry_GYNet_AISPORTS_WGT.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) ///Steven TEMP MARK - { - if (layer_idx < MAX_LAYER_NUM) - { - if (strcmp(WeightFileModeName, "mod003") != 0) { - LILIN_File_Decryption("/emmc/plugin/Aida/AIHUMAN/AMB_GYNet_Human_WGT.aes", "/emmc/plugin/Aida/AIHUMAN/cavalry_GYNet_Human_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIHUMAN/cavalry_GYNet_Human_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIHUMAN/AMB_GYNet_Human_ANC.aes", "/emmc/plugin/Aida/AIHUMAN/anchors_GYNet_Human_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIHUMAN/anchors_GYNet_Human_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIHUMAN/GYNet_Human_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIHUMAN/AMB_Human_VER.txt,"); - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIHUMAN/cavalry_GYNet_Human_WGT.bin"); - } - } - else { - LILIN_File_Decryption("/emmc/plugin/Aida/AIGENDER/AMB_GYNet_AIGENDER_WGT.aes", "/emmc/plugin/Aida/AIGENDER/cavalry_GYNet_AIGENDER_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIGENDER/cavalry_GYNet_AIGENDER_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIGENDER/AMB_GYNet_AIGENDER_ANC.aes", "/emmc/plugin/Aida/AIGENDER/anchors_GYNet_AIGENDER_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIGENDER/anchors_GYNet_AIGENDER_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIGENDER/GYNet_AIGENDER_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIGENDER/AMB_AIGENDER_VER.txt,"); - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIGENDER/cavalry_GYNet_AIGENDER_WGT.bin"); - } - } - - layerFeatureType[layer_idx] = FEATURE_HUM_DET; - layerFeatureType2[layer_idx] = FEATURE_AIMASK; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIMASK; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - - - } - } - //AMBA Weight - if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) - { - if (layer_idx < MAX_LAYER_NUM) - { - if (strcmp(WeightFileModeName, "mod003") != 0) { - LILIN_File_Decryption("/emmc/plugin/Aida/AIAML/AMB_GYNet_AIAML_WGT.aes", "/emmc/plugin/Aida/AIAML/cavalry_GYNet_AIAML_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIAML/cavalry_GYNet_AIAML_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIAML/AMB_GYNet_AIAML_ANC.aes", "/emmc/plugin/Aida/AIAML/anchors_GYNet_AIAML_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIAML/anchors_GYNet_AIAML_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIAML/GYNet_AIAML_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIAML/AMB_AIAML_VER.txt,"); - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIAML/cavalry_GYNet_AIAML_WGT.bin"); - } - } - else { - LILIN_File_Decryption("/emmc/plugin/Aida/AIFRONTBACK/AMB_GYNet_AIFRONTBACK_WGT.aes", "/emmc/plugin/Aida/AIFRONTBACK/cavalry_GYNet_AIFRONTBACK_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIFRONTBACK/cavalry_GYNet_AIFRONTBACK_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIFRONTBACK/AMB_GYNet_AIFRONTBACK_ANC.aes", "/emmc/plugin/Aida/AIFRONTBACK/anchors_GYNet_AIFRONTBACK_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIFRONTBACK/anchors_GYNet_AIFRONTBACK_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIFRONTBACK/GYNet_AIFRONTBACK_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIFRONTBACK/AMB_AIFRONTBACK_VER.txt,"); - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIFRONTBACK/cavalry_GYNet_AIFRONTBACK_WGT.bin"); - } - } - - layerFeatureType[layer_idx] = FEATURE_HUM_DET; - layerFeatureType2[layer_idx] = FEATURE_AIAML; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAML; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - } - } - //AMBA Weight - if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) - { - if (layer_idx < MAX_LAYER_NUM) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AISHIP/AMB_GYNet_AISHIP_WGT.aes", "/emmc/plugin/Aida/AISHIP/cavalry_GYNet_AISHIP_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AISHIP/cavalry_GYNet_AISHIP_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AISHIP/AMB_GYNet_AISHIP_ANC.aes", "/emmc/plugin/Aida/AISHIP/anchors_GYNet_AISHIP_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AISHIP/anchors_GYNet_AISHIP_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AISHIP/GYNet_AISHIP_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AISHIP/AMB_AISHIP_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_HUM_DET; - layerFeatureType2[layer_idx] = FEATURE_AISHIP; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AISHIP; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AISHIP/cavalry_GYNet_AISHIP_WGT.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) - { - if (layer_idx < MAX_LAYER_NUM) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AIPRODUCTION/AMB_GYNet_AIPRODUCTION_WGT.aes", "/emmc/plugin/Aida/AIPRODUCTION/cavalry_GYNet_AIPRODUCTION_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIPRODUCTION/cavalry_GYNet_AIPRODUCTION_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIPRODUCTION/AMB_GYNet_AIPRODUCTION_ANC.aes", "/emmc/plugin/Aida/AIPRODUCTION/anchors_GYNet_AIPRODUCTION_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIPRODUCTION/anchors_GYNet_AIPRODUCTION_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIPRODUCTION/GYNet_AIPRODUCTION_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIPRODUCTION/AMB_AIPRODUCTION_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_HUM_DET; - layerFeatureType2[layer_idx] = FEATURE_AIPRODUCTION; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIPRODUCTION; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIPRODUCTION/cavalry_GYNet_AIPRODUCTION_WGT.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_LPR_TWN) == FEATURE_LPR_TWN) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - //printf("feature type = FEATURE_LPR_TWN\n"); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_LPD_WGT_TWN.bin", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_OCR_WGT_TWN.bin", key, 0, false); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/cavalry_GYNet_LPD_WGT_TWN.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/cavalry_GYNet_OCR_WGT_TWN.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRTWN/anchors_GYNet_LPD_ANC_TWN.txt", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRTWN/anchors_GYNet_OCR_ANC_TWN.txt", key, 0, false); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/anchors_GYNet_LPD_ANC_TWN.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/anchors_GYNet_OCR_ANC_TWN.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_LPD_Label_TWN.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_OCR_Label_TWN.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTWN/AMB_ANPR_TWN_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_TWN; - layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - layerFeatureType[layer_idx] = FEATURE_LPR_TWN; - layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_LPD_WGT_TWN.bin"); - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTWN/cavalry_GYNet_OCR_WGT_TWN.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_LPR_EUR) == FEATURE_LPR_EUR)//20201216 Jim add - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - //printf("feature type = FEATURE_LPR_EUR\n"); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_LPD_WGT_EUR.bin", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_OCR_WGT_EUR.bin", key, 0, false); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/cavalry_GYNet_LPD_WGT_EUR.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/cavalry_GYNet_OCR_WGT_EUR.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPREUR/anchors_GYNet_LPD_ANC_EUR.txt", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPREUR/anchors_GYNet_OCR_ANC_EUR.txt", key, 0, false); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/anchors_GYNet_LPD_ANC_EUR.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/anchors_GYNet_OCR_ANC_EUR.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_LPD_Label_EUR.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_OCR_Label_EUR.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPREUR/AMB_ANPR_EUR_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_EUR; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; - stAMBAcontent.tiny_enable[layer_idx] = 1; - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - layerFeatureType[layer_idx] = FEATURE_LPR_EUR; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; - stAMBAcontent.tiny_enable[layer_idx] = 1; - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_LPD_WGT_EUR.bin"); - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPREUR/cavalry_GYNet_OCR_WGT_EUR.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_LPR_SEA) == FEATURE_LPR_SEA || - (featureType & FEATURE_LPR_VNM) == FEATURE_LPR_VNM || - (featureType & FEATURE_LPR_IDN) == FEATURE_LPR_IDN) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - //printf("feature type = FEATURE_LPR_SEA\n"); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_LPD_SEA_WGT.aes", "/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_LPD_WGT_SEA.bin", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_OCR_SEA_WGT.aes", "/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_OCR_WGT_SEA.bin", key, 0, false); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/cavalry_GYNet_LPD_WGT_SEA.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/cavalry_GYNet_OCR_WGT_SEA.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_LPD_SEA_ANC.aes", "/emmc/plugin/Aida/AIANPRSEA/anchors_GYNet_LPD_ANC_SEA.txt", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRSEA/AMB_GYNet_OCR_SEA_ANC.aes", "/emmc/plugin/Aida/AIANPRSEA/anchors_GYNet_OCR_ANC_SEA.txt", key, 0, false); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/anchors_GYNet_LPD_ANC_SEA.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/anchors_GYNet_OCR_ANC_SEA.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_LPD_Label_SEA.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_OCR_Label_SEA.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRSEA/AMB_ANPR_SEA_VER.txt,"); - - if ((featureType & FEATURE_LPR_SEA) == FEATURE_LPR_SEA) { - layerFeatureType[layer_idx] = FEATURE_LPR_SEA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; - stAMBAcontent.tiny_enable[layer_idx] = 1; - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - layerFeatureType[layer_idx] = FEATURE_LPR_SEA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; - stAMBAcontent.tiny_enable[layer_idx] = 1; - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - } - else if ((featureType & FEATURE_LPR_VNM) == FEATURE_LPR_VNM) { - layerFeatureType[layer_idx] = FEATURE_LPR_VNM; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_VNM; - stAMBAcontent.tiny_enable[layer_idx] = 1; - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - layerFeatureType[layer_idx] = FEATURE_LPR_VNM; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_VNM; - stAMBAcontent.tiny_enable[layer_idx] = 1; - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - } - else if ((featureType & FEATURE_LPR_IDN) == FEATURE_LPR_IDN) { - layerFeatureType[layer_idx] = FEATURE_LPR_IDN; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_IDN; - stAMBAcontent.tiny_enable[layer_idx] = 1; - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - layerFeatureType[layer_idx] = FEATURE_LPR_IDN; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_IDN; - stAMBAcontent.tiny_enable[layer_idx] = 1; - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - } - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_LPD_WGT_SEA.bin"); - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRSEA/cavalry_GYNet_OCR_WGT_SEA.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_LPR_MEA) == FEATURE_LPR_MEA)//20201216 Jim add - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - //printf("feature type = FEATURE_LPR_MEA\n"); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_LPD_MEA_WGT.aes", "/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_LPD_WGT_MEA.bin", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_OCR_MEA_WGT.aes", "/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_OCR_WGT_MEA.bin", key, 0, false); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/cavalry_GYNet_LPD_WGT_MEA.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/cavalry_GYNet_OCR_WGT_MEA.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_LPD_MEA_ANC.aes", "/emmc/plugin/Aida/AIANPRMEA/anchors_GYNet_LPD_ANC_MEA.txt", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRMEA/AMB_GYNet_OCR_MEA_ANC.aes", "/emmc/plugin/Aida/AIANPRMEA/anchors_GYNet_OCR_ANC_MEA.txt", key, 0, false); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/anchors_GYNet_LPD_ANC_MEA.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/anchors_GYNet_OCR_ANC_MEA.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_LPD_Label_MEA.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_OCR_Label_MEA.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRMEA/AMB_ANPR_MEA_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_MEA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; - stAMBAcontent.tiny_enable[layer_idx] = 1; - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - layerFeatureType[layer_idx] = FEATURE_LPR_MEA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; - stAMBAcontent.tiny_enable[layer_idx] = 1; - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_LPD_WGT_MEA.bin"); - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRMEA/cavalry_GYNet_OCR_WGT_MEA.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_LPR_USA) == FEATURE_LPR_USA) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - //printf("feature type = FEATURE_LPR_USA\n"); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_LPD_WGT_USA.bin", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_OCR_WGT_USA.bin", key, 0, false); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRUSA/cavalry_GYNet_LPD_WGT_USA.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRUSA/cavalry_GYNet_OCR_WGT_USA.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRUSA/anchors_GYNet_LPD_ANC_USA.txt", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRUSA/anchors_GYNet_OCR_ANC_USA.txt", key, 0, false); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRUSA/anchors_GYNet_LPD_ANC_USA.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRUSA/anchors_GYNet_OCR_ANC_USA.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_LPD_Label_USA.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_OCR_Label_USA.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRUSA/AMB_ANPR_USA_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_USA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - layerFeatureType[layer_idx] = FEATURE_LPR_USA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_LPD_WGT_USA.bin"); - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRUSA/cavalry_GYNet_OCR_WGT_USA.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_LPR_GBR) == FEATURE_LPR_GBR) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - //printf("feature type = FEATURE_LPR_GBR\n"); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_LPD_WGT_GBR.bin", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_WGT.aes", "/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_OCR_WGT_GBR.bin", key, 0, false); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRGBR/cavalry_GYNet_LPD_WGT_GBR.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRGBR/cavalry_GYNet_OCR_WGT_GBR.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_LPD_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPRGBR/anchors_GYNet_LPD_ANC_GBR.txt", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPREUR/AMB_GYNet_OCR_EUR_ANC.aes", "/emmc/plugin/Aida/AIANPRGBR/anchors_GYNet_OCR_ANC_GBR.txt", key, 0, false); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRGBR/anchors_GYNet_LPD_ANC_GBR.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRGBR/anchors_GYNet_OCR_ANC_GBR.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_LPD_Label_GBR.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_OCR_Label_GBR.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRGBR/AMB_ANPR_GBR_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_GBR; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; - stAMBAcontent.tiny_enable[layer_idx] = 1; - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - layerFeatureType[layer_idx] = FEATURE_LPR_GBR; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; - stAMBAcontent.tiny_enable[layer_idx] = 1; - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_LPD_WGT_GBR.bin"); - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRGBR/cavalry_GYNet_OCR_WGT_GBR.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_LPR_JPN) == FEATURE_LPR_JPN) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_LPD_WGT_JPN.bin", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_WGT.aes", "/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_OCR_WGT_JPN.bin", key, 0, false); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRJPN/cavalry_GYNet_LPD_WGT_JPN.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRJPN/cavalry_GYNet_OCR_WGT_JPN.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRJPN/anchors_GYNet_LPD_ANC_JPN.txt", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_ANC.aes", "/emmc/plugin/Aida/AIANPRJPN/anchors_GYNet_OCR_ANC_JPN.txt", key, 0, false); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRJPN/anchors_GYNet_LPD_ANC_JPN.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRJPN/anchors_GYNet_OCR_ANC_JPN.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_LPD_Label_JPN.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_OCR_Label_JPN.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRJPN/AMB_ANPR_JPN_VER.txt,"); - - - layerFeatureType[layer_idx] = FEATURE_LPR_JPN; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - //Second setting is for OCR det. - layerFeatureType[layer_idx] = FEATURE_LPR_JPN; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_LPD_WGT_JPN.bin"); - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRJPN/cavalry_GYNet_OCR_WGT_JPN.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_LPR_THA) == FEATURE_LPR_THA) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_LPD_WGT_THA.bin", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTHA/AMB_GYNet_OCR_THA_WGT.aes", "/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_OCR_WGT_THA.bin", key, 0, false); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/cavalry_GYNet_LPD_WGT_THA.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/cavalry_GYNet_OCR_WGT_THA.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRTHA/anchors_GYNet_LPD_ANC_THA.txt", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTHA/AMB_GYNet_OCR_THA_ANC.aes", "/emmc/plugin/Aida/AIANPRTHA/anchors_GYNet_OCR_ANC_THA.txt", key, 0, false); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/anchors_GYNet_LPD_ANC_THA.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/anchors_GYNet_OCR_ANC_THA.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_LPD_Label_THA.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_OCR_Label_THA.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTHA/AMB_ANPR_THA_VER.txt,"); - - - layerFeatureType[layer_idx] = FEATURE_LPR_THA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - layerFeatureType[layer_idx] = FEATURE_LPR_THA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_LPD_WGT_THA.bin"); - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRTHA/cavalry_GYNet_OCR_WGT_THA.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_LPR_BGD) == FEATURE_LPR_BGD) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_LPD_BGD_WGT.aes", "/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_LPD_WGT_BGD.bin", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_OCR_BGD_WGT.aes", "/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_OCR_WGT_BGD.bin", key, 0, false); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRBGD/cavalry_GYNet_LPD_WGT_BGD.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRBGD/cavalry_GYNet_OCR_WGT_BGD.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_LPD_BGD_ANC.aes", "/emmc/plugin/Aida/AIANPRBGD/anchors_GYNet_LPD_ANC_BGD.txt", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRBGD/AMB_GYNet_OCR_BGD_ANC.aes", "/emmc/plugin/Aida/AIANPRBGD/anchors_GYNet_OCR_ANC_BGD.txt", key, 0, false); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRBGD/anchors_GYNet_LPD_ANC_BGD.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRBGD/anchors_GYNet_OCR_ANC_BGD.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRBGD/GYNet_LPD_Label_BGD.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRBGD/GYNet_OCR_Label_BGD.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRBGD/AMB_ANPR_BGD_VER.txt,"); - - - layerFeatureType[layer_idx] = FEATURE_LPR_BGD; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_BGD; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - layerFeatureType[layer_idx] = FEATURE_LPR_BGD; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_BGD; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_LPD_WGT_BGD.bin"); - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRBGD/cavalry_GYNet_OCR_WGT_BGD.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_LPR_PHL) == FEATURE_LPR_PHL) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_LPD_WGT_PHL.bin", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_OCR_WGT_PHL.bin", key, 0, false); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRPHL/cavalry_GYNet_LPD_WGT_PHL.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRPHL/cavalry_GYNet_OCR_WGT_PHL.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRPHL/anchors_GYNet_LPD_ANC_PHL.txt", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_OCR_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRPHL/anchors_GYNet_OCR_ANC_PHL.txt", key, 0, false); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRPHL/anchors_GYNet_LPD_ANC_PHL.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRPHL/anchors_GYNet_OCR_ANC_PHL.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_LPD_Label_PHL.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_OCR_Label_PHL.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRPHL/AMB_ANPR_PHL_VER.txt,"); - - - layerFeatureType[layer_idx] = FEATURE_LPR_PHL; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - layerFeatureType[layer_idx] = FEATURE_LPR_PHL; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_LPD_WGT_PHL.bin"); - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRPHL/cavalry_GYNet_OCR_WGT_PHL.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_LPR_CNT) == FEATURE_LPR_CNT) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_LPD_CNT_WGT.aes", "/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_LPD_WGT_CNT.bin", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_OCR_CNT_WGT.aes", "/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_OCR_WGT_CNT.bin", key, 0, false); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRCNT/cavalry_GYNet_LPD_WGT_CNT.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRCNT/cavalry_GYNet_OCR_WGT_CNT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_LPD_CNT_ANC.aes", "/emmc/plugin/Aida/AIANPRCNT/anchors_GYNet_LPD_ANC_CNT.txt", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRCNT/AMB_GYNet_OCR_CNT_ANC.aes", "/emmc/plugin/Aida/AIANPRCNT/anchors_GYNet_OCR_ANC_CNT.txt", key, 0, false); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRCNT/anchors_GYNet_LPD_ANC_CNT.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRCNT/anchors_GYNet_OCR_ANC_CNT.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRCNT/GYNet_LPD_Label_CNT.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRCNT/GYNet_OCR_Label_CNT.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRCNT/AMB_ANPR_CNT_VER.txt,"); - - - layerFeatureType[layer_idx] = FEATURE_LPR_CNT; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_CNT; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - layerFeatureType[layer_idx] = FEATURE_LPR_CNT; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_CNT; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_LPD_WGT_CNT.bin"); - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRCNT/cavalry_GYNet_OCR_WGT_CNT.bin"); - } - } - } - //AMBA Weight - if ((featureType & FEATURE_LPR_AUS) == FEATURE_LPR_AUS) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_WGT.aes", "/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_LPD_WGT_AUS.bin", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_WGT.aes", "/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_OCR_WGT_AUS.bin", key, 0, false); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRAUS/cavalry_GYNet_LPD_WGT_AUS.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRAUS/cavalry_GYNet_OCR_WGT_AUS.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRTWN/AMB_GYNet_LPD_TWN_ANC.aes", "/emmc/plugin/Aida/AIANPRAUS/anchors_GYNet_LPD_ANC_AUS.txt", key, 0, false); - LILIN_File_Decryption("/emmc/plugin/Aida/AIANPRJPN/AMB_GYNet_OCR_JPN_ANC.aes", "/emmc/plugin/Aida/AIANPRAUS/anchors_GYNet_OCR_ANC_AUS.txt", key, 0, false); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRAUS/anchors_GYNet_LPD_ANC_AUS.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRAUS/anchors_GYNet_OCR_ANC_AUS.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_LPD_Label_AUS.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_OCR_Label_AUS.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRAUS/AMB_ANPR_AUS_VER.txt,"); - - - layerFeatureType[layer_idx] = FEATURE_LPR_AUS; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; - stAMBAcontent.tiny_enable[layer_idx] = 1; - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - layerFeatureType[layer_idx] = FEATURE_LPR_AUS; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; - stAMBAcontent.tiny_enable[layer_idx] = 1; - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_LPD_WGT_AUS.bin"); - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AIANPRAUS/cavalry_GYNet_OCR_WGT_AUS.bin"); - } - } - } - //AMBA Weight - if (g_IsToFDevice == 1) - { - if (layer_idx < MAX_LAYER_NUM) - { - LILIN_File_Decryption("/emmc/plugin/Aida/AITOF/AMB_GYNet_AITOF_WGT.aes", "/emmc/plugin/Aida/AITOF/cavalry_GYNet_AITOF_WGT.bin", key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITOF/cavalry_GYNet_AITOF_WGT.bin,"); - - LILIN_File_Decryption("/emmc/plugin/Aida/AITOF/AMB_GYNet_AITOF_ANC.aes", "/emmc/plugin/Aida/AITOF/anchors_GYNet_AITOF_ANC.txt", key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITOF/anchors_GYNet_AITOF_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITOF/GYNet_AITOF_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITOF/AMB_AITOF_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_HUM_DET; - layerFeatureType2[layer_idx] = FEATURE_AITOF; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AITOF; - stAMBAcontent.tiny_enable[layer_idx] = 1; - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0("/emmc/plugin/Aida/AITOF/cavalry_GYNet_AITOF_WGT.bin"); - } - } - - } - //AMBA Weight - if (g_IsRadarDevice == 1) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIRADAR/GYNet_Radar_Tiny_Label.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIRADAR/AMB_AIRADAR_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_HUM_DET; - layerFeatureType2[layer_idx] = FEATURE_AIRADAR; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_HUM_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIRADAR; - // stAMBAcontent.tiny_enable[layer_idx] = 1; // Radar ??????n YOLO - layer_idx++; - } - } -#endif - -#ifdef GY_OS_NOVA - //NOVA Weight - if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && - ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP - )) - { - if (layer_idx < MAX_LAYER_NUM) - { - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_Label.txt")); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_WGT.bin,"); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AITRAFFIC/NOV_GYNet_Traffic_Tiny_Label.txt,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AITRAFFIC/NOV_Traffic_Tiny_VER.txt,"); - - if ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AIFLOW; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIFLOW; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_TRAF_DET)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_AIFLOW)); - } - else if ((featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA) { - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AIAREA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AIAREA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_TRAF_DET)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_AIAREA)); - } - else if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { - layerFeatureType[layer_idx] = FEATURE_TRAF_DET; - layerFeatureType2[layer_idx] = FEATURE_AICAP; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_TRAF_DET; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_AICAP; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add 1:12 0:18 - layer_idx++; - - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_TRAF_DET)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_AICAP)); - } - - } - } - //NOVA Weight - if ((featureType & FEATURE_LPR_TWN) == FEATURE_LPR_TWN) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/GYNet_LPD_Label_TWN.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_TWN)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_TWN)); - - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/GYNet_OCR_Label_TWN.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_TWN)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_TWN)); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin,"); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_LPD_Label_TWN.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTWN/GYNet_OCR_Label_TWN.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTWN/NOV_ANPR_TWN_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_TWN; - layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - //Second setting is for OCR det. - layerFeatureType[layer_idx] = FEATURE_LPR_TWN; - layerFeatureType2[layer_idx] = FEATURE_LPR_TWN; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_TWN; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_TWN; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - - } - } - //NOVA Weight - if ((featureType & FEATURE_LPR_USA) == FEATURE_LPR_USA) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRUSA/GYNet_LPD_Label_USA.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_USA)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_USA)); - - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRUSA/GYNet_OCR_Label_USA.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_USA)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_USA)); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin,"); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_LPD_Label_USA.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRUSA/GYNet_OCR_Label_USA.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRUSA/NOV_ANPR_USA_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_USA; - layerFeatureType2[layer_idx] = FEATURE_LPR_USA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_USA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - //Second setting is for OCR det. - layerFeatureType[layer_idx] = FEATURE_LPR_USA; - layerFeatureType2[layer_idx] = FEATURE_LPR_USA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_USA; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_USA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - - } - } - //NOVA Weight - if ((featureType & FEATURE_LPR_PHL) == FEATURE_LPR_PHL) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRPHL/GYNet_LPD_Label_PHL.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_PHL)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_PHL)); - - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRPHL/GYNet_OCR_Label_PHL.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_PHL)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_PHL)); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_WGT.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_WGT.bin,"); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_LPD_TWN_ANC.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTWN/NOV_GYNet_OCR_TWN_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_LPD_Label_PHL.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRPHL/GYNet_OCR_Label_PHL.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRPHL/NOV_ANPR_PHL_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_PHL; - layerFeatureType2[layer_idx] = FEATURE_LPR_PHL; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_PHL; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - //Second setting is for OCR det. - layerFeatureType[layer_idx] = FEATURE_LPR_PHL; - layerFeatureType2[layer_idx] = FEATURE_LPR_PHL; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_PHL; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_PHL; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - - } - } - //NOVA Weight - if ((featureType & FEATURE_LPR_THA) == FEATURE_LPR_THA) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/GYNet_LPD_Label_THA.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_THA)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_THA)); - - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_OCR_THA_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/NOV_GYNet_OCR_THA_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRTHA/GYNet_OCR_Label_THA.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_THA)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_THA)); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_WGT.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRTHA/NOV_GYNet_OCR_THA_WGT.bin,"); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/NOV_GYNet_LPD_TWN_ANC.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRTHA/NOV_GYNet_OCR_THA_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_LPD_Label_THA.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRTHA/GYNet_OCR_Label_THA.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRTHA/NOV_ANPR_THA_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_THA; - layerFeatureType2[layer_idx] = FEATURE_LPR_THA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_THA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - //Second setting is for OCR det. - layerFeatureType[layer_idx] = FEATURE_LPR_THA; - layerFeatureType2[layer_idx] = FEATURE_LPR_THA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_THA; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_THA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - - } - } - //NOVA Weight - if ((featureType & FEATURE_LPR_SEA) == FEATURE_LPR_SEA) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/GYNet_LPD_Label_SEA.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_SEA)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_SEA)); - - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRSEA/GYNet_OCR_Label_SEA.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_SEA)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_SEA)); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_WGT.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_WGT.bin,"); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/NOV_GYNet_LPD_SEA_ANC.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRSEA/NOV_GYNet_OCR_SEA_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_LPD_Label_SEA.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRSEA/GYNet_OCR_Label_SEA.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRSEA/NOV_ANPR_SEA_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_SEA; - layerFeatureType2[layer_idx] = FEATURE_LPR_SEA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_SEA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - //Second setting is for OCR det. - layerFeatureType[layer_idx] = FEATURE_LPR_SEA; - layerFeatureType2[layer_idx] = FEATURE_LPR_SEA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_SEA; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_SEA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - - } - } - //NOVA Weight - if ((featureType & FEATURE_LPR_MEA) == FEATURE_LPR_MEA) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/GYNet_LPD_Label_MEA.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_MEA)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_MEA)); - - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRMEA/GYNet_OCR_Label_MEA.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_MEA)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_MEA)); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_WGT.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_WGT.bin,"); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/NOV_GYNet_LPD_MEA_ANC.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPRMEA/NOV_GYNet_OCR_MEA_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_LPD_Label_MEA.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRMEA/GYNet_OCR_Label_MEA.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRMEA/NOV_ANPR_MEA_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_MEA; - layerFeatureType2[layer_idx] = FEATURE_LPR_MEA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_MEA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - //Second setting is for OCR det. - layerFeatureType[layer_idx] = FEATURE_LPR_MEA; - layerFeatureType2[layer_idx] = FEATURE_LPR_MEA; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_MEA; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_MEA; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - - } - } - //NOVA Weight - if ((featureType & FEATURE_LPR_EUR) == FEATURE_LPR_EUR) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/GYNet_LPD_Label_EUR.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_EUR)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_EUR)); - - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/GYNet_OCR_Label_EUR.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_EUR)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_EUR)); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_LPD_Label_EUR.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPREUR/GYNet_OCR_Label_EUR.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPREUR/NOV_ANPR_EUR_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_EUR; - layerFeatureType2[layer_idx] = FEATURE_LPR_EUR; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_EUR; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - //Second setting is for OCR det. - layerFeatureType[layer_idx] = FEATURE_LPR_EUR; - layerFeatureType2[layer_idx] = FEATURE_LPR_EUR; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_EUR; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_EUR; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - - } - } - //NOVA Weight - if ((featureType & FEATURE_LPR_GBR) == FEATURE_LPR_GBR) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRGBR/GYNet_LPD_Label_GBR.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_GBR)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_GBR)); - - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRGBR/GYNet_OCR_Label_GBR.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_GBR)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_GBR)); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_LPD_Label_GBR.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRGBR/GYNet_OCR_Label_GBR.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRGBR/NOV_ANPR_GBR_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_GBR; - layerFeatureType2[layer_idx] = FEATURE_LPR_GBR; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_GBR; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - //Second setting is for OCR det. - layerFeatureType[layer_idx] = FEATURE_LPR_GBR; - layerFeatureType2[layer_idx] = FEATURE_LPR_GBR; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_GBR; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_GBR; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - - } - } - //NOVA Weight - if ((featureType & FEATURE_LPR_JPN) == FEATURE_LPR_JPN) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRJPN/GYNet_LPD_Label_JPN.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_JPN)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_JPN)); - - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRJPN/GYNet_OCR_Label_JPN.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_JPN)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_JPN)); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_LPD_Label_JPN.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRJPN/GYNet_OCR_Label_JPN.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRJPN/NOV_ANPR_JPN_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_JPN; - layerFeatureType2[layer_idx] = FEATURE_LPR_JPN; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_JPN; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - //Second setting is for OCR det. - layerFeatureType[layer_idx] = FEATURE_LPR_JPN; - layerFeatureType2[layer_idx] = FEATURE_LPR_JPN; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_JPN; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_JPN; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - - - } - } - //NOVA Weight - if ((featureType & FEATURE_LPR_AUS) == FEATURE_LPR_AUS) - { - if (layer_idx < MAX_LAYER_NUM - 1) - { - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_LPD_TWN_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRAUS/GYNet_LPD_Label_AUS.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_AUS)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_AUS)); - - net_info = cJSON_CreateObject(); - cJSON_AddItemToArray(net_info_list, net_info); - cJSON_AddItemToObject(net_info, "weight_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin")); - cJSON_AddItemToObject(net_info, "anc_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt")); - cJSON_AddItemToObject(net_info, "label_name", cJSON_CreateString("/emmc/plugin/Aida/AIANPRAUS/GYNet_OCR_Label_AUS.names")); - cJSON_AddItemToObject(net_info, "featureType", cJSON_CreateNumber(FEATURE_LPR_AUS)); - cJSON_AddItemToObject(net_info, "featureType2", cJSON_CreateNumber(FEATURE_LPR_AUS)); - - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_WGT.bin,"); - strcat(stAMBAcontent.sz_amba_NetworkNames, exePath); - strcat(stAMBAcontent.sz_amba_NetworkNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_WGT.bin,"); - - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_LPD_EUR_ANC.txt,"); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, "../Aida/AIANPREUR/NOV_GYNet_OCR_EUR_ANC.txt,"); - - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_LPD_Label_AUS.names,"); - strcat(stAMBAcontent.sz_amba_label_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_label_fileNames, "../Aida/AIANPRAUS/GYNet_OCR_Label_AUS.names,"); - - strcat(stAMBAcontent.sz_amba_ver_fileNames, exePath); - strcat(stAMBAcontent.sz_amba_ver_fileNames, "../Aida/AIANPRAUS/NOV_ANPR_AUS_VER.txt,"); - - layerFeatureType[layer_idx] = FEATURE_LPR_AUS; - layerFeatureType2[layer_idx] = FEATURE_LPR_AUS; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_AUS; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - //Second setting is for OCR det. - layerFeatureType[layer_idx] = FEATURE_LPR_AUS; - layerFeatureType2[layer_idx] = FEATURE_LPR_AUS; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_LPR_AUS; - stAMBAcontent.i_amba_LayerFeatureType2[layer_idx] = FEATURE_LPR_AUS; - stAMBAcontent.tiny_enable[layer_idx] = 1; //20201127 sohia add temp - //printf("layer type = %d \n", stAMBAcontent.i_amba_LayerFeatureType[layer_idx]); - layer_idx++; - } - } -#endif - } - -#ifdef GY_OS_NOVA - cJSON_AddItemToObject(root_weight, "net_number", cJSON_CreateNumber(layer_idx)); - - char * JsonString_weight = cJSON_PrintUnformatted(root_weight); - //(Nova: 生成授權設定檔 nova_driver_valid_weight.txt) - write_driver_setting_file(JsonString_weight); - - if (JsonString_weight != NULL) { - free(JsonString_weight); - JsonString_weight = NULL; - } - - if (root_weight) { - cJSON_Delete(root_weight); - root_weight = NULL; - } - - if (IsExistingWeight(featureType, featureType2)) - { - pthread_t NOVA_detection/*, NOVA_listener, NOVA_listener_image*/; - pthread_create(&NOVA_detection, 0, RUN_NOVA_DETECTION, NULL); //A11en create pthread to run detection - printf("\n==== Gynet create nova_driver ====\n"); - } -#endif - - /* - printf("\n--------------------\n"); - printf("\nfeatureType: 0x%x\n", featureType); - printf("\nfeatureType2: 0x%x\n", featureType2); - printf("\n--------------------\n"); - */ - - //printf("333 get password = %s \n", accountData[0].account_password); -#ifdef GY_OS_AMBA - //Third party weight - //printf("td_weight_num: %d \n", td_weight_num); - - //printf("\n---------------key:%s\n",key); - //printf("\n---------------mykey_custom:%s\n", mykey_custom); - //printf("\n---------------first_half_char_key:%s\n", first_half_char_key); - if(check_if_correct_mail == 1 && g_match_mac == 1) - { - for (int read_td_weight_idx = 0; read_td_weight_idx < td_weight_num; read_td_weight_idx++) - { - if (layer_idx < MAX_LAYER_NUM) - { - char ori_weight_name[MAX_MSG_LEN] = { 0 }; - strcpy(ori_weight_name,"/emmc/plugin/Aida"); - strcat(ori_weight_name, td_weight_info[read_td_weight_idx].weight_name); - - char new_weight_name[MAX_MSG_LEN] = { 0 }; - strcpy(new_weight_name, "/emmc/plugin/Aida"); - strcat(new_weight_name, td_weight_info[read_td_weight_idx].weight_name); - new_weight_name[strlen(new_weight_name) - 3] = 'b'; - new_weight_name[strlen(new_weight_name) - 2] = 'i'; - new_weight_name[strlen(new_weight_name) - 1] = 'n'; - - //printf("\n-------------new_weight_name:%s\n", new_weight_name); - if (td_weight_info[read_td_weight_idx].is_encryption == 1) { - LILIN_File_Decryption(ori_weight_name, new_weight_name, first_half_char_key, 0, false); - strcat(stAMBAcontent.sz_amba_NetworkNames, new_weight_name); - } - else - strcat(stAMBAcontent.sz_amba_NetworkNames, ori_weight_name); - strcat(stAMBAcontent.sz_amba_NetworkNames, ","); - - - char ori_anchor_name[MAX_MSG_LEN] = { 0 }; - strcpy(ori_anchor_name, "/emmc/plugin/Aida"); - strcat(ori_anchor_name, td_weight_info[read_td_weight_idx].anchor_name); - - char new_anchor_name[MAX_MSG_LEN] = { 0 }; - strcpy(new_anchor_name, "/emmc/plugin/Aida"); - strcat(new_anchor_name, td_weight_info[read_td_weight_idx].anchor_name); - new_anchor_name[strlen(new_anchor_name) - 3] = 't'; - new_anchor_name[strlen(new_anchor_name) - 2] = 'x'; - new_anchor_name[strlen(new_anchor_name) - 1] = 't'; - - //printf("\n-------------new_anchor_name:%s\n", new_anchor_name); - if (td_weight_info[read_td_weight_idx].is_encryption == 1) { - LILIN_File_Decryption(ori_anchor_name, new_anchor_name, first_half_char_key, 0, false); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, new_anchor_name); - } - else - strcat(stAMBAcontent.sz_amba_anchor_fileNames, ori_anchor_name); - strcat(stAMBAcontent.sz_amba_anchor_fileNames, ","); - - char ori_label_name[MAX_MSG_LEN] = { 0 }; - strcpy(ori_label_name, "/emmc/plugin/Aida"); - strcat(ori_label_name, td_weight_info[read_td_weight_idx].label_name); - - //printf("\n-------------ori_label_name:%s\n", ori_label_name); - - strcat(stAMBAcontent.sz_amba_label_fileNames, ori_label_name); - strcat(stAMBAcontent.sz_amba_label_fileNames, ","); - - layerFeatureType[layer_idx] = FEATURE_ACCESS_CTRL; - stAMBAcontent.i_amba_LayerFeatureType[layer_idx] = FEATURE_ACCESS_CTRL; - stAMBAcontent.tiny_enable[layer_idx] = 1; - layer_idx++; - - if (g_IsSDK_3_0 == 1) { - cavalry_gen_sdk_3_0(new_weight_name); - } - } - } - } -#endif - - //printf("\n%s\n", stAMBAcontent.sz_amba_ver_fileNames); - -#ifdef TEST_DETECTOR_MEM - //到此記憶體線漏大約1304個 - - //printf("\n--------------------------:6\n"); - test_detector_mem(NULL, cnn_type, stAMBAcontent.sz_amba_NetworkNames, thresh, hier_thresh, ext_output, save_labels, NULL, NULL, input_resizable, custom_cpu_library, custom_cldnn, performance_counter, nIsHardwareOK); -#endif - } - else - { - printf("\n****************\n"); - printf("No License Key"); - printf("\n****************\n"); - - //沒有license key還是會運行http server, 可以用/server查詢伺服器狀態 - //http_ip_address = (ip_address) ? ip_address : NULL; - - //http_http_port = http_port; - licenseType = _TRIAL_LICENSE_FPS06; - - -#ifdef TEST_DETECTOR_MEM - test_detector_mem(NULL, cnn_type, NULL, thresh, hier_thresh, ext_output, save_labels, NULL, NULL, input_resizable, NULL, NULL, performance_counter, nIsHardwareOK); -#endif - }/// if (fe && li && st && et && id) - } - else - printf("config.json parse FAIL.\n"); - } - } - else - printf("-http_port %d not found!\n", http_port); - - //printf("999 get password = %s \n", accountData[0].account_password); - - printf("\n[run_server] end\n"); -} - -void getCameraPlugInInfo() { - //printf("\n---------------get Camera PlugIn Info start\n"); - char filename[1024] = { 0 }; - strcpy(filename, "/www/plugin/json/CameraPlug-in.json"); - if (!FileExist(filename)) - printf("%s doesn't exist.\n", filename); - else { - char* fileBuf = ReadAllBytes(filename); - if (fileBuf) { - cJSON *plugin; - - plugin = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - - if (plugin) { - cJSON *description; - description = cJSON_GetObjectItem(plugin, "description"); - - if (description) { - if (strstr(description->valuestring, "LILIN") != NULL) { - //printf("\n---------------get Camera PlugIn Info 1\n"); - g_check_if_no_brand = 0; - } - else { - //printf("\n---------------get Camera PlugIn Info 2\n"); - g_check_if_no_brand = 1; - } - } - else { - //printf("\n---------------get Camera PlugIn Info 3\n"); - g_check_if_no_brand = 0; - } - - if (plugin) { - cJSON_Delete(plugin); - plugin = NULL; - } - } - else - printf("CameraPlug-in.json parse FAIL.\n"); - } - } - //printf("\n---------------get Camera PlugIn Info end\n"); -} - -long getCurrentTime() { - struct timeval tv; - gettimeofday(&tv, NULL); - return tv.tv_sec * 1000 + tv.tv_usec / 1000; -} - -static int CheckIsExistingWeight = 1; -int IsExistingWeight(size_t featureType, size_t featureType2) -{ - int nHasFeature = 0; - int count_weight = 0; - -#ifdef GY_OS_AMBA - if (strcmp(WeightFileModeName, "mod004") == 0) - { - if (weightfileList[30].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && - ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP - )) - { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - else if (weightfileList[30].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && - ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP - )) - { - CheckIsExistingWeight = 0; - } - } - else -#endif - { - if (weightfileList[15].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && - ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP - )) - { -#ifdef GY_OS_V_SERIES - if ((featureType2 & FEATURE_AICAP) == FEATURE_AICAP) { - CheckIsExistingWeight = 0; - } - else { - nHasFeature = 1; - count_weight++; - } -#else - nHasFeature = 1; - count_weight++; -#endif - - CheckIsExistingSpeed = 1; - } - else if (weightfileList[15].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && - ((featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW || (featureType2 & FEATURE_AIAREA) == FEATURE_AIAREA || (featureType2 & FEATURE_AICAP) == FEATURE_AICAP - )) - { - CheckIsExistingWeight = 0; - } - } - - if (weightfileList[27].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0) - { - nHasFeature = 1; - count_weight++; - } - else if (weightfileList[27].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIGARBAGE) == FEATURE_AIGARBAGE && strcmp(WeightFileModeName, "mod003") != 0) - { - CheckIsExistingWeight = 0; - } - - if (weightfileList[28].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) - { - nHasFeature = 1; - count_weight++; - } - else if (weightfileList[28].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AIAREO) == FEATURE_AIAREO) - { - CheckIsExistingWeight = 0; - } - - if (weightfileList[11].enable_weight_to_run == 1 && (featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE) - { - nHasFeature = 1; - count_weight++; - } - else if (weightfileList[11].enable_weight_to_run == 0 && (featureType & FEATURE_AIFIRE) == FEATURE_AIFIRE) - { - CheckIsExistingWeight = 0; - } - - if (weightfileList[13].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) - { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - else if (weightfileList[13].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) - { - CheckIsExistingWeight = 0; - } - - if (weightfileList[22].enable_weight_to_run == 1 && (featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) - { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - else if (weightfileList[22].enable_weight_to_run == 0 && (featureType & FEATURE_AIRAIL) == FEATURE_AIRAIL && (featureType2 & FEATURE_AIFLOW) == FEATURE_AIFLOW) { - CheckIsExistingWeight = 0; - } - - if (weightfileList[23].enable_weight_to_run == 1 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) - { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - else if (weightfileList[23].enable_weight_to_run == 0 && (featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) { - CheckIsExistingWeight = 0; - } - - if (strcmp(WeightFileModeName, "mod003") != 0) { - if (weightfileList[12].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) - { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - else if (weightfileList[12].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) - { - CheckIsExistingWeight = 0; - } - } - else { - if (weightfileList[25].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) - { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - else if (weightfileList[25].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK) - { - CheckIsExistingWeight = 0; - } - } - - if (weightfileList[14].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) - { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - else if (weightfileList[14].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AISHIP) == FEATURE_AISHIP) - { - CheckIsExistingWeight = 0; - } - - if (weightfileList[26].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) - { - nHasFeature = 1; - count_weight++; - } - else if (weightfileList[26].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIPRODUCTION) == FEATURE_AIPRODUCTION) - { - CheckIsExistingWeight = 0; - } - - if (strcmp(WeightFileModeName, "mod003") != 0) { - if (weightfileList[0].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) - { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - else if (weightfileList[0].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) - { - CheckIsExistingWeight = 0; - } - } - else { - if (weightfileList[29].enable_weight_to_run == 1 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) - { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - else if (weightfileList[29].enable_weight_to_run == 0 && (featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML) - { - CheckIsExistingWeight = 0; - } - } - - if ((featureType & FEATURE_AIFISHTRAF) == FEATURE_AIFISHTRAF) - { - CheckIsExistingWeight = 0; - } - if ((featureType & FEATURE_POK_DET) != 0) - { - CheckIsExistingWeight = 0; - } - if ((featureType & FEATURE_HUM_POS) != 0) - { - CheckIsExistingWeight = 0; - } - if ((featureType & FEATURE_LED_DGT) != 0) - { - CheckIsExistingWeight = 0; - } - if ((featureType & FEATURE_SHOES_DET) != 0) - { - CheckIsExistingWeight = 0; - } - if (weightfileList[10].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_LOGO) != 0) - { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - else if (weightfileList[10].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_LOGO) != 0) - { - CheckIsExistingWeight = 0; - } - - if (weightfileList[7].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_TWN) != 0) - { - if (g_check_if_OK_getfeatures == 0) { - CheckIsExistingWeight = 0; - } - else { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - } - else if (weightfileList[7].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_TWN) != 0) - { - CheckIsExistingWeight = 0; - } - - if (weightfileList[1].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_EUR) != 0) - { - if (g_check_if_OK_getfeatures == 0) { - CheckIsExistingWeight = 0; - } - else { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - } - else if (weightfileList[1].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_EUR) != 0) - { - CheckIsExistingWeight = 0; - } - - if ((weightfileList[5].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_SEA) != 0) || - (weightfileList[5].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_VNM) != 0) || - (weightfileList[5].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_IDN) != 0)) - { - if (g_check_if_OK_getfeatures == 0) { - CheckIsExistingWeight = 0; - } - else { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - } - else if ((weightfileList[5].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_SEA) != 0) || - (weightfileList[5].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_VNM) != 0) || - (weightfileList[5].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_IDN) != 0)) - { - CheckIsExistingWeight = 0; - } - -#if 0 - if (weightfileList[9].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_VNM) != 0) - { - if (g_check_if_OK_getfeatures == 0) { - CheckIsExistingWeight = 0; - } - else { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - } - else if (weightfileList[9].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_VNM) != 0) - { - CheckIsExistingWeight = 0; - } -#endif - - /* - if ((featureType & FEATURE_LPR_CNA) != 0) - { - CheckIsExistingWeight = 0; - }*/ - - if (weightfileList[17].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_MEA) != 0) - { - if (g_check_if_OK_getfeatures == 0) { - CheckIsExistingWeight = 0; - } - else { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - } - else if (weightfileList[17].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_MEA) != 0) - { - CheckIsExistingWeight = 0; - } - - if (weightfileList[19].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_AUS) != 0) - { - if (g_check_if_OK_getfeatures == 0) { - CheckIsExistingWeight = 0; - } - else { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - } - else if (weightfileList[19].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_AUS) != 0) - { - CheckIsExistingWeight = 0; - } - - if (weightfileList[8].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_USA) != 0) - { - if (g_check_if_OK_getfeatures == 0) { - CheckIsExistingWeight = 0; - } - else { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - } - else if(weightfileList[8].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_USA) != 0) - { - CheckIsExistingWeight = 0; - } - - if (weightfileList[2].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_GBR) != 0) - { - if (g_check_if_OK_getfeatures == 0) { - CheckIsExistingWeight = 0; - } - else { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - } - else if (weightfileList[2].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_GBR) != 0) - { - CheckIsExistingWeight = 0; - } - -#if 0 - if (weightfileList[24].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_IDN) != 0) - { - if (g_check_if_OK_getfeatures == 0) { - CheckIsExistingWeight = 0; - } - else { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - } - else if (weightfileList[24].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_IDN) != 0) - { - CheckIsExistingWeight = 0; - } -#endif - - if (weightfileList[3].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_JPN) != 0) - { - if (g_check_if_OK_getfeatures == 0) { - CheckIsExistingWeight = 0; - } - else { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - } - else if (weightfileList[3].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_JPN) != 0) - { - CheckIsExistingWeight = 0; - } - - if ((featureType & FEATURE_LPR_IND) != 0) - { - CheckIsExistingWeight = 0; - } - - if (weightfileList[6].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_THA) != 0) - { - if (g_check_if_OK_getfeatures == 0) { - CheckIsExistingWeight = 0; - } - else { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - } - else if (weightfileList[6].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_THA) != 0) - { - CheckIsExistingWeight = 0; - } - - if ((featureType & FEATURE_LPR_LAO) != 0) - { - CheckIsExistingWeight = 0; - } - if (weightfileList[16].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_BGD) != 0) - { - if (g_check_if_OK_getfeatures == 0) { - CheckIsExistingWeight = 0; - } - else { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - } - else if (weightfileList[16].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_BGD) != 0) - { - CheckIsExistingWeight = 0; - } - - if (weightfileList[4].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_PHL) != 0) - { - if (g_check_if_OK_getfeatures == 0) { - CheckIsExistingWeight = 0; - } - else { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - } - else if (weightfileList[4].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_PHL) != 0) - { - CheckIsExistingWeight = 0; - } - - if (weightfileList[18].enable_weight_to_run == 1 && (featureType & FEATURE_LPR_CNT) != 0) - { - if (g_check_if_OK_getfeatures == 0) { - CheckIsExistingWeight = 0; - } - else { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - } - else if (weightfileList[18].enable_weight_to_run == 0 && (featureType & FEATURE_LPR_CNT) != 0) - { - CheckIsExistingWeight = 0; - } - - if ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && - featureType2 == FEATURE_EMPTY) - { - CheckIsExistingWeight = 0; - } - - if (g_IsCustomWeight == 1) - { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - - if (weightfileList[20].enable_weight_to_run == 1 && g_IsRadarDevice == 1) - { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - else if (weightfileList[20].enable_weight_to_run == 0 && g_IsRadarDevice == 1) - { - CheckIsExistingWeight = 0; - } - - if (weightfileList[21].enable_weight_to_run == 1 && g_IsToFDevice == 1) - { - nHasFeature = 1; - count_weight++; - CheckIsExistingSpeed = 1; - } - else if(weightfileList[21].enable_weight_to_run == 0 && g_IsToFDevice == 1){ - CheckIsExistingWeight = 0; - } - - if (unlockingKeyInnoFR == 1 && unlockingKeyInnoFR_success == 1) { - nHasFeature = 1; - count_weight++; - } - else if(unlockingKeyInnoFR == 1 && unlockingKeyInnoFR_success == 0){ - CheckIsExistingWeight = 0; - } - - if (count_weight >= 2) { -#ifdef GY_OS_NOVA - CheckIsExistingWeight = 0; -#endif - } - - return (CheckIsExistingWeight) > 0 && nHasFeature == 1 ? 1 : 0; -} -void RefreshCheckExistingWeight() -{ - CheckIsExistingWeight = 1; -} -#ifdef GY_OS_AMBA -void cavalry_gen_sdk_3_0(char * bin_name) { - { - FILE * pPipe; - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - sprintf(cmd, "/usr/local/bin/cavalry_gen -f %s -t /emmc/plugin/Aida/temp.bin -V 2.2.8.3", bin_name); - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); - } - - { - FILE * pPipe; - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - sprintf(cmd, "cp /emmc/plugin/Aida/temp.bin %s", bin_name); - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); - } - - { - FILE * pPipe; - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - sprintf(cmd, "rm -f /emmc/plugin/Aida/temp.bin"); - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); - } -} -#endif - -void initial_weight_settings() { - //會根據設定檔,建立權重是否啟動 - strcpy(weightfileList[0].weight_repository, "AIAML"); - strcpy(weightfileList[1].weight_repository, "AIANPREUR"); - strcpy(weightfileList[2].weight_repository, "AIANPRGBR"); - strcpy(weightfileList[3].weight_repository, "AIANPRJPN"); - strcpy(weightfileList[4].weight_repository, "AIANPRPHL"); - strcpy(weightfileList[5].weight_repository, "AIANPRSEA"); - strcpy(weightfileList[6].weight_repository, "AIANPRTHA"); - strcpy(weightfileList[7].weight_repository, "AIANPRTWN"); - strcpy(weightfileList[8].weight_repository, "AIANPRUSA"); - strcpy(weightfileList[9].weight_repository, "AIANPRVNM"); - strcpy(weightfileList[10].weight_repository, "AICarMake"); - strcpy(weightfileList[11].weight_repository, "AIFIRE"); - strcpy(weightfileList[12].weight_repository, "AIHUMAN"); - strcpy(weightfileList[13].weight_repository, "AISAFTY"); - strcpy(weightfileList[14].weight_repository, "AISHIP"); - strcpy(weightfileList[15].weight_repository, "AITRAFFIC"); - strcpy(weightfileList[16].weight_repository, "AIANPRBGD"); - strcpy(weightfileList[17].weight_repository, "AIANPRMEA"); - strcpy(weightfileList[18].weight_repository, "AIANPRCNT"); - strcpy(weightfileList[19].weight_repository, "AIANPRAUS"); - strcpy(weightfileList[20].weight_repository, "AIRADAR"); // Ken 2022-10-13 - strcpy(weightfileList[21].weight_repository, "AITOF"); - strcpy(weightfileList[22].weight_repository, "AIRAILWAY"); - strcpy(weightfileList[23].weight_repository, "AISPORTS"); - strcpy(weightfileList[24].weight_repository, "AIANPRIDN"); - strcpy(weightfileList[25].weight_repository, "AIGENDER"); - strcpy(weightfileList[26].weight_repository, "AIPRODUCTION"); - strcpy(weightfileList[27].weight_repository, "AIGARBAGE"); - strcpy(weightfileList[28].weight_repository, "AIAERO"); - strcpy(weightfileList[29].weight_repository, "AIFRONTBACK"); - strcpy(weightfileList[30].weight_repository, "AITHERMAL"); - - for (size_t index_weightfile = 0; index_weightfile < MAX_WEIGHT_FILE_LIST; index_weightfile++) { - weightfileList[index_weightfile].enable_weight_to_run = 0; - } - - char c_file_name_weight_setting[1024] = { 0 }; - strcpy(c_file_name_weight_setting, "/emmc/plugin/Aida_data/weight_setting.json"); - - if (!FileExist(c_file_name_weight_setting) || ReadFileSize(c_file_name_weight_setting) == 0) - { - printf("weight_setting file doesn't exist.\n"); - cJSON *s_root = cJSON_CreateObject(); - cJSON_AddItemToObject(s_root, "mode_name", cJSON_CreateString("mode_err")); - //AIAML,AIANPREUR,AIANPRGBR,AIANPRJPN,AIANPRPHL,AIANPRSEA,AIANPRTHA,AIANPRTWN,AIANPRUSA,AIANPRVNM,AICarMake,AIFIRE,AIHUMAN,AISAFTY,AISHIP,AITRAFFIC - cJSON_AddItemToObject(s_root, "mode_repository", cJSON_CreateString("")); - - char* JsonString = cJSON_Print(s_root); - - FILE *f = fopen(c_file_name_weight_setting, "w"); - if (f == NULL) - { - printf("Error opening setting file!\n"); - } - else { - fprintf(f, "%s\n", JsonString); - fclose(f); - } - if (JsonString) { - free(JsonString); - JsonString = NULL; - } - if (s_root) { - free(s_root); - s_root = NULL; - } - } - - cJSON* root_weight_setting, *mode_name, *mode_repository; - - if (!FileExist(c_file_name_weight_setting)) - { - printf("%s doesn't exist.\n", c_file_name_weight_setting); - } - else - { - char* fileBuf_weight_setting = ReadAllBytes(c_file_name_weight_setting); - if (fileBuf_weight_setting) { - root_weight_setting = cJSON_Parse(fileBuf_weight_setting); - - if (fileBuf_weight_setting) { - free(fileBuf_weight_setting); - fileBuf_weight_setting = NULL; - } - mode_name = cJSON_GetObjectItem(root_weight_setting, "mode_name"); - mode_repository = cJSON_GetObjectItem(root_weight_setting, "mode_repository"); - - strcpy(WeightFileModeName, mode_name->valuestring); - char temp_buf_mode_repository[1024] = { 0 }; - strcpy(temp_buf_mode_repository, mode_repository->valuestring); - - if (strstr(temp_buf_mode_repository, "AIAML") != NULL) { - weightfileList[0].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIANPREUR") != NULL) { - weightfileList[1].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIANPRGBR") != NULL) { - weightfileList[2].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIANPRJPN") != NULL) { - weightfileList[3].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIANPRPHL") != NULL) { - weightfileList[4].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIANPRSEA") != NULL) { - weightfileList[5].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIANPRTHA") != NULL) { - weightfileList[6].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIANPRTWN") != NULL) { - weightfileList[7].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIANPRUSA") != NULL) { - weightfileList[8].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIANPRVNM") != NULL) { - weightfileList[9].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AICarMake") != NULL) { - weightfileList[10].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIFIRE") != NULL) { - weightfileList[11].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIHUMAN") != NULL) { - weightfileList[12].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AISAFTY") != NULL) { - weightfileList[13].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AISHIP") != NULL) { - weightfileList[14].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AITRAFFIC") != NULL) { - weightfileList[15].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIANPRBGD") != NULL) { - weightfileList[16].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIANPRMEA") != NULL) { - weightfileList[17].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIANPRCNT") != NULL) { - weightfileList[18].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIANPRAUS") != NULL) { - weightfileList[19].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AIRADAR") != NULL) { - weightfileList[20].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AITOF") != NULL) { - weightfileList[21].enable_weight_to_run = 1; - } - - if (strstr(temp_buf_mode_repository, "AIRAILWAY") != NULL) { - weightfileList[22].enable_weight_to_run = 1; - } - if (strstr(temp_buf_mode_repository, "AISPORTS") != NULL) { - weightfileList[23].enable_weight_to_run = 1; - } - - if (strstr(temp_buf_mode_repository, "AIANPRIDN") != NULL) { - weightfileList[24].enable_weight_to_run = 1; - } - - if (strstr(temp_buf_mode_repository, "AIGENDER") != NULL) { - weightfileList[25].enable_weight_to_run = 1; - } - - if (strstr(temp_buf_mode_repository, "AIPRODUCTION") != NULL) { - weightfileList[26].enable_weight_to_run = 1; - } - - if (strstr(temp_buf_mode_repository, "AIGARBAGE") != NULL) { - weightfileList[27].enable_weight_to_run = 1; - } - - if (strstr(temp_buf_mode_repository, "AIAERO") != NULL) { - weightfileList[28].enable_weight_to_run = 1; - } - - if (strstr(temp_buf_mode_repository, "AIFRONTBACK") != NULL) { - weightfileList[29].enable_weight_to_run = 1; - } - - if (strstr(temp_buf_mode_repository, "AITHERMAL") != NULL) { - weightfileList[30].enable_weight_to_run = 1; - } - - if (root_weight_setting) { - cJSON_Delete(root_weight_setting); - root_weight_setting = NULL; - } - } - } -} - -void file_management() { - char buf[1024] = { 0 }; - readlink("/proc/self/exe", buf, sizeof(buf)); - //printf("Program binary path is: %s\n", buf); - - char exePath[1024] = { 0 }; - getFilePath(buf, exePath, 1024); - - char configPATH[1024] = { 0 }; -#ifdef GY_OS_NOVA - char config_smallPATH[1024] = { 0 }; -#endif - char config_installPATH[1024] = { 0 }; - -#ifdef GY_OS_NOVA - char config_small_installPATH[1024] = { 0 }; -#endif - char config_bakPATH[1024] = { 0 }; - - char events_installPATH[1024] = { 0 }; - char eventsPATH[1024] = { 0 }; - char events_bakPATH[1024] = { 0 }; - - char tof_installPATH[1024] = { 0 }; - char tofPATH[1024] = { 0 }; - char tof_bakPATH[1024] = { 0 }; - - char emails_installPATH[1024] = { 0 }; - char emailsPATH[1024] = { 0 }; - char emails_bakPATH[1024] = { 0 }; - - char cold_objects_installPATH[1024] = { 0 }; - char cold_objectsPATH[1024] = { 0 }; - - char face_installPATH[1024] = { 0 }; - char facePATH[1024] = { 0 }; - - char db_fflprPATH[1024] = { 0 }; - char db_fflpr_installPATH[1024] = { 0 }; - char db_fflpr_bakPATH[1024] = { 0 }; - - char db_facePATH[1024] = { 0 }; - char db_face_installPATH[1024] = { 0 }; - char db_face_bakPATH[1024] = { 0 }; - - char face_license_PATH[1024] = { 0 }; - char face_license_installPATH[1024] = { 0 }; - char face_license_bakPATH[1024] = { 0 }; - - strcpy(configPATH, exePath); -#ifdef GY_OS_NOVA - strcpy(config_smallPATH, exePath); -#endif - strcpy(config_installPATH, exePath); -#ifdef GY_OS_NOVA - strcpy(config_small_installPATH, exePath); -#endif - strcpy(config_bakPATH, exePath); - - strcpy(eventsPATH, exePath); - strcpy(events_installPATH, exePath); - strcpy(events_bakPATH, exePath); - - strcpy(tofPATH, exePath); - strcpy(tof_installPATH, exePath); - strcpy(tof_bakPATH, exePath); - - strcpy(emailsPATH, exePath); - strcpy(emails_installPATH, exePath); - strcpy(emails_bakPATH, exePath); - - strcpy(cold_objectsPATH, exePath); - strcpy(cold_objects_installPATH, exePath); - - strcpy(facePATH, exePath); - strcpy(face_installPATH, exePath); - - strcpy(db_fflprPATH, exePath); - strcpy(db_fflpr_installPATH, exePath); - strcpy(db_fflpr_bakPATH, exePath); - - strcpy(db_facePATH, exePath); - strcpy(db_face_installPATH, exePath); - strcpy(db_face_bakPATH, exePath); - - strcpy(face_license_PATH, exePath); - strcpy(face_license_installPATH, exePath); - strcpy(face_license_bakPATH, exePath); - - strcat(configPATH, "config.json"); -#ifdef GY_OS_NOVA - strcat(config_smallPATH, "config_small.json"); -#endif - strcat(config_installPATH, "config_install.json"); - -#ifdef GY_OS_NOVA - strcat(config_small_installPATH, "config_small_install.json"); -#endif - strcat(config_bakPATH, "config_bak.json"); - - strcat(eventsPATH, "events.json"); - strcat(events_installPATH, "events_install.json"); - strcat(events_bakPATH, "events_bak.json"); - - strcat(tofPATH, "tof.json"); - strcat(tof_installPATH, "tof_install.json"); - strcat(tof_bakPATH, "tof_bak.json"); - - strcat(emailsPATH, "emails.json"); - strcat(emails_installPATH, "emails_install.json"); - strcat(emails_bakPATH, "emails_bak.json"); - - strcat(cold_objectsPATH, "cold_objects.json"); - strcat(cold_objects_installPATH, "cold_objects_install.json"); - - strcat(facePATH, "sfe/iengine.lic"); - strcat(face_installPATH, "sfe/iengine_install.lic"); - -#if defined GY_OS_AMBA || defined GY_OS_NOVA - strcat(db_fflprPATH, "db_fflpr.db"); - strcat(db_fflpr_installPATH, "db_fflpr_install_2.db"); - - strcat(db_facePATH, "db_face.db"); - strcat(db_face_installPATH, "db_face_install_2.db"); - -#endif - - //確認config_bak.json沒有壞掉 - { - char* fileBuf = ReadAllBytes(config_bakPATH); - if (fileBuf) { - cJSON* root; - root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (root) { - //printf("config_bakPATH parse OK\n"); - cJSON_Delete(root); - root = NULL; - } - else { - //printf("config_bakPATH parse FAIL.0\n"); - - if (FileExist(config_bakPATH)) { - int del = unlink(config_bakPATH); - if (!del) { - //printf("config_bakPATH is Deleted successfully."); - } - else { - printf("config_bakPATH cannot be Deleted.\n"); - } - } - } - } - } - - if (FileExist(config_bakPATH) == 1 && ReadFileSize(config_bakPATH) >= 20000) - { - //CopyFileTo(configPATH, config_bakPATH); - CopyFileTo(config_bakPATH, configPATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_bak to main config <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - else if (FileExist(config_bakPATH) == 1 && ReadFileSize(config_bakPATH) < 20000) - { - int del = remove(config_bakPATH); - if (!del) { - //printf("config_bak is Deleted successfully."); - } - else { - printf("config_bak cannot be Deleted.\n"); - } - } - - //確認config.json沒有壞掉 - { - char* fileBuf = ReadAllBytes(configPATH); - if (fileBuf) { - cJSON* root; - root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (root) { - //printf("config_bakPATH parse OK\n"); - cJSON_Delete(root); - root = NULL; - } - else { - printf("configPATH parse FAIL.0\n"); - - if (FileExist(config_bakPATH)) { - printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_bakPATH to main_0 config <<<<<<<<<<<<<<<<<<<<<<<\n"); - CopyFileTo(config_bakPATH, configPATH); - } - else { - if (FileExist(configPATH)) { - int del = unlink(configPATH); - if (!del) { - //printf("configPATH is Deleted successfully."); - } - else { - printf("configPATH cannot be Deleted.\n"); - } - } - } - } - } - } - - //確認events_bak.json沒有壞掉 - { - char* fileBuf = ReadAllBytes(events_bakPATH); - if (fileBuf) { - cJSON* root; - root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (root) { - //printf("config_bakPATH parse OK\n"); - cJSON_Delete(root); - root = NULL; - } - else { - //printf("events_bakPATH parse FAIL.0\n"); - - if (FileExist(events_bakPATH)) { - int del = unlink(events_bakPATH); - if (!del) { - //printf("config_bakPATH is Deleted successfully."); - } - else { - printf("events_bakPATH cannot be Deleted.\n"); - } - } - } - } - } - - if (FileExist(events_bakPATH) == 1 && ReadFileSize(events_bakPATH) >= 8000) - { - CopyFileTo(events_bakPATH, eventsPATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_bak to main events <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - else if (FileExist(events_bakPATH) == 1 && ReadFileSize(events_bakPATH) < 8000) - { - int del = remove(events_bakPATH); - if (!del) { - //printf("events_bak is Deleted successfully."); - } - else { - printf("events_bak cannot be Deleted.\n"); - } - } - - //確認events.json沒有壞掉 - { - char* fileBuf = ReadAllBytes(eventsPATH); - if (fileBuf) { - cJSON* root; - root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (root) { - //printf("eventsPATH parse OK\n"); - cJSON_Delete(root); - root = NULL; - } - else { - printf("eventsPATH parse FAIL.0\n"); - - if (FileExist(events_bakPATH)) { - printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_bakPATH to main_0 events <<<<<<<<<<<<<<<<<<<<<<<\n"); - CopyFileTo(events_bakPATH, eventsPATH); - } - else { - if (FileExist(events_bakPATH)) { - int del = unlink(events_bakPATH); - if (!del) { - //printf("events_bakPATH is Deleted successfully."); - } - else { - printf("events_bakPATH cannot be Deleted.\n"); - } - } - } - } - } - } - - //確認tof_bak.json沒有壞掉 - { - char* fileBuf = ReadAllBytes(tof_bakPATH); - if (fileBuf) { - cJSON* root; - root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (root) { - //printf("tof_bakPATH parse OK\n"); - cJSON_Delete(root); - root = NULL; - } - else { - //printf("tof_bakPATH parse FAIL.0\n"); - - if (FileExist(tof_bakPATH)) { - int del = unlink(tof_bakPATH); - if (!del) { - //printf("tof_bakPATH is Deleted successfully."); - } - else { - printf("tof_bakPATH cannot be Deleted.\n"); - } - } - } - } - } - - if (FileExist(tof_bakPATH) == 1 && ReadFileSize(tof_bakPATH) >= 250) - { - CopyFileTo(tof_bakPATH, tofPATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_bak to main tof <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - else if (FileExist(tof_bakPATH) == 1 && ReadFileSize(tof_bakPATH) < 250) - { - int del = remove(tof_bakPATH); - if (!del) { - //printf("tof_bak is Deleted successfully."); - } - else { - printf("tof_bak cannot be Deleted.\n"); - } - } - - //確認tof.json沒有壞掉 - { - char* fileBuf = ReadAllBytes(tofPATH); - if (fileBuf) { - cJSON* root; - root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (root) { - //printf("eventsPATH parse OK\n"); - cJSON_Delete(root); - root = NULL; - } - else { - printf("tofPATH parse FAIL.0\n"); - - if (FileExist(tof_bakPATH)) { - printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_bakPATH to main_0 tof <<<<<<<<<<<<<<<<<<<<<<<\n"); - CopyFileTo(tof_bakPATH, tofPATH); - } - else { - if (FileExist(tof_bakPATH)) { - int del = unlink(tof_bakPATH); - if (!del) { - //printf("tof_bakPATH is Deleted successfully."); - } - else { - printf("tof_bakPATH cannot be Deleted.\n"); - } - } - } - } - } - } - - //確認emails_bak.json沒有壞掉 - { - char* fileBuf = ReadAllBytes(emails_bakPATH); - if (fileBuf) { - cJSON* root; - root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (root) { - //printf("config_bakPATH parse OK\n"); - cJSON_Delete(root); - root = NULL; - } - else { - //printf("emails_bakPATH parse FAIL.0\n"); - - if (FileExist(emails_bakPATH)) { - int del = unlink(emails_bakPATH); - if (!del) { - //printf("emails_bakPATH is Deleted successfully."); - } - else { - printf("emails_bakPATH cannot be Deleted.\n"); - } - } - } - } - } - - //確認emails.json沒有壞掉 - { - char* fileBuf = ReadAllBytes(emailsPATH); - if (fileBuf) { - cJSON* root; - root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (root) { - //printf("eventsPATH parse OK\n"); - cJSON_Delete(root); - root = NULL; - } - else { - printf("emailsPATH parse FAIL.0\n"); - - if (FileExist(emails_bakPATH)) { - printf(">>>>>>>>>>>>>>>>>>>>>> Copy emails_bakPATH to main_0 emails <<<<<<<<<<<<<<<<<<<<<<<\n"); - CopyFileTo(emails_bakPATH, emailsPATH); - } - else { - if (FileExist(emails_bakPATH)) { - int del = unlink(emails_bakPATH); - if (!del) { - //printf("emails_bakPATH is Deleted successfully."); - } - else { - printf("emails_bakPATH cannot be Deleted.\n"); - } - } - } - } - } - } -#if defined GY_OS_AMBA || defined GY_OS_NOVA - //確認是不是剛update LPKG,如果是則刪除舊的db,以符合新的db格式。 - { - char NEW_UPDATE_PATH[1024] = "/emmc/plugin/Aida_data/new_update.txt"; - if (FileExist(NEW_UPDATE_PATH)) { - int del = unlink(NEW_UPDATE_PATH); - if (!del) { - //printf("txt is Deleted successfully."); - } - else { - printf("NEW UPDATE PATH cannot be Deleted.\n"); - } - - /*char DB_FFLPR_PATH[1024] = "/emmc/plugin/Aida_data/db_fflpr.db"; - if (FileExist(DB_FFLPR_PATH)) { - int del = unlink(DB_FFLPR_PATH); - if (!del) { - //printf("db is Deleted successfully."); - } - else { - printf("DB FFLPR PATH cannot be Deleted.\n"); - } - }*/ - - - char DB_FACE_PATH[1024] = "/emmc/plugin/Aida_data/db_face.db"; - if (FileExist(DB_FACE_PATH)) { - int del = unlink(DB_FACE_PATH); - if (!del) { - //printf("db is Deleted successfully."); - } - else { - printf("DB FACE PATH cannot be Deleted.\n"); - } - } - - delete_file("/emmc/plugin/Aida_data/sfe/storage/entities.rec"); - delete_file("/emmc/plugin/Aida_data/sfe/storage/face_templates.map"); - delete_file("/emmc/plugin/Aida_data/sfe/storage/face_templates.rec"); - delete_file("/emmc/plugin/Aida_data/sfe/storage/labels.rec"); - - } - } - - { //face db - char NEW_UPDATE_PATH[1024] = "/emmc/plugin/Aida_data/new_update.txt"; - if (FileExist(NEW_UPDATE_PATH)) { - int del = unlink(NEW_UPDATE_PATH); - if (!del) { - //printf("txt is Deleted successfully."); - } - else { - printf("NEW UPDATE PATH cannot be Deleted.\n"); - } - - char DB_FACE_PATH[1024] = "/emmc/plugin/Aida_data/db_face.db"; - if (FileExist(DB_FACE_PATH)) { - int del = unlink(DB_FACE_PATH); - if (!del) { - //printf("db is Deleted successfully."); - } - else { - printf("DB FACE PATH cannot be Deleted.\n"); - } - } - } - } -#endif - if (FileExist(config_installPATH) == 1 && (FileExist(configPATH) == 0 || ReadFileSize(configPATH) == 0)) { - CopyFileTo(config_installPATH, configPATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_install to main config <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - - if (FileExist(config_installPATH) == 1 && (FileExist(config_bakPATH) == 1 && ReadFileSize(config_bakPATH) == 0)) { - CopyFileTo(config_installPATH, config_bakPATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_install to back config <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - -#ifdef GY_OS_NOVA - if (FileExist(config_small_installPATH) == 1 && (FileExist(config_smallPATH) == 0 || ReadFileSize(config_smallPATH) == 0)) { - CopyFileTo(config_small_installPATH, config_smallPATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy config_small_installPATH to main config_small <<<<<<<<<<<<<<<<<<<<<<<\n"); - } -#endif - - if (FileExist(events_installPATH) == 1 && (FileExist(eventsPATH) == 0 || ReadFileSize(eventsPATH) == 0)) { - CopyFileTo(events_installPATH, eventsPATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_install to main events <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - - if (FileExist(events_installPATH) == 1 && (FileExist(events_bakPATH) == 1 && ReadFileSize(events_bakPATH) == 0)) { - CopyFileTo(events_installPATH, events_bakPATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy events_install to back events <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - - if (FileExist(tof_installPATH) == 1 && (FileExist(tofPATH) == 0 || ReadFileSize(tofPATH) == 0)) { - CopyFileTo(tof_installPATH, tofPATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_install to main tof <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - - if (FileExist(tof_installPATH) == 1 && (FileExist(tof_bakPATH) == 1 && ReadFileSize(tof_bakPATH) == 0)) { - CopyFileTo(tof_installPATH, tof_bakPATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy tof_install to back tof <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - - if (FileExist(emails_installPATH) == 1 && (FileExist(emailsPATH) == 0 || ReadFileSize(emailsPATH) == 0)) { - CopyFileTo(emails_installPATH, emailsPATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy emails_install to main emails <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - - if (FileExist(emails_installPATH) == 1 && (FileExist(emails_bakPATH) == 1 && ReadFileSize(emails_bakPATH) == 0)) { - CopyFileTo(emails_installPATH, emails_bakPATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy emails_install to back emails <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - -#if defined GY_OS_AMBA || defined GY_OS_NOVA - if (FileExist(db_fflpr_installPATH) == 1 && (FileExist(db_fflprPATH) == 0 || ReadFileSize(db_fflprPATH) == 0)) { - CopyFileTo(db_fflpr_installPATH, db_fflprPATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy db_fflpr_install to main db_fflpr <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - if (FileExist(db_face_installPATH) == 1 && (FileExist(db_facePATH) == 0 || ReadFileSize(db_facePATH) == 0)) { - CopyFileTo(db_face_installPATH, db_facePATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy db_face_install to main db_fflpr <<<<<<<<<<<<<<<<<<<<<<<\n"); - } -#endif - if (FileExist(face_installPATH) == 1 && (FileExist(facePATH) == 0 || ReadFileSize(facePATH) == 0)) { - CopyFileTo(face_installPATH, facePATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy face_install to main face <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - - if (FileExist(cold_objects_installPATH) == 1 && (FileExist(cold_objectsPATH) == 0 || ReadFileSize(cold_objectsPATH) == 0)) { - CopyFileTo(cold_objects_installPATH, cold_objectsPATH); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy cold_objects_install to main cold_objects <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - - if (FileExist("/emmc/plugin/Aida_data/heatmap_data_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_bak.js") >= 1) { - CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_bak.js", "/emmc/plugin/Aida/heatmap_data.js"); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_bak to main heatmap_data <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - - if (FileExist("/emmc/plugin/Aida_data/heatmap_data_1_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_1_bak.js") >= 1) { - CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_1_bak.js", "/emmc/plugin/Aida/heatmap_data_1.js"); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_1_bak to main heatmap_data_1 <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - - if (FileExist("/emmc/plugin/Aida_data/heatmap_data_2_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_2_bak.js") >= 1) { - CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_2_bak.js", "/emmc/plugin/Aida/heatmap_data_2.js"); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_2_bak to main heatmap_data_2 <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - - if (FileExist("/emmc/plugin/Aida_data/heatmap_data_3_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_3_bak.js") >= 1) { - CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_3_bak.js", "/emmc/plugin/Aida/heatmap_data_3.js"); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_3_bak to main heatmap_data_3 <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - - if (FileExist("/emmc/plugin/Aida_data/heatmap_data_4_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_4_bak.js") >= 1) { - CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_4_bak.js", "/emmc/plugin/Aida/heatmap_data_4.js"); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_4_bak to main heatmap_data_4 <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - - if (FileExist("/emmc/plugin/Aida_data/heatmap_data_5_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_5_bak.js") >= 1) { - CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_5_bak.js", "/emmc/plugin/Aida/heatmap_data_5.js"); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_5_bak to main heatmap_data_5 <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - - if (FileExist("/emmc/plugin/Aida_data/heatmap_data_6_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_6_bak.js") >= 1) { - CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_6_bak.js", "/emmc/plugin/Aida/heatmap_data_6.js"); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_6_bak to main heatmap_data_6 <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - - if (FileExist("/emmc/plugin/Aida_data/heatmap_data_7_bak.js") == 1 && ReadFileSize("/emmc/plugin/Aida_data/heatmap_data_7_bak.js") >= 1) { - CopyFileTo("/emmc/plugin/Aida_data/heatmap_data_7_bak.js", "/emmc/plugin/Aida/heatmap_data_7.js"); - printf(">>>>>>>>>>>>>>>>>>>>>> Copy heatmap_data_7_bak to main heatmap_data_7 <<<<<<<<<<<<<<<<<<<<<<<\n"); - } - -#ifdef GY_OS_AMBA - char sdk_versionPATH[1024] = { 0 }; - strcpy(sdk_versionPATH, exePath); - strcat(sdk_versionPATH, "sdk_version.txt"); - - { - char *filename = sdk_versionPATH; - if (FileExist(filename)) { - char* fileBuf = ReadAllBytes(filename); - - //printf("\n[run server]----sdk version:%s\n", fileBuf); - - if (strstr(fileBuf, "3.0") != NULL) { - g_IsSDK_3_0 = 1; - } - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - } - } -#endif -} - -#ifdef GY_OS_NOVA -int get_pid_nova_driver() { - char *temp = NULL; - int size_psBuffer = 512; - char psBuffer[512] = { 0 }; - - { - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - sprintf(cmd, "pidof nova_driver"); - FILE * pPipe; - pPipe = vpopen(cmd, "r"); - - if (pPipe != NULL) { - temp = fgets(psBuffer, size_psBuffer, pPipe); - if (pPipe != NULL) - vpclose(pPipe); - } - } - if (temp != NULL && (int)strlen(psBuffer) >= 1) { - /* - printf("\n-------------------------------\n"); - printf("\psBuffer: %d\n", atoi(psBuffer)); - printf("\n-------------------------------\n"); - */ - return atoi(psBuffer); - } - - return -1; -} - -int g_check_run_nova_detection = 0; -void *RUN_NOVA_DETECTION(void *ptr) { //A11en - pthread_detach(pthread_self()); - setPthreadName("RUN_NOVA"); - usSleep(1000000); - - system("killall -15 nova_driver"); - usSleep(15000000); - char cmd[256] = { 0 }; - sprintf(cmd,"/emmc/plugin/Aida_data/nova_driver server -http_port %s &", accountData[0].account_aida_port); - g_check_run_nova_detection = 1; - system(cmd); - - usSleep(2000000); - - if (get_live_mode_flag() == 1 && g_check_run_nova_detection == 1) { - if (get_pid_nova_driver() == -1) { - - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "get_pid_nova_driver() == -1"); - write_to_logs_html(temp_msg, "RUN NOVA DETECTION", "CGI_REBOOT", "Yes"); - write_to_log_if_error(temp_msg, "RUN NOVA DETECTION", "CGI_REBOOT"); - - pthread_t auto_reboot_thread_id; - if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) - { - printf("\ncreate auto reboot thread faile \n"); - } - } - } - - pthread_exit(NULL); -} -#endif \ No newline at end of file diff --git a/src/detector_Ming.h b/src/detector_Ming.h deleted file mode 100644 index 5f4ebf5..0000000 --- a/src/detector_Ming.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#ifndef DETECTOR_H -#define DETECTOR_H -#include "define_inc.h" -#include -#include "setting.h" - -#ifdef __cplusplus -extern "C" { -#endif - - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/src/nweb.c b/src/nweb.c index 161b9b4..d3856d0 100644 --- a/src/nweb.c +++ b/src/nweb.c @@ -7944,6 +7944,9 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch (strcmp(urlBuffer, "/Aida/snmptoken.html") == 0) || (strcmp(urlBuffer, "/Aida/osdtoken.html") == 0) || (strcmp(urlBuffer, "/Aida/jquery.easyui.min.js") == 0) || + (strcmp(urlBuffer, "/Aida/codemirror.min.css") == 0) || // for python codemirror + (strcmp(urlBuffer, "/Aida/codemirror.min.js") == 0) || // for python codemirror + (strcmp(urlBuffer, "/Aida/python.min.js") == 0) || // for python codemirror (strcmp(urlBuffer, "/Aida/jquery.slider.js") == 0) || (strcmp(urlBuffer, "/Aida/aes.js") == 0) || (strcmp(urlBuffer, "/Aida/easyui.css") == 0) || @@ -16529,12 +16532,14 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch // 不讀正在寫的行數 // printf("!!! [/pythongetbuffer] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); pthread_mutex_lock(&mutex_buffer); + // 拿 python 輸出 printf("[pythongetbuffer] get %d data \n",g_uiWebPythonLastBufferIndex); strcat(sPythonBufferTemp, g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex]); // 清空拿過的 row memset(g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex], 0, WEBPYTHONBUFFER_ROWSIZE); pthread_mutex_unlock(&mutex_buffer); // 解鎖 + // 更新讀取位置 g_uiWebPythonLastBufferIndex++; } diff --git a/src/nweb_Ming.c b/src/nweb_Ming.c deleted file mode 100644 index 44d394c..0000000 --- a/src/nweb_Ming.c +++ /dev/null @@ -1,25843 +0,0 @@ - - -#pragma comment(lib, "WS2_32.lib") /* program use socket library */ -#pragma warning(disable:4996) -#define _CRT_SECURE_NO_DEPRECATE - -#include "define_inc.h" -#include "url_encode.h" -#ifdef GY_OS_AMBA -#include "ptz.h" -//#include "tof.h" -//#include "radar.h" -//#include "radar_receive.h" // leo 09-28 -#endif -#include "cold_zone.h" -#include - -#include -#include -#include -#include -#ifdef GY_OS_AMBA -//#include "radar_parser.h" -#endif - -#ifndef TRY_CATCH -#define TRY_CATCH -#define TRY do{ jmp_buf ex_buf__; if( !setjmp(ex_buf__) ){ -#define CATCH } else { -#define ETRY } }while(0) -#define THROW longjmp(ex_buf__, 1) -#endif - -#ifdef GY_OS_WIN -#include -#include -#include -#elif defined GY_OS_AMBA || defined GY_OS_NOVA -#include -#include -#include -#include -#include - -#include -#include - -#endif - -#include /* Added for the nonblocking socket */ -#include -#include - -//#include "image.h" -#include "layer.h" -#include "network.h" -#include "nweb.h" -#include "setting.h" -//#include "utility.h" -#include "cryptionPlus.h" -#include "cJSON.h" -#include "zlog.h" -#include "fflpr_plate_db.h" -#include "cgicmd.h" -#include "test_nnctrl_live.h" -#include "pns.h" -#include "net_curl.h" -#include "strptime_c.h" -#ifdef GY_OS_NOVA -#include "bbox_receive.h" -#endif -//#include "curl.h" - -//#include -//#include "SSLClient.h" - -#include -#include - -#include "sha1.h" -#include "intLib.h" -#include "websocket.h" - -#include "url_encode.h" - -#ifdef GY_OS_AMBA -#include "pythonR.h" -//#include "jvc_progress.h" -#endif - -#ifdef OPENCV -#include "opencv2/highgui/highgui_c.h" -#include "opencv2/imgproc/imgproc_c.h" -#include "opencv2/core/types_c.h" -#include "opencv2/core/version.hpp" -#ifndef CV_VERSION_EPOCH -#include "opencv2/videoio/videoio_c.h" -#include "opencv2/imgcodecs/imgcodecs_c.h" -#endif -#endif - -#include "fork_pipe_lib.h" -#include "ivsC.h" - -#ifdef GY_OS_WIN -extern int UpdateTrafficLightZone(int tracking_channel_idx); -#endif - -#ifdef GY_OS_NOVA -extern RecvBbox g_current_bbox_list[MAX_TRACKING_NUM]; -extern int g_count_bbox_list; - -extern RecvBbox temp_current_bbox_list[MAX_TRACKING_NUM]; -extern int temp_count_bbox_list; - -extern int g_check_if_run_parse_json_data_from_bbox_receive; -#endif - -extern int reload_dataset_from_jsonfile(void); //0 fail, 1 success -//extern int default_dataset_for_jsonfile(void); //0 fail, 1 success - -pthread_mutex_t mutex_http_layer[MAX_LAYER_NUM]; -extern pthread_mutex_t mutex_getalarmmotion; -extern pthread_mutex_t mutex_alm; -extern pthread_mutex_t mutex_curl; -extern pthread_mutex_t mutex_websocket; -extern pthread_mutex_t mutex_enable_lpr_db; -#ifdef GY_OS_AMBA -extern pthread_mutex_t mutex_enable_face_db; -#endif -extern pthread_mutex_t mutex_username; -extern pthread_mutex_t mutex_config_json; -#if defined GY_OS_AMBA -//extern pthread_mutex_t mutex_jvc_config_json; -#endif -extern pthread_mutex_t mutex_events_json; -#ifdef GY_OS_AMBA -extern pthread_mutex_t mutex_radar_json; // Ken 2022-09-22 -extern pthread_mutex_t mutex_tof_json; -#endif -extern pthread_mutex_t mutex_web; -//extern pthread_mutex_t mutex_http_connection_handler; -extern pthread_mutex_t mutex_base64; -//extern pthread_mutex_t mutex_get_canvas; -extern pthread_mutex_t mutex_get_network_input; -extern pthread_mutex_t mutex_buffer; - -extern pthread_mutex_t mutex_set_http_request; -extern pthread_mutex_t mutex_reset_counter; -extern pthread_mutex_t mutex_get_image; -extern pthread_mutex_t mutex_get_image_HD; - -extern pthread_mutex_t mutex_snap_image; -#ifdef GY_OS_NOVA -extern pthread_mutex_t mutex_pre_connection; -#endif -#ifdef GY_OS_AMBA -extern pthread_mutex_t mutex_remotesnap_image; -#endif -//extern pthread_mutex_t mutex_snap_hd_image; - -#ifdef GY_OS_AMBA -extern pthread_mutex_t mutex_perspective_transform; -#endif - -#ifdef GY_OS_NOVA -extern pthread_mutex_t mutex_run_parse_json; -#endif - -zlog_category_t *zc=NULL; - -extern int sharkhand_s(int client_socket, char *buffer, int *iIsWebsocket_hybi_00); - -extern int websocket_response(int connfd, char* message); - -extern char* global_message_for_pns_response; - -int g_socket; -// Ken -//extern char *global_message_for_radar_response; -#ifdef GY_OS_AMBA -extern char *g_radar_image_queue; -#endif - -struct timeval currtime_setosd; -long last_ms_setosd = 0; -long current_ms_setosd = 0; - -int CheckIsExistingSpeed = 0; - -int g_dual_sensor = 0; - -int g_camera_white_LED = 0; - -int g_change_getnetwork_buffer_id = 0; - -int g_check_h264_gop = 1; - -#if defined GY_OS_AMBA -int g_isAiRelay = 0; -#endif -struct -{ - char *ext; - char *filetype; -} -extensions[] = -{ -{ "gif", "image/gif" }, -{ "jpg", "image/jpeg" }, -{ "jpeg", "image/jpeg" }, -{ "png", "image/png" }, -{ "ico", "image/ico" }, -{ "zip", "image/zip" }, -{ "gz", "image/gz" }, -{ "tar", "image/tar" }, -{ "htm", "text/html" }, -{ "html", "text/html" }, -{ "css", "text/css" }, -{ "js", "text/javascript" }, -{ "wasm", "application/wasm" }, -{ 0, 0 } -}; - - -//===================== -//sophia add 2020/09/24 -#if defined GY_OS_AMBA || defined GY_OS_NOVA -//SocketInfo_ALM socketRecord_ALM[MAX_CLIENT_SOCKET] = { 0 }; -int bHttpServerMainStart = 0; -int bPreloadHttpServerMainStart = 0; -#endif -//===================== - -CNNType http_cnn_type; -//static network http_nets[MAX_LAYER_NUM]; -//static char **http_names[MAX_LAYER_NUM]; -//static image **http_alphabet; -static float http_thresh; -static float http_hier_thresh; -//static float http_nms[MAX_LAYER_NUM]; -static int http_dont_show; -static int http_ext_output; -static int http_save_labels; -//static char *http_ip_address; -//static char *http_mac_address; -static int http_http_port; -//static int http_layer_count; -static LicenseType http_licenseType; -static AdvanceLicenseType http_advLicenseType; -static AuthFailStatusCode http_afsCode; -static size_t http_featureType; -static size_t http_layerFeatureType[MAX_LAYER_NUM]; -static char *http_strLicenseType; -//static char *http_strLicenseStatus; -//static char *http_strUnlockingKey; - -extern double http_license_fps; -extern int http_sleep_interval; -unsigned int python_check_webstatus = 0; -float confidence_limit; - -extern CPoint trafficLightPoint; -extern int traffic_light_zone_width; -extern int traffic_light_zone_height; -//extern pthread_mutex_t mutex_post_notification; - -char websocket_alarm[CONTENT_BUFSIZE] = { 0 }; - -static float diff; - -int AI_fps = -1; // 變數定義,並且設定初始值 -#ifdef GY_OS_NOVA -int AI_fps2 = -1; //nova_driver的fps -#endif - -static char g_account_port_protected[512] = { 0 }; - -#ifdef REBOOT_BY_CPU_GPU_USAGE -int CPU_usage_int = -1; -int GPU_usage_int = -1; -#endif - -//bool enable_loop_getalarmmotion = FALSE; //變數定義,並且設定初始值 -//int times_of_enable_loop_getalarmmotion = 1; //前面要呼叫isFirstAlarmMotion幾次 -char CPU_usage[256] = { 0 }; -char GPU_usage[256] = { 0 }; -char Buffer_ver[BUFSIZE] = { 0 }; -int g_write_config_file_dirty_flag = 0; - -static char g_record_session_id[MAX_NUMBER_SESSION][MAX_SESSION_ID] = { 0 }; - -#if 0 -static int enable_base64 = 0; -#endif - -int enable_only_show_metadata1 = 1; - -int g_check_if_get_picture_not_OK = 0; - -int g_i_get_cpu_loading = 0; - -//CURL_SEND g_stCURL_send_data = { 0 }; - -static char g_stCURL_send_data_q_name[30] = { 0 }; -static char g_stCURL_send_data_q_plate[60] = { 0 }; - -static char g_stCURL_send_data_curl_url[8192] = { 0 }; -static char g_stCURL_send_data_curl_sendbuf[MAX_IMG_SIZE] = { 0 }; -size_t g_stCURL_send_data_curl_sendbuf_size = 0; -static char g_stCURL_send_data_method[32] = { 0 }; -static char g_stCURL_send_data_protocol[32] = { 0 }; -static char g_stCURL_send_data_username[64] = { 0 }; -static char g_stCURL_send_data_password[64] = { 0 }; -static char g_stCURL_send_data_port[10] = { 0 }; //strtol(q_info->host_port, NULL, 10) -static char g_stCURL_send_data_timeout[10] = { 0 }; -static char g_stCURL_send_data_customized_header[8192] = { 0 }; -static int g_stCURL_image_buff_size=0; -static char g_stCURL_image_buff[MAX_IMG_SIZE] = {0}; -static int g_stCURL_check_127 = 0; -static int g_stCURL_enable_attached_image = 0; -static int g_stCURL_enable_filename_fixed = 0; -static char g_stCURL_send_jpeg_file_name[60] = { 0 }; -static char g_response_net_curl[MAX_IMG_SIZE] = { 0 }; -static int g_response_post_OK = 0; - -#ifdef GY_OS_AMBA -static char g_response_snmp[8192] = { 0 }; - -static char g_stCURL_lpr_db_url[8192] = { 0 }; -static char g_stCURL_lpr_db_username[64] = { 0 }; -static char g_stCURL_lpr_db_password[64] = { 0 }; -static char g_stCURL_lpr_db_port[10] = { 0 }; -static char g_response_lpr_db[8192] = { 0 }; -#endif - -static char g_headerBuffer[BUFSIZE_V2] = { 0 }; -static char g_multiPartBoundary[MAX_MSG_LEN] = { 0 }; -static int g_bIsMultipart = 0; -static char g_contentBuffer[CONTENT_BUFSIZE] = { 0 }; -static long g_nTotalContentLen = 0; -static int g_count_lpr_insert_times = -1; //-1代表沒在做或做完了 0代表開始 >0代表import的個數 - -//static char g_image_buff[MAX_IMG_SIZE]; -//size_t g_image_buff_size; - -int switch_g_image_buff_ori = 0; -int g_current_max_num_image_buff = 5; -char g_image_buff_ori[MAX_NUM_IMAGE_BUFF][MAX_IMG_SIZE] = { 0 }; -int g_image_buff_size_ori[MAX_NUM_IMAGE_BUFF] = { 0 }; -char g_image_state_response_ori[256] = { 0 }; - -long g_post_SysTimeStamp_ori[MAX_NUM_IMAGE_BUFF] = { 0 }; - -int g_video_start_HD = 1; -#if defined GY_OS_AMBA -char g_image_buff_HD[MAX_NUM_IMAGE_BUFF][MAX_IMG_SIZE_HD] = { 0 }; -int g_image_buff_size_HD[MAX_NUM_IMAGE_BUFF] = { 0 }; -char g_image_buff_HD_pause[MAX_IMG_SIZE_HD] = { 0 }; -#endif -int g_image_buff_size_HD_pause = 0; -long g_image_HD_pasue_time = 0; - -int g_framesize_width = 0; -int g_framesize_height = 0; - -int g_framesize_width_HD = 0; -int g_framesize_height_HD = 0; - -#ifdef GY_OS_AMBA -//face -char g_image_buff[MAX_IMG_SIZE_HD] = { 0 }; -char g_decrypt_buff[MAX_IMG_SIZE_HD] = { 0 }; -//face end -#endif - -#ifdef GY_OS_AMBA -int g_check_if_change_preset = 0; -#endif -static int g_check_if_snap_running = 0; -char g_snap_snapshot_addr[MAX_IMG_SIZE] = { 0 }; -#ifdef GY_OS_AMBA -//static int g_check_if_remotesnap_running = 0; -//char g_remotesnap_snapshot_addr[MAX_IMG_SIZE] = {0}; -#endif -size_t g_snap_snapshot_size = 0; -#ifdef GY_OS_AMBA -size_t g_remotesnap_snapshot_size = 0; -#endif -static int start_to_import_file = 0; -#ifdef GY_OS_AMBA -float g_min_tof_range = 0.0; -int g_min_tof_range_x = 0; -int g_min_tof_range_y = 0; - -float g_max_tof_range = 0.0; -int g_max_tof_range_x = 0; -int g_max_tof_range_y = 0; - -float g_min_tof_degree = 0.0; -float g_min_tof_height = 0.0; -float g_min_tof_distance = 0.0; - -float g_max_tof_degree = 0.0; -float g_max_tof_height = 0.0; -float g_max_tof_distance = 0.0; - -float g_ground_tof_range = 0.0; -float g_ground_tof_degree = 0.0; -float g_ground_tof_height = 0.0; -float g_ground_tof_distance = 0.0; - -double g_tof_device_height = 0.0; - -int g_bIsSendTofPCD = 1; -int g_bIsWritingPCD = 0; - -#endif - -int g_control_alarm_gpio = 0; - -int g_is_check_credential = 0; - -char g_aWebPythonBuffer2D[WEBPYTHONBUFFER_LENSIZE][WEBPYTHONBUFFER_ROWSIZE]; -unsigned int g_uiWebPythonCurrentBufferIndex = 0; -unsigned int g_uiWebPythonLastBufferIndex = 0; -unsigned int g_cWebPythonBufferSignal = 0; -unsigned int g_cWebPythonDeleteStatus = 0; -unsigned int g_cWebPythonStatus = 0; -char g_cWebPythonName[50]; -struct MemoryStruct -{ - char memory[MEMORY_SIZE];//256KB - size_t size; -}; - -int get_g_control_alarm_gpio() { - return g_control_alarm_gpio; -} - -void set_g_control_alarm_gpio_to_zero() { - g_control_alarm_gpio = 0; -} - -void set_g_control_alarm_gpio_to_one() { - g_control_alarm_gpio = 1; -} - -void memset_snapshot_addr() { - for (int i = 0; i < MAX_SNAP_HD_LIST; i++) { - memset(snapHDList[i].snapshot_addr, 0x00, MAX_IMG_SIZE); - } -} - -static size_t WriteResponseString(void* contents, size_t size, size_t nmemb, void* user_ptr) -{ - size_t realsize = size * nmemb; - struct MemoryStruct* mem = (struct MemoryStruct*)user_ptr; - - /* - char* ptr = realloc(mem->memory, mem->size + realsize + 1); - if (!ptr) { - // out of memory! - printf("\nnot enough memory (realloc returned NULL)\n"); - return 0; - }*/ - - if (mem->size + realsize + 1 >= MEMORY_SIZE)//25KB - { - printf("\nover MEMORY_SIZE KB memory (returned NULL)\n"); - return 0; - } - - //mem->memory = ptr; - memcpy(&(mem->memory[mem->size]), contents, realsize); - mem->size += realsize; - mem->memory[mem->size] = 0; - - return realsize; -} - -#define SOCKET_SEND_ERROR_COUNT 10 -#if 0 -void syslog(int type, char *s1, char *s2, int num) -{ - FILE *fp; - static char log_buf[LOG_BUFSIZE]; - - switch (type) - { - case NW_ERROR: - sprintf(log_buf, "ERROR: %s:%s Errno = %d", s1, s2, errno); - break; - - case NW_SORRY: - sprintf(log_buf, - "

nweb Web Server: %s %s

\r\n", - s1, s2); - send(num, log_buf, strlen(log_buf), 0); - sprintf(log_buf, "SORRY: %s:%s", s1, s2); - break; - - case NW_LOG: - sprintf(log_buf, " INFO: %s:%s:%d", s1, s2, num); - break; - } - - /* write event data to the log file 'nweb.syslog' */ - if ((fp = fopen("nweb.syslog", "a")) != NULL) - { - strncat(log_buf, "\n", LOG_BUFSIZE); - fprintf(fp, log_buf); - fclose(fp); - } -#ifdef GY_OS_WIN - if (type == NW_ERROR || type == NW_SORRY) - { - WSACleanup(); - exit(1); - } -#endif -} -#endif - -char* FindHttpContentStart(char* buffer) -{ - for (int i = 0; i < BUFSIZE_V2; i++) - { - //char* b = buffer + i; - - if (memcmp(buffer + i, "\r\n\r\n", strlen("\r\n\r\n")) == 0) - { - return buffer + i + strlen("\r\n\r\n"); - break; - } - } - return NULL; -} - -void DumpCharacters(char* str, int length) -{ - for (int i = 0; i < length; i++) - printf("%c", *(str + i)); - printf("\n"); -} - -char *removeHTTPHeader(char *buffer, int *bodySize) { - char *t = strstr(buffer, "\r\n\r\n"); - t = t + 4; - - for (char* it = buffer; it != t; ++it) { - ++(*bodySize); - } - - return t; -} - -void getPicture(int socketfd, int bSize,int current_profile_id,int enable_check_profile_id) { - //printf("\n----------getPicture: 1\n"); - //printf("\n--------socketfd:%d,bSize:%d\n", socketfd, bSize); - - char buffer_image[MAX_IMG_SIZE_HD] = { 0 }; - char buffer[MAX_IMG_SIZE_HD] = { 0 }; - size_t bReceived; - - //bReceived = recv(socketfd, buffer, bSize, 0); - - int try_gethead = 0; - while (bHttpServerMainStart) { - bReceived = recv(socketfd, buffer, bSize, 0); - - if (strlen(buffer) == 0) { - g_check_if_get_picture_not_OK = 1; - } - else { - g_check_if_get_picture_not_OK = 0; - } - - if (strstr(buffer, "HTTP") != NULL) - break; - - if (try_gethead >= 10) - break; - - printf("\n-----------get Picture try to receive buffer head:%s\n", buffer); - memset(buffer, 0, bSize); - - try_gethead++; - - usSleep(1); - if (g_check_if_get_picture_not_OK == 1) { - usSleep(1000000); - } - } - if (g_check_if_get_picture_not_OK == 1) { - usSleep(1000000); - } - - int bodySize = 0; - int content_length_image = 0; - - - //char *t = removeHTTPHeader(buffer, &bodySize); - //bodySize = 0; -#if 0 - bodySize = bReceived - bodySize; - if (bodySize >= 1 && bodySize <= bSize) { - memcpy(buffer_image, t, bodySize); - } - printf("\n--------------getPicture---5-------bodySize:%d\n", bodySize); - printf("\n--------------buffer:%s\n", buffer); -#endif - - int framesize_width = 0; - int framesize_height = 0; - - if (strstr(buffer, "framesize=") != NULL) { - char *ptr_1 = strstr(buffer, "framesize=")+10; - char *ptr_2 = strstr(ptr_1,"&"); - if (ptr_2 != NULL) { - int ptr_length = ptr_2 - ptr_1; - char buff_temp[15] = { 0 }; - memcpy(buff_temp,ptr_1, ptr_length); - //printf("\n-----------------buff_temp:%s\n", buff_temp); - - char outArray[2][STRSPLIT_SIZE]={0}; - StrSplit(buff_temp, outArray, "x"); - //printf("\n------UU:19\n"); - - framesize_width = atoi(outArray[0]); - framesize_height = atoi(outArray[1]); - //printf("\n----------buff_temp:%s\n", buff_temp); - //printf("\n----------outArray[0]:%s\n", outArray[0]); - //printf("\n----------outArray[1]:%s\n", outArray[1]); - //printf("\n------------g_framesize_width:%d,g_framesize_height:%d\n", g_framesize_width, g_framesize_height); - } - } - - if (enable_check_profile_id == 1) { - g_framesize_width = framesize_width; - g_framesize_height = framesize_height; - } - else { - g_framesize_width_HD = framesize_width; - g_framesize_height_HD = framesize_height; - } - //struct timeval currtime; - //gettimeofday(&currtime, NULL); - //long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 - //long last_ms = now_ms; - - //printf("\n----------getPicture: 2: %s\n", buffer); - if (strstr(buffer, "HTTP/1.1 200") != NULL && strstr(buffer, "encode=jpeg") != NULL && - framesize_width >= 1 && framesize_width <= 1280 && - framesize_height >= 1 && framesize_height <= 960) - { - - //bodySize = 0; - //if (content_length_image >= 1) - { - memset(buffer, 0, bSize); - bodySize = 0; - content_length_image = 0; - //printf("\n----------getPicture: 3\n"); - - while (bHttpServerMainStart && (bReceived = recv(socketfd, buffer, bSize, 0)) > 0) { - - //printf("\n----------get Picture start\n"); - - //if (switch_g_image_buff_ori == 1) - { - //if (enable_check_profile_id == 0) - { - //printf("\n-------------------------buffer:%s\n", buffer); - //printf("\n-------------------------bReceived:%d\n", bReceived); - } - - if (bReceived >= 3) { - if (strncmp(buffer, "--myboundary", 12) == 0) { - char *ptr_1 = strstr(buffer, "Content-Length: "); - char *ptr_buffer = strstr(buffer, "--myboundary"); - if (ptr_1) { - char *ptr_2 = strstr(ptr_1, "\r\n"); - if (ptr_2) { - int strlen_ptr = ptr_2 - ptr_1 - 16; - char boundary[256] = { 0 }; - if (strlen_ptr >= 1) { - strncpy(boundary, ptr_1 + 16, strlen_ptr); - //printf("\n-----------boundary:%s\n", boundary); - content_length_image = atoi(boundary); - //printf("\n-------------content_length_image:%d\n", content_length_image); - - ptr_2 = ptr_2 + 4; - - int head_length = ptr_2 - ptr_buffer; - - memset(buffer_image, 0x00, MAX_IMG_SIZE_HD); - if (head_length >= 1 && content_length_image >= 1) { - if (bReceived == head_length + content_length_image + 2) { - memcpy(buffer_image, ptr_2, content_length_image); - bodySize = content_length_image; - content_length_image = 0; - } - else if (bReceived == head_length + content_length_image) { - memcpy(buffer_image, ptr_2, content_length_image); - bodySize = content_length_image; - content_length_image = 0; - } - else if (bReceived > head_length) { - memcpy(buffer_image, ptr_2, bReceived - head_length); - bodySize = bReceived - head_length; - content_length_image -= bodySize; - } - - //if (enable_check_profile_id == 0) - { - //printf("\n-getPicture---TTT#2-bReceived:%d\n", bReceived); - //printf("\n-------------------buffer_image#2:%s\n", buffer_image); - - //printf("\n-----------content_length_image #2:%d\n", content_length_image); - //printf("\n-----------bodySize #2:%d\n", bodySize); - } - } - } - } - } - } - else { - if (content_length_image >= 1) { - if (bReceived == content_length_image + 2) { - memcpy(buffer_image + bodySize, buffer, content_length_image); - bodySize += content_length_image; - content_length_image = 0; - } - else if (bReceived == content_length_image) { - memcpy(buffer_image + bodySize, buffer, content_length_image); - bodySize += content_length_image; - content_length_image = 0; - } - else if (bReceived < content_length_image) { - memcpy(buffer_image + bodySize, buffer, bReceived); - bodySize += bReceived; - content_length_image -= bReceived; - } - - //if (enable_check_profile_id == 0) - { - //printf("\n--------------getPicture---TTT------bReceived:%d\n", bReceived); - //printf("\n-------------------buffer_image#1:%s\n", buffer_image); - - //printf("\n-----------content_length_image #1:%d\n", content_length_image); - //printf("\n-----------bodySize #1:%d\n", bodySize); - } - } - } - } - - if (content_length_image <= 0) { - if (bodySize >= 1) { - - //printf("\n--------bodySize:%d\n", bodySize); - - if (enable_check_profile_id == 1) { - pthread_mutex_lock(&mutex_get_image); - g_post_SysTimeStamp_ori[0] = g_osdSysTimeStamp; - for (int i = MAX_NUM_IMAGE_BUFF - 1; i >= 1; i--) { - if (g_image_buff_size_ori[i - 1]) { - memcpy(g_image_buff_ori[i], g_image_buff_ori[i - 1], g_image_buff_size_ori[i - 1]); - g_image_buff_size_ori[i] = g_image_buff_size_ori[i - 1]; - g_post_SysTimeStamp_ori[i] = g_post_SysTimeStamp_ori[i - 1]; - } - } - memcpy(g_image_buff_ori[0], buffer_image, bodySize); - g_image_buff_size_ori[0] = bodySize; - pthread_mutex_unlock(&mutex_get_image); - -#if defined GY_OS_AMBA - if (atoi(SystemSetting.getimage_encoder_id_HD) == atoi(SystemSetting.getimage_encoder_id)) { - pthread_mutex_lock(&mutex_get_image_HD); - for (int i = MAX_NUM_IMAGE_BUFF - 1; i >= 1; i--) { - if (g_image_buff_size_HD[i - 1]) { - memcpy(g_image_buff_HD[i], g_image_buff_HD[i - 1], g_image_buff_size_HD[i - 1]); - g_image_buff_size_HD[i] = g_image_buff_size_HD[i - 1]; - } - } - memcpy(g_image_buff_HD[0], buffer_image, bodySize); - g_image_buff_size_HD[0] = bodySize; - pthread_mutex_unlock(&mutex_get_image_HD); - } -#endif - } - else { -#if defined GY_OS_AMBA - pthread_mutex_lock(&mutex_get_image_HD); - for (int i = MAX_NUM_IMAGE_BUFF - 1; i >= 1; i--) { - if (g_image_buff_size_HD[i - 1]) { - memcpy(g_image_buff_HD[i], g_image_buff_HD[i - 1], g_image_buff_size_HD[i - 1]); - g_image_buff_size_HD[i] = g_image_buff_size_HD[i - 1]; - } - } - memcpy(g_image_buff_HD[0], buffer_image, bodySize); - g_image_buff_size_HD[0] = bodySize; - pthread_mutex_unlock(&mutex_get_image_HD); -#endif - } - - if(enable_check_profile_id == 1) - strcpy(g_image_state_response_ori, "OK"); - - //gettimeofday(&currtime, NULL); - //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 - //double dw_FPS_time_delta = (double)(now_ms - last_ms); - //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); - //printf("\n-----image fps:%lf\n",1000.0/dw_FPS_time_delta); - //last_ms = now_ms; - } - else if (bodySize == 0) { - if (enable_check_profile_id == 1) - strcpy(g_image_state_response_ori, "Encoder: The resolution is not supported."); - } - bodySize = 0; - content_length_image = 0; - memset(buffer_image, 0x00, MAX_IMG_SIZE_HD); - //break; - } - - } - - //printf("\n----------get Picture end\n"); - //printf("\n-----strlen:%d\n",strlen(buffer)); - memset(buffer, 0, bSize); - //usSleep(65000); - usSleep(10000); - - if (enable_check_profile_id == 1) - { - if (current_profile_id != (atoi(SystemSetting.getimage_encoder_id) - 1)) - break; - } -#if defined GY_OS_AMBA - else { - if (current_profile_id != (atoi(SystemSetting.getimage_encoder_id_HD) - 1)) - break; - } -#endif - } - } - } - else { - //printf("\n----------getPicture: 4: %s\n", buffer); - - if (enable_check_profile_id == 1) - strcpy(g_image_state_response_ori,"Encoder: The profile name is not jpeg."); - } - - //printf("\n------------bodySize:%d\n", bodySize); - //printf("\n----------getPicture: 5\n"); -} -#ifdef GY_OS_NOVA -void get_nova_driver(int socketfd) { - //printf("\n----------getPicture: 1\n"); - //printf("\n--------socketfd:%d,bSize:%d\n", socketfd, bSize); - - char buffer[65535] = { 0 }; - size_t bReceived; - - //struct timeval currtime; - //gettimeofday(&currtime, NULL); - //long now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 - //long last_ms = now_ms; - - while (bHttpServerMainStart && (bReceived = recv(socketfd, buffer, 65535, 0)) > 0) { - - //printf("\n----------get Picture start\n"); - - //printf("\n---------buffer:%s\n", buffer); - //printf("\n-------strlen:%d\n", strlen(buffer)); - if (strstr(buffer, "GET /send_nova_driver") != NULL) { - - //printf("\nKKKKKKKKKKK:g_check_if_run_parse_json_data_from_bbox_receive:%d,g_count_bbox_list:%d\n", g_check_if_run_parse_json_data_from_bbox_receive, g_count_bbox_list); - if (g_check_if_run_parse_json_data_from_bbox_receive == 0 && g_count_bbox_list == 0) { - //printf("\n-------kkkkkkkkkkkk: 1\n"); - - - - char * start_mydata = strstr(buffer, "{\"AiEngine\""); - if (start_mydata != NULL) { - //printf("\n-------kkkkkkkkkkkk: 2\n"); - char * end_mydata = strstr(start_mydata, "-----end_nova_driver"); - if (end_mydata != NULL) { - //printf("\n-------kkkkkkkkkkkk: 3\n"); - int recv_len = end_mydata - start_mydata; - if (recv_len >= 1) { - //printf("\n-------kkkkkkkkkkkk: 4\n"); - char mydata[BUFSIZE * 59] = { 0 }; - memcpy(mydata, start_mydata, recv_len); - //printf("\n---------mydata:%s\n", mydata); - - cJSON *root/*, *res_height, *res_width*/, *cJSON_AI_fps2, *detect_count, *AiEngine, *detect; - cJSON *id, *confidence, *class_id, *x, *y, *w, *h, *object_score, *class_score; - cJSON *parent_idx_temp, *obj_type_temp, *featuretype_temp, *enginetype_temp, *featuretype2_temp, *enginetype2_temp, *name_temp/*, *plate_temp*/; - cJSON *id_img, *size_base64_img, *cjson_crop_w, *cjson_crop_h; - - root = cJSON_Parse(mydata); - - if (root) { - //res_height = cJSON_GetObjectItem(root, "res_height"); - //res_width = cJSON_GetObjectItem(root, "res_width"); - detect_count = cJSON_GetObjectItem(root, "Count"); - AiEngine = cJSON_GetObjectItem(root, "AiEngine"); - cJSON_AI_fps2 = cJSON_GetObjectItem(root, "AI_fps"); - - if (cJSON_AI_fps2) { - AI_fps2 = cJSON_AI_fps2->valueint; - } - - /* - if (res_height) { - g_res_height = res_height->valueint; - } - else { - g_res_height = NET_SIZE_H; - } - - if (res_width) { - g_res_width = res_width->valueint; - } - else { - g_res_width = NET_SIZE_W; - }*/ - - if (detect_count) { - if (detect_count->valueint <= MAX_TRACKING_NUM) { - temp_count_bbox_list = detect_count->valueint; - } - else { - temp_count_bbox_list = MAX_TRACKING_NUM; - } - - //printf("\n---------------temp_count_bbox_list:%d\n", temp_count_bbox_list); - } - else { - temp_count_bbox_list = 0; - } - - if (temp_count_bbox_list >= 1) - { - int i = 0; - cJSON_ArrayForEach(detect, AiEngine) - { - id = cJSON_GetObjectItem(detect, "id"); - confidence = cJSON_GetObjectItem(detect, "confidence"); - object_score = cJSON_GetObjectItem(detect, "object_score"); - class_score = cJSON_GetObjectItem(detect, "class_score"); - class_id = cJSON_GetObjectItem(detect, "class_id"); - x = cJSON_GetObjectItem(detect, "x"); - y = cJSON_GetObjectItem(detect, "y"); - w = cJSON_GetObjectItem(detect, "w"); - h = cJSON_GetObjectItem(detect, "h"); - - parent_idx_temp = cJSON_GetObjectItem(detect, "parent_idx"); - obj_type_temp = cJSON_GetObjectItem(detect, "obj_type"); - featuretype_temp = cJSON_GetObjectItem(detect, "featuretype"); - enginetype_temp = cJSON_GetObjectItem(detect, "enginetype"); - featuretype2_temp = cJSON_GetObjectItem(detect, "featuretype2"); - enginetype2_temp = cJSON_GetObjectItem(detect, "enginetype2"); - - name_temp = cJSON_GetObjectItem(detect, "name"); - //plate_temp = cJSON_GetObjectItem(detect, "plate"); - - - - size_base64_img = cJSON_GetObjectItem(detect, "cropped_size"); - id_img = cJSON_GetObjectItem(detect, "id_img"); - cjson_crop_w = cJSON_GetObjectItem(detect, "crop_w"); - cjson_crop_h = cJSON_GetObjectItem(detect, "crop_h"); - - if (id && confidence && class_id && x && y && w && h && object_score && class_score - && parent_idx_temp && obj_type_temp && featuretype_temp && enginetype_temp && featuretype2_temp && enginetype2_temp && name_temp //&& plate_temp - /*&& base64_img && size_base64_img && cjson_crop_w && cjson_crop_h*/) { - - temp_current_bbox_list[i].id = id->valueint; - temp_current_bbox_list[i].confidence = (float)confidence->valueint; - temp_current_bbox_list[i].class_id = class_id->valueint; - temp_current_bbox_list[i].x = (float)x->valueint; - temp_current_bbox_list[i].y = (float)y->valueint; - temp_current_bbox_list[i].w = (float)w->valueint; - temp_current_bbox_list[i].h = (float)h->valueint; - - temp_current_bbox_list[i].object_score = (float)object_score->valueint; - temp_current_bbox_list[i].class_score = (float)class_score->valueint; - - temp_current_bbox_list[i].parent_idx = (int)parent_idx_temp->valueint; - temp_current_bbox_list[i].obj_type = (int)obj_type_temp->valueint; - temp_current_bbox_list[i].featureType = (size_t)featuretype_temp->valueint; - temp_current_bbox_list[i].engine_type = (unsigned int)enginetype_temp->valueint; - temp_current_bbox_list[i].featureType2 = (size_t)featuretype2_temp->valueint; - temp_current_bbox_list[i].engine_type2 = (unsigned int)enginetype2_temp->valueint; - - strcpy(temp_current_bbox_list[i].name, name_temp->valuestring); - /*if (plate_temp) { - strcpy(temp_current_bbox_list[i].plate, plate_temp->valuestring); - } - else { - strcpy(temp_current_bbox_list[i].plate, ""); - }*/ - - if (size_base64_img && size_base64_img->valueint >= 1 && id_img && id_img->valueint >= 0) { - //temp_current_bbox_list[i].size_base64_cropped_img = size_base64_img->valueint; - if (cjson_crop_w) { - temp_current_bbox_list[i].crop_w = cjson_crop_w->valueint; - } - else { - temp_current_bbox_list[i].crop_w = 0; - } - - if (cjson_crop_h) { - temp_current_bbox_list[i].crop_h = cjson_crop_h->valueint; - } - else { - temp_current_bbox_list[i].crop_h = 0; - } - - //memcpy(temp_current_bbox_list[i].base64_cropped_img, base64_img->valuestring, temp_current_bbox_list[i].size_base64_cropped_img); - - if (temp_current_bbox_list[i].crop_h >= 1 && temp_current_bbox_list[i].crop_w >= 1) { - g_size_base64_cropped_img[id_img->valueint] = size_base64_img->valueint; - //memcpy(g_base64_cropped_img[g_index_base64_cropped_img], base64_img->valuestring, g_size_base64_cropped_img[g_index_base64_cropped_img]); - temp_current_bbox_list[i].image_id = id_img->valueint; - //g_index_base64_cropped_img++; - //if (g_index_base64_cropped_img >= MAX_IMAGE_YUV) { - //g_index_base64_cropped_img = 0; - //} - } - else { - temp_current_bbox_list[i].image_id = -1; - } - } - else { - //temp_current_bbox_list[i].size_base64_cropped_img = 0; - temp_current_bbox_list[i].crop_w = 0; - temp_current_bbox_list[i].crop_h = 0; - temp_current_bbox_list[i].image_id = -1; - //strcpy(temp_current_bbox_list[i].base64_cropped_img, ""); - } - - i++; - } - - /* - printf("\n----[gynet][bbox receive]After parsing received TCP json data--id:%d,confidence:%f,class_id:%d,x:%f,y:%f,w:%f,h:%f\n", - temp_current_bbox_list[i].id, - temp_current_bbox_list[i].confidence, - temp_current_bbox_list[i].class_id, - temp_current_bbox_list[i].x, - temp_current_bbox_list[i].y, - temp_current_bbox_list[i].w, - temp_current_bbox_list[i].h);*/ - - if (i >= temp_count_bbox_list) - break; - } - temp_count_bbox_list = i; - } - - if (root) { - cJSON_Delete(root); - root = NULL; - } - //printf("\n-------kkkkkkkkkkkk: 5\n"); - //if (check_if_finish_thread_bbox_list == 1) - { - pthread_mutex_lock(&mutex_run_parse_json); - - if (temp_count_bbox_list >= 1) { - //printf("\nGGGGGGGGGGG:%d\n", temp_count_bbox_list); - for (int i = 0; i < temp_count_bbox_list; i++) { - g_current_bbox_list[i].id = temp_current_bbox_list[i].id; - g_current_bbox_list[i].confidence = temp_current_bbox_list[i].confidence; - g_current_bbox_list[i].class_id = temp_current_bbox_list[i].class_id; - g_current_bbox_list[i].x = temp_current_bbox_list[i].x; - g_current_bbox_list[i].y = temp_current_bbox_list[i].y; - g_current_bbox_list[i].w = temp_current_bbox_list[i].w; - g_current_bbox_list[i].h = temp_current_bbox_list[i].h; - - g_current_bbox_list[i].object_score = temp_current_bbox_list[i].object_score; - g_current_bbox_list[i].class_score = temp_current_bbox_list[i].class_score; - - g_current_bbox_list[i].parent_idx = temp_current_bbox_list[i].parent_idx; - g_current_bbox_list[i].obj_type = temp_current_bbox_list[i].obj_type; - g_current_bbox_list[i].featureType = temp_current_bbox_list[i].featureType; - g_current_bbox_list[i].engine_type = temp_current_bbox_list[i].engine_type; - g_current_bbox_list[i].featureType2 = temp_current_bbox_list[i].featureType2; - g_current_bbox_list[i].engine_type2 = temp_current_bbox_list[i].engine_type2; - - strcpy(g_current_bbox_list[i].name, temp_current_bbox_list[i].name); - //strcpy(g_current_bbox_list[i].plate, temp_current_bbox_list[i].plate); - - if (temp_current_bbox_list[i].image_id >= 0) { - //g_current_bbox_list[i].size_base64_cropped_img = temp_current_bbox_list[i].size_base64_cropped_img; - g_current_bbox_list[i].crop_w = temp_current_bbox_list[i].crop_w; - g_current_bbox_list[i].crop_h = temp_current_bbox_list[i].crop_h; - g_current_bbox_list[i].image_id = temp_current_bbox_list[i].image_id; - //memcpy(g_current_bbox_list[i].base64_cropped_img, temp_current_bbox_list[i].base64_cropped_img, g_current_bbox_list[i].size_base64_cropped_img); - } - else { - //g_current_bbox_list[i].size_base64_cropped_img = 0; - g_current_bbox_list[i].crop_w = 0; - g_current_bbox_list[i].crop_h = 0; - g_current_bbox_list[i].image_id = -1; - //strcpy(g_current_bbox_list[i].base64_cropped_img, ""); - } - - } - g_count_bbox_list = temp_count_bbox_list; - } - else { - g_count_bbox_list = 0; - } - pthread_mutex_unlock(&mutex_run_parse_json); - - //check_if_finish_thread_bbox_list = 0; - } - } - - g_check_if_run_parse_json_data_from_bbox_receive = 1; - } - } - } - //g_check_if_run_parse_json_data_from_bbox_receive = 0; - - //gettimeofday(&currtime, NULL); - //now_ms = (currtime.tv_sec * 1000) + (currtime.tv_usec / 1000); //單位為毫秒 - //double dw_FPS_time_delta = (double)(now_ms - last_ms); - //dw_FPS_time_delta = abs((int)dw_FPS_time_delta); - //printf("\n-----get nova driver ms:%lf\n", dw_FPS_time_delta); - //last_ms = now_ms; - } - } - - //printf("\n----------get Picture end\n"); - - memset(buffer, 0x00, 65535); - usSleep(70000); - } -} -#endif - -int get_g_framesize_width() { - return g_framesize_width; -} - -int get_g_framesize_height() { - return g_framesize_height; -} -#ifdef GY_OS_NOVA -void start_nova_driver() { - int nova_driver_port = 4343; - - struct sockaddr_in info; - bzero(&info, sizeof(info)); - info.sin_family = AF_INET; - - //localhost test - info.sin_addr.s_addr = INADDR_ANY; - info.sin_port = htons(nova_driver_port); - //socket的建立 TCP_PORT_IMAGE - int sockfd = 0; - sockfd = socket(AF_INET, SOCK_STREAM, 0); - - struct timeval timeout; - timeout.tv_sec = 10; - timeout.tv_usec = 0; - - setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); - setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); - - int tcpnodelay = 1; - setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); - - int reuse = 1; - setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); - setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); - - int qlen = 5; - setsockopt(sockfd, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); - - //printf("\n------------get snap with profile id:5\n"); - if (sockfd >= 0) { - - int err = connect(sockfd, (struct sockaddr *)&info, sizeof(info)); - if (err == -1) { - //printf("Connection error #2"); - } - else { - char msg[2560] = { 0 }; - - sprintf(msg, "GET /start_nova_driver HTTP/1.1\r\nhost: 127.0.0.1\r\nport: %d\r\nConnection: close\r\n", nova_driver_port); - - err = send(sockfd, msg, strlen(msg), 0); - if (err == -1) { - printf("\nerror sending #2\n"); - - //exit(EXIT_FAILURE); - } - else { - get_nova_driver(sockfd); - } - } - - close(sockfd); - sockfd = -1; - } - else { - printf("\nCould not create socket!\n"); - } - -} -#endif -void get_snap_with_profile_id(int i_profileid,int enable_check_profile_id) { - if (g_check_h264_gop == 0) { - //printf("\n------------get snap with profile id:1\n"); - - //int snapshot_size = 0; - - int status; - struct addrinfo host_info; - struct addrinfo *host_info_list = NULL; - - memset(&host_info, 0, sizeof(host_info)); - - host_info.ai_family = AF_INET;//AF_UNSPEC - host_info.ai_socktype = SOCK_STREAM; - host_info.ai_protocol = 0; - - status = getaddrinfo("127.0.0.1", accountData[0].account_port, &host_info, &host_info_list); - if (status != 0) { - printf("\ngetaddrinfo error: %d\n", enable_check_profile_id); - if (enable_check_profile_id == 1) - strcpy(g_image_state_response_ori, "Network problem: getaddrinfo error"); - } - else - { - //printf("\n------------get snap with profile id:2\n"); - int socketfd = -1;; - //socketfd = socket(host_info_list->ai_family, host_info_list->ai_socktype, host_info_list->ai_protocol); - struct timeval timeout; - timeout.tv_sec = 3;//3 - timeout.tv_usec = 0; - int tcpnodelay = 1; - int reuse = 1; - int qlen = 5; - - /* - struct sockaddr_in info; - bzero(&info, sizeof(info)); - info.sin_family = PF_INET; - - //localhost test - info.sin_addr.s_addr = inet_addr("127.0.0.1"); - info.sin_port = htons(accountData[0].account_port); - //socket的建立 TCP_PORT_IMAGE - socketfd = socket(host_info_list->ai_family, host_info_list->ai_socktype, host_info_list->ai_protocol);*/ - - int err = -1; - -#if 1 - struct addrinfo *rp; - for (rp = host_info_list; rp != NULL; rp = rp->ai_next) { - - socketfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - if (socketfd == -1) { - printf("\nsocket error:%d\n", enable_check_profile_id); - if (enable_check_profile_id == 1) - strcpy(g_image_state_response_ori, "Network problem: socket error"); - } - else { - //printf("\n-------open getimage connected (%d)\n", socketfd); - - setsockopt(socketfd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); - setsockopt(socketfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); - setsockopt(socketfd, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); - setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); - setsockopt(socketfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); - setsockopt(socketfd, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); - - if (connect(socketfd, rp->ai_addr, rp->ai_addrlen) != -1) { - - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - if (socketRecords[i].used == 0 && socketRecords[i].sock == -1) - { - socketRecords[i].sock = socketfd; - - //memset(&(socketRecords[i].recent_sec_data), 0x00, sizeof(SecData)); - //socketRecords[i].thread_id = 0; - socketRecords[i].channel_id = -1; - //socketRecords[i].last_recv_time = time(0); - //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; - socketRecords[i].isGetAlarmMotion = FALSE; - //socketRecords[i].isFirstAlarmMotion = FALSE; - socketRecords[i].isUdpSocket = FALSE; - socketRecords[i].isWebSocketConnect = FALSE; - socketRecords[i].isNvrRequest = 0; - socketRecords[i].isCredentialRequest = 0; - socketRecords[i].debug_type = 3; -#if defined GY_OS_AMBA - //socketRecords[i].iIsAIRelay = 0; -#endif - - socketRecords[i].used = 1; - //printf("\n(%d) [run http server] socketRecords[%d].sock:%d\n", client_sock, i, socketRecords[i].sock); - break; - } - else { - if (i == MAX_CLIENT_SOCKET - 1) { - closesocket(socketfd); - //printf("\n-------close getimage connected (%d)\n", socketfd); - socketfd = -1; - //printf("\n------------get snap with profile id:3\n"); - } - } - } - - if (socketfd != -1) { - break; - } - } - else { - closesocket(socketfd); - //printf("\n-------close getimage connected (%d)\n", socketfd); - socketfd = -1; - //printf("\n------------get snap with profile id:4\n"); - } - } - } -#endif - //printf("\n------------get snap with profile id:5\n"); - if (socketfd >= 0) { - char Authorization[2560] = { 0 }; - if (strlen(accountData[0].account_username) > 0) - { - //strcat(sendBuffer, "Authorization: Basic "); - char buf_account[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); - strcpy(Authorization, buf_account); - strcat(Authorization, ":"); - - if (strlen(accountData[0].account_password) > 0) { - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); - strcat(Authorization, buf_account2); - } - } - - size_t base64_encode_length = 0; - char httpAuth[2560] = { 0 }; - if (strlen(Authorization) >= 1) - { - - base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); - httpAuth[base64_encode_length] = '\0'; - } - - - char msg[2560] = { 0 }; - - sprintf(msg, "GET /getimage?profileid=%d HTTP/1.1\r\nhost: 127.0.0.1\r\nport: %s\r\nConnection: close\r\n", i_profileid, accountData[0].account_port); - - strcat(msg, "Authorization: Basic "); - strcat(msg, httpAuth); - strcat(msg, "\r\n"); - strcat(msg, "\r\n"); - - //printf("\n-----------msg:%s\n", msg); - //printf("\n------------get snap with profile id:6\n"); - err = send(socketfd, msg, strlen(msg), 0); - if (err == -1) { - printf("\nerror sending:%d\n", enable_check_profile_id); - if (enable_check_profile_id == 1) - strcpy(g_image_state_response_ori, "Network problem: error sending"); - - //exit(EXIT_FAILURE); - } - else { - getPicture(socketfd, MAX_IMG_SIZE, i_profileid, enable_check_profile_id); - } - //printf("\n------------get snap with profile id:7\n"); - closesocket(socketfd); - //printf("\n-------close getimage connected (%d)\n", socketfd); - - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - if (socketRecords[i].used == 1 && socketRecords[i].sock == socketfd) - { - //printf("\n\n(%d) [http connection fun] clean socket[%d]\n\n", sock, i); - - socketRecords[i].sock = -1; - //socketRecords[i].thread_id = 0; - socketRecords[i].channel_id = -1; - //socketRecords[i].last_recv_time = time(0); - //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; - socketRecords[i].isGetAlarmMotion = FALSE; - //socketRecords[i].isFirstAlarmMotion = FALSE; - socketRecords[i].isWebSocketConnect = FALSE; - socketRecords[i].isUdpSocket = FALSE; - socketRecords[i].isNvrRequest = 0; - socketRecords[i].isCredentialRequest = 0; - socketRecords[i].debug_type = 0; -#if defined GY_OS_AMBA - //socketRecords[i].iIsAIRelay = 0; -#endif - socketRecords[i].used = 0; - break; - } - } - - socketfd = -1; - //printf("\n------------get snap with profile id:8\n"); - } - else { - printf("\nCould not create socket!:%d\n", enable_check_profile_id); - if (enable_check_profile_id == 1) - strcpy(g_image_state_response_ori, "Network problem: Could not create socket!"); - - pthread_t thread_id_getipcamsettings; - if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { - printf("\ngetipcamsettings thread creation failed #1\n"); - } - pthread_join(thread_id_getipcamsettings, NULL); - } - } - //printf("\n------------get snap with profile id:9\n"); - if (host_info_list != NULL) { - freeaddrinfo(host_info_list); - host_info_list = NULL; - } - //printf("\n------------get snap with profile id:10\n"); - } -} - -void *net_curl_https_post_push_info_attached_image(void *ptr) { - pthread_detach(pthread_self()); - setPthreadName("curl_attached"); - pthread_mutex_lock(&mutex_curl); - - char sUrl[8192] = { 0 }; - strcpy(sUrl, g_stCURL_send_data_curl_url); - char sData[MAX_IMG_SIZE] = { 0 }; - //size_t sData_size = g_stCURL_send_data_curl_sendbuf_size; - memcpy(sData, g_stCURL_send_data_curl_sendbuf, g_stCURL_send_data_curl_sendbuf_size); - char method[32] = { 0 }; - strcpy(method, g_stCURL_send_data_method); - char sProtocol[32] = { 0 }; - strcpy(sProtocol, g_stCURL_send_data_protocol); - char sUserNmae[64] = { 0 }; - strcpy(sUserNmae, g_stCURL_send_data_username); - char sPassWord[64] = { 0 }; - strcpy(sPassWord, g_stCURL_send_data_password); - int iPort = atoi(g_stCURL_send_data_port); - char sCustomizedHeader[8192] = { 0 }; - strcpy(sCustomizedHeader, g_stCURL_send_data_customized_header); - int itimeout = atoi(g_stCURL_send_data_timeout); - - char s_q_name[30] = { 0 }; - strcpy(s_q_name, g_stCURL_send_data_q_name); - char s_q_plate[60] = { 0 }; - strcpy(s_q_plate, g_stCURL_send_data_q_plate); - - size_t snapshot_size = 0; - CURLcode ret; - curl_mime *mime1; - curl_mimepart *part1; - struct curl_slist *slist1; - char g_snapshot_addr_to_net_curl[MAX_IMG_SIZE] = { 0 }; - - if (g_stCURL_image_buff_size >= 1) { - memcpy(g_snapshot_addr_to_net_curl,g_stCURL_image_buff, g_stCURL_image_buff_size); - snapshot_size = (size_t)g_stCURL_image_buff_size; - } - else { -#ifdef GY_OS_AMBA - pthread_mutex_lock(&mutex_get_network_input); - snapshot_size = get_g_canvas_addr(g_snapshot_addr_to_net_curl); - pthread_mutex_unlock(&mutex_get_network_input); -#endif - } - - //memset(g_snapshot_addr_to_net_curl, 0x00, MAX_IMG_SIZE); - - //snapshot_size = get_snap_with_profile_id(g_snapshot_addr_to_net_curl, 1); - - //snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", g_snapshot_addr_to_net_curl, 0); - //snapshot_size = (size_t)get_ori_c_image(g_snapshot_addr_to_net_curl); - - if (g_http_handle != NULL && (int)snapshot_size >= 1) { - mime1 = NULL; - slist1 = NULL; - -#if 1 - slist1 = curl_slist_append(slist1, "charset: utf-8"); - slist1 = curl_slist_append(slist1, "Expect:"); - if (strcmp(method, "POST") == 0) - { - if ((int)strlen(sCustomizedHeader) >= 1) { - slist1 = curl_slist_append(slist1, sCustomizedHeader); - //slist1 = curl_slist_append(slist1, "CK:DKB2219EFF5PE5U3YS"); - } - curl_easy_setopt(g_http_handle, CURLOPT_CUSTOMREQUEST, "POST"); - } -#endif - curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(g_http_handle, CURLOPT_BUFFERSIZE, 102400L); - //curl_easy_setopt(g_http_handle, CURLOPT_URL, "http://0922992430:DKB2219EFF5PE5U3YS@iot.cht.com.tw:80/iot/v1/device/28354474443/snapshot"); - curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); - - if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) - { - curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); - curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); - } - curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); -#ifdef GY_OS_NOVA - curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, itimeout); //1 設定連線超時,單位秒 - curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, itimeout*2);//3 -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, itimeout); //1 設定連線超時,單位秒 - curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, itimeout*2);//3 -#endif - //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); - - curl_easy_setopt(g_http_handle, CURLOPT_NOPROGRESS, 1L); - mime1 = curl_mime_init(g_http_handle); - part1 = curl_mime_addpart(mime1); - //curl_mime_data(part1, "{\"id\":\"pedestrian\",\"lat\":22.663136,\"lon\":120.303307,\"value\":[\"silver\"]}", CURL_ZERO_TERMINATED); - curl_mime_data(part1, sData, CURL_ZERO_TERMINATED); - curl_mime_name(part1, "meta"); - part1 = curl_mime_addpart(mime1); - //curl_mime_filedata(part1, "/emmc/plugin/Aida_data/storage/snap_buf.jpg"); - curl_mime_data(part1, g_snapshot_addr_to_net_curl, snapshot_size); - curl_mime_type(part1, "image/jpg"); - curl_mime_name(part1, "image"); - - char temp_file_jpg_name[512] = { 0 }; - - if (g_stCURL_enable_filename_fixed==1) { - sprintf(temp_file_jpg_name,"%s.jpg", g_stCURL_send_jpeg_file_name); - } - else { - time_t rawtime = g_osdSysTimeStamp; - if (rawtime < 1000000000) { - rawtime = time(0); - } - struct tm * timeinfo; - timeinfo = localtime(&rawtime); - - struct timeval time_now; - gettimeofday(&time_now, NULL); - time_t msecs_time = time_now.tv_usec / 1000; - - char buf_time_info[256] = { 0 }; - sprintf(buf_time_info, "%04d_%02d_%02d_%02d_%02d_%02d_%03ld", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, - timeinfo->tm_min, timeinfo->tm_sec, msecs_time); - - sprintf(temp_file_jpg_name,"%s_%s.jpg", g_stCURL_send_jpeg_file_name, buf_time_info); - } - curl_mime_filename(part1, temp_file_jpg_name); - - curl_easy_setopt(g_http_handle, CURLOPT_MIMEPOST, mime1); - curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, slist1); - curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); - curl_easy_setopt(g_http_handle, CURLOPT_MAXREDIRS, 50L); - curl_easy_setopt(g_http_handle, CURLOPT_HTTP09_ALLOWED, 1L); - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_TCP_KEEPALIVE, 1L); - - curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); - curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 - -#ifdef GY_OS_NOVA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L);//10 -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 -#endif - struct MemoryStruct temp_msg; - struct MemoryStruct* ptr_responded_msg = &temp_msg; - ptr_responded_msg->size = 0; - curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); - curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); - - /* Here is a list of options the curl code used that cannot get generated - as source easily. You may select to either not use them or implement - them yourself. - - CURLOPT_WRITEDATA set to a objectpointer - CURLOPT_INTERLEAVEDATA set to a objectpointer - CURLOPT_WRITEFUNCTION set to a functionpointer - CURLOPT_READDATA set to a objectpointer - CURLOPT_READFUNCTION set to a functionpointer - CURLOPT_SEEKDATA set to a objectpointer - CURLOPT_SEEKFUNCTION set to a functionpointer - CURLOPT_ERRORBUFFER set to a objectpointer - CURLOPT_STDERR set to a objectpointer - CURLOPT_DEBUGFUNCTION set to a functionpointer - CURLOPT_DEBUGDATA set to a objectpointer - CURLOPT_HEADERFUNCTION set to a functionpointer - CURLOPT_HEADERDATA set to a objectpointer - - */ - - ret = curl_easy_perform(g_http_handle); - - /* Check for errors */ - if (ret != CURLE_OK) - { - /* if errors have occured, tell us wath's wrong with 'ret'*/ - sprintf(g_response_net_curl, "Notification failed:%s,%s,%s", s_q_name, s_q_plate, curl_easy_strerror(ret)); - char temp_msg[MAX_IMG_SIZE] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "Notification failed:%s,%s,%s", s_q_name, s_q_plate, curl_easy_strerror(ret)); - write_to_logs_html(temp_msg, "curl to post image", "ERROR", SystemSetting.enable_system_logs); - fprintf(stderr, "#1 curl_easy_perform() failed: %s\n", curl_easy_strerror(ret)); - - if (strstr(temp_msg, "Timeout was reached") != NULL || - strstr(temp_msg, "timeout was reached") != NULL) { - g_check_ping_OK = 0; - } - } - else { - if (ptr_responded_msg != NULL && ptr_responded_msg->size >= 1) { - sprintf(g_response_net_curl, "Notification OK:%s,%s,%s", s_q_name, s_q_plate,ptr_responded_msg->memory); - //printf("\n[net attached image]:CURLE_OK:%s\n", ptr_responded_msg->memory); - - char temp_msg[MAX_IMG_SIZE] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "Notification OK:%s,%s,%s", s_q_name, s_q_plate, ptr_responded_msg->memory); - write_to_logs_html(temp_msg, "curl to post image", "INFO", SystemSetting.enable_system_logs); - } - else { - sprintf(g_response_net_curl, "Notification OK:%s,%s", s_q_name, s_q_plate); - //printf("\n[net attached image]:CURLE_OK\n"); - - char temp_msg[MAX_IMG_SIZE] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "Notification OK:%s,%s", s_q_name, s_q_plate); - write_to_logs_html(temp_msg, "curl to post image", "INFO", SystemSetting.enable_system_logs); - } - } - - curl_easy_reset(g_http_handle); - curl_mime_free(mime1); - mime1 = NULL; - curl_slist_free_all(slist1); - slist1 = NULL; - - ptr_responded_msg->size = 0; - /*if (ptr_responded_msg) { - free(ptr_responded_msg); - ptr_responded_msg = NULL; - }*/ - } - g_response_post_OK = 1; - pthread_mutex_unlock(&mutex_curl); - pthread_exit(NULL); - //return (int)ret; -} - -//#define LOCAL_FILE "/emmc/plugin/Aida_data/snap.jpg" -#define UPLOAD_FILE_AS "myuploading.jpg" -//#define REMOTE_URL "ftp://example.com/" UPLOAD_FILE_AS -#define RENAME_FILE_TO "myname.jpg" - -/* NOTE: if you want this example to work on Windows with libcurl as a - DLL, you MUST also provide a read callback with CURLOPT_READFUNCTION. - Failing to do so will give you a crash since a DLL may not use the - variable's memory when passed in to it from an app like this. */ -static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream) -{ - unsigned long nread; - /* in real-world cases, this would probably get this data differently - as this fread() stuff is exactly what the library already would do - by default internally */ - size_t retcode = fread(ptr, size, nmemb, stream); - - if (retcode > 0) { - nread = (unsigned long)retcode; - fprintf(stderr, "*** We read %lu bytes from file\n", nread); - } - - return retcode; -} - -void net_curl_ftp_build_folder() -{ - - char sUrl[8192] = { 0 }; - strcpy(sUrl, "ftp://"); - strcat(sUrl, SystemSetting.ftp_url); - strcat(sUrl, "/"); - - char sUserNmae[64] = { 0 }; - strcpy(sUserNmae, SystemSetting.ftp_username); - char sPassWord[64] = { 0 }; - strcpy(sPassWord, SystemSetting.ftp_password); - int iPort = atoi(SystemSetting.ftp_port); - - char spilt_folder[50][STRSPLIT_SIZE]={0}; - const char *del = "/"; - int num_spilt_folder = 0; - - char temp_buildfolder[1024] = { 0 }; - strcpy(temp_buildfolder,SystemSetting.ftp_remote_directory); - - if (strlen(temp_buildfolder) >= 1) { - num_spilt_folder = StrSplit(temp_buildfolder, spilt_folder, del); - //printf("\n------UU:20\n"); - for (int i = 0; i < num_spilt_folder; i++) { - char buildfolder[1024] = { 0 }; - - if (strlen(spilt_folder[i]) >= 1) { - - strcpy(buildfolder, "MKD "); - for (int j = 0; j <= i; j++) - { - strcat(buildfolder, spilt_folder[j]); - if (j < i) { - strcat(buildfolder, "/"); - } - } - - CURLcode res; - struct curl_slist *headerlist = NULL; - pthread_mutex_lock(&mutex_curl); - if (g_http_handle) { - - headerlist = curl_slist_append(headerlist, buildfolder); - - curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(g_http_handle, CURLOPT_BUFFERSIZE, 102400L); - - if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) - { - curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); - curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); - } - else if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) == 0) { - curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); - } - - curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); - curl_easy_setopt(g_http_handle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L); - -#ifdef GY_OS_NOVA - curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 3); //1 設定連線超時,單位秒 - curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 5);//3 -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5); //1 設定連線超時,單位秒 - curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10);//3 -#endif - curl_easy_setopt(g_http_handle, CURLOPT_NOPROGRESS, 1L); - - /* enable uploading */ - //curl_easy_setopt(g_http_handle, CURLOPT_UPLOAD, 1L); - - /* specify target */ - curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); - - /* pass in that last of FTP commands to run after the transfer */ - curl_easy_setopt(g_http_handle, CURLOPT_POSTQUOTE, headerlist); - - - /* Set the size of the file to upload (optional). If you give a *_LARGE - option you MUST make sure that the type of the passed-in argument is a - curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must - make sure that to pass in a type 'long' argument. */ - - curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); - curl_easy_setopt(g_http_handle, CURLOPT_MAXREDIRS, 50L); - curl_easy_setopt(g_http_handle, CURLOPT_HTTP09_ALLOWED, 1L); - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); - - //curl_easy_setopt(g_http_handle, CURLOPT_TCP_KEEPALIVE, 1L); - //curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); not support 不支援 - - curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). - - - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 - -#ifdef GY_OS_NOVA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L);//10 -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 -#endif - - /* Now run off and do what you have been told! */ - res = curl_easy_perform(g_http_handle); - /* Check for errors */ - if (res != CURLE_OK) { - fprintf(stderr, "#2 curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "curl_easy_perform() failed: %s", curl_easy_strerror(res)); - write_to_logs_html(temp_msg, "curl ftp to build folder", "ERROR", SystemSetting.enable_system_logs); - //check_if_build_new_dir = 0; - } - else { - char temp_msg[8192] = { 0 }; - strcpy(temp_msg,"OK"); - write_to_logs_html(temp_msg, "curl ftp to build folder", "INFO", SystemSetting.enable_system_logs); - } - - /* clean up the FTP commands list */ - curl_slist_free_all(headerlist); - - curl_easy_reset(g_http_handle); - } - pthread_mutex_unlock(&mutex_curl); - } - } - } -} - -void net_curl_ftp_delete_file() { - if (strcmp(SystemSetting.ftp_jpeg_file_name_format, "fixed") == 0) { - char sUrl[8192] = { 0 }; - strcpy(sUrl, "ftp://"); - strcat(sUrl, SystemSetting.ftp_url); - strcat(sUrl, "/"); - - char sUserNmae[64] = { 0 }; - strcpy(sUserNmae, SystemSetting.ftp_username); - char sPassWord[64] = { 0 }; - strcpy(sPassWord, SystemSetting.ftp_password); - int iPort = atoi(SystemSetting.ftp_port); - - char temp_file_jpg_name[512] = { 0 }; - sprintf(temp_file_jpg_name, "%s.jpg", SystemSetting.ftp_jpeg_file_name); - - char buildfolder[2048] = { 0 }; - strcpy(buildfolder, "DELE "); - strcat(buildfolder, SystemSetting.ftp_remote_directory); - strcat(buildfolder,"/"); - strcat(buildfolder, temp_file_jpg_name); - - CURLcode res; - struct curl_slist *headerlist = NULL; - pthread_mutex_lock(&mutex_curl); - if (g_http_handle) { - - headerlist = curl_slist_append(headerlist, buildfolder); - - curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(g_http_handle, CURLOPT_BUFFERSIZE, 102400L); - - if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) - { - curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); - curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); - } - else if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) == 0) { - curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); - } - - curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); - curl_easy_setopt(g_http_handle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L); - -#ifdef GY_OS_NOVA - curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 3); //1 設定連線超時,單位秒 - curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 5);//3 -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5); //1 設定連線超時,單位秒 - curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10);//3 -#endif - curl_easy_setopt(g_http_handle, CURLOPT_NOPROGRESS, 1L); - - /* enable uploading */ - //curl_easy_setopt(g_http_handle, CURLOPT_UPLOAD, 1L); - - /* specify target */ - curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); - - /* pass in that last of FTP commands to run after the transfer */ - curl_easy_setopt(g_http_handle, CURLOPT_POSTQUOTE, headerlist); - - - /* Set the size of the file to upload (optional). If you give a *_LARGE - option you MUST make sure that the type of the passed-in argument is a - curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must - make sure that to pass in a type 'long' argument. */ - - curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); - curl_easy_setopt(g_http_handle, CURLOPT_MAXREDIRS, 50L); - curl_easy_setopt(g_http_handle, CURLOPT_HTTP09_ALLOWED, 1L); - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); - - //curl_easy_setopt(g_http_handle, CURLOPT_TCP_KEEPALIVE, 1L); - //curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); not support 不支援 - - curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). - - - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 - -#ifdef GY_OS_NOVA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L);//10 -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 -#endif - - /* Now run off and do what you have been told! */ - res = curl_easy_perform(g_http_handle); - /* Check for errors */ - if (res != CURLE_OK) { - fprintf(stderr, "#3 curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "curl_easy_perform() failed: %s", curl_easy_strerror(res)); - write_to_logs_html(temp_msg, "curl ftp to delete file", "ERROR", SystemSetting.enable_system_logs); - - //check_if_build_new_dir = 0; - } - else { - char temp_msg[8192] = { 0 }; - strcpy(temp_msg, "OK"); - write_to_logs_html(temp_msg, "curl ftp to delete image", "INFO", SystemSetting.enable_system_logs); - } - /* clean up the FTP commands list */ - curl_slist_free_all(headerlist); - - curl_easy_reset(g_http_handle); - } - pthread_mutex_unlock(&mutex_curl); - } -} - -void net_curl_ftp_post_push_info_attached_image(char* image_buff, int image_buff_size) -{ - net_curl_ftp_delete_file(); - if (image_buff_size >= 1) { - char write_filename[256] = "/emmc/plugin/Aida_data/"; - strcat(write_filename, "snap.jpg"); - FILE* fp = fopen(write_filename, "w+"); - if (fp != NULL) - { - fwrite(image_buff, sizeof(char), image_buff_size, fp); - fclose(fp); - - char sUrl[8192] = { 0 }; - strcpy(sUrl, "ftp://"); - strcat(sUrl, SystemSetting.ftp_url); - strcat(sUrl, "/"); - strcat(sUrl, UPLOAD_FILE_AS); - char sUserNmae[64] = { 0 }; - strcpy(sUserNmae, SystemSetting.ftp_username); - char sPassWord[64] = { 0 }; - strcpy(sPassWord, SystemSetting.ftp_password); - int iPort = atoi(SystemSetting.ftp_port); - - char temp_file_jpg_name[512] = { 0 }; - if (strcmp(SystemSetting.ftp_jpeg_file_name_format,"fixed")==0) { - sprintf(temp_file_jpg_name, "%s.jpg", SystemSetting.ftp_jpeg_file_name); - } - else { - time_t rawtime = time(0); - struct tm * timeinfo; - timeinfo = localtime(&rawtime); - - struct timeval time_now; - gettimeofday(&time_now, NULL); - time_t msecs_time = time_now.tv_usec / 1000; - - char buf_time_info[256] = { 0 }; - sprintf(buf_time_info, "%04d_%02d_%02d_%02d_%02d_%02d_%03ld", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, - timeinfo->tm_min, timeinfo->tm_sec, msecs_time); - - sprintf(temp_file_jpg_name, "%s_%s.jpg", SystemSetting.ftp_jpeg_file_name, buf_time_info); - } - - - char sFileto[1024] = { 0 }; - strcpy(sFileto, "RNTO "); - strcat(sFileto, "../"); - if (strlen(SystemSetting.ftp_remote_directory) >= 1) { - strcat(sFileto, SystemSetting.ftp_remote_directory); - strcat(sFileto, "/"); - } - strcat(sFileto, temp_file_jpg_name);//RENAME_FILE_TO - - //printf("\n------sFileto:%s\n", sFileto); - - CURLcode res; - FILE *hd_src; - struct stat file_info; - unsigned long fsize; - - struct curl_slist *headerlist = NULL; - //MKD bbDir - static const char buf_1[] = "RNFR " UPLOAD_FILE_AS; - //static const char buf_2[] = "RNTO " RENAME_FILE_TO; - //printf("\n------buf_2:%s\n", buf_2); - - /* get the file size of the local file */ - if (stat(write_filename, &file_info)) { - printf("Couldn't open '%s': %s\n", write_filename, strerror(errno)); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "Couldn't open '%s': %s", write_filename, strerror(errno)); - write_to_logs_html(temp_msg, "curl ftp to post image", "ERROR", SystemSetting.enable_system_logs); - } - else { - fsize = (unsigned long)file_info.st_size; - - printf("Local file size: %lu bytes.\n", fsize); - - /* get a FILE * of the same file */ - hd_src = fopen(write_filename, "rb"); - pthread_mutex_lock(&mutex_curl); - if (g_http_handle && hd_src != NULL) { - /* build a list of commands to pass to libcurl */ - headerlist = curl_slist_append(headerlist, buf_1); - headerlist = curl_slist_append(headerlist, sFileto); - - curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(g_http_handle, CURLOPT_BUFFERSIZE, 102400L); - - if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) - { - curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); - curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); - } - else if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) == 0) { - curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); - } - - curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); - curl_easy_setopt(g_http_handle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L); - -#ifdef GY_OS_NOVA - curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 3); //1 設定連線超時,單位秒 - curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 5);//3 -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5); //1 設定連線超時,單位秒 - curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10);//3 -#endif - curl_easy_setopt(g_http_handle, CURLOPT_NOPROGRESS, 1L); - - /* we want to use our own read function */ - curl_easy_setopt(g_http_handle, CURLOPT_READFUNCTION, read_callback); - - /* enable uploading */ - curl_easy_setopt(g_http_handle, CURLOPT_UPLOAD, 1L); - - /* specify target */ - curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); - - /* pass in that last of FTP commands to run after the transfer */ - curl_easy_setopt(g_http_handle, CURLOPT_POSTQUOTE, headerlist); - - /* now specify which file to upload */ - curl_easy_setopt(g_http_handle, CURLOPT_READDATA, hd_src); - - /* Set the size of the file to upload (optional). If you give a *_LARGE - option you MUST make sure that the type of the passed-in argument is a - curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must - make sure that to pass in a type 'long' argument. */ - curl_easy_setopt(g_http_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize); - - curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); - curl_easy_setopt(g_http_handle, CURLOPT_MAXREDIRS, 50L); - curl_easy_setopt(g_http_handle, CURLOPT_HTTP09_ALLOWED, 1L); - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); - - //curl_easy_setopt(g_http_handle, CURLOPT_TCP_KEEPALIVE, 1L); - //curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); not support 不支援 - - curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). - - - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 - -#ifdef GY_OS_NOVA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L);//10 -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 -#endif - - /* Now run off and do what you have been told! */ - res = curl_easy_perform(g_http_handle); - /* Check for errors */ - if (res != CURLE_OK) { - fprintf(stderr, "#4 curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); - //check_if_build_new_dir = 0; - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "curl_easy_perform() failed: %s", curl_easy_strerror(res)); - write_to_logs_html(temp_msg, "curl ftp to post image", "ERROR", SystemSetting.enable_system_logs); - } - else { - char temp_msg[8192] = { 0 }; - strcpy(temp_msg, "OK"); - write_to_logs_html(temp_msg, "curl ftp to post image", "INFO", SystemSetting.enable_system_logs); - } - /* clean up the FTP commands list */ - curl_slist_free_all(headerlist); - - curl_easy_reset(g_http_handle); - } - pthread_mutex_unlock(&mutex_curl); - if (hd_src != NULL) { - fclose(hd_src); /* close the local file */ - hd_src = NULL; - } - } - } - else - printf("net curl ftp] (For debugging) Error occurred when opening file I/O.\n"); - } -} - -#if 1 -void *net_curl_https_post_push_info(void *ptr) -{ - pthread_detach(pthread_self()); - setPthreadName("curl_post"); -#if 1 - pthread_mutex_lock(&mutex_curl); - //CURLM *multi_handle = NULL; - - //CURL_SEND *stCURL_send_data; - //stCURL_send_data = (CURL_SEND *)p_stCURL_send_data; - //memset(&stCURL_send_data, 0x00, sizeof(stCURL_send_data)); - - char sUrl[8192] = { 0 }; - strcpy(sUrl,g_stCURL_send_data_curl_url); - char sData[MAX_IMG_SIZE] = { 0 }; - size_t sData_size = g_stCURL_send_data_curl_sendbuf_size; - memcpy(sData, g_stCURL_send_data_curl_sendbuf, g_stCURL_send_data_curl_sendbuf_size); - char method[32] = { 0 }; - strcpy(method, g_stCURL_send_data_method); - char sProtocol[32] = { 0 }; - strcpy(sProtocol, g_stCURL_send_data_protocol); - char sUserNmae[64] = { 0 }; - strcpy(sUserNmae, g_stCURL_send_data_username); - char sPassWord[64] = { 0 }; - strcpy(sPassWord, g_stCURL_send_data_password); - int iPort = atoi(g_stCURL_send_data_port); - char sCustomizedHeader[8192] = { 0 }; - strcpy(sCustomizedHeader, g_stCURL_send_data_customized_header); - - int itimeout = atoi(g_stCURL_send_data_timeout); - - char s_q_name[30] = { 0 }; - strcpy(s_q_name, g_stCURL_send_data_q_name); - char s_q_plate[60] = { 0 }; - strcpy(s_q_plate, g_stCURL_send_data_q_plate); - - char l_smtp_capath[512] = { 0 }; - strcpy(l_smtp_capath, CURL_SMTP_CAPATH); - - //curl_mime* form = NULL; - //curl_mimepart* mimepart = NULL; - - - - //int still_running = 0; /* keep number of running handles */ - //int repeats = 0; - - //usSleep(100); - //usSleep(1000000); - - //const int timeout = 30000; - /*int timeout = 5; - if (QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) - timeout = 5; - else - timeout = 1;*/ - - //multi_handle = curl_multi_init(); - - //memset(g_snapshot_addr_to_net_curl, 0x00, MAX_IMG_SIZE); - //size_t snapshot_size = 0; - //snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", g_snapshot_addr_to_net_curl, 1); - - int check_reboot = 0; - - if (g_http_handle != NULL /*& multi_handle != NULL*/) - { - //form = curl_mime_init(g_http_handle); - - //struct curl_slist *pList = NULL; - // - - - struct curl_slist *pList = NULL; - //struct curl_slist *f_list = NULL; - - //pList = curl_slist_append(pList, "Accept: application/json"); - //pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); - pList = curl_slist_append(pList, "Connection: close"); - pList = curl_slist_append(pList, "charset: utf-8"); - pList = curl_slist_append(pList, "Content-Type: application/json"); - pList = curl_slist_append(pList, "Expect:"); - -#if 1 - if (strcmp(method, "POST") == 0) - { - //pList = curl_slist_append(pList, "Content-Type: text/html; charset=utf-8"); - if ((int)strlen(sCustomizedHeader) >= 1) { - pList = curl_slist_append(pList, sCustomizedHeader); - } - //pList = curl_slist_append(pList, "X-Api-Key: AAAAAAAAAAA");//正確寫法 - //curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, "Content-Type: text/html; charset=utf-8"); - } -#endif - - - curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); - curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); - - //printf("[%s] url: [%s]\n", __func__, "oe65meb2tl.execute-api.ap-northeast-1.amazonaws.com/v1/ipcamera/person/traffic"); - //curl_easy_setopt(http_handle, CURLOPT_URL, "https://oe65meb2tl.execute-api.ap-northeast-1.amazonaws.com/v1/ipcamera/person/traffic"); - //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/4zxou-1615769161/post"); - //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/d31mm-1621568101/post"); - //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/d31mm-1621568101/post"); - - curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); - //printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); - /*if (g_stCURL_check_127 == 0)*/ - if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) - { - //printf("\n---------sUserNmae:%s\n", sUserNmae); - //printf("\n---------sPassWord:%s\n", sPassWord); - curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); - curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); - } - - curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); -#ifdef GY_OS_NOVA - curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, itimeout); //1 設定連線超時,單位秒 - curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, itimeout*2);//3 -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, itimeout); //1 設定連線超時,單位秒 - curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, itimeout*2);//3 -#endif - //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); - - /* - if (strcmp(sProtocol, "HTTPS") == 0) { - curl_easy_setopt(g_http_handle, CURLOPT_USE_SSL, CURLUSESSL_ALL); - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 1L); - //curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_CAINFO, l_smtp_capath); - } - else {*/ - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); - //} - - curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); - - curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). - - curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) - - //curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); - curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); - - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 -#ifdef GY_OS_NOVA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L);//10 -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 -#endif - struct MemoryStruct temp_msg; - struct MemoryStruct* ptr_responded_msg = &temp_msg; - ptr_responded_msg->size = 0; - curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); - curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); - - if (strcmp(method, "POST") == 0) - { - //printf("\nsData_size:%d\n",(int)sData_size); - //printf("\n%s\n", sData); - //fwrite(sData, 1, sData_size, stdout); - - - if (sData_size >= 1) { - - - curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDS, sData); - curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDSIZE, sData_size); - - //mimepart = curl_mime_addpart(form); - //curl_mime_name(mimepart, "meta"); - //curl_mime_type(mimepart, "text/plain"); - //curl_mime_data(mimepart, sData, sData_size); - } - - /* - if ((int)snapshot_size >= 1) - { - // Fill in the filename field - mimepart = curl_mime_addpart(form); - - f_list = curl_slist_append(f_list, "Content-Transfer-Encoding: 8bit"); - char temp_content_range[128] = { 0 }; - char temp_content_length[128] = { 0 }; - sprintf(temp_content_range , "Content-Range 0-%d/%d",(int)(snapshot_size-1), (int)snapshot_size); - sprintf(temp_content_length, "Content-Length %d", (int)snapshot_size); - f_list = curl_slist_append(f_list, temp_content_range); - f_list = curl_slist_append(f_list, temp_content_length); - - curl_mime_name(mimepart, "image"); - curl_mime_headers(mimepart, f_list, 1); - curl_mime_filedata(mimepart, "./storage/snap_buf.jpg"); - //curl_mime_data(mimepart, g_snapshot_addr_to_net_curl, snapshot_size); - } - curl_easy_setopt(g_http_handle, CURLOPT_MIMEPOST, form); - */ - //curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDS, outputmessage); - //curl_easy_setopt(g_http_handle, CURLOPT_POSTFIELDSIZE, strlen(outputmessage)); - curl_easy_setopt(g_http_handle, CURLOPT_POST, 1L); - } - CURLcode result = CURLE_FAILED_INIT; - //printf("\n-------------result:start\n"); - TRY - { - //printf("In Try Statement\n"); - result = curl_easy_perform(g_http_handle); - //THROW; - //printf("I do not appear\n"); - } - CATCH - { - result = CURLE_FAILED_INIT; - //printf("Got Exception!\n"); - } - ETRY; - //printf("\n-------------result:%d\n", (int)result); - - /* Check for errors */ - if (result != CURLE_OK) - { - /* if errors have occured, tell us wath's wrong with 'ret'*/ - sprintf(g_response_net_curl, "Notification failed:%s,%s,%s", s_q_name, s_q_plate, curl_easy_strerror(result)); - fprintf(stderr, "#5 curl_easy_perform() failed: %s\n", curl_easy_strerror(result)); - - char temp_msg[MAX_IMG_SIZE] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "Notification failed:%s,%s,%s", s_q_name, s_q_plate, curl_easy_strerror(result)); - write_to_logs_html(temp_msg, "curl to post", "ERROR", SystemSetting.enable_system_logs); - - if (strstr(temp_msg, "Timeout was reached") != NULL || - strstr(temp_msg, "timeout was reached") != NULL) { - g_check_ping_OK = 0; - } - - //printf("\n--------Notification failed:%s\n", curl_easy_strerror(result)); - } - else { - if (ptr_responded_msg!=NULL && ptr_responded_msg->size >= 1) { - sprintf(g_response_net_curl, "Notification OK:%s,%s,%s", s_q_name, s_q_plate, ptr_responded_msg->memory); - //printf("\n[net curl https]:CURLE_OK:%s\n", ptr_responded_msg->memory); - - char temp_msg[MAX_IMG_SIZE] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "Notification OK:%s,%s,%s", s_q_name, s_q_plate, ptr_responded_msg->memory); - write_to_logs_html(temp_msg, "curl to post", "INFO", SystemSetting.enable_system_logs); - } - else { - sprintf(g_response_net_curl, "Notification OK:%s,%s", s_q_name, s_q_plate); - //printf("\n[net curl https]:CURLE_OK\n"); - - char temp_msg[MAX_IMG_SIZE] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "Notification OK:%s,%s", s_q_name, s_q_plate); - write_to_logs_html(temp_msg, "curl to post", "INFO", SystemSetting.enable_system_logs); - - } - } - - curl_easy_reset(g_http_handle); - if (pList != NULL) - curl_slist_free_all(pList); -#if 0 - curl_multi_add_handle(multi_handle, g_http_handle); - curl_multi_perform(multi_handle, &still_running); - - //curl_multi_add_handle(g_multi_handle, curl); - //curl_multi_perform(g_multi_handle, &g_handle_count); -#endif - //Clean curl_ease ver2 -#if 0 - int repeats = 0; - while (still_running) { - CURLMcode mc; - int numfds; - - mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds); - - if (mc != CURLM_OK) { - printf("\ncurl_multi_wait() failed, code %d.\n", mc); - break; - } - - if (!numfds) { - repeats++; /* count number of repeated zero numfds */ - if (repeats > 1) { - usSleep(100000); /* sleep 100 milliseconds */ - } - } - else - repeats = 0; - - //printf("Wait repeats %d \n", repeats); - - curl_multi_perform(multi_handle, &still_running); - } -#endif - -#if 1 - if (result == CURLE_OUT_OF_MEMORY) { - printf("\n[net curl https post push info]CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error \n instead of a memory allocation error if CURL_DOES_CONVERSIONS \n is defined\n"); - - check_reboot = 1; - } -#endif - - //curl_mime_free(form); - - ptr_responded_msg->size = 0; - /*if (ptr_responded_msg) { - free(ptr_responded_msg); - ptr_responded_msg = NULL; - }*/ - } - - - //curl_multi_remove_handle(multi_handle, g_http_handle); - //curl_multi_cleanup(multi_handle); - //g_http_handle = NULL; - -#endif - g_response_post_OK = 1; - pthread_mutex_unlock(&mutex_curl); - - if (check_reboot == 1) { - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY"); - write_to_logs_html(temp_msg, "curl to post", "CGI_REBOOT", "Yes"); - write_to_log_if_error(temp_msg, "curl to post", "CGI_REBOOT"); - - pthread_t auto_reboot_thread_id; - if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) - { - printf("\ncreate auto reboot thread faile \n"); - } - } - - pthread_exit(NULL); -} -#endif - -#ifdef GY_OS_AMBA -void *net_curl_https_get_other_lpr_db(void *ptr) -{ - pthread_detach(pthread_self()); - setPthreadName("curl_lpr"); -#if 1 - pthread_mutex_lock(&mutex_curl); - //CURLM *multi_handle = NULL; - - //CURL_SEND *stCURL_send_data; - //stCURL_send_data = (CURL_SEND *)p_stCURL_send_data; - //memset(&stCURL_send_data, 0x00, sizeof(stCURL_send_data)); - - - - char sUrl[8192] = { 0 }; - strcpy(sUrl, g_stCURL_lpr_db_url); - char sUserNmae[64] = { 0 }; - strcpy(sUserNmae, g_stCURL_lpr_db_username); - char sPassWord[64] = { 0 }; - strcpy(sPassWord, g_stCURL_lpr_db_password); - int iPort = atoi(g_stCURL_lpr_db_port); - - - - //char l_smtp_capath[512] = { 0 }; - //strcpy(l_smtp_capath, CURL_SMTP_CAPATH); - - //curl_mime* form = NULL; - //curl_mimepart* mimepart = NULL; - - - - //int still_running = 0; /* keep number of running handles */ - //int repeats = 0; - - //usSleep(100); - //usSleep(1000000); - - //const int timeout = 30000; - /*int timeout = 5; - if (QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0) - timeout = 5; - else - timeout = 1;*/ - - //multi_handle = curl_multi_init(); - - //memset(g_snapshot_addr_to_net_curl, 0x00, MAX_IMG_SIZE); - //size_t snapshot_size = 0; - //snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", g_snapshot_addr_to_net_curl, 1); - int check_reboot = 0; - if (g_http_handle != NULL /*& multi_handle != NULL*/) - { - //form = curl_mime_init(g_http_handle); - - //struct curl_slist *pList = NULL; - // - - - struct curl_slist *pList = NULL; - //struct curl_slist *f_list = NULL; - - //pList = curl_slist_append(pList, "Accept: application/json"); - //pList = curl_slist_append(pList, "Content-Type:multipart/form-data"); - pList = curl_slist_append(pList, "Connection: close"); - pList = curl_slist_append(pList, "charset: utf-8"); - pList = curl_slist_append(pList, "Content-Type: application/json"); - - curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); - curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); - - //printf("[%s] url: [%s]\n", __func__, "oe65meb2tl.execute-api.ap-northeast-1.amazonaws.com/v1/ipcamera/person/traffic"); - //curl_easy_setopt(http_handle, CURLOPT_URL, "https://oe65meb2tl.execute-api.ap-northeast-1.amazonaws.com/v1/ipcamera/person/traffic"); - //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/4zxou-1615769161/post"); - //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/d31mm-1621568101/post"); - //curl_easy_setopt(http_handle, CURLOPT_URL, "https://ptsv2.com/t/d31mm-1621568101/post"); - - curl_easy_setopt(g_http_handle, CURLOPT_URL, sUrl); - - //printf("%s, %s, %d \n", sUserNmae, sPassWord, iPort); - /*if (g_stCURL_check_127 == 0)*/ - if ((int)strlen(sUserNmae) >= 1 && (int)strlen(sPassWord) >= 1) - { - curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, sUserNmae); - curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, sPassWord); - } - curl_easy_setopt(g_http_handle, CURLOPT_PORT, iPort); - - curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 5); //1 設定連線超時,單位秒 - curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 10);//3 - //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); - - /* - if (strcmp(sProtocol, "HTTPS") == 0) { - curl_easy_setopt(g_http_handle, CURLOPT_USE_SSL, CURLUSESSL_ALL); - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 1L); - //curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_CAINFO, l_smtp_capath); - } - else {*/ - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); - //} - - curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); - - curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). - - curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) - - //curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.5"); - curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); - - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L);//1 - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L);//10 - struct MemoryStruct temp_msg; - struct MemoryStruct* ptr_responded_msg = &temp_msg; - ptr_responded_msg->size = 0; - curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); - curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); - - CURLcode result = CURLE_FAILED_INIT; - //printf("\n-------------result:start\n"); - TRY - { - //printf("In Try Statement\n"); - result = curl_easy_perform(g_http_handle); - //THROW; - //printf("I do not appear\n"); - } - CATCH - { - result = CURLE_FAILED_INIT; - //printf("Got Exception!\n"); - } - ETRY; - //printf("\n-------------result:%d\n", (int)result); - - /* Check for errors */ - if (result != CURLE_OK) - { - /* if errors have occured, tell us wath's wrong with 'ret'*/ - sprintf(g_response_lpr_db, "Notification failed:%s", curl_easy_strerror(result)); - fprintf(stderr, "#6 curl_easy_perform() failed: %s\n", curl_easy_strerror(result)); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "curl_easy_perform() failed: %s", curl_easy_strerror(result)); - write_to_logs_html(temp_msg, "curl to post to get lpr db", "ERROR", SystemSetting.enable_system_logs); - } - else { - if (ptr_responded_msg != NULL && ptr_responded_msg->size >= 1) { - sprintf(g_response_lpr_db, "Notification OK size:%ld", ptr_responded_msg->size);//ptr_responded_msg->memory - - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char DB_FFLPR_IMPORT_PATH[1024]; - strcpy(DB_FFLPR_IMPORT_PATH, exePath); - strcat(DB_FFLPR_IMPORT_PATH, "db_fflpr_import.db"); - - - FILE *f = fopen(DB_FFLPR_IMPORT_PATH, "w"); - if (f != NULL) - { - fwrite(ptr_responded_msg->memory, ptr_responded_msg->size, 1, f); - fclose(f); - } - - printf("\n[net lpr db]:CURLE_OK size:%ld\n", ptr_responded_msg->size); - get_fflpr_db_import(); -#if 0 - if (unlockingKeyInnoFR == 1) { - get_face_db_import();// face - leo - } -#endif - } - else { - strcpy(g_response_lpr_db, "Notification OK"); - printf("\n[net lpr db]:CURLE_OK\n"); - } - } - - curl_easy_reset(g_http_handle); - if (pList != NULL) - curl_slist_free_all(pList); -#if 0 - curl_multi_add_handle(multi_handle, g_http_handle); - curl_multi_perform(multi_handle, &still_running); - - //curl_multi_add_handle(g_multi_handle, curl); - //curl_multi_perform(g_multi_handle, &g_handle_count); -#endif - //Clean curl_ease ver2 -#if 0 - int repeats = 0; - while (still_running) { - CURLMcode mc; - int numfds; - - mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds); - - if (mc != CURLM_OK) { - printf("\ncurl_multi_wait() failed, code %d.\n", mc); - break; - } - - if (!numfds) { - repeats++; /* count number of repeated zero numfds */ - if (repeats > 1) { - usSleep(100000); /* sleep 100 milliseconds */ - } - } - else - repeats = 0; - - //printf("Wait repeats %d \n", repeats); - - curl_multi_perform(multi_handle, &still_running); - } -#endif - -#if 1 - if (result == CURLE_OUT_OF_MEMORY) { - printf("\n[net curl https post push info]CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error \n instead of a memory allocation error if CURL_DOES_CONVERSIONS \n is defined\n"); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY"); - write_to_logs_html(temp_msg, "net curl https get other lpr db", "CGI_REBOOT", "Yes"); - write_to_log_if_error(temp_msg, "net curl https get other lpr db", "CGI_REBOOT"); - - check_reboot = 1; - } -#endif - - //curl_mime_free(form); - - ptr_responded_msg->size = 0; - /*if (ptr_responded_msg) { - free(ptr_responded_msg); - ptr_responded_msg = NULL; - }*/ - } - - - //curl_multi_remove_handle(multi_handle, g_http_handle); - //curl_multi_cleanup(multi_handle); - //g_http_handle = NULL; - -#endif - g_response_post_OK = 1; - pthread_mutex_unlock(&mutex_curl); - - if (check_reboot == 1) { - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY"); - write_to_logs_html(temp_msg, "curl to post to get lpr db", "CGI_REBOOT", "Yes"); - write_to_log_if_error(temp_msg, "curl to post to get lpr db", "CGI_REBOOT"); - - pthread_t auto_reboot_thread_id; - if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) - { - printf("\ncreate auto reboot thread faile \n"); - } - } - - pthread_exit(NULL); -} -#endif -#ifdef GY_OS_AMBA -size_t SetSNMPRequest(QueueInfo *q_info) -{ - - if(strlen(q_info->snmp_version)>=1 && - strlen(q_info->snmp_group_name) >= 1 && - strlen(q_info->snmp_host_ip) >= 1 && - strlen(q_info->snmp_host_port) >= 1 && - strlen(q_info->snmp_oid) >= 1 && - strlen(q_info->snmp_value) >= 1 && - strlen(q_info->snmp_type) >= 1 - ) - { - FILE * pPipe; - char cmd[8192*4] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - sprintf(cmd, "timeout 10 /bin/snmpset -%s -c %s %s:%s %s %s %s", - q_info->snmp_version, - q_info->snmp_group_name, - q_info->snmp_host_ip, - q_info->snmp_host_port, - q_info->snmp_oid, - q_info->snmp_type, - q_info->snmp_value); - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) { - char path[1024] = { 0 }; - while (fgets(path, sizeof(path), pPipe) != NULL) - { - sprintf(g_response_snmp, "free:%d,%s,SNMP OK: %s", get_free_mem_data(), cmd, path); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s,SNMP OK: %s", get_free_mem_data(), cmd, path); - write_to_logs_html(temp_msg, "SNMP vpopen snmpset", "INFO", SystemSetting.enable_system_logs); - - break; - } - if (strlen(path) == 0) { - sprintf(g_response_snmp, "free:%d,%s,SNMP OK: Fail, no response.", get_free_mem_data(), cmd); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s,SNMP OK: Fail, no response.", get_free_mem_data(), cmd); - write_to_logs_html(temp_msg, "SNMP vpopen snmpset", "ERROR", SystemSetting.enable_system_logs); - - } - vpclose(pPipe); - } - else { - sprintf(g_response_snmp, "free:%d,%s,SNMP snmpset Fail.", get_free_mem_data(), cmd); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s,SNMP snmpset Fail.", get_free_mem_data(),cmd); - write_to_logs_html(temp_msg, "SNMP vpopen snmpset", "ERROR", SystemSetting.enable_system_logs); - } - } - else { - printf("\n[Set SNMP Request]SNMP was set wrongly.\n"); - sprintf(g_response_snmp,"free:%d,SNMP Format Failed.", get_free_mem_data()); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,SNMP Format Failed.", get_free_mem_data()); - write_to_logs_html(temp_msg, "SNMP vpopen snmpset", "ERROR", SystemSetting.enable_system_logs); - } - - for (int j = 0; j < MAX_SNMP_MANAGEMENT; j++) - { - if (strlen(q_info->snmp_event_name) >= 1 && strcmp(q_info->snmp_event_name, SNMPManagementList[j].snmp_event_name) == 0) - { - SNMPManagementList[j].check_if_delivering = 0; - break; - } - } - - return 0; -} -#endif -#ifdef GY_OS_NOVA -size_t SetHttpRequest_sock(QueueInfo *q_info, char* sendBuffer, char* method) -{ - char sock_sendbuf[MAX_IMG_SIZE] = { 0 }; - char sock_url[8192] = { 0 }; - //size_t content_size_sendbuf = 0; - - char sock_method[32] = { 0 }; - char sock_protocol[32] = { 0 }; - char sock_username[64] = { 0 }; - char sock_password[64] = { 0 }; - char sock_port[10] = { 0 }; - char sock_header[8192] = { 0 }; - - if (strcmp(method, "POST") == 0) - { - if ((int)q_info->content_size >= 1) { - memcpy(sock_sendbuf, q_info->content, (int)q_info->content_size); - } - } - - - if (strcmp(q_info->post_protocol, "HTTP") == 0) { - strcpy(sock_url, "http://"); - } - else { - strcpy(sock_url, "https://"); - } - - if (strcmp(q_info->host_name, "127.0.0.1") != 0 && strcmp(q_info->host_name, "localhost") != 0) { - //if (strlen(q_info->post_username) >= 1) { - //strcat(sock_url, q_info->post_username); - //strcat(sock_url, ":"); - //strcat(sock_url, q_info->post_password); - //strcat(sock_url, "@"); - //} - strcat(sock_url, q_info->host_name); - } - else { - strcpy(q_info->host_name, "127.0.0.1"); - strcat(sock_url, q_info->host_name); - } - - if (strlen(q_info->host_port) >= 1) { - strcat(sock_url, ":"); - strcat(sock_url, q_info->host_port); - } - - //strcat(sock_url, q_info->post_url); - //content_size_sendbuf = q_info->content_size; - strcpy(sock_method, method); - strcpy(sock_protocol, q_info->post_protocol); - - char buf_account[512] = { 0 }; - urldecode((unsigned char *)q_info->post_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)q_info->post_password, (unsigned char *)buf_account2); - - strcpy(sock_username, buf_account); - strcpy(sock_password, buf_account2); - strcpy(sock_port, q_info->host_port); - strcpy(sock_header, q_info->post_customized_header); - - /* - g_stCURL_enable_attached_image = 0; - g_stCURL_enable_attached_image = q_info->enable_attached_image; - g_stCURL_enable_filename_fixed = 0; - g_stCURL_enable_filename_fixed = q_info->enable_filename_fixed; - strcpy(g_stCURL_send_jpeg_file_name, q_info->post_jpeg_file_name); - - if (q_info->image_buff_size >= 1) { - memcpy(g_stCURL_image_buff, q_info->image_buff, q_info->image_buff_size); - g_stCURL_image_buff_size = q_info->image_buff_size; - } - else { - g_stCURL_image_buff_size = 0; - }*/ - - { - //int snapshot_size = 0; - - int status; - struct addrinfo host_info; - struct addrinfo *host_info_list = NULL; - - memset(&host_info, 0, sizeof(host_info)); - - host_info.ai_family = AF_INET;//AF_UNSPEC - host_info.ai_socktype = SOCK_STREAM; - host_info.ai_protocol = 0; - - status = getaddrinfo("127.0.0.1", sock_port, &host_info, &host_info_list); - if (status != 0) { - printf("\n[SetHttpRequest sock]getaddrinfo error\n"); - strcpy(g_response_net_curl,"getaddrinfo error"); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); - write_to_logs_html(temp_msg, "Set Http Request sock", "ERROR", SystemSetting.enable_system_logs); - - g_response_post_OK = 1; - } - else - { - - int socketfd = -1;; - //socketfd = socket(host_info_list->ai_family, host_info_list->ai_socktype, host_info_list->ai_protocol); - struct timeval timeout; - timeout.tv_sec = 3;//3 - timeout.tv_usec = 0; - int tcpnodelay = 1; - int reuse = 1; - int qlen = 5; - - /* - struct sockaddr_in info; - bzero(&info, sizeof(info)); - info.sin_family = PF_INET; - - //localhost test - info.sin_addr.s_addr = inet_addr("127.0.0.1"); - info.sin_port = htons(accountData[0].account_port); - //socket的建立 TCP_PORT_IMAGE - socketfd = socket(host_info_list->ai_family, host_info_list->ai_socktype, host_info_list->ai_protocol);*/ - - int err = -1; - -#if 1 - struct addrinfo *rp; - for (rp = host_info_list; rp != NULL; rp = rp->ai_next) { - - socketfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - if (socketfd == -1) { - printf("\n[SetHttpRequest sock]socket error\n"); - strcpy(g_response_net_curl, "socket error"); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); - write_to_logs_html(temp_msg, "Set Http Request sock", "ERROR", SystemSetting.enable_system_logs); - - g_response_post_OK = 1; - } - else { - //printf("\n-------open getimage connected (%d)\n", socketfd); - - setsockopt(socketfd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); - setsockopt(socketfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); - setsockopt(socketfd, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); - setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); - setsockopt(socketfd, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); - setsockopt(socketfd, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); - - if (connect(socketfd, rp->ai_addr, rp->ai_addrlen) != -1) { - - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - if (socketRecords[i].used == 0 && socketRecords[i].sock == -1) - { - socketRecords[i].sock = socketfd; - //memset(&(socketRecords[i].recent_sec_data), 0x00, sizeof(SecData)); - //socketRecords[i].thread_id = 0; - socketRecords[i].channel_id = -1; - //socketRecords[i].last_recv_time = time(0); - //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; - socketRecords[i].isGetAlarmMotion = FALSE; - //socketRecords[i].isFirstAlarmMotion = FALSE; - socketRecords[i].isUdpSocket = FALSE; - socketRecords[i].isWebSocketConnect = FALSE; - socketRecords[i].isNvrRequest = 0; - socketRecords[i].isCredentialRequest = 0; - socketRecords[i].debug_type = 3; -#if defined GY_OS_AMBA - //socketRecords[i].iIsAIRelay = 0; -#endif - socketRecords[i].used = 1; - //printf("\n(%d) [run http server] socketRecords[%d].sock:%d\n", client_sock, i, socketRecords[i].sock); - break; - } - else { - if (i == MAX_CLIENT_SOCKET - 1) { - close(socketfd); - //printf("\n-------close getimage connected (%d)\n", socketfd); - socketfd = -1; - } - } - } - - if (socketfd != -1) { - break; - } - } - else { - close(socketfd); - //printf("\n-------close getimage connected (%d)\n", socketfd); - socketfd = -1; - } - } - } -#endif - - if (socketfd >= 0) { - char Authorization[2560] = { 0 }; - if (strlen(sock_username) > 0) - { - //strcat(sendBuffer, "Authorization: Basic "); - strcpy(Authorization, sock_username); - strcat(Authorization, ":"); - - if (strlen(sock_password) > 0) - strcat(Authorization, sock_password); - } - - size_t base64_encode_length = 0; - char httpAuth[2560] = { 0 }; - if (strlen(Authorization) >= 1) - { - - base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); - httpAuth[base64_encode_length] = '\0'; - } - - //printf("\n------httpAuth:%s\n", httpAuth); - - char msg[2560] = { 0 }; - sprintf(msg, "%s %s HTTP/1.1\r\nhost: 127.0.0.1\r\nport: %s\r\nConnection: close\r\n", sock_method, q_info->post_url, sock_port); - - strcat(msg, "Authorization: Basic "); - strcat(msg, httpAuth); - strcat(msg, "\r\n"); - strcat(msg, "\r\n"); - - //printf("\n-----------msg:%s\n", msg); - - err = send(socketfd, msg, strlen(msg), 0); - if (err == -1) { - printf("\n[SetHttpRequest sock]error sending\n"); - strcpy(g_response_net_curl, "error sending"); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); - write_to_logs_html(temp_msg, "Set Http Request sock", "ERROR", SystemSetting.enable_system_logs); - - g_response_post_OK = 1; - } - else { - char b_buffer[MAX_IMG_SIZE] = { 0 }; - //size_t bReceived; - - /*bReceived = */recv(socketfd, b_buffer, MAX_IMG_SIZE, 0); - //printf("\n[SetHttpRequest sock]------:%s\n", b_buffer); - if (strstr(b_buffer, "200") != NULL) { - strcpy(g_response_net_curl, "OK"); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); - write_to_logs_html(temp_msg, "Set Http Request sock", "INFO", SystemSetting.enable_system_logs); - - g_response_post_OK = 1; - } - else { - strcpy(g_response_net_curl, "error response"); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); - write_to_logs_html(temp_msg, "Set Http Request sock", "ERROR", SystemSetting.enable_system_logs); - - g_response_post_OK = 1; - } - } - - close(socketfd); - //printf("\n-------close getimage connected (%d)\n", socketfd); - - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - if (socketRecords[i].used == 1 && socketRecords[i].sock == socketfd) - { - //printf("\n\n(%d) [http connection fun] clean socket[%d]\n\n", sock, i); - - socketRecords[i].sock = -1; - //socketRecords[i].thread_id = 0; - socketRecords[i].channel_id = -1; - //socketRecords[i].last_recv_time = time(0); - //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; - socketRecords[i].isGetAlarmMotion = FALSE; - //socketRecords[i].isFirstAlarmMotion = FALSE; - socketRecords[i].isWebSocketConnect = FALSE; - socketRecords[i].isUdpSocket = FALSE; - socketRecords[i].isNvrRequest = 0; - socketRecords[i].isCredentialRequest = 0; - socketRecords[i].debug_type = 0; -#if defined GY_OS_AMBA - //socketRecords[i].iIsAIRelay = 0; -#endif - socketRecords[i].used = 0; - break; - } - } - - socketfd = -1; - } - else { - printf("\n[SetHttpRequest sock]Could not create socket!\n"); - strcpy(g_response_net_curl, "Could not create socket!"); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "%s", g_response_net_curl); - write_to_logs_html(temp_msg, "Set Http Request sock", "ERROR", SystemSetting.enable_system_logs); - - g_response_post_OK = 1; - } - } - - if (host_info_list != NULL) { - freeaddrinfo(host_info_list); - host_info_list = NULL; - } - } -} -#endif - -size_t SetHttpRequest(QueueInfo *q_info, char* sendBuffer, char* method) -{ - -#if 1 - // Declare and initialize variables - //SOCKET sock; - //char* ip = NULL; - //char HostName[MAX_MSG_LEN] = { 0 }; // an IP address or a hostname, like "www.google.com" by itself - //char HostPort[10] = { 0 }; - //unsigned char Authorization[2560] = { 0 }; - //char Temp[MAX_MSG_LEN] = { 0 }; - //size_t sendLen = 0; - - //struct addrinfo* result = NULL; - //struct addrinfo* ptr = NULL; - //struct addrinfo hints = { 0 }; - //struct sockaddr_in* sockaddr_ipv4 = NULL; - - /*if (MapFind("", Value)) - strcpy(HostName, Value); - - if (MapFind("", Value)) - strcpy(HostPort, Value);*/ - - //hints.ai_flags = AI_NUMERICHOST; - - /* - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - */ - char curl_sendbuf[MAX_IMG_SIZE] = ""; - char curl_url[8192] = ""; - -#ifdef FOR_CC_POST -#else - //DWORD ret = getaddrinfo(HostName, "http", &hints, &result); - DWORD ret = getaddrinfo(q_info->host_name, q_info->host_port, &hints, &result); - if (ret != 0) { - printf("\ngetaddrinfo failed with error: %d\n", ret); - return 1; - } - - for (ptr = result; ptr != NULL; ptr = ptr->ai_next) - { - sock = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); - - /*printf("\nsock: %d\n",sock); - printf("\nptr->ai_addrlen: %d\n",ptr->ai_addrlen);*/ - - if (sock == -1) - continue; - - if (connect(sock, ptr->ai_addr, ptr->ai_addrlen) != -1) - { - break; /* Success */ - } - - close(sock); - //closesocket(sock); - } - - if (ptr == NULL) - { - // 迴圈已經執行到 list 的最後,都無法連線 - fprintf(stderr, "Failed to send POST to %s%s:%s\n", "http://", q_info->host_name, q_info->host_port); - return 1; - } - - if (ptr->ai_family == AF_INET) - { - sockaddr_ipv4 = (struct sockaddr_in *) ptr->ai_addr; - ip = inet_ntoa(sockaddr_ipv4->sin_addr); - //printf("ip address=%s\n", ip); - } - freeaddrinfo(result); // 釋放 servinfo 記憶體空間 -#endif - //http first line - //if (featureType & FEATURE_LPR_TUR) - { -#if 0 - strcat(sendBuffer, method); - strcat(sendBuffer, " "); - /*if (MapFind("", Value)) - { - if(Value[0]=='/') - strcat(sendBuffer, Value); - else - { - strcat(sendBuffer, "/"); - strcat(sendBuffer, Value); - } - } - else - strcat(sendBuffer, "/");*/ - - if (q_info->post_url[0] == '/') - strcat(sendBuffer, q_info->post_url); - else - { - strcat(sendBuffer, "/"); - strcat(sendBuffer, q_info->post_url); - } - - strcat(sendBuffer, " "); - strcat(sendBuffer, "HTTP/1.1"); - strcat(sendBuffer, "\r\n"); - - strcat(sendBuffer, "Host: "); - strcat(sendBuffer, q_info->host_name); - if (strlen(q_info->host_port) > 0) - { - strcat(sendBuffer, ":"); - strcat(sendBuffer, q_info->host_port); - } - - /*strcat(sendBuffer, "Host: "); - strcat(sendBuffer, q_info->host_name); - - if (MapFind("", Value)) - { - strcat(sendBuffer, Value); - if (MapFind("", Value)) - { - strcat(sendBuffer, ":"); - strcat(sendBuffer, Value); - } - }*/ - strcat(sendBuffer, "\r\n"); - - strcat(sendBuffer, "Cache-Control: no-cache"); - strcat(sendBuffer, "\r\n"); - - strcat(sendBuffer, "User-Agent: IPVideo"); - strcat(sendBuffer, "\r\n"); - - strcat(sendBuffer, "Accept: */*"); - strcat(sendBuffer, "\r\n"); - - //strcat(sendBuffer, "Cookie: PHPSESSID=rqtd0uct26c5rnba0a4f6fsva1"); - //strcat(sendBuffer, "\r\n"); - - //strcat(sendBuffer, "Accept-Encoding: gzip, deflate"); - strcat(sendBuffer, "\r\n"); - - strcat(sendBuffer, "Content-Type: text/html; charset=utf-8"); - strcat(sendBuffer, "\r\n"); -#endif - -#if 0 - size_t contentLen = strlen(q_info->content); - - sprintf(Temp, "%ld", contentLen); - strcat(sendBuffer, "Content-Length: "); - strcat(sendBuffer, Temp); - strcat(sendBuffer, "\r\n"); - - strcat(sendBuffer, "Connection: Closed"); - strcat(sendBuffer, "\r\n"); - - if (strlen(q_info->post_username) > 0) - { - strcat(sendBuffer, "Authorization: Basic "); - strcpy(Authorization, q_info->post_username); - strcat(Authorization, ":"); - - if (strlen(q_info->post_password) > 0) - strcat(Authorization, q_info->post_password); - } -#endif - /*strcat(sendBuffer, "Authorization: Basic "); - if (MapFind("", Value)) - strcpy(Authorization, Value); - if (MapFind("", Value)) - { - strcat(Authorization, ":"); - strcat(Authorization, Value); - }*/ -#if 0 - size_t base64_encode_length = 0; - char httpAuth[2560] = { 0 }; - strcpy(httpAuth,base64_encode(Authorization, strlen(Authorization), &base64_encode_length)); - httpAuth[base64_encode_length] = '\0'; - //*(httpAuth + base64_encode_length-1) = '6'; - - strcat(sendBuffer, httpAuth); - strcat(sendBuffer, "\r\n"); - strcat(sendBuffer, "\r\n"); -#endif - -#if 0 - size_t headerLen = strlen(sendBuffer); - /*if (MapFind("", Value)) - { - strcat(sendBuffer, Value); - contentLen = strlen(Value); - }*/ - - //printf("sendBuffer= %s\n", sendBuffer); - //size_t headerLen = strlen(sendBuffer); - size_t totalLen = headerLen; -#endif - if (strcmp(method, "POST") == 0) - { -#if 0 - contentLen = strlen(q_info->content); - - memset(curl_sendbuf, 0, sizeof(curl_sendbuf)); -#endif - if ((int)q_info->content_size >= 1) { - memcpy(curl_sendbuf, q_info->content, (int)q_info->content_size); - } - -#if 0 - memcpy(curl_sendbuf, q_info->content, strlen(q_info->content)); - memcpy(sendBuffer + headerLen, q_info->content, contentLen); - totalLen = headerLen + contentLen; -#endif - } - - //printf("send= %s\n", sendBuffer); - -#if 0 - if (strcmp(q_info->post_protocol, "HTTPS") == 0) - { - strcat(curl_url, "https://"); - strcat(curl_url, q_info->host_name); - strcat(curl_url, q_info->post_url); - - printf("Https curl_url: %s \n", curl_url); - - memset(&g_stCURL_send_data, 0, sizeof(g_stCURL_send_data)); - - strncpy(g_stCURL_send_data.curl_url, curl_url, strlen(curl_url)); - strncpy(g_stCURL_send_data.curl_sendbuf, curl_sendbuf, strlen(curl_sendbuf)); - strncpy(g_stCURL_send_data.method, method, strlen(method)); - strncpy(g_stCURL_send_data.username, q_info->post_username, strlen(q_info->post_username)); - strncpy(g_stCURL_send_data.password, q_info->post_password, strlen(q_info->post_password)); - strncpy(g_stCURL_send_data.port, q_info->host_port, strlen(q_info->host_port)); - - - pthread_t curl_thread_id; - if (pthread_create(&curl_thread_id, 0, net_curl_https_post_push_info, NULL)) - { - printf("create curl thread faile \n"); - } - - //int curl_ret = net_curl_https_post_push_info(curl_url, curl_sendbuf, NULL); - //int curl_ret = net_curl_https_post_push_info(curl_url, curl_sendbuf, NULL, method, - // q_info->post_username, q_info->post_password, strtol(q_info->host_port, NULL, 10)); - } - else -#endif - { - if (strcmp(q_info->post_protocol, "HTTP") == 0) { - strcat(curl_url, "http://"); - } - else { - strcat(curl_url, "https://"); - } - - if (strcmp(q_info->host_name, "127.0.0.1") != 0 && strcmp(q_info->host_name, "localhost") != 0) { - g_stCURL_check_127 = 0; - //if (strlen(q_info->post_username) >= 1 /*&& strlen(q_info->post_password) >= 1*/) { - //strcat(curl_url, q_info->post_username); - //strcat(curl_url, ":"); - //strcat(curl_url, q_info->post_password); - //strcat(curl_url, "@"); - //} - strcat(curl_url, q_info->host_name); - } - else { - g_stCURL_check_127 = 1; - strcpy(q_info->host_name, "127.0.0.1"); - strcat(curl_url, q_info->host_name); - } - - if (strlen(q_info->host_port) >= 1) { - strcat(curl_url, ":"); - strcat(curl_url, q_info->host_port); - } - - strcat(curl_url, q_info->post_url); - - if (strstr(q_info->post_url, "control?virtual.input") != NULL && strcmp(viewChannelData[0].enable_lpr_upon_triggered, "Yes") == 0) { - g_control_alarm_gpio = 1; - } - - - //printf("Http curl_url: %s \n", curl_url); - - //memset(&g_stCURL_send_data, 0, sizeof(g_stCURL_send_data)); - - //memset(g_stCURL_send_data_curl_url, 0, 8192); - //memset(g_stCURL_send_data_curl_sendbuf, 0, 8192); - //memset(g_stCURL_send_data_method, 0, 32); - //memset(g_stCURL_send_data_username, 0, 64); - //memset(g_stCURL_send_data_password, 0, 64); - //memset(g_stCURL_send_data_port, 0, 10); - - pthread_mutex_lock(&mutex_curl); - - strcpy(g_stCURL_send_data_curl_url, curl_url); - g_stCURL_send_data_curl_sendbuf_size = 0; - g_stCURL_send_data_curl_sendbuf_size = q_info->content_size; - memcpy(g_stCURL_send_data_curl_sendbuf, curl_sendbuf, g_stCURL_send_data_curl_sendbuf_size); - strcpy(g_stCURL_send_data_method, method); - strcpy(g_stCURL_send_data_protocol, q_info->post_protocol); - char buf_account[512] = { 0 }; - urldecode((unsigned char *)q_info->post_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)q_info->post_password, (unsigned char *)buf_account2); - - strcpy(g_stCURL_send_data_username, buf_account); - strcpy(g_stCURL_send_data_password, buf_account2); - strcpy(g_stCURL_send_data_port, q_info->host_port); - strcpy(g_stCURL_send_data_timeout, q_info->post_timeout); - strcpy(g_stCURL_send_data_customized_header, q_info->post_customized_header); - g_stCURL_enable_attached_image = 0; - g_stCURL_enable_attached_image = q_info->enable_attached_image; - g_stCURL_enable_filename_fixed = 0; - g_stCURL_enable_filename_fixed = q_info->enable_filename_fixed; - strcpy(g_stCURL_send_jpeg_file_name, q_info->post_jpeg_file_name); - - if (q_info->image_buff_size >= 1) { - memcpy(g_stCURL_image_buff, q_info->image_buff, q_info->image_buff_size); - g_stCURL_image_buff_size = q_info->image_buff_size; - } - else { - g_stCURL_image_buff_size = 0; - } - - strcpy(g_stCURL_send_data_q_name, q_info->q_name); - strcpy(g_stCURL_send_data_q_plate, q_info->q_plate); - - pthread_mutex_unlock(&mutex_curl); - - /* - printf("\n-----------g_stCURL_send_data_curl_url:%s\n", g_stCURL_send_data_curl_url); - printf("\n-----------g_stCURL_send_data_curl_sendbuf_size:%d\n", g_stCURL_send_data_curl_sendbuf_size); - printf("\n-----------g_stCURL_send_data_curl_sendbuf:%s\n", g_stCURL_send_data_curl_sendbuf); - printf("\n-----------g_stCURL_send_data_method:%s\n", g_stCURL_send_data_method); - printf("\n-----------g_stCURL_send_data_protocol:%s\n", g_stCURL_send_data_protocol); - printf("\n-----------g_stCURL_send_data_username:%s\n", g_stCURL_send_data_username); - printf("\n-----------g_stCURL_send_data_password:%s\n", g_stCURL_send_data_password); - printf("\n-----------g_stCURL_send_data_port:%s\n", g_stCURL_send_data_port); - printf("\n-----------g_stCURL_send_data_customized_header:%s\n", g_stCURL_send_data_customized_header); - printf("\n-----------g_stCURL_enable_attached_image:%d\n", g_stCURL_enable_attached_image); - printf("\n-----------g_stCURL_enable_filename_fixed:%d\n", g_stCURL_enable_filename_fixed); - printf("\n-----------g_stCURL_send_jpeg_file_name:%s\n", g_stCURL_send_jpeg_file_name); - */ -#if 1 - - //if (IsValidURL(curl_url)==true) { - - if (g_check_ping_OK == 1) { - if (g_stCURL_enable_attached_image == 0) { - pthread_t curl_thread_id; - if (pthread_create(&curl_thread_id, 0, net_curl_https_post_push_info, NULL)) - { - printf("create curl thread faile \n"); - } - } - else if (g_stCURL_enable_attached_image == 1) { - pthread_t curl_image_thread_id; - if (pthread_create(&curl_image_thread_id, 0, net_curl_https_post_push_info_attached_image, NULL)) - { - printf("create curl image thread faile \n"); - } - } - } - - - //} -#endif - - //int curl_ret = net_curl_https_post_push_info(curl_url, curl_sendbuf, NULL, method, - // q_info->post_username, q_info->post_password, strtol(q_info->host_port, NULL, 10)); -#if 0 - if (send(sock, sendBuffer, totalLen, MSG_MORE) == -1) - printf("\nsend error(post notification) #1\n"); - else - printf("\nSuccess to send.\n"); -#endif - } - - -#ifdef FOR_CC_POST -#else - closesocket(sock); -#endif - } - -#endif - return 0; -} -#ifdef GY_OS_AMBA -void Create_ptz_socket() -{ - char *host = "127.0.0.1"; // 目標 URI - char *PORT_NUM = "80"; // HTTP port - - //int cfd; // Socket 檔案描述符 (File Descriptor) - int gaiStatus; // getaddrinfo 狀態碼 - struct addrinfo hints; // hints 參數,設定 getaddrinfo() 的回傳方式 - struct addrinfo *result; // getaddrinfo() 執行結果的 addrinfo 結構指標 - - // 以 memset 清空 hints 結構 - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; // 使用 IPv4 or IPv6 - hints.ai_socktype = SOCK_STREAM; // 串流 Socket - hints.ai_flags = AI_NUMERICSERV; // 將 getaddrinfo() 第 2 參數 (PORT_NUM) 視為數字 - - // 以 getaddrinfo 透過 DNS,取得 addrinfo 鏈結串列 (Linked List) - // 以從中取得 Host 的 IP 位址 - if ((gaiStatus = getaddrinfo(host, PORT_NUM, &hints, &result)) != 0) - printf("fail getaddrinfo\n"); - - // 分別以 domain, type, protocol 建立 socket 檔案描述符 - g_socket = socket(result->ai_family, result->ai_socktype, 0); - - g_socket = socket(AF_INET, SOCK_STREAM, 0); - fcntl(g_socket, F_SETFL, O_NONBLOCK); - - // 以 socket 檔案描述符 (cfd), addr, addrlen 進行連線 - // 其中,result->ai_addr 為 gai 取得之 通用 socket 位址結構 -- sockaddr - if (connect(g_socket, result->ai_addr, result->ai_addrlen) < 0) - printf("fail connect\n"); - - - // 釋放 getaddrinfo (Linked List) 記憶體空間 - freeaddrinfo(result); - result = NULL; -} - -void SetHttpRequest_ptz_re(char *cgi_url, char *sOutput_data, char *sUsername, char *sPassword) -{ - //char *host = "ptsv2.com"; // 目標 URI - //char *host = "127.0.0.1"; // 目標 URI - //char *PORT_NUM = "80"; // HTTP port - - char request[0xfff], response[0xfff]; // 請求 與 回應訊息 - - //char *requestLine = "GET /t/g9mu2-1639036821/post HTTP/1.1\r\n"; // 請求行 - //char *requestLine = "GET /server HTTP/1.1\r\n"; // 請求行 - //char *headerFmt = "Host: %s\r\n"; // Host 表頭欄位 - char *headerFmt = "Host: 127.0.0.1\r\n"; // Host 表頭欄位 - char *CRLF = "\r\n"; // 表頭後的 CRLF - - // 靜態配置表頭記憶體 - //size_t bufferLen = 1024; - char buffer[1024] = { 0 }; - - //組裝請求CGI - char requestLine[512] = { 0 }; //"GET /server HTTP/1.1\r\n"; // 請求行 - strcat(requestLine, "GET"); - strcat(requestLine, " "); - - if (strlen(cgi_url) > 0) - strcat(requestLine, cgi_url); - else - strcat(requestLine, "/server"); - - strcat(requestLine, " "); - strcat(requestLine, "HTTP/1.1"); - strcat(requestLine, CRLF); - - //組裝請求訊息 - strcpy(request, requestLine); - - //snprintf(buffer, bufferLen, headerFmt, host); //(配合動態配置記憶體) - strcat(buffer, headerFmt); - strcat(request, buffer); - - strcat(request, "Accept: */*"); - strcat(request, CRLF); - - strcat(request, "Content-Type: application/json"); - strcat(request, CRLF); - - strcat(request, "Connection: close"); - strcat(request, CRLF); - - - //組裝帳密資料 - strcat(request, "Authorization: Basic "); - //strcpy(Authorization, q_info->post_username); - - char Authorization[2560] = { 0 }; - strcpy(Authorization, sUsername); - strcat(Authorization, ":"); - strcat(Authorization, sPassword); - - size_t base64_encode_length = 0; - char httpAuth[2560] = { 0 }; - //char original_base64_output[8 * 8192] = { 0 }; - base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); - httpAuth[base64_encode_length] = '\0'; - - strcat(request, httpAuth); - strcat(request, CRLF); - strcat(request, CRLF); - - // 格式化輸出請求訊息 - printf("----------\nRequest:\n----------\n%s\n", request); - - // 發送請求 - if (send(g_socket, request, strlen(request), 0) < 0) - printf("Send\n"); - - - // 接收回應 - if (recv(g_socket, response, 0xfff, 0) < 0) - { - printf("Receive fail\n"); - } - else - { - size_t iRecvLen = strlen(response); - printf("ReceiveLen: %d\n", (int)iRecvLen); - printf("Receive: \n%s\n", response); - - - snprintf(sOutput_data, iRecvLen, response); - //strcpy(sOutput_data, response); - } -} - -void SetHttpRequest_ptz(char *cgi_url, char *sOutput_data, char *sUsername, char *sPassword) -{ - //char *host = "ptsv2.com"; // 目標 URI - char *host = "127.0.0.1"; // 目標 URI - char *PORT_NUM = "80"; // HTTP port - - char request[0xfff], response[0xfff]; // 請求 與 回應訊息 - - //char *requestLine = "GET /t/g9mu2-1639036821/post HTTP/1.1\r\n"; // 請求行 - //char *requestLine = "GET /server HTTP/1.1\r\n"; // 請求行 - //char *headerFmt = "Host: %s\r\n"; // Host 表頭欄位 - char *headerFmt = "Host: 127.0.0.1\r\n"; // Host 表頭欄位 - char *CRLF = "\r\n"; // 表頭後的 CRLF - - int cfd; // Socket 檔案描述符 (File Descriptor) - int gaiStatus; // getaddrinfo 狀態碼 - struct addrinfo hints; // hints 參數,設定 getaddrinfo() 的回傳方式 - struct addrinfo *result; // getaddrinfo() 執行結果的 addrinfo 結構指標 - - // 動態配置記憶體,以決定 表頭緩衝區 (Header Buffer) 長度 - //size_t bufferLen = strlen(headerFmt) + strlen(host) + 1; - //char *buffer = (char *)malloc(bufferLen); // 表頭緩衝區 - - // 靜態配置表頭記憶體 - //size_t bufferLen = 1024; - char buffer[1024] = { 0 }; - - //組裝請求CGI - char requestLine[512] = { 0 }; //"GET /server HTTP/1.1\r\n"; // 請求行 - strcat(requestLine, "GET"); - strcat(requestLine, " "); - - if (strlen(cgi_url) > 0) - strcat(requestLine, cgi_url); - else - strcat(requestLine, "/server"); - - strcat(requestLine, " "); - strcat(requestLine, "HTTP/1.1"); - strcat(requestLine, CRLF); - - //組裝請求訊息 - strcpy(request, requestLine); - - //snprintf(buffer, bufferLen, headerFmt, host); //(配合動態配置記憶體) - strcat(buffer, headerFmt); - strcat(request, buffer); - - strcat(request, "Accept: */*"); - strcat(request, CRLF); - - strcat(request, "Content-Type: application/json"); - strcat(request, CRLF); - - strcat(request, "Connection: close"); - strcat(request, CRLF); - - - //組裝帳密資料 - strcat(request, "Authorization: Basic "); - //strcpy(Authorization, q_info->post_username); - - char Authorization[2560] = { 0 }; - strcpy(Authorization, sUsername); - strcat(Authorization, ":"); - strcat(Authorization, sPassword); - - size_t base64_encode_length = 0; - char httpAuth[2560] = { 0 }; - //char original_base64_output[8 * 8192] = { 0 }; - base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); - httpAuth[base64_encode_length] = '\0'; - - strcat(request, httpAuth); - strcat(request, CRLF); - strcat(request, CRLF); - - - // 釋放緩衝區記憶體 (配合動態配置記憶體) - //free(buffer); - //buffer = NULL; - - // 以 memset 清空 hints 結構 - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; // 使用 IPv4 or IPv6 - hints.ai_socktype = SOCK_STREAM; // 串流 Socket - hints.ai_flags = AI_NUMERICSERV; // 將 getaddrinfo() 第 2 參數 (PORT_NUM) 視為數字 - - // 以 getaddrinfo 透過 DNS,取得 addrinfo 鏈結串列 (Linked List) - // 以從中取得 Host 的 IP 位址 - if ((gaiStatus = getaddrinfo(host, PORT_NUM, &hints, &result)) != 0) - printf("fail getaddrinfo\n"); - - - // 分別以 domain, type, protocol 建立 socket 檔案描述符 - cfd = socket(result->ai_family, result->ai_socktype, 0); - - cfd = socket(AF_INET, SOCK_STREAM, 0); - fcntl(cfd, F_SETFL, O_NONBLOCK); - - // 以 socket 檔案描述符 (cfd), addr, addrlen 進行連線 - // 其中,result->ai_addr 為 gai 取得之 通用 socket 位址結構 -- sockaddr - if (connect(cfd, result->ai_addr, result->ai_addrlen) < 0) - printf("fail connect\n"); - - - // 釋放 getaddrinfo (Linked List) 記憶體空間 - freeaddrinfo(result); - result = NULL; - - // 格式化輸出請求訊息 - printf("----------\nRequest:\n----------\n%s\n", request); - - // 發送請求 - if (send(cfd, request, strlen(request), 0) < 0) - printf("Send\n"); - - - // 接收回應 - if (recv(cfd, response, 0xfff, 0) < 0) - { - printf("Receive fail\n"); - } - else - { - size_t iRecvLen = strlen(response); - printf("ReceiveLen: %d\n", (int)iRecvLen); - printf("Receive: \n%s\n", response); - - - snprintf(sOutput_data, iRecvLen, response); - //strcpy(sOutput_data, response); - } - - close(cfd); -} - -void SetHttpRequest_ptz_ok() -{ - //char *host = "ptsv2.com"; // 目標 URI - char *host = "127.0.0.1"; // 目標 URI - char *PORT_NUM = "80"; // HTTP port - - char request[0xfff], response[0xfff]; // 請求 與 回應訊息 - //char *requestLine = "GET /t/g9mu2-1639036821/post HTTP/1.1\r\n"; // 請求行 - char *requestLine = "GET /server HTTP/1.1\r\n"; // 請求行 - char *headerFmt = "Host: %s\r\n"; // Host 表頭欄位 - char *CRLF = "\r\n"; // 表頭後的 CRLF - - int cfd; // Socket 檔案描述符 (File Descriptor) - int gaiStatus; // getaddrinfo 狀態碼 - struct addrinfo hints; // hints 參數,設定 getaddrinfo() 的回傳方式 - struct addrinfo *result; // getaddrinfo() 執行結果的 addrinfo 結構指標 - - // 動態配置記憶體,以決定 表頭緩衝區 (Header Buffer) 長度 - size_t bufferLen = strlen(headerFmt) + strlen(host) + 1; - char *buffer = (char *)malloc(bufferLen); // 表頭緩衝區 - - //組裝請求訊息 - strcpy(request, requestLine); - snprintf(buffer, bufferLen, headerFmt, host); - strcat(request, buffer); - strcat(request, CRLF); - - // 釋放緩衝區記憶體 - if (buffer != NULL) - { - free(buffer); - buffer = NULL; - } - // 以 memset 清空 hints 結構 - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; // 使用 IPv4 or IPv6 - hints.ai_socktype = SOCK_STREAM; // 串流 Socket - hints.ai_flags = AI_NUMERICSERV; // 將 getaddrinfo() 第 2 參數 (PORT_NUM) 視為數字 - - // 以 getaddrinfo 透過 DNS,取得 addrinfo 鏈結串列 (Linked List) - // 以從中取得 Host 的 IP 位址 - if ((gaiStatus = getaddrinfo(host, PORT_NUM, &hints, &result)) != 0) - printf("fail getaddrinfo\n"); - - - // 分別以 domain, type, protocol 建立 socket 檔案描述符 - cfd = socket(result->ai_family, result->ai_socktype, 0); - - // 以 socket 檔案描述符 (cfd), addr, addrlen 進行連線 - // 其中,result->ai_addr 為 gai 取得之 通用 socket 位址結構 -- sockaddr - if (connect(cfd, result->ai_addr, result->ai_addrlen) < 0) - printf("fail connect\n"); - - - // 釋放 getaddrinfo (Linked List) 記憶體空間 - freeaddrinfo(result); - result = NULL; - - // 格式化輸出請求訊息 - printf("----------\nRequest:\n----------\n%s\n", request); - - // 發送請求 - if (send(cfd, request, strlen(request), 0) < 0) - printf("Send\n"); - - // 接收回應 - if (recv(cfd, response, 0xfff, 0) < 0) - printf("Receive fail\n"); - else - printf("Receive: %s\n", response); - -} - -#if 0 -void SetHttpRequest_ptz() -{ - QueueInfo single_queue_node; - - strcat(single_queue_node.host_name, "ptsv2.com"); - strcat(single_queue_node.post_url, "/t/g9mu2-1639036821/post"); - strcat(single_queue_node.post_protocol, "HTTP"); - strcat(single_queue_node.content, "/t/g9mu2-1639036821/post"); - - char *host = "ptsv2.com"; // 目標 URI - //char *host = "127.0.0.1"; // 目標 URI - char *PORT_NUM = "80"; // HTTP port - - - //char sTestSendBuffer[512]; - //SetHttpRequest_ptz(&single_queue_node, sTestSendBuffer, "POST"); - - - struct addrinfo hints = { 0 }; - struct addrinfo* feed_server = NULL; - - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; // 使用 IPv4 or IPv6 - hints.ai_socktype = SOCK_STREAM; // 串流 Socket - hints.ai_flags = AI_NUMERICSERV; // 將 getaddrinfo() 第 2 參數 (PORT_NUM) 視為數字 - //hints.ai_family = AF_INET; - //getaddrinfo("ptsv2.com", NULL, &hints, &feed_server); - if ((gaiStatus = getaddrinfo(host, PORT_NUM, &hints, &result)) != 0) - printf("fail getaddrinfo\n"); - - - SOCKET sock; - - struct addrinfo *res; - for (res = feed_server; res != NULL; res = res->ai_next) { - struct sockaddr_in* saddr = (struct sockaddr_in*)res->ai_addr; - - sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); - /*printf("\nsock: %d\n",sock); - printf("\nres->ai_addrlen: %d\n",res->ai_addrlen);*/ - printf("22\n"); - - if (sock == -1) - continue; - - if (connect(sock, res->ai_addr, res->ai_addrlen) != -1) - { - printf("conn sock = %d \n", sock); - printf("hostname: %s\n", inet_ntoa(saddr->sin_addr)); - break; /* Success */ - } - - //closesocket(sock); - } - - if (res == NULL) - { - // 迴圈已經執行到 list 的最後,都無法連線 - printf("Failed to send POST to %s%s:%s\n", "http://", "127.0.0.1", "80"); - return; - } - - char sendBuffer[1024]; - char Temp[MAX_MSG_LEN] = { 0 }; - - //size_t sendLen = 0; - - { - strcat(sendBuffer, "POST"); - //strcat(sendBuffer, "GET"); - strcat(sendBuffer, " "); - - if (strcmp("HTTP", "HTTP") == 0) - { - //if (q_info->post_url[0] == '/') - //{ - //strcat(sendBuffer, q_info->post_url); - //} - //else - //{ - // strcat(sendBuffer, "/"); - //strcat(sendBuffer, q_info->post_url); - //} - } - //strcat(sendBuffer, q_info->post_url); - //strcat(sendBuffer, "/server"); - strcat(sendBuffer, "/t/g9mu2-1639036821/post"); - - strcat(sendBuffer, " "); - strcat(sendBuffer, "HTTP/1.1"); - strcat(sendBuffer, "\r\n"); - int first_line_len = strlen(sendBuffer); - - strcat(sendBuffer, "Host: "); - strcat(sendBuffer, "ptsv2.com"); - //strcat(sendBuffer, q_info->host_name); - - //if (strlen(q_info->host_port) > 0) - //{ - // strcat(sendBuffer, ":"); - // strcat(sendBuffer, q_info->host_port); - //} - - strcat(sendBuffer, "\r\n"); - - //strcat(sendBuffer, "Cache-Control: no-cache"); - //strcat(sendBuffer, "\r\n"); - - //strcat(sendBuffer, "User-Agent: IPVideo"); - //strcat(sendBuffer, "\r\n"); - - //strcat(sendBuffer, "Accept: */*"); - //strcat(sendBuffer, "\r\n"); - - //strcat(sendBuffer, "Cookie: PHPSESSID=rqtd0uct26c5rnba0a4f6fsva1"); - //strcat(sendBuffer, "\r\n"); - - //strcat(sendBuffer, "Accept-Encoding: gzip, deflate"); - //strcat(sendBuffer, "\r\n"); - - //strcat(sendBuffer, "Content-Type: text/html; charset=utf-8"); - strcat(sendBuffer, "Content-Type: application/json"); - strcat(sendBuffer, "\r\n"); - - - - //size_t contentLen = strlen(q_info->content); - //size_t contentLen = strlen("/t/g9mu2-1639036821/post"); - size_t contentLen = 0; - - strcat(sendBuffer, "Content-Length: "); - sprintf(Temp, "%ld", contentLen); - strcat(sendBuffer, Temp); - strcat(sendBuffer, "\r\n"); - - //strcat(sendBuffer, "Connection: Closed"); - //strcat(sendBuffer, "\r\n"); - - //unsigned char Authorization[2560] = { 0 }; - - ////if (strlen(q_info->post_username) > 0) - //if (strlen("admin") > 0) - //{ - // strcat(sendBuffer, "Authorization: Basic "); - // //strcpy(Authorization, q_info->post_username); - // strcpy(Authorization, "admin"); - // strcat(Authorization, ":"); - - // //if (strlen(q_info->post_password) > 0) - // if (strlen("Pass1234") > 0) - // strcat(Authorization, "Pass1234"); - //} - - - - //size_t base64_encode_length = 0; - //char httpAuth[2560] = { 0 }; - - ////char original_base64_output[8 * 8192] = { 0 }; - //base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); - //httpAuth[base64_encode_length] = '\0'; - ////*(httpAuth + base64_encode_length-1) = '6'; - - //strcat(sendBuffer, httpAuth); - //strcat(sendBuffer, "\r\n"); - - //strcat(sendBuffer, "\r\n"); - - - size_t headerLen = strlen(sendBuffer); - size_t totalLen = headerLen; -#if 0 - /*if (strcmp("GET", "POST") == 0) - { - contentLen = strlen("/t/g9mu2-1639036821/post"); - - memcpy(sendBuffer + headerLen, "/t/g9mu2-1639036821/post", contentLen); - totalLen = headerLen + contentLen; - }*/ - - if (strcmp("GET", "GET") == 0) - { - contentLen = strlen("/t/g9mu2-1639036821/post"); - - memcpy(sendBuffer + headerLen, "/t/g9mu2-1639036821/post", contentLen); - totalLen = headerLen + contentLen; - } -#endif - - printf("send= \n%s\n", sendBuffer); - - if (send(sock, sendBuffer, totalLen, MSG_MORE) == -1) - printf("\nsend error(post notification) #2\n"); - else - printf("\nSuccess to send.\n"); - - closesocket(sock); - } -} - - -size_t SetHttpRequest_ptz(QueueInfo *q_info, char* sendBuffer, char* method) -{ - // Declare and initialize variables - SOCKET sock; - char* ip = NULL; - char HostName[MAX_MSG_LEN] = { 0 }; // an IP address or a hostname, like "www.google.com" by itself - char HostPort[10] = { 0 }; - unsigned char Authorization[2560] = { 0 }; - char Temp[MAX_MSG_LEN] = { 0 }; - size_t sendLen = 0; - - struct addrinfo* result = NULL, *tmp; - struct addrinfo* ptr = NULL; - struct addrinfo hints = { 0 }; - struct sockaddr_in* sockaddr_ipv4 = NULL; - - - - //hints.ai_flags = AI_NUMERICHOST; - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - - char curl_sendbuf[8192] = ""; - char curl_url[8192] = ""; - char host[256]; - - - //DWORD ret = getaddrinfo(HostName, "http", &hints, &result); - //DWORD ret = getaddrinfo(q_info->host_name, q_info->host_port, &hints, &result); - - printf("00\n"); - - DWORD ret = getaddrinfo("127.0.0.1", NULL, &hints, &result); - - printf("11\n"); - - if (ret != 0) { - printf("getaddrinfo failed with error: %d\n", ret); - return 1; - } - - //for (tmp = result; tmp != NULL; tmp = tmp->ai_next) { - // getnameinfo(tmp->ai_addr, tmp->ai_addrlen, host, sizeof(host), NULL, 0, NI_NUMERICHOST); - // puts(host); - //} - - freeaddrinfo(result); - - for (ptr = result; ptr != NULL; ptr = ptr->ai_next) - { - sock = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); - /*printf("\nsock: %d\n",sock); - printf("\nptr->ai_addrlen: %d\n",ptr->ai_addrlen);*/ - printf("22\n"); - - if (sock == -1) - continue; - - if (connect(sock, ptr->ai_addr, ptr->ai_addrlen) != -1) - { - printf("conn sock = %d \n", sock); - break; /* Success */ - } - - closesocket(sock); - } - printf("33\n"); - if (ptr == NULL) - { - // 迴圈已經執行到 list 的最後,都無法連線 - fprintf(stderr, "Failed to send POST to %s%s:%s\n", "http://", "127.0.0.1", "80"); - return 1; - } - - if (ptr->ai_family == AF_INET) - { - sockaddr_ipv4 = (struct sockaddr_in *) ptr->ai_addr; - ip = inet_ntoa(sockaddr_ipv4->sin_addr); - //printf("ip address=%s\n", ip); - } - freeaddrinfo(result); // 釋放 servinfo 記憶體空間 - - printf("44\n"); - - { - strcat(sendBuffer, method); - strcat(sendBuffer, " "); - - if (strcmp(q_info->post_protocol, "HTTP") == 0) - { - if (q_info->post_url[0] == '/') - { - //strcat(sendBuffer, q_info->post_url); - } - else - { - strcat(sendBuffer, "/"); - //strcat(sendBuffer, q_info->post_url); - } - } - //strcat(sendBuffer, q_info->post_url); - strcat(sendBuffer, "/server"); - - strcat(sendBuffer, " "); - strcat(sendBuffer, "HTTP/1.1"); - strcat(sendBuffer, "\r\n"); - int first_line_len = strlen(sendBuffer); - - strcat(sendBuffer, "Host: "); - strcat(sendBuffer, "127.0.0.1"); - //strcat(sendBuffer, q_info->host_name); - - //if (strlen(q_info->host_port) > 0) - //{ - // strcat(sendBuffer, ":"); - // strcat(sendBuffer, q_info->host_port); - //} - - strcat(sendBuffer, "\r\n"); - - strcat(sendBuffer, "Cache-Control: no-cache"); - strcat(sendBuffer, "\r\n"); - - strcat(sendBuffer, "User-Agent: IPVideo"); - strcat(sendBuffer, "\r\n"); - - strcat(sendBuffer, "Accept: */*"); - strcat(sendBuffer, "\r\n"); - - //strcat(sendBuffer, "Cookie: PHPSESSID=rqtd0uct26c5rnba0a4f6fsva1"); - //strcat(sendBuffer, "\r\n"); - - //strcat(sendBuffer, "Accept-Encoding: gzip, deflate"); - strcat(sendBuffer, "\r\n"); - - strcat(sendBuffer, "Content-Type: text/html; charset=utf-8"); - strcat(sendBuffer, "\r\n"); - - - - //size_t contentLen = strlen(q_info->content); - size_t contentLen = strlen("\server"); - - strcat(sendBuffer, "Content-Length: "); - sprintf(Temp, "%ld", contentLen); - strcat(sendBuffer, Temp); - strcat(sendBuffer, "\r\n"); - - strcat(sendBuffer, "Connection: Closed"); - strcat(sendBuffer, "\r\n"); - - //if (strlen(q_info->post_username) > 0) - if (strlen("admin") > 0) - { - strcat(sendBuffer, "Authorization: Basic "); - //strcpy(Authorization, q_info->post_username); - strcpy(Authorization, "admin"); - strcat(Authorization, ":"); - - //if (strlen(q_info->post_password) > 0) - if (strlen("Pass1234") > 0) - strcat(Authorization, "Pass1234"); - } - - - - size_t base64_encode_length = 0; - char httpAuth[2560] = { 0 }; - //char original_base64_output[8 * 8192] = { 0 }; - base64_encode((const unsigned char*)Authorization, strlen(Authorization), &base64_encode_length, httpAuth); - httpAuth[base64_encode_length] = '\0'; - //*(httpAuth + base64_encode_length-1) = '6'; - - strcat(sendBuffer, httpAuth); - strcat(sendBuffer, "\r\n"); - strcat(sendBuffer, "\r\n"); - - size_t headerLen = strlen(sendBuffer); - size_t totalLen = headerLen; - - if (strcmp(method, "POST") == 0) - { - contentLen = strlen(q_info->content); - - memcpy(sendBuffer + headerLen, q_info->content, contentLen); - totalLen = headerLen + contentLen; - } - - //printf("send= %s\n", sendBuffer); - - if (send(sock, sendBuffer, totalLen, MSG_MORE) == -1) - printf("\nsend error(post notification) #3\n"); - else - printf("\nSuccess to send.\n"); - - closesocket(sock); - } -#if 0 - - - - - - - //http first line - //if (featureType & FEATURE_LPR_TUR) - -#endif - - return 0; -} -#endif -#endif //#ifdef GY_OS_AMBA -size_t SetHttpResponse_server(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content) -{ - char tempStr[MAX_MSG_LEN] = { 0 }; - size_t sendLen = 0; - - switch (httpCode) - { - case _CODE_200: - strcpy(sendBuffer, "HTTP/1.1 200 OK"); - break; - case _CODE_204: - strcpy(sendBuffer, "HTTP/1.1 204 No Content"); - break; - case _CODE_400: - strcpy(sendBuffer, "HTTP/1.1 400 Bad Request"); - break; - case _CODE_401: - strcpy(sendBuffer, "HTTP/1.1 401 Unauthorized"); - break; - case _CODE_403: - strcpy(sendBuffer, "HTTP/1.1 403 Forbidden"); - break; - case _CODE_404: - strcpy(sendBuffer, "HTTP/1.1 404 Not Found"); - break; - } - //strcat(sendBuffer, tempStr); - strcat(sendBuffer, "\r\n"); - - //time_t now = time(0); - //struct tm tm = *gmtime(&now); - //memset(tempStr, 0x00, sizeof(tempStr)); - //strftime(tempStr, sizeof tempStr, "%a, %d %b %Y %H:%M:%S GMT", &tm); - //strcat(sendBuffer, "Date: "); - //strcat(sendBuffer, tempStr); - //strcat(sendBuffer, "\r\n"); - //memset(tempStr, 0x00, sizeof(tempStr)); - //snprintf(tempStr, sizeof(tempStr) - 1, "Server: GYNet/%s\r\n", APP_VERSION); - //strcat(sendBuffer, tempStr); - - strcat(sendBuffer, "Content-Type: "); - strcat(sendBuffer, contentType); - strcat(sendBuffer, ";charset=utf-8;"); - strcat(sendBuffer, "\r\n"); - memset(tempStr, 0x00, sizeof(tempStr)); - snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", (long int)contentLen); - strcat(sendBuffer, tempStr); - strcat(sendBuffer, "\r\n"); - strcat(sendBuffer, "Access-Control-Allow-Headers: content-type"); - strcat(sendBuffer, "\r\n"); - strcat(sendBuffer, "Access-Control-Allow-Methods: POST,GET"); - strcat(sendBuffer, "\r\n"); - strcat(sendBuffer, "Access-Control-Allow-Origin: *"); - strcat(sendBuffer, "\r\n"); - strcat(sendBuffer, "Access-Control-Allow-Credentials: true"); - strcat(sendBuffer, "\r\n"); - /* - if (httpCode == _CODE_200) - strcat(sendBuffer, "Connection: Keep-Alive\r\n"); - else - strcat(sendBuffer, "Connection: Closed\r\n");*/ - strcat(sendBuffer, "\r\n"); - - strcat(sendBuffer, content); - strcat(sendBuffer, "\r\n"); - strcat(sendBuffer, "\r\n"); - sendLen = strlen(sendBuffer); - - //char* content_utf8 = StringToUTF8(content); - //strcat(sendBuffer, content_utf8); - //sendLen += strlen(content_utf8); - //DumpHex(sendBuffer, sendLen); - - return sendLen; -} - -size_t SetHttpResponse(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content) -{ - char tempStr[MAX_MSG_LEN] = { 0 }; - size_t sendLen = 0; - - switch (httpCode) - { - case _CODE_200: - strcpy(sendBuffer, "HTTP/1.1 200 OK"); - break; - case _CODE_204: - strcpy(sendBuffer, "HTTP/1.1 204 No Content"); - break; - case _CODE_400: - strcpy(sendBuffer, "HTTP/1.1 400 Bad Request"); - break; - case _CODE_401: - strcpy(sendBuffer, "HTTP/1.1 401 Unauthorized"); - break; - case _CODE_403: - strcpy(sendBuffer, "HTTP/1.1 403 Forbidden"); - break; - case _CODE_404: - strcpy(sendBuffer, "HTTP/1.1 404 Not Found"); - break; - } - //strcat(sendBuffer, tempStr); - strcat(sendBuffer, "\r\n"); - - //time_t now = time(0); - //struct tm tm = *gmtime(&now); - //memset(tempStr, 0x00, sizeof(tempStr)); - //strftime(tempStr, sizeof tempStr, "%a, %d %b %Y %H:%M:%S GMT", &tm); - //strcat(sendBuffer, "Date: "); - //strcat(sendBuffer, tempStr); - //strcat(sendBuffer, "\r\n"); - //memset(tempStr, 0x00, sizeof(tempStr)); - //snprintf(tempStr, sizeof(tempStr) - 1, "Server: GYNet/%s\r\n", APP_VERSION); - //strcat(sendBuffer, tempStr); - /* - if (strncmp(contentType, "Multipart", strlen("Multipart")) != 0) - { - memset(tempStr, 0x00, sizeof(tempStr)); - snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %d", contentLen); - strcat(sendBuffer, tempStr); - strcat(sendBuffer, "\r\n"); - }*/ - strcat(sendBuffer, "Content-Type: "); - - if (strcmp(contentType, "text/html;") == 0) { - strcat(sendBuffer, contentType); - strcat(sendBuffer, "charset=utf-8;"); - } - else if (strcmp(contentType, "text/html") == 0) { - strcat(sendBuffer, contentType); - strcat(sendBuffer, ";charset=utf-8;"); - } - else { - strcat(sendBuffer, contentType); - strcat(sendBuffer, ";charset=utf-8;"); - } - - strcat(sendBuffer, "\r\n"); - memset(tempStr, 0x00, sizeof(tempStr)); - snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", (long int)contentLen); - strcat(sendBuffer, tempStr); - strcat(sendBuffer, "\r\n"); - strcat(sendBuffer, "Access-Control-Allow-Headers: content-type"); - strcat(sendBuffer, "\r\n"); - strcat(sendBuffer, "Access-Control-Allow-Methods: POST,GET"); - strcat(sendBuffer, "\r\n"); - strcat(sendBuffer, "Access-Control-Allow-Origin: *"); - strcat(sendBuffer, "\r\n"); - strcat(sendBuffer, "Access-Control-Allow-Credentials: true"); - strcat(sendBuffer, "\r\n"); - /* - if (httpCode == _CODE_200) - strcat(sendBuffer, "Connection: Keep-Alive\r\n"); - else - strcat(sendBuffer, "Connection: Closed\r\n");*/ - strcat(sendBuffer, "\r\n"); - - strcat(sendBuffer, content); - strcat(sendBuffer, "\r\n"); - strcat(sendBuffer, "\r\n"); - sendLen = strlen(sendBuffer); - - //char* content_utf8 = StringToUTF8(content); - //strcat(sendBuffer, content_utf8); - //sendLen += strlen(content_utf8); - //DumpHex(sendBuffer, sendLen); - - return sendLen; -} -//claire, response attachment -size_t SetHttpResponse_att(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content) -{ - char tempStr[MAX_MSG_LEN] = { 0 }; - size_t sendLen = 0; - - switch (httpCode) - { - case _CODE_200: - strcpy(tempStr, "HTTP/1.1 200 OK"); - break; - case _CODE_204: - strcpy(tempStr, "HTTP/1.1 204 No Content"); - break; - case _CODE_400: - strcpy(tempStr, "HTTP/1.1 400 Bad Request"); - break; - case _CODE_401: - strcpy(tempStr, "HTTP/1.1 401 Unauthorized"); - break; - case _CODE_403: - strcpy(tempStr, "HTTP/1.1 403 Forbidden"); - break; - case _CODE_404: - strcpy(tempStr, "HTTP/1.1 404 Not Found"); - break; - } - strcat(sendBuffer, tempStr); - strcat(sendBuffer, "\r\n"); - - time_t now = time(0); - struct tm tm = *gmtime(&now); - memset(tempStr, 0x00, sizeof(tempStr)); - strftime(tempStr, sizeof tempStr, "%a, %d %b %Y %H:%M:%S GMT", &tm); - strcat(sendBuffer, "Date: "); - strcat(sendBuffer, tempStr); - strcat(sendBuffer, "\r\n"); - memset(tempStr, 0x00, sizeof(tempStr)); - snprintf(tempStr, sizeof(tempStr) - 1, "Server: GYNet/%s\r\n", APP_VERSION); - strcat(sendBuffer, tempStr); - if (strncmp(contentType, "Multipart", strlen("Multipart")) != 0) - { - memset(tempStr, 0x00, sizeof(tempStr)); - snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", (long int)contentLen); - strcat(sendBuffer, tempStr); - strcat(sendBuffer, "\r\n"); - } - strcat(sendBuffer, "Content-Type: "); - strcat(sendBuffer, contentType); - //strcat(sendBuffer, "; charset=utf-8"); - strcat(sendBuffer, "\r\n"); - if (httpCode == _CODE_200) { - strcat(sendBuffer, "Connection: Keep-Alive\r\n"); - } - else { - strcat(sendBuffer, "Connection: Closed\r\n"); - } - strcat(sendBuffer, "\r\n"); - - strcat(sendBuffer, content); - strcat(sendBuffer, "\r\n"); - strcat(sendBuffer, "\r\n"); - sendLen = strlen(sendBuffer); - - //char* content_utf8 = StringToUTF8(content); - //strcat(sendBuffer, content_utf8); - //sendLen += strlen(content_utf8); - //DumpHex(sendBuffer, sendLen); - - return sendLen; -} -//20201028 sophia add -size_t SetHttpResponse_authHeader(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content) -{ - char tempStr[MAX_MSG_LEN] = { 0 }; - size_t sendLen = 0; - - switch (httpCode) - { - case _CODE_200: - strcpy(tempStr, "HTTP/1.1 200 OK"); - break; - case _CODE_204: - strcpy(tempStr, "HTTP/1.1 204 No Content"); - break; - case _CODE_400: - strcpy(tempStr, "HTTP/1.1 400 Bad Request"); - break; - case _CODE_401: - strcpy(tempStr, "HTTP/1.1 401 Unauthorized"); - break; - case _CODE_403: - strcpy(tempStr, "HTTP/1.1 403 Forbidden"); - break; - case _CODE_404: - strcpy(tempStr, "HTTP/1.1 404 Not Found"); - break; - } - strcat(sendBuffer, tempStr); - strcat(sendBuffer, "\r\n"); - - time_t now = time(0); - struct tm tm = *gmtime(&now); - memset(tempStr, 0x00, sizeof(tempStr)); - strftime(tempStr, sizeof tempStr, "%a, %d %b %Y %H:%M:%S GMT", &tm); - strcat(sendBuffer, "Date: "); - strcat(sendBuffer, tempStr); - strcat(sendBuffer, "\r\n"); - memset(tempStr, 0x00, sizeof(tempStr)); - snprintf(tempStr, sizeof(tempStr) - 1, "Server: GYNet/%s\r\n", APP_VERSION); - strcat(sendBuffer, tempStr); - strcat(sendBuffer, "WWW-Authenticate: Basic realm=\"IPVideo\""); - strcat(sendBuffer, "\r\n"); - if (strncmp(contentType, "Multipart", strlen("Multipart")) != 0) - { - memset(tempStr, 0x00, sizeof(tempStr)); - snprintf(tempStr, sizeof(tempStr) - 1, "Content-Length: %ld", (long int)contentLen); - strcat(sendBuffer, tempStr); - strcat(sendBuffer, "\r\n"); - } - strcat(sendBuffer, "Content-Type: "); - strcat(sendBuffer, contentType); - //strcat(sendBuffer, "; charset=utf-8"); - strcat(sendBuffer, "\r\n"); - if (httpCode == _CODE_200) - strcat(sendBuffer, "Connection: Keep-Alive\r\n"); - else - strcat(sendBuffer, "Connection: Closed\r\n"); - strcat(sendBuffer, "\r\n"); - - strcat(sendBuffer, content); - strcat(sendBuffer, "\r\n"); - strcat(sendBuffer, "\r\n"); - sendLen = strlen(sendBuffer); - - //char* content_utf8 = StringToUTF8(content); - //strcat(sendBuffer, content_utf8); - //sendLen += strlen(content_utf8); - //DumpHex(sendBuffer, sendLen); - #ifdef _DEBUG_AMBA - printf("\n[SetHttpResponse] sendBuffer:%s\n", sendBuffer); - #endif - return sendLen; -} - -//20201028 sophia add - -int run_connection_authorized = 0; -int is_connection_authorized(char* recvBuffer, SOCKET *client_socket, int isTcpTunnel) -{ - if (run_connection_authorized == 0) { - run_connection_authorized = 1; - //pthread_mutex_lock(&mutex_base64); - - SOCKET cli_socket = *client_socket; - - /* - printf("\n-----------------------\n"); - printf("\n%s\n",recvBuffer); - printf("\n-----------------------\n");*/ - - int check_if_data_loading_OK = 0; - - int is_authorized = 0; - if (is_authorized == 0) { - //char *is_localhost = strstr(recvBuffer, "127.0.0.1"); - //if (is_localhost == NULL) - { - //get id,pass - - char id[512] = { 0 }; - char pass[512] = { 0 }; - - //memset(id, 0x00, sizeof(id)); - //memset(pass, 0x00, sizeof(pass)); - -#ifdef _DEBUG_AMBA - printf("\n(%d) [is_connection_authorized] not localhost\n", cli_socket); - printf("\n(%d) [is_connection_authorized] recvBuffer: %s\n", cli_socket, recvBuffer); -#endif - - //is_authorized = 0; - - //check authorization process - char *start = strstr(recvBuffer, "Authorization: Basic "); - if (start != NULL) - { -#ifdef _DEBUG_AMBA - printf("\n(%d) [is_connection_authorized] Authorization: Basic here\n", cli_socket); -#endif - - start = start + strlen("Authorization: Basic "); - char *end = start; - int len = 0; - if (start) - { - while (*end != '\r' && *end != '\n' && *end != ' ' /*&& *end != '\r\n'*/) - { - len = len + 1; - end++; - } - - //decrypt id:pass - char EncryptIdPass[512]; - memset(EncryptIdPass, 0x00, sizeof(EncryptIdPass)); - strncpy(EncryptIdPass, start, len); - -#ifdef _DEBUG_AMBA - printf("\n(%d) [is_connection_authorized] EncryptIdPass:%s %d %d\n", cli_socket, EncryptIdPass, strlen(EncryptIdPass), len); -#endif - - size_t base64_decode_length = 0; - char DecryptData[512]; - memset(DecryptData, 0x00, sizeof(DecryptData)); - unsigned char OriEncryptData[1024] = { 0 }; - base64_decode(EncryptIdPass, strlen(EncryptIdPass), &base64_decode_length, OriEncryptData); - memcpy(DecryptData, OriEncryptData, base64_decode_length); - -#ifdef _DEBUG_AMBA - printf("\n(%d) [is_connection_authorized] ### OriEncryptData:%s DecryptData:%s\n", cli_socket, OriEncryptData, DecryptData); -#endif //_DEBUG_AMBA - - if (strlen(DecryptData) > 1) //more than ":" - { - //printf("\n--------------DecryptData:%s\n", DecryptData); - - char *delim = ":"; - char *pch = NULL; - char *pLeft = NULL; - pch = strtok_modified(DecryptData, delim, &pLeft); - if (pch != NULL) - { - char temp_cpy[100] = { 0 }; - sprintf(temp_cpy, "%s", pch); - char temp_account[512] = { 0 }; - urlencode((unsigned char *)temp_cpy, strlen(temp_cpy), (unsigned char *)temp_account, 512); - - sprintf(id, "%s", temp_account); - //printf("\n-------------id:%s\n",id); - pch = strtok_modified(NULL, delim, &pLeft); - if (pch != NULL) - { - char temp_cpy_2[100] = { 0 }; - sprintf(temp_cpy_2, "%s", pch); - char temp_account_2[512] = { 0 }; - urlencode((unsigned char *)temp_cpy_2, strlen(temp_cpy_2), (unsigned char *)temp_account_2, 512); - sprintf(pass, "%s", temp_account_2); - //printf("\n-------------pass:%s\n", pass); - } - } - -#if 0 - printf("\n(%d) [is_connection_authorized] ### id:%s pass:%s\n", cli_socket, id, pass); -#endif - - //comapre id,pass with accountData - - //{ - //int match = 0; - //int i = 0; - //while (!is_authorized && i < MAX_ACCOUNT_DATA_NUM /*&& strlen(id) >= 1 && strlen(pass) >= 1*/) - //{ - /* - if (strlen(accountData[i].account_username) >= 1 && strlen(accountData[i].account_password) >= 1) { - */ - // if (strcmp(id, accountData[i].account_username) == 0) - // { - // if (strcmp(pass, accountData[i].account_password) == 0) - // { - // is_authorized = 1; - // break; - // } - // } - //} - // i++; - //} - //} - } - } - } - - /* - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\nid: %s; pass: %s\n",id,pass); - for(int i = 0 ; i < 10 ; i++) - printf("\n(%d)username: %s; password: %s\n",i, accountData[i].account_username, accountData[i].account_password); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");*/ - - for (int i = 0; i < MAX_ACCOUNT_DATA_NUM; i++) { - if (strlen(accountData[i].account_username) == 0) { - continue; - } - - if (strlen(accountData[i].account_username) >= 1 && strlen(accountData[i].account_password) >= 1) { - check_if_data_loading_OK = 1; - } - - if (strcmp(id, accountData[i].account_username) == 0) - { - if (strcmp(pass, accountData[i].account_password) == 0) - { - is_authorized = 1; - break; - } - } - } - } - } - - /* - printf("\n-----------------------AABB\n"); - printf("\n%s\n", recvBuffer); - printf("\n-----------------------AABB\n"); - */ - - int iSockIdx = -1; - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - if (socketRecords[i].used == 1) { - if (socketRecords[i].sock == cli_socket) - { - iSockIdx = i; - break; - } - } - } - - - char *is_NVR_client = strstr(recvBuffer, "menu_on_nvr"); - if (is_NVR_client != NULL || (iSockIdx >= 0 && socketRecords[iSockIdx].isNvrRequest == 1)) - { - //printf("pppppppppppppppppppppppppppppppppppppppppppppppp find \n"); - - if(iSockIdx >= 0) - socketRecords[iSockIdx].isNvrRequest = 1; - - is_authorized = 1; - } - - if (is_authorized == 1 && (iSockIdx >= 0 && socketRecords[iSockIdx].isCredentialRequest == 1)) { - g_is_check_credential = 1; - } - else if (is_authorized == 0 && (iSockIdx >= 0 && socketRecords[iSockIdx].isCredentialRequest == 1)) { - g_is_check_credential = 0; - } - else if (g_is_check_credential == 1 || isTcpTunnel == TRUE) { - is_authorized = 1; - } - - //is_authorized = 1; - if (is_authorized == 0 && check_if_data_loading_OK == 1) - { - - //printf("\n---------------------------------------------\n"); - //printf("\n(%d) [is_connection_authorized] recvBuffer: %s\n", cli_socket, recvBuffer); - //printf("\n----------------------------------------------\n"); - - char msg[MAX_MSG_LEN]; - char sendBuffer[BUFSIZE_V2] = { 0 }; - char beforeSendBuffer[BUFSIZE_V2] = { 0 }; - char contentDescription[MAX_MSG_LEN] = { 0 }; - - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "Unauthorized."); - printf(msg); - //syslog(NW_SORRY, msg, recvBuffer, cli_socket); - strcpy(beforeSendBuffer, msg); - //strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse_authHeader(sendBuffer, _CODE_401, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #16\n"); - - pthread_t thread_id_getipcamsettings; - if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { - printf("\ngetipcamsettings thread creation failed####11\n"); - } - - //return; - }/* - else { - char msg[MAX_MSG_LEN]; - char sendBuffer[BUFSIZE] = { 0 }; - char beforeSendBuffer[BUFSIZE * 4] = { 0 }; - char contentDescription[MAX_MSG_LEN] = { 0 }; - - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "OK."); - printf(msg); - //syslog(NW_SORRY, msg, recvBuffer, cli_socket); - strcpy(beforeSendBuffer, msg); - //strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse_authHeader(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error\n"); - }*/ - - //pthread_mutex_unlock(&mutex_base64); - run_connection_authorized = 0; - return is_authorized; - } - else { - return 1; - } -} - -void update_config(char *recInfo) -{ - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - //printf("Program binary path is: %s\n", buf); - - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char configPATH[1024] = { 0 }; - char config_bakPATH[1024] = { 0 }; - - strcpy(configPATH, exePath); - strcpy(config_bakPATH, exePath); - - strcat(configPATH, "config.json"); - strcat(config_bakPATH, "config_bak.json"); - - //post events setting - //char filename[] = "config.json"; - char *filename = configPATH; - if (!FileExist(filename)) - printf("%s doesn't exist.\n", filename); - else { - //printf("read config.json.\n"); - - //size_t nfileSize = ReadFileSize(filename); - char* fileBuf = ReadAllBytes(filename); - - if (fileBuf) { - - cJSON* root, *about_box;//, * unlock_key, * sys_id; - cJSON *rec_json, *rec_key; - rec_json = cJSON_Parse(recInfo); - root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - - //static char* unlocking_key; - - if (root) - { - //printf("config.json parse OK.\n"); - about_box = cJSON_GetObjectItem(root, "about_box"); - //unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); - //if (unlock_key) - // printf("unlocking_key exists.\n"); - //else - // printf("unlocking_key is NULL.\n"); - - //printf("get sys id = %s \n", fetch_mac_addr); - //printf("get jsonfile key = %s \n", unlock_key->valuestring); - - //Get MAC Address - /*printf("\ng_match_mac: %d\n", g_match_mac); - printf("\ng_mac_address: %s\n", g_mac_address);*/ - - if (g_match_mac == 1) { - cJSON_ReplaceItemInObject(about_box, "system id", cJSON_CreateString(g_mac_address)); - } - else { - char fetch_mac_addr[64] = { 0 }; - memset(fetch_mac_addr, 0x00, sizeof(fetch_mac_addr)); - GetMACAddress(fetch_mac_addr); - //printf("mac addr = %s \n", fetch_mac_addr); - - char *find; - find = strchr(fetch_mac_addr, '\n'); - if (find) - *find = '\0'; - - cJSON_ReplaceItemInObject(about_box, "system id", cJSON_CreateString(fetch_mac_addr)); - } - - //sys_id = cJSON_GetObjectItem(about_box, "system id"); - //printf("show update sys id = %s \n", sys_id->valuestring); - //cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString("testkey123456")); - - rec_key = cJSON_GetObjectItem(rec_json, "unlocking_key"); - //printf("get input key = %s \n", rec_key->valuestring); - - -//#ifdef GY_OS_AMBA - //if (rec_key && strlen(rec_key->valuestring)>=1) -//#else - if (rec_key) -//#endif - { - - memset(strUnlockingKey, 0x00, sizeof(strUnlockingKey)); -//#ifdef GY_OS_AMBA - /*char temp_key[512] = { 0 }; - char formatted_mac[30] = { 0 }; - if (strstr(rec_key->valuestring, "face") != NULL) { - getContractSignature(temp_key, formatted_mac); - } - if (strstr(rec_key->valuestring, "face") != NULL) { - strcpy(strUnlockingKey, "face"); - strcat(strUnlockingKey, temp_key); - } - else *///{ - //strcpy(strUnlockingKey, rec_key->valuestring); - //} -//#else - if (strlen(rec_key->valuestring) >= 1) { - strcpy(strUnlockingKey, rec_key->valuestring); - } - else { - strcpy(strUnlockingKey,"auto"); - } -//#endif - - - cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString(strUnlockingKey)); - - { - char buf_exe[1024] = {}; - readlink("/proc/self/exe", buf_exe, sizeof(buf_exe)); - - char exePath_temp[1024] = {}; - getFilePath(buf_exe, exePath_temp, 1024); - - char keyPATH[1024] = { 0 }; - strcpy(keyPATH, exePath_temp); - strcat(keyPATH, "key.txt"); - if (FileExist(keyPATH) == 1) { - FILE *pFile; - - if ((pFile = fopen(keyPATH, "w")) != NULL) - { - fprintf(pFile, strUnlockingKey); - fclose(pFile); - - } - else - printf("Fail to open key.txt \n"); - } - } - } - - //printf("read key = %s \n", unlock_key->valuestring); - - char* JsonString = cJSON_Print(root); - - FILE *fp; - if ((fp = fopen(filename, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - CopyFileTo(configPATH, config_bakPATH); - } - else - { - printf("Fail to open Config.json \n"); - } - - if (rec_json) { - free(rec_json); - rec_json = NULL; - } - - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - if (root) { - cJSON_Delete(root); - root = NULL; - } - } - else - printf("config.json parse FAIL.\n"); - } - } -} - -void update_enable_only_show_metadata1(int temp_enable_only_show_metadata1) -{ - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - //printf("Program binary path is: %s\n", buf); - - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char configPATH[1024] = { 0 }; - char config_bakPATH[1024] = { 0 }; - - strcpy(configPATH, exePath); - strcpy(config_bakPATH, exePath); - - strcat(configPATH, "config.json"); - strcat(config_bakPATH, "config_bak.json"); - - char *filename = configPATH; - if (!FileExist(filename)) - printf("%s doesn't exist.\n", filename); - else { - //printf("read config.json.\n"); - - char* fileBuf = ReadAllBytes(filename); - - if (fileBuf) { - - cJSON* root, *view_setting,*camera01;//, * unlock_key, * sys_id; - root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - - if (root) - { - //printf("config.json parse OK.\n"); - view_setting = cJSON_GetObjectItem(root, "view_setting"); - camera01 = cJSON_GetObjectItem(view_setting, "camera01"); - - cJSON_ReplaceItemInObject(camera01, "enable_only_show_metadata1", cJSON_CreateNumber(temp_enable_only_show_metadata1)); - char* JsonString = cJSON_Print(root); - - FILE *fp; - if ((fp = fopen(filename, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - CopyFileTo(configPATH, config_bakPATH); - } - else - { - printf("Fail to open Config.json \n"); - } - - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - if (root) { - cJSON_Delete(root); - root = NULL; - } - } - else - printf("config.json parse FAIL.\n"); - } - } -} - -void replace_one_line_in_a_file(char *path,int line,char *newline) { - /* File pointer to hold reference of input file */ - FILE * fPtr; - FILE * fTemp; - - char buffer[BUFFER_SIZE] = { 0 }; - int count; - - /* Open all required files */ - fPtr = fopen(path, "r"); - fTemp = fopen("replace.tmp", "w+"); - - /* fopen() return NULL if unable to open file in given mode. */ - if (fPtr == NULL ) - { - /* Unable to open file hence exit */ - printf("\nUnable to open [fPtr] file.\n"); - printf("Please check whether file exists and you have read/write privilege.\n"); - exit(EXIT_SUCCESS); - } - if (fTemp == NULL) - { - /* Unable to open file hence exit */ - printf("\nUnable to open [fTemp] file.\n"); - printf("Please check whether file exists and you have read/write privilege.\n"); - exit(EXIT_SUCCESS); - } - /* - * Read line from source file and write to destination - * file after replacing given line. - */ - count = 0; - while ((fgets(buffer, BUFFER_SIZE, fPtr)) != NULL) - { - count++; - - /* If current line is line to replace */ - if (count == line) - fputs(newline, fTemp); - else - fputs(buffer, fTemp); - memset(buffer, 0x00, sizeof(buffer)); - } - - /* Close all files to release resource */ - fclose(fPtr); - fclose(fTemp); - - /* Delete original source file */ - remove(path); - - /* Rename temporary file as original file */ - rename("replace.tmp", path); - //printf("\nSuccessfully replaced '%d' line with '%s'.", line, newline); -} - -size_t get_control_io_from_ipcam(char * response_from_ipcam) { - //printf("\nname: %s\n", myname); - //printf("\nvalue: %s\n", myvalue); - //printf("\n-----get_control_io_from_ipcam start\n"); - pthread_mutex_lock(&mutex_curl); - //g_curl_handle_service_from_ipcam = curl_easy_init(); // Initialization for each handler. - - size_t response_size = 0; - - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - - //char cmd1[256] = "curl http://"; - char cmd1[256] = "http://"; - //char cmd2[256] = ":"; - char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" - char cmd4[256] = "/control?get=io"; - - //curl http://:d@192.168.3.57:81/event?event.event0000=1 - - strcpy(cmd, cmd1); - //strcat(cmd, accountData[0].account_username); - //strcat(cmd, cmd2); - //strcat(cmd, accountData[0].account_password); - strcat(cmd, cmd3); - strcat(cmd, accountData[0].account_port); - strcat(cmd, cmd4); - - //printf("\n[get service from ipcam]cmd: %s\n", cmd); - - if (g_http_handle) - { - struct MemoryStruct temp_msg; - struct MemoryStruct* ptr_responded_msg = &temp_msg; - ptr_responded_msg->size = 0; - - struct curl_slist *pList = NULL; - pList = curl_slist_append(pList, "Connection: close"); - pList = curl_slist_append(pList, "charset: utf-8"); - pList = curl_slist_append(pList, "Expect:"); - curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); - - curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(g_http_handle, CURLOPT_URL, cmd); - char buf_account[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); - curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, buf_account); - curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, buf_account2); - long port_num = atoi((const char*)accountData[0].account_port); - curl_easy_setopt(g_http_handle, CURLOPT_PORT, port_num); - - curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 1); // 設定連線超時,單位秒 - curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 3); - //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); - - curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); - curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); - - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); - - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L); -#ifdef GY_OS_NOVA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L); -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 1L); -#endif - curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); - - curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) - - curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). - - - CURLcode res_service_from_ipcam = curl_easy_perform(g_http_handle); - if (res_service_from_ipcam != CURLE_OK) // Check for errors - { - fprintf(stderr, "[get control io from ipcam] Failed to initialize the CURL handler for service from ipcam. #1 Reason: %s\n", curl_easy_strerror(res_service_from_ipcam)); - } - else { - strcpy(response_from_ipcam, ptr_responded_msg->memory); - response_size = ptr_responded_msg->size; - } - - ptr_responded_msg->size = 0; - /*if (ptr_responded_msg) { - free(ptr_responded_msg); - ptr_responded_msg = NULL; - }*/ - - curl_easy_reset(g_http_handle); - if (pList != NULL) - curl_slist_free_all(pList); - } - else - { - printf("[get control io from ipcam] CURL failed to initialize!\n"); - } - - //curl_easy_cleanup(g_curl_handle_service_from_ipcam); - //g_curl_handle_service_from_ipcam = NULL; - //printf("\n-----get_control_io_from_ipcam end\n"); - - pthread_mutex_unlock(&mutex_curl); - usSleep(20000); - return response_size; -} - -//CURL* g_curl_handle_service_from_ipcam = NULL; -size_t get_service_from_ipcam(char * response_from_ipcam) { - //printf("\nname: %s\n", myname); - //printf("\nvalue: %s\n", myvalue); - //printf("\n-----get_service_from_ipcam start\n"); - pthread_mutex_lock(&mutex_curl); - //g_curl_handle_service_from_ipcam = curl_easy_init(); // Initialization for each handler. - - if (g_http_handle != NULL) { - curl_easy_cleanup(g_http_handle); - curl_global_cleanup(); - curl_global_init(CURL_GLOBAL_SSL); - g_http_handle = NULL; - g_http_handle = curl_easy_init(); - } - - size_t response_size = 0; - - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - - //char cmd1[256] = "curl http://"; - char cmd1[256] = "http://"; - //char cmd2[256] = ":"; - char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" - char cmd4[256] = "/service?get=all"; - - //curl http://:d@192.168.3.57:81/event?event.event0000=1 - - strcpy(cmd, cmd1); - //strcat(cmd, accountData[0].account_username); - //strcat(cmd, cmd2); - //strcat(cmd, accountData[0].account_password); - strcat(cmd, cmd3); - strcat(cmd, accountData[0].account_port); - strcat(cmd, cmd4); - - //printf("\n[get service from ipcam]cmd: %s\n", cmd); - - if (g_http_handle) - { - struct MemoryStruct temp_msg; - struct MemoryStruct* ptr_responded_msg = &temp_msg; - ptr_responded_msg->size = 0; - - struct curl_slist *pList = NULL; - pList = curl_slist_append(pList, "Connection: close"); - pList = curl_slist_append(pList, "charset: utf-8"); - pList = curl_slist_append(pList, "Expect:"); - curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); - - curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(g_http_handle, CURLOPT_URL, cmd); - char buf_account[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); - curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, buf_account); - curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, buf_account2); - long port_num = atoi((const char*)accountData[0].account_port); - curl_easy_setopt(g_http_handle, CURLOPT_PORT, port_num); - - curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 1); // 設定連線超時,單位秒 - curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 3); - //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); - - curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); - curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); - - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); - - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L); -#ifdef GY_OS_NOVA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L); -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 5L); -#endif - curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); - - curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) - - curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). - - - CURLcode res_service_from_ipcam = curl_easy_perform(g_http_handle); - if (res_service_from_ipcam != CURLE_OK) // Check for errors - { - fprintf(stderr, "[get service from ipcam] Failed to initialize the CURL handler for service from ipcam. #1 Reason: %s\n", curl_easy_strerror(res_service_from_ipcam)); - } - else { - strcpy(response_from_ipcam, ptr_responded_msg->memory); - response_size = ptr_responded_msg->size; - } - - ptr_responded_msg->size = 0; - /*if (ptr_responded_msg) { - free(ptr_responded_msg); - ptr_responded_msg = NULL; - }*/ - - curl_easy_reset(g_http_handle); - if (pList != NULL) - curl_slist_free_all(pList); - } - else - { - printf("[get service from ipcam] CURL failed to initialize!\n"); - } - - //curl_easy_cleanup(g_curl_handle_service_from_ipcam); - //g_curl_handle_service_from_ipcam = NULL; - //printf("\n-----get_service_from_ipcam end\n"); - - pthread_mutex_unlock(&mutex_curl); - usSleep(20000); - return response_size; -} - -CURL* g_curl_handle_set_gpio = NULL; -void build_one_gpio(char * myname, char * myvalue) { - //printf("\nname: %s\n", myname); - //printf("\nvalue: %s\n", myvalue); - - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - - //char cmd1[256] = "curl http://"; - char cmd1[256] = "http://"; - //char cmd2[256] = ":"; - char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" - char cmd4[256] = "/service?post."; - char cmd5[256] = "="; - - //curl http://:d@192.168.3.57:81/event?event.event0000=1 - - strcpy(cmd, cmd1); - //strcat(cmd, accountData[0].account_username); - //strcat(cmd, cmd2); - //strcat(cmd, accountData[0].account_password); - strcat(cmd, cmd3); - strcat(cmd, accountData[0].account_port); - strcat(cmd, cmd4); - strcat(cmd, myname); - strcat(cmd, cmd5); - strcat(cmd, myvalue); - - - //printf("\n[setsmartevent]cmd: %s\n", cmd); - -# if 0 - FILE* pPipe; - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); -#else - - if (g_curl_handle_set_gpio) - { - struct curl_slist *pList = NULL; - pList = curl_slist_append(pList, "Connection: close"); - pList = curl_slist_append(pList, "charset: utf-8"); - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_HTTPHEADER, pList); - - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_URL, cmd); - char buf_account[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_USERNAME, buf_account); - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_PASSWORD, buf_account2); - long port_num = atoi((const char*)accountData[0].account_port); - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_PORT, port_num); - -#ifdef GY_OS_NOVA - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_CONNECTTIMEOUT, 3); // 設定連線超時,單位秒 - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_TIMEOUT, 5); -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_CONNECTTIMEOUT, 1); // 設定連線超時,單位秒 - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_TIMEOUT, 3); -#endif - - //curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_ACCEPT_ENCODING, "gzip"); - - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_USERAGENT, "IPVideo"); - - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_LOW_SPEED_LIMIT, 1L); - - -#ifdef GY_OS_NOVA - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_LOW_SPEED_TIME, 3L); -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_LOW_SPEED_TIME, 1L); -#endif - - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_TCP_FASTOPEN, 1L); - - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). - - curl_easy_setopt(g_curl_handle_set_gpio, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) - - CURLcode res_smart_event = curl_easy_perform(g_curl_handle_set_gpio); - if (res_smart_event != CURLE_OK) // Check for errors - { - fprintf(stderr, "[build one gpio] Failed to initialize the CURL handler for gpio. Reason: %s\n", curl_easy_strerror(res_smart_event)); - } - - curl_easy_reset(g_curl_handle_set_gpio); - if (pList != NULL) - curl_slist_free_all(pList); - } - else - { - printf("[build one gpio] CURL failed to initialize!\n"); - } - - usSleep(20000); -#endif -} - -CURL* g_curl_handle_set_smart_event = NULL; -void build_one_smart_event(char * myname,char * myvalue) { - //printf("\nname: %s\n", myname); - //printf("\nvalue: %s\n", myvalue); - - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - - //char cmd1[256] = "curl http://"; - char cmd1[256] = "http://"; - //char cmd2[256] = ":"; - char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" - char cmd4[256] = "/event?event."; - char cmd5[256] = "="; - - //curl http://:d@192.168.3.57:81/event?event.event0000=1 - - strcpy(cmd, cmd1); - //strcat(cmd, accountData[0].account_username); - //strcat(cmd, cmd2); - //strcat(cmd, accountData[0].account_password); - strcat(cmd, cmd3); - strcat(cmd, accountData[0].account_port); - strcat(cmd, cmd4); - strcat(cmd, myname); - strcat(cmd, cmd5); - strcat(cmd, myvalue); - - - //printf("\n[setsmartevent]cmd: %s\n", cmd); - -# if 0 - FILE* pPipe; - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); -#else - - if (g_curl_handle_set_smart_event) - { - struct curl_slist *pList = NULL; - pList = curl_slist_append(pList, "Connection: close"); - pList = curl_slist_append(pList, "charset: utf-8"); - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_HTTPHEADER, pList); - - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_URL, cmd); - char buf_account[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_USERNAME, buf_account); - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_PASSWORD, buf_account2); - long port_num = atoi((const char*)accountData[0].account_port); - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_PORT, port_num); - -#ifdef GY_OS_NOVA - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_CONNECTTIMEOUT, 3); // 設定連線超時,單位秒 - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_TIMEOUT, 5); -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_CONNECTTIMEOUT, 1); // 設定連線超時,單位秒 - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_TIMEOUT, 3); -#endif - - //curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_ACCEPT_ENCODING, "gzip"); - - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_USERAGENT, "IPVideo"); - - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_LOW_SPEED_LIMIT, 1L); - - -#ifdef GY_OS_NOVA - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_LOW_SPEED_TIME, 3L); -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_LOW_SPEED_TIME, 1L); -#endif - - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_TCP_FASTOPEN, 1L); - - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). - - curl_easy_setopt(g_curl_handle_set_smart_event, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) - - CURLcode res_smart_event = curl_easy_perform(g_curl_handle_set_smart_event); - if (res_smart_event != CURLE_OK) // Check for errors - { - fprintf(stderr, "[build one smart event] Failed to initialize the CURL handler for smart event. Reason: %s\n", curl_easy_strerror(res_smart_event)); - } - - curl_easy_reset(g_curl_handle_set_smart_event); - if (pList != NULL) - curl_slist_free_all(pList); - } - else - { - printf("[build one smart event] CURL failed to initialize!\n"); - } - - usSleep(20000); -#endif -} - -void* auto_build_smart_events(void * ptr) { - pthread_detach(pthread_self()); - setPthreadName("smart_event"); - pthread_mutex_lock(&mutex_curl); - - if (g_http_handle != NULL) { - curl_easy_cleanup(g_http_handle); - curl_global_cleanup(); - curl_global_init(CURL_GLOBAL_SSL); - g_http_handle = NULL; - g_http_handle = curl_easy_init(); - } - - g_curl_handle_set_smart_event = g_http_handle; // Initialization for each handler. - - build_one_smart_event("event0000", "1"); - build_one_smart_event("name0000", "Aida%20Event%201"); -#ifdef GY_OS_AMBA - build_one_smart_event("c_name00000000", "Open%20Alarm%20And%20Close%20Virtual%201"); -#else - build_one_smart_event("c_name00000000", "Close%20Virtual%201"); -#endif - - build_one_smart_event("c_time00000000", "1,5000,0,0,1"); - build_one_smart_event("c_trigger00000000", "virtual_in/0/0/0/1/1"); - build_one_smart_event("c_schedule00000000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); - -#ifdef GY_OS_AMBA - build_one_smart_event("c_action00000000", "do/0/1000/active/0/0/0,virtual_in/0/0/inactive/0/0/0,"); -#else - build_one_smart_event("c_action00000000", "virtual_in/0/0/inactive/0/0/0,"); -#endif - - build_one_smart_event("event0001", "1"); - build_one_smart_event("name0001", "Aida%20Event%202%20%2F%20SD%20Recording"); - build_one_smart_event("c_name00010000", "Close%20Virtual%202%20And%20Start%20Recording"); - build_one_smart_event("c_time00010000", "1,5000,0,0,1"); - build_one_smart_event("c_trigger00010000", "virtual_in/1/0/0/1/1"); - build_one_smart_event("c_schedule00010000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); - build_one_smart_event("c_action00010000", "sd/0/60000/active/0/0/0,virtual_in/1/0/inactive/0/0/0,"); - -#ifdef GY_OS_NOVA - if (g_camera_white_LED == 1) { - build_one_smart_event("event0002", "1"); - build_one_smart_event("name0002", "Aida%20Event%203%20%2F%20White%20LED"); - build_one_smart_event("c_name00020000", "Close%20Virtual%203%20And%20Start%20LED"); - build_one_smart_event("c_time00020000", "1,5000,0,0,1"); - build_one_smart_event("c_trigger00020000", "virtual_in/2/0/0/1/1"); - build_one_smart_event("c_schedule00020000", "0,7/0/21600,7/64800/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); - build_one_smart_event("c_action00020000", "ir_led/1/60000/active/0/0/0,virtual_in/2/0/inactive/0/0/0,"); - } -#endif - - -#ifdef GY_OS_AMBA - build_one_smart_event("event0002", "1"); - build_one_smart_event("name0002", "Aida%20Event%203"); - build_one_smart_event("c_name00020000", "Open%20Alarm%20And%20Close%20Virtual%203"); - build_one_smart_event("c_time00020000", "1,5000,0,0,1"); - build_one_smart_event("c_trigger00020000", "virtual_in/2/0/0/1/1"); - build_one_smart_event("c_schedule00020000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); - build_one_smart_event("c_action00020000", "do/0/1000/active/0/0/0,virtual_in/2/0/inactive/0/0/0,"); - - build_one_smart_event("event0003", "1"); - build_one_smart_event("name0003", "Aida%20Event%204"); - build_one_smart_event("c_name00030000", "Open%20Alarm%20And%20Close%20Virtual%204"); - build_one_smart_event("c_time00030000", "1,5000,0,0,1"); - build_one_smart_event("c_trigger00030000", "virtual_in/3/0/0/1/1"); - build_one_smart_event("c_schedule00030000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); - build_one_smart_event("c_action00030000", "do/0/1000/active/0/0/0,virtual_in/3/0/inactive/0/0/0,"); -#endif - - if (g_IsPTZDevice == 0 && g_dual_sensor == 0) { -#ifdef GY_OS_V_SERIES - -#else - if (g_http_handle != NULL) { - curl_easy_cleanup(g_http_handle); - curl_global_cleanup(); - curl_global_init(CURL_GLOBAL_SSL); - g_http_handle = NULL; - g_http_handle = curl_easy_init(); - } - - g_curl_handle_set_smart_event = g_http_handle; - - build_one_smart_event("event0004", "1"); - build_one_smart_event("name0004", "LPR%20Digital%20Trigger%201"); - build_one_smart_event("c_name00040000", "Open%20HTTP%20Post%20Service%201"); - build_one_smart_event("c_time00040000", "1,10500,0,0,1"); - build_one_smart_event("c_trigger00040000", "digital_in/0/0/8/1/0"); - build_one_smart_event("c_schedule00040000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); - build_one_smart_event("c_action00040000", "post/0/0/active/0/0/0"); -#endif - - curl_easy_reset(g_curl_handle_set_smart_event); - -#ifdef GY_OS_V_SERIES - -#else - g_curl_handle_set_gpio = g_http_handle; - - build_one_gpio("name0", "Digital_Trigger_Post"); - build_one_gpio("server0", "localhost"); - build_one_gpio("server_port0", accountData[0].account_aida_port); - build_one_gpio("account0", accountData[0].account_username); - build_one_gpio("password0", accountData[0].account_password); - build_one_gpio("url0", "/control?alarm.gpio=1"); - build_one_gpio("content0", "lilinstarthttpget"); - - curl_easy_reset(g_curl_handle_set_gpio); -#endif - } - - pthread_mutex_unlock(&mutex_curl); - - pthread_exit(NULL); - -} - -void* auto_build_smart_events_di_vi(void * ptr) { - pthread_detach(pthread_self()); - setPthreadName("smart_di_vi"); - if (g_IsPTZDevice == 0 && g_dual_sensor == 0) { -#ifdef GY_OS_V_SERIES - -#else - pthread_mutex_lock(&mutex_curl); - - if (g_http_handle != NULL) { - curl_easy_cleanup(g_http_handle); - curl_global_cleanup(); - curl_global_init(CURL_GLOBAL_SSL); - g_http_handle = NULL; - g_http_handle = curl_easy_init(); - } - - g_curl_handle_set_smart_event = g_http_handle; // Initialization for each handler. - - build_one_smart_event("event0004", "1"); - build_one_smart_event("name0004", "LPR%20Digital%20Trigger%201"); - build_one_smart_event("c_name00040000", "Open%20HTTP%20Post%20Service%201"); - build_one_smart_event("c_time00040000", "1,10500,0,0,1"); - build_one_smart_event("c_trigger00040000", "digital_in/0/0/8/1/0"); - build_one_smart_event("c_schedule00040000", "0,7/0/86400,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,-1/0/0,"); - build_one_smart_event("c_action00040000", "post/0/0/active/0/0/0"); - - curl_easy_reset(g_curl_handle_set_smart_event); - - g_curl_handle_set_gpio = g_http_handle; - - build_one_gpio("name0", "Digital_Trigger_Post"); - build_one_gpio("server0", "localhost"); - build_one_gpio("server_port0", accountData[0].account_aida_port); - build_one_gpio("account0", accountData[0].account_username); - build_one_gpio("password0", accountData[0].account_password); - build_one_gpio("url0", "/control?alarm.gpio=1"); - build_one_gpio("content0", "lilinstarthttpget"); - - curl_easy_reset(g_curl_handle_set_gpio); - pthread_mutex_unlock(&mutex_curl); -#endif - } - pthread_exit(NULL); -} - -CURL* g_curl_handle_set_tof_basic = NULL; -void build_one_set_for_tof_basic(char * myname, char * myvalue) { - //printf("\nname: %s\n", myname); - //printf("\nvalue: %s\n", myvalue); - - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - - //char cmd1[256] = "curl http://"; - char cmd1[256] = "http://"; - //char cmd2[256] = ":"; - char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" - char cmd4[256] = "/tof?image."; - char cmd5[256] = "="; - - //curl http://:d@192.168.3.57:81/event?event.event0000=1 - - strcpy(cmd, cmd1); - //strcat(cmd, accountData[0].account_username); - //strcat(cmd, cmd2); - //strcat(cmd, accountData[0].account_password); - strcat(cmd, cmd3); - strcat(cmd, accountData[0].account_port); - strcat(cmd, cmd4); - strcat(cmd, myname); - strcat(cmd, cmd5); - strcat(cmd, myvalue); - - - //printf("\n[setsmartevent]cmd: %s\n", cmd); - -# if 0 - FILE* pPipe; - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); -#else - - if (g_curl_handle_set_tof_basic) - { - struct curl_slist *pList = NULL; - pList = curl_slist_append(pList, "Connection: close"); - pList = curl_slist_append(pList, "charset: utf-8"); - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_HTTPHEADER, pList); - - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_URL, cmd); - char buf_account[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_USERNAME, buf_account); - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_PASSWORD, buf_account2); - long port_num = atoi((const char*)accountData[0].account_port); - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_PORT, port_num); - - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_CONNECTTIMEOUT, 1); // 設定連線超時,單位秒 - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_TIMEOUT, 3); - //curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_ACCEPT_ENCODING, "gzip"); - - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_USERAGENT, "IPVideo"); - - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_LOW_SPEED_LIMIT, 1L); - - -#ifdef GY_OS_NOVA - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_LOW_SPEED_TIME, 3L); -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_LOW_SPEED_TIME, 1L); -#endif - - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_TCP_FASTOPEN, 1L); - - curl_easy_setopt(g_curl_handle_set_tof_basic, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) - - CURLcode res_quality_basic = curl_easy_perform(g_curl_handle_set_tof_basic); - if (res_quality_basic != CURLE_OK) // Check for errors - { - fprintf(stderr, "[build one set for quality basic] Failed to initialize the CURL handler for quality basic. Reason: %s\n", curl_easy_strerror(res_quality_basic)); - } - - curl_easy_reset(g_curl_handle_set_tof_basic); - if (pList != NULL) - curl_slist_free_all(pList); - } - else - { - printf("[build one set for quality basic] CURL failed to initialize!\n"); - } - - usSleep(20000); -#endif -} - -void* auto_set_tof_basic(void * ptr) { - pthread_detach(pthread_self()); - setPthreadName("tof_basic"); - pthread_mutex_lock(&mutex_curl); - g_curl_handle_set_tof_basic = g_http_handle; // Initialization for each handler. - - build_one_set_for_tof_basic("mode", "1"); - - curl_easy_reset(g_curl_handle_set_tof_basic); - //g_curl_handle_set_tof_basic = NULL; - pthread_mutex_unlock(&mutex_curl); - pthread_exit(NULL); -} - -CURL* g_curl_handle_set_quality_basic = NULL; -void build_one_set_for_quality_basic(char * myname, char * myvalue) { - //printf("\nname: %s\n", myname); - //printf("\nvalue: %s\n", myvalue); - - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - - //char cmd1[256] = "curl http://"; - char cmd1[256] = "http://"; - //char cmd2[256] = ":"; - char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" - char cmd4[256] = "/image?image."; - char cmd5[256] = "="; - - //curl http://:d@192.168.3.57:81/event?event.event0000=1 - - strcpy(cmd, cmd1); - //strcat(cmd, accountData[0].account_username); - //strcat(cmd, cmd2); - //strcat(cmd, accountData[0].account_password); - strcat(cmd, cmd3); - strcat(cmd, accountData[0].account_port); - strcat(cmd, cmd4); - strcat(cmd, myname); - strcat(cmd, cmd5); - strcat(cmd, myvalue); - - - //printf("\n[setsmartevent]cmd: %s\n", cmd); - -# if 0 - FILE* pPipe; - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); -#else - - if (g_curl_handle_set_quality_basic) - { - struct curl_slist *pList = NULL; - pList = curl_slist_append(pList, "Connection: close"); - pList = curl_slist_append(pList, "charset: utf-8"); - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_HTTPHEADER, pList); - - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_URL, cmd); - char buf_account[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_USERNAME, buf_account); - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_PASSWORD, buf_account2); - long port_num = atoi((const char*)accountData[0].account_port); - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_PORT, port_num); - - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_CONNECTTIMEOUT, 1); // 設定連線超時,單位秒 - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_TIMEOUT, 3); - //curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_ACCEPT_ENCODING, "gzip"); - - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_USERAGENT, "IPVideo"); - - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_LOW_SPEED_LIMIT, 1L); - - -#ifdef GY_OS_NOVA - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_LOW_SPEED_TIME, 3L); -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_LOW_SPEED_TIME, 1L); -#endif - - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_TCP_FASTOPEN, 1L); - - curl_easy_setopt(g_curl_handle_set_quality_basic, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) - - CURLcode res_quality_basic = curl_easy_perform(g_curl_handle_set_quality_basic); - if (res_quality_basic != CURLE_OK) // Check for errors - { - fprintf(stderr, "[build one set for quality basic] Failed to initialize the CURL handler for quality basic. Reason: %s\n", curl_easy_strerror(res_quality_basic)); - } - else { - if (strcmp(myname, "flip") == 0) { - strcpy(accountData[0].account_flip, myvalue); - } - else if (strcmp(myname, "mirror") == 0) { - strcpy(accountData[0].account_mirror, myvalue); - } - else if (strcmp(myname, "rotate") == 0) { - strcpy(accountData[0].account_rotate, myvalue); - } - } - - curl_easy_reset(g_curl_handle_set_quality_basic); - if (pList != NULL) - curl_slist_free_all(pList); - } - else - { - printf("[build one set for quality basic] CURL failed to initialize!\n"); - } - - usSleep(20000); -#endif -} - -void* auto_set_quality_basic(void * ptr) { - pthread_detach(pthread_self()); - setPthreadName("set_qual"); - pthread_mutex_lock(&mutex_curl); - g_curl_handle_set_quality_basic = g_http_handle; // Initialization for each handler. - - build_one_set_for_quality_basic("3dnrday", "0"); - build_one_set_for_quality_basic("3dnrnight", "0"); - build_one_set_for_quality_basic("sharpnessday", "0"); - build_one_set_for_quality_basic("sharpnessnight", "0"); - - curl_easy_reset(g_curl_handle_set_quality_basic); - //g_curl_handle_set_quality_basic = NULL; - pthread_mutex_unlock(&mutex_curl); - pthread_exit(NULL); - -} - -void sync_image_rotation_thread() { - //pthread_detach(pthread_self()); - pthread_mutex_lock(&mutex_curl); - g_curl_handle_set_quality_basic = g_http_handle; - - if (strcmp(accountData[0].account_flip, "1") == 0){ - build_one_set_for_quality_basic("flip", "0"); - usSleep(50000); - } - - if (strcmp(accountData[0].account_mirror, "1") == 0){ - build_one_set_for_quality_basic("mirror", "0"); - usSleep(50000); - } - - if (strcmp(accountData[0].account_rotate, "1") == 0){ - build_one_set_for_quality_basic("rotate", "0"); - usSleep(50000); - } - - curl_easy_reset(g_curl_handle_set_quality_basic); - //g_curl_handle_set_quality_basic = NULL; - pthread_mutex_unlock(&mutex_curl); - //pthread_exit(NULL); -} - -//CURL* g_curl_handle_system_time = NULL; -size_t get_system_time_from_ipcam(char * response_from_ipcam) { - //printf("\nname: %s\n", myname); - //printf("\nvalue: %s\n", myvalue); - pthread_mutex_lock(&mutex_curl); - //printf("\n-----get_system_time_from_ipcam start\n"); - //g_curl_handle_system_time = curl_easy_init(); // Initialization for each handler. - - if (g_http_handle != NULL) { - curl_easy_cleanup(g_http_handle); - curl_global_cleanup(); - curl_global_init(CURL_GLOBAL_SSL); - g_http_handle = NULL; - g_http_handle = curl_easy_init(); - } - - size_t response_size = 0; - - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - - //char cmd1[256] = "curl http://"; - char cmd1[256] = "http://"; - //char cmd2[256] = ":"; - char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" - char cmd4[256] = "/system?get=server"; - - //curl http://:d@192.168.3.57:81/event?event.event0000=1 - - strcpy(cmd, cmd1); - //strcat(cmd, accountData[0].account_username); - //strcat(cmd, cmd2); - //strcat(cmd, accountData[0].account_password); - strcat(cmd, cmd3); - strcat(cmd, accountData[0].account_port); - strcat(cmd, cmd4); - - //printf("\n[get service from ipcam]cmd: %s\n", cmd); - - if (g_http_handle) - { - struct MemoryStruct temp_msg; - struct MemoryStruct* ptr_responded_msg = &temp_msg; - ptr_responded_msg->size = 0; - - struct curl_slist *pList = NULL; - pList = curl_slist_append(pList, "Connection: close"); - pList = curl_slist_append(pList, "charset: utf-8"); - pList = curl_slist_append(pList, "Expect:"); - curl_easy_setopt(g_http_handle, CURLOPT_HTTPHEADER, pList); - - curl_easy_setopt(g_http_handle, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(g_http_handle, CURLOPT_URL, cmd); - char buf_account[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); - curl_easy_setopt(g_http_handle, CURLOPT_USERNAME, buf_account); - curl_easy_setopt(g_http_handle, CURLOPT_PASSWORD, buf_account2); - long port_num = atoi((const char*)accountData[0].account_port); - curl_easy_setopt(g_http_handle, CURLOPT_PORT, port_num); - - curl_easy_setopt(g_http_handle, CURLOPT_CONNECTTIMEOUT, 1); // 設定連線超時,單位秒 - curl_easy_setopt(g_http_handle, CURLOPT_TIMEOUT, 3); - //curl_easy_setopt(g_http_handle, CURLOPT_ACCEPT_ENCODING, "gzip"); - - curl_easy_setopt(g_http_handle, CURLOPT_WRITEFUNCTION, WriteResponseString); - curl_easy_setopt(g_http_handle, CURLOPT_WRITEDATA, ptr_responded_msg); - - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_http_handle, CURLOPT_USERAGENT, "IPVideo"); - - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_LIMIT, 1L); -#ifdef GY_OS_NOVA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 3L); -#endif - -#ifdef GY_OS_AMBA - curl_easy_setopt(g_http_handle, CURLOPT_LOW_SPEED_TIME, 1L); -#endif - curl_easy_setopt(g_http_handle, CURLOPT_TCP_FASTOPEN, 1L); - - curl_easy_setopt(g_http_handle, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) - - curl_easy_setopt(g_http_handle, CURLOPT_FORBID_REUSE, 0L); //Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior). - - CURLcode res_service_from_ipcam = curl_easy_perform(g_http_handle); - if (res_service_from_ipcam != CURLE_OK) // Check for errors - { - fprintf(stderr, "[get service from ipcam] Failed to initialize the CURL handler for service from ipcam. #2 Reason: %s\n", curl_easy_strerror(res_service_from_ipcam)); - } - else { - strcpy(response_from_ipcam, ptr_responded_msg->memory); - response_size = ptr_responded_msg->size; - } - - ptr_responded_msg->size = 0; - /*if (ptr_responded_msg) { - free(ptr_responded_msg); - ptr_responded_msg = NULL; - }*/ - - curl_easy_reset(g_http_handle); - if (pList != NULL) - curl_slist_free_all(pList); - } - else - { - printf("[get service from ipcam] CURL failed to initialize!\n"); - } - - //curl_easy_cleanup(g_curl_handle_system_time); - //g_curl_handle_system_time = NULL; - //printf("\n-----get_system_time_from_ipcam end\n"); - pthread_mutex_unlock(&mutex_curl); - usSleep(20000); - return response_size; -} - -CURL* g_curl_handle_resolution_changed = NULL; -size_t build_resolution_changed(char * response_from_ipcam) { - //printf("\nname: %s\n", myname); - //printf("\nvalue: %s\n", myvalue); - - size_t response_size = 0; - - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - - //char cmd1[256] = "curl http://"; - char cmd1[256] = "http://"; - //char cmd2[256] = ":"; - char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" - char cmd4[256] = "/get_sencode_info"; - //char cmd5[256] = "="; - - //curl http://:d@192.168.3.57:81/event?event.event0000=1 - - strcpy(cmd, cmd1); - //strcat(cmd, accountData[0].account_username); - //strcat(cmd, cmd2); - //strcat(cmd, accountData[0].account_password); - strcat(cmd, cmd3); - strcat(cmd, accountData[0].account_port); - strcat(cmd, cmd4); - //strcat(cmd, myname); - //strcat(cmd, cmd5); - //strcat(cmd, myvalue); - - - //printf("\n[setsmartevent]cmd: %s\n", cmd); - -# if 0 - FILE* pPipe; - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); -#else - - if (g_curl_handle_resolution_changed) - { - struct MemoryStruct temp_msg; - struct MemoryStruct* ptr_responded_msg = &temp_msg; - ptr_responded_msg->size = 0; - - struct curl_slist *pList = NULL; - pList = curl_slist_append(pList, "Connection: close"); - pList = curl_slist_append(pList, "charset: utf-8"); - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_HTTPHEADER, pList); - - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_URL, cmd); - char buf_account[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_USERNAME, buf_account); - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_PASSWORD, buf_account2); - long port_num = atoi((const char*)accountData[0].account_port); - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_PORT, port_num); - - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_CONNECTTIMEOUT, 1); // 設定連線超時,單位秒 - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_TIMEOUT, 3); - //curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_ACCEPT_ENCODING, "gzip"); - - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_WRITEFUNCTION, WriteResponseString); - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_WRITEDATA, ptr_responded_msg); - - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_USERAGENT, "IPVideo"); - - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_LOW_SPEED_LIMIT, 1L); - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_LOW_SPEED_TIME, 1L); - - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_TCP_FASTOPEN, 1L); - - curl_easy_setopt(g_curl_handle_resolution_changed, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) - - CURLcode res_quality_basic = curl_easy_perform(g_curl_handle_resolution_changed); - if (res_quality_basic != CURLE_OK) // Check for errors - { - fprintf(stderr, "[build resolution changed] Failed to initialize the CURL handler for quality basic. Reason: %s\n", curl_easy_strerror(res_quality_basic)); - } - else { - strcpy(response_from_ipcam, ptr_responded_msg->memory); - response_size = ptr_responded_msg->size; - } - - ptr_responded_msg->size = 0; - /*if (ptr_responded_msg) { - free(ptr_responded_msg); - ptr_responded_msg = NULL; - }*/ - - curl_easy_reset(g_curl_handle_resolution_changed); - if (pList != NULL) - curl_slist_free_all(pList); - } - else - { - printf("[build resolution changed] CURL failed to initialize!\n"); - } - - usSleep(20000); -#endif - - return response_size; -} - -int g_check_if_different_width_or_height = 0; -void write_to_stream_width_and_stream_height(int stream_width,int stream_height) { - - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - - char exePath[1024] = {}; - //printf("exePath:%s\n", exePath); - getFilePath(buf, exePath, 1024); - //printf("exePath:%s\n", exePath); - - char streamPATH[1024] = { 0 }; - strcpy(streamPATH, exePath); - strcat(streamPATH, "stream.json"); - - char stream_bakPATH[1024] = { 0 }; - strcpy(stream_bakPATH, exePath); - strcat(stream_bakPATH, "stream_bak.json"); - - char *filename_stream = streamPATH; - if (!FileExist(filename_stream) && !FileExist(stream_bakPATH)) - { - //printf("%s doesn't exist.\n", filename_stream); - - FILE *fp; - char JsonString[512] = { 0 }; - sprintf(JsonString,"{\"stream_width\":%d,\"stream_height\":%d}", stream_width, stream_height); - - if ((fp = fopen(filename_stream, "w+")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - - CopyFileTo(streamPATH, stream_bakPATH); - } - else - { - printf("Fail to open stream.json #1\n"); - } - } - else - { - if ((!FileExist(streamPATH)) && FileExist(stream_bakPATH)) { - CopyFileTo(stream_bakPATH, streamPATH); - } - - //size_t nfileSize_cofnig = ReadFileSize(filename_config); - char *fileBuf_stream = ReadAllBytes(filename_stream); - if (fileBuf_stream) { - cJSON *root = NULL; - root = cJSON_Parse(fileBuf_stream); - if (fileBuf_stream) { - free(fileBuf_stream); - fileBuf_stream = NULL; - } - - if (root == NULL) - { - printf("root_stream is NULL\n"); - } - else - { - cJSON *cjson_stream_width,*cjson_stream_height; - - cjson_stream_width = cJSON_GetObjectItem(root, "stream_width"); - cjson_stream_height = cJSON_GetObjectItem(root, "stream_height"); - - if (cjson_stream_width) { - if ((int)cjson_stream_width->valueint != stream_width) { - g_check_if_different_width_or_height = 1; - if (cjson_stream_width) { - cJSON_ReplaceItemInObject(root, "stream_width", cJSON_CreateNumber(stream_width)); - } - } - } - - if (cjson_stream_height) { - if ((int)cjson_stream_height->valueint != stream_height) { - g_check_if_different_width_or_height = 1; - if (cjson_stream_height) { - cJSON_ReplaceItemInObject(root, "stream_height", cJSON_CreateNumber(stream_height)); - } - } - } - - if (g_check_if_different_width_or_height == 1) { - - char* JsonString = cJSON_Print(root); - FILE *fp; - - if ((fp = fopen(filename_stream, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - - CopyFileTo(streamPATH, stream_bakPATH); - } - else - { - printf("Fail to open stream.json #2\n"); - } - - if (JsonString) { - free(JsonString); - JsonString = NULL; - } - } - } - if (root) { - cJSON_Delete(root); - root = NULL; - } - } - } -} - -int get_g_check_if_different_width_or_height() { - return g_check_if_different_width_or_height; -} - -void* auto_resolution_changed(void * ptr) { - pthread_detach(pthread_self()); - setPthreadName("resolu"); - char sOutputResponse[MEMORY_SIZE] = { 0 }; - - int try_check_count = 0; - do{ - pthread_mutex_lock(&mutex_curl); - if (g_http_handle != NULL) { - curl_easy_cleanup(g_http_handle); - curl_global_cleanup(); - curl_global_init(CURL_GLOBAL_SSL); - g_http_handle = NULL; - g_http_handle = curl_easy_init(); - } - - g_curl_handle_resolution_changed = g_http_handle; // Initialization for each handler. - - memset(sOutputResponse,0x00, MEMORY_SIZE); - int get_size = (int)build_resolution_changed(sOutputResponse); -#ifdef GY_OS_V_SERIES - int check_reboot = 0; -#endif - if (get_size >= 1) { - //printf("\n-----------sOutputResponse:%s\n", sOutputResponse); - char *stream_w = strstr(sOutputResponse, ""); - char *stream_h = strstr(sOutputResponse, ""); - - if (stream_w != NULL && stream_h != NULL){ - - char *stream_w_end = strstr(stream_w, ""); - char *stream_h_end = strstr(stream_h, ""); - if(stream_w_end != NULL && stream_w_end - stream_w - 7 >= 1 && - stream_h_end != NULL && stream_h_end - stream_h - 8 >= 1){ - char stream_width[25] = { 0 }; - memcpy(stream_width, stream_w + 7 , stream_w_end - stream_w - 7); - char stream_height[25] = { 0 }; - memcpy(stream_height, stream_h + 8, stream_h_end - stream_h - 8); - - int current_stream_width = atoi(stream_width); - int current_stream_height = atoi(stream_height); - - //printf("\n--------%d,%d\n", current_stream_width, current_stream_height); - write_to_stream_width_and_stream_height(current_stream_width, current_stream_height); - - if (g_check_if_different_width_or_height == 1) { -#ifdef GY_OS_V_SERIES - check_reboot = 1; -#endif - } - else { - try_check_count++; - } - } - } - - char *stream_encoder1 = strstr(sOutputResponse, ""); - if (stream_encoder1) { - char temp_stream_encoder1[2048] = { 0 }; - memcpy(temp_stream_encoder1, stream_encoder1 + 8, strlen(stream_encoder1) - 8); - char *stream_encoder2 = strstr(temp_stream_encoder1, ""); - if (stream_encoder2) { - char temp_stream_encoder2[2048] = { 0 }; - memcpy(temp_stream_encoder2, stream_encoder2 + 8, strlen(stream_encoder2) - 8); - char *stream_encoder3 = strstr(temp_stream_encoder2, ""); - if (stream_encoder3) { - char temp_stream_encoder3[2048] = { 0 }; - memcpy(temp_stream_encoder3, stream_encoder3 + 8, strlen(stream_encoder2) - 8); - char *stream_h264_gop = strstr(temp_stream_encoder3, ""); - if (stream_h264_gop) { - char *stream_h264_gop_end = strstr(stream_h264_gop, ""); - if (stream_h264_gop_end != NULL && stream_h264_gop_end - stream_h264_gop - 10 >= 1) { - char stream_gop[25] = { 0 }; - memcpy(stream_gop, stream_h264_gop + 10, stream_h264_gop_end - stream_h264_gop - 10); - int current_stream_gop = atoi(stream_gop); - g_check_h264_gop = current_stream_gop; - } - } - } - } - } - - } - curl_easy_reset(g_curl_handle_resolution_changed); - //g_curl_handle_resolution_changed = NULL; - pthread_mutex_unlock(&mutex_curl); - -#ifdef GY_OS_V_SERIES - if (check_reboot == 1) { - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "different width or height"); - write_to_logs_html(temp_msg, "auto resolution changed", "CGI_REBOOT", "Yes"); - write_to_log_if_error(temp_msg, "auto resolution changed", "CGI_REBOOT"); - - pthread_t auto_reboot_thread_id; - if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) - { - printf("\ncreate auto reboot thread faile \n"); - } - } -#else - -#endif - - if (try_check_count >= 10) - break; - usSleep(10000000); - } while (bHttpServerMainStart); - - pthread_exit(NULL); - -} -#ifdef GY_OS_AMBA -int run_check_current_resolution = -1; - -void set_run_check_current_resolution(int set_value) { - run_check_current_resolution = set_value; -} - -int get_run_check_current_resolution() { - return run_check_current_resolution; -} - -void* check_current_resolution(void * ptr) { - pthread_detach(pthread_self()); - setPthreadName("check_resolu"); - set_record_process_note("resol_start"); - if (run_check_current_resolution == 0) { - run_check_current_resolution = 1; - int compared_width = 1920; - int compared_height = 1080; - - char sOutputResponse[MEMORY_SIZE] = { 0 }; - - int try_check_count = 0; - do { - pthread_mutex_lock(&mutex_curl); - g_curl_handle_resolution_changed = g_http_handle; // Initialization for each handler. - - memset(sOutputResponse, 0x00, MEMORY_SIZE); - int get_size = (int)build_resolution_changed(sOutputResponse); - if (get_size >= 1) { - //printf("\n-----------sOutputResponse:%s\n", sOutputResponse); - char *stream_w = strstr(sOutputResponse, ""); - char *stream_h = strstr(sOutputResponse, ""); - - if (stream_w != NULL && stream_h != NULL) { - - char *stream_w_end = strstr(stream_w, ""); - char *stream_h_end = strstr(stream_h, ""); - if (stream_w_end != NULL && stream_w_end - stream_w - 7 >= 1 && - stream_h_end != NULL && stream_h_end - stream_h - 8 >= 1) { - char stream_width[25] = { 0 }; - memcpy(stream_width, stream_w + 7, stream_w_end - stream_w - 7); - char stream_height[25] = { 0 }; - memcpy(stream_height, stream_h + 8, stream_h_end - stream_h - 8); - - int current_stream_width = atoi(stream_width); - int current_stream_height = atoi(stream_height); - - if (current_stream_width > compared_width || current_stream_height > compared_height) { - g_check_current_resolution = 0; - } - else { - try_check_count++; - } - } - } - - char *stream_encoder1 = strstr(sOutputResponse, ""); - if (stream_encoder1) { - char temp_stream_encoder1[2048] = { 0 }; - memcpy(temp_stream_encoder1, stream_encoder1 + 8, strlen(stream_encoder1) - 8); - char *stream_encoder2 = strstr(temp_stream_encoder1, ""); - if (stream_encoder2) { - char temp_stream_encoder2[2048] = { 0 }; - memcpy(temp_stream_encoder2, stream_encoder2 + 8, strlen(stream_encoder2) - 8); - char *stream_encoder3 = strstr(temp_stream_encoder2, ""); - if (stream_encoder3) { - char temp_stream_encoder3[2048] = { 0 }; - memcpy(temp_stream_encoder3, stream_encoder3 + 8, strlen(stream_encoder3) - 8); - char *stream_encoder4 = strstr(temp_stream_encoder3, ""); - if (stream_encoder4) { - char temp_stream_encoder4[2048] = { 0 }; - memcpy(temp_stream_encoder4, stream_encoder4 + 8, strlen(stream_encoder4) - 8); - char *stream_h264_gop = strstr(temp_stream_encoder4, ""); - if (stream_h264_gop) { - char *stream_h264_gop_end = strstr(stream_h264_gop, ""); - if (stream_h264_gop_end != NULL && stream_h264_gop_end - stream_h264_gop - 10 >= 1) { - char stream_gop[25] = { 0 }; - memcpy(stream_gop, stream_h264_gop + 10, stream_h264_gop_end - stream_h264_gop - 10); - int current_stream_gop = atoi(stream_gop); - g_check_h264_gop = current_stream_gop; - } - } - } - } - } - } - } - curl_easy_reset(g_curl_handle_resolution_changed); - //g_curl_handle_resolution_changed = NULL; - pthread_mutex_unlock(&mutex_curl); - - if (try_check_count >= 10) - break; - usSleep(10000000); - } while (bHttpServerMainStart); - run_check_current_resolution = -1; - } - set_record_process_note("resol_start"); - pthread_exit(NULL); -} -#endif -CURL* g_curl_handle_getfeatures = NULL; -int g_check_if_OK_getfeatures = 1; -void ipcam_getfeatures() { - //printf("\nname: %s\n", myname); - //printf("\nvalue: %s\n", myvalue); - - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - - //char cmd1[256] = "curl http://"; - char cmd1[256] = "http://"; - //char cmd2[256] = ":"; - char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" - char cmd4[256] = "/system?get=features"; - - //curl http://:d@192.168.3.57:81/event?event.event0000=1 - - strcpy(cmd, cmd1); - //strcat(cmd, accountData[0].account_username); - //strcat(cmd, cmd2); - //strcat(cmd, accountData[0].account_password); - strcat(cmd, cmd3); - strcat(cmd, accountData[0].account_port); - strcat(cmd, cmd4); - - //printf("\n[setsmartevent]cmd: %s\n", cmd); - pthread_mutex_lock(&mutex_curl); - g_curl_handle_getfeatures = g_http_handle; - if (g_curl_handle_getfeatures) - { - struct curl_slist *pList = NULL; - pList = curl_slist_append(pList, "Connection: close"); - pList = curl_slist_append(pList, "charset: utf-8"); - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_HTTPHEADER, pList); - - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_URL, cmd); - char buf_account[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_USERNAME, buf_account); - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_PASSWORD, buf_account2); - long port_num = atoi((const char*)accountData[0].account_port); - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_PORT, port_num); - - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_CONNECTTIMEOUT, 1); // 設定連線超時,單位秒 - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_TIMEOUT, 3); - //curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_ACCEPT_ENCODING, "gzip"); - - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_USERAGENT, "IPVideo"); - - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_LOW_SPEED_LIMIT, 1L); - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_LOW_SPEED_TIME, 1L); - - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_TCP_FASTOPEN, 1L); - - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) - - struct MemoryStruct temp_msg; - struct MemoryStruct* ptr_responded_msg = &temp_msg; - ptr_responded_msg->size = 0; - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_WRITEFUNCTION, WriteResponseString); - curl_easy_setopt(g_curl_handle_getfeatures, CURLOPT_WRITEDATA, ptr_responded_msg); - - CURLcode res_getfeatures = curl_easy_perform(g_curl_handle_getfeatures); - if (res_getfeatures != CURLE_OK) // Check for errors - { - fprintf(stderr, "[ipcam getfeatures] Failed to initialize the CURL handler. Reason: %s\n", curl_easy_strerror(res_getfeatures)); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "[ipcam getfeatures] Failed to initialize the CURL handler. Reason: %s", curl_easy_strerror(res_getfeatures)); - write_to_logs_html(temp_msg, "ipcam_getfeatures", "ERROR", SystemSetting.enable_system_logs); - } - else { - if (ptr_responded_msg != NULL && ptr_responded_msg->size >= 1) { - if (strstr(ptr_responded_msg->memory,"98529ab")!=NULL) { - char temp_msg[8192] = { 0 }; - strcpy(temp_msg, "The camera doesn't support car plate."); - write_to_logs_html(temp_msg, "ipcam_getfeatures", "INFO", SystemSetting.enable_system_logs); - g_check_if_OK_getfeatures = 0; - } - - if (strstr(ptr_responded_msg->memory, "FEATURE_SYS_CAPTURE_EFR=1") != NULL) { - //char temp_msg[8192] = { 0 }; - //strcpy(temp_msg, "The camera support thermal."); - //write_to_logs_html(temp_msg, "ipcam_getfeatures", "INFO", SystemSetting.enable_system_logs); - g_check_if_OK_thermal = 1; - } - } - } - - curl_easy_reset(g_curl_handle_getfeatures); - if (pList != NULL) - curl_slist_free_all(pList); - - ptr_responded_msg->size = 0; - } - else - { - printf("[ipcam getfeatures] CURL failed to initialize!\n"); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "%s", "[ipcam getfeatures] CURL failed to initialize!"); - write_to_logs_html(temp_msg, "ipcam_getfeatures", "ERROR", SystemSetting.enable_system_logs); - } - - //curl_easy_cleanup(g_curl_handle_getfeatures); - //g_curl_handle_getfeatures = NULL; - pthread_mutex_unlock(&mutex_curl); - usSleep(20000); -} - -CURL* g_curl_handle_reboot = NULL; -void build_reboot(char * myname, char * myvalue) { - //printf("\nname: %s\n", myname); - //printf("\nvalue: %s\n", myvalue); - - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - - //char cmd1[256] = "curl http://"; - char cmd1[256] = "http://"; - //char cmd2[256] = ":"; - char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" - char cmd4[256] = "/maintenance?"; - char cmd5[256] = "="; - - //curl http://:d@192.168.3.57:81/event?event.event0000=1 - - strcpy(cmd, cmd1); - //strcat(cmd, accountData[0].account_username); - //strcat(cmd, cmd2); - //strcat(cmd, accountData[0].account_password); - strcat(cmd, cmd3); - strcat(cmd, accountData[0].account_port); - strcat(cmd, cmd4); - strcat(cmd, myname); - strcat(cmd, cmd5); - strcat(cmd, myvalue); - - - //printf("\n[setsmartevent]cmd: %s\n", cmd); - -# if 0 - FILE* pPipe; - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); -#else - - if (g_curl_handle_reboot) - { - struct curl_slist *pList = NULL; - pList = curl_slist_append(pList, "Connection: close"); - pList = curl_slist_append(pList, "charset: utf-8"); - curl_easy_setopt(g_curl_handle_reboot, CURLOPT_HTTPHEADER, pList); - - curl_easy_setopt(g_curl_handle_reboot, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(g_curl_handle_reboot, CURLOPT_URL, cmd); - char buf_account[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); - curl_easy_setopt(g_curl_handle_reboot, CURLOPT_USERNAME, buf_account); - curl_easy_setopt(g_curl_handle_reboot, CURLOPT_PASSWORD, buf_account2); - long port_num = atoi((const char*)accountData[0].account_port); - curl_easy_setopt(g_curl_handle_reboot, CURLOPT_PORT, port_num); - - curl_easy_setopt(g_curl_handle_reboot, CURLOPT_CONNECTTIMEOUT, 1); // 設定連線超時,單位秒 - curl_easy_setopt(g_curl_handle_reboot, CURLOPT_TIMEOUT, 3); - //curl_easy_setopt(g_curl_handle_reboot, CURLOPT_ACCEPT_ENCODING, "gzip"); - - curl_easy_setopt(g_curl_handle_reboot, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_curl_handle_reboot, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_curl_handle_reboot, CURLOPT_USERAGENT, "IPVideo"); - - curl_easy_setopt(g_curl_handle_reboot, CURLOPT_LOW_SPEED_LIMIT, 1L); - curl_easy_setopt(g_curl_handle_reboot, CURLOPT_LOW_SPEED_TIME, 1L); - - curl_easy_setopt(g_curl_handle_reboot, CURLOPT_TCP_FASTOPEN, 1L); - - curl_easy_setopt(g_curl_handle_reboot, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) - - CURLcode res_quality_basic = curl_easy_perform(g_curl_handle_reboot); - if (res_quality_basic != CURLE_OK) // Check for errors - { - fprintf(stderr, "[build one set for quality basic] Failed to initialize the CURL handler for quality basic. Reason: %s\n", curl_easy_strerror(res_quality_basic)); - } - - curl_easy_reset(g_curl_handle_reboot); - if (pList != NULL) - curl_slist_free_all(pList); - } - else - { - printf("[build one set for quality basic] CURL failed to initialize!\n"); - } - - usSleep(20000); -#endif -} - -void* auto_reboot(void * ptr) { - pthread_detach(pthread_self()); - setPthreadName("reboot"); - do{ - pthread_mutex_lock(&mutex_curl); - g_curl_handle_reboot = g_http_handle; // Initialization for each handler. - - build_reboot("reboot", "1"); - - curl_easy_reset(g_curl_handle_reboot); - //g_curl_handle_reboot = NULL; - pthread_mutex_unlock(&mutex_curl); - - usSleep(1000000); - } while (bHttpServerMainStart); - - pthread_exit(NULL); - -} - -CURL* g_curl_handle_system = NULL; -void build_system(char * myname, char * myvalue) { - //printf("\nname: %s\n", myname); - //printf("\nvalue: %s\n", myvalue); - - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - - //char cmd1[256] = "curl http://"; - char cmd1[256] = "http://"; - //char cmd2[256] = ":"; - char cmd3[256] = "127.0.0.1:";//"@127.0.0.1:" - char cmd4[256] = "/system?"; - char cmd5[256] = "="; - - //curl http://:d@192.168.3.57:81/event?event.event0000=1 - - strcpy(cmd, cmd1); - //strcat(cmd, accountData[0].account_username); - //strcat(cmd, cmd2); - //strcat(cmd, accountData[0].account_password); - strcat(cmd, cmd3); - strcat(cmd, accountData[0].account_port); - strcat(cmd, cmd4); - strcat(cmd, myname); - strcat(cmd, cmd5); - strcat(cmd, myvalue); - - - //printf("\n[setsmartevent]cmd: %s\n", cmd); - -# if 0 - FILE* pPipe; - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); -#else - - if (g_curl_handle_system) - { - struct curl_slist *pList = NULL; - pList = curl_slist_append(pList, "Connection: close"); - pList = curl_slist_append(pList, "charset: utf-8"); - curl_easy_setopt(g_curl_handle_system, CURLOPT_HTTPHEADER, pList); - - curl_easy_setopt(g_curl_handle_system, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(g_curl_handle_system, CURLOPT_URL, cmd); - char buf_account[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_username, (unsigned char *)buf_account); - char buf_account2[512] = { 0 }; - urldecode((unsigned char *)accountData[0].account_password, (unsigned char *)buf_account2); - curl_easy_setopt(g_curl_handle_system, CURLOPT_USERNAME, buf_account); - curl_easy_setopt(g_curl_handle_system, CURLOPT_PASSWORD, buf_account2); - long port_num = atoi((const char*)accountData[0].account_port); - curl_easy_setopt(g_curl_handle_system, CURLOPT_PORT, port_num); - - curl_easy_setopt(g_curl_handle_system, CURLOPT_CONNECTTIMEOUT, 1); // 設定連線超時,單位秒 - curl_easy_setopt(g_curl_handle_system, CURLOPT_TIMEOUT, 3); - //curl_easy_setopt(g_curl_handle_system, CURLOPT_ACCEPT_ENCODING, "gzip"); - - curl_easy_setopt(g_curl_handle_system, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(g_curl_handle_system, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(g_curl_handle_system, CURLOPT_USERAGENT, "IPVideo"); - - curl_easy_setopt(g_curl_handle_system, CURLOPT_LOW_SPEED_LIMIT, 1L); - curl_easy_setopt(g_curl_handle_system, CURLOPT_LOW_SPEED_TIME, 1L); - - curl_easy_setopt(g_curl_handle_system, CURLOPT_TCP_FASTOPEN, 1L); - - curl_easy_setopt(g_curl_handle_system, CURLOPT_VERBOSE, 0L); // Switch on full protocol/debug output (1L) - - CURLcode res_quality_basic = curl_easy_perform(g_curl_handle_system); - if (res_quality_basic != CURLE_OK) // Check for errors - { - fprintf(stderr, "[build one set for quality basic] Failed to initialize the CURL handler for quality basic. Reason: %s\n", curl_easy_strerror(res_quality_basic)); - } - - curl_easy_reset(g_curl_handle_system); - if (pList != NULL) - curl_slist_free_all(pList); - } - else - { - printf("[build one set for quality basic] CURL failed to initialize!\n"); - } - - usSleep(20000); -#endif -} - -void* auto_system(void * ptr) { - pthread_detach(pthread_self()); - setPthreadName("osd_system"); - //do - { - pthread_mutex_lock(&mutex_curl); - g_curl_handle_system = g_http_handle; // Initialization for each handler. - - build_system("osd.font", "0"); - build_system("osd.time", "0"); - build_system("osd.status", "0"); - - curl_easy_reset(g_curl_handle_system); - //g_curl_handle_system = NULL; - pthread_mutex_unlock(&mutex_curl); - } - //while (bHttpServerMainStart); - - pthread_exit(NULL); - -} - -#if 0 -void GetAidaPort(){ - //printf("\nGetAidaPort 1\n"); - char filename[1024] = {0}; - strcpy(filename, "/www/plugin/json/CameraPlug-in.json"); - if (!FileExist(filename)) - printf("%s doesn't exist.\n", filename); - else { - //printf("\nGetAidaPort 1-2\n"); - char* fileBuf = ReadAllBytes(filename); - - if (fileBuf) { - cJSON *plugin, *aida_port; - //printf("\nGetAidaPort 2\n"); - plugin = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - //printf("\nGetAidaPort 3\n"); - if (plugin != NULL) { - //printf("config.json parse OK.\n"); - aida_port = cJSON_GetObjectItem(plugin, "port"); - strcpy(accountData[0].account_aida_port, aida_port->valuestring); - //printf("\nKKKKKKK:%s\n", accountData[0].account_aida_port); - if (plugin) { - cJSON_Delete(plugin); - plugin = NULL; - } - } - else - printf("CameraPlug-in.json parse FAIL.\n"); - } - } -} - -#endif - -#define TIME_ZONE_NUMBER 32 -//char g_time_zone_text[TIME_ZONE_NUMBER][10] = { "UTC","GMT","BST","IST","WET","WEST","CET","CEST","EET","EEST","MSK","MSD","AST","ADT","NST","NDT","EST","EDT","CST","CDT","MST","MDT","PST","PDT","HST","AKST","AKDT","AEST","AEDT","ACST","ACDT","AWST" }; -//float g_time_zone_number[TIME_ZONE_NUMBER] = { 0,0,1,1,0,1,1,2,2,3,3,4,-4,-3,-3.5,-2.5,-5,-4,-6,-5,-7,-6,-8,-7,-10,-9,-8,10,11,9.5,10.5,8 }; - -int get_timezone_info(char *time_zone_buf) -{ - int timeZone = 0; - - -#if 0 - char *findPos = NULL; - if (strstr(sOutputResponse, "+") != NULL) - { - } - else if (strstr(sOutputResponse, "-") != NULL) - { - } - else - { - for (int i = 0; i < TIME_ZONE_NUMBER; i++) - { - if (strcmp(sOutputResponse, g_time_zone_text[i]) != 0) - { - - break; - } - } - } -#endif - return timeZone; -} - -void update_system_time() { - char sOutputResponse[MEMORY_SIZE] = { 0 }; - char SystemTimeText[8192] = { 0 }; - //char SystemTimeText_withzone[8192] = { 0 }; - - int get_size = (int)get_system_time_from_ipcam(sOutputResponse); - - //printf("get size = %d \n, %s \n", get_size, sOutputResponse); - - if (get_size >= 1) { - sOutputResponse[get_size] = '\0'; - char *findPos = NULL; - findPos = strstr(sOutputResponse, "time="); - //char *findPosB = NULL; - //findPosB = strstr(sOutputResponse, "model="); - - if (findPos != NULL - && strlen(findPos) >= 24 - //& findPosB != NULL - ) //time=2022/12/02 14:37:23 - { - //int time_str_len = findPosB - (findPos + 5); - //memcpy(SystemTimeText_withzone, findPos + 5, time_str_len); //+19 - //printf("get sys time zone text= %s \n", SystemTimeText); - - //int iTimeZone = get_timezone_info(SystemTimeText_withzone); - - memcpy(SystemTimeText, findPos + 5, 19); //+19 - //printf("get sys time text= %s \n", SystemTimeText); - - int count_digit = 0; - for (int i = 0; i < strlen(SystemTimeText); i++) { - if (isdigit(SystemTimeText[i])) - { - count_digit++; - } - } - - if (count_digit == 14) { - struct tm tm_val; - time_t epoch = 0; - - //strptime - int r; - r = sscanf(SystemTimeText, "%d/%d/%d %d:%d:%d", &tm_val.tm_year, &tm_val.tm_mon, &tm_val.tm_mday, &tm_val.tm_hour, &tm_val.tm_min, &tm_val.tm_sec); - - if (r != 6) { - printf("expected %d numbers scanned in %s\n", r, SystemTimeText); - //char* defaultdata = "1900-01-01 01:01:01"; - } - - epoch = strptime_s(&tm_val); - //strptime_c(eventCounterList[i].reset_at, "%Y-%m-%d %H:%M:%S", &tm); - //epoch = mktime(&tm_val); - //printf("get sys time stamp = %d \n", epoch); - //printf("\n-----g_osdSysTimeStamp:%ld,time(0):%ld\n", g_osdSysTimeStamp, time(0)); - - - if (epoch > time(0) && difftime(epoch, time(0)) >= 3540 && difftime(epoch, time(0)) <= 3660) { - g_osdSysTimeStamp = time(0); - } - else if (epoch < time(0) && difftime(time(0), epoch) >= 3540 && difftime(time(0), epoch) <= 3660) { - g_osdSysTimeStamp = time(0); - } - else{ - g_osdSysTimeStamp = epoch; - } - - //get gmt+0 time - time_t t, gmt_t; - struct tm *gmt; - t = time(NULL); - gmt = gmtime(&t); - gmt_t = mktime(gmt); - - int iTimeZone = 0; - - iTimeZone = epoch - gmt_t; - - g_osdSysTimeZoneInfo = iTimeZone; - - /*if (tm_val.tm_mday == gmt->tm_mday) - { - iTimeZone = tm_val.tm_hour - gmt->tm_hour; - } - else - { - if (tm_val.tm_mday > gmt->tm_mday) - { - iTimeZone = (24 + tm_val.tm_hour) - gmt->tm_hour; - } - else - { - iTimeZone = tm_val.tm_hour - (24 + gmt->tm_hour); - } - }*/ - - //printf("Time Zone info = %d \n", iTimeZone); - - - - //struct tm *tm_local; - //tm_local = localtime(&epoch); - //printf("time = %d-%d-%d %d:%d:%d \n", tm_local->tm_year+1900, tm_local->tm_mon+1, tm_local->tm_mday, tm_local->tm_hour, tm_local->tm_min, tm_local->tm_sec); - } - } - } -} - -void copy_control_io_to_gynet() { - char my_response[MEMORY_SIZE] = { 0 }; - int my_size = 0; - - int count_row = 0; - char data_service[MAX_SERVICE_SIZE][STRSPLIT_SIZE] = { 0 }; - - const char *del = "\n"; - const char *del2 = "="; - - char data_service_pair[MAX_SERVICE_SIZE][2][STRSPLIT_SIZE] = { 0 }; - //int data_service_pair_num[MAX_SERVICE_SIZE] = { 0 }; - - my_size = (int)get_control_io_from_ipcam(my_response); - - if (my_size >= 1) { - my_response[my_size] = '\0'; - - count_row = StrSplit(my_response, data_service, del); - //printf("\n------UU:21\n"); - - //int i_temp = -1; - - for (int i = 0; i < count_row; i++) - { - if (strlen(data_service[i]) >= 1) - { - /*data_service_pair_num[i] = - */ - StrSplit(data_service[i], data_service_pair[i], del2); - //printf("\n------UU:22\n"); - - - if (strcmp(data_service_pair[i][0], "alarm_input0") == 0) { - if (atoi(data_service_pair[i][1]) == 0) { - set_g_control_alarm_gpio_to_zero(); - } - else if(atoi(data_service_pair[i][1]) == 1){ - set_g_control_alarm_gpio_to_one(); - } - break; - } - } - } - } -} - -void copy_ipcam_smtp_service_to_gynet() { - char my_response[MEMORY_SIZE] = { 0 }; - int my_size = 0; - - int count_row = 0; - char data_service[MAX_SERVICE_SIZE][STRSPLIT_SIZE]={0}; - - const char *del = "\n"; - const char *del2 = "="; - - char data_service_pair[MAX_SERVICE_SIZE][2][STRSPLIT_SIZE]={0}; - //int data_service_pair_num[MAX_SERVICE_SIZE] = { 0 }; - - my_size = (int)get_service_from_ipcam(my_response); - - if (my_size >= 1) { - my_response[my_size] = '\0'; - - count_row = StrSplit(my_response, data_service, del); - //printf("\n------UU:21\n"); - - //int i_temp = -1; - - for (int i = 0; i < count_row; i++) - { - if (strlen(data_service[i]) >= 1) - { - /*data_service_pair_num[i] = - */ - StrSplit(data_service[i], data_service_pair[i], del2); - //printf("\n------UU:22\n"); - - if (strcmp(data_service_pair[i][0], "smtp.receiver0") == 0) { - strcpy(IPCAMService.email_address1, data_service_pair[i][1]); - IPCAMService.email_address1[strlen(IPCAMService.email_address1) - 1] = '\0'; - } - else if (strcmp(data_service_pair[i][0], "smtp.receiver1") == 0) { - strcpy(IPCAMService.email_address2, data_service_pair[i][1]); - IPCAMService.email_address2[strlen(IPCAMService.email_address2) - 1] = '\0'; - } - else if (strcmp(data_service_pair[i][0], "smtp.receiver2") == 0) { - strcpy(IPCAMService.email_address3, data_service_pair[i][1]); - IPCAMService.email_address3[strlen(IPCAMService.email_address3) - 1] = '\0'; - } - else if (strcmp(data_service_pair[i][0], "smtp.receiver3") == 0) { - strcpy(IPCAMService.email_address4, data_service_pair[i][1]); - IPCAMService.email_address4[strlen(IPCAMService.email_address4) - 1] = '\0'; - } - else if (strcmp(data_service_pair[i][0], "smtp.receiver4") == 0) { - strcpy(IPCAMService.email_address5, data_service_pair[i][1]); - IPCAMService.email_address5[strlen(IPCAMService.email_address5) - 1] = '\0'; - } - else if (strcmp(data_service_pair[i][0], "smtp.address") == 0) { - strcpy(IPCAMService.email_address, data_service_pair[i][1]); - IPCAMService.email_address[strlen(IPCAMService.email_address) - 1] = '\0'; - } - else if (strcmp(data_service_pair[i][0], "smtp.server") == 0) { - strcpy(IPCAMService.smtp_server, data_service_pair[i][1]); - IPCAMService.smtp_server[strlen(IPCAMService.smtp_server) - 1] = '\0'; - } - else if (strcmp(data_service_pair[i][0], "smtp.auth_mode") == 0) { - IPCAMService.smtp_auth_mode = atoi(data_service_pair[i][1]); - } - else if (strcmp(data_service_pair[i][0], "smtp.port") == 0) { - strcpy(IPCAMService.smtp_port, data_service_pair[i][1]); - IPCAMService.smtp_port[strlen(IPCAMService.smtp_port) - 1] = '\0'; - } - else if (strcmp(data_service_pair[i][0], "smtp.auth") == 0) { - IPCAMService.smtp_auth = atoi(data_service_pair[i][1]); - } - else if (strcmp(data_service_pair[i][0], "smtp.account") == 0) { - strcpy(IPCAMService.auth_account, data_service_pair[i][1]); - IPCAMService.auth_account[strlen(IPCAMService.auth_account) - 1] = '\0'; - } - } - } - /* - printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT start\n"); - printf("\nemail_address1:%s\n", IPCAMService.email_address1); - printf("\nemail_address2:%s\n", IPCAMService.email_address2); - printf("\nemail_address3:%s\n", IPCAMService.email_address3); - printf("\nemail_address4:%s\n", IPCAMService.email_address4); - printf("\nemail_address5:%s\n", IPCAMService.email_address5); - printf("\nemail_address:%s\n", IPCAMService.email_address); - printf("\nsmtp_server:%s\n", IPCAMService.smtp_server); - printf("\nsmtp_auth_mode:%d\n", IPCAMService.smtp_auth_mode); - printf("\nsmtp_port:%s\n", IPCAMService.smtp_port); - printf("\nsmtp_auth:%d\n", IPCAMService.smtp_auth); - printf("\nauth_account:%s\n", IPCAMService.auth_account); - - printf("\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT end\n");*/ - } -} -#ifdef GY_OS_AMBA -void sync_other_camera_lpr_db() { - - char lpr_db_url[8192] = { 0 }; - - strcpy(lpr_db_url, "http://"); - - if (strlen(SystemSetting.external_lpr_db_username) >= 1 && strlen(SystemSetting.external_lpr_db_password) >= 1) { - strcat(lpr_db_url, SystemSetting.external_lpr_db_username); - strcat(lpr_db_url, ":"); - strcat(lpr_db_url, SystemSetting.external_lpr_db_password); - strcat(lpr_db_url, "@"); - } - - if (strcmp(SystemSetting.external_lpr_db_IP, "127.0.0.1") != 0 && strcmp(SystemSetting.external_lpr_db_IP, "localhost") != 0) { - strcat(lpr_db_url, SystemSetting.external_lpr_db_IP); - } - else { - strcpy(SystemSetting.external_lpr_db_IP, "127.0.0.1"); - strcat(lpr_db_url, SystemSetting.external_lpr_db_IP); - } - - if (strlen(SystemSetting.external_lpr_db_port) >= 1) { - strcat(lpr_db_url, ":"); - strcat(lpr_db_url, SystemSetting.external_lpr_db_port); - } - - strcat(lpr_db_url, "/Aida_data/db_fflpr.db"); - - printf("Http lpr_db_url: %s \n", lpr_db_url); - - strcpy(g_stCURL_lpr_db_url, lpr_db_url); - strcpy(g_stCURL_lpr_db_username, SystemSetting.external_lpr_db_username); - strcpy(g_stCURL_lpr_db_password, SystemSetting.external_lpr_db_password); - strcpy(g_stCURL_lpr_db_port, SystemSetting.external_lpr_db_port); - - pthread_t curl_lpr_db_thread_id; - if (pthread_create(&curl_lpr_db_thread_id, 0, net_curl_https_get_other_lpr_db, NULL)) - { - printf("create curl lpr db thread faile \n"); - } -} -#endif -void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, char* contentBuffer/*, int layer_count, network nets[], char **names[], image **alphabet, float nms[]*/, float thresh, float hier_thresh, int dont_show, int ext_output, int save_labels, int http_port, LicenseType licenseType, AdvanceLicenseType advLicenseType, AuthFailStatusCode afsCode, size_t layerFeatureType[], char* strLicenseType, int* isGetalarmMotion, int sock_info_idx) -{ - - //printf("----------------------------[web process]recvBuffer: %s\n",recvBuffer); - int j = 0, buflen = 0, len = 0, /*bIsContent = 0,*/ bIsMultipart = 0; - long idx = 0, nTotalContentLen = 0; - //long nbytes = 0, nTotalBytes = 0, nContentLen = 0; - char* fstr, * ContentStart; - char msg[MAX_MSG_LEN] = {0}; - char sendBuffer[BUFSIZE_V2] = { 0 }; - char beforeSendBuffer[BUFSIZE_V2] = { 0 }; - char headerBuffer[BUFSIZE_V2] = { 0 }; - char firstBuffer[BUFSIZE_V2] = { 0 }; - char urlBuffer[BUFSIZE_V2] = { 0 }; - char httpCommand[8] = { 0 }; - - //char OriAttribute[512] = { 0 };//512 - char tempBuffer[BUFSIZE_V2] = { 0 }; - char out[MAX_MSG_LEN] = { 0 }; - char multiPartBoundary[MAX_MSG_LEN] = { 0 }; - char contentDescription[MAX_MSG_LEN] = { 0 }; - SOCKET cli_socket = *client_socket; - int tracking_channel = MAX_AI_ENGINE_VIEW; - int tracking_channel_idx = MAX_AI_ENGINE_VIEW - 1; -#if defined GY_OS_AMBA - int AIImage_width = 1920; - int AIImage_height = 1080; -#endif - /* read the web browser request through the TCP connection */ - //memset(recvBuffer, 0x00, sizeof(recvBuffer)); - //memset(sendBuffer, 0x00, sizeof(sendBuffer)); - //memset(headerBuffer, 0x00, sizeof(headerBuffer)); - //memset(httpCommand , 0x00, sizeof(httpCommand)); - //printf("\n------------recvBuffer:%s\n", recvBuffer); - - //printf("\n[web process]start\n"); - - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - -//#ifdef _DEBUG_AMBA - //printf("\n(%d) [web process] Program binary path is: %s\n", cli_socket,buf); - //printf("\n(%d) [web process] mac_address: %s\n", cli_socket, mac_address); -//#endif - - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char configPATH[1024]; - char config_bakPATH[1024]; - char eventsPATH[1024]; - char events_bakPATH[1024]; - - strcpy(configPATH, exePath); - strcpy(config_bakPATH, exePath); - strcpy(eventsPATH, exePath); - strcpy(events_bakPATH, exePath); - - strcat(configPATH, "config.json"); - strcat(config_bakPATH, "config_bak.json"); - strcat(eventsPATH, "events.json"); - strcat(events_bakPATH, "events_bak.json"); - - clock_t t1 = clock(); - - if (strncmp(recvBuffer, "GET ", strlen("GET ")) == 0 || strncmp(recvBuffer, "get ", strlen("get ")) == 0) - memcpy(httpCommand, recvBuffer, strlen("GET ")); - else if (strncmp(recvBuffer, "POST ", strlen("POST ")) == 0 || strncmp(recvBuffer, "post ", strlen("post ")) == 0) - memcpy(httpCommand, recvBuffer, strlen("POST ")); - else - { - sprintf(msg, "Only simple GET and POST method is supported."); - printf(msg); - //syslog(NW_SORRY, msg, recvBuffer, cli_socket); - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #17\n"); - //printf("\n[web process]-1: closesocket(cli_socket): %d\n", cli_socket); - closesocket(cli_socket); - return; - } - //syslog(NW_LOG, "request", httpCommand, hit); - //printf("\n[web process]start 2\n"); - if (strcmp(httpCommand, "GET ") == 0 || strcmp(httpCommand, "POST ") == 0) - { - ContentStart = FindHttpContentStart(recvBuffer); - if (ContentStart) - { - memcpy(headerBuffer, recvBuffer, ContentStart - recvBuffer); - //DumpCharacters(headerBuffer, nTotalBytes + ContentStart - recvBuffer); - memcpy(contentBuffer, ContentStart, recvBuffer + recv_buff_size - ContentStart); - //printf("contentBuffer=%s", contentBuffer); - //DumpCharacters(contentBuffer, 8192); - //nContentLen = (recvBuffer + nbytes - ContentStart); - - if (strcmp(httpCommand, "POST ") == 0) - { - //char delim[2] = "HT"; - char *start = headerBuffer; - char *pDelim; - do - { - pDelim = strstr(start, "\r\n"); - // string between start and delim (or end of string if delim is NULL). - if (pDelim) - { - char attribute[512] = { 0 };//512 - memcpy(attribute, start, pDelim - start); - attribute[pDelim - start] = 0; - char att_var[10][STRSPLIT_SIZE]={0}; - char *del = ":"; - - if ((pDelim - start) >= 1) - { - if (strstr(attribute, "Content-Length") != NULL) { - //printf("\n------UU:23-1\n"); - StrSplit(attribute, att_var, del); - if (strcmp(att_var[0], "Content-Length") == 0) - { - nTotalContentLen = atoi(att_var[1]); - //printf("Content-Length %d:%d\n", cli_socket, nTotalContentLen); - } - } - else if (strstr(attribute, "Content-Type") != NULL) { - //printf("\n------UU:23-2\n"); - StrSplit(attribute, att_var, del); - if (strcmp(att_var[0], "Content-Type") == 0) - { - TrimSpace(out, sizeof(out), att_var[1], 0); - if (strncmp(MULTIPART_CONTENT, out, strlen(MULTIPART_CONTENT)) == 0) - { - bIsMultipart = 1; - strcat(multiPartBoundary, "--"); - strcat(multiPartBoundary, out + strlen(MULTIPART_CONTENT)); - } - } - } - else if (strstr(attribute, "Content-Description") != NULL) { - //printf("\n------UU:23-3\n"); - StrSplit(attribute, att_var, del); - if (strcmp(att_var[0], "Content-Description") == 0) - { - strcpy(contentDescription, att_var[1]); - char* channelNum = strstr(contentDescription, "-CH"); - if (channelNum) - { - channelNum = channelNum + strlen("-CH"); - tracking_channel = atoi(channelNum) /*+ 16*/; //1~16 reserved for AIEngine.exe. - tracking_channel_idx = tracking_channel; - } - else - { - channelNum = strstr(contentDescription, "CHANNEL") + strlen("CHANNEL"); - if (channelNum) - { - tracking_channel = atoi(channelNum); - tracking_channel_idx = tracking_channel - 1; - } - else - { - tracking_channel = MAX_TRACKING_NUM + 1; - tracking_channel_idx = MAX_TRACKING_NUM; - } - } - - char* jpegWidthNum = strstr(contentDescription, "width="); - if (jpegWidthNum) - { - jpegWidthNum = jpegWidthNum + strlen("width="); -#if defined GY_OS_AMBA - AIImage_width = atoi(jpegWidthNum); -#endif - } - - char* jpegHeightNum = strstr(contentDescription, "height="); - if (jpegHeightNum) - { - jpegHeightNum = jpegHeightNum + strlen("height="); -#if defined GY_OS_AMBA - AIImage_height = atoi(jpegHeightNum); -#endif - } - } - } - } - start = pDelim + 2; // Use length of your b string. - } - } - while (pDelim); - } - } - else - { - //printf("\n[web process]-2: closesocket(cli_socket): %d\n", cli_socket); - closesocket(cli_socket); - printf("[web process] FindHttpContentStart returned error.\n"); - return; - } - } - //printf("\n[web process]start 3\n"); - //clock_t t2 = clock(); - //diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); - //printf("parsing header time:%f\n", diff); - /* null-terminate after the second space to ignore extra stuff */ - - for (idx = strlen(httpCommand); idx < LINE_BUFSIZE; idx++) - { - if (headerBuffer[idx] == ' ') - { - /* string is "GET URL " +lots of other stuff */ - memcpy(urlBuffer, headerBuffer + strlen(httpCommand), idx - strlen(httpCommand)); - urlBuffer[idx - strlen(httpCommand)] = 0; - memcpy(firstBuffer, headerBuffer, idx); - firstBuffer[idx] = 0; - break; - } - } - -#if defined GY_OS_AMBA - //check /airelay - char *pch; - int newStrLen = 0; - pch = strstr(urlBuffer, "/airelay"); - if (pch != NULL) - { - if (pch == urlBuffer) - { - newStrLen = strlen(urlBuffer) - 8; - memcpy(urlBuffer, urlBuffer + 8, newStrLen); - urlBuffer[newStrLen] = 0; - } - } -#endif - - //printf("\n[web process]start 4\n"); - /* check for illegal parent directory use .. */ - for (j = 0; j < idx - 1 - strlen(httpCommand); j++) - { - if (urlBuffer[j] == '.' && urlBuffer[j + 1] == '.') - { - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "Parent directory(..) path names not supported."); - printf("%s\n", msg); - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_204, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend\n"); - //syslog(NW_SORRY, "Parent directory (..) path names not supported", firstBuffer, cli_socket); - //printf("\n(%d) [web process] Parent directory (..) path names not supported \n", cli_socket); - //printf("\n[web process]-3: closesocket(cli_socket): %d\n", cli_socket); - closesocket(cli_socket); - return; - } - } - //printf("\n[web process]start 5\n"); - char beforeSendBuffer_xtra[BUFSIZE * 60] = { 0 }; - - if (strlen(g_account_port_protected) == 0) { - strcpy(g_account_port_protected, accountData[0].account_port); - } - else { - if (strcmp(g_account_port_protected, accountData[0].account_port) != 0) { - memset(g_account_port_protected, 0x00, sizeof(g_account_port_protected)); - strcpy(g_account_port_protected, accountData[0].account_port); - } - } - //printf("\n[web process]start 6\n"); - // Analyze all HTTP requests - //printf("\n-------httpCommand:%s\n", httpCommand); - - if (strcmp(httpCommand, "GET ") == 0) - { -#ifdef _DEBUG_AMBA - printf("\n(%d) [web process] ### sophia (%d) urlBuffer:%s start \n", cli_socket, cli_socket,urlBuffer); -#endif - - //printf("\n---------urlBuffer:%s\n", urlBuffer); - if (strcmp(urlBuffer, "/server") == 0) - { - //printf("\n[web process]start 7\n"); - - char Msg[256] = { 0 }; - strcpy(contentBuffer, "DeviceName=GYNet\r\n
"); -#ifdef GY_OS_WIN - sprintf(Msg, "Version=%s\r\n", ProductVersion); -#elif defined GY_OS_AMBA || defined GY_OS_NOVA - sprintf(Msg, "Version=%s\r\n", APP_VERSION); -#endif - strcat(contentBuffer, Msg); - strcat(contentBuffer, "Language="); - strcat(contentBuffer, SystemSetting.language); - strcat(contentBuffer, "\r\n
"); -//#ifdef GY_OS_WIN - //sprintf(Msg, "SystemID=%s\r\n
", mac_address); -//#elif defined GY_OS_AMBA || defined GY_OS_NOVA - //Get MAC Address - char fetch_mac_addr[30] = { 0 }; - memset(fetch_mac_addr, 0x00, sizeof(fetch_mac_addr)); - GetMACAddress(fetch_mac_addr); - sprintf(Msg, "SystemID=%s\r\n
", fetch_mac_addr); -//#endif - strcat(contentBuffer, Msg); - sprintf(Msg, "LicenseType=%s\r\n
", strLicenseType); - strcat(contentBuffer, Msg); - sprintf(Msg, "Default=%s\r\n
", heartbeatData.events_default_version); - strcat(contentBuffer, Msg); - - int check_input_key = 0; - - { - char buf_exe[1024] = {}; - readlink("/proc/self/exe", buf_exe, sizeof(buf_exe)); - - char exePath_temp[1024] = {}; - getFilePath(buf_exe, exePath_temp, 1024); - - char keyPATH[1024] = { 0 }; - strcpy(keyPATH, exePath_temp); - strcat(keyPATH, "key.txt"); - - char key_buff[1024] = { 0 };//creating char array to store data of file - - if (FileExist(keyPATH) == 1) { - - FILE *pFile; - if ((pFile = fopen(keyPATH, "r")) != NULL) - { - fscanf(pFile, "%s", key_buff); - fclose(pFile); - } - } - - if (strcmp(key_buff, strUnlockingKey)==0) { - check_input_key = 1; - } - } - - if (check_input_key == 1) - { - sprintf(Msg, "LicenseStatus=%s\r\n
", strLicenseStatus); - strcat(contentBuffer, Msg); - sprintf(Msg, "UnlockingKey=%s\r\n
", strUnlockingKey); - strcat(contentBuffer, Msg); - } - else { - sprintf(Msg, "LicenseStatus=%s\r\n
", ""); - strcpy(strLicenseStatus,""); - strcat(contentBuffer, Msg); - sprintf(Msg, "UnlockingKey=%s\r\n
", strUnlockingKey); - strcat(contentBuffer, Msg); - } - - /*else { - sprintf(Msg, "LicenseStatus=%s\r\n
", "Fail to input key."); - strcpy(strLicenseStatus,"Fail to input key."); - strcat(contentBuffer, Msg); - sprintf(Msg, "UnlockingKey=%s\r\n
", strUnlockingKey); - strcat(contentBuffer, Msg); - }*/ - - sprintf(Msg, "ModeName=%s\r\n
", WeightFileModeName); - strcat(contentBuffer, Msg); - -#ifdef GY_OS_WIN - if (!nIsCompatibleCPU) - { - sprintf(Msg, "SysStatus=%s\r\n
", "[ERROR] The CPU doesn't meet hardware requirements for OpenVINO!"); - strcat(contentBuffer, Msg); - } - else - strcat(contentBuffer, "SysStatus=OK\r\n
"); -#endif - strcpy(beforeSendBuffer, contentBuffer); - //strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse_server(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #18\n"); - //printf("\n[web process]-4: closesocket(cli_socket): %d\n", cli_socket); - closesocket(cli_socket); - return; - } -#if 1 - else if (strcmp(urlBuffer, "/enable_downsized_cropped_roi") == 0 || strcmp(urlBuffer, "/disable_downsized_cropped_roi") == 0) - { -#ifdef GY_OS_AMBA - if (strcmp(urlBuffer, "/enable_downsized_cropped_roi") == 0) { - set_enable_downsized_cropped_roi(1); - strcpy(beforeSendBuffer, "Enable downsized cropped roi."); - } - else { - set_enable_downsized_cropped_roi(0); - strcpy(beforeSendBuffer, "Disable downsized cropped roi."); - } -#endif //GY_OS_AMBA - - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #18-2\n"); - closesocket(cli_socket); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/enable_zone_crop") == 0 || strcmp(urlBuffer, "/disable_zone_crop") == 0) - { -#ifdef GY_OS_AMBA - if (strcmp(urlBuffer, "/enable_zone_crop") == 0) { - set_enable_zone_crop_1(1); - strcpy(beforeSendBuffer, "Enable zone crop."); - } - else { - set_enable_zone_crop_1(0); - strcpy(beforeSendBuffer, "Disable zone crop."); - } -#endif //GY_OS_AMBA - - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #18-212\n"); - closesocket(cli_socket); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/get_cropped_roi") == 0) - { - char Msg[256] = { 0 }; -#if defined GY_OS_AMBA || defined GY_OS_NOVA - sprintf(Msg, "{\"CROPPED_ROI\":\"%d\",\"CROPPED_ZONE_1\":\"%d\"}", get_enable_downsized_cropped_roi(), get_enable_zone_crop_1()); -#endif //GY_OS_AMBA - strcpy(contentBuffer, Msg); - - strcpy(beforeSendBuffer, contentBuffer); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #18-3\n"); - closesocket(cli_socket); - } -#endif - else if (strcmp(httpCommand, "GET ") == 0 && (strcmp(urlBuffer, "/getalarmmotion") == 0 || strstr(urlBuffer, "/getalarmmotion"))) - { - //printf("******************************************* recv getalarmmotion [%d]\n", cli_socket); - //printf("\n[web process]start 8\n"); - - *isGetalarmMotion = TRUE; - } - else if ((strcmp(urlBuffer, "/Aida/index.html") == 0) || - (strcmp(urlBuffer, "/Aida/radar.html") == 0) || - (strcmp(urlBuffer, "/Aida/radar.js") == 0) || - (strcmp(urlBuffer, "/Aida/face_index.html") == 0) || - (strcmp(urlBuffer, "/Aida/face_list.html") == 0) || - (strcmp(urlBuffer, "/Aida/face_index.js") == 0) || - (strcmp(urlBuffer, "/Aida/face_list.js") == 0) || - (strcmp(urlBuffer, "/Aida/face.js") == 0) || - (strcmp(urlBuffer, "/Aida/sweetalert2.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/css/sweetalert2.min.css") == 0) || - (strcmp(urlBuffer, "/Aida/upload_img.html") == 0) || - (strcmp(urlBuffer, "/Aida/anpr_index.html") == 0) || - (strcmp(urlBuffer, "/Aida/countdown.html") == 0) || - (strcmp(urlBuffer, "/Aida/countdown_output.html") == 0) || - (strcmp(urlBuffer, "/Aida/speed_index.html") == 0) || - (strcmp(urlBuffer, "/Aida/speed_index.js") == 0) || - (strcmp(urlBuffer, "/Aida/radar_speed_share.js") == 0) || - (strcmp(urlBuffer, "/Aida/ptz.html") == 0) || - (strcmp(urlBuffer, "/Aida/ptz.js") == 0) || - (strcmp(urlBuffer, "/Aida/tof.html") == 0) || - (strcmp(urlBuffer, "/Aida/tof.js") == 0) || - (strcmp(urlBuffer, "/Aida/setting.html") == 0) || - (strcmp(urlBuffer, "/Aida/license.html") == 0) || - (strcmp(urlBuffer, "/Aida/alarm.html") == 0) || - (strcmp(urlBuffer, "/Aida/airelay_init.html") == 0) || - (strcmp(urlBuffer, "/Aida/alarm_on_airelay.html") == 0) || - (strcmp(urlBuffer, "/Aida/alarm_on_airelay.js") == 0) || - (strcmp(urlBuffer, "/Aida/unit1.js") == 0) || - (strcmp(urlBuffer, "/Aida/unit2.js") == 0) || - (strcmp(urlBuffer, "/Aida/unit3.js") == 0) || - (strcmp(urlBuffer, "/Aida/unit3.wasm") == 0) || - (strcmp(urlBuffer, "/Aida/output.html") == 0) || - (strcmp(urlBuffer, "/Aida/logs.html") == 0) || - (strcmp(urlBuffer, "/Aida/pythonR.html") == 0) || - (strcmp(urlBuffer, "/Aida/python.html") == 0) || - //(strcmp(urlBuffer, "/Aida/logs_sample.html") == 0) || - (strcmp(urlBuffer, "/Aida/lib/logs/bootstrap.min.css") == 0) || - (strcmp(urlBuffer, "/Aida/lib/logs/jquery.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/lib/logs/bootstrap.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/lib/logs/geotools.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/lib/logs/geotools-swedish-zipcodes.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/lib/logs/moment.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/lib/logs/fancyTable.js") == 0) || - (strcmp(urlBuffer, "/Aida/object_index.html") == 0) || - (strcmp(urlBuffer, "/Aida/js_3_5_1.js") == 0) || - //(strcmp(urlBuffer, "/Aida/lilinivs.js") == 0) || - (strcmp(urlBuffer, "/Aida/index.js") == 0) || - (strcmp(urlBuffer, "/Aida/config.js") == 0) || - (strcmp(urlBuffer, "/Aida/lang.js") == 0) || - (strcmp(urlBuffer, "/Aida/alarm.js") == 0) || - (strcmp(urlBuffer, "/Aida/state.js") == 0) || - (strcmp(urlBuffer, "/Aida/label_names.js") == 0) || - (strcmp(urlBuffer, "/Aida/third_party_label_names.js") == 0) || - (strcmp(urlBuffer, "/Aida/jquery.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/setting_on_nvr.html") == 0) || - (strcmp(urlBuffer, "/Aida/gauge.min_on_nvr.js") == 0) || - (strcmp(urlBuffer, "/Aida/css/style.css") == 0) || - (strcmp(urlBuffer, "/Aida/css/timebar.css") == 0) || - (strcmp(urlBuffer, "/Aida/css/timebar.min.css") == 0) || - (strcmp(urlBuffer, "/Aida/css/owl.carousel.min.css") == 0) || - (strcmp(urlBuffer, "/Aida/css/owl.theme.default.min.css") == 0) || - (strcmp(urlBuffer, "/Aida/lib/owl.carousel.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/lib/timebar.js") == 0) || - (strcmp(urlBuffer, "/Aida/lib/timebar.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/lib/timebar-1.js") == 0) || - (strcmp(urlBuffer, "/Aida/jquery-ui.js") == 0) || - (strcmp(urlBuffer, "/Aida/jquery.blockUI.js") == 0) || - (strcmp(urlBuffer, "/Aida/fabric.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/lpr.html") == 0) || - (strcmp(urlBuffer, "/Aida/cool_counter_on_nvr.html") == 0) || - (strcmp(urlBuffer, "/Aida/lpr_on_nvr.html") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_return.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_return2.png") == 0) || - (strcmp(urlBuffer, "/Aida/lpr.js") == 0) || - (strcmp(urlBuffer, "/Aida/heatmap.css") == 0) || - (strcmp(urlBuffer, "/Aida/heatmap.html") == 0) || - (strcmp(urlBuffer, "/Aida/heatmap.min.js") == 0) || - (strncmp(urlBuffer, "/Aida/heatmap_data.js",21) == 0) || - (strncmp(urlBuffer, "/Aida/heatmap_data_1.js", 23) == 0) || - (strncmp(urlBuffer, "/Aida/heatmap_data_2.js", 23) == 0) || - (strncmp(urlBuffer, "/Aida/heatmap_data_3.js", 23) == 0) || - (strncmp(urlBuffer, "/Aida/heatmap_data_4.js", 23) == 0) || - (strncmp(urlBuffer, "/Aida/heatmap_data_5.js", 23) == 0) || - (strncmp(urlBuffer, "/Aida/heatmap_data_6.js", 23) == 0) || - (strncmp(urlBuffer, "/Aida/heatmap_data_7.js", 23) == 0) || - (strcmp(urlBuffer, "/Aida/heatmap_index.js") == 0) || - (strcmp(urlBuffer, "/Aida/prism.js") == 0) || - (strcmp(urlBuffer, "/Aida/cgi.js") == 0) || - (strcmp(urlBuffer, "/Aida/icon.js") == 0) || - (strcmp(urlBuffer, "/Aida/gauge.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/chirun_min.js") == 0) || - (strcmp(urlBuffer, "/Aida/jquery.form.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/lpr_mapping.htm") == 0) || - (strcmp(urlBuffer, "/Aida/lpr_list_upload.htm") == 0) || - (strcmp(urlBuffer, "/Aida/lpr_list.html") == 0) || - (strcmp(urlBuffer, "/Aida/cool_counter.html") == 0) || - //(strcmp(urlBuffer, "/Aida/time_bar.html") == 0) || - (strcmp(urlBuffer, "/Aida/jquery-ui.css") == 0) || - (strcmp(urlBuffer, "/Aida/jqueryAll.js") == 0) || - (strcmp(urlBuffer, "/Aida/cool_counter.js") == 0) || - (strcmp(urlBuffer, "/Aida/heatmap.js") == 0) || - (strcmp(urlBuffer, "/Aida/cookie.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/fabric.js") == 0) || - (strcmp(urlBuffer, "/Aida/lang_cookie.js") == 0) || - (strcmp(urlBuffer, "/Aida/posttoken.html") == 0) || - (strcmp(urlBuffer, "/Aida/snmptoken.html") == 0) || - (strcmp(urlBuffer, "/Aida/osdtoken.html") == 0) || - (strcmp(urlBuffer, "/Aida/jquery.easyui.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/jquery.slider.js") == 0) || - (strcmp(urlBuffer, "/Aida/aes.js") == 0) || - (strcmp(urlBuffer, "/Aida/easyui.css") == 0) || - (strcmp(urlBuffer, "/Aida/easyui_jvc.css") == 0) || - (strcmp(urlBuffer, "/Aida/object_index.js") == 0) || - (strcmp(urlBuffer, "/Aida/bootstrap.min.css") == 0) || - (strcmp(urlBuffer, "/Aida/warning.html") == 0) || - (strcmp(urlBuffer, "/Aida/Icon/NoParking_Red_64x64px.png") == 0) || - (strcmp(urlBuffer, "/Aida/Icon/Counter_Green_64x64px.png") == 0) || - (strcmp(urlBuffer, "/Aida/Icon/SpeedWithRim_Red_64x64px.png") == 0) || - (strcmp(urlBuffer, "/Aida/Icon/CarWithRim_Yellow_64x64px.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/ExclamationMark_Blue_64x64px.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_alarm.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_ai_setting1.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_ai_setting2.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_anpr.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_export.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_import.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_license.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_lpr_list.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_lpr_list_upload.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_lpr_mapping.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_output.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_setting.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_radar.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_face.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/speed_bg_default_0.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/speed_bg_default_1.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/speed_bg_default_2.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/speed_bg_default_3.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/speed_bg_default_4.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_ptz.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_counter.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_stopwatch.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_tof.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/slider_handle.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/rotate.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/user_blue.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/snap_blue.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/combo_arrow.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/catalog.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/spinner_arrows_up.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/spinner_arrows_down.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/datebox_arrow.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/calendar_prevmonth.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/calendar_nextmonth.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/calendar_prevyear.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/calendar_nextyear.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_black_center_bottom.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_black_center_center.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_black_center_top.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_black_left_bottom.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_black_left_center.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_black_left_top.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_black_right_bottom.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_black_right_center.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_black_right_top.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_blue_center_bottom.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_blue_center_center.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_blue_center_top.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_blue_left_bottom.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_blue_left_center.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_blue_left_top.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_blue_right_bottom.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_blue_right_center.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_1_blue_right_top.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_black_center_bottom.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_black_center_center.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_black_center_top.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_black_left_bottom.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_black_left_center.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_black_left_top.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_black_right_bottom.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_black_right_center.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_black_right_top.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_blue_center_bottom.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_blue_center_center.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_blue_center_top.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_blue_left_bottom.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_blue_left_center.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_blue_left_top.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_blue_right_bottom.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_blue_right_center.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/icon_2_blue_right_top.png") == 0) || - (strcmp(urlBuffer, "/Aida/draw_arrow.js") == 0) || - (strcmp(urlBuffer, "/Aida/websocket.html") == 0) || - (strcmp(urlBuffer, "/Aida/images/ui-bg_glass_65_ffffff_1x400.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/ui-bg_glass_75_e6e6e6_1x400.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/ui-bg_glass_75_dadada_1x400.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/gray_background.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/info-1-32X32.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/info-1-64X64.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/info-2-32X32.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/info-2-64X64.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/info-3-32X32.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/info-3-64X64.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/down_arrow.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/up_arrow.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/file.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/html.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/png.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/jpg.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/js.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/py.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/json.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/zip.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/bin.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/play.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/save.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/delete.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/uploadfile.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/refreshfile.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/deletefile.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/addfile.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/stop.png") == 0) || - (strcmp(urlBuffer, "/Aida/images/clear.png") == 0) || - (strcmp(urlBuffer, "/Aida/") == 0) || - (strcmp(urlBuffer, "/Aida/favicon.ico") == 0) || - (strcmp(urlBuffer, "/favicon.ico") == 0) || - (strcmp(urlBuffer, "/Aida/fabric_jquery.easyui.min_compressed.js") == 0) || - (strcmp(urlBuffer, "/Aida/jqueryAll_compressed.js") == 0) || - (strcmp(urlBuffer, "/Aida/main.css") == 0) || - (strcmp(urlBuffer, "/Aida_data/logs.js") == 0) || - (strcmp(urlBuffer, "/Aida_data/db_fflpr.db") == 0) || - (strcmp(urlBuffer, "/Aida/alarm_on_nvr.html") == 0) || - (strcmp(urlBuffer, "/Aida/ai_meta.html") == 0) || - //(strcmp(urlBuffer, "/Aida/ai_meta.js") == 0) ||//網頁尚未放上來 - (strcmp(urlBuffer, "/Aida/menu_on_nvr.html") == 0) || - (strcmp(urlBuffer, "/Aida/jquery_3_2_1.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/fabric_jquery.easyui.min_compressed_on_nvr.js") == 0) || - (strcmp(urlBuffer, "/Aida/csvformat_help.html") == 0) || - (strncmp(urlBuffer, "/Aida/Icon/counter_icon/", 24) == 0) || - (strncmp(urlBuffer, "/Aida/labels/car_type/", 22) == 0) || - (strncmp(urlBuffer, "/Aida/labels/",13) == 0) || - (strcmp(urlBuffer, "/Aida/ruler/demo.js") == 0) || // a113n 2022-09-29 - (strcmp(urlBuffer, "/Aida/ruler/ruler.js") == 0) || // a113n 2022-09-29 - (strcmp(urlBuffer, "/Aida/ruler/ruler.min.js") == 0) || // a113n 2022-09-29 - (strcmp(urlBuffer, "/Aida/ruler/ruler.min.css") == 0) || // a113n 2022-09-29 - (strcmp(urlBuffer, "/Aida/pcl/pcl.html") == 0) || // add pcl .js - (strcmp(urlBuffer, "/Aida/pcl/test.html") == 0) || - (strcmp(urlBuffer, "/Aida/pcl/OrbitControls.js") == 0) || - (strcmp(urlBuffer, "/Aida/pcl/PCDLoader.js") == 0) || - (strcmp(urlBuffer, "/Aida/pcl/three.min.js") == 0) || - (strcmp(urlBuffer, "/Aida/pcl/TrackballControls.js") == 0) || - (strcmp(urlBuffer, "/Aida/pcl/pcd/tof.pcd") == 0) || - (strcmp(urlBuffer, "/Aida/css/upload_img_demo.css") == 0) || - (strcmp(urlBuffer, "/Aida/css/upload_img_style.css") == 0) || - (strcmp(urlBuffer, "/Aida/lilin.png") == 0) || - (strcmp(urlBuffer, "/Aida/normalize.min.css") == 0) || - (strcmp(urlBuffer, "/Aida/cropper.min.css") == 0) || - (strcmp(urlBuffer, "/Aida/cropper.min.js") == 0) - ) - { - - pthread_mutex_lock(&mutex_web); - - if (strcmp(urlBuffer, "/favicon.ico") == 0) { - strcpy(urlBuffer,"/Aida/favicon.ico"); - } - - if ((strncmp(urlBuffer, "/Aida/heatmap_data.js", 21) == 0)) { - strcpy(urlBuffer, "/Aida/heatmap_data.js"); - } - - if ((strncmp(urlBuffer, "/Aida/heatmap_data_1.js", 23) == 0)) { - strcpy(urlBuffer, "/Aida/heatmap_data_1.js"); - } - - if ((strncmp(urlBuffer, "/Aida/heatmap_data_2.js", 23) == 0)) { - strcpy(urlBuffer, "/Aida/heatmap_data_2.js"); - } - - if ((strncmp(urlBuffer, "/Aida/heatmap_data_3.js", 23) == 0)) { - strcpy(urlBuffer, "/Aida/heatmap_data_3.js"); - } - - if ((strncmp(urlBuffer, "/Aida/heatmap_data_4.js", 23) == 0)) { - strcpy(urlBuffer, "/Aida/heatmap_data_4.js"); - } - - if ((strncmp(urlBuffer, "/Aida/heatmap_data_5.js", 23) == 0)) { - strcpy(urlBuffer, "/Aida/heatmap_data_5.js"); - } - - if ((strncmp(urlBuffer, "/Aida/heatmap_data_6.js", 23) == 0)) { - strcpy(urlBuffer, "/Aida/heatmap_data_6.js"); - } - - if ((strncmp(urlBuffer, "/Aida/heatmap_data_7.js", 23) == 0)) { - strcpy(urlBuffer, "/Aida/heatmap_data_7.js"); - } - - //printf("\n[web process]start 9\n"); - - //printf("\nsock(%d):%s\n", cli_socket, urlBuffer); - char tmp_open_file[512]; - memset(tmp_open_file, 0, sizeof(tmp_open_file)); - - if (isGYNetReady == FALSE) - { - sprintf(tmp_open_file, "./Aida/wait.html"); - } - else if (g_IsPTZDevice == 0) - { - - if (strcmp(accountData[0].account_flip, "1") == 0 || - strcmp(accountData[0].account_mirror, "1") == 0 || - strcmp(accountData[0].account_rotate, "1") == 0) - { - sprintf(tmp_open_file, "./Aida/warning.html"); - } - else{ - sprintf(tmp_open_file, ".%s", urlBuffer); - } - } - else if (g_IsPTZDevice == 1) - { - - if (strcmp(accountData[0].account_rotate, "1") == 0 || - strcmp(accountData[0].account_mirror, "1") == 0) - { - sprintf(tmp_open_file, "./Aida/warning.html"); - } - else{ - sprintf(tmp_open_file, ".%s", urlBuffer); - } - } - - - /*//#ifdef _DEBUG_AMBA - printf("\n(%d) [web process] http get tmp_open_file:%s\n", cli_socket,tmp_open_file); - //#endif //_DEBUG_AMBA*/ - - if ((strcmp(urlBuffer, "/Aida/cool_counter.html") != 0) || - (strcmp(urlBuffer, "/Aida/cool_counter.html") == 0 && (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || -#ifdef GY_OS_NOVA - IsANPRCategory(featureType) || -#endif - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) - ))) - { - int file_fd; - if ((file_fd = open(tmp_open_file, O_RDONLY)) == -1) - { - printf("Failed to open file : %s\n", tmp_open_file);//網頁檔案有沒有被讀取 - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #19-2\n"); - } - else { - int iFileLength = 0; - char sendBuffer_superlarge[BUFSIZE * 8 * 16] = { 0 }; - iFileLength = read(file_fd, sendBuffer_superlarge, BUFSIZE * 8 * 16); - close(file_fd); - - /* work out the file type and check if we support it */ - buflen = strlen(urlBuffer); - fstr = NULL; - for (idx = 0; extensions[idx].ext != 0; idx++) - { - len = strlen(extensions[idx].ext); - if (!strncmp(&urlBuffer[buflen - len], extensions[idx].ext, len)) - { - fstr = extensions[idx].filetype; - break; - } - } - - if (fstr == NULL) - { - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #19\n"); - } - else - { - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: %s;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n", fstr); /*\r\nCache - Control: max - age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #20\n"); - } - - int iSentLeft = 0; - int iSentLength = 0; - int iHaveSentLength = 0; - int iRetryCount = 5; - - - - iSentLeft = iFileLength; - - while (iSentLeft >= 1) { - iSentLength = send(cli_socket, sendBuffer_superlarge + iHaveSentLength, iSentLeft, MSG_MORE); - - if (iSentLength <= 0) - break; - - iHaveSentLength = iHaveSentLength + iSentLength; - iSentLeft = iSentLeft - iSentLength; - iRetryCount--; - - if (iSentLeft >= 1) { - //printf("\n[web process]iSentLeft: %d\n", iSentLeft); - } - - if (iRetryCount <= 0) - break; - //usSleep(100); - } - - - } - } - else if(strcmp(urlBuffer, "/Aida/cool_counter.html") == 0){ - strcpy(beforeSendBuffer, "The weight should support the counter function."); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #22\n"); - } - - pthread_mutex_unlock(&mutex_web); - closesocket(cli_socket); - } -#if 1 - else if (strcmp(urlBuffer, "/getAidaInfo") == 0) - { - //printf("\n[web process]start 10\n"); - //Get MAC Address - char fetch_mac_addr[30] = { 0 }; - memset(fetch_mac_addr, 0x00, sizeof(fetch_mac_addr)); - if (g_match_mac) - strcpy(fetch_mac_addr, g_mac_address); - else - { - GetMACAddress(fetch_mac_addr); - //printf("mac addr = %s \n", fetch_mac_addr); - int i = 0; - while (fetch_mac_addr[i] != '\0') - { - if (fetch_mac_addr[i] == '\n') - { - fetch_mac_addr[i] = '\0'; - break; - } - i++; - } - } - ///get config info - //post events setting - //char filename[] = "config.json"; - char *filename = configPATH; - if (!FileExist(filename)) - printf("%s doesn't exist.\n", filename); - else { -#ifdef _DEBUG_AMBA - printf("read config.json.\n"); -#endif - - //size_t nfileSize = ReadFileSize(filename); - char* fileBuf = ReadAllBytes(filename); - if (fileBuf) { - cJSON *config_root, *about_box, *unlock_key; - - config_root = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - - if (config_root) { - //printf("config.json parse OK.\n"); - about_box = cJSON_GetObjectItem(config_root, "about_box"); - //nic_name = cJSON_GetObjectItem(about_box, "NIC name"); - unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); - - ///read config.json - - cJSON /**dataset_ver,*/ *root; - char* JsonString = NULL; - root = cJSON_CreateObject(); - - /*jstr1 = cJSON_CreateString("json test1"); - jstr2 = cJSON_CreateString("json test2"); - jnum1 = cJSON_CreateNumber(4456);*/ - //sys_id = cJSON_CreateString(fetch_mac_addr); - //dataset_ver = cJSON_CreateString("1.0.0"); - //soft_ver = cJSON_CreateString("1.0.0"); - //dataset_ver = cJSON_GetObjectItem(about_box, "dataset version"); - //soft_ver = cJSON_GetObjectItem(about_box, "software version"); - /*license_type = cJSON_CreateString("licensed"); - license_status = cJSON_CreateString("test"); - license_des = cJSON_CreateString("test");*/ - - //printf("\n"); - //printf(unlock_key->valuestring); - //printf("\n"); -#ifdef GY_OS_AMBA - cJSON_AddItemToObject(root, "model_camera", cJSON_CreateNumber(get_g_PTZ_model())); -#else - cJSON_AddItemToObject(root, "model_camera", cJSON_CreateNumber(0)); -#endif - - cJSON_AddItemToObject(root, "unlock_key", cJSON_CreateString(unlock_key->valuestring)); - -#if 0 - char temp_key[512] = { 0 }; - char formatted_mac[30] = { 0 }; - if (strstr(unlock_key->valuestring, "face") != NULL) { - getContractSignature(temp_key, formatted_mac); - } -#endif - - cJSON_AddItemToObject(root, "sys_id", cJSON_CreateString(fetch_mac_addr)); - cJSON_AddItemToObject(root, "dataset_ver", cJSON_CreateString(Buffer_ver)); - char temp_soft_ver[50] = { 0 }; - strcat(temp_soft_ver, APP_VERSION); - strcat(temp_soft_ver, "-"); - strcat(temp_soft_ver, WeightFileModeName); - cJSON_AddItemToObject(root, "soft_ver", cJSON_CreateString(temp_soft_ver)); - cJSON_AddItemToObject(root, "license_type", cJSON_CreateString(http_strLicenseType)); - cJSON_AddItemToObject(root, "license_status", cJSON_CreateString(strLicenseStatus)); - -#ifdef GY_OS_V_SERIES - cJSON_AddItemToObject(root, "v_series", cJSON_CreateString("Yes")); -#else - cJSON_AddItemToObject(root, "v_series", cJSON_CreateString("No")); -#endif - - cJSON_AddItemToObject(root, "events_default_version", cJSON_CreateString(heartbeatData.events_default_version)); - - cJSON_AddItemToObject(root, "CheckIsExistingSpeed", cJSON_CreateNumber(CheckIsExistingSpeed)); - cJSON_AddItemToObject(root, "White_LED", cJSON_CreateNumber(g_camera_white_LED)); - cJSON_AddItemToObject(root, "No_brand", cJSON_CreateNumber(g_check_if_no_brand)); - cJSON_AddItemToObject(root, "sdk_version", cJSON_CreateNumber(g_sdk_version)); - - char licensePATH[1024] = { 0 }; - //strcpy(licensePATH, exePath); - strcpy(licensePATH, "/emmc/plugin/Aida/license.txt"); - - if (!FileExist(licensePATH)) - printf("%s doesn't exist.\n", licensePATH); - else - { - char* fileBuf = ReadAllBytes(licensePATH); - - if (fileBuf) { -#ifdef _DEBUG_AMBA - printf("licensePATH = %s \n", licensePATH); - printf("fileBuf = %s \n", fileBuf); -#endif - cJSON_AddItemToObject(root, "license_file_content", cJSON_CreateString(fileBuf)); - } - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - } - - JsonString = cJSON_PrintUnformatted(root); -#ifdef _DEBUG_AMBA - printf("return json str = %s \n", JsonString); -#endif - strcat(contentBuffer, JsonString); - - if (config_root) { - cJSON_Delete(config_root); - config_root = NULL; - } - - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - - //char Msg[256] = { 0 }; - - strcpy(beforeSendBuffer, contentBuffer); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #21\n"); - - //send(cli_socket, JsonString, sizeof(JsonString), 0); - //int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(JsonString), JsonString); - //if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - //{ - // printf("\nsend error\n"); - //} - //printf("get aida info \n"); - if (root) { - cJSON_Delete(root); - root = NULL; - } - } - else - printf("config.json parse FAIL.\n"); - } - } - closesocket(cli_socket); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/getloading") == 0) //20201222 合併CPU和GPU - { - /*if (!is_connection_authorized(recvBuffer, cli_socket, FALSE)) {} - else*/ { - //printf("\n[web process]start 11\n"); - char AI_fps_tojson[256] = { 0 }; - sprintf(AI_fps_tojson, "%d", AI_fps); - - char temp_CPU_usage[256] = { 0 }; - char temp_GPU_usage[256] = { 0 }; - char temp_AI_fps_tojson[256] = { 0 }; - - strcpy(temp_CPU_usage, CPU_usage); - strcpy(temp_GPU_usage, GPU_usage); - strcpy(temp_AI_fps_tojson, AI_fps_tojson); - - //get_loading(); - if (g_i_get_cpu_loading == 0) - { - g_i_get_cpu_loading = 1; - -#ifdef GY_OS_AMBA - pthread_t thread_id_getloading; - if (pthread_create(&thread_id_getloading, 0, get_loading, NULL)) - printf("\ngetloading thread creation failed\n"); -#endif - } - - //printf("getloading\n"); - - char convert_tojson1[256] = "{\"CPU_USAGE\":"; - char convert_tojson2[256] = ",\"GPU_USAGE\":"; - char convert_tojson3[256] = ",\"FPS\":"; - char convert_tojson4[256] = "}"; - - strcat(contentBuffer, convert_tojson1); - strcat(contentBuffer, temp_CPU_usage); - strcat(contentBuffer, convert_tojson2); - strcat(contentBuffer, temp_GPU_usage); - strcat(contentBuffer, convert_tojson3); - strcat(contentBuffer, temp_AI_fps_tojson); - strcat(contentBuffer, convert_tojson4); - - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - //char Msg[256] = { 0 }; - - strcpy(beforeSendBuffer, contentBuffer); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #22\n"); - } - //printf("\ngetloading \n"); - //if (pPipe != NULL) - // vpclose(pPipe); - closesocket(cli_socket); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/getplayback_list") == 0) //20201222 合併CPU和GPU - { - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - char Msg[BUFSIZE_V2] = { 0 }; - - - pthread_mutex_lock(&mutex_heatmap_jpeg); - DIR *d_file; - struct dirent *dir_file; - d_file = opendir("/emmc/plugin/Aida_data/playback"); - if (d_file) { - while ((dir_file = readdir(d_file)) != NULL) { - if (strlen(dir_file->d_name) >= 17) { - strcat(Msg, dir_file->d_name); - strcat(Msg, ","); - } - } - closedir(d_file); - } - pthread_mutex_unlock(&mutex_heatmap_jpeg); - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #22\n"); - - closesocket(cli_socket); - } -#endif -#ifdef GY_OS_V_SERIES - -#else - else if (strncmp(urlBuffer, "/control?alarm.gpio=",20) == 0) //20201222 合併CPU和GPU - { - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - - char c_alarm_gpio[256] = { 0 }; - memset(c_alarm_gpio, 0x00, sizeof(c_alarm_gpio)); - strcpy(c_alarm_gpio, urlBuffer + 20); - - char Msg[256] = { 0 }; - if (strlen(c_alarm_gpio) == 1 && isdigit(c_alarm_gpio[0])) { - g_control_alarm_gpio = atoi(c_alarm_gpio); - sprintf(Msg, "%d", g_control_alarm_gpio); - } - else { - strcpy(Msg,"Fail."); - } - - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #2299\n"); - - closesocket(cli_socket); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/run_osd_server") == 0) //20201222 合併CPU和GPU - { - - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); -#ifdef GY_OS_AMBA - //OSD server 建立 - pthread_t thread_id_osd; - if (pthread_create(&thread_id_osd, 0, run_osd_server_thread, NULL)) { - printf("\nrun osd server thread creation failed #22\n"); - } -#endif - strcpy(beforeSendBuffer, ""); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #22\n"); - - closesocket(cli_socket); - } -#endif -#ifdef GY_OS_AMBA - else if (strcmp(urlBuffer, "/getcheck_current_resolution") == 0) //20201222 合併CPU和GPU - { - - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - char Msg[256] = { 0 }; - sprintf(Msg, "%d", g_check_current_resolution); - - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #2233\n"); - - closesocket(cli_socket); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/getcountpost") == 0) //20201222 合併CPU和GPU - { - - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - char Msg[256] = { 0 }; - sprintf(Msg, "%d", get_g_counter_index_post()); - - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #252\n"); - - closesocket(cli_socket); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/getcountlong") == 0) //20201222 合併CPU和GPU - { - - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - char Msg[256] = { 0 }; - sprintf(Msg, "%d", get_g_counter_index_long()); - - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #253\n"); - - closesocket(cli_socket); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/getptztest") == 0) //20201222 合併CPU和GPU - { - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - char Msg[256] = { 0 }; - sprintf(Msg, "g_ori_yuv_height:%d,g_ori_yuv_width:%d,g_framesize_height:%d,g_framesize_width:%d", - g_ori_yuv_height, g_ori_yuv_width, g_framesize_height, g_framesize_width); - - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #252\n"); - - closesocket(cli_socket); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/getfree") == 0) //20201222 合併CPU和GPU - { - - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - char Msg[256] = { 0 }; - sprintf(Msg,"%d", get_free_mem_data()); - - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #22\n"); - - closesocket(cli_socket); - } -#endif -#if 1 - else if (strncmp(urlBuffer, "/setcamera",10) == 0) //20201222 合併CPU和GPU - { - - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - char Msg[512] = { 0 }; - sprintf(Msg, "%s", urlBuffer + 10); - printf("\n--------[setcamera]:%s\n", Msg); - - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #2552\n"); - - closesocket(cli_socket); - } -#endif - else if (strcmp(urlBuffer, "/exit_gynet") == 0) //20201222 合併CPU和GPU - { - - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - - char Msg[256] = { 0 }; - sprintf(Msg, "%d", g_change_getnetwork_buffer_id); - - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #212\n"); - - closesocket(cli_socket); - - if (g_change_getnetwork_buffer_id == 1) { - usSleep(2000000); -#ifdef GY_OS_AMBA - printf("\n-----------------------get network buffer id# 2: exit-----------------------\n"); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "getnetwork_buffer_id change"); - write_to_logs_html(temp_msg, "exit gynet", "CGI_REBOOT", "Yes"); - write_to_log_if_error(temp_msg, "exit gynet", "CGI_REBOOT"); - - pthread_t auto_reboot_thread_id; - if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) - { - printf("\ncreate auto reboot thread faile \n"); - } -#endif - } - } -#ifdef GY_OS_AMBA - else if (strcmp(urlBuffer, "/get_cur_pos") == 0) //20201222 合併CPU和GPU - { - //UpdatePTZCurPos(); - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - char Msg[512] = { 0 }; - sprintf(Msg, "{\"pan\":\"%d\",\"tilt\":\"%d\",\"zoom\":\"%d\"}", g_stPTZ_Handle.iPanABS, g_stPTZ_Handle.iTiltABS, g_stPTZ_Handle.iZoomABS); - //strcpy(Msg,"hello"); - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #2882\n"); - - closesocket(cli_socket); - } -#endif -#if 0 - else if (strcmp(urlBuffer, "/clean_face_list") == 0) //20201222 合併CPU和GPU - { - start_to_import_file = 0; - - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - char Msg[256] = { 0 }; - sprintf(Msg, "%s", "OK"); - - { - //清空黑白名單資料庫 - char urlBuffer_4[256] = "/set_search_info?clean=watch"; - char urlBuffer_5[256] = "/set_search_info?clean=vip"; - char urlBuffer_6[256] = "/set_search_info?clean=log"; - char urlBuffer_7[256] = "/set_search_info?clean=visitor"; - char urlBuffer_8[256] = "/set_search_info?clean=mapping"; - - - memcpy(firstBuffer, urlBuffer_4, strlen(urlBuffer_4)); - firstBuffer[strlen(urlBuffer_4)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 17); - cgi_set_search_info_face(cli_socket, beforeSendBuffer); - - memcpy(firstBuffer, urlBuffer_5, strlen(urlBuffer_5)); - firstBuffer[strlen(urlBuffer_5)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 17); - cgi_set_search_info_face(cli_socket, beforeSendBuffer); - - memcpy(firstBuffer, urlBuffer_6, strlen(urlBuffer_6)); - firstBuffer[strlen(urlBuffer_6)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 17); - cgi_set_search_info_face(cli_socket, beforeSendBuffer); - - memcpy(firstBuffer, urlBuffer_7, strlen(urlBuffer_7)); - firstBuffer[strlen(urlBuffer_7)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 17); - cgi_set_search_info_face(cli_socket, beforeSendBuffer); - - memcpy(firstBuffer, urlBuffer_8, strlen(urlBuffer_8)); - firstBuffer[strlen(urlBuffer_8)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 17); - cgi_set_search_info_face(cli_socket, beforeSendBuffer); - } - - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #2fff2\n"); - - closesocket(cli_socket); - } - -#endif -#if defined GY_OS_AMBA || defined GY_OS_NOVA - else if (strcmp(urlBuffer, "/clean_lpr_list") == 0) //20201222 合併CPU和GPU - { - start_to_import_file = 0; - - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - char Msg[256] = { 0 }; - sprintf(Msg, "%s", "OK"); - - { - //清空黑白名單資料庫 - char urlBuffer_4[256] = "/set_search_info?clean=black"; - char urlBuffer_5[256] = "/set_search_info?clean=white"; - - memcpy(firstBuffer, urlBuffer_4, strlen(urlBuffer_4)); - firstBuffer[strlen(urlBuffer_4)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 17); - cgi_set_search_info(cli_socket, beforeSendBuffer); - - memcpy(firstBuffer, urlBuffer_5, strlen(urlBuffer_5)); - firstBuffer[strlen(urlBuffer_5)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 17); - cgi_set_search_info(cli_socket, beforeSendBuffer); - } - - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #2fff2\n"); - - closesocket(cli_socket); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/get_pause_time") == 0) - { - - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - - char MSG[50] = { 0 }; - sprintf(MSG,"%ld", g_image_HD_pasue_time); - strcpy(beforeSendBuffer, MSG); - - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #212\n"); - - closesocket(cli_socket); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/get_play_video") == 0) - { - - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - - if (g_video_start_HD == 1) { - strcpy(beforeSendBuffer, "Yes"); - } - else { - strcpy(beforeSendBuffer, "No"); - } - - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #212\n"); - - closesocket(cli_socket); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/play_video") == 0) - { - - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - - if (g_video_start_HD == 0) { - g_video_start_HD = 1; - strcpy(beforeSendBuffer, "Yes"); - } - else { - g_video_start_HD = 0; - strcpy(beforeSendBuffer, "No"); - } - - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #212\n"); - - closesocket(cli_socket); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/get_framesize_HD") == 0) - { - - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - char Msg[256] = { 0 }; - sprintf(Msg, "{\"width_HD\":\"%d\",\"height_HD\":\"%d\"}", g_framesize_width_HD, g_framesize_height_HD); - - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #22\n"); - - closesocket(cli_socket); - } -#endif -#if 1 -#ifdef GY_OS_V_SERIES - -#else - else if (strcmp(urlBuffer, "/reset_counter") == 0) - { - - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || -#ifdef GY_OS_NOVA - IsANPRCategory(featureType) || -#endif - g_IsCustomWeight == 1) { - pthread_mutex_lock(&mutex_reset_counter); - time_t now_time = g_osdSysTimeStamp; - if (now_time < 1000000000) { - now_time = time(0); - } - - for (int j = 0; j < MAX_EVENT_COUNTERS; j++) - { - reset_counter(j, now_time); - } - reset_onvif(); - - pthread_mutex_unlock(&mutex_reset_counter); - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #2212\n"); - - closesocket(cli_socket); - } -#endif -#endif -#if 1 -#ifdef GY_OS_V_SERIES - -#else - else if (strncmp(urlBuffer, "/resetcounting?counter_id=",26) == 0) - { - char c_counting_index[256] = { 0 }; - memset(c_counting_index, 0x00, sizeof(c_counting_index)); - strcpy(c_counting_index, urlBuffer + 26); - - int index_counting = -1; - if (strlen(c_counting_index) >= 1) { - if (strcmp(c_counting_index, "1") == 0) { - index_counting = 0; - } - else if (strcmp(c_counting_index, "2") == 0) { - index_counting = 1; - } - else if (strcmp(c_counting_index, "3") == 0) { - index_counting = 2; - } - else if (strcmp(c_counting_index, "4") == 0) { - index_counting = 3; - } - else if (strcmp(c_counting_index, "5") == 0) { - index_counting = 4; - } - else if (strcmp(c_counting_index, "6") == 0) { - index_counting = 5; - } - else if (strcmp(c_counting_index, "7") == 0) { - index_counting = 6; - } - else if (strcmp(c_counting_index, "8") == 0) { - index_counting = 7; - } - } - - if (index_counting >= 0) { - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || -#ifdef GY_OS_NOVA - IsANPRCategory(featureType) || -#endif - g_IsCustomWeight == 1) { - pthread_mutex_lock(&mutex_reset_counter); - time_t now_time = g_osdSysTimeStamp; - if (now_time < 1000000000) { - now_time = time(0); - } - reset_counter(index_counting, now_time); - reset_certain_counter_onvif(index_counting); - pthread_mutex_unlock(&mutex_reset_counter); - } - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #2312\n"); - - closesocket(cli_socket); - } -#endif -#endif -#if 1 -#ifdef GY_OS_V_SERIES - -#else - else if (strncmp(urlBuffer, "/getcounting?counter_id=", 24) == 0) - { - char c_counting_index[256] = { 0 }; - memset(c_counting_index, 0x00, sizeof(c_counting_index)); - strcpy(c_counting_index, urlBuffer + 24); - - int index_counting = -1; - if (strlen(c_counting_index) >= 1) { - if (strcmp(c_counting_index, "1") == 0) { - index_counting = 0; - } - else if (strcmp(c_counting_index, "2") == 0) { - index_counting = 1; - } - else if (strcmp(c_counting_index, "3") == 0) { - index_counting = 2; - } - else if (strcmp(c_counting_index, "4") == 0) { - index_counting = 3; - } - else if (strcmp(c_counting_index, "5") == 0) { - index_counting = 4; - } - else if (strcmp(c_counting_index, "6") == 0) { - index_counting = 5; - } - else if (strcmp(c_counting_index, "7") == 0) { - index_counting = 6; - } - else if (strcmp(c_counting_index, "8") == 0) { - index_counting = 7; - } - } - - if (index_counting >= 0) { - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || -#ifdef GY_OS_NOVA - IsANPRCategory(featureType) || -#endif - g_IsCustomWeight == 1) { - sprintf(beforeSendBuffer,"%d", eventCounterList[index_counting].counter_count); - } - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #2312\n"); - - closesocket(cli_socket); - } -#endif -#endif -#if 1 -#ifdef GY_OS_V_SERIES - -#else - else if (strcmp(urlBuffer, "/get_counter") == 0) - { - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || -#ifdef GY_OS_NOVA - IsANPRCategory(featureType) || -#endif - g_IsCustomWeight == 1) { - char temp_count[256] = { 0 }; - char temp_buf[256] = { 0 }; - for (int index_j = 0; index_j < MAX_EVENT_COUNTERS; index_j++) - { - sprintf(temp_count, "%d", eventCounterList[index_j].counter_count); - strcat(temp_buf, temp_count); - if(index_j < MAX_EVENT_COUNTERS - 1) - strcat(temp_buf, ","); - } - strcpy(beforeSendBuffer, temp_buf); - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #2312\n"); - - closesocket(cli_socket); - } -#endif -#endif -#if 1 -#ifdef GY_OS_V_SERIES - -#else - else if (strcmp(urlBuffer, "/get_counter_cust_name") == 0) - { - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || -#ifdef GY_OS_NOVA - IsANPRCategory(featureType) || -#endif - g_IsCustomWeight == 1) { - char temp_count[1024] = { 0 }; - char temp_buf[1024] = { 0 }; - for (int index_j = 0; index_j < MAX_EVENT_COUNTERS; index_j++) - { - sprintf(temp_count, "%s", eventCounterList[index_j].counter_cust_name); - strcat(temp_buf, temp_count); - if (index_j < MAX_EVENT_COUNTERS - 1) - strcat(temp_buf, ","); - } - strcpy(beforeSendBuffer, temp_buf); - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #2382\n"); - - closesocket(cli_socket); - } -#endif -#endif -#if 1 - else if (strcmp(urlBuffer, "/get_check_if_illegal_id_or_pass") == 0) - { - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - - int check_if_illegal_id_or_pass = 0; - /* - if (strstr(accountData[0].account_username, "?") != NULL || - strstr(accountData[0].account_username, ":") != NULL || - strstr(accountData[0].account_username, "/") != NULL || - strstr(accountData[0].account_username, " ") != NULL || - strstr(accountData[0].account_username, "@") != NULL || - strstr(accountData[0].account_username, "#") != NULL || - strstr(accountData[0].account_password, "?") != NULL || - strstr(accountData[0].account_password, ":") != NULL || - strstr(accountData[0].account_password, "/") != NULL || - strstr(accountData[0].account_password, " ") != NULL || - strstr(accountData[0].account_password, "@") != NULL || - strstr(accountData[0].account_password, "#") != NULL) { - check_if_illegal_id_or_pass = 1; - }*/ - - char Msg[256] = { 0 }; - sprintf(Msg, "%d", check_if_illegal_id_or_pass); - - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #22\n"); - - closesocket(cli_socket); - } -#endif - else if (strcmp(urlBuffer, "/getbar") == 0) - { - - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - char Msg[256] = { 0 }; -#ifdef GY_OS_AMBA - if (get_g_check_if_differ_image_is_running() == 1) { - sprintf(Msg, "%d", get_g_progress_bar()); - } - else { - sprintf(Msg, "%d", -1); - } -#else - sprintf(Msg, "%d", get_g_progress_bar()); -#endif - - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #213\n"); - - closesocket(cli_socket); - } -#if 1 - else if (strncmp(urlBuffer, "/do_a_test_to_post&index=",25) == 0) - { - //printf("\n[do a test to post]return contentBuffer = %s \n", contentBuffer); - long int last_do_a_test, now_do_a_test; - struct timeval currtime_do_a_test; - gettimeofday(&currtime_do_a_test, NULL); - last_do_a_test = (currtime_do_a_test.tv_sec * 1000) + (currtime_do_a_test.tv_usec / 1000); - - char index_post[50] = { 0 }; - strcpy(index_post, urlBuffer + 25); - - int index_j = atoi(index_post); - - QueueInfo q_info = { 0 }; - strcpy(q_info.post_protocol, postEventList[index_j].post_protocol); - strcpy(q_info.post_method, postEventList[index_j].post_event_method); - strcpy(q_info.host_name, postEventList[index_j].post_host_ip); - strcpy(q_info.host_port, postEventList[index_j].post_host_port); - strcpy(q_info.post_url, postEventList[index_j].post_url); - strcpy(q_info.post_username, postEventList[index_j].post_username); - strcpy(q_info.post_password, postEventList[index_j].post_password); - strcpy(q_info.post_jpeg_file_name, postEventList[index_j].post_jpeg_file_name); - - if (strcmp(postEventList[index_j].post_jpeg_file_name_format, "fixed")) { - q_info.enable_filename_fixed = 1; - } - else { - q_info.enable_filename_fixed = 0; - } - - - if (strlen(postEventList[index_j].post_customized_header) >= 1) { - strcpy(q_info.post_customized_header, postEventList[index_j].post_customized_header); - } - else - q_info.post_customized_header[0] = '\0'; - - - if (strcmp(postEventList[index_j].post_file_format, "text") == 0) { - q_info.enable_attached_image = 0; - if (strlen(postEventList[index_j].post_content) >= 1) { - char *replacement_t = NULL; - - replacement_t = StrReplace(postEventList[index_j].post_content, "<|snap_image|>", g_current_snapshot_addr_base64); - strcpy(q_info.content, replacement_t); - - if (replacement_t != NULL) { - free(replacement_t); - replacement_t = NULL; - } - - q_info.content_size = strlen(q_info.content); - } - else - q_info.content[0] = '\0'; - } - else if (strcmp(postEventList[index_j].post_file_format, "jpeg") == 0) { - q_info.enable_attached_image = 1; - if (strlen(postEventList[index_j].post_content) >= 1) { - strcpy(q_info.content, postEventList[index_j].post_content); - q_info.content_size = strlen(postEventList[index_j].post_content); - } - else - q_info.content[0] = '\0'; - } - else { - q_info.enable_attached_image = 0; - q_info.content[0] = '\0'; - } - - - pthread_mutex_lock(&mutex_set_http_request); - struct timeval currtime_set_http_request; - gettimeofday(&currtime_set_http_request, NULL); - long current_ms_set_http_request = (currtime_set_http_request.tv_sec * 1000) + (currtime_set_http_request.tv_usec / 1000); - long last_ms_set_http_request = current_ms_set_http_request; - - int check_if_time_is_too_long = 0; - - g_response_post_OK = 0; -#ifdef GY_OS_NOVA - - if (strcmp(q_info.host_name, "127.0.0.1") != 0 && strcmp(q_info.host_name, "localhost") != 0) { - SetHttpRequest(&q_info, sendBuffer, q_info.post_method); - } - else { - SetHttpRequest_sock(&q_info, sendBuffer, q_info.post_method); - } -#endif -#ifdef GY_OS_AMBA - SetHttpRequest(&q_info, sendBuffer, q_info.post_method); -#endif - while (g_response_post_OK == 0) { - if (current_ms_set_http_request > last_ms_set_http_request + 10000) { - check_if_time_is_too_long = 1; - break; - } - - gettimeofday(&currtime_set_http_request, NULL); - current_ms_set_http_request = (currtime_set_http_request.tv_sec * 1000) + (currtime_set_http_request.tv_usec / 1000); - usSleep(1000); - } - - gettimeofday(&currtime_do_a_test, NULL); - now_do_a_test = (currtime_do_a_test.tv_sec * 1000) + (currtime_do_a_test.tv_usec / 1000); //單位為毫秒 - - if (check_if_time_is_too_long == 0) { - //strcpy(beforeSendBuffer, g_response_net_curl); - sprintf(beforeSendBuffer,"%s, Time:%ld ms, Size:%ld Bytes", g_response_net_curl, (now_do_a_test- last_do_a_test), (long int)q_info.content_size); - } - else { - //strcpy(beforeSendBuffer, "The Post time is too long (> 10 secs). We cannot continue to wait it."); - sprintf(beforeSendBuffer,"%s, Time:%ld ms, Size:%ld Bytes", "The Post time is too long (> 10 secs). We cannot continue to wait it.", (now_do_a_test - last_do_a_test), (long int)q_info.content_size); - } - g_response_post_OK = 0; - pthread_mutex_unlock(&mutex_set_http_request); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #2122\n"); - - closesocket(cli_socket); - } -#endif -#ifdef GY_OS_AMBA - else if (strncmp(urlBuffer, "/do_a_snmp_to_post&index=", 25) == 0) - { - //printf("\n[do a test to post]return contentBuffer = %s \n", contentBuffer); - char index_post[50] = { 0 }; - strcpy(index_post, urlBuffer + 25); - - int index_j = atoi(index_post); - - if (SNMPManagementList[index_j].check_if_delivering == 0) { - SNMPManagementList[index_j].check_if_delivering = 1; - - static long last_do_a_test, now_do_a_test; - struct timeval currtime_do_a_test; - gettimeofday(&currtime_do_a_test, NULL); - last_do_a_test = (currtime_do_a_test.tv_sec * 1000) + (currtime_do_a_test.tv_usec / 1000); - - QueueInfo q_info = { 0 }; - strcpy(q_info.snmp_event_name, SNMPManagementList[index_j].snmp_event_name); - strcpy(q_info.snmp_version, SNMPManagementList[index_j].snmp_version); - strcpy(q_info.snmp_group_name, SNMPManagementList[index_j].snmp_group_name); - strcpy(q_info.snmp_host_ip, SNMPManagementList[index_j].snmp_host_ip); - strcpy(q_info.snmp_host_port, SNMPManagementList[index_j].snmp_host_port); - strcpy(q_info.snmp_oid, SNMPManagementList[index_j].snmp_oid); - strcpy(q_info.snmp_value, SNMPManagementList[index_j].snmp_value); - strcpy(q_info.snmp_type, SNMPManagementList[index_j].snmp_type); - - SetSNMPRequest(&q_info); - - gettimeofday(&currtime_do_a_test, NULL); - now_do_a_test = (currtime_do_a_test.tv_sec * 1000) + (currtime_do_a_test.tv_usec / 1000); //單位為毫秒 - - { - //strcpy(beforeSendBuffer, g_response_net_curl); - sprintf(beforeSendBuffer, "%s, Time:%ld ms", g_response_snmp, now_do_a_test - last_do_a_test); - } - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #21122\n"); - - closesocket(cli_socket); - } -#endif -#ifdef GY_OS_AMBA - else if (strcmp(urlBuffer, "/getdebugplate") == 0) - { - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - pthread_mutex_lock(&mutex_run_one_net); - strcpy(beforeSendBuffer, g_debug_plate); - pthread_mutex_unlock(&mutex_run_one_net); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #22\n"); - - closesocket(cli_socket); - } - -#endif -#if defined GY_OS_AMBA || defined GY_OS_NOVA - else if (strcmp(urlBuffer, "/get_g_count_lpr_insert_times") == 0) - { - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - char Msg[256] = { 0 }; - sprintf(Msg, "%d", g_count_lpr_insert_times); - - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #22232\n"); - - closesocket(cli_socket); - } -#endif - else if (strcmp(urlBuffer, "/getplugin") == 0) //get aida port - { - //printf("\n[web process]start 11-2\n"); - char filename[1024] = { 0 }; - strcat(filename,"/www/plugin/json/CameraPlug-in.json"); - if (!FileExist(filename)) - printf("%s doesn't exist.\n", filename); - else{ - //size_t nfileSize = ReadFileSize(filename); - char* fileBuf = ReadAllBytes(filename); - if (fileBuf) { - cJSON *plugin; - - plugin = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - - if (plugin) { - - char* JsonString = NULL; - JsonString = cJSON_PrintUnformatted(plugin); - strcat(contentBuffer, JsonString); - - if (plugin) { - cJSON_Delete(plugin); - plugin = NULL; - } - - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - - //char Msg[256] = { 0 }; - - strcpy(beforeSendBuffer, contentBuffer); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #21-2\n"); - - } - else - printf("CameraPlug-in.json parse FAIL.\n"); - } - } - closesocket(cli_socket); - } - else if (strcmp(urlBuffer, "/set_no_brand") == 0) //get aida port - { - //printf("\n[web process]start 12\n"); - char Cmd[MAX_CMD_SIZE] = { 0 }; - int check_if_set_no_brand = 0; - /* - char Cmd[MAX_CMD_SIZE] = { 0 }; - strcpy(Cmd, urlBuffer + 16); - int check_if_not_digit = 0; - for (int i = 0; i < strlen(Cmd); i++) - { - if (!isdigit(Cmd[i])) - { - check_if_not_digit = 1; - break; - } - }*/ - //if (check_if_not_digit == 0) - { - //printf("\nKKKK: Cmd: %s\n",Cmd); - /*int port_number = atoi(Cmd); - if (port_number < 0 && port_number > 65535) { - if (strlen(accountData[0].account_aida_port) >= 1) - port_number = atoi(accountData[0].account_aida_port); - } - //printf("\nKKKKKKKKK: port_number: %d\n",port_number); - char port_number_char[256] = { 0 }; - sprintf(port_number_char, "%d", port_number);*/ - - char filename[1024] = { 0 }; - strcat(filename, "/www/plugin/json/CameraPlug-in.json"); - if (!FileExist(filename)) - printf("%s doesn't exist.\n", filename); - else { - char* fileBuf = ReadAllBytes(filename); - if (fileBuf) { - cJSON *plugin; - - plugin = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - - if (plugin) { - //printf("config.json parse OK.\n"); - char* JsonString = NULL; - - char temp_version[256] = { 0 }; - sprintf(temp_version,"%s-%s", APP_VERSION, WeightFileModeName); - - cJSON_ReplaceItemInObject(plugin, "description", cJSON_CreateString("Camera Plug-in")); - cJSON_ReplaceItemInObject(plugin, "homepage", cJSON_CreateString("")); - cJSON_ReplaceItemInObject(plugin, "author", cJSON_CreateString("")); - cJSON_ReplaceItemInObject(plugin, "version", cJSON_CreateString(temp_version)); - - JsonString = cJSON_Print(plugin); - FILE *fp; - - if ((fp = fopen(filename, "w")) != NULL) - { - fprintf(fp, JsonString); - strcpy(Cmd,JsonString); - check_if_set_no_brand = 1; - fclose(fp); - } - else - { - printf("%s cannot open.\n", filename); - } - - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - - if (plugin) { - cJSON_Delete(plugin); - plugin = NULL; - } - } - else - printf("CameraPlug-in.json parse FAIL.\n"); - } - } - } - - if (strlen(Cmd) >= 1) { - strcpy(beforeSendBuffer, Cmd); - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #252-3\n"); - - closesocket(cli_socket); - - if (check_if_set_no_brand == 1) { - printf("\n[--------Set no brand successfully-------]: We will close gynet.exe with the no brand. Please restart gynet.exe with the new brand.\n"); - usSleep(1000); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "We will close gynet.exe with the no brand. Please restart gynet.exe with the new brand."); - write_to_logs_html(temp_msg, "set no brand", "CGI_REBOOT", "Yes"); - write_to_log_if_error(temp_msg, "set no brand", "CGI_REBOOT"); - - pthread_t auto_reboot_thread_id; - if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) - { - printf("create auto reboot thread faile \n"); - } - } - } - else if (strcmp(urlBuffer, "/set_lilin") == 0) //get aida port - { - //printf("\n[web process]start 12\n"); - char Cmd[MAX_CMD_SIZE] = { 0 }; - int check_if_set_lilin = 0; - /* - char Cmd[MAX_CMD_SIZE] = { 0 }; - strcpy(Cmd, urlBuffer + 16); - int check_if_not_digit = 0; - for (int i = 0; i < strlen(Cmd); i++) - { - if (!isdigit(Cmd[i])) - { - check_if_not_digit = 1; - break; - } - }*/ - //if (check_if_not_digit == 0) - { - //printf("\nKKKK: Cmd: %s\n",Cmd); - /*int port_number = atoi(Cmd); - if (port_number < 0 && port_number > 65535) { - if (strlen(accountData[0].account_aida_port) >= 1) - port_number = atoi(accountData[0].account_aida_port); - } - //printf("\nKKKKKKKKK: port_number: %d\n",port_number); - char port_number_char[256] = { 0 }; - sprintf(port_number_char, "%d", port_number);*/ - - char filename[1024] = { 0 }; - strcat(filename, "/www/plugin/json/CameraPlug-in.json"); - if (!FileExist(filename)) - printf("%s doesn't exist.\n", filename); - else { - char* fileBuf = ReadAllBytes(filename); - if (fileBuf) { - cJSON *plugin; - - plugin = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - - if (plugin) { - //printf("config.json parse OK.\n"); - char* JsonString = NULL; - - char temp_version[256] = { 0 }; - sprintf(temp_version, "%s-%s", APP_VERSION, WeightFileModeName); - - cJSON_ReplaceItemInObject(plugin, "description", cJSON_CreateString("LILIN Aida Camera Plug-in")); - cJSON_ReplaceItemInObject(plugin, "homepage", cJSON_CreateString("http://www.meritlilin.com")); - cJSON_ReplaceItemInObject(plugin, "author", cJSON_CreateString("LILIN ")); - cJSON_ReplaceItemInObject(plugin, "version", cJSON_CreateString(temp_version)); - - JsonString = cJSON_Print(plugin); - FILE *fp; - - if ((fp = fopen(filename, "w")) != NULL) - { - fprintf(fp, JsonString); - strcpy(Cmd, JsonString); - check_if_set_lilin = 1; - fclose(fp); - } - else - { - printf("%s cannot open.\n", filename); - } - - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - - if (plugin) { - cJSON_Delete(plugin); - plugin = NULL; - } - } - else - printf("CameraPlug-in.json parse FAIL.\n"); - } - } - } - - if (strlen(Cmd) >= 1) { - strcpy(beforeSendBuffer, Cmd); - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #252-32\n"); - - closesocket(cli_socket); - - if (check_if_set_lilin == 1) { - printf("\n[--------Set lilin successfully-------]: We will close gynet.exe with the lilin brand. Please restart gynet.exe with the new brand.\n"); - usSleep(1000); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "We will close gynet.exe with the lilin brand. Please restart gynet.exe with the new brand."); - write_to_logs_html(temp_msg, "set lilin", "CGI_REBOOT", "Yes"); - write_to_log_if_error(temp_msg, "set lilin", "CGI_REBOOT"); - - pthread_t auto_reboot_thread_id; - if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) - { - printf("create auto reboot thread faile \n"); - } - } - } - else if (strncmp(urlBuffer, "/setplugin?port=",16) == 0) //get aida port - { - //printf("\n[web process]start 12\n"); - char Cmd[MAX_CMD_SIZE] = { 0 }; - strcpy(Cmd, urlBuffer + 16); - int check_if_not_digit = 0; - for (int i = 0; i < strlen(Cmd); i++) - { - if (!isdigit(Cmd[i])) - { - check_if_not_digit = 1; - break; - } - } - if (check_if_not_digit == 0) - { - //printf("\nKKKK: Cmd: %s\n",Cmd); - int port_number = atoi(Cmd); - if (port_number < 0 && port_number > 65535) { - if(strlen(accountData[0].account_aida_port)>=1) - port_number = atoi(accountData[0].account_aida_port); - } - //printf("\nKKKKKKKKK: port_number: %d\n",port_number); - char port_number_char[256] = { 0 }; - sprintf(port_number_char, "%d", port_number); - - char filename[1024] = { 0 }; - strcat(filename, "/www/plugin/json/CameraPlug-in.json"); - if (!FileExist(filename)) - printf("%s doesn't exist.\n", filename); - else { - char newline_char[BUFFER_SIZE] = { 0 }; - strcpy(newline_char, "/emmc/plugin/Aida_data/mon -s 2 \"/emmc/plugin/Aida_data/gynet server -http_port "); - strcat(newline_char, port_number_char); - strcat(newline_char, "\" &\n"); - - //printf("%s",newline_char); - - replace_one_line_in_a_file("/emmc/plugin/Aida_data/aiengine", 31, newline_char); - FILE * pPipe2; - char cmd2[256] = { 0 }; - strcpy(cmd2, "chmod 777 /emmc/plugin/Aida_data/aiengine"); - pPipe2 = vpopen(cmd2, "r"); - if (pPipe2 != NULL) - vpclose(pPipe2); - - char* fileBuf = ReadAllBytes(filename); - if (fileBuf) { - cJSON *plugin; - - plugin = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - - if (plugin) { - //printf("config.json parse OK.\n"); - char* JsonString = NULL; - - cJSON_ReplaceItemInObject(plugin, "port", cJSON_CreateString(port_number_char)); - - JsonString = cJSON_Print(plugin); - FILE *fp; - - if ((fp = fopen(filename, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - } - else - { - printf("%s cannot open.\n", filename); - } - - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - - if (plugin) { - cJSON_Delete(plugin); - plugin = NULL; - } - } - else - printf("CameraPlug-in.json parse FAIL.\n"); - } - } - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #22-3\n"); - - closesocket(cli_socket); - - if (check_if_not_digit == 0) { - printf("\n[--------Set aida port successfully-------]: We will close gynet.exe with the old port. Please restart gynet.exe with the new port.\n"); - usSleep(1000); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "We will close gynet.exe with the old port. Please restart gynet.exe with the new port."); - write_to_logs_html(temp_msg, "set new port", "CGI_REBOOT", "Yes"); - write_to_log_if_error(temp_msg, "set new port", "CGI_REBOOT"); - - pthread_t auto_reboot_thread_id; - if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) - { - printf("create auto reboot thread faile \n"); - } - } - } - else if (strncmp(urlBuffer, "/setplugin?desc=", 16) == 0) //get aida port - { - //printf("\n[web process]start 12\n"); - char filename[1024] = { 0 }; - strcat(filename, "/www/plugin/json/CameraPlug-in.json"); - if (!FileExist(filename)) - printf("%s doesn't exist.\n", filename); - else { - char Cmd[MAX_CMD_SIZE] = { 0 }; - memset(Cmd, 0x00, sizeof(Cmd)); - strcpy(Cmd, urlBuffer + 16); - - char name_char[8192*4] = { 0 }; - sprintf(name_char, "%s", Cmd); - - char* fileBuf = ReadAllBytes(filename); - if (fileBuf) { - cJSON *plugin; - - plugin = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - - if (plugin) { - //printf("config.json parse OK.\n"); - char* JsonString = NULL; - - //cJSON_ReplaceItemInObject(plugin, "name", cJSON_CreateString(name_char)); //LILIN Aida Camera Plug-in - cJSON_ReplaceItemInObject(plugin, "description", cJSON_CreateString(name_char)); //LILIN Aida Camera Plug-in - - JsonString = cJSON_Print(plugin); - FILE *fp; - - if ((fp = fopen(filename, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - } - else - { - printf("%s cannot open.\n", filename); - } - - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - - if (plugin) { - cJSON_Delete(plugin); - plugin = NULL; - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #22-33\n"); - - closesocket(cli_socket); - } - else - printf("CameraPlug-in.json parse FAIL.\n"); - } - } - } - else if (strcmp(urlBuffer, "/getipcamsettings") == 0) //get current ipcam settings - { - //printf("\n[web process]start 13\n"); - //printf("getipcamport\n"); - - char convert_tojson1[256] = "{\"IPCAM_PORT\":\""; - /*char convert_tojson2[256] = "\","; - char convert_tojson3[256] = "\"IPCAM_MIRROR\":\""; - char convert_tojson4[256] = "\","; - char convert_tojson5[256] = "\"IPCAM_FLIP\":\""; - char convert_tojson6[256] = "\","; - char convert_tojson7[256] = "\"IPCAM_ROTATE\":\"";*/ - char convert_tojson8[256] = "\"}"; - - strcat(contentBuffer, convert_tojson1); - strcat(contentBuffer, g_account_port_protected); - /* - strcat(contentBuffer, convert_tojson2); - - strcat(contentBuffer, convert_tojson3); - strcat(contentBuffer, accountData[0].account_mirror); - strcat(contentBuffer, convert_tojson4); - - strcat(contentBuffer, convert_tojson5); - strcat(contentBuffer, accountData[0].account_flip); - strcat(contentBuffer, convert_tojson6); - - strcat(contentBuffer, convert_tojson7); - strcat(contentBuffer, accountData[0].account_rotate);*/ - strcat(contentBuffer, convert_tojson8); - - //printf("\n[getipcamport]return contentBuffer = %s \n", contentBuffer); - - //char Msg[256] = { 0 }; - - strcpy(beforeSendBuffer, contentBuffer); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #23\n"); - - //printf("\ngetipcamport \n"); - - closesocket(cli_socket); - } - else if (strcmp(urlBuffer, "/sync_service") == 0) //get current ipcam settings - { - copy_ipcam_smtp_service_to_gynet(); - - strcpy(beforeSendBuffer, ""); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #2355\n"); - - //printf("\ngetipcamport \n"); - - closesocket(cli_socket); - } - else if (strcmp(urlBuffer, "/service?get=all") == 0) //get current ipcam settings - { - //printf("\n[web process]start 13\n"); - //printf("getipcamport\n"); - - char convert_tojson1[256] = "{\"EMAIL_ADDRESS1\":\""; - char convert_tojson2[256] = "\","; - char convert_tojson3[256] = "\"EMAIL_ADDRESS2\":\""; - char convert_tojson4[256] = "\","; - char convert_tojson5[256] = "\"EMAIL_ADDRESS3\":\""; - char convert_tojson6[256] = "\","; - char convert_tojson7[256] = "\"EMAIL_ADDRESS4\":\""; - char convert_tojson8[256] = "\","; - char convert_tojson9[256] = "\"EMAIL_ADDRESS5\":\""; - char convert_tojson10[256] = "\","; - char convert_tojson11[256] = "\"EMAIL_ADDRESS\":\""; - char convert_tojson12[256] = "\","; - char convert_tojson13[256] = "\"SMTP_SERVER\":\""; - char convert_tojson14[256] = "\","; - char convert_tojson15[256] = "\"SMTP_AUTH_MODE\":"; - char convert_tojson16[256] = ","; - char convert_tojson17[256] = "\"SMTP_PORT\":\""; - char convert_tojson18[256] = "\","; - char convert_tojson19[256] = "\"SMTP_AUTH\":"; - char convert_tojson20[256] = ","; - char convert_tojson21[256] = "\"AUTH_ACCOUNT\":\""; - char convert_tojson22[256] = "\"}"; - - strcat(contentBuffer, convert_tojson1); - strcat(contentBuffer, IPCAMService.email_address1); - strcat(contentBuffer, convert_tojson2); - - strcat(contentBuffer, convert_tojson3); - strcat(contentBuffer, IPCAMService.email_address2); - strcat(contentBuffer, convert_tojson4); - - strcat(contentBuffer, convert_tojson5); - strcat(contentBuffer, IPCAMService.email_address3); - strcat(contentBuffer, convert_tojson6); - - strcat(contentBuffer, convert_tojson7); - strcat(contentBuffer, IPCAMService.email_address4); - strcat(contentBuffer, convert_tojson8); - - strcat(contentBuffer, convert_tojson9); - strcat(contentBuffer, IPCAMService.email_address5); - strcat(contentBuffer, convert_tojson10); - - strcat(contentBuffer, convert_tojson11); - strcat(contentBuffer, IPCAMService.email_address); - strcat(contentBuffer, convert_tojson12); - - strcat(contentBuffer, convert_tojson13); - strcat(contentBuffer, IPCAMService.smtp_server); - strcat(contentBuffer, convert_tojson14); - - strcat(contentBuffer, convert_tojson15); - char temp_smtp_auth_mode[10] = { 0 }; - sprintf(temp_smtp_auth_mode,"%d", IPCAMService.smtp_auth_mode); - strcat(contentBuffer, temp_smtp_auth_mode); - strcat(contentBuffer, convert_tojson16); - - strcat(contentBuffer, convert_tojson17); - strcat(contentBuffer, IPCAMService.smtp_port); - strcat(contentBuffer, convert_tojson18); - - strcat(contentBuffer, convert_tojson19); - char temp_smtp_auth[10] = { 0 }; - sprintf(temp_smtp_auth, "%d", IPCAMService.smtp_auth); - strcat(contentBuffer, temp_smtp_auth); - strcat(contentBuffer, convert_tojson20); - - strcat(contentBuffer, convert_tojson21); - strcat(contentBuffer, IPCAMService.auth_account); - strcat(contentBuffer, convert_tojson22); - - strcpy(beforeSendBuffer, contentBuffer); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #2333\n"); - - //printf("\ngetipcamport \n"); - - closesocket(cli_socket); - } -#if 0 - else if (strcmp(urlBuffer, "/set_bypass_login_on") == 0 || strcmp(urlBuffer, "/set_bypass_login_off") == 0) - { - /*printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\nenable_base64: %d\n", enable_base64); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");*/ - //printf("set_bypass_login\n"); - char convert_tojson1[256] = "{\"BYPASS_LOGIN\":\""; - char convert_tojson2[256] = "\"}"; - char bypass_login_on[256] = "on"; - char bypass_login_off[256] = "off"; - - strcat(contentBuffer, convert_tojson1); - - if (strcmp(urlBuffer, "/set_bypass_login_on") == 0) - { - enable_base64 = 0; - strcat(contentBuffer, bypass_login_on); - } - else if (strcmp(urlBuffer, "/set_bypass_login_off") == 0) - { - enable_base64 = 1; - strcat(contentBuffer, bypass_login_off); - } - - strcat(contentBuffer, convert_tojson2); - //printf("\n[set_bypass_login]return contentBuffer = %s \n", contentBuffer); - - strcpy(beforeSendBuffer, contentBuffer); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #24\n"); - - //printf("\nset_bypass_login \n"); - - closesocket(cli_socket); - } -#endif - else if (strncmp(urlBuffer, "/register_session_id?id=", 24) == 0) - { - - - char c_session_id[MAX_SESSION_ID] = { 0 }; - memset(c_session_id, 0x00, sizeof(c_session_id)); - strcpy(c_session_id, urlBuffer + 24); - //printf("\n-----------register session_id:%s\n", c_session_id); - - if (strlen(c_session_id) >= 1) { - for (int i = 0; i < MAX_NUMBER_SESSION; i++) { - if (strlen(g_record_session_id[i]) == 0) { - strcpy(g_record_session_id[i], c_session_id); - break; - } - else if (strcmp(g_record_session_id[i], c_session_id)==0) { - break; - } - else if (i == MAX_NUMBER_SESSION-1) { - for (int j = 0; j < MAX_NUMBER_DELETED_SESSION; j++) { - memset(g_record_session_id[j], 0x00, sizeof(g_record_session_id[j])); - } - for (int j = 0; j < MAX_NUMBER_SESSION- MAX_NUMBER_DELETED_SESSION; j++) { - strcpy(g_record_session_id[j], g_record_session_id[j+ MAX_NUMBER_DELETED_SESSION]); - memset(g_record_session_id[j + MAX_NUMBER_DELETED_SESSION], 0x00, sizeof(g_record_session_id[j + MAX_NUMBER_DELETED_SESSION])); - } - } - } - } - - /* - for (int i = 0; i < MAX_NUMBER_SESSION; i++) { - printf("\n(%d)----session id:%s\n",i, g_record_session_id[i]); - }*/ - - strcpy(contentBuffer," "); - strcpy(beforeSendBuffer, contentBuffer); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #231\n"); - - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/login_session_id?id=", 21) == 0) - { - char c_session_id[MAX_SESSION_ID] = { 0 }; - memset(c_session_id, 0x00, sizeof(c_session_id)); - strcpy(c_session_id, urlBuffer + 21); - //printf("\n-----------login session_id:%s\n", c_session_id); - - if (strlen(c_session_id) >= 1) { - int check_existing_session = 0; - for (int i = 0; i < MAX_NUMBER_SESSION; i++) { - if (strcmp(g_record_session_id[i], c_session_id) == 0) { - check_existing_session = 1; - break; - } - } - if (check_existing_session == 1) { - strcpy(contentBuffer, "Yes"); - } - else { - strcpy(contentBuffer, "No"); - } - } - else { - strcpy(contentBuffer, "No"); - } - - strcpy(beforeSendBuffer, contentBuffer); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #232\n"); - - closesocket(cli_socket); - } -#ifdef GY_OS_AMBA - else if (strncmp(urlBuffer, "/setmetadata?", 13) == 0) { - - int check_if_radar_open = 0; - for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) { - if (strncmp(viewDetectionZone[0][index_zone].enable_speed, "Yes", strlen("Yes")) == 0 /*&& - strncmp(viewDetectionZone[0][index_zone].enable_radar_speed, "Yes", strlen("Yes")) == 0*/) { - check_if_radar_open = 1; - break; - } - } - - if (check_if_radar_open == 1) { - - char Cmd[8192] = { 0 }; - strcpy(Cmd, urlBuffer + 13); - char msg[256] = { 0 }; - - if (strlen(Cmd) >= 1) { - const char *del = "&"; - char a_data_sp[MAX_SIZE_A_SP_OBJECT][STRSPLIT_SIZE]={0}; - int a_data_sp_num = 0; - - const char *del2 = "="; - char a_data_sp_pair[MAX_SIZE_A_SP_OBJECT][2][STRSPLIT_SIZE]={0}; - - float speed_sp = -1.0; //1 - char unit_sp[256] = { 0 }; //2 - float res_width_sp = -1.0; //3 - float res_height_sp = -1.0;; //4 - float x_sp = -1.0; //5 - float y_sp = -1.0; //6 - - a_data_sp_num = StrSplit(Cmd, a_data_sp, del); - //printf("\n------UU:24\n"); - if (a_data_sp_num == MAX_SIZE_A_SP_OBJECT) - { - for (int i = 0; i < a_data_sp_num; i++) - { - if (a_data_sp[i]) - { - //printf("\n%s\n", a_data_osd[i]); - StrSplit(a_data_sp[i], a_data_sp_pair[i], del2); - //printf("\n------UU:25\n"); - if (strlen(a_data_sp_pair[i][0]) >= 1 && strlen(a_data_sp_pair[i][1]) >= 1) { - - if (strcmp(a_data_sp_pair[i][0], "speed") == 0 || - strcmp(a_data_sp_pair[i][0], "Speed") == 0) { - speed_sp = atof(a_data_sp_pair[i][1]); - } - if (strcmp(a_data_sp_pair[i][0], "speed_unit") == 0 || - strcmp(a_data_sp_pair[i][0], "Speed_unit") == 0) { - strcpy(unit_sp, a_data_sp_pair[i][1]); - } - else if (strcmp(a_data_sp_pair[i][0], "res_width") == 0 || - strcmp(a_data_sp_pair[i][0], "res_width") == 0) { - res_width_sp = atof(a_data_sp_pair[i][1]); - } - else if (strcmp(a_data_sp_pair[i][0], "res_height") == 0 || - strcmp(a_data_sp_pair[i][0], "res_height") == 0) { - res_height_sp = atof(a_data_sp_pair[i][1]); - } - else if (strcmp(a_data_sp_pair[i][0], "x") == 0 || - strcmp(a_data_sp_pair[i][0], "X") == 0) { - x_sp = atof(a_data_sp_pair[i][1]); - } - else if (strcmp(a_data_sp_pair[i][0], "y") == 0 || - strcmp(a_data_sp_pair[i][0], "Y") == 0) { - y_sp = atof(a_data_sp_pair[i][1]); - } - } - } - } - } - - int check_if_sp_ok = 1; - - if (speed_sp == -1.0 || strlen(unit_sp) == 0 || res_width_sp == -1.0 || res_height_sp == -1.0 || x_sp == -1.0 || y_sp == -1.0) { - check_if_sp_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: Parameter"); - } - else if (speed_sp < 0) { - check_if_sp_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: speed < 0"); - } - else if (strcmp(unit_sp, "KPH") != 0 && strcmp(unit_sp, "MPH") != 0) { - check_if_sp_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: speed_unit should be KPH or MPH"); - } - else if (res_width_sp <= 0) { - check_if_sp_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: res_width <= 0"); - } - else if (res_height_sp <= 0) { - check_if_sp_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: res_height <= 0"); - } - else if (x_sp <= 0 || x_sp >= res_width_sp) { - check_if_sp_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: x <= 0 || x >= res_width"); - } - else if (y_sp <= 0 || y_sp >= res_height_sp) { - check_if_sp_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: y <= 0 || y >= res_height"); - } - - if (check_if_sp_ok == 1) { - //printf("\n---------%f,%s,%f,%f,%f,%f\n", speed_sp, unit_sp, res_width_sp, res_height_sp, x_sp, y_sp); - for (int i = 0; i < MAX_SIZE_SP_ARRAY; i++) { - if (SpeedData[i].flag_protected == 0) { - SpeedData[i].speed = speed_sp; - strcpy(SpeedData[i].speed_unit, unit_sp); - SpeedData[i].res_width = res_width_sp; - SpeedData[i].res_height = res_height_sp; - SpeedData[i].x = x_sp; - SpeedData[i].y = y_sp; - SpeedData[i].flag_protected = 1; - } - } - strcpy(msg, "HTTP 200 OK, content: OK"); - } - } - - if (strlen(msg) == 0) { - strcpy(msg, "HTTP 200 OK, content: Error: Format"); - } - } - else { - strcpy(msg, "HTTP 200 OK, content: Error: Please enable speed"); - } - - strcpy(beforeSendBuffer_xtra, msg); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #32\n"); - - closesocket(cli_socket); - } -#endif -#if 1 - else if (strncmp(urlBuffer, "/snaphd?index=", 14) == 0) { - pthread_mutex_lock(&mutex_web); - - char snap_hd_index[50] = { 0 }; - memset(snap_hd_index, 0x00, sizeof(snap_hd_index)); - strcpy(snap_hd_index, urlBuffer + 14); - - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #199922\n"); - - int current_hd_index = atoi(snap_hd_index); - - if (current_hd_index >= 0 && current_hd_index < MAX_SNAP_HD_LIST && - snapHDList[current_hd_index].snapshot_size >= 1) - { - if (send(cli_socket, snapHDList[current_hd_index].snapshot_addr, snapHDList[current_hd_index].snapshot_size, MSG_NOSIGNAL) == -1) - printf("\nsend error #19999991\n"); - } - - pthread_mutex_unlock(&mutex_web); - closesocket(cli_socket); - } -#endif -#if 1 - else if (strncmp(urlBuffer, "/snaphd?time=", 13) == 0) { - pthread_mutex_lock(&mutex_web); - - char c_snap_hd_time[50] = { 0 }; - memset(c_snap_hd_time, 0x00, sizeof(c_snap_hd_time)); - strcpy(c_snap_hd_time, urlBuffer + 13); - - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #199922\n"); - - if (strlen(c_snap_hd_time) == 13) { - char c_msec[10] = { 0 }; - c_msec[0] = c_snap_hd_time[10]; - c_msec[1] = c_snap_hd_time[11]; - c_msec[2] = c_snap_hd_time[12]; - c_msec[3] = '\0'; - c_snap_hd_time[10] = '\0'; - c_snap_hd_time[11] = '\0'; - c_snap_hd_time[12] = '\0'; - - time_t snap_hd_time = (time_t)atoll(c_snap_hd_time); - time_t snap_hd_msec = (time_t)atoll(c_msec); - time_t snap_hd_combine_time = snap_hd_time * 1000 + snap_hd_msec; - -#if 0 - printf("\n---------snap_hd_time:%llu\n", snap_hd_time); - printf("\n---------snap_hd_msec:%llu\n", snap_hd_msec); - - struct tm * timeinfo; - timeinfo = localtime(&snap_hd_time); - - char buf_time_info[256] = { 0 }; - sprintf(buf_time_info, "%04d-%02d-%02d %02d:%02d:%02d:%03ld", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, - timeinfo->tm_min, timeinfo->tm_sec, snap_hd_msec); - - printf("\n--------buf_time_info:%s\n", buf_time_info); -#endif - int index_approaching_to_the_object = 0; - time_t combine_time_approaching_to_the_object = snapHDList[0].snapshot_time_mktime*1000 + snapHDList[0].snapshot_msecs_time; - time_t the_difference_value = combine_time_approaching_to_the_object >= snap_hd_combine_time ? - combine_time_approaching_to_the_object - snap_hd_combine_time : - snap_hd_combine_time - combine_time_approaching_to_the_object; - - for (int i = index_approaching_to_the_object + 1; i < MAX_SNAP_HD_LIST; i++) { - time_t temp_combine_time = snapHDList[i].snapshot_time_mktime * 1000 + snapHDList[i].snapshot_msecs_time; - time_t temp_the_difference_value = temp_combine_time >= snap_hd_combine_time ? - temp_combine_time - snap_hd_combine_time : - snap_hd_combine_time - temp_combine_time; - if (temp_the_difference_value < the_difference_value) { - index_approaching_to_the_object = i; - combine_time_approaching_to_the_object = temp_combine_time; - the_difference_value = temp_the_difference_value; - } - } - - int choose_hd_index = index_approaching_to_the_object; - - if (choose_hd_index >= 0 && choose_hd_index < MAX_SNAP_HD_LIST && - snapHDList[choose_hd_index].snapshot_size >= 1) - { - if (send(cli_socket, snapHDList[choose_hd_index].snapshot_addr, snapHDList[choose_hd_index].snapshot_size, MSG_NOSIGNAL) == -1) - printf("\nsend error #19999992\n"); - } - } - pthread_mutex_unlock(&mutex_web); - closesocket(cli_socket); - } -#endif -#if 1 - else if (strncmp(urlBuffer, "/snaphd", 7) == 0 && strncmp(urlBuffer, "/snaphd?index=", 14) != 0 && strncmp(urlBuffer, "/snaphd?time=", 13) != 0) - { - pthread_mutex_lock(&mutex_web); - //pthread_mutex_lock(&mutex_get_canvas); - //pthread_mutex_lock(&mutex_get_network_input); - size_t snapshot_size = 0; - - //char snapshot_addr[MAX_IMG_SIZE] = { 0 }; - //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); - - - char snapshot_addr[MAX_IMG_SIZE] = { 0 }; - //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); - - //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); - pthread_mutex_lock(&mutex_get_network_input); - snapshot_size = get_g_canvas_addr(snapshot_addr); - pthread_mutex_unlock(&mutex_get_network_input); - - - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #19991\n"); - - //printf("\n------------snapshot_size:%d\n",(int)snapshot_size); - - if ((int)snapshot_size >= 1) { - if (send(cli_socket, snapshot_addr, (int)snapshot_size, MSG_NOSIGNAL) == -1) - printf("\nsend error #19999993\n"); -#if 1 - for (int i = 0; i < MAX_SNAP_HD_LIST; i++) { - if (snapHDList[i].snapshot_size == 0) { - snapHDList[i].snapshot_size = (int)snapshot_size; - - memset(snapHDList[i].snapshot_addr, 0x00, MAX_IMG_SIZE); - memcpy(snapHDList[i].snapshot_addr, snapshot_addr, (int)snapshot_size); - - time_t rawtime = time(0); - snapHDList[i].snapshot_time = localtime(&rawtime); - snapHDList[i].snapshot_time_mktime = mktime(snapHDList[i].snapshot_time); - - struct timeval time_now; - gettimeofday(&time_now, NULL); - snapHDList[i].snapshot_msecs_time = time_now.tv_usec / 1000; - - break; - } - else if (i == MAX_SNAP_HD_LIST - 1) { - - int min_time_index = 0; - time_t min_time_mktime = snapHDList[0].snapshot_time_mktime; - time_t min_time_msecs_time = snapHDList[0].snapshot_msecs_time; - - for (int index_j = min_time_index + 1; index_j < MAX_SNAP_HD_LIST; index_j++) { - if (snapHDList[index_j].snapshot_time_mktime < min_time_mktime) { - min_time_index = index_j; - min_time_mktime = snapHDList[index_j].snapshot_time_mktime; - min_time_msecs_time = snapHDList[index_j].snapshot_msecs_time; - } - else if (snapHDList[index_j].snapshot_time_mktime == min_time_mktime) { - if (snapHDList[index_j].snapshot_msecs_time < min_time_msecs_time) { - min_time_index = index_j; - min_time_mktime = snapHDList[index_j].snapshot_time_mktime; - min_time_msecs_time = snapHDList[index_j].snapshot_msecs_time; - } - } - } - - snapHDList[min_time_index].snapshot_size = (int)snapshot_size; - - memset(snapHDList[min_time_index].snapshot_addr, 0x00, MAX_IMG_SIZE); - memcpy(snapHDList[min_time_index].snapshot_addr, snapshot_addr, (int)snapshot_size); - - time_t rawtime = time(0); - snapHDList[min_time_index].snapshot_time = localtime(&rawtime); - snapHDList[min_time_index].snapshot_time_mktime = mktime(snapHDList[min_time_index].snapshot_time); - - struct timeval time_now; - gettimeofday(&time_now, NULL); - snapHDList[min_time_index].snapshot_msecs_time = time_now.tv_usec / 1000; - } - } -#endif - } - //pthread_mutex_unlock(&mutex_get_network_input); - //pthread_mutex_unlock(&mutex_get_canvas); - pthread_mutex_unlock(&mutex_web); - closesocket(cli_socket); - - } -#endif -#if 0 - else if (strncmp(urlBuffer, "/switchimage", 12) == 0) { - pthread_mutex_lock(&mutex_web); - //switch_g_image_buff_ori = 1; - if (strlen(contentDescription) > 0) - { - strcpy(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #24-2111\n"); - - //printf("\nset_bypass_login \n"); - pthread_mutex_unlock(&mutex_web); - closesocket(cli_socket); - } -#endif -#if 1 - //== /getimage_ori? - else if (strncmp(urlBuffer, "/getimage?", 10) == 0) { - - //pthread_mutex_lock(&mutex_web); - - char snapshot_addr[MAX_IMG_SIZE] = {0}; - int snapshot_size = 0; - - // char c_profileid[30] = { 0 }; - /// strcpy(c_profileid, urlBuffer+16); - // int i_profileid = atoi(c_profileid); - - // printf("\n----------i_profileid:%d\n", i_profileid); - - pthread_mutex_lock(&mutex_get_image); - //if (snapshot_size == 0 && g_image_buff_size_ori >= 1) - - // 2022-11-24 Ken Move /radarsnap to here -#if 0 - if (strstr(urlBuffer, "?radar") != NULL) - { - memset(snapshot_addr, 0x00, MAX_IMG_SIZE); - // struct timeval start; - // gettimeofday(&start, NULL); - // time_t start_msecs_time = start.tv_usec / 1000; - - snapshot_size = (int)get_radar_image(snapshot_addr); - - // struct timeval end; - // gettimeofday(&end, NULL); - // time_t end_msecs_time = end.tv_usec / 1000; - // printf("\n=== radarsnap - get radar time, ms Time = %f\n\n", difftime(end_msecs_time, start_msecs_time)); // 2022-11-01 time cost : 30 ~ 170 ms >>> 2x ~ 15x ms - - // sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ - // if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) - // perror("send error #1999"); - } - else -#endif - { - if (g_image_buff_size_ori[g_current_max_num_image_buff - 1] >= 1) { - memcpy(snapshot_addr, g_image_buff_ori[g_current_max_num_image_buff - 1], g_image_buff_size_ori[g_current_max_num_image_buff - 1]); - snapshot_size = g_image_buff_size_ori[g_current_max_num_image_buff - 1]; - } - // snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", snapshot_addr, 0); - // snapshot_size = get_snap_with_profile_id(snapshot_addr, i_profileid); - } - pthread_mutex_unlock(&mutex_get_image); - //printf("\n---------------getimage ori:snapshot_size:%d\n", snapshot_size); - - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #19121\n"); - else { - - if (snapshot_size >= 1) { - if (send(cli_socket, snapshot_addr, snapshot_size, MSG_MORE) == -1) - printf("\nsend error #19129\n"); - } - } - - //pthread_mutex_unlock(&mutex_web); - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/getimage_ori?", 14) == 0) { - - //pthread_mutex_lock(&mutex_web); - - char snapshot_addr[MAX_IMG_SIZE] = { 0 }; - int snapshot_size = 0; - - //char c_profileid[30] = { 0 }; - ///strcpy(c_profileid, urlBuffer+16); - //int i_profileid = atoi(c_profileid); - - //printf("\n----------i_profileid:%d\n", i_profileid); - - pthread_mutex_lock(&mutex_get_image); - //if (snapshot_size == 0 && g_image_buff_size_ori >= 1) - - // 2022-11-24 Ken Move /radarsnap to here -#if 0 - if (strstr(urlBuffer, "?radar") != NULL) - { - memset(snapshot_addr, 0x00, MAX_IMG_SIZE); - - // struct timeval start; - // gettimeofday(&start, NULL); - // time_t start_msecs_time = start.tv_usec / 1000; - - snapshot_size = (int)get_radar_image(snapshot_addr); - - // struct timeval end; - // gettimeofday(&end, NULL); - // time_t end_msecs_time = end.tv_usec / 1000; - // printf("\n=== radarsnap - get radar time, ms Time = %f\n\n", difftime(end_msecs_time, start_msecs_time)); // 2022-11-01 time cost : 30 ~ 170 ms >>> 2x ~ 15x ms - - // sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ - // if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) - // perror("send error #1999"); - } - else -#endif - { - if (g_image_buff_size_ori[g_current_max_num_image_buff - 1] >= 1){ - memcpy(snapshot_addr, g_image_buff_ori[g_current_max_num_image_buff - 1], g_image_buff_size_ori[g_current_max_num_image_buff - 1]); - snapshot_size = g_image_buff_size_ori[g_current_max_num_image_buff - 1]; - } - //snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", snapshot_addr, 0); - //snapshot_size = get_snap_with_profile_id(snapshot_addr, i_profileid); - } - pthread_mutex_unlock(&mutex_get_image); - //printf("\n---------------getimage ori:snapshot_size:%d\n", snapshot_size); - - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #19121\n"); - else { - if (snapshot_size >= 1) { - if (send(cli_socket, snapshot_addr, snapshot_size, MSG_MORE) == -1) - printf("\nsend error #19129\n"); - } - } - - //pthread_mutex_unlock(&mutex_web); - closesocket(cli_socket); - } -#if defined GY_OS_AMBA - else if (strncmp(urlBuffer, "/getimage_HD?", 13) == 0) { - - //pthread_mutex_lock(&mutex_web); - - char snapshot_addr[MAX_IMG_SIZE_HD] = { 0 }; - int snapshot_size = 0; - - //char c_profileid[30] = { 0 }; - ///strcpy(c_profileid, urlBuffer+16); - //int i_profileid = atoi(c_profileid); - - //printf("\n----------i_profileid:%d\n", i_profileid); - - if (g_video_start_HD == 1) { - pthread_mutex_lock(&mutex_get_image_HD); - //if (snapshot_size == 0 && g_image_buff_size_ori >= 1) - { - if (g_image_buff_size_HD[g_current_max_num_image_buff - 1] >= 1) { - memcpy(snapshot_addr, g_image_buff_HD[g_current_max_num_image_buff - 1], g_image_buff_size_HD[g_current_max_num_image_buff - 1]); - snapshot_size = g_image_buff_size_HD[g_current_max_num_image_buff - 1]; - - memcpy(g_image_buff_HD_pause, snapshot_addr, snapshot_size); - g_image_buff_size_HD_pause = snapshot_size; - } - - //snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", snapshot_addr, 0); - //snapshot_size = get_snap_with_profile_id(snapshot_addr, i_profileid); - } - pthread_mutex_unlock(&mutex_get_image_HD); - //printf("\n---------------getimage HD:snapshot_size:%d\n", snapshot_size); - } - else if(g_image_buff_size_HD_pause >= 1) { - memcpy(snapshot_addr, g_image_buff_HD_pause, g_image_buff_size_HD_pause); - snapshot_size = g_image_buff_size_HD_pause; - } - - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #1912122\n"); - else { - if (snapshot_size >= 1) { - if (send(cli_socket, snapshot_addr, snapshot_size, MSG_MORE) == -1) - printf("\nsend error #1912922\n"); - } - } - - //pthread_mutex_unlock(&mutex_web); - closesocket(cli_socket); - } -#endif -#endif -#if 0 - else if (strncmp(urlBuffer, "/remotesnap", 11) == 0) - { - // printf("\nurlBuffer : %s\n", urlBuffer); - - if (g_check_if_remotesnap_running == 0) - { - // TODO check PTZ - g_check_if_remotesnap_running = 1; - - pthread_mutex_lock(&mutex_remotesnap_image); - - // char snapshot_addr[MAX_IMG_SIZE] = { 0 }; - // size_t snapshot_size = 0; - - // memset(snapshot_addr, 0x00, MEMORY_SIZE); - - // snapshot_size = (size_t)get_ori_c_image(snapshot_addr); - // snapshot_size = get_g_canvas_addr(snapshot_addr); - - g_remotesnap_snapshot_size = 0; - if ((int)g_remotesnap_snapshot_size == 0) - { - g_remotesnap_snapshot_size = PNS_Get_Snapshot_From_Remote_IPCam("remotesnap_buf.jpg", g_remotesnap_snapshot_addr, 0); - // printf("\nnormal g_remotesnap_snapshot_size %d\n", g_remotesnap_snapshot_size); - } - if ((int)g_remotesnap_snapshot_size >= 0 && (int)g_remotesnap_snapshot_size < 500) - { - g_remotesnap_snapshot_size = get_nosignal_image(g_remotesnap_snapshot_addr); - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - { - printf("\n[CGI:/remotesnap] send buffer error #1\n"); - } - - if (send(cli_socket, g_remotesnap_snapshot_addr, (int)g_remotesnap_snapshot_size, MSG_MORE) == -1) - printf("\n[CGI:/remotesnap] send snapshot error #1\n"); - } - - if ((int)g_remotesnap_snapshot_size >= 500) - { - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - { - printf("\n[CGI:/remotesnap] send buffer error #2\n"); - } - - if (send(cli_socket, g_remotesnap_snapshot_addr, (int)g_remotesnap_snapshot_size, MSG_MORE) == -1) - printf("\n[CGI:/remotesnap] send snapshot error #2\n"); - } - - pthread_mutex_unlock(&mutex_remotesnap_image); - g_check_if_remotesnap_running = 0; - } - else - { - pthread_mutex_lock(&mutex_remotesnap_image); - if ((int)g_snap_snapshot_size >= 1) - { - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - { - printf("\n[CGI:/remotesnap] send buffer error #3\n"); - } - - if (send(cli_socket, g_remotesnap_snapshot_addr, (int)g_remotesnap_snapshot_size, MSG_MORE) == -1) - printf("\n[CGI:/remotesnap] send snapshot error #3\n"); - } - pthread_mutex_unlock(&mutex_remotesnap_image); - } - - // else { - // sprintf(sendBuffer, "HTTP/1.1 400 Bad Request\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - // if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - // printf("\nsend error #1991239\n"); - //} - closesocket(cli_socket); - } -#endif -#if 1 - else if (strncmp(urlBuffer, "/snap",5) == 0 && strncmp(urlBuffer, "/snaphd", 7) != 0 && strncmp(urlBuffer, "/snap?profileid=", 16) != 0) - { - if (g_check_if_snap_running == 0) { - g_check_if_snap_running = 1; - - pthread_mutex_lock(&mutex_snap_image); - - //char snapshot_addr[MAX_IMG_SIZE] = { 0 }; - //size_t snapshot_size = 0; - - //memset(snapshot_addr, 0x00, MEMORY_SIZE); - - //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); - //snapshot_size = get_g_canvas_addr(snapshot_addr); - - g_snap_snapshot_size = 0; - if ((int)g_snap_snapshot_size == 0){ - g_snap_snapshot_size = PNS_Get_Snapshot_From_IPCam("snap_buf.jpg", g_snap_snapshot_addr, 0); - } - - - if ((int)g_snap_snapshot_size >= 1) { - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) { - printf("\nsend error #199911\n"); - } - - if (send(cli_socket, g_snap_snapshot_addr, (int)g_snap_snapshot_size, MSG_MORE) == -1) - printf("\nsend error #19999994\n"); - } - - pthread_mutex_unlock(&mutex_snap_image); - g_check_if_snap_running = 0; - - - } - else { - pthread_mutex_lock(&mutex_snap_image); - if ((int)g_snap_snapshot_size >= 1) { - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) { - printf("\nsend error #199912\n"); - } - - if (send(cli_socket, g_snap_snapshot_addr, (int)g_snap_snapshot_size, MSG_MORE) == -1) - printf("\nsend error #1999933\n"); - } - pthread_mutex_unlock(&mutex_snap_image); - } - - - //else { - //sprintf(sendBuffer, "HTTP/1.1 400 Bad Request\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - //if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - //printf("\nsend error #1991239\n"); - //} - closesocket(cli_socket); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/differ_image_test") == 0) - { - pthread_mutex_lock(&mutex_web); - pthread_mutex_lock(&mutex_run_one_net); - //pthread_mutex_lock(&mutex_get_network_input); - - size_t snapshot_size = 0; - - char snapshot_addr[MAX_IMG_SIZE] = { 0 }; - //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); - - //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); - pthread_mutex_lock(&mutex_get_network_input); - snapshot_size = get_g_canvas_addr(snapshot_addr); - pthread_mutex_unlock(&mutex_get_network_input); - - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #199915\n"); - - if ((int)snapshot_size >= 1) { - - int differ_size = 0; - char differ_addr[MAX_IMG_SIZE] = { 0 }; - memset(differ_addr, 0x00, MAX_IMG_SIZE); - differ_image_test(differ_addr, &differ_size, snapshot_addr, (int)snapshot_size, get_g_ori_yuv_width(), get_g_ori_yuv_height()); - - - //printf("\n-------------------differ_size:%d\n", differ_size); - if (differ_size >= 1) { - if (send(cli_socket, differ_addr, differ_size, MSG_NOSIGNAL) == -1) - printf("\nsend error #19999997\n"); - } - } - - - //pthread_mutex_unlock(&mutex_get_network_input); - pthread_mutex_unlock(&mutex_run_one_net); - pthread_mutex_unlock(&mutex_web); - closesocket(cli_socket); - - } -#endif - else if (strncmp(urlBuffer, "/set_value&",11) == 0) - { - //printf("\n[getloading]return contentBuffer = %s \n", contentBuffer); - char value_buffer[256] = { 0 }; - memset(value_buffer, 0x00, sizeof(value_buffer)); - strcpy(value_buffer, urlBuffer + 11); - - //printf("\n-----------%s\n", value_buffer); - - char Msg[256] = { 0 }; - - if (strncmp(value_buffer, "day_or_night=1", 14) == 0) { - - imageDnData.color_mode = 1; - - strcpy(Msg,"OK"); - } - else if (strncmp(value_buffer, "day_or_night=0", 14) == 0){ - - imageDnData.color_mode = 2; - - strcpy(Msg, "OK"); - } - else { - strcpy(Msg, "fail"); - } - - strcpy(beforeSendBuffer, Msg); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #212\n"); - - closesocket(cli_socket); - } -#if 0 - else if (strcmp(urlBuffer, "/differ_image") == 0) - { - pthread_mutex_lock(&mutex_web); - pthread_mutex_lock(&mutex_run_one_net); - //pthread_mutex_lock(&mutex_get_network_input); - - size_t snapshot_size = 0; - - char snapshot_addr[MAX_IMG_SIZE] = { 0 }; - //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); - - //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); - pthread_mutex_lock(&mutex_get_network_input); - snapshot_size = get_g_canvas_addr(snapshot_addr); - pthread_mutex_unlock(&mutex_get_network_input); - - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #199915\n"); - - if ((int)snapshot_size >= 1) { - - int differ_size = 0; - char differ_addr[MAX_IMG_SIZE] = { 0 }; - memset(differ_addr, 0x00, MAX_IMG_SIZE); - int no_tempering = 0; - differ_image(differ_addr, &differ_size, snapshot_addr, (int)snapshot_size, NULL, get_g_ori_yuv_width(), get_g_ori_yuv_height(),0,0,&no_tempering,1); - - - //printf("\n-------------------differ_size:%d\n", differ_size); - if (differ_size >= 1) { - if (send(cli_socket, differ_addr, differ_size, MSG_NOSIGNAL) == -1) - printf("\nsend error #19999997\n"); - } - } - - - //pthread_mutex_unlock(&mutex_get_network_input); - pthread_mutex_unlock(&mutex_run_one_net); - pthread_mutex_unlock(&mutex_web); - closesocket(cli_socket); - - } -#endif -#if 0 - else if (strncmp(urlBuffer, "/bgsnap", 7) == 0) - { - if (g_IsRadarDevice == 1) { - pthread_mutex_lock(&mutex_web); - char snapshot_addr_radar[MEMORY_SIZE] = { 0 }; - memset(snapshot_addr_radar, 0x00, MEMORY_SIZE); - size_t snapshot_size = 0; - snapshot_size = (size_t)get_bg_radar_image(snapshot_addr_radar); - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) - perror("send error #199916"); - if ((int)snapshot_size >= 1) - { - if (send(cli_socket, snapshot_addr_radar, (int)snapshot_size, 0) == -1) - perror("send error #19999998"); - } - else - { - printf("empty radar image\n"); - } - pthread_mutex_unlock(&mutex_web); - } - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/speedbgsnap", 12) == 0) - { - pthread_mutex_lock(&mutex_web); - char radar_speed_snapshot_addr[MEMORY_SIZE] = {0}; - memset(radar_speed_snapshot_addr, 0x00, MEMORY_SIZE); - size_t speed_snapshot_size = 0; - speed_snapshot_size = (size_t)get_speed_bg_image(radar_speed_snapshot_addr); - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n"); /*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), 0) == -1) - perror("send error #199917"); - if ((int)speed_snapshot_size >= 1) - { - if (send(cli_socket, radar_speed_snapshot_addr, (int)speed_snapshot_size, 0) == -1) - perror("send error #19999999"); - } - else - { - printf("empty radar image\n"); - } - pthread_mutex_unlock(&mutex_web); - closesocket(cli_socket); - } - // ======================================================================================== -#endif -#if 0 - else if (strcmp(urlBuffer, "/differ_image_short") == 0) - { - pthread_mutex_lock(&mutex_web); - pthread_mutex_lock(&mutex_run_one_net); - //pthread_mutex_lock(&mutex_get_network_input); - - size_t snapshot_size = 0; - - char snapshot_addr[MAX_IMG_SIZE] = { 0 }; - //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); - - //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); - pthread_mutex_lock(&mutex_get_network_input); - snapshot_size = get_g_canvas_addr(snapshot_addr); - pthread_mutex_unlock(&mutex_get_network_input); - - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #199918\n"); - - if ((int)snapshot_size >= 1) { - - int differ_size = 0; - char differ_addr[MAX_IMG_SIZE] = { 0 }; - memset(differ_addr, 0x00, MAX_IMG_SIZE); - - - int no_tempering = 0; - differ_image(differ_addr, &differ_size, snapshot_addr, (int)snapshot_size, NULL, get_g_ori_yuv_width(), get_g_ori_yuv_height(), 0, 1, &no_tempering,1); - - - //printf("\n-------------------differ_size:%d\n", differ_size); - if (differ_size >= 1) { - if (send(cli_socket, differ_addr, differ_size, MSG_NOSIGNAL) == -1) - printf("\nsend error #1999989\n"); - } - } - - - ///pthread_mutex_unlock(&mutex_get_network_input); - pthread_mutex_unlock(&mutex_run_one_net); - pthread_mutex_unlock(&mutex_web); - closesocket(cli_socket); - - } -#endif -#if 0 - else if (strcmp(urlBuffer, "/differ_image_long") == 0) - { - pthread_mutex_lock(&mutex_web); - pthread_mutex_lock(&mutex_run_one_net); - //pthread_mutex_lock(&mutex_get_network_input); - - size_t snapshot_size = 0; - - char snapshot_addr[MAX_IMG_SIZE] = { 0 }; - //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); - - //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); - pthread_mutex_lock(&mutex_get_network_input); - snapshot_size = get_g_canvas_addr(snapshot_addr); - pthread_mutex_unlock(&mutex_get_network_input); - - - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #199919\n"); - - if ((int)snapshot_size >= 1) { - - int differ_size = 0; - char differ_addr[MAX_IMG_SIZE] = { 0 }; - memset(differ_addr, 0x00, MAX_IMG_SIZE); - - int no_tempering = 0; - differ_image(differ_addr, &differ_size, snapshot_addr, (int)snapshot_size, NULL, get_g_ori_yuv_width(), get_g_ori_yuv_height(), 1, 0, &no_tempering,1); - - //printf("\n-------------------differ_size:%d\n", differ_size); - if (differ_size >= 1) { - if (send(cli_socket, differ_addr, differ_size, MSG_NOSIGNAL) == -1) - printf("\nsend error #1999989\n"); - } - } - - - //pthread_mutex_unlock(&mutex_get_network_input); - pthread_mutex_unlock(&mutex_run_one_net); - pthread_mutex_unlock(&mutex_web); - closesocket(cli_socket); - - } -#endif -#if 0 - else if (strncmp(urlBuffer, "/count_color", 12) == 0) - { - pthread_mutex_lock(&mutex_web); - //pthread_mutex_lock(&mutex_get_network_input); - pthread_mutex_lock(&mutex_differ_image); - - size_t snapshot_size = 0; - - char snapshot_addr[MAX_IMG_SIZE] = { 0 }; - //memset(snapshot_addr, 0x00, MAX_IMG_SIZE); - - //snapshot_size = (size_t)get_ori_c_image(snapshot_addr); - pthread_mutex_lock(&mutex_get_network_input); - snapshot_size = get_g_canvas_addr(snapshot_addr); - pthread_mutex_unlock(&mutex_get_network_input); - - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #199920\n"); - - if ((int)snapshot_size >= 1) { - - int color_size = 0; - char color_addr[MAX_IMG_SIZE] = { 0 }; - memset(color_addr, 0x00, MAX_IMG_SIZE); - //pNext_word->name:car,pNext_word->box_x:878.322632,pNext_word->box_y:560.714294,pNext_word->box_w:1680.456665,pNext_word->box_h:1315.334717 - detection_pos fake_pNext = { 0 }; - fake_pNext.left_x = 948; - fake_pNext.top_y = 1093; - fake_pNext.width = 1245; - fake_pNext.height = 648; - - crop_image_ivs(color_addr, &color_size, snapshot_addr, (int)snapshot_size, &fake_pNext, get_g_ori_yuv_width(), get_g_ori_yuv_height()); - - //printf("\n-------------------differ_size:%d\n", differ_size); - if (color_size >= 1) { - if (send(cli_socket, color_addr, color_size, MSG_NOSIGNAL) == -1) - printf("\nsend error #19999990\n"); - } - } - - - pthread_mutex_unlock(&mutex_differ_image); - //pthread_mutex_unlock(&mutex_get_network_input); - pthread_mutex_unlock(&mutex_web); - closesocket(cli_socket); - - } -#endif - else if (strcmp(urlBuffer, "/sync_ipcam_account_setting") == 0) - { - - pthread_t thread_id_getipcamsettings; - if (pthread_create(&thread_id_getipcamsettings, 0, read_ipcam_account_setting_thread, NULL)) { - printf("\ngetipcamsettings thread creation failed\n"); - } - - - if (strlen(contentDescription) > 0) - { - strcpy(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #24-2111\n"); - - //printf("\nset_bypass_login \n"); - closesocket(cli_socket); - } -#if 1 - else if (strcmp(urlBuffer, "/sync_image_rotation") == 0) - { -#if 1 - sync_image_rotation_thread(); -#endif - if (strlen(contentDescription) > 0) - { - strcpy(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #24-2113\n"); - - //printf("\nset_bypass_login \n"); - closesocket(cli_socket); - } -#endif - else if (strcmp(urlBuffer, "/get_enable_ptz") == 0) - { - char convert_tojson1[256] = "{\"enable_PTZ\":\""; - char convert_tojson2[256] = "\"}"; - - - strcat(contentBuffer, convert_tojson1); - - char enable_PTZ_off[256] = "No"; -#ifdef GY_OS_AMBA - char enable_PTZ_on[256] = "Yes"; - - //Check PTZ device - //char ptz_curl_url[512] = { 0 }; - //char ptz_curl_sendbuf[1] = { 0 }; - //char ptz_curl_username[128] = { 0 }; - //char ptz_curl_password[128] = { 0 }; - //char *method = "GET"; - //int ptz_port = atoi(accountData[0].account_port); - - //strcpy(ptz_curl_username, accountData[0].account_username); - //strcpy(ptz_curl_password, accountData[0].account_password); - - //strcpy(ptz_curl_url, "http://"); - //strcat(ptz_curl_url, "127.0.0.1:"); - //strcat(ptz_curl_url, accountData[0].account_port); - //strcat(ptz_curl_url, "/server"); - - //if (check_ptz(ptz_curl_url, ptz_curl_sendbuf, ptz_curl_username, ptz_curl_password, method, ptz_port)) - if(g_IsPTZDevice == 1) - { - strcat(contentBuffer, enable_PTZ_on); - //strcat(contentBuffer, enable_PTZ_off); - //write_to_enable_PTZ("Yes"); //enable_PTZ 不會用到 - } - else -#endif - { - strcat(contentBuffer, enable_PTZ_off); - //write_to_enable_PTZ("No"); //enable_PTZ 不會用到 - } - - strcat(contentBuffer, convert_tojson2); - //printf("\n[set_bypass_login]return contentBuffer = %s \n", contentBuffer); - - strcpy(beforeSendBuffer, contentBuffer); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #24-2\n"); - - //printf("\nset_bypass_login \n"); - closesocket(cli_socket); - } - else if (strcmp(urlBuffer, "/set_only_show_metadata1_on") == 0 || strcmp(urlBuffer, "/set_only_show_metadata1_off") == 0) - { - //printf("\n[web process]start 14\n"); - /*printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\nenable_base64: %d\n", enable_base64); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");*/ - //printf("set_bypass_login\n"); - char convert_tojson1[256] = "{\"ONLY_SHOW_METADATA1\":\""; - char convert_tojson2[256] = "\"}"; - - char only_show_metadata1_on[256] = "on"; - char only_show_metadata1_off[256] = "off"; - - strcat(contentBuffer, convert_tojson1); - - if (strcmp(urlBuffer, "/set_only_show_metadata1_on") == 0) - { - enable_only_show_metadata1 = 1; - strcat(contentBuffer, only_show_metadata1_on); - update_enable_only_show_metadata1(enable_only_show_metadata1); - } - else if (strcmp(urlBuffer, "/set_only_show_metadata1_off") == 0) - { - enable_only_show_metadata1 = 0; - strcat(contentBuffer, only_show_metadata1_off); - update_enable_only_show_metadata1(enable_only_show_metadata1); - } - - strcat(contentBuffer, convert_tojson2); - //printf("\n[set_bypass_login]return contentBuffer = %s \n", contentBuffer); - - strcpy(beforeSendBuffer, contentBuffer); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #24-2\n"); - - //printf("\nset_bypass_login \n"); - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/getsmartevent?", 15) == 0 || strncmp(urlBuffer, "/setsmartevent?", 15) == 0) //取得ipcam的event?get=all (strncmp(urlBuffer, "/getconfig?", 11) == 0) || (strncmp(urlBuffer, "/setconfig?", 11) == 0) - { - //printf("\n[web process]start 15\n"); - char wanted[512] = { 0 }; - - memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); - firstBuffer[strlen(urlBuffer)] = '\0'; - strcpy(wanted, firstBuffer + 15); - - //printf("\n%s\n", accountData[0].account_username); - //printf("\n%s\n", accountData[0].account_password); - int size_psBuffer = 256; - - char psBuffer[256] = { 0 }; - char psBuffer_temp[256] = { 0 }; - char psBuffer_send[256] = { 0 }; - - if (strncmp(urlBuffer, "/getsmartevent?", 15) == 0) - { - FILE* pPipe;/*,*pPipe2*/ - printf("\ngetsmartevent\n"); - printf("\n%s\n", wanted); - - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - /* - char cmd_port[256] = { 0 }; - memset(cmd_port, 0x00, sizeof(cmd_port)); - */ - char cmd1[256] = "curl http://"; - //char cmd2[256] = ":"; - char cmd3[256] = "127.0.0.1:";//@127.0.0.1: - char cmd4[256] = "/event?get=all | grep "; - //char cmd_port1[256] = "@localhost/network?http.port=81 | grep http.port"; - - strcpy(cmd, cmd1); - //strcat(cmd, accountData[0].account_username); - //strcat(cmd, cmd2); - //strcat(cmd, accountData[0].account_password); - strcat(cmd, cmd3); - strcat(cmd, accountData[0].account_port); - strcat(cmd, cmd4); - strcat(cmd, wanted); - //printf("\n[getallevent]cmd: %s\n",cmd); - - /*strcat(cmd_port, cmd1); - strcat(cmd_port, accountData[0].account_username); - strcat(cmd_port, cmd2); - strcat(cmd_port, accountData[0].account_password); - strcat(cmd_port, cmd_port1);*/ - - if (/*(pPipe2 = vpopen(cmd_port,"r")) == NULL ||*/ (pPipe = vpopen(cmd, "r")) == NULL) - { - printf("[Error] getsmartevent\n"); - } - else - { - printf("Run: getsmartevent\n"); - char* temp = NULL; - temp = fgets(psBuffer, size_psBuffer, pPipe); - - if (temp != NULL) - { - strncpy(psBuffer_temp, psBuffer, 256); - int c = 0, d = 0; - while (psBuffer_temp[c] != '\0') - { - if (psBuffer_temp[c] == ' ' || psBuffer_temp[c] == '\t') - { - int temp_index = c + 1; - if (psBuffer_temp[temp_index] != '\0') - { - while ((psBuffer_temp[temp_index] == ' ' || psBuffer_temp[temp_index] == '\t') && psBuffer_temp[temp_index] != '\0') - { - if (psBuffer_temp[temp_index] == ' ' || psBuffer_temp[temp_index] == '\t') - c++; - - temp_index++; - } - } - } - psBuffer_send[d] = psBuffer_temp[c]; - c++; - d++; - } - psBuffer_send[d] = '\0'; - - printf("getsmartevent psBuffer: OK\n"); - } - else - { - strcpy(psBuffer_send, "NULL"); - printf("[Error]getsmartevent psBuffer Empty\n"); - } - - if (strcmp(psBuffer_send, "NULL") == 0) - { - char convert_tojson1[256] = "{\"ALL_EVENT\":\""; - char convert_tojson2[256] = "\"}"; - printf("\n[getsmartevent] return str = %s \n", psBuffer_send); - strcat(contentBuffer, convert_tojson1); - strcat(contentBuffer, psBuffer_send); - strcat(contentBuffer, convert_tojson2); - } - else - { - char convert_tojson1[256] = "{\""; - char convert_tojson2[256] = "\":\""; - char convert_tojson3[256] = "\"}"; - char myarr[2][STRSPLIT_SIZE] = { 0 }; - const char *mydel = "="; - - printf("\n[getsmartevent] return str = %s \n", psBuffer_send); - StrSplit(psBuffer_send, myarr, mydel); - - - strcat(contentBuffer, convert_tojson1); - strcat(contentBuffer, *(myarr)); - strcat(contentBuffer, convert_tojson2); - /* - int temp_index = 0; - while (*(myarr + 1)[temp_index] != '\0' && *(myarr + 1)[temp_index] != '\n') { - strcat(contentBuffer, *(myarr + 1)[temp_index]); - temp_index++; - }*/ - strcat(contentBuffer, *(myarr + 1)); - strcat(contentBuffer, convert_tojson3); - //name: *(myarr) //vale: *(myarr+1) - } - printf("\n[getsmartevent] contentBuffer = %s \n", contentBuffer); - - //char Msg[256] = { 0 }; - - strcpy(beforeSendBuffer, contentBuffer); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #25\n"); - - printf("\ngetsmartevent\n"); - } - if (pPipe != NULL) - vpclose(pPipe); - } - else if (strncmp(urlBuffer, "/setsmartevent?", 15) == 0) - { - strcpy(beforeSendBuffer, contentBuffer); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #26\n"); - - pthread_t auto_build_smart_events_thread_id; - if (pthread_create(&auto_build_smart_events_thread_id, 0, auto_build_smart_events, NULL)) - { - printf("create auto_build_smart_events thread faile \n"); - } - } - //if (pPipe2 != NULL) - // vpclose(pPipe2); - closesocket(cli_socket); - usSleep(5000); - } -#ifdef GY_OS_V_SERIES - -#else - else if (strncmp(urlBuffer, "/set_divi_smartevent", 20) == 0) - { - - strcpy(beforeSendBuffer, contentBuffer); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #2556\n"); - - pthread_t auto_build_smart_events_thread_id_di_vi; - if (pthread_create(&auto_build_smart_events_thread_id_di_vi, 0, auto_build_smart_events_di_vi, NULL)) - { - printf("create auto build smart events di vi thread faile \n"); - } - - closesocket(cli_socket); - usSleep(1250); - } -#endif -#if 1 //會有crash - else if (strcmp(urlBuffer, "/pns_dev_name") == 0) // Trigger command for PNS 2.0 - { - printf("[pns_dev_name] Triggered.\n"); - char returned_msg[512] = { 0 }; - PNS_Get_Device_Name(1, returned_msg); - if (returned_msg != NULL) - { - char sendBuffer[BUFSIZE_V2] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\npns_debug sending response error.\n"); - - } - else { - printf("[web process] Warning: returned_msg is NULL.\n"); - char sendBuffer[BUFSIZE_V2] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #34-22\n"); - } - - printf("[pns_dev_name] Finished.\n"); - closesocket(cli_socket); - } -#endif -#if 0 - else if (strcmp(urlBuffer, "/pns_snap") == 0) - { - printf("[pns_snap] Triggered.\n"); - - char sendBuffer[BUFSIZE_V2] = { 0 }; - char img_addr[25 * 1024] = {0}; - size_t img_size = PNS_Get_Snapshot_From_IPCam("curl_saved_from_pns_buf.jpg", img_addr,1); - - if (img_size >= 1) - { - char img_info[1024]; - sprintf(img_info, "Image addr: %p\nImage size: %ld\nImage content:\n", img_addr, img_size); - - /* - for (int i = 0; i < img_size; i++) - { - char value[8]; - sprintf(value, "0x%x", img_addr[i]); - strcat(img_info, value); - } - strcat(img_info, "\n");*/ - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(img_info), img_info); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\n[pns_snap] sending successfully.\n"); - } - else - { - printf("[pns_snap] PNS_Get_Snapshot_From_IPCam fetching error.\n"); - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #34-23\n"); - } - - closesocket(cli_socket); - printf("[pns_snap] Finished.\n"); - } -#endif -#if 0 - else if (strcmp(urlBuffer, "/pns_query") == 0) // Only for test. Not the official service. - { - printf("[pns query] Triggered.\n"); - char returned_msg[MEMORY_SIZE] = { 0 }; - PNS_Query_Service_Status(returned_msg); - - const char keyword[] = "\"snap\":\""; - char* start = strstr(returned_msg, keyword); - char* end = strstr(returned_msg, "\"}"); - size_t length = (size_t)end - (size_t)start - strlen(keyword); - if (length > 0) - { - char* cloud_addr = malloc(length + 1); - strncpy(cloud_addr, start + strlen(keyword), length); - cloud_addr[length] = '\0'; - printf("Cloud addr. before ddDec: %s\n", cloud_addr); - char* dddec_cloud_addr = ddDec(cloud_addr); - printf("Cloud addr. after ddDec: %s\n", dddec_cloud_addr); - if (cloud_addr) { - free(cloud_addr); - cloud_addr = NULL; - } - if (dddec_cloud_addr) { - free(dddec_cloud_addr); - dddec_cloud_addr = NULL; - } - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\n[pns query] Sending response error.\n"); - closesocket(cli_socket); - printf("[pns query] Finished.\n"); - } -#endif -#if 0 - else if (strcmp(urlBuffer, "/pns_multipart_debug") == 0) // Only for test. Not the official service. - { - printf("[pns_multipart_debug] Triggered.\n"); - char fake_desc[512] = { 0 }; - PNS_Get_Device_Name(1, fake_desc); - char returned_msg[MEMORY_SIZE] = { 0 }; - PNS_Send_Multipart_POST("wtf", "", "", "", fake_desc, "vega@ddnsipcam.com", "5Wizards", "https://cloud.ddnsipcam.com/pns/", returned_msg); - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\npns_multipart sending response error.\n"); - closesocket(cli_socket); - printf("[pns_multipart_debug] Finished.\n"); - } -#endif -#if 0 - else if (strcmp(urlBuffer, "/pns_multipart") == 0) // Only for test. Not the official service. - { - printf("[pns_multipart] Triggered.\n"); - char returned_msg[MEMORY_SIZE] = { 0 }; - PNS_Send_Multipart_POST("wtf", "", "", "", "", SystemSetting.cloud_account, SystemSetting.cloud_password, "https://cloud.ddnsipcam.com/pns/", returned_msg); - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\npns_multipart sending response error.\n"); - closesocket(cli_socket); - printf("[pns_multipart] Finished.\n"); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/ddns_check") == 0) // Only for test. Not the official service. - { - printf("[ddns_check_acc] Triggered.\n"); - - char returned_msg[MEMORY_SIZE] = { 0 }; - //int result = - DDNS_Communication(0, "stevehub@meritlilin.com.tw", "12345", returned_msg); - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\n[ddns_check_acc] Service sending/response error.\n"); - closesocket(cli_socket); - printf("[ddns_check_acc] Finished.\n"); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/ddns_register") == 0) // Only for test. Not the official service. - { - printf("[ddns_check_acc] Triggered.\n"); - - char returned_msg[MEMORY_SIZE] = { 0 }; - //int result = - DDNS_Communication(1, SystemSetting.cloud_account, SystemSetting.cloud_password, returned_msg); - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\n[ddns_check_acc] Service sending/response error.\n"); - closesocket(cli_socket); - printf("[ddns_check_acc] Finished.\n"); - } -#endif -#if 1 - else if (strcmp(urlBuffer, "/ddns_login") == 0) // Only for test. Not the official service. - { - printf("[ddns_check_acc] Triggered.\n"); - - char returned_msg[MEMORY_SIZE] = { 0 }; - //int result = - DDNS_Communication(2, SystemSetting.cloud_account, SystemSetting.cloud_password, returned_msg); - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\n[ddns_check_acc] Service sending/response error.\n"); - closesocket(cli_socket); - printf("[ddns_check_acc] Finished.\n"); - } -#endif -#if 0 - else if (strcmp(urlBuffer, "/ddns_image_check") == 0) // Only for test. Not the official service. - { - //printf("[ddns_check_acc] Triggered.\n"); - - char returned_msg[MEMORY_SIZE] = { 0 }; - //int result = - PNS_check_if_to_post_image(SystemSetting.cloud_account, SystemSetting.cloud_password, returned_msg,"https://cloud.ddnsipcam.com/pns/"); - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\n[ddns_check_acc] Service sending/response error.\n"); - closesocket(cli_socket); - //printf("[ddns_check_acc] Finished.\n"); - } -#endif -#if 0 - else if (strcmp(urlBuffer, "/net_curl_test") == 0) // Only for test. Not the official service. - { - printf("[net curl test] Triggered.\n"); - char returned_msg[MEMORY_SIZE] = { 0 }; - - curl_information_smtp_t user_smtp; - - strcpy(user_smtp.receiver[0], IPCAMService.email_address1); - strcpy(user_smtp.receiver[1], IPCAMService.email_address2); - strcpy(user_smtp.receiver[2], IPCAMService.email_address3); - strcpy(user_smtp.receiver[3], IPCAMService.email_address4); - strcpy(user_smtp.receiver[4], IPCAMService.email_address5); - - - strcpy(user_smtp.address, IPCAMService.email_address); - strcpy(user_smtp.server, IPCAMService.smtp_server); - sprintf(user_smtp.auth_mode,"%d", IPCAMService.smtp_auth_mode); - strcpy(user_smtp.port, IPCAMService.smtp_port); - sprintf(user_smtp.auth, "%d", IPCAMService.smtp_auth); - strcpy(user_smtp.user, IPCAMService.auth_account); - - char test_temp[10] = { 0 }; - - if (net_curl_smtp_data(&user_smtp, test_temp,0) < 0){ - strcpy(returned_msg, "SMTP Fail"); - printf("\nSMTP Fail\n"); - } - else { - strcpy(returned_msg, "SMTP OK"); - printf("\nSMTP OK\n"); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\n[net curl test] Service sending/response error.\n"); - closesocket(cli_socket); - printf("[net curl test] Finished.\n"); - } -#endif -#if 0 - else if (strcmp(urlBuffer, "/reboot_my_service") == 0) // Only for test. Not the official service. - { - printf("[reboot test] Triggered.\n"); - char returned_msg[MEMORY_SIZE] = { 0 }; - - strcpy(returned_msg,"start to reboot"); - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(returned_msg), returned_msg); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\n[reboot test] Service sending/response error.\n"); - closesocket(cli_socket); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "reboot my service"); - write_to_logs_html(temp_msg, "reboot my service", "CGI_REBOOT", "Yes"); - write_to_log_if_error(temp_msg, "reboot my service", "CGI_REBOOT"); - - pthread_t auto_reboot_thread_id; - if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) - { - printf("create auto reboot thread faile \n"); - } - - printf("[reboot test] Finished.\n"); - } -#endif - else if (strcmp(urlBuffer, "/getAnprInfo") == 0) //20201005 sophia add - { - //printf("\n[web process]start 17\n"); - ///get config info - //post events setting - //char filename[] = "config.json"; - char *filename = configPATH; - if (!FileExist(filename)) - printf("%s doesn't exist.\n", filename); - else { - //printf("read config.json.\n"); - - //size_t nfileSize = ReadFileSize(filename); - char* fileBuf = ReadAllBytes(filename); - if (fileBuf) { - cJSON *config_root, *view_setting, *camera; - - config_root = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - //printf("\n[web process]start 17-2\n"); - if (config_root) - { - //printf("config.json parse OK.\n"); - int anpr_ch = 0; - { - view_setting = cJSON_GetObjectItem(config_root, "view_setting"); - char CameraID[20] = { 0 }; - sprintf(CameraID, "camera%02d", anpr_ch + 1); - camera = cJSON_GetObjectItem(view_setting, CameraID); - - cJSON *root/*, *levenshtein_distance*/, *min_characters, *max_characters, *confidence, *enable_anpr,*enable_face; - char* JsonString = NULL; - root = cJSON_CreateObject(); - - //levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); - min_characters = cJSON_GetObjectItem(camera, "min_characters"); - max_characters = cJSON_GetObjectItem(camera, "max_characters"); - confidence = cJSON_GetObjectItem(camera, "confidence"); - enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); - enable_face = cJSON_GetObjectItem(camera, "enable_face"); - - /*printf("\nenable_anpr:%s", enable_anpr->valuestring); - printf("\nconfidence:%s", confidence->valuestring); - printf("\nmin_characters:%s", min_characters->valuestring); - printf("\nmax_characters:%s", max_characters->valuestring);*/ - - cJSON_AddItemToObject(root, "enable_anpr", cJSON_CreateString(enable_anpr->valuestring)); - cJSON_AddItemToObject(root, "enable_face", cJSON_CreateString(enable_face->valuestring)); - cJSON_AddItemToObject(root, "confidence", cJSON_CreateString(confidence->valuestring)); - cJSON_AddItemToObject(root, "min_characters", cJSON_CreateString(min_characters->valuestring)); - cJSON_AddItemToObject(root, "max_characters", cJSON_CreateString(max_characters->valuestring)); - //printf("\n[web process]start 17-3\n"); - JsonString = cJSON_PrintUnformatted(root); - //printf("\n[getAnprInfo]return json str = %s \n", JsonString); - - strcat(contentBuffer, JsonString); - - //char Msg[256] = { 0 }; - - strcpy(beforeSendBuffer, contentBuffer); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #28\n"); - //printf("\n[web process]start 17-4\n"); - //send(cli_socket, JsonString, sizeof(JsonString), 0); - //int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(JsonString), JsonString); - //if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - //{ - // printf("\nsend error\n"); - //} - //printf("\nget apnr info \n"); - if (root) { - cJSON_Delete(root); - root = NULL; - } - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - } - if (config_root) { - cJSON_Delete(config_root); - config_root = NULL; - } - } - else - printf("config.json parse FAIL.\n"); - } - } - //printf("\n[web process]start 17-5\n"); - closesocket(cli_socket); - } - // ======================================================================================== - // Ken 2022-09-22 - else if (strcmp(urlBuffer, "/getradar") == 0) - { - char radarPATH[1024] = { 0 }; - strcpy(radarPATH, exePath); - strcat(radarPATH, "radar.json"); - char *filename = radarPATH; - if (!FileExist(filename)) - printf("%s doesn't exist.\n", filename); - else - { - char *fileBuf = ReadAllBytes(filename); - if (fileBuf) - { - cJSON *config_root; - char *JsonString = NULL; - config_root = cJSON_Parse(fileBuf); - if (fileBuf) - { - free(fileBuf); - fileBuf = NULL; - } - if (config_root) - { - JsonString = cJSON_PrintUnformatted(config_root); - strcat(contentBuffer, JsonString); - strcpy(beforeSendBuffer, contentBuffer); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) - perror("send error #28"); - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - if (config_root) - { - cJSON_Delete(config_root); - config_root = NULL; - } - } - else - printf("radar.json parse FAIL.\n"); - } - } - // ======================================================================================== - // printf("\n[web process]start 17-5\n"); - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/get_search_info?",17) == 0) //claire add - { -#if defined GY_OS_AMBA || defined GY_OS_NOVA - //printf("\n[web process]start 18\n"); - pthread_mutex_lock(&mutex_enable_lpr_db); - memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); - firstBuffer[strlen(urlBuffer)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer+17); - //printf("\n------beforeSendBuffer:%s\n", beforeSendBuffer); - cgi_get_search_info(cli_socket, beforeSendBuffer); - //printf("\n[web process]end 18888\n"); - pthread_mutex_unlock(&mutex_enable_lpr_db); - //printf("\n[web process]end 18\n"); - /* - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error\n"); - */ -#endif - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/set_search_info?",17) == 0) //claire add - { -#if defined GY_OS_AMBA || defined GY_OS_NOVA - //printf("\n[web process]start 19\n"); - //printf("\n-------urlBufffer:%s\n",urlBuffer); - - memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); - firstBuffer[strlen(urlBuffer)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer+17); - char *temp_beforeSendBuffer = StrReplace(beforeSendBuffer, "%20", " "); - strcpy(beforeSendBuffer, temp_beforeSendBuffer); - - if (temp_beforeSendBuffer != NULL) { - free(temp_beforeSendBuffer); - temp_beforeSendBuffer = NULL; - } - - url_decode(beforeSendBuffer, strlen(beforeSendBuffer)); - - //printf("\n-------beforeSendBuffer:%s\n", beforeSendBuffer); - - cgi_set_search_info(cli_socket, beforeSendBuffer); - -#endif - closesocket(cli_socket); - } -#if 0 - // joy - else if (strncmp(urlBuffer, "/import_face_list", strlen("/import_face_list")) == 0) - { - printf("\n-------------import face list\n"); - g_count_lpr_insert_times = 0; - - memset(g_headerBuffer,0x00, BUFSIZE_V2); - memset(g_multiPartBoundary, 0x00, MAX_MSG_LEN); - memset(g_contentBuffer, 0x00, CONTENT_BUFSIZE); - - strcpy(g_headerBuffer, headerBuffer); - strcpy(g_multiPartBoundary, multiPartBoundary); - g_bIsMultipart = bIsMultipart; - strcpy(g_contentBuffer, contentBuffer); - g_nTotalContentLen = nTotalContentLen; - - printf("\ng_headerBuffer -------------%s\n",g_headerBuffer); - printf("\ng_contentBuffer-------------%s\n",g_contentBuffer); - printf("\ng_multiPartBoundary-------------%s\n",g_multiPartBoundary); - printf("\ng_bIsMultipart-------------%d\n",g_bIsMultipart); - printf("\ng_nTotalContentLen-------------%ld\n",g_nTotalContentLen); - - pthread_t import_face_list_file_thread_id; - // 另外開 thread 來儲存檔案資料 - if (pthread_create(&import_face_list_file_thread_id, 0, import_face_list_file_thread, NULL)) - { - printf("create import_face_list_file_thread faile \n"); - } - - strcpy(beforeSendBuffer, ""); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend\n"); - - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/face_list?", 11) == 0) //claire add - { - printf("face list = %s \n", urlBuffer); - - if (unlockingKeyInnoFR == 1) { - if (strstr(urlBuffer, "select=") != NULL || - strstr(urlBuffer, "flist=") != NULL || - strstr(urlBuffer, "download=") != NULL) - { - ///get_search_info_face - - pthread_mutex_lock(&mutex_enable_face_db); - //printf("select url buf: %s \n", urlBuffer); - - memset(firstBuffer, 0, sizeof(firstBuffer)); - - //printf("urlBuffer = %s \n", urlBuffer); - - - //printf("no err str \n"); - memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); - - printf("firstbuf = %s \n", firstBuffer); - - - //firstBuffer[strlen(urlBuffer)] = '\0'; - - strcpy(beforeSendBuffer, firstBuffer + 11); - //printf("beforeSendBuffer = %s \n", beforeSendBuffer); - cgi_get_search_info_face(cli_socket, beforeSendBuffer); - //printf("\n[web process]end 18888\n"); - pthread_mutex_unlock(&mutex_enable_face_db); - } - else if (strstr(urlBuffer, "delete=") != NULL || - strstr(urlBuffer, "clean=") != NULL || - strstr(urlBuffer, "add=") != NULL || - strstr(urlBuffer, "update=") != NULL - ) - { - ///set_search_info_face - - memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); - firstBuffer[strlen(urlBuffer)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 11); - char *temp_beforeSendBuffer = StrReplace(beforeSendBuffer, "%20", " "); - strcpy(beforeSendBuffer, temp_beforeSendBuffer); - - if (temp_beforeSendBuffer != NULL) { - free(temp_beforeSendBuffer); - temp_beforeSendBuffer = NULL; - } - - url_decode(beforeSendBuffer, strlen(beforeSendBuffer)); - - printf("\n-------beforeSendBuffer:%s\n", beforeSendBuffer); - //FACE_MSG_BLACKTABLE - cgi_set_search_info_face(cli_socket, beforeSendBuffer); - } - } - - closesocket(cli_socket); - } -#endif - else if (strncmp(urlBuffer, "/get_search_info_face?",22) == 0) // face - leo - { -#ifdef GY_OS_AMBA -#if 0 - if (unlockingKeyInnoFR == 1) { - pthread_mutex_lock(&mutex_enable_face_db); - //printf("select url buf: %s \n", urlBuffer); - - memset(firstBuffer, 0, sizeof(firstBuffer)); - - //printf("urlBuffer = %s \n", urlBuffer); - - - //printf("no err str \n"); - memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); - - //printf("firstbuf = %s \n", firstBuffer); - - //firstBuffer[strlen(urlBuffer)] = '\0'; - - strcpy(beforeSendBuffer, firstBuffer+22); - cgi_get_search_info_face(cli_socket, beforeSendBuffer); - //printf("\n[web process]end 18888\n"); - pthread_mutex_unlock(&mutex_enable_face_db); - - // sqlite_facegroup_add_list_white_face_list_fix(); - - // test_sfe_add_face_group(); - - //int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - //if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - // printf("\nsend error\n"); - - } -#endif -#endif - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/set_search_info_face?",22) == 0) // face - leo - { -#ifdef GY_OS_AMBA -#if 0 - if (unlockingKeyInnoFR == 1) { - //printf("\n[web process]start /set_search_info_face?\n"); - //printf("\n-------urlBufffer:%s\n",urlBuffer); - - memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); - firstBuffer[strlen(urlBuffer)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer+22); - char *temp_beforeSendBuffer = StrReplace(beforeSendBuffer, "%20", " "); - strcpy(beforeSendBuffer, temp_beforeSendBuffer); - - if (temp_beforeSendBuffer != NULL) { - free(temp_beforeSendBuffer); - temp_beforeSendBuffer = NULL; - } - - url_decode(beforeSendBuffer, strlen(beforeSendBuffer)); - - //printf("\n-------beforeSendBuffer:%s\n", beforeSendBuffer); - //FACE_MSG_BLACKTABLE - cgi_set_search_info_face(cli_socket, beforeSendBuffer); - } -#endif - -#endif - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/lpr_info?",10) == 0) //claire add - { -#if defined GY_OS_AMBA || defined GY_OS_NOVA - //printf("\n[web process]start 20\n"); - pthread_mutex_lock(&mutex_enable_lpr_db); - char *path = NULL; - memcpy(firstBuffer, urlBuffer, strlen(urlBuffer)); - firstBuffer[strlen(urlBuffer)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer+10); - - char l_lpr_cgi_param[BUFSIZE_V2] = {0}; - char l_count[16] = {0}; - //char l_action_lpr[16] = {0}; - char l_compare_str[16] = {0}; - - path = &beforeSendBuffer[0]; - - //set information - sprintf(l_compare_str,"set=status&"); - if(strncmp(path,l_compare_str,strlen(l_compare_str))==0) - { - strncpy(l_lpr_cgi_param, path+strlen(l_compare_str), strlen(path)-strlen(l_compare_str)); - l_lpr_cgi_param[strlen(l_lpr_cgi_param)] = '\0'; - - if ((strstr(path, "LPR_FLAG")) != NULL) - { - printf("\nin LPR_FLAG \n"); - - memset(l_compare_str, 0, sizeof(l_compare_str)); - sprintf(l_compare_str, "LPR_FLAG"); - getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); - if (strlen(l_count) != 0) - { - printf("set LPR_FLAG %s\n", l_count); - } - } - else if ((strstr(path, "LPR_WHITE_FLAG")) != NULL) - { - printf("\nin LPR_WHITE_FLAG \n"); - - memset(l_compare_str, 0, sizeof(l_compare_str)); - memset(l_count, 0, sizeof(l_count)); - sprintf(l_compare_str, "LPR_WHITE_FLAG"); - getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); - if (strlen(l_count) != 0) - { - printf("set LPR_WHITE_FLAG %s\n", l_count); - - if (strcmp(l_count, "0") == 0)//disable - { - char Cmd[MAX_CMD_SIZE] = { 0 }; - memset(Cmd, 0x00, sizeof(Cmd)); - sprintf(Cmd, "ch=system_setting&whitelist=No"); - memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra)); - //CgiCmdRtnCode rtn = - cgicmd_process(Cmd, _CGICMD_SET, beforeSendBuffer_xtra, BUFSIZE * 60); - } - else if (strcmp(l_count, "1") == 0)//disable//enable - { - char Cmd[MAX_CMD_SIZE] = { 0 }; - memset(Cmd, 0x00, sizeof(Cmd)); - sprintf(Cmd, "ch=system_setting&whitelist=Yes"); - memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra)); - //CgiCmdRtnCode rtn = - cgicmd_process(Cmd, _CGICMD_SET, beforeSendBuffer_xtra, BUFSIZE * 60); - } - } - } - else if ((strstr(path, "LPR_BLACK_FLAG")) != NULL) - { - printf("\nin LPR_BLACK_FLAG \n"); - - memset(l_compare_str, 0, sizeof(l_compare_str)); - memset(l_count, 0, sizeof(l_count)); - sprintf(l_compare_str, "LPR_BLACK_FLAG"); - getvalueForKey(l_lpr_cgi_param, l_compare_str, l_count); - if (strlen(l_count) != 0) - { - printf("set LPR_BLACK_FLAG %s\n", l_count); - - if (strcmp(l_count, "0") == 0)//disable - { - char Cmd[MAX_CMD_SIZE] = { 0 }; - memset(Cmd, 0x00, sizeof(Cmd)); - sprintf(Cmd, "ch=system_setting&blacklist=No"); - memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra));; - //CgiCmdRtnCode rtn = - cgicmd_process(Cmd, _CGICMD_SET, beforeSendBuffer_xtra, BUFSIZE * 60); - } - else if (strcmp(l_count, "1") == 0)//disable//enable - { - char Cmd[MAX_CMD_SIZE] = { 0 }; - memset(Cmd, 0x00, sizeof(Cmd)); - sprintf(Cmd, "ch=system_setting&blacklist=Yes"); - memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra)); - //CgiCmdRtnCode rtn = - cgicmd_process(Cmd, _CGICMD_SET, beforeSendBuffer_xtra, BUFSIZE * 60); - } - } - } - } - //get information - sprintf(l_compare_str,"get=status"); - if (strncmp(path, l_compare_str, strlen(l_compare_str)) == 0) - { - //printf("get LPR_FLAG & LPR_BLACK_FLAG & LPR_WHITE_FLAG status\n"); - - if ((strstr(path, "LPR_FLAG")) != NULL) { - //printf("\nin LPR_FLAG \n"); - } - else if ((strstr(path, "LPR_WHITE_FLAG")) != NULL) - { - //printf("\nin LPR_WHITE_FLAG \n"); - - char Cmd[MAX_CMD_SIZE] = { 0 }; - memset(Cmd, 0x00, sizeof(Cmd)); - sprintf(Cmd, "ch=system_setting&whitelist=all"); - memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra)); - //CgiCmdRtnCode rtn = - cgicmd_process(Cmd, _CGICMD_GET, beforeSendBuffer_xtra, BUFSIZE * 60); - } - else if ((strstr(path, "LPR_BLACK_FLAG")) != NULL) - { - //printf("\nin LPR_BLACK_FLAG \n"); - - char Cmd[MAX_CMD_SIZE] = { 0 }; - memset(Cmd, 0x00, sizeof(Cmd)); - sprintf(Cmd, "ch=system_setting&blacklist=all"); - memset(beforeSendBuffer_xtra, 0x00, sizeof(beforeSendBuffer_xtra)); - //CgiCmdRtnCode rtn = - cgicmd_process(Cmd, _CGICMD_GET, beforeSendBuffer_xtra, BUFSIZE * 60); - } - } -#endif //#ifdef GY_OS_AMBA - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #29\n"); - pthread_mutex_unlock(&mutex_enable_lpr_db); - - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/system?", 8) == 0) - { - //printf("\n[web process]start 21\n"); - - char Cmd[MAX_CMD_SIZE] = { 0 }; - memset(Cmd, 0x00, sizeof(Cmd)); - strcpy(Cmd, urlBuffer +8); - - #ifdef _DEBUG_AMBA - printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); - #endif - - CgiCmdType type; - type = _CGICMD_GET; - - CgiCmdRtnCode rtn = cgicmd_process(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); - - int default_version = 0; - if (rtn == _CGICMD_DEFAULT_NUMBER) { - - if (strncmp(urlBuffer, "/system?default=", 16) == 0) - { - char Cmd_temp[MAX_CMD_SIZE] = { 0 }; - strcpy(Cmd_temp, urlBuffer + 16); - - int check_if_not_digit = 0; - for (int index_cmd = 0; index_cmd < strlen(Cmd_temp); index_cmd++) - { - if (!isdigit(Cmd_temp[index_cmd])) - { - check_if_not_digit = 1; - break; - } - } - if (strlen(Cmd_temp) == 0) { - check_if_not_digit = 1; - } - - if (check_if_not_digit == 0) { - default_version = atoi(Cmd_temp); - } - } - } - - //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); - if (rtn == _CGICMD_DEFAULT_3 || rtn == _CGICMD_DEFAULT_ALL || (default_version >= 1 && default_version != 3)) - { - //printf("\nKKKKKKKKKKKKKKK 1\n"); - if (strlen(beforeSendBuffer_xtra) == 0) - { - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "OK"); - printf(msg); - strcpy(beforeSendBuffer_xtra, msg); - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #30\n"); - closesocket(cli_socket); - -#if 1 - //if (unlockingKeyInnoFR_success == 1) { - //face_engine_default(); - //usSleep(5000); - //} -#endif - - -#if 1 - char HEATMAP_DATA_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_bak.js"; - if (FileExist(HEATMAP_DATA_BAK_PATH)) { - int del = unlink(HEATMAP_DATA_BAK_PATH); - if (!del) { - //printf("HEATMAP_DATA_BAK_PATH is Deleted successfully."); - } - else { - printf("HEATMAP_DATA_BAK_PATH cannot be Deleted.\n"); - } - } - - char HEATMAP_DATA_1_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_1_bak.js"; - if (FileExist(HEATMAP_DATA_1_BAK_PATH)) { - int del = unlink(HEATMAP_DATA_1_BAK_PATH); - if (!del) { - //printf("HEATMAP_DATA_1_BAK_PATH is Deleted successfully."); - } - else { - printf("HEATMAP_DATA_1_BAK_PATH cannot be Deleted.\n"); - } - } - - char HEATMAP_DATA_2_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_2_bak.js"; - if (FileExist(HEATMAP_DATA_2_BAK_PATH)) { - int del = unlink(HEATMAP_DATA_2_BAK_PATH); - if (!del) { - //printf("HEATMAP_DATA_2_BAK_PATH is Deleted successfully."); - } - else { - printf("HEATMAP_DATA_2_BAK_PATH cannot be Deleted.\n"); - } - } - - char HEATMAP_DATA_3_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_3_bak.js"; - if (FileExist(HEATMAP_DATA_3_BAK_PATH)) { - int del = unlink(HEATMAP_DATA_3_BAK_PATH); - if (!del) { - //printf("HEATMAP_DATA_3_BAK_PATH is Deleted successfully."); - } - else { - printf("HEATMAP_DATA_3_BAK_PATH cannot be Deleted.\n"); - } - } - - char HEATMAP_DATA_4_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_4_bak.js"; - if (FileExist(HEATMAP_DATA_4_BAK_PATH)) { - int del = unlink(HEATMAP_DATA_4_BAK_PATH); - if (!del) { - //printf("HEATMAP_DATA_4_BAK_PATH is Deleted successfully."); - } - else { - printf("HEATMAP_DATA_4_BAK_PATH cannot be Deleted.\n"); - } - } - - char HEATMAP_DATA_5_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_5_bak.js"; - if (FileExist(HEATMAP_DATA_5_BAK_PATH)) { - int del = unlink(HEATMAP_DATA_5_BAK_PATH); - if (!del) { - //printf("HEATMAP_DATA_5_BAK_PATH is Deleted successfully."); - } - else { - printf("HEATMAP_DATA_5_BAK_PATH cannot be Deleted.\n"); - } - } - - char HEATMAP_DATA_6_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_6_bak.js"; - if (FileExist(HEATMAP_DATA_6_BAK_PATH)) { - int del = unlink(HEATMAP_DATA_6_BAK_PATH); - if (!del) { - //printf("HEATMAP_DATA_6_BAK_PATH is Deleted successfully."); - } - else { - printf("HEATMAP_DATA_6_BAK_PATH cannot be Deleted.\n"); - } - } - - char HEATMAP_DATA_7_BAK_PATH[256] = "/emmc/plugin/Aida_data/heatmap_data_7_bak.js"; - if (FileExist(HEATMAP_DATA_7_BAK_PATH)) { - int del = unlink(HEATMAP_DATA_7_BAK_PATH); - if (!del) { - //printf("HEATMAP_DATA_7_BAK_PATH is Deleted successfully."); - } - else { - printf("HEATMAP_DATA_7_BAK_PATH cannot be Deleted.\n"); - } - } -#endif - - char CONFIG_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config.json"; - char CONFIG_BAK_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config_bak.json"; - char CONFIG_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config_install.json"; - - if (FileExist(CONFIG_JSON_PATH)) { - int del = unlink(CONFIG_JSON_PATH); - if (!del) { - //printf("CONFIG_JSON_PATH is Deleted successfully."); - } - else { - printf("CONFIG_JSON_PATH cannot be Deleted.\n"); - } - } - - if (FileExist(CONFIG_BAK_JSON_PATH)) { - int del = unlink(CONFIG_BAK_JSON_PATH); - if (!del) { - //printf("CONFIG_BAK_JSON_PATH is Deleted successfully."); - } - else { - printf("CONFIG_BAK_JSON_PATH cannot be Deleted.\n"); - } - } - - char CONFIG_CUSTOM_1_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config_custom_1.json"; - - if (rtn == _CGICMD_DEFAULT_ALL) { - - if (FileExist(CONFIG_INSTALL_JSON_PATH)) { - int del = unlink(CONFIG_INSTALL_JSON_PATH); - if (!del) { - //printf("events is Deleted successfully."); - } - else { - printf("CONFIG_INSTALL_JSON_PATH cannot be Deleted.\n"); - } - } - - CopyFileTo(CONFIG_CUSTOM_1_JSON_PATH, CONFIG_INSTALL_JSON_PATH); - } - else if (default_version >= 1 && default_version != 3) { - if (FileExist(CONFIG_INSTALL_JSON_PATH)) { - int del = unlink(CONFIG_INSTALL_JSON_PATH); - if (!del) { - //printf("events is Deleted successfully."); - } - else { - printf("CONFIG_INSTALL_JSON_PATH cannot be Deleted.\n"); - } - } - - char CONFIG_CUSTOM_NUM_JSON_PATH[1024] = { 0 }; - sprintf(CONFIG_CUSTOM_NUM_JSON_PATH, "/emmc/plugin/Aida_data/config_custom_%d.json", default_version); - CopyFileTo(CONFIG_CUSTOM_NUM_JSON_PATH, CONFIG_INSTALL_JSON_PATH); - } - else { - //_CGICMD_DEFAULT_3 - } - - CopyFileTo(CONFIG_INSTALL_JSON_PATH, CONFIG_JSON_PATH); - - char* fileBuf = ReadAllBytes(CONFIG_JSON_PATH); - if (fileBuf) { - cJSON * about_box, *root,*system_setting; - root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - about_box = cJSON_GetObjectItem(root, "about_box"); - system_setting = cJSON_GetObjectItem(root, "system_setting"); - cJSON_ReplaceItemInObject(about_box, "unlocking key", cJSON_CreateString(strUnlockingKey)); - cJSON_ReplaceItemInObject(system_setting, "enable_cloud", cJSON_CreateString("No")); - cJSON_ReplaceItemInObject(system_setting, "enable_python", cJSON_CreateString("No")); - cJSON_ReplaceItemInObject(system_setting, "enable_python_file", cJSON_CreateString("No python running.")); - cJSON_ReplaceItemInObject(system_setting, "enable_special_edition", cJSON_CreateString("No")); - char* JsonString = cJSON_Print(root); - - FILE *f = fopen(CONFIG_JSON_PATH, "w"); - if (f == NULL) - { - - } - else { - - fprintf(f, "%s\n", JsonString); - fclose(f); - CopyFileTo(CONFIG_JSON_PATH, CONFIG_BAK_JSON_PATH); - } - - if (JsonString) { - free(JsonString); - JsonString = NULL; - } - } - - char COLD_OBJECTS_JSON_PATH[1024] = "/emmc/plugin/Aida_data/cold_objects.json"; - char COLD_OBJECTS_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/cold_objects_install.json"; - if (FileExist(COLD_OBJECTS_JSON_PATH)) { - int del = unlink(COLD_OBJECTS_JSON_PATH); - if (!del) { - //printf("cold_objects is Deleted successfully."); - } - else { - printf("COLD_OBJECTS_JSON_PATH cannot be Deleted.\n"); - } - } - CopyFileTo(COLD_OBJECTS_INSTALL_JSON_PATH, COLD_OBJECTS_JSON_PATH); - - char EVENTS_JSON_PATH[1024] = "/emmc/plugin/Aida_data/events.json"; - char EVENTS_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/events_install.json"; - char EVENTS_BAK_JSON_PATH[1024] = "/emmc/plugin/Aida_data/events_bak.json"; - char EVENTS_CUSTOM_1_JSON_PATH[1024] = "/emmc/plugin/Aida_data/events_custom_1.json"; - - if (FileExist(EVENTS_JSON_PATH)) { - int del = unlink(EVENTS_JSON_PATH); - if (!del) { - //printf("events is Deleted successfully."); - } - else { - printf("EVENTS_JSON_PATH cannot be Deleted.\n"); - } - } - - if (FileExist(EVENTS_BAK_JSON_PATH)) { - int del = unlink(EVENTS_BAK_JSON_PATH); - if (!del) { - //printf("events is Deleted successfully."); - } - else { - printf("EVENTS_BAK_JSON_PATH cannot be Deleted.\n"); - } - } - - if(rtn == _CGICMD_DEFAULT_ALL){ - - if (FileExist(EVENTS_INSTALL_JSON_PATH)) { - int del = unlink(EVENTS_INSTALL_JSON_PATH); - if (!del) { - //printf("events is Deleted successfully."); - } - else { - printf("EVENTS_INSTALL_JSON_PATH cannot be Deleted.\n"); - } - } - - CopyFileTo(EVENTS_CUSTOM_1_JSON_PATH, EVENTS_INSTALL_JSON_PATH); - } - else if (default_version >= 1 && default_version != 3) { - if (FileExist(EVENTS_INSTALL_JSON_PATH)) { - int del = unlink(EVENTS_INSTALL_JSON_PATH); - if (!del) { - //printf("events is Deleted successfully."); - } - else { - printf("EVENTS_INSTALL_JSON_PATH cannot be Deleted.\n"); - } - } - - char EVENTS_CUSTOM_NUM_JSON_PATH[1024] = { 0 }; - sprintf(EVENTS_CUSTOM_NUM_JSON_PATH,"/emmc/plugin/Aida_data/events_custom_%d.json", default_version); - CopyFileTo(EVENTS_CUSTOM_NUM_JSON_PATH, EVENTS_INSTALL_JSON_PATH); - } - else { - //_CGICMD_DEFAULT_3 - } - - CopyFileTo(EVENTS_INSTALL_JSON_PATH, EVENTS_JSON_PATH); - - char EMAILS_JSON_PATH[1024] = "/emmc/plugin/Aida_data/emails.json"; - char EMAILS_BAK_JSON_PATH[1024] = "/emmc/plugin/Aida_data/emails_bak.json"; - if (FileExist(EMAILS_JSON_PATH)) { - int del = unlink(EMAILS_JSON_PATH); - if (!del) { - //printf("emails is Deleted successfully."); - } - else { - printf("EMAILS_JSON_PATH cannot be Deleted.\n"); - } - } - - if (FileExist(EMAILS_BAK_JSON_PATH)) { - int del = unlink(EMAILS_BAK_JSON_PATH); - if (!del) { - //printf("emails is Deleted successfully."); - } - else { - printf("EMAILS_BAK_JSON_PATH cannot be Deleted.\n"); - } - } - - char TOF_JSON_PATH[1024] = "/emmc/plugin/Aida_data/tof.json"; - char TOF_BAK_JSON_PATH[1024] = "/emmc/plugin/Aida_data/tof_bak.json"; - if (FileExist(TOF_JSON_PATH)) { - int del = unlink(TOF_JSON_PATH); - if (!del) { - //printf("tof is Deleted successfully."); - } - else { - printf("TOF_JSON_PATH cannot be Deleted.\n"); - } - } - - if (FileExist(TOF_BAK_JSON_PATH)) { - int del = unlink(TOF_BAK_JSON_PATH); - if (!del) { - //printf("tof is Deleted successfully."); - } - else { - printf("TOF_BAK_JSON_PATH cannot be Deleted.\n"); - } - } - - { - FILE * pPipe; - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - sprintf(cmd, "rm -r -f /emmc/plugin/Aida_data/storage"); - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); - } - - { - FILE * pPipe; - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - sprintf(cmd, "rm -r -f /emmc/plugin/Aida_data/sfe/storage"); - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); - } - - { - FILE * pPipe; - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - sprintf(cmd, "rm -r -f /emmc/plugin/Aida_data/playback"); - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); - } - - - g_write_config_file_dirty_flag = 0; - - //memset(msg, 0x00, sizeof(msg)); - //sprintf(msg, (default_dataset_for_jsonfile() > 0 ? "Default failed!" : "Default OK.")); - //printf(msg); - //strcpy(beforeSendBuffer_xtra, msg); - - - printf("\n--------------------reload 1\n"); - - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); - printf(msg); - strcat(beforeSendBuffer_xtra, msg); - - char db_fflprPATH[1024] = { 0 }; - char db_fflpr_installPATH[1024] = { 0 }; - char db_facePATH[1024] = { 0 }; - char db_face_installPATH[1024] = { 0 }; - - char buf[1024] = { 0 }; - readlink("/proc/self/exe", buf, sizeof(buf)); - char exePath[1024] = { 0 }; - getFilePath(buf, exePath, 1024); - - strcpy(db_fflprPATH, exePath); - strcpy(db_fflpr_installPATH, exePath); - strcpy(db_facePATH, exePath); - strcpy(db_face_installPATH, exePath); - - strcat(db_fflprPATH, "db_fflpr.db"); - strcat(db_fflpr_installPATH, "db_fflpr_install_2.db"); - - strcat(db_facePATH, "db_face.db"); - strcat(db_face_installPATH, "db_face_install_2.db"); - -#ifdef GY_OS_AMBA - if (unlockingKeyInnoFR_success == 1) { -#if 0 - char urlBuffer_2[256] = "/set_search_info?clean=log"; - char urlBuffer_3[256] = "/set_search_info?clean=visitor"; - char urlBuffer_4[256] = "/set_search_info?clean=watch"; - char urlBuffer_5[256] = "/set_search_info?clean=vip"; - - memcpy(firstBuffer, urlBuffer_4, strlen(urlBuffer_4)); - firstBuffer[strlen(urlBuffer_4)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 17); - cgi_set_search_info_face(cli_socket, beforeSendBuffer); - - memcpy(firstBuffer, urlBuffer_5, strlen(urlBuffer_5)); - firstBuffer[strlen(urlBuffer_5)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 17); - cgi_set_search_info_face(cli_socket, beforeSendBuffer); - - memcpy(firstBuffer, urlBuffer_2, strlen(urlBuffer_2)); - firstBuffer[strlen(urlBuffer_2)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 17); - cgi_set_search_info_face(cli_socket, beforeSendBuffer); - - memcpy(firstBuffer, urlBuffer_3, strlen(urlBuffer_3)); - firstBuffer[strlen(urlBuffer_3)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 17); - cgi_set_search_info_face(cli_socket, beforeSendBuffer); -#endif - pthread_mutex_lock(&mutex_enable_face_db); - CopyFileTo(db_face_installPATH, db_facePATH); - pthread_mutex_unlock(&mutex_enable_face_db); - } -#endif -#if 0 - char urlBuffer_2[256] = "/set_search_info?clean=log"; - char urlBuffer_3[256] = "/set_search_info?clean=customer"; - char urlBuffer_4[256] = "/set_search_info?clean=black"; - char urlBuffer_5[256] = "/set_search_info?clean=white"; - - memcpy(firstBuffer, urlBuffer_4, strlen(urlBuffer_4)); - firstBuffer[strlen(urlBuffer_4)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 17); - cgi_set_search_info(cli_socket, beforeSendBuffer); - - memcpy(firstBuffer, urlBuffer_5, strlen(urlBuffer_5)); - firstBuffer[strlen(urlBuffer_5)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 17); - cgi_set_search_info(cli_socket, beforeSendBuffer); - - memcpy(firstBuffer, urlBuffer_2, strlen(urlBuffer_2)); - firstBuffer[strlen(urlBuffer_2)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 17); - cgi_set_search_info(cli_socket, beforeSendBuffer); - - memcpy(firstBuffer, urlBuffer_3, strlen(urlBuffer_3)); - firstBuffer[strlen(urlBuffer_3)] = '\0'; - strcpy(beforeSendBuffer, firstBuffer + 17); - cgi_set_search_info(cli_socket, beforeSendBuffer); -#endif - pthread_mutex_lock(&mutex_enable_lpr_db); - CopyFileTo(db_fflpr_installPATH, db_fflprPATH); - pthread_mutex_unlock(&mutex_enable_lpr_db); - closesocket(cli_socket); - -#ifdef GY_OS_AMBA - usSleep(1000000); -#else - g_check_run_nova_detection = 0; - system("killall -15 nova_driver"); - usSleep(10000000); - - char CONFIG_SMALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config_small.json"; - char CONFIG_SMALL_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/config_small_install.json"; - - if (FileExist(CONFIG_SMALL_JSON_PATH)) { - int del = unlink(CONFIG_SMALL_JSON_PATH); - if (!del) { - //printf("CONFIG_SMALL_JSON_PATH is Deleted successfully."); - } - else { - printf("CONFIG_SMALL_JSON_PATH cannot be Deleted.\n"); - } - } - - CopyFileTo(CONFIG_SMALL_INSTALL_JSON_PATH, CONFIG_SMALL_JSON_PATH); -#endif - - pthread_t auto_build_smart_events_thread_id; - if (pthread_create(&auto_build_smart_events_thread_id, 0, auto_build_smart_events, NULL)) - { - printf("create auto_build_smart_events thread faile \n"); - } - pthread_join(auto_build_smart_events_thread_id, NULL); - - //stop_test_nn_cavalry(); - - printf("\n[---CGICMD DEFAULT---]: reboot to release memory\n"); - - char temp_msg[8192] = { 0 }; - snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "reboot to release memory"); - write_to_logs_html(temp_msg, "CGICMD DEFAULT", "CGI_REBOOT", "Yes"); - write_to_log_if_error(temp_msg, "CGICMD DEFAULT", "CGI_REBOOT"); - - pthread_t auto_reboot_thread_id; - if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL)) - { - printf("create auto reboot thread faile \n"); - } - } - else - { - if (strlen(beforeSendBuffer_xtra) == 0) - { - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "Invalid operation."); - printf(msg); - strcpy(beforeSendBuffer_xtra, msg); - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #30\n"); - closesocket(cli_socket); - } - } - else if ((strncmp(urlBuffer, "/getconfig?coldobjects=", 23) == 0) || (strncmp(urlBuffer, "/setconfig?coldobjects&", 23) == 0)) - { - //printf("\n[web process]start 22\n"); - char Cmd[MAX_CMD_SIZE] = { 0 }; - memset(Cmd, 0x00, sizeof(Cmd)); - -#ifdef _DEBUG_AMBA - printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); -#endif //_DEBUG_AMBA - CgiCmdType type; - CgiCmdRtnCode rtn; - rtn = _CGICMD_FAIL; - - if (strncmp(urlBuffer, "/getconfig?coldobjects=", 23) == 0) - { - type = _CGICMD_GET; - strcpy(Cmd, urlBuffer + 11); - - char Cmd_temp[MAX_CMD_SIZE] = { 0 }; - memset(Cmd_temp, 0x00, sizeof(Cmd_temp)); - strcpy(Cmd_temp, urlBuffer + 23); - - if (strcmp(Cmd_temp, "clean") == 0) { - char COLD_OBJECTS_JSON_PATH[1024] = "/emmc/plugin/Aida_data/cold_objects.json"; - char COLD_OBJECTS_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/cold_objects_install.json"; - if (FileExist(COLD_OBJECTS_JSON_PATH)) { - int del = unlink(COLD_OBJECTS_JSON_PATH); - if (!del) { - //printf("cold_objects is Deleted successfully."); - } - else { - printf("COLD_OBJECTS_JSON_PATH cannot be Deleted.\n"); - } - } - CopyFileTo(COLD_OBJECTS_INSTALL_JSON_PATH, COLD_OBJECTS_JSON_PATH); - rtn = _CGICMD_RELOAD; - } - else - rtn = cgicmd_process_cold_objects(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); - } - else if(strncmp(urlBuffer, "/setconfig?coldobjects&", 23) == 0) - { - strcpy(Cmd, urlBuffer + 23); - - int iSetColdZoneResult = 0; - - if ((int)strlen(Cmd) >= 1) - { - iSetColdZoneResult = SetColdZone(Cmd); - - if (iSetColdZoneResult == 0) - { - WriteColdZoneJsonFile(); - rtn = _CGICMD_RELOAD; - } - else - rtn = _CGICMD_FAIL; - - } - - //if (Cmd) - - /* - printf("\n----------[coldobjects]--------------\n"); - printf("\nx: %d\n", x_coldobject); - printf("\ny: %d\n", y_coldobject); - printf("\nw: %d\n", w_coldobject); - printf("\nh: %d\n", h_coldobject); - printf("\nobject: %s\n", object_coldobject); - printf("\n-------------------------------------\n"); - */ - } - else - rtn = _CGICMD_FAIL; - - - //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); - if (rtn == _CGICMD_RELOAD) - { - memset(msg, 0x00, sizeof(msg)); - printf("\n--------------------reload 2\n"); - - g_write_config_file_dirty_flag = 0; - - write_config(); - - sprintf(msg, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); - printf(msg); - strcpy(beforeSendBuffer_xtra, msg); - } - else if (rtn == _CGICMD_SUCCESS) - { - if (type == _CGICMD_SET) { - g_write_config_file_dirty_flag = 1; - } - - if (strlen(beforeSendBuffer_xtra) == 0) - { - memset(msg, 0x00, sizeof(msg)); - //sprintf(msg, "Success."); - printf(msg); - strcpy(beforeSendBuffer_xtra, msg); - } - } - else - { - if (strlen(beforeSendBuffer_xtra) == 0) - { - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "Invalid operation."); - printf(msg); - strcpy(beforeSendBuffer_xtra, msg); - } - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #31\n"); - closesocket(cli_socket); - } - else if ((strncmp(urlBuffer, "/getconfig?detection_zone=", 26) == 0) || (strncmp(urlBuffer, "/setconfig?detection_zone&", 26) == 0)) - { - //printf("\n[web process]start 23\n"); - char Cmd[MAX_CMD_SIZE] = { 0 }; - memset(Cmd, 0x00, sizeof(Cmd)); - - #ifdef _DEBUG_AMBA - printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); - #endif - CgiCmdType type; - CgiCmdRtnCode rtn; - rtn = _CGICMD_FAIL; - if (strncmp(urlBuffer, "/getconfig?detection_zone=", 26) == 0) - { - type = _CGICMD_GET; - strcpy(Cmd, urlBuffer + 11); - rtn = cgicmd_process_detection_zone(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); - } - else if (strncmp(urlBuffer, "/setconfig?detection_zone&", 26) == 0) - { - strcpy(Cmd, urlBuffer + 26); - - const char *del = "&"; - const char *del2 = "="; - char data_detection_zone[MAX_DETECTION_ZONE*(MAX_SIZE_POINT *2+1)][STRSPLIT_SIZE]={0}; - int data_detection_zone_num = 0; - - char data_detection_zone_pair[MAX_DETECTION_ZONE*(MAX_SIZE_POINT * 2 + 1)][2][STRSPLIT_SIZE]={0}; - //int data_detection_zone_pair_num[MAX_DETECTION_ZONE*(MAX_SIZE_POINT * 2 + 1)] = { 0 }; - - int zone[MAX_DETECTION_ZONE] = { 0 }; - int x1[MAX_DETECTION_ZONE] = { 0 }; - int y1[MAX_DETECTION_ZONE] = { 0 }; - int x2[MAX_DETECTION_ZONE] = { 0 }; - int y2[MAX_DETECTION_ZONE] = { 0 }; - int x3[MAX_DETECTION_ZONE] = { 0 }; - int y3[MAX_DETECTION_ZONE] = { 0 }; - int x4[MAX_DETECTION_ZONE] = { 0 }; - int y4[MAX_DETECTION_ZONE] = { 0 }; - int x5[MAX_DETECTION_ZONE] = { 0 }; - int y5[MAX_DETECTION_ZONE] = { 0 }; - int x6[MAX_DETECTION_ZONE] = { 0 }; - int y6[MAX_DETECTION_ZONE] = { 0 }; - - if ((int)strlen(Cmd)>=1) - { - data_detection_zone_num = StrSplit(Cmd, data_detection_zone, del); - //printf("\n------UU:26\n"); - int i_temp = -1; - for (int i = 0; i < data_detection_zone_num; i++) - { - printf("\n%s\n", data_detection_zone[i]); - if (data_detection_zone[i]) - { - /*data_detection_zone_pair_num[i] = */StrSplit(data_detection_zone[i], data_detection_zone_pair[i], del2); - //printf("\n------UU:27\n"); - if (strcmp(data_detection_zone_pair[i][0], "zone") == 0 || - strcmp(data_detection_zone_pair[i][0], "Zone") == 0) { - i_temp++; - zone[i_temp] = atoi(data_detection_zone_pair[i][1]); - } - - if (i_temp >= 0) - { - if (strcmp(data_detection_zone_pair[i][0], "x1") == 0 || - strcmp(data_detection_zone_pair[i][0], "X1") == 0) { - x1[i_temp] = atoi(data_detection_zone_pair[i][1]); - } - else if (strcmp(data_detection_zone_pair[i][0], "y1") == 0 || - strcmp(data_detection_zone_pair[i][0], "Y1") == 0) { - y1[i_temp] = atoi(data_detection_zone_pair[i][1]); - } - else if (strcmp(data_detection_zone_pair[i][0], "x2") == 0 || - strcmp(data_detection_zone_pair[i][0], "X2") == 0) { - x2[i_temp] = atoi(data_detection_zone_pair[i][1]); - } - else if (strcmp(data_detection_zone_pair[i][0], "y2") == 0 || - strcmp(data_detection_zone_pair[i][0], "Y2") == 0) { - y2[i_temp] = atoi(data_detection_zone_pair[i][1]); - } - else if (strcmp(data_detection_zone_pair[i][0], "x3") == 0 || - strcmp(data_detection_zone_pair[i][0], "X3") == 0) { - x3[i_temp] = atoi(data_detection_zone_pair[i][1]); - } - else if (strcmp(data_detection_zone_pair[i][0], "y3") == 0 || - strcmp(data_detection_zone_pair[i][0], "Y3") == 0) { - y3[i_temp] = atoi(data_detection_zone_pair[i][1]); - } - else if (strcmp(data_detection_zone_pair[i][0], "x4") == 0 || - strcmp(data_detection_zone_pair[i][0], "X4") == 0) { - x4[i_temp] = atoi(data_detection_zone_pair[i][1]); - } - else if (strcmp(data_detection_zone_pair[i][0], "y4") == 0 || - strcmp(data_detection_zone_pair[i][0], "Y4") == 0) { - y4[i_temp] = atoi(data_detection_zone_pair[i][1]); - } - else if (strcmp(data_detection_zone_pair[i][0], "x5") == 0 || - strcmp(data_detection_zone_pair[i][0], "X5") == 0) { - x5[i_temp] = atoi(data_detection_zone_pair[i][1]); - } - else if (strcmp(data_detection_zone_pair[i][0], "y5") == 0 || - strcmp(data_detection_zone_pair[i][0], "Y5") == 0) { - y5[i_temp] = atoi(data_detection_zone_pair[i][1]); - } - else if (strcmp(data_detection_zone_pair[i][0], "x6") == 0 || - strcmp(data_detection_zone_pair[i][0], "X6") == 0) { - x6[i_temp] = atoi(data_detection_zone_pair[i][1]); - } - else if (strcmp(data_detection_zone_pair[i][0], "y6") == 0 || - strcmp(data_detection_zone_pair[i][0], "Y6") == 0) { - y6[i_temp] = atoi(data_detection_zone_pair[i][1]); - } - } - } - } - } - /* - printf("\n----------[detection_zone]--------------\n"); - for (int i = 0; i < MAX_DETECTION_ZONE; i++) { - printf("\nzone: %d\n", zone[i]); - printf("\nx1: %d\n", x1[i]); - printf("\ny1: %d\n", y1[i]); - printf("\nx2: %d\n", x2[i]); - printf("\ny2: %d\n", y2[i]); - printf("\nx3: %d\n", x3[i]); - printf("\ny3: %d\n", y3[i]); - printf("\nx4: %d\n", x4[i]); - printf("\ny4: %d\n", y4[i]); - printf("\nx5: %d\n", x5[i]); - printf("\ny5: %d\n", y5[i]); - printf("\nx6: %d\n", x6[i]); - printf("\ny6: %d\n", y6[i]); - } - printf("\n-------------------------------------\n"); - */ - - if (data_detection_zone_num == 52 || data_detection_zone_num == 36) - { - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - - char exePath[1024] = {}; - //printf("exePath:%s\n", exePath); - getFilePath(buf, exePath, 1024); - //printf("exePath:%s\n", exePath); - - char configPATH[1024] = { 0 }; - strcpy(configPATH, exePath); - strcat(configPATH, "config.json"); - - char *filename_config = configPATH; - if (!FileExist(filename_config)) - { - printf("%s doesn't exist.\n", filename_config); - rtn = _CGICMD_FAIL; - } - else - { - //size_t nfileSize_cofnig = ReadFileSize(filename_config); - char *fileBuf_config = ReadAllBytes(filename_config); - if (fileBuf_config) { - cJSON *root = NULL; - root = cJSON_Parse(fileBuf_config); - - if (fileBuf_config) { - free(fileBuf_config); - fileBuf_config = NULL; - } - - if (root == NULL) - { - printf("root_config is NULL\n"); - rtn = _CGICMD_FAIL; - } - else - { - cJSON *view_setting, *camera01, *temp_detection_zone, *detect; - - view_setting = cJSON_GetObjectItem(root, "view_setting"); - camera01 = cJSON_GetObjectItem(view_setting, "camera01"); - temp_detection_zone = cJSON_GetObjectItem(camera01, "detection_zone"); - - int i = 0; - cJSON_ArrayForEach(detect, temp_detection_zone) - { - for (int j = 0; j < MAX_DETECTION_ZONE; j++) - { - if ((i + 1) == zone[j]) - { - cJSON_ReplaceItemInObject(detect, "x1", cJSON_CreateNumber(x1[j])); - cJSON_ReplaceItemInObject(detect, "y1", cJSON_CreateNumber(y1[j])); - cJSON_ReplaceItemInObject(detect, "x2", cJSON_CreateNumber(x2[j])); - cJSON_ReplaceItemInObject(detect, "y2", cJSON_CreateNumber(y2[j])); - cJSON_ReplaceItemInObject(detect, "x3", cJSON_CreateNumber(x3[j])); - cJSON_ReplaceItemInObject(detect, "y3", cJSON_CreateNumber(y3[j])); - cJSON_ReplaceItemInObject(detect, "x4", cJSON_CreateNumber(x4[j])); - cJSON_ReplaceItemInObject(detect, "y4", cJSON_CreateNumber(y4[j])); - - if (data_detection_zone_num == 52) { - cJSON_ReplaceItemInObject(detect, "x5", cJSON_CreateNumber(x5[j])); - cJSON_ReplaceItemInObject(detect, "y5", cJSON_CreateNumber(y5[j])); - cJSON_ReplaceItemInObject(detect, "x6", cJSON_CreateNumber(x6[j])); - cJSON_ReplaceItemInObject(detect, "y6", cJSON_CreateNumber(y6[j])); - } - else { - cJSON_ReplaceItemInObject(detect, "x5", cJSON_CreateNumber(0)); - cJSON_ReplaceItemInObject(detect, "y5", cJSON_CreateNumber(0)); - cJSON_ReplaceItemInObject(detect, "x6", cJSON_CreateNumber(0)); - cJSON_ReplaceItemInObject(detect, "y6", cJSON_CreateNumber(0)); - } - } - } - i++; - - if (i < MAX_DETECTION_ZONE) { - - } - else { - break; - } - } - - char* JsonString = cJSON_Print(root); - FILE *fp; - - if ((fp = fopen(filename_config, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - - rtn = _CGICMD_SUCCESS; - printf("\n--------------------reload 3\n"); - reload_dataset_from_jsonfile(); - } - else - { - printf("Fail to open config.json \n"); - rtn = _CGICMD_FAIL; - } - - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - } - if (root) { - cJSON_Delete(root); - root = NULL; - } - } - } - } - else - { - printf("Fail detection_zone numbers (data_detection_zone_num: %d)\n", data_detection_zone_num); - rtn = _CGICMD_FAIL; - } - } - else - rtn = _CGICMD_FAIL; - - //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); - if (rtn == _CGICMD_SUCCESS) - { - if (strlen(beforeSendBuffer_xtra) == 0) - { - memset(msg, 0x00, sizeof(msg)); - //sprintf(msg, "Success."); - printf(msg); - strcpy(beforeSendBuffer_xtra, msg); - } - } - else - { - if (strlen(beforeSendBuffer_xtra) == 0) - { - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "Invalid operation."); - printf(msg); - strcpy(beforeSendBuffer_xtra, msg); - } - } - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #31\n"); - closesocket(cli_socket); - } -#if 0 - else if (strncmp(urlBuffer, "/get_jsonclassid=", 17) == 0) - { - memset(msg, 0x00, sizeof(msg)); - - char Cmd[MAX_CMD_SIZE] = { 0 }; - memset(Cmd, 0x00, sizeof(Cmd)); - strcpy(Cmd, urlBuffer + 17); - - get_classname(atoi(Cmd), msg); - - strcpy(beforeSendBuffer, msg); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #38-123\n"); - - closesocket(cli_socket); - - } -#endif - else if (strncmp(urlBuffer, "/get_cloud_statue", 17) == 0) - { - strcpy(beforeSendBuffer, ""); - strcat(beforeSendBuffer, SystemSetting.cloud_statue); - strcat(beforeSendBuffer, ",,,"); - strcat(beforeSendBuffer, SystemSetting.cloud_v2_statue); - strcat(beforeSendBuffer, ",,,"); - strcat(beforeSendBuffer, SystemSetting.cloud_record_v2_statue); - - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #38-122\n"); - - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/do_cloud_v2_statue", 19) == 0) - { - if (strcmp(SystemSetting.enable_cloud_v2, "Yes") == 0) - { - //for (int count_delay = 0; count_delay < 5; count_delay++) - if (QueueSize(_GETALARMMOTION) < MAX_QUEUE_SIZE) - { - //if (QueueSize(_GETALARMMOTION) < 1) - { - - QueueInfo q_info = { 0 }; - strcpy(q_info.post_url, "cloud_v2"); - - if (strlen(SystemSetting.cloud_v2_content) >= 1) { - strcpy(q_info.cloud_v2_aiengine, SystemSetting.cloud_v2_content); - } - else - q_info.cloud_v2_aiengine[0] = '\0'; - - //strcpy(SystemSetting.cloud_v2_statue, ""); - - pthread_mutex_lock(&mutex_getalarmmotion); - QueuePush(q_info, _GETALARMMOTION); - pthread_mutex_unlock(&mutex_getalarmmotion); - //break; - } - //usSleep(100000); - } - } - - strcpy(beforeSendBuffer,""); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #38-1231\n"); - - } -#if 0 - else if (strncmp(urlBuffer, "/do_cloud_record_v2_statue", 26) == 0) - { - if (strcmp(SystemSetting.enable_cloud_record_v2, "Yes") == 0) - { - //for (int count_delay = 0; count_delay < 5; count_delay++) - if (QueueSize(_GETALARMMOTION) < MAX_QUEUE_SIZE) - { - //if (QueueSize(_GETALARMMOTION) < 1) - { - QueueInfo q_info = { 0 }; - strcpy(q_info.post_url, "cloud_record_v2"); - - if (strlen(SystemSetting.cloud_record_v2_content) >= 1) { - strcpy(q_info.record_cloud_v2_aiengine, SystemSetting.cloud_record_v2_content); - } - else - q_info.record_cloud_v2_aiengine[0] = '\0'; - - //strcpy(SystemSetting.cloud_record_v2_statue, ""); - pthread_mutex_lock(&mutex_getalarmmotion); - QueuePush(q_info, _GETALARMMOTION); - pthread_mutex_unlock(&mutex_getalarmmotion); - //break; - } - //usSleep(100000); - } - } - - strcpy(beforeSendBuffer, ""); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #38-12312\n"); - - } -#endif -#ifdef GY_OS_AMBA - else if (strncmp(urlBuffer, "/ptzcontrol?enable_ptz=Yes", 26) == 0) - { - memset(msg, 0x00, sizeof(msg)); - - if (IsPTZ() == 1) - { - //UpdatePTZIPcamSetting(); - - int iHomePreset = GetHomePreset(); - - if (iHomePreset >= 0 && iHomePreset <= 256) - { - if (IsPTZatHomePos() != 1) - { - GoPreset(iHomePreset); - } - - StartStopAutopan(1); - - /*int zone_to_preset[4]; - - for (int i = 0; i < 4; i++) - { - zone_to_preset[i] = 0; - - if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL - && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) - { - zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); - } - }*/ - - //Update PTZ - strcpy(viewChannelData[0].ptz_enable_tracking, "Yes"); - write_to_enable_tracking("Yes"); - - /*UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, - viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, - viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, - viewChannelData[0].ptz_tracking_resume_dwell, viewDetectionZone[0][0].metadata1, zone_to_preset);*/ - - UpdatePTZConfigSetting(); - SetPtzSensitivity(viewChannelData[0].ptz_sensitivity); - - //if (viewChannelData[0].ptz_tracking_resume_dwell) - //SetPtzSensitivity(viewChannelData[0].ptz_sensitivity); - //else - //SetPtzSensitivity(PTZ_DEFAULT_SENSITIVITY); - - //SetPtzSensitivity(PTZ_DEFAULT_SENSITIVITY); - //StartPTZtrackingThread(); - - sprintf(msg, "Start PTZ success."); - } - else - { - sprintf(msg, "Please setup the camera at Home position and click Start button."); - } - } - else - { - sprintf(msg, "This device is not support PTZ."); - } - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #38\n"); - - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/ptzcontrol?enable_ptz=No", 25) == 0) - { - memset(msg, 0x00, sizeof(msg)); - - if (IsPTZ() == 1) - { - StartStopAutopan(0); - - /*int zone_to_preset[4]; - - for (int i = 0; i < 4; i++) - { - zone_to_preset[i] = 0; - - if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL - && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) - { - zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); - } - }*/ - - //Update PTZ - strcpy(viewChannelData[0].ptz_enable_tracking, "No"); - write_to_enable_tracking("No"); - - /*UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, - viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, - viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, - viewChannelData[0].ptz_tracking_resume_dwell, viewDetectionZone[0][0].metadata1, zone_to_preset);*/ - - UpdatePTZConfigSetting(); - - //StopPTZtrackingThread(); - - sprintf(msg, "Stop PTZ success."); - } - else - { - sprintf(msg, "This device is not support PTZ."); - } - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #38\n"); - - closesocket(cli_socket); - } -#endif -#ifdef GY_OS_AMBA - else if (strncmp(urlBuffer, "/ptzcontrol?go_preset=", 22) == 0) - { - if (IsPTZ() == 1) - { - //Stop PTZ - StopPtz(); - - //Go Preset - char sPresetNumber[10] = { 0 }; - memset(sPresetNumber, 0x00, sizeof(sPresetNumber)); - strcpy(sPresetNumber, urlBuffer + 22); - - int iPreset_number = 0; - if (strlen(sPresetNumber) > 0) - iPreset_number = atoi(sPresetNumber); - - GoPreset(iPreset_number); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #38\n"); - - closesocket(cli_socket); - } - else - { - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "This device is not support PTZ."); - //printf(msg); - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #38\n"); - - closesocket(cli_socket); - } - } - else if (strncmp(urlBuffer, "/ptzcontrol?set&zone=", 21) == 0) - { - if (IsPTZ() == 1) - { - //Stop PTZ - StopPtz(); - - //Go Preset - char sZone[10] = { 0 }; - memset(sZone, 0x00, sizeof(sZone)); - strncpy(sZone, urlBuffer + 21,1); - - int index_zone = -1; - if (strlen(sZone) > 0) - index_zone = atoi(sZone); - - if (index_zone >= 0) { - ///ptzcontrol?set&zone=0&preset=1 - char sPreset[10] = { 0 }; - memset(sPreset, 0x00, sizeof(sPreset)); - strcpy(sPreset, urlBuffer + 30); - - int iPreset_number = -1; - if (strlen(sPreset) > 0) - iPreset_number = atoi(sPreset); - - if (iPreset_number >= 0) { - - g_check_if_change_preset = 1; - - strcpy(viewDetectionZone[0][index_zone].ptz_zone_to_preset, sPreset); - - /* - int zone_to_preset[4]; - for (int i = 0; i < 4; i++) - { - zone_to_preset[i] = 0; - - if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL - && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) - { - zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); - } - }*/ - - //Update PTZ - //strcpy(viewChannelData[0].ptz_enable_tracking, "No"); - //write_to_enable_tracking("No"); - - UpdatePTZConfigSetting(); - /* - UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, - viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, - viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, - viewChannelData[0].ptz_tracking_resume_dwell, viewDetectionZone[0][0].metadata1, zone_to_preset);*/ - - GoPreset(iPreset_number); - } - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #38\n"); - - closesocket(cli_socket); - } - else - { - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "This device is not support PTZ."); - //printf(msg); - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #38\n"); - - closesocket(cli_socket); - } - } -#endif -#if 1 - else if (strncmp(urlBuffer, "/get_simulated_plate?lpr=", 25) == 0) - { - char Cmd_temp[MAX_CMD_SIZE] = { 0 }; - memset(Cmd_temp, 0x00, sizeof(Cmd_temp)); - strcpy(Cmd_temp, urlBuffer + 25); - - if (strlen(Cmd_temp) >= 1) { - - int total_element_size_temp = 1; - detection_pos PosInfo_temp[MAX_DETECT_OBJECTS] = { 0 }; - int index_pos = 0; - detection_pos *pNext_temp; - pNext_temp = PosInfo_temp + index_pos; - strcpy(pNext_temp->name, "L._Plate_TWN"); - pNext_temp->left_x = 200; - pNext_temp->top_y = 200; - pNext_temp->width = 600; - pNext_temp->height = 300; - pNext_temp->center_x = pNext_temp->left_x + pNext_temp->width / 2; - pNext_temp->center_y = pNext_temp->top_y + pNext_temp->height / 2; - pNext_temp->box_x = pNext_temp->left_x; - pNext_temp->box_y = pNext_temp->top_y; - pNext_temp->box_w = pNext_temp->width; - pNext_temp->box_h = pNext_temp->height; - pNext_temp->confidence = 100.0; - pNext_temp->engine_type = FEATURE_LPR_TWN;//layerFeatureType[layer_idx]; - pNext_temp->engine_type2 = FEATURE_LPR_TWN; - pNext_temp->parent_idx = -1; - pNext_temp->car_logo_idx = -1; - pNext_temp->number_row = 1; - pNext_temp->class_id = 0; - - pNext_temp->obj_type = _PLATE; - pNext_temp->test_id = 0; - pNext_temp->image_id = 0; - - //printf("\n--------Cmd_temp:%s\n", Cmd_temp); - - strcpy(pNext_temp->properties.plate, Cmd_temp); - ReplacePlateWithDB(PosInfo_temp, total_element_size_temp, featureType, tracking_channel_idx); - AddTWPlateDASH(PosInfo_temp, total_element_size_temp, featureType); - PlateFilterForParkingPlot(PosInfo_temp, total_element_size_temp, featureType, tracking_channel_idx); - //printf("\n--------pNext_temp->properties.plate:%s\n", pNext_temp->properties.plate); - - //for (int index_temp = 0; index_temp < total_element_size_temp; index_temp++) - { - int index_temp = 0; - pNext_temp = PosInfo_temp + index_temp; - //printf("\n%d plate name = %s\n", index_temp, pNext_temp->properties.plate); - sprintf(beforeSendBuffer_xtra,"LPR:%s,confidence:%d\n", pNext_temp->properties.plate, (int)pNext_temp->confidence); - } - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #3212\n"); - closesocket(cli_socket); - } -#endif -#if 1 - else if ((strncmp(urlBuffer, "/getconfig?", 11) == 0) || (strncmp(urlBuffer, "/setconfig?", 11) == 0)) - { - pthread_mutex_lock(&mutex_config_json); - - //printf("\n[web process]start 24\n"); - char Cmd[8192] = { 0 }; - char msg_temp[512] = { 0 }; - strcpy(Cmd, urlBuffer + 11); - #ifdef _DEBUG_AMBA - printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket,Cmd,(int)strlen(Cmd)); - #endif //_DEBUG_AMBA - CgiCmdType type; - if (strncmp(urlBuffer, "/getconfig?", 11) == 0) { - type = _CGICMD_GET; - //printf("\n[web process]start 24-2\n"); -#if 0 - GetAidaPort(); -#endif - //printf("\n[web process]start 24-2-2\n"); - - //strcpy(accountData[0].account_aida_port, "8592"); - - if(strlen(accountData[0].account_aida_port)>= 1) - strcpy(aida_port_for_cgicmd,accountData[0].account_aida_port); - if (strlen(accountData[0].account_username) >= 1) - strcpy(aida_username_for_cgicmd, accountData[0].account_username); - //PNS_Get_Device_Name(1, aida_device_name_for_cgicmd); - strcpy(aida_device_name_for_cgicmd, g_device_name); - //printf("\n[web process]start 24-3\n"); - } - else { - type = _CGICMD_SET; // /setconfig? - check_if_correct_post = 0; - } - CgiCmdRtnCode rtn = cgicmd_process(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); - //CgiCmdRtnCode rtn = _CGICMD_SUCCESS; - //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn, beforeSendBuffer_xtra); - if (rtn == _CGICMD_RELOAD) - { - - g_write_config_file_dirty_flag = 0; - - write_config(); - - //usSleep(1000000); - printf("\n--------------------reload 4\n"); - sprintf(msg_temp, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); - - //printf(msg_temp); - strcpy(beforeSendBuffer_xtra, msg_temp); - } - else if (rtn == _CGICMD_SUCCESS) - { - //printf("\nhellllo\n"); - if (type == _CGICMD_SET) { - g_write_config_file_dirty_flag = 1; - } - if (strlen(beforeSendBuffer_xtra) == 0) - { - //sprintf(msg_temp, "Success."); - //printf(msg_temp); - strcpy(beforeSendBuffer_xtra, msg_temp); - } - //printf("\nhellllo2\n"); - } - else - { - if (strlen(beforeSendBuffer_xtra) == 0) - { - sprintf(msg_temp, "Invalid operation."); - printf(msg_temp); - strcpy(beforeSendBuffer_xtra, msg_temp); - } - } - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #32\n"); - - pthread_mutex_unlock(&mutex_config_json); - closesocket(cli_socket); - //printf("\nhellllo3\n"); - - - - } -#endif -#ifdef GY_OS_AMBA - else if (strncmp(urlBuffer, "/python?getfilelist=all", 23) == 0) - { - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - if (strcmp(SystemSetting.enable_python, "Yes") == 0) { - char sFileList[60000] = { 0 }; - - readFolderList(sFileList); - - strcpy(beforeSendBuffer_xtra, sFileList); - printf("sFileList: %s\n", sFileList); - } - else { - strcpy(beforeSendBuffer_xtra, ""); - } - - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #32\n"); - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/pythonget?file=", strlen("/pythonget?file=")) == 0) - { - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - if (strcmp(SystemSetting.enable_python, "Yes") == 0) { - char Cmd[512] = { 0 }; - char sOutput[10240]; - strcpy(Cmd, urlBuffer + 16); - - printf("get file name = %s \n", Cmd); - - readPythonFile(Cmd, sOutput); - // printf("\nfile!!!\n"); - - // 2024-09-26 switch py or refresh web need to clear buffer - for (int i = 0;i <= WEBPYTHONBUFFER_LENSIZE;i++) - { - memset(g_aWebPythonBuffer2D[i], 0, WEBPYTHONBUFFER_LENSIZE); - } - // 2024-09-26 switch py or refresh web need to reset index - g_uiWebPythonCurrentBufferIndex = 0; - g_uiWebPythonLastBufferIndex = 0; - - strcpy(beforeSendBuffer_xtra, sOutput); - } - else { - - strcpy(beforeSendBuffer_xtra, ""); - } - - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #32\n"); - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/pythonupload?", strlen("/pythonupload?")) == 0) - { - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - if (strcmp(SystemSetting.enable_python, "Yes") == 0) { - - char Cmd[PYTHON_CODE_SIZE] = { 0 }; - strcpy(Cmd, urlBuffer + strlen("/pythonupload?")); - // printf("[/pythonupload?] cmd = %s \n", Cmd); //2024/03/08 - - printf("Uploading...\n"); - char decodeCMD[PYTHON_CODE_SIZE] = { 0 }; - urldecode((unsigned char *)Cmd, (unsigned char *)decodeCMD); - strcpy(beforeSendBuffer_xtra, uploadPython(decodeCMD)); - - } - else { - strcpy(beforeSendBuffer_xtra, ""); - } - - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) { - printf("\nsend error #3552\n"); - } - - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/pythonsave?", strlen("/pythonsave")) == 0) - { - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - if (strcmp(SystemSetting.enable_python, "Yes") == 0) { - - char Cmd[PYTHON_CODE_SIZE] = { 0 }; - strcpy(Cmd, urlBuffer + strlen("/pythonsave?")); - // printf("[/pythonupload?] cmd = %s \n", Cmd); //2024/03/08 - - printf("Saving...\n"); - char decodeCMD[PYTHON_CODE_SIZE] = { 0 }; - urldecode((unsigned char *)Cmd, (unsigned char *)decodeCMD); - strcpy(beforeSendBuffer_xtra, SavePython(decodeCMD)); - - } - else { - strcpy(beforeSendBuffer_xtra, "Save python file failed !!"); - } - - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) { - printf("\nsend error #3552\n"); - } - - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/pythondelete?file=", 19) == 0) - { - char DeleteMessage_xtra[BUFSIZE] = { 0 }; - char SendDeleteStatus[BUFSIZE] = {0}; - if (strcmp(SystemSetting.enable_python, "Yes") == 0) { - char Cmd[512] = { 0 }; - strcpy(Cmd, urlBuffer + 14); - - printf("cmd = %s \n", Cmd); - - strcpy(Cmd, urlBuffer + 19); - - printf("get file name = %s \n", Cmd); - - deletePythonFile(Cmd); - if (g_cWebPythonDeleteStatus == 1) - { - sprintf(SendDeleteStatus, "%s was deleted successfully.",Cmd); - } - else - { - sprintf(SendDeleteStatus, "Failed to delete %s.",Cmd); - } - - } - else { - sprintf(SendDeleteStatus, "Please check the Enable python checkbox configuration in the SETTING TAB"); - } - int sendBufferSize = SetHttpResponse(DeleteMessage_xtra, _CODE_200, "text/html; charset=utf-8", strlen(SendDeleteStatus), SendDeleteStatus); - if (send(cli_socket, DeleteMessage_xtra, sendBufferSize, MSG_MORE) == -1) - { - printf("\nsend error #32\n"); - } - memset(SendDeleteStatus, 0, sizeof(SendDeleteStatus)); - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/python?playfile=", 17) == 0) - { - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - if (strcmp(SystemSetting.enable_python, "Yes") == 0) { - char Cmd[512] = { 0 }; - strcpy(Cmd, urlBuffer + 17); - - printf("cmd = %s \n", Cmd); - } - else { - strcpy(beforeSendBuffer_xtra, "Please check the Enable python checkbox configuration in the SETTING TAB"); - } - - //strcpy(beforeSendBuffer_xtra, sFileList); - - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #32\n"); - closesocket(cli_socket); - } -#endif -#if 1 - else if (strncmp(urlBuffer, "/getconfigfile?ch=all", 21) == 0) - { - pthread_mutex_lock(&mutex_config_json); - //char Cmd[8192] = { 0 }; - //strcpy(Cmd, urlBuffer + 15); - - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char configPATH[1024] = { 0 }; - strcpy(configPATH, exePath); - strcat(configPATH, "config.json"); - - //char filename[] = config_bakPATH; - char *filename = configPATH; - //char *filename = config_bakPATH; - - if (!FileExist(filename)) - { - printf("%s doesn't exist.\n", filename); - - } - else { - char* fileBuf = ReadAllBytes(filename); - if (fileBuf) { - - cJSON *root = cJSON_Parse(fileBuf); - //g_config_root = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (root) - { - //CgiCmdType type; - if (strncmp(urlBuffer, "/getconfigfile?ch=all", 21) == 0) { - //type = _CGICMD_GET; - - cJSON *view_setting, *system_setting; - view_setting = cJSON_GetObjectItem(root, "view_setting"); - system_setting = cJSON_GetObjectItem(root, "system_setting"); - - char *JsonString_view_setting = cJSON_PrintUnformatted(view_setting); - char *JsonString_system_setting = cJSON_PrintUnformatted(system_setting); - - if (JsonString_view_setting != NULL && JsonString_system_setting != NULL) { - - //printf("\n-------JsonString_view_setting:%s\n", JsonString_view_setting); - - if (strlen(accountData[0].account_aida_port) >= 1) - strcpy(aida_port_for_cgicmd, accountData[0].account_aida_port); - if (strlen(accountData[0].account_username) >= 1) - strcpy(aida_username_for_cgicmd, accountData[0].account_username); - //PNS_Get_Device_Name(1, aida_device_name_for_cgicmd); - strcpy(aida_device_name_for_cgicmd, g_device_name); - - - { - char *loc = strstr(JsonString_view_setting, "ip\":\"127.0.0.1"); - if (loc != NULL) { - char *temp2 = StrReplace(JsonString_view_setting, "ip\":\"127.0.0.1", "ip\":\"localhost"); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - } - } - - { - char *loc = strstr(JsonString_view_setting, ",\"username\":\"guest\","); - if (loc != NULL) { - char temp[256] = ","; - char *temp2 = StrReplace(JsonString_view_setting, ",\"username\":\"guest\",", temp); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - } - } - - { - char *loc = strstr(JsonString_view_setting, ",\"password\":\"GP12345\","); - if (loc != NULL) { - char temp[256] = ","; - char *temp2 = StrReplace(JsonString_view_setting, ",\"password\":\"GP12345\",", temp); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - } - } - - { - char *loc = strstr(JsonString_view_setting, "\"channel_id\":\"\""); - if (loc != NULL) { - char temp[256] = "\"channel_id\":\"0\""; - char *temp2 = StrReplace(JsonString_view_setting, "\"channel_id\":\"\"", temp); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - } - } - - { - char *loc = strstr(JsonString_view_setting, "\"camera_name\":\"\""); - if (loc != NULL) { - char temp[1024] = { 0 }; - sprintf(temp, "\"camera_name\":\"%s\"", aida_device_name_for_cgicmd); - char *temp2 = StrReplace(JsonString_view_setting, "\"camera_name\":\"\"", temp); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - } - } - - { - char *loc = strstr(JsonString_view_setting, "ip\":\"47.176.29.11"); - if (loc != NULL) { - char *temp2 = StrReplace(JsonString_view_setting, "ip\":\"47.176.29.11", "ip\":\"localhost"); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - } - } - - { - char *loc = strstr(JsonString_view_setting, "http_port\":\"80"); - if (loc != NULL) { - char temp[1024]; - sprintf(temp, "http_port\":\"%s", aida_port_for_cgicmd); - char *temp2 = StrReplace(JsonString_view_setting, "http_port\":\"80", temp); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - - } - } - - { - char *loc = strstr(JsonString_view_setting, "video_port\":\"80"); - if (loc != NULL) { - char temp[1024]; - sprintf(temp, "video_port\":\"%s", aida_port_for_cgicmd); - char *temp2 = StrReplace(JsonString_view_setting, "video_port\":\"80", temp); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - } - } - - strcpy(beforeSendBuffer_xtra, "{\"view_setting\":"); - strcat(beforeSendBuffer_xtra, JsonString_view_setting); - strcat(beforeSendBuffer_xtra, ",\"system_setting\":"); - strcat(beforeSendBuffer_xtra, JsonString_system_setting); - strcat(beforeSendBuffer_xtra, ",\"g_check_if_get_picture_not_OK\":"); - char temp_picture[10] = { 0 }; - sprintf(temp_picture, "%d", g_check_if_get_picture_not_OK); - strcat(beforeSendBuffer_xtra, temp_picture); - strcat(beforeSendBuffer_xtra, ",\"g_check_h264_gop\":"); - char temp_gop[10] = { 0 }; - sprintf(temp_gop, "%d", g_check_h264_gop); - strcat(beforeSendBuffer_xtra, temp_gop); - strcat(beforeSendBuffer_xtra, "}"); - } - - if (JsonString_view_setting) { - free(JsonString_view_setting); - JsonString_view_setting = NULL; - } - if (JsonString_system_setting) { - free(JsonString_system_setting); - JsonString_system_setting = NULL; - } - - - } - - if (root) { - cJSON_Delete(root); - root = NULL; - } - } - } - } - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #32\n"); - pthread_mutex_unlock(&mutex_config_json); - closesocket(cli_socket); - } -#endif -#if 0 - else if (strncmp(urlBuffer, "/getjvcconfigfile?ch=all", 24) == 0) - { - pthread_mutex_lock(&mutex_config_json); - //char Cmd[8192] = { 0 }; - //strcpy(Cmd, urlBuffer + 15); - - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char configPATH[1024] = { 0 }; - strcpy(configPATH, exePath); - strcat(configPATH, "jvc_config.json"); - - //char filename[] = config_bakPATH; - char *filename = configPATH; - //char *filename = config_bakPATH; - - if (!FileExist(filename)) - { - printf("%s doesn't exist.\n", filename); - - } - else { - char* fileBuf = ReadAllBytes(filename); - if (fileBuf) { - - cJSON *root = cJSON_Parse(fileBuf); - //g_config_root = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (root) - { - //CgiCmdType type; - if (strncmp(urlBuffer, "/getjvcconfigfile?ch=all", 24) == 0) { - //type = _CGICMD_GET; - - cJSON *view_setting, *system_setting; - view_setting = cJSON_GetObjectItem(root, "view_setting"); - system_setting = cJSON_GetObjectItem(root, "system_setting"); - - char *JsonString_view_setting = cJSON_PrintUnformatted(view_setting); - char *JsonString_system_setting = cJSON_PrintUnformatted(system_setting); - - if (JsonString_view_setting != NULL && JsonString_system_setting != NULL) { - - //printf("\n-------JsonString_view_setting:%s\n", JsonString_view_setting); - - if (strlen(accountData[0].account_aida_port) >= 1) - strcpy(aida_port_for_cgicmd, accountData[0].account_aida_port); - if (strlen(accountData[0].account_username) >= 1) - strcpy(aida_username_for_cgicmd, accountData[0].account_username); - //PNS_Get_Device_Name(1, aida_device_name_for_cgicmd); - strcpy(aida_device_name_for_cgicmd, g_device_name); - - - { - char *loc = strstr(JsonString_view_setting, "ip\":\"127.0.0.1"); - if (loc != NULL) { - char *temp2 = StrReplace(JsonString_view_setting, "ip\":\"127.0.0.1", "ip\":\"localhost"); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - } - } - - { - char *loc = strstr(JsonString_view_setting, ",\"username\":\"guest\","); - if (loc != NULL) { - char temp[256] = ","; - char *temp2 = StrReplace(JsonString_view_setting, ",\"username\":\"guest\",", temp); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - } - } - - { - char *loc = strstr(JsonString_view_setting, ",\"password\":\"GP12345\","); - if (loc != NULL) { - char temp[256] = ","; - char *temp2 = StrReplace(JsonString_view_setting, ",\"password\":\"GP12345\",", temp); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - } - } - - { - char *loc = strstr(JsonString_view_setting, "\"channel_id\":\"\""); - if (loc != NULL) { - char temp[256] = "\"channel_id\":\"0\""; - char *temp2 = StrReplace(JsonString_view_setting, "\"channel_id\":\"\"", temp); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - } - } - - { - char *loc = strstr(JsonString_view_setting, "\"camera_name\":\"\""); - if (loc != NULL) { - char temp[1024] = { 0 }; - sprintf(temp, "\"camera_name\":\"%s\"", aida_device_name_for_cgicmd); - char *temp2 = StrReplace(JsonString_view_setting, "\"camera_name\":\"\"", temp); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - } - } - - { - char *loc = strstr(JsonString_view_setting, "ip\":\"47.176.29.11"); - if (loc != NULL) { - char *temp2 = StrReplace(JsonString_view_setting, "ip\":\"47.176.29.11", "ip\":\"localhost"); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - } - } - - { - char *loc = strstr(JsonString_view_setting, "http_port\":\"80"); - if (loc != NULL) { - char temp[1024]; - sprintf(temp, "http_port\":\"%s", aida_port_for_cgicmd); - char *temp2 = StrReplace(JsonString_view_setting, "http_port\":\"80", temp); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - - } - } - - { - char *loc = strstr(JsonString_view_setting, "video_port\":\"80"); - if (loc != NULL) { - char temp[1024]; - sprintf(temp, "video_port\":\"%s", aida_port_for_cgicmd); - char *temp2 = StrReplace(JsonString_view_setting, "video_port\":\"80", temp); - strcpy(JsonString_view_setting, temp2); - if (temp2 != NULL) { - free(temp2); - temp2 = NULL; - } - } - } - - strcpy(beforeSendBuffer_xtra, "{\"view_setting\":"); - strcat(beforeSendBuffer_xtra, JsonString_view_setting); - strcat(beforeSendBuffer_xtra, ",\"system_setting\":"); - strcat(beforeSendBuffer_xtra, JsonString_system_setting); - strcat(beforeSendBuffer_xtra, ",\"g_check_if_get_picture_not_OK\":"); - char temp_picture[10] = { 0 }; - sprintf(temp_picture, "%d", g_check_if_get_picture_not_OK); - strcat(beforeSendBuffer_xtra, temp_picture); - strcat(beforeSendBuffer_xtra, "}"); - } - - if (JsonString_view_setting) { - free(JsonString_view_setting); - JsonString_view_setting = NULL; - } - if (JsonString_system_setting) { - free(JsonString_system_setting); - JsonString_system_setting = NULL; - } - - - } - - if (root) { - cJSON_Delete(root); - root = NULL; - } - } - } - } - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #32\n"); - pthread_mutex_unlock(&mutex_config_json); - closesocket(cli_socket); - } -#endif - else if (strncmp(urlBuffer, "/getemailsfile", strlen("/getemailsfile")) == 0) { - - if (strlen(IPCAMService.auth_password) >= 8) { - strcpy(beforeSendBuffer, "1"); - } - else { - strcpy(beforeSendBuffer, "0"); - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("send(Not get emails file)"); - closesocket(cli_socket); - } -#ifdef GY_OS_AMBA - else if (strncmp(urlBuffer, "/setosd?", 8) == 0) - { - gettimeofday(&currtime_setosd, NULL); - long current_ms_setosd = (currtime_setosd.tv_sec * 1000) + (currtime_setosd.tv_usec / 1000); - - //pthread_mutex_lock(&mutex_events_json); - char Cmd[8192] = { 0 }; - strcpy(Cmd, urlBuffer + 8); - char msg[256] = { 0 }; - - if (last_ms_setosd == 0 || current_ms_setosd >= last_ms_setosd + 20) { - if (strlen(Cmd) >= 1) { - - const char *del = "&"; - char a_data_osd[MAX_SIZE_A_OSD_OBJECT][STRSPLIT_SIZE]={0}; - int a_data_osd_num = 0; - - const char *del2 = "="; - char a_data_osd_pair[MAX_SIZE_A_OSD_OBJECT][2][STRSPLIT_SIZE]={0}; - - int id_osd = -1; //1 - int x_osd = -1; //2 - int y_osd = -1; //3 - int w_osd = -1; //4 - int h_osd = -1; //5 - int color_osd = -1; //6 - int size_osd = -1; //7 - int sec_osd = -1; //8 - char text_osd[256] = { 0 }; //9 - - int bg_transparency = 0; //10 0~255 - int outline_sw = 0; //11 0:off 1:on - - - a_data_osd_num = StrSplit(Cmd, a_data_osd, del); - //printf("\n------UU:28\n"); - if (a_data_osd_num == MAX_SIZE_A_OSD_OBJECT) - { - for (int i = 0; i < a_data_osd_num; i++) - { - if (a_data_osd[i]) - { - //printf("\n%s\n", a_data_osd[i]); - StrSplit(a_data_osd[i], a_data_osd_pair[i], del2); - //printf("\n------UU:29\n"); - if (strlen(a_data_osd_pair[i][0]) >= 1 && strlen(a_data_osd_pair[i][1]) >= 1) { - - if (strcmp(a_data_osd_pair[i][0], "id") == 0 || - strcmp(a_data_osd_pair[i][0], "ID") == 0) { - id_osd = atoi(a_data_osd_pair[i][1]); - } - else if (strcmp(a_data_osd_pair[i][0], "x") == 0 || - strcmp(a_data_osd_pair[i][0], "X") == 0) { - x_osd = atoi(a_data_osd_pair[i][1]); - } - else if (strcmp(a_data_osd_pair[i][0], "y") == 0 || - strcmp(a_data_osd_pair[i][0], "Y") == 0) { - y_osd = atoi(a_data_osd_pair[i][1]); - } - else if (strcmp(a_data_osd_pair[i][0], "w") == 0 || - strcmp(a_data_osd_pair[i][0], "W") == 0) { - w_osd = atoi(a_data_osd_pair[i][1]); - } - else if (strcmp(a_data_osd_pair[i][0], "h") == 0 || - strcmp(a_data_osd_pair[i][0], "H") == 0) { - h_osd = atoi(a_data_osd_pair[i][1]); - } - else if (strcmp(a_data_osd_pair[i][0], "color") == 0 || - strcmp(a_data_osd_pair[i][0], "Color") == 0) { - color_osd = atoi(a_data_osd_pair[i][1]); - } - else if (strcmp(a_data_osd_pair[i][0], "size") == 0 || - strcmp(a_data_osd_pair[i][0], "Size") == 0) { - size_osd = atoi(a_data_osd_pair[i][1]); - } - else if (strcmp(a_data_osd_pair[i][0], "ms") == 0) { - sec_osd = atoi(a_data_osd_pair[i][1]); - } - else if (strcmp(a_data_osd_pair[i][0], "bg") == 0) { - bg_transparency = atoi(a_data_osd_pair[i][1]); - } - else if (strcmp(a_data_osd_pair[i][0], "outline") == 0) { - outline_sw = atoi(a_data_osd_pair[i][1]); - } - else if (strcmp(a_data_osd_pair[i][0], "text") == 0 || - strcmp(a_data_osd_pair[i][0], "Text") == 0) { - strcpy(text_osd, a_data_osd_pair[i][1]); - url_decode(text_osd, strlen(text_osd)); - } - } - } - } - - if (bg_transparency < 0) - bg_transparency = 0; - else if (bg_transparency > 255) - bg_transparency = 255; - - if (outline_sw > 0) - outline_sw = 1; - if (outline_sw < 0) - outline_sw = 0; - - int check_if_osd_ok = 1; - - int num_width = -1; - int num_height = -1; - //int max_length_text = -1; - - if (w_osd >= 1 && size_osd >= 1) - num_width = w_osd / size_osd; - if (h_osd >= 1 && size_osd >= 1) - num_height = h_osd / (size_osd * 2); - - /* - if (num_width >= 1 && num_height >= 1) - max_length_text = num_width * 4; - */ - int num_br = 0; - int check_if_line_too_long = 0; - int isTextEmpty = 0; - if (strstr(text_osd, "empty") != NULL) - { - isTextEmpty = 1; - } - - if (strlen(text_osd) >= 1 - && isTextEmpty == 0) { - //printf("=====> AAAAA \n"); - num_br = strstr_cnt(text_osd, "
"); - - char temp_osd_text[256] = { 0 }; - strcpy(temp_osd_text, text_osd); - - char *p_osd; - char *read_point; - read_point = text_osd; - char current_osd_text[256] = { 0 }; - - for (int index_line = 0; index_line < 4; index_line++) { - - p_osd = strstr(read_point, "
"); - - if (p_osd) { - memset(current_osd_text, 0x00, sizeof(current_osd_text)); - strncpy(current_osd_text, read_point, p_osd - read_point); - if (strlen(current_osd_text) >= 30 || strlen(current_osd_text) >= num_width + 1) { - check_if_line_too_long = 1; - break; - } - p_osd += 4; - read_point = p_osd; - - //strcpy(temp_osd_text, p_osd + 4); - } - else { - //memset(current_osd_text, 0x00, sizeof(current_osd_text)); - //strncpy(current_osd_text, read_point, strlen(read_point)); - - //if (strlen(temp_osd_text) >= 30 || strlen(temp_osd_text) >= num_width + 2) - if (strlen(read_point) >= 30 || strlen(read_point) >= num_width + 1) - { - check_if_line_too_long = 1; - } - break; - } - } - - //printf("get cgi osd info: \n %d, %d, %d, %d, %d, %d, %d, %d, %d \n", id_osd, x_osd, y_osd, w_osd, h_osd, color_osd, size_osd, sec_osd, strlen(text_osd)); - //printf("----------------------------------%d, %d \n", bg_transparency, outline_sw); - - if (id_osd == -1 || x_osd == -1 || y_osd == -1 || w_osd == -1 || h_osd == -1 || color_osd == -1 || size_osd == -1 || sec_osd == -1 || strlen(text_osd) == 0) { - check_if_osd_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: Parameter"); - } - else if (x_osd <= 1 || x_osd >= SCALE_BOUNDING_BOX_WIDTH) { - check_if_osd_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: x <= 1 || x >= 1920"); - } - else if (y_osd <= 1 || y_osd >= SCALE_BOUNDING_BOX_HEIGHT) { - check_if_osd_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: y <= 1 || y >= 1080"); - } - else if (w_osd <= 1 || w_osd >= SCALE_BOUNDING_BOX_WIDTH || x_osd + w_osd >= SCALE_BOUNDING_BOX_WIDTH) { - check_if_osd_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: w <= 1 || w >= 1920 || x + w >= 1920"); - } - else if (h_osd <= 1 || h_osd >= SCALE_BOUNDING_BOX_HEIGHT || y_osd + h_osd >= SCALE_BOUNDING_BOX_HEIGHT) { - check_if_osd_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: h <= 1 || h >= 1080 || y + h >= 1080"); - } - else if (size_osd <= 9 || size_osd >= 51) { - check_if_osd_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: size <= 25 || size >= 51"); - } - //else if (strlen(text_osd) <= 0 || strlen(text_osd) >= 100 || strlen(text_osd) >= max_length_text) { - // check_if_osd_ok = 0; - // strcpy(msg, "HTTP 200 OK, content: Error: strlen(text) <= 0 || strlen(text) >= 100 || strlen(text) >= w / size * 4"); - //} - else if (strlen(text_osd) >= 1 && (num_br >= 4 || num_height < (num_br + 2))) { - check_if_osd_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: The number of BR >= 4 || (h / (font size * 2)) < (The number of row + 1)"); - } - else if (check_if_line_too_long == 1) { - check_if_osd_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: The text line is too long (>= 30 || >= ((w / size) + 2)). Please use newline label BR."); - } - else if (num_width <= 4 || num_height <= 1 || w_osd * h_osd > 644253) { - check_if_osd_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: w / size <= 4 || h / (size * 2) <= 1 || w * h > 644253"); - } - else if (sec_osd <= 0 || sec_osd >= 60000) { - check_if_osd_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: ms <= 0 || ms >= 60000"); - } - else if (id_osd < 0 || id_osd >= 12) { - check_if_osd_ok = 0; - strcpy(msg, "HTTP 200 OK, content: Error: id_osd < 0 || id_osd >= 12"); - } - } - else if (isTextEmpty == 1) - { - //printf("=====> bbbbb \n"); - //strncpy(current_osd_text, " ", 1); - sprintf(text_osd, "%s", ""); - //sprintf(text_osd, "%s", "TESTabc123"); - } - - if (check_if_osd_ok == 1 && color_osd >= 0) { - //for (int i = 0 ; i < MAX_SIZE_OSD_ARRAY ; i++) - int i = id_osd; - if (i >= 0 && i < MAX_SIZE_OSD_ARRAY) - { - if (OSDData[i].flag_protected == 0) { - OSDData[i].id = id_osd; - OSDData[i].x = x_osd; - OSDData[i].y = y_osd; - OSDData[i].w = w_osd; - OSDData[i].h = h_osd; - OSDData[i].color = color_osd; - OSDData[i].size = size_osd; - OSDData[i].show_sec = sec_osd; - OSDData[i].bg_tran = bg_transparency; - OSDData[i].outline_sw = outline_sw; - strcpy(OSDData[i].text, text_osd); - OSDData[i].flag_protected = 1; - - //printf("----------------------------------%d, %d \n", OSDData[i].bg_tran, OSDData[i].outline_sw); - - /* - printf("\n[x,y,w,h,color,size,sec,text]:[%d,%d,%d,%d,%d,%d,%d,%s]\n", - OSDData[i].x, OSDData[i].y, OSDData[i].w, OSDData[i].h, - OSDData[i].color, OSDData[i].size, OSDData[i].sec, OSDData[i].text); - */ - strcpy(msg, "HTTP 200 OK, content: OK"); - //break; - } - } - } - } - } - - if (strlen(msg) == 0) { - strcpy(msg, "HTTP 200 OK, content: Error: Format"); - } - last_ms_setosd = current_ms_setosd; - } - else { - strcpy(msg, "HTTP 200 OK, content: Error: Busy"); - } - - strcpy(beforeSendBuffer_xtra, msg); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #32\n"); - - //pthread_mutex_unlock(&mutex_events_json); - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/setosdtime?", 12) == 0) - { - char msg[256] = { 0 }; - - //printf("-----------------------------------\n-------------------------------------\n"); - update_system_time(); - - #if 1 - // /setosdtime?osdtime=1 - char Cmd[8192] = { 0 }; - const char *del2 = "="; - char a_data_osd_pair[1][2][STRSPLIT_SIZE]={0}; - strcpy(Cmd, urlBuffer + 12); - - if (strstr(Cmd, "osdtime=") != NULL) - { - StrSplit(Cmd, a_data_osd_pair[0], del2); - //printf("\n------UU:30\n"); - if (strlen(a_data_osd_pair[0][1]) > 0) - { - //12 0:off 1:left-top, 2:mid-top, 3:right-top, 4:left_bottom, 5:mid_bottom, 6:right:bottom - g_osdTime_sw = atoi(a_data_osd_pair[0][1]); - if (g_osdTime_sw < 0) { - g_osdTime_sw = 0; - strcpy(msg,"Please set g_osdTime_sw to 0-6."); - } - else if (g_osdTime_sw > 6) { - g_osdTime_sw = 4; //default left_bottom - strcpy(msg, "Please set g_osdTime_sw to 0-6."); - } - else { - strcpy(msg, "OK"); - } - } - else { - g_osdTime_sw = 0; - } - } - #endif - - if (strlen(msg) == 0) { - strcpy(msg,"Wrong format."); - } - - strcpy(beforeSendBuffer_xtra, msg); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #3222\n"); - - //pthread_mutex_unlock(&mutex_events_json); - closesocket(cli_socket); - } -#endif -#if 1 - else if (strncmp(urlBuffer, "/geteventsfile?ch=all", 21) == 0) - { - pthread_mutex_lock(&mutex_events_json); - //char Cmd[8192] = { 0 }; - //strcpy(Cmd, urlBuffer + 15); - - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char eventsPATH[1024] = { 0 }; - strcpy(eventsPATH, exePath); - strcat(eventsPATH, "events.json"); - - //char filename[] = config_bakPATH; - char *filename = eventsPATH; - //char *filename = config_bakPATH; - - if (!FileExist(filename)) - { - printf("%s doesn't exist.\n", filename); - - } - else { - char* fileBuf = ReadAllBytes(filename); - if (fileBuf) { - - cJSON *root = cJSON_Parse(fileBuf); - //g_config_root = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (root) - { - //CgiCmdType type; - if (strncmp(urlBuffer, "/geteventsfile?ch=all", 21) == 0) { - //type = _CGICMD_GET; - char *JsonString = cJSON_PrintUnformatted(root); - if (JsonString != NULL) { - strcpy(beforeSendBuffer_xtra, JsonString); - free(JsonString); - JsonString = NULL; - } - } - /* - else { - type = _CGICMD_SET; // /setconfig? - strcpy(beforeSendBuffer_xtra, Cmd); - }*/ - cJSON_Delete(root); - root = NULL; - } - } - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #32\n"); - - pthread_mutex_unlock(&mutex_events_json); - closesocket(cli_socket); - } -#endif -#if 1 - else if (strncmp(urlBuffer, "/geteventscustom?num=", 21) == 0) - { - pthread_mutex_lock(&mutex_events_json); - //char Cmd[8192] = { 0 }; - //strcpy(Cmd, urlBuffer + 15); - - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - int default_version = 0; - - { - char Cmd_temp[MAX_CMD_SIZE] = { 0 }; - strcpy(Cmd_temp, urlBuffer + 21); - - int check_if_not_digit = 0; - for (int index_cmd = 0; index_cmd < strlen(Cmd_temp); index_cmd++) - { - if (!isdigit(Cmd_temp[index_cmd])) - { - check_if_not_digit = 1; - break; - } - } - if (strlen(Cmd_temp) == 0) { - check_if_not_digit = 1; - } - - if (check_if_not_digit == 0) { - default_version = atoi(Cmd_temp); - } - } - - if (default_version >= 1 && default_version != 3) { - - char eventsPATH[1024] = { 0 }; - sprintf(eventsPATH,"%sevents_custom_%d.json", exePath, default_version); - - //char filename[] = config_bakPATH; - char *filename = eventsPATH; - //char *filename = config_bakPATH; - - if (!FileExist(filename)) - { - printf("%s doesn't exist.\n", filename); - - } - else { - char* fileBuf = ReadAllBytes(filename); - if (fileBuf) { - - cJSON *root = cJSON_Parse(fileBuf); - //g_config_root = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (root) - { - //CgiCmdType type; - if (strncmp(urlBuffer, "/geteventscustom?num=", 21) == 0) { - //type = _CGICMD_GET; - char *JsonString = cJSON_PrintUnformatted(root); - if (JsonString != NULL) { - strcpy(beforeSendBuffer_xtra, JsonString); - free(JsonString); - JsonString = NULL; - } - } - /* - else { - type = _CGICMD_SET; // /setconfig? - strcpy(beforeSendBuffer_xtra, Cmd); - }*/ - cJSON_Delete(root); - root = NULL; - } - } - } - } - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #326\n"); - - pthread_mutex_unlock(&mutex_events_json); - closesocket(cli_socket); - } -#endif - // ======================================================================================== - else if ((strncmp(urlBuffer, "/getconfig?radar_position=", 26) == 0) || (strncmp(urlBuffer, "/setconfig?radar_position&", 26) == 0)) - { - } - else if ((strncmp(urlBuffer, "/getconfig?ptz_position=", 24) == 0) || (strncmp(urlBuffer, "/setconfig?ptz_position&", 24) == 0)) - { // ?i?H???U?????g - } -#if 0 - else if ((strncmp(urlBuffer, "/setradarconfig?default", 23) == 0)) - { - pthread_mutex_lock(&mutex_radar_json); - char RADAR_JSON_PATH[1024] = "/emmc/plugin/Aida_data/radar.json"; - char RADAR_BAK_JSON_PATH[1024] = "/emmc/plugin/Aida_data/radar_bak.json"; - - CopyFileTo(RADAR_BAK_JSON_PATH, RADAR_JSON_PATH); - - pthread_mutex_unlock(&mutex_radar_json); - update_radar_json(); - closesocket(cli_socket); - } - else if ((strncmp(urlBuffer, "/setradarconfig?ch=1&", 21) == 0)) - { - //@TODO: cola 2022/02/23 save radar config - // kuan 2022/05/17 - pthread_mutex_lock(&mutex_radar_json); - char buf[1024] = {}; - char Cmd[8192] = {0}; - //char msg_temp[512] = {0}; - CgiCmdRtnCode rtn; - readlink("/proc/self/exe", buf, sizeof(buf)); - char exePath[1024] = {}; - // printf("exePath:%s\n", exePath); - getFilePath(buf, exePath, 1024); - // printf("exePath:%s\n", exePath); - char configPATH[1024] = { 0 }; - strcpy(configPATH, exePath); - strcat(configPATH, "radar.json"); - char *filename_config = configPATH; - if (!FileExist(filename_config)) - { - printf("%s doesn't exist.\n", filename_config); - rtn = _CGICMD_FAIL; - } - else - { - //size_t nfileSize_cofnig = ReadFileSize(filename_config); - char *fileBuf_config = ReadAllBytes(filename_config); - if (fileBuf_config) - { - cJSON *root = NULL; - root = cJSON_Parse(fileBuf_config); - if (fileBuf_config) - { - free(fileBuf_config); - fileBuf_config = NULL; - } - if (root == NULL) - { - printf("root_config is NULL\n"); - rtn = _CGICMD_FAIL; - } - else - { // ?g?J radar.html ???n?s?^ json ????? - strcpy(Cmd, urlBuffer + 21); - const char *del = "="; - const char *del2 = "\n"; - char name[50][STRSPLIT_SIZE]={0}; - int value = 0; - char value2[50][STRSPLIT_SIZE]={0}; - StrSplit(Cmd, name, del); // segmentation fault function work well, the reason may be the input data - //printf("\n------UU:31\n"); - cJSON *camera; - // if (*name == "enable_calibration_radar") - //{ - // printf("get enable_calibration_radar\n"); - // } - if (!(camera = cJSON_GetObjectItem(root, "camera"))) - { - printf("cJSON_GetObjectItem error \n"); - } - - if (strcmp(*name, "trial_life_time") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(root, "trial_life_time", cJSON_CreateNumber(value)); - // printf("setting radar.json trial_life_time = %d \n", value); - } - else if (strcmp(*name, "calibration_camera") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - bool inbool = false; - if (strcmp(*value2, "Yes") == 0) - inbool = true; - cJSON_ReplaceItemInObject(camera, "calibration_camera", cJSON_CreateBool(inbool)); - // printf("setting radar.json calibration_camera = %d \n", inbool); - } - //@TODO cola....finish all setting - // kuan - else if (strcmp(*name, "enable_calibration_radar") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - bool inbool = false; - if (strcmp(*value2, "Yes") == 0) - inbool = true; - cJSON_ReplaceItemInObject(camera, "enable_calibration_radar", cJSON_CreateBool(inbool)); - // printf("setting radar.jsonenable_calibration_radar = %d \n", inbool); - } - else if (strcmp(*name, "calibration_radar") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - bool inbool = false; - if (strcmp(*value2, "Yes") == 0) - inbool = true; - cJSON_ReplaceItemInObject(root, "calibration_radar", cJSON_CreateBool(inbool)); - // printf("setting radar.json calibration_radar = %d \n", inbool); - } - else if (strcmp(*name, "enable_camera") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - bool inbool = false; - if (strcmp(*value2, "Yes") == 0) - inbool = true; - cJSON_ReplaceItemInObject(root, "enable_camera", cJSON_CreateBool(inbool)); - json_enable_camera_p = inbool; - // printf("setting radar.json enable_camera = %d \n", inbool); - } - else if (strcmp(*name, "world_radar_height") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(root, "world_radar_height", cJSON_CreateNumber(value)); - // printf("setting radar.json world_radar_height = %d \n", value); - } - else if (strcmp(*name, "distance_meter") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(root, "distance_meter", cJSON_CreateNumber(value)); - // json_distance_meter = value; // leo 09-28 - json_distance_meter_p = value; // leo 11-25 - // printf("setting radar.json distance_meter = %d \n", value); - } - else if (strcmp(*name, "distance_meter_y") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(root, "distance_meter_y", cJSON_CreateNumber(value)); - // json_distance_meter_y = value; // steven 230111 - json_distance_meter_y_p = value; // steven 230111 - // printf("setting radar.json distance_meter = %d \n", value); - } - else if (strcmp(*name, "world_camera_height") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(camera, "world_camera_height", cJSON_CreateNumber(value)); - // printf("setting radar.json world_camera_height = %d \n", value); - } - else if (strcmp(*name, "world_camera_degree") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(camera, "world_camera_degree", cJSON_CreateNumber(value)); - // printf("setting radar.json world_camera_degree = %d \n", value); - } - else if (strcmp(*name, "world_camera_degree_offset") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(camera, "world_camera_degree_offset", cJSON_CreateNumber(value)); - json_world_camera_degree_offset_p = value; - // printf("setting radar.json world_camera_degree_offset = %d \n", value); - } - else if (strcmp(*name, "world_camera_home_point_degree") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(camera, "world_camera_home_point_degree", cJSON_CreateNumber(value)); - json_world_camera_home_point_degree_p = value; - // printf("setting radar.json world_camera_home_point_degree = %d \n", value); - } - else if (strcmp(*name, "world_camera_x_axis") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(camera, "world_camera_x_axis", cJSON_CreateNumber(value)); - json_world_camera_x_axis_p = value; // - // printf("setting radar.json world_camera_x_axis = %d \n", value); - } - else if (strcmp(*name, "world_camera_y_axis") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(camera, "world_camera_y_axis", cJSON_CreateNumber(value)); - json_world_camera_y_axis_p = value; // - // printf("setting radar.json world_camera_y_axis = %d \n", value); - } - else if (strcmp(*name, "world_radar_degree") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(root, "world_radar_degree", cJSON_CreateNumber(value)); - // printf("setting radar.json world_radar_degree = %d \n", value); - } - else if (strcmp(*name, "enable_camera_tracking") == 0) - { - ; - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - bool inbool = false; - if (strcmp(*value2, "Yes") == 0) - inbool = true; - cJSON_ReplaceItemInObject(camera, "enable_camera_tracking", cJSON_CreateBool(inbool)); - // printf("setting radar.json enable_camera_tracking = %d \n", inbool); - } - else if (strcmp(*name, "distance_format") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(root, "distance_format", cJSON_CreateString(*value2)); - // printf("setting radar.json distance_format = %s \n", *value2); - } - else if (strcmp(*name, "radar_section_degree") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(root, "radar_section_degree", cJSON_CreateNumber(value)); - json_radar_section_degree = value; // leo 09-28 - // printf("setting radar.json radar_section_degree = %d \n", value); - } - else if (strcmp(*name, "target_x_axis") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(root, "target_x_axis", cJSON_CreateNumber(value)); - json_target_x_axis = value; // leo 09-28 - json_target_x_axis_p = value; // leo 11-25 - // printf("setting radar.json target_x_axis = %d \n", value); - } - else if (strcmp(*name, "target_y_axis") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(root, "target_y_axis", cJSON_CreateNumber(value)); - json_target_y_axis = value; // leo 09-28 - json_target_y_axis_p = value; // leo 11-25 - // printf("setting radar.json target_y_axis = %d \n", value); - } - else if (strcmp(*name, "radar_x_axis") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(root, "radar_x_axis", cJSON_CreateNumber(value)); - json_radar_x_axis = value; // leo 09-28 - json_radar_x_axis_p = value; // leo 11-25 - // printf("setting radar.json radar_x_axis = %d \n", value); - } - else if (strcmp(*name, "radar_y_axis") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(root, "radar_y_axis", cJSON_CreateNumber(value)); - json_radar_y_axis = value; // leo 09-28 - json_radar_y_axis_p = value; // leo 11-25 - // printf("setting radar.json radar_y_axis = %d \n", value); - } - else if (strcmp(*name, "ip_setting") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - bool inbool = false; - if (strcmp(*value2, "true") == 0) - inbool = true; - cJSON_ReplaceItemInObject(camera, "ip_setting", cJSON_CreateBool(inbool)); - printf("setting radar.json ip_setting = %d \n", inbool); - } - else if (strcmp(*name, "camera_ip") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(camera, "camera_ip", cJSON_CreateString(*value2)); - sprintf(json_ptz_ip_p, "%s", *value2); - printf("setting radar.json camera_ip = %s \n", *value2); - } - else if (strcmp(*name, "camera_port") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(camera, "camera_port", cJSON_CreateString(*value2)); - sprintf(json_ptz_port_num_p, "%s", *value2); - printf("setting radar.json camera_port = %s \n", *value2); - } - else if (strcmp(*name, "camera_username") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(camera, "camera_username", cJSON_CreateString(*value2)); - sprintf(json_ptz_username_p, "%s", *value2); - printf("setting radar.json camera_username = %s \n", *value2); - } - else if (strcmp(*name, "camera_password") == 0) - { - strcpy(Cmd, urlBuffer + 22 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(camera, "camera_password", cJSON_CreateString(*value2)); - sprintf(json_ptz_password_p, "%s", *value2); - printf("setting radar.json camera_password = %s \n", *value2); - } - // kuan - char *JsonString = cJSON_Print(root); - FILE *fp; - if ((fp = fopen(filename_config, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - rtn = _CGICMD_SUCCESS; - // printf("\n--------------------reload 3\n"); - // reload_dataset_from_jsonfile(); - } - else - { - printf("Fail to open radar.json \n"); - rtn = _CGICMD_FAIL; - } - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - } - if (rtn == _CGICMD_SUCCESS) - { - if (strlen(beforeSendBuffer_xtra) == 0) - { - memset(msg, 0x00, sizeof(msg)); - // sprintf(msg, "Success."); - printf(msg); - strcpy(beforeSendBuffer_xtra, msg); - } - } - else - { - if (strlen(beforeSendBuffer_xtra) == 0) - { - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "Invalid operation."); - printf(msg); - strcpy(beforeSendBuffer_xtra, msg); - } - } - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - char sendBuffer_xtra[BUFSIZE * 8] = {0}; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, 0) == -1) - perror("send error radar.json"); - // if no closesocket(), html console will show net::ERR_EMPTY_RESPONSE - if (root) - { - cJSON_Delete(root); - root = NULL; - } - } - } - pthread_mutex_unlock(&mutex_radar_json); - closesocket(cli_socket); - } -#endif - // ======================================================================================== -#ifdef GY_OS_AMBA -#if 0 - else if ((strncmp(urlBuffer, "/is_send_pcl", strlen("/is_send_pcl")) == 0)) - { - char Msg[256] = {0}; - g_bIsSendTofPCD = !g_bIsSendTofPCD; - sprintf(Msg, "%d", g_bIsSendTofPCD); - printf("[nweb.c] /is_send_pcl CGI - json str : %s\n\n", Msg); - strcpy(contentBuffer, Msg); - - strcpy(beforeSendBuffer, contentBuffer); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\n[CGI:/is_send_pcl] send error\n"); - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/gettof3dpcd", strlen("/gettof3dpcd")) == 0) - { - char* contentBuffer_pcd = NULL; - int contentSize_pcd = 0; - int check_if_send_OK = 0; - int check_if_send_480 = 0; - - // Get the "res" parameter from the URL - char* resParam = strstr(urlBuffer, "res="); - if (resParam == NULL) { - // No "res" parameter, return an error message - pthread_mutex_lock(&mutex_write_pcd_data_S); - contentBuffer_pcd = tof_pcd_buffer_S; - contentSize_pcd = strlen(tof_pcd_buffer_S); - pthread_mutex_unlock(&mutex_write_pcd_data_S); - } - else { - // Extract the value of the "res" parameter - int resolution = atoi(resParam + strlen("res=")); - - // Return the appropriate PCD buffer based on the resolution - if (resolution == 60) { - pthread_mutex_lock(&mutex_write_pcd_data_S); - contentBuffer_pcd = tof_pcd_buffer_S; - contentSize_pcd = strlen(tof_pcd_buffer_S); - pthread_mutex_unlock(&mutex_write_pcd_data_S); - } - else if (resolution == 120) { - pthread_mutex_lock(&mutex_write_pcd_data_M); - contentBuffer_pcd = tof_pcd_buffer_M; - contentSize_pcd = strlen(tof_pcd_buffer_M); - pthread_mutex_unlock(&mutex_write_pcd_data_M); - } - else if (resolution == 480) { - pthread_mutex_lock(&mutex_write_pcd_data_L); - - FILE *fp = fopen("/emmc/plugin/Aida/pcl/pcd/tof_pcd_data_L.txt", "r"); - - // 確認檔案是否成功開啟 - if (fp == NULL) { - printf("File open failed."); - } - else { - // 將資料分批傳輸 - int totalSent = 0; - int remaining = 0; - int check_if_error = 0; - while (!feof(fp)) { - // 讀取資料塊 - char chunk[CHUNK_SIZE]; - int bytesRead = fread(chunk, 1, CHUNK_SIZE, fp); - remaining = bytesRead; - - // 寫入 socket - while (remaining > 0) { - int chunkSize = (remaining < CHUNK_SIZE) ? remaining : CHUNK_SIZE; - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", chunkSize, chunk + (bytesRead - remaining)); - if (sendBufferSize == -1) { - printf("\n[CGI:/gettof3dpcd] send error\n"); - check_if_error = 1; - break; - } - if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) { - printf("\n[CGI:/gettof3dpcd] send error\n"); - check_if_error = 1; - break; - } - totalSent += chunkSize; - remaining -= chunkSize; - } - - if (check_if_error == 1) - break; - } - } - // 釋放記憶體 - if (fp != NULL) { - fclose(fp); - fp = NULL; - } - - pthread_mutex_unlock(&mutex_write_pcd_data_L); - bTofDataFileStart = 0; - check_if_send_480 = 1; - } - else { - // Invalid resolution parameter, return an error message - contentBuffer_pcd = "Invalid resolution parameter."; - contentSize_pcd = strlen(contentBuffer_pcd); - } - - if (check_if_send_480 == 0) { - if (contentBuffer_pcd == NULL) { - // The requested PCD buffer is not available, return an error message - contentBuffer_pcd = "PCD buffer not available."; - contentSize_pcd = strlen(contentBuffer_pcd); - - } - else if (g_bIsWritingPCD) { - // The PCD file is currently being written, return a message to try again later - contentBuffer_pcd = "File is currently being written. Please wait and try again later."; - contentSize_pcd = strlen(contentBuffer_pcd); - - } - else { - - check_if_send_OK = 1; - } - } - } - - if (check_if_send_OK == 1) { - // Lock the mutex to prevent other threads from accessing the PCD buffer while we send the response - pthread_mutex_lock(&mutex_write_pcd_data); - - // Mark the PCD file as being written to prevent other threads from accessing it - g_bIsWritingPCD = 1; - - // Send the PCD buffer as the response - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", contentSize_pcd, contentBuffer_pcd); - if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) { - printf("\n[CGI:/gettof3dpcd] send error\n"); - } - g_bIsWritingPCD = 0; - // Unlock the mutex to allow other threads to access the PCD buffer again - pthread_mutex_unlock(&mutex_write_pcd_data); - } - else if (check_if_send_480 == 1) { - - } - else{ - g_bIsWritingPCD = 1; - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", contentSize_pcd, contentBuffer_pcd); - - if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) { - printf("\n[CGI:/gettof3dpcd] send error\n"); - } - g_bIsWritingPCD = 0; - } - - closesocket(cli_socket); - } - else if ((strncmp(urlBuffer, "/gettofpixel?", strlen("/gettofpixel?")) == 0)) - { - // printf("urlBuffer : %s\n", urlBuffer); // URL Ex : /gettofpixel?x=1&y=2 - - float depth = 0.0; - - char Cmd[8192] = {0}; - strcpy(Cmd, urlBuffer + strlen("/gettofpixel?")); - - //int init_size = strlen(Cmd); - char delimAnd[] = "&"; - char delimEqu[] = "="; - //char delimNewLine[] = "\n"; - - char *params = strtok(Cmd, delimAnd); - - int pixelX = 0; - int pixelY = 0; - - int installAngle = 0; - int settofheight = 0; - int y_diff = 0; - double angle_diff = 0.0; - double pixelDegree = 0.0; - double pointHeight = 0.0; - - double height = 0.0; - double distance = 0.0; - - // Compare each parameter with pre-defined key, and get the value for specific application - while(params != NULL) - { - char keyValPair[2][100]={0}; - StrSplit(params, keyValPair, delimEqu); - // printf("key:%s\n", keyValPair[0]); - // printf("value:%s\n", keyValPair[1]); - - if (strstr(keyValPair[0], "x")) - { - pixelX = atoi(keyValPair[1]); - } - else if (strstr(keyValPair[0], "y")) - { - pixelY = atoi(keyValPair[1]); - } - else if (strstr(keyValPair[0], "angle")) - { - installAngle = atoi(keyValPair[1]); - } - else if (strstr(keyValPair[0], "settofheight")) - { - settofheight = atoi(keyValPair[1]); - } - - params = strtok(NULL, delimAnd); - } - - // depth = getToFDepthByPixel(pixelX, pixelY); // send request to tof driver - depth = getDepth(pixelX, pixelY); - - // calculate distance and height by depth and install angel - // --------------------------------------------------------------------- - // printf("depth (M) : %lf\n", depth); // c - - y_diff = 240 - pixelY; - // printf("pixelY : %d , y_diff : %d\n", pixelY, y_diff); - - // angle_diff = ( FoV vertical angle / 2 ) * ( y_diff / ( res_h / 2 ) ) - // FoV vertical angle : 47.2 | Resolution Height : 480 - if (y_diff != 0) - { - angle_diff = 23.6 * ( (double)y_diff / 240.0 ); - } - - pixelDegree = ((double)installAngle) - angle_diff; - - // printf("install degree : %d\n", installAngle); // theta - // printf("angle_diff : %lf\n", angle_diff); - // printf("pixelDegree : %lf\n", pixelDegree); - - pointHeight = sin( pixelDegree * (double)(PI / 180) ) * depth; // sin(theta) = a / c ( depth ) - - // printf("object to tof height (M) : %lf\n", pointHeight); - - if (settofheight) - { - g_tof_device_height = pointHeight; - height = pointHeight; - } else { - height = g_tof_device_height - pointHeight; - } - - distance = fabs(cos( pixelDegree * (double)(PI / 180) )) * depth; // cos(theta) = b / c ( depth ) - - printf("height (M) : %lf\n", height); - printf("distance (M) : %lf\n", distance); - printf("-------------------\n"); - - char Msg[256] = {0}; - sprintf(Msg, "{\"x\":\"%d\", \"y\":\"%d\", \"depth\":\"%f\", \"height\":\"%f\", \"distance\":\"%f\"}", pixelX, pixelY, depth, height, distance); // converted X, Y - printf("[nweb.c] /gettofpixel CGI - json str : %s\n\n", Msg); - strcpy(contentBuffer, Msg); - - strcpy(beforeSendBuffer, contentBuffer); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\n[CGI:/gettofpixel] send error\n"); - closesocket(cli_socket); - } - else if ((strncmp(urlBuffer, "/settofrange?", strlen("/settofrange?")) == 0)) - { - char Cmd[8192] = {0}; - strcpy(Cmd, urlBuffer + strlen("/settofrange?")); - //printf("[nweb.c] /settofrange CGI - URL params : %s\n", Cmd); // URL params Ex : min=0.1&max=0.5 - - //int init_size = strlen(Cmd); - //char delimAnd[] = "&"; - //char delimEqu[] = "="; - //char delimNewLine[] = "\n"; - - //char *params = strtok(Cmd, delimAnd); - - // Compare each parameter with pre-defined key, and get the value for specific application - // while(params != NULL) - // { - // char *keyValPair[2]; - // StrSplit(params, keyValPair, delimEqu); - // // printf("key:%s\n", keyValPair[0]); - // // printf("value:%s\n", keyValPair[1]); - - // if ((strncmp(keyValPair[0], "minX", strlen("minX")) == 0)) - // { - // g_min_tof_range_x = atof(keyValPair[1]); - // // printf("[ CGI : /settofrange ] overwrite min x\n"); - // } - // else if ((strncmp(keyValPair[0], "minY", strlen("minY")) == 0)) - // { - // g_min_tof_range_y = atof(keyValPair[1]); - // // printf("[ CGI : /settofrange ] overwrite min y\n"); - // } - // else if ((strncmp(keyValPair[0], "min", strlen("min")) == 0)) - // { - // g_min_tof_range = atof(keyValPair[1]); - // // printf("[ CGI : /settofrange ] overwrite min\n"); - // } - // else if ((strncmp(keyValPair[0], "maxX", strlen("maxX")) == 0)) - // { - // g_max_tof_range_x = atof(keyValPair[1]); - // // printf("[ CGI : /settofrange ] overwrite max x\n"); - // } - // else if ((strncmp(keyValPair[0], "maxY", strlen("maxY")) == 0)) - // { - // g_max_tof_range_y = atof(keyValPair[1]); - // // printf("[ CGI : /settofrange ] overwrite max y\n"); - // } - // else if ((strncmp(keyValPair[0], "max", strlen("max")) == 0)) - // { - // g_max_tof_range = atof(keyValPair[1]); - // // printf("[ CGI : /settofrange ] overwrite max\n"); - // } - // // other parameters ... - - // params = strtok(NULL, delimAnd); - // } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\n[CGI:/settofrange] send error\n"); - closesocket(cli_socket); - } - else if (strcmp(urlBuffer, "/gettofrange") == 0) - { - char Msg[256] = {0}; - sprintf(Msg, "{\"min_tof_range\":\"%f\", \"max_tof_range\":\"%f\", \"unit\":\"M\"}", g_min_tof_range, g_max_tof_range); - // printf("\n[nweb.c] /gettofrange CGI - json str : %s\n\n", Msg); - strcpy(contentBuffer, Msg); - - strcpy(beforeSendBuffer, contentBuffer); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\n[CGI:/gettofrange] send error\n"); - closesocket(cli_socket); - } - else if (strcmp(urlBuffer, "/gettof") == 0) - { - char tofPATH[1024] = { 0 }; - strcpy(tofPATH, exePath); - strcat(tofPATH, "tof.json"); - char *filename = tofPATH; - if (!FileExist(filename)) - printf("[CGI:/gettof] %s doesn't exist.\n", filename); - else - { - char *fileBuf = ReadAllBytes(filename); - if (fileBuf) - { - cJSON *config_root; - char *JsonString = NULL; - config_root = cJSON_Parse(fileBuf); - if (fileBuf) - { - free(fileBuf); - fileBuf = NULL; - } - if (config_root) - { - JsonString = cJSON_PrintUnformatted(config_root); - strcat(contentBuffer, JsonString); - strcpy(beforeSendBuffer, contentBuffer); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1) - perror("[CGI:/gettof] send json string error"); - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - if (config_root) - { - cJSON_Delete(config_root); - config_root = NULL; - } - } - else - printf("[CGI:/gettof] tof.json parse FAIL.\n"); - } - } - // ======================================================================================== - // printf("\n[web process]start 17-5\n"); - closesocket(cli_socket); - } - else if ((strncmp(urlBuffer, "/settofconfig?default", 21) == 0)) - { - pthread_mutex_lock(&mutex_tof_json); - char TOF_JSON_PATH[1024] = "/emmc/plugin/Aida_data/tof.json"; - char TOF_INSTALL_JSON_PATH[1024] = "/emmc/plugin/Aida_data/tof_install.json"; - - CopyFileTo(TOF_INSTALL_JSON_PATH, TOF_JSON_PATH); - - pthread_mutex_unlock(&mutex_tof_json); - // update_radar_json(); // TODO - closesocket(cli_socket); - } - else if ((strncmp(urlBuffer, "/settofconfig?ch=1&", 19) == 0)) - { - // 01-31 - pthread_mutex_lock(&mutex_tof_json); - char buf[1024] = {}; - char Cmd[8192] = {0}; - //char msg_temp[512] = {0}; - CgiCmdRtnCode rtn; - readlink("/proc/self/exe", buf, sizeof(buf)); - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - char configPATH[1024] = { 0 }; - char config_bakPATH[1024] = { 0 }; - strcpy(configPATH, exePath); - strcpy(config_bakPATH, exePath); - strcat(configPATH, "tof.json"); - strcat(config_bakPATH, "tof_bak.json"); - - char *filename_config = configPATH; - if (!FileExist(filename_config)) - { - printf("%s doesn't exist.\n", filename_config); - rtn = _CGICMD_FAIL; - } - else - { - //size_t nfileSize_cofnig = ReadFileSize(filename_config); - char *fileBuf_config = ReadAllBytes(filename_config); - if (fileBuf_config) - { - cJSON *root = NULL; - root = cJSON_Parse(fileBuf_config); - - if (fileBuf_config) - { - free(fileBuf_config); - fileBuf_config = NULL; - } - if (root == NULL) - { - printf("root_config is NULL\n"); - rtn = _CGICMD_FAIL; - } - else - { - strcpy(Cmd, urlBuffer + 19); - const char *del = "="; - const char *del2 = "\n"; - char name[50][100]={0}; - int value = 0; - char value2[50][100]={0}; - StrSplit(Cmd, name, del); - - cJSON *camera; - if (!(camera = cJSON_GetObjectItem(root, "camera"))) - { - printf("cJSON_GetObjectItem error \n"); - } - - if (strcmp(*name, "install_angle") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - value = atoi(*value2); - cJSON_ReplaceItemInObject(root, "install_angle", cJSON_CreateNumber(value)); - tofData.tof_install_angle = value; - // printf("setting tof.json install_angle = %d \n", value); - } - else if (strcmp(*name, "enable_camera") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - bool inbool = false; - if (strcmp(*value2, "true") == 0) - inbool = true; - cJSON_ReplaceItemInObject(root, "enable_camera", cJSON_CreateBool(inbool)); - json_enable_camera_p = inbool; - tofData.tof_enable_camera = inbool; - // printf("setting tof.json enable_camera = %d \n", inbool); - } - else if (strcmp(*name, "ip_setting") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - bool inbool = false; - if (strcmp(*value2, "true") == 0) - inbool = true; - cJSON_ReplaceItemInObject(camera, "ip_setting", cJSON_CreateBool(inbool)); - tofData.tof_ip_setting = inbool; - // printf("setting tof.json ip_setting = %d \n", inbool); - } - else if (strcmp(*name, "camera_ip") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(camera, "camera_ip", cJSON_CreateString(*value2)); - sprintf(json_ptz_ip_p, "%s", *value2); - sprintf(tofData.tof_camera_ip, "%s", *value2); - // printf("setting tof.json camera_ip = %s \n", *value2); - } - else if (strcmp(*name, "camera_port") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(camera, "camera_port", cJSON_CreateString(*value2)); - sprintf(json_ptz_port_num_p, "%s", *value2); - sprintf(tofData.tof_camera_port, "%s", *value2); - // printf("setting tof.json camera_port = %s \n", *value2); - } - else if (strcmp(*name, "camera_username") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(camera, "camera_username", cJSON_CreateString(*value2)); - sprintf(json_ptz_username_p, "%s", *value2); - //sprintf(tofData.tof_camera_username, "%s", *value2); - - char temp_account[512] = { 0 }; - urlencode((unsigned char *)*value2, strlen(*value2), (unsigned char *)temp_account, 512); - memcpy(tofData.tof_camera_username, temp_account, strlen(temp_account)); - tofData.tof_camera_username[strlen(temp_account)] = '\0'; - - // printf("setting tof.json camera_username = %s \n", *value2); - } - else if (strcmp(*name, "camera_password") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(camera, "camera_password", cJSON_CreateString(*value2)); - sprintf(json_ptz_password_p, "%s", *value2); - sprintf(tofData.tof_camera_password, "%s", *value2); - // printf("setting tof.json camera_password = %s \n", *value2); - - char temp_account[512] = { 0 }; - urlencode((unsigned char *)*value2, strlen(*value2), (unsigned char *)temp_account, 512); - memcpy(tofData.tof_camera_password, temp_account, strlen(temp_account)); - tofData.tof_camera_password[strlen(temp_account)] = '\0'; - - } - else if (strcmp(*name, "enable_tof_ground") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - bool inbool = false; - if (strcmp(*value2, "true") == 0) - inbool = true; - cJSON_ReplaceItemInObject(root, "enable_tof_ground", cJSON_CreateBool(inbool)); - tofData.enable_tof_ground = inbool; - printf("setting tof.json enable_tof_ground = %d \n", inbool); - } - else if (strcmp(*name, "enable_tof_wall") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - bool inbool = false; - if (strcmp(*value2, "true") == 0) - inbool = true; - cJSON_ReplaceItemInObject(root, "enable_tof_wall", cJSON_CreateBool(inbool)); - tofData.enable_tof_wall = inbool; - printf("setting tof.json enable_tof_wall = %d \n", inbool); - } - else if (strcmp(*name, "distance_options") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(root, "distance_options", cJSON_CreateString(*value2)); - sprintf(tofData.distance_options, "%s", *value2); - //printf("setting tof.json distance_options = %s \n", *value2); - } - else if (strcmp(*name, "distance_min_max") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(root, "distance_min_max", cJSON_CreateString(*value2)); - sprintf(tofData.distance_min_max, "%s", *value2); - //printf("setting tof.json distance_options = %s \n", *value2); - } - else if (strcmp(*name, "distance_threshold") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(root, "distance_threshold", cJSON_CreateString(*value2)); - sprintf(tofData.distance_threshold, "%s", *value2); - //printf("setting tof.json distance_threshold = %s \n", *value2); - } - else if (strcmp(*name, "height_options") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(root, "height_options", cJSON_CreateString(*value2)); - sprintf(tofData.height_options, "%s", *value2); - //printf("setting tof.json height_options = %s \n", *value2); - } - else if (strcmp(*name, "height_min_max") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(root, "height_min_max", cJSON_CreateString(*value2)); - sprintf(tofData.height_min_max, "%s", *value2); - //printf("setting tof.json height_options = %s \n", *value2); - } - else if (strcmp(*name, "height_threshold") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(root, "height_threshold", cJSON_CreateString(*value2)); - sprintf(tofData.height_threshold, "%s", *value2); - //printf("setting tof.json height_threshold = %s \n", *value2); - } - else if (strcmp(*name, "ground_x") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(root, "ground_x", cJSON_CreateString(*value2)); - sprintf(tofData.ground_x, "%s", *value2); - //printf("setting tof.json height_options = %s \n", *value2); - - if (tofData.enable_tof_ground) { - int pixelX = atoi(tofData.ground_x); - int pixelY = atoi(tofData.ground_y); -#ifdef GY_OS_AMBA - g_ground_tof_range = (float)getDepth(pixelX, pixelY); -#else - g_ground_tof_range = getToFDepthByPixel(pixelX, pixelY); -#endif - int y_diff = 240 - pixelY; - double angle_diff = 0.0; - if (y_diff != 0) - { - angle_diff = 23.6 * ((double)y_diff / 240.0); - } - g_ground_tof_degree = (float)(((double)tofData.tof_install_angle) - angle_diff); - g_ground_tof_height = (float)(sin(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); - g_ground_tof_distance = (float)(cos(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); - g_tof_device_height = g_ground_tof_height; - } - } - else if (strcmp(*name, "ground_y") == 0) - { - strcpy(Cmd, urlBuffer + 20 + strlen(*name)); - StrSplit(Cmd, value2, del2); - cJSON_ReplaceItemInObject(root, "ground_y", cJSON_CreateString(*value2)); - sprintf(tofData.ground_y, "%s", *value2); - //printf("setting tof.json height_options = %s \n", *value2); - - if (tofData.enable_tof_ground) { - int pixelX = atoi(tofData.ground_x); - int pixelY = atoi(tofData.ground_y); -#ifdef GY_OS_AMBA - g_ground_tof_range = (float)getDepth(pixelX, pixelY); -#else - g_ground_tof_range = getToFDepthByPixel(pixelX, pixelY); -#endif - int y_diff = 240 - pixelY; - double angle_diff = 0.0; - if (y_diff != 0) - { - angle_diff = 23.6 * ((double)y_diff / 240.0); - } - g_ground_tof_degree = (float)(((double)tofData.tof_install_angle) - angle_diff); - g_ground_tof_height = (float)(sin(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); - g_ground_tof_distance = (float)(cos(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); - g_tof_device_height = g_ground_tof_height; - } - } - - - - char *JsonString = cJSON_Print(root); - FILE *fp; - if ((fp = fopen(filename_config, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - rtn = _CGICMD_SUCCESS; - - CopyFileTo(filename_config, config_bakPATH); - // printf("\n--------------------reload 3\n"); - // reload_dataset_from_jsonfile(); - } - else - { - printf("Fail to open tof.json \n"); - rtn = _CGICMD_FAIL; - } - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - } - if (rtn == _CGICMD_SUCCESS) - { - if (strlen(beforeSendBuffer_xtra) == 0) - { - memset(msg, 0x00, sizeof(msg)); - // sprintf(msg, "Success."); - printf(msg); - strcpy(beforeSendBuffer_xtra, msg); - } - } - else - { - if (strlen(beforeSendBuffer_xtra) == 0) - { - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "Invalid operation."); - printf(msg); - strcpy(beforeSendBuffer_xtra, msg); - } - } - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - char sendBuffer_xtra[BUFSIZE * 8] = {0}; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, 0) == -1) - perror("send error tof.json"); - // if no closesocket(), html console will show net::ERR_EMPTY_RESPONSE - if (root) - { - cJSON_Delete(root); - root = NULL; - } - } - } - pthread_mutex_unlock(&mutex_tof_json); - closesocket(cli_socket); - } -#endif - else if (strncmp(urlBuffer, "/stoppython", strlen("/stoppython")) == 0) //ming add 2024/08/26 - { - char response[256]; - if (strcmp(SystemSetting.enable_python, "Yes") == 0) - { - stopPython(); - strcpy(response, "Python has been signaled to stop."); - } - else - { - strcpy(response, "Please check the Enable python checkbox configuration in the SETTING TAB"); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html; charset=utf-8", strlen(response), response); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) { - printf("\nsend error #32\n"); - } - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/pythongetstatus", strlen("/pythongetstatus")) == 0) //2024/08/28 - { - g_cWebPythonStatus = 0; - // Definition - // 0: SETTING TAB python check box 沒勾 - // 1: buffersize 參數正常 - // 2: 寫入和讀取不在同一 Row ,並且 Buffer 有值 - // 3: buffersize 參數異常 - // 4: 寫入和讀取在同一 Row ,無法拿資料 - // 5: 在執行的 python 檔輸出已轉發完 - unsigned int uiCMDBufferRowSize = MAX_GET_PYTHON_BUFFER_ROW_SIZE; - size_t bufferContentSize = 0; - char sPythonBufferTemp[MAX_GET_PYTHON_BUFFER_ROW_SIZE * 8] = { 0 }; // 單行 512,最多拿 8 行,最大尺寸即為 4096 - char SendBufferStatus[BUFSIZE * 8] = {0}; - if (strcmp(SystemSetting.enable_python, "Yes") == 0) - { - char *buffersize_ptr = strstr(urlBuffer, "buffersize="); - if (buffersize_ptr != NULL) - { - char *buffersize_value = buffersize_ptr + strlen("buffersize="); - sscanf(buffersize_value, "%d", &uiCMDBufferRowSize); - // printf("Buffersize value: %d\n", uiCMDBufferRowSize); - g_cWebPythonStatus = 1; - } - else - { - g_cWebPythonStatus = 3; - } - printf("!!! [/pythongetstatus g_uiWebPythonLastBufferIndex:%d & g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); - - // 每次拿取 Buffer N 個 Row 的資料 - for (unsigned int i = 0; i < uiCMDBufferRowSize; i++) - { - bufferContentSize = strlen(g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex]); - // printf("[/pythongetstatus] for loop index(i) : %d , Reading g_aWebPythonBuffer2D[%d] , bufferContentSize: %zu\n", i, g_uiWebPythonLastBufferIndex, bufferContentSize); - - if (bufferContentSize > 0) - { - if (g_uiWebPythonLastBufferIndex != ((int)g_uiWebPythonCurrentBufferIndex) ) - { - g_cWebPythonStatus = 2; // 寫入和讀取不在同一 Row ,並且 Buffer 有值 - - } - else - { - g_cWebPythonStatus = 4; // 寫入和讀取在同一 Row - printf("\n\n[/pythongetstatus] Same Index !!! Wait Write Data \n\n"); - continue; - } - } - else - { - // No data in the buffer - // printf("[/pythongetstatus] Python buffer is empty.\n"); - g_cWebPythonStatus = 5; - continue; - } - } - } - else - { - g_cWebPythonStatus = 0; - // strcpy(sPythonBufferTemp, "Please check the Enable python checkbox configuration in the SETTING TAB"); - } - - sprintf(SendBufferStatus, "{\"status\":\"%d\",\"bufferSignal\":\"%d\"}", g_cWebPythonStatus, g_cWebPythonBufferSignal); - - // printf("[/pythongetstatus] Send Data To Web : %s\n\n\n",SendBufferStatus); - printf("!!! [/pythongetstatus] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(SendBufferStatus), SendBufferStatus); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - { - printf("\nsend error #32\n"); - } - memset(SendBufferStatus, 0, sizeof(SendBufferStatus)); - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/pythongetbuffer?buffersize=", strlen("/pythongetbuffer?buffersize=")) == 0) //2024/08/28 - { - - unsigned int uiCMDBufferRowSize = MAX_GET_PYTHON_BUFFER_ROW_SIZE; - size_t bufferContentSize = 0; - - char sPythonBufferTemp[MAX_GET_PYTHON_BUFFER_ROW_SIZE * 8] = { 0 }; // 單行 512,最多拿 8 行,最大尺寸即為 4096 - char beforeSendBuffer[BUFSIZE * 8] = {0}; - - if (strcmp(SystemSetting.enable_python, "Yes") == 0) - { - char *buffersize_ptr = strstr(urlBuffer, "buffersize="); - if (buffersize_ptr != NULL) - { - char *buffersize_value = buffersize_ptr + strlen("buffersize="); - sscanf(buffersize_value, "%d", &uiCMDBufferRowSize); - // printf("Buffersize value: %d\n", uiCMDBufferRowSize); - } - else - { - // printf("Invalid URL uiCMDBufferRowSize\n"); - } - - // printf("[/pythongetbuffer] check g_cWebPythonBufferSignal:%d & uiCMDBufferRowSize:%u\n", g_cWebPythonBufferSignal, uiCMDBufferRowSize); - - // 每次拿取 Buffer N 個 Row 的資料 - for (unsigned int i = 0; i < uiCMDBufferRowSize; i++) - { - bufferContentSize = strlen(g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex]); - // printf("[/pythongetbuffer] for loop index(i) : %d , Reading g_aWebPythonBuffer2D[%d] , bufferContentSize: %zu\n", i, g_uiWebPythonLastBufferIndex, bufferContentSize); - - if (g_uiWebPythonLastBufferIndex >= (WEBPYTHONBUFFER_LENSIZE-1)) - { - printf("\n\n\n/pythongetbuffer] Buffer Row Reset !!!\n\n\n"); - g_uiWebPythonLastBufferIndex = 0; - } - if (bufferContentSize > 0) - { - if (g_uiWebPythonLastBufferIndex != ((int)g_uiWebPythonCurrentBufferIndex)) - { - // 不讀正在寫的行數 - // printf("!!! [/pythongetbuffer] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); - pthread_mutex_lock(&mutex_buffer); - // 拿 python 輸出 - printf("[pythongetbuffer] get %d data \n",g_uiWebPythonLastBufferIndex); - strcat(sPythonBufferTemp, g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex]); - // 清空拿過的 row - memset(g_aWebPythonBuffer2D[g_uiWebPythonLastBufferIndex], 0, WEBPYTHONBUFFER_ROWSIZE); - pthread_mutex_unlock(&mutex_buffer); // 解鎖 - // 更新讀取位置 - g_uiWebPythonLastBufferIndex++; - } - else - { - printf("\n\n/pythongetbuffer] Same Index !!! No Read Data \n\n"); - continue; - } - - } - else - { - // No data in the buffer - // printf("[/pythongetbuffer] Python buffer is empty.\n"); - continue; - } - - } - } - else - { - strcpy(sPythonBufferTemp, "Please check the Enable python checkbox configuration in the SETTING TAB"); - } - printf("\n\nsPythonBufferTemp : %s\n\n",sPythonBufferTemp); - sprintf(beforeSendBuffer , sPythonBufferTemp); - // printf("[/pythongetbuffer] Send Data To Web : %s\n\n\n",beforeSendBuffer); - printf("!!! [/pythongetbuffer] reach writing index, g_uiWebPythonLastBufferIndex:%d == g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex); - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - { - printf("\nsend error #32\n"); - } - memset(beforeSendBuffer, 0, sizeof(beforeSendBuffer)); - closesocket(cli_socket); - } - // ======================================================================================== -#endif -#if 1 - else if ((strncmp(urlBuffer, "/getevents?", 11) == 0) || (strncmp(urlBuffer, "/setevents?", 11) == 0)) - { - pthread_mutex_lock(&mutex_events_json); - - //printf("\n[web process]start 25\n"); - - //printf("\n--------------urlBuffer:%s\n", urlBuffer); - - char Cmd[8192] = { 0 }; - char msg_temp[512] = { 0 }; - strcpy(Cmd, urlBuffer + 11); -#ifdef _DEBUG_AMBA - printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); -#endif - CgiCmdType type; - if (strncmp(urlBuffer, "/getevents?", 11) == 0) type = _CGICMD_GET; - else { - type = _CGICMD_SET; - check_if_correct_post = 0; - } - //printf("\n[web process]start cgi 25\n"); - CgiCmdRtnCode rtn = cgicmd_process_events(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); - //printf("\n[web process]end cgi 25\n"); - //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); - if (rtn == _CGICMD_RELOAD) - { - g_write_config_file_dirty_flag = 0; - - write_config(); - - printf("\n--------------------reload 5\n"); - sprintf(msg_temp, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); - printf(msg_temp); - strcpy(beforeSendBuffer_xtra, msg_temp); - - } - else if (rtn == _CGICMD_SUCCESS) - { - if (type == _CGICMD_SET) { - g_write_config_file_dirty_flag = 1; - } - - if (strlen(beforeSendBuffer_xtra) == 0) - { - //sprintf(msg, "Success."); - printf(msg_temp); - strcpy(beforeSendBuffer_xtra, msg_temp); - } - } - else - { - if (strlen(beforeSendBuffer_xtra) == 0) - { - sprintf(msg_temp, "Invalid operation."); - printf(msg_temp); - strcpy(beforeSendBuffer_xtra, msg_temp); - } - } - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #33\n"); - //printf("\n[web process]end 25\n"); - - pthread_mutex_unlock(&mutex_events_json); - closesocket(cli_socket); - - - } -#endif -#if 1 - else if ((strncmp(urlBuffer, "/getcounters?", 13) == 0) || (strncmp(urlBuffer, "/setcounters?", 13) == 0)) - { - pthread_mutex_lock(&mutex_events_json); - - - //printf("\n[web process]start 2555\n"); - //printf("\n--------set counters:%s\n", urlBuffer); - - char Cmd_temp[8192] = { 0 }; - char msg_temp[512] = { 0 }; - strcpy(Cmd_temp, urlBuffer + 13); - char Cmd[8192] = { 0 }; - int Cmd_index = 0; - for (int i = 0; i < (int)strlen(Cmd_temp); i++) { - if (i< (int)strlen(Cmd_temp)-2) { - if (!(Cmd_temp[i] == '%' && Cmd_temp[i + 1] == '2' && Cmd_temp[i + 2] == '0')) { - Cmd[Cmd_index] = Cmd_temp[i]; - Cmd_index++; - } - else { - Cmd[Cmd_index] = ' '; - Cmd_index++; - i += 2; - } - } - else { - Cmd[Cmd_index] = Cmd_temp[i]; - Cmd_index++; - } - } - Cmd[Cmd_index] = '\0'; - //printf("\n--------Cmd:%s\n", Cmd); - - #ifdef _DEBUG_AMBA - printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); - #endif - CgiCmdType type; - if (strncmp(urlBuffer, "/getcounters?", 13) == 0) type = _CGICMD_GET; - else type = _CGICMD_SET; - //printf("\n[web process]start cgi 25\n"); - CgiCmdRtnCode rtn = cgicmd_process_event_counters(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); - //printf("\n[web process]end cgi 25\n"); - //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); - if (rtn == _CGICMD_RELOAD) - { - g_write_config_file_dirty_flag = 0; - - write_config(); - - printf("\n--------------------reload 6\n"); - sprintf(msg_temp, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); - printf(msg_temp); - strcpy(beforeSendBuffer_xtra, msg_temp); - - } - else if (rtn == _CGICMD_SUCCESS) - { - if (type == _CGICMD_SET) { - g_write_config_file_dirty_flag = 1; - } - - if (strlen(beforeSendBuffer_xtra) == 0) - { - //sprintf(msg, "Success."); - printf(msg_temp); - strcpy(beforeSendBuffer_xtra, msg_temp); - } - } - else - { - if (strlen(beforeSendBuffer_xtra) == 0) - { - sprintf(msg_temp, "Invalid operation."); - printf(msg_temp); - strcpy(beforeSendBuffer_xtra, msg_temp); - } - } - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #33--2\n"); - //printf("\n[web process]end 25\n"); - - pthread_mutex_unlock(&mutex_events_json); - closesocket(cli_socket); - } -#endif -#if 1 - else if ((strncmp(urlBuffer, "/getemail?", 10) == 0) || (strncmp(urlBuffer, "/setemail?", 10) == 0)) - { - pthread_mutex_lock(&mutex_events_json); - - - //printf("\n[web process]start 2555\n"); - //printf("\n--------set email:%s\n", urlBuffer); - - char Cmd_temp[8192] = { 0 }; - char msg_temp[512] = { 0 }; - strcpy(Cmd_temp, urlBuffer + 10); - char Cmd[8192] = { 0 }; - int Cmd_index = 0; - for (int i = 0; i < (int)strlen(Cmd_temp); i++) { - if (i < (int)strlen(Cmd_temp) - 2) { - if (Cmd_temp[i] == '%' && Cmd_temp[i + 1] == '2' && Cmd_temp[i + 2] == '0') { - Cmd[Cmd_index] = ' '; - Cmd_index++; - i += 2; - } - else if (Cmd_temp[i] == '%' && Cmd_temp[i + 1] == '3' && Cmd_temp[i + 2] == 'C') { - Cmd[Cmd_index] = '<'; - Cmd_index++; - i += 2; - } - else if (Cmd_temp[i] == '%' && Cmd_temp[i + 1] == '3' && Cmd_temp[i + 2] == 'E') { - Cmd[Cmd_index] = '>'; - Cmd_index++; - i += 2; - } - else if (Cmd_temp[i] == '%' && Cmd_temp[i + 1] == '7' && Cmd_temp[i + 2] == 'C') { - Cmd[Cmd_index] = '|'; - Cmd_index++; - i += 2; - } - else { - Cmd[Cmd_index] = Cmd_temp[i]; - Cmd_index++; - } - } - else { - Cmd[Cmd_index] = Cmd_temp[i]; - Cmd_index++; - } - } - Cmd[Cmd_index] = '\0'; - //printf("\n--------Cmd:%s\n", Cmd); - - #ifdef _DEBUG_AMBA - printf("\n(%d) [web process] ### Cmd:%s %d\n=======================\n", cli_socket, Cmd, (int)strlen(Cmd)); - #endif - CgiCmdType type; - if (strncmp(urlBuffer, "/getemail?", 10) == 0) type = _CGICMD_GET; - else type = _CGICMD_SET; - //printf("\n[web process]start cgi 25\n"); - CgiCmdRtnCode rtn = cgicmd_process_email_setting(Cmd, type, beforeSendBuffer_xtra, BUFSIZE * 60); - //printf("\n[web process]end cgi 25\n"); - //printf("\n(%d) [web process] ### CgiCmdRtnCode rtn:%d \n%s\n=======================\n", cli_socket, rtn,beforeSendBuffer); - if (rtn == _CGICMD_RELOAD) - { - g_write_config_file_dirty_flag = 0; - - write_config(); - - printf("\n--------------------reload 66\n"); - sprintf(msg_temp, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); - printf(msg_temp); - strcpy(beforeSendBuffer_xtra, msg_temp); - - } - else if (rtn == _CGICMD_SUCCESS) - { - if (type == _CGICMD_SET) { - g_write_config_file_dirty_flag = 1; - } - - if (strlen(beforeSendBuffer_xtra) == 0) - { - //sprintf(msg, "Success."); - printf(msg_temp); - strcpy(beforeSendBuffer_xtra, msg_temp); - } - } - else - { - if (strlen(beforeSendBuffer_xtra) == 0) - { - sprintf(msg_temp, "Invalid operation."); - printf(msg_temp); - strcpy(beforeSendBuffer_xtra, msg_temp); - } - } - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #33--22\n"); - //printf("\n[web process]end 25\n"); - - pthread_mutex_unlock(&mutex_events_json); - closesocket(cli_socket); - } -#endif -#if 0 - else if (strcmp(urlBuffer, "/get_replace_email") == 0){ - pthread_mutex_lock(&mutex_events_json); - - char *replacement_t = NULL; - - replacement_t = StrReplace(emailData.email_content, "An apple", "A banana"); - strcpy(beforeSendBuffer_xtra, replacement_t); - free(replacement_t); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #33--2211\n"); - closesocket(cli_socket); - - pthread_mutex_unlock(&mutex_events_json); - } -#endif -#ifdef GY_OS_AMBA - else if (strcmp(urlBuffer, "/aiautotracking_json") == 0) - { - //printf("\n[web process]start 7\n"); - - char Msg[256] = { 0 }; - strcpy(beforeSendBuffer_xtra, "{\"DeviceName\":\"GYNet\","); -#if defined GY_OS_AMBA || defined GY_OS_NOVA - sprintf(Msg, "\"Version\":\"%s\",", APP_VERSION); -#endif - strcat(beforeSendBuffer_xtra, Msg); - - sprintf(Msg, "\"Thread_Running\":%d,", g_stPTZ_Handle.iThreadRunningFlag); - strcat(beforeSendBuffer_xtra, Msg); - - //sprintf(Msg, "\"iTimer_send_count\":%d,", g_stPTZ_Handle.iTimer_send_count); - //strcat(beforeSendBuffer_xtra, Msg); - - //sprintf(Msg, "\"iPTZ_sensitivity\":%d,", g_stPTZ_Handle.iPTZ_sensitivity); - //strcat(beforeSendBuffer_xtra, Msg); - - //sprintf(Msg, "\"Lose_Running\":%d,", g_stPTZ_Handle.LostTime); - //strcat(beforeSendBuffer_xtra, Msg); - - //sprintf(Msg, "\"Resume_Running\":%d,", g_stPTZ_Handle.ResumTime); - //strcat(beforeSendBuffer_xtra, Msg); - - sprintf(Msg, "\"iEnable_tracking\":%d,", g_stPTZ_Handle.iEnable_tracking); - strcat(beforeSendBuffer_xtra, Msg); - - sprintf(Msg, "\"iIsAtHomePOS\":%d,", g_stPTZ_Handle.iIsAtHomePOS); - strcat(beforeSendBuffer_xtra, Msg); - - sprintf(Msg, "\"iIsInPreset\":%d,", g_stPTZ_Handle.iIsInPreset); - strcat(beforeSendBuffer_xtra, Msg); - - sprintf(Msg, "\"iIsInAutopan\":%d,", g_stPTZ_Handle.iIsInAutopan); - strcat(beforeSendBuffer_xtra, Msg); - - sprintf(Msg, "\"iIsInAutoTracking\":%d,", g_stPTZ_Handle.iIsInAutoTracking); - strcat(beforeSendBuffer_xtra, Msg); - - sprintf(Msg, "\"iHomePreset\":%d,", g_stPTZ_Handle.iHomePreset); - strcat(beforeSendBuffer_xtra, Msg); - - sprintf(Msg, "\"iRunPTZUpdateStatusThread_flag\":%d,", g_stPTZ_Handle.iRunPTZTrackingThread_flag); - strcat(beforeSendBuffer_xtra, Msg); - - sprintf(Msg, "\"iRunPTZTrackingThread_flag\":%d,", g_stPTZ_Handle.iRunPTZTrackingThread_flag); - strcat(beforeSendBuffer_xtra, Msg); - - sprintf(Msg, "\"iCandidateBoxCount\":%d,", g_stPTZ_Handle.iCandidateBoxCount); - strcat(beforeSendBuffer_xtra, Msg); - - sprintf(Msg, "\"iIsGetLockTrackingBox\":%d,", g_stPTZ_Handle.iIsGetLockTrackingBox); - strcat(beforeSendBuffer_xtra, Msg); - - sprintf(Msg, "\"iLockBoxIdx\":%d,", g_stPTZ_Handle.iLockBoxIdx); - strcat(beforeSendBuffer_xtra, Msg); - - sprintf(Msg, "\"stPTZLockTrackingBox.stPTZLockTrackingBox.obj_tracking_id\":%d", g_stPTZ_Handle.stPTZLockTrackingBox.obj_tracking_id); - strcat(beforeSendBuffer_xtra, Msg); - - strcat(beforeSendBuffer_xtra, "}"); - - //strcat(beforeSendBuffer_xtra, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer_xtra, " "); - strcat(beforeSendBuffer_xtra, contentDescription); - } - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html;", strlen(beforeSendBuffer_xtra), beforeSendBuffer_xtra); - if (send(cli_socket, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #188\n"); - //printf("\n[web process]-4: closesocket(cli_socket): %d\n", cli_socket); - closesocket(cli_socket); - } - else if (strcmp(urlBuffer, "/aiautotracking_info") == 0) - { - //printf("\n[web process]start 7\n"); - - char Msg[256] = { 0 }; - strcpy(contentBuffer, "DeviceName=GYNet\r\n
"); -#if defined GY_OS_AMBA || defined GY_OS_NOVA - sprintf(Msg, "Version=%s\r\n
", APP_VERSION); -#endif - strcat(contentBuffer, Msg); - - sprintf(Msg, "Thread Running = %d\r\n
", g_stPTZ_Handle.iThreadRunningFlag); - strcat(contentBuffer, Msg); - - //sprintf(Msg, "iTimer_send_count = %d\r\n
", g_stPTZ_Handle.iTimer_send_count); - //strcat(contentBuffer, Msg); - - //sprintf(Msg, "iPTZ_sensitivity = %d\r\n
", g_stPTZ_Handle.iPTZ_sensitivity); - //strcat(contentBuffer, Msg); - - //sprintf(Msg, "Lose Running = %d\r\n
", g_stPTZ_Handle.LostTime); - //strcat(contentBuffer, Msg); - - //sprintf(Msg, "Resume Running = %d\r\n
", g_stPTZ_Handle.ResumTime); - //strcat(contentBuffer, Msg); - - sprintf(Msg, "iEnable_tracking=%d\r\n
", g_stPTZ_Handle.iEnable_tracking); - strcat(contentBuffer, Msg); - - sprintf(Msg, "iIsAtHomePOS=%d\r\n
", g_stPTZ_Handle.iIsAtHomePOS); - strcat(contentBuffer, Msg); - - sprintf(Msg, "iIsInPreset=%d\r\n
", g_stPTZ_Handle.iIsInPreset); - strcat(contentBuffer, Msg); - - sprintf(Msg, "iIsInAutopan=%d\r\n
", g_stPTZ_Handle.iIsInAutopan); - strcat(contentBuffer, Msg); - - sprintf(Msg, "iIsInAutoTracking=%d\r\n
", g_stPTZ_Handle.iIsInAutoTracking); - strcat(contentBuffer, Msg); - - sprintf(Msg, "iHomePreset=%d\r\n
", g_stPTZ_Handle.iHomePreset); - strcat(contentBuffer, Msg); - - sprintf(Msg, "iRunPTZUpdateStatusThread_flag=%d\r\n
", g_stPTZ_Handle.iRunPTZTrackingThread_flag); - strcat(contentBuffer, Msg); - - sprintf(Msg, "iRunPTZTrackingThread_flag=%d\r\n
", g_stPTZ_Handle.iRunPTZTrackingThread_flag); - strcat(contentBuffer, Msg); - - sprintf(Msg, "iCandidateBoxCount=%d\r\n
", g_stPTZ_Handle.iCandidateBoxCount); - strcat(contentBuffer, Msg); - - sprintf(Msg, "iIsGetLockTrackingBox=%d\r\n
", g_stPTZ_Handle.iIsGetLockTrackingBox); - strcat(contentBuffer, Msg); - - sprintf(Msg, "iLockBoxIdx=%d\r\n
", g_stPTZ_Handle.iLockBoxIdx); - strcat(contentBuffer, Msg); - - sprintf(Msg, "stPTZLockTrackingBox=%ld\r\n
", sizeof(g_stPTZ_Handle.stPTZLockTrackingBox)); - strcat(contentBuffer, Msg); - - strcat(contentBuffer, "\r\n
"); - - - - strcpy(beforeSendBuffer, contentBuffer); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse_server(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #18\n"); - //printf("\n[web process]-4: closesocket(cli_socket): %d\n", cli_socket); - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/ptzpreset?camid=1&ai_goto_preset=", 34) == 0) - { - if (IsPTZ() == 1) - { - //Stop Autopan - //StartStopAutopan(0); - - //Go Preset - char sPresetNumber[10] = { 0 }; - memset(sPresetNumber, 0x00, sizeof(sPresetNumber)); - strcpy(sPresetNumber, urlBuffer + 34); - - int iPreset_number = 1; - if (strlen(sPresetNumber) > 0) - iPreset_number = atoi(sPresetNumber); - - GoPreset(iPreset_number); - - //usSleep(2000000); - - //Start Autopan - //StartStopAutopan(1); - - //Response - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "go preset success."); - //printf(msg); - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #38\n"); - - closesocket(cli_socket); - } - else - { - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "This device is not support PTZ."); - //printf(msg); - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #38\n"); - - closesocket(cli_socket); - } - } - else if (strncmp(urlBuffer, "/ptz_move_direction?", 20) == 0) - { - memset(msg, 0x00, sizeof(msg)); - if (IsPTZ() == 1) - { - char sCmd[256] = { 0 }; - memset(sCmd, 0x00, sizeof(sCmd)); - strcpy(sCmd, urlBuffer + 20); - - char spilt_move[2][STRSPLIT_SIZE]={0}; - const char *del = "&"; - int num_move = 0; - num_move = StrSplit(sCmd, spilt_move, del); - //printf("\n------UU:32\n"); - int iPan = 0; - int iTilt = 0; - - for (int i = 0; i < num_move; i++) { - char a_spilt_move[2][STRSPLIT_SIZE]={0}; - const char *del2 = "="; - int a_num_move = 0; - a_num_move = StrSplit(spilt_move[i], a_spilt_move, del2); - //printf("\n------UU:33\n"); - for (int j = 0; j < a_num_move; j++) { - if (strcmp(a_spilt_move[0], "pan") == 0) { - iPan = atoi(a_spilt_move[1]) * atoi(viewChannelData[0].ptz_speed); - } - else if (strcmp(a_spilt_move[0], "tilt") == 0) { - iTilt = atoi(a_spilt_move[1]) * atoi(viewChannelData[0].ptz_speed); //避免太快 - } - } - } - - if (iPan != 0 || iTilt != 0){ - StopPtz(); - move_PTZ_in_the_direction(iPan, iTilt); - pthread_t ptz_stop_thread_id; - if (pthread_create(&ptz_stop_thread_id, 0, ptz_stop_thread, NULL)) - { - printf("\ncreate ptz stop thread faile \n"); - } - sprintf(msg, "Move direction success."); - } - else { - sprintf(msg, "Move direction fail."); - } - } - else - { - sprintf(msg, "This device is not support PTZ."); - } - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #328\n"); - - closesocket(cli_socket); - } - else if (strncmp(urlBuffer, "/ptz_stop", 9) == 0) - { - memset(msg, 0x00, sizeof(msg)); - if (IsPTZ() == 1) - { - StopPtz(); - } - else - { - sprintf(msg, "This device is not support PTZ."); - } - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #3128\n"); - - closesocket(cli_socket); - } -#endif - else if (strncmp(urlBuffer, "/", 1) == 0) - { - //printf("\n[web process]start 26\n"); - char * pch; - pch = strstr(urlBuffer, "jpg"); - - if (pch == NULL) - { - //syslog(NW_SORRY, "file type not supported", firstBuffer, cli_socket); - //memset(msg, 0x00, sizeof(msg)); - - char msg_temp[512] = { 0 }; - sprintf(msg_temp, "Unknown Url"); - //printf("%s\n", msg); - - strcpy(beforeSendBuffer, msg_temp); - //strcat(beforeSendBuffer, MSG_END_PATTERN); - - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - char sendBuffer[BUFSIZE_V2] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #34\n"); - - /*printf("\n[web process]-A-1:free(contentBuffer)\n"); - free(contentBuffer); //double free - */ - //printf("\n[web process]-A-1: closesocket(client_socket): %d\n", cli_socket); - closesocket(cli_socket); - } - else - { - //printf("\n[nweb.c]urlBuffer:\n"); - //printf(urlBuffer); - //printf("\n"); - /* convert no filename to index file */ - - if (!strncmp(&firstBuffer[0], "GET /\0", 6) || !strncmp(&firstBuffer[0], "get /\0", 6)) - strcpy(firstBuffer, "GET /example.htm"); - else - { - strcpy(firstBuffer, "GET "); - strcat(firstBuffer, urlBuffer); - firstBuffer[strlen("GET ") + strlen(urlBuffer)] = '\0'; - } - - /* work out the file type and check if we support it */ - buflen = strlen(firstBuffer); - fstr = NULL; - for (idx = 0; extensions[idx].ext != 0; idx++) - { - len = strlen(extensions[idx].ext); - //printf(extensions[idx].ext); - if (!strncmp(&firstBuffer[buflen - len], extensions[idx].ext, len)) - { - fstr = extensions[idx].filetype; - break; - } - } - - if (fstr == NULL) - { - //syslog(NW_SORRY, "file type not supported", firstBuffer, cli_socket); - char msg_temp[512] = { 0 }; - //memset(msg, 0x00, sizeof(msg)); - sprintf(msg_temp, "[0]The file %s has unknown file extension.", &firstBuffer[5]); - //printf("%s\n", msg); - - strcpy(beforeSendBuffer, msg_temp); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - char sendBuffer[BUFSIZE_V2] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #35\n"); - } - else - { - /* execute the send command, but first check if the browser */ - /* has requested the default icon file, favicon.ico. */ - if (!strncmp(firstBuffer + 5, "/favicon.ico", 12)) - { - /* Send a null file to satisfy a request for favicon.ico */ - sprintf(tempBuffer, "HTTP/1.1 204 No Content\r\n\r\n"); - send(cli_socket, tempBuffer, strlen(tempBuffer), 0); - } - else - { - ///* open the file for reading */ - //if ((fp = fopen(&firstBuffer[5], "rb")) == NULL) - //{ - // syslog(NW_SORRY, "failed to open file", &firstBuffer[5], cli_socket); - //} - - int file_fd; - if ((file_fd = open(&firstBuffer[5], O_RDONLY)) == -1) - { - printf("Failed to open file : %s\n", &firstBuffer[5]);//網頁檔案有沒有被讀取 - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #19-52\n"); - } - else { - int iFileLength = 0; - char sendBuffer_superlarge[BUFSIZE * 8 * 16] = { 0 }; - iFileLength = read(file_fd, sendBuffer_superlarge, BUFSIZE * 8 * 16); - close(file_fd); - - /* work out the file type and check if we support it */ - buflen = strlen(urlBuffer); - fstr = NULL; - for (idx = 0; extensions[idx].ext != 0; idx++) - { - len = strlen(extensions[idx].ext); - if (!strncmp(&urlBuffer[buflen - len], extensions[idx].ext, len)) - { - fstr = extensions[idx].filetype; - break; - } - } - - if (fstr == NULL) - { - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #19554\n"); - } - else - { - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: %s;charset=utf-8;\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n", fstr); /*\r\nCache - Control: max - age = 30*/ - if (send(cli_socket, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #20221\n"); - } - - int iSentLeft = 0; - int iSentLength = 0; - int iHaveSentLength = 0; - int iRetryCount = 5; - - - - iSentLeft = iFileLength; - - while (iSentLeft >= 1) { - iSentLength = send(cli_socket, sendBuffer_superlarge + iHaveSentLength, iSentLeft, MSG_MORE); - - if (iSentLength <= 0) - break; - - iHaveSentLength = iHaveSentLength + iSentLength; - iSentLeft = iSentLeft - iSentLength; - iRetryCount--; - - if (iSentLeft >= 1) { - //printf("\n[web process]iSentLeft: %d\n", iSentLeft); - } - - if (iRetryCount <= 0) - break; - //usSleep(100); - } - } - } - } - closesocket(cli_socket); - } - } - } - else if (strcmp(httpCommand, "POST ") == 0) - { - if (strncmp(urlBuffer, "/sendjpeg", strlen("/sendjpeg")) == 0) - { - //printf("\n[web process]start 27\n"); - char *image_buff = NULL; - int image_buff_size = 0; - image_buff = malloc(CONTENT_BUFSIZE); - char httpVariables[BUFSIZE_V2] = { 0 }; - char *QuestionMarK = strstr(urlBuffer, "?"); - - if (QuestionMarK) - { - strcpy(httpVariables, QuestionMarK + 1); - //char *start = httpVariables; - char *pch; - char *pDelim = "&"; - char *pLeft = NULL; - // pch = strtok_r(httpVariables, pDelim, &pLeft); - // BUG9 : 改用 strtok_modified - pch = strtok_modified(httpVariables, pDelim, &pLeft); - while (pch != NULL) { - // string between start and delim (or end of string if delim is NULL). - if (pch) - { - char attribute[512] = { 0 };//512 - strcpy(attribute, pch); - //attribute[pDelim - start] = 0; - char att_var[10][STRSPLIT_SIZE]={0}; - char *del = "="; - //int att_var_num = 0; - //if (attribute) - { - /*att_var_num = */StrSplit(attribute, att_var, del); - //printf("\n------UU:34\n"); - if (strcmp(att_var[0], "channel") == 0) - { - tracking_channel = atoi(att_var[1]); - tracking_channel_idx = tracking_channel - 1; - } - } - //start = pDelim + 1; // Use length of your b string. - } - pch = strtok_modified(NULL, pDelim, &pLeft); - } - } - - if (bIsMultipart) - { - char* pContent = contentBuffer; - char* pBlockStart = contentBuffer; - image_buff_size = nTotalContentLen; - memset(image_buff, 0x00, CONTENT_BUFSIZE); - size_t nbytes = 0; - size_t nTotalBytes = 0; - - for (int i = 0; i < nTotalContentLen; i++) - { - pContent = contentBuffer + i; - if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) - { - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - i += (pBlockStart - pContent - 1); - } - else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) - { - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - i += (pBlockStart - pContent - 1); - } - else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) - { - if (pContent - pBlockStart == 0) - nbytes = pContent - pBlockStart; - else if (pContent - pBlockStart > 0) - nbytes = (pContent - pBlockStart) - strlen("\r\n"); - memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); - nTotalBytes += nbytes; - - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - i += (pBlockStart - pContent - 1); - } - - } - char* pJpegStart = NULL; - char* pJpegEnd = NULL; - for (int i = 0; i < nTotalBytes; i++) - { - if (memcmp(image_buff + i, "\xFF\xD8", 2) == 0) - { - pJpegStart = image_buff + i; - break; - } - } - - for (int i = nTotalBytes; i > 0; i--) - { - if (memcmp(image_buff + i, "\xFF\xD9", 2) == 0) - { - pJpegEnd = image_buff + i + 2; - break; - } - } - - //printf("%x%x%x%x\n", *(image_buff + 0) & 0xff, *(image_buff + 1) & 0xff, *(image_buff + image_buff_size - 2) & 0xff, *(image_buff + image_buff_size -1) & 0xff); - - if (!pJpegStart || !pJpegEnd) - { - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "Error JPEG format(Multipart)."); - printf("%s\n", msg); - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_204, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend(Not JPEG format)\n"); - - - //printf("\n[web process]-A-3: free(contentBuffer)\n"); - if (contentBuffer) { - free(contentBuffer); - contentBuffer = NULL; - } - if (image_buff) { - free(image_buff); - image_buff = NULL; - } - - //printf("\n[web process]-A-3: closesocket(client_socket): %d\n", cli_socket); - closesocket(cli_socket); - - return; - } - else - { - image_buff_size = pJpegEnd - pJpegStart; - memmove(image_buff, pJpegStart, image_buff_size); - -#if 0 - printf("[%d]===>image_buff_size = %d \n", tracking_channel_idx, image_buff_size); -#endif - - memset(image_buff + image_buff_size, 0x00, nTotalBytes - image_buff_size); - } - } - else - { - image_buff_size = nTotalContentLen; - memcpy(image_buff, contentBuffer, image_buff_size); - //DumpHex(image_buff + image_buff_size - 10, 10); - } - - if (!(memcmp(image_buff, "\xFF\xD8", 2) == 0 && memcmp(image_buff + image_buff_size - 2, "\xFF\xD9", 2) == 0)) - { - //DumpHex(image_buff, 2); - //DumpHex(image_buff + image_buff_size - 2, 2); - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "Error JPEG format."); - printf("%s\n", msg); - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend\n"); - //printf("\n[web process]-A-4: free(contentBuffer)\n"); - if (contentBuffer) { - free(contentBuffer); - contentBuffer = NULL; - } - if (image_buff) { - free(image_buff); - image_buff = NULL; - } - - //printf("\n[web process]-A-4: closesocket(cli_socket): %d\n", cli_socket); - closesocket(cli_socket); - return; - } - - /*if (layer_count == 0) - { - printf("Invalid layer count %d\n", cli_socket); - //int sendBufferSize = SetHttpResponse(sendBuffer, "HTTP/1.1 403 Forbidden", "text/html;", strlen("Invalid license key"), "Invalid license key");//20201028 sophia mark - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_403, "text/html;", strlen("Invalid license key"), "Invalid license key");//20201028 sophia add - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #37\n"); - //printf("\n[web process]-A-5: free(contentBuffer)\n"); - if (contentBuffer) { - free(contentBuffer); - contentBuffer = NULL; - } - if (image_buff) { - free(image_buff); - image_buff = NULL; - } - - //printf("\n[web process]-A-5: closesocket(cli_socket): %d\n", cli_socket); - closesocket(cli_socket); - return; - }*/ - -#if defined GY_OS_AMBA - GetAIImageDimension(image_buff, image_buff_size, &AIImage_width, &AIImage_height); - - //int nNeedUpdateTrafficLightZone = 0; - /* - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\njpeg_width: %d\n", jpeg_width); - printf("\ntab_view_width: %d\n", viewChannelData[tracking_channel_idx].tab_view_width); - printf("\ntab_view_height: %d\n", viewChannelData[tracking_channel_idx].tab_view_height); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - */ - if (AIImage_width > 0) - { - //if (abs(viewChannelData[tracking_channel_idx].tab_view_width_ratio * viewChannelData[tracking_channel_idx].tab_view_width - AIImage_width) > 5) - //nNeedUpdateTrafficLightZone = 1; - // - viewChannelData[tracking_channel_idx].tab_view_width_ratio = (float)AIImage_width / viewChannelData[tracking_channel_idx].tab_view_width; - viewChannelData[tracking_channel_idx].tab_view_height_ratio = (float)AIImage_width / viewChannelData[tracking_channel_idx].tab_view_height; -//#ifdef GY_OS_WIN - //if (nNeedUpdateTrafficLightZone) - //UpdateTrafficLightZone(tracking_channel_idx); -//#endif - } -#endif - socketRecords[sock_info_idx].channel_id = tracking_channel; - - //double recv_clock = clock(); - //double diff = ((double)(recv_clock - begin_clock) / CLOCKS_PER_SEC); - //sprintf(msg, "log/sock-%05d_sec_%f %s.jpg", cli_socket, diff, contentDescription); - //FILE *f = fopen(msg, "wb"); - //if (f == NULL) - //{ - // printf("Error opening file!\n"); - // //exit(1); - //} - //fwrite(image_buff, image_buff_size, 1, f); - //fclose(f); - - //AI recognizing process - clock_t c1 = clock(); - ///Steven MARK TEMP - /* - - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\nweb process: %d\n",1); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");*/ - - clock_t c2 = clock(); - double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); - printf("recognition time %d:%f\n", cli_socket, dDiff); - if (image_buff) { - free(image_buff); - image_buff = NULL; - } - } - else if (strncmp(urlBuffer, "/setemailsfile", strlen("/setemailsfile")) == 0) { - //printf("\n----------urlBuffer:%s\n", urlBuffer); - - //pthread_mutex_lock(&mutex_config_json); - - int check_if_setfile_OK = 0; - - int file_buff_size = nTotalContentLen; - if (file_buff_size >= 1) - { - char* file_Content = recvBuffer + recv_buff_size; - - //printf("\n------file_buff_size:%d\n", file_buff_size); - //printf("\n------file_Content:%s\n", file_Content); - -#if 1 - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char emails_importPATH[1024]; - strcpy(emails_importPATH, exePath); - strcat(emails_importPATH, "emails_import.json"); - - char emails_PATH[1024]; - char emails_bakPATH[1024]; - strcpy(emails_PATH, exePath); - strcpy(emails_bakPATH, exePath); - strcat(emails_PATH, "emails.json"); - strcat(emails_bakPATH, "emails_bak.json"); - - FILE *pFile; - - if ((pFile = fopen(emails_importPATH, "w+")) != NULL) - { - fprintf(pFile, "%s", file_Content); - fclose(pFile); - - char* fileBuf = ReadAllBytes(emails_importPATH); - char* fileBuf2 = ReadAllBytes(emails_PATH); - - if (fileBuf && fileBuf2) { - - cJSON *root = cJSON_Parse(fileBuf); - cJSON *s_root = cJSON_Parse(fileBuf2); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (fileBuf2) { - free(fileBuf2); - fileBuf2 = NULL; - } - if (root && s_root) - { - cJSON *auth_password; - //cJSON *s_auth_password; - auth_password = cJSON_GetObjectItem(root, "auth_password"); - //s_auth_password = cJSON_GetObjectItem(s_root, "auth_password"); - - if (auth_password) - { - size_t base64_decode_length = 0; - char EncryptKeyData[256]; - //char DecryptKeyData[256]; - memset(EncryptKeyData, 0x00, sizeof(EncryptKeyData)); - //memset(DecryptKeyData, 0x00, sizeof(DecryptKeyData)); - unsigned char OriEncryptData[512] = { 0 }; - - char temp_auth_password[256] = { 0 }; - memcpy(temp_auth_password,auth_password->valuestring,strlen(auth_password->valuestring)); - - base64_decode(temp_auth_password, strlen(temp_auth_password), &base64_decode_length, OriEncryptData); - memcpy(EncryptKeyData, OriEncryptData, base64_decode_length); - - //KeyExpansion(key_email, expandedKey_email); - //unsigned char EncryptData[1 * 1024]; - //memset(EncryptData, 0x00, sizeof(EncryptData)); - //int encryptSize = AESEncryptArrayToArray(temp_auth_password, strlen(temp_auth_password), expandedKey_email, EncryptData, sizeof(EncryptData)); - - //EncryptData[encryptSize] = '\0'; - //int decryptSize = AESDecryptArrayToArray(EncryptData, strlen(EncryptData), expandedKey_email, DecryptKeyData, sizeof(DecryptKeyData)); - - strcpy(IPCAMService.auth_password, EncryptKeyData); - cJSON_ReplaceItemInObject(s_root, "auth_password", cJSON_CreateString(temp_auth_password)); - - //printf("\n----------IPCAMService.auth_password:%s\n", IPCAMService.auth_password); - //printf("\n----------temp_auth_password:%s\n", temp_auth_password); - //printf("\n----------EncryptData:%s\n", EncryptData); - } - - - char* JsonString = cJSON_Print(s_root); - - FILE *f = fopen(emails_PATH, "w"); - if (f != NULL) - { - fprintf(f, "%s\n", JsonString); - fclose(f); - - CopyFileTo(emails_PATH, emails_bakPATH); - check_if_setfile_OK = 1; - //g_count_alter = 50; - } - - if (JsonString) { - free(JsonString); - JsonString = NULL; - } - } - - if (root) { - cJSON_Delete(root); - root = NULL; - } - if (s_root) { - cJSON_Delete(s_root); - s_root = NULL; - } - } - else { - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (fileBuf2) { - free(fileBuf2); - fileBuf2 = NULL; - } - printf("\nFail to read config_import.json or config.json\n"); - } - } - -#endif - } - - strcpy(beforeSendBuffer, ""); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - if (check_if_setfile_OK == 1) { - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("send(Not set emails file)"); - } - else { - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("send(Not set emails file#2)"); - } - - //pthread_mutex_unlock(&mutex_config_json); - - closesocket(cli_socket); - } -#if 0 - else if (strncmp(urlBuffer, "/settoffile", strlen("/settoffile")) == 0) - { - pthread_mutex_lock(&mutex_tof_json); - - int check_if_setfile_OK = 0; - - int file_buff_size = nTotalContentLen; - if (file_buff_size >= 1) - { - char* file_Content = recvBuffer + recv_buff_size; - - //printf("\n------file_buff_size:%d\n", file_buff_size); - //printf("\n------file_Content:%s\n", file_Content); - - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char tof_importPATH[1024]; - strcpy(tof_importPATH, exePath); - strcat(tof_importPATH, "tof_import.json"); - - char tof_PATH[1024]; - strcpy(tof_PATH, exePath); - strcat(tof_PATH, "tof.json"); - - char tof_bakPATH[1024]; - strcpy(tof_bakPATH, exePath); - strcat(tof_bakPATH, "tof_bak.json"); - - FILE *pFile; - - if ((pFile = fopen(tof_importPATH, "w+")) != NULL) - { - fprintf(pFile, "%s", file_Content); - fclose(pFile); - - char* fileBuf = ReadAllBytes(tof_importPATH); - char* fileBuf2 = ReadAllBytes(tof_PATH); - - if (fileBuf && fileBuf2) { - - cJSON *root = cJSON_Parse(fileBuf); - cJSON *s_root = cJSON_Parse(fileBuf2); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (fileBuf2) { - free(fileBuf2); - fileBuf2 = NULL; - } - - if (root && s_root) - { - cJSON *tof_version, *tof_debug, *tof_install_angle, *tof_enable_camera, *enable_tof_ground, *enable_tof_wall, *tof_camera; - cJSON *tof_camera_ip, *tof_camera_port, *tof_camera_sub_url, *tof_auth_key, *tof_ip_setting, *tof_camera_username, *tof_camera_password; - cJSON *distance_options, *distance_threshold, *height_options, *height_threshold, *distance_min_max, *height_min_max; - cJSON *ground_x, *ground_y; - - cJSON *s_tof_camera; - - tof_version = cJSON_GetObjectItem(root, "version"); - tof_debug = cJSON_GetObjectItem(root, "debug"); - tof_install_angle = cJSON_GetObjectItem(root, "install_angle"); - tof_enable_camera = cJSON_GetObjectItem(root, "enable_camera"); - enable_tof_ground = cJSON_GetObjectItem(root, "enable_tof_ground"); - enable_tof_wall = cJSON_GetObjectItem(root, "enable_tof_wall"); - distance_options = cJSON_GetObjectItem(root, "distance_options"); - distance_threshold = cJSON_GetObjectItem(root, "distance_threshold"); - height_options = cJSON_GetObjectItem(root, "height_options"); - height_threshold = cJSON_GetObjectItem(root, "height_threshold"); - distance_min_max = cJSON_GetObjectItem(root, "distance_min_max"); - height_min_max = cJSON_GetObjectItem(root, "height_min_max"); - - ground_x = cJSON_GetObjectItem(root, "ground_x"); - ground_y = cJSON_GetObjectItem(root, "ground_y"); - - tof_camera = cJSON_GetObjectItem(root, "camera"); - s_tof_camera = cJSON_GetObjectItem(s_root, "camera"); - - if (tof_version) - { - tofData.tof_version = tof_version->valueint; - cJSON_ReplaceItemInObject(s_root, "version", cJSON_CreateNumber(tofData.tof_version)); - } - - if (tof_debug) - { - if (cJSON_IsTrue(tof_debug)) - { - tofData.tof_debug = true; - } - else - { - tofData.tof_debug = false; - } - cJSON_ReplaceItemInObject(s_root, "debug", cJSON_CreateBool(tofData.tof_debug)); - } - - if (tof_install_angle) { - tofData.tof_install_angle = tof_install_angle->valueint; - cJSON_ReplaceItemInObject(s_root, "install_angle", cJSON_CreateNumber(tofData.tof_install_angle)); - } - - if (tof_enable_camera) { - if (cJSON_IsTrue(tof_enable_camera)) - { - tofData.tof_enable_camera = true; - } - else - { - tofData.tof_enable_camera = false; - } - cJSON_ReplaceItemInObject(s_root, "enable_camera", cJSON_CreateBool(tofData.tof_enable_camera)); - } - - if (enable_tof_ground) { - if (cJSON_IsTrue(enable_tof_ground)) - { - tofData.enable_tof_ground = true; - } - else - { - tofData.enable_tof_ground = false; - } - cJSON_ReplaceItemInObject(s_root, "enable_tof_ground", cJSON_CreateBool(tofData.enable_tof_ground)); - } - - if (enable_tof_wall) { - if (cJSON_IsTrue(enable_tof_wall)) - { - tofData.enable_tof_wall = true; - } - else - { - tofData.enable_tof_wall = false; - } - cJSON_ReplaceItemInObject(s_root, "enable_tof_wall", cJSON_CreateBool(tofData.enable_tof_wall)); - } - - if (distance_options) - { - strcpy(tofData.distance_options, distance_options->valuestring); - cJSON_ReplaceItemInObject(s_root, "distance_options", cJSON_CreateString(tofData.distance_options)); - } - - if (distance_min_max) { - strcpy(tofData.distance_min_max, distance_min_max->valuestring); - cJSON_ReplaceItemInObject(s_root, "distance_min_max", cJSON_CreateString(tofData.distance_min_max)); - } - - if (distance_threshold) { - strcpy(tofData.distance_threshold, distance_threshold->valuestring); - cJSON_ReplaceItemInObject(s_root, "distance_threshold", cJSON_CreateString(tofData.distance_threshold)); - } - - if (height_options) { - strcpy(tofData.height_options, height_options->valuestring); - cJSON_ReplaceItemInObject(s_root, "height_options", cJSON_CreateString(tofData.height_options)); - } - - if (height_min_max) { - strcpy(tofData.height_min_max, height_min_max->valuestring); - cJSON_ReplaceItemInObject(s_root, "height_min_max", cJSON_CreateString(tofData.height_min_max)); - } - - - if (ground_x) { - strcpy(tofData.ground_x, ground_x->valuestring); - cJSON_ReplaceItemInObject(s_root, "ground_x", cJSON_CreateString(tofData.ground_x)); - } - - if (ground_y) { - strcpy(tofData.ground_y, ground_y->valuestring); - cJSON_ReplaceItemInObject(s_root, "ground_y", cJSON_CreateString(tofData.ground_y)); - } - - if (ground_x || ground_y) { - if (tofData.enable_tof_ground) { - int pixelX = atoi(tofData.ground_x); - int pixelY = atoi(tofData.ground_y); -#ifdef GY_OS_AMBA - g_ground_tof_range = (float)getDepth(pixelX, pixelY); -#else - g_ground_tof_range = getToFDepthByPixel(pixelX, pixelY); -#endif - int y_diff = 240 - pixelY; - double angle_diff = 0.0; - if (y_diff != 0) - { - angle_diff = 23.6 * ((double)y_diff / 240.0); - } - g_ground_tof_degree = (float)(((double)tofData.tof_install_angle) - angle_diff); - g_ground_tof_height = (float)(sin(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); - g_ground_tof_distance = (float)(cos(g_ground_tof_degree * (double)(PI / 180)) * g_ground_tof_range); - g_tof_device_height = g_ground_tof_height; - } - } - - if (height_threshold) { - strcpy(tofData.height_threshold, height_threshold->valuestring); - cJSON_ReplaceItemInObject(s_root, "height_threshold", cJSON_CreateString(tofData.height_threshold)); - } - - if (tof_camera) { - tof_camera_ip = cJSON_GetObjectItem(tof_camera, "camera_ip"); - tof_camera_port = cJSON_GetObjectItem(tof_camera, "camera_port"); - tof_camera_sub_url = cJSON_GetObjectItem(tof_camera, "camera_sub_url"); - tof_auth_key = cJSON_GetObjectItem(tof_camera, "auth_key"); - tof_ip_setting = cJSON_GetObjectItem(tof_camera, "ip_setting"); - tof_camera_username = cJSON_GetObjectItem(tof_camera, "camera_username"); - tof_camera_password = cJSON_GetObjectItem(tof_camera, "camera_password"); - - if (tof_camera_ip) { - strcpy(tofData.tof_camera_ip, tof_camera_ip->valuestring); - cJSON_ReplaceItemInObject(s_tof_camera, "camera_ip", cJSON_CreateString(tofData.tof_camera_ip)); - } - - if (tof_camera_port) { - strcpy(tofData.tof_camera_port, tof_camera_port->valuestring); - cJSON_ReplaceItemInObject(s_tof_camera, "camera_port", cJSON_CreateString(tofData.tof_camera_port)); - } - - if (tof_camera_sub_url) { - strcpy(tofData.tof_camera_sub_url, tof_camera_sub_url->valuestring); - cJSON_ReplaceItemInObject(s_tof_camera, "camera_sub_url", cJSON_CreateString(tofData.tof_camera_sub_url)); - } - - if (tof_auth_key) { - strcpy(tofData.tof_auth_key, tof_auth_key->valuestring); - cJSON_ReplaceItemInObject(s_tof_camera, "auth_key", cJSON_CreateString(tofData.tof_auth_key)); - } - - if (tof_ip_setting) { - if (cJSON_IsTrue(tof_ip_setting)) - { - tofData.tof_ip_setting = true; - } - else - { - tofData.tof_ip_setting = false; - } - cJSON_ReplaceItemInObject(s_tof_camera, "ip_setting", cJSON_CreateBool(tofData.tof_ip_setting)); - } - - if (tof_camera_username) { - char temp_account[512] = { 0 }; - urlencode((unsigned char *)tof_camera_username->valuestring, strlen(tof_camera_username->valuestring), (unsigned char *)temp_account, 512); - memcpy(tofData.tof_camera_username, temp_account, strlen(temp_account)); - tofData.tof_camera_username[strlen(temp_account)] = '\0'; - - cJSON_ReplaceItemInObject(s_tof_camera, "camera_username", cJSON_CreateString(tof_camera_username->valuestring)); - } - - if (tof_camera_password) { - char temp_account[512] = { 0 }; - urlencode((unsigned char *)tof_camera_password->valuestring, strlen(tof_camera_password->valuestring), (unsigned char *)temp_account, 512); - memcpy(tofData.tof_camera_password, temp_account, strlen(temp_account)); - tofData.tof_camera_password[strlen(temp_account)] = '\0'; - - cJSON_ReplaceItemInObject(s_tof_camera, "camera_password", cJSON_CreateString(tof_camera_password->valuestring)); - } - } - - - char* JsonString = cJSON_Print(s_root); - - FILE *f = fopen(tof_PATH, "w"); - if (f != NULL) - { - - fprintf(f, "%s\n", JsonString); - fclose(f); - - CopyFileTo(tof_PATH, tof_bakPATH); - - check_if_setfile_OK = 1; - //g_count_alter = 50; - } - - if (JsonString) { - free(JsonString); - JsonString = NULL; - } - - } - - if (root) { - cJSON_Delete(root); - root = NULL; - } - if (s_root) { - cJSON_Delete(s_root); - s_root = NULL; - } - } - else { - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (fileBuf2) { - free(fileBuf2); - fileBuf2 = NULL; - } - printf("\nFail to read tof_import.json or tof.json\n"); - } - } - } - - strcpy(beforeSendBuffer, ""); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - if (check_if_setfile_OK == 1) { - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend(Not settoffile)\n"); - } - else { - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend(Not settoffile#2)\n"); - } - - pthread_mutex_unlock(&mutex_tof_json); - closesocket(cli_socket); - } -#endif - else if (strncmp(urlBuffer, "/setconfigfile", strlen("/setconfigfile")) == 0) { - //printf("\n----------urlBuffer:%s\n", urlBuffer); - - pthread_mutex_lock(&mutex_config_json); - - int check_if_setfile_OK = 0; - - int file_buff_size = nTotalContentLen; - if (file_buff_size >= 1) - { - char* file_Content = recvBuffer+ recv_buff_size; - - //printf("\n------file_buff_size:%d\n", file_buff_size); - //printf("\n------file_Content:%s\n", file_Content); - - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char config_importPATH[1024]; - strcpy(config_importPATH, exePath); - strcat(config_importPATH, "config_import.json"); - - char config_PATH[1024]; -#ifdef GY_OS_NOVA - char config_smallPATH[1024]; -#endif - char config_bakPATH[1024]; - strcpy(config_PATH, exePath); -#ifdef GY_OS_NOVA - strcpy(config_smallPATH, exePath); -#endif - strcpy(config_bakPATH, exePath); - strcat(config_PATH, "config.json"); -#ifdef GY_OS_NOVA - strcat(config_smallPATH, "config_small.json"); -#endif - strcat(config_bakPATH, "config_bak.json"); - - FILE *pFile; - - if ((pFile = fopen(config_importPATH, "w+")) != NULL) - { - fprintf(pFile, "%s", file_Content); - fclose(pFile); - - char* fileBuf = ReadAllBytes(config_importPATH); - char* fileBuf2 = ReadAllBytes(config_PATH); -#ifdef GY_OS_NOVA - char* fileBuf3 = ReadAllBytes(config_smallPATH); -#endif - -#ifdef GY_OS_NOVA - if (fileBuf && fileBuf2 && fileBuf3) { -#else - if (fileBuf && fileBuf2) { -#endif - - cJSON *root = cJSON_Parse(fileBuf); - cJSON *s_root = cJSON_Parse(fileBuf2); -#ifdef GY_OS_NOVA - cJSON *root_small = cJSON_Parse(fileBuf3); -#endif - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (fileBuf2) { - free(fileBuf2); - fileBuf2 = NULL; - } -#ifdef GY_OS_NOVA - if (fileBuf3) { - free(fileBuf3); - fileBuf3 = NULL; - } -#endif - -#ifdef GY_OS_NOVA - if (root && s_root && root_small) -#else - if (root && s_root) -#endif - { - cJSON *view_setting,*camera,*camera_name,*levenshtein_distance,*min_characters,*max_characters,*obj_min_proportion,*obj_max_proportion, - *confidence,*confidence2,*confidence3, *confidence4,*count_zone,*enable_lpr_db,*enable_downsized_cropped_roi,*enable_zone_crop_1, *enable_add_face_frequent_list, // joy add - *enable_track,*enable_PTZ,*ptz_tracking_fov_min,*ptz_tracking_fov_max,*ptz_enable_tracking,*ptz_tracking_mode,*ptz_tracking_by_enter_zone, - *enable_tracking_limits,*ptz_pan_left_limit,*ptz_pan_right_limit,*ptz_tilt_up_limit,*ptz_tilt_down_limit,*ptz_speed, - *enable_unknown_object, *ivs_mode, *enable_ivs_person_detection, *assign_ivs_object_to, *enable_show_unknown_object, *enable_ivs_fix_mode, *enable_ivs_and_ai,*enable_lpr_upon_triggered, *dwell_lpr_upon_triggered,*unknown_object_max_proportion,*unknown_object_min_proportion, *confidence_unknown_object, *confidence2_unknown_object,*enable_ambulance, *enable_blank_plate, *enable_stop_sign, - *dwell_unknown_object,*dwell_minute_focus_on, *person_obj_fov,*ptz_sensitivity,*ptz_tracking_resume_dwell,*cJSON_enable_only_show_metadata1,*getnetwork_buffer_id, - *tab_view_size,*enable_anpr,*enable_face,*enable_traffic,*enable_logo, - *temp_detection_zone,*detect,*enable_traffic_light,*detection_time,*metadata1,*metadata2, *metadata_stop,*link_to_counter,*enable_direction1, - *enable_direction2, *direction1,*direction2,*no_parking_time,*no_parking_time_in_minute,*queuing_count,*ptz_zone_to_preset,*enable_speed,*enable_radar_speed, *enable_ivs_zone, - *set_distance,*world_distance_unit,*world_distance_side1, *world_distance_side2,*world_time_unit,*parking_space, *parking_line, - *point_number,*x1,*y1,*x2,*y2,*x3,*y3, *x4, *y4, *x5, *y5, *x6, *y6, - *plate_filter_times, *plate_filter_time, *plate_free_time, *obj_max_proportion_in_zone, *obj_min_proportion_in_zone, *red_light_zone, *no_give_way_zone_to_protect, *no_give_way_zone_to_keep_away, *no_give_way_zone_to_protect_2, *no_give_way_zone_to_keep_away_2; - cJSON *trigger_events_0, *trigger_events_1, *trigger_events_2,*trigger_events_3, *trigger_events_4, *trigger_events_5, *trigger_events_6, *trigger_events_7,*checked,*detect_event_name,*post_event_name, - *counter_name/*,*counter_cust_name*/,*counter_increment; - cJSON *s_view_setting, *s_camera, *s_detection_zone, *s_detect,*s_trigger_events_0, *s_trigger_events_1, *s_trigger_events_2, *s_trigger_events_3, *s_trigger_events_4, *s_trigger_events_5, *s_trigger_events_6, *s_trigger_events_7; - - cJSON *trigger_events_temp, *s_trigger_events_temp; -#ifdef GY_OS_NOVA - cJSON *view_setting_small, *system_setting_small, *camera_small/*, *count_zone_small*/, *detection_zone_small, *detect_small/*, *point_number_small*/, - *x1_small, *y1_small, *x2_small, *y2_small, *x3_small, *y3_small, *x4_small, *y4_small, *x5_small, *y5_small, *x6_small, *y6_small; -#endif - view_setting = cJSON_GetObjectItem(root, "view_setting"); - s_view_setting = cJSON_GetObjectItem(s_root, "view_setting"); -#ifdef GY_OS_NOVA - view_setting_small = cJSON_GetObjectItem(root_small, "view_setting"); -#endif - if (view_setting) { - for (int n = 0; n < MAX_AI_ENGINE_VIEW; n++) - { - char CameraID[20] = { 0 }; - sprintf(CameraID, "camera%02d", n + 1); - camera = cJSON_GetObjectItem(view_setting, CameraID); - s_camera = cJSON_GetObjectItem(s_view_setting, CameraID); -#ifdef GY_OS_NOVA - camera_small = cJSON_GetObjectItem(view_setting_small, CameraID); -#endif - if (camera) { - camera_name = cJSON_GetObjectItem(camera, "camera_name"); - levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); - min_characters = cJSON_GetObjectItem(camera, "min_characters"); - max_characters = cJSON_GetObjectItem(camera, "max_characters"); - obj_min_proportion = cJSON_GetObjectItem(camera, "obj_min_proportion"); - obj_max_proportion = cJSON_GetObjectItem(camera, "obj_max_proportion"); - plate_filter_times = cJSON_GetObjectItem(camera, "PlateFilterTimes"); - plate_filter_time = cJSON_GetObjectItem(camera, "PlateFilterTime"); - plate_free_time = cJSON_GetObjectItem(camera, "PlateRecorderFreeTime"); - confidence = cJSON_GetObjectItem(camera, "confidence"); //Plate 車牌 - confidence2 = cJSON_GetObjectItem(camera, "confidence2"); //Traffic 交通 - confidence3 = cJSON_GetObjectItem(camera, "confidence3"); - confidence4 = cJSON_GetObjectItem(camera, "confidence4"); - count_zone = cJSON_GetObjectItem(camera, "count_zone"); - enable_lpr_db = cJSON_GetObjectItem(camera, "enable_lpr_db"); - enable_downsized_cropped_roi = cJSON_GetObjectItem(camera, "enable_downsized_cropped_roi"); - enable_add_face_frequent_list = cJSON_GetObjectItem(camera, "enable_add_face_frequent_list"); - enable_zone_crop_1 = cJSON_GetObjectItem(camera, "enable_zone_crop_1"); - enable_PTZ = cJSON_GetObjectItem(camera, "enable_PTZ"); - enable_track = cJSON_GetObjectItem(camera, "enable_track"); - ptz_tracking_fov_min = cJSON_GetObjectItem(camera, "ptz_tracking_fov_min"); - ptz_tracking_fov_max = cJSON_GetObjectItem(camera, "ptz_tracking_fov_max"); - ptz_enable_tracking = cJSON_GetObjectItem(camera, "ptz_enable_tracking"); - ptz_tracking_mode = cJSON_GetObjectItem(camera, "ptz_tracking_mode"); - ptz_tracking_by_enter_zone = cJSON_GetObjectItem(camera, "ptz_tracking_by_enter_zone"); - enable_tracking_limits = cJSON_GetObjectItem(camera, "enable_tracking_limits"); - ptz_pan_left_limit = cJSON_GetObjectItem(camera, "ptz_pan_left_limit"); - ptz_pan_right_limit = cJSON_GetObjectItem(camera, "ptz_pan_right_limit"); - ptz_tilt_up_limit = cJSON_GetObjectItem(camera, "ptz_tilt_up_limit"); - ptz_tilt_down_limit = cJSON_GetObjectItem(camera, "ptz_tilt_down_limit"); - ptz_speed = cJSON_GetObjectItem(camera, "ptz_speed"); - enable_unknown_object = cJSON_GetObjectItem(camera, "enable_unknown_object"); - enable_ivs_person_detection = cJSON_GetObjectItem(camera, "enable_ivs_person_detection"); - assign_ivs_object_to = cJSON_GetObjectItem(camera, "assign_ivs_object_to"); - enable_ambulance = cJSON_GetObjectItem(camera, "enable_ambulance"); - enable_blank_plate = cJSON_GetObjectItem(camera, "enable_blank_plate"); - enable_stop_sign = cJSON_GetObjectItem(camera, "enable_stop_sign"); - enable_show_unknown_object = cJSON_GetObjectItem(camera, "enable_show_unknown_object"); - enable_ivs_fix_mode = cJSON_GetObjectItem(camera, "enable_ivs_fix_mode"); - enable_ivs_and_ai = cJSON_GetObjectItem(camera, "enable_ivs_and_ai"); - enable_lpr_upon_triggered = cJSON_GetObjectItem(camera, "enable_lpr_upon_triggered"); - dwell_lpr_upon_triggered = cJSON_GetObjectItem(camera, "dwell_lpr_upon_triggered"); - unknown_object_max_proportion = cJSON_GetObjectItem(camera, "unknown_object_max_proportion"); - unknown_object_min_proportion = cJSON_GetObjectItem(camera, "unknown_object_min_proportion"); - confidence_unknown_object = cJSON_GetObjectItem(camera, "confidence_unknown_object"); - confidence2_unknown_object = cJSON_GetObjectItem(camera, "confidence2_unknown_object"); - dwell_unknown_object = cJSON_GetObjectItem(camera, "dwell_unknown_object"); - dwell_minute_focus_on = cJSON_GetObjectItem(camera, "dwell_minute_focus_on"); - person_obj_fov = cJSON_GetObjectItem(camera, "person_obj_fov"); - getnetwork_buffer_id = cJSON_GetObjectItem(camera, "getnetwork_buffer_id"); - red_light_zone = cJSON_GetObjectItem(camera, "red_light_zone"); - no_give_way_zone_to_protect = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect"); - no_give_way_zone_to_keep_away = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away"); - no_give_way_zone_to_protect_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_protect_2"); - no_give_way_zone_to_keep_away_2 = cJSON_GetObjectItem(camera, "no_give_way_zone_to_keep_away_2"); - ptz_sensitivity = cJSON_GetObjectItem(camera, "ptz_sensitivity"); - ptz_tracking_resume_dwell = cJSON_GetObjectItem(camera, "ptz_tracking_resume_dwell"); - cJSON_enable_only_show_metadata1 = cJSON_GetObjectItem(camera, "enable_only_show_metadata1"); - tab_view_size = cJSON_GetObjectItem(camera, "tab_view_size"); - enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); - enable_face = cJSON_GetObjectItem(camera, "enable_face"); - enable_traffic = cJSON_GetObjectItem(camera, "enable_traffic"); - enable_logo = cJSON_GetObjectItem(camera, "enable_logo"); - - ivs_mode = cJSON_GetObjectItem(camera, "ivs_mode"); - - temp_detection_zone = cJSON_GetObjectItem(camera, "detection_zone"); - s_detection_zone = cJSON_GetObjectItem(s_camera, "detection_zone"); -#ifdef GY_OS_NOVA - detection_zone_small = cJSON_GetObjectItem(camera_small, "detection_zone"); -#endif - } - - if (camera_name) { - strcpy(viewChannelData[n].camera_name, camera_name->valuestring); - cJSON_ReplaceItemInObject(s_camera, "camera_name", cJSON_CreateString(viewChannelData[n].camera_name)); - } - if (levenshtein_distance) { - strcpy(viewChannelData[n].levenshtein_distance, levenshtein_distance->valuestring); - cJSON_ReplaceItemInObject(s_camera, "levenshtein_distance", cJSON_CreateString(viewChannelData[n].levenshtein_distance)); - } - if (min_characters) { - strcpy(viewChannelData[n].min_characters, min_characters->valuestring); - cJSON_ReplaceItemInObject(s_camera, "min_characters", cJSON_CreateString(viewChannelData[n].min_characters)); - } - if (max_characters) { - strcpy(viewChannelData[n].max_characters, max_characters->valuestring); - cJSON_ReplaceItemInObject(s_camera, "max_characters", cJSON_CreateString(viewChannelData[n].max_characters)); - } - if (obj_min_proportion) { - strcpy(viewChannelData[n].obj_min_proportion, obj_min_proportion->valuestring); - cJSON_ReplaceItemInObject(s_camera, "obj_min_proportion", cJSON_CreateString(viewChannelData[n].obj_min_proportion)); - } - if (obj_max_proportion) { - strcpy(viewChannelData[n].obj_max_proportion, obj_max_proportion->valuestring); - cJSON_ReplaceItemInObject(s_camera, "obj_max_proportion", cJSON_CreateString(viewChannelData[n].obj_max_proportion)); - } - - if (plate_filter_times) { - viewChannelData[n].i_plate_filter_times = atoi(plate_filter_times->valuestring); - cJSON_ReplaceItemInObject(s_camera, "PlateFilterTimes", cJSON_CreateString(plate_filter_times->valuestring)); - } - - if (plate_filter_time) { - viewChannelData[n].i_plate_filter_time = atoi(plate_filter_time->valuestring); - cJSON_ReplaceItemInObject(s_camera, "PlateFilterTime", cJSON_CreateString(plate_filter_time->valuestring)); - } - - if (plate_free_time) { - viewChannelData[n].i_plate_free_time = atoi(plate_free_time->valuestring); - cJSON_ReplaceItemInObject(s_camera, "PlateRecorderFreeTime", cJSON_CreateString(plate_free_time->valuestring)); - } - - if (confidence) { - strcpy(viewChannelData[n].confidence, confidence->valuestring); - cJSON_ReplaceItemInObject(s_camera, "confidence", cJSON_CreateString(viewChannelData[n].confidence)); - } - if (confidence2) { - strcpy(viewChannelData[n].confidence2, confidence2->valuestring); - cJSON_ReplaceItemInObject(s_camera, "confidence2", cJSON_CreateString(viewChannelData[n].confidence2)); - } - if (confidence3) { - strcpy(viewChannelData[n].confidence3, confidence3->valuestring); - cJSON_ReplaceItemInObject(s_camera, "confidence3", cJSON_CreateString(viewChannelData[n].confidence3)); - } - if (confidence4) { - strcpy(viewChannelData[n].confidence4, confidence4->valuestring); - cJSON_ReplaceItemInObject(s_camera, "confidence4", cJSON_CreateString(viewChannelData[n].confidence4)); - } - if (count_zone) { - viewChannelData[n].count_zone = count_zone->valueint; - cJSON_ReplaceItemInObject(s_camera, "count_zone", cJSON_CreateNumber(viewChannelData[n].count_zone)); -#ifdef GY_OS_NOVA - cJSON_ReplaceItemInObject(camera_small, "count_zone", cJSON_CreateNumber(viewChannelData[n].count_zone)); -#endif - } - if (enable_lpr_db) { - pthread_mutex_lock(&mutex_enable_lpr_db); - strcpy(viewChannelData[n].enable_lpr_db, enable_lpr_db->valuestring); - cJSON_ReplaceItemInObject(s_camera, "enable_lpr_db", cJSON_CreateString(viewChannelData[n].enable_lpr_db)); - pthread_mutex_unlock(&mutex_enable_lpr_db); - } - if (enable_add_face_frequent_list) { - if (strcmp(enable_add_face_frequent_list->valuestring, "Yes") == 0) - viewChannelData[n].enable_add_face_frequent_list = 1; - else - viewChannelData[n].enable_add_face_frequent_list = 0; - cJSON_ReplaceItemInObject(s_camera, "enable_add_face_frequent_list", cJSON_CreateString(enable_add_face_frequent_list->valuestring)); - } - if (enable_downsized_cropped_roi) { - set_enable_downsized_cropped_roi(enable_downsized_cropped_roi->valueint); - cJSON_ReplaceItemInObject(s_camera, "enable_downsized_cropped_roi", cJSON_CreateNumber(enable_downsized_cropped_roi->valueint)); - } - if (enable_zone_crop_1) { - set_enable_zone_crop_1(enable_zone_crop_1->valueint); - cJSON_ReplaceItemInObject(s_camera, "enable_zone_crop_1", cJSON_CreateNumber(enable_zone_crop_1->valueint)); - } - if (enable_PTZ) { - strcpy(viewChannelData[n].enable_PTZ, enable_PTZ->valuestring); - cJSON_ReplaceItemInObject(s_camera, "enable_PTZ", cJSON_CreateString(viewChannelData[n].enable_PTZ)); - } - if (enable_track) { - strcpy(viewChannelData[n].enable_track, enable_track->valuestring); - cJSON_ReplaceItemInObject(s_camera, "enable_track", cJSON_CreateString(viewChannelData[n].enable_track)); - } - if (ptz_tracking_fov_min) { - strcpy(viewChannelData[n].ptz_tracking_fov_min, ptz_tracking_fov_min->valuestring); - cJSON_ReplaceItemInObject(s_camera, "ptz_tracking_fov_min", cJSON_CreateString(viewChannelData[n].ptz_tracking_fov_min)); - } - if (ptz_tracking_fov_max) { - strcpy(viewChannelData[n].ptz_tracking_fov_max, ptz_tracking_fov_max->valuestring); - cJSON_ReplaceItemInObject(s_camera, "ptz_tracking_fov_max", cJSON_CreateString(viewChannelData[n].ptz_tracking_fov_max)); - } - if (ptz_enable_tracking) { - strcpy(viewChannelData[n].ptz_enable_tracking, ptz_enable_tracking->valuestring); - cJSON_ReplaceItemInObject(s_camera, "ptz_enable_tracking", cJSON_CreateString(viewChannelData[n].ptz_enable_tracking)); - } - if (ptz_tracking_mode) { - viewChannelData[n].ptz_tracking_mode = atoi(ptz_tracking_mode->valuestring); - cJSON_ReplaceItemInObject(s_camera, "ptz_tracking_mode", cJSON_CreateString(ptz_tracking_mode->valuestring)); - } - if (ptz_tracking_by_enter_zone) { - if (strcmp(ptz_tracking_by_enter_zone->valuestring, "Yes") == 0) - viewChannelData[n].ptz_tracking_by_enter_zone = 1; - else - viewChannelData[n].ptz_tracking_by_enter_zone = 0; - cJSON_ReplaceItemInObject(s_camera, "ptz_tracking_by_enter_zone", cJSON_CreateString(ptz_tracking_by_enter_zone->valuestring)); - } - - if (enable_tracking_limits) { - strcpy(viewChannelData[n].enable_tracking_limits, enable_tracking_limits->valuestring); - cJSON_ReplaceItemInObject(s_camera, "enable_tracking_limits", cJSON_CreateString(viewChannelData[n].enable_tracking_limits)); - } - - if (ptz_pan_left_limit) { - strcpy(viewChannelData[n].ptz_pan_left_limit, ptz_pan_left_limit->valuestring); - cJSON_ReplaceItemInObject(s_camera, "ptz_pan_left_limit", cJSON_CreateString(viewChannelData[n].ptz_pan_left_limit)); - } - - if (ptz_pan_right_limit) { - strcpy(viewChannelData[n].ptz_pan_right_limit, ptz_pan_right_limit->valuestring); - cJSON_ReplaceItemInObject(s_camera, "ptz_pan_right_limit", cJSON_CreateString(viewChannelData[n].ptz_pan_right_limit)); - } - - if (ptz_tilt_up_limit) { - strcpy(viewChannelData[n].ptz_tilt_up_limit, ptz_tilt_up_limit->valuestring); - cJSON_ReplaceItemInObject(s_camera, "ptz_tilt_up_limit", cJSON_CreateString(viewChannelData[n].ptz_tilt_up_limit)); - } - - if (ptz_tilt_down_limit) { - strcpy(viewChannelData[n].ptz_tilt_down_limit, ptz_tilt_down_limit->valuestring); - cJSON_ReplaceItemInObject(s_camera, "ptz_tilt_down_limit", cJSON_CreateString(viewChannelData[n].ptz_tilt_down_limit)); - } - - if (ptz_speed) { - strcpy(viewChannelData[n].ptz_speed, ptz_speed->valuestring); - cJSON_ReplaceItemInObject(s_camera, "ptz_speed", cJSON_CreateString(viewChannelData[n].ptz_speed)); - } - - if (enable_unknown_object) { - strcpy(viewChannelData[n].enable_unknown_object, enable_unknown_object->valuestring); - cJSON_ReplaceItemInObject(s_camera, "enable_unknown_object", cJSON_CreateString(viewChannelData[n].enable_unknown_object)); - -#ifdef GY_OS_NOVA - cJSON_ReplaceItemInObject(camera_small, "enable_unknown_object", cJSON_CreateString(viewChannelData[n].enable_unknown_object)); -#endif - } - - if (enable_ivs_person_detection) { - strcpy(viewChannelData[n].enable_ivs_person_detection, enable_ivs_person_detection->valuestring); - cJSON_ReplaceItemInObject(s_camera, "enable_ivs_person_detection", cJSON_CreateString(viewChannelData[n].enable_ivs_person_detection)); -#ifdef GY_OS_NOVA - cJSON_ReplaceItemInObject(camera_small, "enable_ivs_person_detection", cJSON_CreateString(viewChannelData[n].enable_ivs_person_detection)); -#endif - } - - if (assign_ivs_object_to) { - strcpy(viewChannelData[n].assign_ivs_object_to, assign_ivs_object_to->valuestring); - cJSON_ReplaceItemInObject(s_camera, "assign_ivs_object_to", cJSON_CreateString(viewChannelData[n].assign_ivs_object_to)); -#ifdef GY_OS_NOVA - cJSON_ReplaceItemInObject(camera_small, "assign_ivs_object_to", cJSON_CreateString(viewChannelData[n].assign_ivs_object_to)); -#endif - } - - if (enable_ambulance) { - strcpy(viewChannelData[n].enable_ambulance, enable_ambulance->valuestring); - cJSON_ReplaceItemInObject(s_camera, "enable_ambulance", cJSON_CreateString(viewChannelData[n].enable_ambulance)); - } - if (enable_blank_plate) { - strcpy(viewChannelData[n].enable_blank_plate, enable_blank_plate->valuestring); - cJSON_ReplaceItemInObject(s_camera, "enable_blank_plate", cJSON_CreateString(viewChannelData[n].enable_blank_plate)); - } - if (enable_stop_sign) { - strcpy(viewChannelData[n].enable_stop_sign, enable_stop_sign->valuestring); - cJSON_ReplaceItemInObject(s_camera, "enable_stop_sign", cJSON_CreateString(viewChannelData[n].enable_stop_sign)); - } - if (enable_show_unknown_object) { - strcpy(viewChannelData[n].enable_show_unknown_object, enable_show_unknown_object->valuestring); - cJSON_ReplaceItemInObject(s_camera, "enable_show_unknown_object", cJSON_CreateString(viewChannelData[n].enable_show_unknown_object)); -#ifdef GY_OS_NOVA - cJSON_ReplaceItemInObject(camera_small, "enable_show_unknown_object", cJSON_CreateString(viewChannelData[n].enable_show_unknown_object)); -#endif - } - - if (enable_ivs_fix_mode) { - strcpy(viewChannelData[n].enable_ivs_fix_mode, enable_ivs_fix_mode->valuestring); - cJSON_ReplaceItemInObject(s_camera, "enable_ivs_fix_mode", cJSON_CreateString(viewChannelData[n].enable_ivs_fix_mode)); - } - - if (enable_ivs_and_ai) { - strcpy(viewChannelData[n].enable_ivs_and_ai, enable_ivs_and_ai->valuestring); - cJSON_ReplaceItemInObject(s_camera, "enable_ivs_and_ai", cJSON_CreateString(viewChannelData[n].enable_ivs_and_ai)); - } - - if (enable_lpr_upon_triggered) { - strcpy(viewChannelData[n].enable_lpr_upon_triggered, enable_lpr_upon_triggered->valuestring); - cJSON_ReplaceItemInObject(s_camera, "enable_lpr_upon_triggered", cJSON_CreateString(viewChannelData[n].enable_lpr_upon_triggered)); - } - if (dwell_lpr_upon_triggered) { - strcpy(viewChannelData[n].dwell_lpr_upon_triggered, dwell_lpr_upon_triggered->valuestring); - cJSON_ReplaceItemInObject(s_camera, "dwell_lpr_upon_triggered", cJSON_CreateString(viewChannelData[n].dwell_lpr_upon_triggered)); - } - if (unknown_object_max_proportion) { - strcpy(viewChannelData[n].unknown_object_max_proportion, unknown_object_max_proportion->valuestring); - cJSON_ReplaceItemInObject(s_camera, "unknown_object_max_proportion", cJSON_CreateString(viewChannelData[n].unknown_object_max_proportion)); -#ifdef GY_OS_NOVA - cJSON_ReplaceItemInObject(camera_small, "unknown_object_max_proportion", cJSON_CreateString(viewChannelData[n].unknown_object_max_proportion)); -#endif - } - if (unknown_object_min_proportion) { - strcpy(viewChannelData[n].unknown_object_min_proportion, unknown_object_min_proportion->valuestring); - cJSON_ReplaceItemInObject(s_camera, "unknown_object_min_proportion", cJSON_CreateString(viewChannelData[n].unknown_object_min_proportion)); -#ifdef GY_OS_NOVA - cJSON_ReplaceItemInObject(camera_small, "unknown_object_min_proportion", cJSON_CreateString(viewChannelData[n].unknown_object_min_proportion)); -#endif - } - if (confidence_unknown_object) { - strcpy(viewChannelData[n].confidence_unknown_object, confidence_unknown_object->valuestring); - cJSON_ReplaceItemInObject(s_camera, "confidence_unknown_object", cJSON_CreateString(viewChannelData[n].confidence_unknown_object)); -#ifdef GY_OS_NOVA - cJSON_ReplaceItemInObject(camera_small, "confidence_unknown_object", cJSON_CreateString(viewChannelData[n].confidence_unknown_object)); -#endif - } - if (confidence2_unknown_object) { - strcpy(viewChannelData[n].confidence2_unknown_object, confidence2_unknown_object->valuestring); - cJSON_ReplaceItemInObject(s_camera, "confidence2_unknown_object", cJSON_CreateString(viewChannelData[n].confidence2_unknown_object)); -#ifdef GY_OS_NOVA - cJSON_ReplaceItemInObject(camera_small, "confidence2_unknown_object", cJSON_CreateString(viewChannelData[n].confidence2_unknown_object)); -#endif - } - if (dwell_unknown_object) { - strcpy(viewChannelData[n].dwell_unknown_object, dwell_unknown_object->valuestring); - cJSON_ReplaceItemInObject(s_camera, "dwell_unknown_object", cJSON_CreateString(viewChannelData[n].dwell_unknown_object)); -#ifdef GY_OS_NOVA - cJSON_ReplaceItemInObject(camera_small, "dwell_unknown_object", cJSON_CreateString(viewChannelData[n].dwell_unknown_object)); -#endif - } - - if (dwell_minute_focus_on) { - strcpy(viewChannelData[n].dwell_minute_focus_on, dwell_minute_focus_on->valuestring); - cJSON_ReplaceItemInObject(s_camera, "dwell_minute_focus_on", cJSON_CreateString(viewChannelData[n].dwell_minute_focus_on)); -#ifdef GY_OS_NOVA - cJSON_ReplaceItemInObject(camera_small, "dwell_minute_focus_on", cJSON_CreateString(viewChannelData[n].dwell_minute_focus_on)); -#endif - } - - if (person_obj_fov) { - strcpy(viewChannelData[n].person_obj_fov, person_obj_fov->valuestring); - cJSON_ReplaceItemInObject(s_camera, "person_obj_fov", cJSON_CreateString(viewChannelData[n].person_obj_fov)); -#ifdef GY_OS_NOVA - cJSON_ReplaceItemInObject(camera_small, "person_obj_fov", cJSON_CreateString(viewChannelData[n].person_obj_fov)); -#endif - } - if (getnetwork_buffer_id) { - if (strcmp(viewChannelData[n].getnetwork_buffer_id, getnetwork_buffer_id->valuestring) != 0) - { - g_change_getnetwork_buffer_id = 1; - } - - strcpy(viewChannelData[n].getnetwork_buffer_id, getnetwork_buffer_id->valuestring); - cJSON_ReplaceItemInObject(s_camera, "getnetwork_buffer_id", cJSON_CreateString(viewChannelData[n].getnetwork_buffer_id)); - } - if (red_light_zone) { - strcpy(viewChannelData[n].red_light_zone, red_light_zone->valuestring); - cJSON_ReplaceItemInObject(s_camera, "red_light_zone", cJSON_CreateString(viewChannelData[n].red_light_zone)); - } - if (no_give_way_zone_to_protect) { - strcpy(viewChannelData[n].no_give_way_zone_to_protect, no_give_way_zone_to_protect->valuestring); - cJSON_ReplaceItemInObject(s_camera, "no_give_way_zone_to_protect", cJSON_CreateString(viewChannelData[n].no_give_way_zone_to_protect)); - } - if (no_give_way_zone_to_keep_away) { - strcpy(viewChannelData[n].no_give_way_zone_to_keep_away, no_give_way_zone_to_keep_away->valuestring); - cJSON_ReplaceItemInObject(s_camera, "no_give_way_zone_to_keep_away", cJSON_CreateString(viewChannelData[n].no_give_way_zone_to_keep_away)); - } - if (no_give_way_zone_to_protect_2) { - strcpy(viewChannelData[n].no_give_way_zone_to_protect_2, no_give_way_zone_to_protect_2->valuestring); - cJSON_ReplaceItemInObject(s_camera, "no_give_way_zone_to_protect_2", cJSON_CreateString(viewChannelData[n].no_give_way_zone_to_protect_2)); - } - if (no_give_way_zone_to_keep_away_2) { - strcpy(viewChannelData[n].no_give_way_zone_to_keep_away_2, no_give_way_zone_to_keep_away_2->valuestring); - cJSON_ReplaceItemInObject(s_camera, "no_give_way_zone_to_keep_away_2", cJSON_CreateString(viewChannelData[n].no_give_way_zone_to_keep_away_2)); - } - if (ptz_sensitivity) { - viewChannelData[n].ptz_sensitivity = atoi(ptz_sensitivity->valuestring); - cJSON_ReplaceItemInObject(s_camera, "ptz_sensitivity", cJSON_CreateString(ptz_sensitivity->valuestring)); - } - if (ptz_tracking_resume_dwell) { - strcpy(viewChannelData[n].ptz_tracking_resume_dwell, ptz_tracking_resume_dwell->valuestring); - cJSON_ReplaceItemInObject(s_camera, "ptz_tracking_resume_dwell", cJSON_CreateString(viewChannelData[n].ptz_tracking_resume_dwell)); - } - if (cJSON_enable_only_show_metadata1) { - enable_only_show_metadata1 = cJSON_enable_only_show_metadata1->valueint; - cJSON_ReplaceItemInObject(s_camera, "enable_only_show_metadata1", cJSON_CreateNumber(enable_only_show_metadata1)); - } - - if (ivs_mode) { - strcpy(viewChannelData[n].ivs_mode, ivs_mode->valuestring); - cJSON_ReplaceItemInObject(s_camera, "ivs_mode", cJSON_CreateString(viewChannelData[n].ivs_mode)); - } - - viewChannelData[n].channel_idx = n; - - if (tab_view_size) { - char temp_tab[50] = { 0 }; - strcpy(temp_tab, tab_view_size->valuestring); - char outArray[2][STRSPLIT_SIZE]={0}; - StrSplit(temp_tab, outArray, "x"); - //printf("\n------UU:35\n"); - if (strlen(outArray[0]) >= 1) - viewChannelData[n].tab_view_width = atoi(outArray[0]); - if (strlen(outArray[0]) >= 1) - viewChannelData[n].tab_view_height = atoi(outArray[1]); - if (strlen(outArray[0]) >= 1 && strlen(outArray[0]) >= 1) { - cJSON_ReplaceItemInObject(s_camera, "tab_view_size", cJSON_CreateString(tab_view_size->valuestring)); - } - } - if (enable_anpr) { - if (strcmp(enable_anpr->valuestring, "Yes") == 0) - viewChannelData[n].enable_anpr = 1; - else - viewChannelData[n].enable_anpr = 0; - cJSON_ReplaceItemInObject(s_camera, "enable_anpr", cJSON_CreateString(enable_anpr->valuestring)); -#ifdef GY_OS_NOVA - cJSON_ReplaceItemInObject(camera_small, "enable_anpr", cJSON_CreateString(enable_anpr->valuestring)); -#endif - } - if (enable_face) { - if (strcmp(enable_face->valuestring, "Yes") == 0) - viewChannelData[n].enable_face = 1; - else - viewChannelData[n].enable_face = 0; - cJSON_ReplaceItemInObject(s_camera, "enable_face", cJSON_CreateString(enable_face->valuestring)); - } - if (enable_traffic) { - if (strcmp(enable_traffic->valuestring, "Yes") == 0) - viewChannelData[n].enable_traffic = 1; - else - viewChannelData[n].enable_traffic = 0; - cJSON_ReplaceItemInObject(s_camera, "enable_traffic", cJSON_CreateString(enable_traffic->valuestring)); -#ifdef GY_OS_NOVA - cJSON_ReplaceItemInObject(camera_small, "enable_traffic", cJSON_CreateString(enable_traffic->valuestring)); -#endif - } - if (enable_logo) { - if (strcmp(enable_logo->valuestring, "Yes") == 0) - viewChannelData[n].enable_logo = 1; - else - viewChannelData[n].enable_logo = 0; - cJSON_ReplaceItemInObject(s_camera, "enable_logo", cJSON_CreateString(enable_logo->valuestring)); - } - - viewChannelData[n].enable_traffic_light_zone = 0; - if (temp_detection_zone && s_detection_zone) { - //printf("\nTTTTTTTTTTTTTTT: 1\n"); - { - int i = 0; - cJSON_ArrayForEach(detect, temp_detection_zone) - { - if (detect) - { - int j = 0; - cJSON_ArrayForEach(s_detect, s_detection_zone) - { - if (i == j) - { - - enable_traffic_light = cJSON_GetObjectItem(detect, "enable_traffic_light"); - detection_time = cJSON_GetObjectItem(detect, "detection_time"); - metadata1 = cJSON_GetObjectItem(detect, "metadata1"); - metadata2 = cJSON_GetObjectItem(detect, "metadata2"); - metadata_stop = cJSON_GetObjectItem(detect, "metadata_stop"); - link_to_counter = cJSON_GetObjectItem(detect, "link_to_counter"); - enable_direction1 = cJSON_GetObjectItem(detect, "enable_direction1"); - enable_direction2 = cJSON_GetObjectItem(detect, "enable_direction2"); - direction1 = cJSON_GetObjectItem(detect, "direction1"); - direction2 = cJSON_GetObjectItem(detect, "direction2"); - no_parking_time = cJSON_GetObjectItem(detect, "no_parking_time"); - no_parking_time_in_minute = cJSON_GetObjectItem(detect, "no_parking_time_in_minute"); - queuing_count = cJSON_GetObjectItem(detect, "queuing_count"); - ptz_zone_to_preset = cJSON_GetObjectItem(detect, "ptz_zone_to_preset"); - obj_max_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_max_proportion_in_zone"); - obj_min_proportion_in_zone = cJSON_GetObjectItem(detect, "obj_min_proportion_in_zone"); - - enable_speed = cJSON_GetObjectItem(detect, "enable_speed"); - enable_radar_speed = cJSON_GetObjectItem(detect, "enable_radar_speed"); - enable_ivs_zone = cJSON_GetObjectItem(detect, "enable_ivs_zone"); - parking_space = cJSON_GetObjectItem(detect, "parking_space"); - parking_line = cJSON_GetObjectItem(detect, "parking_line"); - set_distance = cJSON_GetObjectItem(detect, "set_distance"); - world_distance_unit = cJSON_GetObjectItem(detect, "world_distance_unit"); - world_distance_side1 = cJSON_GetObjectItem(detect, "world_distance_side1"); - world_distance_side2 = cJSON_GetObjectItem(detect, "world_distance_side2"); - world_time_unit = cJSON_GetObjectItem(detect, "world_time_unit"); - - if (i == 0) { - trigger_events_0 = cJSON_GetObjectItem(detect, "trigger_events"); - s_trigger_events_0 = cJSON_GetObjectItem(s_detect, "trigger_events"); - } - else if (i == 1) { - - trigger_events_1 = cJSON_GetObjectItem(detect, "trigger_events"); - s_trigger_events_1 = cJSON_GetObjectItem(s_detect, "trigger_events"); - } - else if (i == 2) { - - trigger_events_2 = cJSON_GetObjectItem(detect, "trigger_events"); - s_trigger_events_2 = cJSON_GetObjectItem(s_detect, "trigger_events"); - } - else if (i == 3) { - - trigger_events_3 = cJSON_GetObjectItem(detect, "trigger_events"); - s_trigger_events_3 = cJSON_GetObjectItem(s_detect, "trigger_events"); - } - else if (i == 4) { - - trigger_events_4 = cJSON_GetObjectItem(detect, "trigger_events"); - s_trigger_events_4 = cJSON_GetObjectItem(s_detect, "trigger_events"); - } - else if (i == 5) { - - trigger_events_5 = cJSON_GetObjectItem(detect, "trigger_events"); - s_trigger_events_5 = cJSON_GetObjectItem(s_detect, "trigger_events"); - } - else if (i == 6) { - - trigger_events_6 = cJSON_GetObjectItem(detect, "trigger_events"); - s_trigger_events_6 = cJSON_GetObjectItem(s_detect, "trigger_events"); - } - else if (i == 7) { - - trigger_events_7 = cJSON_GetObjectItem(detect, "trigger_events"); - s_trigger_events_7 = cJSON_GetObjectItem(s_detect, "trigger_events"); - } - - point_number = cJSON_GetObjectItem(detect, "point_number"); - x1 = cJSON_GetObjectItem(detect, "x1"); - y1 = cJSON_GetObjectItem(detect, "y1"); - x2 = cJSON_GetObjectItem(detect, "x2"); - y2 = cJSON_GetObjectItem(detect, "y2"); - x3 = cJSON_GetObjectItem(detect, "x3"); - y3 = cJSON_GetObjectItem(detect, "y3"); - x4 = cJSON_GetObjectItem(detect, "x4"); - y4 = cJSON_GetObjectItem(detect, "y4"); - x5 = cJSON_GetObjectItem(detect, "x5"); - y5 = cJSON_GetObjectItem(detect, "y5"); - x6 = cJSON_GetObjectItem(detect, "x6"); - y6 = cJSON_GetObjectItem(detect, "y6"); - - if (obj_max_proportion_in_zone) - { - strcpy(viewDetectionZone[n][i].obj_max_proportion_in_zone, obj_max_proportion_in_zone->valuestring); - cJSON_ReplaceItemInObject(s_detect, "obj_max_proportion_in_zone", cJSON_CreateString(viewDetectionZone[n][i].obj_max_proportion_in_zone)); - } - if (obj_min_proportion_in_zone) - { - strcpy(viewDetectionZone[n][i].obj_min_proportion_in_zone, obj_min_proportion_in_zone->valuestring); - cJSON_ReplaceItemInObject(s_detect, "obj_min_proportion_in_zone", cJSON_CreateString(viewDetectionZone[n][i].obj_min_proportion_in_zone)); - } - if (ptz_zone_to_preset) - { - strcpy(viewDetectionZone[n][i].ptz_zone_to_preset, ptz_zone_to_preset->valuestring); - cJSON_ReplaceItemInObject(s_detect, "ptz_zone_to_preset", cJSON_CreateString(viewDetectionZone[n][i].ptz_zone_to_preset)); - } - if (enable_speed) - { - strcpy(viewDetectionZone[n][i].enable_speed, enable_speed->valuestring); - cJSON_ReplaceItemInObject(s_detect, "enable_speed", cJSON_CreateString(viewDetectionZone[n][i].enable_speed)); - } - if (enable_radar_speed) - { - strcpy(viewDetectionZone[n][i].enable_radar_speed, enable_radar_speed->valuestring); - cJSON_ReplaceItemInObject(s_detect, "enable_radar_speed", cJSON_CreateString(viewDetectionZone[n][i].enable_radar_speed)); - } - if (enable_ivs_zone) - { - strcpy(viewDetectionZone[n][i].enable_ivs_zone, enable_ivs_zone->valuestring); - cJSON_ReplaceItemInObject(s_detect, "enable_ivs_zone", cJSON_CreateString(viewDetectionZone[n][i].enable_ivs_zone)); - } - if (parking_space) - { - viewDetectionZone[n][i].parking_space = atoi(parking_space->valuestring); - cJSON_ReplaceItemInObject(s_detect, "parking_space", cJSON_CreateString(parking_space->valuestring)); - } - if (parking_line) - { - viewDetectionZone[n][i].parking_line = atoi(parking_line->valuestring); - cJSON_ReplaceItemInObject(s_detect, "parking_line", cJSON_CreateString(parking_line->valuestring)); - } - if (set_distance) - { - viewDetectionZone[n][i].set_distance = atof(set_distance->valuestring); - cJSON_ReplaceItemInObject(s_detect, "set_distance", cJSON_CreateString(set_distance->valuestring)); - } - if (world_distance_unit) - { - strcpy(viewDetectionZone[n][i].world_distance_unit, world_distance_unit->valuestring); - cJSON_ReplaceItemInObject(s_detect, "world_distance_unit", cJSON_CreateString(world_distance_unit->valuestring)); - } - if (world_distance_side1) - { - viewDetectionZone[n][i].world_distance_side1 = atof(world_distance_side1->valuestring); - cJSON_ReplaceItemInObject(s_detect, "world_distance_side1", cJSON_CreateString(world_distance_side1->valuestring)); - viewDetectionZone[n][i].world_distance[0] = viewDetectionZone[n][i].world_distance_side1; - viewDetectionZone[n][i].world_distance[2] = viewDetectionZone[n][i].world_distance_side1; - } - if (world_distance_side2) - { - viewDetectionZone[n][i].world_distance_side2 = atof(world_distance_side2->valuestring); - cJSON_ReplaceItemInObject(s_detect, "world_distance_side2", cJSON_CreateString(world_distance_side2->valuestring)); - viewDetectionZone[n][i].world_distance[1] = viewDetectionZone[n][i].world_distance_side2; - viewDetectionZone[n][i].world_distance[3] = viewDetectionZone[n][i].world_distance_side2; - } - if (world_time_unit) - { - strcpy(viewDetectionZone[n][i].world_time_unit, world_time_unit->valuestring); - cJSON_ReplaceItemInObject(s_detect, "world_time_unit", cJSON_CreateString(viewDetectionZone[n][i].world_time_unit)); - } - if (detection_time) - { - strcpy(viewDetectionZone[n][i].detection_time, detection_time->valuestring); - cJSON_ReplaceItemInObject(s_detect, "detection_time", cJSON_CreateString(viewDetectionZone[n][i].detection_time)); - } - if (metadata1) - { - strcpy(viewDetectionZone[n][i].metadata1, metadata1->valuestring); - cJSON_ReplaceItemInObject(s_detect, "metadata1", cJSON_CreateString(viewDetectionZone[n][i].metadata1)); - } - if (metadata2) - { - strcpy(viewDetectionZone[n][i].metadata2, metadata2->valuestring); - cJSON_ReplaceItemInObject(s_detect, "metadata2", cJSON_CreateString(viewDetectionZone[n][i].metadata2)); - } - if (metadata_stop) - { - strcpy(viewDetectionZone[n][i].metadata_stop, metadata_stop->valuestring); - cJSON_ReplaceItemInObject(s_detect, "metadata_stop", cJSON_CreateString(viewDetectionZone[n][i].metadata_stop)); - } - if (link_to_counter) - { - strcpy(viewDetectionZone[n][i].link_to_counter, link_to_counter->valuestring); - cJSON_ReplaceItemInObject(s_detect, "link_to_counter", cJSON_CreateString(viewDetectionZone[n][i].link_to_counter)); - } - if (enable_direction1) - { - strcpy(viewDetectionZone[n][i].enable_direction1, enable_direction1->valuestring); - cJSON_ReplaceItemInObject(s_detect, "enable_direction1", cJSON_CreateString(viewDetectionZone[n][i].enable_direction1)); - } - if (enable_direction2) - { - strcpy(viewDetectionZone[n][i].enable_direction2, enable_direction2->valuestring); - cJSON_ReplaceItemInObject(s_detect, "enable_direction2", cJSON_CreateString(viewDetectionZone[n][i].enable_direction2)); - } - if (direction1) - { - strcpy(viewDetectionZone[n][i].direction1, direction1->valuestring); - cJSON_ReplaceItemInObject(s_detect, "direction1", cJSON_CreateString(viewDetectionZone[n][i].direction1)); - } - if (direction2) - { - strcpy(viewDetectionZone[n][i].direction2, direction2->valuestring); - cJSON_ReplaceItemInObject(s_detect, "direction2", cJSON_CreateString(viewDetectionZone[n][i].direction2)); - } - if (no_parking_time) - { - viewDetectionZone[n][i].no_parking_time = atoi(no_parking_time->valuestring); - cJSON_ReplaceItemInObject(s_detect, "no_parking_time", cJSON_CreateString(no_parking_time->valuestring)); - } - if (no_parking_time_in_minute) - { - viewDetectionZone[n][i].no_parking_time_in_minute = atoi(no_parking_time_in_minute->valuestring); - cJSON_ReplaceItemInObject(s_detect, "no_parking_time_in_minute", cJSON_CreateString(no_parking_time_in_minute->valuestring)); - } - if (queuing_count && strlen(queuing_count->valuestring) >= 1) - { - viewDetectionZone[n][i].queuing_count = atoi(queuing_count->valuestring); - cJSON_ReplaceItemInObject(s_detect, "queuing_count", cJSON_CreateString(queuing_count->valuestring)); - } - - if (point_number) { - viewDetectionZone[n][i].point_num = point_number->valueint; - cJSON_ReplaceItemInObject(s_detect, "point_number", cJSON_CreateNumber(viewDetectionZone[n][i].point_num)); - } - if (x1) { - viewDetectionZone[n][i].Points[0].x = x1->valueint; - viewDetectionZone[n][i].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)x1->valueint, CANVAS_WIDTH / 2); - cJSON_ReplaceItemInObject(s_detect, "x1", cJSON_CreateNumber(viewDetectionZone[n][i].Points[0].x)); - } - if (y1) { - viewDetectionZone[n][i].Points[0].y = y1->valueint; - viewDetectionZone[n][i].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)y1->valueint, CANVAS_HEIGHT / 2); - cJSON_ReplaceItemInObject(s_detect, "y1", cJSON_CreateNumber(viewDetectionZone[n][i].Points[0].y)); - } - if (x2) { - viewDetectionZone[n][i].Points[1].x = x2->valueint; - viewDetectionZone[n][i].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)x2->valueint, CANVAS_WIDTH / 2); - cJSON_ReplaceItemInObject(s_detect, "x2", cJSON_CreateNumber(viewDetectionZone[n][i].Points[1].x)); - } - if (y2) { - viewDetectionZone[n][i].Points[1].y = y2->valueint; - viewDetectionZone[n][i].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)y2->valueint, CANVAS_HEIGHT / 2); - cJSON_ReplaceItemInObject(s_detect, "y2", cJSON_CreateNumber(viewDetectionZone[n][i].Points[1].y)); - } - if (x3) { - viewDetectionZone[n][i].Points[2].x = x3->valueint; - viewDetectionZone[n][i].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)x3->valueint, CANVAS_WIDTH / 2); - cJSON_ReplaceItemInObject(s_detect, "x3", cJSON_CreateNumber(viewDetectionZone[n][i].Points[2].x)); - } - if (y3) { - viewDetectionZone[n][i].Points[2].y = y3->valueint; - viewDetectionZone[n][i].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)y3->valueint, CANVAS_HEIGHT / 2); - cJSON_ReplaceItemInObject(s_detect, "y3", cJSON_CreateNumber(viewDetectionZone[n][i].Points[2].y)); - } - if (x4) { - viewDetectionZone[n][i].Points[3].x = x4->valueint; - viewDetectionZone[n][i].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)x4->valueint, CANVAS_WIDTH / 2); - cJSON_ReplaceItemInObject(s_detect, "x4", cJSON_CreateNumber(viewDetectionZone[n][i].Points[3].x)); - } - if (y4) { - viewDetectionZone[n][i].Points[3].y = y4->valueint; - viewDetectionZone[n][i].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)y4->valueint, CANVAS_HEIGHT / 2); - cJSON_ReplaceItemInObject(s_detect, "y4", cJSON_CreateNumber(viewDetectionZone[n][i].Points[3].y)); - } - if (x5) { - viewDetectionZone[n][i].Points[4].x = x5->valueint; - viewDetectionZone[n][i].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)x5->valueint, CANVAS_WIDTH / 2); - cJSON_ReplaceItemInObject(s_detect, "x5", cJSON_CreateNumber(viewDetectionZone[n][i].Points[4].x)); - } - if (y5) { - viewDetectionZone[n][i].Points[4].y = y5->valueint; - viewDetectionZone[n][i].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)y5->valueint, CANVAS_HEIGHT / 2); - cJSON_ReplaceItemInObject(s_detect, "y5", cJSON_CreateNumber(viewDetectionZone[n][i].Points[4].y)); - } - if (x6) { - viewDetectionZone[n][i].Points[5].x = x6->valueint; - viewDetectionZone[n][i].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)x6->valueint, CANVAS_WIDTH / 2); - cJSON_ReplaceItemInObject(s_detect, "x6", cJSON_CreateNumber(viewDetectionZone[n][i].Points[5].x)); - } - if (y6) { - viewDetectionZone[n][i].Points[5].y = y6->valueint; - viewDetectionZone[n][i].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)y6->valueint, CANVAS_HEIGHT / 2); - cJSON_ReplaceItemInObject(s_detect, "y6", cJSON_CreateNumber(viewDetectionZone[n][i].Points[5].y)); - } - if (enable_traffic_light) { - strcpy(viewDetectionZone[n][i].enable_traffic_light, enable_traffic_light->valuestring); - if (strncmp(viewDetectionZone[n][i].enable_traffic_light, "Yes", strlen("Yes")) == 0) - { - viewChannelData[n].enable_traffic_light_zone = i + 1; - //UpdateTrafficLightZone(n); - } - cJSON_ReplaceItemInObject(s_detect, "enable_traffic_light", cJSON_CreateString(enable_traffic_light->valuestring)); - } - break; - } - j++; - } -#ifdef GY_OS_NOVA - if (detection_zone_small) { - j = 0; - cJSON_ArrayForEach(detect_small, detection_zone_small) - { - if (i == j) { - point_number = cJSON_GetObjectItem(detect, "point_number"); - x1 = cJSON_GetObjectItem(detect, "x1"); - y1 = cJSON_GetObjectItem(detect, "y1"); - x2 = cJSON_GetObjectItem(detect, "x2"); - y2 = cJSON_GetObjectItem(detect, "y2"); - x3 = cJSON_GetObjectItem(detect, "x3"); - y3 = cJSON_GetObjectItem(detect, "y3"); - x4 = cJSON_GetObjectItem(detect, "x4"); - y4 = cJSON_GetObjectItem(detect, "y4"); - x5 = cJSON_GetObjectItem(detect, "x5"); - y5 = cJSON_GetObjectItem(detect, "y5"); - x6 = cJSON_GetObjectItem(detect, "x6"); - y6 = cJSON_GetObjectItem(detect, "y6"); - - if (point_number) { - cJSON_ReplaceItemInObject(detect_small, "point_number", cJSON_CreateNumber(viewDetectionZone[n][i].point_num)); - } - if (x1) { - cJSON_ReplaceItemInObject(detect_small, "x1", cJSON_CreateNumber(viewDetectionZone[n][i].Points[0].x)); - } - if (y1) { - cJSON_ReplaceItemInObject(detect_small, "y1", cJSON_CreateNumber(viewDetectionZone[n][i].Points[0].y)); - } - if (x2) { - cJSON_ReplaceItemInObject(detect_small, "x2", cJSON_CreateNumber(viewDetectionZone[n][i].Points[1].x)); - } - if (y2) { - cJSON_ReplaceItemInObject(detect_small, "y2", cJSON_CreateNumber(viewDetectionZone[n][i].Points[1].y)); - } - if (x3) { - cJSON_ReplaceItemInObject(detect_small, "x3", cJSON_CreateNumber(viewDetectionZone[n][i].Points[2].x)); - } - if (y3) { - cJSON_ReplaceItemInObject(detect_small, "y3", cJSON_CreateNumber(viewDetectionZone[n][i].Points[2].y)); - } - if (x4) { - cJSON_ReplaceItemInObject(detect_small, "x4", cJSON_CreateNumber(viewDetectionZone[n][i].Points[3].x)); - } - if (y4) { - cJSON_ReplaceItemInObject(detect_small, "y4", cJSON_CreateNumber(viewDetectionZone[n][i].Points[3].y)); - } - if (x5) { - cJSON_ReplaceItemInObject(detect_small, "x5", cJSON_CreateNumber(viewDetectionZone[n][i].Points[4].x)); - } - if (y5) { - cJSON_ReplaceItemInObject(detect_small, "y5", cJSON_CreateNumber(viewDetectionZone[n][i].Points[4].y)); - } - if (x6) { - cJSON_ReplaceItemInObject(detect_small, "x6", cJSON_CreateNumber(viewDetectionZone[n][i].Points[5].x)); - } - if (y6) { - cJSON_ReplaceItemInObject(detect_small, "y6", cJSON_CreateNumber(viewDetectionZone[n][i].Points[5].y)); - } - } - j++; - } - } -#endif - } - i++; - - if (i < MAX_DETECTION_ZONE) { - - } - else { - break; - } - } - } - //printf("\nTTTTTTTTTTTTTTT: 2\n"); -#if 1 - - for (int i = 0; i < viewChannelData[n].count_zone; i++) { - - if (i == 0) { - trigger_events_temp = trigger_events_0; - s_trigger_events_temp = s_trigger_events_0; - } - else if (i == 1) { - trigger_events_temp = trigger_events_1; - s_trigger_events_temp = s_trigger_events_1; - } - else if (i == 2) { - trigger_events_temp = trigger_events_2; - s_trigger_events_temp = s_trigger_events_2; - } - else if (i == 3) { - trigger_events_temp = trigger_events_3; - s_trigger_events_temp = s_trigger_events_3; - } - else if (i == 4) { - trigger_events_temp = trigger_events_4; - s_trigger_events_temp = s_trigger_events_4; - } - else if (i == 5) { - trigger_events_temp = trigger_events_5; - s_trigger_events_temp = s_trigger_events_5; - } - else if (i == 6) { - trigger_events_temp = trigger_events_6; - s_trigger_events_temp = s_trigger_events_6; - } - else if (i == 7) { - trigger_events_temp = trigger_events_7; - s_trigger_events_temp = s_trigger_events_7; - } - - if (trigger_events_temp && s_trigger_events_temp) { - int k = 0; - - cJSON_ArrayForEach(detect, trigger_events_temp) - { - if (detect) - { - int m = 0; - - cJSON_ArrayForEach(s_detect, s_trigger_events_temp) - { - if (s_detect) { - cJSON * detect_event_id = cJSON_GetObjectItem(detect, "detect_event_id"); - cJSON * s_detect_event_id = cJSON_GetObjectItem(s_detect, "detect_event_id"); - - if (detect_event_id && s_detect_event_id) - { - if (strcmp(detect_event_id->valuestring, s_detect_event_id->valuestring) == 0) - { - checked = cJSON_GetObjectItem(detect, "checked"); - detect_event_name = cJSON_GetObjectItem(detect, "detect_event_name"); - post_event_name = cJSON_GetObjectItem(detect, "post_event_name"); - counter_name = cJSON_GetObjectItem(detect, "counter_name"); - counter_increment = cJSON_GetObjectItem(detect, "counter_increment"); - - if (checked) - { - viewDetectionZone[n][i].trigger_event[m].checked = checked->valueint; - cJSON_ReplaceItemInObject(s_detect, "checked", cJSON_CreateNumber(viewDetectionZone[n][i].trigger_event[m].checked)); - } - if (detect_event_id) - { - strcpy(viewDetectionZone[n][i].trigger_event[m].detect_event_id, detect_event_id->valuestring); - cJSON_ReplaceItemInObject(s_detect, "detect_event_id", cJSON_CreateString(viewDetectionZone[n][i].trigger_event[m].detect_event_id)); - } - if (detect_event_name) - { - strcpy(viewDetectionZone[n][i].trigger_event[m].detect_event_name, detect_event_name->valuestring); - cJSON_ReplaceItemInObject(s_detect, "detect_event_name", cJSON_CreateString(viewDetectionZone[n][i].trigger_event[m].detect_event_name)); - } - if (post_event_name) { - strcpy(viewDetectionZone[n][i].trigger_event[m].post_event_name, post_event_name->valuestring); - cJSON_ReplaceItemInObject(s_detect, "post_event_name", cJSON_CreateString(viewDetectionZone[n][i].trigger_event[m].post_event_name)); - } - if (counter_name) { - strcpy(viewDetectionZone[n][i].trigger_event[m].counter_name, counter_name->valuestring); - cJSON_ReplaceItemInObject(s_detect, "counter_name", cJSON_CreateString(viewDetectionZone[n][i].trigger_event[m].counter_name)); - } - - if (counter_increment) { - if (strcmp(counter_increment->valuestring, "counter_increment_add") == 0) - viewDetectionZone[n][i].trigger_event[m].counter_increment = 1; - else if (strcmp(counter_increment->valuestring, "counter_increment_minus") == 0) - viewDetectionZone[n][i].trigger_event[m].counter_increment = -1; - else if (strcmp(counter_increment->valuestring, "counter_increment_equal") == 0) - viewDetectionZone[n][i].trigger_event[m].counter_increment = 0; - else - viewDetectionZone[n][i].trigger_event[m].counter_increment = -2; - cJSON_ReplaceItemInObject(s_detect, "counter_increment", cJSON_CreateString(counter_increment->valuestring)); - } - - break; - } - } - } - m++; - } - } - k++; - } - } - - } -#endif - //printf("\nTTTTTTTTTTTTTTT: 3\n"); - } - - } - } - - cJSON *system_setting,*nms_thres, *tracking_id_dwell, *enable_cloud, *enable_special_edition, *enable_python, *enable_python_file, *enable_low_cpu_usage,*enable_person_independent,*enable_onvif_profile_m,*cloud_enable_snap, *cloud_enable_notification, *cloud_account, *cloud_password, *cloud_notification_dwell, *cloud_statue, *language, *display_properties,*display_OSD, *display_dash, - *enable_bounding_box, *enable_dwell_bounding_box,*enable_special_char,*force_i_to_one, *force_o_to_zero, *enable_plate_angle_correction,*enable_ai_mirror, *ai_mirror_feature, *enable_post_only_if_both_detected,*enable_getalarmmotion_snap, *getimage_encoder_id, *getimage_encoder_id_HD, *osd_encoder_id, *osd_font_size, *osd_outline_lilin,*enable_osd_bottom,*osd_bottom_bg_tran, *osd_bottom_content, *enable_sync_external_lpr_db, *external_lpr_db_IP, *external_lpr_db_port, *external_lpr_db_username, *external_lpr_db_password,*enable_system_logs,*enable_email_jpeg,*enable_email_notification,*email_reset_time_interval, - *sensors_type, *enable_ftp, *ftp_url, *ftp_port, *ftp_username, *ftp_password, *ftp_remote_directory, *ftp_jpeg_file_name_format, *ftp_jpeg_file_name; - cJSON *enable_cloud_v2, *cloud_v2_notification_dwell, *cloud_v2_content, *enable_cloud_record_v2, *cloud_record_v2_notification_dwell, *cloud_record_v2_content,*cloud_v2_statue,*cloud_record_v2_statue; - - cJSON *s_system_setting; - - system_setting = cJSON_GetObjectItem(root, "system_setting"); - s_system_setting = cJSON_GetObjectItem(s_root, "system_setting"); - -#ifdef GY_OS_NOVA - system_setting_small = cJSON_GetObjectItem(root_small, "system_setting"); -#endif - - if (system_setting) { - enable_person_independent = cJSON_GetObjectItem(system_setting, "enable_person_independent"); - enable_onvif_profile_m = cJSON_GetObjectItem(system_setting, "enable_onvif_profile_m"); - nms_thres = cJSON_GetObjectItem(system_setting, "nms_thres"); - tracking_id_dwell = cJSON_GetObjectItem(system_setting, "tracking_id_dwell"); - enable_cloud = cJSON_GetObjectItem(system_setting, "enable_cloud"); - enable_special_edition = cJSON_GetObjectItem(system_setting, "enable_special_edition"); - enable_python = cJSON_GetObjectItem(system_setting, "enable_python"); - enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file"); - enable_low_cpu_usage = cJSON_GetObjectItem(system_setting, "enable_low_cpu_usage"); - cloud_enable_snap = cJSON_GetObjectItem(system_setting, "cloud_enable_snap"); - cloud_enable_notification = cJSON_GetObjectItem(system_setting, "cloud_enable_notification"); - cloud_account = cJSON_GetObjectItem(system_setting, "cloud_account"); - cloud_password = cJSON_GetObjectItem(system_setting, "cloud_password"); - cloud_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_notification_dwell"); - cloud_statue = cJSON_GetObjectItem(system_setting, "cloud_statue"); - cloud_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_v2_statue"); - cloud_record_v2_statue = cJSON_GetObjectItem(system_setting, "cloud_record_v2_statue"); - language = cJSON_GetObjectItem(system_setting, "language"); - display_properties = cJSON_GetObjectItem(system_setting, "display properties"); - display_OSD = cJSON_GetObjectItem(system_setting, "display OSD"); - display_dash = cJSON_GetObjectItem(system_setting, "display dash"); - enable_special_char = cJSON_GetObjectItem(system_setting, "enable_special_char"); - enable_bounding_box = cJSON_GetObjectItem(system_setting, "enable_bounding_box"); - enable_dwell_bounding_box = cJSON_GetObjectItem(system_setting, "enable_dwell_bounding_box"); - force_i_to_one = cJSON_GetObjectItem(system_setting, "force_i_to_one"); - force_o_to_zero = cJSON_GetObjectItem(system_setting, "force_o_to_zero"); - enable_plate_angle_correction = cJSON_GetObjectItem(system_setting, "enable_plate_angle_correction"); - - enable_ai_mirror = cJSON_GetObjectItem(system_setting, "enable_ai_mirror"); - ai_mirror_feature = cJSON_GetObjectItem(system_setting, "ai_mirror_feature"); - - enable_cloud_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_v2"); - cloud_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_v2_notification_dwell"); - cloud_v2_content = cJSON_GetObjectItem(system_setting, "cloud_v2_content"); - enable_cloud_record_v2 = cJSON_GetObjectItem(system_setting, "enable_cloud_record_v2"); - cloud_record_v2_notification_dwell = cJSON_GetObjectItem(system_setting, "cloud_record_v2_notification_dwell"); - cloud_record_v2_content = cJSON_GetObjectItem(system_setting, "cloud_record_v2_content"); - - enable_post_only_if_both_detected = cJSON_GetObjectItem(system_setting, "enable_post_only_if_both_detected"); - enable_getalarmmotion_snap = cJSON_GetObjectItem(system_setting, "enable_getalarmmotion_snap"); - getimage_encoder_id = cJSON_GetObjectItem(system_setting, "getimage_encoder_id"); - getimage_encoder_id_HD = cJSON_GetObjectItem(system_setting, "getimage_encoder_id_HD"); - osd_encoder_id = cJSON_GetObjectItem(system_setting, "osd_encoder_id"); - osd_font_size = cJSON_GetObjectItem(system_setting, "osd_font_size"); - osd_outline_lilin = cJSON_GetObjectItem(system_setting, "osd_outline_lilin"); - enable_osd_bottom = cJSON_GetObjectItem(system_setting, "enable_osd_bottom"); - osd_bottom_bg_tran = cJSON_GetObjectItem(system_setting, "osd_bottom_bg_tran"); - osd_bottom_content = cJSON_GetObjectItem(system_setting, "osd_bottom_content"); - sensors_type = cJSON_GetObjectItem(system_setting, "sensors_type"); - enable_sync_external_lpr_db = cJSON_GetObjectItem(system_setting, "enable_sync_external_lpr_db"); - external_lpr_db_IP = cJSON_GetObjectItem(system_setting, "external_lpr_db_IP"); - external_lpr_db_port = cJSON_GetObjectItem(system_setting, "external_lpr_db_port"); - external_lpr_db_username = cJSON_GetObjectItem(system_setting, "external_lpr_db_username"); - external_lpr_db_password = cJSON_GetObjectItem(system_setting, "external_lpr_db_password"); - enable_email_notification = cJSON_GetObjectItem(system_setting, "enable_email_notification"); - enable_system_logs = cJSON_GetObjectItem(system_setting, "enable_system_logs"); - enable_email_jpeg = cJSON_GetObjectItem(system_setting, "enable_email_jpeg"); - email_reset_time_interval = cJSON_GetObjectItem(system_setting, "email_reset_time_interval"); - - enable_ftp = cJSON_GetObjectItem(system_setting, "enable_ftp"); - ftp_url = cJSON_GetObjectItem(system_setting, "ftp_url"); - ftp_port = cJSON_GetObjectItem(system_setting, "ftp_port"); - ftp_username = cJSON_GetObjectItem(system_setting, "ftp_username"); - ftp_password = cJSON_GetObjectItem(system_setting, "ftp_password"); - ftp_remote_directory = cJSON_GetObjectItem(system_setting, "ftp_remote_directory"); - ftp_jpeg_file_name_format = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name_format"); - ftp_jpeg_file_name = cJSON_GetObjectItem(system_setting, "ftp_jpeg_file_name"); - - if (enable_person_independent) - { - strcpy(SystemSetting.enable_person_independent, enable_person_independent->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_person_independent", cJSON_CreateString(SystemSetting.enable_person_independent)); - } - - if (enable_onvif_profile_m) - { - strcpy(SystemSetting.enable_onvif_profile_m, enable_onvif_profile_m->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_onvif_profile_m", cJSON_CreateString(SystemSetting.enable_onvif_profile_m)); - } - - if (nms_thres) - { - strcpy(SystemSetting.nms_thres, nms_thres->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "nms_thres", cJSON_CreateString(SystemSetting.nms_thres)); - } - - if (tracking_id_dwell) - { - strcpy(SystemSetting.tracking_id_dwell, tracking_id_dwell->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "tracking_id_dwell", cJSON_CreateString(SystemSetting.tracking_id_dwell)); - } - - if (cloud_enable_snap) - { - strcpy(SystemSetting.cloud_enable_snap, cloud_enable_snap->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "cloud_enable_snap", cJSON_CreateString(SystemSetting.cloud_enable_snap)); - } - if (enable_cloud) - { - strcpy(SystemSetting.enable_cloud, enable_cloud->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_cloud", cJSON_CreateString(SystemSetting.enable_cloud)); - } - if (enable_special_edition) - { - strcpy(SystemSetting.enable_special_edition, enable_special_edition->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_special_edition", cJSON_CreateString(SystemSetting.enable_special_edition)); - } - if (enable_python) - { - strcpy(SystemSetting.enable_python, enable_python->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_python", cJSON_CreateString(SystemSetting.enable_python)); - } - if (enable_python_file) - { - strcpy(SystemSetting.enable_python_file, enable_python_file->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_python_file", cJSON_CreateString(SystemSetting.enable_python_file)); - - } - if (enable_low_cpu_usage) - { - strcpy(SystemSetting.enable_low_cpu_usage, enable_low_cpu_usage->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_low_cpu_usage", cJSON_CreateString(SystemSetting.enable_low_cpu_usage)); - } - if (cloud_enable_notification) - { - strcpy(SystemSetting.cloud_enable_notification, cloud_enable_notification->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "cloud_enable_notification", cJSON_CreateString(SystemSetting.cloud_enable_notification)); - } - if (cloud_account) - { - strcpy(SystemSetting.cloud_account, cloud_account->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "cloud_account", cJSON_CreateString(SystemSetting.cloud_account)); - } - if (cloud_password) - { - strcpy(SystemSetting.cloud_password, cloud_password->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "cloud_password", cJSON_CreateString(SystemSetting.cloud_password)); - } - if (cloud_notification_dwell) - { - strcpy(SystemSetting.cloud_notification_dwell, cloud_notification_dwell->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "cloud_notification_dwell", cJSON_CreateString(SystemSetting.cloud_notification_dwell)); - } - if (cloud_statue) - { - strcpy(SystemSetting.cloud_statue, cloud_statue->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "cloud_statue", cJSON_CreateString(SystemSetting.cloud_statue)); - } - if (cloud_v2_statue) - { - strcpy(SystemSetting.cloud_v2_statue, cloud_v2_statue->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "cloud_v2_statue", cJSON_CreateString(SystemSetting.cloud_v2_statue)); - } - if (cloud_record_v2_statue) - { - strcpy(SystemSetting.cloud_record_v2_statue, cloud_record_v2_statue->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "cloud_record_v2_statue", cJSON_CreateString(SystemSetting.cloud_record_v2_statue)); - } - if (language) - { - strcpy(SystemSetting.language, language->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "language", cJSON_CreateString(SystemSetting.language)); - } - if (display_properties) - { - strcpy(SystemSetting.enable_display_properties, display_properties->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "display properties", cJSON_CreateString(SystemSetting.enable_display_properties)); - } -#ifdef GY_OS_AMBA - if (display_OSD) - { - pthread_mutex_lock(&mutex_run_one_net); - pthread_mutex_lock(&mutex_get_network_input); - strcpy(SystemSetting.enable_display_OSD, display_OSD->valuestring); - pthread_mutex_unlock(&mutex_get_network_input); - pthread_mutex_unlock(&mutex_run_one_net); - cJSON_ReplaceItemInObject(s_system_setting, "display OSD", cJSON_CreateString(SystemSetting.enable_display_OSD)); - } -#endif - - if (display_dash) - { - activeDisplayDash = (strcmp(display_dash->valuestring, "Yes") == 0) ? _TRUE : _FALSE; - cJSON_ReplaceItemInObject(s_system_setting, "display dash", cJSON_CreateString(display_dash->valuestring)); - } - if (enable_special_char) - { - strcpy(SystemSetting.enable_special_char, enable_special_char->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_special_char", cJSON_CreateString(SystemSetting.enable_special_char)); - } - if (enable_bounding_box) - { - strcpy(SystemSetting.enable_bounding_box, enable_bounding_box->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_bounding_box", cJSON_CreateString(SystemSetting.enable_bounding_box)); - } - if (enable_dwell_bounding_box) - { - strcpy(SystemSetting.enable_dwell_bounding_box, enable_dwell_bounding_box->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_dwell_bounding_box", cJSON_CreateString(SystemSetting.enable_dwell_bounding_box)); - } - if (force_i_to_one) - { - strcpy(SystemSetting.force_i_to_one, force_i_to_one->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "force_i_to_one", cJSON_CreateString(SystemSetting.force_i_to_one)); - } - if (force_o_to_zero) - { - strcpy(SystemSetting.force_o_to_zero, force_o_to_zero->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "force_o_to_zero", cJSON_CreateString(SystemSetting.force_o_to_zero)); - } - if (enable_plate_angle_correction) - { - strcpy(SystemSetting.enable_plate_angle_correction, enable_plate_angle_correction->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_plate_angle_correction", cJSON_CreateString(SystemSetting.enable_plate_angle_correction)); -#ifdef GY_OS_NOVA - cJSON_ReplaceItemInObject(system_setting_small, "enable_plate_angle_correction", cJSON_CreateString(SystemSetting.enable_plate_angle_correction)); -#endif - } - if (enable_ai_mirror) - { - strcpy(SystemSetting.enable_ai_mirror, enable_ai_mirror->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_ai_mirror", cJSON_CreateString(SystemSetting.enable_ai_mirror)); - } - if (ai_mirror_feature) - { - strcpy(SystemSetting.ai_mirror_feature, ai_mirror_feature->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "ai_mirror_feature", cJSON_CreateString(SystemSetting.ai_mirror_feature)); - } - if (enable_cloud_v2) - { - strcpy(SystemSetting.enable_cloud_v2, enable_cloud_v2->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_cloud_v2", cJSON_CreateString(SystemSetting.enable_cloud_v2)); - } - if (cloud_v2_notification_dwell) - { - strcpy(SystemSetting.cloud_v2_notification_dwell, cloud_v2_notification_dwell->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "cloud_v2_notification_dwell", cJSON_CreateString(SystemSetting.cloud_v2_notification_dwell)); - } - if (cloud_v2_content) - { - strcpy(SystemSetting.cloud_v2_content, cloud_v2_content->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "cloud_v2_content", cJSON_CreateString(SystemSetting.cloud_v2_content)); - } - if (enable_cloud_record_v2) - { - strcpy(SystemSetting.enable_cloud_record_v2, enable_cloud_record_v2->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_cloud_record_v2", cJSON_CreateString(SystemSetting.enable_cloud_record_v2)); - } - if (cloud_record_v2_notification_dwell) - { - strcpy(SystemSetting.cloud_record_v2_notification_dwell, cloud_record_v2_notification_dwell->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "cloud_record_v2_notification_dwell", cJSON_CreateString(SystemSetting.cloud_record_v2_notification_dwell)); - } - if (cloud_record_v2_content) - { - strcpy(SystemSetting.cloud_record_v2_content, cloud_record_v2_content->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "cloud_record_v2_content", cJSON_CreateString(SystemSetting.cloud_record_v2_content)); - } - if (enable_post_only_if_both_detected) - { - strcpy(SystemSetting.enable_post_only_if_both_detected, enable_post_only_if_both_detected->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_post_only_if_both_detected", cJSON_CreateString(SystemSetting.enable_post_only_if_both_detected)); - } - if (enable_getalarmmotion_snap) - { - strcpy(SystemSetting.enable_getalarmmotion_snap, enable_getalarmmotion_snap->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_getalarmmotion_snap", cJSON_CreateString(SystemSetting.enable_getalarmmotion_snap)); - } - if (getimage_encoder_id) - { - strcpy(SystemSetting.getimage_encoder_id, getimage_encoder_id->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "getimage_encoder_id", cJSON_CreateString(SystemSetting.getimage_encoder_id)); - } - if (getimage_encoder_id_HD) - { - strcpy(SystemSetting.getimage_encoder_id_HD, getimage_encoder_id_HD->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "getimage_encoder_id_HD", cJSON_CreateString(SystemSetting.getimage_encoder_id_HD)); - } - if (osd_encoder_id) - { - strcpy(SystemSetting.osd_encoder_id, osd_encoder_id->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "osd_encoder_id", cJSON_CreateString(SystemSetting.osd_encoder_id)); - } - if (osd_font_size) - { - strcpy(SystemSetting.osd_font_size, osd_font_size->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "osd_font_size", cJSON_CreateString(SystemSetting.osd_font_size)); - } - if (osd_outline_lilin) - { - strcpy(SystemSetting.osd_outline_lilin, osd_outline_lilin->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "osd_outline_lilin", cJSON_CreateString(SystemSetting.osd_outline_lilin)); - } - if (enable_osd_bottom) - { - strcpy(SystemSetting.enable_osd_bottom, enable_osd_bottom->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_osd_bottom", cJSON_CreateString(SystemSetting.enable_osd_bottom)); - } - if (osd_bottom_bg_tran) - { - strcpy(SystemSetting.osd_bottom_bg_tran, osd_bottom_bg_tran->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "osd_bottom_bg_tran", cJSON_CreateString(SystemSetting.osd_bottom_bg_tran)); - } - if (osd_bottom_content) - { - strcpy(SystemSetting.osd_bottom_content, osd_bottom_content->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "osd_bottom_content", cJSON_CreateString(SystemSetting.osd_bottom_content)); - } - if (sensors_type) - { - strcpy(SystemSetting.sensors_type, sensors_type->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "sensors_type", cJSON_CreateString(SystemSetting.sensors_type)); - } - if (enable_sync_external_lpr_db) - { - strcpy(SystemSetting.enable_sync_external_lpr_db, enable_sync_external_lpr_db->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_sync_external_lpr_db", cJSON_CreateString(SystemSetting.enable_sync_external_lpr_db)); - } - if (external_lpr_db_IP) - { - strcpy(SystemSetting.external_lpr_db_IP, external_lpr_db_IP->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "external_lpr_db_IP", cJSON_CreateString(SystemSetting.external_lpr_db_IP)); - } - if (external_lpr_db_port) - { - strcpy(SystemSetting.external_lpr_db_port, external_lpr_db_port->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "external_lpr_db_port", cJSON_CreateString(SystemSetting.external_lpr_db_port)); - } - if (external_lpr_db_username) - { - strcpy(SystemSetting.external_lpr_db_username, external_lpr_db_username->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "external_lpr_db_username", cJSON_CreateString(SystemSetting.external_lpr_db_username)); - } - if (external_lpr_db_password) - { - strcpy(SystemSetting.external_lpr_db_password, external_lpr_db_password->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "external_lpr_db_password", cJSON_CreateString(SystemSetting.external_lpr_db_password)); - } - - if (enable_system_logs) - { - strcpy(SystemSetting.enable_system_logs, enable_system_logs->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_system_logs", cJSON_CreateString(SystemSetting.enable_system_logs)); - } - - if (enable_email_jpeg) - { - strcpy(SystemSetting.enable_email_jpeg, enable_email_jpeg->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_email_jpeg", cJSON_CreateString(SystemSetting.enable_email_jpeg)); - } - - if (email_reset_time_interval) - { - strcpy(SystemSetting.email_reset_time_interval, email_reset_time_interval->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "email_reset_time_interval", cJSON_CreateString(SystemSetting.email_reset_time_interval)); - } - - if (enable_ftp) - { - strcpy(SystemSetting.enable_ftp, enable_ftp->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_ftp", cJSON_CreateString(SystemSetting.enable_ftp)); - } - - if (ftp_url) - { - strcpy(SystemSetting.ftp_url, ftp_url->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "ftp_url", cJSON_CreateString(SystemSetting.ftp_url)); - } - - if (ftp_port) - { - strcpy(SystemSetting.ftp_port, ftp_port->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "ftp_port", cJSON_CreateString(SystemSetting.ftp_port)); - } - - if (ftp_username) - { - strcpy(SystemSetting.ftp_username, ftp_username->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "ftp_username", cJSON_CreateString(SystemSetting.ftp_username)); - } - - if (ftp_password) - { - strcpy(SystemSetting.ftp_password, ftp_password->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "ftp_password", cJSON_CreateString(SystemSetting.ftp_password)); - } - - if (ftp_remote_directory) - { - strcpy(SystemSetting.ftp_remote_directory, ftp_remote_directory->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "ftp_remote_directory", cJSON_CreateString(SystemSetting.ftp_remote_directory)); - } - - if (ftp_jpeg_file_name_format) - { - strcpy(SystemSetting.ftp_jpeg_file_name_format, ftp_jpeg_file_name_format->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "ftp_jpeg_file_name_format", cJSON_CreateString(SystemSetting.ftp_jpeg_file_name_format)); - } - - if (ftp_jpeg_file_name) - { - strcpy(SystemSetting.ftp_jpeg_file_name, ftp_jpeg_file_name->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "ftp_jpeg_file_name", cJSON_CreateString(SystemSetting.ftp_jpeg_file_name)); - } - - if (enable_email_notification) - { - strcpy(SystemSetting.enable_email_notification, enable_email_notification->valuestring); - cJSON_ReplaceItemInObject(s_system_setting, "enable_email_notification", cJSON_CreateString(SystemSetting.enable_email_notification)); - } - - } - - char* JsonString = cJSON_Print(s_root); - - FILE *f = fopen(config_PATH, "w"); - if (f != NULL) - { - fprintf(f, "%s\n", JsonString); - fclose(f); - - CopyFileTo(config_PATH, config_bakPATH); - check_if_setfile_OK = 1; - g_count_alter = 50; - } - - if (JsonString) { - free(JsonString); - JsonString = NULL; - } - -#ifdef GY_OS_NOVA - JsonString = cJSON_Print(root_small); - - f = fopen(config_smallPATH, "w"); - if (f != NULL) - { - fprintf(f, "%s\n", JsonString); - fclose(f); - } - - if (JsonString) { - free(JsonString); - JsonString = NULL; - } -#endif - -#ifdef GY_OS_AMBA - if (!g_IsPTZDevice && get_g_PTZ_model() != 659 && get_g_PTZ_model() != 715 && get_g_PTZ_model() != 714 && get_g_PTZ_model() != 731 && get_g_PTZ_model() != 716) { - if (enable_ai_mirror && ai_mirror_feature){ - if (strcmp(SystemSetting.enable_ai_mirror, "Yes") == 0) - { - if (strcmp(SystemSetting.ai_mirror_feature, "1") == 0) - { - FILE * pPipe; - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 2"); - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); - } - else { - FILE * pPipe; - char cmd[256] = { 0 }; - memset(cmd, 0x00, sizeof(cmd)); - sprintf(cmd, "timeout 3s /usr/local/bin/test_vin -m 0"); - pPipe = vpopen(cmd, "r"); - if (pPipe != NULL) - vpclose(pPipe); - } - } - } - } -#endif - - if (ftp_remote_directory) { - if (strlen(SystemSetting.ftp_remote_directory) >= 1) { - net_curl_ftp_build_folder(); - } - } - -#ifdef GY_OS_AMBA - - viewChannelData[0].speed_view_width_ratio = (float)(1920 / 889); - viewChannelData[0].speed_view_height_ratio = (float)(1080 / 500); - for (int i = 0; i < MAX_DETECTION_ZONE; i++) { - if (strncmp(viewDetectionZone[0][i].enable_speed, "Yes", strlen("Yes")) == 0) - { - int social_zone_idx = i; - if (social_zone_idx >= 0) - { - pthread_mutex_lock(&mutex_perspective_transform); - if (viewDetectionZone[0][i].PerspectiveTransformArray != NULL) - cvReleaseMat(&viewDetectionZone[0][i].PerspectiveTransformArray); - viewDetectionZone[0][i].PerspectiveTransformArray = GetPerspectiveTransformArray(0, social_zone_idx); - pthread_mutex_unlock(&mutex_perspective_transform); - } - } - } - -#endif - - } - - if (root) { - cJSON_Delete(root); - root = NULL; - } - if (s_root) { - cJSON_Delete(s_root); - s_root = NULL; - } - -#ifdef GY_OS_NOVA - if (root_small) { - cJSON_Delete(root_small); - root_small = NULL; - } -#endif - } - else { - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (fileBuf2) { - free(fileBuf2); - fileBuf2 = NULL; - } -#ifdef GY_OS_NOVA - if (fileBuf3) { - free(fileBuf3); - fileBuf3 = NULL; - } -#endif - printf("\nFail to read config_import.json or config.json\n"); - } - } - } - - strcpy(beforeSendBuffer, ""); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - if (check_if_setfile_OK == 1) { - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend(Not setconfigfile)\n"); - } - else { - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend(Not setconfigfile#2)\n"); - } - - pthread_mutex_unlock(&mutex_config_json); - - closesocket(cli_socket); - -#ifdef GY_OS_AMBA - - /* - int zone_to_preset[4]; - - for (int i = 0; i < 4; i++) - { - zone_to_preset[i] = 0; - - if (viewDetectionZone[0][i].ptz_zone_to_preset != NULL - && strlen(viewDetectionZone[0][i].ptz_zone_to_preset) > 0) - { - zone_to_preset[i] = atoi(viewDetectionZone[0][i].ptz_zone_to_preset); - } - }*/ - - //Update PTZ - - UpdatePTZConfigSetting(); - - /* - UpdatePTZConfigSetting(viewChannelData[0].enable_PTZ, viewChannelData[0].ptz_enable_tracking, - viewChannelData[0].ptz_tracking_fov_min, viewChannelData[0].ptz_tracking_fov_max, - viewChannelData[0].confidence2, viewChannelData[0].ptz_tracking_mode, viewChannelData[0].ptz_tracking_by_enter_zone, viewChannelData[0].ptz_tracking_resume_dwell, - viewDetectionZone[0][0].metadata1, zone_to_preset);*/ - - SetPtzSensitivity(viewChannelData[0].ptz_sensitivity); - -#endif - - //Reload cold zone - /*int iReadCodeZoneRet = */ ReadColdZoneJsonFile(); - - set_metadata(); - -#ifdef GY_OS_AMBA - for (int index_zone = 0; index_zone < viewChannelData[0].count_zone; index_zone++) { - if (strstr(viewDetectionZone[0][index_zone].metadata1, "qrcode") != NULL || - strstr(viewDetectionZone[0][index_zone].metadata1, "barcode") != NULL || - g_check_h264_gop != 0) - { - if (run_check_current_resolution == -1) { - run_check_current_resolution = 0; - if (pthread_create(&resolution_changed_thread, 0, check_current_resolution, NULL)) - printf("\ncheck current resolution thread failed #2\n"); - run_check_current_resolution = 1; - break; - } - } - } -#endif - - set_counter_zone(); - - check_if_correct_post = 0; - - clear_all_record_locked_ivs(); - - //printf("\n------------setconfigfile end\n"); - } - else if (strncmp(urlBuffer, "/seteventsfile", strlen("/seteventsfile")) == 0) - { - pthread_mutex_lock(&mutex_events_json); - - int check_if_setfile_OK = 0; - - int file_buff_size = nTotalContentLen; - if (file_buff_size >= 1) - { - char* file_Content = recvBuffer + recv_buff_size; - - //printf("\n------file_buff_size:%d\n", file_buff_size); - //printf("\n------file_Content:%s\n", file_Content); - - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char events_importPATH[1024]; - strcpy(events_importPATH, exePath); - strcat(events_importPATH, "events_import.json"); - - char events_PATH[1024]; - strcpy(events_PATH, exePath); - strcat(events_PATH, "events.json"); - - FILE *pFile; - - if ((pFile = fopen(events_importPATH, "w+")) != NULL) - { - fprintf(pFile, "%s", file_Content); - fclose(pFile); - - char* fileBuf = ReadAllBytes(events_importPATH); - char* fileBuf2 = ReadAllBytes(events_PATH); - - if (fileBuf && fileBuf2) { - - cJSON *root = cJSON_Parse(fileBuf); - cJSON *s_root = cJSON_Parse(fileBuf2); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (fileBuf2) { - free(fileBuf2); - fileBuf2 = NULL; - } - - if (root && s_root) - { - cJSON *notification, *enable_post,*events_default_version,*enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content, - *post_customized_header; - cJSON *post_sequence,*post_file_format, *post_jpeg_file_name_format, *post_jpeg_file_name,*post_timeout; - cJSON *enable_heartbeat, *heartbeat_dwell, *heartbeat_link_to_post_event_name, *dwell_to_the_same_location, - *enable_snmp_heartbeat, *snmp_heartbeat_dwell, *snmp_heartbeat_link_to_post_event_name, - *enable_only_once_to_post, *enable_obj_once_to_post, *enable_location_once_to_post,*enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion,*heatmap_max, *enable_heatmap, *heatmap_frequency,*lpr_title,*enable_counter_snap, *enable_barcode_qr, - *enable_check_ptz_start_autotracking,*enable_check_ptz_end_autotracking,*ptz_start_autotracking_link_to_post_event_name,*ptz_end_autotracking_link_to_post_event_name; - - cJSON *s_notification, *s_http_post_events, *s_detect2; - - notification = cJSON_GetObjectItem(root, "notification"); - s_notification = cJSON_GetObjectItem(s_root, "notification"); - - if (notification) { - events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); - enable_post = cJSON_GetObjectItem(notification, "enable_post"); - enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); - enable_heartbeat = cJSON_GetObjectItem(notification, "enable_heartbeat"); - - enable_snmp_heartbeat = cJSON_GetObjectItem(notification, "enable_snmp_heartbeat"); - snmp_heartbeat_dwell = cJSON_GetObjectItem(notification, "snmp_heartbeat_dwell"); - snmp_heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "snmp_heartbeat_link_to_post_event_name"); - - enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); - enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); - ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); - ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); - - enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); - enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); - enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); - dwell_to_the_same_location = cJSON_GetObjectItem(notification, "dwell_to_the_same_location"); - enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); - enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); - heartbeat_dwell = cJSON_GetObjectItem(notification, "heartbeat_dwell"); - heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "heartbeat_link_to_post_event_name"); - heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); - enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); - heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); - lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); - enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); - enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); - - http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); - s_http_post_events = cJSON_GetObjectItem(s_notification, "http_post_events"); - - if (events_default_version) - { - strcpy(heartbeatData.events_default_version, events_default_version->valuestring); - cJSON_ReplaceItemInObject(s_notification, "events_default_version", cJSON_CreateString(heartbeatData.events_default_version)); - } - - if(enable_post) - { - - activePostNotification = strcmp(enable_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; - cJSON_ReplaceItemInObject(s_notification, "enable_post", cJSON_CreateString(enable_post->valuestring)); - } - if (enable_snmp_post) - { - activeSNMPPost = strcmp(enable_snmp_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; - cJSON_ReplaceItemInObject(s_notification, "enable_snmp_post", cJSON_CreateString(enable_snmp_post->valuestring)); - } - if (enable_heartbeat) - { - strcpy(heartbeatData.enable_heartbeat, enable_heartbeat->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_heartbeat", cJSON_CreateString(heartbeatData.enable_heartbeat)); - } - if (enable_snmp_heartbeat) - { - strcpy(heartbeatData.enable_snmp_heartbeat, enable_snmp_heartbeat->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_snmp_heartbeat", cJSON_CreateString(heartbeatData.enable_snmp_heartbeat)); - } - if (snmp_heartbeat_dwell) - { - strcpy(heartbeatData.snmp_heartbeat_dwell, snmp_heartbeat_dwell->valuestring); - cJSON_ReplaceItemInObject(s_notification, "snmp_heartbeat_dwell", cJSON_CreateString(heartbeatData.snmp_heartbeat_dwell)); - } - if (snmp_heartbeat_link_to_post_event_name) - { - strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, snmp_heartbeat_link_to_post_event_name->valuestring); - cJSON_ReplaceItemInObject(s_notification, "snmp_heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.snmp_heartbeat_link_to_post_event_name)); - } - if (enable_check_ptz_start_autotracking) - { - strcpy(heartbeatData.enable_check_ptz_start_autotracking, enable_check_ptz_start_autotracking->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_check_ptz_start_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_start_autotracking)); - } - if (enable_check_ptz_end_autotracking) - { - strcpy(heartbeatData.enable_check_ptz_end_autotracking, enable_check_ptz_end_autotracking->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_check_ptz_end_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_end_autotracking)); - } - if (enable_only_once_to_post) - { - strcpy(heartbeatData.enable_only_once_to_post, enable_only_once_to_post->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_only_once_to_post", cJSON_CreateString(heartbeatData.enable_only_once_to_post)); - } - if (enable_obj_once_to_post) - { - strcpy(heartbeatData.enable_obj_once_to_post, enable_obj_once_to_post->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_obj_once_to_post", cJSON_CreateString(heartbeatData.enable_obj_once_to_post)); - } - if (enable_location_once_to_post) - { - strcpy(heartbeatData.enable_location_once_to_post, enable_location_once_to_post->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_location_once_to_post", cJSON_CreateString(heartbeatData.enable_location_once_to_post)); - } - if (enable_nvr_once_to_getalarmmotion) - { - strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, enable_nvr_once_to_getalarmmotion->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_nvr_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_nvr_once_to_getalarmmotion)); - } - if (enable_8592_once_to_getalarmmotion) - { - strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, enable_8592_once_to_getalarmmotion->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_8592_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_8592_once_to_getalarmmotion)); - } - if (dwell_to_the_same_location) - { - strcpy(heartbeatData.dwell_to_the_same_location, dwell_to_the_same_location->valuestring); - cJSON_ReplaceItemInObject(s_notification, "dwell_to_the_same_location", cJSON_CreateString(heartbeatData.dwell_to_the_same_location)); - } - if (heartbeat_dwell) - { - strcpy(heartbeatData.heartbeat_dwell, heartbeat_dwell->valuestring); - cJSON_ReplaceItemInObject(s_notification, "heartbeat_dwell", cJSON_CreateString(heartbeatData.heartbeat_dwell)); - } - if (heartbeat_link_to_post_event_name) - { - strcpy(heartbeatData.heartbeat_link_to_post_event_name, heartbeat_link_to_post_event_name->valuestring); - cJSON_ReplaceItemInObject(s_notification, "heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.heartbeat_link_to_post_event_name)); - } - if (ptz_start_autotracking_link_to_post_event_name) - { - strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ptz_start_autotracking_link_to_post_event_name->valuestring); - cJSON_ReplaceItemInObject(s_notification, "ptz_start_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_start_autotracking_link_to_post_event_name)); - } - if (ptz_end_autotracking_link_to_post_event_name) - { - strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ptz_end_autotracking_link_to_post_event_name->valuestring); - cJSON_ReplaceItemInObject(s_notification, "ptz_end_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_end_autotracking_link_to_post_event_name)); - } - if (heatmap_max) - { - strcpy(heartbeatData.heatmap_max, heatmap_max->valuestring); - cJSON_ReplaceItemInObject(s_notification, "heatmap_max", cJSON_CreateString(heartbeatData.heatmap_max)); - } - if (enable_heatmap) - { - strcpy(heartbeatData.enable_heatmap, enable_heatmap->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_heatmap", cJSON_CreateString(heartbeatData.enable_heatmap)); - } - if (heatmap_frequency) - { - strcpy(heartbeatData.heatmap_frequency, heatmap_frequency->valuestring); - cJSON_ReplaceItemInObject(s_notification, "heatmap_frequency", cJSON_CreateString(heartbeatData.heatmap_frequency)); - } - if (lpr_title) - { - strcpy(heartbeatData.lpr_title, lpr_title->valuestring); - cJSON_ReplaceItemInObject(s_notification, "lpr_title", cJSON_CreateString(heartbeatData.lpr_title)); - } - if (enable_counter_snap) - { - strcpy(heartbeatData.enable_counter_snap, enable_counter_snap->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_counter_snap", cJSON_CreateString(heartbeatData.enable_counter_snap)); - } - if (enable_barcode_qr) - { - strcpy(heartbeatData.enable_barcode_qr, enable_barcode_qr->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_barcode_qr", cJSON_CreateString(heartbeatData.enable_barcode_qr)); - } - if (http_post_events) - { - - int i = 0; - cJSON_ArrayForEach(detect2, http_post_events) - { - if (detect2) - { - int j = 0; - cJSON_ArrayForEach(s_detect2, s_http_post_events) - { - if(i==j) - { - post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); - post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); - post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); - post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); - post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); - post_url = cJSON_GetObjectItem(detect2, "post_url"); - post_username = cJSON_GetObjectItem(detect2, "post_username"); - post_password = cJSON_GetObjectItem(detect2, "post_password"); - post_content = cJSON_GetObjectItem(detect2, "post_content"); - post_customized_header = cJSON_GetObjectItem(detect2, "post_customized_header"); - post_sequence = cJSON_GetObjectItem(detect2, "post_sequence"); - post_file_format = cJSON_GetObjectItem(detect2, "post_file_format"); - post_jpeg_file_name_format = cJSON_GetObjectItem(detect2, "post_jpeg_file_name_format"); - post_jpeg_file_name = cJSON_GetObjectItem(detect2, "post_jpeg_file_name"); - post_timeout = cJSON_GetObjectItem(detect2, "post_timeout"); - - if (post_protocol) - { - strcpy(postEventList[j].post_protocol, post_protocol->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_protocol", cJSON_CreateString(postEventList[j].post_protocol)); - } - if (post_event_method) - { - strcpy(postEventList[j].post_event_method, post_event_method->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_event_method", cJSON_CreateString(postEventList[j].post_event_method)); - } - if (post_event_name2) { - strcpy(postEventList[j].post_event_name, post_event_name2->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_event_name", cJSON_CreateString(postEventList[j].post_event_name)); - } - if (post_host_ip) - { - strcpy(postEventList[j].post_host_ip, post_host_ip->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_host_ip", cJSON_CreateString(postEventList[j].post_host_ip)); - } - if(post_host_port) - { - strcpy(postEventList[j].post_host_port, post_host_port->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_host_port", cJSON_CreateString(postEventList[j].post_host_port)); - } - if (post_url) - { - strcpy(postEventList[j].post_url, post_url->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_url", cJSON_CreateString(postEventList[j].post_url)); - } - if (post_username) - { - char temp_account[512] = { 0 }; - urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); - memcpy(postEventList[i].post_username, temp_account, strlen(temp_account)); - postEventList[i].post_username[strlen(temp_account)] = '\0'; - - //strcpy(postEventList[j].post_username, post_username->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_username", cJSON_CreateString(post_username->valuestring)); - } - if (post_password) - { - char temp_account2[512] = { 0 }; - urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); - memcpy(postEventList[i].post_password, temp_account2, strlen(temp_account2)); - postEventList[i].post_password[strlen(temp_account2)] = '\0'; - - //strcpy(postEventList[j].post_password, post_password->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_password", cJSON_CreateString(post_password->valuestring)); - } - if (post_content) - { - strcpy(postEventList[j].post_content, post_content->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_content", cJSON_CreateString(postEventList[j].post_content)); - } - if(post_customized_header) - { - strcpy(postEventList[j].post_customized_header, post_customized_header->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_customized_header", cJSON_CreateString(postEventList[j].post_customized_header)); - } - if (post_sequence) - { - strcpy(postEventList[j].post_sequence, post_sequence->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_sequence", cJSON_CreateString(postEventList[j].post_sequence)); - } - if (post_timeout) - { - strcpy(postEventList[j].post_timeout, post_timeout->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_timeout", cJSON_CreateString(postEventList[j].post_timeout)); - } - if (post_file_format) - { - strcpy(postEventList[j].post_file_format, post_file_format->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_file_format", cJSON_CreateString(postEventList[j].post_file_format)); - } - if (post_jpeg_file_name_format) - { - strcpy(postEventList[j].post_jpeg_file_name_format, post_jpeg_file_name_format->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_jpeg_file_name_format", cJSON_CreateString(postEventList[j].post_jpeg_file_name_format)); - } - if (post_jpeg_file_name) - { - strcpy(postEventList[j].post_jpeg_file_name, post_jpeg_file_name->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_jpeg_file_name", cJSON_CreateString(postEventList[j].post_jpeg_file_name)); - } - break; - } - j++; - } - } - i++; - } - } - - } - cJSON *event_counter_setting, *detect3, *event_counters, *counter_name,*counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *enable_reset_only_cloud,*enable_linked_to_dwell_time;// *reset_at, *enable_time_range, *time_range_from, *time_range_to, - cJSON *link_to_post_event_name, *post_interval; - cJSON *a_report, *report_counters, *counter_a, *counter_a_name, *counter_b, *counter_b_name, *counter_a_zone,*counter_b_zone,*counter_c_name, - *enable_report,*report_max_value, *initial_icon, *detection_output, *output_icon,*counter_mode; - cJSON *a_snmp, *snmp_management, *snmp_event_name, *snmp_version, *snmp_group_name, *snmp_host_ip, *snmp_host_port, - *snmp_oid, *snmp_value, *snmp_type; - - cJSON *s_event_counter_setting, *s_event_counters,*s_detect3,*s_counter_name,*s_a_report,*s_report_counters, *s_a_snmp, *s_snmp_management; - - event_counter_setting = cJSON_GetObjectItem(root, "event_counter_setting"); - s_event_counter_setting = cJSON_GetObjectItem(s_root, "event_counter_setting"); -#ifdef GY_OS_V_SERIES - -#else - if (event_counter_setting) - { - event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); - s_event_counters = cJSON_GetObjectItem(s_event_counter_setting, "event_counters"); - if (event_counters) - { - int i = 0; - cJSON_ArrayForEach(detect3, event_counters) - { - if (detect3) - { - counter_name = cJSON_GetObjectItem(detect3, "counter_name"); - if (counter_name) { - int j = 0; - cJSON_ArrayForEach(s_detect3, s_event_counters) - { - s_counter_name = cJSON_GetObjectItem(s_detect3, "counter_name"); - if(strcmp(counter_name->valuestring, s_counter_name->valuestring)==0) - { - counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); - counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); - reset_value = cJSON_GetObjectItem(detect3, "reset_value"); - enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); - reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); - //reset_at = cJSON_GetObjectItem(detect3, "reset_at"); - //enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); - //time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); - //time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); - enable_reset_only_cloud = cJSON_GetObjectItem(detect3, "enable_reset_only_cloud"); - enable_linked_to_dwell_time = cJSON_GetObjectItem(detect3, "enable_linked_to_dwell_time"); - link_to_post_event_name = cJSON_GetObjectItem(detect3, "link_to_post_event_name"); - post_interval = cJSON_GetObjectItem(detect3, "post_interval"); - - if (counter_name) - { - strcpy(eventCounterList[j].counter_name, counter_name->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "counter_name", cJSON_CreateString(eventCounterList[j].counter_name)); - } - if (counter_cust_name) - { - strcpy(eventCounterList[j].counter_cust_name, counter_cust_name->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "counter_cust_name", cJSON_CreateString(eventCounterList[j].counter_cust_name)); - } - if (counter_unit) - { - strcpy(eventCounterList[j].counter_unit, counter_unit->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "counter_unit", cJSON_CreateString(eventCounterList[j].counter_unit)); - } - if (reset_value) - { - eventCounterList[j].reset_value = atoi(reset_value->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "reset_value", cJSON_CreateString(reset_value->valuestring)); - } - if (enable_reset_time_interval) - { - strcpy(eventCounterList[j].enable_reset_time_interval, enable_reset_time_interval->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "enable_reset_time_interval", cJSON_CreateString(eventCounterList[j].enable_reset_time_interval)); - } - if (reset_time_interval) - { - strcpy(eventCounterList[j].reset_time_interval, reset_time_interval->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "reset_time_interval", cJSON_CreateString(eventCounterList[j].reset_time_interval)); - } - -#if 0 - - if (reset_at) - { - strcpy(eventCounterList[j].reset_at, reset_at->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "reset_at", cJSON_CreateString(eventCounterList[j].reset_at)); - struct tm tm; - strptime_c(eventCounterList[j].reset_at, "%Y-%m-%d %H:%M:%S", &tm); - eventCounterList[j].timetResetAt = mktime(&tm); - struct tm *resetTime = localtime(&eventCounterList[j].timetResetAt); - eventCounterList[j].reset_month = resetTime->tm_mon; - eventCounterList[j].reset_month_day = resetTime->tm_mday; - eventCounterList[j].reset_week_day = resetTime->tm_wday; - eventCounterList[j].reset_hour = resetTime->tm_hour; - eventCounterList[j].reset_min = resetTime->tm_min; - eventCounterList[j].reset_sec = resetTime->tm_sec; - } - - if (enable_time_range) - { - strcpy(eventCounterList[j].enable_time_range, enable_time_range->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "enable_time_range", cJSON_CreateString(eventCounterList[j].enable_time_range)); - } - if (time_range_from) - { - strcpy(eventCounterList[j].time_range_from, time_range_from->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "time_range_from", cJSON_CreateString(eventCounterList[j].time_range_from)); - struct tm tm; - strptime_c(eventCounterList[j].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); - eventCounterList[j].timetTimeRangeFrom = mktime(&tm); - } - if (time_range_to) - { - strcpy(eventCounterList[j].time_range_to, time_range_to->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "time_range_to", cJSON_CreateString(eventCounterList[j].time_range_to)); - struct tm tm; - strptime_c(eventCounterList[j].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); - eventCounterList[j].timetTimeRangeTo = mktime(&tm); - } -#endif - - if (link_to_post_event_name) - { - strcpy(eventCounterList[j].link_to_post_event_name, link_to_post_event_name->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "link_to_post_event_name", cJSON_CreateString(eventCounterList[j].link_to_post_event_name)); - } - if (post_interval) - { - strcpy(eventCounterList[j].post_interval, post_interval->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "post_interval", cJSON_CreateString(eventCounterList[j].post_interval)); - } - if (enable_reset_only_cloud) { - strcpy(eventCounterList[j].enable_reset_only_cloud, enable_reset_only_cloud->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "enable_reset_only_cloud", cJSON_CreateString(eventCounterList[j].enable_reset_only_cloud)); - } - if (enable_linked_to_dwell_time) { - strcpy(eventCounterList[j].enable_linked_to_dwell_time, enable_linked_to_dwell_time->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "enable_linked_to_dwell_time", cJSON_CreateString(eventCounterList[j].enable_linked_to_dwell_time)); - } - break; - } - j++; - } - } - } - - i++; - } - -#if 0 - if (strcmp(SystemSetting.cloud_enable_notification, "No") == 0) - { - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || -#ifdef GY_OS_NOVA - IsANPRCategory(featureType) || -#endif - g_IsCustomWeight == 1) { - pthread_mutex_lock(&mutex_reset_counter); - time_t now_time = g_osdSysTimeStamp; - if (now_time < 1000000000) { - now_time = time(0); - } - for (int j = 0; j < MAX_EVENT_COUNTERS; j++) - { - reset_counter(j, now_time); - } - pthread_mutex_unlock(&mutex_reset_counter); - } - } -#endif - } - - report_counters = cJSON_GetObjectItem(event_counter_setting, "report_counters"); - s_report_counters = cJSON_GetObjectItem(s_event_counter_setting, "report_counters"); - - if (report_counters) { - int i = 0; - cJSON_ArrayForEach(a_report, report_counters) - { - if (a_report) - { - int j = 0; - cJSON_ArrayForEach(s_a_report, s_report_counters) - { - if (i == j) { - counter_a = cJSON_GetObjectItem(a_report, "counter_a"); - counter_a_name = cJSON_GetObjectItem(a_report, "counter_a_name"); - counter_a_zone = cJSON_GetObjectItem(a_report, "counter_a_zone"); - counter_b = cJSON_GetObjectItem(a_report, "counter_b"); - counter_b_name = cJSON_GetObjectItem(a_report, "counter_b_name"); - counter_b_zone = cJSON_GetObjectItem(a_report, "counter_b_zone"); - counter_c_name = cJSON_GetObjectItem(a_report, "counter_c_name"); - report_max_value = cJSON_GetObjectItem(a_report, "report_max_value"); - enable_report = cJSON_GetObjectItem(a_report, "enable_report"); - counter_mode = cJSON_GetObjectItem(a_report, "counter_mode"); - initial_icon = cJSON_GetObjectItem(a_report, "initial_icon"); - detection_output = cJSON_GetObjectItem(a_report, "detection_output"); - output_icon = cJSON_GetObjectItem(a_report, "output_icon"); - - - if (counter_a) - { - strcpy(reportCounterList[j].counter_a, counter_a->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_a", cJSON_CreateString(reportCounterList[j].counter_a)); - } - - if (counter_a_name) - { - strcpy(reportCounterList[j].counter_a_name, counter_a_name->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_a_name", cJSON_CreateString(reportCounterList[j].counter_a_name)); - } - - if (counter_a_zone) - { - strcpy(reportCounterList[j].counter_a_zone, counter_a_zone->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_a_zone", cJSON_CreateString(reportCounterList[j].counter_a_zone)); - } - - if (counter_b) - { - strcpy(reportCounterList[j].counter_b, counter_b->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_b", cJSON_CreateString(reportCounterList[j].counter_b)); - } - - if (counter_b_name) - { - strcpy(reportCounterList[j].counter_b_name, counter_b_name->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_b_name", cJSON_CreateString(reportCounterList[j].counter_b_name)); - } - - if (counter_b_zone) - { - strcpy(reportCounterList[j].counter_b_zone, counter_b_zone->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_b_zone", cJSON_CreateString(reportCounterList[j].counter_b_zone)); - } - - if (counter_c_name) - { - strcpy(reportCounterList[j].counter_c_name, counter_c_name->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_c_name", cJSON_CreateString(reportCounterList[j].counter_c_name)); - } - - if (report_max_value) - { - strcpy(reportCounterList[j].report_max_value, report_max_value->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "report_max_value", cJSON_CreateString(reportCounterList[j].report_max_value)); - } - - if (enable_report) - { - strcpy(reportCounterList[j].enable_report, enable_report->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "enable_report", cJSON_CreateString(reportCounterList[j].enable_report)); - } - - if (counter_mode) - { - strcpy(reportCounterList[j].counter_mode, counter_mode->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_mode", cJSON_CreateString(reportCounterList[j].counter_mode)); - } - - if (initial_icon) - { - strcpy(reportCounterList[j].initial_icon, initial_icon->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "initial_icon", cJSON_CreateString(reportCounterList[j].initial_icon)); - } - - if (detection_output) - { - strcpy(reportCounterList[j].detection_output, detection_output->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "detection_output", cJSON_CreateString(reportCounterList[j].detection_output)); - } - - if (output_icon) - { - strcpy(reportCounterList[j].output_icon, output_icon->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "output_icon", cJSON_CreateString(reportCounterList[j].output_icon)); - } - - break; - } - j++; - } - } - - i++; - } - } - - snmp_management = cJSON_GetObjectItem(event_counter_setting, "snmp_management"); - s_snmp_management = cJSON_GetObjectItem(s_event_counter_setting, "snmp_management"); - - if (snmp_management) { - int i = 0; - cJSON_ArrayForEach(a_snmp, snmp_management) - { - if (a_snmp) - { - int j = 0; - cJSON_ArrayForEach(s_a_snmp, s_snmp_management) - { - if (i == j) { - snmp_event_name = cJSON_GetObjectItem(a_snmp, "snmp_event_name"); - snmp_version = cJSON_GetObjectItem(a_snmp, "snmp_version"); - snmp_group_name = cJSON_GetObjectItem(a_snmp, "snmp_group_name"); - snmp_host_ip = cJSON_GetObjectItem(a_snmp, "snmp_host_ip"); - snmp_host_port = cJSON_GetObjectItem(a_snmp, "snmp_host_port"); - snmp_oid = cJSON_GetObjectItem(a_snmp, "snmp_oid"); - snmp_value = cJSON_GetObjectItem(a_snmp, "snmp_value"); - snmp_type = cJSON_GetObjectItem(a_snmp, "snmp_type"); - - - if (snmp_event_name) - { - strcpy(SNMPManagementList[j].snmp_event_name, snmp_event_name->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_event_name", cJSON_CreateString(SNMPManagementList[j].snmp_event_name)); - } - - if (snmp_version) - { - strcpy(SNMPManagementList[j].snmp_version, snmp_version->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_version", cJSON_CreateString(SNMPManagementList[j].snmp_version)); - } - - if (snmp_group_name) - { - strcpy(SNMPManagementList[j].snmp_group_name, snmp_group_name->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_group_name", cJSON_CreateString(SNMPManagementList[j].snmp_group_name)); - } - - if (snmp_host_ip) - { - strcpy(SNMPManagementList[j].snmp_host_ip, snmp_host_ip->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_host_ip", cJSON_CreateString(SNMPManagementList[j].snmp_host_ip)); - } - - if (snmp_host_port) - { - strcpy(SNMPManagementList[j].snmp_host_port, snmp_host_port->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_host_port", cJSON_CreateString(SNMPManagementList[j].snmp_host_port)); - } - - if (snmp_oid) - { - strcpy(SNMPManagementList[j].snmp_oid, snmp_oid->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_oid", cJSON_CreateString(SNMPManagementList[j].snmp_oid)); - } - - if (snmp_value) - { - strcpy(SNMPManagementList[j].snmp_value, snmp_value->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_value", cJSON_CreateString(SNMPManagementList[j].snmp_value)); - } - - if (snmp_type) - { - strcpy(SNMPManagementList[j].snmp_type, snmp_type->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_type", cJSON_CreateString(SNMPManagementList[j].snmp_type)); - } - break; - } - j++; - } - } - - i++; - } - } - } -#endif - cJSON *email_setting, *email_content; - cJSON *s_email_setting; - - email_setting = cJSON_GetObjectItem(root, "email_setting"); - s_email_setting = cJSON_GetObjectItem(s_root, "email_setting"); - - if (email_setting) - { - email_content = cJSON_GetObjectItem(email_setting, "email_content"); - if (email_content) { - strcpy(emailData.email_content, email_content->valuestring); - cJSON_ReplaceItemInObject(s_email_setting, "email_content", cJSON_CreateString(emailData.email_content)); - } - } - - char* JsonString = cJSON_Print(s_root); - - FILE *f = fopen(events_PATH, "w"); - if (f != NULL) - { - - fprintf(f, "%s\n", JsonString); - fclose(f); - - CopyFileTo(events_PATH, events_bakPATH); - - check_if_setfile_OK = 1; - g_count_alter = 50; - } - - if (JsonString) { - free(JsonString); - JsonString = NULL; - } - - } - - if (root) { - cJSON_Delete(root); - root = NULL; - } - if (s_root) { - cJSON_Delete(s_root); - s_root = NULL; - } - } - else { - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (fileBuf2) { - free(fileBuf2); - fileBuf2 = NULL; - } - printf("\nFail to read events_import.json or events.json\n"); - } - } - - } - - strcpy(beforeSendBuffer, ""); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - if (check_if_setfile_OK == 1) { - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend(Not seteventsfile)\n"); - } - else { - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend(Not seteventsfile#2)\n"); - } - - pthread_mutex_unlock(&mutex_events_json); - - closesocket(cli_socket); - - set_counter_zone(); - - check_if_correct_post = 0; - } - else if (strncmp(urlBuffer, "/seteventscustom2", strlen("/seteventscustom2")) == 0) - { - pthread_mutex_lock(&mutex_events_json); - - int check_if_setfile_OK = 0; - - int file_buff_size = nTotalContentLen; - if (file_buff_size >= 1) - { - char* file_Content = recvBuffer + recv_buff_size; - - //printf("\n------file_buff_size:%d\n", file_buff_size); - //printf("\n------file_Content:%s\n", file_Content); - - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char events_importPATH[1024]; - strcpy(events_importPATH, exePath); - strcat(events_importPATH, "events_custom_2_import.json"); - - char events_PATH[1024]; - strcpy(events_PATH, exePath); - strcat(events_PATH, "events_custom_2.json"); - - FILE *pFile; - - if ((pFile = fopen(events_importPATH, "w+")) != NULL) - { - fprintf(pFile, "%s", file_Content); - fclose(pFile); - - char* fileBuf = ReadAllBytes(events_importPATH); - char* fileBuf2 = ReadAllBytes(events_PATH); - - if (fileBuf && fileBuf2) { - - cJSON *root = cJSON_Parse(fileBuf); - cJSON *s_root = cJSON_Parse(fileBuf2); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (fileBuf2) { - free(fileBuf2); - fileBuf2 = NULL; - } - - if (root && s_root) - { - cJSON *notification, *events_default_version,*enable_post, *enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content, - *post_customized_header; - cJSON *post_sequence, *post_file_format, *post_jpeg_file_name_format, *post_jpeg_file_name,*post_timeout; - cJSON *enable_heartbeat, *heartbeat_dwell, *heartbeat_link_to_post_event_name, *dwell_to_the_same_location, - *enable_snmp_heartbeat, *snmp_heartbeat_dwell, *snmp_heartbeat_link_to_post_event_name, - *enable_only_once_to_post, *enable_obj_once_to_post, *enable_location_once_to_post, *enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion, *heatmap_max, *enable_heatmap, *heatmap_frequency, *lpr_title, *enable_counter_snap, *enable_barcode_qr, - *enable_check_ptz_start_autotracking, *enable_check_ptz_end_autotracking, *ptz_start_autotracking_link_to_post_event_name, *ptz_end_autotracking_link_to_post_event_name; - - cJSON *s_notification, *s_http_post_events, *s_detect2; - - notification = cJSON_GetObjectItem(root, "notification"); - s_notification = cJSON_GetObjectItem(s_root, "notification"); - - if (notification) { - events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); - enable_post = cJSON_GetObjectItem(notification, "enable_post"); - enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); - enable_heartbeat = cJSON_GetObjectItem(notification, "enable_heartbeat"); - - enable_snmp_heartbeat = cJSON_GetObjectItem(notification, "enable_snmp_heartbeat"); - snmp_heartbeat_dwell = cJSON_GetObjectItem(notification, "snmp_heartbeat_dwell"); - snmp_heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "snmp_heartbeat_link_to_post_event_name"); - - enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); - enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); - ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); - ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); - - enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); - enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); - enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); - dwell_to_the_same_location = cJSON_GetObjectItem(notification, "dwell_to_the_same_location"); - enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); - enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); - heartbeat_dwell = cJSON_GetObjectItem(notification, "heartbeat_dwell"); - heartbeat_link_to_post_event_name = cJSON_GetObjectItem(notification, "heartbeat_link_to_post_event_name"); - heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); - enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); - heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); - lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); - enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); - enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); - - http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); - s_http_post_events = cJSON_GetObjectItem(s_notification, "http_post_events"); - - if (events_default_version) - { - strcpy(heartbeatData.events_default_version, events_default_version->valuestring); - cJSON_ReplaceItemInObject(s_notification, "events_default_version", cJSON_CreateString(heartbeatData.events_default_version)); - } - - if (enable_post) - { - - activePostNotification = strcmp(enable_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; - cJSON_ReplaceItemInObject(s_notification, "enable_post", cJSON_CreateString(enable_post->valuestring)); - } - if (enable_snmp_post) - { - activeSNMPPost = strcmp(enable_snmp_post->valuestring, "Yes") == 0 ? _TRUE : _FALSE; - cJSON_ReplaceItemInObject(s_notification, "enable_snmp_post", cJSON_CreateString(enable_snmp_post->valuestring)); - } - if (enable_heartbeat) - { - strcpy(heartbeatData.enable_heartbeat, enable_heartbeat->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_heartbeat", cJSON_CreateString(heartbeatData.enable_heartbeat)); - } - if (enable_snmp_heartbeat) - { - strcpy(heartbeatData.enable_snmp_heartbeat, enable_snmp_heartbeat->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_snmp_heartbeat", cJSON_CreateString(heartbeatData.enable_snmp_heartbeat)); - } - if (snmp_heartbeat_dwell) - { - strcpy(heartbeatData.snmp_heartbeat_dwell, snmp_heartbeat_dwell->valuestring); - cJSON_ReplaceItemInObject(s_notification, "snmp_heartbeat_dwell", cJSON_CreateString(heartbeatData.snmp_heartbeat_dwell)); - } - if (snmp_heartbeat_link_to_post_event_name) - { - strcpy(heartbeatData.snmp_heartbeat_link_to_post_event_name, snmp_heartbeat_link_to_post_event_name->valuestring); - cJSON_ReplaceItemInObject(s_notification, "snmp_heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.snmp_heartbeat_link_to_post_event_name)); - } - if (enable_check_ptz_start_autotracking) - { - strcpy(heartbeatData.enable_check_ptz_start_autotracking, enable_check_ptz_start_autotracking->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_check_ptz_start_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_start_autotracking)); - } - if (enable_check_ptz_end_autotracking) - { - strcpy(heartbeatData.enable_check_ptz_end_autotracking, enable_check_ptz_end_autotracking->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_check_ptz_end_autotracking", cJSON_CreateString(heartbeatData.enable_check_ptz_end_autotracking)); - } - if (enable_only_once_to_post) - { - strcpy(heartbeatData.enable_only_once_to_post, enable_only_once_to_post->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_only_once_to_post", cJSON_CreateString(heartbeatData.enable_only_once_to_post)); - } - if (enable_obj_once_to_post) - { - strcpy(heartbeatData.enable_obj_once_to_post, enable_obj_once_to_post->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_obj_once_to_post", cJSON_CreateString(heartbeatData.enable_obj_once_to_post)); - } - if (enable_location_once_to_post) - { - strcpy(heartbeatData.enable_location_once_to_post, enable_location_once_to_post->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_location_once_to_post", cJSON_CreateString(heartbeatData.enable_location_once_to_post)); - } - if (enable_nvr_once_to_getalarmmotion) - { - strcpy(heartbeatData.enable_nvr_once_to_getalarmmotion, enable_nvr_once_to_getalarmmotion->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_nvr_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_nvr_once_to_getalarmmotion)); - } - if (enable_8592_once_to_getalarmmotion) - { - strcpy(heartbeatData.enable_8592_once_to_getalarmmotion, enable_8592_once_to_getalarmmotion->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_8592_once_to_getalarmmotion", cJSON_CreateString(heartbeatData.enable_8592_once_to_getalarmmotion)); - } - if (dwell_to_the_same_location) - { - strcpy(heartbeatData.dwell_to_the_same_location, dwell_to_the_same_location->valuestring); - cJSON_ReplaceItemInObject(s_notification, "dwell_to_the_same_location", cJSON_CreateString(heartbeatData.dwell_to_the_same_location)); - } - if (heartbeat_dwell) - { - strcpy(heartbeatData.heartbeat_dwell, heartbeat_dwell->valuestring); - cJSON_ReplaceItemInObject(s_notification, "heartbeat_dwell", cJSON_CreateString(heartbeatData.heartbeat_dwell)); - } - if (heartbeat_link_to_post_event_name) - { - strcpy(heartbeatData.heartbeat_link_to_post_event_name, heartbeat_link_to_post_event_name->valuestring); - cJSON_ReplaceItemInObject(s_notification, "heartbeat_link_to_post_event_name", cJSON_CreateString(heartbeatData.heartbeat_link_to_post_event_name)); - } - if (ptz_start_autotracking_link_to_post_event_name) - { - strcpy(heartbeatData.ptz_start_autotracking_link_to_post_event_name, ptz_start_autotracking_link_to_post_event_name->valuestring); - cJSON_ReplaceItemInObject(s_notification, "ptz_start_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_start_autotracking_link_to_post_event_name)); - } - if (ptz_end_autotracking_link_to_post_event_name) - { - strcpy(heartbeatData.ptz_end_autotracking_link_to_post_event_name, ptz_end_autotracking_link_to_post_event_name->valuestring); - cJSON_ReplaceItemInObject(s_notification, "ptz_end_autotracking_link_to_post_event_name", cJSON_CreateString(heartbeatData.ptz_end_autotracking_link_to_post_event_name)); - } - if (heatmap_max) - { - strcpy(heartbeatData.heatmap_max, heatmap_max->valuestring); - cJSON_ReplaceItemInObject(s_notification, "heatmap_max", cJSON_CreateString(heartbeatData.heatmap_max)); - } - if (enable_heatmap) - { - strcpy(heartbeatData.enable_heatmap, enable_heatmap->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_heatmap", cJSON_CreateString(heartbeatData.enable_heatmap)); - } - if (heatmap_frequency) - { - strcpy(heartbeatData.heatmap_frequency, heatmap_frequency->valuestring); - cJSON_ReplaceItemInObject(s_notification, "heatmap_frequency", cJSON_CreateString(heartbeatData.heatmap_frequency)); - } - if (lpr_title) - { - strcpy(heartbeatData.lpr_title, lpr_title->valuestring); - cJSON_ReplaceItemInObject(s_notification, "lpr_title", cJSON_CreateString(heartbeatData.lpr_title)); - } - if (enable_counter_snap) - { - strcpy(heartbeatData.enable_counter_snap, enable_counter_snap->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_counter_snap", cJSON_CreateString(heartbeatData.enable_counter_snap)); - } - if (enable_barcode_qr) - { - strcpy(heartbeatData.enable_barcode_qr, enable_barcode_qr->valuestring); - cJSON_ReplaceItemInObject(s_notification, "enable_barcode_qr", cJSON_CreateString(heartbeatData.enable_barcode_qr)); - } - if (http_post_events) - { - - int i = 0; - cJSON_ArrayForEach(detect2, http_post_events) - { - if (detect2) - { - int j = 0; - cJSON_ArrayForEach(s_detect2, s_http_post_events) - { - if (i == j) - { - post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); - post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); - post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); - post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); - post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); - post_url = cJSON_GetObjectItem(detect2, "post_url"); - post_username = cJSON_GetObjectItem(detect2, "post_username"); - post_password = cJSON_GetObjectItem(detect2, "post_password"); - post_content = cJSON_GetObjectItem(detect2, "post_content"); - post_customized_header = cJSON_GetObjectItem(detect2, "post_customized_header"); - post_sequence = cJSON_GetObjectItem(detect2, "post_sequence"); - post_timeout = cJSON_GetObjectItem(detect2, "post_timeout"); - post_file_format = cJSON_GetObjectItem(detect2, "post_file_format"); - post_jpeg_file_name_format = cJSON_GetObjectItem(detect2, "post_jpeg_file_name_format"); - post_jpeg_file_name = cJSON_GetObjectItem(detect2, "post_jpeg_file_name"); - - if (post_protocol) - { - strcpy(postEventList[j].post_protocol, post_protocol->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_protocol", cJSON_CreateString(postEventList[j].post_protocol)); - } - if (post_event_method) - { - strcpy(postEventList[j].post_event_method, post_event_method->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_event_method", cJSON_CreateString(postEventList[j].post_event_method)); - } - if (post_event_name2) { - strcpy(postEventList[j].post_event_name, post_event_name2->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_event_name", cJSON_CreateString(postEventList[j].post_event_name)); - } - if (post_host_ip) - { - strcpy(postEventList[j].post_host_ip, post_host_ip->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_host_ip", cJSON_CreateString(postEventList[j].post_host_ip)); - } - if (post_host_port) - { - strcpy(postEventList[j].post_host_port, post_host_port->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_host_port", cJSON_CreateString(postEventList[j].post_host_port)); - } - if (post_url) - { - strcpy(postEventList[j].post_url, post_url->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_url", cJSON_CreateString(postEventList[j].post_url)); - } - if (post_username) - { - char temp_account[512] = { 0 }; - urlencode((unsigned char *)post_username->valuestring, strlen(post_username->valuestring), (unsigned char *)temp_account, 512); - memcpy(postEventList[i].post_username, temp_account, strlen(temp_account)); - postEventList[i].post_username[strlen(temp_account)] = '\0'; - - //strcpy(postEventList[j].post_username, post_username->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_username", cJSON_CreateString(post_username->valuestring)); - } - if (post_password) - { - char temp_account2[512] = { 0 }; - urlencode((unsigned char *)post_password->valuestring, strlen(post_password->valuestring), (unsigned char *)temp_account2, 512); - memcpy(postEventList[i].post_password, temp_account2, strlen(temp_account2)); - postEventList[i].post_password[strlen(temp_account2)] = '\0'; - - //strcpy(postEventList[j].post_password, post_password->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_password", cJSON_CreateString(post_password->valuestring)); - } - if (post_content) - { - strcpy(postEventList[j].post_content, post_content->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_content", cJSON_CreateString(postEventList[j].post_content)); - } - if (post_customized_header) - { - strcpy(postEventList[j].post_customized_header, post_customized_header->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_customized_header", cJSON_CreateString(postEventList[j].post_customized_header)); - } - if (post_sequence) - { - strcpy(postEventList[j].post_sequence, post_sequence->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_sequence", cJSON_CreateString(postEventList[j].post_sequence)); - } - if (post_timeout) - { - strcpy(postEventList[j].post_timeout, post_timeout->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_timeout", cJSON_CreateString(postEventList[j].post_timeout)); - } - if (post_file_format) - { - strcpy(postEventList[j].post_file_format, post_file_format->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_file_format", cJSON_CreateString(postEventList[j].post_file_format)); - } - if (post_jpeg_file_name_format) - { - strcpy(postEventList[j].post_jpeg_file_name_format, post_jpeg_file_name_format->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_jpeg_file_name_format", cJSON_CreateString(postEventList[j].post_jpeg_file_name_format)); - } - if (post_jpeg_file_name) - { - strcpy(postEventList[j].post_jpeg_file_name, post_jpeg_file_name->valuestring); - cJSON_ReplaceItemInObject(s_detect2, "post_jpeg_file_name", cJSON_CreateString(postEventList[j].post_jpeg_file_name)); - } - break; - } - j++; - } - } - i++; - } - } - - } - cJSON *event_counter_setting, *detect3, *event_counters, *counter_name, *counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *enable_reset_only_cloud, *enable_linked_to_dwell_time;// *reset_at, *enable_time_range, *time_range_from, *time_range_to, - cJSON *link_to_post_event_name, *post_interval; - cJSON *a_report, *report_counters, *counter_a, *counter_a_name, *counter_b, *counter_b_name, *counter_a_zone, *counter_b_zone, *counter_c_name, - *enable_report, *report_max_value, *initial_icon, *detection_output, *output_icon, *counter_mode; - cJSON *a_snmp, *snmp_management, *snmp_event_name, *snmp_version, *snmp_group_name, *snmp_host_ip, *snmp_host_port, - *snmp_oid, *snmp_value, *snmp_type; - - cJSON *s_event_counter_setting, *s_event_counters, *s_detect3, *s_counter_name, *s_a_report, *s_report_counters, *s_a_snmp, *s_snmp_management; - - event_counter_setting = cJSON_GetObjectItem(root, "event_counter_setting"); - s_event_counter_setting = cJSON_GetObjectItem(s_root, "event_counter_setting"); -#ifdef GY_OS_V_SERIES - -#else - if (event_counter_setting) - { - event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); - s_event_counters = cJSON_GetObjectItem(s_event_counter_setting, "event_counters"); - if (event_counters) - { - int i = 0; - cJSON_ArrayForEach(detect3, event_counters) - { - if (detect3) - { - counter_name = cJSON_GetObjectItem(detect3, "counter_name"); - if (counter_name) { - int j = 0; - cJSON_ArrayForEach(s_detect3, s_event_counters) - { - s_counter_name = cJSON_GetObjectItem(s_detect3, "counter_name"); - if (strcmp(counter_name->valuestring, s_counter_name->valuestring) == 0) - { - counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); - counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); - reset_value = cJSON_GetObjectItem(detect3, "reset_value"); - enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); - reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); - //reset_at = cJSON_GetObjectItem(detect3, "reset_at"); - //enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); - //time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); - //time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); - enable_reset_only_cloud = cJSON_GetObjectItem(detect3, "enable_reset_only_cloud"); - enable_linked_to_dwell_time = cJSON_GetObjectItem(detect3, "enable_linked_to_dwell_time"); - link_to_post_event_name = cJSON_GetObjectItem(detect3, "link_to_post_event_name"); - post_interval = cJSON_GetObjectItem(detect3, "post_interval"); - - if (counter_name) - { - strcpy(eventCounterList[j].counter_name, counter_name->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "counter_name", cJSON_CreateString(eventCounterList[j].counter_name)); - } - if (counter_cust_name) - { - strcpy(eventCounterList[j].counter_cust_name, counter_cust_name->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "counter_cust_name", cJSON_CreateString(eventCounterList[j].counter_cust_name)); - } - if (counter_unit) - { - strcpy(eventCounterList[j].counter_unit, counter_unit->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "counter_unit", cJSON_CreateString(eventCounterList[j].counter_unit)); - } - if (reset_value) - { - eventCounterList[j].reset_value = atoi(reset_value->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "reset_value", cJSON_CreateString(reset_value->valuestring)); - } - if (enable_reset_time_interval) - { - strcpy(eventCounterList[j].enable_reset_time_interval, enable_reset_time_interval->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "enable_reset_time_interval", cJSON_CreateString(eventCounterList[j].enable_reset_time_interval)); - } - if (reset_time_interval) - { - strcpy(eventCounterList[j].reset_time_interval, reset_time_interval->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "reset_time_interval", cJSON_CreateString(eventCounterList[j].reset_time_interval)); - } - - #if 0 - - if (reset_at) - { - strcpy(eventCounterList[j].reset_at, reset_at->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "reset_at", cJSON_CreateString(eventCounterList[j].reset_at)); - struct tm tm; - strptime_c(eventCounterList[j].reset_at, "%Y-%m-%d %H:%M:%S", &tm); - eventCounterList[j].timetResetAt = mktime(&tm); - struct tm *resetTime = localtime(&eventCounterList[j].timetResetAt); - eventCounterList[j].reset_month = resetTime->tm_mon; - eventCounterList[j].reset_month_day = resetTime->tm_mday; - eventCounterList[j].reset_week_day = resetTime->tm_wday; - eventCounterList[j].reset_hour = resetTime->tm_hour; - eventCounterList[j].reset_min = resetTime->tm_min; - eventCounterList[j].reset_sec = resetTime->tm_sec; - } - - if (enable_time_range) - { - strcpy(eventCounterList[j].enable_time_range, enable_time_range->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "enable_time_range", cJSON_CreateString(eventCounterList[j].enable_time_range)); - } - if (time_range_from) - { - strcpy(eventCounterList[j].time_range_from, time_range_from->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "time_range_from", cJSON_CreateString(eventCounterList[j].time_range_from)); - struct tm tm; - strptime_c(eventCounterList[j].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); - eventCounterList[j].timetTimeRangeFrom = mktime(&tm); - } - if (time_range_to) - { - strcpy(eventCounterList[j].time_range_to, time_range_to->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "time_range_to", cJSON_CreateString(eventCounterList[j].time_range_to)); - struct tm tm; - strptime_c(eventCounterList[j].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); - eventCounterList[j].timetTimeRangeTo = mktime(&tm); - } - #endif - - if (link_to_post_event_name) - { - strcpy(eventCounterList[j].link_to_post_event_name, link_to_post_event_name->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "link_to_post_event_name", cJSON_CreateString(eventCounterList[j].link_to_post_event_name)); - } - if (post_interval) - { - strcpy(eventCounterList[j].post_interval, post_interval->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "post_interval", cJSON_CreateString(eventCounterList[j].post_interval)); - } - if (enable_reset_only_cloud) { - strcpy(eventCounterList[j].enable_reset_only_cloud, enable_reset_only_cloud->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "enable_reset_only_cloud", cJSON_CreateString(eventCounterList[j].enable_reset_only_cloud)); - } - if (enable_linked_to_dwell_time) { - strcpy(eventCounterList[j].enable_linked_to_dwell_time, enable_linked_to_dwell_time->valuestring); - cJSON_ReplaceItemInObject(s_detect3, "enable_linked_to_dwell_time", cJSON_CreateString(eventCounterList[j].enable_linked_to_dwell_time)); - } - break; - } - j++; - } - } - } - - i++; - } - -#if 0 - if (strcmp(SystemSetting.cloud_enable_notification, "No") == 0) - { - if (((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AICAP) == FEATURE_AICAP) || - ((featureType & FEATURE_TRAF_DET) == FEATURE_TRAF_DET && (featureType2 & FEATURE_AISPORTS) == FEATURE_AISPORTS && strcmp(WeightFileModeName, "mod002") == 0) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIHELM) == FEATURE_AIHELM) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIMASK) == FEATURE_AIMASK && (strcmp(WeightFileModeName, "mod001") == 0 || strcmp(WeightFileModeName, "mod002") == 0)) || - ((featureType & FEATURE_HUM_DET) == FEATURE_HUM_DET && (featureType2 & FEATURE_AIAML) == FEATURE_AIAML && strcmp(WeightFileModeName, "mod003") == 0) || - IsANPRCategory(featureType) || - g_IsCustomWeight == 1) { - pthread_mutex_lock(&mutex_reset_counter); - time_t now_time = g_osdSysTimeStamp; - if (now_time < 1000000000) { - now_time = time(0); - } - - for (int j = 0; j < MAX_EVENT_COUNTERS; j++) - { - reset_counter(j, now_time); - } - pthread_mutex_unlock(&mutex_reset_counter); - } - } -#endif - } - - report_counters = cJSON_GetObjectItem(event_counter_setting, "report_counters"); - s_report_counters = cJSON_GetObjectItem(s_event_counter_setting, "report_counters"); - - if (report_counters) { - int i = 0; - cJSON_ArrayForEach(a_report, report_counters) - { - if (a_report) - { - int j = 0; - cJSON_ArrayForEach(s_a_report, s_report_counters) - { - if (i == j) { - counter_a = cJSON_GetObjectItem(a_report, "counter_a"); - counter_a_name = cJSON_GetObjectItem(a_report, "counter_a_name"); - counter_a_zone = cJSON_GetObjectItem(a_report, "counter_a_zone"); - counter_b = cJSON_GetObjectItem(a_report, "counter_b"); - counter_b_name = cJSON_GetObjectItem(a_report, "counter_b_name"); - counter_b_zone = cJSON_GetObjectItem(a_report, "counter_b_zone"); - counter_c_name = cJSON_GetObjectItem(a_report, "counter_c_name"); - report_max_value = cJSON_GetObjectItem(a_report, "report_max_value"); - enable_report = cJSON_GetObjectItem(a_report, "enable_report"); - counter_mode = cJSON_GetObjectItem(a_report, "counter_mode"); - initial_icon = cJSON_GetObjectItem(a_report, "initial_icon"); - detection_output = cJSON_GetObjectItem(a_report, "detection_output"); - output_icon = cJSON_GetObjectItem(a_report, "output_icon"); - - - if (counter_a) - { - strcpy(reportCounterList[j].counter_a, counter_a->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_a", cJSON_CreateString(reportCounterList[j].counter_a)); - } - - if (counter_a_name) - { - strcpy(reportCounterList[j].counter_a_name, counter_a_name->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_a_name", cJSON_CreateString(reportCounterList[j].counter_a_name)); - } - - if (counter_a_zone) - { - strcpy(reportCounterList[j].counter_a_zone, counter_a_zone->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_a_zone", cJSON_CreateString(reportCounterList[j].counter_a_zone)); - } - - if (counter_b) - { - strcpy(reportCounterList[j].counter_b, counter_b->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_b", cJSON_CreateString(reportCounterList[j].counter_b)); - } - - if (counter_b_name) - { - strcpy(reportCounterList[j].counter_b_name, counter_b_name->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_b_name", cJSON_CreateString(reportCounterList[j].counter_b_name)); - } - - if (counter_b_zone) - { - strcpy(reportCounterList[j].counter_b_zone, counter_b_zone->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_b_zone", cJSON_CreateString(reportCounterList[j].counter_b_zone)); - } - - if (counter_c_name) - { - strcpy(reportCounterList[j].counter_c_name, counter_c_name->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_c_name", cJSON_CreateString(reportCounterList[j].counter_c_name)); - } - - if (report_max_value) - { - strcpy(reportCounterList[j].report_max_value, report_max_value->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "report_max_value", cJSON_CreateString(reportCounterList[j].report_max_value)); - } - - if (enable_report) - { - strcpy(reportCounterList[j].enable_report, enable_report->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "enable_report", cJSON_CreateString(reportCounterList[j].enable_report)); - } - - if (counter_mode) - { - strcpy(reportCounterList[j].counter_mode, counter_mode->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "counter_mode", cJSON_CreateString(reportCounterList[j].counter_mode)); - } - - if (initial_icon) - { - strcpy(reportCounterList[j].initial_icon, initial_icon->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "initial_icon", cJSON_CreateString(reportCounterList[j].initial_icon)); - } - - if (detection_output) - { - strcpy(reportCounterList[j].detection_output, detection_output->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "detection_output", cJSON_CreateString(reportCounterList[j].detection_output)); - } - - if (output_icon) - { - strcpy(reportCounterList[j].output_icon, output_icon->valuestring); - cJSON_ReplaceItemInObject(s_a_report, "output_icon", cJSON_CreateString(reportCounterList[j].output_icon)); - } - - break; - } - j++; - } - } - - i++; - } - } - - snmp_management = cJSON_GetObjectItem(event_counter_setting, "snmp_management"); - s_snmp_management = cJSON_GetObjectItem(s_event_counter_setting, "snmp_management"); - - if (snmp_management) { - int i = 0; - cJSON_ArrayForEach(a_snmp, snmp_management) - { - if (a_snmp) - { - int j = 0; - cJSON_ArrayForEach(s_a_snmp, s_snmp_management) - { - if (i == j) { - snmp_event_name = cJSON_GetObjectItem(a_snmp, "snmp_event_name"); - snmp_version = cJSON_GetObjectItem(a_snmp, "snmp_version"); - snmp_group_name = cJSON_GetObjectItem(a_snmp, "snmp_group_name"); - snmp_host_ip = cJSON_GetObjectItem(a_snmp, "snmp_host_ip"); - snmp_host_port = cJSON_GetObjectItem(a_snmp, "snmp_host_port"); - snmp_oid = cJSON_GetObjectItem(a_snmp, "snmp_oid"); - snmp_value = cJSON_GetObjectItem(a_snmp, "snmp_value"); - snmp_type = cJSON_GetObjectItem(a_snmp, "snmp_type"); - - - if (snmp_event_name) - { - strcpy(SNMPManagementList[j].snmp_event_name, snmp_event_name->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_event_name", cJSON_CreateString(SNMPManagementList[j].snmp_event_name)); - } - - if (snmp_version) - { - strcpy(SNMPManagementList[j].snmp_version, snmp_version->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_version", cJSON_CreateString(SNMPManagementList[j].snmp_version)); - } - - if (snmp_group_name) - { - strcpy(SNMPManagementList[j].snmp_group_name, snmp_group_name->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_group_name", cJSON_CreateString(SNMPManagementList[j].snmp_group_name)); - } - - if (snmp_host_ip) - { - strcpy(SNMPManagementList[j].snmp_host_ip, snmp_host_ip->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_host_ip", cJSON_CreateString(SNMPManagementList[j].snmp_host_ip)); - } - - if (snmp_host_port) - { - strcpy(SNMPManagementList[j].snmp_host_port, snmp_host_port->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_host_port", cJSON_CreateString(SNMPManagementList[j].snmp_host_port)); - } - - if (snmp_oid) - { - strcpy(SNMPManagementList[j].snmp_oid, snmp_oid->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_oid", cJSON_CreateString(SNMPManagementList[j].snmp_oid)); - } - - if (snmp_value) - { - strcpy(SNMPManagementList[j].snmp_value, snmp_value->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_value", cJSON_CreateString(SNMPManagementList[j].snmp_value)); - } - - if (snmp_type) - { - strcpy(SNMPManagementList[j].snmp_type, snmp_type->valuestring); - cJSON_ReplaceItemInObject(s_a_snmp, "snmp_type", cJSON_CreateString(SNMPManagementList[j].snmp_type)); - } - break; - } - j++; - } - } - - i++; - } - } - } -#endif - cJSON *email_setting, *email_content; - cJSON *s_email_setting; - - email_setting = cJSON_GetObjectItem(root, "email_setting"); - s_email_setting = cJSON_GetObjectItem(s_root, "email_setting"); - - if (email_setting) - { - email_content = cJSON_GetObjectItem(email_setting, "email_content"); - if (email_content) { - strcpy(emailData.email_content, email_content->valuestring); - cJSON_ReplaceItemInObject(s_email_setting, "email_content", cJSON_CreateString(emailData.email_content)); - } - } - - char* JsonString = cJSON_Print(s_root); - - FILE *f = fopen(events_PATH, "w"); - if (f != NULL) - { - - fprintf(f, "%s\n", JsonString); - fclose(f); - - CopyFileTo(events_PATH, events_bakPATH); - - check_if_setfile_OK = 1; - g_count_alter = 50; - } - - if (JsonString) { - free(JsonString); - JsonString = NULL; - } - - } - - if (root) { - cJSON_Delete(root); - root = NULL; - } - if (s_root) { - cJSON_Delete(s_root); - s_root = NULL; - } - } - else { - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (fileBuf2) { - free(fileBuf2); - fileBuf2 = NULL; - } - printf("\nFail to read events_import.json or events.json\n"); - } - } - } - - strcpy(beforeSendBuffer, ""); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - if (check_if_setfile_OK == 1) { - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend(Not seteventscustom2)\n"); - } - else { - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend(Not seteventscustom2#2)\n"); - } - - pthread_mutex_unlock(&mutex_events_json); - - closesocket(cli_socket); - - check_if_correct_post = 0; - } -#if 0 - else if (strncmp(urlBuffer, "/setjvcconfigfile", strlen("/setjvcconfigfile")) == 0) { - int check_if_setfile_OK = 0; - //printf("----------------------------[setjvcconfigfile]recvBuffer: %s\n", recvBuffer); - - pthread_mutex_lock(&mutex_jvc_config_json); - - check_if_setfile_OK = 1; - - int file_buff_size = nTotalContentLen; - //char msg_temp[512] = { 0 }; -#if 1 - if (file_buff_size >= 1) - { - char* file_Content = recvBuffer + recv_buff_size; - - //printf("\n------file_buff_size:%d\n", file_buff_size); - //printf("\n------file_Content:%s\n", file_Content); - - jvc_setconfig(file_Content); - - - //sprintf(msg_temp, (reload_dataset_from_jsonfile() > 0 ? "Reload failed!" : "Reload OK.")); - //printf("\n--------------------reload 4: %s\n", msg_temp); - } -#endif - -#if 0 - jvc_setMainSetting(); -#endif - - strcpy(beforeSendBuffer, ""); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - //printf("jvc configfile: \n %s \n", beforeSendBuffer); - if (check_if_setfile_OK == 1) { - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend(Not setconfigfile)\n"); - } - else { - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend(Not setconfigfile#2)\n"); - } - - pthread_mutex_unlock(&mutex_jvc_config_json); - -#if 0 - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend(Not setconfigfile)\n"); -#endif - closesocket(cli_socket); - } -#endif - else if (strcmp(urlBuffer, "/sendyuv") == 0) - { - //printf("\n[web process]start 28\n"); - char *image_buff = NULL; - size_t image_buff_size = 0; - image_buff = malloc(CONTENT_BUFSIZE); - memset(image_buff, 0x00, CONTENT_BUFSIZE); - - char* pContent = contentBuffer; - char* pBlockEnd = contentBuffer; - //image_buff_size = nTotalContentLen; - //size_t nbytes = 0; - //size_t nTotalBytes = 0; - - int yuv_width = 0; - int yuv_height = 0; - char resolutionStr[10] = { 0 }; - char resolution[2][STRSPLIT_SIZE]={0}; - const char *del = "x"; - - char* pYUVStart = NULL; - char* pYUVEnd = NULL; - //int nNeedUpdateTrafficLightZone = 0; - for (int i = 0; i < nTotalContentLen; i++) - { - pContent = contentBuffer + i; - if (strncmp(pContent, MSG_RESOLUTION_PATTERN, strlen(MSG_RESOLUTION_PATTERN)) == 0) - { - pBlockEnd = strstr(pContent, "\r\n"); - pYUVStart = pBlockEnd + 2; - //DumpHex(pYUVStart, 320); - memcpy(resolutionStr, pContent + strlen(MSG_RESOLUTION_PATTERN), pBlockEnd - (pContent + strlen(MSG_RESOLUTION_PATTERN))); - if (strlen(resolutionStr) > 0) - { - //if (abs(viewChannelData[tracking_channel_idx].tab_view_width_ratio * viewChannelData[tracking_channel_idx].tab_view_width - AIImage_width) > 5) - //nNeedUpdateTrafficLightZone = 1; - StrSplit(resolutionStr, resolution, del); - //printf("\n------UU:36\n"); - yuv_width = atoi(resolution[0]); - yuv_height = atoi(resolution[1]); - viewChannelData[tracking_channel_idx].tab_view_width_ratio = (float)yuv_width / viewChannelData[tracking_channel_idx].tab_view_width; - viewChannelData[tracking_channel_idx].tab_view_height_ratio = (float)yuv_height / viewChannelData[tracking_channel_idx].tab_view_height; - #ifdef GY_OS_WIN - if (nNeedUpdateTrafficLightZone) - UpdateTrafficLightZone(tracking_channel_idx); - #endif - } - break; - } - /*else if (strncmp(pContent, MSG_END_PATTERN, strlen(MSG_END_PATTERN)) == 0) - { - pYUVEnd = pContent; - break; - }*/ - } - - for (int i = nTotalContentLen - strlen(MSG_END_PATTERN); i < nTotalContentLen; i++) - { - pContent = contentBuffer + i; - if (strncmp(pContent, MSG_END_PATTERN, strlen(MSG_END_PATTERN)) == 0) - { - pYUVEnd = pContent; - break; - } - } - - image_buff_size = pYUVEnd - pYUVStart; - memcpy(image_buff, pYUVStart, image_buff_size); - - if (!pYUVStart || !pYUVEnd) - { - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "Error YUV format."); - printf("%s\n", msg); - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend\n"); - //printf("\n[web process]-A-6: free(contentBuffer)\n"); - if (contentBuffer) { - free(contentBuffer); - contentBuffer = NULL; - } - if (image_buff) { - free(image_buff); - image_buff = NULL; - } - - //printf("\n[web process]-A-6: closesocket(cli_socket): %d\n", cli_socket); - closesocket(cli_socket); - return; - } - - clock_t t2 = clock(); - diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); - //printf("pre AI recog time: %f\n", diff); - /*int local_tracking_idx = 0; - int b_nav_channel_exist = 0; - for (int i = 0; i <= MAX_CLIENT_SOCKET; i++) - { - if (g_TrackingIDAndChannel[i][1] == nav_tracking_channel) - { - local_tracking_idx = i; - b_nav_channel_exist = 1; - break; - } - } - - if (!b_nav_channel_exist) - { - local_tracking_idx = tracking_idx; - memset(g_TrackingIDAndChannel[local_tracking_idx], 0x00, sizeof(g_TrackingIDAndChannel[local_tracking_idx])); - g_TrackingIDAndChannel[local_tracking_idx][1] = nav_tracking_channel; - }*/ - - socketRecords[sock_info_idx].channel_id = tracking_channel; - - clock_t c1 = clock(); - - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\nweb process: %d\n", 2); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"); - - clock_t c2 = clock(); - double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); - printf("recognition time %d:%f\n", cli_socket, dDiff); - - if (image_buff) { - free(image_buff); - image_buff = NULL; - } - } -#if 0 - else if (strncmp(urlBuffer, "/user_command", strlen("/user_command")) == 0) - { - //printf("\n[web process]start 29\n"); - //char *start = NULL; - char *pDelim = NULL; - QueueInfo q_info = { 0 }; - MapClear(); - char CorrectParameter[MAX_MSG_LEN * 2] = { 0 }; - char* pContent = contentBuffer + strlen(MSG_START_PATTERN); - printf("recv /user_command : %s\n", pContent); - //start = contentBuffer + 2; - do { - pDelim = strstr(pContent, "\r\n"); - // string between start and delim (or end of string if delim is NULL). - if (pDelim) - { - char attribute[512] = { 0 };//512 - memset(attribute, 0x00, sizeof(attribute)); - //memset(OriAttribute, 0x00, sizeof(OriAttribute)); - memcpy(attribute, pContent, pDelim - pContent); - //memcpy(OriAttribute, pContent, pDelim - pContent); - memset(CorrectParameter, 0x00, sizeof(CorrectParameter)); - attribute[pDelim - pContent] = 0; - char att_var[10][STRSPLIT_SIZE]={0}; - char *del = "="; - int att_var_num = 0; - if (attribute) - { - att_var_num = StrSplit(attribute, att_var, del); - if (att_var_num == 2) - { - sprintf(CorrectParameter, "%s", att_var[1]); - } - if (att_var_num > 2) - { - for (int n = 1; n < att_var_num; n++) - { - if (n == 1) - sprintf(CorrectParameter, "%s", att_var[1]); - else - sprintf(CorrectParameter, "%s%s%s", CorrectParameter, del, att_var[n]); - } - } - int anpr_ch = -1; - - if (strcmp(att_var[0], "") == 0) - anpr_ch = atoi(att_var[1]); - - if (anpr_ch != -1) - { - //char filename[] = "config.json"; - char *filename = configPATH; - char *fileBuf = ReadAllBytes(filename); - if (fileBuf) { - cJSON* root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (root) { - cJSON* view_setting = cJSON_GetObjectItem(root, "view_setting"); - - char CameraID[20] = { 0 }; - sprintf(CameraID, "camera%02d", anpr_ch + 1); - cJSON* camera = cJSON_GetObjectItem(view_setting, CameraID); - - if (strcmp(att_var[0], "") == 0) - { - if (strcmp(att_var[1], "1") == 0) - { - viewChannelData[anpr_ch].channel_idx = 1; - } - if (strcmp(att_var[1], "0") == 0) - { - viewChannelData[anpr_ch].channel_idx = 0; - } - - cJSON_ReplaceItemInObject(camera, "enable_anpr", cJSON_CreateString(att_var[1])); - } - if (strcmp(att_var[0], "") == 0) - { - strcpy(viewChannelData[anpr_ch].confidence, att_var[1]); - cJSON_ReplaceItemInObject(camera, "confidence", cJSON_CreateString(att_var[1])); - } - if (strcmp(att_var[0], "") == 0) - { - strcpy(viewChannelData[anpr_ch].min_characters, att_var[1]); - cJSON_ReplaceItemInObject(camera, "min_characters", cJSON_CreateString(att_var[1])); - } - if (strcmp(att_var[0], "") == 0) - { - strcpy(viewChannelData[anpr_ch].max_characters, att_var[1]); - cJSON_ReplaceItemInObject(camera, "max_characters", cJSON_CreateString(att_var[1])); - } - - char* JsonString = cJSON_Print(root); - FILE *fp; - - if ((fp = fopen(filename, "w")) != NULL) - { - fprintf(fp, JsonString); - fclose(fp); - - //copy config.json to config_bak.json - CopyFileTo(filename, config_bakPATH); - } - else - printf("Fail to open Config.json \n"); - - if (JsonString != NULL) - { - free(JsonString); - JsonString = NULL; - } - - if (root) { - cJSON_Delete(root); - root = NULL; - } - } - } - } - - if (strcmp(att_var[0], "") == 0) - { - activePostNotification = atoi(att_var[1]) > 0 ? _TRUE : _FALSE; - { - //char filename[] = "config.json"; - char *filename = configPATH; - char *fileBuf = ReadAllBytes(filename); - if (fileBuf) { - //cJSON* cam_ip, * http_port, * vedio_port, * cam_username, * cam_pwd, * channel_id; - cJSON *camera, *camera_name, *obj_max_proportion, *obj_min_proportion, *tab_view_size, *enable_lpr_db, *count_zone, *enable_anpr, *enable_traffic, *enable_logo, *temp_detection_zone, *detect, - *levenshtein_distance, *min_characters, *max_characters, *confidence, *confidence2, *confidence3, *confidence4, *enable_traffic_light, *detection_time, *metadata1, *metadata2, *metadata_stop, *link_to_counter, - *enable_direction1, *enable_direction2, *direction1, *direction2, *no_parking_time,*no_parking_time_in_minute, *queuing_count, *trigger_events[MAX_TRIGGER_EVENT], *checked, *detect_event_id, *detect_event_name, *post_event_name, *counter_name,*counter_cust_name, *counter_increment, - *point_num, - *x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4, *x5, *y5, *x6, *y6; - cJSON* root = cJSON_Parse(fileBuf); - - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (root) { - - cJSON* view_setting = cJSON_GetObjectItem(root, "view_setting"); - - for (int n = 0; n < MAX_AI_ENGINE_VIEW; n++) - { - char CameraID[20] = { 0 }; - sprintf(CameraID, "camera%02d", n + 1); - camera = cJSON_GetObjectItem(view_setting, CameraID); - - /*cam_ip = cJSON_GetObjectItem(camera, "ip"); - http_port = cJSON_GetObjectItem(camera, "http_port"); - vedio_port = cJSON_GetObjectItem(camera, "vedio_port"); - cam_username = cJSON_GetObjectItem(camera, "username"); - cam_pwd = cJSON_GetObjectItem(camera, "password"); - channel_id = cJSON_GetObjectItem(camera, "channel_id");*/ - camera_name = cJSON_GetObjectItem(camera, "camera_name"); - obj_max_proportion = cJSON_GetObjectItem(camera, "obj_max_proportion"); - obj_min_proportion = cJSON_GetObjectItem(camera, "obj_min_proportion"); - levenshtein_distance = cJSON_GetObjectItem(camera, "levenshtein_distance"); - min_characters = cJSON_GetObjectItem(camera, "min_characters"); - max_characters = cJSON_GetObjectItem(camera, "max_characters"); - confidence = cJSON_GetObjectItem(camera, "confidence"); //Plate 車牌 - confidence2 = cJSON_GetObjectItem(camera, "confidence2"); //Traffic 交通 - confidence3 = cJSON_GetObjectItem(camera, "confidence3"); - confidence4 = cJSON_GetObjectItem(camera, "confidence4"); - enable_lpr_db = cJSON_GetObjectItem(camera, "enable_lpr_db"); - count_zone = cJSON_GetObjectItem(camera, "count_zone"); - - strcpy(viewChannelData[n].camera_name, camera_name->valuestring); - strcpy(viewChannelData[n].obj_max_proportion, obj_max_proportion->valuestring); - strcpy(viewChannelData[n].obj_min_proportion, obj_min_proportion->valuestring); - - strcpy(viewChannelData[n].levenshtein_distance, levenshtein_distance->valuestring); - strcpy(viewChannelData[n].min_characters, min_characters->valuestring); - strcpy(viewChannelData[n].max_characters, max_characters->valuestring); - strcpy(viewChannelData[n].confidence, confidence->valuestring); - strcpy(viewChannelData[n].confidence2, confidence2->valuestring); - strcpy(viewChannelData[n].confidence3, confidence3->valuestring); - strcpy(viewChannelData[n].confidence4, confidence4->valuestring); - - strcpy(viewChannelData[n].enable_lpr_db, enable_lpr_db->valuestring); - viewChannelData[n].count_zone = count_zone->valueint; - - tab_view_size = cJSON_GetObjectItem(camera, "tab_view_size"); - //printf("\n[web process]tab_view_size: %s\n", tab_view_size->valuestring); - char temp_tab[50] = { 0 }; - strcpy(temp_tab, tab_view_size->valuestring); - char outArray[2][STRSPLIT_SIZE]={0}; - StrSplit(temp_tab, outArray, "x"); - //printf("\n------UU:37\n"); - viewChannelData[n].channel_idx = n; - - viewChannelData[n].tab_view_width = atoi(outArray[0]); - viewChannelData[n].tab_view_height = atoi(outArray[1]); - - enable_anpr = cJSON_GetObjectItem(camera, "enable_anpr"); - if (strcmp(enable_anpr->valuestring, "Yes") == 0) - viewChannelData[n].enable_anpr = 1; - else - viewChannelData[n].enable_anpr = 0; - - enable_traffic = cJSON_GetObjectItem(camera, "enable_traffic"); - if (strcmp(enable_traffic->valuestring, "Yes") == 0) - viewChannelData[n].enable_traffic = 1; - else - viewChannelData[n].enable_traffic = 0; - - enable_logo = cJSON_GetObjectItem(camera, "enable_logo"); - if (strcmp(enable_logo->valuestring, "Yes") == 0) - viewChannelData[n].enable_logo = 1; - else - viewChannelData[n].enable_logo = 0; - - - temp_detection_zone = cJSON_GetObjectItem(camera, "detection_zone"); - viewChannelData[n].enable_traffic_light_zone = 0; - int i = 0; - cJSON_ArrayForEach(detect, temp_detection_zone) - { - /*levenshtein_distance = cJSON_GetObjectItem(detect, "levenshtein_distance"); - min_characters = cJSON_GetObjectItem(detect, "min_characters"); - max_characters = cJSON_GetObjectItem(detect, "max_characters"); - confidence = cJSON_GetObjectItem(detect, "confidence");*/ - enable_traffic_light = cJSON_GetObjectItem(detect, "enable_traffic_light"); - detection_time = cJSON_GetObjectItem(detect, "detection_time"); - metadata1 = cJSON_GetObjectItem(detect, "metadata1"); - metadata2 = cJSON_GetObjectItem(detect, "metadata2"); - metadata_stop = cJSON_GetObjectItem(detect, "metadata_stop"); - link_to_counter = cJSON_GetObjectItem(detect, "link_to_counter"); - enable_direction1 = cJSON_GetObjectItem(detect, "enable_direction1"); - enable_direction2 = cJSON_GetObjectItem(detect, "enable_direction2"); - direction1 = cJSON_GetObjectItem(detect, "direction1"); - direction2 = cJSON_GetObjectItem(detect, "direction2"); - /*confidence3 = cJSON_GetObjectItem(detect, "confidence3");*/ - no_parking_time = cJSON_GetObjectItem(detect, "no_parking_time"); - no_parking_time_in_minute = cJSON_GetObjectItem(detect, "no_parking_time_in_minute"); - queuing_count = cJSON_GetObjectItem(detect, "queuing_count"); - trigger_events[i] = cJSON_GetObjectItem(detect, "trigger_events"); - - point_num = cJSON_GetObjectItem(detect, "point_number"); - - x1 = cJSON_GetObjectItem(detect, "x1"); - y1 = cJSON_GetObjectItem(detect, "y1"); - x2 = cJSON_GetObjectItem(detect, "x2"); - y2 = cJSON_GetObjectItem(detect, "y2"); - x3 = cJSON_GetObjectItem(detect, "x3"); - y3 = cJSON_GetObjectItem(detect, "y3"); - x4 = cJSON_GetObjectItem(detect, "x4"); - y4 = cJSON_GetObjectItem(detect, "y4"); - - x5 = cJSON_GetObjectItem(detect, "x5"); - y5 = cJSON_GetObjectItem(detect, "y5"); - x6 = cJSON_GetObjectItem(detect, "x6"); - y6 = cJSON_GetObjectItem(detect, "y6"); - - /*strcpy(viewDetectionZone[n][i].levenshtein_distance, levenshtein_distance->valuestring); - strcpy(viewDetectionZone[n][i].min_characters, min_characters->valuestring); - strcpy(viewDetectionZone[n][i].max_characters, max_characters->valuestring); - strcpy(viewDetectionZone[n][i].confidence, confidence->valuestring);*/ - strcpy(viewDetectionZone[n][i].detection_time, detection_time->valuestring); - strcpy(viewDetectionZone[n][i].metadata1, metadata1->valuestring); - strcpy(viewDetectionZone[n][i].metadata2, metadata2->valuestring); - if(metadata_stop) - strcpy(viewDetectionZone[n][i].metadata_stop, metadata_stop->valuestring); - strcpy(viewDetectionZone[n][i].link_to_counter, link_to_counter->valuestring); - strcpy(viewDetectionZone[n][i].enable_direction1, enable_direction1->valuestring); - strcpy(viewDetectionZone[n][i].enable_direction2, enable_direction2->valuestring); - strcpy(viewDetectionZone[n][i].direction1, direction1->valuestring); - strcpy(viewDetectionZone[n][i].direction2, direction2->valuestring); - if (no_parking_time) - viewDetectionZone[n][i].no_parking_time = atoi(no_parking_time->valuestring); - if (no_parking_time_in_minute) - viewDetectionZone[n][i].no_parking_time_in_minute = atoi(no_parking_time_in_minute->valuestring); - - if (queuing_count) - viewDetectionZone[n][i].queuing_count = atoi(queuing_count->valuestring); - /*strcpy(viewDetectionZone[n][i].confidence3, confidence3->valuestring);*/ - - if (point_num) - viewDetectionZone[n][i].point_num = point_num->valueint; - - viewDetectionZone[n][i].Points[0].x = x1->valueint; - viewDetectionZone[n][i].Points[0].y = y1->valueint; - viewDetectionZone[n][i].Points[1].x = x2->valueint; - viewDetectionZone[n][i].Points[1].y = y2->valueint; - viewDetectionZone[n][i].Points[2].x = x3->valueint; - viewDetectionZone[n][i].Points[2].y = y3->valueint; - viewDetectionZone[n][i].Points[3].x = x4->valueint; - viewDetectionZone[n][i].Points[3].y = y4->valueint; - - viewDetectionZone[n][i].onvif_Points[0].x = X_Tranform_To_Onvif_Space((float)x1->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[0].y = Y_Tranform_To_Onvif_Space((float)y1->valueint, CANVAS_HEIGHT / 2); - viewDetectionZone[n][i].onvif_Points[1].x = X_Tranform_To_Onvif_Space((float)x2->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[1].y = Y_Tranform_To_Onvif_Space((float)y2->valueint, CANVAS_HEIGHT / 2); - viewDetectionZone[n][i].onvif_Points[2].x = X_Tranform_To_Onvif_Space((float)x3->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[2].y = Y_Tranform_To_Onvif_Space((float)y3->valueint, CANVAS_HEIGHT / 2); - viewDetectionZone[n][i].onvif_Points[3].x = X_Tranform_To_Onvif_Space((float)x4->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[3].y = Y_Tranform_To_Onvif_Space((float)y4->valueint, CANVAS_HEIGHT / 2); - - if (x5 && x6) - { - viewDetectionZone[n][i].Points[4].x = x5->valueint; - viewDetectionZone[n][i].Points[4].y = y5->valueint; - viewDetectionZone[n][i].Points[5].x = x6->valueint; - viewDetectionZone[n][i].Points[5].y = y6->valueint; - - viewDetectionZone[n][i].onvif_Points[4].x = X_Tranform_To_Onvif_Space((float)x5->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[4].y = Y_Tranform_To_Onvif_Space((float)y5->valueint, CANVAS_HEIGHT / 2); - viewDetectionZone[n][i].onvif_Points[5].x = X_Tranform_To_Onvif_Space((float)x6->valueint, CANVAS_WIDTH / 2); - viewDetectionZone[n][i].onvif_Points[5].y = Y_Tranform_To_Onvif_Space((float)y6->valueint, CANVAS_HEIGHT / 2); - } - - strcpy(viewDetectionZone[n][i].enable_traffic_light, enable_traffic_light->valuestring); - if (strncmp(viewDetectionZone[n][i].enable_traffic_light, "Yes", strlen("Yes")) == 0) - { - viewChannelData[n].enable_traffic_light_zone = i + 1; -#ifdef GY_OS_WIN - UpdateTrafficLightZone(n); -#endif - } - i++; - - if (i < MAX_DETECTION_ZONE) { - - } - else { - break; - } - } - - //int arraySize = cJSON_GetArraySize(temp_detection_zone); - int k = 0; - for (int j = 0; j < MAX_DETECTION_ZONE; j++) - { - k = 0; - cJSON_ArrayForEach(detect, trigger_events[j]) - { - checked = cJSON_GetObjectItem(detect, "checked"); - detect_event_id = cJSON_GetObjectItem(detect, "detect_event_id"); - detect_event_name = cJSON_GetObjectItem(detect, "detect_event_name"); - post_event_name = cJSON_GetObjectItem(detect, "post_event_name"); - counter_name = cJSON_GetObjectItem(detect, "counter_name"); - counter_increment = cJSON_GetObjectItem(detect, "counter_increment"); - - viewDetectionZone[n][j].trigger_event[k].checked = checked->valueint; - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_id, detect_event_id->valuestring); - strcpy(viewDetectionZone[n][j].trigger_event[k].detect_event_name, detect_event_name->valuestring); - strcpy(viewDetectionZone[n][j].trigger_event[k].post_event_name, post_event_name->valuestring); - strcpy(viewDetectionZone[n][j].trigger_event[k].counter_name, counter_name->valuestring); - - if (counter_increment) { - if (strcmp(counter_increment->valuestring, "counter_increment_add") == 0) - viewDetectionZone[n][j].trigger_event[k].counter_increment = 1; - else if (strcmp(counter_increment->valuestring, "counter_increment_minus") == 0) - viewDetectionZone[n][j].trigger_event[k].counter_increment = -1; - else if (strcmp(counter_increment->valuestring, "counter_increment_equal") == 0) - viewDetectionZone[n][j].trigger_event[k].counter_increment = 0; - else - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - } - else - viewDetectionZone[n][j].trigger_event[k].counter_increment = -2; - k++; - } - } - } - if (root) { - cJSON_Delete(root); - root = NULL; - } - } - } - } - //break; - } - - if (strcmp(att_var[0], "") == 0) - { - //post events setting - //char filename2[] = "events.json"; - char *filename2 = eventsPATH; - if (!FileExist(filename2)) - { - printf("%s doesn't exist.\n", filename2); - printf("Press any key to exit...\n"); - getchar(); - //printf("\n[web process]-A-7: closesocket(cli_socket): %d\n", cli_socket); - closesocket(cli_socket); - return; - } - - char* fileBuf = ReadAllBytes(filename2); - if (fileBuf) { - - cJSON *n_root, *notification, *events_default_version, *enable_post,*enable_snmp_post, *detect2, *http_post_events, *post_protocol, *post_event_method, *post_event_name2, *post_host_ip, *post_host_port, *post_url, *post_username, *post_password, *post_content; - cJSON *enable_only_once_to_post, *enable_obj_once_to_post, *enable_location_once_to_post,*enable_nvr_once_to_getalarmmotion, *enable_8592_once_to_getalarmmotion,*heatmap_max, *enable_heatmap, *heatmap_frequency,*lpr_title,*enable_counter_snap, *enable_barcode_qr, - *enable_check_ptz_start_autotracking,*enable_check_ptz_end_autotracking,*ptz_start_autotracking_link_to_post_event_name,*ptz_end_autotracking_link_to_post_event_name; - - n_root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - - if (n_root) { - notification = cJSON_GetObjectItem(n_root, "notification"); - events_default_version = cJSON_GetObjectItem(notification, "events_default_version"); - enable_post = cJSON_GetObjectItem(notification, "enable_post"); - enable_snmp_post = cJSON_GetObjectItem(notification, "enable_snmp_post"); - - enable_check_ptz_start_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_start_autotracking"); - enable_check_ptz_end_autotracking = cJSON_GetObjectItem(notification, "enable_check_ptz_end_autotracking"); - ptz_start_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_start_autotracking_link_to_post_event_name"); - ptz_end_autotracking_link_to_post_event_name = cJSON_GetObjectItem(notification, "ptz_end_autotracking_link_to_post_event_name"); - - enable_only_once_to_post = cJSON_GetObjectItem(notification, "enable_only_once_to_post"); - enable_obj_once_to_post = cJSON_GetObjectItem(notification, "enable_obj_once_to_post"); - enable_location_once_to_post = cJSON_GetObjectItem(notification, "enable_location_once_to_post"); - enable_nvr_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_nvr_once_to_getalarmmotion"); - enable_8592_once_to_getalarmmotion = cJSON_GetObjectItem(notification, "enable_8592_once_to_getalarmmotion"); - - http_post_events = cJSON_GetObjectItem(notification, "http_post_events"); - heatmap_max = cJSON_GetObjectItem(notification, "heatmap_max"); - enable_heatmap = cJSON_GetObjectItem(notification, "enable_heatmap"); - heatmap_frequency = cJSON_GetObjectItem(notification, "heatmap_frequency"); - lpr_title = cJSON_GetObjectItem(notification, "lpr_title"); - enable_counter_snap = cJSON_GetObjectItem(notification, "enable_counter_snap"); - enable_barcode_qr = cJSON_GetObjectItem(notification, "enable_barcode_qr"); - - int i = 0; - cJSON_ArrayForEach(detect2, http_post_events) - { - post_protocol = cJSON_GetObjectItem(detect2, "post_protocol"); - post_event_method = cJSON_GetObjectItem(detect2, "post_event_method"); - post_event_name2 = cJSON_GetObjectItem(detect2, "post_event_name"); - post_host_ip = cJSON_GetObjectItem(detect2, "post_host_ip"); - post_host_port = cJSON_GetObjectItem(detect2, "post_host_port"); - post_url = cJSON_GetObjectItem(detect2, "post_url"); - post_username = cJSON_GetObjectItem(detect2, "post_username"); - post_password = cJSON_GetObjectItem(detect2, "post_password"); - post_content = cJSON_GetObjectItem(detect2, "post_content"); - - strcpy(postEventList[i].post_protocol, post_protocol->valuestring); - strcpy(postEventList[i].post_event_method, post_event_method->valuestring); - strcpy(postEventList[i].post_event_name, post_event_name2->valuestring); - strcpy(postEventList[i].post_host_ip, post_host_ip->valuestring); - strcpy(postEventList[i].post_host_port, post_host_port->valuestring); - strcpy(postEventList[i].post_url, post_url->valuestring); - strcpy(postEventList[i].post_username, post_username->valuestring); - strcpy(postEventList[i].post_password, post_password->valuestring); - strcpy(postEventList[i].post_content, post_content->valuestring); - i++; - } - - cJSON *event_counter_setting, *detect3, *event_counters, *counter_name,*counter_cust_name, *counter_unit, *enable_reset_time_interval, *reset_value, *reset_time_interval, *reset_at, *enable_time_range, *time_range_from, *time_range_to; - -#ifdef GY_OS_V_SERIES - -#else - event_counter_setting = cJSON_GetObjectItem(n_root, "event_counter_setting"); - event_counters = cJSON_GetObjectItem(event_counter_setting, "event_counters"); - - i = 0; - cJSON_ArrayForEach(detect3, event_counters) - { - counter_name = cJSON_GetObjectItem(detect3, "counter_name"); - counter_cust_name = cJSON_GetObjectItem(detect3, "counter_cust_name"); - counter_unit = cJSON_GetObjectItem(detect3, "counter_unit"); - reset_value = cJSON_GetObjectItem(detect3, "reset_value"); - enable_reset_time_interval = cJSON_GetObjectItem(detect3, "enable_reset_time_interval"); - reset_time_interval = cJSON_GetObjectItem(detect3, "reset_time_interval"); - reset_at = cJSON_GetObjectItem(detect3, "reset_at"); - enable_time_range = cJSON_GetObjectItem(detect3, "enable_time_range"); - time_range_from = cJSON_GetObjectItem(detect3, "time_range_from"); - time_range_to = cJSON_GetObjectItem(detect3, "time_range_to"); - - strcpy(eventCounterList[i].counter_name, counter_name->valuestring); - strcpy(eventCounterList[i].counter_cust_name, counter_cust_name->valuestring); - strcpy(eventCounterList[i].counter_unit, counter_unit->valuestring); - if (reset_value->valuestring) - eventCounterList[i].reset_value = atoi(reset_value->valuestring); - else - eventCounterList[i].reset_value = 0; - strcpy(eventCounterList[i].enable_reset_time_interval, enable_reset_time_interval->valuestring); - strcpy(eventCounterList[i].reset_time_interval, reset_time_interval->valuestring); - strcpy(eventCounterList[i].reset_at, reset_at->valuestring); - strcpy(eventCounterList[i].enable_time_range, enable_time_range->valuestring); - strcpy(eventCounterList[i].time_range_from, time_range_from->valuestring); - strcpy(eventCounterList[i].time_range_to, time_range_to->valuestring); - struct tm tm; - strptime_c(eventCounterList[i].reset_at, "%Y-%m-%d %H:%M:%S", &tm); - eventCounterList[i].timetResetAt = mktime(&tm); - struct tm *resetTime = localtime(&eventCounterList[i].timetResetAt); - eventCounterList[i].reset_month = resetTime->tm_mon; - eventCounterList[i].reset_month_day = resetTime->tm_mday; - eventCounterList[i].reset_week_day = resetTime->tm_wday; - eventCounterList[i].reset_hour = resetTime->tm_hour; - eventCounterList[i].reset_min = resetTime->tm_min; - eventCounterList[i].reset_sec = resetTime->tm_sec; - strptime_c(eventCounterList[i].time_range_from, "%Y-%m-%d %H:%M:%S", &tm); - eventCounterList[i].timetTimeRangeFrom = mktime(&tm); - strptime_c(eventCounterList[i].time_range_to, "%Y-%m-%d %H:%M:%S", &tm); - eventCounterList[i].timetTimeRangeTo = mktime(&tm); - i++; - } -#endif - - if (n_root) { - cJSON_Delete(n_root); - n_root = NULL; - } - } - } - } - - if (strcmp(att_var[0], "") == 0) - { - if (strcmp(att_var[1], "1 dash") == 0) - activeDisplayDash = _TRUE; - - if (strcmp(att_var[1], "0 dash") == 0) - activeDisplayDash = _FALSE; - - if (strcmp(att_var[1], "1 properties") == 0) - activeDisplayProperties = _TRUE; - - if (strcmp(att_var[1], "0 properties") == 0) - activeDisplayProperties = _FALSE; - } - - //test http notification - if (strcmp(att_var[0], "") == 0) - { - testPostNotification = _TRUE; - strcpy(q_info.post_method, CorrectParameter); - } - - //if (strcmp(att_var[0], "") == 0) - //strcpy(q_info.post_name, CorrectParameter); - - if (strcmp(att_var[0], "") == 0) - strcpy(q_info.host_name, CorrectParameter); - - if (strcmp(att_var[0], "") == 0) - strcpy(q_info.host_port, CorrectParameter); - - if (strcmp(att_var[0], "") == 0) - { - //strcpy(q_info.post_url, OriAttribute + strlen("=")); - strcpy(q_info.post_url, CorrectParameter); - } - - if (strcmp(att_var[0], "") == 0) - strcpy(q_info.post_username, CorrectParameter); - - if (strcmp(att_var[0], "") == 0) - strcpy(q_info.post_password, CorrectParameter); - - if (strcmp(att_var[0], "") == 0) - { - strcpy(q_info.content, CorrectParameter); - } - - /*char Value[MAX_MSG_LEN] = { 0 }; - MapFind("", Value); - printf("%s",Value);*/ - } - pContent = pDelim + 2; // Use length of your b string. - } - } - while (pDelim); - - if (testPostNotification) - { - //pthread_mutex_lock(&mutex_post_notification); - if (!q_info.content) - { - memset(q_info.content, 0x00, strlen(pContent) + 1); - } - q_info.image_buff = NULL; //20201105 sophia add - q_info.image_buff_size = 0; - //q_info.pNext = malloc(sizeof(detection_pos)); - if (AI_fps >= 1) - QueuePush(q_info, _POST_NOTIFICATION); - //pthread_mutex_unlock(&mutex_post_notification); - testPostNotification = _FALSE; - } - } -#endif - else if (strncmp(urlBuffer, "/import_lpr_map_list", strlen("/import_lpr_map_list")) == 0) - { -#ifdef GY_OS_AMBA - //printf("\n[web process]start 30\n"); - char *image_buff = NULL; - //int image_buff_size = 0; - image_buff = malloc(CONTENT_BUFSIZE); - //char httpVariables[BUFSIZE_V2] = { 0 }; - //char boundary[255] = {0}; - char *cp = NULL; - char *tempPtr = NULL; - if ((cp = strstr( headerBuffer, "boundary=" )) != NULL) - { - int strlen =0; - tempPtr = cp + 9; - cp = strstr(tempPtr, "\r\n"); - if (cp != NULL) - { - strlen = cp - tempPtr; - if (strlen > 0) - { - memset(multiPartBoundary, 0, sizeof(multiPartBoundary)); - //char endStr[] = "--"; - strncpy(multiPartBoundary, tempPtr, strlen); - //strcat(multiPartBoundary,endStr); - } - } - } - - if (bIsMultipart) - { - char* pContent = contentBuffer; - char* pBlockStart = contentBuffer; - //image_buff_size = nTotalContentLen; - memset(image_buff, 0x00, CONTENT_BUFSIZE); - size_t nbytes = 0; - size_t nTotalBytes = 0; - - for (int i = 0; i < nTotalContentLen; i++) - { - pContent = contentBuffer + i; - if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) - { - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - i += (pBlockStart - pContent - 1); - } - else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) - { - pBlockStart = strstr(pContent, "\r\n\r\n"); - pBlockStart += 4; - i += (pBlockStart - pContent - 1); - } - else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) - { - if (pContent - pBlockStart == 0) - nbytes = pContent - pBlockStart; - else if (pContent - pBlockStart > 0) - nbytes = (pContent - pBlockStart) - strlen("\r\n"); - memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); - nTotalBytes += nbytes; - if (nbytes != 0)//find end of boundary - { - char endStr[] = "--"; - pBlockStart = strstr(pContent, endStr); - pBlockStart += 2; - }else - { - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - } - - i += (pBlockStart - pContent - 1); - - } - - } - } - if (!((image_buff[0]== 0xef) && (image_buff[1]== 0xbb) && (image_buff[2]== 0xbf))) - { - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "file type error."); - printf("%s\n", msg); - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend\n"); - } - else - { - int map_length = 0; - char *lpr_data_p = NULL; - char *lpr_line_data = NULL,*value = NULL; - int lpr_len = 0; - int nlen; - char *lpr_detect = NULL; - char *lpr_plate = NULL; - char *lpr_line_end = NULL; - callback_reset_db_map_list(); //clean mapping table - lpr_data_p = image_buff + 3;// 0xEF 0xBB 0xBF utf8 with BOM - lpr_line_data=lpr_data_p; - nlen = strlen(lpr_data_p); - lpr_line_end = strstr(lpr_data_p, "\r\n"); - if (lpr_line_end == NULL) - lpr_line_end = strstr(lpr_data_p, "\n"); - if (lpr_line_end != NULL) - { - lpr_len = lpr_line_end - lpr_line_data; - } - - for (lpr_line_data = lpr_data_p; lpr_line_data < (lpr_data_p + nlen);) - { - value = lpr_line_data; - - if(map_length == COUNT_MAPPING) - break; - for (lpr_line_data += lpr_len; lpr_line_data < (lpr_data_p + nlen) && (!lpr_line_data[0]||(lpr_line_data[0]=='\r')||(lpr_line_data[0]=='\n')); lpr_line_data++); - lpr_detect = strsep(&value, ","); - if ((lpr_plate = strsep(&value, "\r\n"))==NULL) - lpr_plate = strsep(&value, "\n"); - if ((lpr_detect != NULL) && (lpr_plate != NULL)) - { - lpr_plate = rtrim(lpr_plate); - action_import_lpr_map_info( lpr_detect, lpr_plate); - map_length++; - } - - lpr_line_end = strstr(lpr_line_data, "\r\n"); - if (lpr_line_end == NULL) - lpr_line_end = strstr(lpr_line_data, "\n"); - if (lpr_line_end != NULL) - { - lpr_len = lpr_line_end - lpr_line_data; - } - } - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "lpr map file upload ok."); - printf("%s\n", msg); - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend\n"); - } - - //AI recognizing process - clock_t c1 = clock(); - ///Steven MARK TEMP - /* - printf("\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); - printf("\nweb process: %d\n", 3); - printf("\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");*/ - - clock_t c2 = clock(); - double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); - printf("recognition time %d:%f\n", cli_socket, dDiff); - if (image_buff) { - free(image_buff); - image_buff = NULL; - } -#endif //#ifdef GY_OS_AMBA - } - else if (strncmp(urlBuffer, "/import_lpr_list", strlen("/import_lpr_list")) == 0) - { - //printf("\n-------------import lpr list\n"); -#if defined GY_OS_AMBA || defined GY_OS_NOVA - g_count_lpr_insert_times = 0; - - memset(g_headerBuffer,0x00, BUFSIZE_V2); - memset(g_multiPartBoundary, 0x00, MAX_MSG_LEN); - memset(g_contentBuffer, 0x00, CONTENT_BUFSIZE); - - strcpy(g_headerBuffer, headerBuffer); - strcpy(g_multiPartBoundary, multiPartBoundary); - g_bIsMultipart = bIsMultipart; - strcpy(g_contentBuffer, contentBuffer); - g_nTotalContentLen = nTotalContentLen; - - //printf("\n-----g_contentBuffer:%s\n", g_contentBuffer); - - pthread_t import_lpr_list_file_thread_id; - if (pthread_create(&import_lpr_list_file_thread_id, 0, import_lpr_list_file_thread, NULL)) - { - printf("create import_lpr_list_file_thread thread faile \n"); - } - - strcpy(beforeSendBuffer, ""); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend\n"); - -#endif - closesocket(cli_socket); - } -#if 0 - else if (strncmp(urlBuffer, "/import_radarbg", strlen("/import_radarbg")) == 0) // a113n 10/6 - { - pthread_mutex_lock(&mutex_web); - // copy from /sendjpeg - { - char *image_buff = NULL; - int image_buff_size = 0; - image_buff = malloc(CONTENT_BUFSIZE); - //char httpVariables[BUFSIZE_V2] = {0}; - - int check_if_error = 0; - - if (bIsMultipart) - { - char *pContent = contentBuffer; - char *pBlockStart = contentBuffer; - image_buff_size = nTotalContentLen; - memset(image_buff, 0x00, CONTENT_BUFSIZE); - size_t nbytes = 0; - size_t nTotalBytes = 0; - - for (int i = 0; i < nTotalContentLen; i++) - { - pContent = contentBuffer + i; - if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) - { - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - i += (pBlockStart - pContent - 1); - } - else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) - { - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - i += (pBlockStart - pContent - 1); - } - else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) - { - if (pContent - pBlockStart == 0) - nbytes = pContent - pBlockStart; - else if (pContent - pBlockStart > 0) - nbytes = (pContent - pBlockStart) - strlen("\r\n"); - memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); - nTotalBytes += nbytes; - - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - i += (pBlockStart - pContent - 1); - } - } - char *pJpegStart = NULL; - char *pJpegEnd = NULL; - for (int i = 0; i < nTotalBytes; i++) - { - if (memcmp(image_buff + i, "\xFF\xD8", 2) == 0) - { - pJpegStart = image_buff + i; - break; - } - } - - for (int i = nTotalBytes; i > 0; i--) - { - if (memcmp(image_buff + i, "\xFF\xD9", 2) == 0) - { - pJpegEnd = image_buff + i + 2; - break; - } - } - - // printf("%x%x%x%x\n", *(image_buff + 0) & 0xff, *(image_buff + 1) & 0xff, *(image_buff + image_buff_size - 2) & 0xff, *(image_buff + image_buff_size -1) & 0xff); - - if (!pJpegStart || !pJpegEnd) - { - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "Error JPEG format(Multipart)."); - printf("%s\n", msg); - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_204, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend(Not JPEG format)\n"); - - // printf("\n[web process]-A-3: free(contentBuffer)\n"); - if (contentBuffer) - { - free(contentBuffer); - contentBuffer = NULL; - } - if (image_buff) - { - free(image_buff); - image_buff = NULL; - } - - check_if_error = 1; - // printf("\n[web process]-A-3: closesocket(client_socket): %d\n", cli_socket); - } - else - { - image_buff_size = pJpegEnd - pJpegStart; - memmove(image_buff, pJpegStart, image_buff_size); - - // printf("[%d]===>image_buff_size = %d \n", tracking_channel_idx, image_buff_size); - - memset(image_buff + image_buff_size, 0x00, nTotalBytes - image_buff_size); - } - } - else - { - image_buff_size = nTotalContentLen; - memcpy(image_buff, contentBuffer, image_buff_size); - // DumpHex(image_buff + image_buff_size - 10, 10); - } - - if (check_if_error == 0) { - if (!(memcmp(image_buff, "\xFF\xD8", 2) == 0 && memcmp(image_buff + image_buff_size - 2, "\xFF\xD9", 2) == 0)) - { - // DumpHex(image_buff, 2); - // DumpHex(image_buff + image_buff_size - 2, 2); - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "Error JPEG format."); - printf("%s\n", msg); - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend\n"); - // printf("\n[web process]-A-4: free(contentBuffer)\n"); - if (contentBuffer) - { - free(contentBuffer); - contentBuffer = NULL; - } - if (image_buff) - { - free(image_buff); - image_buff = NULL; - } - - // printf("\n[web process]-A-4: closesocket(cli_socket): %d\n", cli_socket); - } - else { - GetAIImageDimension(image_buff, image_buff_size, &AIImage_width, &AIImage_height); - - FILE *f = fopen("/emmc/plugin/Aida_data/radar/radar_user.jpg", "wb"); - if (f == NULL) - { - printf("Error opening file!\n"); - // exit(1); - } - fwrite(image_buff, image_buff_size, 1, f); - fclose(f); - - Reread_radarbg(); - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend\n"); - - if (image_buff) - { - free(image_buff); - image_buff = NULL; - } - } - } - } - closesocket(cli_socket); - pthread_mutex_unlock(&mutex_web); - } - else if (strncmp(urlBuffer, "/import_speedbg", strlen("/import_speedbg")) == 0) // 2022-11-03 Ken, thanks to a113n! - { - pthread_mutex_lock(&mutex_web); - // copy from /sendjpeg - { - char *image_buff = NULL; - int image_buff_size = 0; - image_buff = malloc(CONTENT_BUFSIZE); - //char httpVariables[BUFSIZE_V2] = {0}; - - int check_if_error = 0; - - if (bIsMultipart) - { - char *pContent = contentBuffer; - char *pBlockStart = contentBuffer; - image_buff_size = nTotalContentLen; - memset(image_buff, 0x00, CONTENT_BUFSIZE); - size_t nbytes = 0; - size_t nTotalBytes = 0; - - for (int i = 0; i < nTotalContentLen; i++) - { - pContent = contentBuffer + i; - if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) - { - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - i += (pBlockStart - pContent - 1); - } - else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) - { - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - i += (pBlockStart - pContent - 1); - } - else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) - { - if (pContent - pBlockStart == 0) - nbytes = pContent - pBlockStart; - else if (pContent - pBlockStart > 0) - nbytes = (pContent - pBlockStart) - strlen("\r\n"); - memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); - nTotalBytes += nbytes; - - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - i += (pBlockStart - pContent - 1); - } - } - char *pJpegStart = NULL; - char *pJpegEnd = NULL; - for (int i = 0; i < nTotalBytes; i++) - { - if (memcmp(image_buff + i, "\xFF\xD8", 2) == 0) - { - pJpegStart = image_buff + i; - break; - } - } - - for (int i = nTotalBytes; i > 0; i--) - { - if (memcmp(image_buff + i, "\xFF\xD9", 2) == 0) - { - pJpegEnd = image_buff + i + 2; - break; - } - } - - // printf("%x%x%x%x\n", *(image_buff + 0) & 0xff, *(image_buff + 1) & 0xff, *(image_buff + image_buff_size - 2) & 0xff, *(image_buff + image_buff_size -1) & 0xff); - - if (!pJpegStart || !pJpegEnd) - { - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "Error JPEG format(Multipart)."); - printf("%s\n", msg); - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_204, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend(Not JPEG format)\n"); - - // printf("\n[web process]-A-3: free(contentBuffer)\n"); - if (contentBuffer) - { - free(contentBuffer); - contentBuffer = NULL; - } - if (image_buff) - { - free(image_buff); - image_buff = NULL; - } - - check_if_error = 1; - // printf("\n[web process]-A-3: closesocket(client_socket): %d\n", cli_socket); - } - else - { - image_buff_size = pJpegEnd - pJpegStart; - memmove(image_buff, pJpegStart, image_buff_size); - - // printf("[%d]===>image_buff_size = %d \n", tracking_channel_idx, image_buff_size); - - memset(image_buff + image_buff_size, 0x00, nTotalBytes - image_buff_size); - } - } - else - { - image_buff_size = nTotalContentLen; - memcpy(image_buff, contentBuffer, image_buff_size); - // DumpHex(image_buff + image_buff_size - 10, 10); - } - - if (check_if_error == 0) { - if (!(memcmp(image_buff, "\xFF\xD8", 2) == 0 && memcmp(image_buff + image_buff_size - 2, "\xFF\xD9", 2) == 0)) - { - // DumpHex(image_buff, 2); - // DumpHex(image_buff + image_buff_size - 2, 2); - memset(msg, 0x00, sizeof(msg)); - sprintf(msg, "Error JPEG format."); - printf("%s\n", msg); - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend\n"); - // printf("\n[web process]-A-4: free(contentBuffer)\n"); - if (contentBuffer) - { - free(contentBuffer); - contentBuffer = NULL; - } - if (image_buff) - { - free(image_buff); - image_buff = NULL; - } - - // printf("\n[web process]-A-4: closesocket(cli_socket): %d\n", cli_socket); - } - else { - GetAIImageDimension(image_buff, image_buff_size, &AIImage_width, &AIImage_height); - - FILE *f = fopen("/emmc/plugin/Aida_data/radar/speed_user.jpg", "wb"); - if (f == NULL) - { - printf("Error opening file!\n"); - // exit(1); - } - fwrite(image_buff, image_buff_size, 1, f); - fclose(f); - - Reread_speedbg(); - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend\n"); - - if (image_buff) - { - free(image_buff); - image_buff = NULL; - } - - } - } - } - closesocket(cli_socket); - pthread_mutex_unlock(&mutex_web); - } -#endif - //printf("\n---------PP 1\n"); - } - // else if (strncmp(urlBuffer, "/import_radar_img", strlen("/import_radar_img")) == 0) // Ken 10-07 10-11 - // { - // #ifdef GY_OS_AMBA - - // memset(g_headerBuffer, 0x00, BUFSIZE_V2); - // memset(g_multiPartBoundary, 0x00, MAX_MSG_LEN); - // memset(g_contentBuffer, 0x00, CONTENT_BUFSIZE); - - // strcpy(g_headerBuffer, headerBuffer); - // strcpy(g_multiPartBoundary, multiPartBoundary); - // g_bIsMultipart = bIsMultipart; - // strcpy(g_contentBuffer, contentBuffer); - // g_nTotalContentLen = nTotalContentLen; - - // pthread_t import_lpr_list_file_thread_id; - // if (pthread_create(&import_lpr_list_file_thread_id, 0, import_lpr_list_file_thread, NULL)) - // { - // printf("create import_lpr_list_file_thread thread faile \n"); - // } - - // strcpy(beforeSendBuffer, ""); - // if (strlen(contentDescription) > 0) - // { - // strcat(beforeSendBuffer, " "); - // strcat(beforeSendBuffer, contentDescription); - // } - - // int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - // if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - // printf("\nsend\n"); - - // #endif - // closesocket(cli_socket); - // } - // } - - else - { - //printf("\n[web process]start 32\n"); - sprintf(msg, "URL not Found."); - printf(msg); - - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - if (strlen(contentDescription) > 0) - { - strcat(beforeSendBuffer, " "); - strcat(beforeSendBuffer, contentDescription); - } - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_404, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(cli_socket, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error #38\n"); - - //printf("\n[web process]-6: closesocket(cli_socket): %d\n", cli_socket); - closesocket(cli_socket); - } - //printf("\n---------PP 2\n"); - //printf("\nhellllo4\n"); -} - -/*int caculate_ftp_of_each_sockets(SOCKET sock, int *sock_record_idx) -{ - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - if (socketRecords[i].used == 1) { - if (socketRecords[i].sock == sock) - { - socketRecords[i].last_recv_time = time(0); - int idx_last_recv_time_min = 0; - time_t last_recv_time_min = 0; - *sock_record_idx = i; - //printf("last recv time=%I64d\n", socketRecords[i].last_recv_time); - for (int j = 0; j < FPS_AVG_SECS; j++) - { - if (socketRecords[i].recent_sec_data[j].recv_time == socketRecords[i].last_recv_time) - { - socketRecords[i].recent_sec_data[j].frames++; - break; - } - - if (socketRecords[i].recent_sec_data[j].recv_time <= socketRecords[i].last_recv_time - FPS_AVG_SECS) - { - socketRecords[i].recent_sec_data[j].frames = 0; - socketRecords[i].recent_sec_data[j].recv_time = 0; - } - - if (j == 0) - { - idx_last_recv_time_min = 0; - last_recv_time_min = socketRecords[i].recent_sec_data[j].recv_time; - } - else - { - if (socketRecords[i].recent_sec_data[j].recv_time < last_recv_time_min) - { - idx_last_recv_time_min = j; - last_recv_time_min = socketRecords[i].recent_sec_data[j].recv_time; - } - } - - if (j == FPS_AVG_SECS - 1) - { - socketRecords[i].recent_sec_data[idx_last_recv_time_min].frames = 1; - socketRecords[i].recent_sec_data[idx_last_recv_time_min].recv_time = socketRecords[i].last_recv_time; - } - } - return i; - } - } - } - return -1; -}*/ - -///Create this thread by run_http_server for each socket - -void sharkhand_s_connection_upgrade(int* sock,char *buffer,int* websocket_connected) { - - //if (0 == websocket_connected) - { - /*if ((*websocket_connected) == 0)*/ - { - //int count_sharkhand = 0; - int iIsWebsocketHybi00 = 0; - //while (sharkhand_s((*sock), buffer, &iIsWebsocketHybi00) < 0 && count_sharkhand < MAX_SHARKHAND_REPEAT) { - - sharkhand_s((*sock), buffer, &iIsWebsocketHybi00); - /* - while (sharkhand_s((*sock), buffer, websocket_connected) < 0 && count_sharkhand < MAX_SHARKHAND_REPEAT) { - //printf("\n[%d]build sharkhand - repeat: %d\n", sock, count_sharkhand); - count_sharkhand++; - usSleep(1000); - }*/ - - (*websocket_connected) = 1; - - /* - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - //printf("rA[%d]=%d, *sock=%d \n", i, socketRecords[i].sock, *sock); - if (socketRecords[i].sock == *sock) - { - //socketRecords[i].iIsWebsocketHybi00 = iIsWebsocketHybi00; - //printf("idx[%d]xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx is hybi00: %d \n", i, socketRecords[i].iIsWebsocketHybi00); - } - - }*/ - } - } - -} - -static int is_authorized_run_preload_http_server = 1; -//static int is_WebsocketConnecting = 0; -#if 0 -static int is_referer_from_setup = 0; -#endif - -void *http_connection_handler(void *socket_desc) -{ - pthread_detach(pthread_self()); - setPthreadName("http_conn"); - //pthread_mutex_lock(&mutex_http_connection_handler); - //printf("\n[http_connection_handler] Pthread created and detached.\n"); - //printf("\n---------http connection handler ----------- 1\n"); - int sock = (intptr_t)socket_desc; // Get the socket descriptor - //char buffer[BUFSIZE_V2]; - char buffer[BUFSIZE * 59] = { 0 }; - - char recvbuffer[BUFSIZE * 60] = {0};//BUFSIZE * 60 - char contentBuffer[BUFSIZE * 60] = {0};//BUFSIZE * 60 - - unsigned int nTotalBytes = 0; - unsigned int nContentLength = 0; - int nbytes = 0; - clock_t t1 = clock(); - clock_t t2; - //int bIsMultipart = 0; - char sendBuffer[8196] = { 0 }; - int isGetAlarmMotion = FALSE; - //int sock_record_idx = -1; - - int websocket_connected = 0; - - //char *secWebSocketKey; - //char *data; - - //g_tracking_idx++; - - //if (g_tracking_idx >= MAX_CLIENT_SOCKET) - // g_tracking_idx = 0; - - char buf[1024] = {}; - readlink("/proc/self/exe", buf, sizeof(buf)); -#ifdef _DEBUG_AMBA - printf("(%d) [http_connection_handler] Program binary path is: %s\n", sock,buf); -#endif //_DEBUG_AMBA - - char exePath[1024] = {}; - getFilePath(buf, exePath, 1024); - - char configPATH[1024]; - char eventsPATH[1024]; - - strcpy(configPATH, exePath); - strcpy(eventsPATH, exePath); - - strcat(configPATH, "config.json"); - strcat(eventsPATH, "events.json"); - - int header_len = 0; - //int doubleCRLF = 0; - - //printf("\n[nweb.c]-----------------------------kkkk:5\n"); - //int tracking_idx = g_tracking_idx; - //memset(g_TrackingIDAndChannel[tracking_idx], 0x00, sizeof(g_TrackingIDAndChannel[tracking_idx])); - //pthread_mutex_lock(&mutex_t); - - /* - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - if (socketRecords[i].sock == sock) - { - socketRecords[i].debug_type = 9; - } - }*/ - //printf("\n---------http connection handler ----------- 2\n"); - int nbytes_sec = 0; - // recv( pCli, pCli->reqFd, pCli->readBuf+pCli->header_len, 1, MSG_WAITALL ); - //while ((nbytes = recv(sock, buffer, sizeof(buffer), 0)) > 0) - //char temp_buffer[8196] = { 0 }; - - int isTcpTunnel = FALSE; - - //while ((nbytes = recv(sock, buffer, sizeof(buffer), 0)) > 0) - while (bHttpServerMainStart && ((nbytes = recv(sock, buffer + header_len, 1, 0)) > 0)) - { - //printf("\n---------http connection handler ----------- 3\n"); - /* - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - if (socketRecords[i].sock == sock) - { - socketRecords[i].debug_type = 5; - } - }*/ - - header_len += nbytes; - //printf("read size: %d \n", header_len); - -#if 1 - if (strstr(buffer, "User-Agent: Mozilla/5.0 ") != NULL)//User-Agent有做其他偽裝的,是走瀏覽器,現在瀏覽器,都會加上一堆偽裝。 - { - if (strstr(buffer , "Connection: keep-alive") != NULL || - strstr(buffer , "Connection: close") != NULL || - strstr(buffer , "Connection: Keep-Alive") != NULL || - strstr(buffer , "Connection: Closed") != NULL)//一般socket的會去檢查是不是HTTP Connection,如果是則改成一次全收,並且往下執行。 - { - nbytes_sec = recv(sock, buffer + header_len, (sizeof(buffer) - header_len), 0); - //printf("\n-----------strlen(buffer):%d\n", strlen(buffer)); - //printf("\n--------------header_len:%d\n", header_len); - //printf("\n---------[#1]buffer:%s\n", buffer); - - //memset(temp_buffer, 0x00, header_len+ nbytes_sec); - //memcpy(temp_buffer, buffer, header_len+ nbytes_sec); - } - else if ((strstr(buffer, "Connection: Upgrade") != NULL || strstr(buffer, "Upgrade: websocket") != NULL ) - && strstr(buffer, "\r\n\r\n") != NULL) //非socket的會去檢查到\r\n\r\n,才往下執行。 - { - //printf("\n---------[websocket#2]buffer:%s\n", buffer); - //doubleCRLF = 1; - - //memset(temp_buffer, 0x00, header_len); - //memcpy(temp_buffer, buffer, header_len); - } - else { - //memset(temp_buffer,0x00, header_len); - //memcpy(temp_buffer, buffer, header_len); - continue; - } - } - else if (strstr(buffer, "setconfigfile") != NULL || - strstr(buffer, "seteventsfile") != NULL || - strstr(buffer, "seteventscustom2") != NULL || - strstr(buffer, "settoffile") != NULL || - strstr(buffer, "setemailsfile") != NULL) //[NVR]setconfigfile or seteventsfile則直接做全收。 - { - nbytes_sec = recv(sock, buffer + header_len, (sizeof(buffer)- header_len), 0); - //printf("\n---------[NVR#1]buffer:%s\n", buffer); - //memset(temp_buffer, 0x00, header_len + nbytes_sec); - //memcpy(temp_buffer, buffer, header_len + nbytes_sec); - } - else if (strstr(buffer, "\r\n\r\n") != NULL) //如果不是上述兩個,則[NVR]直接做"\r\n\r\n"的判斷。 - { - //printf("\n---------[NVR#2]buffer:%s\n", buffer); - //doubleCRLF = 1; - //memset(temp_buffer, 0x00, header_len); - //memcpy(temp_buffer, buffer, header_len); - } - else { - //memset(temp_buffer, 0x00, header_len); - //memcpy(temp_buffer, buffer, header_len); - continue; - } -#endif - - //printf("\n---------http connection handler ----------- 4\n"); -#if 0 - if (strstr(buffer, "\r\n\r\n")) - { - //doubleCRLF = 1; - } - else - continue; -#endif - - //printf("KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK read finish \n\n\n\n"); - - nbytes = header_len + nbytes_sec; - - //printf("\n[nweb.c]-----------------------------kkkk:4\n"); - if (nTotalBytes + nbytes > MAX_IMG_BUFF_SIZE - 4) - { - printf("[ERROR] receive buffer is full %d\n", sock); - ///Steven MARK TEMP - - //fflush(stdout); - //closesocket(sock); - break; - } - - //printf("\n-------------buffer:%s\n", buffer); - - //receive client data successfully - memcpy(recvbuffer + nTotalBytes, buffer, nbytes); - //printf("\n---------http connection handler ----------- 5\n"); - - if (strstr(buffer, "airelay") != NULL) - { - isTcpTunnel = TRUE; - } - else - { - isTcpTunnel = FALSE; - } - - //printf("\n----recvbuffer:%s\n", recvbuffer); - - nTotalBytes += nbytes; - //DumpHex(recvbuffer, 300); - //memset(recvbuffer + nTotalBytes, 0x00, MAX_IMG_BUFF_SIZE - nTotalBytes); - //printf("\n[nweb.c]-----------------------------kkkk:3\n"); - if (nbytes == 0) - { - printf("Socket hung up %d\n", sock); - - //fflush(stdout); - //closesocket(sock); - break; - } - else if (nbytes == -1) - { - printf("HTTP recv failed %d\n", sock); - - //closesocket(sock); - break; - } - //printf("\n[nweb.c]-----------------------------kkkk:2\n"); -#if defined GY_OS_AMBA || defined GY_OS_NOVA - //20201028 sophia add, host not from ipcam & not authorized -#if 0 - if (enable_base64 == 1) { -#endif -#if 0 - if(is_authorized_run_preload_http_server == 0 && - strstr(recvbuffer, "/setup.htm") && - is_referer_from_setup == 0){ - is_referer_from_setup = 1; - } -#endif - //printf("\n---------http connection handler ----------- 6 --- %d\n", is_authorized_run_preload_http_server); - if (is_authorized_run_preload_http_server == 0) { - //printf("\n---------http connection handler ----------- 7\n"); -#if 0 - if (is_referer_from_setup == 0) { - - char tmp_open_file[512]; - memset(tmp_open_file, 0, sizeof(tmp_open_file)); - - { - sprintf(tmp_open_file, "./Aida/warning2.html"); - } - - - char sendBuffer[BUFSIZE * 8] = { 0 }; - - /*//#ifdef _DEBUG_AMBA - printf("\n(%d) [web process] http get tmp_open_file:%s\n", cli_socket,tmp_open_file); - //#endif //_DEBUG_AMBA*/ - - int file_fd; - if ((file_fd = open(tmp_open_file, O_RDONLY)) == -1) - { - printf("Failed to open file : %s\n", tmp_open_file);//網頁檔案有沒有被讀取 - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(sock, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #19-2\n"); - } - else { - /* work out the file type and check if we support it */ - int iFileLength = 0; - char sendBuffer_superlarge[BUFSIZE * 8 * 16] = { 0 }; - iFileLength = read(file_fd, sendBuffer_superlarge, BUFSIZE * 8 * 16); - close(file_fd); - - { - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Keep-Alive\r\nCache-Control: max-age = 30\r\n\r\n");/*\r\nCache-Control: max-age = 30*/ - if (send(sock, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #19\n"); - } - - int iSentLeft = 0; - int iSentLength = 0; - int iRetryCount = 5; - - - - - - iSentLeft = iFileLength; - - while (iSentLeft >= 1) { - iSentLength = send(sock, sendBuffer_superlarge, iSentLeft, 0); - iSentLeft = iSentLeft - iSentLength; - iRetryCount--; - sendBuffer_superlarge + iSentLength; - - if (iSentLeft >= 1) { - //printf("\n[web process]iSentLeft: %d\n", iSentLeft); - } - - if (iRetryCount <= 0) - break; - } - - - } - closesocket(sock); - - break; - } -#endif - if (strncmp(recvbuffer, "GET /getalarmmotion?nvr_auth=", 29) != 0 && strncmp(recvbuffer, "GET /server HTTP/1.1", 20) != 0 && strncmp(recvbuffer, "GET /getdebugplate HTTP/1.1", 27) != 0 && strncmp(recvbuffer, "GET /getfree HTTP/1.1", 21) != 0 && strstr(recvbuffer, "GET /get_search_info?select=log&limit=1&credential=") == NULL) { - - //printf("\n-------------------is_connection_authorized #recvbuffer:%s\n", recvbuffer); - if (!is_connection_authorized(recvbuffer, &sock, isTcpTunnel)) { - //printf("\n-------------------is_connection_authorized dropout #recvbuffer:%s\n", recvbuffer); - closesocket(sock); - break; - } - else { - //printf("\n-------------------is_connection_authorized #recvbuffer:%s\n", recvbuffer); - } - } - else if (strncmp(recvbuffer, "GET /getalarmmotion?nvr_auth=", 29) == 0){ - - char *is_nvr_auth = NULL; - is_nvr_auth = strstr(recvbuffer, "nvr_auth="); - if (is_nvr_auth != NULL && strlen(is_nvr_auth) > 9){ - char auth_basic[256] = { 0 }; - strcpy(auth_basic, "Authorization: Basic "); - memcpy(auth_basic + 21, is_nvr_auth + 9, strlen(is_nvr_auth)); - //printf("\n-------------------auth_basic:%s\n", auth_basic); - - if (!is_connection_authorized(auth_basic, &sock, isTcpTunnel)) { - //printf("\n-------------------is_connection_authorized dropout #recvbuffer:%s\n", recvbuffer); - closesocket(sock); - break; - } - else { - //printf("\n-------------------is_connection_authorized #recvbuffer:%s\n", recvbuffer); - } - } - else { - closesocket(sock); - break; - } - } - else if (strstr(recvbuffer, "GET /get_search_info?select=log&limit=1&credential=") != NULL) { - - char *is_credential_auth = NULL; - is_credential_auth = strstr(recvbuffer, "credential="); - //printf("\n-------------------is_credential_auth:%s\n", is_credential_auth); - if (is_credential_auth != NULL && strlen(is_credential_auth) > 11) { - char auth_basic[256] = { 0 }; - strcpy(auth_basic, "Authorization: Basic "); - memcpy(auth_basic + 21, is_credential_auth + 11, strlen(is_credential_auth)); - //printf("\n-------------------auth_basic:%s\n", auth_basic); - - int iSockIdx = -1; - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - if (socketRecords[i].sock == sock) - { - iSockIdx = i; - socketRecords[iSockIdx].isCredentialRequest = 1; - break; - } - } - - if (!is_connection_authorized(auth_basic, &sock, isTcpTunnel)) { - //printf("\n-------------------is_connection_authorized dropout #recvbuffer:%s\n", recvbuffer); - closesocket(sock); - break; - } - else { - //printf("\n-------------------is_connection_authorized #recvbuffer:%s\n", recvbuffer); - } - } - else { - closesocket(sock); - break; - } - } - } -#if 0 - } -#endif -#endif - //printf("\n-------recvbuffer #1:%s\n", recvbuffer); - //printf("\n[nweb.c]-----------------------------kkkk:1\n"); - //printf("\n---------http connection handler ----------- 7\n"); - if (strstr(recvbuffer, "Upgrade: websocket") || strstr(recvbuffer, "Connection: Upgrade") || strstr(recvbuffer, "Upgrade: WebSocket")) - { - //printf("\n-------recvbuffer #1:%s\n", recvbuffer); - - //printf("\n[nweb.c][%d]--------sharkhand process---start:1\n", sock); - - websocket_connected = 0; - sharkhand_s_connection_upgrade(&sock,buffer,&websocket_connected); - - //printf("\n[nweb.c][%d]--------sharkhand process---end:1\n", sock); - - int sock_info_idx = -1; - //printf("\n[nweb.c][%d]--------web process---start:1\n", sock); - - web_process(&sock, recvbuffer, nTotalBytes, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); - //printf("\n------web_process end 1\n"); - //printf("\n[nweb.c][%d]--------web process---end:1, getalarmmotion = %d\n", sock, isGetAlarmMotion); - break; - } - else if (memcmp(recvbuffer, "GET ", strlen("GET ")) == 0) - { - //printf("\n-------recvbuffer #2:%s\n", recvbuffer); - -//#ifdef _DEBUG_AMBA - //printf("\n(%d) [http_connection_handler] recv GET http request(%d):%sCHECK-END\n", sock, sock, recvbuffer); -//#endif - - int sock_info_idx = -1; - if (memcmp(recvbuffer + nTotalBytes - 4, "\r\n\r\n", 4) == 0) - { - t1 = clock(); - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - if (socketRecords[i].used == 1) { - if (socketRecords[i].sock == sock) - { - sock_info_idx = i; - break; - } - } - } - //printf("\n[nweb.c]--------web process---start:2\n"); - web_process(&sock, recvbuffer, nTotalBytes, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); - //printf("\n[nweb.c]--------web process---end:2\n"); - //printf("\n------web_process end 2\n"); - nTotalBytes = 0; - memset(recvbuffer, 0x00, sizeof(recvbuffer)); - t2 = clock(); - diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); - // printf("(%d) web end time %d:%f\n",sock, sock, diff); - } - -#ifdef _DEBUG_AMBA - printf("\n(%d) [http_connection_handler] recv GET http request END===========\n\n", sock); -#endif - break; - } -#if 0 - else if (memcmp(recvbuffer, "POST /sendjpeg", strlen("POST /sendjpeg")) == 0) - { - //printf("recv POST http request(%d):%.30s\n", sock, recvbuffer); - - for (int i = nTotalBytes - nbytes + 1; i <= nTotalBytes; i++) - { - if (memcmp(recvbuffer + i - strlen(MULTIPART_CONTENT), MULTIPART_CONTENT, strlen(MULTIPART_CONTENT)) == 0) - bIsMultipart = 1; - - if ((memcmp(recvbuffer + i - 2, "\xFF\xD9", 2) == 0 && !bIsMultipart && (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0) ) || - (memcmp(recvbuffer + i - 4, "--\r\n", 4) == 0 && memcmp(recvbuffer + i - 5, "-", 1) != 0 && bIsMultipart) - ) - { - //DumpHex(recvbuffer, 320); - //printf("\n"); - //DumpHex(recvbuffer + i, 320); - //DumpHex(recvbuffer + i - 2 , 16); - //caculate fps of each sockets - int sock_info_idx = caculate_ftp_of_each_sockets(sock, &sock_record_idx); - //printf("\n[nweb.c]--------web process---start:3\n"); - web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh,http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); - //printf("\n[nweb.c]--------web process---end:3\n"); - //printf("\n------web_process end 3\n"); - memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); - memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i) ); - nTotalBytes = nTotalBytes - i; - bIsMultipart = 0; - t2 = clock(); - diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); - //printf("web end time %d:%f\n", sock, diff); - t1 = clock(); -#ifdef _WIN32 - usSleep(http_sleep_interval*1000); -#else - usSleep(1000); -#endif - break; - } - } - closesocket(sock); - break; - } -#endif -#if 0 - else if (memcmp(recvbuffer, "POST /sendyuv", strlen("POST /sendyuv")) == 0) - { - for (int i = nTotalBytes - nbytes + 1; i <= nTotalBytes; i++) - { - if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) - nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); - - if (nContentLength != 0) - { - if (nTotalBytes < nContentLength) - break; - } - - if ((memcmp(recvbuffer + i - strlen(MSG_END_PATTERN), MSG_END_PATTERN, strlen(MSG_END_PATTERN)) == 0 /*&& (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0)*/) - ) - { - //DumpHex(recvbuffer, 320); - //printf("\n"); - //DumpHex(recvbuffer + i, 320); - //DumpHex(recvbuffer + i - 2 , 16); - //caculate fps of each sockets - t2 = clock(); - diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); - // printf("recv done time: %d:%f\n", sock, diff); - - int sock_info_idx = caculate_ftp_of_each_sockets(sock, &sock_record_idx); - //printf("\n[nweb.c]--------web process---start:4\n"); - web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); - //printf("\n[nweb.c]--------web process---end:4\n"); - //printf("\n------web_process end 4\n"); - memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); - memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); - nTotalBytes = nTotalBytes - i; - bIsMultipart = 0; - nContentLength = 0; - - t2 = clock(); - diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); - //printf("web end time %d:%f\n", sock, diff); - t1 = clock(); -#ifdef _WIN32 - usSleep(http_sleep_interval*1000); -#else - usSleep(1000); -#endif - break; - } - } - closesocket(sock); - break; - } -#endif -#if 0 - else if (memcmp(recvbuffer, "POST /user_command", strlen("POST /user_command")) == 0) - { - for (int i = nTotalBytes - nbytes + 1; i <= nTotalBytes; i++) - { - if ((memcmp(recvbuffer + i - strlen(MSG_END_PATTERN), MSG_END_PATTERN, strlen(MSG_END_PATTERN)) == 0 /*&& (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0)*/) - ) - { - //DumpHex(recvbuffer, 320); - //printf("\n"); - //DumpHex(recvbuffer + i, 320); - //DumpHex(recvbuffer + i - 2 , 16); - //caculate fps of each sockets - int sock_info_idx = caculate_ftp_of_each_sockets(sock, &sock_record_idx); - //printf("\n[nweb.c]--------web process---start:5\n"); - web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); - //printf("\n[nweb.c]--------web process---end:5\n"); - //printf("\n------web_process end 5\n"); - memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); - memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); - nTotalBytes = nTotalBytes - i; - bIsMultipart = 0; - t2 = clock(); - diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); - //printf("web end time %d:%f\n", sock, diff); - t1 = clock(); -#ifdef _WIN32 - usSleep(http_sleep_interval*1000); -#else - usSleep(1000); -#endif - break; - } - } - - closesocket(sock); - break; - } -#endif - else if (memcmp(recvbuffer, "POST /setconfigfile", strlen("POST /setconfigfile")) == 0 || - memcmp(recvbuffer, "POST /airelay/setconfigfile", strlen("POST /airelay/setconfigfile")) == 0 || - memcmp(recvbuffer, "POST /seteventsfile", strlen("POST /seteventsfile")) == 0 || - memcmp(recvbuffer, "POST /airelay/seteventsfile", strlen("POST /airelay/seteventsfile")) == 0 || - memcmp(recvbuffer, "POST /seteventscustom2", strlen("POST /seteventscustom2")) == 0 || - memcmp(recvbuffer, "POST /settoffile", strlen("POST /settoffile")) == 0 || - memcmp(recvbuffer, "POST /setemailsfile", strlen("POST /setemailsfile")) == 0 -#if 0 - || memcmp(recvbuffer, "POST /setjvcconfigfile", strlen("POST /setjvcconfigfile")) == 0 -#endif - ) - { - //printf("\n---------recvbuffer:%s\n", recvbuffer); - - char *cp = NULL; - char *cp2 = NULL; - char *cp3 = NULL; - char *tempPtr = NULL; - char boundary[BUFSIZE * 60] = { 0 }; - int strlen_boundary = 0; - - if ((cp = strstr(recvbuffer, "boundary=")) != NULL) - { - - tempPtr = cp + 9; - //printf("\n---------tempPtr:%s\n", tempPtr); - - cp = strstr(tempPtr, "\r\n\r\n"); - - if (cp != NULL) - { - //printf("\n---------cp:%s\n", cp); - cp2 = strstr(cp, "{"); - - if (cp2 != NULL) - { - //printf("\n---------cp2:%s\n", cp2); - //cp3 = strstr(cp2, "----------------"); - cp3 = strstr(cp2, "--"); - strlen_boundary = cp3 - cp2; - while (strlen_boundary >= 1 && cp2[strlen_boundary - 1] != '}') - { - strlen_boundary = strlen_boundary - 1; - } - - if(strlen_boundary >= 1) - strncpy(boundary, cp2, strlen_boundary); - } - } - } - //printf("\n---------boundary:%s\n", boundary); - - int sock_info_idx = -1; - - for (int i = 0; i <= nTotalBytes; i++) - { - for (int j = 0; j < MAX_CLIENT_SOCKET; j++) - { - if (socketRecords[j].used == 1) { - if (socketRecords[j].sock == sock) - { - sock_info_idx = j; - break; - } - } - } - - if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) - nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); - - if (nContentLength != 0) - { - //printf("\n--------recvbuffer + i:%s\n", recvbuffer + i); - if (nTotalBytes < nContentLength) - break; - } - - if (strlen_boundary == 0) { - if (memcmp(recvbuffer + i - strlen("\r\n\r\n"), "\r\n\r\n", strlen("\r\n\r\n")) == 0) - { - //printf("\n-----bIsMultipart:%d\n", bIsMultipart); - //printf("\n-----nContentLength:%d\n", nContentLength); - - //printf("\n----6-recvbuffer:%s\n", recvbuffer); - //printf("\n-----recvbuffer+i:%s\n", recvbuffer+i); - - web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); - //printf("\n------web_process end 6\n"); - //bIsMultipart = 0; - nContentLength = 0; - memset(recvbuffer, 0x00, sizeof(recvbuffer)); - - break; - } - } - else { - - if (memcmp(recvbuffer + i - strlen(boundary), boundary, strlen(boundary)) == 0) { - - nContentLength = strlen_boundary; - recvbuffer[i] = '\0'; - //printf("\n----7-recvbuffer:%s\n", recvbuffer); - //printf("\n-----recvbuffer+i - strlen(boundary):%s\n", recvbuffer + i - strlen(boundary)); - - web_process(&sock, recvbuffer, i - strlen(boundary), contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); - //printf("\n------web_process end 7\n"); - //bIsMultipart = 0; - nContentLength = 0; - memset(recvbuffer, 0x00, sizeof(recvbuffer)); - - break; - } - } - } - - //printf("\n------web_process end 8\n"); - - break; - } -#ifdef GY_OS_AMBA - else if (memcmp(recvbuffer, "POST /sendpycode", strlen("POST /sendpycode")) == 0 ) - { - //printf("\n---------recvbuffer:%s\n", recvbuffer); - //int sock_info_idx = -1; - int strlen_boundary = 0; - char SendPython[BUFSIZE * 8] = {0}; - //char beforeSendBuffer_xtra[BUFSIZE * 60] = { 0 }; - if (strcmp(SystemSetting.enable_python, "Yes") == 0) { - - for (int i = 0; i <= nTotalBytes; i++) - { - if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) - nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); - if (nContentLength != 0) - { - if (nTotalBytes < nContentLength) - break; - } - if (strlen_boundary == 0) { - if (memcmp(recvbuffer + i - strlen("\r\n\r\n"), "\r\n\r\n", strlen("\r\n\r\n")) == 0) - { - char* file_Content = recvbuffer + i; - - printf("file content = %s \n", file_Content); - //printf("\nfile!!!\n"); - //runPython(file_Content, sock); - // strcpy(sendBuffer_xtra, "Send python file OK!!"); - printf("##################### file_Content : %s /n", file_Content); - runPython(file_Content); - strcpy(SendPython, "Web Buffer Run OK !!"); - } - else - { - strcpy(SendPython, "Send python file fail !!"); - } - } - - } - } - else { - strcpy(SendPython,"Please check the Enable python checkbox configuration in the SETTING TAB"); - } - - - char sendBuffer_xtra[BUFSIZE * 8] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(SendPython), SendPython); - if (send(sock, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1) - { - printf("\nsend error #32\n"); - } - memset(SendPython, 0, sizeof(SendPython)); - closesocket(sock); - } -#endif - else if (memcmp(recvbuffer, "POST /keyInfo", strlen("POST /keyInfo")) == 0) - { - g_write_config_file_dirty_flag = 0; - //printf("POST KEY Info \n"); - //printf("recv= %s \n", recvbuffer); - - char* pContent = strstr(recvbuffer, "--boundary START"); - - //printf("\n---get post content=[%s]\n", pContent + 16); - - update_config(pContent + 16); -#ifdef GY_OS_NOVA - g_check_run_nova_detection = 0; - system("killall -15 nova_driver"); - usSleep(1000000); -#endif - //printf("\n--------------------reload 7\n"); - //reload_dataset_from_jsonfile(); - - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Keep-Alive\r\n\r\n"); - if (send(sock, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #39\n"); - closesocket(sock); - - printf("\n-----------------------keyInfo: exit-----------------------\n"); -#if 1 - stop_test_nn_cavalry("keyInfo exit"); - //stop_server(); -#endif - //exit(EXIT_SUCCESS); - } - else if (memcmp(recvbuffer, "POST /getAidaInfo", strlen("POST /getAidaInfo")) == 0) - { - // printf("POST AidaInfo \n"); - - sprintf(sendBuffer, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Keep-Alive\r\n\r\n"); - if (send(sock, sendBuffer, strlen(sendBuffer), MSG_MORE) == -1) - printf("\nsend error #40\n"); - //write(fd,buffer,strlen(buffer)); - - //int ret = 0; - /* 讀取檔案內容輸出到客戶端瀏覽器 */ - - //post events setting - //char filename[] = "config.json"; - char *filename = configPATH; - if (!FileExist(filename)) - printf("%s doesn't exist.\n", filename); - else { - printf("read config.json.\n"); - - //size_t nfileSize = ReadFileSize(filename); - char* fileBuf = ReadAllBytes(filename); - if (fileBuf) { - cJSON* config_root = cJSON_Parse(fileBuf); - if (fileBuf) { - free(fileBuf); - fileBuf = NULL; - } - if (config_root) { - //printf("config.json parse OK.\n"); - //cJSON* about_box = cJSON_GetObjectItem(config_root, "about_box"); - //cJSON *nic_name = cJSON_GetObjectItem(about_box, "NIC name"); - //cJSON* unlock_key = cJSON_GetObjectItem(about_box, "unlocking key"); - - ///read config.json - - cJSON *jstr1, *jstr2, *jnum1, *root; - char* JsonString = NULL; - root = cJSON_CreateObject(); - - jstr1 = cJSON_CreateString("json test1"); - jstr2 = cJSON_CreateString("json test2"); - jnum1 = cJSON_CreateNumber(4456); - - cJSON_AddItemToObject(root, "jstr1", jstr1); - cJSON_AddItemToObject(root, "jstr2", jstr2); - cJSON_AddItemToObject(root, "jnum1", jnum1); - //cJSON_AddItemToObject(root, "unlock_key", unlock_key->valuestring); - - JsonString = cJSON_PrintUnformatted(root); - - send(sock, JsonString, sizeof(JsonString), 0); - - if (JsonString != NULL) { - free(JsonString); - JsonString = NULL; - } - - if (root) { - cJSON_Delete(root); - root = NULL; - } - - if (config_root) { - cJSON_Delete(config_root); - config_root = NULL; - } - //write(cli_socket, sendBuffer, ret); - } - else - printf("config.json parse FAIL.\n"); - } - } - - closesocket(sock); - break; - } - else if ((memcmp(recvbuffer, "POST /import_lpr_map_list", strlen("POST /import_lpr_map_list")) == 0) - ||(memcmp(recvbuffer, "POST /import_lpr_list", strlen("POST /import_lpr_list")) == 0)) - { - //printf("\n------------recvbuffer:%s\n", recvbuffer); - - char *cp = NULL; - char *tempPtr = NULL; - char boundary[255] = {0}; - if ((cp = strstr( recvbuffer, "boundary=" )) != NULL) - { - int strlen =0; - tempPtr = cp + 9; - cp = strstr(tempPtr, "\r\n"); - if (cp != NULL) - { - strlen = cp - tempPtr; - if (strlen > 0) - { - char endStr[] = "--"; - strncpy(boundary, tempPtr, strlen); - strcat(boundary,endStr); - } - } - } - - if (strlen(boundary) >= 1) { - //printf("\n--------import lpr list ---- 1 --- nTotalBytes %d\n", nTotalBytes); - int sock_info_idx = -1; - for (int i = 0; i <= nTotalBytes; i++) - { - for (int j = 0; j < MAX_CLIENT_SOCKET; j++) - { - if (socketRecords[j].used == 1) { - if (socketRecords[j].sock == sock) - { - sock_info_idx = j; - break; - } - } - } - //printf("\n--------import lpr list ---- 2 ------ %d\n", i); - if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) - nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); - //printf("\n--------import lpr list ---- 3\n"); - if (nContentLength != 0) - { - if (nTotalBytes < nContentLength) - break; - } - //printf("\n--------import lpr list ---- 4\n"); - if ((memcmp(recvbuffer + i - strlen(boundary), boundary, strlen(boundary)) == 0 /*&& (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0)*/) - ) - { - //DumpHex(recvbuffer, 320); - //printf("\n"); - //DumpHex(recvbuffer + i, 320); - //DumpHex(recvbuffer + i - 2 , 16); - //caculate fps of each sockets - t2 = clock(); - diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); - //printf("recv done time: %d:%f\n", sock, diff); - //printf("\n[nweb.c]--------web process---start:6\n"); - web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); - //printf("\n------web_process end 9\n"); - //printf("\n[nweb.c]--------web process---end:6\n"); - //memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); - //memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); - //nTotalBytes = nTotalBytes - i; - //printf("\n[nweb.c]--------web process---end:6-------1\n"); - //memset(recvbuffer , 0x00, MAX_IMG_BUFF_SIZE); - //bIsMultipart = 0; - nContentLength = 0; - //printf("\n[nweb.c]--------web process---end:6-------2\n"); - t2 = clock(); - diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); - //printf("\n[nweb.c]--------web process---end:6-------2\n"); - //printf("web end time %d:%f\n", sock, diff); - t1 = clock(); - // printf("\n[nweb.c]--------web process---end:6-------4\n"); - - usSleep(1000); - break; - } - //printf("\n--------import lpr list ---- 5\n"); - } - } - /* - char* cp = NULL, tempPtr = NULL; - char boundary[255]; - char contLen[20]; - int datalen = 0; - printf("POST import_lpr_map_list \n"); - printf("recv= %s \n", recvbuffer); - if (cp = strstr( recvbuffer, "Content-Length:" )) - { - datalen = atoi((char *)(cp+16)); - printf("length:%d\n",datalen); - } - if ((cp = strstr( recvbuffer, "boundary=" ))) - { - tempPtr = &cp[9]; - //strncpy(boundary, tempPtr, sizeof(boundary)-1); - //printf("boundary:%s\n",boundary); - if (datalen > 0) - do_upload_lpr_map_post("/import_lpr_map_list", recvbuffer, datalen, tempPtr) - } - */ - closesocket(sock); - break; - } - else if ((memcmp(recvbuffer, "POST /import_radarbg", strlen("POST /import_radarbg")) == 0)) // a113n 10/12 - { - char *cp = NULL; - char *tempPtr = NULL; - char boundary[255] = {0}; - if ((cp = strstr(recvbuffer, "boundary=")) != NULL) - { - int strlen = 0; - tempPtr = cp + 9; - cp = strstr(tempPtr, "\r\n"); - if (cp != NULL) - { - strlen = cp - tempPtr; - if (strlen > 0) - { - char endStr[] = "--"; - strncpy(boundary, tempPtr, strlen); - strcat(boundary, endStr); - } - } - } - int sock_info_idx = -1; - for (int i = 0; i <= nTotalBytes; i++) - { - for (int j = 0; j < MAX_CLIENT_SOCKET; j++) - { - if (socketRecords[j].used == 1) { - if (socketRecords[j].sock == sock) - { - sock_info_idx = j; - break; - } - } - } - - if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) - nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); - - if (nContentLength != 0) - { - if (nTotalBytes < nContentLength) - break; - } - - if ((memcmp(recvbuffer + i - strlen(boundary), boundary, strlen(boundary)) == 0 /*&& (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0)*/)) - { - // DumpHex(recvbuffer, 320); - // printf("\n"); - // DumpHex(recvbuffer + i, 320); - // DumpHex(recvbuffer + i - 2 , 16); - // caculate fps of each sockets - t2 = clock(); - diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); - // printf("recv done time: %d:%f\n", sock, diff); - // printf("\n[nweb.c]--------web process---start:6\n"); - web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); - //printf("\n------web_process end 10\n"); - // printf("\n[nweb.c]--------web process---end:6\n"); - // memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); - // memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); - // nTotalBytes = nTotalBytes - i; - // printf("\n[nweb.c]--------web process---end:6-------1\n"); - // memset(recvbuffer , 0x00, MAX_IMG_BUFF_SIZE); - //bIsMultipart = 0; - nContentLength = 0; - // printf("\n[nweb.c]--------web process---end:6-------2\n"); - t2 = clock(); - diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); - // printf("\n[nweb.c]--------web process---end:6-------2\n"); - // printf("web end time %d:%f\n", sock, diff); - t1 = clock(); - // printf("\n[nweb.c]--------web process---end:6-------4\n"); - - usSleep(1000); - break; - } - } - /* - char* cp = NULL, tempPtr = NULL; - char boundary[255]; - char contLen[20]; - int datalen = 0; - printf("POST import_lpr_map_list \n"); - printf("recv= %s \n", recvbuffer); - if (cp = strstr( recvbuffer, "Content-Length:" )) - { - datalen = atoi((char *)(cp+16)); - printf("length:%d\n",datalen); - } - if ((cp = strstr( recvbuffer, "boundary=" ))) - { - tempPtr = &cp[9]; - //strncpy(boundary, tempPtr, sizeof(boundary)-1); - //printf("boundary:%s\n",boundary); - if (datalen > 0) - do_upload_lpr_map_post("/import_lpr_map_list", recvbuffer, datalen, tempPtr) - } - */ - closesocket(sock); - break; - } - else if ((memcmp(recvbuffer, "POST /import_speedbg", strlen("POST /import_speedbg")) == 0)) // 2022-11-03 Ken - { - char *cp = NULL; - char *tempPtr = NULL; - char boundary[255] = {0}; - if ((cp = strstr(recvbuffer, "boundary=")) != NULL) - { - int strlen = 0; - tempPtr = cp + 9; - cp = strstr(tempPtr, "\r\n"); - if (cp != NULL) - { - strlen = cp - tempPtr; - if (strlen > 0) - { - char endStr[] = "--"; - strncpy(boundary, tempPtr, strlen); - strcat(boundary, endStr); - } - } - } - int sock_info_idx = -1; - for (int i = 0; i <= nTotalBytes; i++) - { - for (int j = 0; j < MAX_CLIENT_SOCKET; j++) - { - if (socketRecords[j].used == 1) { - if (socketRecords[j].sock == sock) - { - sock_info_idx = j; - break; - } - } - } - - if (memcmp(recvbuffer + i, "Content-Length:", strlen("Content-Length:")) == 0) - nContentLength = atoi(recvbuffer + i + strlen("Content-Length:")); - - if (nContentLength != 0) - { - if (nTotalBytes < nContentLength) - break; - } - - if ((memcmp(recvbuffer + i - strlen(boundary), boundary, strlen(boundary)) == 0 /*&& (memcmp(recvbuffer + i, "GET", strlen("GET")) == 0 || memcmp(recvbuffer + i, "POST", strlen("POST")) == 0 || memcmp(recvbuffer + i, "\x00\x00\x00\x00", 4) == 0)*/)) - { - // DumpHex(recvbuffer, 320); - // printf("\n"); - // DumpHex(recvbuffer + i, 320); - // DumpHex(recvbuffer + i - 2 , 16); - // caculate fps of each sockets - t2 = clock(); - diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); - // printf("recv done time: %d:%f\n", sock, diff); - // printf("\n[nweb.c]--------web process---start:6\n"); - web_process(&sock, recvbuffer, i, contentBuffer/*, http_layer_count, http_nets, http_names, http_alphabet, http_nms*/, http_thresh, http_hier_thresh, http_dont_show, http_ext_output, http_save_labels, http_http_port, http_licenseType, http_advLicenseType, http_afsCode, http_layerFeatureType, http_strLicenseType, &isGetAlarmMotion, sock_info_idx); - //printf("\n------web_process end 11\n"); - // printf("\n[nweb.c]--------web process---end:6\n"); - // memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); - // memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); - // nTotalBytes = nTotalBytes - i; - // printf("\n[nweb.c]--------web process---end:6-------1\n"); - // memset(recvbuffer , 0x00, MAX_IMG_BUFF_SIZE); - //bIsMultipart = 0; - nContentLength = 0; - // printf("\n[nweb.c]--------web process---end:6-------2\n"); - t2 = clock(); - diff = ((float)(t2 - t1) / CLOCKS_PER_SEC); - // printf("\n[nweb.c]--------web process---end:6-------2\n"); - // printf("web end time %d:%f\n", sock, diff); - t1 = clock(); - // printf("\n[nweb.c]--------web process---end:6-------4\n"); - - usSleep(1000); - break; - } - } - /* - char* cp = NULL, tempPtr = NULL; - char boundary[255]; - char contLen[20]; - int datalen = 0; - printf("POST import_lpr_map_list \n"); - printf("recv= %s \n", recvbuffer); - if (cp = strstr( recvbuffer, "Content-Length:" )) - { - datalen = atoi((char *)(cp+16)); - printf("length:%d\n",datalen); - } - if ((cp = strstr( recvbuffer, "boundary=" ))) - { - tempPtr = &cp[9]; - //strncpy(boundary, tempPtr, sizeof(boundary)-1); - //printf("boundary:%s\n",boundary); - if (datalen > 0) - do_upload_lpr_map_post("/import_lpr_map_list", recvbuffer, datalen, tempPtr) - } - */ - closesocket(sock); - break; - } -#if 0 - else - { - char msg[MAX_MSG_LEN] = { 0 }; - //char beforeSendBuffer[BUFSIZE * 4] = { 0 }; - sprintf(msg, "The URL is not correct(%d)\n", sock /*,recvbuffer*/); - printf("%s\n", msg); - - /*printf("\n"); - strcpy(beforeSendBuffer, msg); - strcat(beforeSendBuffer, MSG_END_PATTERN); - - char sendBuffer[BUFSIZE] = { 0 }; - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(sock, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend error\n");*/ - - for (int i = 0; i < nTotalBytes; i++) - { - if (memcmp(recvbuffer + i, "POST /sendjpeg", strlen("POST /sendjpeg")) == 0) - { - //DumpHex(recvbuffer + i, 256); - sprintf(msg, "The URL is not correct(%d)\n", sock /*,recvbuffer*/); - printf("%s\n", msg); - - memmove(recvbuffer, recvbuffer + i, nTotalBytes - i); - memset(recvbuffer + nTotalBytes - i, 0x00, MAX_IMG_BUFF_SIZE - (nTotalBytes - i)); - nTotalBytes = nTotalBytes - i; - break; - } - } - - /*if (nTotalBytes >= MAX_IMG_BUFF_SIZE - 8*BUFSIZE) - { - memset(recvbuffer, 0x00, sizeof(recvbuffer)); - nTotalBytes = 0; - break; - }*/ - closesocket(sock); - break; - } -#endif -#if 0 - else if ((memcmp(recvbuffer, "POST /upload_face_img", strlen("POST /upload_face_img")) == 0)) // 2023-12-12 Steven - { - //printf("\n\n\n--------------------------------UPLOAD FACE IMG \n"); - - //int image_buff_size = 0; - - //char *image_buff = NULL; - //image_buff = malloc(MAX_IMG_SIZE_HD); - //memset(image_buff, 0, MAX_IMG_SIZE_HD); - - //char *decrypt_buff = NULL; - //decrypt_buff = malloc(MAX_IMG_SIZE_HD); - //memset(decrypt_buff, 0, MAX_IMG_SIZE_HD); - - char *cp = NULL; - char *dataEnd = NULL; - char *tempPtr = NULL; - int base64_len = 0; - - //printf("--------------------------------UPLOAD FACE IMG 2\n"); - - //printf("\n\n\n%s\n", recvbuffer); - - if ((cp = strstr(recvbuffer, "base64,")) != NULL) - { - //printf("\n\n\n ============================= JPEG SIZE = %d \n\n", strlen(cp)); - tempPtr = cp + 7; - //printf("find data start: 0x%x\n", tempPtr); - } - - //printf("--------------------------------UPLOAD FACE IMG 3\n"); - - if ((dataEnd = strstr(tempPtr, "------WebKit")) != NULL) - { - //printf("find data end: 0x%x\n", dataEnd); - } - - //printf("--------------------------------UPLOAD FACE IMG 4\n"); - - if (tempPtr != NULL && dataEnd != NULL) - { - base64_len = (dataEnd - tempPtr) - 2; - //printf("\n\ndata len = %d \n", base64_len); - } - - //printf("--------------------------------UPLOAD FACE IMG 5\n"); -#if 1 - if (base64_len > 0) - { - memcpy(g_image_buff, tempPtr, base64_len); - - size_t base64_decode_length = 0; - - //printf("55555555555555555555555555 \n\n\n %d \n\n\n", base64_len); - - //printf(" 666666666666666666666666666666666666 \n\n\n %s \n\n\n", image_buff); - - int encode_len = strlen(g_image_buff) - (strlen(g_image_buff) % 4); - - //printf("55555555555555555555555555 enc len\n\n\n %d \n\n\n", encode_len); - - base64_decode(g_image_buff, encode_len, &base64_decode_length, g_decrypt_buff); - - //printf("666666666666666666666666666666 \n\n\n %d \n\n\n", base64_decode_length); - printf("--------------------------------UPLOAD FACE IMG 6\n"); - //writeImageFromBuffer("/emmc/plugin/Aida_data/tmp/crop.jpg", g_decrypt_buff, base64_decode_length); -#if 1 - // deal with face data - time_t rawtime = time(0); - struct tm * timeinfo; - timeinfo = localtime(&rawtime); - struct timeval time_now; - gettimeofday(&time_now, NULL); - time_t msecs_time = time_now.tv_usec / 1000; - - if (get_ff_face_name_max_num() > g_face_frame_uid) { - g_face_frame_uid = get_ff_face_name_max_num() + 1; - printf("g_face_frame_uid = %d\n", g_face_frame_uid); - } - else { - printf("get_ff_face_name_max_num < g_face_frame_uid, get_ff_face_name_max_num = %d\n", get_ff_face_name_max_num()); - } - - if (g_face_frame_uid >= 0) { - // deal with register - char visitor_tmp[14] = "Visitor"; - char face_uid_tmp[10]; - sprintf(face_uid_tmp, "%05d", g_face_frame_uid); - strcat(visitor_tmp, face_uid_tmp); - - char base64_image_filename[60] = { 0 }; - sprintf(base64_image_filename, "%d_%d_%d_%d_%d_%d_%ld_%05d", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, - timeinfo->tm_min, timeinfo->tm_sec, msecs_time, g_face_frame_uid); - - char base64_image_filename_path[128] = { 0 }; - sprintf(base64_image_filename_path, "/tmp/face/%s.jpg", base64_image_filename); - //CopyFileTo("/emmc/plugin/Aida_data/tmp/crop.jpg", base64_image_filename_path); - writeImageFromBuffer(base64_image_filename_path, g_decrypt_buff, base64_decode_length); - - char base64_image_filename_path_2[128] = { 0 }; - sprintf(base64_image_filename_path_2, "/emmc/plugin/Aida_data/storage/vip/%s.jpg", base64_image_filename); - //CopyFileTo("/emmc/plugin/Aida_data/tmp/crop.jpg", base64_image_filename_path_2); - writeImageFromBuffer(base64_image_filename_path_2, g_decrypt_buff, base64_decode_length); - - char base64_tmplate_filename_path[128] = { 0 }; - sprintf(base64_tmplate_filename_path, "/emmc/plugin/Aida_data/storage/template/%s.tpl", face_uid_tmp); - //CopyFileTo("/emmc/plugin/Aida_data/tmp/crop.jpg", base64_tmplate_filename_path); - writeImageFromBuffer(base64_tmplate_filename_path, g_decrypt_buff, base64_decode_length); - test_sfe_add_face_group(face_uid_tmp, base64_tmplate_filename_path); - - //if (viewChannelData[0].enable_add_face_frequent_list) - { - sqlite_facegroup_add_face_list(face_uid_tmp, visitor_tmp, "", "9964094f-df62-41a0-a666-134b3dbc9123", "100.0", base64_image_filename, "9964094f-df62-41a0-a666-134b3dbc9123", "", "", "vip", "00:00", "23:59", "2200-12-30_23:59"); - } - - //face_get_watchlist_members(); - - g_face_frame_uid++; - } -#endif - } -#endif - //free(image_buff); - //free(decrypt_buff); - - memset(g_image_buff, 0, MAX_IMG_SIZE_HD); - memset(g_decrypt_buff, 0, MAX_IMG_SIZE_HD); - - - char beforeSendBuffer[64]; - strcpy(beforeSendBuffer, "ok"); - - int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer); - if (send(sock, sendBuffer, sendBufferSize, MSG_MORE) == -1) - printf("\nsend\n"); - - closesocket(sock); - break; - } - else if ((memcmp(recvbuffer, "POST /import_face_list", strlen("POST /import_face_list")) == 0)) // 2023-12-19 Joy - { - printf("\n import_face_list \n"); - printf("recvbuffer: %s\n",recvbuffer); - - closesocket(sock); - break; - } - else if ((memcmp(recvbuffer, "POST /upload_face_licensekey", strlen("POST /upload_face_licensekey")) == 0)) // 2023-12-19 Joy - { - char *dataStart = strchr(recvbuffer, '{'); - if (dataStart != NULL) - { - char *dataEnd = strrchr(recvbuffer, '}'); - if (dataEnd != NULL) - { - size_t dataLength = dataEnd - dataStart + 1; - char jsonData[dataLength + 1]; - strncpy(jsonData, dataStart, dataLength); - jsonData[dataLength] = '\0'; - - char *customerStart = strstr(jsonData, "\"customer\":"); - if (customerStart != NULL) - { - char *customerEnd = strchr(customerStart, ','); - if (customerEnd != NULL) - { - char customerValue[100]; - int customerLength = customerEnd - (customerStart + 12); - strncpy(customerValue, customerStart + 12, customerLength); - customerValue[customerLength] = '\0'; - - if (strcmp(customerValue, "\"MERITLILIN_REST integration\"") == 0) - { - char *saveFilePath = "/emmc/plugin/Aida_data/sfe/iengine.lic"; - FILE *file = fopen(saveFilePath, "w"); - if (file != NULL) - { - fputs(jsonData, file); - fclose(file); - - char successResponse[] = "Please press the 'Apply' button to restart the device."; - int successResponseSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(successResponse), successResponse); - if (send(sock, sendBuffer, successResponseSize, MSG_MORE) == -1) - printf("\nsend\n"); - } - else - { - char fileWriteError[] = "Failed to save the file."; - int fileWriteErrorSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(fileWriteError), fileWriteError); - if (send(sock, sendBuffer, fileWriteErrorSize, MSG_MORE) == -1) - printf("\nsend\n"); - } - } - else - { - char invalidCustomerError[] = "Invalid customer value."; - int invalidCustomerErrorSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(invalidCustomerError), invalidCustomerError); - if (send(sock, sendBuffer, invalidCustomerErrorSize, MSG_MORE) == -1) - printf("\nsend\n"); - } - } - } - else - { - char customerNotFoundError[] = "Customer not found in the request."; - int customerNotFoundErrorSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(customerNotFoundError), customerNotFoundError); - if (send(sock, sendBuffer, customerNotFoundErrorSize, MSG_MORE) == -1) - printf("\nsend\n"); - } - } - else - { - char dataEndNotFoundError[] = "End of data not found in the request."; - int dataEndNotFoundErrorSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(dataEndNotFoundError), dataEndNotFoundError); - if (send(sock, sendBuffer, dataEndNotFoundErrorSize, MSG_MORE) == -1) - printf("\nsend\n"); - } - } - else - { - char jsonDataNotFoundError[] = "JSON data not found in the request."; - int jsonDataNotFoundErrorSize = SetHttpResponse(sendBuffer, _CODE_400, "text/html;", strlen(jsonDataNotFoundError), jsonDataNotFoundError); - if (send(sock, sendBuffer, jsonDataNotFoundErrorSize, MSG_MORE) == -1) - printf("\nsend\n"); - } - - closesocket(sock); - - memset(g_image_buff, 0, MAX_IMG_SIZE_HD); - memset(g_decrypt_buff, 0, MAX_IMG_SIZE_HD); - memset(buffer, 0x00, sizeof(buffer)); - - printf("\n-----------------------upload face licensekey: exit-----------------------\n"); -#if 1 - stop_test_nn_cavalry("upload face licensekey exit"); - //stop_server(); -#endif - //exit(EXIT_SUCCESS); - } -#endif - //usSleep(1000); - memset(buffer, 0x00, sizeof(buffer)); - } - - //printf("\n(%d) [http connection fun] isGetAlarmMotion: %d ", sock, isGetAlarmMotion); - //printf("\nweb process-----double free---2\n"); - if (isGetAlarmMotion) - { - for (int j = 0; j < MAX_CLIENT_SOCKET; j++) - { - if (socketRecords[j].used == 0 && socketRecords[j].sock == -1) - { - socketRecords[j].sock = sock; - - //memset(&(socketRecords[j].recent_sec_data), 0x00, sizeof(SecData)); - //socketRecords[j].thread_id = 0; - socketRecords[j].channel_id = -1; - //socketRecords[j].last_recv_time = time(0); - //socketRecords[j].recent_sec_data[0].recv_time = socketRecords[j].last_recv_time; - socketRecords[j].isGetAlarmMotion = TRUE; - //socketRecords[j].isFirstAlarmMotion = FALSE; - if (websocket_connected) - { - //printf("Set sock:%d isWebSocketConnect: TRUE \n",sock); - socketRecords[j].isWebSocketConnect = TRUE; - } - else - { - //printf("Set sock:%d isWebSocketConnect: FALSE \n", sock); - socketRecords[j].isWebSocketConnect = FALSE; - } - socketRecords[j].isUdpSocket = FALSE; - socketRecords[j].isNvrRequest = 0; - socketRecords[j].isCredentialRequest = 0; - socketRecords[j].debug_type = 1; -#if defined GY_OS_AMBA - //socketRecords[j].iIsAIRelay = 0; -#endif - socketRecords[j].used = 1; - break; - } - } - } - - //printf("\n---------http connection handler ----------- 8\n"); - if (nbytes == SOCKET_ERROR) - { - printf("Unable to connect to server: %d\n", errno); - //printf("\n-----------temp_buffer:%s\n", temp_buffer); - //printf("Unable to connect to server: %d\n", WSAGetLastError()); - //usSleep(2000000); - //WSACleanup(); - //closesocket(sock); - } - - if (isGetAlarmMotion && websocket_connected) - { - //printf("\n(%d) [http connection fun] Sophia isGetAlarmMotion\n", sock); - - ///要關閉reuse - int reuse = 0; - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); - setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); - - int sock_err_hold_times = 0; - //int alarm_send_count = 0; - - while (bHttpServerMainStart) - { - if (sock_err_hold_times >= MAX_SOCK_ERR_HOLD_TIMES * 2) { - //printf("\n------------websocket break 1\n"); - break; - } - - int sock_idx = -1; - - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - //if (socketRecord_ALM[i].sock == sock) - //sock_idx = i; - if (socketRecords[i].used == 1) { - if (socketRecords[i].sock == sock) - { - sock_idx = i; - - socketRecords[i].debug_type = 6; - //socketRecords[i].last_recv_time = time(0); - //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; - break; - } - } - } - - if (sock_idx >= 0) - { - if (socketRecords[sock_idx].isGetAlarmMotion == FALSE || socketRecords[sock_idx].isWebSocketConnect == FALSE) { - //printf("\n------------websocket break 2\n"); - break; - } - pthread_mutex_lock(&mutex_alm); - int len = ALMQueueSize(sock_idx); - pthread_mutex_unlock(&mutex_alm); - //printf("\n--------len:%d\n",len); - if (len > 0) - { - int ret = 1; - - for (int index_len = 0; index_len < len; index_len++) { - pthread_mutex_lock(&mutex_alm); - ALMQueueInfo alm_q_info = ALMQueueFront(sock_idx); - char dupstr[ALMBUFSIZE] = { 0 }; - //strcpy(dupstr, alm_q_info.websocket_content); - strcpy(dupstr, alm_q_info.pszContent); - //int dupstr_len = strlen(dupstr); - - ALMQueuePop(sock_idx); - pthread_mutex_unlock(&mutex_alm); - - //printf("\n---------strlen(dupstr):%d\n", strlen(dupstr)); - if (strlen(dupstr) >= 1) - { -#if 1 - //printf("\n---------%s\n", dupstr); - - //int iAlarm_send_delay_fps = 0; - - //if (socketRecord_ALM[sock_idx].iIsWebsockethybi00 == 1) - //iAlarm_send_delay_fps = WEBSOCKET_SEND_DELAY_B; //6 - //else - //iAlarm_send_delay_fps = WEBSOCKET_SEND_DELAY_A; //0 - - //if (alarm_send_count == iAlarm_send_delay_fps) - { - ret = websocket_response(sock, dupstr); - //alarm_send_count = 0; - } - //else - { - //ret = 1; - //alarm_send_count++; - } - - //ALMQueueClear(sock_idx); //後面有加了 - if (ret <= 0) - { - printf("\n(%d) [http connection fun]#1 printf(send error) and close socket\n", sock); - break; - } - else - { - //printf("\n(%d) [http connection fun]Send successfully.\n", sock); - } -#endif - sock_err_hold_times = 0; - } - else - { - sock_err_hold_times++; - //printf("\n------sock_err_hold_times# A : %d\n", sock_err_hold_times); - } - - if (index_len < len - 1) { - usSleep(25000); - } - } - - - if (ret <= 0) { - break; - } - //printf("\n[http connection fun]-2-1: closesocket:%d\n", sock); - } - else { - sock_err_hold_times++; - //printf("\n------sock_err_hold_times# B : %d\n", sock_err_hold_times); - } - } - else - { - //printf("\n(%d) [http connection fun] there is no correct sock in socketRecord_ALM\n", sock); - sock_err_hold_times++; - //printf("\n------sock_err_hold_times# C : %d\n", sock_err_hold_times); - } -#ifdef GY_OS_AMBA - usSleep(25000); -#elif defined GY_OS_V_SERIES - usSleep(110000); -#else - usSleep(60000); -#endif - - } - - //printf("\n----------------------[http connection fun]Websocket: closesocket:%d\n",sock); - - closesocket(sock); - websocket_connected = 0; - } - else if (isGetAlarmMotion && !(websocket_connected)) - { - //printf("\n(%d) [http connection fun] Sophia isGetAlarmMotion\n", sock); - - int reuse = 1; - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); - setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); - - int sock_err_hold_times = 0; - //int alarm_send_count = 0; - - while (bHttpServerMainStart) - { - if (sock_err_hold_times >= MAX_SOCK_ERR_HOLD_TIMES * 2) - break; - - int sock_idx = -1; - - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - //if (socketRecord_ALM[i].sock == sock) - //sock_idx = i; - if (socketRecords[i].used == 1) { - if (socketRecords[i].sock == sock) - { - sock_idx = i; - - socketRecords[i].debug_type = 7; - //socketRecords[i].last_recv_time = time(0); - //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; - break; - } - } - } - - if (sock_idx >= 0) - { - if (socketRecords[sock_idx].isGetAlarmMotion == FALSE) { - //set_record_process_note("getalarm_8592_end_1"); - break; - } - pthread_mutex_lock(&mutex_alm); - int len = ALMQueueSize(sock_idx); - pthread_mutex_unlock(&mutex_alm); - //printf("\n(%d) [http connection fun] queue_len:%d\n", sock, len); - - if (len > 0) - { - int rtn_s = 1; - set_record_process_note("getalarm_8592_start"); - for (int index_len = 0; index_len < len; index_len++) { - pthread_mutex_lock(&mutex_alm); - ALMQueueInfo alm_q_info = ALMQueueFront(sock_idx); - //char *dupstr = strdup(alm_q_info.pszContent); - char dupstr[ALMBUFSIZE] = { 0 }; - strcpy(dupstr, alm_q_info.pszContent); - int dupstr_len = strlen(dupstr); - //int dupstr_len = alm_q_info.nSize; - - //printf("\n(%d) [http connection fun] (before send)dupstr_len:%d\n", sock, dupstr_len); - //printf("\nstrlen(dupstr): %d\n", strlen(dupstr)); - - ALMQueuePop(sock_idx); - pthread_mutex_unlock(&mutex_alm); - - if (strlen(dupstr) >= 1) - { -#if 1 - - //printf("\n[nweb.c]restful: %d\n", sock); - //int rtn_s = send(sock, alm_q_info_copy.szContent, alm_q_info_copy.nSize, MSG_NOSIGNAL); - //printf("\n-------------[http connection fun]Http: send:%d\n", sock); - rtn_s = send(sock, dupstr, dupstr_len, MSG_NOSIGNAL); - - //printf("\n(%d) [http connection fun](after send) ALMQueueClear",sock); - //ALMQueueClear(sock_idx); //後面有加了 - //dupstr_len = alm_q_info.nSize; - - //printf("\nrtn_s: %d\n", rtn_s); - if (rtn_s <= 0 /*&& rtn_s2 <= 0 && rtn_s3 <= 0*/) - { - break; - } - else { - } - sock_err_hold_times = 0; -#endif - } - else { - sock_err_hold_times++; - } - - if (index_len < len - 1) { - usSleep(25000); - } - } - - if (rtn_s <= 0) { - set_record_process_note("getalarm_8592_end_2"); - break; - } - else { - set_record_process_note("getalarm_8592_end_3"); - } - //-------------------------------jim add 2021/04/15 每次送完getalarmmotion,會關掉socket - //printf("\n[http connection fun]-2-1: closesocket:%d\n", sock); - //closesocket(sock); - } - else { - //set_record_process_note("getalarm_8592_end_4"); - sock_err_hold_times++; - } - } - else { - //set_record_process_note("getalarm_8592_end_5"); - //printf("\n(%d) [http connection fun] there is no correct sock in socketRecord_ALM\n", sock); - //closesocket(sock);//最外層已放 - //break; - sock_err_hold_times++; - } - -#ifdef GY_OS_AMBA - usSleep(25000); -#elif defined GY_OS_V_SERIES - usSleep(110000); -#else - usSleep(60000); -#endif - } - - //printf("\n-------------[http connection fun]Http: closesocket:%d\n", sock); - closesocket(sock); - } - - if (isGetAlarmMotion) { - //printf("\n---------http connection handler ----------- 9\n"); - for (int i = 0; i < MAX_CLIENT_SOCKET; i++) - { - if (socketRecords[i].used == 1 && socketRecords[i].sock == sock) - { - socketRecords[i].sock = -1; - //printf("\n\n(%d) [http connection fun] clean socket[%d]\n\n", sock, i); - //socketRecords[i].thread_id = 0; - socketRecords[i].channel_id = -1; - //socketRecords[i].last_recv_time = time(0); - //socketRecords[i].recent_sec_data[0].recv_time = socketRecords[i].last_recv_time; - socketRecords[i].isGetAlarmMotion = FALSE; - //socketRecords[i].isFirstAlarmMotion = FALSE; - socketRecords[i].isWebSocketConnect = FALSE; - socketRecords[i].isUdpSocket = FALSE; - socketRecords[i].isNvrRequest = 0; - socketRecords[i].isCredentialRequest = 0; - socketRecords[i].debug_type = 0; -#if defined GY_OS_AMBA - //socketRecords[i].iIsAIRelay = 0; -#endif - closesocket(sock); - - pthread_mutex_lock(&mutex_alm); - ALMQueueClear(i); - pthread_mutex_unlock(&mutex_alm); - - socketRecords[i].used = 0; - - break; - } - } - } - - //printf("\n---------http connection handler ----------- 11\n"); - //pthread_mutex_unlock(&mutex_http_connection_handler); - pthread_exit(NULL); -} - -int run_preload_http_server(int http_port) -{ - if (isGYNetReady == FALSE) - { - int socket_desc, client_sock; - struct sockaddr_in server, client; - socklen_t client_length = sizeof(client); - - socket_desc = socket(AF_INET, SOCK_STREAM, 0); - if (socket_desc == -1) - { - printf("[run preload http server] Could not create a socket!\n"); - return 1; - } - //puts("Socket created"); - - //Prepare the sockaddr_in structure - server.sin_family = AF_INET; - server.sin_addr.s_addr = INADDR_ANY; - server.sin_port = htons(http_port); - - struct timeval timeout; - timeout.tv_sec = 5; - timeout.tv_usec = 0; - - setsockopt(socket_desc, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); - setsockopt(socket_desc, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); - - int tcpnodelay = 1; - setsockopt(socket_desc, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); - - int reuse = 1; - setsockopt(socket_desc, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); - setsockopt(socket_desc, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); - - int qlen = 5; - setsockopt(socket_desc, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); - - if (bind(socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) { - printf("\n[run preload http server] Could not bind a socket!\n"); - closesocket(socket_desc); - return 1; - } - - //puts("bind done"); - - if (listen(socket_desc, 256)) { - printf("\n[run preload http server] Could not listen from a socket!\n"); - closesocket(socket_desc); - return 1; - } - - //pthread_t thread_id; - - int count = 5; - fd_set active_fd_set, read_fds; - FD_ZERO(&active_fd_set); - FD_SET(socket_desc, &active_fd_set); - - struct timeval tvSelect; - tvSelect.tv_sec = 1; - tvSelect.tv_usec = 0; - int retval = 0; - is_authorized_run_preload_http_server = 1; - while (bPreloadHttpServerMainStart && (isGYNetReady == FALSE)) - { - for (int countloop = 0; bPreloadHttpServerMainStart && (isGYNetReady == FALSE) && countloop < count; countloop++) - { - read_fds = active_fd_set; - retval = select(socket_desc + 1, &read_fds, NULL, NULL, &tvSelect); - - if (retval == -1) { - printf("\nselect() error #1\n");//perror is strange in nova - break; - } - else if (retval == 0) - { - //printf("\nselect timeout\n"); - } - else - { - //for (int i = 0; i < 256; i++) - { - //if (FD_ISSET(i, &read_fds)) - if (FD_ISSET(socket_desc, &read_fds)) - { - //if (i == socket_desc) - { - client_sock = accept(socket_desc, (struct sockaddr *)&client, &client_length); - - if (client_sock < 0) - { - - } - else - { - timeout.tv_sec = 5; - timeout.tv_usec = 0; - - setsockopt(client_sock, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); - setsockopt(client_sock, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); - - //20210714 ADD - int reuse = 1; - setsockopt(client_sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); - setsockopt(client_sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); - - int qlen = 5; - setsockopt(client_sock, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); - - //if (check_if_socket_ok == 1) - //{ - pthread_t thread_id; - pthread_create(&thread_id, 0, http_connection_handler, (void*)(intptr_t)client_sock); - //} - //else { - //closesocket(client_sock); - //} - } - - - //usSleep(SLEEP_HTTP_CONNECTION_HANDLER*1000); - //usSleep(1000); - //break; - } - } - //else { - //usSleep(50); - //} - } - } - - usSleep(SLEEP_HTTP_CONNECTION_HANDLER * 1000); - //usSleep(1000); - } - - if (retval == -1) { - break; - } - } - - is_authorized_run_preload_http_server = 0; - //bPreloadHttpServerMainStart = 0; - FD_CLR(socket_desc, &active_fd_set); - closesocket(socket_desc); - } - - return 0; -} - -int run_http_server(char *option, void* _zc, CNNType cnn_type/*, int layer_count, network nets[], char **names[], image **alphabet, float nms[]*/, float thresh, float hier_thresh, int dont_show, int ext_output, int save_labels, - char *mac_address, char *ip_address, int http_port, LicenseType licenseType, AdvanceLicenseType advLicenseType, AuthFailStatusCode afsCode, size_t layerFeatureType[], char* strLicenseType) -{ - http_cnn_type = cnn_type; - for (int n = 0; n < MAX_LAYER_NUM; n++) - { - //http_nets[n] = nets[n]; - //http_names[n] = names[n]; - //http_nms[n] = nms[n]; - http_layerFeatureType[n] = layerFeatureType[n]; - } - //http_layer_count = layer_count; - //http_alphabet = alphabet; - http_thresh = thresh; - http_hier_thresh = hier_thresh; - http_dont_show = dont_show; - http_ext_output = ext_output; - http_save_labels = save_labels; - //http_mac_address = mac_address; - //http_ip_address = ip_address; - http_http_port = http_port; - http_licenseType = licenseType; - http_afsCode = afsCode; - http_featureType = featureType; - http_strLicenseType = strLicenseType; - //http_strLicenseStatus = strLicenseStatus; - //http_strUnlockingKey = strUnlockingKey; - http_advLicenseType = advLicenseType; - - if (unlockingKeyInnoFR == 1||g_IsToFDevice == 1 || g_IsRadarDevice == 1 || td_weight_num >= 1 || check_if_fe_fail == 1 || licenseType == _PERMANENT_LICENSE_MULTI || licenseType == _TRIAL_LICENSE_MULTI || licenseType == _PERMANENT_LICENSE_MULTI_POST || - licenseType == _LICENSE_FPS06 || licenseType == _LICENSE_FPS12 || licenseType == _LICENSE_FPS18 || licenseType == _LICENSE_FPS24 || licenseType == _LICENSE_FPS30 || - licenseType == _LICENSE_FPS36 || licenseType == _LICENSE_FPS42 || licenseType == _LICENSE_FPS48 || licenseType == _LICENSE_FPS54 || licenseType == _LICENSE_FPS60 || - licenseType == _TRIAL_LICENSE_FPS06 || licenseType == _TRIAL_LICENSE_FPS12 || licenseType == _TRIAL_LICENSE_FPS18 || licenseType == _TRIAL_LICENSE_FPS24 || licenseType == _TRIAL_LICENSE_FPS30 || - licenseType == _TRIAL_LICENSE_FPS36 || licenseType == _TRIAL_LICENSE_FPS42 || licenseType == _TRIAL_LICENSE_FPS48 || licenseType == _TRIAL_LICENSE_FPS54 || licenseType == _TRIAL_LICENSE_FPS60) //multi-thread server - { - int socket_desc = 0; - - //Web - socket_desc = socket(AF_INET, SOCK_STREAM, 0); - if (socket_desc == -1) - { - printf("[run http server] Could not create a socket!\n"); - usSleep(SLEEP_RUN_HTTP_SERVER_THREAD);//避免sock建失敗後,又馬上詢問。 - return 1; - } - - struct sockaddr_in server; - bzero(&server, sizeof(server)); - - //Prepare the sockaddr_in structure - server.sin_family = AF_INET; - server.sin_addr.s_addr = INADDR_ANY; - server.sin_port = htons(http_port); - - struct timeval timeout; - timeout.tv_sec = 5; - timeout.tv_usec = 0; - int tcpnodelay = 1; - int reuse = 1; - int qlen = 5; - int priority = 2; - - setsockopt(socket_desc, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); - setsockopt(socket_desc, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); - setsockopt(socket_desc, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); - setsockopt(socket_desc, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); - setsockopt(socket_desc, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); - setsockopt(socket_desc, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); - setsockopt(socket_desc, SOL_SOCKET, SO_PRIORITY, (const char*)&priority, sizeof(priority)); - - if (bind(socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) - { - printf("\n[run http server] Could not bind a socket!\n"); - closesocket(socket_desc); - usSleep(SLEEP_RUN_HTTP_SERVER_THREAD);//避免sock建失敗後,又馬上詢問。 - return 1; - } - //puts("bind done"); - - if (listen(socket_desc, 256) < 0)//MAX_CLIENT_SOCKET - { - printf("\n[run http server] Could not listen from a socket!\n"); - closesocket(socket_desc); - usSleep(SLEEP_RUN_HTTP_SERVER_THREAD);//避免sock建失敗後,又馬上詢問。 - return 1; - } - - int maxfd = 0; - fd_set active_fd_set, read_fds; - FD_ZERO(&active_fd_set); - FD_SET(socket_desc, &active_fd_set); - - struct timeval tvSelect; - tvSelect.tv_sec = 1; - tvSelect.tv_usec = 0; - int retval = 0; - - //pthread_t thread_id_for_sock[FD_SETSIZE] = { 0 }; - //first_is_connection_authorized = 0; - while (bHttpServerMainStart) - { - python_check_webstatus = 1; // Ming add - // printf("\n[run http server] while start\n"); - //for (int countloop = 0; bHttpServerMainStart && countloop < count; countloop++) - { - maxfd = socket_desc; - //maxfd = socket_desc > sockfd ? socket_desc : sockfd; - //printf("\n----#1-----maxfd:%d\n", maxfd); - - read_fds = active_fd_set; - retval = select(maxfd + 1, &read_fds, NULL, NULL, &tvSelect); - //printf("\n [[[run http server] retval:%d]]\n", retval); - - if (retval == -1) { - printf("\nselect()\n"); - break; - } - else if (retval == 0) - { - //printf("\nselect timeout\n"); - } - else - { - //for (int i = 0; i < 256; i++)//FD_SETSIZE - { - //printf("\n [[[run http server] i:%d]]\n", i); - - //if (FD_ISSET(i, &read_fds)) - if (FD_ISSET(socket_desc, &read_fds)) - { - //if (i == socket_desc) - { - //printf("\n [[[run http server] i=socket_desc:%d]]\n", socket_desc); - struct sockaddr_in client; - socklen_t client_length = sizeof(client); - int client_sock = accept(socket_desc, (struct sockaddr *)&client, &client_length); - //#ifdef _DEBUG_AMBA - //printf("\n(%d) [[[run http server] while start ======================]]\n", client_sock); - //#endif - - if (client_sock < 0) - { - //printf("[[[run http server] invalid socket]]\n"); - } - else - { - - //printf("\n[[[run http server] while start 1======================]]\n"); - timeout.tv_sec = 5;//3 - timeout.tv_usec = 0; - //reuse = 1; - //qlen = 5; - - setsockopt(client_sock, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(timeout)); - setsockopt(client_sock, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); - setsockopt(client_sock, IPPROTO_TCP, TCP_NODELAY, (const char*)&tcpnodelay, sizeof(tcpnodelay)); - //20210714 ADD - setsockopt(client_sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); - setsockopt(client_sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse)); - setsockopt(client_sock, SOL_TCP, TCP_FASTOPEN, (const char*)&qlen, sizeof(qlen)); - setsockopt(client_sock, SOL_SOCKET, SO_PRIORITY, (const char*)&priority, sizeof(priority)); - - //printf("\n[[[run http server] while start 2======================]]\n"); - - - //if (check_if_socket_ok == 1) { - pthread_t thread_id; - pthread_create(&thread_id, 0, http_connection_handler, (void*)(intptr_t)client_sock); - //} - //else { - //closesocket(client_sock); - //} - } - - //usSleep(SLEEP_HTTP_CONNECTION_HANDLER*1000); - //break; - } - //usSleep(1000); - //printf("\n[run http server] double free - 1\n"); - //usSleep(SLEEP_HTTP_CONNECTION_HANDLER * 1000); - } - //else { - //usSleep(50); - //} - //printf("\n[run http server] double free - 2\n"); - } - //printf("\n[run http server] double free - 3\n"); - } - //printf("\n[run http server] double free - 4\n"); - } - - //usSleep(SLEEP_HTTP_CONNECTION_HANDLER*1000); - //printf("\n[run http server] while end\n"); - usSleep(SLEEP_HTTP_CONNECTION_HANDLER * 1000); - //usSleep(1000); - - } - - FD_CLR(socket_desc, &active_fd_set); - //printf("\n\n(%d)[[[run http server] while end ======================]]\n\n", client_sock); - closesocket(socket_desc); - - } - else if (licenseType == _PERMANENT_LICENSE_SINGLE || licenseType == _TRIAL_LICENSE_SINGLE || licenseType == _PERMANENT_LICENSE_SINGLE_POST) //single thread version - { - - } - - //printf("\n[[[run http server] end ======================]]\n\n"); - return 0; -} - - -#if defined GY_OS_AMBA || defined GY_OS_NOVA -void import_lpr_list_file(char *headerBuffer,char *multiPartBoundary,int bIsMultipart,char *contentBuffer,long nTotalContentLen) { - //printf("\n---------------import lpr list:%d\n",1); - char *image_buff = NULL; - image_buff = malloc(CONTENT_BUFSIZE); - char *cp = NULL; - char *tempPtr = NULL; - if ((cp = strstr(headerBuffer, "boundary=")) != NULL) - { - //printf("\n---------------import lpr list:%d\n", 2); - - int strlen = 0; - tempPtr = cp + 9; - cp = strstr(tempPtr, "\r\n"); - if (cp != NULL) - { - strlen = cp - tempPtr; - if (strlen > 0) - { - memset(multiPartBoundary, 0, MAX_MSG_LEN); - //char endStr[] = "--"; - strncpy(multiPartBoundary, tempPtr, strlen); - //strcat(multiPartBoundary,endStr); - } - - } - } - //printf("\n---------------import lpr list:%d\n", 3); - - if (bIsMultipart) - { - char* pContent = contentBuffer; - char* pBlockStart = contentBuffer; - - memset(image_buff, 0x00, CONTENT_BUFSIZE); - size_t nbytes = 0; - size_t nTotalBytes = 0; - //printf("\n---------------import lpr list:%d\n", 4); - for (int i = 0; i < nTotalContentLen; i++) - { - pContent = contentBuffer + i; - if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) - { - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - i += (pBlockStart - pContent - 1); - } - else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) - { - pBlockStart = strstr(pContent, "\r\n\r\n"); - pBlockStart += 4; - i += (pBlockStart - pContent - 1); - } - else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) - { - if (pContent - pBlockStart == 0) - nbytes = pContent - pBlockStart; - else if (pContent - pBlockStart > 0) - nbytes = (pContent - pBlockStart) - strlen("\r\n"); - memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); - nTotalBytes += nbytes; - if (nbytes != 0)//find end of boundary - { - char endStr[] = "--"; - pBlockStart = strstr(pContent, endStr); - pBlockStart += 2; - } - else - { - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - } - - i += (pBlockStart - pContent - 1); - } - } - } - - //printf("\n---------------nTotalContentLen:%d\n", nTotalContentLen); - //printf("\n---------------import lpr list:%d\n", 5); - //printf("\n-----multiPartBoundary:%s\n", multiPartBoundary); - //printf("\n--------------strlen(contentBuffer):%d\n", strlen(contentBuffer)); - //printf("\n--------------strlen(image_buff):%d\n", strlen(image_buff)); - //printf("\n--------------contentBuffer:%s\n", contentBuffer); - -#if 1 - if (start_to_import_file == 0 && !((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf))) - { - printf("file type error.:%x,%x,%x\n", image_buff[0], image_buff[1], image_buff[2]); - } - else -#endif - { - start_to_import_file = 1; - - -#if 1 - char *lpr_data_p = NULL; - int rule_reject = 0; - int lpr_max_length = 0; - int lpr_b_length = 0; - int lpr_w_length = 0; - int _max_len = COUNT_BLACK + COUNT_WHITE - 200; - char *lpr_line_data = NULL, *name = NULL, *value = NULL; - int lpr_len = 0; - int nlen; - char *lpr_list_type = NULL; - char *lpr_name = NULL; - char *lpr_usrname = NULL; - char *lpr_other = NULL; - char *lpr_schedule_start = NULL; - char *lpr_schedule_end = NULL; - char *lpr_endtime = NULL; - char *lpr_detect_level = NULL; - //printf("\n---------------import lpr list:%d\n", 61101); - //printf("\n---------------import lpr list:%d\n", 61111); - //printf("\n---------------import lpr list:%d\n", 61121); - //printf("\n---------------import lpr list:%d\n", 9); - char *lpr_line_end = NULL; - if ((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf)) - { - lpr_data_p = image_buff + 3;// 0xEF 0xBB 0xBF utf8 with BOM - } - else { - lpr_data_p = image_buff + 2; - } - - lpr_line_data = lpr_data_p; - nlen = strlen(lpr_data_p); - lpr_line_end = strstr(lpr_data_p, "\r\n"); - if (lpr_line_end == NULL) - lpr_line_end = strstr(lpr_data_p, "\n"); - if (lpr_line_end != NULL) - lpr_len = lpr_line_end - lpr_line_data; - - //fprintf(stderr, "CGI[nlen string] : %d\n", nlen); - //fprintf(stderr, "CGI[lpr_data_p nlen] : %s\n",lpr_data_p + nlen); - //printf("\n---------------import lpr list:%d\n", 7); - for (lpr_line_data = lpr_data_p; lpr_line_data < (lpr_data_p + nlen);) - { - value = lpr_list_type = lpr_line_data; - - //Assign variable - for (lpr_line_data += lpr_len; lpr_line_data < (lpr_data_p + nlen) && (!lpr_line_data[0] || (lpr_line_data[0] == '\r') || (lpr_line_data[0] == '\n')); lpr_line_data++); - - name = value; - lpr_name = strstr(value, ",") + 1; - value = lpr_name; - lpr_usrname = strstr(value, ",") + 1; - //name = strsep(&value, ","); - //lpr_name = strsep(&value, ","); - //lpr_usrname = strsep(&value, ","); - - if (lpr_name == NULL || lpr_list_type == NULL || lpr_usrname == NULL) - break; - - if (lpr_max_length == _max_len) - { - //printf("\n---------------import lpr list:%d\n", 71); - rule_reject = 1; - break; - } - - if ((strncmp(name, ACT_PARAM_BKLISTNAME, strlen(ACT_PARAM_BKLISTNAME)) == 0) || (strncmp(name, S_ACT_PARAM_BKLISTNAME, strlen(S_ACT_PARAM_BKLISTNAME)) == 0) || (strncmp(name, BKLISTNAME, strlen(BKLISTNAME)) == 0)) - lpr_b_length++; - else if ((strncmp(name, ACT_PARAM_WTLISTNAME, strlen(ACT_PARAM_WTLISTNAME)) == 0) || (strncmp(name, S_ACT_PARAM_WTLISTNAME, strlen(S_ACT_PARAM_WTLISTNAME)) == 0) || (strncmp(name, WTLISTNAME, strlen(WTLISTNAME)) == 0)) - lpr_w_length++; - else - { - //printf("\n---------------import lpr list:%d\n", 72); - continue; - //rule_reject = 1; - //break; - } - - if (lpr_b_length > COUNT_BLACK - 100) - { - //printf("\n---------------import lpr list:%d\n", 73); - rule_reject = 1; - break; - } - - if (lpr_w_length > COUNT_WHITE - 100) - { - //printf("\n---------------import lpr list:%d\n", 74); - rule_reject = 1; - break; - } - - lpr_max_length++; - - lpr_line_end = strstr(lpr_line_data, "\r\n"); - if (lpr_line_end == NULL) - lpr_line_end = strstr(lpr_line_data, "\n"); - - if (lpr_line_end != NULL) - lpr_len = lpr_line_end - lpr_line_data; - } - //printf("\n---------------import lpr list:%d\n", 8); - if (rule_reject != 1) - { - //printf("\n---------------import lpr list:%d\n", 88); - //callback_reset_db_list(); //clean black&white - if ((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf)) - { - lpr_data_p = image_buff + 3;// 0xEF 0xBB 0xBF utf8 with BOM - } - else { - //printf("\n--------------image_buff:%s\n", image_buff + 2); - lpr_data_p = image_buff + 2; - } - lpr_line_data = lpr_data_p; - nlen = strlen(lpr_data_p); - lpr_line_end = strstr(lpr_data_p, "\r\n"); - - if (lpr_line_end == NULL) - lpr_line_end = strstr(lpr_data_p, "\n"); - - if (lpr_line_end != NULL) - lpr_len = lpr_line_end - lpr_line_data; - - //fprintf(stderr, "CGI[nlen string] : %d\n", nlen); - //fprintf(stderr, "CGI[lpr_data_p nlen] : %s\n",lpr_data_p + nlen); - for (lpr_line_data = lpr_data_p; lpr_line_data < (lpr_data_p + nlen);) - { - value = lpr_list_type = lpr_line_data; - /* Skip to next assignment */ - //fprintf(stderr, "[string] : %s\n", lpr_line_data); - //fprintf(stderr, "[string len] : %d\n", strlen(lpr_line_data)); - - //Assign variable - for (lpr_line_data += lpr_len; lpr_line_data < (lpr_data_p + nlen) && (!lpr_line_data[0] || (lpr_line_data[0] == '\r') || (lpr_line_data[0] == '\n')); lpr_line_data++); - - name = strsep(&value, ","); - lpr_name = strsep(&value, ","); - lpr_usrname = strsep(&value, ","); - lpr_other = strsep(&value, ","); - //lpr_address = strsep(&value, ","); - //lpr_address = strsep(&value, ","); - lpr_schedule_start = strsep(&value, ","); - lpr_schedule_end = strsep(&value, ","); - lpr_endtime = strsep(&value, ","); - if ((lpr_detect_level = strsep(&value, "\r\n")) == NULL) - lpr_detect_level = strsep(&value, "\n"); - lpr_detect_level = rtrim(lpr_detect_level); - - //lpr_exist= strsep(&value, ","); - //lpr_paystatus = strsep(&value, ","); - //lpr_paystatus =rtrim(lpr_paystatus); - - for (int try_counts = 0; try_counts < 5; try_counts++) { - int ret_action = action_lpr_import_infomation(lpr_name, lpr_list_type, lpr_usrname, lpr_other, lpr_schedule_start, lpr_schedule_end, lpr_endtime, lpr_detect_level); //lpr_other); - if (ret_action) - break; - usSleep(10000); - } - - g_count_lpr_insert_times++; - lpr_line_end = strstr(lpr_line_data, "\r\n"); - - if (lpr_line_end == NULL) - lpr_line_end = strstr(lpr_line_data, "\n"); - - if (lpr_line_end != NULL) - lpr_len = lpr_line_end - lpr_line_data; - } - } -#endif - printf("lpr list file upload ok.\n"); - } - - //AI recognizing process - clock_t c1 = clock(); - ///Steven MARK TEMP - //printf("\n---------------import lpr list:%d\n", 11); - - clock_t c2 = clock(); - double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); - printf("recognition time: %f\n", dDiff); - if (image_buff) { - free(image_buff); - image_buff = NULL; - } -} - -void *import_lpr_list_file_thread(void *ptr) { - pthread_detach(pthread_self()); - setPthreadName("import_lpr"); - //printf("\n--------------import lpr list file thread\n"); - import_lpr_list_file(g_headerBuffer, g_multiPartBoundary, g_bIsMultipart, g_contentBuffer, g_nTotalContentLen); - g_count_lpr_insert_times = -1; - pthread_exit(NULL); -} -#ifdef GY_OS_AMBA -void import_face_list_file(char *headerBuffer, char *multiPartBoundary, int bIsMultipart, char *contentBuffer, long nTotalContentLen) { - //printf("\n---------------import lpr list:%d\n",1); - char *image_buff = NULL; - image_buff = malloc(CONTENT_BUFSIZE); - char *cp = NULL; - char *tempPtr = NULL; - if ((cp = strstr(headerBuffer, "boundary=")) != NULL) - { - //printf("\n---------------import lpr list:%d\n", 2); - - int strlen = 0; - tempPtr = cp + 9; - cp = strstr(tempPtr, "\r\n"); - if (cp != NULL) - { - strlen = cp - tempPtr; - if (strlen > 0) - { - memset(multiPartBoundary, 0, MAX_MSG_LEN); - strncpy(multiPartBoundary, tempPtr, strlen); - } - - } - } - //printf("\n---------------import lpr list:%d\n", 3); - - if (bIsMultipart) - { - char* pContent = contentBuffer; - char* pBlockStart = contentBuffer; - - memset(image_buff, 0x00, CONTENT_BUFSIZE); - size_t nbytes = 0; - size_t nTotalBytes = 0; - //printf("\n---------------import lpr list:%d\n", 4); - for (int i = 0; i < nTotalContentLen; i++) - { - pContent = contentBuffer + i; - if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) - { - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - i += (pBlockStart - pContent - 1); - } - else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) - { - pBlockStart = strstr(pContent, "\r\n\r\n"); - pBlockStart += 4; - i += (pBlockStart - pContent - 1); - } - else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) - { - if (pContent - pBlockStart == 0) - nbytes = pContent - pBlockStart; - else if (pContent - pBlockStart > 0) - nbytes = (pContent - pBlockStart) - strlen("\r\n"); - memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); - nTotalBytes += nbytes; - if (nbytes != 0)//find end of boundary - { - char endStr[] = "--"; - pBlockStart = strstr(pContent, endStr); - pBlockStart += 2; - } - else - { - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - } - - i += (pBlockStart - pContent - 1); - } - } - } - - //printf("\n---------------nTotalContentLen:%d\n", nTotalContentLen); - //printf("\n---------------import lpr list:%d\n", 5); - //printf("\n-----multiPartBoundary:%s\n", multiPartBoundary); - //printf("\n--------------strlen(contentBuffer):%d\n", strlen(contentBuffer)); - //printf("\n--------------strlen(image_buff):%d\n", strlen(image_buff)); - //printf("\n--------------contentBuffer:%s\n", contentBuffer); - - if (start_to_import_file == 0 && !((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf))) - { - printf("file type error.:%x,%x,%x\n", image_buff[0], image_buff[1], image_buff[2]); - } - else - { - start_to_import_file = 1; - - char *lpr_data_p = NULL; - int rule_reject = 0; - int lpr_max_length = 0; - int lpr_b_length = 0; - int lpr_w_length = 0; - int _max_len = COUNT_BLACK + COUNT_WHITE - 200; - char *lpr_line_data = NULL, *name = NULL, *value = NULL; - int lpr_len = 0; - int nlen; - char *lpr_list_type = NULL; - char *lpr_name = NULL; - char *lpr_usrname = NULL; - char *lpr_other = NULL; - char *lpr_schedule_start = NULL; - char *lpr_schedule_end = NULL; - char *lpr_endtime = NULL; - char *lpr_detect_level = NULL; - //printf("\n---------------import lpr list:%d\n", 61101); - //printf("\n---------------import lpr list:%d\n", 61111); - //printf("\n---------------import lpr list:%d\n", 61121); - //printf("\n---------------import lpr list:%d\n", 9); - char *lpr_line_end = NULL; - if ((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf)) - { - lpr_data_p = image_buff + 3;// 0xEF 0xBB 0xBF utf8 with BOM - } - else { - lpr_data_p = image_buff + 2; - } - - lpr_line_data = lpr_data_p; - nlen = strlen(lpr_data_p); - lpr_line_end = strstr(lpr_data_p, "\r\n"); - if (lpr_line_end == NULL) - lpr_line_end = strstr(lpr_data_p, "\n"); - if (lpr_line_end != NULL) - lpr_len = lpr_line_end - lpr_line_data; - - //fprintf(stderr, "CGI[nlen string] : %d\n", nlen); - //fprintf(stderr, "CGI[lpr_data_p nlen] : %s\n",lpr_data_p + nlen); - //printf("\n---------------import lpr list:%d\n", 7); - for (lpr_line_data = lpr_data_p; lpr_line_data < (lpr_data_p + nlen);) - { - value = lpr_list_type = lpr_line_data; - - // Assign variable - for (lpr_line_data += lpr_len; lpr_line_data < (lpr_data_p + nlen) && (!lpr_line_data[0] || (lpr_line_data[0] == '\r') || (lpr_line_data[0] == '\n')); lpr_line_data++); - - name = value; - lpr_name = strstr(value, ",") + 1; - value = lpr_name; - lpr_usrname = strstr(value, ",") + 1; - - if (lpr_name == NULL || lpr_list_type == NULL || lpr_usrname == NULL) - break; - - if (lpr_max_length == _max_len) - { - //printf("\n---------------import lpr list:%d\n", 71); - rule_reject = 1; - break; - } - - if ((strncmp(name, ACT_PARAM_BKLISTNAME, strlen(ACT_PARAM_BKLISTNAME)) == 0) || (strncmp(name, S_ACT_PARAM_BKLISTNAME, strlen(S_ACT_PARAM_BKLISTNAME)) == 0) || (strncmp(name, BKLISTNAME, strlen(BKLISTNAME)) == 0)) - lpr_b_length++; - else if ((strncmp(name, ACT_PARAM_WTLISTNAME, strlen(ACT_PARAM_WTLISTNAME)) == 0) || (strncmp(name, S_ACT_PARAM_WTLISTNAME, strlen(S_ACT_PARAM_WTLISTNAME)) == 0) || (strncmp(name, WTLISTNAME, strlen(WTLISTNAME)) == 0)) - lpr_w_length++; - else - { - continue; - } - - if (lpr_b_length > COUNT_BLACK - 100) - { - rule_reject = 1; - break; - } - - if (lpr_w_length > COUNT_WHITE - 100) - { - rule_reject = 1; - break; - } - - lpr_max_length++; - - lpr_line_end = strstr(lpr_line_data, "\r\n"); - if (lpr_line_end == NULL) - lpr_line_end = strstr(lpr_line_data, "\n"); - - if (lpr_line_end != NULL) - lpr_len = lpr_line_end - lpr_line_data; - } - //printf("\n---------------import lpr list:%d\n", 8); - if (rule_reject != 1) - { - //printf("\n---------------import lpr list:%d\n", 88); - //callback_reset_db_list(); //clean black&white - if ((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf)) - { - lpr_data_p = image_buff + 3;// 0xEF 0xBB 0xBF utf8 with BOM - } - else { - //printf("\n--------------image_buff:%s\n", image_buff + 2); - lpr_data_p = image_buff + 2; - } - lpr_line_data = lpr_data_p; - nlen = strlen(lpr_data_p); - lpr_line_end = strstr(lpr_data_p, "\r\n"); - - if (lpr_line_end == NULL) - lpr_line_end = strstr(lpr_data_p, "\n"); - - if (lpr_line_end != NULL) - lpr_len = lpr_line_end - lpr_line_data; - - //fprintf(stderr, "CGI[nlen string] : %d\n", nlen); - //fprintf(stderr, "CGI[lpr_data_p nlen] : %s\n",lpr_data_p + nlen); - for (lpr_line_data = lpr_data_p; lpr_line_data < (lpr_data_p + nlen);) - { - value = lpr_list_type = lpr_line_data; - /* Skip to next assignment */ - //fprintf(stderr, "[string] : %s\n", lpr_line_data); - //fprintf(stderr, "[string len] : %d\n", strlen(lpr_line_data)); - - //Assign variable - for (lpr_line_data += lpr_len; lpr_line_data < (lpr_data_p + nlen) && (!lpr_line_data[0] || (lpr_line_data[0] == '\r') || (lpr_line_data[0] == '\n')); lpr_line_data++); - - name = strsep(&value, ","); - lpr_name = strsep(&value, ","); - lpr_usrname = strsep(&value, ","); - lpr_other = strsep(&value, ","); - //lpr_address = strsep(&value, ","); - //lpr_address = strsep(&value, ","); - lpr_schedule_start = strsep(&value, ","); - lpr_schedule_end = strsep(&value, ","); - lpr_endtime = strsep(&value, ","); - if ((lpr_detect_level = strsep(&value, "\r\n")) == NULL) - lpr_detect_level = strsep(&value, "\n"); - lpr_detect_level = rtrim(lpr_detect_level); - - //lpr_exist= strsep(&value, ","); - //lpr_paystatus = strsep(&value, ","); - //lpr_paystatus =rtrim(lpr_paystatus); - - for (int try_counts = 0; try_counts < 5; try_counts++) { - int ret_action = action_lpr_import_infomation(lpr_name, lpr_list_type, lpr_usrname, lpr_other, lpr_schedule_start, lpr_schedule_end, lpr_endtime, lpr_detect_level); //lpr_other); - if (ret_action) - break; - usSleep(10000); - } - - g_count_lpr_insert_times++; - lpr_line_end = strstr(lpr_line_data, "\r\n"); - - if (lpr_line_end == NULL) - lpr_line_end = strstr(lpr_line_data, "\n"); - - if (lpr_line_end != NULL) - lpr_len = lpr_line_end - lpr_line_data; - } - } - printf("lpr list file upload ok.\n"); - } - - //AI recognizing process - clock_t c1 = clock(); - ///Steven MARK TEMP - //printf("\n---------------import lpr list:%d\n", 11); - - clock_t c2 = clock(); - double dDiff = ((float)(c2 - c1) / CLOCKS_PER_SEC); - printf("recognition time: %f\n", dDiff); - if (image_buff) { - free(image_buff); - image_buff = NULL; - } -} - -void *import_face_list_file_thread(void *ptr) { - pthread_detach(pthread_self()); - setPthreadName("import_lpr"); - import_face_list_file(g_headerBuffer, g_multiPartBoundary, g_bIsMultipart, g_contentBuffer, g_nTotalContentLen); - g_count_lpr_insert_times = -1; - pthread_exit(NULL); -} - -int get_g_check_if_change_preset() { - return g_check_if_change_preset; -} - -void set_g_check_if_change_preset_to_zero() { - g_check_if_change_preset = 0; -} -#endif -#endif - -#ifdef GY_OS_AMBA -// a113n radarbg - -void import_radarbg(char *headerBuffer, char *multiPartBoundary, int bIsMultipart, char *contentBuffer, long nTotalContentLen) -{ - // printf("\n---------------import lpr list:%d\n",1); - printf("[import_radarbg] Enter\n"); - char *image_buff = NULL; - image_buff = malloc(CONTENT_BUFSIZE); - char *cp = NULL; - char *tempPtr = NULL; - if ((cp = strstr(headerBuffer, "boundary=")) != NULL) // 我猜這邊是將來自 http request 的 header 拆開, 因為檔案跟在後面 - { - // printf("\n---------------import lpr list:%d\n", 2); - - int strlen = 0; - tempPtr = cp + 9; - cp = strstr(tempPtr, "\r\n"); - if (cp != NULL) - { - strlen = cp - tempPtr; - if (strlen > 0) - { - memset(multiPartBoundary, 0, MAX_MSG_LEN); - // char endStr[] = "--"; - strncpy(multiPartBoundary, tempPtr, strlen); - // strcat(multiPartBoundary,endStr); - } - } - } - // printf("\n---------------import lpr list:%d\n", 3); - - if (bIsMultipart) // 這邊我猜是如果檔案被拆分成多份封包的處理之類的 - { - char *pContent = contentBuffer; - char *pBlockStart = contentBuffer; - - memset(image_buff, 0x00, CONTENT_BUFSIZE); - size_t nbytes = 0; - size_t nTotalBytes = 0; - // printf("\n---------------import lpr list:%d\n", 4); - for (int i = 0; i < nTotalContentLen; i++) - { - pContent = contentBuffer + i; - if (strncmp(pContent, "Content-Disposition:", strlen("Content-Disposition:")) == 0) - { - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - i += (pBlockStart - pContent - 1); - } - else if (strncmp(pContent, "Content-Type:", strlen("Content-Type:")) == 0) - { - pBlockStart = strstr(pContent, "\r\n\r\n"); - pBlockStart += 4; - i += (pBlockStart - pContent - 1); - } - else if (strncmp(pContent, multiPartBoundary, strlen(multiPartBoundary)) == 0) - { - if (pContent - pBlockStart == 0) - nbytes = pContent - pBlockStart; - else if (pContent - pBlockStart > 0) - nbytes = (pContent - pBlockStart) - strlen("\r\n"); - memcpy(image_buff + nTotalBytes, pBlockStart, nbytes); - nTotalBytes += nbytes; - if (nbytes != 0) // find end of boundary - { - char endStr[] = "--"; - pBlockStart = strstr(pContent, endStr); - pBlockStart += 2; - } - else - { - pBlockStart = strstr(pContent, "\r\n"); - pBlockStart += 2; - } - - i += (pBlockStart - pContent - 1); - } - } - } // 做完之後應該是 image_buff 是檔案 , 但這邊尷尬的是 img 應該是三維陣列 - - // printf("\n---------------nTotalContentLen:%d\n", nTotalContentLen); - // printf("\n---------------import lpr list:%d\n", 5); - // printf("\n-----multiPartBoundary:%s\n", multiPartBoundary); - // printf("\n--------------strlen(contentBuffer):%d\n", strlen(contentBuffer)); - // printf("\n--------------strlen(image_buff):%d\n", strlen(image_buff)); - // printf("\n--------------contentBuffer:%s\n", contentBuffer); - - { // img 存檔 - // Mat tempImg; - // tempImg = Mat(600, 800, CV_8UC3, image_buff); // 一維陣列要給 pitch 那是啥 - // printf("[import_radarbg] tempImg init success\n"); - // imwrite("/emmc/plugin/Aida_data/radar/radar_uploadtest.jpg", tempImg); - // printf("[import_radarbg] imwrite success\n"); - // tempImg.release(); - // 上面是 c++ code 所以這邊改用下面 配合開頭 include colordetector.cpp - printf("[import_radarbg] saverawrgbtojpg enter\n"); - SaveRawRGBToJPG("/emmc/plugin/Aida_data/radar/radar_uploadtest.jpg", image_buff, 800, 0, 600, 1); // For normal type - printf("[import_radarbg] saverawrgbtojpg end\n"); - } - -#if 0 - if (!((image_buff[0] == 0xef) && (image_buff[1] == 0xbb) && (image_buff[2] == 0xbf))) // 這邊是檔案類型檢查 要確認一下 jpg 格式怎麼檢查 - { - printf("file type error.:%x,%x,%x\n", image_buff[0], image_buff[1], image_buff[2]); - } - else - { // 檔案對了接下來應該就存檔 我猜的 這邊應該要去找存圖片的部分怎麼做 - Mat tempImg; - tempImg = Mat(h, w, CV_8UC3, image_buff); - printf("radar back ground img file upload ok.\n"); - } -#endif - - if (image_buff) - { - free(image_buff); - image_buff = NULL; - } -} - -void *import_radarbg_thread(void *ptr) -{ - pthread_detach(pthread_self()); - import_radarbg(g_headerBuffer, g_multiPartBoundary, g_bIsMultipart, g_contentBuffer, g_nTotalContentLen); - // g_count_lpr_insert_times = -1; - pthread_exit(NULL); -} -#endif \ No newline at end of file diff --git a/src/nweb_Ming.h b/src/nweb_Ming.h deleted file mode 100644 index 38d312b..0000000 --- a/src/nweb_Ming.h +++ /dev/null @@ -1,1123 +0,0 @@ -#if 1 -#pragma once -#ifndef NWEB_H -#define NWEB_H -//#include "structures.h" -#include "define_inc.h" -#include "zlog.h" -#include "cv.h" -#include "utility.h" -#include "onvif_data.h" -#ifdef GY_OS_NOVA -#include "bbox_receive.h" -#endif -#include -#include -#if defined GY_OS_AMBA || defined GY_OS_NOVA -#include -#endif -#ifdef GY_OS_WIN -#include "opencv2/highgui/highgui_c.h" -#include "opencv2/imgproc/imgproc_c.h" -#endif - -#include -#include -#include - -#ifdef GY_OS_AMBA -//#include "face_parser.h" -#endif - -#ifdef __cplusplus -extern "C" { -#include -#include -#endif - -#define CONTENT_BUFSIZE MAX_IMG_BUFF_SIZE -#define LOG_BUFSIZE (BUFSIZE<<1) -#define NW_ERROR 1 -#define NW_SORRY 2 -#define NW_LOG 3 -#define LINE_BUFSIZE 7*8192 //512 -#define MAX_SIZE_POINT 6 -#define MAX_NUMBER_PAGE 59 -#define HEADER_BUFSIZE 1024 - -#define WEBPYTHONBUFFER_LENSIZE 256 -#define WEBPYTHONBUFFER_ROWSIZE 256 -#define MAX_GET_PYTHON_BUFFER_ROW_SIZE 8 - -#ifdef GY_OS_NOVA -#define MEMORY_SIZE 256*1024 -#endif - -#ifdef GY_OS_AMBA -#define MEMORY_SIZE 512*1024 -#endif - -#define MAX_SERVICE_SIZE 256 - -#define MAX_SIZE_A_OSD_OBJECT 11 -#define MAX_SIZE_A_SP_OBJECT 6 - - //trigger types -#define TRIGGER_OUTSIDE_INSIDE 1 -#define TRIGGER_INSIDE_OUTSIDE 2 -#define TRIGGER_INSIDE_INSIDE 3 -#define TRIGGER_OUTSIDE_OUTSIDE 4 - - /*typedef struct - { - int x; - int y; - } Point;*/ - - /*typedef struct { - char* recvBuffer; - char* contentBuffer; - } BufferPtr;*/ - - /*typedef struct { - time_t recv_time; - int frames; - } SecData;*/ - - typedef struct - { - struct tm * snapshot_time; - time_t snapshot_time_mktime; - time_t snapshot_msecs_time; - char snapshot_addr[MAX_IMG_SIZE]; - int snapshot_size; - }SnapHDInfo; - - typedef struct - { - char weight_repository[35]; - int enable_weight_to_run; - }WeightFileInfo; - - typedef struct - { - char email_address1[50]; - char email_address2[50]; - char email_address3[50]; - char email_address4[50]; - char email_address5[50]; - - char email_address[50]; - - char smtp_server[50]; - int smtp_auth_mode; - char smtp_port[10]; - int smtp_auth; - - char auth_account[50]; - char auth_password[50]; - } IPCAMServiceInfo; - - typedef struct - { - int checked; - char detect_event_id[20]; - char detect_event_name[50]; - char post_event_name[MAX_MSG_LEN * 10]; - char counter_name[MAX_MSG_LEN * 10]; - int counter_increment; - //TriggerData [MAX_DETECT_OBJECTS]; - } TriggerEvent; - - typedef struct - { - bool isActive; - - time_t det_time; - /*char levenshtein_distance[10]; - char min_characters[10]; - char max_characters[10]; - char confidence[10];*/ - char enable_traffic_light[10]; - //char enable_social_distance[10]; -#ifdef GY_OS_AMBA - CvMat* PerspectiveTransformArray; -#endif - char detection_time[20]; - char metadata1[BUFSIZE]; - char metadata2[BUFSIZE]; - char metadata_stop[50]; - char link_to_counter[10]; - char enable_direction1[10]; - char enable_direction2[10]; - char direction1[10]; - char direction2[10]; - int no_parking_time; - int no_parking_time_in_minute; - int queuing_count; - int prev_queuing_num; - int queuing_trigger_event_idx; - char ptz_zone_to_preset[20]; - - TriggerEvent trigger_event[MAX_TRIGGER_EVENT]; - CPoint Points[6]; - int min_x_points; - int max_x_points; - int min_y_points; - int max_y_points; - - f_CPoint onvif_Points[6]; - - int parking_space; - int parking_line; - - //Social Distance - float set_distance; - char world_distance_unit[10]; - float world_distance[DETECTION_POINTS_COUNT]; - int distance_violation_count; - int prev_distance_violation_num; - time_t prev_distance_violation_time; - time_t recent_distance_violation_start_time; - int distance_trigger_event_idx; - //float LinearFormula[DETECTION_POINTS_COUNT][3]; //4 edges, each edge has it's ax+by+c =0 values - //char* MovingDirection[DETECTION_POINTS_COUNT]; - - int point_num; - - int obj_tracking_id_in_zone[MAX_OBJ_TRACKING_ID_IN_ZONE]; - int last_obj_tracking_id_in_zone[MAX_OBJ_TRACKING_ID_IN_ZONE]; - int last_two_obj_tracking_id_in_zone[MAX_OBJ_TRACKING_ID_IN_ZONE]; - int check_if_missing; - - char enable_speed[10]; - char enable_radar_speed[10]; - char enable_ivs_zone[10]; - float world_distance_side1; - float world_distance_side2; - char world_time_unit[20]; - - char obj_max_proportion_in_zone[10]; - char obj_min_proportion_in_zone[10]; - - //int speed_upper_bound;//請改用set_distance - //int speed_lower_bound;//請改用set_distance - - //char confidence3[10]; -#if defined GY_OS_AMBA - //jvc setting - int jvc_enable_detect; - int jvc_person_check; - int jvc_vehicle_check; - int jvc_person_confidence; - int jvc_vehicle_confidence; - int jvc_behavior; - int jvc_obj_size; - int jvc_detect_priority; - int jvc_detect_mode; - int jvc_detect_fov; - int jvc_trigger_delay_time; - int jvc_trigger_times; - int jvc_queuing_count; - int jvc_enable_direction1; - int jvc_direction1; - char jvc_counter_name[50]; - int jvc_counter_value; - int jvc_density_value; - - int jvc_enable_ptz; - int jvc_ptz_tracking_time; - int jvc_ptz_fov; - int jvc_ptz_auto_intercept; - int jvc_ptz_preset_intercept; - int jvc_ptz_zone_to_preset; -#endif - } DetectionZoneInfo; - - typedef struct - { - int channel_idx; - int enable_anpr; - int enable_face; - int enable_traffic; - int enable_logo; - int enable_add_face_frequent_list; - int tab_view_width; - int tab_view_height; - float tab_view_width_ratio; - float tab_view_height_ratio; - float speed_view_width_ratio; - float speed_view_height_ratio; - char camera_name[20]; - char obj_max_proportion[10]; - char obj_min_proportion[10]; - char levenshtein_distance[10]; - char min_characters[10]; - char max_characters[10]; - - int i_plate_filter_times; - int i_plate_filter_time; - int i_plate_free_time; - - char confidence[10]; //車牌 Plate - char confidence2[10]; //交通 Traffic - char confidence3[10]; //沒有用到 None - char confidence4[10]; //沒有用到 None - int enable_traffic_light_zone; - //int enable_social_distance_zone; - char traffic_light_color[20]; - //CvMat* PerspectiveTransformArray; - char enable_lpr_db[10]; - char enable_PTZ[10]; - char enable_track[10]; - - char ivs_mode[10]; - - char ptz_tracking_fov_min[10]; - char ptz_tracking_fov_max[10]; - char ptz_enable_tracking[10]; - char ptz_tracking_resume_dwell[10]; - int ptz_tracking_by_enter_zone; - int ptz_tracking_mode; - int ptz_sensitivity; - int iVideo_source_w; - int iVideo_source_h; - - char enable_tracking_limits[10]; - char ptz_pan_left_limit[20]; - char ptz_pan_right_limit[20]; - char ptz_tilt_up_limit[20]; - char ptz_tilt_down_limit[20]; - char ptz_speed[20]; - - char enable_unknown_object[10]; - char enable_ivs_person_detection[10]; - - char assign_ivs_object_to[100]; - - char enable_ambulance[10]; - char enable_blank_plate[10]; - char enable_stop_sign[10]; - - char enable_ivs_fix_mode[10]; - - char enable_show_unknown_object[10]; - char enable_ivs_and_ai[10]; - char enable_lpr_upon_triggered[10]; - - char dwell_lpr_upon_triggered[10]; - - char unknown_object_max_proportion[10]; - char unknown_object_min_proportion[10]; - char confidence_unknown_object[10]; - char confidence2_unknown_object[10]; - char dwell_unknown_object[10]; - char dwell_minute_focus_on[10]; - char person_obj_fov[10]; - - char getnetwork_buffer_id[10]; - - char red_light_zone[10]; - char no_give_way_zone_to_protect[10]; - char no_give_way_zone_to_keep_away[10]; - char no_give_way_zone_to_protect_2[10]; - char no_give_way_zone_to_keep_away_2[10]; - int count_zone; - - } ChannelInfo; - - typedef struct - { - char enable_person_independent[10]; - char enable_onvif_profile_m[10]; - char nms_thres[10]; - char tracking_id_dwell[10]; - - char enable_cloud[10]; - char enable_special_edition[10]; - char enable_python[10]; - char enable_python_file[50]; - char enable_low_cpu_usage[10]; - char cloud_enable_snap[10]; - char cloud_enable_notification[10]; - char cloud_account[256]; - char cloud_password[256]; - char cloud_notification_dwell[10]; - char cloud_statue[MEMORY_SIZE]; - char language[50]; - - char enable_display_properties[10];//enable to show color - char enable_display_OSD[10]; - - char enable_special_char[10]; - char enable_bounding_box[10]; - - char enable_dwell_bounding_box[10]; - - char force_i_to_one[10]; - char force_o_to_zero[10]; - char enable_plate_angle_correction[10]; - - char enable_ai_mirror[10]; - char ai_mirror_feature[10]; - - char enable_cloud_v2[10]; - char cloud_v2_notification_dwell[10]; - char cloud_v2_content[BUFSIZE_V3]; - char enable_cloud_record_v2[10]; - char cloud_record_v2_notification_dwell[10]; - char cloud_record_v2_content[BUFSIZE_V3]; - - char cloud_v2_statue[MEMORY_SIZE]; - char cloud_record_v2_statue[MEMORY_SIZE]; - - char enable_post_only_if_both_detected[10]; - - char enable_getalarmmotion_snap[10]; - char getimage_encoder_id[10]; - char getimage_encoder_id_HD[10]; - - char osd_encoder_id[10]; - char osd_font_size[10]; - char osd_outline_lilin[10]; - char enable_osd_bottom[10]; - char osd_bottom_bg_tran[10]; - char osd_bottom_content[BUFSIZE_V3]; - - - char sensors_type[10]; - - char enable_sync_external_lpr_db[10]; - char external_lpr_db_IP[256]; - char external_lpr_db_port[10]; - char external_lpr_db_username[60]; - char external_lpr_db_password[60]; - - char enable_email_notification[10]; - char enable_system_logs[10]; - char enable_email_jpeg[10]; - char email_reset_time_interval[20]; - - char enable_ftp[10]; - char ftp_url[256]; - char ftp_port[25]; - char ftp_username[256]; - char ftp_password[256]; - char ftp_remote_directory[1024]; - char ftp_jpeg_file_name_format[10 + 1]; - char ftp_jpeg_file_name[60]; - - } SystemSettingInfo; - - typedef struct - { - char post_protocol[10 + 1]; - char post_event_method[10+1]; - char post_event_name[60]; - char post_host_ip[256]; - char post_host_port[5+1]; - char post_url[8192];//BUFSIZE_V2 - char post_username[60]; - char post_password[60]; - char post_content[MAX_IMG_SIZE]; - char post_customized_header[8192]; - - //unsigned char post_content_bin[MAX_HTTP_BUFFER]; - char post_sequence[60]; - - char post_file_format[10 + 1]; - char post_jpeg_file_name_format[10 + 1]; - char post_jpeg_file_name[60]; - - char post_timeout[10]; - - int check_if_delivering; - } PostEventInfo; - - typedef struct - { - char email_content[BUFSIZE_V3]; - //unsigned char email_content_bin[MAX_HTTP_BUFFER]; - } EmailInfo; - - typedef struct { - //int nListIndex; - char counter_name[36 + 1]; - int counter_zone; - char counter_cust_name[256]; - char counter_unit[16 + 1]; - int reset_value; - - int reset_year; - int reset_month; - int reset_month_day; - int reset_week_day; - int reset_hour; - int reset_min; - int reset_sec; - - int gmt_year; - int gmt_month; - int gmt_month_day; - int gmt_week_day; - int gmt_hour; - int gmt_min; - int gmt_sec; - - int next_year; - int next_month; - int next_month_day; - int next_week_day; - int next_hour; - int next_min; - int next_sec; - - char ReportTimeInterval[30]; - char ResetTime[50]; - - int already_reset; - int counter_count; - time_t timetResetAt; - time_t next_timetResetAt; - - char enable_reset_time_interval[10 + 1]; - char reset_time_interval[36 + 1]; - char reset_at[36 + 1]; - - char enable_time_range[10 + 1]; - char time_range_from[36 + 1]; - char time_range_to[36 + 1]; - time_t timetTimeRangeFrom; - time_t timetTimeRangeTo; - - char link_to_post_event_name[256]; - char post_interval[36 + 1]; - - int dwell_time; - char dwell_unit[10 + 1]; - - //char MetaOut1[512][50]; - //int metadata1_num; - - char enable_reset_only_cloud[10 + 1]; - char enable_linked_to_dwell_time[10 + 1]; - time_t last_post_time; - - } EventCounterInfo; - - typedef struct { - char counter_a[20]; - char counter_a_name[50]; - char counter_a_zone[10]; - char counter_b[20]; - char counter_b_name[50]; - char counter_b_zone[10]; - char counter_c_name[50]; - - char report_max_value[20]; - - char enable_report[10]; - - char counter_mode[20]; - - char initial_icon[50]; - char output_icon[50]; - - char detection_output[100]; - - } ReportCounterInfo; - - typedef struct { - char snmp_event_name[256]; - char snmp_version[10]; - char snmp_group_name[256]; - char snmp_host_ip[256]; - char snmp_host_port[10]; - char snmp_oid[256]; - char snmp_value[BUFSIZE]; - char snmp_type[20]; - - int check_if_delivering; - } SNMPManagementInfo; - - //20201027 sophia add - //read from [ipcam /usr/local/bin/nvclient -k user.password0 /usr/local/bin/nvclient -k user.account0 ...9] - //save to config.json account_setting->account_data - typedef struct { - char account_username[256]; - char account_password[256]; - char account_port[50]; - char account_mirror[20]; - char account_flip[20]; - char account_rotate[20]; - char account_aida_port[50]; - int account_type; //default ? - int account_status; //default ? - } AccountDataInfo; - - typedef struct { - //pthread_t thread_id; - SOCKET sock; - int channel_id; - double fps; - //time_t last_recv_time; - //SecData recent_sec_data[FPS_AVG_SECS]; - int isGetAlarmMotion; - //int isFirstAlarmMotion; - int isWebSocketConnect; - int isNvrRequest; - int isCredentialRequest; -#if defined GY_OS_AMBA || defined GY_OS_NOVA - int isUdpSocket; //20201112 sophia add -#endif //GY_OS_AMBA - uchar* prev_frame_data; - //int iIsWebsocketHybi00; -#if defined GY_OS_AMBA - //int iIsAIRelay; -#endif - int debug_type; - - int used; - - } SocketInfo; - - typedef struct { - char curl_url[8192]; - char curl_sendbuf[8192]; - char method[32]; - char username[64]; - char password[64]; - char port[10]; //strtol(q_info->host_port, NULL, 10) - } CURL_SEND; - - typedef struct { - int tof_version; - bool tof_debug; - int tof_install_angle; - bool tof_enable_camera; - bool enable_tof_ground; - bool enable_tof_wall; - - char tof_camera_ip[256]; - char tof_camera_port[10]; - char tof_camera_sub_url[8192]; - char tof_auth_key[8192]; - bool tof_ip_setting; - char tof_camera_username[512]; - char tof_camera_password[512]; - - char distance_options[10]; - char distance_min_max[10]; - char distance_threshold[20]; - char height_options[10]; - char height_min_max[10]; - char height_threshold[20]; - - char ground_x[10]; - char ground_y[10]; - } TofInfo; - - typedef struct { - char enable_heartbeat[10]; - char events_default_version[10]; - char heartbeat_dwell[10]; - char heartbeat_link_to_post_event_name[256]; - - char dwell_to_the_same_location[10]; - - char enable_snmp_heartbeat[10]; - char snmp_heartbeat_dwell[10]; - char snmp_heartbeat_link_to_post_event_name[256]; - - char enable_only_once_to_post[10]; - char enable_obj_once_to_post[10]; - char enable_location_once_to_post[10]; - char enable_nvr_once_to_getalarmmotion[10]; - char enable_8592_once_to_getalarmmotion[10]; - - char heatmap_max[20]; - char enable_heatmap[10]; - char heatmap_frequency[20]; - char lpr_title[256]; - - char enable_counter_snap[10]; - char enable_barcode_qr[10]; - - char enable_check_ptz_start_autotracking[10]; - char enable_check_ptz_end_autotracking[10]; - char ptz_start_autotracking_link_to_post_event_name[256]; - char ptz_end_autotracking_link_to_post_event_name[256]; - } HeartbeatInfo; - - typedef struct { - char sPlateNumber[100]; - time_t t_FirstGetTime; - time_t t_UpdateTime; - time_t t_LoopTime; - - int iGetCounter; - int iIfUse; - - float box_x; - float box_y; - float box_w; - float box_h; - - float last_box_x; - float last_box_y; - float last_box_w; - float last_box_h; - - float last_box_center_x; - float last_box_center_y; - - int iPlateZoomOutCounter; - int iPlateZoomInCounter; - - int iTrackingID; - //int iTrackingIDidx; - - int existing_dash; - - char car_type_name[20]; - int check_if_counted[MAX_DETECTION_ZONE]; - - } PlateRecoder; - - typedef struct { - //char name[30]; - //int class_id; - - time_t t_FirstGetTime; - time_t t_UpdateTime; - - int iGetCounter; - int iIfUse; - - float box_x; - float box_y; - float box_w; - float box_h; - - //float left_x; - //float top_y; - - int iTrackingID; - //int iTrackingIDidx; - - int check_if_counted[MAX_DETECTION_ZONE]; - - } ObjectRecoder; - - typedef struct { - char name[30]; - char sPlateNumber[100]; - - time_t t_FirstGetTime_total; - time_t t_FirstGetTime; - time_t t_UpdateTime; - - int iIfUse; - - float box_x; - float box_y; - float box_w; - float box_h; - - int check_if_post[MAX_DETECTION_ZONE]; - int check_if_cloud; - int check_if_cloud_v2; - int check_if_cloud_record_v2; - int check_if_email; - int check_if_ftp; - int check_if_getalarmmotion; - - int object_id; - int zone_idx; - - //int the_same_id; - - float count_trigger; - - //detection_pos ori_Data; - //int iIsInvisible; - //time_t t_InvisibleStartTime; - //time_t t_InvisibleUpdateTime; - - } PostRecoder; - - - typedef struct { - - int locked; - - int used; - float box_x; - float box_y; - float box_w; - float box_h; - - } MotionAreaInfo; - - typedef struct { - int color_mode;//image.dn.switch //0 auto mode; 1 day mode; 2 night mode; 3 schedule mode - int light_sensor_value;//image.dn.luminosity - int day_to_night_threshold;//image.dn.luminosity.dtn - int night_to_day_threshold;//image.dn.luminosity.ntd - int dwell_sec_in_auto_mode;//image.dn.switch.dwell - int day_to_night_time_of_schedule;//image.dn.schedule.day - int night_to_day_time_of_schedule;//image.dn.schedule.night - - int hour_day_to_night; - int min_day_to_night; - int total_min_day_to_night; - - int hour_night_to_day; - int min_night_to_day; - int total_min_night_to_day; - - int current_day_or_night_mode;//result // day : 1 ; night : 2 - int last_day_or_night_mode; - - int check_if_switch_happened[MAX_SIZE_SWITCH_HAPPENED]; - - //int ircut; - //int irledfar; - //int irlednear; - - int iAutoModeSwitchCount; - } ImageDn; - - typedef struct { - int id; - int flag_protected; - int x; - int y; - int w; - int h; - int color; - int size; - int show_sec; - int bg_tran; //0~255 - int outline_sw; //0:off 1:on - char text[256]; - } OSDInfo; - - typedef struct { - int flag_protected; - float speed; - char speed_unit[256]; - float res_width; - float res_height; - float x; - float y; - } SpeedInfo; - - extern char g_aWebPythonBuffer2D[WEBPYTHONBUFFER_LENSIZE][WEBPYTHONBUFFER_ROWSIZE]; - extern unsigned int g_uiWebPythonCurrentBufferIndex; - extern unsigned int g_uiWebPythonLastBufferIndex; - extern unsigned int g_cWebPythonBufferSignal; - extern unsigned int g_cWebPythonDeleteStatus; - extern char g_cWebPythonName[50]; - extern unsigned int g_cWebPythonStatus; - extern unsigned int python_check_webstatus; // 給開關 plugin 時用的 - - extern bool isGYNetReady; - -//===================== -//sophia add 2020/09/24 -#if defined GY_OS_AMBA || defined GY_OS_NOVA - -#include "alm_queue.h" - - typedef struct { - SOCKET sock; - //stALMNode *head; - //stALMNode *tail; - //int iIsWebsockethybi00; - } SocketInfo_ALM; - - //extern SocketInfo_ALM socketRecord_ALM[MAX_CLIENT_SOCKET]; - extern int bHttpServerMainStart; - extern int bPreloadHttpServerMainStart; -#endif //GY_OS_AMBA -//===================== - - extern int g_check_ping_OK; - - extern int g_sdk_version; - - extern int CheckIsExistingSpeed; - - extern SocketInfo socketRecords[MAX_CLIENT_SOCKET]; - extern ChannelInfo viewChannelData[MAX_AI_ENGINE_VIEW]; - extern DetectionZoneInfo viewDetectionZone[MAX_AI_ENGINE_VIEW][MAX_DETECTION_ZONE]; - extern SystemSettingInfo SystemSetting; - extern PostEventInfo postEventList[MAX_POST_EVENTS]; -#ifdef GY_OS_V_SERIES - -#else - extern EventCounterInfo eventCounterList[MAX_EVENT_COUNTERS]; - extern ReportCounterInfo reportCounterList[MAX_REPORT_COUNTERS]; - extern SNMPManagementInfo SNMPManagementList[MAX_SNMP_MANAGEMENT]; -#endif - - extern AccountDataInfo accountData[MAX_ACCOUNT_DATA_NUM]; //20201027 sophia add - extern IPCAMServiceInfo IPCAMService; - extern SnapHDInfo snapHDList[MAX_SNAP_HD_LIST]; - extern WeightFileInfo weightfileList[MAX_WEIGHT_FILE_LIST]; - extern char WeightFileModeName[35]; - extern EmailInfo emailData; - extern HeartbeatInfo heartbeatData; -#ifdef GY_OS_AMBA - extern TofInfo tofData; -#endif - -#if defined GY_OS_AMBA || defined GY_OS_NOVA - extern PlateRecoder g_PlateRecorderList[MAX_PLATE_RECORDER]; -#endif - extern ObjectRecoder g_ObjectRecorderList[MAX_OBJECT_RECORDER]; - extern PostRecoder g_PostRecorderList[MAX_POST_RECODER_SIZE]; - extern PostRecoder g_longterm_PostRecorderList[MAX_POST_RECODER_SIZE]; - - //extern MotionAreaInfo g_Motion_Area_Data[MAX_MOTION_AREA]; - -#if defined GY_OS_AMBA || defined GY_OS_NOVA - extern ImageDn imageDnData; - -#endif - -#ifdef GY_OS_AMBA - - extern OSDInfo OSDData[MAX_SIZE_OSD_ARRAY]; - extern SpeedInfo SpeedData[MAX_SIZE_SP_ARRAY]; -#endif - extern int g_PlateFilterTimes; //Times - extern int g_PlateFilterTime; //Second - extern int g_PlateRecorderFreeTime; //Second -#ifdef GY_OS_AMBA - extern int g_face_frame_uid; -#endif - extern int g_IsRadarDevice; - extern char radar_json_data[4096]; - - extern int unlockingKeyInnoFR_success; - extern int unlockingKeyInnoFR; - - extern int g_IsSDK_3_0; - extern int g_IsToFDevice; - extern int g_IsCustomWeight; - extern int g_IsHelm_without_car; - - extern float g_min_tof_range; - extern int g_min_tof_range_x; - extern int g_min_tof_range_y; - - extern float g_max_tof_range; - extern int g_max_tof_range_x; - extern int g_max_tof_range_y; - - extern int g_bIsSendTofPCD; - extern int g_bIsWritingPCD; - - extern float g_ground_tof_range; - - extern float g_min_tof_degree; - extern float g_min_tof_height; - extern float g_min_tof_distance; - - extern float g_max_tof_degree; - extern float g_max_tof_height; - extern float g_max_tof_distance; - - extern float g_ground_tof_degree; - extern float g_ground_tof_height; - extern float g_ground_tof_distance; - - extern double g_tof_device_height; - - extern int g_ori_yuv_width; - extern int g_ori_yuv_height; - extern int g_ori_half_yuv_width; - extern int g_ori_half_yuv_height; - - //extern int sockNum[4]; - extern zlog_category_t *zc; - extern double begin_clock; - - extern float confidence_limit; - extern int AI_fps; - -#ifdef REBOOT_BY_CPU_GPU_USAGE - extern int CPU_usage_int; - extern int GPU_usage_int; -#endif - - extern char CPU_usage[256]; - extern char GPU_usage[256]; - extern char Buffer_ver[BUFSIZE]; - //extern bool enable_loop_getalarmmotion; - //extern int times_of_enable_loop_getalarmmotion; - extern int g_write_config_file_dirty_flag; - - extern int g_match_mac; - extern char g_mac_address[256]; - - extern int enable_only_show_metadata1; - extern char websocket_alarm[CONTENT_BUFSIZE]; - - extern int g_i_get_cpu_loading; - - //extern CURLM* g_multi_handle; - extern CURL* g_http_handle; - //extern int g_handle_count; - - extern int g_alter_something; - extern int g_count_alter; - - extern long g_image_HD_pasue_time; - extern int g_video_start_HD; - - extern int g_current_max_num_image_buff; - - extern int g_osdTime_sw; - extern long g_osdSysTimeStamp; - extern int g_osdSysTimeZoneInfo; - - extern int check_if_correct_post; - extern int check_if_run_post; - - extern long g_post_SysTimeStamp; - - int run_http_server(char *option, void* _zc, CNNType cnn_type/*, int layer_count, network nets[], char **names[], image **alphabet, float nms[]*/, float thresh, float hier_thresh, int dont_show, int ext_output, int save_labels, - char *mac_address, char *ip_address, int http_port, LicenseType licenseType, AdvanceLicenseType advLicenseType, AuthFailStatusCode afsCode, size_t layerFeatureType[], char* strLicenseType); - - //int caculate_ftp_of_each_sockets(SOCKET sock, int *sock_record_idx); -#ifdef GY_OS_NOVA - size_t SetHttpRequest_sock(QueueInfo *q_info, char* sendBuffer, char* method); -#endif - size_t SetHttpRequest(QueueInfo* q_info, char* sendBuffer, char* method); - size_t SetHttpResponse(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content); - void Create_ptz_socket(); - void SetHttpRequest_ptz(char* cgi_url, char* sOutput_data, char* username, char* password); - //void SetHttpRequest_ptz(); - //size_t SetHttpRequest_ptz(QueueInfo *q_info, char* sendBuffer, char* method); - size_t SetHttpResponse_server(char* sendBuffer, int httpCode, char* contentType, size_t contentLen, char* content); - void replace_one_line_in_a_file(char *path, int line, char *newline); -#if 0 - void GetAidaPort(); -#endif - void update_enable_only_show_metadata1(int temp_enable_only_show_metadata1); - size_t get_service_from_ipcam(char * response_from_ipcam); - size_t get_control_io_from_ipcam(char * response_from_ipcam); - void copy_ipcam_smtp_service_to_gynet(); - void copy_control_io_to_gynet(); - void sync_other_camera_lpr_db(); - - void *net_curl_https_post_push_info(void *ptr); - void *net_curl_https_post_push_info_attached_image(void *ptr); - - void net_curl_ftp_post_push_info_attached_image(char* image_buff, int image_buff_size); - void net_curl_ftp_build_folder(); -#ifdef GY_OS_AMBA - size_t SetSNMPRequest(QueueInfo *q_info); -#endif - void *net_curl_https_get_other_lpr_db(void *ptr); - - extern char id[512]; - extern char pass[512]; - - extern char strUnlockingKey[MAX_MSG_LEN]; - extern char strLicenseStatus[MAX_MSG_LEN]; - - extern char g_device_name[512]; - - extern int g_IsPTZDevice; - extern int g_check_if_no_brand; - - extern int g_check_if_OK_getfeatures; - extern int g_check_if_OK_thermal; - - void memset_snapshot_addr(); - - void build_one_smart_event(char * myname, char * myvalue); - void build_one_gpio(char * myname, char * myvalue); - - void* auto_build_smart_events(void * ptr); - void* auto_build_smart_events_di_vi(void * ptr); - void build_one_set_for_quality_basic(char * myname, char * myvalue); -#ifdef GY_OS_AMBA - void build_one_set_for_tof_basic(char * myname, char * myvalue); -#endif - void* auto_set_quality_basic(void * ptr); -#ifdef GY_OS_AMBA - void* auto_set_tof_basic(void * ptr); -#endif - - size_t build_resolution_changed(char * response_from_ipcam); - extern pthread_t resolution_changed_thread; - void* auto_resolution_changed(void * ptr); -#ifdef GY_OS_AMBA - void* check_current_resolution(void * ptr); - void set_run_check_current_resolution(int set_value); - int get_run_check_current_resolution(); -#endif - void write_to_stream_width_and_stream_height(int stream_width, int stream_height); - int get_g_check_if_different_width_or_height(); - - void build_reboot(char * myname, char * myvalue); - void ipcam_getfeatures(); - - void* auto_reboot(void * ptr); - - void build_system(char * myname, char * myvalue); - void* auto_system(void * ptr); - - void sync_image_rotation_thread(); - - int is_connection_authorized(char* recvBuffer, SOCKET *client_socket, int isTcpTunnel); - - void import_lpr_list_file(char *headerBuffer, char *multiPartBoundary, int bIsMultipart, char *contentBuffer, long nTotalContentLen); - void *import_lpr_list_file_thread(void *ptr); -#ifdef GY_OS_AMBA - void *import_face_list_file_thread(void *ptr); -#endif - void get_snap_with_profile_id(int i_profileid, int enable_check_profile_id); -#ifdef GY_OS_NOVA - void *pre_connection_handler(void *socket_temp); -#endif - void *thread_getimage(void *ptr); - void *thread_getimage_hd(void *ptr); - -#ifdef GY_OS_NOVA - void *thread_get_nova_driver(void *ptr); -#endif - char *removeHTTPHeader(char *buffer, int *bodySize); - void getPicture(int socketfd, int bSize, int current_profile_id, int enable_check_profile_id); - int get_g_framesize_width(); - int get_g_framesize_height(); - - void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, char* contentBuffer/*, int layer_count, network nets[], char **names[], image **alphabet, float nms[]*/, float thresh, float hier_thresh, int dont_show, int ext_output, int save_labels, int http_port, LicenseType licenseType, AdvanceLicenseType advLicenseType, AuthFailStatusCode afsCode, size_t layerFeatureType[], char* strLicenseType, int* isGetalarmMotion, int sock_info_idx); - -#ifdef GY_OS_AMBA - int get_g_check_if_change_preset(); - void set_g_check_if_change_preset_to_zero(); - void *import_radarbg_thread(void *ptr); - void import_radarbg(char *headerBuffer, char *multiPartBoundary, int bIsMultipart, char *contentBuffer, long nTotalContentLen); -#endif - void update_system_time(); - - int get_g_control_alarm_gpio(); - void set_g_control_alarm_gpio_to_zero(); - void set_g_control_alarm_gpio_to_one(); -#ifdef GY_OS_NOVA - void start_nova_driver(); - void get_nova_driver(int socketfd); -#endif - -#ifdef __cplusplus -} -#endif - -#endif -#endif \ No newline at end of file