@@ -2399,109 +2399,174 @@ void HandleWebViewMsg(CString msg ,CString &outmsg, int msg_source = 0)
23992399 break ;
24002400 case LOGGING_DATA:
24012401 {
2402+ // Local flag to enable/disable logging - set to false to disable
2403+ bool enable_logging_data_log = true ;
2404+
24022405 Json::Value tempjson;
24032406 tempjson[" action" ] = " LOGGING_DATA_RES" ;
24042407
24052408 Post_ReadAllTrendlog_Message ();
24062409
24072410 // 发送消息加载所有panel 的 in out var 数据;
2408- int p_i = 0 ;
2409- for (int i = 0 ; i < g_bacnet_panel_info.size (); i ++)
2411+ int device_count = 0 ;
2412+ for (int panel_idx = 0 ; panel_idx < g_bacnet_panel_info.size (); panel_idx ++)
24102413 {
24112414#if 1
2412- int npanel_id = g_bacnet_panel_info.at (i ).panel_number ;
2415+ int npanel_id = g_bacnet_panel_info.at (panel_idx ).panel_number ;
24132416
2414-
2415- if (g_bacnet_panel_info.at (i).object_instance != g_logging_time[npanel_id].bac_instance )
2417+ if (g_bacnet_panel_info.at (panel_idx).object_instance != g_logging_time[npanel_id].bac_instance )
24162418 continue ;
2417- if (g_bacnet_panel_info.at (i ).nseiral_number != g_logging_time[npanel_id].sn )
2419+ if (g_bacnet_panel_info.at (panel_idx ).nseiral_number != g_logging_time[npanel_id].sn )
24182420 continue ;
2419- if (g_bacnet_panel_info.at (i ).panel_number != g_logging_time[npanel_id].n_panel_number )
2421+ if (g_bacnet_panel_info.at (panel_idx ).panel_number != g_logging_time[npanel_id].n_panel_number )
24202422 continue ;
24212423 if (npanel_id != g_logging_time[npanel_id].n_panel_number )
24222424 continue ;
24232425 if (g_logging_time[npanel_id].basic_setting_status != 1 )
24242426 continue ;
2425-
2427+
2428+ // Device passed validation - add device main info
24262429 g_Device_Basic_Setting[npanel_id].reg .ip_addr ;
24272430 char ipStr[16 ]; // 用于存储转换后的IP字符串
24282431 unsigned char * ipAddr = g_Device_Basic_Setting[npanel_id].reg .ip_addr ;
24292432 // 使用 sprintf 将 IP 地址转换为字符串
24302433 sprintf (ipStr, " %d.%d.%d.%d" , ipAddr[0 ], ipAddr[1 ], ipAddr[2 ], ipAddr[3 ]);
24312434
2432- tempjson[" panel_id" ] = npanel_id;
2433- tempjson[" panel_name" ] = (char *)g_Device_Basic_Setting[npanel_id].reg .panel_name ;
2434- tempjson[" panel_serial_number" ] = g_Device_Basic_Setting[npanel_id].reg .n_serial_number ;
2435- tempjson[" panel_ipaddress" ] = ipStr;
2436-
2437- tempjson[" input_logging_time" ] = g_logging_time[npanel_id].input_log_time ;
2438- tempjson[" output_logging_time" ] = g_logging_time[npanel_id].output_log_time ;
2439- tempjson[" variable_logging_time" ] = g_logging_time[npanel_id].variable_log_time ;
2440- for (int i = 0 ; i < BAC_INPUT_ITEM_COUNT; i++) {
2441- tempjson[" data" ][p_i][" pid" ] = npanel_id;
2442- tempjson[" data" ][p_i][" type" ] = " INPUT" ;
2443- tempjson[" data" ][p_i][" index" ] = i;
2444- tempjson[" data" ][p_i][" id" ] = " IN" + to_string (i + 1 );
2445- tempjson[" data" ][p_i][" command" ] = to_string (npanel_id) + " IN" + to_string (i + 1 );
2446- tempjson[" data" ][p_i][" description" ] = (char *)g_Input_data[npanel_id].at (i).description ;
2447- tempjson[" data" ][p_i][" label" ] = (char *)g_Input_data[npanel_id].at (i).label ;
2448- tempjson[" data" ][p_i][" unit" ] = g_Input_data[npanel_id].at (i).range ;
2449- tempjson[" data" ][p_i][" auto_manual" ] = g_Input_data[npanel_id].at (i).auto_manual ;
2450- tempjson[" data" ][p_i][" value" ] = g_Input_data[npanel_id].at (i).value ;
2451- tempjson[" data" ][p_i][" filter" ] = g_Input_data[npanel_id].at (i).filter ;
2452- tempjson[" data" ][p_i][" control" ] = g_Input_data[npanel_id].at (i).control ;
2453- tempjson[" data" ][p_i][" digital_analog" ] = g_Input_data[npanel_id].at (i).digital_analog ;
2454- tempjson[" data" ][p_i][" range" ] = g_Input_data[npanel_id].at (i).range ;
2455- tempjson[" data" ][p_i][" calibration_sign" ] = g_Input_data[npanel_id].at (i).calibration_sign ;
2456- tempjson[" data" ][p_i][" calibration_h" ] = g_Input_data[npanel_id].at (i).calibration_h ;
2457- tempjson[" data" ][p_i][" calibration_l" ] = g_Input_data[npanel_id].at (i).calibration_l ;
2458- tempjson[" data" ][p_i][" decom" ] = g_Input_data[npanel_id].at (i).decom ; // for input 0 "Normal" 1"Open" 2 "Shorted"
2459- p_i++;
2460- }
2461-
2462- for (int i = 0 ; i < BAC_OUTPUT_ITEM_COUNT; i++) {
2463- tempjson[" data" ][p_i][" pid" ] = npanel_id;
2464- tempjson[" data" ][p_i][" type" ] = " OUTPUT" ;
2465- tempjson[" data" ][p_i][" index" ] = i;
2466- tempjson[" data" ][p_i][" id" ] = " OUT" + to_string (i + 1 );
2467- tempjson[" data" ][p_i][" command" ] = to_string (npanel_id) + " OUT" + to_string (i + 1 );
2468- tempjson[" data" ][p_i][" description" ] = (char *)g_Output_data[npanel_id].at (i).description ;
2469- tempjson[" data" ][p_i][" label" ] = (char *)g_Output_data[npanel_id].at (i).label ;
2470- tempjson[" data" ][p_i][" auto_manual" ] = g_Output_data[npanel_id].at (i).auto_manual ;
2471- tempjson[" data" ][p_i][" value" ] = g_Output_data[npanel_id].at (i).value ;
2472- tempjson[" data" ][p_i][" low_voltage" ] = g_Output_data[npanel_id].at (i).low_voltage ;
2473- tempjson[" data" ][p_i][" high_voltage" ] = g_Output_data[npanel_id].at (i).high_voltage ;
2474- tempjson[" data" ][p_i][" range" ] = g_Output_data[npanel_id].at (i).range ;
2475- tempjson[" data" ][p_i][" control" ] = g_Output_data[npanel_id].at (i).control ;
2476- tempjson[" data" ][p_i][" digital_analog" ] = g_Output_data[npanel_id].at (i).digital_analog ;
2477- tempjson[" data" ][p_i][" hw_switch_status" ] = g_Output_data[npanel_id].at (i).hw_switch_status ;
2478- tempjson[" data" ][p_i][" decom" ] = g_Output_data[npanel_id].at (i).decom ; // for output 0 "Normal" 1"Alarm"
2479- p_i++;
2480- }
2481-
2482-
2483- for (int i = 0 ; i < BAC_VARIABLE_ITEM_COUNT; i++) {
2484- tempjson[" data" ][p_i][" pid" ] = npanel_id;
2485- tempjson[" data" ][p_i][" type" ] = " VARIABLE" ;
2486- tempjson[" data" ][p_i][" index" ] = i;
2487- tempjson[" data" ][p_i][" id" ] = " VAR" + to_string (i + 1 );
2488- tempjson[" data" ][p_i][" command" ] = to_string (npanel_id) + " VAR" + to_string (i + 1 );
2489- tempjson[" data" ][p_i][" description" ] = (char *)g_Variable_data[npanel_id].at (i).description ;
2490- tempjson[" data" ][p_i][" label" ] = (char *)g_Variable_data[npanel_id].at (i).label ;
2491- tempjson[" data" ][p_i][" auto_manual" ] = g_Variable_data[npanel_id].at (i).auto_manual ;
2492- tempjson[" data" ][p_i][" value" ] = g_Variable_data[npanel_id].at (i).value ;
2493- tempjson[" data" ][p_i][" range" ] = g_Variable_data[npanel_id].at (i).range ;
2494- tempjson[" data" ][p_i][" control" ] = g_Variable_data[npanel_id].at (i).control ;
2495- tempjson[" data" ][p_i][" digital_analog" ] = g_Variable_data[npanel_id].at (i).digital_analog ;
2496- tempjson[" data" ][p_i][" unused" ] = g_Variable_data[npanel_id].at (i).unused ;
2497- p_i++;
2498- }
2499- const std::string output = Json::writeString (builder, tempjson);
2500- CString temp_cs (output.c_str ());
2501- outmsg = temp_cs;
2435+ // Add device main info to data array
2436+ tempjson[" data" ][device_count][" panel_id" ] = npanel_id;
2437+ tempjson[" data" ][device_count][" panel_name" ] = (char *)g_Device_Basic_Setting[npanel_id].reg .panel_name ;
2438+ tempjson[" data" ][device_count][" panel_serial_number" ] = g_Device_Basic_Setting[npanel_id].reg .n_serial_number ;
2439+ tempjson[" data" ][device_count][" panel_ipaddress" ] = ipStr;
2440+ tempjson[" data" ][device_count][" input_logging_time" ] = g_logging_time[npanel_id].input_log_time ;
2441+ tempjson[" data" ][device_count][" output_logging_time" ] = g_logging_time[npanel_id].output_log_time ;
2442+ tempjson[" data" ][device_count][" variable_logging_time" ] = g_logging_time[npanel_id].variable_log_time ;
2443+
2444+ // Add all INPUT points for this device in device_data array
2445+ int point_idx = 0 ;
2446+ for (int input_idx = 0 ; input_idx < BAC_INPUT_ITEM_COUNT; input_idx++) {
2447+ tempjson[" data" ][device_count][" device_data" ][point_idx][" pid" ] = npanel_id;
2448+ tempjson[" data" ][device_count][" device_data" ][point_idx][" type" ] = " INPUT" ;
2449+ tempjson[" data" ][device_count][" device_data" ][point_idx][" index" ] = input_idx;
2450+ tempjson[" data" ][device_count][" device_data" ][point_idx][" id" ] = " IN" + to_string (input_idx + 1 );
2451+ tempjson[" data" ][device_count][" device_data" ][point_idx][" command" ] = to_string (npanel_id) + " IN" + to_string (input_idx + 1 );
2452+ tempjson[" data" ][device_count][" device_data" ][point_idx][" description" ] = (char *)g_Input_data[npanel_id].at (input_idx).description ;
2453+ tempjson[" data" ][device_count][" device_data" ][point_idx][" label" ] = (char *)g_Input_data[npanel_id].at (input_idx).label ;
2454+ tempjson[" data" ][device_count][" device_data" ][point_idx][" unit" ] = g_Input_data[npanel_id].at (input_idx).range ;
2455+ tempjson[" data" ][device_count][" device_data" ][point_idx][" auto_manual" ] = g_Input_data[npanel_id].at (input_idx).auto_manual ;
2456+ tempjson[" data" ][device_count][" device_data" ][point_idx][" value" ] = g_Input_data[npanel_id].at (input_idx).value ;
2457+ tempjson[" data" ][device_count][" device_data" ][point_idx][" filter" ] = g_Input_data[npanel_id].at (input_idx).filter ;
2458+ tempjson[" data" ][device_count][" device_data" ][point_idx][" control" ] = g_Input_data[npanel_id].at (input_idx).control ;
2459+ tempjson[" data" ][device_count][" device_data" ][point_idx][" digital_analog" ] = g_Input_data[npanel_id].at (input_idx).digital_analog ;
2460+ tempjson[" data" ][device_count][" device_data" ][point_idx][" range" ] = g_Input_data[npanel_id].at (input_idx).range ;
2461+ tempjson[" data" ][device_count][" device_data" ][point_idx][" calibration_sign" ] = g_Input_data[npanel_id].at (input_idx).calibration_sign ;
2462+ tempjson[" data" ][device_count][" device_data" ][point_idx][" calibration_h" ] = g_Input_data[npanel_id].at (input_idx).calibration_h ;
2463+ tempjson[" data" ][device_count][" device_data" ][point_idx][" calibration_l" ] = g_Input_data[npanel_id].at (input_idx).calibration_l ;
2464+ tempjson[" data" ][device_count][" device_data" ][point_idx][" decom" ] = g_Input_data[npanel_id].at (input_idx).decom ; // for input 0 "Normal" 1"Open" 2 "Shorted"
2465+ point_idx++;
2466+ }
2467+
2468+ // Add all OUTPUT points for this device in device_data array
2469+ for (int output_idx = 0 ; output_idx < BAC_OUTPUT_ITEM_COUNT; output_idx++) {
2470+ tempjson[" data" ][device_count][" device_data" ][point_idx][" pid" ] = npanel_id;
2471+ tempjson[" data" ][device_count][" device_data" ][point_idx][" type" ] = " OUTPUT" ;
2472+ tempjson[" data" ][device_count][" device_data" ][point_idx][" index" ] = output_idx;
2473+ tempjson[" data" ][device_count][" device_data" ][point_idx][" id" ] = " OUT" + to_string (output_idx + 1 );
2474+ tempjson[" data" ][device_count][" device_data" ][point_idx][" command" ] = to_string (npanel_id) + " OUT" + to_string (output_idx + 1 );
2475+ tempjson[" data" ][device_count][" device_data" ][point_idx][" description" ] = (char *)g_Output_data[npanel_id].at (output_idx).description ;
2476+ tempjson[" data" ][device_count][" device_data" ][point_idx][" label" ] = (char *)g_Output_data[npanel_id].at (output_idx).label ;
2477+ tempjson[" data" ][device_count][" device_data" ][point_idx][" auto_manual" ] = g_Output_data[npanel_id].at (output_idx).auto_manual ;
2478+ tempjson[" data" ][device_count][" device_data" ][point_idx][" value" ] = g_Output_data[npanel_id].at (output_idx).value ;
2479+ tempjson[" data" ][device_count][" device_data" ][point_idx][" low_voltage" ] = g_Output_data[npanel_id].at (output_idx).low_voltage ;
2480+ tempjson[" data" ][device_count][" device_data" ][point_idx][" high_voltage" ] = g_Output_data[npanel_id].at (output_idx).high_voltage ;
2481+ tempjson[" data" ][device_count][" device_data" ][point_idx][" range" ] = g_Output_data[npanel_id].at (output_idx).range ;
2482+ tempjson[" data" ][device_count][" device_data" ][point_idx][" control" ] = g_Output_data[npanel_id].at (output_idx).control ;
2483+ tempjson[" data" ][device_count][" device_data" ][point_idx][" digital_analog" ] = g_Output_data[npanel_id].at (output_idx).digital_analog ;
2484+ tempjson[" data" ][device_count][" device_data" ][point_idx][" hw_switch_status" ] = g_Output_data[npanel_id].at (output_idx).hw_switch_status ;
2485+ tempjson[" data" ][device_count][" device_data" ][point_idx][" decom" ] = g_Output_data[npanel_id].at (output_idx).decom ; // for output 0 "Normal" 1"Alarm"
2486+ point_idx++;
2487+ }
2488+
2489+ // Add all VARIABLE points for this device in device_data array
2490+ for (int var_idx = 0 ; var_idx < BAC_VARIABLE_ITEM_COUNT; var_idx++) {
2491+ tempjson[" data" ][device_count][" device_data" ][point_idx][" pid" ] = npanel_id;
2492+ tempjson[" data" ][device_count][" device_data" ][point_idx][" type" ] = " VARIABLE" ;
2493+ tempjson[" data" ][device_count][" device_data" ][point_idx][" index" ] = var_idx;
2494+ tempjson[" data" ][device_count][" device_data" ][point_idx][" id" ] = " VAR" + to_string (var_idx + 1 );
2495+ tempjson[" data" ][device_count][" device_data" ][point_idx][" command" ] = to_string (npanel_id) + " VAR" + to_string (var_idx + 1 );
2496+ tempjson[" data" ][device_count][" device_data" ][point_idx][" description" ] = (char *)g_Variable_data[npanel_id].at (var_idx).description ;
2497+ tempjson[" data" ][device_count][" device_data" ][point_idx][" label" ] = (char *)g_Variable_data[npanel_id].at (var_idx).label ;
2498+ tempjson[" data" ][device_count][" device_data" ][point_idx][" auto_manual" ] = g_Variable_data[npanel_id].at (var_idx).auto_manual ;
2499+ tempjson[" data" ][device_count][" device_data" ][point_idx][" value" ] = g_Variable_data[npanel_id].at (var_idx).value ;
2500+ tempjson[" data" ][device_count][" device_data" ][point_idx][" range" ] = g_Variable_data[npanel_id].at (var_idx).range ;
2501+ tempjson[" data" ][device_count][" device_data" ][point_idx][" control" ] = g_Variable_data[npanel_id].at (var_idx).control ;
2502+ tempjson[" data" ][device_count][" device_data" ][point_idx][" digital_analog" ] = g_Variable_data[npanel_id].at (var_idx).digital_analog ;
2503+ tempjson[" data" ][device_count][" device_data" ][point_idx][" unused" ] = g_Variable_data[npanel_id].at (var_idx).unused ;
2504+ point_idx++;
2505+ }
2506+ device_count++;
25022507#endif
25032508 }
25042509
2510+ // Generate final JSON response once for all devices
2511+ const std::string output = Json::writeString (builder, tempjson);
2512+ CString temp_cs (output.c_str ());
2513+ outmsg = temp_cs;
2514+
2515+ // Final log message - write to T3WebLog\YYYY-MM\ if logging enabled
2516+ if (enable_logging_data_log) {
2517+ try {
2518+ SYSTEMTIME st;
2519+ GetSystemTime (&st);
2520+
2521+ // Create directory path based on current date
2522+ CString logDir;
2523+ logDir.Format (_T (" T3WebLog\\ %04d-%02d" ), st.wYear , st.wMonth );
2524+ CreateDirectory (logDir, NULL );
2525+
2526+ // Calculate 4-hour bucket (00-03, 04-07, 08-11, 12-15, 16-19, 20-23)
2527+ int start_hour = (st.wHour / 4 ) * 4 ;
2528+ int end_hour = start_hour + 3 ;
2529+
2530+ // Create log file with new naming convention: t3_cppmsg_logging_data_MMDD_HHHH.txt
2531+ CString logFile;
2532+ logFile.Format (_T (" %s\\ T3_CppMsg_LOGGING_DATA_%02d%02d_%02d%02d.txt" ),
2533+ logDir, st.wMonth , st.wDay , start_hour, end_hour);
2534+
2535+ CStdioFile file;
2536+ // Use append mode to add multiple calls to same 4-hour period file
2537+ if (file.Open (logFile, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate | CFile::typeText)) {
2538+ // Move to end of file for appending
2539+ file.SeekToEnd ();
2540+
2541+ // Log entry separator and timestamp
2542+ CString logContent;
2543+ logContent.Format (_T (" === LOGGING_DATA C++ FFI Call [%04d-%02d-%02d %02d:%02d:%02d] ===\n " ),
2544+ st.wYear , st.wMonth , st.wDay , st.wHour , st.wMinute , st.wSecond );
2545+ file.WriteString (logContent);
2546+
2547+ logContent.Format (_T (" Total panels found: %zu\n " ), g_bacnet_panel_info.size ());
2548+ file.WriteString (logContent);
2549+
2550+ logContent.Format (_T (" JSON response size: %d characters\n " ), outmsg.GetLength ());
2551+ file.WriteString (logContent);
2552+
2553+ logContent.Format (_T (" Data items processed: %d\n " ), device_count);
2554+ file.WriteString (logContent);
2555+
2556+ // Log full JSON response for complete inspection
2557+ file.WriteString (_T (" === Complete JSON Response ===\n " ));
2558+ file.WriteString (outmsg);
2559+ file.WriteString (_T (" \n " ));
2560+
2561+ file.WriteString (_T (" === End of Entry ===\r\n " ));
2562+ file.Close ();
2563+ }
2564+ }
2565+ catch (...) {
2566+ // Silently ignore logging errors to prevent disrupting main functionality
2567+ // Logging failure should not affect the FFI response
2568+ }
2569+ }
25052570 }
25062571 break ;
25072572 default :
0 commit comments