Browse Source

2.0.7.69

master
ming.hong 1 year ago
parent
commit
0277927cc4
  1. BIN
      gynet
  2. BIN
      libdarknet.a
  3. BIN
      obj/block_to_send.o
  4. BIN
      obj/dbscan.o
  5. BIN
      obj/detector.o
  6. BIN
      obj/fflpr_plate_db.o
  7. BIN
      obj/ivs.o
  8. BIN
      obj/network.o
  9. BIN
      obj/nweb.o
  10. BIN
      obj/parser.o
  11. BIN
      obj/pns.o
  12. BIN
      obj/ptz.o
  13. BIN
      obj/pythonR.o
  14. BIN
      obj/test_nnctrl_live.o
  15. BIN
      obj/test_yuv_rgb.o
  16. BIN
      obj/utility.o
  17. BIN
      obj/utils.o
  18. BIN
      obj/websocket.o
  19. 2
      src/art.c
  20. 8
      src/cuda.c
  21. 1
      src/darknet.c
  22. 6
      src/dbscan.c
  23. 12
      src/demo.c
  24. 434
      src/detector.c
  25. 10
      src/face_parser.cpp
  26. 84
      src/ivs.cpp
  27. 6
      src/network.c
  28. 154
      src/nweb.c
  29. 9
      src/nweb.h
  30. 28
      src/parser.c
  31. 101
      src/pns.c
  32. 6
      src/pns.h
  33. 2
      src/ptz.c
  34. 574
      src/pythonR.c
  35. 16
      src/pythonR.h
  36. 4
      src/radar_receive.c
  37. 5
      src/setting.h
  38. 1373
      src/test_nnctrl_live.c
  39. 18
      src/test_yuv_rgb.c
  40. 10
      src/tof.c
  41. 62
      src/utility.cpp
  42. 6
      src/utility.h
  43. 6
      src/utils.c

BIN
gynet

Binary file not shown.

BIN
libdarknet.a

Binary file not shown.

BIN
obj/block_to_send.o

Binary file not shown.

BIN
obj/dbscan.o

Binary file not shown.

BIN
obj/detector.o

Binary file not shown.

BIN
obj/fflpr_plate_db.o

Binary file not shown.

BIN
obj/ivs.o

Binary file not shown.

BIN
obj/network.o

Binary file not shown.

BIN
obj/nweb.o

Binary file not shown.

BIN
obj/parser.o

Binary file not shown.

BIN
obj/pns.o

Binary file not shown.

BIN
obj/ptz.o

Binary file not shown.

BIN
obj/pythonR.o

Binary file not shown.

BIN
obj/test_nnctrl_live.o

Binary file not shown.

BIN
obj/test_yuv_rgb.o

Binary file not shown.

BIN
obj/utility.o

Binary file not shown.

BIN
obj/utils.o

Binary file not shown.

BIN
obj/websocket.o

Binary file not shown.

2
src/art.c

@ -15,7 +15,7 @@ void demo_art(char *cfgfile, char *weightfile, int cam_index)
void * cap = open_video_stream(0, cam_index, 0,0,0);
char *window = "ArtJudgementBot9000!!!";
if(!cap) error("Couldn't connect to webcam.\n");
if(!cap) printf("Couldn't connect to webcam.\n");
int i;
int idx[] = {37, 401, 434};
int n = sizeof(idx)/sizeof(idx[0]);

8
src/cuda.c

@ -35,7 +35,7 @@ void check_error(cudaError_t status)
printf("CUDA Error: %s\n", s);
assert(0);
snprintf(buffer, 256, "CUDA Error: %s", s);
error(buffer);
printf("%s\n",buffer);
}
if (status2 != cudaSuccess)
{
@ -44,7 +44,7 @@ void check_error(cudaError_t status)
printf("CUDA Error Prev: %s\n", s);
assert(0);
snprintf(buffer, 256, "CUDA Error Prev: %s", s);
error(buffer);
printf("%s\n",buffer);
}
}
@ -99,7 +99,7 @@ float *cuda_make_array(float *x, size_t n)
} else {
fill_gpu(n, 0, x_gpu, 1);
}
if(!x_gpu) error("Cuda malloc failed\n");
if(!x_gpu) printf("Cuda malloc failed\n");
return x_gpu;
}
@ -143,7 +143,7 @@ int *cuda_make_int_array(int *x, size_t n)
status = cudaMemcpy(x_gpu, x, size, cudaMemcpyHostToDevice);
check_error(status);
}
if(!x_gpu) error("Cuda malloc failed\n");
if(!x_gpu) printf("Cuda malloc failed\n");
return x_gpu;
}

1
src/darknet.c

@ -151,7 +151,6 @@ int main(int argc, char **argv)
//sophia add 2020/10/08
if (chdir("/emmc/plugin") != 0)
{
//perror("chdir() to /emmc/plugin fail");
printf("\nchdir() to /emmc/plugin fail\n");
return 0;
}

6
src/dbscan.c

