Compare commits
7 Commits
d76b897eb2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 0c4a728c17 | |||
| d92a1d9533 | |||
| 9325fa20c8 | |||
| 08c47f00f8 | |||
| 1cba00df8c | |||
| 35bd208cc0 | |||
| 48cfcd5d4c |
64
.gitignore
vendored
64
.gitignore
vendored
@@ -1 +1,65 @@
|
||||
**/build
|
||||
|
||||
# Zephyr build directories
|
||||
build/
|
||||
build-*/
|
||||
*/build/
|
||||
**/build/
|
||||
|
||||
# Zephyr out-of-tree build directories
|
||||
out-of-tree-build/
|
||||
|
||||
# Files generated by the build system
|
||||
zephyr.elf
|
||||
zephyr.bin
|
||||
zephyr.hex
|
||||
zephyr.map
|
||||
zephyr.strip
|
||||
zephyr.lst
|
||||
zephyr.asm
|
||||
zephyr.stat
|
||||
zephyr.a
|
||||
zephyr.o
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
*.so.*
|
||||
*.dll
|
||||
*.exe
|
||||
|
||||
# Cmake
|
||||
CMakeCache.txt
|
||||
CMakeFiles/
|
||||
cmake_install.cmake
|
||||
CTestTestfile.cmake
|
||||
compile_commands.json
|
||||
|
||||
# Kconfig generated files
|
||||
.config
|
||||
.config.old
|
||||
autoconf.h
|
||||
|
||||
# Doxygen
|
||||
doxygen/
|
||||
|
||||
# west
|
||||
.west/
|
||||
west.yml.bak
|
||||
|
||||
# Editor-specific files
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*~
|
||||
*.bak
|
||||
*.orig
|
||||
|
||||
# Python
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Mac OS X
|
||||
.DS_Store
|
||||
|
||||
# Windows
|
||||
Thumbs.db
|
||||
10
software/apps/can_node/CMakeLists.txt
Normal file
10
software/apps/can_node/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
|
||||
project(can_node LANGUAGES C)
|
||||
|
||||
zephyr_include_directories(../../include)
|
||||
add_subdirectory(../../lib lib)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
||||
2
software/apps/can_node/Kconfig
Normal file
2
software/apps/can_node/Kconfig
Normal file
@@ -0,0 +1,2 @@
|
||||
rsource "../../lib/Kconfig"
|
||||
source "Kconfig.zephyr"
|
||||
5
software/apps/can_node/VERSION
Normal file
5
software/apps/can_node/VERSION
Normal file
@@ -0,0 +1,5 @@
|
||||
VERSION_MAJOR = 0
|
||||
VERSION_MINOR = 0
|
||||
PATCHLEVEL = 1
|
||||
VERSION_TWEAK = 1
|
||||
EXTRAVERSION = devel
|
||||
7
software/apps/can_node/boards/bluepill_f103rb.conf
Normal file
7
software/apps/can_node/boards/bluepill_f103rb.conf
Normal file
@@ -0,0 +1,7 @@
|
||||
# Disable UART console
|
||||
CONFIG_UART_CONSOLE=n
|
||||
|
||||
# Enable RTT console
|
||||
CONFIG_RTT_CONSOLE=y
|
||||
CONFIG_USE_SEGGER_RTT=y
|
||||
CONFIG_SHELL_BACKEND_RTT=y
|
||||
43
software/apps/can_node/boards/bluepill_f103rb.overlay
Normal file
43
software/apps/can_node/boards/bluepill_f103rb.overlay
Normal file
@@ -0,0 +1,43 @@
|
||||
/ {
|
||||
chosen {
|
||||
zephyr,console = &rtt;
|
||||
zephyr,shell = &rtt;
|
||||
zephyr,settings-partition = &storage_partition;
|
||||
};
|
||||
|
||||
rtt: rtt {
|
||||
compatible = "segger,rtt-uart";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
label = "RTT";
|
||||
status = "okay";
|
||||
};
|
||||
};
|
||||
|
||||
&flash0 {
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
/* Application partition starts at the beginning of flash */
|
||||
slot0_partition: partition@0 {
|
||||
label = "image-0";
|
||||
reg = <0x00000000 DT_SIZE_K(120)>;
|
||||
};
|
||||
|
||||
/* Use the last 8K for settings */
|
||||
storage_partition: partition@1E000 {
|
||||
label = "storage";
|
||||
reg = <0x0001E000 DT_SIZE_K(8)>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&usart1 {
|
||||
modbus0 {
|
||||
compatible = "zephyr,modbus-serial";
|
||||
status = "okay";
|
||||
};
|
||||
status = "okay";
|
||||
};
|
||||
47
software/apps/can_node/boards/native_sim.overlay
Normal file
47
software/apps/can_node/boards/native_sim.overlay
Normal file
@@ -0,0 +1,47 @@
|
||||
/ {
|
||||
aliases {
|
||||
vnd7050aj = &vnd7050aj;
|
||||
};
|
||||
|
||||
vnd7050aj: vnd7050aj {
|
||||
compatible = "st,vnd7050aj";
|
||||
status = "okay";
|
||||
|
||||
input0-gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>;
|
||||
input1-gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
|
||||
select0-gpios = <&gpio0 3 GPIO_ACTIVE_HIGH>;
|
||||
select1-gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>;
|
||||
sense-enable-gpios = <&gpio0 5 GPIO_ACTIVE_HIGH>;
|
||||
fault-reset-gpios = <&gpio0 6 GPIO_ACTIVE_LOW>;
|
||||
io-channels = <&adc0 0>;
|
||||
r-sense-ohms = <1500>;
|
||||
k-vcc = <4000>;
|
||||
};
|
||||
|
||||
modbus_uart: uart_2 {
|
||||
compatible = "zephyr,native-pty-uart";
|
||||
status = "okay";
|
||||
current-speed = <19200>;
|
||||
|
||||
modbus0: modbus0 {
|
||||
compatible = "zephyr,modbus-serial";
|
||||
status = "okay";
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
&adc0 {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
ref-internal-mv = <3300>;
|
||||
ref-external1-mv = <5000>;
|
||||
|
||||
channel@0 {
|
||||
reg = <0>;
|
||||
zephyr,gain = "ADC_GAIN_1";
|
||||
zephyr,reference = "ADC_REF_INTERNAL";
|
||||
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
|
||||
zephyr,resolution = <12>;
|
||||
};
|
||||
};
|
||||
48
software/apps/can_node/boards/weact_stm32g431_core.overlay
Normal file
48
software/apps/can_node/boards/weact_stm32g431_core.overlay
Normal file
@@ -0,0 +1,48 @@
|
||||
/ {
|
||||
aliases {
|
||||
vnd7050aj = &vnd7050aj;
|
||||
};
|
||||
|
||||
vnd7050aj: vnd7050aj {
|
||||
compatible = "st,vnd7050aj";
|
||||
status = "okay";
|
||||
|
||||
input0-gpios = <&gpiob 3 GPIO_ACTIVE_HIGH>;
|
||||
input1-gpios = <&gpiob 4 GPIO_ACTIVE_HIGH>;
|
||||
select0-gpios = <&gpiob 0 GPIO_ACTIVE_HIGH>;
|
||||
select1-gpios = <&gpiob 1 GPIO_ACTIVE_HIGH>;
|
||||
sense-enable-gpios = <&gpiob 6 GPIO_ACTIVE_HIGH>;
|
||||
fault-reset-gpios = <&gpiob 5 GPIO_ACTIVE_LOW>;
|
||||
io-channels = <&adc1 1>;
|
||||
r-sense-ohms = <1500>;
|
||||
k-vcc = <4000>;
|
||||
};
|
||||
};
|
||||
|
||||
&adc1 {
|
||||
status = "okay";
|
||||
pinctrl-0 = <&adc1_in1_pa0>;
|
||||
pinctrl-names = "default";
|
||||
st,adc-clock-source = "SYNC";
|
||||
st,adc-prescaler = <4>;
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
||||
channel@1 {
|
||||
reg = <1>;
|
||||
zephyr,gain = "ADC_GAIN_1";
|
||||
zephyr,reference = "ADC_REF_INTERNAL";
|
||||
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
|
||||
zephyr,resolution = <12>;
|
||||
};
|
||||
};
|
||||
|
||||
&usart1 {
|
||||
modbus0 {
|
||||
compatible = "zephyr,modbus-serial";
|
||||
status = "okay";
|
||||
};
|
||||
status = "okay";
|
||||
pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>; // PA9=TX, PA10=RX for Modbus communication
|
||||
pinctrl-names = "default";
|
||||
};
|
||||
16
software/apps/can_node/cdc-acm.overlay
Normal file
16
software/apps/can_node/cdc-acm.overlay
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <zephyr/dt-bindings/gpio/gpio.h>
|
||||
|
||||
&zephyr_udc0 {
|
||||
cdc_acm_uart0: cdc_acm_uart0 {
|
||||
compatible = "zephyr,cdc-acm-uart";
|
||||
|
||||
modbus0 {
|
||||
compatible = "zephyr,modbus-serial";
|
||||
status = "okay";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&usart1 {
|
||||
/delete-node/ modbus0;
|
||||
};
|
||||
88
software/apps/can_node/dts/bindings/st,vnd7050aj.yaml
Normal file
88
software/apps/can_node/dts/bindings/st,vnd7050aj.yaml
Normal file
@@ -0,0 +1,88 @@
|
||||
# Copyright (c) 2024, Eduard Iten
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: |
|
||||
STMicroelectronics VND7050AJ dual-channel high-side driver.
|
||||
This is a GPIO and ADC controlled device.
|
||||
|
||||
compatible: "st,vnd7050aj"
|
||||
|
||||
include: base.yaml
|
||||
|
||||
properties:
|
||||
input0-gpios:
|
||||
type: phandle-array
|
||||
required: true
|
||||
description: GPIO to control output channel 0.
|
||||
|
||||
input1-gpios:
|
||||
type: phandle-array
|
||||
required: true
|
||||
description: GPIO to control output channel 1.
|
||||
|
||||
select0-gpios:
|
||||
type: phandle-array
|
||||
required: true
|
||||
description: GPIO for MultiSense selection bit 0.
|
||||
|
||||
select1-gpios:
|
||||
type: phandle-array
|
||||
required: true
|
||||
description: GPIO for MultiSense selection bit 1.
|
||||
|
||||
sense-enable-gpios:
|
||||
type: phandle-array
|
||||
required: true
|
||||
description: GPIO to enable the MultiSense output.
|
||||
|
||||
fault-reset-gpios:
|
||||
type: phandle-array
|
||||
required: true
|
||||
description: GPIO to reset a latched fault (active-low).
|
||||
|
||||
io-channels:
|
||||
type: phandle-array
|
||||
required: true
|
||||
description: |
|
||||
ADC channel connected to the MultiSense pin. This should be an
|
||||
io-channels property pointing to the ADC controller and channel number.
|
||||
|
||||
r-sense-ohms:
|
||||
type: int
|
||||
required: true
|
||||
description: |
|
||||
Value of the external sense resistor connected from the MultiSense
|
||||
pin to GND, specified in Ohms. This is critical for correct
|
||||
conversion of the analog readings.
|
||||
|
||||
k-factor:
|
||||
type: int
|
||||
default: 1500
|
||||
description: |
|
||||
Factor between PowerMOS and SenseMOS.
|
||||
|
||||
k-vcc:
|
||||
type: int
|
||||
default: 8000
|
||||
description: |
|
||||
VCC sense ratio multiplied by 1000. Used for supply voltage calculation.
|
||||
|
||||
t-sense-0:
|
||||
type: int
|
||||
default: 25
|
||||
description: |
|
||||
Temperature sense reference temperature in degrees Celsius.
|
||||
|
||||
v-sense-0:
|
||||
type: int
|
||||
default: 2070
|
||||
description: |
|
||||
Temperature sense reference voltage in millivolts.
|
||||
|
||||
k-tchip:
|
||||
type: int
|
||||
default: -5500
|
||||
description: |
|
||||
Temperature sense gain coefficient multiplied by 1000.
|
||||
Used for chip temperature calculation.
|
||||
|
||||
4
software/apps/can_node/overlay-cdc-acm.conf
Normal file
4
software/apps/can_node/overlay-cdc-acm.conf
Normal file
@@ -0,0 +1,4 @@
|
||||
CONFIG_USB_DEVICE_STACK=y
|
||||
CONFIG_USB_DEVICE_PRODUCT="Modbus slave node"
|
||||
CONFIG_UART_LINE_CTRL=y
|
||||
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
|
||||
31
software/apps/can_node/prj.conf
Normal file
31
software/apps/can_node/prj.conf
Normal file
@@ -0,0 +1,31 @@
|
||||
# Enable Console and printk for logging
|
||||
CONFIG_CONSOLE=y
|
||||
CONFIG_LOG=y
|
||||
|
||||
# Enable Shell
|
||||
CONFIG_SHELL=y
|
||||
CONFIG_REBOOT=y
|
||||
CONFIG_SHELL_MODBUS=n
|
||||
CONFIG_SHELL_VALVE=y
|
||||
CONFIG_SHELL_SYSTEM=y
|
||||
|
||||
# Enable Settings Subsystem
|
||||
CONFIG_SETTINGS=y
|
||||
CONFIG_SETTINGS_NVS=y
|
||||
CONFIG_NVS=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_MAP=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
|
||||
# Config modbus
|
||||
CONFIG_UART_INTERRUPT_DRIVEN=y
|
||||
CONFIG_MODBUS=y
|
||||
CONFIG_MODBUS_ROLE_SERVER=y
|
||||
CONFIG_MODBUS_LOG_LEVEL_DBG=y
|
||||
|
||||
# enable Valve Driver
|
||||
CONFIG_LIB_VALVE=y
|
||||
CONFIG_LOG_VALVE_LEVEL=4
|
||||
|
||||
# Enable VND7050AJ
|
||||
CONFIG_VND7050AJ=y
|
||||
40
software/apps/can_node/src/main.c
Normal file
40
software/apps/can_node/src/main.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/settings/settings.h>
|
||||
#include <app_version.h>
|
||||
#include <lib/valve.h>
|
||||
#include <lib/vnd7050aj.h>
|
||||
|
||||
LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int rc;
|
||||
LOG_INF("Starting Irrigation System CAN Node, Version %s", APP_VERSION_EXTENDED_STRING);
|
||||
|
||||
/* Initialize settings subsystem */
|
||||
rc = settings_subsys_init();
|
||||
if (rc != 0) {
|
||||
LOG_ERR("Failed to initialize settings subsystem (%d)", rc);
|
||||
return rc;
|
||||
}
|
||||
LOG_INF("Settings subsystem initialized");
|
||||
|
||||
/* Load settings from storage */
|
||||
rc = settings_load();
|
||||
if (rc == 0) {
|
||||
LOG_INF("Settings loaded successfully");
|
||||
} else {
|
||||
LOG_WRN("Failed to load settings (%d)", rc);
|
||||
}
|
||||
|
||||
/* Initialize valve system */
|
||||
rc = valve_init();
|
||||
if (rc != 0) {
|
||||
LOG_ERR("Failed to initialize valve system (%d)", rc);
|
||||
return rc;
|
||||
}
|
||||
LOG_INF("Valve system initialized");
|
||||
|
||||
return 0;
|
||||
}
|
||||
5
software/apps/can_node/sysbuild.conf
Normal file
5
software/apps/can_node/sysbuild.conf
Normal file
@@ -0,0 +1,5 @@
|
||||
SB_CONFIG_BOOTLOADER_MCUBOOT=y
|
||||
SB_CONFIG_MCUBOOT_MODE_SINGLE_APP=y
|
||||
|
||||
CONFIG_LOG=y
|
||||
CONFIG_MCUBOOT_LOG_LEVEL_INF=y
|
||||
1
software/apps/mqtt_gateway
Submodule
1
software/apps/mqtt_gateway
Submodule
Submodule software/apps/mqtt_gateway added at 6e669cfc4e
@@ -7,12 +7,12 @@
|
||||
compatible = "st,vnd7050aj";
|
||||
status = "okay";
|
||||
|
||||
input0-gpios = <&gpiob 7 GPIO_ACTIVE_HIGH>;
|
||||
input1-gpios = <&gpiob 9 GPIO_ACTIVE_HIGH>;
|
||||
select0-gpios = <&gpiob 5 GPIO_ACTIVE_HIGH>;
|
||||
select1-gpios = <&gpiob 6 GPIO_ACTIVE_HIGH>;
|
||||
sense-enable-gpios = <&gpiob 4 GPIO_ACTIVE_HIGH>;
|
||||
fault-reset-gpios = <&gpiob 3 GPIO_ACTIVE_LOW>;
|
||||
input0-gpios = <&gpiob 3 GPIO_ACTIVE_HIGH>;
|
||||
input1-gpios = <&gpiob 4 GPIO_ACTIVE_HIGH>;
|
||||
select0-gpios = <&gpiob 7 GPIO_ACTIVE_HIGH>;
|
||||
select1-gpios = <&gpiob 9 GPIO_ACTIVE_HIGH>;
|
||||
sense-enable-gpios = <&gpiob 6 GPIO_ACTIVE_HIGH>;
|
||||
fault-reset-gpios = <&gpiob 5 GPIO_ACTIVE_LOW>;
|
||||
io-channels = <&adc1 1>;
|
||||
r-sense-ohms = <1500>;
|
||||
k-vcc = <4000>;
|
||||
@@ -45,4 +45,4 @@
|
||||
status = "okay";
|
||||
pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>; // PA9=TX, PA10=RX for Modbus communication
|
||||
pinctrl-names = "default";
|
||||
};
|
||||
};
|
||||
|
||||
106
software/esphome/can.yaml
Normal file
106
software/esphome/can.yaml
Normal file
@@ -0,0 +1,106 @@
|
||||
# ===================================================================
|
||||
# ESPHome Configuration
|
||||
# CAN-Bus Master für ein Bewässerungssystem auf Basis des ESP32-C6
|
||||
#
|
||||
# Version 10: Finale Korrektur der Lambda-Signatur gemäß Dokumentation
|
||||
# ===================================================================
|
||||
|
||||
esphome:
|
||||
name: can-bridge
|
||||
friendly_name: Irrigation can bridge
|
||||
|
||||
esp32:
|
||||
board: esp32-c6-devkitm-1
|
||||
framework:
|
||||
type: esp-idf # Erforderlich für den ESP32-C6
|
||||
|
||||
# --- Netzwerk & Sicherheit ---
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
fast_connect: true
|
||||
|
||||
api:
|
||||
encryption:
|
||||
key: !secret api_key
|
||||
|
||||
ota:
|
||||
platform: esphome
|
||||
password: !secret ota_password
|
||||
|
||||
logger:
|
||||
|
||||
web_server:
|
||||
|
||||
# --- Globale Variablen ---
|
||||
globals:
|
||||
- id: ventil_2_can_state
|
||||
type: int
|
||||
initial_value: '0' # Startet als "geschlossen"
|
||||
|
||||
# --- CAN-Bus Konfiguration ---
|
||||
canbus:
|
||||
- platform: esp32_can
|
||||
id: my_can_bus
|
||||
tx_pin: GPIO5
|
||||
rx_pin: GPIO4
|
||||
bit_rate: 125kbps
|
||||
can_id: 0x000 # Erforderlich, um Parser-Fehler zu beheben.
|
||||
on_frame:
|
||||
# Horcht nur auf die Statusmeldung von Knoten 2 (ID 0x422)
|
||||
- can_id: 0x422
|
||||
then:
|
||||
- lambda: |-
|
||||
if (x.size() < 1) {
|
||||
ESP_LOGW("on_can_frame", "Received empty Frame for ID 0x422");
|
||||
return;
|
||||
}
|
||||
int received_state = x[0];
|
||||
id(ventil_2_can_state) = received_state;
|
||||
ESP_LOGD("on_can_frame", "Received state from Valve 2: %i", received_state);
|
||||
- valve.template.publish:
|
||||
id: ventil_2
|
||||
current_operation: !lambda |-
|
||||
int state = id(ventil_2_can_state);
|
||||
if (state == 2) {
|
||||
return VALVE_OPERATION_OPENING;
|
||||
} else if (state == 3) {
|
||||
return VALVE_OPERATION_CLOSING;
|
||||
} else {
|
||||
return VALVE_OPERATION_IDLE;
|
||||
}
|
||||
|
||||
# --- Home Assistant Entitäten ---
|
||||
valve:
|
||||
- platform: template
|
||||
name: "Ventil 2"
|
||||
id: ventil_2
|
||||
|
||||
# Diese Lambda meldet nur den binären End-Zustand (offen/geschlossen)
|
||||
lambda: |-
|
||||
if (id(ventil_2_can_state) == 0) {
|
||||
return VALVE_CLOSED;
|
||||
} else if (id(ventil_2_can_state) == 1) {
|
||||
return VALVE_OPEN;
|
||||
} else {
|
||||
return NAN;
|
||||
}
|
||||
|
||||
# Aktionen zum Steuern des Ventils
|
||||
open_action:
|
||||
- canbus.send:
|
||||
canbus_id: my_can_bus
|
||||
can_id: 0x210
|
||||
data: [0x02, 0x01]
|
||||
|
||||
close_action:
|
||||
- canbus.send:
|
||||
canbus_id: my_can_bus
|
||||
can_id: 0x210
|
||||
data: [0x02, 0x00]
|
||||
|
||||
stop_action:
|
||||
- canbus.send:
|
||||
canbus_id: my_can_bus
|
||||
can_id: 0x210
|
||||
data: [0x02, 0x03]
|
||||
41
software/include/lib/can_ids.h
Normal file
41
software/include/lib/can_ids.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef CAN_IDS_H
|
||||
#define CAN_IDS_H
|
||||
|
||||
/*
|
||||
CAN ID structure for the irrigation system.
|
||||
PPP FFFF NNNN
|
||||
|
||||
PPP: Priority
|
||||
000: Network segment
|
||||
001: Critical error
|
||||
010: Commands
|
||||
100: Status messages
|
||||
110: measurements
|
||||
111: Info messages
|
||||
|
||||
FFFF: Function
|
||||
0001: Valve Commands
|
||||
0010: Valve States
|
||||
0011: IO Commands
|
||||
0100: IO States
|
||||
0101: Measurements
|
||||
0111: Sysem Functions (e.g. reset, firmware update)
|
||||
|
||||
NNNN: Node ID
|
||||
*/
|
||||
|
||||
#define CAN_ID_PRIORITY_NETWORK 0x000
|
||||
#define CAN_ID_PRIORITY_CRITICAL_ERROR 0x100
|
||||
#define CAN_ID_PRIORITY_COMMANDS 0x200
|
||||
#define CAN_ID_PRIORITY_STATUS 0x400
|
||||
#define CAN_ID_PRIORITY_MEASUREMENTS 0x600
|
||||
#define CAN_ID_PRIORITY_INFO 0x700
|
||||
|
||||
#define CAN_ID_FUNCTION_VALVE_COMMANDS 0x010
|
||||
#define CAN_ID_FUNCTION_VALVE_STATES 0x020
|
||||
#define CAN_ID_FUNCTION_IO_COMMANDS 0x030
|
||||
#define CAN_ID_FUNCTION_IO_STATES 0x040
|
||||
#define CAN_ID_FUNCTION_MEASUREMENTS 0x050
|
||||
#define CAN_ID_FUNCTION_SYSTEM_FUNCTIONS 0x070
|
||||
|
||||
#endif // CAN_IDS_H
|
||||
@@ -191,4 +191,24 @@ uint16_t valve_get_obstacle_threshold_open(void);
|
||||
*/
|
||||
uint16_t valve_get_obstacle_threshold_close(void);
|
||||
|
||||
/**
|
||||
* @brief Callback function called during valve opening with current readings.
|
||||
*
|
||||
* This is a weak function that can be overridden to provide custom handling
|
||||
* of current readings during valve opening operations.
|
||||
*
|
||||
* @param current_ma The current reading in milliamps.
|
||||
*/
|
||||
void valve_current_open_callback(int current_ma);
|
||||
|
||||
/**
|
||||
* @brief Callback function called during valve closing with current readings.
|
||||
*
|
||||
* This is a weak function that can be overridden to provide custom handling
|
||||
* of current readings during valve closing operations.
|
||||
*
|
||||
* @param current_ma The current reading in milliamps.
|
||||
*/
|
||||
void valve_current_close_callback(int current_ma);
|
||||
|
||||
#endif // VALVE_H
|
||||
@@ -1,5 +1,5 @@
|
||||
config LIB_MODBUS_SERVER
|
||||
bool "Enable Modbus Server Library"
|
||||
default y
|
||||
default n
|
||||
help
|
||||
Enable the Modbus Server Library.
|
||||
|
||||
@@ -111,26 +111,75 @@ static int cmd_valve_show(const struct shell *sh, size_t argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_open(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
ARG_UNUSED(argc);
|
||||
ARG_UNUSED(argv);
|
||||
if (valve_get_movement() != VALVE_MOVEMENT_IDLE) {
|
||||
shell_print(sh, "Valve is already moving.");
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
valve_open();
|
||||
shell_print(sh, "Valve is opening.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_close(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
ARG_UNUSED(argc);
|
||||
ARG_UNUSED(argv);
|
||||
if (valve_get_movement() != VALVE_MOVEMENT_IDLE) {
|
||||
shell_print(sh, "Valve is already moving.");
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
valve_close();
|
||||
shell_print(sh, "Valve is closing.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_stop(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
ARG_UNUSED(argc);
|
||||
ARG_UNUSED(argv);
|
||||
if (valve_get_movement() == VALVE_MOVEMENT_IDLE) {
|
||||
shell_print(sh, "Valve is already stopped.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
valve_stop();
|
||||
shell_print(sh, "Valve movement stopped.");
|
||||
return 0;
|
||||
}
|
||||
SHELL_STATIC_SUBCMD_SET_CREATE(sub_valve_settings,
|
||||
SHELL_CMD(set_open_t, NULL, "Set max open time (seconds)", cmd_valve_set_open_t),
|
||||
SHELL_CMD(set_close_t, NULL, "Set max close time (seconds)", cmd_valve_set_close_t),
|
||||
SHELL_CMD(set_end_curr_open,
|
||||
SHELL_CMD(open_t, NULL, "Set max open time (seconds)", cmd_valve_set_open_t),
|
||||
SHELL_CMD(close_t, NULL, "Set max close time (seconds)", cmd_valve_set_close_t),
|
||||
SHELL_CMD(end_curr_open,
|
||||
NULL,
|
||||
"Set end current threshold for opening (mA)",
|
||||
cmd_valve_set_end_curr_open),
|
||||
SHELL_CMD(set_end_curr_close,
|
||||
SHELL_CMD(end_curr_close,
|
||||
NULL,
|
||||
"Set end current threshold for closing (mA)",
|
||||
cmd_valve_set_end_curr_close),
|
||||
SHELL_CMD(set_obstacle_open,
|
||||
SHELL_CMD(obstacle_curr_open,
|
||||
NULL,
|
||||
"Set obstacle threshold for opening (mA)",
|
||||
cmd_valve_set_obstacle_open),
|
||||
SHELL_CMD(set_obstacle_close,
|
||||
SHELL_CMD(obstacle_curr_close,
|
||||
NULL,
|
||||
"Set obstacle threshold for closing (mA)",
|
||||
cmd_valve_set_obstacle_close),
|
||||
SHELL_CMD(show, NULL, "Show valve configuration", cmd_valve_show),
|
||||
|
||||
SHELL_SUBCMD_SET_END);
|
||||
|
||||
SHELL_CMD_REGISTER(valve, &sub_valve_settings, "Valve commands", NULL);
|
||||
SHELL_STATIC_SUBCMD_SET_CREATE(valve_cmds,
|
||||
SHELL_CMD(show, NULL, "Show valve configuration", cmd_valve_show),
|
||||
SHELL_CMD(set, &sub_valve_settings, "Valve settings commands", NULL),
|
||||
SHELL_CMD(open, NULL, "Open the valve", cmd_valve_open),
|
||||
SHELL_CMD(close, NULL, "Close the valve", cmd_valve_close),
|
||||
SHELL_CMD(stop, NULL, "Stop the valve movement", cmd_valve_stop),
|
||||
SHELL_SUBCMD_SET_END);
|
||||
|
||||
SHELL_CMD_REGISTER(valve, &valve_cmds, "Valve commands", NULL);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
config LIB_VALVE
|
||||
bool "Enable Valve Library"
|
||||
default y
|
||||
default n
|
||||
help
|
||||
Enable the Valve Library.
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ static void valve_work_handler(struct k_work *work)
|
||||
|
||||
if (current_movement == VALVE_MOVEMENT_OPENING) {
|
||||
vnd7050aj_read_load_current(vnd7050aj_dev, VALVE_CHANNEL_OPEN, ¤t_ma);
|
||||
LOG_DBG("Current load during opening: %d mA", current_ma);
|
||||
valve_current_open_callback(current_ma);
|
||||
if (current_ma > obstacle_threshold_open_ma) {
|
||||
LOG_ERR(
|
||||
"Obstacle detected during opening (current: %d mA), stopping motor.",
|
||||
@@ -64,7 +64,7 @@ static void valve_work_handler(struct k_work *work)
|
||||
LOG_DBG("Valve finished opening");
|
||||
} else if (current_movement == VALVE_MOVEMENT_CLOSING) {
|
||||
vnd7050aj_read_load_current(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, ¤t_ma);
|
||||
LOG_DBG("Current load during closing: %d mA", current_ma);
|
||||
valve_current_close_callback(current_ma);
|
||||
if (current_ma > obstacle_threshold_close_ma) {
|
||||
LOG_ERR(
|
||||
"Obstacle detected during closing (current: %d mA), stopping motor.",
|
||||
@@ -106,7 +106,8 @@ void movement_timeout_handler(struct k_timer *timer)
|
||||
}
|
||||
vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_OPEN, false);
|
||||
vnd7050aj_set_output_state(vnd7050aj_dev, VALVE_CHANNEL_CLOSE, false);
|
||||
current_state = VALVE_STATE_CLOSED;
|
||||
current_state = VALVE_STATE_OPEN;
|
||||
current_movement = VALVE_MOVEMENT_IDLE;
|
||||
}
|
||||
|
||||
int valve_init(void)
|
||||
@@ -291,3 +292,13 @@ uint16_t valve_get_obstacle_threshold_close(void)
|
||||
{
|
||||
return obstacle_threshold_close_ma;
|
||||
}
|
||||
|
||||
__weak void valve_current_open_callback(int current_ma)
|
||||
{
|
||||
LOG_DBG("Open current callback: %d mA", current_ma);
|
||||
}
|
||||
|
||||
__weak void valve_current_close_callback(int current_ma)
|
||||
{
|
||||
LOG_DBG("Close current callback: %d mA", current_ma);
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
source /home/edi/zephyrproject/.venv/bin/activate && source /home/edi/zephyrproject/zephyr/zephyr-env.sh && rm -r build ;west build -p always -b esp32c6_devkitc/esp32c6/hpcore apps/gateway -D CMAKE_OBJCOPY=/home/edi/zephyr-sdk-0.17.1/riscv64-zephyr-elf/bin/riscv64-zephyr-elf-objcopy;
|
||||
@@ -1,3 +0,0 @@
|
||||
source /home/edi/zephyrproject/.venv/bin/activate && \
|
||||
source /home/edi/zephyrproject/zephyr/zephyr-env.sh && \
|
||||
rm -r build ;west build --sysbuild -p always -b esp32c6_devkitc/esp32c6/hpcore apps/gateway -D CMAKE_OBJCOPY=/home/edi/zephyr-sdk-0.17.1/riscv64-zephyr-elf/bin/riscv64-zephyr-elf-objcopy;
|
||||
Binary file not shown.
Reference in New Issue
Block a user