首页 > 其他分享 >code

code

时间:2023-04-19 12:11:23浏览次数:26  
标签:code void uint8 dnFlag rvFlag ui MainWindow

#include "mainwindow.h"
#include "ui_mainwindow.h"

#define LED_ON    setStyleSheet("background-color:lightGreen;")
#define LED_OFF   setStyleSheet("background-color:lightBlack;")



MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    SingleBoardTestFlag = 0x00;
    dnData_MsgLen = 0;                 //下发数据长度
    dnFlag_PowerOff = 0;               //主机关机中
    dnFlag_DisableWalk = 0;            //升降、行走、支脚禁用信号
    dnFlag_LargeColumnLimit = 0;       //大立柱限位有效标志
    dnFlag_LargeColumnProgram = 0;     //大立柱TWINCAT程序控制标志
    dnFlag_LargeColumnUp = 0;          //大立柱向上运动标志
    dnFlag_LargeColumnDown  = 0;       //大立柱向下运动标志
    dnFlag_LaserLight = 0;             //十字激光点亮标志
    dnFlag_ParkBrake = 0;              //支脚电机升降控制
    dnData_LargeColumnUpLimitVal = 0;  //大立柱上限值
    dnData_LargeColumnDownLimitVal = 0;//大立柱下限值
    dnData_LargeColumnProgramVal = 0;  //大立柱TWINCAT程序控制目标值
    dnState_SystemReset = 0;           //复位按钮灯状态(无效值常零)
    dnFlag_LargeColumnCanMove = 0;     //横梁立柱动作使能标志

    rvFlag_PowerKey = 0;                //开关机按键信号(按下为1、抬起为0)
    rvData_BMS_SOC = 0;                 //电池电量
    rvState_PowerSta = 0;               //1-市电供电且电池满电  2-电池供电   3电池充电状态
    rvFlag_LeftRunMotorEn = 0;          //左行走驱动器状态
    rvFlag_RightRunMotorEn = 0;         //右行走驱动器状态
    rvFlag_LeftStandMotorEn = 0;        //左支脚驱动器状态
    rvFlag_RightStandMotorEn = 0;       //右支脚驱动器状态
    rvFlag_ColumMotorEn = 0;            //大立柱驱动器状态
    rvFlag_ColumnMoveFlag = 0;          //大立柱动作标志
    rvData_ColumPosition = 0;           //大立柱当前位置
    rvData_beam_FrBkValue = 0;          //大横梁三轴电位器前后位置
    rvData_beam_LeRiValue = 0;          //大横梁三轴电位器左右位置
    rvData_beam_RotaValue = 0;          //大横梁三轴电位器旋转位置
    rvFlag_RunMoveFlag = 0;             //行走电机工作标识
    rvData_ErrCode = 0;                 //错误代码
    rvFlag_UseLineFlag = 0;             //线控手柄启用标识
    rvData_HandKeyValue = 0;            //线控手柄按键值
    rvFlag_LeftStandSwitch = 0;         //左侧支脚电机光电开关信号
    rvFlag_RightStandSwitch = 0;        //右侧支脚电机光电开关信号

    ui -> setupUi(this);
    this -> setWindowTitle("2.0项目台车调试V00-产品电控部");
    my_socket = new QTcpSocket();
    connectstat = false;
    connect(my_socket,&QTcpSocket::readyRead,this,&MainWindow::readyReadSlots);
    connect( &m_tData, SIGNAL(timeout()), this, SLOT(SLOT_TimerOver()) );
    m_tData.start(10);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::readyReadSlots()
{
     int RecvLen;
     uint8_t TCPRecvBuff[28] = {0};
     QByteArray RecvBuff;
     RecvLen = my_socket->bytesAvailable();
     RecvBuff = my_socket->read(RecvLen>65535?65535:RecvLen);
     memcpy(TCPRecvBuff,RecvBuff,RecvLen);

     if((TCPRecvBuff[0]==0xEB)&&(TCPRecvBuff[1]==0x90))
     {
         rvFlag_PowerKey          = TCPRecvBuff[6];       //开关机按键信号(按下为1、抬起为0)
         rvState_PowerSta         = TCPRecvBuff[7];       //1-市电供电且电池满电  2-电池供电   3电池充电状态
         rvData_BMS_SOC           = TCPRecvBuff[8];       //电量
         rvFlag_LeftRunMotorEn    = TCPRecvBuff[9];       //左行走驱动器状态
         rvFlag_RightRunMotorEn   = TCPRecvBuff[10];      //右行走驱动器状态
         rvFlag_LeftStandMotorEn  = TCPRecvBuff[12];      //左支脚驱动器状态
         rvFlag_RightStandMotorEn = TCPRecvBuff[13];      //右支脚驱动器状态
         rvFlag_ColumMotorEn      = TCPRecvBuff[11];      //大立柱驱动器状态
         rvFlag_ColumnMoveFlag    = TCPRecvBuff[14];
         memcpy(&rvData_ColumPosition,TCPRecvBuff+15,2);  //大立柱当前位置
         rvData_beam_FrBkValue    = TCPRecvBuff[17];      //大横梁三轴电位器前后位置
         rvData_beam_LeRiValue    = TCPRecvBuff[18];      //大横梁三轴电位器左右位置
         rvData_beam_RotaValue    = TCPRecvBuff[19];      //大横梁三轴电位器旋转位置
         rvFlag_RunMoveFlag       = TCPRecvBuff[21];      //行走电机工作标识
         rvData_ErrCode           = TCPRecvBuff[22];      //错误代码
         rvFlag_UseLineFlag       = TCPRecvBuff[23];      //线控手柄启用标识
         memcpy(&rvData_HandKeyValue,TCPRecvBuff+24,2);   //线控手柄按键值
         rvFlag_LeftStandSwitch   = TCPRecvBuff[26];      //左侧支脚电机光电开关信号
         rvFlag_RightStandSwitch  = TCPRecvBuff[27];      //右侧支脚电机光电开关信号
      }
}
void MainWindow::ShowRecvState()
{
   QString strShow;
   ui->lcdnumber->setSegmentStyle(QLCDNumber::Flat);
   ui->lcdnumber->display(rvData_BMS_SOC);
   switch(rvState_PowerSta)
   {
     case 0x01: ui->label_PowerSta->setText("供电:市电");  break;
     case 0x02: ui->label_PowerSta->setText("供电:电池");  break;
     case 0x03: ui->label_PowerSta->setText("供电:充电中"); break;
   }
   rvFlag_PowerKey         ? ui->LED1->LED_ON  : ui->LED1->LED_OFF;
   rvFlag_LeftRunMotorEn   ? ui->LED4->LED_ON  : ui->LED4->LED_OFF;
   rvFlag_RightRunMotorEn  ? ui->LED5->LED_ON  : ui->LED5->LED_OFF;
   rvFlag_LeftStandSwitch  ? ui->LED8_4->LED_ON: ui->LED8_4->LED_OFF;
   rvFlag_RightStandSwitch ? ui->LED8_3->LED_ON: ui->LED8_3->LED_OFF;
   rvFlag_LeftStandMotorEn ? ui->LED8->LED_ON  : ui->LED8->LED_OFF;
   rvFlag_RightStandMotorEn? ui->LED8_2->LED_ON: ui->LED8_2->LED_OFF;
   rvFlag_ColumMotorEn     ? ui->LED7->LED_ON  : ui->LED7->LED_OFF;
   rvFlag_ColumnMoveFlag   ? ui->LED6->LED_ON  : ui->LED6->LED_OFF;
   rvFlag_RunMoveFlag      ? ui->LED2->LED_ON  : ui->LED2->LED_OFF;
   rvFlag_UseLineFlag      ? ui->LED3->LED_ON  : ui->LED3->LED_OFF;
   strShow.setNum(rvData_beam_FrBkValue);
   ui->label_20->setText(strShow);
   strShow.setNum(rvData_beam_LeRiValue);
   ui->label_23->setText(strShow);
   strShow.setNum(rvData_beam_RotaValue);
   ui->label_24->setText(strShow);
   strShow.setNum(rvData_ColumPosition);
   ui->label_26->setText(strShow);
   ui->lineEdit_ColumCurPosi->setText(strShow);
}
void MainWindow::on_pushButton_clicked()
{
    QString ip  = ui -> lineEdit  -> text();
    qint16 port = ui -> lineEdit_2-> text().toInt();

    QHostAddress address = QHostAddress(ip);

    if(!connectstat)//如果没有连接
    {
        my_socket -> connectToHost(address,port);
        if(!my_socket -> waitForConnected(5000))
        {
            qDebug()<<my_socket -> errorString();
            QMessageBox::critical(this, "连接错误", "以太网连接失败!");
            return ;
        }
        else
        {
            ui->pushButton->setText("断开连接");
            connectstat=true;
        }
    }
    else
    {
        ui->pushButton->setText("建立连接");
        connectstat=false;
    }
}
uint16_t GetCRC16(unsigned char * pszBuf, uint16_t unLength)
{
  uint16_t i, j, CurVal;
  uint16_t CrcReg = 0xFFFF;

  for (i = 0; i < unLength; i++)
  {
    CurVal = pszBuf[i] << 8;

    for (j = 0; j < 8; j++)
    {
      if ((short)(CrcReg ^ CurVal) < 0)
        CrcReg = (CrcReg << 1) ^ 0x1021;
      else
        CrcReg <<= 1;

      CurVal <<= 1;
    }
  }
  return CrcReg;
}
void MainWindow::TCP_SendData(QByteArray Data,uint8_t Len)
{
  //Data = res.toLocal8Bit();
  my_socket->write(QByteArray::fromHex(Data),Len);
 //  my_socket->write(Data.toHex(),Len);
}
void MainWindow::SLOT_TimerOver()
{
    QString StrSend;
    uint16_t CRCData = 0;
    uint8_t  SendBuff[24] = {0};
    SendBuff[ 0 ] = 0xEB;
    SendBuff[ 1 ] = 0x90;
    SendBuff[ 2 ] = 0xFF;
    SendBuff[ 3 ] = 0xFF;
    SendBuff[ 4 ] = 0xFF;
    SendBuff[ 5 ] = 0x10;
    SendBuff[ 6 ] = dnFlag_PowerOff;
    SendBuff[ 7 ] = dnFlag_DisableWalk;         //动作禁用
    SendBuff[ 8 ] = dnFlag_LargeColumnLimit;    //立柱限位有效
    SendBuff[ 9 ] = dnFlag_LargeColumnProgram;  //立柱程控标识
    SendBuff[ 10] = dnFlag_LargeColumnUp;       //立柱向上
    SendBuff[ 11] = dnFlag_LargeColumnDown;     //立柱向下
    SendBuff[ 12] = dnFlag_LaserLight;          //激光点亮
    SendBuff[ 13] = dnFlag_ParkBrake;           //支脚升降
    memcpy( SendBuff + 14, &dnData_LargeColumnUpLimitVal,  2 ); //大立柱上限位
    memcpy( SendBuff + 16, &dnData_LargeColumnDownLimitVal,2 ); //大立柱下限位
    memcpy( SendBuff + 18, &dnData_LargeColumnProgramVal,  2 ); //大立柱程控目标值
    SendBuff[ 20] = 0x00;
    SendBuff[ 21] = dnFlag_LargeColumnCanMove;  //梁柱使能标识
    CRCData = GetCRC16(SendBuff,22);
    SendBuff[ 22] = CRCData & 0xFF;
    SendBuff[ 23] = CRCData >> 8;
    for(uint8_t i=0;i<sizeof(SendBuff);i++)
    {
       StrSend += QString(SendBuff[i]);
    }

    if(connectstat == true)
    {
       my_socket->write(StrSend.toLatin1(),24);
    }
    ShowRecvState();

}

void MainWindow::on_pushButton_Laser_pressed()
{
   dnFlag_LaserLight = 0x01;
}
void MainWindow::on_pushButton_Laser_released()
{
   dnFlag_LaserLight = 0x00;
}
void MainWindow::on_checkBox_DisMove_clicked(bool checked)
{
   dnFlag_DisableWalk =  checked;
}
/*****************************驻车********************************************************/

void MainWindow::on_pushButton_ParkKey_clicked()
{
    dnFlag_ParkBrake = 0x01;
}
void MainWindow::on_pushButton_DisPark_clicked()  //驻车取消
{
    dnFlag_ParkBrake = 0x00;
}
/***************************************************************************************/
//关机
void MainWindow::on_pushButton_PowerOff_pressed()
{
   dnFlag_PowerOff = 0x01;
}
void MainWindow::on_pushButton_PowerOff_released()
{
   dnFlag_PowerOff = 0x00;
}
//----------------------------立柱----------------------------------------------------------
void MainWindow::on_checkBox_3_clicked(bool checked)
{
    dnFlag_LargeColumnCanMove = checked;
}
void MainWindow::on_checkBox_clicked(bool checked)  //选择程序控制
{
   dnFlag_LargeColumnProgram = checked;
   qDebug("LargeColumnUp:%d",dnFlag_LargeColumnProgram);
}

