You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

157 lines
5.1 KiB

#include "main.hpp"
#include <stddef.h>
#include <stdio.h>
#include "main.h"
#include "project.hpp"
//
// #include "sdk/components/single_axis_motor_control_v2/single_axis_motor_control_v2.hpp"
#include "sdk/components/iflytop_can_slave_modules/idcard_reader_service.hpp"
#include "sdk/components/single_axis_motor_control/single_axis_motor_control.hpp"
#include "sdk/hal/zhal.hpp"
#include "sdk\components\iflytop_can_slave_modules\io_control_service.hpp"
#include "sdk\components\iflytop_can_slave_v1\iflytop_can_slave.hpp"
#include "sdk\components\m3078\m3078_code_scaner.hpp"
#include "sdk\components\tmc\ic\ztmc4361A.hpp"
#include "sdk\components\tmc\ic\ztmc5130.hpp"
//
#include "hardware.hpp"
#include "sdk\components\huacheng_sensor\dp600_pressure_sensor.hpp"
#include "sdk\components\string_utils.hpp"
#include "sdk\components\zcan_module\huacheng_pressure_sensor.hpp"
#include "sdk\components\zcan_module\zcan_basic_order_module.hpp"
#include "sdk\components\zcan_module\zcan_pump_ctrl_module.hpp"
#include "sdk\components\zcan_module\zcan_trigle_warning_light_ctl_module.hpp"
#define TAG "main"
namespace iflytop {
Main gmain;
};
using namespace iflytop;
void dumphexdata(uint8_t *data, int32_t len) {
for (int32_t i = 0; i < len; i++) {
printf("%02X ", data[i]);
}
printf("\n");
}
/*******************************************************************************
* GLOBAL *
*******************************************************************************/
IflytopCanProtocolStackProcesser m_protocolStack;
Hardware m_hardware;
ZGPIO debuglight;
ZCanReceiver m_canReceiver;
/*******************************************************************************
* MESSAGE_HANDLER *
*******************************************************************************/
/**
* @brief 处理CAN接收到消息
*/
void Main::onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len) {
// ZLOGI(TAG, "onRceivePacket from %d %d", rxbuf->id, len);
static uint8_t rxdata[1024] = {0};
memset(rxdata, 0, sizeof(rxdata));
Cmdheader_t *cmdheader = (Cmdheader_t *)packet;
bool match = false;
int32_t receipt_size = 0;
int32_t ecode = m_hardware.process_rx_packet(Hardware::from_where_t::kcan, packet, len, rxdata, receipt_size, match);
if (match) {
if (ecode != 0) {
m_canReceiver.sendErrorAck(cmdheader, ecode);
} else {
m_canReceiver.sendAck(cmdheader, rxdata, receipt_size);
}
}
}
/**
* @brief 处理串口接收到的消息
*/
static void processUARTEachLine(char *packet, size_t len) {
static uint8_t rxdata[1024] = {0};
int32_t receipt_size = 0;
bool match = false;
memset(rxdata, 0, sizeof(rxdata));
//
int32_t bytelen = 0;
uint8_t *hexbytes = StringUtils::hex_str_to_bytes((char *)packet, len, bytelen);
if (hexbytes == NULL) {
ZLOGE(TAG, "hex_str_to_bytes failed");
return;
}
dumphexdata(hexbytes, bytelen);
int32_t ecode = m_hardware.process_rx_packet(Hardware::kuart, hexbytes, bytelen, rxdata, receipt_size, match);
if (match) {
printf("match\n");
if (ecode < 0) {
printf("ecode :%d\n", ecode);
return;
}
dumphexdata(rxdata, receipt_size);
}
printf("\n");
}
static void processUartRX(uint8_t *packet, size_t len) {
for (size_t i = 0; i < len; i++) {
if (packet[i] == '\n' || packet[i] == '\r') {
packet[i] = '\0';
}
}
for (size_t i = 0; i < len; i++) {
if (i == 0) {
processUARTEachLine((char *)packet, strlen((char *)packet));
} else if (packet[i - 1] == '\0' && packet[i] != '\0') {
processUARTEachLine((char *)packet + i, strlen((char *)packet + i));
}
}
}
/*******************************************************************************
* MAIN *
*******************************************************************************/
void Main::run() {
ZHALCORE::cfg_t oscfg = {
.delayhtim = &DELAY_US_TIMER,
.debuguart = &DEBUG_UART,
};
ZHALCORE::getInstance()->initialize(oscfg);
ZLOGI(TAG, "little_disinfection_liquid_path_control:%s", VERSION);
debuglight.initAsOutput(DEBUG_LIGHT_GPIO, ZGPIO::kMode_nopull, false, false);
ZHAL_CORE_REG(200, { debuglight.toggleState(); });
m_hardware.initialize(DEVICE_ID);
static ZUART uartreceiver;
static ZUART::cfg_t uartreceiver_cfg = {
.name = "uartreceiver",
.huart = &DEBUG_UART,
.rxbuffersize = 512,
.rxovertime_ms = 30,
};
uartreceiver.initialize(&uartreceiver_cfg);
uartreceiver.setrxcb([this](uint8_t *data, size_t len) { processUartRX(data, len); });
uartreceiver.startRxIt();
ZCanReceiver::CFG *cfg = m_canReceiver.createCFG(DEVICE_ID);
m_canReceiver.init(cfg);
m_canReceiver.registerListener(this);
ZLOGI(TAG, "init done");
while (1) {
ZHALCORE::getInstance()->loop();
m_hardware.loop();
uartreceiver.forceCchedule();
}
}