@ -83,7 +83,7 @@ node_t *create_node(unsigned int index)
{
node_t *n = (node_t *) calloc(1, sizeof(node_t));
if (n == NULL)
perror("Failed to allocate node.");
printf("Failed to allocate node.\n");
else {
n->index = index;
n->next = NULL;
@ -121,7 +121,7 @@ epsilon_neighbours_t *get_epsilon_neighbours(
epsilon_neighbours_t *en = (epsilon_neighbours_t *)
calloc(1, sizeof(epsilon_neighbours_t));
if (en == NULL) {
perror("Failed to allocate epsilon neighbours.");
printf("Failed to allocate epsilon neighbours.\n");
return en;
}
for (int i = 0; i < (int)num_points; ++i) {
@ -296,7 +296,7 @@ unsigned int parse_input(
point_t *p = (point_t *)
calloc(num_points, sizeof(point_t));
if (p == NULL) {
perror("Failed to allocate points array");
printf("Failed to allocate points array\n");
return 0;
}
while (i < num_points) {

12
src/demo.c

@ -216,7 +216,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const ch
cap = open_video_stream(0, cam_index, w, h, frames);
}
if(!cap) error("Couldn't connect to webcam.\n");
if(!cap) printf("Couldn't connect to webcam.\n");
buff[0] = get_image_from_stream(cap);
buff[1] = copy_image(buff[0]);
@ -234,8 +234,8 @@ void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const ch
while(!demo_done){
buff_index = (buff_index + 1) %3;
if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed");
if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed");
if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) printf("Thread creation failed\n");
if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) printf("Thread creation failed\n");
if(!prefix){
fps = 1./(what_time_is_it_now() - demo_time);
demo_time = what_time_is_it_now();
@ -287,7 +287,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const ch
}
}
if(!cap) error("Couldn't connect to webcam.\n");
if(!cap) printf("Couldn't connect to webcam.\n");
layer l = net->layers[net->n-1];
demo_detections = l.n*l.w*l.h;
@ -323,8 +323,8 @@ void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const ch
while(!demo_done){
buff_index = (buff_index + 1) %3;
if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed");
if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed");
if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) printf("Thread creation failed\n");
if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) printf("Thread creation failed\n");
if(!prefix){
fps = 1./(what_time_is_it_now() - demo_time);
demo_time = what_time_is_it_now();

434
src/detector.c

@ -32,7 +32,9 @@
#include <errno.h>
#include <time.h>
#include "net_curl.h"
#ifdef GY_OS_AMBA
#include <pythonR.h>
#endif
#include "structures.h"
#if defined GY_OS_AMBA
@ -156,11 +158,12 @@ 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 buffer_mutex;
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
@ -298,7 +301,7 @@ 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 {
@ -383,7 +386,9 @@ pthread_t http_thread_parse_json_data;
pthread_t http_thread_pre_image_receive;
#endif
pthread_t post_notification_thread;
#ifdef GY_OS_AMBA
pthread_t runpython_thread;
#endif
pthread_t getalarmmotion_thread;
pthread_t delete_jpg_in_seven_days_detector_thread_id;
@ -984,6 +989,8 @@ void *run_event_counter_thread(void *ptr)
set_counter_zone();
loadCounters();
while (bHttpServerThreadStart)
{
//printf("\n-----run event counter thread start\n");
@ -1191,6 +1198,9 @@ void *run_post_notification_thread(void *ptr)
int count_ptz = 0;
#endif
struct timeval currtime_pns_check;
long last_s_pns_check = 0;
while (bHttpServerThreadStart)
{
//printf("\n-----run post notification start\n");
@ -1309,6 +1319,54 @@ void *run_post_notification_thread(void *ptr)
#endif
}
if (strcmp(SystemSetting.cloud_enable_notification, "Yes") == 0){
if (strlen(SystemSetting.cloud_account) >= 1 && strlen(SystemSetting.cloud_password) >= 1 && strcmp(SystemSetting.cloud_account, "myaccount@mail.com") != 0) {
if (g_check_ping_OK == 1) {
gettimeofday(&currtime_pns_check, NULL);
long current_s_pns_check = currtime_pns_check.tv_sec;
if (last_s_pns_check == 0 ||
((current_s_pns_check - last_s_pns_check) >= 3600 && get_g_check_wrong_pass_or_email() == 0) ||
((current_s_pns_check - last_s_pns_check) >= 900 && get_g_check_wrong_pass_or_email() == 1)) {
char returned_msg_temp[MEMORY_SIZE] = { 0 };
PNS_check_if_to_post_image(SystemSetting.cloud_account, SystemSetting.cloud_password, returned_msg_temp, "https://cloud.ddnsipcam.com/pns/");
if (strstr(returned_msg_temp, "\"msg\":\"oaA=\"") != NULL) {
set_g_pns_account_OK(1);
if (strstr(returned_msg_temp, "\"eid\":\"Yg==\"") != NULL) {
set_g_pns_access_level(0);
}
else if (strstr(returned_msg_temp, "\"eid\":\"Yw==\"") != NULL) {
set_g_pns_access_level(1);
set_g_check_invalidpass(0);
set_g_check_emailnotvalid(0);
}
else if (strstr(returned_msg_temp, "\"eid\":\"ZQ==\"") != NULL) {
set_g_pns_access_level(3);
set_g_check_invalidpass(0);
set_g_check_emailnotvalid(0);
}
else if (strstr(returned_msg_temp, "\"eid\":{\"err\":\"Yw==\",\"msg\":\"p6PFmpaZoZqU\"}") != NULL) {
set_g_pns_access_level(-2);
}
}
last_s_pns_check = current_s_pns_check;
}
}
}
else {
set_g_pns_account_OK(1);
set_g_pns_access_level(0);
last_s_pns_check = 0;
}
}
else {
last_s_pns_check = 0;
}
#ifdef GY_OS_AMBA
if (g_IsPTZDevice == 1 && get_try_once_ptz() == 1) {
if (IsTracking() == 1) {
@ -5492,7 +5550,7 @@ void PlateFilterForParkingPlot(detection_pos* PosInfo, int total_element_size, i
g_PostRecorderList[k].box_h = 0;
g_PostRecorderList[k].object_id = 0;
g_PostRecorderList[k].zone_idx = 0;
g_PostRecorderList[k].zone_idx = -1;
strcpy(g_PostRecorderList[k].sPlateNumber, "");
g_PostRecorderList[k].count_trigger = 0;
@ -5525,7 +5583,7 @@ void PlateFilterForParkingPlot(detection_pos* PosInfo, int total_element_size, i
g_longterm_PostRecorderList[k].box_h = 0;
g_longterm_PostRecorderList[k].object_id = 0;
g_longterm_PostRecorderList[k].zone_idx = 0;
g_longterm_PostRecorderList[k].zone_idx = -1;
strcpy(g_longterm_PostRecorderList[k].sPlateNumber, "");
g_longterm_PostRecorderList[k].count_trigger = 0;
@ -11223,7 +11281,7 @@ void initial_g_PostRecorderList() {
g_PostRecorderList[i].box_h = 0.0;
g_PostRecorderList[i].object_id = 0.0;
g_PostRecorderList[i].zone_idx = 0.0;
g_PostRecorderList[i].zone_idx = -1;
strcpy(g_PostRecorderList[i].sPlateNumber, "");
strcpy(g_PostRecorderList[i].name, "");
@ -11253,7 +11311,7 @@ void initial_g_PostRecorderList() {
g_longterm_PostRecorderList[i].box_h = 0.0;
g_longterm_PostRecorderList[i].object_id = 0.0;
g_longterm_PostRecorderList[i].zone_idx = 0.0;
g_longterm_PostRecorderList[i].zone_idx = -1;
strcpy(g_longterm_PostRecorderList[i].sPlateNumber, "");
strcpy(g_longterm_PostRecorderList[i].name, "");
@ -11342,11 +11400,17 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int
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 temp_A_iou = detection_overlap_ratio(&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;
float temp_A_center_x = temp_A.left_x + temp_A.width / 2.0;
float temp_A_center_y = temp_A.top_y + temp_A.height / 2.0;
float p_center_x = pNext->left_x + pNext->width / 2.0;
float p_center_y = pNext->top_y + pNext->height / 2.0;
float temp_distance = (temp_A_center_x - p_center_x) * (temp_A_center_x - p_center_x) + (temp_A_center_y - p_center_y) * (temp_A_center_y - p_center_y);
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)
@ -11391,14 +11455,16 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int
}
}
else {
if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0
&& compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0)
/*if ((strcmp(pNext->name, "car") != 0 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0
&& compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) ||
(strcmp(pNext->name, "car") == 0 && compare_height_ratio >= 5.0 && compare_height_ratio <= 9.0
&& compare_width_ratio >= 5.0 && compare_width_ratio <= 9.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) {
if (/*g_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7) {
double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total);
if (temp_dTime > max_dwell_short) {
max_dwell_short = temp_dTime;
@ -11419,7 +11485,7 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int
}
}
else {
if (/*g_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) {
if (/*g_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7 /*|| temp_distance <= 225.0*/) {
double temp_dTime = difftime(now_time, g_PostRecorderList[i].t_FirstGetTime_total);
if (temp_dTime > max_dwell_short) {
max_dwell_short = temp_dTime;
@ -11454,11 +11520,17 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int
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 temp_A_iou = detection_overlap_ratio(&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;
float temp_A_center_x = temp_A.left_x + temp_A.width / 2.0;
float temp_A_center_y = temp_A.top_y + temp_A.height / 2.0;
float p_center_x = pNext->left_x + pNext->width / 2.0;
float p_center_y = pNext->top_y + pNext->height / 2.0;
float temp_distance = (temp_A_center_x - p_center_x) * (temp_A_center_x - p_center_x) + (temp_A_center_y - p_center_y) * (temp_A_center_y - p_center_y);
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)
@ -11493,14 +11565,16 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int
}
}
else {
if (compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0
&& compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0)
/*if ((strcmp(pNext->name, "car") != 0 && compare_height_ratio >= 2.0 && compare_height_ratio <= 4.0
&& compare_width_ratio >= 2.0 && compare_width_ratio <= 4.0) ||
(strcmp(pNext->name, "car") == 0 && compare_height_ratio >= 5.0 && compare_height_ratio <= 9.0
&& compare_width_ratio >= 5.0 && compare_width_ratio <= 9.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) {
if (/*g_longterm_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7) {
iFindMatchPost_longterm = 1;
//g_longterm_PostRecorderList[i].t_UpdateTime = now_time;
//g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id;
@ -11516,7 +11590,7 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int
}
}
else {
if (/*g_longterm_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.35) {
if (/*g_longterm_PostRecorderList[i].object_id == pNext->obj_tracking_id || */temp_A_iou > 0.7 /*|| temp_distance <= 225.0*/) {
iFindMatchPost_longterm = 1;
//g_longterm_PostRecorderList[i].t_UpdateTime = now_time;
//g_longterm_PostRecorderList[i].object_id = pNext->obj_tracking_id;
@ -11537,7 +11611,7 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int
}
}
#if 1
#if 0
if (strcmp(pNext->name, "object") != 0 && strcmp(pNext->name, "person") != 0) {
if (iFindMatchPost_longterm == 0)
{
@ -11618,10 +11692,18 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int
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;
if (strcmp(pNext->name, "car") == 0) {
g_PostRecorderList[i].box_x = pNext->left_x + pNext->width * 2.0 / 5.0;
g_PostRecorderList[i].box_y = pNext->top_y + pNext->height * 2.0 / 5.0;
g_PostRecorderList[i].box_w = pNext->width / 5.0;
g_PostRecorderList[i].box_h = pNext->height / 5.0;
}
else {
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;
@ -12576,13 +12658,11 @@ void CheckPostEventCondition(detection_pos* pNext, int tracking_channel_idx, int
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 && strcmp(SystemSetting.send_counter_at_specific_hour, "NULL") == 0 &&
(current_ms_CheckPostEventCondition_email - last_ms_CheckPostEventCondition_email) > d_no_parking_time * 1000) ||
(Get_mail_post_interval() != -1 && strcmp(SystemSetting.send_counter_at_specific_hour, "NULL") == 0 &&
(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)
if (Get_mail_post_interval() != -1 && strcmp(SystemSetting.send_counter_at_specific_hour, "NULL") == 0 &&
(last_ms_CheckPostEventCondition_email == 0 ||
(current_ms_CheckPostEventCondition_email - last_ms_CheckPostEventCondition_email) > Get_mail_post_interval() * 1000))
{
if (QueueSize(_POST_NOTIFICATION) < MAX_QUEUE_SIZE && QueueSize(_POST_NOTIFICATION) >= 0)
{
QueueInfo q_info = { 0 };
@ -13338,7 +13418,8 @@ void Record_Point_Touch_and_IsInsideZone(detection_pos* pNext, int tracking_chan
//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;
//int threahold_div = g_sensors_type == 0 ? 1 : 5;
int threahold_div = 2;
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;
@ -13772,7 +13853,7 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki
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
int threahold_div = g_sensors_type == 0 ? 1 : 5;//1 7
if (ratio_area_zone_polygon >= 0.75) {
threshold_for_count_touch = 0.67;
@ -13870,7 +13951,7 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki
}
}
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(strcmp(pNext->name,"person") != 0 || fabs(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 };
@ -14009,7 +14090,7 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki
}
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 (strcmp(pNext->name, "person") != 0 || fabs(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)) {
@ -14670,7 +14751,7 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki
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
int threahold_div = g_sensors_type == 0 ? 1 : 5;//1 7
if (ratio_area_zone_polygon >= 0.75) {
threshold_for_count_touch = 0.67;
@ -14768,7 +14849,8 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki
}
}
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 ((strcmp(pNext->name, "person") != 0 && fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 1.5) ||
(strcmp(pNext->name, "person") == 0 && fabs(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 };
@ -14908,7 +14990,8 @@ void UpdateZoneStatus(detection_pos* pNext, int tracking_channel_idx, int tracki
}
}
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 ((strcmp(pNext->name, "person") != 0 && fabs(g_TrackingRecords[tracking_channel_idx][tracking_obj_idx].prev_detections[det_count_idx - 1].left_x - pNext->left_x) <= pNext->width * 1.5) ||
(strcmp(pNext->name, "person") == 0 && fabs(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)) {
@ -17396,7 +17479,7 @@ void GetObjectTrackingIDNew(detection_pos* PosInfo, int * total_element_size_tem
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);
int checkisInside = check_if_object_in_zone(pNext->center_x, pNext->center_y, pNext->width + pNext->height, pNext->width + pNext->height, 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) {
@ -20886,6 +20969,7 @@ int reload_dataset_from_jsonfile(void)
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");
saveCounters();
pthread_t auto_reboot_thread_id;
if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL))
@ -21225,11 +21309,10 @@ int reload_dataset_from_jsonfile(void)
strcpy(SystemSetting.enable_python, enable_python->valuestring);
enable_python_file = cJSON_GetObjectItem(system_setting, "enable_python_file");
if (enable_python_file)
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);
@ -21884,7 +21967,7 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa
#if 1
//329個Memory not freed 正常背景值洩漏
if (pthread_create(&http_thread, 0, run_http_server_thread, 0))
error("HTTP server thread creation failed\n");
printf("HTTP server thread creation failed\n");
#endif
@ -21899,7 +21982,7 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa
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");
printf("Create shared memory failed !\n");
}
else {
// 初始化緩衝區
@ -21908,7 +21991,7 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa
bTofDataStart = 1;
if (pthread_create(&gettofdata_thread, 0, thread_getTofData, 0))
error("thread gettofdata creation failed\n");
printf("thread gettofdata creation failed\n");
}
}
#endif
@ -21981,17 +22064,17 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa
bHttpServerThreadStart = 1;
if (pthread_create(&post_notification_thread, 0, run_post_notification_thread, NULL))
error("Post notification thread creation failed\n");
printf("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");
printf("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");
printf("check current resolution thread failed\n");
}
#endif
@ -22010,10 +22093,10 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa
{
printf("\n[gynet] g_IsRadarDevice || g_IsToFDevice\n");
if (pthread_create(&getimage_thread, 0, thread_getimage, 0))
error("thread getimage creation failed\n");
printf("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");
printf("thread getimage creation failed\n");
#endif
}
@ -22023,20 +22106,20 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa
if (g_IsRadarDevice == 1)
{
if (pthread_create(&render_radar_thread, 0, thread_render_radar_img, 0))
error("thread render_radar creation failed\n");
printf("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");
printf("RADAR_recieve creation failed\n");
}
else
{
if (pthread_create(&getstream_thread, 0, thread_getstream, 0))
error("thread getimage creation failed\n");
printf("thread getimage creation failed\n");
if (pthread_create(&radar_parser_thread, 0, thread_parse_radar, 0))
error("thread radar parser creation failed\n");
printf("thread radar parser creation failed\n");
}
}
#endif
@ -22054,9 +22137,9 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa
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");
printf("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");
printf("thread parse_face creation failed\n");
#endif
}
#endif
@ -22068,7 +22151,7 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa
#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");
printf("Getalarmmotion thread creation failed\n");
#endif
#ifdef GY_OS_V_SERIES
@ -22087,7 +22170,7 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa
#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");
printf("check http socket thread creation failed\n");
#endif
}
#endif
@ -22108,7 +22191,7 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa
#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");
printf("check http socket thread creation failed\n");
#endif
#ifdef GY_OS_AMBA
@ -22120,21 +22203,21 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa
{
#if 1
if (pthread_create(&test_nnctrl_live_thread, 0, test_nn_main, &stAMBAcontent))
error("Test nnctrl live thread creation failed\n");
printf("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");
printf("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");
printf("fps loading thread creation failed\n");
#endif
#ifdef GY_OS_AMBA
#if 1
@ -22147,13 +22230,23 @@ void test_detector_mem(char *image_buff, CNNType cnn_type, char *cfg_files, floa
#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");
printf("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");
//}
#ifdef GY_OS_AMBA
if (strcmp(SystemSetting.enable_cloud, "Yes") == 0 && strstr(SystemSetting.enable_python_file, ".py") != NULL)
{
if (pthread_create(&runpython_thread, NULL, start_run_python_thread, NULL))
{
printf("thread start run python failed\n");
}
}
#endif
}
else
bHttpServerThreadStart = 1;
@ -22349,7 +22442,6 @@ 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);
@ -22406,6 +22498,8 @@ void stop_server()
pthread_mutex_destroy(&mutex_write_pcd_data_L);
pthread_mutex_destroy(&mutex_write_pcd_data_M);
pthread_mutex_destroy(&mutex_write_pcd_data_S);
pthread_mutex_destroy(&buffer_mutex);
#endif
#ifdef GY_OS_NOVA
pthread_mutex_destroy(&mutex_pre_bbox_receive);
@ -22473,6 +22567,7 @@ 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;
@ -22640,88 +22735,35 @@ void move_file() {
}
}
#ifdef GY_OS_AMBA
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 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); // 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);
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;
while (1)
{
if (AI_fps >= 1)
{
// 抓取 python 檔案
if (strstr(SystemSetting.enable_python_file, ".py") != NULL)
{
const char *prefix = "lifile_liname=";
char pythonfile[256] = { 0 };
snprintf(pythonfile, sizeof(pythonfile), "%s%s", prefix, SystemSetting.enable_python_file);
runPython(pythonfile);
break;
}
}
else
{
printf("Wait AI_fps...");
sleep(1);
}
}
pthread_exit(NULL);
}
#endif
void run_server(int argc, char **argv)
{
//以下沒有記憶體洩漏------------------------20210803
@ -22914,9 +22956,7 @@ void run_server(int argc, char **argv)
#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);
pthread_mutex_init(&mutex_buffer, NULL);
pthread_mutex_init(&mutex_tof_json, NULL);
#endif
pthread_mutex_init(&mutex_get_image, NULL);
pthread_mutex_init(&mutex_get_image_HD, NULL);
@ -22969,6 +23009,8 @@ void run_server(int argc, char **argv)
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);
pthread_mutex_init(&buffer_mutex, NULL);
#endif
#ifdef GY_OS_NOVA
pthread_mutex_init(&mutex_pre_bbox_receive, NULL);
@ -23024,7 +23066,7 @@ void run_server(int argc, char **argv)
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");
printf("preload http server thread creation failed\n");
}
@ -25929,22 +25971,17 @@ 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)
{
// 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");
}
pthread_create(&runpython_thread, NULL, start_run_python_thread, (void*)configPATH);
} 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;
@ -27383,7 +27420,7 @@ void run_server(int argc, char **argv)
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));
}
@ -31775,6 +31812,104 @@ void file_management() {
#endif
}
#define COUNTER_FILE "/emmc/plugin/Aida_data/counters.dat"
int protected_counters = 0;
int g_last_counters[MAX_EVENT_COUNTERS] = { 0 };
void loadCounters() {
#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 (protected_counters == 0) {
protected_counters = 1;
FILE *file = fopen(COUNTER_FILE, "r+"); // 以二進位讀取方式開啟檔案
int counters[MAX_EVENT_COUNTERS] = { 0 };
if (file) {
fread(counters, sizeof(int), MAX_EVENT_COUNTERS, file); // 從檔案中讀取計數器值
fclose(file);
for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++)
{
eventCounterList[index_counter].counter_count = counters[index_counter];
g_last_counters[index_counter] = counters[index_counter];
}
}
else {
for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++)
{
counters[index_counter] = eventCounterList[index_counter].counter_count;
g_last_counters[index_counter] = counters[index_counter];
}
file = fopen(COUNTER_FILE, "w+"); // 以二進位寫入方式開啟檔案
if (file) {
fwrite(counters, sizeof(int), MAX_EVENT_COUNTERS, file); // 將計數器值寫入檔案
fclose(file);
}
else {
printf("\nCOUNTER FILE error.#2\n");
}
}
protected_counters = 0;
}
}
#endif
}
void saveCounters() {
#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 (protected_counters == 0) {
protected_counters = 1;
int counters[MAX_EVENT_COUNTERS] = { 0 };
int check_if_difference = 0;
for (int index_counter = 0; index_counter < MAX_EVENT_COUNTERS; index_counter++)
{
counters[index_counter] = eventCounterList[index_counter].counter_count;
if (counters[index_counter] != g_last_counters[index_counter]) {
check_if_difference = 1;
}
g_last_counters[index_counter] = counters[index_counter];
}
if (check_if_difference == 1) {
FILE *file = fopen(COUNTER_FILE, "wb"); // 以二進位寫入方式開啟檔案
if (file) {
fwrite(counters, sizeof(int), MAX_EVENT_COUNTERS, file); // 將計數器值寫入檔案
fclose(file);
}
else {
printf("\nCOUNTER FILE error.\n");
}
}
protected_counters = 0;
}
}
#endif
}
#ifdef GY_OS_NOVA
int get_pid_nova_driver() {
char *temp = NULL;
@ -31829,6 +31964,7 @@ void *RUN_NOVA_DETECTION(void *ptr) { //A11en
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");
saveCounters();
pthread_t auto_reboot_thread_id;
if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL))

