5 changed files with 242 additions and 1 deletions
-
130components/taojingchi_screen/taojingchi_screen_service.cpp
-
38components/taojingchi_screen/taojingchi_screen_service.hpp
-
57components/zprotocol_helper/micro_computer_module_device_script_cmder_paser.cpp
-
16components/zprotocol_helper/micro_computer_module_device_script_cmder_paser.hpp
-
2components/zprotocols/zcancmder_v2
@ -0,0 +1,130 @@ |
|||||
|
|
||||
|
#include "taojingchi_screen_service.hpp"
|
||||
|
|
||||
|
#include <stdarg.h>
|
||||
|
#include <stdlib.h>
|
||||
|
#include <string.h>
|
||||
|
|
||||
|
#include "sdk\components\zprotocols\errorcode\errorcode.hpp"
|
||||
|
using namespace iflytop; |
||||
|
|
||||
|
#define TAG "CMD"
|
||||
|
|
||||
|
void TaoJingChiScreenService::tx(const char* data, int len) { m_uart->tx((uint8_t*)data, len); } |
||||
|
void TaoJingChiScreenService::txcmd(const char* fmt, ...) { |
||||
|
va_list args; |
||||
|
va_start(args, fmt); |
||||
|
int ret = vsnprintf(m_txbuf, sizeof(m_txbuf) - 3, fmt, args); |
||||
|
va_end(args); |
||||
|
if (ret < 0) return; |
||||
|
|
||||
|
m_txbuf[ret] = 0xff; |
||||
|
m_txbuf[ret + 1] = 0xff; |
||||
|
m_txbuf[ret + 2] = 0xff; |
||||
|
|
||||
|
tx(m_txbuf, ret + 3); |
||||
|
} |
||||
|
|
||||
|
void TaoJingChiScreenService::initialize(UART_HandleTypeDef* huart, uint32_t rxbufsize, on_cmdline_cmd_t on_cmdline_cmd, on_taojingchi_screen_rx_t on_taojingchi_screen_rx) { |
||||
|
m_rxbufsize = rxbufsize; |
||||
|
|
||||
|
m_uart = new ZUART(); |
||||
|
ZASSERT(m_uart != NULL); |
||||
|
|
||||
|
ZUART::cfg_t cfg; |
||||
|
cfg.huart = huart; |
||||
|
cfg.rxbuffersize = rxbufsize; |
||||
|
cfg.rxovertime_ms = 10; |
||||
|
cfg.name = "TaoJingChiScreenService"; |
||||
|
|
||||
|
m_on_cmdline_cmd = on_cmdline_cmd; |
||||
|
m_on_taojingchi_screen_rx = on_taojingchi_screen_rx; |
||||
|
|
||||
|
rxbuf = new char[rxbufsize + 1]; |
||||
|
ZASSERT(rxbuf != NULL); |
||||
|
|
||||
|
m_uart->initialize(&cfg); |
||||
|
ZASSERT(m_uart->startRxIt()); |
||||
|
m_uart->setrxcb([this](uint8_t* data, size_t len) { |
||||
|
if (m_dataisready) { |
||||
|
return; |
||||
|
} |
||||
|
memcpy(rxbuf, data, len); |
||||
|
rxbuf[len] = '\0'; |
||||
|
m_rxsize = len; |
||||
|
m_dataisready = true; |
||||
|
// on data ,in irq context
|
||||
|
}); |
||||
|
} |
||||
|
// int32_t getAckInt32Val(int index) {
|
||||
|
// int32_t getAckInt32Num() {
|
||||
|
void TaoJingChiScreenService::prase_cmd(char* input, int inputlen, int32_t& argc, char* argv[]) { |
||||
|
for (int i = 0; input[i] == 0 || i < inputlen; i++) { |
||||
|
if (input[i] == ' ' || input[i] == '\r' || input[i] == '\n') { |
||||
|
input[i] = 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
int j = 0; |
||||
|
for (int i = 0; input[i] == 0 || i < inputlen; i++) { |
||||
|
if (input[i] != 0 && j == 0) { |
||||
|
argv[argc++] = &input[i]; |
||||
|
j = 1; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if (input[i] == 0 && j == 1) { |
||||
|
j = 0; |
||||
|
continue; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
void TaoJingChiScreenService::schedule() { |
||||
|
if (!m_dataisready) return; |
||||
|
char* cmdstart = nullptr; |
||||
|
int32_t packetlen = 0; |
||||
|
int32_t packetstartoff = 0; |
||||
|
|
||||
|
for (int i = 0; i < m_rxsize - 2;) { |
||||
|
if (cmdstart == nullptr) { |
||||
|
cmdstart = &rxbuf[i]; |
||||
|
packetstartoff = i; |
||||
|
i++; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
/**
|
||||
|
* @brief 憬쑨넴葵累관棺 |
||||
|
*/ |
||||
|
if (rxbuf[i] == 0xff && rxbuf[i + 1] == 0xff && rxbuf[i + 2] == 0xff) { |
||||
|
packetlen = i - packetstartoff; |
||||
|
ZLOGI(TAG, "RX TaoJingChiPacket %d", packetlen); |
||||
|
cmdstart = nullptr; |
||||
|
packetstartoff = 0; |
||||
|
i += 3; //
|
||||
|
continue; |
||||
|
} |
||||
|
/**
|
||||
|
* @brief 降唐葵累관棺 |
||||
|
*/ |
||||
|
else if (rxbuf[i] == 0xff && rxbuf[i + 1] == 0xff && rxbuf[i + 2] == 0xfa) { |
||||
|
packetlen = i - packetstartoff; |
||||
|
rxbuf[i] = 0; |
||||
|
ZLOGI(TAG, "RX PrivatePacket %s(%d)", cmdstart, packetlen); |
||||
|
int32_t argc = 0; |
||||
|
char* argv[10] = {0}; |
||||
|
prase_cmd(cmdstart, packetlen, argc, argv); |
||||
|
|
||||
|
if (m_on_cmdline_cmd) { |
||||
|
m_on_cmdline_cmd(argv[0], argc - 1, (const char**)&argv[1]); |
||||
|
} |
||||
|
cmdstart = nullptr; |
||||
|
packetstartoff = 0; |
||||
|
i += 3; //
|
||||
|
continue; |
||||
|
} |
||||
|
i++; |
||||
|
} |
||||
|
|
||||
|
m_dataisready = false; |
||||
|
} |
@ -0,0 +1,38 @@ |
|||||
|
#pragma once
|
||||
|
#include <map>
|
||||
|
#include <string>
|
||||
|
|
||||
|
#include "sdk/os/zos.hpp"
|
||||
|
#include "sdk\components\zprotocols\errorcode\errorcode.hpp"
|
||||
|
|
||||
|
namespace iflytop { |
||||
|
using namespace std; |
||||
|
|
||||
|
typedef function<void(const char* cmd, int32_t paramN, const char** paraV)> on_cmdline_cmd_t; |
||||
|
typedef function<void(uint8_t* data, size_t len)> on_taojingchi_screen_rx_t; |
||||
|
|
||||
|
class TaoJingChiScreenService { |
||||
|
public: |
||||
|
ZUART* m_uart; |
||||
|
char* rxbuf; |
||||
|
int32_t m_rxsize = 0; |
||||
|
uint32_t m_rxbufsize; |
||||
|
bool m_dataisready = false; |
||||
|
char cmdcache[100] = {0}; |
||||
|
char m_txbuf[1024] = {0}; |
||||
|
|
||||
|
on_cmdline_cmd_t m_on_cmdline_cmd; |
||||
|
on_taojingchi_screen_rx_t m_on_taojingchi_screen_rx; |
||||
|
|
||||
|
public: |
||||
|
void initialize(UART_HandleTypeDef* huart, uint32_t rxbufsize, on_cmdline_cmd_t on_cmdline_cmd, on_taojingchi_screen_rx_t on_taojingchi_screen_rx); |
||||
|
void schedule(); |
||||
|
|
||||
|
void txcmd(const char* fmt, ...); |
||||
|
|
||||
|
private: |
||||
|
void tx(const char* data, int len); |
||||
|
void prase_cmd(char* input, int inputlen, int32_t& argc, char* argv[]); |
||||
|
}; |
||||
|
|
||||
|
} // namespace iflytop
|
@ -0,0 +1,57 @@ |
|||||
|
#include "micro_computer_module_device_script_cmder_paser.hpp"
|
||||
|
#include <stdlib.h>
|
||||
|
|
||||
|
#include "sdk/os/zos.hpp"
|
||||
|
using namespace iflytop; |
||||
|
using namespace std; |
||||
|
|
||||
|
#define TAG "CMD"
|
||||
|
|
||||
|
void MicroComputerModuleDeviceScriptCmderPaser::initialize(ICmdParser* cancmder, ZModuleDeviceManager* deviceManager) { |
||||
|
ZModuleDeviceScriptCmderPaser::initialize(cancmder, deviceManager); |
||||
|
m_cmdParser = cancmder; |
||||
|
m_deviceManager = deviceManager; |
||||
|
|
||||
|
cancmder->regCMD("dumpconfig", "dumpconfig (mid)", 1, [this](int32_t paramN, const char* paraV[], ICmdParserACK* ack) { //
|
||||
|
ack->ecode = 0; |
||||
|
|
||||
|
uint16_t moduleId = atoi(paraV[0]); |
||||
|
int32_t configval = 0; |
||||
|
int32_t ecode = 0; |
||||
|
|
||||
|
#define DUMP_CONFIG(tag, configid) \
|
||||
|
ecode = m_deviceManager->module_get_param(moduleId, configid, &configval); \ |
||||
|
if (ecode != 0) { \ |
||||
|
ZLOGI(TAG, "%30s :%d", tag, configval); \ |
||||
|
} |
||||
|
|
||||
|
DUMP_CONFIG("motor_x_shift", kcfg_motor_x_shift); |
||||
|
DUMP_CONFIG("motor_y_shift", kcfg_motor_y_shift); |
||||
|
DUMP_CONFIG("motor_z_shift", kcfg_motor_z_shift); |
||||
|
DUMP_CONFIG("motor_x_shaft", kcfg_motor_x_shaft); |
||||
|
DUMP_CONFIG("motor_y_shaft", kcfg_motor_y_shaft); |
||||
|
DUMP_CONFIG("motor_z_shaft", kcfg_motor_z_shaft); |
||||
|
DUMP_CONFIG("motor_x_one_circle_pulse", kcfg_motor_x_one_circle_pulse); |
||||
|
DUMP_CONFIG("motor_y_one_circle_pulse", kcfg_motor_y_one_circle_pulse); |
||||
|
DUMP_CONFIG("motor_z_one_circle_pulse", kcfg_motor_z_one_circle_pulse); |
||||
|
DUMP_CONFIG("motor_default_velocity", kcfg_motor_default_velocity); |
||||
|
DUMP_CONFIG("motor_default_acc", kcfg_motor_default_acc); |
||||
|
DUMP_CONFIG("motor_default_dec", kcfg_motor_default_dec); |
||||
|
DUMP_CONFIG("motor_default_break_dec", kcfg_motor_default_break_dec); |
||||
|
DUMP_CONFIG("motor_run_to_zero_max_x_d", kcfg_motor_run_to_zero_max_x_d); |
||||
|
DUMP_CONFIG("motor_run_to_zero_max_y_d", kcfg_motor_run_to_zero_max_y_d); |
||||
|
DUMP_CONFIG("motor_run_to_zero_max_z_d", kcfg_motor_run_to_zero_max_z_d); |
||||
|
DUMP_CONFIG("motor_look_zero_edge_max_x_d", kcfg_motor_look_zero_edge_max_x_d); |
||||
|
DUMP_CONFIG("motor_look_zero_edge_max_y_d", kcfg_motor_look_zero_edge_max_y_d); |
||||
|
DUMP_CONFIG("motor_look_zero_edge_max_z_d", kcfg_motor_look_zero_edge_max_z_d); |
||||
|
DUMP_CONFIG("motor_run_to_zero_speed", kcfg_motor_run_to_zero_speed); |
||||
|
DUMP_CONFIG("motor_run_to_zero_dec", kcfg_motor_run_to_zero_dec); |
||||
|
DUMP_CONFIG("motor_look_zero_edge_speed", kcfg_motor_look_zero_edge_speed); |
||||
|
DUMP_CONFIG("motor_look_zero_edge_dec", kcfg_motor_look_zero_edge_dec); |
||||
|
DUMP_CONFIG("cfg_stepmotor_ihold", k_cfg_stepmotor_ihold); |
||||
|
DUMP_CONFIG("cfg_stepmotor_irun", k_cfg_stepmotor_irun); |
||||
|
DUMP_CONFIG("cfg_stepmotor_iholddelay", k_cfg_stepmotor_iholddelay); |
||||
|
DUMP_CONFIG("cfg_xyrobot_robot_type", k_cfg_xyrobot_robot_type); |
||||
|
|
||||
|
}); |
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
#pragma once
|
||||
|
#include "sdk\components\zprotocols\zcancmder_v2\zmodule_device_script_cmder_paser.hpp"
|
||||
|
namespace iflytop { |
||||
|
using namespace std; |
||||
|
|
||||
|
class MicroComputerModuleDeviceScriptCmderPaser : public ZModuleDeviceScriptCmderPaser { |
||||
|
ICmdParser* m_cmdParser = nullptr; |
||||
|
ZModuleDeviceManager* m_deviceManager; |
||||
|
|
||||
|
public: |
||||
|
void initialize(ICmdParser* cancmder, ZModuleDeviceManager* deviceManager); |
||||
|
}; |
||||
|
|
||||
|
} // namespace iflytop
|
||||
|
|
||||
|
|
@ -1 +1 @@ |
|||||
Subproject commit 850402ceaf70cdcabc1773af1ef4bc7019cada36 |
|
||||
|
Subproject commit aef6c931d2a0b215c46c19fb22bb7b1892b36dd9 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue