From 2fb109f2acd47df514210d59ed1c85fef250e92d Mon Sep 17 00:00:00 2001 From: ranchuan Date: Mon, 29 Jan 2024 18:05:23 +0800 Subject: [PATCH] =?UTF-8?q?=20=20=E6=B7=BB=E5=8A=A0=E5=AF=B9hmi=E5=B1=8F?= =?UTF-8?q?=E5=B9=95=E7=9A=84=E6=94=AF=E6=8C=81=EF=BC=8C=E8=B5=8B=E7=A0=81?= =?UTF-8?q?=E4=BB=AA=E6=8C=89=E9=94=AE=E6=8C=89=E4=B8=8B=E6=97=B6=E5=8F=91?= =?UTF-8?q?=E9=80=81=E8=B5=8B=E7=A0=81=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ReadMe.txt | 3 +- base/beep.h | 2 +- checker_host.pro | 2 + complier_info.h | 2 +- info.json | 2 +- interface/codec_m4.cpp | 2 +- interface/if_uart.cpp | 8 ++- main.cpp | 4 ++ prot/prot_m4.cpp | 2 +- prot/prot_pc.cpp | 27 ++++++++++ prot/prot_pc.h | 2 +- prot_cmd/cmd_cmdline.cpp | 47 ++++++++++++++++- prot_cmd/cmd_coder.h | 26 ++++++++++ prot_cmd/cmd_hmi_coder.cpp | 103 +++++++++++++++++++++++++++++++++++++ prot_cmd/cmd_hmi_coder.h | 69 +++++++++++++++++++++++++ prot_cmd/cmd_m4.cpp | 39 ++++++++++++++ prot_cmd/cmd_pc.cpp | 21 +++----- 17 files changed, 338 insertions(+), 23 deletions(-) create mode 100644 prot_cmd/cmd_hmi_coder.cpp create mode 100644 prot_cmd/cmd_hmi_coder.h diff --git a/ReadMe.txt b/ReadMe.txt index e12e1a5..eb1cc9e 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -64,7 +64,8 @@ 自动检测指令0x44不读取流水号 解决新赋码指令回复指令不对的问题 解决tcp不上报心跳的问题 - +2024.1.29 + 添加对hmi屏幕的支持,赋码仪按键按下时发送赋码请求 diff --git a/base/beep.h b/base/beep.h index 5e082a3..4ffd99f 100644 --- a/base/beep.h +++ b/base/beep.h @@ -17,9 +17,9 @@ public: void start(); // 用户程序调用这个函数开启蜂鸣器 void set_beep(int delay_on_ms,int delay_off_ms,int ticks); + bool set_state(bool state); private: bool get_state(); - bool set_state(bool state); private: bool is_run; bool state; diff --git a/checker_host.pro b/checker_host.pro index ff846f1..4f94ffe 100644 --- a/checker_host.pro +++ b/checker_host.pro @@ -48,6 +48,7 @@ SOURCES += \ prot/prot_slave.cpp \ prot_cmd/cmd_cmdline.cpp \ prot_cmd/cmd_coder.cpp \ + prot_cmd/cmd_hmi_coder.cpp \ prot_cmd/cmd_m4.cpp \ prot_cmd/cmd_pc.cpp \ prot_cmd/cmd_slave.cpp \ @@ -82,6 +83,7 @@ HEADERS += \ prot/prot_slave.h \ prot_cmd/cmd_cmdline.h \ prot_cmd/cmd_coder.h \ + prot_cmd/cmd_hmi_coder.h \ prot_cmd/cmd_m4.h \ prot_cmd/cmd_pc.h \ prot_cmd/cmd_slave.h \ diff --git a/complier_info.h b/complier_info.h index bb6537d..6e3c80a 100644 --- a/complier_info.h +++ b/complier_info.h @@ -6,7 +6,7 @@ -#define BUILD_DATE "2024-01-18 15:53:38" +#define BUILD_DATE "2024-01-29 17:53:35" diff --git a/info.json b/info.json index 13de7e3..4e215bf 100644 --- a/info.json +++ b/info.json @@ -1,5 +1,5 @@ { - "build_date": "2024-01-18 15:53:38", + "build_date": "2024-01-29 17:53:35", "hard_version": "MHPZ2_V1.00", "private": [ "info.json", diff --git a/interface/codec_m4.cpp b/interface/codec_m4.cpp index d76ba9a..769c9e0 100644 --- a/interface/codec_m4.cpp +++ b/interface/codec_m4.cpp @@ -69,7 +69,7 @@ myarray codec_m4::decode(int &srcAddr, int &dstAddr, int &cmd, myarray data) // qDebug("m4 recv:%s",data.toHex(' ').data()); if (packCheck(data)) { - return data.mid(2); + return data.mid(2,data[1]); } return myarray(); } diff --git a/interface/if_uart.cpp b/interface/if_uart.cpp index 678fd12..17e808e 100644 --- a/interface/if_uart.cpp +++ b/interface/if_uart.cpp @@ -60,7 +60,13 @@ InterFace *if_uart_hmi() static InterFace *if_ = nullptr; if (if_ == nullptr) { - if_ = new if_uart("/dev/ttySTM1", 115200); + char *dev=nullptr; + if(syscfg()->device_type=="hmi_coder"){ + dev="/dev/ttySTM3"; + }else{ + dev="/dev/ttySTM1"; + } + if_ = new if_uart(dev, 115200); // QTimer::singleShot(0, if_, &InterFace::init); if_->init(); } diff --git a/main.cpp b/main.cpp index 815503b..ab25dc3 100644 --- a/main.cpp +++ b/main.cpp @@ -15,6 +15,7 @@ #include "prot_cmd/cmd_m4.h" #include "base/beep.h" #include "prot_cmd/keep_live.h" +#include "prot_cmd/cmd_hmi_coder.h" @@ -54,5 +55,8 @@ int main(int argc, char *argv[]) m4->del_irq_fun(nullptr,"moterinited"); },"moterinited"); m4->send_data_slot("moterinit"); + + hmicoder_init(); + return app.exec(); } diff --git a/prot/prot_m4.cpp b/prot/prot_m4.cpp index e4d9e1c..0b4c854 100644 --- a/prot/prot_m4.cpp +++ b/prot/prot_m4.cpp @@ -18,7 +18,7 @@ void prot_m4::init() recv_data.remove(0,pack_len); if(wait>0) wait--; if(exe_cb_fun(data)==false){ - qWarning("can not find cb fun with:\"%s\"",data.data()); + // qWarning("can not find cb fun with:\"%s\"",data.data()); } if(send_list.size()>0){ if_->write(send_list.takeFirst()); diff --git a/prot/prot_pc.cpp b/prot/prot_pc.cpp index eaa907a..289b4e6 100644 --- a/prot/prot_pc.cpp +++ b/prot/prot_pc.cpp @@ -23,6 +23,33 @@ HandlePc *handlePcFind(int cmd) } + + + +QList handlePcList() +{ + extern const int __start_protpc; + extern const int __stop_protpc; + handlepc_def *start = (handlepc_def *)&__start_protpc; + handlepc_def *end = (handlepc_def *)&__stop_protpc; + handlepc_def *item = 0; + QList list; + for (item = start; item < end; item++) + { + if (item != nullptr) + { + list.append(item->cmd); + } + } + return list; +} + + + + + + + void ProtPc::init() { if(syscfg()->tcp_enable==false){ diff --git a/prot/prot_pc.h b/prot/prot_pc.h index d17e50e..9407a0a 100644 --- a/prot/prot_pc.h +++ b/prot/prot_pc.h @@ -78,7 +78,7 @@ protpc_export(0x30, get_ChidlPc); - +QList handlePcList(); diff --git a/prot_cmd/cmd_cmdline.cpp b/prot_cmd/cmd_cmdline.cpp index 1f86e73..d76e12e 100644 --- a/prot_cmd/cmd_cmdline.cpp +++ b/prot_cmd/cmd_cmdline.cpp @@ -12,6 +12,7 @@ #include "interface/if_can.h" #include "elec/mystring.h" #include "prot/prot_pc.h" +#include "elec/elec_judge.h" @@ -291,9 +292,17 @@ cmdline_export(cfginfo, cfginfo, get cfg info.); void cmd_line_slots::auto_test(){ + ProtPc *pc=protPc(); + check_cfg *ccfg_=check_plan(); if(syscfg()->auto_test>0){ - ProtPc *pc=protPc(); - pc->send_data_slot(0x37,myarray(1,char(0))); + if(syscfg()->device_type=="checker"){ + pc->send_data_slot(0x37,myarray(1,char(0))); + }else{ + int chip=elec_extract_chip(ccfg_->get_plan_id()); + QByteArray r; + r.append(char(chip)); + pc->send_data_slot(0x8b,r); + } } } @@ -385,3 +394,37 @@ cmdline_export(cfgset, cfgset, set cfg info.); +static QListsort(QList in){ + int temp; + int num=in.size(); + for(int i=0;iin[j]){ + in[i]=in[j]; + in[j]=temp; + temp=in[i]; + } + } + } + return in; +} + +static void pclist(QList args){ + command *c=command_start(); + ProtPc *pc=protPc(); + QList list=handlePcList(); + mystring s; + list=sort(list); + for (int i=0;isend(s.data()); +} +cmdline_export(pclist, pclist, print pc cmd list.); + + + + + + diff --git a/prot_cmd/cmd_coder.h b/prot_cmd/cmd_coder.h index 578914c..e6e154c 100644 --- a/prot_cmd/cmd_coder.h +++ b/prot_cmd/cmd_coder.h @@ -37,6 +37,32 @@ */ +#define coder_led_yellow(){\ + prot_m4 *m4=protM4();\ + m4->send_data_slot("ledg on");\ + m4->send_data_slot("ledr on");\ +} + +#define coder_led_green(){\ + prot_m4 *m4=protM4();\ + m4->send_data_slot("ledg on");\ + m4->send_data_slot("ledr off");\ +} + +#define coder_led_red(){\ + prot_m4 *m4=protM4();\ + m4->send_data_slot("ledg off");\ + m4->send_data_slot("ledr on");\ +} + +#define coder_led_off(){\ + prot_m4 *m4=protM4();\ + m4->send_data_slot("ledg off");\ + m4->send_data_slot("ledr off");\ +} + + + typedef struct{ const char *name; int task_id; diff --git a/prot_cmd/cmd_hmi_coder.cpp b/prot_cmd/cmd_hmi_coder.cpp new file mode 100644 index 0000000..f2afe7c --- /dev/null +++ b/prot_cmd/cmd_hmi_coder.cpp @@ -0,0 +1,103 @@ +#include "cmd_hmi_coder.h" +#include "interface/interface.h" +#include +#include "prot_cmd/cmd_coder.h" +#include "base/beep.h" + +#define send_to_hmi(fmt,...){\ + QString str=QString::asprintf(fmt,##__VA_ARGS__);\ + send_data(toGbk(str));\ + } + + +static void send_data(QByteArray d); + +QByteArray toGbk(QString str){ + QTextCodec *utf8 = QTextCodec::codecForName("UTF-8"); + QTextCodec::setCodecForLocale(utf8); + QTextCodec* gbk = QTextCodec::codecForName("gbk"); + //utf8 -> gbk + //1. utf8 -> unicode + QString strUnicode= utf8->toUnicode(str.toLocal8Bit().data()); + //2. unicode -> gbk, 得到QByteArray + QByteArray gb_bytes= gbk->fromUnicode(strUnicode); + return gb_bytes; +} + +void hmicoder_init(){ + mycfg *cfg_=syscfg(); + send_data(toGbk(QString::asprintf("page pagelogin"))); + send_data(toGbk(QString("tVersion.txt=\"%1\"").arg(cfg_->soft_version))); +} + +myarray cmd_hmicoder_check::cmd_pc_to_slave(myarray data) +{ + mycfg *cfg_=syscfg(); + myarray d; + // 检测模式0,返回原始检测结果 + d.insert(0,uint8_t(0)); + coder_led_yellow(); + send_to_hmi("page pagecheck"); + for(int i=0;islave_num;i++){ + send_to_hmi("p%d.pic=%d",i+1,i+1); + send_to_hmi("t%d.txt=\"\"",i+1); + } + return d; +} + +// 把从机回复的数据转化为上位机能理解的格式 +myarray cmd_hmicoder_check::ret_slave_to_pc(QList data) +{ + check_cfg *ccfg_=check_plan(); + uint8_t err_flag=0; + for (int i=0;icheck_scheme(),ccfg_->get_check_task_num(), + d,d+8,d+16,&marerr,&suberr); + if(marerr==0){ + marerr=slave_err; + } + err_flag|=marerr; + send_data(toGbk(QString("t%1.txt=\"[%2]%3\"").arg(addr).arg(suberr).arg(ccfg_->get_err_string(marerr)))); + } + if(err_flag){ + coder_led_red(); + Beep()->set_beep(300,300,3); + }else{ + coder_led_green(); + } + return myarray(); +} +// pc回复命令,返回0不回复 +int cmd_hmicoder_check::cmd_pc_ret(){ + return 0; +} + +static void send_data(QByteArray d){ + InterFace *if_=interFaceFind("uart_hmi"); + myarray da; + da.append(d); + da.append(3,char(0xff)); + if(if_!=nullptr){ + if_->write(da); + } +} + + +static HandlePc *get_hmicoder_check(){ + return new cmd_hmicoder_check(); +} +// 赋码仪按键动作命令 +protpc_export(0xe0, get_hmicoder_check); + + + + + + diff --git a/prot_cmd/cmd_hmi_coder.h b/prot_cmd/cmd_hmi_coder.h new file mode 100644 index 0000000..13f1355 --- /dev/null +++ b/prot_cmd/cmd_hmi_coder.h @@ -0,0 +1,69 @@ +#ifndef CMD_HMI_CODER_H +#define CMD_HMI_CODER_H + + +#include +#include "prot_cmd/cmd_pc.h" +#include "base/check_cfg.h" +#include "elec/elec_judge.h" +#include "QByteArray" + + + + +// 赋码仪检测命令 +class cmd_hmicoder_check : public selfdev_runtask +{ + Q_OBJECT +public: + cmd_hmicoder_check():selfdev_runtask(){ + } + // pc指令转从机 + myarray cmd_pc_to_slave(myarray data); + // pc指令生成从机列表 + QList cmd_pc_to_addrs(myarray data){ + QList addr_list; + addrs=data[0]; + mode=data[1]; + if(addrs<=0||addrs>20){ + return addr_list; + } + for(int i=0;i data); +protected: + int addrs; + int mode; +}; + + +void hmicoder_init(); + + + + +#endif // CMD_HMI_CODER_H + + diff --git a/prot_cmd/cmd_m4.cpp b/prot_cmd/cmd_m4.cpp index b360555..01818ce 100644 --- a/prot_cmd/cmd_m4.cpp +++ b/prot_cmd/cmd_m4.cpp @@ -4,6 +4,10 @@ #include "base/mycfg.h" #include "prot/prot_m4.h" #include "prot/prot_pc.h" +#include "base/beep.h" +#include "prot_cmd/cmd_coder.h" +#include "elec/coder_lib.h" +#include "elec/elec_judge.h" typedef struct{ @@ -15,9 +19,15 @@ typedef struct{ static self_def g_self; +static int docmd_ke1(); + + + void cmd_m4_init() { prot_m4 *m4=protM4(); + beep *beep_=Beep(); + mycfg *cfg_=syscfg(); m4->set_irq_fun([=](myarray data){ ProtPc *pc=protPc(); g_self.key_pressed=1; @@ -30,11 +40,14 @@ void cmd_m4_init() },"key up"); m4->set_irq_fun([=](myarray data){ g_self.ke1_pressed=1; + beep_->set_state(true); qDebug("ke1 press"); },"ke1 press"); m4->set_irq_fun([=](myarray data){ g_self.ke1_pressed=0; + beep_->set_state(false); qDebug("ke1 up"); + docmd_ke1(); },"ke1 up"); // m4->set_irq_fun([=](myarray data){ // ProtPc *pc=protPc(); @@ -55,3 +68,29 @@ int cmd_m4_key_pressed() +static int docmd_ke1(){ + /* + 赋码仪按键按下时,如果是赋码仪一体机,则发送请求赋码命令0x8b + 按键加上300ms屏蔽 + 赋码仪按键按下,直接开始检测 + + */ + ProtPc *pc=protPc(); + mycfg *cfg_=syscfg(); + check_cfg *ccfg_=check_plan(); + if(cfg_->device_type=="inte_coder"){ + int chip=elec_extract_chip(ccfg_->get_plan_id()); + QByteArray r; + r.append(char(chip)); + qInfo("key1 press:send cmd 0x8b."); + pc->send_data_slot(0x8b,r); + }else{ + char data[]={10,0}; + qInfo("key1 press:start check."); + pc->docmd(0xe0,myarray(data,2)); + } + return 0; +} + + + diff --git a/prot_cmd/cmd_pc.cpp b/prot_cmd/cmd_pc.cpp index 0046a93..691b799 100644 --- a/prot_cmd/cmd_pc.cpp +++ b/prot_cmd/cmd_pc.cpp @@ -927,17 +927,9 @@ void selfdev_runtask::slave_sort(){ void selfdev_runtask::slave_end_slot(int addr,int ack, slave_data data) { + int cmd; + myarray da; qDebug("selfdev runtask end."); -// for(int i=0;i