Compare commits

...

7 Commits

Author SHA1 Message Date
c8b985ccff add missing include 2022-03-30 16:17:46 +02:00
b21076ce2b light up error lamp if modbus connection is lost 2022-03-30 16:16:42 +02:00
56ff8260a1 remove warnings 2022-03-30 16:16:06 +02:00
b842604f98 link with printf float 2022-03-30 16:14:47 +02:00
55ef5f2031 wiring changes 2022-03-30 16:14:13 +02:00
e775792323 remove warnings 2022-03-30 16:13:21 +02:00
62cb87ffa0 correct missing _ 2022-03-24 16:43:10 +01:00
7 changed files with 38 additions and 26 deletions

View File

@@ -117,7 +117,7 @@ char* MQTTFormat_toClientString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
int32_t index = 0; int32_t index = 0;
int32_t rem_length = 0; int32_t rem_length = 0;
MQTTHeader header = {0}; MQTTHeader header = {0};
int32_t strindex = 0; //int32_t strindex = 0;
header.byte = buf[index++]; header.byte = buf[index++];
index += MQTTPacket_decodeBuf(&buf[index], &rem_length); index += MQTTPacket_decodeBuf(&buf[index], &rem_length);
@@ -128,7 +128,7 @@ char* MQTTFormat_toClientString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
{ {
uint8_t sessionPresent, connack_rc; uint8_t sessionPresent, connack_rc;
if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, buf, buflen) == 1) if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, buf, buflen) == 1)
strindex = MQTTStringFormat_connack(strbuf, strbuflen, connack_rc, sessionPresent); /*strindex = */MQTTStringFormat_connack(strbuf, strbuflen, connack_rc, sessionPresent);
} }
break; break;
case PUBLISH: case PUBLISH:
@@ -141,7 +141,7 @@ char* MQTTFormat_toClientString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName, if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
&payload, &payloadlen, buf, buflen) == 1) &payload, &payloadlen, buf, buflen) == 1)
strindex = MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, /*strindex = */MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained,
packetid, topicName, payload, payloadlen); packetid, topicName, payload, payloadlen);
} }
break; break;
@@ -153,7 +153,7 @@ char* MQTTFormat_toClientString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
uint8_t packettype, dup; uint8_t packettype, dup;
uint16_t packetid; uint16_t packetid;
if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1) if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)
strindex = MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid); /*strindex = */MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);
} }
break; break;
case SUBACK: case SUBACK:
@@ -162,20 +162,20 @@ char* MQTTFormat_toClientString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
int32_t maxcount = 1, count = 0; int32_t maxcount = 1, count = 0;
int32_t grantedQoSs[1]; int32_t grantedQoSs[1];
if (MQTTDeserialize_suback(&packetid, maxcount, &count, grantedQoSs, buf, buflen) == 1) if (MQTTDeserialize_suback(&packetid, maxcount, &count, grantedQoSs, buf, buflen) == 1)
strindex = MQTTStringFormat_suback(strbuf, strbuflen, packetid, count, grantedQoSs); /*strindex = */MQTTStringFormat_suback(strbuf, strbuflen, packetid, count, grantedQoSs);
} }
break; break;
case UNSUBACK: case UNSUBACK:
{ {
uint16_t packetid; uint16_t packetid;
if (MQTTDeserialize_unsuback(&packetid, buf, buflen) == 1) if (MQTTDeserialize_unsuback(&packetid, buf, buflen) == 1)
strindex = MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid); /*strindex = */MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid);
} }
break; break;
case PINGREQ: case PINGREQ:
case PINGRESP: case PINGRESP:
case DISCONNECT: case DISCONNECT:
strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]); /*strindex = */snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
break; break;
} }
@@ -188,7 +188,7 @@ char* MQTTFormat_toServerString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
int32_t index = 0; int32_t index = 0;
int32_t rem_length = 0; int32_t rem_length = 0;
MQTTHeader header = {0}; MQTTHeader header = {0};
int32_t strindex = 0; //int32_t strindex = 0;
header.byte = buf[index++]; header.byte = buf[index++];
index += MQTTPacket_decodeBuf(&buf[index], &rem_length); index += MQTTPacket_decodeBuf(&buf[index], &rem_length);
@@ -201,7 +201,7 @@ char* MQTTFormat_toServerString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
int32_t rc; int32_t rc;
if ((rc = MQTTDeserialize_connect(&data, buf, buflen)) == 1) if ((rc = MQTTDeserialize_connect(&data, buf, buflen)) == 1)
strindex = MQTTStringFormat_connect(strbuf, strbuflen, &data); /*strindex = */MQTTStringFormat_connect(strbuf, strbuflen, &data);
} }
break; break;
case PUBLISH: case PUBLISH:
@@ -214,7 +214,7 @@ char* MQTTFormat_toServerString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName, if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
&payload, &payloadlen, buf, buflen) == 1) &payload, &payloadlen, buf, buflen) == 1)
strindex = MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, /*strindex = */MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained,
packetid, topicName, payload, payloadlen); packetid, topicName, payload, payloadlen);
} }
break; break;
@@ -227,7 +227,7 @@ char* MQTTFormat_toServerString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
uint16_t packetid; uint16_t packetid;
if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1) if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)
strindex = MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid); /*strindex = */MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);
} }
break; break;
case SUBSCRIBE: case SUBSCRIBE:
@@ -240,7 +240,7 @@ char* MQTTFormat_toServerString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
if (MQTTDeserialize_subscribe(&dup, &packetid, maxcount, &count, if (MQTTDeserialize_subscribe(&dup, &packetid, maxcount, &count,
topicFilters, requestedQoSs, buf, buflen) == 1) topicFilters, requestedQoSs, buf, buflen) == 1)
strindex = MQTTStringFormat_subscribe(strbuf, strbuflen, dup, packetid, count, topicFilters, requestedQoSs);; /*strindex = */MQTTStringFormat_subscribe(strbuf, strbuflen, dup, packetid, count, topicFilters, requestedQoSs);;
} }
break; break;
case UNSUBSCRIBE: case UNSUBSCRIBE:
@@ -250,13 +250,13 @@ char* MQTTFormat_toServerString(char* strbuf, int32_t strbuflen, uint8_t* buf, i
int32_t maxcount = 1, count = 0; int32_t maxcount = 1, count = 0;
MQTTString topicFilters[1]; MQTTString topicFilters[1];
if (MQTTDeserialize_unsubscribe(&dup, &packetid, maxcount, &count, topicFilters, buf, buflen) == 1) if (MQTTDeserialize_unsubscribe(&dup, &packetid, maxcount, &count, topicFilters, buf, buflen) == 1)
strindex = MQTTStringFormat_unsubscribe(strbuf, strbuflen, dup, packetid, count, topicFilters); /*strindex = */MQTTStringFormat_unsubscribe(strbuf, strbuflen, dup, packetid, count, topicFilters);
} }
break; break;
case PINGREQ: case PINGREQ:
case PINGRESP: case PINGRESP:
case DISCONNECT: case DISCONNECT:
strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]); /*strindex = */snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
break; break;
} }

