Compare commits
6 Commits
5208f1370d
...
project-re
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c1ff0c4df | |||
| 3f0d5a76c6 | |||
| 10a770de59 | |||
| 1b0519aadf | |||
| e429a0874d | |||
| 3a05c80b25 |
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"fwu.h": "c"
|
||||||
|
}
|
||||||
|
}
|
||||||
6
lib/fwu/CMakeLists.txt
Normal file
6
lib/fwu/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
|
project(fwu)
|
||||||
|
|
||||||
|
target_sources(fwu PRIVATE src/fwu.c)
|
||||||
|
target_include_directories(fwu PUBLIC include)
|
||||||
6
lib/modbus_server/CMakeLists.txt
Normal file
6
lib/modbus_server/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
|
project(modbus_server)
|
||||||
|
|
||||||
|
target_sources(modbus_server PRIVATE src/modbus_server.c)
|
||||||
|
target_include_directories(modbus_server PUBLIC include)
|
||||||
6
lib/valve/CMakeLists.txt
Normal file
6
lib/valve/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
|
project(valve)
|
||||||
|
|
||||||
|
target_sources(valve PRIVATE src/valve.c)
|
||||||
|
target_include_directories(valve PUBLIC include)
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.13.1)
|
|
||||||
|
|
||||||
project(software)
|
|
||||||
|
|
||||||
add_subdirectory(modules/modbus_server)
|
|
||||||
add_subdirectory(modules/valve)
|
|
||||||
add_subdirectory(modules/fwu)
|
|
||||||
add_subdirectory(apps/stm32g431_tests)
|
|
||||||
1
software/Kconfig
Normal file
1
software/Kconfig
Normal file
@@ -0,0 +1 @@
|
|||||||
|
rsource "lib/Kconfig"
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
|
|
||||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
|
||||||
project(hello_world)
|
|
||||||
|
|
||||||
target_sources(app PRIVATE src/main.c)
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
|
|
||||||
CONFIG_CONSOLE=y
|
|
||||||
CONFIG_LOG=y
|
|
||||||
CONFIG_UART_CONSOLE=y
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#include <zephyr/kernel.h>
|
|
||||||
#include <zephyr/sys/printk.h>
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
printk("Hello World! %s\n", CONFIG_BOARD);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,27 +1,8 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
# Point BOARD_ROOT and DTS_ROOT to the 'software' directory, which contains 'boards'.
|
|
||||||
list(APPEND BOARD_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
|
|
||||||
|
|
||||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
project(slave_node)
|
|
||||||
|
|
||||||
list(APPEND KCONFIG_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../../modules/modbus_server/Kconfig)
|
project(slave_node LANGUAGES C)
|
||||||
list(APPEND KCONFIG_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../../modules/valve/Kconfig)
|
zephyr_include_directories(../../include)
|
||||||
list(APPEND KCONFIG_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../../modules/fwu/Kconfig)
|
add_subdirectory(../../lib lib)
|
||||||
|
target_sources(app PRIVATE src/main.c)
|
||||||
target_include_directories(app PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../modules/valve/include
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../modules/modbus_server/include
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../modules/fwu/include
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add the source files from the app and the libraries
|
|
||||||
target_sources(app PRIVATE
|
|
||||||
src/main.c
|
|
||||||
src/shell_modbus.c
|
|
||||||
src/shell_system.c
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../modules/valve/src/valve.c
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../modules/modbus_server/src/modbus_server.c
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../modules/fwu/src/fwu.c
|
|
||||||
)
|
|
||||||
2
software/apps/slave_node/Kconfig
Normal file
2
software/apps/slave_node/Kconfig
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
rsource "../../lib/Kconfig"
|
||||||
|
source "Kconfig.zephyr"
|
||||||
@@ -3,4 +3,5 @@ CONFIG_UART_CONSOLE=n
|
|||||||
|
|
||||||
# Enable RTT console
|
# Enable RTT console
|
||||||
CONFIG_RTT_CONSOLE=y
|
CONFIG_RTT_CONSOLE=y
|
||||||
CONFIG_USE_SEGGER_RTT=y
|
CONFIG_USE_SEGGER_RTT=y
|
||||||
|
CONFIG_SHELL_BACKEND_RTT=y
|
||||||
10
software/apps/slave_node/cdc-acm.overlay
Normal file
10
software/apps/slave_node/cdc-acm.overlay
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
&zephyr_udc0 {
|
||||||
|
cdc_acm_uart0: cdc_acm_uart0 {
|
||||||
|
compatible = "zephyr,cdc-acm-uart";
|
||||||
|
|
||||||
|
modbus0 {
|
||||||
|
compatible = "zephyr,modbus-serial";
|
||||||
|
status = "okay";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
4
software/apps/slave_node/overlay-cdc-acm.conf
Normal file
4
software/apps/slave_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
|
||||||
@@ -4,7 +4,6 @@ CONFIG_LOG=y
|
|||||||
|
|
||||||
# Enable Shell
|
# Enable Shell
|
||||||
CONFIG_SHELL=y
|
CONFIG_SHELL=y
|
||||||
CONFIG_SHELL_BACKEND_RTT=y
|
|
||||||
CONFIG_REBOOT=y
|
CONFIG_REBOOT=y
|
||||||
|
|
||||||
# Enable Settings Subsystem
|
# Enable Settings Subsystem
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/settings/settings.h>
|
#include <zephyr/settings/settings.h>
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
#include <modbus_server.h>
|
#include <lib/modbus_server.h>
|
||||||
#include <valve.h>
|
#include <lib/valve.h>
|
||||||
#include <fwu.h>
|
#include <lib/fwu.h>
|
||||||
|
|
||||||
LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
|
LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
|
|
||||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
|
||||||
project(stm32g431_tests)
|
|
||||||
|
|
||||||
target_sources(app PRIVATE src/main.c)
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
|
|
||||||
CONFIG_CONSOLE=y
|
|
||||||
CONFIG_LOG=y
|
|
||||||
CONFIG_UART_CONSOLE=y
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#include <zephyr/kernel.h>
|
|
||||||
#include <zephyr/sys/printk.h>
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
printk("Hello World! %s\n", CONFIG_BOARD);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
5
software/lib/CMakeLists.txt
Normal file
5
software/lib/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
add_subdirectory_ifdef(CONFIG_LIB_FWU fwu)
|
||||||
|
add_subdirectory_ifdef(CONFIG_LIB_MODBUS_SERVER modbus_server)
|
||||||
|
add_subdirectory_ifdef(CONFIG_LIB_VALVE valve)
|
||||||
|
add_subdirectory_ifdef(CONFIG_SHELL_SYSTEM shell_system)
|
||||||
|
add_subdirectory_ifdef(CONFIG_SHELL_MODBUS shell_modbus)
|
||||||
8
software/lib/Kconfig
Normal file
8
software/lib/Kconfig
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
menu "Irrigation system software libraries"
|
||||||
|
|
||||||
|
rsource "fwu/Kconfig"
|
||||||
|
rsource "modbus_server/Kconfig"
|
||||||
|
rsource "valve/Kconfig"
|
||||||
|
rsource "shell_system/Kconfig"
|
||||||
|
rsource "shell_modbus/Kconfig"
|
||||||
|
endmenu
|
||||||
1
software/lib/fwu/CMakeLists.txt
Normal file
1
software/lib/fwu/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
zephyr_library_sources(fwu.c)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
config FWU
|
config LIB_FWU
|
||||||
bool "Enable Firmware Update Library"
|
bool "Enable Firmware Update Library"
|
||||||
default y
|
default y
|
||||||
help
|
help
|
||||||
Enable the Firmware Update module.
|
Enable the Firmware Update Library.
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#include "fwu.h"
|
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/sys/crc.h>
|
#include <zephyr/sys/crc.h>
|
||||||
#include <zephyr/sys/byteorder.h>
|
#include <zephyr/sys/byteorder.h>
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
|
#include <lib/fwu.h>
|
||||||
|
|
||||||
LOG_MODULE_REGISTER(fwu, LOG_LEVEL_INF);
|
LOG_MODULE_REGISTER(fwu, LOG_LEVEL_INF);
|
||||||
|
|
||||||
1
software/lib/modbus_server/CMakeLists.txt
Normal file
1
software/lib/modbus_server/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
zephyr_library_sources(modbus_server.c)
|
||||||
5
software/lib/modbus_server/Kconfig
Normal file
5
software/lib/modbus_server/Kconfig
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
config LIB_MODBUS_SERVER
|
||||||
|
bool "Enable Modbus Server Library"
|
||||||
|
default y
|
||||||
|
help
|
||||||
|
Enable the Modbus Server Library.
|
||||||
@@ -1,19 +1,23 @@
|
|||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include "modbus_server.h"
|
#include <zephyr/drivers/uart.h>
|
||||||
|
#include <zephyr/device.h>
|
||||||
#include <zephyr/modbus/modbus.h>
|
#include <zephyr/modbus/modbus.h>
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
#include <zephyr/settings/settings.h>
|
#include <zephyr/settings/settings.h>
|
||||||
#include <zephyr/sys/reboot.h>
|
#include <zephyr/sys/reboot.h>
|
||||||
#include "valve.h"
|
#include <lib/modbus_server.h>
|
||||||
#include "fwu.h"
|
#include <lib/valve.h>
|
||||||
|
#include <lib/fwu.h>
|
||||||
|
|
||||||
|
#include <zephyr/usb/usb_device.h>
|
||||||
|
|
||||||
LOG_MODULE_REGISTER(modbus_server, LOG_LEVEL_INF);
|
LOG_MODULE_REGISTER(modbus_server, LOG_LEVEL_INF);
|
||||||
|
|
||||||
static int modbus_iface;
|
static int modbus_iface;
|
||||||
static struct modbus_iface_param server_param = {
|
static struct modbus_iface_param server_param = {
|
||||||
.mode = MODBUS_MODE_RTU,
|
.mode = MODBUS_MODE_RTU,
|
||||||
.server = { .user_cb = NULL, .unit_id = 1 },
|
.server = {.user_cb = NULL, .unit_id = 1},
|
||||||
.serial = { .baud = 19200, .parity = UART_CFG_PARITY_NONE },
|
.serial = {.baud = 19200, .parity = UART_CFG_PARITY_NONE},
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint16_t watchdog_timeout_s = 0;
|
static uint16_t watchdog_timeout_s = 0;
|
||||||
@@ -27,7 +31,8 @@ static void watchdog_timer_handler(struct k_timer *timer_id)
|
|||||||
|
|
||||||
static inline void reset_watchdog(void)
|
static inline void reset_watchdog(void)
|
||||||
{
|
{
|
||||||
if (watchdog_timeout_s > 0) {
|
if (watchdog_timeout_s > 0)
|
||||||
|
{
|
||||||
k_timer_start(&watchdog_timer, K_SECONDS(watchdog_timeout_s), K_NO_WAIT);
|
k_timer_start(&watchdog_timer, K_SECONDS(watchdog_timeout_s), K_NO_WAIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,11 +40,20 @@ static inline void reset_watchdog(void)
|
|||||||
static int holding_reg_rd(uint16_t addr, uint16_t *reg)
|
static int holding_reg_rd(uint16_t addr, uint16_t *reg)
|
||||||
{
|
{
|
||||||
reset_watchdog();
|
reset_watchdog();
|
||||||
switch (addr) {
|
switch (addr)
|
||||||
case REG_HOLDING_MAX_OPENING_TIME_S: *reg = valve_get_max_open_time(); break;
|
{
|
||||||
case REG_HOLDING_MAX_CLOSING_TIME_S: *reg = valve_get_max_close_time(); break;
|
case REG_HOLDING_MAX_OPENING_TIME_S:
|
||||||
case REG_HOLDING_WATCHDOG_TIMEOUT_S: *reg = watchdog_timeout_s; break;
|
*reg = valve_get_max_open_time();
|
||||||
default: *reg = 0; break;
|
break;
|
||||||
|
case REG_HOLDING_MAX_CLOSING_TIME_S:
|
||||||
|
*reg = valve_get_max_close_time();
|
||||||
|
break;
|
||||||
|
case REG_HOLDING_WATCHDOG_TIMEOUT_S:
|
||||||
|
*reg = watchdog_timeout_s;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
*reg = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -47,11 +61,21 @@ static int holding_reg_rd(uint16_t addr, uint16_t *reg)
|
|||||||
static int holding_reg_wr(uint16_t addr, uint16_t reg)
|
static int holding_reg_wr(uint16_t addr, uint16_t reg)
|
||||||
{
|
{
|
||||||
reset_watchdog();
|
reset_watchdog();
|
||||||
switch (addr) {
|
switch (addr)
|
||||||
|
{
|
||||||
case REG_HOLDING_VALVE_COMMAND:
|
case REG_HOLDING_VALVE_COMMAND:
|
||||||
if (reg == 1) { valve_open(); }
|
if (reg == 1)
|
||||||
else if (reg == 2) { valve_close(); }
|
{
|
||||||
else if (reg == 0) { valve_stop(); }
|
valve_open();
|
||||||
|
}
|
||||||
|
else if (reg == 2)
|
||||||
|
{
|
||||||
|
valve_close();
|
||||||
|
}
|
||||||
|
else if (reg == 0)
|
||||||
|
{
|
||||||
|
valve_stop();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case REG_HOLDING_MAX_OPENING_TIME_S:
|
case REG_HOLDING_MAX_OPENING_TIME_S:
|
||||||
valve_set_max_open_time(reg);
|
valve_set_max_open_time(reg);
|
||||||
@@ -61,23 +85,27 @@ static int holding_reg_wr(uint16_t addr, uint16_t reg)
|
|||||||
break;
|
break;
|
||||||
case REG_HOLDING_WATCHDOG_TIMEOUT_S:
|
case REG_HOLDING_WATCHDOG_TIMEOUT_S:
|
||||||
watchdog_timeout_s = reg;
|
watchdog_timeout_s = reg;
|
||||||
if (watchdog_timeout_s > 0) {
|
if (watchdog_timeout_s > 0)
|
||||||
|
{
|
||||||
LOG_INF("Watchdog enabled with %u s timeout.", watchdog_timeout_s);
|
LOG_INF("Watchdog enabled with %u s timeout.", watchdog_timeout_s);
|
||||||
reset_watchdog();
|
reset_watchdog();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
LOG_INF("Watchdog disabled.");
|
LOG_INF("Watchdog disabled.");
|
||||||
k_timer_stop(&watchdog_timer);
|
k_timer_stop(&watchdog_timer);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case REG_HOLDING_DEVICE_RESET:
|
case REG_HOLDING_DEVICE_RESET:
|
||||||
if (reg == 1) {
|
if (reg == 1)
|
||||||
|
{
|
||||||
LOG_WRN("Modbus reset command received. Rebooting...");
|
LOG_WRN("Modbus reset command received. Rebooting...");
|
||||||
sys_reboot(SYS_REBOOT_WARM);
|
sys_reboot(SYS_REBOOT_WARM);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fwu_handler(addr, reg);
|
fwu_handler(addr, reg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -86,13 +114,32 @@ static int input_reg_rd(uint16_t addr, uint16_t *reg)
|
|||||||
{
|
{
|
||||||
reset_watchdog();
|
reset_watchdog();
|
||||||
uint32_t uptime_s = k_uptime_get_32() / 1000;
|
uint32_t uptime_s = k_uptime_get_32() / 1000;
|
||||||
switch (addr) {
|
switch (addr)
|
||||||
case REG_INPUT_VALVE_STATE_MOVEMENT: *reg = (valve_get_movement() << 8) | (valve_get_state() & 0xFF); break;
|
{
|
||||||
case REG_INPUT_MOTOR_CURRENT_MA: *reg = valve_get_motor_current(); break;
|
case REG_INPUT_VALVE_STATE_MOVEMENT:
|
||||||
case REG_INPUT_UPTIME_SECONDS_LOW: *reg = (uint16_t)(uptime_s & 0xFFFF); break;
|
*reg = (valve_get_movement() << 8) | (valve_get_state() & 0xFF);
|
||||||
case REG_INPUT_UPTIME_SECONDS_HIGH: *reg = (uint16_t)(uptime_s >> 16); break;
|
break;
|
||||||
case REG_INPUT_FWU_LAST_CHUNK_CRC: *reg = fwu_get_last_chunk_crc(); break;
|
case REG_INPUT_MOTOR_CURRENT_MA:
|
||||||
default: *reg = 0; break;
|
*reg = valve_get_motor_current();
|
||||||
|
break;
|
||||||
|
case REG_INPUT_UPTIME_SECONDS_LOW:
|
||||||
|
*reg = (uint16_t)(uptime_s & 0xFFFF);
|
||||||
|
break;
|
||||||
|
case REG_INPUT_UPTIME_SECONDS_HIGH:
|
||||||
|
*reg = (uint16_t)(uptime_s >> 16);
|
||||||
|
break;
|
||||||
|
case REG_INPUT_FWU_LAST_CHUNK_CRC:
|
||||||
|
*reg = fwu_get_last_chunk_crc();
|
||||||
|
break;
|
||||||
|
case REG_INPUT_FIRMWARE_VERSION_MAJOR_MINOR:
|
||||||
|
*reg = (0 << 8) | 0;
|
||||||
|
break;
|
||||||
|
case REG_INPUT_FIRMWARE_VERSION_PATCH:
|
||||||
|
*reg = 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
*reg = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -109,8 +156,28 @@ int modbus_server_init(void)
|
|||||||
{
|
{
|
||||||
k_timer_init(&watchdog_timer, watchdog_timer_handler, NULL);
|
k_timer_init(&watchdog_timer, watchdog_timer_handler, NULL);
|
||||||
const char iface_name[] = {DEVICE_DT_NAME(MODBUS_NODE)};
|
const char iface_name[] = {DEVICE_DT_NAME(MODBUS_NODE)};
|
||||||
|
#if DT_NODE_HAS_COMPAT(DT_PARENT(MODBUS_NODE), zephyr_cdc_acm_uart)
|
||||||
|
const struct device *const dev = DEVICE_DT_GET(DT_PARENT(MODBUS_NODE));
|
||||||
|
uint32_t dtr = 0;
|
||||||
|
|
||||||
|
if (!device_is_ready(dev) || usb_enable(NULL))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!dtr)
|
||||||
|
{
|
||||||
|
uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr);
|
||||||
|
k_sleep(K_MSEC(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INF("Client connected to server on %s", dev->name);
|
||||||
|
#endif
|
||||||
modbus_iface = modbus_iface_get_by_name(iface_name);
|
modbus_iface = modbus_iface_get_by_name(iface_name);
|
||||||
if (modbus_iface < 0) { return modbus_iface; }
|
if (modbus_iface < 0)
|
||||||
|
{
|
||||||
|
return modbus_iface;
|
||||||
|
}
|
||||||
server_param.server.user_cb = &mbs_cbs;
|
server_param.server.user_cb = &mbs_cbs;
|
||||||
return modbus_init_server(modbus_iface, server_param);
|
return modbus_init_server(modbus_iface, server_param);
|
||||||
}
|
}
|
||||||
@@ -122,12 +189,13 @@ int modbus_reconfigure(uint32_t baudrate, uint8_t unit_id)
|
|||||||
|
|
||||||
int ret = modbus_init_server(modbus_iface, server_param);
|
int ret = modbus_init_server(modbus_iface, server_param);
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0)
|
||||||
settings_save_one("modbus/baudrate", &baudrate, sizeof(baudrate));
|
{
|
||||||
settings_save_one("modbus/unit_id", &unit_id, sizeof(unit_id));
|
settings_save_one("modbus/baudrate", &baudrate, sizeof(baudrate));
|
||||||
}
|
settings_save_one("modbus/unit_id", &unit_id, sizeof(unit_id));
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t modbus_get_baudrate(void) { return server_param.serial.baud; }
|
uint32_t modbus_get_baudrate(void) { return server_param.serial.baud; }
|
||||||
1
software/lib/shell_modbus/CMakeLists.txt
Normal file
1
software/lib/shell_modbus/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
zephyr_library_sources(shell_modbus.c)
|
||||||
5
software/lib/shell_modbus/Kconfig
Normal file
5
software/lib/shell_modbus/Kconfig
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
config SHELL_MODBUS
|
||||||
|
bool "Enable Shell Modbus"
|
||||||
|
default y
|
||||||
|
help
|
||||||
|
Enable the modnbus shell commands.
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <zephyr/shell/shell.h>
|
#include <zephyr/shell/shell.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <modbus_server.h>
|
#include <lib/modbus_server.h>
|
||||||
#include <valve.h>
|
#include <lib/valve.h>
|
||||||
|
|
||||||
static int cmd_modbus_set_baud(const struct shell *sh, size_t argc, char **argv)
|
static int cmd_modbus_set_baud(const struct shell *sh, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
1
software/lib/shell_system/CMakeLists.txt
Normal file
1
software/lib/shell_system/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
zephyr_library_sources(shell_system.c)
|
||||||
5
software/lib/shell_system/Kconfig
Normal file
5
software/lib/shell_system/Kconfig
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
config SHELL_SYSTEM
|
||||||
|
bool "Enable Shell System"
|
||||||
|
default y
|
||||||
|
help
|
||||||
|
Enable the system commands.
|
||||||
1
software/lib/valve/CMakeLists.txt
Normal file
1
software/lib/valve/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
zephyr_library_sources(valve.c)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
config VALVE
|
config LIB_VALVE
|
||||||
bool "Enable Valve Library"
|
bool "Enable Valve Library"
|
||||||
default y
|
default y
|
||||||
help
|
help
|
||||||
Enable the Valve module.
|
Enable the Valve Library.
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "valve.h"
|
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/settings/settings.h>
|
#include <zephyr/settings/settings.h>
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
|
#include <lib/valve.h>
|
||||||
|
|
||||||
LOG_MODULE_REGISTER(valve, LOG_LEVEL_INF);
|
LOG_MODULE_REGISTER(valve, LOG_LEVEL_INF);
|
||||||
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.13.1)
|
|
||||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
|
||||||
|
|
||||||
project(fwu)
|
|
||||||
|
|
||||||
target_sources(app PRIVATE src/fwu.c)
|
|
||||||
target_include_directories(app PUBLIC include)
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.13.1)
|
|
||||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
|
||||||
|
|
||||||
project(modbus_server)
|
|
||||||
|
|
||||||
target_sources(app PRIVATE src/modbus_server.c)
|
|
||||||
target_include_directories(app PUBLIC include)
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
config MODBUS_SERVER
|
|
||||||
bool "Enable Modbus Server Library"
|
|
||||||
default y
|
|
||||||
help
|
|
||||||
Enable the Modbus Server module.
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.13.1)
|
|
||||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
|
||||||
|
|
||||||
project(valve)
|
|
||||||
|
|
||||||
target_sources(app PRIVATE src/valve.c)
|
|
||||||
target_include_directories(app PUBLIC include)
|
|
||||||
Reference in New Issue
Block a user