void MainWindow::on_checkBox_2_clicked(bool checked)//立柱限位有效标识
{
  dnFlag_LargeColumnLimit = checked;
}
void MainWindow::on_pushButton_CulumUp_pressed()
{
   dnFlag_LargeColumnUp = 0x01;

   qDebug("LargeColumnUp:%d",dnFlag_LargeColumnUp);
}
void MainWindow::on_pushButton_CulumUp_released()
{
   dnFlag_LargeColumnUp = 0x00;
   qDebug("LargeColumnUp:%d",dnFlag_LargeColumnUp);
}
void MainWindow::on_pushButton_CulumUp_2_pressed()
{
    dnFlag_LargeColumnDown = 0x01;
}
void MainWindow::on_pushButton_CulumUp_2_released()
{
    dnFlag_LargeColumnDown = 0x00;
}

 

 

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTcpServer>
#include <QTcpSocket>
#include <QDebug>
#include <QHostAddress>
#include <QMessageBox>
#include <QTimer>
#include <QKeyEvent>

namespace Ui {
class MainWindow;
}


class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

public slots:

    void SLOT_TimerOver();

private slots:

    void readyReadSlots();
    void on_pushButton_clicked();

    void on_pushButton_ParkKey_clicked();
    void on_pushButton_DisPark_clicked();

    void on_checkBox_clicked(bool checked);
    void on_checkBox_2_clicked(bool checked);

    void on_pushButton_CulumUp_pressed();
    void on_pushButton_CulumUp_released();

    void on_pushButton_CulumUp_2_pressed();
    void on_pushButton_CulumUp_2_released();

    void on_pushButton_PowerOff_pressed();
    void on_pushButton_PowerOff_released();

    void on_checkBox_3_clicked(bool checked);
    void on_checkBox_DisMove_clicked(bool checked);

    void on_pushButton_Laser_pressed();
    void on_pushButton_Laser_released();



private:
    Ui::MainWindow                *ui;
    QTcpSocket                    *my_socket;
    bool                          connectstat;
    QTimer                        m_tData;

    uint8_t   SingleBoardTestFlag;           //单板测试标识

    uint8_t   dnData_MsgLen;                 //下发数据长度
    uint8_t   dnFlag_PowerOff;               //主机关机中
    uint8_t   dnFlag_DisableWalk;            //升降、行走、支脚禁用信号
    uint8_t   dnFlag_LargeColumnLimit;       //大立柱限位有效标志
    uint8_t   dnFlag_LargeColumnProgram;     //大立柱TWINCAT程序控制标志
    uint8_t   dnFlag_LargeColumnUp;          //大立柱向上运动标志
    uint8_t   dnFlag_LargeColumnDown ;       //大立柱向下运动标志
    uint8_t   dnFlag_LaserLight;             //十字激光点亮标志
    uint8_t   dnFlag_ParkBrake;              //支脚电机升降控制
    uint16_t  dnData_LargeColumnUpLimitVal;  //大立柱上限值
    uint16_t  dnData_LargeColumnDownLimitVal;//大立柱下限值
    uint16_t  dnData_LargeColumnProgramVal;  //大立柱TWINCAT程序控制目标值
    uint8_t   dnState_SystemReset;           //复位按钮灯状态(无效值常零)
    uint8_t   dnFlag_LargeColumnCanMove;     //横梁立柱动作使能标志

    uint8_t   rvFlag_PowerKey;                //开关机按键信号(按下为1、抬起为0)
    uint8_t   rvData_BMS_SOC;                 //电池电量
    uint8_t   rvState_PowerSta;               //1-市电供电且电池满电  2-电池供电   3电池充电状态
    uint8_t   rvFlag_LeftRunMotorEn;          //左行走驱动器状态
    uint8_t   rvFlag_RightRunMotorEn;         //右行走驱动器状态
    uint8_t   rvFlag_LeftStandMotorEn;        //左支脚驱动器状态
    uint8_t   rvFlag_RightStandMotorEn;       //右支脚驱动器状态
    uint8_t   rvFlag_ColumMotorEn;            //大立柱驱动器状态
    uint8_t   rvFlag_ColumnMoveFlag;          //大立柱动作标志
    uint8_t   rvData_ColumPosition;           //大立柱当前位置
    uint8_t   rvData_beam_FrBkValue;          //大横梁三轴电位器前后位置
    uint8_t   rvData_beam_LeRiValue;          //大横梁三轴电位器左右位置
    uint8_t   rvData_beam_RotaValue;          //大横梁三轴电位器旋转位置
    uint8_t   rvFlag_RunMoveFlag;             //行走电机工作标识
    uint8_t   rvData_ErrCode;                 //错误代码
    uint8_t   rvFlag_UseLineFlag;             //线控手柄启用标识
    uint16_t  rvData_HandKeyValue;            //线控手柄按键值
    uint8_t   rvFlag_LeftStandSwitch;         //左侧支脚电机光电开关信号
    uint8_t   rvFlag_RightStandSwitch;        //右侧支脚电机光电开关信号
    void TCP_SendData(QByteArray Data,uint8_t Len);
    void ShowRecvState();
};

#endif // MAINWINDOW_H

 

标签:code,void,uint8,dnFlag,rvFlag,ui,MainWindow
From: https://www.cnblogs.com/einstein-2014731/p/17332900.html

相关文章

  • 【DP】LeetCode 题号.题目
    题目链接377.组合总和Ⅳ思路分析动态规划题目的时候只需要考虑最后一个阶段,因为所有的阶段转化都是相同的,考虑最后一个阶段容易发现规律在数组的动态规划问题中,一般dp[i]都是表示以nums[i]为结尾的状态;dp[i][j]分别表示以nums1[i]和nums2[j]为结尾的状态,以此类推......
  • VSCode修饰器报错,对修饰器的实验支持功能在将来的版本中可能更改
    报错内容对修饰器的实验支持功能在将来的版本中可能更改。在“tsconfig”或“jsconfig”中设置“experimentalDecorators”选项以删除此警告解决办法方法一:设置VSCode选项管理==>设置==>搜索experimentalDecorators==>打上勾勾方法二:增加jsconfig文件在根目录下新......
  • cocoapods Xcode 14.3 Archive Command PhaseScriptExecution failed with a nonzero
    Xcode升级到14.3进行  Archive CommandPhaseScriptExecutionfailedwithanonzeroexitcode解决方法Xcode搜索 source="$(readlink-f"${source}")"将 source="$(readlink-f"${source}")"改为 source="$(readlink-f"......
  • leetcode刷题随笔(2)
    42.收集雨水(TrappingRainWater)方法一:利用双指针交叉循环求解,时间复杂度O(n)//接雨水inttrap(vector<int>&height){inti=0,j=height.size()-1;intleft_max=0,right_max=0;intvan=0;while(i<j){if(height[i]......
  • LeetCode Top100: 反转链表 (python)
     给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。 示例1:输入:head=[1,2,3,4,5]输出:[5,4,3,2,1]示例2:输入:head=[1,2]输出:[2,1]示例3:输入:head=[]输出:[] 提示:链表中节点的数目范围是 [0,5000]-5000<=Node.val<=5000实现:给你......
  • Educational Codeforces Round 113 (Rated for Div. 2)
    题目链接B核心思路这个题目我觉得很好。首先分析下吧,如果有人需要执行操作二那么我们肯定就是给他们都打上平局是最优的。那么如果有人需要执行操作一呢,那么我们就可以把这些需要执行操作1的都搞一起。然后是他们成一个环。这样肯定就保证了每个人都会赢上一次。C核心思路......
  • Codeforces Round 866 (Div. 2)
    A.Yura'sNewName一个简单的dp,状态是\(f[i][0/1]\)表示前\(i\)位变成合法的且最后一位是^或_的最小代价。如果是_只能从^转移过来,如果是^则都可以转移过来#include<bits/stdc++.h>usingnamespacestd;voidsolve(){ strings; cin>>s; intn=s.size(); if(n=......
  • LeetCode Top100: 翻转二叉树(python)
    给你一棵二叉树的根节点 root ,翻转这棵二叉树,并返回其根节点。 示例1:输入:root=[4,2,7,1,3,6,9]输出:[4,7,2,9,6,3,1]示例2:输入:root=[2,1,3]输出:[2,3,1]示例3:输入:root=[]输出:[] 提示:树中节点数目范围在 [0,100] 内-100<=Node.val<=100实......
  • LeetCode Top 100: 二叉树的直径 (python)
     给定一棵二叉树,你需要计算它的直径长度。一棵二叉树的直径长度是任意两个结点路径长度中的最大值。这条路径可能穿过也可能不穿过根结点。 示例:给定二叉树1/\23/\45返回 3,它的长度是路径[4,2,1,3]......
  • 4月18日leetcode二叉树几种遍历方式的非递归和递归
    给你二叉树的根节点 root ,返回它节点值的 前序 遍历。 示例1:二叉树的前序中序和后序遍历算法是学习二叉树必不可少的,若是使用c语言遍历前中后序还是比较繁琐的,因为要考虑遍历结果存放的序列大小问题,想要解决这个问题就得想用递归计算二叉树的节点数量,再调用递归子函数完......