Skip to content

Commit

Permalink
add CAN objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon-Knight committed Jan 3, 2025
1 parent 2461006 commit a97f023
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 338 deletions.
6 changes: 3 additions & 3 deletions include/Analog.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Analog
uint16_t OnMuxRequest(uint8_t address);
void OnMuxResponse(uint8_t address, uint16_t value);

EasyPinA adc_pin(&hadc1, GPIOB, GPIO_PIN_1, ADC_CHANNEL_9, ADC_SAMPLETIME_8CYCLES_5);
EasyPinA adc_pin(&hadc1, GPIOB, GPIO_PIN_1, ADC_CHANNEL_5, ADC_SAMPLETIME_8CYCLES_5);
volt_calc_t VoltCalcParams = {((1 << 12) - 1), 3324, 82000, 10000, 17};

AnalogMux<0> mux( OnMuxRequest, OnMuxResponse
Expand Down Expand Up @@ -63,8 +63,8 @@ namespace Analog
if(++adc_calibration >= 60)
{
adc_calibration = 0;

adc_pin.Calibration();
// Не нужно, потому что выполняется в другом месте.
//adc_pin.Calibration();
}
}

Expand Down
332 changes: 11 additions & 321 deletions include/CANLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,100 +20,14 @@ namespace CANLib
CANObject<uint8_t, 7> obj_block_features(CFG_CANFirstId + 2);
CANObject<uint8_t, 7> obj_block_error(CFG_CANFirstId + 3);

CANObject<uint8_t, 1> obj_side_beam(CFG_CANFirstId + 4);
CANObject<uint8_t, 1> obj_low_beam(CFG_CANFirstId + 5);
CANObject<uint8_t, 1> obj_high_beam(CFG_CANFirstId + 6);
CANObject<uint8_t, 1> obj_left_indicator(CFG_CANFirstId + 7);
CANObject<uint8_t, 1> obj_right_indicator(CFG_CANFirstId + 8);
CANObject<uint8_t, 1> obj_hazard_beam(CFG_CANFirstId + 9);
CANObject<uint8_t, 1> obj_custom_beam(CFG_CANFirstId + 10);
CANObject<uint8_t, 1> obj_custom_image(CFG_CANFirstId + 11);



can_result_t OnPowerOutputCtrl(uint8_t port, can_frame_t &can_frame, can_error_t &error)
{
can_frame.initialized = true;

switch(can_frame.function_id)
{
case CAN_FUNC_SET_IN:
{
bool result = Outputs::outObj.SetWrite( port, can_frame.data[0] );
can_frame.function_id = (result == true) ? CAN_FUNC_EVENT_OK : CAN_FUNC_EVENT_ERROR;

break;
}
case CAN_FUNC_TOGGLE_IN:
{
Outputs::outObj.SetToggle(port);
can_frame.function_id = CAN_FUNC_EVENT_OK;

break;
}
case CAN_FUNC_ACTION_IN:
{
bool result = Outputs::outObj.SetOn(port, 250);
can_frame.function_id = (result == true) ? CAN_FUNC_EVENT_OK : CAN_FUNC_EVENT_ERROR;

break;
}
case CAN_FUNC_REQUEST_IN:
{
uint8_t result = (Outputs::outObj.GetState(port) > 0) ? 0xFF : 0x00;
can_frame.function_id = CAN_FUNC_EVENT_OK;
can_frame.data[0] = result;

break;
}
default:
{
break;
}
}

return CAN_RESULT_CAN_FRAME;
}

can_result_t OnPowerOutputCtrl_1(can_frame_t &can_frame, can_error_t &error)
{
return OnPowerOutputCtrl(1, can_frame, error);
}

can_result_t OnPowerOutputCtrl_2(can_frame_t &can_frame, can_error_t &error)
{
return OnPowerOutputCtrl(2, can_frame, error);
}

can_result_t OnPowerOutputCtrl_3(can_frame_t &can_frame, can_error_t &error)
{
return OnPowerOutputCtrl(3, can_frame, error);
}

