📄 groundcontrol.ui.h
字号:
/****************************************************************************** ui.h extension file, included from the uic-generated form implementation.**** If you wish to add, delete or rename functions or slots use** Qt Designer which will update this file, preserving your code. Create an** init() function in place of a constructor, and a destroy() function in** place of a destructor.*****************************************************************************/#define STATE_IDLE 0x00#define STATE_HEAD0_GOT 0x01#define STATE_HEAD1_GOT 0x02#define STATE_CHECKSUM_OK 0x03#define CMD_HEAD0 0xeb#define CMD_HEAD1 0x90#define PLANFORM_LEFT ( planform_disp_left->x() )#define PLANFORM_RIGHT ( planform_disp_right->x() )#define PLANFORM_TOP ( planform_disp_top->y() )#define PLANFORM_BOTTOM ( planform_disp_bottom->y() )#define COLLECTFORM_TOP ( CollectFormTop->y() )#define COLLECTFORM_BOTTOM ( CollectFormBottom->y()+1 )#define THROTTLEFORM_TOP ( CollectFormTop->y() )#define THROTTLEFORM_BOTTOM ( CollectFormBottom->y()+1 )unsigned int count; //the frame number counterint32_t GroundControl::initCOM(char* sDevice, int32_t* hdl, int baudrate){ struct termios options; int32_t fSuccess; *hdl = open( sDevice, O_RDWR | O_NOCTTY | O_NDELAY); if ( *hdl == -1 ) return -1; { fcntl( *hdl, F_SETFL, 0 ); tcgetattr( *hdl, &options ); tcflush (*hdl, TCIOFLUSH ); cfsetispeed ( &options, baudrate ); //Set Baud cfsetospeed ( &options, baudrate ); //Set Baud //options.c_cflag |= (CLOCAL | CREAD ); // Enable receiver and set local mode options.c_cflag &= ~PARENB; // No parity options.c_cflag &= ~CSTOPB; // 1 stop bit options.c_cflag &= ~CSIZE; // Mask the character size bit options.c_cflag |= CS8; // Select 8 data bits options.c_cflag &= ~CRTSCTS; // Disable hardware flow control options.c_iflag = ( INPCK ); // Enable parity check options.c_iflag &= ~ INPCK ; // Enable parity check options.c_iflag &= ~(IXON |IXOFF |IXANY); //Disable software flow control options.c_lflag &= ~ (ICANON | ECHO |ECHOE | ISIG ); //Choosing Raw input options.c_oflag &= ~OPOST; // Raw Output options.c_cc[VMIN]=0; // Disable read blocking tcflush (*hdl, TCIOFLUSH ); fSuccess = tcsetattr( *hdl, TCSANOW, &options ); // Set the attribute and all changes occur immediately } return 0;}//Initialize functionvoid GroundControl::init(){ timer_id = startTimer(20); //Set timer 20ms if ( GroundControl::initCOM( "/dev/ttyS1", &mhCom, B115200) == -1 ) // Open COM2 StatusLabel->setText( QString::fromLocal8Bit( "-1" , 2 ) ); Courseslider->setRange(0,256); Courseslider->setValue(128 ); timercounter=0; //初始状态 NavLabel->setText("IDLE"); NavLabel->setBackgroundColor(Qt::yellow); PlatformLabel->setText("unvalid");}void GroundControl::destroy(){ killTimer(timer_id); // close( mhCom );}void GroundControl::timerEvent( QTimerEvent * ){ unsigned char BufferIn[60]; //Buffer size : 60 unsigned char j,cmd_state; unsigned char m_pitch,m_roll,m_course,m_throttle,m_collect; short int nread ; unsigned char SWHeight,SWRoll,SWCourse,SWPitch,SWRotate,SWON,SWOFF0,SWOFF1; unsigned char SWMainFu,SWStation; unsigned char CheckSum,Sum; unsigned char m_nav; //navigator command value unsigned int m_height; //height set command value unsigned char m_platform; //platform set command value double m_number;//LCD display number cmd_state=STATE_IDLE; CheckSum=0; Sum=0; nread=read(mhCom,BufferIn,60); //the begin of the serial buffer data number check if(nread==60) { //the begin of frame head check if((BufferIn[0]==0xeb)&&(BufferIn[1]==0x90)) { //get the checksum for(j=0;j<28;j++) CheckSum+=BufferIn[j]; CheckLabel->setText(QString::number(CheckSum)); //debug: Sum=BufferIn[28]; SumLabel->setText(QString::number(Sum)); //debug: //the begin of the checksum if(CheckSum==Sum){ //check the frame data update if(count!=BufferIn[2])//数据更新了 { m_pitch=BufferIn[3]; m_roll=BufferIn[4]; m_course=BufferIn[5]; m_collect=BufferIn[6]; m_throttle=BufferIn[7]; PitchLabel->setText(QString::number(m_pitch)); RollLabel->setText(QString::number(m_roll)); CourseLabel->setText(QString::number(m_course)); ColLabel->setText(QString::number(m_collect)); ThrLabel->setText(QString::number(m_throttle)); //draw pitch and roll position in the platform //QPainter painter( this ); QPainter painter; painter.begin(this); //clear the old line by draw the old line with background color painter.setPen( QColor (192,192,192)); painter.drawLine(PLANFORM_LEFT,(-m_pitch_last*96/256+PLANFORM_BOTTOM),PLANFORM_RIGHT,(-m_pitch_last*96/256+PLANFORM_BOTTOM)); painter.drawLine((m_roll_last*96/256+PLANFORM_LEFT),PLANFORM_TOP,(m_roll_last*96/256+PLANFORM_LEFT),PLANFORM_BOTTOM); //draw the new line to show the updated value painter.setPen( QColor (255, 0, 0)); painter.drawLine(PLANFORM_LEFT,(-m_pitch*96/256+PLANFORM_BOTTOM),PLANFORM_RIGHT,(-m_pitch*96/256+PLANFORM_BOTTOM)); painter.setPen( QColor (0,255,0)); painter.drawLine((m_roll*96/256+PLANFORM_LEFT),PLANFORM_TOP,(m_roll*96/256+PLANFORM_LEFT),PLANFORM_BOTTOM); //save the present value m_roll_last=m_roll; m_pitch_last=m_pitch; //draw the collect rect //clear the old line by draw the old line with background color painter.setPen(Qt::lightGray); painter.setBrush(Qt::lightGray); painter.drawRect(5,(COLLECTFORM_BOTTOM-m_collect_last*96/256),11,(m_collect_last*96/256)); //draw new rect painter.setBrush(Qt::blue); painter.drawRect(5,(COLLECTFORM_BOTTOM-m_collect*96/256),11,(m_collect*96/256)); //draw the throttle rect //clear the old rect painter.setBrush(Qt::lightGray); painter.drawRect(25,(THROTTLEFORM_BOTTOM-m_throttle_last*96/256),11,m_throttle_last*96/256); //draw the new rect painter.setBrush(Qt::blue); painter.drawRect(25,(THROTTLEFORM_BOTTOM-m_throttle*96/256),11,m_throttle*96/256); //save the present value m_collect_last=m_collect; m_throttle_last=m_throttle; //painting done painter.end(); //draw course position Courseslider->setValue(m_course); //the begin of SWITCHER operation SWHeight=BufferIn[8]&0x08; //Height switch(SWHeight) { case 0x00: SWHightLabel->setText("AUTO"); SWHightLabel->setBackgroundColor(Qt::yellow); break; case 0x08: SWHightLabel->setText("MAN"); SWHightLabel->setBackgroundColor(Qt::green); break; } SWRoll=BufferIn[8]&0x02; //Roll switch(SWRoll) { case 0x00: SWRollLabel->setText("AUTO"); SWRollLabel->setBackgroundColor(Qt::yellow); break; case 0x02: SWRollLabel->setText("MAN"); SWRollLabel->setBackgroundColor(Qt::green); break; } SWCourse=BufferIn[8]&0x04; //Course switch(SWCourse) { case 0x00: SWCLabel->setText("AUTO"); SWCLabel->setBackgroundColor(Qt::yellow); break; case 0x04: SWCLabel->setText("MAN"); SWCLabel->setBackgroundColor(Qt::green); break; } SWPitch=BufferIn[8]&0x01; //Pitch switch(SWPitch) { case 0x00: SWPitchLabel->setText("AUTO"); SWPitchLabel->setBackgroundColor(Qt::yellow); break; case 0x01: SWPitchLabel->setText("MAN"); SWPitchLabel->setBackgroundColor(Qt::green); break; } SWRotate=BufferIn[8]&0x80; //Rotate switch(SWRotate) { case 0x00: SWROtLabel->setText("AUTO"); SWROtLabel->setBackgroundColor(Qt::yellow); break; case 0x80: SWROtLabel->setText("MAN"); SWROtLabel->setBackgroundColor(Qt::green); break; } SWON=BufferIn[8]&0x40; //ON switch(SWON) { case 0x00: SWONLabel->setText("OPEN"); SWONLabel->setBackgroundColor(Qt::yellow); break; case 0x40: SWONLabel->setText("CLOSE"); SWONLabel->setBackgroundColor(Qt::green); break; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -