Erste Vorbereitungen für Settings-Datei

This commit is contained in:
Bernhard Schräer
2026-01-20 07:33:02 +01:00
parent f91aee06c7
commit b5f7b5a45d
7 changed files with 87 additions and 32 deletions

View File

@@ -1,14 +1,15 @@
#include "main.h"
#include <settings/settings.h>
#include <can/can_client.h>
#include <io/io.h>
#include <mqtt/mqtt_client.h>
int iCanSimu = 0;
struct MOTOR_CONTROL_DATA motctrl[MOTOR_COUNT];
struct CAN_INTERFACE_DATA intf_data[MOTOR_COUNT];
struct MOTOR_CONTROL_DATA motctrl[MAX_MOTOR_COUNT];
struct CAN_INTERFACE_DATA intf_data[MAX_MOTOR_COUNT];
int iBusTimeoutCounter = 0;
@@ -47,7 +48,8 @@ int Can_OpenInterface(int iMotorIndex, const char * ifacename)
motctrl[iMotorIndex].nDriveConnected = 0;
motctrl[iMotorIndex].nDriveReady = 0;
mylog(LOG_INFO, "CAN: PWR_MAX_RAW=%d PWR_STEP_COUNT=%d", MOTOR_PWR_MAX_RAW, MOTOR_PWR_STEP_COUNT);
mylog(LOG_INFO, "CAN: PWR_MIN_RAW=%d PWR_MAX_RAW=%d PWR_STEP_COUNT=%d",
settings.iMotorPwrMinRaw, settings.iMotorPwrMaxRaw, settings.iMotorPwrStepCount);
strcpy(intf_data[iMotorIndex].iface_name, ifacename);
Can_SetMotorGear(iMotorIndex, MOTOR_GEAR_NEUTRAL);
@@ -177,7 +179,7 @@ void Can_SetMotorGear(int iMotorIndex, int iGear)
/// @brief Set power for the given motor
/// @param iMotorIndex
/// @param iPower (Range: 0..MOTOR_PWR_STEP_COUNT)
/// @param iPower (Range: 0..settings.iMotorPwrStepCount)
void Can_SetMotorPower(int iMotorIndex, int iPower)
{
if ((motctrl[iMotorIndex].iMotorGear == MOTOR_GEAR_NEUTRAL) || (motctrl[iMotorIndex].nDriveReady == 0))
@@ -190,10 +192,10 @@ void Can_SetMotorPower(int iMotorIndex, int iPower)
// limit to min. power
motctrl[iMotorIndex].iMotorPowerSteps = 1;
}
else if (iPower >= MOTOR_PWR_STEP_COUNT)
else if (iPower >= settings.iMotorPwrStepCount)
{
// limit to max. power
motctrl[iMotorIndex].iMotorPowerSteps = MOTOR_PWR_STEP_COUNT;
motctrl[iMotorIndex].iMotorPowerSteps = settings.iMotorPwrStepCount;
}
else
{
@@ -208,7 +210,16 @@ void Can_SetMotorPower(int iMotorIndex, int iPower)
}
else
{
motctrl[iMotorIndex].iMotorPowerRaw = (((MOTOR_PWR_MAX_RAW - MOTOR_PWR_MIN_RAW) * (motctrl[iMotorIndex].iMotorPowerSteps - 1)) / (MOTOR_PWR_STEP_COUNT - 1)) + MOTOR_PWR_MIN_RAW;
// Scale motor power from steps to raw value
motctrl[iMotorIndex].iMotorPowerRaw = (((settings.iMotorPwrMaxRaw - settings.iMotorPwrMinRaw) * (motctrl[iMotorIndex].iMotorPowerSteps - 1)) / (settings.iMotorPwrStepCount - 1)) + settings.iMotorPwrMinRaw;
if (motctrl[iMotorIndex].iMotorPowerRaw < settings.iMotorPwrMinRaw)
{
motctrl[iMotorIndex].iMotorPowerRaw = settings.iMotorPwrMinRaw;
}
else if (motctrl[iMotorIndex].iMotorPowerRaw > settings.iMotorPwrMaxRaw)
{
motctrl[iMotorIndex].iMotorPowerRaw = settings.iMotorPwrMaxRaw;
}
}
mylog(LOG_INFO, "CAN: Motor[%d]: Set power to %d -> %d",

View File

@@ -15,17 +15,13 @@
#include <linux/can.h>
#include <linux/can/raw.h>
#define MOTOR_COUNT 2
#define MAX_MOTOR_COUNT 2
// motor gear: 0x7C=reverse, 0x7D=neutral, 0x7E=forward
#define MOTOR_GEAR_REVERSE 0x7C
#define MOTOR_GEAR_NEUTRAL 0x7D
#define MOTOR_GEAR_FORWARD 0x7E
#define MOTOR_PWR_STEP_COUNT 7 // how many steps to set power
#define MOTOR_PWR_MIN_RAW 38
#define MOTOR_PWR_MAX_RAW 250 // max. raw power value for motor
struct MOTOR_CONTROL_DATA
{
char nDriveConnected;
@@ -36,7 +32,7 @@ struct MOTOR_CONTROL_DATA
unsigned char nSwitchState;
int iActualMotorPowerW;
};
extern struct MOTOR_CONTROL_DATA motctrl[MOTOR_COUNT];
extern struct MOTOR_CONTROL_DATA motctrl[MAX_MOTOR_COUNT];
struct CAN_INTERFACE_DATA
{