2024-12-27 10:50:32 +03:00
# include <message_modbus.h>
# include <message_terminals_can.h>
# include <message2.h>
# include <modbus_hmi.h>
# include <project.h>
# include <vector.h>
# include <modbus_hmi_update.h>
# include "CAN_Setup.h"
# include "global_time.h"
# include "modbus_table_v2.h"
# include "oscil_can.h"
# include "RS_modbus_pult.h"
# include "DSP281x_Examples.h" // DSP281x Examples Include File
# include "DSP281x_Device.h" // DSP281x Headerfile Include File
# include "CRC_Functions.h"
# include "RS_Function_terminal.h"
# include "RS_modbus_svu.h"
# include "TuneUpPlane.h"
# if (USE_CONTROL_STATION==1)
# include "control_station.h"
# endif
# include <message2can.h>
# include <edrk_main.h>
//#include "can_setup_21300.h"
//#include "modbus_can.h"
//static int err_modbus3=1;
//static int err_modbus16=1;
//static int cmd_3_or_16=0;
int enable_can = 0 ;
void write_all_data_to_mpu_485 ( int run_force )
{
static unsigned int time_tick_modbus = 0 ;
static unsigned int old_PWM_ticks = 0 ;
static int count_write_to_modbus = 0 ;
static int cur_position_buf_modbus16 = 0 ;
if ( global_time . pwm_tics ! = old_PWM_ticks )
{
if ( global_time . pwm_tics > old_PWM_ticks )
time_tick_modbus = time_tick_modbus + ( global_time . pwm_tics - old_PWM_ticks ) ;
else
time_tick_modbus + + ;
}
if ( time_tick_modbus > TIME_PAUSE_MODBUS_MPU )
{
// pause_1000()
time_tick_modbus = 0 ;
pause_1000 ( 10 ) ;
// SendCommandModbus3(&rs_b, 0x1, 0xc012,1);
// rs_b.flag_LEADING = 0;
if ( ! rs_b . flag_LEADING )
{
time_tick_modbus = 0 ;
//Fast answer to SVU when command changed
// if (flag_send_answer_rs) {
// flag_send_answer_rs = 0;
// err_modbus16++;
// SendCommandModbus16(&rs_b,1,210,SIZE_BUF_WRITE_TO_MODBUS16);
// return;
// }
if ( err_modbus16 = = 0 )
cur_position_buf_modbus16 = cur_position_buf_modbus16 + SIZE_BUF_WRITE_TO_MODBUS16_VPU ;
if ( cur_position_buf_modbus16 > = SIZE_MODBUS_TABLE )
cur_position_buf_modbus16 = 0 ;
if ( ( cur_position_buf_modbus16 + SIZE_BUF_WRITE_TO_MODBUS16_VPU ) > SIZE_MODBUS_TABLE )
count_write_to_modbus = SIZE_MODBUS_TABLE - cur_position_buf_modbus16 ;
else
count_write_to_modbus = SIZE_BUF_WRITE_TO_MODBUS16_VPU ;
// count_write_to_modbus = SIZE_BUF_WRITE_TO_MODBUS16_VPU;
// cur_position_buf_modbus=0;
err_modbus16 + + ;
if ( err_modbus16 > MAX_COUNT_ERROR_FROM_RS_MPU )
f . RS_MPU_ERROR = 1 ;
ModbusRTUsend16 ( & rs_b , 1 ,
ADR_MODBUS_TABLE + cur_position_buf_modbus16 ,
count_write_to_modbus ) ;
// SendCommandModbus16(&rs_b,1,ADR_MODBUS_TABLE+cur_position_buf_modbus16,count_write_to_modbus);
// SendCommandModbus16(&rs_b,1,1,30);
//
// SendCommandModbus16(&rs_b,1,0xc001,0x64);
// err_modbus
}
}
}
void read_all_data_from_mpu_485 ( int run_force )
{
static unsigned int time_tick_modbus = 0 ;
static unsigned int old_PWM_ticks = 0 ;
static unsigned int count_write_to_modbus = 0 ;
static int cur_position_buf_modbus3 = 0 ;
if ( global_time . pwm_tics ! = old_PWM_ticks )
{
if ( global_time . pwm_tics > old_PWM_ticks )
time_tick_modbus = time_tick_modbus + ( global_time . pwm_tics - old_PWM_ticks ) ;
else
time_tick_modbus + + ;
}
old_PWM_ticks = global_time . pwm_tics ;
if ( TIME_PAUSE_MODBUS_MPU < time_tick_modbus )
{
// pause_1000()
pause_1000 ( 10 ) ;
// SendCommandModbus3(&rs_b, 0x1, 0xc012,1);
//rs_b.flag_LEADING = 0;
if ( ! rs_b . flag_LEADING )
{
time_tick_modbus = 0 ;
if ( err_modbus3 = = 0 )
cur_position_buf_modbus3 = cur_position_buf_modbus3 + SIZE_BUF_WRITE_TO_MODBUS16_VPU ;
if ( cur_position_buf_modbus3 > = SIZE_MODBUS_TABLE )
cur_position_buf_modbus3 = 0 ;
if ( ( cur_position_buf_modbus3 + SIZE_BUF_WRITE_TO_MODBUS16_VPU ) > SIZE_MODBUS_TABLE )
count_write_to_modbus = SIZE_MODBUS_TABLE - cur_position_buf_modbus3 ;
else
count_write_to_modbus = SIZE_BUF_WRITE_TO_MODBUS16_VPU ;
// count_write_to_modbus = SIZE_BUF_WRITE_TO_MODBUS16_VPU;
// cur_position_buf_modbus=0;
err_modbus3 + + ;
if ( err_modbus3 > MAX_COUNT_ERROR_FROM_RS_MPU )
f . RS_MPU_ERROR = 1 ;
// SendCommandModbus3(&rs_b,1,ADR_MODBUS_TABLE+cur_position_buf_modbus3,count_write_to_modbus);
ModbusRTUsend3 ( & rs_b , 1 ,
ADR_MODBUS_TABLE + cur_position_buf_modbus3 ,
count_write_to_modbus ) ;
}
}
// time_tick_modbus++;
}
void write_all_data_to_mpu_can ( int run_force , unsigned int pause )
{
// static int time_tick_modbus_can = 0;
static unsigned int old_time = 0 ;
static int count_write_to_modbus_can = 0 ;
// static int time_send_to_can = 0;
// static unsigned int counter_max_I = 0, counter_max_M = 0;
static int cur_position_buf_modbus16_can = 0 , prev_send_to_can = 0 ;
int real_mbox ;
real_mbox = get_real_out_mbox ( MPU_TYPE_BOX , edrk . flag_second_PCH ) ;
if ( prev_send_to_can & & CAN_cycle_full_free ( real_mbox , CAN_BOX_STAT_OFF ) = = 0 )
{
old_time = ( unsigned int ) global_time . miliseconds ;
return ;
}
prev_send_to_can = 0 ;
if ( ! detect_pause_milisec ( pause , & old_time ) )
return ;
//
//
// if (cmd_3_or_16 == 1 || run_force)
// {
//
// if (global_time.pwm_tics != old_PWM_ticks)
// {
// if (global_time.pwm_tics > old_PWM_ticks)
// time_tick_modbus_can = time_tick_modbus_can + (global_time.pwm_tics - old_PWM_ticks);
// else
// time_tick_modbus_can++;
// }
//
// old_PWM_ticks = global_time.pwm_tics;
// }
// else
// {
// old_PWM_ticks = global_time.pwm_tics;
// return;
// }
//
//
//
// if (CAN_cycle_free(real_mbox))
// {
// if (time_send_to_can == 0)
// time_send_to_can = time_tick_modbus_can;
//
// // time_tick_modbus_can=0;
//
// }
// if(f.Prepare && CAN_cycle_free(real_mbox))
// {
// CAN_cycle_send( MPU_TYPE_BOX, 0, 198, &modbus_table_can_out[197].all, 1);
// }
// if (time_tick_modbus_can > TIME_PAUSE_MODBUS_CAN)
// {
// time_tick_modbus_can = 0;
// time_send_to_can = 0;
// // pause_1000(300);
if ( CAN_cycle_full_free ( real_mbox , CAN_BOX_STAT_ON ) )
{
/////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
if ( cur_position_buf_modbus16_can > = SIZE_MODBUS_TABLE )
{
cur_position_buf_modbus16_can = 0 ;
// modbus_table_can_out[ADR_CAN_TEST_PLUS_ONE].all++;
}
if ( ( cur_position_buf_modbus16_can + SIZE_BUF_WRITE_TO_MODBUS16_CAN ) > = SIZE_MODBUS_TABLE )
count_write_to_modbus_can = SIZE_MODBUS_TABLE - cur_position_buf_modbus16_can ;
else
count_write_to_modbus_can = SIZE_BUF_WRITE_TO_MODBUS16_CAN ;
if ( CAN_cycle_full_free ( real_mbox , CAN_BOX_STAT_ON ) )
{
// modbus_table_can_out[0x124].all++;
// CAN_cycle_send(MPU_CAN_DEVICE, cur_position_buf_modbus16_can+1, &modbus_table_can_out[cur_position_buf_modbus16_can].all, count_write_to_modbus_can);
CAN_cycle_send (
MPU_TYPE_BOX ,
edrk . flag_second_PCH ,
cur_position_buf_modbus16_can + 1 ,
2025-01-15 13:39:33 +03:00
& modbus_table_can_out [ cur_position_buf_modbus16_can ] . all ,
2024-12-27 10:50:32 +03:00
count_write_to_modbus_can , CAN_BOX_STANDART_ADR , CAN_BOX_PRIORITY_NORMAL ) ;
cur_position_buf_modbus16_can = cur_position_buf_modbus16_can + SIZE_BUF_WRITE_TO_MODBUS16_CAN ;
}
}
// }
}
//void test_rs_can_with_svu_mpu()
//{
// int test_a, test_b;
//
// test_a = test_rs_live(&rs_a);
// test_b = test_rs_live(&rs_b);
//
// if (test_a == 0 && test_b == 0 && f.status_MODE_WORK_SVU == 0)
// {
// /* <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> RS232 */
// if (test_can_live_mpu() == 0)
// {
// // if (f.cmd_to_go == 0) f.cmd_to_go = ERROR_CMD_GO_1;
// edrk.Go = 0; /* <09> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> */
// }
// }
//
// if (test_a == 0 && test_b == 0 && f.status_MODE_WORK_MPU == 0 /*&& f.status_SPEED_SELECT_KEY==0*/)
// {
// /* <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> RS232 */
// if (test_can_live_mpu() == 0)
// {
// // if (f.cmd_to_go == 0) f.cmd_to_go = ERROR_CMD_GO_2;
// edrk.Go = 0; /* <09> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> */
// }
// }
//
// if (test_a == 2)
// {
// /* <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> RS232 */
// // edrk.Go=0; /* <09> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> */
// resetup_rs(&rs_a);
// }
//
// if (test_b == 2)
// {
// /* <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> RS232 */
// resetup_rs(&rs_b);
//// flag_waiting_answer = 0; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ,
// //<2F> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> slave <20> <> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
// }
//
// if (test_b == 5)
// {
// /* <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> RS232 */
// resetup_rs(&rs_b);
//// flag_waiting_answer = 0; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ,
// //<2F> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> slave <20> <> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> .
// }
//
// if (test_a == 4 && test_b == 4) //TODO: && SPEED_SELECT_REMOTE==1)
// {
// // <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> RS232
// if (test_can_live_mpu() == 0)
// {
// // if (f.cmd_to_go == 0) f.cmd_to_go = ERROR_CMD_GO_3;
// edrk.Go = 0; // <09> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// }
// resetup_mpu_rs(&rs_a);
// resetup_mpu_rs(&rs_b);
//// flag_waiting_answer = 0;
// }
//
// if (test_a == 4 && test_b == 4) //TOD: && SPEED_SELECT_REMOTE==0)
// {
// // <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> RS232
// // if (test_can_live_mpu()==0)
//
// // test_can_live_terminal //
//
// {
// // if (f.cmd_to_go == 0) f.cmd_to_go = ERROR_CMD_GO_20;
// edrk.Go = 0; // <09> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// }
// resetup_mpu_rs(&rs_a);
// resetup_mpu_rs(&rs_b);
// }
//
// if (test_a == 0 && f.status_MODE_WORK_MPU == 0) // && SPEED_SELECT_REMOTE==0)
// {
// /* <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> RS232 */
// // if (test_can_live_mpu()==0)
// // if (f.cmd_to_go == 0) f.cmd_to_go = ERROR_CMD_GO_4;
// edrk.Go = 0; /* <09> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> */
// }
//
// // if (CAN_timeout[]==1)
// // f.CAN_MPU_ERROR=CAN_timeout[MPU_CAN_DEVICE];
//}
# define TIME_REINIT_PULT_INGETEAM 5
void test_alive_pult_485 ( void )
{
static unsigned int time_pause = 0 , old_time = 0 ;
//
// if (control_station.time_detect_answer_485[CONTROL_STATION_INGETEAM_PULT_RS485]>control_station.setup_time_detect_active_resend_485[CONTROL_STATION_INGETEAM_PULT_RS485])
// {
// resetup_mpu_rs(&rs_b);
// control_station.flag_waiting_answer[CONTROL_STATION_INGETEAM_PULT_RS485] = 0;
// control_station.flag_message_sent[CONTROL_STATION_INGETEAM_PULT_RS485] = 0;
// control_station.time_detect_answer_485[CONTROL_STATION_INGETEAM_PULT_RS485] = 0;
// }
/*
if ( control_station . time_detect_active [ CONTROL_STATION_INGETEAM_PULT_RS485 ] > control_station . setup_time_detect_active_resend_485 [ CONTROL_STATION_INGETEAM_PULT_RS485 ] )
{
resetup_mpu_rs ( & rs_b ) ;
control_station . flag_waiting_answer [ CONTROL_STATION_INGETEAM_PULT_RS485 ] = 0 ;
// control_station.time_detect_active[CONTROL_STATION_INGETEAM_PULT_RS485] = 0;
}
*/
// if (control_station.time_detect_active[CONTROL_STATION_INGETEAM_PULT_RS485]>control_station.setup_time_detect_active[CONTROL_STATION_INGETEAM_PULT_RS485])
// {
// resetup_mpu_rs(&rs_b);
// control_station.flag_waiting_answer[CONTROL_STATION_INGETEAM_PULT_RS485] = 0;
// control_station.time_detect_active[CONTROL_STATION_INGETEAM_PULT_RS485] = 0;
// }
/*
if ( ! detect_pause_milisec ( CONTROL_STATION_TIME_WAIT , & old_time ) )
return ;
time_pause + + ;
if ( time_pause > = TIME_REINIT_PULT_INGETEAM )
{
flag_waiting_answer = 0 ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
}
*/
}
int modbusNetworkSharing ( int flag_update_only_hmi )
{
static unsigned int old_time = 0 , old_time_refresh = 0 , time_pause = TIME_PAUSE_MODBUS_REMOUTE ;
static unsigned int old_time_status_3 = 0 , time_pause_status_3 = 500 ;
int final_code = 0 ;
static unsigned int status = 0 ;
static int numberInT = 0 , enable_send_cmd = 0 ;
static int run_pause = 1 , flag_next = 0 , prev_flag_next = 0 ;
static int last_ok_cmd = 0 ;
static int flag_only_one_cmd = 0 ;
RS232_WorkingWith ( 0 , 1 , 0 ) ;
// <20> <> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> -<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// control_station.flag_waiting_answer[CONTROL_STATION_INGETEAM_PULT_RS485] = 1;
control_station_test_alive_all_control ( ) ;
// if (detect_pause_milisec(100,&old_time_refresh))
control_station . update_timers ( & control_station ) ;
detecting_cmd_from_can ( ) ;
// test_rs_can_with_svu_mpu();
// test_alive_pult_485();
// if (rs_b.RS_DataSended==0 && rs_b.RS_DataReadyAnswerAnalyze==0)
// status = 0;
control_station . flag_message_sent [ CONTROL_STATION_INGETEAM_PULT_RS485 ] = rs_b . RS_DataSended ;
final_code = 0 ;
if ( status = = 0 )
{
old_time = global_time . miliseconds ;
status = 1 ;
}
if ( status = = 1 )
{
2025-01-15 13:39:33 +03:00
if ( numberInT = = 0 )
{
2024-12-27 10:50:32 +03:00
if ( detect_pause_milisec ( time_pause , & old_time ) )
status = 2 ;
2025-01-15 13:39:33 +03:00
}
else
status = 2 ;
2024-12-27 10:50:32 +03:00
}
if ( status = = 2 )
{
enable_send_cmd = 1 ;
control_station . time_detect_answer_485 [ CONTROL_STATION_INGETEAM_PULT_RS485 ] = 0 ;
status = 3 ;
old_time_status_3 = global_time . miliseconds ;
}
if ( status = = 3 )
{
if ( rs_b . RS_DataReadyAnswerAnalyze )
{
// i_led2_on_off(0);
control_station . time_detect_answer_485 [ CONTROL_STATION_INGETEAM_PULT_RS485 ] = 0 ;
control_station . count_ok_modbus [ CONTROL_STATION_INGETEAM_PULT_RS485 ] + + ;
rs_b . RS_DataReadyAnswerAnalyze = 0 ;
status = 0 ;
if ( last_ok_cmd = = 4 ) // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> readAnalogDataFromRemote() <20> <> <20> <> <EFBFBD> <EFBFBD>
edrk . get_new_data_from_hmi = 1 ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ?
final_code = last_ok_cmd ; //numberInT+1;
}
else
{
if ( ( control_station . time_detect_answer_485 [ CONTROL_STATION_INGETEAM_PULT_RS485 ] > control_station . setup_time_detect_active_resend_485 [ CONTROL_STATION_INGETEAM_PULT_RS485 ] )
| | ( detect_pause_milisec ( time_pause_status_3 , & old_time_status_3 ) ) )
{
resetup_mpu_rs ( & rs_b ) ;
control_station . time_detect_answer_485 [ CONTROL_STATION_INGETEAM_PULT_RS485 ] = 0 ;
status = 0 ;
control_station . count_error_modbus [ CONTROL_STATION_INGETEAM_PULT_RS485 ] + + ;
}
}
}
2025-01-15 13:39:33 +03:00
2024-12-27 10:50:32 +03:00
// switch (status)
// {
// case 0 : status = 1;
// break;
//
// case 1 : old_time = global_time.miliseconds;
// status = 2;
// break;
//
// case 2 :
// if (run_pause)
// {
// status = 3;
// run_pause = 0;
// }
// if (detect_pause_milisec(time_pause,&old_time))
// status = 3;
// break;
//
// case 3 :
// enable_send_cmd = 1;
//// control_station.count_error_modbus_15[CONTROL_STATION_INGETEAM_PULT_RS485]++;
// control_station.time_detect_answer_485[CONTROL_STATION_INGETEAM_PULT_RS485] = 0;
// status = 4;
// break;
//
//
// case 4 :
// if (rs_b.RS_DataReadyAnswerAnalyze)
// {
// control_station.time_detect_answer_485[CONTROL_STATION_INGETEAM_PULT_RS485] = 0;
// control_station.count_ok_modbus[CONTROL_STATION_INGETEAM_PULT_RS485]++;
// rs_b.RS_DataReadyAnswerAnalyze = 0;
// status = 1;
// final_code = numberInT+1;
// }
// else
// {
// if (control_station.time_detect_answer_485[CONTROL_STATION_INGETEAM_PULT_RS485]>control_station.setup_time_detect_active_resend_485[CONTROL_STATION_INGETEAM_PULT_RS485])
// {
// resetup_mpu_rs(&rs_b);
// control_station.time_detect_answer_485[CONTROL_STATION_INGETEAM_PULT_RS485] = 0;
// status = 1;
// control_station.count_error_modbus[CONTROL_STATION_INGETEAM_PULT_RS485]++;
// }
// }
// break;
//
//
// case 5 : break;
//
//
// case 6 : break;
//
// default : break;
// }
//
//
// if (control_station.flag_message_sent[CONTROL_STATION_INGETEAM_PULT_RS485] == 1)
// {
// if (control_station.flag_waiting_answer[CONTROL_STATION_INGETEAM_PULT_RS485] == 0 && prev_flag_waiting_answer == 1)
// {
// old_time = global_time.miliseconds;
// }
//
// if (control_station.flag_waiting_answer[CONTROL_STATION_INGETEAM_PULT_RS485] == 0)
// {
// if (detect_pause_milisec(time_pause,&old_time))
// {
// control_station.flag_message_sent[CONTROL_STATION_INGETEAM_PULT_RS485] = 0;
// }
//
// }
// }
// prev_flag_waiting_answer = control_station.flag_waiting_answer[CONTROL_STATION_INGETEAM_PULT_RS485];
//
//
// if (control_station.flag_message_sent[CONTROL_STATION_INGETEAM_PULT_RS485] == 0 &&
// control_station.flag_waiting_answer[CONTROL_STATION_INGETEAM_PULT_RS485] == 0 )
// {
// enable_send_cmd = 1;
//// numberInT++;
//// if (numberInT>3)
//// numberInT = 1;
// }
//
// <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
if ( flag_only_one_cmd )
numberInT = flag_only_one_cmd - 1 ;
//
2025-01-15 13:39:33 +03:00
if ( enable_send_cmd & & ( log_to_HMI . send_log = = 0 ) )
2024-12-27 10:50:32 +03:00
{
//i_led2_on_off(1);
last_ok_cmd = numberInT ;
switch ( numberInT )
{
case 0 :
if ( ( flag_update_only_hmi = = 0 ) & & ( edrk . flag_enable_update_hmi ) )
update_tables_HMI_discrete ( ) ;
writeDiscreteDataToRemote ( ) ;
edrk . test + + ;
numberInT + + ;
break ;
case 1 :
if ( ( flag_update_only_hmi = = 0 ) & & ( edrk . flag_enable_update_hmi ) )
update_tables_HMI_analog ( ) ;
writeAnalogDataToRemote ( ) ; // 1 <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// if (flag_update_only_hmi==1)
// // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// numberInT = 0;
// else
numberInT + + ;
break ;
case 2 :
// if (edrk.flag_enable_update_hmi)
// update_tables_HMI_analog();
writeAnalogDataToRemote ( ) ; // 2 <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// if (flag_update_only_hmi==1)
// // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// numberInT = 0;
// else
numberInT + + ;
break ;
case 3 :
readAnalogDataFromRemote ( ) ; // 1 <20> <> <EFBFBD> <EFBFBD> <EFBFBD>
numberInT + + ;
break ;
case 4 :
readAnalogDataFromRemote ( ) ; // 2 <20> <> <EFBFBD> <EFBFBD> <EFBFBD>
2025-01-15 13:39:33 +03:00
if ( log_to_HMI . send_log = = 1 )
2024-12-27 10:50:32 +03:00
numberInT + + ;
else
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
numberInT = 0 ;
break ;
case 5 :
2025-01-15 13:39:33 +03:00
sendLogToHMI ( ) ;
numberInT = 0 ;
2024-12-27 10:50:32 +03:00
break ;
default :
break ;
}
2025-01-15 13:39:33 +03:00
enable_send_cmd = 0 ;
2024-12-27 10:50:32 +03:00
//i_led2_on_off(0);
}
2025-01-15 13:39:33 +03:00
sendLogToHMI ( ) ;
2024-12-27 10:50:32 +03:00
if ( flag_update_only_hmi )
return final_code ;
return 0 ;
}
int modbusNetworkSharingCAN ( void )
{
// static unsigned int old_time1 = 0 , time_pause1 = TIME_PAUSE_NETWORK_CAN1;
// static unsigned int old_time2 = 0 , time_pause2 = TIME_PAUSE_NETWORK_CAN2;
// static unsigned int old_time3 = 0 , time_pause3 = TIME_PAUSE_NETWORK_CAN3;
# if (ENABLE_CAN_SEND_TO_MPU_FROM_MAIN)
// if (detect_pause_milisec(time_pause1,&old_time1))
2025-01-15 13:39:33 +03:00
write_all_data_to_mpu_can ( 1 , TIME_PAUSE_MODBUS_CAN_MPU ) ;
2024-12-27 10:50:32 +03:00
# endif
# if (ENABLE_CAN_SEND_TO_TERMINAL_FROM_MAIN)
// if (detect_pause_milisec(time_pause2,&old_time2))
2025-01-15 13:39:33 +03:00
write_all_data_to_terminals_can ( 1 , TIME_PAUSE_MODBUS_CAN_TERMINALS ) ;
2024-12-27 10:50:32 +03:00
# endif
# if (ENABLE_CAN_SEND_TO_TERMINAL_OSCIL)
// if (detect_pause_milisec(time_pause3,&old_time3))
oscil_can . pause_can = TIME_PAUSE_MODBUS_CAN_OSCIL ;
oscil_can . send ( & oscil_can ) ;
# endif
return 0 ;
}