10
src/face_parser.cpp

@ -313,7 +313,7 @@ void check_directory_exists(const char* path) {
if (stat(directory_path, &st) == -1) {
if (mkdir(directory_path, 0700) == -1) {
perror("mkdir error");
printf("mkdir error\n");
}
}
}
@ -362,7 +362,7 @@ void save_base64_image(char* base64_data, const char* output_filename) {
#endif
if (errno != 0) {
// 發生錯誤,根據實際情況處理錯誤原因,可以使用 perror 函式打印錯誤訊息
perror("fwrite error");
printf("fwrite error\n");
// Fail
}
} else {
@ -652,7 +652,7 @@ void base64_to_tpl(char* base64_data, char* output_filename) {
#endif
if (errno != 0) {
// 發生錯誤,根據實際情況處理錯誤原因,可以使用 perror 函式打印錯誤訊息
perror("fwrite error");
printf("fwrite error\n");
// Fail
}
} else {
@ -678,7 +678,7 @@ void base64_to_tpl(char* base64_data, char* output_filename) {
char *readJsonFile(const char *filePath) {
FILE *file = fopen(filePath, "r");
if (file == NULL) {
perror("Error opening file");
printf("Error opening file\n");
return NULL;
}
@ -698,7 +698,7 @@ char *readJsonFile(const char *filePath) {
void writeJsonToFile(const char *filePath, const char *jsonData) {
FILE *file = fopen(filePath, "w");
if (file == NULL) {
perror("Error opening file");
printf("Error opening file\n");
return;
}

84
src/ivs.cpp

@ -516,29 +516,17 @@ int get_store_img_background_array_length_test() {
void release_img_background() {
//if (g_pMOG2 != nullptr) {
//g_pMOG2.release();
//}
//if (g_pMOG2_2 != nullptr) {
//g_pMOG2_2.release();
//}
// ²M²z°O¾ÐÅé
g_multiLayerMOG2.clearMemory();
g_multiLayerMOG2_2.clearMemory();
for (int i = 0; i < store_img_background_array_length; i++) {
if (!img_background_array[i].empty()) {
img_background_array[i].release();
}
}
for (int i = 0; i < store_img_background_array_length_test; i++) {
if (!img_background_array_test[i].empty()) {
img_background_array_test[i].release();
}
}
//for (int i = 0; i < store_img_background_array_length_test; i++) {
//if (!img_background_array_test[i].empty()) {
//img_background_array_test[i].release();
//}
//}
if (!img_background_short_term.empty()) {
img_background_short_term.release();
@ -560,6 +548,17 @@ void release_img_background() {
if (!img_background_long_term_yuv.empty())
img_background_long_term_yuv.release();
//if (g_pMOG2 != nullptr) {
//g_pMOG2.release();
//}
//if (g_pMOG2_2 != nullptr) {
//g_pMOG2_2.release();
//}
// ²M²z°O¾ÐÅé
g_multiLayerMOG2.clearMemory();
g_multiLayerMOG2_2.clearMemory();
}
void run_compute_median() {
@ -2282,7 +2281,7 @@ int differ_image(char *output_image,int* image_size,char * snaphd_image_buffer,
//printf("\n-------tempering_ready:%d\n", tempering_ready);
//printf("\n-------switch_happened:%d\n", get_check_if_existing_any_switch_happened());
if (not_to_show_tempering == 1 || (area_scale <= 0.95 && tempering_ready == 0))
if (not_to_show_tempering == 1 || (area_scale <= 0.45 && tempering_ready == 0))
{
check_if_tempering_many_times = (temp_AI_fps - 1) * 4;
@ -2742,7 +2741,7 @@ int differ_image(char *output_image,int* image_size,char * snaphd_image_buffer,
}
}
}
else if (not_to_show_tempering == 0 && ((area_scale >= 0.95 && check_if_tempering_many_times <= 0) || tempering_ready == 1))//(area_scale >= 0.83 && imageDnData.check_if_switch_happened[MAX_SIZE_SWITCH_HAPPENED - 1] == 1) ||
else if (not_to_show_tempering == 0 && ((area_scale >= 0.6 && check_if_tempering_many_times <= 0) || tempering_ready == 1))//(area_scale >= 0.83 && imageDnData.check_if_switch_happened[MAX_SIZE_SWITCH_HAPPENED - 1] == 1) ||
{
current_store_object_size = 0;
@ -2764,9 +2763,9 @@ int differ_image(char *output_image,int* image_size,char * snaphd_image_buffer,
tempering_ready = 0;
}
}
#if 0
else if ((area_scale < 0.83 && get_check_if_existing_any_switch_happened() == 1) ||
record_change_state == 1) {
#if 1
else if (not_to_show_tempering == 0 && ((area_scale < 0.83 && get_check_if_existing_any_switch_happened() == 1) ||
record_change_state == 1)) {
current_store_object_size = 0;
last_store_object_size = current_store_object_size;
@ -2787,7 +2786,7 @@ int differ_image(char *output_image,int* image_size,char * snaphd_image_buffer,
}
}
#endif
else if (not_to_show_tempering == 0 && (area_scale >= 0.95 && check_if_tempering_many_times >= 1)) {
else if (not_to_show_tempering == 0 && (area_scale >= 0.6 && check_if_tempering_many_times >= 1)) {
current_store_object_size = 0;
last_store_object_size = current_store_object_size;
/*
@ -2931,15 +2930,13 @@ int mog2_image(char *output_image, int* image_size, char * snaphd_image_buffer,
uint32_t valid_bbox_idx = 0;
int ivs_width = 240;//320
int ivs_height = 135;//180
int ivs_width = 320;//320
int ivs_height = 180;//180
float ratio_width = (float)i_InSourceOri_w / (float)ivs_width;
float ratio_height = (float)i_InSourceOri_h / (float)ivs_height;
if (not_to_show_tempering == 0 && check_if_tempering_happened <= 0) {
*no_tempering = 0;
check_if_tempering_many_times = (temp_AI_fps - 1) * 2;
g_progress_bar = 100.0;
}
else if (not_to_show_tempering == 0 && check_if_tempering_happened >= 1) {
g_progress_bar = 1.0;
@ -2985,6 +2982,10 @@ int mog2_image(char *output_image, int* image_size, char * snaphd_image_buffer,
g_multiLayerMOG2_2.initialize();
g_count_mog2_2 = 0;
check_if_tempering_many_times = (temp_AI_fps - 1) * 2;
*no_tempering = 0;
g_progress_bar = 100.0;
}
check_if_tempering_happened--;
@ -3659,10 +3660,11 @@ int mog2_image(char *output_image, int* image_size, char * snaphd_image_buffer,
double area_scale = ((double)sum_area) / ((double)ivs_width * (double)ivs_height);
//printf("\n-------area scale:%lf\n", area_scale);
//printf("\n-------area scale:%lf,switch:%d,times:%d,not_to_show:%d,no_tempering:%d,record_change_state:%d\n", area_scale, get_check_if_existing_any_switch_happened(), check_if_tempering_many_times, not_to_show_tempering, *no_tempering, record_change_state);
if (not_to_show_tempering == 1 || (area_scale <= 0.95 && tempering_ready == 0))
if (not_to_show_tempering == 1 || (area_scale <= 0.45 && tempering_ready == 0))
{
//printf("\nAAAAAAAA 1:not_to_show:%d,area_scale:%lf,tempering_ready:%d\n", not_to_show_tempering, area_scale, tempering_ready);
check_if_tempering_many_times = (temp_AI_fps - 1) * 2;
current_store_object_size = 0;
@ -4011,8 +4013,10 @@ int mog2_image(char *output_image, int* image_size, char * snaphd_image_buffer,
}
}
}
else if (not_to_show_tempering == 0 && ((area_scale >= 0.95 && check_if_tempering_many_times <= 0) || tempering_ready == 1))
else if (not_to_show_tempering == 0 && ((area_scale >= 0.6 && check_if_tempering_many_times <= 0) || tempering_ready == 1))
{
//printf("\nAAAAAAAA 2:not_to_show:%d,area_scale:%lf,tempering_ready:%d,times:%d\n", not_to_show_tempering, area_scale, tempering_ready, check_if_tempering_many_times);
current_store_object_size = 0;
last_store_object_size = current_store_object_size;
@ -4023,8 +4027,24 @@ int mog2_image(char *output_image, int* image_size, char * snaphd_image_buffer,
*no_tempering = 0;
tempering_ready = 0;
}
else if (not_to_show_tempering == 0 && (area_scale >= 0.95 && check_if_tempering_many_times >= 1))
else if (not_to_show_tempering == 0 && ((area_scale < 0.83 && get_check_if_existing_any_switch_happened() == 1) ||
record_change_state == 1))
{
//printf("\nAAAAAAAA 3:not_to_show:%d,area_scale:%lf,record_change_state:%d\n", not_to_show_tempering, area_scale, record_change_state);
current_store_object_size = 0;
last_store_object_size = current_store_object_size;
record_change_state = 1;
check_if_tempering_happened = 0;
record_change_state = 0;
*no_tempering = 0;
tempering_ready = 0;
}
else if (not_to_show_tempering == 0 && (area_scale >= 0.6 && check_if_tempering_many_times >= 1))
{
//printf("\nAAAAAAAA 4:not_to_show:%d,area_scale:%lf,times:%d\n", not_to_show_tempering, area_scale, check_if_tempering_many_times);
current_store_object_size = 0;
last_store_object_size = current_store_object_size;

6
src/network.c

@ -396,7 +396,7 @@ int resize_network(network *net, int w, int h)
}else if(l.type == COST){
resize_cost_layer(&l, inputs);
}else{
error("Cannot resize this type of layer");
printf("Cannot resize this type of layer\n");
}
if(l.workspace_size > workspace_size) workspace_size = l.workspace_size;
if(l.workspace_size > 2000000000) assert(0);
@ -899,7 +899,7 @@ pthread_t train_network_in_thread(network *net, data d, float *err)
ptr->net = net;
ptr->d = d;
ptr->err = err;
if(pthread_create(&thread, 0, train_thread, ptr)) error("Thread creation failed");
if(pthread_create(&thread, 0, train_thread, ptr)) printf("Thread creation failed\n");
return thread;
}
@ -1097,7 +1097,7 @@ pthread_t sync_layer_in_thread(network **nets, int n, int j)
ptr->nets = nets;
ptr->n = n;
ptr->j = j;
if(pthread_create(&thread, 0, sync_layer_thread, ptr)) error("Thread creation failed");
if(pthread_create(&thread, 0, sync_layer_thread, ptr)) printf("Thread creation failed\n");
return thread;
}

154
src/nweb.c

@ -143,7 +143,6 @@ extern pthread_mutex_t mutex_web;
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;
@ -257,7 +256,7 @@ static char *http_strLicenseType;
extern double http_license_fps;
extern int http_sleep_interval;
unsigned int python_check_webstatus = 0;
float confidence_limit;
extern CPoint trafficLightPoint;
@ -421,13 +420,13 @@ int g_control_alarm_gpio = 0;
int g_is_check_credential = 0;
char g_aWebPythonBuffer2D[WEBPYTHONBUFFER_LENSIZE][WEBPYTHONBUFFER_ROWSIZE];
char g_aWebPythonBuffer2D[WEBPYTHONBUFFER_LENSIZE][WEBPYTHONBUFFER_ROWSIZE] = { 0 };
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];
//char g_cWebPythonName[50] = { 0 };
struct MemoryStruct
{
char memory[MEMORY_SIZE];//256KB
@ -2476,6 +2475,7 @@ void *net_curl_https_post_push_info(void *ptr)
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");
saveCounters();
pthread_t auto_reboot_thread_id;
if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL))
@ -2748,6 +2748,7 @@ void *net_curl_https_get_other_lpr_db(void *ptr)
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");
saveCounters();
pthread_t auto_reboot_thread_id;
if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL))
@ -6530,6 +6531,7 @@ void* auto_resolution_changed(void * ptr) {
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");
saveCounters();
pthread_t auto_reboot_thread_id;
if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL))
@ -8798,6 +8800,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
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");
saveCounters();
pthread_t auto_reboot_thread_id;
if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL))
@ -9764,6 +9767,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
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");
saveCounters();
pthread_t auto_reboot_thread_id;
if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL))
@ -9885,6 +9889,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
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");
saveCounters();
pthread_t auto_reboot_thread_id;
if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL))
@ -10006,6 +10011,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
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");
saveCounters();
pthread_t auto_reboot_thread_id;
if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL))
@ -10774,7 +10780,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
// 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");
// printf("send error #1999\n");
}
else
#endif
@ -10838,7 +10844,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
// 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");
// printf("send error #1999\n");
}
else
#endif
@ -11198,11 +11204,11 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
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");
printf("send error #199916\n");
if ((int)snapshot_size >= 1)
{
if (send(cli_socket, snapshot_addr_radar, (int)snapshot_size, 0) == -1)
perror("send error #19999998");
printf("send error #19999998\n");
}
else
{
@ -11221,11 +11227,11 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
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");
printf("send error #199917\n");
if ((int)speed_snapshot_size >= 1)
{
if (send(cli_socket, radar_speed_snapshot_addr, (int)speed_snapshot_size, 0) == -1)
perror("send error #19999999");
printf("send error #19999999\n");
}
else
{
@ -11971,6 +11977,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
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");
saveCounters();
pthread_t auto_reboot_thread_id;
if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL))
@ -12119,7 +12126,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
}
int sendBufferSize = SetHttpResponse(sendBuffer, _CODE_200, "text/html;", strlen(beforeSendBuffer), beforeSendBuffer);
if (send(cli_socket, sendBuffer, sendBufferSize, 0) == -1)
perror("send error #28");
printf("send error #28\n");
if (JsonString != NULL)
{
free(JsonString);
@ -13080,6 +13087,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
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");
saveCounters();
pthread_t auto_reboot_thread_id;
if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL))
@ -14116,7 +14124,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
readFolderList(sFileList);
strcpy(beforeSendBuffer_xtra, sFileList);
printf("sFileList: %s\n", sFileList);
//printf("sFileList: %s\n", sFileList);
}
else {
strcpy(beforeSendBuffer_xtra, "");
@ -14130,12 +14138,13 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
else if (strncmp(urlBuffer, "/pythonget?file=", strlen("/pythonget?file=")) == 0)
{
char sendBuffer_xtra[BUFSIZE * 8] = { 0 };
if (strcmp(SystemSetting.enable_python, "Yes") == 0) {
if (strcmp(SystemSetting.enable_python, "Yes") == 0 && g_cWebPythonBufferSignal == 0){
g_cWebPythonBufferSignal = 1;
char Cmd[512] = { 0 };
char sOutput[10240];
strcpy(Cmd, urlBuffer + 16);
printf("get file name = %s \n", Cmd);
//printf("get file name = %s \n", Cmd);
readPythonFile(Cmd, sOutput);
// printf("\nfile!!!\n");
@ -14150,6 +14159,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
g_uiWebPythonLastBufferIndex = 0;
strcpy(beforeSendBuffer_xtra, sOutput);
g_cWebPythonBufferSignal = 0;
}
else {
@ -14170,7 +14180,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
strcpy(Cmd, urlBuffer + strlen("/pythonupload?"));
// printf("[/pythonupload?] cmd = %s \n", Cmd); //2024/03/08
printf("Uploading...\n");
//printf("Uploading...\n");
char decodeCMD[PYTHON_CODE_SIZE] = { 0 };
urldecode((unsigned char *)Cmd, (unsigned char *)decodeCMD);
strcpy(beforeSendBuffer_xtra, uploadPython(decodeCMD));
@ -14196,7 +14206,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
strcpy(Cmd, urlBuffer + strlen("/pythonsave?"));
// printf("[/pythonupload?] cmd = %s \n", Cmd); //2024/03/08
printf("Saving...\n");
//printf("Saving...\n");
char decodeCMD[PYTHON_CODE_SIZE] = { 0 };
urldecode((unsigned char *)Cmd, (unsigned char *)decodeCMD);
strcpy(beforeSendBuffer_xtra, SavePython(decodeCMD));
@ -14222,11 +14232,11 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
char Cmd[512] = { 0 };
strcpy(Cmd, urlBuffer + 14);
printf("cmd = %s \n", Cmd);
//printf("cmd = %s \n", Cmd);
strcpy(Cmd, urlBuffer + 19);
printf("get file name = %s \n", Cmd);
//printf("get file name = %s \n", Cmd);
deletePythonFile(Cmd);
if (g_cWebPythonDeleteStatus == 1)
@ -14240,7 +14250,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
}
else {
sprintf(SendDeleteStatus, "Please check the Enable python checkbox configuration in the SETTING TAB");
strcpy(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)
@ -14257,7 +14267,8 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
char Cmd[512] = { 0 };
strcpy(Cmd, urlBuffer + 17);
printf("cmd = %s \n", Cmd);
//printf("cmd = %s \n", Cmd);
strcpy(beforeSendBuffer_xtra,"");
}
else {
strcpy(beforeSendBuffer_xtra, "Please check the Enable python checkbox configuration in the SETTING TAB");
@ -15621,7 +15632,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
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");
printf("send error radar.json\n");
// if no closesocket(), html console will show net::ERR_EMPTY_RESPONSE
if (root)
{
@ -16028,7 +16039,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
}
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");
printf("[CGI:/gettof] send json string error\n");
if (JsonString != NULL)
{
free(JsonString);
@ -16379,7 +16390,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
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");
printf("send error tof.json\n");
// if no closesocket(), html console will show net::ERR_EMPTY_RESPONSE
if (root)
{
@ -16425,7 +16436,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
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)
if (strcmp(SystemSetting.enable_python, "Yes") == 0)
{
char *buffersize_ptr = strstr(urlBuffer, "buffersize=");
if (buffersize_ptr != NULL)
@ -16439,7 +16450,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
{
g_cWebPythonStatus = 3;
}
printf("!!! [/pythongetstatus g_uiWebPythonLastBufferIndex:%d & g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex);
//printf("!!! [/pythongetstatus g_uiWebPythonLastBufferIndex:%d & g_uiWebPythonCurrentBufferIndex:%u\n", g_uiWebPythonLastBufferIndex, g_uiWebPythonCurrentBufferIndex);
// 每次拿取 Buffer N 個 Row 的資料
for (unsigned int i = 0; i < uiCMDBufferRowSize; i++)
@ -16457,7 +16468,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
else
{
g_cWebPythonStatus = 4; // 寫入和讀取在同一 Row
printf("\n\n[/pythongetstatus] Same Index !!! Wait Write Data \n\n");
//printf("\n\n[/pythongetstatus] Same Index !!! Wait Write Data \n\n");
continue;
}
}
@ -16479,7 +16490,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
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);
//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)
@ -16498,7 +16509,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
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)
if (strcmp(SystemSetting.enable_python, "Yes") == 0)
{
char *buffersize_ptr = strstr(urlBuffer, "buffersize=");
if (buffersize_ptr != NULL)
@ -16522,7 +16533,7 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
if (g_uiWebPythonLastBufferIndex >= (WEBPYTHONBUFFER_LENSIZE-1))
{
printf("\n\n\n/pythongetbuffer] Buffer Row Reset !!!\n\n\n");
//printf("\n\n\n/pythongetbuffer] Buffer Row Reset !!!\n\n\n");
g_uiWebPythonLastBufferIndex = 0;
}
if (bufferContentSize > 0)
@ -16531,21 +16542,22 @@ 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);
pthread_mutex_lock(&buffer_mutex);
// 拿 python 輸出
printf("[pythongetbuffer] get %d data \n",g_uiWebPythonLastBufferIndex);
//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); // ¸ÑÂê
pthread_mutex_unlock(&buffer_mutex); // ¸ÑÂê
// 更新讀取位置
g_uiWebPythonLastBufferIndex++;
usSleep(1000);
}
else
{
printf("\n\n/pythongetbuffer] Same Index !!! No Read Data \n\n");
//printf("\n\n/pythongetbuffer] Same Index !!! No Read Data \n\n");
continue;
}
@ -16558,15 +16570,18 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
}
}
g_cWebPythonBufferSignal = 0;
}
else
{
strcpy(sPythonBufferTemp, "Please check the Enable python checkbox configuration in the SETTING TAB");
//strcpy(sPythonBufferTemp, "Please check the Enable python checkbox configuration in the SETTING TAB");
strcpy(sPythonBufferTemp, "");
}
printf("\n\nsPythonBufferTemp : %s\n\n",sPythonBufferTemp);
//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);
//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)
@ -19730,7 +19745,11 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
#endif
}
else {
//strcpy(beforeSendBuffer, "Fail---4:");
//strcat(beforeSendBuffer, file_Content);
}
if (root) {
cJSON_Delete(root);
root = NULL;
@ -19763,18 +19782,33 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
}
#endif
printf("\nFail to read config_import.json or config.json\n");
//strcpy(beforeSendBuffer, "Fail---3");
}
}
else {
//strcpy(beforeSendBuffer, "Fail---2");
}
}
else {
//strcpy(beforeSendBuffer, "Fail---1");
}
if (check_if_setfile_OK == 1)
{
strcpy(beforeSendBuffer, "OK");
}
else {
strcpy(beforeSendBuffer, "Fail");
}
strcpy(beforeSendBuffer, "");
if (strlen(contentDescription) > 0)
{
strcat(beforeSendBuffer, " ");
strcat(beforeSendBuffer, contentDescription);
}
if (check_if_setfile_OK == 1) {
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");
@ -20631,7 +20665,14 @@ void web_process(SOCKET* client_socket, char* recvBuffer, int recv_buff_size, ch
}
strcpy(beforeSendBuffer, "");
if (check_if_setfile_OK == 1)
{
strcpy(beforeSendBuffer, "OK");
}
else {
strcpy(beforeSendBuffer, "Fail");
}
if (strlen(contentDescription) > 0)
{
strcat(beforeSendBuffer, " ");
@ -23115,6 +23156,19 @@ void *http_connection_handler(void *socket_desc)
//memset(temp_buffer, 0x00, header_len+ nbytes_sec);
//memcpy(temp_buffer, buffer, header_len+ nbytes_sec);
if (strstr(buffer, "setconfigfile") != NULL && strstr(buffer, "camera01") != NULL)
{
if (strstr(buffer, "}}}") != NULL) {
}
else if (strstr(buffer, "system_setting") != NULL && strstr(buffer, "}}") != NULL) {
}
else {
header_len += nbytes_sec;
continue;
}
}
}
else if ((strstr(buffer, "Connection: Upgrade") != NULL || strstr(buffer, "Upgrade: websocket") != NULL )
&& strstr(buffer, "\r\n\r\n") != NULL) //非socket的會去檢查到\r\n\r\n,才往下執行。
@ -23141,6 +23195,20 @@ void *http_connection_handler(void *socket_desc)
//printf("\n---------[NVR#1]buffer:%s\n", buffer);
//memset(temp_buffer, 0x00, header_len + nbytes_sec);
//memcpy(temp_buffer, buffer, header_len + nbytes_sec);
if (strstr(buffer, "setconfigfile") != NULL && strstr(buffer, "camera01") != NULL)
{
if (strstr(buffer, "}}}") != NULL) {
}
else if (strstr(buffer, "system_setting") != NULL && strstr(buffer, "}}") != NULL) {
}
else {
header_len += nbytes_sec;
continue;
}
}
}
else if (strstr(buffer, "\r\n\r\n") != NULL) //如果不是上述兩個,則[NVR]直接做"\r\n\r\n"的判斷。
{
@ -23718,11 +23786,11 @@ void *http_connection_handler(void *socket_desc)
{
char* file_Content = recvbuffer + i;
printf("file content = %s \n", file_Content);
//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);
//printf("##################### file_Content : %s /n", file_Content);
runPython(file_Content);
strcpy(SendPython, "Web Buffer Run OK !!");
}
@ -23731,7 +23799,6 @@ void *http_connection_handler(void *socket_desc)
strcpy(SendPython, "Send python file fail !!");
}
}
}
}
else {
@ -24521,7 +24588,6 @@ void *http_connection_handler(void *socket_desc)
while (bHttpServerMainStart)
{
python_check_webstatus = 1; // Ming add
if (sock_err_hold_times >= MAX_SOCK_ERR_HOLD_TIMES * 2) {
//printf("\n------------websocket break 1\n");
break;

9
src/nweb.h

@ -814,15 +814,6 @@ extern "C" {
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;
//=====================

28
src/parser.c

@ -242,7 +242,7 @@ local_layer parse_local(list *options, size_params params)
w = params.w;
c = params.c;
batch=params.batch;
if(!(h && w && c)) error("Layer before local layer must output image.");
if(!(h && w && c)) printf("Layer before local layer must output image.\n");
local_layer layer = make_local_layer(batch,h,w,c,n,size,stride,pad,activation);
@ -263,7 +263,7 @@ layer parse_deconvolutional(list *options, size_params params)
w = params.w;
c = params.c;
batch=params.batch;
if(!(h && w && c)) error("Layer before deconvolutional layer must output image.");
if(!(h && w && c)) printf("Layer before deconvolutional layer must output image.\n");
int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0);
int pad = option_find_int_quiet(options, "pad",0);
int padding = option_find_int_quiet(options, "padding",0);
@ -293,7 +293,7 @@ convolutional_layer parse_convolutional(list *options, size_params params)
w = params.w;
c = params.c;
batch=params.batch;
if(!(h && w && c)) error("Layer before convolutional layer must output image.");
if(!(h && w && c)) printf("Layer before convolutional layer must output image.\n");
int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0);
int binary = option_find_int_quiet(options, "binary", 0);
int xnor = option_find_int_quiet(options, "xnor", 0);
@ -557,7 +557,7 @@ crop_layer parse_crop(list *options, size_params params)
w = params.w;
c = params.c;
batch=params.batch;
if(!(h && w && c)) error("Layer before crop layer must output image.");
if(!(h && w && c)) printf("Layer before crop layer must output image.\n");
int noadjust = option_find_int_quiet(options, "noadjust",0);
@ -579,7 +579,7 @@ layer parse_reorg(list *options, size_params params)
w = params.w;
c = params.c;
batch=params.batch;
if(!(h && w && c)) error("Layer before reorg layer must output image.");
if(!(h && w && c)) printf("Layer before reorg layer must output image.\n");
layer layer = make_reorg_layer(batch,w,h,c,stride,reverse, flatten, extra);
return layer;
@ -596,7 +596,7 @@ maxpool_layer parse_maxpool(list *options, size_params params)
w = params.w;
c = params.c;
batch=params.batch;
if(!(h && w && c)) error("Layer before maxpool layer must output image.");
if(!(h && w && c)) printf("Layer before maxpool layer must output image.\n");
maxpool_layer layer = make_maxpool_layer(batch,h,w,c,size,stride,padding);
return layer;
@ -609,7 +609,7 @@ avgpool_layer parse_avgpool(list *options, size_params params)
h = params.h;
c = params.c;
batch=params.batch;
if(!(h && w && c)) error("Layer before avgpool layer must output image.");
if(!(h && w && c)) printf("Layer before avgpool layer must output image.\n");
avgpool_layer layer = make_avgpool_layer(batch,w,h,c);
return layer;
@ -707,7 +707,7 @@ route_layer parse_route(list *options, size_params params, network *net)
{
char *l = option_find(options, "layers");
int len = strlen(l);
if(!l) error("Route Layer must specify input layers");
if(!l) printf("Route Layer must specify input layers\n");
int n = 1;
int i;
for(i = 0; i < len; ++i){
@ -795,7 +795,7 @@ void parse_net_options(list *options, network *net)
net->exposure = option_find_float_quiet(options, "exposure", 1);
net->hue = option_find_float_quiet(options, "hue", 0);
if(!net->inputs && !(net->h && net->w && net->c)) error("No input parameters supplied");
if(!net->inputs && !(net->h && net->w && net->c)) printf("No input parameters supplied\n");
char *policy_s = option_find_str(options, "policy", "constant");
net->policy = get_policy(policy_s);
@ -807,7 +807,7 @@ void parse_net_options(list *options, network *net)
} else if (net->policy == STEPS){
char *l = option_find(options, "steps");
char *p = option_find(options, "scales");
if(!l || !p) error("STEPS policy must have steps and scales in cfg file");
if(!l || !p) printf("STEPS policy must have steps and scales in cfg file\n");
int len = strlen(l);
int n = 1;
@ -848,14 +848,14 @@ network *parse_network_cfg(char *filename)
{
list *sections = read_cfg(filename);
node *n = sections->front;
if(!n) error("Config file has no sections");
if(!n) printf("Config file has no sections\n");
network *net = make_network(sections->size - 1);
net->gpu_index = gpu_index;
size_params params;
section *s = (section *)n->val;
list *options = s->options;
if(!is_network(s)) error("First section must be [net] or [network]");
if(!is_network(s)) printf("First section must be [net] or [network]\n");
parse_net_options(options, net);
params.h = net->h;
@ -1685,7 +1685,7 @@ convolutional_layer parse_convolutional_mem(list *options, size_params params)
w = params.w;
c = params.c;
batch = params.batch;
if (!(h && w && c)) error("Layer before convolutional layer must output image.");
if (!(h && w && c)) printf("Layer before convolutional layer must output image.\n");
int batch_normalize = option_find_int_quiet(options, "batch_normalize", 0);
int binary = option_find_int_quiet(options, "binary", 0);
int xnor = option_find_int_quiet(options, "xnor", 0);
@ -1765,7 +1765,7 @@ maxpool_layer parse_maxpool_mem(list *options, size_params params)
w = params.w;
c = params.c;
batch = params.batch;
if (!(h && w && c)) error("Layer before maxpool layer must output image.");
if (!(h && w && c)) printf("Layer before maxpool layer must output image.\n");
maxpool_layer layer = make_maxpool_layer_mem(batch, h, w, c, size, stride, padding);
return layer;

101
src/pns.c

@ -856,6 +856,7 @@ size_t PNS_Get_Snapshot_From_IPCam(char* file_name, char* img_addr, int enable_t
snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY");
write_to_logs_html(temp_msg, "PNS Get Snapshot", "CGI_REBOOT", "Yes");
write_to_log_if_error(temp_msg, "PNS Get Snapshot", "CGI_REBOOT");
saveCounters();
pthread_t auto_reboot_thread_id;
if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL))
@ -1005,6 +1006,7 @@ size_t PNS_Get_Snapshot_From_Remote_IPCam(char* file_name, char* img_addr, int e
snprintf(temp_msg,sizeof(temp_msg), "free:%d,%s", get_free_mem_data(), "CURLE OUT OF MEMORY");
write_to_logs_html(temp_msg, "PNS Get Snapshot remote", "CGI_REBOOT", "Yes");
write_to_log_if_error(temp_msg, "PNS Get Snapshot remote", "CGI_REBOOT");
saveCounters();
pthread_t auto_reboot_thread_id;
if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL))
@ -1121,10 +1123,38 @@ void stop_canvas_live_mode_flag() {
int g_pns_account_OK = 0;
int g_pns_access_level = -1;
int g_check_noapplink = 0;
char g_last_cloud_account[256] = { 0 };
char g_last_cloud_password[256] = { 0 };
int g_check_invalidpass = 0;
int g_check_emailnotvalid = 0;
//char g_last_cloud_account[256] = { 0 };
//char g_last_cloud_password[256] = { 0 };
struct timeval g_currtime_pns_post;
long g_last_s_pns_post = 0;
void set_g_pns_account_OK(int temp_g_pns_account_OK) {
g_pns_account_OK = temp_g_pns_account_OK;
}
void set_g_pns_access_level(int temp_g_pns_access_level) {
g_pns_access_level = temp_g_pns_access_level;
}
void set_g_check_invalidpass(int temp_g_check_invalidpass) {
g_check_invalidpass = temp_g_check_invalidpass;
}
void set_g_check_emailnotvalid(int temp_g_check_emailnotvalid) {
g_check_emailnotvalid = temp_g_check_emailnotvalid;
}
int get_g_check_wrong_pass_or_email() {
if (g_check_emailnotvalid == 1 || g_check_invalidpass == 1) {
return 1;
}
else {
return 0;
}
}
void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str, char* arg_event_id, char* arg_event_id_16, char* arg_event_desc, char* user_account, char* user_password, char* region_cloud_addr, char *returned_msg, char* image_buff, int image_buff_size, time_t rawtime)
{
//printf("\n---------------[PNS Send Multipart POST]:%d\n",1);
@ -1138,12 +1168,10 @@ void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str,
if (g_check_ping_OK == 1) {
if (g_pns_access_level <= 0 && (current_s_pns_post - g_last_s_pns_post) >= 3600) {
g_check_noapplink = 0;
g_pns_account_OK = 0;
g_last_s_pns_post = current_s_pns_post;
}
else if (g_pns_access_level >= 1 && (current_s_pns_post - g_last_s_pns_post) >= 600) {
g_check_noapplink = 0;
g_pns_account_OK = 0;
g_last_s_pns_post = current_s_pns_post;
}
}
@ -1151,48 +1179,7 @@ void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str,
int check_reboot = 0;
if (g_check_ping_OK == 1 && g_check_noapplink == 0) {
if (strlen(user_account) >= 1 && strlen(user_password) >= 1 && strcmp(user_account,"myaccount@mail.com") != 0){
if (strlen(g_last_cloud_account) >= 1 && strlen(g_last_cloud_password) >= 1) {
if (strcmp(user_account, g_last_cloud_account) != 0 ||
strcmp(user_password, g_last_cloud_password) != 0) {
g_pns_account_OK = 0;
}
}
if (g_pns_account_OK == 0) {
memset(g_last_cloud_account, 0x00, sizeof(g_last_cloud_account));
memset(g_last_cloud_password, 0x00, sizeof(g_last_cloud_password));
strcpy(g_last_cloud_account, user_account);
strcpy(g_last_cloud_password, user_password);
char returned_msg_temp[MEMORY_SIZE] = { 0 };
PNS_check_if_to_post_image(user_account, user_password, returned_msg_temp, region_cloud_addr);
if (strstr(returned_msg_temp, "\"msg\":\"oaA=\"") != NULL) {
g_pns_account_OK = 1;
}
if (g_pns_account_OK == 1) {
if (strstr(returned_msg_temp, "\"eid\":\"Yg==\"") != NULL) {
g_pns_access_level = 0;
}
else if (strstr(returned_msg_temp, "\"eid\":\"Yw==\"") != NULL) {
g_pns_access_level = 1;
}
else if (strstr(returned_msg_temp, "\"eid\":\"ZQ==\"") != NULL) {
g_pns_access_level = 3;
}
else if (strstr(returned_msg_temp, "\"eid\":{\"err\":\"Yw==\",\"msg\":\"p6PFmpaZoZqU\"}") != NULL) {
g_pns_access_level = -2;
}
}
}
}
else {
g_pns_account_OK = 1;
g_pns_access_level = 0;
}
if (g_check_ping_OK == 1 && g_check_noapplink == 0 && g_pns_access_level >= 0) {
//CURL* curl = curl_easy_init();
curl_mime* form = NULL;
@ -1737,6 +1724,16 @@ void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str,
if (strcmp(temp_msg,"noAppLink")==0 || strstr(temp_msg, "\"msg\":\"oKSipaB8nKOb\"") != NULL) {
g_check_noapplink = 1;
}
if (strcmp(temp_msg, "invalidPass") == 0 || strstr(temp_msg, "\"msg\":\"m6PXlpyZl4WR1qs=\"") != NULL) {
g_check_invalidpass = 1;
g_pns_access_level = 0;
}
if (strcmp(temp_msg, "emailNotValid") == 0 || strstr(temp_msg, "\"msg\":\"l6LCnpx+oqmGxKSdyg==\"") != NULL) {
g_check_emailnotvalid = 1;
g_pns_access_level = 0;
}
}
else {
char c_access_level[50] = { 0 };
@ -1754,6 +1751,16 @@ void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str,
if (strstr(ptr_responded_msg->memory, "\"msg\":\"oKSipaB8nKOb\"") != NULL) {
g_check_noapplink = 1;
}
if (strstr(ptr_responded_msg->memory, "\"msg\":\"m6PXlpyZl4WR1qs=\"") != NULL) {
g_check_invalidpass = 1;
g_pns_access_level = 0;
}
if (strstr(ptr_responded_msg->memory, "\"msg\":\"l6LCnpx+oqmGxKSdyg==\"") != NULL) {
g_check_emailnotvalid = 1;
g_pns_access_level = 0;
}
}
//printf("\n---------------[PNS Send Multipart POST]:%d\n", 12);
@ -1862,6 +1869,8 @@ void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str,
}*/
if (check_reboot == 1) {
saveCounters();
pthread_t auto_reboot_thread_id;
if (pthread_create(&auto_reboot_thread_id, 0, auto_reboot, NULL))
{

6
src/pns.h

@ -43,6 +43,12 @@ extern int g_check_ping_OK;
extern int g_sdk_version;
void set_g_pns_access_level(int temp_g_pns_access_level);
void set_g_pns_account_OK(int temp_g_pns_account_OK);
void set_g_check_invalidpass(int temp_g_check_invalidpass);
void set_g_check_emailnotvalid(int temp_g_check_emailnotvalid);
int get_g_check_wrong_pass_or_email();
void PNS_Query_Service_Status(char* returned_msg);
void PNS_Send_Multipart_POST(char* arg_json_string_for_im, char* arg_event_str, char* arg_event_id, char* arg_event_id_16, char* arg_event_desc, char* user_account, char* user_password, char* region_cloud_addr,char *returned_msg, char* image_buff, int image_buff_size, time_t rawtime);
int PNS_Get_Device_Name(int arg_url_encoded_or_not, char *returned_msg);

2
src/ptz.c

@ -896,7 +896,7 @@ void UpdatePTZConfigSetting()
}
}*/
printf("\n------------------------------->%d \n", g_stPTZ_Handle.iZoneToPresetAnyOne);
//printf("\n------------------------------->%d \n", g_stPTZ_Handle.iZoneToPresetAnyOne);

574
src/pythonR.c

@ -1,43 +1,52 @@
#include "pythonR.h"
#include <pthread.h>
#define MAX_BUFFER_LINES 1024
char sPythonCode[PYTHON_CODE_SIZE] = { 0 };
char sFileName[PTYHON_FILE_NAME] = { 0 };
//char sPythonCode[PYTHON_CODE_SIZE] = { 0 };
//char sFileName[PTYHON_FILE_NAME] = { 0 };
//char sPythonFilename[PTYHON_FILE_NAME];
pthread_mutex_t buffer_mutex = PTHREAD_MUTEX_INITIALIZER;
int check_count = 0;
//int check_count = 0;
void IfFolderExist()
{
if (access(PYTHON_FOLDER, 0) == 0)
{
printf("FOLDER EXISTS. \n");
}
else
{
printf("FOLDER DOESN'T EXISTS! \n");
//int ret;
/*ret = */mkdir(PYTHON_FOLDER, S_IRWXU | S_IRWXG | S_IRWXO);
int check_count = 0;
int check_if_ok = 0;
while (check_count < 10) {
if (access(PYTHON_FOLDER, F_OK) == 0) {
//printf("FOLDER EXISTS.\n");
check_if_ok = 1;
break;
}
else {
//printf("FOLDER DOESN'T EXIST! Attempting to create it...\n");
check_count++;
if (check_count < 10)
{
IfFolderExist();
if (mkdir(PYTHON_FOLDER, S_IRWXU | S_IRWXG | S_IRWXO) == 0) {
//printf("FOLDER CREATED SUCCESSFULLY.\n");
}
else {
//printf("Failed to create python folder\n");
}
}
check_count++;
usSleep(100);
}
if(check_if_ok == 0)
printf("FAILED TO CREATE FOLDER AFTER %d ATTEMPTS.\n", check_count);
}
void readPythonFile(char *sINFileName, char *sOutput)
{
memset(sPythonCode, 0, PYTHON_CODE_SIZE);
memset(sFileName, 0, PTYHON_FILE_NAME);
//char sPythonCode[PYTHON_CODE_SIZE] = { 0 };
char sFileName[PTYHON_FILE_NAME] = { 0 };
int lSize = 0;
//check folder exist
check_count = 0;
//check_count = 0;
IfFolderExist();
//python file name
@ -60,37 +69,49 @@ void readPythonFile(char *sINFileName, char *sOutput)
fclose(f);
}
else {
}
}
// ½T»{¸ê®Æ§¨¦s¦b
int ensureFolderExists(const char *folderPath) {
struct stat st = { 0 };
if (stat(folderPath, &st) == -1) {
mkdir(folderPath, 0777);
if (stat(folderPath, &st) == -1) {
return -1; // 無法創建資料夾
int ret = 0;
// 檢查資料夾是否已存在
if (stat(folderPath, &st) == -1) {
// 嘗試創建資料夾
if (mkdir(folderPath, 0777) == -1) {
// 如果創建失敗,記錄原因
printf("\nFailed to create directory\n");
ret = -1; // 創建失敗
}
}
else if (!S_ISDIR(st.st_mode)) {
// 如果同名的檔案存在但不是資料夾
printf("\nError: A file with the same name as the folder exists.\n");
ret = -1;
}
return 0; //
return ret;
}
int saveFile(char *pythonData, char *filename) {
int ret = 0;
if (ensureFolderExists(PYTHON_FOLDER) == -1) {
return -1; // 資料夾不存在
}
chmod(filename, 0777);
printf("[pythonR.html saveFile()] filename = %s\n", filename);
FILE *f = fopen(filename, "w");
if (f != NULL) {
fprintf(f, "%s\n", pythonData);
fclose(f);
return 0; // 成功
} else {
return -2; // 無法寫入
ret = -1; // 資料夾不存在
}
else {
chmod(filename, 0777);
//printf("[pythonR.html saveFile()] filename = %s\n", filename);
FILE *f = fopen(filename, "w");
if (f != NULL) {
fprintf(f, "%s\n", pythonData);
fclose(f);
}
else {
ret = -2; // 無法寫入
}
}
return ret;
}
#if 1
@ -100,19 +121,19 @@ void deletePythonFile(char *sINFileName)
// g_cWebPythonDeleteStatus = 0 deleted successfully
// g_cWebPythonDeleteStatus = 1 deleted failed
g_cWebPythonDeleteStatus = 0;
memset(sFileName, 0, PTYHON_FILE_NAME);
char sFileName[PTYHON_FILE_NAME] = { 0 };
//check folder exist
check_count = 0;
//check_count = 0;
IfFolderExist();
//python file name
//sprintf(sFileName, "%s/%s.py", PYTHON_FOLDER, sINFileName);
sprintf(sFileName, "%s/%s", PYTHON_FOLDER, sINFileName);
printf("[pythonR.html deletePythonFile()] filename = %s\n", sFileName);
//printf("[pythonR.html deletePythonFile()] filename = %s\n", sFileName);
if (remove(sFileName) == 0) {
printf("The file is deleted successfully. \n");
//printf("The file is deleted successfully. \n");
g_cWebPythonDeleteStatus = 1;
}
else {
@ -124,15 +145,21 @@ void deletePythonFile(char *sINFileName)
#endif
int checkDuplicateFile(const char *filename) { // check file name duplicate
char fullPath[1024];
snprintf(fullPath, sizeof(fullPath), "%s/%s", PYTHON_FOLDER, filename);
int ret = 0;
char fullPath[1024];
snprintf(fullPath, sizeof(fullPath), "%s/%s", PYTHON_FOLDER, filename);
if (access(fullPath, F_OK) != -1) {
// file exists
return 1;
ret = 1;
}
// file not exists
return 0;
else {
// file not exists
ret = 0;
}
return ret;
}
const char* SavePython(char *urlData) {
@ -140,7 +167,8 @@ const char* SavePython(char *urlData) {
char *substr2 = "&code=";
char *result_1 = strstr(urlData, substr1);
char *result_2 = strstr(urlData, substr2);
int ret = 0;
if (result_1 != NULL && result_2 != NULL) {
char sPythonFileName[1024] = {0};
char sPythonFilePath[1024] = {0};
@ -151,14 +179,26 @@ const char* SavePython(char *urlData) {
sprintf(sPythonFilePath, "%s/%s", PYTHON_FOLDER, sPythonFileName);
int saveResult = saveFile(sPythonCode, sPythonFilePath);
if(saveResult==0){
return "File save successfully";
}else{
return "File save failed";
}
if(saveResult == 0){
ret = 1;
}
else{
ret = 2;
}
}
else {
ret = 0;
}
if (ret == 1) {
return "File save successfully";
}
else if (ret == 2) {
return "File save failed";
}
else {//ret = 0
return "Invalid URL parameters";
}
return "Invalid URL parameters";
}
const char* uploadPython(char *urlData) {
@ -166,7 +206,8 @@ const char* uploadPython(char *urlData) {
char *substr2 = "&code=";
char *result_1 = strstr(urlData, substr1);
char *result_2 = strstr(urlData, substr2);
int ret = 0;
if (result_1 != NULL && result_2 != NULL) {
char sPythonFileName[1024] = {0};
char sPythonFilePath[1024] = {0};
@ -175,243 +216,268 @@ const char* uploadPython(char *urlData) {
memcpy(sPythonFileName, result_1 + strlen(substr1) , (result_2)-(result_1 + strlen(substr1)));
memcpy(sPythonCode, result_2 + strlen(substr2), (strlen(urlData) - ((result_2 + strlen(substr2)) - urlData)));
sprintf(sPythonFilePath, "%s/%s", PYTHON_FOLDER, sPythonFileName);
printf("[uploadPython] sPythonFileName = %s : ", sPythonFileName);
//printf("[uploadPython] sPythonFileName = %s : ", sPythonFileName);
if (strlen(sPythonFileName) == 0) {
printf("######################## No File name \n ");
return "Invalid file name";
//printf("######################## No File name \n ");
ret = 1;
}
else if (checkDuplicateFile(sPythonFileName) == 1)
{
return "File already exists, please choose a different file name";
ret = 2;
}
int saveResult = saveFile(sPythonCode, sPythonFilePath);
if(saveResult==0){
return "File uploaded successfully";
}else{
return "File upload failed";
}
else {
int saveResult = saveFile(sPythonCode, sPythonFilePath);
if (saveResult == 0) {
ret = 3;
}
else {
ret = 4;
}
}
}
else {
ret = 0;
}
if (ret == 1) {
return "Invalid file name";
}
else if (ret == 2) {
return "File already exists, please choose a different file name";
}
else if (ret == 3) {
return "File uploaded successfully";
}
else if (ret == 4) {
return "File upload failed";
}
else {//ret = 0
return "Invalid URL parameters";
}
return "Invalid URL parameters";
}
int g_stop_python = 0;
void stopPython() {
g_cWebPythonBufferSignal = 0;
for (int i = 0;i <= WEBPYTHONBUFFER_LENSIZE;i++)
{
memset(g_aWebPythonBuffer2D[i], 0, WEBPYTHONBUFFER_LENSIZE); // 2024-09-09 sure buffer clear
g_stop_python = 1;
if (g_cWebPythonBufferSignal == 0) {
g_cWebPythonBufferSignal = 0;
for (int i = 0; i <= WEBPYTHONBUFFER_LENSIZE; i++)
{
memset(g_aWebPythonBuffer2D[i], 0, WEBPYTHONBUFFER_LENSIZE); // 2024-09-09 sure buffer clear
}
g_uiWebPythonCurrentBufferIndex = 0;
g_uiWebPythonLastBufferIndex = 0;
g_cWebPythonStatus = 0;
//printf("\n\n\n\n\n\n\nPython has been signaled to stop.\n\n\n\n\n\n\n");
}
g_uiWebPythonCurrentBufferIndex = 0;
g_uiWebPythonLastBufferIndex = 0;
g_cWebPythonStatus = 0;
printf("\n\n\n\n\n\n\nPython has been signaled to stop.\n\n\n\n\n\n\n");
}
void runPython(char *pythonData) //2024/02/27 run button action
{
// -------------------------------------------------
// 處理 ajax 傳來的字串,拆解成檔名與檔案內容
char *substr1 = "lifile_liname=";
char *result_1 = NULL;
char sPythonFileName[1024] = {0};
result_1 = strstr(pythonData, substr1); //2024/02/27, search str and return str pointer position
memset(sPythonFileName, 0, PTYHON_FILE_NAME); //2024/02/27 name limit 1024 (use set mem value)
memset(sPythonCode, 0, PYTHON_CODE_SIZE); //2024/02/27 code size limit 20KB (use set mem value)
for (int i = 0;i <= WEBPYTHONBUFFER_LENSIZE;i++) // 2024-09-13 sure buffer clear
{
memset(g_aWebPythonBuffer2D[i], 0, WEBPYTHONBUFFER_LENSIZE);
}
memcpy(sPythonFileName, result_1 + 14, strlen(pythonData) - (result_1 + 14 - pythonData));
// if (g_cWebPythonName != NULL) {
// memcpy(sPythonFileName, result_1 + 14, strlen(pythonData) - (result_1 + 14 - pythonData));
// } else {
// // 如果 json 檔抓到 g_cWebPythonName 有值
// strncpy(sPythonFileName, g_cWebPythonName, sizeof(sPythonFileName) - 1);
// memset(g_cWebPythonName, 0, sizeof(g_cWebPythonName));
// }
// if need read python content, use cat command
// char result_3[PYTHON_CODE_SIZE] = {0};
// char cat_cmd[1024] = {0};
// FILE *fp;
// snprintf(cat_cmd, sizeof(cat_cmd), "cat %s/%s", PYTHON_FOLDER, sPythonFileName);
// fp = popen(cat_cmd, "r");
// if (fp == NULL) {
// printf("can't use cat command \n");
// } else {
// size_t bytes_read = fread(result_3, 1, sizeof(result_3) - 1, fp);
// if (bytes_read > 0) {
// result_3[bytes_read] = '\0'; // 確保字串結尾
// } else {
// printf("read file content failed \n");
// }
// pclose(fp);
// }
// -------------------------------------------------
// 建立 virtual pipeline 取得 python 輸出
int size_psBuffer = BUFSIZE_V3;
char psBuffer[WEBPYTHONBUFFER_ROWSIZE] = {0};
char sendBuffer_xtra[BUFSIZE * 8] = {0};
//char psRunPythonStatusMessage[80] = {0};
char psBufferTemp[WEBPYTHONBUFFER_ROWSIZE] = { 0 };
FILE *pPipe;
char cmd[256] = {0};
memset(cmd, 0x00, sizeof(cmd));
size_t psbufferContentSize = 0;
size_t psBufferTempSize = 0;
g_uiWebPythonCurrentBufferIndex = 0;
g_uiWebPythonLastBufferIndex = 0;
// sprintf(cmd, "python3 %s", sPythonFilePath);
sprintf(cmd, "python3 %s/%s 2>&1", PYTHON_FOLDER, sPythonFileName); // 新增 2>&1
printf("run python cmd = \n%s \n", cmd);
pPipe = vpopen(cmd, "r");
if (pPipe == NULL)
{
// virtual pipeline 建立失敗,回傳給 Web 錯誤訊息
printf("\n-------------------------------------\n");
printf("Failed to run command\n");
printf("pPipe is None!!\n");
printf("\n-------------------------------------\n");
// sprintf(psRunPythonStatusMessage, "Failed to run command. pPipe is None!!");
}
else
{
// sprintf(psRunPythonStatusMessage, "Web Buffer Run OK");
// 成功開啟 virtual pipeline 才去讀 python 輸出
g_stop_python = 0;
if (g_cWebPythonBufferSignal == 0) {
g_cWebPythonBufferSignal = 1; // Signal to start reading
// g_uiWebPythonCurrentBufferIndex = 0;
while ((fgets(psBuffer, sizeof(psBuffer), pPipe) != NULL) && (g_cWebPythonBufferSignal != 0)) { //Ming 2024-09-01
printf("[runPython] PYTHON OUTPUT: %s", psBuffer);
// printf("[runPython] Before writing: g_uiWebPythonCurrentBufferIndex[%d]\n", g_uiWebPythonCurrentBufferIndex);
psbufferContentSize = strlen(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex]);
// printf("\npsbufferContentSize len : %zu\n", psbufferContentSize);
if (psbufferContentSize == 0) {
printf("\n\n\n\n Writing !!!!!\n\n\n\n");
pthread_mutex_lock(&buffer_mutex);
size_t len = strlen(psBuffer);
if (psBufferTempSize + len < sizeof(psBufferTemp)) {
strcat(psBufferTemp, psBuffer); // 添加內容到 psBufferTemp
psBufferTempSize += len; // 更新計數器
} else {
// psBufferTemp 滿時,移到 g_aWebPythonBuffer2D 中並重置
// -------------------------------------------------
// 處理 ajax 傳來的字串,拆解成檔名與檔案內容
char *substr1 = "lifile_liname=";
char *result_1 = strstr(pythonData, substr1); //2024/02/27, search str and return str pointer position
if (result_1 != NULL) {
char sPythonFileName[PTYHON_FILE_NAME] = { 0 };
char sPythonCode[PYTHON_CODE_SIZE] = { 0 };
for (int i = 0; i <= WEBPYTHONBUFFER_LENSIZE; i++) // 2024-09-13 sure buffer clear
{
memset(g_aWebPythonBuffer2D[i], 0, WEBPYTHONBUFFER_LENSIZE);
}
memcpy(sPythonFileName, result_1 + 14, strlen(pythonData) - (result_1 + 14 - pythonData));
// if (g_cWebPythonName != NULL) {
// memcpy(sPythonFileName, result_1 + 14, strlen(pythonData) - (result_1 + 14 - pythonData));
// } else {
// // 如果 json 檔抓到 g_cWebPythonName 有值
// strncpy(sPythonFileName, g_cWebPythonName, sizeof(sPythonFileName) - 1);
// memset(g_cWebPythonName, 0, sizeof(g_cWebPythonName));
// }
// if need read python content, use cat command
// char result_3[PYTHON_CODE_SIZE] = {0};
// char cat_cmd[1024] = {0};
// FILE *fp;
// snprintf(cat_cmd, sizeof(cat_cmd), "cat %s/%s", PYTHON_FOLDER, sPythonFileName);
// fp = popen(cat_cmd, "r");
// if (fp == NULL) {
// printf("can't use cat command \n");
// } else {
// size_t bytes_read = fread(result_3, 1, sizeof(result_3) - 1, fp);
// if (bytes_read > 0) {
// result_3[bytes_read] = '\0'; // 確保字串結尾
// } else {
// printf("read file content failed \n");
// }
// pclose(fp);
// }
// -------------------------------------------------
// 建立 virtual pipeline 取得 python 輸出
char cmd[256] = { 0 };
// sprintf(cmd, "python3 %s", sPythonFilePath);
sprintf(cmd, "python3 %s/%s 2>&1", PYTHON_FOLDER, sPythonFileName); // 新增 2>&1
//printf("run python cmd = \n%s \n", cmd);
FILE *pPipe;
pPipe = vpopen(cmd, "r");
if (pPipe == NULL)
{
// virtual pipeline 建立失敗,回傳給 Web 錯誤訊息
printf("\n-------------------------------------\n");
printf("Failed to run command\n");
printf("pPipe is None!!\n");
printf("\n-------------------------------------\n");
// sprintf(psRunPythonStatusMessage, "Failed to run command. pPipe is None!!");
}
else
{
//int size_psBuffer = BUFSIZE_V3;
char psBuffer[WEBPYTHONBUFFER_ROWSIZE] = { 0 };
//char sendBuffer_xtra[BUFSIZE * 8] = { 0 };
//char psRunPythonStatusMessage[80] = {0};
char psBufferTemp[WEBPYTHONBUFFER_ROWSIZE] = { 0 };
size_t psbufferContentSize = 0;
size_t psBufferTempSize = 0;
g_uiWebPythonCurrentBufferIndex = 0;
g_uiWebPythonLastBufferIndex = 0;
// sprintf(psRunPythonStatusMessage, "Web Buffer Run OK");
// 成功開啟 virtual pipeline 才去讀 python 輸出
// g_uiWebPythonCurrentBufferIndex = 0;
while ((fgets(psBuffer, sizeof(psBuffer), pPipe) != NULL) && g_stop_python == 0) { //Ming 2024-09-01
// printf("[runPython] PYTHON OUTPUT: %s", psBuffer);
// printf("[runPython] Before writing: g_uiWebPythonCurrentBufferIndex[%d]\n", g_uiWebPythonCurrentBufferIndex);
psbufferContentSize = strlen(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex]);
// printf("\npsbufferContentSize len : %zu\n", psbufferContentSize);
if (psbufferContentSize == 0) {
//printf("\n\n\n\n Writing !!!!!\n\n\n\n");
pthread_mutex_lock(&buffer_mutex);
size_t len = strlen(psBuffer);
if (psBufferTempSize + len < sizeof(psBufferTemp)) {
strcat(psBufferTemp, psBuffer); // 添加內容到 psBufferTemp
psBufferTempSize += len; // 更新計數器
}
else {
// psBufferTemp 滿時,移到 g_aWebPythonBuffer2D 中並重置
strncpy(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex], psBufferTemp, WEBPYTHONBUFFER_ROWSIZE);
memset(psBufferTemp, 0, sizeof(psBufferTemp)); // 清空 psBufferTemp
strcat(psBufferTemp, psBuffer); // 重置後繼續放入資料
psBufferTempSize = 0; // 重置計數器
psBufferTempSize += len; // 重置後繼續計數
// printf("\n\n\n\n [runPython] Moved data to buffer : %s\n\n\n\n", g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex]);
g_uiWebPythonCurrentBufferIndex++;
}
pthread_mutex_unlock(&buffer_mutex);
if (g_uiWebPythonCurrentBufferIndex >= (WEBPYTHONBUFFER_LENSIZE - 1)) {
//printf("!!! [runPython] Reset buffer index\n");
g_uiWebPythonCurrentBufferIndex = 0;
}
usSleep(1000);
}
else {
//printf("[runPython] buffer is not empty, psbufferContentSize:%zu\n", psbufferContentSize);
continue;
}
}
vpclose(pPipe); // Close the pipe after reading all outputs
// 未滿的 Row 要送入 Buffer
if (psBufferTempSize > 0)
{
strncpy(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex], psBufferTemp, WEBPYTHONBUFFER_ROWSIZE);
memset(psBufferTemp, 0, sizeof(psBufferTemp)); // ²MªÅ psBufferTemp
strcat(psBufferTemp, psBuffer); // 重置後繼續放入資料
psBufferTempSize = 0; // 重置計數器
psBufferTempSize += len; // 重置後繼續計數
// printf("\n\n\n\n [runPython] Moved data to buffer : %s\n\n\n\n", g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex]);
g_uiWebPythonCurrentBufferIndex++;
}
pthread_mutex_unlock(&buffer_mutex);
if (g_uiWebPythonCurrentBufferIndex >= (WEBPYTHONBUFFER_LENSIZE - 1)) {
printf("!!! [runPython] Reset buffer index\n");
g_uiWebPythonCurrentBufferIndex = 0;
}
} else {
printf("[runPython] buffer is not empty, psbufferContentSize:%zu\n", psbufferContentSize);
continue;
//
}
// int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(psRunPythonStatusMessage), psRunPythonStatusMessage);
// if (send(sock, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1)
// {
// printf("\nsend error #32\n");
// }
}
// 未滿的 Row 要送入 Buffer
if (psBufferTempSize > 0 )
{
strncpy(g_aWebPythonBuffer2D[g_uiWebPythonCurrentBufferIndex], psBufferTemp, WEBPYTHONBUFFER_ROWSIZE);
memset(psBufferTemp, 0, sizeof(psBufferTemp)); // 清空 psBufferTemp
g_uiWebPythonCurrentBufferIndex++;
}
g_cWebPythonBufferSignal = 0; // 需在 python 跑完時,切回 0,pythongetbuffer CGI 才能確切知道 python 執行狀態
//
pclose(pPipe); // Close the pipe after reading all outputs
g_cWebPythonBufferSignal = 0; // 需在 python 跑完時,切回 0,pythongetbuffer CGI 才能確切知道 python 執行狀態
}
// int sendBufferSize = SetHttpResponse(sendBuffer_xtra, _CODE_200, "text/html; charset=utf-8", strlen(psRunPythonStatusMessage), psRunPythonStatusMessage);
// if (send(sock, sendBuffer_xtra, sendBufferSize, MSG_MORE) == -1)
// {
// printf("\nsend error #32\n");
// }
}
void readFolderList(char *output)
{
DIR *d;
struct dirent *dir;
char sfileList[200][256] = { 0 };
int file_number = 0;
char *testsarr[100] = { "a","b","c" };
//Create JSON
cJSON *s_root = cJSON_CreateObject();
cJSON *s_file_name;
cJSON *file_list = cJSON_CreateArray();
int ret = 0;
if (ensureFolderExists(PYTHON_FOLDER) == -1) {
return -1; // 資料夾不存在
ret = -1; // 資料夾不存在
}
d = opendir(PYTHON_FOLDER);
if (d) {
while ((dir = readdir(d)) != NULL) {
if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, ".."))
{
// do nothing (straight logic)
else {
DIR *folder_dir;
folder_dir = opendir(PYTHON_FOLDER);
if (folder_dir) {
//Create JSON
cJSON *s_root = cJSON_CreateObject();
cJSON *file_list = cJSON_CreateArray();
struct dirent *dir;
//int file_number = 0;
//char sfileList[200][256] = { 0 };
while ((dir = readdir(folder_dir)) != NULL) {
if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, ".."))
{
// do nothing (straight logic)
}
else {
//printf("%s\n", dir->d_name);
//sprintf(&sfileList[file_number], "%s", dir->d_name);
//printf("%s\n", sfileList[file_number]);
//file_number++;
cJSON_AddItemToArray(file_list, cJSON_CreateString(dir->d_name));
}
}
else {
//printf("%s\n", dir->d_name);
//sprintf(&sfileList[file_number], "%s", dir->d_name);
//printf("%s\n", sfileList[file_number]);
//file_number++;
closedir(folder_dir);
s_file_name = cJSON_CreateString(dir->d_name);
//printf("file num: %d \n", file_number);
cJSON_AddItemToArray(file_list, s_file_name);
}
}
//printf("file num: %d \n", file_number);
for (int j = 0; j < file_number; j++)
{
printf("%s\n", sfileList[j]);
}
//for (int j = 0; j < file_number; j++)
//{
//printf("%s\n", sfileList[j]);
//}
cJSON_AddItemToObject(s_root, "file_list", file_list);
cJSON_AddItemToObject(s_root, "file_list", file_list);
char* JsonString = cJSON_Print(s_root);
char* JsonString = cJSON_PrintUnformatted(s_root);
sprintf(output, "%s", JsonString);
sprintf(output, "%s", JsonString);
//printf("jstring = \n%s\n", JsonString);
//printf("jstring = \n%s\n", JsonString);
if (JsonString) {
free(JsonString);
JsonString = NULL;
}
if (JsonString) {
free(JsonString);
JsonString = NULL;
}
if (s_root) {
cJSON_Delete(s_root);
s_root = NULL;
if (s_root) {
cJSON_Delete(s_root);
s_root = NULL;
}
}
closedir(d);
}
return 0;
return ret;
}

16
src/pythonR.h

@ -22,18 +22,30 @@
#define PYTHON_LOG "python_log.txt"
#define PYTHON_CODE_SIZE 1024*20
#define PTYHON_FILE_NAME 1024
#define MAX_BUFFER_LINES 1024
#define DEBUG_COMPORT_PRINT_FGET 1
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;
#ifdef GY_OS_AMBA
extern pthread_mutex_t buffer_mutex;
#endif
void deletePythonFile(char *sINFileName);
void readPythonFile(char *sINFileName, char *sOutput);
void readFolderList(char *output);
//int runPython(char *pythonData, int sock); //2024/03/08
void runPython(char *pythonData); // 2024-10-14
//void runPython(char *pythonData);
//void uploadPython(char *urlData);
const char* uploadPython(char *urlData);
void parseContent(char *recvBuffer);
#endif

4
src/radar_receive.c

@ -105,13 +105,13 @@ void *RADAR_recieve(void *jsonstr) // a113n
if (bind(sockfd, (const struct sockaddr *)&info, sizeof(info)) < 0)
{
perror("error bind failed\n");
printf("error bind failed\n");
close(sockfd);
}
/*
if(listen(sockfd, 512) == -1){
perror("error listen failed\n");
printf("error listen failed\n");
close(sockfd);
}*/

5
src/setting.h

@ -11,12 +11,11 @@
//general difinition
#ifdef GY_OS_AMBA
#define APP_VERSION "2.0.7.60" //跟AMBA的LPKG.json要一致
#define APP_VERSION "2.0.7.69" //跟AMBA的LPKG.json要一致
#else
#define APP_VERSION "1.4.3.2" //跟NOVA的LPKG.json要一致
#define APP_VERSION "1.4.3.4" //跟NOVA的LPKG.json要一致
#endif
#ifdef GY_OS_AMBA
#define MAX_IMG_BUFF_SIZE 1024*1024*20 //max image size is 20MB
//#define MAX_IMG_BUFF_SIZE 8192*13

1373
src/test_nnctrl_live.c

File diff suppressed because it is too large Load Diff

18
src/test_yuv_rgb.c

@ -31,7 +31,7 @@ int readRawYUV(const char *filename, uint32_t width, uint32_t height, uint8_t **
FILE *fp = fopen(filename, "rb");
if(!fp)
{
perror("Error opening yuv image for read");
printf("Error opening yuv image for read\n");
return 1;
}
@ -49,7 +49,7 @@ int readRawYUV(const char *filename, uint32_t width, uint32_t height, uint8_t **
*YUV = malloc(size);
size_t result = fread(*YUV, 1, size, fp);
if (result != size) {
perror("Error reading yuv image");
printf("Error reading yuv image\n");
fclose(fp);
return 3;
}
@ -63,7 +63,7 @@ int saveRawYUV(const char *filename, uint32_t width, uint32_t height, const uint
FILE *fp = fopen(filename, "wb");
if(!fp)
{
perror("Error opening yuv image for write");
printf("Error opening yuv image for write\n");
return 1;
}
@ -112,7 +112,7 @@ int readPPM(const char* filename, uint32_t *width, uint32_t *height, uint8_t **R
FILE *fp = fopen(filename, "rb");
if(!fp)
{
perror("Error opening rgb image for read");
printf("Error opening rgb image for read\n");
return 1;
}
@ -121,7 +121,7 @@ int readPPM(const char* filename, uint32_t *width, uint32_t *height, uint8_t **R
magic[2]='\0';
if(result!=2 || strcmp(magic,"P6")!=0)
{
perror("Error reading rgb image header, or invalid format");
printf("Error reading rgb image header, or invalid format\n");
fclose(fp);
return 3;
}
@ -130,7 +130,7 @@ int readPPM(const char* filename, uint32_t *width, uint32_t *height, uint8_t **R
result = fscanf(fp, " %u %u %u ", width, height, &max);
if(result!=3 || max>255)
{
perror("Error reading rgb image header, or invalid values");
printf("Error reading rgb image header, or invalid values\n");
fclose(fp);
return 3;
}
@ -139,7 +139,7 @@ int readPPM(const char* filename, uint32_t *width, uint32_t *height, uint8_t **R
*RGB = malloc(size);
if(!*RGB)
{
perror("Error allocating rgb image memory");
printf("Error allocating rgb image memory\n");
fclose(fp);
return 2;
}
@ -147,7 +147,7 @@ int readPPM(const char* filename, uint32_t *width, uint32_t *height, uint8_t **R
result = fread(*RGB, 1, size, fp);
if(result != size)
{
perror("Error reading rgb image");
printf("Error reading rgb image\n");
fclose(fp);
return 3;
}
@ -162,7 +162,7 @@ int savePPM(const char* filename, uint32_t width, uint32_t height, const uint8_t
FILE *fp = fopen(filename, "wb");
if(!fp)
{
perror("Error opening rgb image for write");
printf("Error opening rgb image for write\n");
return 1;
}

10
src/tof.c

@ -626,13 +626,13 @@ void *thread_getTofData(void *ptr) {
// 對映記憶體共享區
tof_raw_arr = Correspond_Memory(tof_depth_shmid);
if (tof_raw_arr == (void *)-1) {
perror(" [tof.c] Mapping RAW shared memory failed !\n");
printf(" [tof.c] Mapping RAW shared memory failed !\n");
break;
}
else {
// tof_yuv_arr = Correspond_Memory_YUV(tof_yuv_shmid);
// if (tof_yuv_arr == (void *)-1) {
// perror(" [tof.c] Mapping YUV shared memory failed !\n");
// printf(" [tof.c] Mapping YUV shared memory failed !\n");
// }
// 先檢查相同的 frame 之前有沒有進來過
@ -813,7 +813,7 @@ void Receive_Data_ShareMemory(frameimage_yuv *arr){
// 釋放記憶體共享區(for depth values)
char Free_ShareMemory(frameimage *arr){
if (shmdt((void *) arr) == -1) {
perror(" [tof.c] Free depth shared memory failed !\n");
printf(" [tof.c] Free depth shared memory failed !\n");
return -1;
}
return 0;
@ -821,7 +821,7 @@ char Free_ShareMemory(frameimage *arr){
// 釋放記憶體共享區(for YUV values)
char Free_ShareMemory_YUV(frameimage_yuv *arr){
if (shmdt((void *) arr) == -1) {
perror(" [tof.c] Free YUV shared memory failed!\n");
printf(" [tof.c] Free YUV shared memory failed!\n");
return -1;
}
return 0;
@ -829,7 +829,7 @@ char Free_ShareMemory_YUV(frameimage_yuv *arr){
// 移除記憶體共享區
char Delete_ShareMemory(int shmid){
if (shmctl(shmid, IPC_RMID, 0) == -1) {
perror(" [tof.c] Remove shared memory failed!\n");
printf(" [tof.c] Remove shared memory failed!\n");
return -1;
}
return 0;

62
src/utility.cpp

@ -173,34 +173,46 @@ char* ReadAllBytes(const char *fileName) //You must free the result
float detection_overlap_ratio(detection_pos* det1, detection_pos* det2)
{
if (det1->left_x > det2->left_x + det2->width) { return 0.0; }
if (det1->top_y > det2->top_y + det2->height) { return 0.0; }
if (det1->left_x + det1->width < det2->left_x) { return 0.0; }
if (det1->top_y + det1->height < det2->top_y) { return 0.0; }
float colInt = abs(std::min(det1->left_x + det1->width, det2->left_x + det2->width) - std::max(det1->left_x, det2->left_x));
float rowInt = abs(std::min(det1->top_y + det1->height, det2->top_y + det2->height) - std::max(det1->top_y, det2->top_y));
float overlapArea = colInt * rowInt; //¬Û¥æ³B­±¿n
float area1 = det1->width * det1->height;
float area2 = det2->width * det2->height;
float smallerArea = (area1 > area2) ? area2 : area1;
return overlapArea / smallerArea; //¬Û¥æ³B­±¿n¥e¸û¤pª«¥ó¤ñ¨Ò
//return overlapArea / (area1 + area2 - overlapArea); //¬Û¥æ³B­±¿n¤ñ¨Ò¥e¤j¤pª«¥ó¥[Á`¤ñ¨Ò
// 計算重疊區域的寬度和高度
float colInt = std::min(det1->left_x + det1->width, det2->left_x + det2->width) - std::max(det1->left_x, det2->left_x);
float rowInt = std::min(det1->top_y + det1->height, det2->top_y + det2->height) - std::max(det1->top_y, det2->top_y);
// 檢查是否完全不重疊
if (colInt <= 0 || rowInt <= 0) { return 0.0; }
// 計算重疊區域面積
float overlapArea = colInt * rowInt;
// 計算兩個偵測框的面積
float area1 = det1->width * det1->height;
float area2 = det2->width * det2->height;
// 使用較小的面積作為基準,計算重疊比例
float smallerArea = (area1 < area2) ? area1 : area2;
return overlapArea / smallerArea;
}
float detection_overlap_ratio_union(detection_pos* det1, detection_pos* det2)
{
if (det1->left_x > det2->left_x + det2->width) { return 0.0; }
if (det1->top_y > det2->top_y + det2->height) { return 0.0; }
if (det1->left_x + det1->width < det2->left_x) { return 0.0; }
if (det1->top_y + det1->height < det2->top_y) { return 0.0; }
float colInt = abs(std::min(det1->left_x + det1->width, det2->left_x + det2->width) - std::max(det1->left_x, det2->left_x));
float rowInt = abs(std::min(det1->top_y + det1->height, det2->top_y + det2->height) - std::max(det1->top_y, det2->top_y));
float overlapArea = colInt * rowInt; //¬Û¥æ³B­±¿n
float area1 = det1->width * det1->height;
float area2 = det2->width * det2->height;
//float smallerArea = (area1 > area2) ? area2 : area1;
//return overlapArea / smallerArea; //¬Û¥æ³B­±¿n¥e¸û¤pª«¥ó¤ñ¨Ò
return overlapArea / (area1 + area2 - overlapArea); //¬Û¥æ³B­±¿n¤ñ¨Ò¥e¤j¤pª«¥ó¥[Á`¤ñ¨Ò
// 檢查是否完全不重疊
if (det1->left_x >= det2->left_x + det2->width) { return 0.0; }
if (det1->top_y >= det2->top_y + det2->height) { return 0.0; }
if (det1->left_x + det1->width <= det2->left_x) { return 0.0; }
if (det1->top_y + det1->height <= det2->top_y) { return 0.0; }
// 計算重疊區域的寬度和高度
float colInt = std::min(det1->left_x + det1->width, det2->left_x + det2->width) - std::max(det1->left_x, det2->left_x);
float rowInt = std::min(det1->top_y + det1->height, det2->top_y + det2->height) - std::max(det1->top_y, det2->top_y);
// 計算重疊區域面積
float overlapArea = colInt * rowInt;
// 計算兩個偵測框的面積
float area1 = det1->width * det1->height;
float area2 = det2->width * det2->height;
// 計算重疊比例:重疊面積占聯集面積的比例
return overlapArea / (area1 + area2 - overlapArea);
}
void PrintMACaddress(char* MACAddress, unsigned char MACData[])
@ -2037,7 +2049,7 @@ void verify_directory_exists(const char* path) {
if (stat(directory_path, &st) == -1) {
if (mkdir(directory_path, 0700) == -1) {
perror("mkdir error");
printf("mkdir error\n");
}
}
}

6
src/utility.h

@ -772,6 +772,12 @@ extern "C" {
void set_record_process_note(char *process_note);
void set_logo_to_plate_or_vehicle(detection_pos* PosInfo, int total_element_size);
void loadCounters();
void saveCounters();
#ifdef GY_OS_AMBA
void *start_run_python_thread(void* pythonpath);
#endif
#ifdef GY_OS_V_SERIES
#else

6
src/utils.c

@ -360,7 +360,7 @@ int read_int(int fd)
void write_int(int fd, int n)
{
int next = write(fd, &n, sizeof(int));
if(next <= 0) error("read failed");
if(next <= 0) printf("read failed\n");
}
int read_all_fail(int fd, char *buffer, size_t bytes)
@ -390,7 +390,7 @@ void read_all(int fd, char *buffer, size_t bytes)
size_t n = 0;
while(n < bytes){
int next = read(fd, buffer + n, bytes-n);
if(next <= 0) error("read failed");
if(next <= 0) printf("read failed\n");
n += next;
}
}
@ -400,7 +400,7 @@ void write_all(int fd, char *buffer, size_t bytes)
size_t n = 0;
while(n < bytes){
size_t next = write(fd, buffer + n, bytes-n);
if(next <= 0) error("write failed");
if(next <= 0) printf("write failed\n");
n += next;
}
}

Loading…
Cancel
Save