|
|
|
|
@ -18,6 +18,7 @@
|
|
|
|
|
#include "mqtt.h"
|
|
|
|
|
#include "modbus.h"
|
|
|
|
|
#include "modbus-master.h"
|
|
|
|
|
#include "modbus_io_slave.h"
|
|
|
|
|
|
|
|
|
|
#include "util/delay.h"
|
|
|
|
|
|
|
|
|
|
@ -135,71 +136,6 @@ void send_values(void){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void modbus_set_Output(uint8_t slave_adr, uint8_t nr, uint8_t state) {
|
|
|
|
|
switch (state) {
|
|
|
|
|
case BLINK:
|
|
|
|
|
//ioHelperSetBit(outStatesBlinking, nr, ON);
|
|
|
|
|
writeCoil(slave_adr,100+nr,1);
|
|
|
|
|
wait_write(10);
|
|
|
|
|
break;
|
|
|
|
|
//case TOGGLE:
|
|
|
|
|
// ioHelperSetBit(outStatesBlinking, nr, OFF);
|
|
|
|
|
// if (ioHelperReadBit(outStates, nr)) {
|
|
|
|
|
// ioHelperSetBit(outStates, nr, OFF);
|
|
|
|
|
// } else {
|
|
|
|
|
// ioHelperSetBit(outStates, nr, ON);
|
|
|
|
|
// }
|
|
|
|
|
// break;
|
|
|
|
|
case ON:
|
|
|
|
|
//ioHelperSetBit(outStates, nr, ON);
|
|
|
|
|
//ioHelperSetBit(outStatesBlinking, nr, OFF);
|
|
|
|
|
writeCoil(slave_adr,nr,1);
|
|
|
|
|
wait_write(10);
|
|
|
|
|
break;
|
|
|
|
|
case OFF:
|
|
|
|
|
writeCoil(slave_adr,nr,0);
|
|
|
|
|
wait_write(10);
|
|
|
|
|
//ioHelperSetBit(outStates, nr, OFF);
|
|
|
|
|
//ioHelperSetBit(outStatesBlinking, nr, OFF);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t modbus_read_Input(uint8_t nr, uint8_t type) {
|
|
|
|
|
uint8_t state = 0;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case LEVEL:
|
|
|
|
|
state = ioHelperReadBit(inStates, nr);
|
|
|
|
|
break;
|
|
|
|
|
case EDGE:
|
|
|
|
|
state = ioHelperReadBit(inStatesBothEdges, nr);
|
|
|
|
|
ioHelperSetBit(inStatesBothEdges, nr, 0);
|
|
|
|
|
break;
|
|
|
|
|
case RISING:
|
|
|
|
|
state = ioHelperReadBit(inStatesRisingEdge, nr);
|
|
|
|
|
ioHelperSetBit(inStatesRisingEdge, nr, 0);
|
|
|
|
|
break;
|
|
|
|
|
case FALLING:
|
|
|
|
|
state = ioHelperReadBit(inStatesFallingEdge, nr);
|
|
|
|
|
ioHelperSetBit(inStatesFallingEdge, nr, 0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//reset edges after being read once
|
|
|
|
|
// if (state) {
|
|
|
|
|
// if (type == EDGE)
|
|
|
|
|
// ioHelperSetBit(inStatesBothEdges, nr, OFF);
|
|
|
|
|
// if (type == RISING)
|
|
|
|
|
// ioHelperSetBit(inStatesRisingEdge, nr, OFF);
|
|
|
|
|
// if (type == FALLING)
|
|
|
|
|
// ioHelperSetBit(inStatesFallingEdge, nr, OFF);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(){
|
|
|
|
|
// INIT MCU
|
|
|
|
|
avr_init();
|
|
|
|
|
@ -260,6 +196,7 @@ int main(){
|
|
|
|
|
uint32_t timer_blink_outs = millis();
|
|
|
|
|
uint32_t timer_send_uptime = millis();
|
|
|
|
|
uint32_t timer_send_info = millis();
|
|
|
|
|
uint32_t timer_read_slave = millis();
|
|
|
|
|
|
|
|
|
|
//printf("anlage: %x\n\r", read_Input(IN_ANLAGE_EIN_INV, LEVEL));
|
|
|
|
|
|
|
|
|
|
@ -282,20 +219,34 @@ int main(){
|
|
|
|
|
|
|
|
|
|
do_kraftsensor();
|
|
|
|
|
|
|
|
|
|
#if PLC_MQTT_ENABLED
|
|
|
|
|
char msg[64];
|
|
|
|
|
sprintf(msg, "%d", kraftsensor_value);
|
|
|
|
|
mqtt_pub(&mqtt_client, "/Filamentanlage/01_Extruder/kraft", msg, strlen(msg));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
modbus_io_set_Output(4, 0, TOGGLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(millis() - timer_read_slave > 100){
|
|
|
|
|
timer_read_slave = millis();
|
|
|
|
|
//readInputState(4, 200, 32);
|
|
|
|
|
modbus_io_read();
|
|
|
|
|
|
|
|
|
|
if(modbus_io_read_Input(16, RISING))
|
|
|
|
|
modbus_io_set_Output(4, 3, ON);
|
|
|
|
|
if(modbus_io_read_Input(17, RISING))
|
|
|
|
|
modbus_io_set_Output(4, 3, OFF);
|
|
|
|
|
|
|
|
|
|
//tgl ^= 0x01;
|
|
|
|
|
//modbus_set_Output(4, 0, OFF);
|
|
|
|
|
//modbus_set_Output(4, 1, ON);
|
|
|
|
|
//modbus_set_Output(4, 2, BLINK);
|
|
|
|
|
//modbus_set_Output(4, 3, tgl);
|
|
|
|
|
|
|
|
|
|
//readInputReg(4, 0, 1);
|
|
|
|
|
//uint16_t inp;
|
|
|
|
|
//wait_receive(1, &inp, 100);
|
|
|
|
|
//printf("read inputs: 0x%X\n", inp);
|
|
|
|
|
//printf("read inputs: 0x%02X 0x%02X 0x%02X 0x%02X\n", inp[3], inp[2], inp[1], inp[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(read_Input(BTN_HEIZEN_AN, RISING)){
|
|
|
|
|
modbus_io_set_Output(4, MOD_OUT_HEIZEN_LED, 1);
|
|
|
|
|
}
|
|
|
|
|
if(read_Input(BTN_HEIZEN_AUS, RISING)){
|
|
|
|
|
modbus_io_set_Output(4, MOD_OUT_HEIZEN_LED, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if PLC_MQTT_ENABLED
|
|
|
|
|
|