can_result_t OnPowerOutputCtrl_4(can_frame_t &can_frame, can_error_t &error)
{
return OnPowerOutputCtrl(4, can_frame, error);
}

can_result_t OnPowerOutputCtrl_5(can_frame_t &can_frame, can_error_t &error)
{
return OnPowerOutputCtrl(5, can_frame, error);
}

can_result_t OnPowerOutputCtrl_6(can_frame_t &can_frame, can_error_t &error)
{
return OnPowerOutputCtrl(6, can_frame, error);
}

can_result_t OnPowerOutputCtrl_7(can_frame_t &can_frame, can_error_t &error)
{
return OnPowerOutputCtrl(7, can_frame, error);
}

can_result_t OnPowerOutputCtrl_8(can_frame_t &can_frame, can_error_t &error)
{
return OnPowerOutputCtrl(8, can_frame, error);
}
CANObject<uint8_t, 1> obj_side_beam(CFG_CANFirstId + 4); // Габариты
CANObject<uint8_t, 1> obj_low_brake_beam(CFG_CANFirstId + 5); // Ближний свет или Стоп сигнал
CANObject<uint8_t, 1> obj_high_reverse_beam(CFG_CANFirstId + 6); // Дальний свет или Задний ход
CANObject<uint8_t, 1> obj_left_indicator(CFG_CANFirstId + 7); // Левый поворотник
CANObject<uint8_t, 1> obj_right_indicator(CFG_CANFirstId + 8); // Правый поворотник
CANObject<uint8_t, 1> obj_hazard_beam(CFG_CANFirstId + 9); // Аварийний сигнал
CANObject<uint8_t, 1> obj_custom_beam(CFG_CANFirstId + 10); // Доп. свет
CANObject<uint8_t, 1> obj_led_control(CFG_CANFirstId + 11); // Управление WS2812


void CAN_Enable()
Expand Down Expand Up @@ -152,239 +66,15 @@ namespace CANLib
can_manager.RegisterObject(obj_block_error);

can_manager.RegisterObject(obj_side_beam);
can_manager.RegisterObject(obj_low_beam);
can_manager.RegisterObject(obj_high_beam);
can_manager.RegisterObject(obj_low_brake_beam);
can_manager.RegisterObject(obj_high_reverse_beam);
can_manager.RegisterObject(obj_left_indicator);
can_manager.RegisterObject(obj_right_indicator);
can_manager.RegisterObject(obj_hazard_beam);
can_manager.RegisterObject(obj_custom_beam);
can_manager.RegisterObject(obj_custom_image);
/*
obj_out_1.RegisterFunctionSet(OnPowerOutputCtrl_1);
obj_out_1.RegisterFunctionToggle(OnPowerOutputCtrl_1);
obj_out_1.RegisterFunctionAction(OnPowerOutputCtrl_1);
obj_out_1.RegisterFunctionRequest(OnPowerOutputCtrl_1);
obj_out_2.RegisterFunctionSet(OnPowerOutputCtrl_2);
obj_out_2.RegisterFunctionToggle(OnPowerOutputCtrl_2);
obj_out_2.RegisterFunctionAction(OnPowerOutputCtrl_2);
obj_out_2.RegisterFunctionRequest(OnPowerOutputCtrl_2);
obj_out_3.RegisterFunctionSet(OnPowerOutputCtrl_3);
obj_out_3.RegisterFunctionToggle(OnPowerOutputCtrl_3);
obj_out_3.RegisterFunctionAction(OnPowerOutputCtrl_3);
obj_out_3.RegisterFunctionRequest(OnPowerOutputCtrl_3);
obj_out_4.RegisterFunctionSet(OnPowerOutputCtrl_4);
obj_out_4.RegisterFunctionToggle(OnPowerOutputCtrl_4);
obj_out_4.RegisterFunctionAction(OnPowerOutputCtrl_4);
obj_out_4.RegisterFunctionRequest(OnPowerOutputCtrl_4);
obj_out_5.RegisterFunctionSet(OnPowerOutputCtrl_5);
obj_out_5.RegisterFunctionToggle(OnPowerOutputCtrl_5);
obj_out_5.RegisterFunctionAction(OnPowerOutputCtrl_5);
obj_out_5.RegisterFunctionRequest(OnPowerOutputCtrl_5);
obj_out_6.RegisterFunctionSet(OnPowerOutputCtrl_6);
obj_out_6.RegisterFunctionToggle(OnPowerOutputCtrl_6);
obj_out_6.RegisterFunctionAction(OnPowerOutputCtrl_6);
obj_out_6.RegisterFunctionRequest(OnPowerOutputCtrl_6);
obj_out_7.RegisterFunctionSet(OnPowerOutputCtrl_7);
obj_out_7.RegisterFunctionToggle(OnPowerOutputCtrl_7);
obj_out_7.RegisterFunctionAction(OnPowerOutputCtrl_7);
obj_out_7.RegisterFunctionRequest(OnPowerOutputCtrl_7);
obj_out_8.RegisterFunctionSet(OnPowerOutputCtrl_8);
obj_out_8.RegisterFunctionToggle(OnPowerOutputCtrl_8);
obj_out_8.RegisterFunctionAction(OnPowerOutputCtrl_8);
obj_out_8.RegisterFunctionRequest(OnPowerOutputCtrl_8);
*/