View File

@@ -13,7 +13,7 @@ BUILDDIR = Builds
DEFINES = -I . -IInternet/MQTT -I Internet/MQTT/MQTTPacket/src -I Ethernet/W5500 -I Ethernet -DF_CPU=16000000UL -D_WIZCHIP_=W5100 DEFINES = -I . -IInternet/MQTT -I Internet/MQTT/MQTTPacket/src -I Ethernet/W5500 -I Ethernet -DF_CPU=16000000UL -D_WIZCHIP_=W5100
CFLAGS =-mmcu=$(MCU) -O2 -Wall -Wpedantic $(DEFINES) -std=c99 -ffunction-sections -fdata-sections CFLAGS =-mmcu=$(MCU) -O2 -Wall -Wpedantic $(DEFINES) -std=c99 -ffunction-sections -fdata-sections
LDFLAGS =-mmcu=$(MCU) -Wl,--gc-sections LDFLAGS =-mmcu=$(MCU) -Wl,-u,vfprintf -lprintf_flt -lm
LDFILES = $(foreach FILE,$(FILES),$(BUILDDIR)/$(FILE).o) LDFILES = $(foreach FILE,$(FILES),$(BUILDDIR)/$(FILE).o)

View File

@@ -83,7 +83,7 @@ void ioHelperEdgeDetector(void);
// Status Lampen Schrank // Status Lampen Schrank
#define LED_PLC_OK BitPL4 #define LED_PLC_OK BitPL4
#define LED_BUS_OK BitPL2 #define LED_BUS_OK BitPL2
#define LED_FEHLER BitPL5 #define LED_FEHLER BitPB7
// Ampel // Ampel
#define AMPEL_ROT BitPL1 #define AMPEL_ROT BitPL1

10
mqtt.c
View File

