4 changed files with 95 additions and 6 deletions
-
8components/modbus/modbus_client.cpp
-
4components/modbus/modbus_processer.hpp
-
63components/sub_modbus_module/sub_modbus_board_initer.cpp
-
26components/sub_modbus_module/sub_modbus_board_initer.hpp
@ -0,0 +1,63 @@ |
|||
#include "sub_modbus_board_initer.hpp"
|
|||
|
|||
//
|
|||
#include <stdio.h>
|
|||
#include <string.h>
|
|||
|
|||
#include "project_configs.h"
|
|||
|
|||
using namespace iflytop; |
|||
#define TAG "main"
|
|||
|
|||
extern DMA_HandleTypeDef PC_DEBUG_UART_DMA_HANDLER; |
|||
extern DMA_HandleTypeDef PC_MODBUS_UART_DMA_HANDLER; |
|||
|
|||
class UARTSender : public ZIUartSender { |
|||
UART_HandleTypeDef* m_huart; |
|||
|
|||
public: |
|||
void init(UART_HandleTypeDef* huart) { m_huart = huart; } |
|||
virtual void send(const uint8_t* data, size_t len) { HAL_UART_Transmit(m_huart, (uint8_t*)data, len, 1000); } |
|||
}; |
|||
|
|||
void SubModbusBoardIniter::init(int deviceId, //
|
|||
function<void()> subModuleIniter, //
|
|||
on_reg_read_t regreadcb, //
|
|||
on_reg_write_t regwritecb) { |
|||
chip_cfg_t chipcfg = {}; |
|||
chipcfg.us_dleay_tim = &PC_SYS_DELAY_US_TIMER; |
|||
chipcfg.tim_irq_scheduler_tim = &PC_SYS_TIM_IRQ_SCHEDULER_TIMER; |
|||
chipcfg.huart = &PC_DEBUG_UART; |
|||
chipcfg.debuglight = PC_DEBUG_LIGHT_GPIO; |
|||
|
|||
chip_init(&chipcfg); |
|||
|
|||
zos_cfg_t zoscfg; |
|||
zos_init(&zoscfg); |
|||
|
|||
ZLOGI(TAG, "boardId:%d", deviceId); |
|||
|
|||
if (subModuleIniter) { |
|||
subModuleIniter(); |
|||
} |
|||
|
|||
static ZUARTDmaReceiver dmaUartReceiver; |
|||
static ZUARTDmaReceiver::hardware_config_t cfg = { |
|||
.huart = &PC_MODBUS_UART, |
|||
.dma_rx = &PC_MODBUS_UART_DMA_HANDLER, |
|||
.rxbuffersize = PC_MODBUS_UART_RX_BUF_SIZE, |
|||
.rxovertime_ms = 1, |
|||
}; |
|||
dmaUartReceiver.initialize(&cfg); |
|||
|
|||
static UARTSender uartSender; |
|||
uartSender.init(&PC_MODBUS_UART); |
|||
|
|||
ModulebusClient::Inst()->init(&dmaUartReceiver, &uartSender, deviceId, regreadcb, regwritecb); |
|||
} |
|||
void SubModbusBoardIniter::loop() { |
|||
while (true) { |
|||
OSDefaultSchduler::getInstance()->loop(); |
|||
ModulebusClient::Inst()->loop(); |
|||
} |
|||
} |
@ -0,0 +1,26 @@ |
|||
#pragma once
|
|||
#include "sdk/os/zos.hpp"
|
|||
#include "sdk\components\cmdscheduler\cmd_scheduler_v2.hpp"
|
|||
#include "sdk\components\hardware\uart\zuart_dma_receiver.hpp"
|
|||
#include "sdk\components\zcancmder\zcan_board_module.hpp"
|
|||
#include "sdk\components\zcancmder\zcanreceiver.hpp"
|
|||
#include "sdk\components\zprotocol_helper\micro_computer_module_device_script_cmder_paser.hpp"
|
|||
#include "sdk\components\zprotocols\zcancmder_v2\protocol_event_bus_sender.hpp"
|
|||
#include "sdk\components\zprotocols\zcancmder_v2\protocol_parser.hpp"
|
|||
#include "sdk\components\zprotocols\zcancmder_v2\zmodule_device_manager.hpp"
|
|||
//
|
|||
#include "sdk\components\modbus\modbus_client.hpp"
|
|||
|
|||
namespace iflytop { |
|||
|
|||
class SubModbusBoardIniter { |
|||
public: |
|||
void init(int deviceId, //
|
|||
function<void()> subModuleIniter, //
|
|||
on_reg_read_t regreadcb, //
|
|||
on_reg_write_t regwritecb); |
|||
void loop(); |
|||
|
|||
private: |
|||
}; |
|||
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue