/* * logs_hmi.c * * Created on: 28 авг. 2024 г. * Author: Evgeniy_Sokolov */ #include "log_to_memory.h" #include #include #include #include #include "control_station.h" #include "global_time.h" #include "modbus_table_v2.h" #include "RS_modbus_pult.h" #include "DSP281x_Device.h" #include "MemoryFunctions.h" #include "RS_modbus_svu.h" #include "log_params.h" #include "logs_hmi.h" #include "edrk_main.h" #pragma DATA_SECTION(log_to_HMI, ".logs"); t_Logs_with_modbus log_to_HMI = LOGS_WITH_MODBUS_DEFAULTS; #define COUNT_FAST_DATA 300//150 #define COUNT_SLOW_DATA 300 /////////////////////////////////////////////////// /// /////////////////////////////////////////////////// #define MAX_SIZE_LOGS_HMI_FULL (END_ADDRESS_LOGS - START_ADDRESS_LOG + 1) //262144 // 0x80000/2 #define MAX_SIZE_LOGS_HMI_SMALL 10000 #define START_ARRAY_LOG_SEND 300 #define END_ARRAY_LOG_SEND 899 #define SIZE_ARRAY_LOG_SEND (END_ARRAY_LOG_SEND - START_ARRAY_LOG_SEND + 1) #define SIZE_BUF_WRITE_LOGS_TO_MODBUS16_REMOUTE 120 int writeLogsArray(int flag_next) { int succed = 0; static unsigned int old_time = 0; static int count_write_to_modbus = 0; static int cur_position_buf_modbus16 = 0; if (!rs_b.flag_LEADING) { ModbusRTUsetDataArrays(modbus_table_analog_in, modbus_table_analog_out); if (control_station.flag_waiting_answer[CONTROL_STATION_INGETEAM_PULT_RS485] == 0) { if (log_to_HMI.flag_start_log_array_sent) { cur_position_buf_modbus16 = START_ARRAY_LOG_SEND; log_to_HMI.flag_log_array_sended = 0; } else { if (flag_next) cur_position_buf_modbus16 = cur_position_buf_modbus16 + SIZE_BUF_WRITE_LOGS_TO_MODBUS16_REMOUTE; } log_to_HMI.flag_start_log_array_sent = 0; } if (cur_position_buf_modbus16 >= END_ARRAY_LOG_SEND) { // все передали уже? cur_position_buf_modbus16 = START_ARRAY_LOG_SEND; log_to_HMI.flag_log_array_sended = 1; // log_to_HMI.flag_log_array_sent_process = 0; // succed = 1; return succed; } // //Дырка в обмене. Пропускаем. // if ((cur_position_buf_modbus16 > ADRESS_END_FIRST_BLOCK) && // (cur_position_buf_modbus16 < ADRESS_START_PROTECTION_LEVELS)) { // cur_position_buf_modbus16 = ADRESS_START_PROTECTION_LEVELS; // } if ((cur_position_buf_modbus16 + SIZE_BUF_WRITE_LOGS_TO_MODBUS16_REMOUTE) > (END_ARRAY_LOG_SEND+1)) count_write_to_modbus = END_ARRAY_LOG_SEND - cur_position_buf_modbus16 + 1; else count_write_to_modbus = SIZE_BUF_WRITE_LOGS_TO_MODBUS16_REMOUTE; log_to_HMI.n_log_array_sended = (cur_position_buf_modbus16 - START_ARRAY_LOG_SEND)/100 + 1; log_to_HMI.flag_log_array_sent_process++;// = 1; ModbusRTUsend16(&rs_b, 2, ADR_MODBUS_TABLE_REMOUTE + cur_position_buf_modbus16, count_write_to_modbus); // control_station.count_error_modbus_16[CONTROL_STATION_INGETEAM_PULT_RS485]++; // control_station.flag_message_sent[CONTROL_STATION_INGETEAM_PULT_RS485] = 1; succed = count_write_to_modbus; } return succed; /* unsigned long i = 0; int succed = 0; // int *p_log_data = (int*)LOG_START_ADRES; ModbusRTUsetDataArrays(modbus_table_analog_in, modbus_table_analog_out); if (!rs_b.flag_LEADING) { ModbusRTUsend16(&rs_b, 2, log_to_HMI.current_address, log_to_HMI.count_write_to_modbus + 1); if (err_send_log_16 == 0) { //prev message without errors log_to_HMI.current_address = log_to_HMI.current_address + SIZE_BUF_WRITE_LOG_TO_MODBUS16; } if (log_to_HMI.current_address > END_ARRAY_LOG_SEND) { log_to_HMI.current_address = START_ARRAY_LOG_SEND; // log_to_HMI.flag_end_of_log = 1; log_to_HMI.flag_log_array_sent = 1; } if ((log_to_HMI.current_address + SIZE_BUF_WRITE_LOG_TO_MODBUS16) > END_ARRAY_LOG_SEND) { log_to_HMI.count_write_to_modbus = END_ARRAY_LOG_SEND - log_to_HMI.current_address; } else { log_to_HMI.count_write_to_modbus = SIZE_BUF_WRITE_LOG_TO_MODBUS16; } err_send_log_16 += 1; succed = 1; } return succed; */ } void prepareWriteLogsArray(void) { // log_to_HMI.start_log_address = logpar.addres_mem - logpar.count_log_params_fast_log * SIZE_ARRAY_LOG_SEND; // log_to_HMI.start_log_address = log_params.addres_mem - log_params.BlockSizeErr * SIZE_ARRAY_LOG_SEND; if (log_to_HMI.send_log == 1) log_to_HMI.start_log_address = log_params.start_address_log_slow; if (log_to_HMI.send_log == 2) log_to_HMI.start_log_address = log_params.start_address_log; if (log_to_HMI.send_log == 3) log_to_HMI.start_log_address = 0;//log_params.start_address_log; // - log_to_HMI.max_size_logs_hmi; // if (log_to_HMI.start_log_address < log_params.start_address_log) { // log_to_HMI.start_log_address = log_params.end_address_log - (log_params.start_address_log - log_to_HMI.start_log_address); // } // log_to_HMI.log_address_step = SIZE_ARRAY_LOG_SEND;//log_params.BlockSizeErr; } int fillAnalogDataArrayForLogSend(void) { int i, k, n;// = START_ARRAY_LOG_SEND; int c_data = 0, lb = 0, type_log; volatile unsigned long local_pos = 0; // unsigned long current_address = log_to_HMI.start_log_address;// + num_of_log; k = 0; n = 0; for (i = START_ARRAY_LOG_SEND; i <= END_ARRAY_LOG_SEND; i++) { // if (log_to_HMI.count_write_to_modbus > log_to_HMI.max_size_logs_hmi) // break; n = log_to_HMI.count_write_to_modbus/SIZE_BUF_WRITE_LOGS_TO_MODBUS16_REMOUTE; if (k>=SIZE_BUF_WRITE_LOGS_TO_MODBUS16_REMOUTE) k = 0; if (k==0) modbus_table_analog_out[i].all = LOWORD(log_to_HMI.count_write_to_modbus); else if (k==1) modbus_table_analog_out[i].all = LOWORD(global_time.miliseconds); else if (k==2) modbus_table_analog_out[i].all = HIWORD(log_to_HMI.start_log_address); else if (k==3) modbus_table_analog_out[i].all = LOWORD(log_to_HMI.start_log_address); else if (k==SIZE_BUF_WRITE_LOGS_TO_MODBUS16_REMOUTE-1) modbus_table_analog_out[i].all = log_to_HMI.tick_step; else { if (log_to_HMI.count_write_to_modbus > log_to_HMI.max_size_logs_hmi) modbus_table_analog_out[i].all = 0; else { // modbus_table_analog_out[i].all = LOWORD(log_to_HMI.start_log_address); // это для теста if (log_to_HMI.send_log==3) { if (log_to_HMI.start_log_address>=(COUNT_FAST_DATA*log_params.BlockSizeErr) ) { local_pos = log_to_HMI.max_size_logs_hmi - log_to_HMI.start_log_address;// - (COUNT_FAST_DATA*log_params.BlockSizeErr); type_log = SLOW_LOG; } else { local_pos = log_to_HMI.max_size_logs_hmi - log_to_HMI.start_log_address - (COUNT_SLOW_DATA*log_params.BlockSizeErr); type_log = FAST_LOG; } modbus_table_analog_out[i].all = alarm_log_get_data(local_pos, type_log); } else modbus_table_analog_out[i].all = ReadMemory(log_to_HMI.start_log_address); log_to_HMI.start_log_address += 1;//log_to_HMI.log_address_step; log_to_HMI.count_write_to_modbus += 1; } } // modbus_table_analog_out[i+1].all = HIWORD(log_to_HMI.start_log_address);//log_to_HMI.count_write_to_modbus;//ReadMemory(log_to_HMI.start_log_address); // modbus_table_analog_out[i].all = LOWORD(global_time.miliseconds);//ReadMemory(log_to_HMI.start_log_address); // modbus_table_analog_out[i+1].all = HIWORD(global_time.miliseconds);//log_to_HMI.count_write_to_modbus;//ReadMemory(log_to_HMI.start_log_address); // if (k>1 && k 0) { *(p_memory++) = value; value += 1; // if (log_size % 8 == 0) { // value += 1; // } } } int alarm_log_get_data(unsigned long pos, int type_log) { //unsigned int i,k; static volatile unsigned long cur_adr_log, end_log, start_log, addres_mem, temp_length, delta_adr;//clog //real_length //int *adr_finish_temp, *adr_current; // real_length = al->real_points * al->oscills; // real_adr = al->start_adr_real_logs; if (type_log==FAST_LOG) { temp_length = log_params.BlockSizeErr; cur_adr_log = log_params.addres_mem; end_log = log_params.end_address_log; start_log = log_params.start_address_log; } if (type_log==SLOW_LOG) { temp_length = log_params.BlockSizeSlow; cur_adr_log = log_params.addres_mem_slow; end_log = log_params.end_address_log_slow; start_log = log_params.start_address_log_slow; } // ищем точку в памяти addres_mem = cur_adr_log - pos;//temp_length // перехали начло лога? if (addres_memtemp_points * al->oscills; // сколько данных надо выерезать из лога al->temp_log_ready = 0; if (al->current_adr_real_log == al->start_adr_real_logs) // мы в начале, логов нету? return; adr_current = al->current_adr_real_log; // выставили конец лога adr_finish_temp = al->start_adr_temp + temp_length; // тут конец лога temp // теперь начиная с конца adr_finish скопируем в temp_log // с учетом того что мы копируем из циклического буфера в обычный, нужна развертка данных for (clog=0; clog= al->start_adr_real_logs) ) { *adr_finish_temp = *adr_current; // скопирлвали данные // едем назад adr_current--; } else *adr_finish_temp = 0; // а нету данных! // едем назад adr_finish_temp--; // закольцевались? if (adr_current < al->start_adr_real_logs) { if (al->finish_adr_real_log) // лог прокручивался? adr_current = al->finish_adr_real_log; // перешли в конец. else adr_current = al->start_adr_real_logs - 1; } } al->temp_log_ready = 1; */ }