Zustünde Switch und Power publishen
This commit is contained in:
@@ -12,8 +12,15 @@ struct CAN_INTERFACE_DATA intf_data[MOTOR_COUNT];
|
|||||||
/// @return
|
/// @return
|
||||||
int Can_OpenInterface(int iMotorIndex, const char * ifacename)
|
int Can_OpenInterface(int iMotorIndex, const char * ifacename)
|
||||||
{
|
{
|
||||||
|
// Init control data
|
||||||
|
motctrl[iMotorIndex].iActualMotorPowerW = 0;
|
||||||
|
motctrl[iMotorIndex].iMotorGear = MOTOR_GEAR_NEUTRAL;
|
||||||
|
motctrl[iMotorIndex].iMotorPower = 0;
|
||||||
|
motctrl[iMotorIndex].iMotorPowerPct = 0;
|
||||||
|
motctrl[iMotorIndex].nSwitchState = 0;
|
||||||
|
|
||||||
strcpy(intf_data[iMotorIndex].iface_name, ifacename);
|
strcpy(intf_data[iMotorIndex].iface_name, ifacename);
|
||||||
Can_SetMotorGear(iMotorIndex, 0);
|
Can_SetMotorGear(iMotorIndex, MOTOR_GEAR_NEUTRAL);
|
||||||
Can_SetMotorPower(iMotorIndex, 0);
|
Can_SetMotorPower(iMotorIndex, 0);
|
||||||
|
|
||||||
// first we have to create a socket
|
// first we have to create a socket
|
||||||
@@ -232,12 +239,14 @@ void Can_ReadData(int iMotorIndex)
|
|||||||
/// @param frame
|
/// @param frame
|
||||||
void Can_Read_Manu_PGN(int iMotorIndex, struct can_frame *frame)
|
void Can_Read_Manu_PGN(int iMotorIndex, struct can_frame *frame)
|
||||||
{
|
{
|
||||||
|
motctrl[iMotorIndex].nSwitchState = frame->data[2];
|
||||||
|
MqttClient_Publish_MotorSwitchState(iMotorIndex, motctrl[iMotorIndex].nSwitchState);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Read PGN 65300
|
/// @brief Read PGN 65300
|
||||||
/// @param frame
|
/// @param frame
|
||||||
void Can_Read_Manu_PGN2(int iMotorIndex, struct can_frame *frame)
|
void Can_Read_Manu_PGN2(int iMotorIndex, struct can_frame *frame)
|
||||||
{
|
{
|
||||||
|
motctrl[iMotorIndex].iActualMotorPowerW = (frame->data[3] << 16) | (frame->data[4] << 8) | frame->data[5];
|
||||||
|
MqttClient_Publish_MotorActualPowerW(iMotorIndex, motctrl[iMotorIndex].iActualMotorPowerW);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ struct MOTOR_CONTROL_DATA
|
|||||||
int iMotorGear;
|
int iMotorGear;
|
||||||
int iMotorPower;
|
int iMotorPower;
|
||||||
int iMotorPowerPct;
|
int iMotorPowerPct;
|
||||||
|
unsigned char nSwitchState;
|
||||||
|
int iActualMotorPowerW;
|
||||||
};
|
};
|
||||||
extern struct MOTOR_CONTROL_DATA motctrl[MOTOR_COUNT];
|
extern struct MOTOR_CONTROL_DATA motctrl[MOTOR_COUNT];
|
||||||
|
|
||||||
|
|||||||
12
io/io.c
12
io/io.c
@@ -21,16 +21,7 @@ int IO_Init()
|
|||||||
|
|
||||||
// IO-Pins für Ausgänge konfigurieren
|
// IO-Pins für Ausgänge konfigurieren
|
||||||
SetupOutputPin(GPIO_LED_MOTRUN);
|
SetupOutputPin(GPIO_LED_MOTRUN);
|
||||||
|
SetupOutputPin(GPIO_OUT_PWRON);
|
||||||
// Einschaltsequenz
|
|
||||||
WriteOutputPin(GPIO_LED_MOTRUN, HIGH);
|
|
||||||
delay(500);
|
|
||||||
WriteOutputPin(GPIO_LED_MOTRUN, LOW);
|
|
||||||
delay(500);
|
|
||||||
WriteOutputPin(GPIO_LED_MOTRUN, HIGH);
|
|
||||||
delay(500);
|
|
||||||
WriteOutputPin(GPIO_LED_MOTRUN, LOW);
|
|
||||||
delay(500);
|
|
||||||
|
|
||||||
printf("IO initialized successfull!\n");
|
printf("IO initialized successfull!\n");
|
||||||
|
|
||||||
@@ -164,7 +155,6 @@ void WriteOutputPin(int iOutPin, int iValue)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void IO_DoCyclic()
|
void IO_DoCyclic()
|
||||||
{
|
{
|
||||||
ReadKey(&gpioKeyStop);
|
ReadKey(&gpioKeyStop);
|
||||||
|
|||||||
1
io/io.h
1
io/io.h
@@ -5,6 +5,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define GPIO_LED_MOTRUN 17 // GPIO Pin fuer LED Motor läuft
|
#define GPIO_LED_MOTRUN 17 // GPIO Pin fuer LED Motor läuft
|
||||||
|
#define GPIO_OUT_PWRON 22 // GPIO Pin für Relais "Zündschlüssel"
|
||||||
|
|
||||||
#define GPIO_KEY_STOP 26 // GPIO Pin fuer Taster Stop
|
#define GPIO_KEY_STOP 26 // GPIO Pin fuer Taster Stop
|
||||||
#define GPIO_KEY_PWRUP 5 // GPIO Pin fuer Taster Leistung-Erhöhen
|
#define GPIO_KEY_PWRUP 5 // GPIO Pin fuer Taster Leistung-Erhöhen
|
||||||
|
|||||||
3
main.c
3
main.c
@@ -129,6 +129,9 @@ void *thread_func(void *data)
|
|||||||
// initialize cyclic task
|
// initialize cyclic task
|
||||||
periodic_task_init(1, &pinfo);
|
periodic_task_init(1, &pinfo);
|
||||||
|
|
||||||
|
// "Zündung" ein
|
||||||
|
WriteOutputPin(GPIO_OUT_PWRON, 1);
|
||||||
|
|
||||||
// cyclic call of do_cyclic_1ms()
|
// cyclic call of do_cyclic_1ms()
|
||||||
while (iThreadControl == 0)
|
while (iThreadControl == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,6 +24,15 @@ int iMqttMotor2Gear = 0;
|
|||||||
const char* mqtt_topic_motor2_power = "Pool/Motor2/Power";
|
const char* mqtt_topic_motor2_power = "Pool/Motor2/Power";
|
||||||
int iMqttMotor2Power = 0;
|
int iMqttMotor2Power = 0;
|
||||||
|
|
||||||
|
const char* mqtt_topic_motor1_switchstate = "Pool/Motor1/SwitchState";
|
||||||
|
unsigned char nMqttMotor1SwitchState = 0;
|
||||||
|
const char* mqtt_topic_motor2_switchstate = "Pool/Motor1/SwitchState";
|
||||||
|
unsigned char nMqttMotor2SwitchState = 0;
|
||||||
|
const char* mqtt_topic_motor1_actualpowerw = "Pool/Motor1/ActualPowerW";
|
||||||
|
int iMqttMotor1ActualPowerW = 0;
|
||||||
|
const char* mqtt_topic_motor2_actualpowerw = "Pool/Motor1/ActualPowerW";
|
||||||
|
int iMqttMotor2ActualPowerW = 0;
|
||||||
|
|
||||||
const char* mqtt_broker_addr = "127.0.0.1";
|
const char* mqtt_broker_addr = "127.0.0.1";
|
||||||
const int mqtt_broker_port = 1883;
|
const int mqtt_broker_port = 1883;
|
||||||
struct mosquitto *mosq; /**< Libmosquito MQTT client instance. */
|
struct mosquitto *mosq; /**< Libmosquito MQTT client instance. */
|
||||||
@@ -279,3 +288,52 @@ void MqttClient_Publish_MotorPower(int iMotorIndex, int iPower)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MqttClient_Publish_MotorSwitchState(int iMotorIndex, unsigned char nSwitchState)
|
||||||
|
{
|
||||||
|
if (iMotorIndex == 0)
|
||||||
|
{
|
||||||
|
if (nSwitchState != nMqttMotor1SwitchState)
|
||||||
|
{
|
||||||
|
nMqttMotor1SwitchState = nSwitchState;
|
||||||
|
char message[100];
|
||||||
|
snprintf(message, sizeof(message), "%d", nSwitchState);
|
||||||
|
mosquitto_publish(mosq, NULL, mqtt_topic_motor1_switchstate, strlen(message), message, 0, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (iMotorIndex == 1)
|
||||||
|
{
|
||||||
|
if (nSwitchState != nMqttMotor2SwitchState)
|
||||||
|
{
|
||||||
|
nMqttMotor2SwitchState = nSwitchState;
|
||||||
|
char message[100];
|
||||||
|
snprintf(message, sizeof(message), "%d", nSwitchState);
|
||||||
|
mosquitto_publish(mosq, NULL, mqtt_topic_motor2_switchstate, strlen(message), message, 0, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MqttClient_Publish_MotorActualPowerW(int iMotorIndex, int iMotorPowerW)
|
||||||
|
{
|
||||||
|
if (iMotorIndex == 0)
|
||||||
|
{
|
||||||
|
if (iMotorPowerW != iMqttMotor1ActualPowerW)
|
||||||
|
{
|
||||||
|
iMqttMotor1ActualPowerW = iMotorPowerW;
|
||||||
|
char message[100];
|
||||||
|
snprintf(message, sizeof(message), "%d", iMotorPowerW);
|
||||||
|
mosquitto_publish(mosq, NULL, mqtt_topic_motor1_actualpowerw, strlen(message), message, 0, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (iMotorIndex == 1)
|
||||||
|
{
|
||||||
|
if (iMotorPowerW != iMqttMotor2ActualPowerW)
|
||||||
|
{
|
||||||
|
iMqttMotor2ActualPowerW = iMotorPowerW;
|
||||||
|
char message[100];
|
||||||
|
snprintf(message, sizeof(message), "%d", iMotorPowerW);
|
||||||
|
mosquitto_publish(mosq, NULL, mqtt_topic_motor2_actualpowerw, strlen(message), message, 0, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,5 +9,7 @@ void MqttClient_Refresher();
|
|||||||
void MqttClient_Publisher();
|
void MqttClient_Publisher();
|
||||||
void MqttClient_Publish_MotorGear(int iMotorIndex, int iGear);
|
void MqttClient_Publish_MotorGear(int iMotorIndex, int iGear);
|
||||||
void MqttClient_Publish_MotorPower(int iMotorIndex, int iPower);
|
void MqttClient_Publish_MotorPower(int iMotorIndex, int iPower);
|
||||||
|
void MqttClient_Publish_MotorSwitchState(int iMotorIndex, unsigned char nSwitchState);
|
||||||
|
void MqttClient_Publish_MotorActualPowerW(int iMotorIndex, int iMotorPowerW);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user