@@ -35,8 +35,8 @@ void messageArrived(MessageData* md)
void mqtt_pub(Client* mqtt_client, char * mqtt_topic, char * mqtt_msg, int mqtt_msg_len) void mqtt_pub(Client* mqtt_client, char * mqtt_topic, char * mqtt_msg, int mqtt_msg_len)
{ {
static uint32_t mqtt_pub_count = 0; //static uint32_t mqtt_pub_count = 0;
static uint8_t mqtt_err_cnt = 0; //static uint8_t mqtt_err_cnt = 0;
int32_t mqtt_rc; int32_t mqtt_rc;
//printf(">>MQTT pub msg nr%lu ", ++mqtt_pub_count); //printf(">>MQTT pub msg nr%lu ", ++mqtt_pub_count);
@@ -49,17 +49,17 @@ void mqtt_pub(Client* mqtt_client, char * mqtt_topic, char * mqtt_msg, int mqtt_
//Analize MQTT publish result (for MQTT failover mode) //Analize MQTT publish result (for MQTT failover mode)
if (mqtt_rc == SUCCESSS) if (mqtt_rc == SUCCESSS)
{ {
mqtt_err_cnt = 0; //mqtt_err_cnt = 0;
//printf(" - OK\r\n"); //printf(" - OK\r\n");
} }
else else
{ {
printf("mqtt pub - ERROR\r\n"); printf("mqtt pub - ERROR\r\n");
//Reboot device after 20 continuous errors (~ 20sec) printf("Connection with MQTT Broker was lost!!\r\nReboot the board..\r\n");
while(1); while(1);
//Reboot device after 20 continuous errors (~ 20sec)
//if(mqtt_err_cnt++ > 20) //if(mqtt_err_cnt++ > 20)
//{ //{
// printf("Connection with MQTT Broker was lost!!\r\nReboot the board..\r\n");
// while(1); // while(1);
//} //}
} }

View File

@@ -1,4 +1,6 @@
#include <avrIOhelper/io-helper.h> #include "kraftsensor.h"
#include "avrIOhelper/io-helper.h"
#include <stdio.h>
void do_notaus(){ void do_notaus(){
if(!read_Input(IN_NOTAUS_ANLAGE, LEVEL) || read_Input(IN_NOTAUS_SCHRANK, LEVEL) || read_Input(IN_NOTAUS_DISPLAY, LEVEL)){ if(!read_Input(IN_NOTAUS_ANLAGE, LEVEL) || read_Input(IN_NOTAUS_SCHRANK, LEVEL) || read_Input(IN_NOTAUS_DISPLAY, LEVEL)){
@@ -58,6 +60,14 @@ void do_notaus(){
set_Output(LED_ROT_NOTAUS_SCHRANK, OFF); set_Output(LED_ROT_NOTAUS_SCHRANK, OFF);
set_Output(LED_ROT_NOTAUS_DISPLAY, OFF); set_Output(LED_ROT_NOTAUS_DISPLAY, OFF);
} }
if(!kraftsensor_valid)
{
set_Output(LED_FEHLER, ON);
}
else
set_Output(LED_FEHLER, OFF);
} }

View File

@@ -8,7 +8,7 @@
taenzer_state_t taenzer_state; taenzer_state_t taenzer_state;
#define TAENZER KRAFT_SETPOINT 12000 #define TAENZER_KRAFT_SETPOINT 12000
#define TAENZER_KRAFT_HYST 2000 #define TAENZER_KRAFT_HYST 2000
void do_taenzer(){ void do_taenzer(){
@@ -26,7 +26,7 @@ void do_taenzer(){
/* Force regualtion */ /* Force regualtion */
if(kraftsensor_valid && taenzer_state.homed){ if(kraftsensor_valid && taenzer_state.homed){
int16_t err = abs(kraftsensor_value - TAENZER KRAFT_SETPOINT); int16_t err = abs(kraftsensor_value - TAENZER_KRAFT_SETPOINT);
if(err > 8000) if(err > 8000)
err=8000; err=8000;
@@ -34,11 +34,11 @@ void do_taenzer(){
ICR4 = 400000/err; ICR4 = 400000/err;
OCR4A = ICR4/2; OCR4A = ICR4/2;
if(kraftsensor_value < TAENZER KRAFT_SETPOINT - (TAENZER_KRAFT_HYST/2)){ if(kraftsensor_value < TAENZER_KRAFT_SETPOINT - (TAENZER_KRAFT_HYST/2)){
set_Output(MOTOR_TAENZER_DIR, 0); // direction: down set_Output(MOTOR_TAENZER_DIR, 0); // direction: down
TCCR4B |= _BV(CS41); //TURN ON TCCR4B |= _BV(CS41); //TURN ON
} }
else if(kraftsensor_value > TAENZER KRAFT_SETPOINT + (TAENZER_KRAFT_HYST/2)){ else if(kraftsensor_value > TAENZER_KRAFT_SETPOINT + (TAENZER_KRAFT_HYST/2)){
set_Output(MOTOR_TAENZER_DIR, 1); // direction: up set_Output(MOTOR_TAENZER_DIR, 1); // direction: up
TCCR4B |= _BV(CS41); //TURN ON TCCR4B |= _BV(CS41); //TURN ON
} }

View File

@@ -1,6 +1,8 @@
#ifndef _TAENZER_H_ #ifndef _TAENZER_H_
#define _TAENZER_H #define _TAENZER_H
#include <stdint.h>
typedef struct { typedef struct {
uint8_t homed; uint8_t homed;
uint32_t pos; uint32_t pos;