/*
obj_trunk_control
.RegisterFunctionSet([](can_frame_t &can_frame, can_error_t &error) -> can_result_t
{
TrunkHood::LogicSet(TrunkHood::driver2, TrunkHood::actuator_data[1], can_frame.data[0]);
obj_trunk_control.SetValue(0, can_frame.data[0], CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL);
return CAN_RESULT_IGNORE;
})
.RegisterFunctionToggle([](can_frame_t &can_frame, can_error_t &error) -> can_result_t
{
TrunkHood::LogicToggle(TrunkHood::driver2, TrunkHood::actuator_data[1]);
obj_trunk_control.SetValue(0, TrunkHood::actuator_data[1].state, CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL);
return CAN_RESULT_IGNORE;
});
obj_hood_control
.RegisterFunctionSet([](can_frame_t &can_frame, can_error_t &error) -> can_result_t
{
TrunkHood::LogicSet(TrunkHood::driver1, TrunkHood::actuator_data[0], can_frame.data[0]);
obj_hood_control.SetValue(0, can_frame.data[0], CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL);
return CAN_RESULT_IGNORE;
})
.RegisterFunctionToggle([](can_frame_t &can_frame, can_error_t &error) -> can_result_t
{
TrunkHood::LogicToggle(TrunkHood::driver1, TrunkHood::actuator_data[0]);
obj_hood_control.SetValue(0, TrunkHood::actuator_data[0].state, CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL);
return CAN_RESULT_IGNORE;
});
obj_secelec_control
.RegisterFunctionSet([](can_frame_t &can_frame, can_error_t &error) -> can_result_t
{
bool result = true;
if(can_frame.data[0] == 0)
{
Outputs::outObj.SetOff(1);
}
else
{
result = Outputs::outObj.SetOn(1);
}
if (result)
{
obj_secelec_control.SetValue(0, on_off_validator(can_frame.data[0]), CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL);
return CAN_RESULT_IGNORE;
}
error.error_section = ERROR_SECTION_HARDWARE;
error.error_code = ERROR_CODE_HW_SECONDARY_ELECTRONICS_ERROR;
return CAN_RESULT_ERROR;
})
.RegisterFunctionToggle([](can_frame_t &can_frame, can_error_t &error) -> can_result_t
{
Outputs::outObj.SetToggle(1);
obj_secelec_control.SetValue(0, Outputs::outObj.GetState(1), CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL);
return CAN_RESULT_IGNORE;
});
can_manager.RegisterObject(obj_led_control);


obj_leftdoor_control.RegisterFunctionAction([](can_frame_t &can_frame, can_error_t &error) -> can_result_t
{
Outputs::outObj.SetOn(2, 1000);
can_frame.initialized = true;
can_frame.function_id = CAN_FUNC_EVENT_OK;
return CAN_RESULT_CAN_FRAME;
});
obj_rightdoor_control.RegisterFunctionAction([](can_frame_t &can_frame, can_error_t &error) -> can_result_t
{
Outputs::outObj.SetOn(3, 1000);
can_frame.initialized = true;
can_frame.function_id = CAN_FUNC_EVENT_OK;
return CAN_RESULT_CAN_FRAME;
});
obj_cabinlight_control
.RegisterFunctionSet([](can_frame_t &can_frame, can_error_t &error) -> can_result_t
{
bool result = true;
if(can_frame.data[0] == 0)
{
Outputs::outObj.SetOff(4);
}
else
{
result = Outputs::outObj.SetOn(4);
}
if (result)
{
obj_cabinlight_control.SetValue(0, on_off_validator(can_frame.data[0]), CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL);
return CAN_RESULT_IGNORE;
}
error.error_section = ERROR_SECTION_HARDWARE;
error.error_code = ERROR_CODE_HW_CABIN_LIGHT_ERROR;
return CAN_RESULT_ERROR;
})
.RegisterFunctionToggle([](can_frame_t &can_frame, can_error_t &error) -> can_result_t
{
Outputs::outObj.SetToggle(4);
obj_cabinlight_control.SetValue(0, Outputs::outObj.GetState(4), CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL);
return CAN_RESULT_IGNORE;
});
obj_rearcamera_control
.RegisterFunctionSet([](can_frame_t &can_frame, can_error_t &error) -> can_result_t
{
bool result = true;
if(can_frame.data[0] == 0)
{
Outputs::outObj.SetOff(5);
}
else
{
result = Outputs::outObj.SetOn(5);
}
if (result)
{
obj_rearcamera_control.SetValue(0, on_off_validator(can_frame.data[0]), CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL);
return CAN_RESULT_IGNORE;
}
error.error_section = ERROR_SECTION_HARDWARE;
error.error_code = ERROR_CODE_HW_REAR_CAMERA_ERROR;
return CAN_RESULT_ERROR;
})
.RegisterFunctionToggle([](can_frame_t &can_frame, can_error_t &error) -> can_result_t
{
Outputs::outObj.SetToggle(5);
obj_rearcamera_control.SetValue(0, Outputs::outObj.GetState(5), CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL);
return CAN_RESULT_IGNORE;
});
obj_horn_control
.RegisterFunctionSet([](can_frame_t &can_frame, can_error_t &error) -> can_result_t
{
bool result = true;
if(can_frame.data[0] == 0)
{
Outputs::outObj.SetOff(6);
}
else
{
result = Outputs::outObj.SetOn(6);
}
if (result)
{
obj_horn_control.SetValue(0, on_off_validator(can_frame.data[0]), CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL);
return CAN_RESULT_IGNORE;
}
error.error_section = ERROR_SECTION_HARDWARE;
error.error_code = ERROR_CODE_HW_HORN_ERROR;
return CAN_RESULT_ERROR;
})
.RegisterFunctionToggle([](can_frame_t &can_frame, can_error_t &error) -> can_result_t
{
Outputs::outObj.SetToggle(6);
obj_horn_control.SetValue(0, Outputs::outObj.GetState(6), CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL);
return CAN_RESULT_IGNORE;
});
*/


// Передача версий и типов в объект block_info
obj_block_info.SetValue(0, (About::board_type << 3 | About::board_ver), CAN_TIMER_TYPE_NORMAL);
obj_block_info.SetValue(1, (About::soft_ver << 2 | About::can_ver), CAN_TIMER_TYPE_NORMAL);
Expand Down
Loading

0 comments on commit a97f023

Please sign in to comment.