添加tran命令透传小板命令
添加slave_info命令测试小板通信状态 添加cfginfo命令显示配置文件信息 按键处于按下状态才响应检测命令
This commit is contained in:
@@ -40,6 +40,11 @@
|
||||
2023.12.27
|
||||
添加tcp心跳
|
||||
添加升级小板程序、方案、jwt文件的进度条命令
|
||||
2023.12.29
|
||||
添加tran命令透传小板命令
|
||||
添加slave_info命令测试小板通信状态
|
||||
添加cfginfo命令显示配置文件信息
|
||||
按键处于按下状态才响应检测命令
|
||||
|
||||
|
||||
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
|
||||
|
||||
#define BUILD_DATE "2023-12-27 11:25:22"
|
||||
#define BUILD_DATE "2023-12-29 17:59:05"
|
||||
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"build_date": "2023-12-27 11:25:22",
|
||||
"build_date": "2023-12-29 17:59:05",
|
||||
"hard_version": "MHPZ2_V1.00",
|
||||
"private": [
|
||||
"info.json",
|
||||
|
@@ -124,13 +124,17 @@ int CodecYm::packCheck(myarray data)
|
||||
return ack;
|
||||
}
|
||||
uint8_t chk_a = 0, chk_b = 0;
|
||||
uint8_t rchk_a=uint8_t(data[data.size() - 2]),rchk_b=uint8_t(data[data.size() - 1]);
|
||||
crc::crc16((uint8_t *)data.data(), 2, len + 4, &chk_a, &chk_b);
|
||||
if (chk_a != uint8_t(data[data.size() - 2]) || chk_b != uint8_t(data[data.size() - 1]))
|
||||
if (chk_a != rchk_a || chk_b != rchk_b)
|
||||
{
|
||||
// crc校验不对
|
||||
qWarning("recv data check error:%02x,%02x %02x,%02x", chk_a, chk_b, int(data[data.size() - 2]),
|
||||
int(data[data.size() - 1]));
|
||||
if(rchk_a!=0xff||rchk_b!=0xff){
|
||||
qWarning("recv data check error:%02x,%02x %02x,%02x", chk_a, chk_b, rchk_a, rchk_b);
|
||||
failed=true;
|
||||
}else{
|
||||
qWarning("recv data check is 0xff 0xff,seen as check right.");
|
||||
}
|
||||
}
|
||||
// 保存此流水号
|
||||
cmd_no = data[5] | (data[6] << 8);
|
||||
|
@@ -80,6 +80,7 @@ can_host::can_host(int bitrate)
|
||||
this->bitrate = bitrate;
|
||||
this->can_ = nullptr;
|
||||
timer_ = nullptr;
|
||||
recv_cb_fun=nullptr;
|
||||
}
|
||||
|
||||
can_host::~can_host()
|
||||
@@ -166,8 +167,7 @@ void can_host::freams_sent_cb(qint64 count)
|
||||
void can_host::recv_data_cb()
|
||||
{
|
||||
YeCanID_un frame_id;
|
||||
while (can_->framesAvailable())
|
||||
{
|
||||
while (can_->framesAvailable()){
|
||||
const QCanBusFrame frame = can_->readFrame();
|
||||
frame_id.Exide = frame.frameId();
|
||||
if (frame_id.Exide == 0x000000)
|
||||
@@ -178,49 +178,47 @@ void can_host::recv_data_cb()
|
||||
uint8_t seg_flag = frame_id.yecanid.SegFlag;
|
||||
int seg_num = frame_id.yecanid.SegNum;
|
||||
can_slave &slave = get_slave_by_addr(slave_addr);
|
||||
if (seg_flag == 0x00)
|
||||
{
|
||||
if (seg_flag == 0x00){
|
||||
// 不分段
|
||||
slave.clear();
|
||||
slave.append(payload);
|
||||
qDebug()<<"can recv from:"<<slave_addr<<slave.get_data().toHex(' ');
|
||||
if (dst_addr == 0){
|
||||
if (irq_fun)
|
||||
{
|
||||
if (irq_fun){
|
||||
irq_fun(myarray(slave.get_data()));
|
||||
}
|
||||
if(recv_cb_fun){
|
||||
recv_cb_fun(slave_addr,myarray(slave.get_data()));
|
||||
}
|
||||
emit recv_data_signal(slave_addr,slave.get_data());
|
||||
}
|
||||
}
|
||||
else if (seg_flag == 0x01)
|
||||
{
|
||||
else if (seg_flag == 0x01){
|
||||
// 首段
|
||||
slave.clear();
|
||||
slave.append(payload);
|
||||
}
|
||||
else if (seg_flag == 0x02)
|
||||
{
|
||||
else if (seg_flag == 0x02){
|
||||
// 中段
|
||||
slave.append(payload);
|
||||
}
|
||||
else if (seg_flag == 0x03)
|
||||
{
|
||||
else if (seg_flag == 0x03){
|
||||
// 尾段
|
||||
slave.append(payload);
|
||||
if (slave.get_pack_num() - 1 == seg_num)
|
||||
{
|
||||
if (slave.get_pack_num() - 1 == seg_num){
|
||||
qDebug()<<"can recv from:"<<slave_addr<<slave.get_data().toHex(' ');
|
||||
if (dst_addr == 0){
|
||||
if (irq_fun)
|
||||
{
|
||||
if (irq_fun){
|
||||
irq_fun(myarray(slave.get_data()));
|
||||
}
|
||||
if(recv_cb_fun){
|
||||
recv_cb_fun(slave_addr,myarray(slave.get_data()));
|
||||
}
|
||||
emit recv_data_signal(slave_addr,slave.get_data());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "can data from: " << QString::number(slave_addr, 10) << "recv error";
|
||||
else{
|
||||
qDebug() << "can data from: " << slave_addr << "recv error";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,16 @@
|
||||
#include "QTimer"
|
||||
#include "interface/interface.h"
|
||||
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
typedef std::function<void(int src,myarray data)> can_recv_cb;
|
||||
|
||||
|
||||
|
||||
|
||||
// 定义can从机对象
|
||||
class can_slave : public QObject
|
||||
{
|
||||
@@ -48,7 +58,9 @@ public:
|
||||
void init();
|
||||
int write(myarray data){return 0;}
|
||||
int write(int dst,myarray data);
|
||||
|
||||
void set_irq(can_recv_cb fun){
|
||||
recv_cb_fun=fun;
|
||||
}
|
||||
private:
|
||||
can_slave &get_slave_by_addr(uint8_t addr);
|
||||
void append(uint8_t addr, uint8_t fun_class, QByteArray data);
|
||||
@@ -70,6 +82,7 @@ private:
|
||||
QList<QCanBusFrame> send_packets;
|
||||
QList<QCanBusFrame> recv_packets;
|
||||
QTimer *timer_;
|
||||
can_recv_cb recv_cb_fun;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -9,10 +9,19 @@
|
||||
#include "QFile"
|
||||
#include "base/base.h"
|
||||
#include "cmd_cmdline.h"
|
||||
#include "interface/if_can.h"
|
||||
#include "elec/mystring.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
命令行返回有三种
|
||||
data:[str]
|
||||
rate:[rate%],[str]
|
||||
end:[1:ok/0:failed],[str]
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -26,9 +35,10 @@ void rate_slot(int rate,mystring str)
|
||||
}
|
||||
void end_slot(int addr,int ack,slave_data data)
|
||||
{
|
||||
// ack 0是成功,这里转化为1是成功
|
||||
command *c=command_start();
|
||||
mystring strs("ack:%1,%2");
|
||||
strs=strs.arg(ack).arg("end");
|
||||
strs=strs.arg(!ack).arg("end");
|
||||
c->send(strs.data());
|
||||
}
|
||||
|
||||
@@ -79,8 +89,16 @@ cmdline_export(whos, whos, print device base info.);
|
||||
|
||||
|
||||
|
||||
|
||||
// mcu 相关
|
||||
static void mcu_cmdlines_help(){
|
||||
command *c=command_start();
|
||||
c->send("mcu updata [addrs] [file_name] to updata slave app,for example:\n"
|
||||
"\tmcu updata 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 /home/root/config/checker_slave_app.pkt");
|
||||
c->send("mcu upjwt [addrs] [file_name] to updata jwt app,for example:\n"
|
||||
"\tmcu upjwt 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 /home/root/config/jwt_app.jwt");
|
||||
c->send("mcu scheme [addrs] to updata slave scheme,for example:\n"
|
||||
"\tmcu scheme 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20");
|
||||
}
|
||||
// mcu 升级程序及方案等
|
||||
static void mcu_cmdlines(QList<myarray> args)
|
||||
{
|
||||
command *c=command_start();
|
||||
@@ -89,11 +107,12 @@ static void mcu_cmdlines(QList<myarray> args)
|
||||
check_cfg *ccfg_=check_plan();
|
||||
if(args.size()<2){
|
||||
c->send("cmd len too less.");
|
||||
mcu_cmdlines_help();
|
||||
return ;
|
||||
}
|
||||
if(args.size()>=4){
|
||||
QList<int> addrs=str_to_nums<int>(args[2],',');
|
||||
|
||||
qDebug()<<"addrs:"<<addrs;
|
||||
// 升级小板程序
|
||||
if(args[1]=="updata"){
|
||||
HandleBoardCast *b=new boardcast_updata();
|
||||
@@ -142,6 +161,7 @@ static void mcu_cmdlines(QList<myarray> args)
|
||||
}
|
||||
}else if(args.size()>=3){
|
||||
QList<int> addrs=str_to_nums<int>(args[2],',');
|
||||
qDebug()<<"addrs:"<<addrs;
|
||||
// 升级方案
|
||||
if(args[1]=="scheme"){
|
||||
HandleBoardCast *b=new boardcast_updata_scheme();
|
||||
@@ -150,7 +170,7 @@ static void mcu_cmdlines(QList<myarray> args)
|
||||
qWarning("handle is busy.");
|
||||
}else{
|
||||
b->set_cbfun([=](int addr,int ack,slave_data data){
|
||||
end_slot(addr,!ack,data);
|
||||
end_slot(addr,ack,data);
|
||||
},[=](int rate,mystring str){
|
||||
rate_slot(rate,str);
|
||||
});
|
||||
@@ -165,7 +185,108 @@ static void mcu_cmdlines(QList<myarray> args)
|
||||
}
|
||||
}
|
||||
}
|
||||
cmdline_export(mcu, mcu_cmdlines, mcu cmdlines` input [mcu help] to detail.);
|
||||
cmdline_export(mcu, mcu_cmdlines, mcu cmdlines` input [mcu] for detail.);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int g_slave_addr;
|
||||
static void mcu_tran_cmdlines(QList<myarray> args){
|
||||
command *c=command_start();
|
||||
mycfg *cfg_=syscfg();
|
||||
check_cfg *ccfg_=check_plan();
|
||||
can_host *can_=static_cast<can_host *>(interFaceFind("can"));
|
||||
if(args.size()<3){
|
||||
c->send("cmd len too less.");
|
||||
c->send("tran [addr] [cmdline],for example\n"
|
||||
"\ttran 1 sysinfo");
|
||||
return ;
|
||||
}
|
||||
QList<int> addrs=str_to_nums<int>(args[1],',');
|
||||
qDebug()<<"addrs:"<<addrs;
|
||||
myarray can_d;
|
||||
for(int i=2;i<args.size();i++){
|
||||
can_d.append(' ');
|
||||
can_d.append(args[i]);
|
||||
}
|
||||
g_slave_addr=addrs[0];
|
||||
can_->set_irq([=](int src,myarray data){
|
||||
if(str_is_print_str(data.data(),data.size())!=1){
|
||||
return;
|
||||
}
|
||||
if(g_slave_addr!=src){
|
||||
mystring str="src=%1";
|
||||
str=str.arg(src);
|
||||
c->send(str.toLocal8Bit());
|
||||
}
|
||||
c->send(data);
|
||||
});
|
||||
can_->write(g_slave_addr,can_d);
|
||||
}
|
||||
cmdline_export(tran, mcu_tran_cmdlines, tran cmdline to slave.);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void slave_info(QList<myarray> args){
|
||||
command *c=command_start();
|
||||
prot_slave *slave=protSlave();
|
||||
mycfg *cfg_=syscfg();
|
||||
HandleBoardCast *b=new slave_cmd2();
|
||||
bool ack=slave->set_boardcast_handle(cfg_->calc_slave_addrs(),b);
|
||||
if(ack==false){
|
||||
qWarning("handle is busy.");
|
||||
}else{
|
||||
b->set_cbfun([=](int addr,int ack,slave_data data){
|
||||
myarray r=myarray("data:",5);
|
||||
for(int i=0;i<cfg_->slave_num;i++){
|
||||
myarray t=data[i];
|
||||
if(t.size()>0){
|
||||
r.append("ok,");
|
||||
}else{
|
||||
r.append("ng,");
|
||||
}
|
||||
}
|
||||
c->send(r);
|
||||
},nullptr);
|
||||
b->cmd=0x13;
|
||||
b->start(myarray());
|
||||
}
|
||||
}
|
||||
cmdline_export(slave_info, slave_info, get slave communicat info.);
|
||||
|
||||
|
||||
|
||||
|
||||
#define print_item(str,data){\
|
||||
myarray r=str;\
|
||||
r[r.size()-1]=':';\
|
||||
r.append(data);\
|
||||
c->send(r);\
|
||||
}
|
||||
|
||||
|
||||
static void cfginfo(QList<myarray> args){
|
||||
command *c=command_start();
|
||||
prot_slave *slave=protSlave();
|
||||
mycfg *cfg_=syscfg();
|
||||
print_item("tcp_enable",cfg_->tcp_enable?"true":"false");
|
||||
print_item("server_ip",cfg_->server_ip.toLocal8Bit());
|
||||
print_item("server_port",mystring::number(cfg_->server_port).toLocal8Bit());
|
||||
print_item("local_id",mystring::number(cfg_->local_id).toLocal8Bit());
|
||||
print_item("can_bitrate",mystring::number(cfg_->can_bitrate).toLocal8Bit());
|
||||
print_item("slave_num",mystring::number(cfg_->slave_num).toLocal8Bit());
|
||||
print_item("moter_count",mystring::number(cfg_->moter_count).toLocal8Bit());
|
||||
print_item("uart_bsp",mystring::number(cfg_->uart_bsp).toLocal8Bit());
|
||||
print_item("coder_return_mode",mystring::number(cfg_->coder_return_mode).toLocal8Bit());
|
||||
print_item("slave_addr_start",mystring::number(cfg_->slave_addr_start).toLocal8Bit());
|
||||
}
|
||||
cmdline_export(cfginfo, cfginfo, get cfg info.);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -5,6 +5,7 @@
|
||||
#include "elec/JQ_PSDGenerate.h"
|
||||
#include "elec/JQ_UIDGenerate.h"
|
||||
#include "elec/PSDGenerate.h"
|
||||
#include "prot_cmd/cmd_m4.h"
|
||||
|
||||
|
||||
|
||||
@@ -655,19 +656,24 @@ int cmd_checker_check::dolater(int cmd, myarray data)
|
||||
}
|
||||
}
|
||||
};
|
||||
myarray moter_cmd=moter_ctrl("down");
|
||||
if(moter_cmd.size()==0){
|
||||
busy=0;
|
||||
qWarning("moter failed.");
|
||||
}else{
|
||||
m4->set_irq_fun(moter_down_cb_fun,"moter down");
|
||||
emit send_to_m4_signal(moter_cmd);
|
||||
}
|
||||
slave_acked.clear();
|
||||
for(int i=0;i<addrs.size();i++){
|
||||
slave_acked.append(myarray());
|
||||
}
|
||||
slave_acked_num=0;
|
||||
myarray moter_cmd=moter_ctrl("down");
|
||||
if(moter_cmd.size()==0){
|
||||
busy=0;
|
||||
qWarning("moter failed.");
|
||||
return 1;
|
||||
}
|
||||
if(cmd_m4_key_pressed()!=0){
|
||||
m4->set_irq_fun(moter_down_cb_fun,"moter down");
|
||||
emit send_to_m4_signal(moter_cmd);
|
||||
}else{
|
||||
qWarning("key not pressed,check will not start.");
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -43,7 +43,15 @@ void cmd_m4_init()
|
||||
// },"key press");
|
||||
}
|
||||
|
||||
|
||||
// 返回1则按键已按下
|
||||
int cmd_m4_key_pressed()
|
||||
{
|
||||
if(g_self.key_pressed){
|
||||
return 1;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -7,6 +7,7 @@
|
||||
void cmd_m4_init();
|
||||
|
||||
|
||||
int cmd_m4_key_pressed();
|
||||
|
||||
|
||||
|
||||
|
@@ -8,6 +8,7 @@
|
||||
#include "QDebug"
|
||||
#include "elec/elec_judge.h"
|
||||
#include "QDateTime"
|
||||
#include "prot_cmd/cmd_m4.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -96,19 +97,24 @@ int selfdev_check::dolater(int cmd, myarray data)
|
||||
}
|
||||
}
|
||||
};
|
||||
myarray moter_cmd=moter_ctrl("down");
|
||||
if(moter_cmd.size()==0){
|
||||
busy=0;
|
||||
qWarning("moter failed.");
|
||||
}else{
|
||||
m4->set_irq_fun(moter_down_cb_fun,"moter down");
|
||||
emit send_to_m4_signal(moter_cmd);
|
||||
}
|
||||
slave_acked.clear();
|
||||
for(int i=0;i<cfg->slave_num;i++){
|
||||
slave_acked.append(myarray());
|
||||
}
|
||||
slave_acked_num=0;
|
||||
myarray moter_cmd=moter_ctrl("down");
|
||||
if(moter_cmd.size()==0){
|
||||
busy=0;
|
||||
qWarning("moter failed.");
|
||||
return 1;
|
||||
}
|
||||
if(cmd_m4_key_pressed()!=0){
|
||||
m4->set_irq_fun(moter_down_cb_fun,"moter down");
|
||||
emit send_to_m4_signal(moter_cmd);
|
||||
}else{
|
||||
qWarning("key not pressed,check will not start.");
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -581,7 +581,7 @@ int slave_cmd::dolater(int cmd, myarray data)
|
||||
|
||||
int slave_cmd2::start(myarray data)
|
||||
{
|
||||
int timeout=5000;
|
||||
int timeout=3500;
|
||||
busy=1;
|
||||
// 这里addr是bit数,用16进制打印
|
||||
qDebug("addr 0x%06X start ,timeout=%d",addr,timeout);
|
||||
|
Reference in New Issue
Block a user