添加对hmi屏幕的支持,赋码仪按键按下时发送赋码请求
This commit is contained in:
@@ -64,7 +64,8 @@
|
||||
自动检测指令0x44不读取流水号
|
||||
解决新赋码指令回复指令不对的问题
|
||||
解决tcp不上报心跳的问题
|
||||
|
||||
2024.1.29
|
||||
添加对hmi屏幕的支持,赋码仪按键按下时发送赋码请求
|
||||
|
||||
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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 \
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
|
||||
|
||||
#define BUILD_DATE "2024-01-18 15:53:38"
|
||||
#define BUILD_DATE "2024-01-29 17:53:35"
|
||||
|
||||
|
||||
|
||||
|
@@ -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",
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
|
4
main.cpp
4
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();
|
||||
}
|
||||
|
@@ -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());
|
||||
|
@@ -23,6 +23,33 @@ HandlePc *handlePcFind(int cmd)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QList<int> 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<int> list;
|
||||
for (item = start; item < end; item++)
|
||||
{
|
||||
if (item != nullptr)
|
||||
{
|
||||
list.append(item->cmd);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void ProtPc::init()
|
||||
{
|
||||
if(syscfg()->tcp_enable==false){
|
||||
|
@@ -78,7 +78,7 @@ protpc_export(0x30, get_ChidlPc);
|
||||
|
||||
|
||||
|
||||
|
||||
QList<int> handlePcList();
|
||||
|
||||
|
||||
|
||||
|
@@ -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(){
|
||||
if(syscfg()->auto_test>0){
|
||||
ProtPc *pc=protPc();
|
||||
check_cfg *ccfg_=check_plan();
|
||||
if(syscfg()->auto_test>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 QList<int>sort(QList<int> in){
|
||||
int temp;
|
||||
int num=in.size();
|
||||
for(int i=0;i<num;i++){
|
||||
temp=in[i];
|
||||
for(int j=i+1;j<num;j++){
|
||||
if(in[i]>in[j]){
|
||||
in[i]=in[j];
|
||||
in[j]=temp;
|
||||
temp=in[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
static void pclist(QList<myarray> args){
|
||||
command *c=command_start();
|
||||
ProtPc *pc=protPc();
|
||||
QList<int> list=handlePcList();
|
||||
mystring s;
|
||||
list=sort(list);
|
||||
for (int i=0;i<list.size();i++){
|
||||
s.append(mystring::asprintf("0x%02x,",list[i]));
|
||||
}
|
||||
c->send(s.data());
|
||||
}
|
||||
cmdline_export(pclist, pclist, print pc cmd list.);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -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;
|
||||
|
103
prot_cmd/cmd_hmi_coder.cpp
Normal file
103
prot_cmd/cmd_hmi_coder.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include "cmd_hmi_coder.h"
|
||||
#include "interface/interface.h"
|
||||
#include <QTextCodec>
|
||||
#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;i<cfg_->slave_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<myarray> data)
|
||||
{
|
||||
check_cfg *ccfg_=check_plan();
|
||||
uint8_t err_flag=0;
|
||||
for (int i=0;i<data.size();i++)
|
||||
{
|
||||
myarray &sdata=data[i];
|
||||
int addr=sdata[0];
|
||||
sdata.remove(0,1);
|
||||
uint8_t marerr=0,suberr=0;
|
||||
uint8_t slave_err=sdata[0];
|
||||
uint8_t *d=(uint8_t *)sdata.data()+1;
|
||||
elec_judge(ccfg_->check_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);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
69
prot_cmd/cmd_hmi_coder.h
Normal file
69
prot_cmd/cmd_hmi_coder.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#ifndef CMD_HMI_CODER_H
|
||||
#define CMD_HMI_CODER_H
|
||||
|
||||
|
||||
#include <QObject>
|
||||
#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<int> cmd_pc_to_addrs(myarray data){
|
||||
QList<int> addr_list;
|
||||
addrs=data[0];
|
||||
mode=data[1];
|
||||
if(addrs<=0||addrs>20){
|
||||
return addr_list;
|
||||
}
|
||||
for(int i=0;i<addrs;i++){
|
||||
addr_list.append(i+1);
|
||||
}
|
||||
return addr_list;
|
||||
}
|
||||
// 从机发起命令
|
||||
int cmd_slave(){
|
||||
return 0x20;
|
||||
}
|
||||
// pc收到回复,返回0不回复
|
||||
int cmd_pc_recv(){
|
||||
return 0;
|
||||
}
|
||||
// 生成接收回复到pc
|
||||
myarray cmd_pc_recv_to_pc(){
|
||||
myarray r;
|
||||
r.append(uint8_t(addrs));
|
||||
r.append(uint8_t(mode));
|
||||
r.append(uint8_t(0));
|
||||
return r;
|
||||
}
|
||||
// pc回复命令,返回0不回复
|
||||
int cmd_pc_ret();
|
||||
// 从机返回转pc
|
||||
myarray ret_slave_to_pc(QList<myarray> data);
|
||||
protected:
|
||||
int addrs;
|
||||
int mode;
|
||||
};
|
||||
|
||||
|
||||
void hmicoder_init();
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // CMD_HMI_CODER_H
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -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<data.size();i++){
|
||||
// //qDebug("index=%d",i);
|
||||
// slave_ret slave=data.at(i);
|
||||
// //qDebug("index=%d end",i);
|
||||
// // 数据的第一位是来源的地址
|
||||
// slave.data.insert(0,slave.addr);
|
||||
// slave_acked.replace(i,slave.data);
|
||||
// // qDebug("index=%d end 2",i);
|
||||
// slave_acked_num++;
|
||||
// }
|
||||
for(int i=0;i<addrs.size();i++){
|
||||
int addr=addrs[i];
|
||||
myarray sdata=data[addr-1];
|
||||
@@ -946,9 +938,12 @@ void selfdev_runtask::slave_end_slot(int addr,int ack, slave_data data)
|
||||
slave_acked.replace(addr-1,sdata);
|
||||
slave_acked_num++;
|
||||
}
|
||||
if(cmd_pc_ret()!=0){
|
||||
|
||||
slave_sort();
|
||||
emit send_data_signal(cmd_pc_ret(),ret_slave_to_pc(slave_acked));
|
||||
cmd=cmd_pc_ret();
|
||||
da=ret_slave_to_pc(slave_acked);
|
||||
if(cmd!=0){
|
||||
emit send_data_signal(cmd,da);
|
||||
}
|
||||
busy=0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user