📄 qcppdialogimpl.cpp
字号:
m_cmdLe->setEnabled(true); m_sendPb->setEnabled(true); m_protoPb->setEnabled(true); m_closePb->setEnabled(true); m_cmdLe->setFocus();}void QCPPDialogImpl::enableSettingWidgets(bool enable){ m_baudCb->setEnabled(enable); m_dataBitsCb->setEnabled(enable); m_parityCb->setEnabled(enable); m_stopCb->setEnabled(enable); m_softwareCb->setEnabled(enable); m_hardwareCb->setEnabled(enable);}void QCPPDialogImpl::disconnectTTY(){ disconnectTTYRestore(m_applyCb->isChecked());}void QCPPDialogImpl::disconnectTTYRestore(bool restoreSettings){ m_outputTimer.stop(); m_outputBuffer="";// cerr<<"closing "<<m_fd<<endl; if (m_fd!=-1) { if (restoreSettings) tcsetattr(m_fd, TCSANOW, &m_oldtio); ::close(m_fd); } m_fd=-1; m_connectPb->setEnabled(true); m_deviceCb->setEnabled(true); if (m_applyCb->isChecked()) enableSettingWidgets(true); m_applyCb->setEnabled(true); m_readCb->setEnabled(true); m_writeCb->setEnabled(true);// m_outputView->setEnabled(false); m_oldCmdsLb->setEnabled(false); m_cmdLe->setEnabled(false); m_sendPb->setEnabled(false); m_protoPb->setEnabled(false); m_closePb->setEnabled(false); m_connectPb->setFocus(); m_isConnected=false; delete m_notifier; m_notifier=0;}/** This function features some code from minicom 2.0.0, src/sysdep1.c */void QCPPDialogImpl::setNewOptions(int baudrate, int databits, const QString& parity, const QString& stop, bool softwareHandshake, bool hardwareHandshake){ struct termios newtio;// memset(&newtio, 0, sizeof(newtio)); if (tcgetattr(m_fd, &newtio)!=0) cerr<<"tcgetattr() 3 failed"<<endl; /*{ unsigned int i; char *c =(char*)&newtio; fprintf(stderr,"*****************\n"); for (i=0; i<sizeof(newtio); i++) { unsigned int t=*c; if (i%8 == 0) fprintf(stderr,"\n"); fprintf(stderr, " 0x%02x", t&0xff); c++; } }*/ speed_t _baud=0; switch (baudrate) { case 600: _baud=B600; break; case 1200: _baud=B1200; break; case 2400: _baud=B2400; break; case 4800: _baud=B4800; break; case 9600: _baud=B9600; break;// case 14400:// _baud=B14400;// break; case 19200: _baud=B19200; break;// case 28800:// _baud=B28800;// break; case 38400: _baud=B38400; break;// case 56000:// _baud=B56000;// break; case 57600: _baud=B57600; break; case 115200: _baud=B115200; break; case 230400: _baud=B230400; break; case 460800: _baud=B460800; break; case 576000: _baud=B576000; break; case 921600: _baud=B921600; break;// case 128000:// _baud=B128000;// break; default:// case 256000:// _baud=B256000; break; } cfsetospeed(&newtio, (speed_t)_baud); cfsetispeed(&newtio, (speed_t)_baud); /* We generate mark and space parity ourself. */ if (databits == 7 && (parity=="Mark" || parity == "Space")) databits = 8; switch (databits) { case 5: newtio.c_cflag = (newtio.c_cflag & ~CSIZE) | CS5; break; case 6: newtio.c_cflag = (newtio.c_cflag & ~CSIZE) | CS6; break; case 7: newtio.c_cflag = (newtio.c_cflag & ~CSIZE) | CS7; break; case 8: default: newtio.c_cflag = (newtio.c_cflag & ~CSIZE) | CS8; break; } newtio.c_cflag |= CLOCAL | CREAD; //parity newtio.c_cflag &= ~(PARENB | PARODD); if (parity == "Even") newtio.c_cflag |= PARENB; else if (parity== "Odd") newtio.c_cflag |= (PARENB | PARODD); //hardware handshake/* if (hardwareHandshake) newtio.c_cflag |= CRTSCTS; else newtio.c_cflag &= ~CRTSCTS;*/ newtio.c_cflag &= ~CRTSCTS; //stopbits if (stop=="2") newtio.c_cflag |= CSTOPB; else newtio.c_cflag &= ~CSTOPB;// newtio.c_iflag=IGNPAR | IGNBRK; newtio.c_iflag=IGNBRK;// newtio.c_iflag=IGNPAR; //software handshake if (softwareHandshake) newtio.c_iflag |= IXON | IXOFF; else newtio.c_iflag &= ~(IXON|IXOFF|IXANY); newtio.c_lflag=0; newtio.c_oflag=0; newtio.c_cc[VTIME]=1; newtio.c_cc[VMIN]=60;// tcflush(m_fd, TCIFLUSH); if (tcsetattr(m_fd, TCSANOW, &newtio)!=0) cerr<<"tcsetattr() 1 failed"<<endl; int mcs=0;// ioctl(m_fd, TIOCMODG, &mcs); ioctl(m_fd, TIOCMGET, &mcs); mcs |= TIOCM_RTS; ioctl(m_fd, TIOCMSET, &mcs); if (tcgetattr(m_fd, &newtio)!=0) cerr<<"tcgetattr() 4 failed"<<endl; //hardware handshake if (hardwareHandshake) newtio.c_cflag |= CRTSCTS; else newtio.c_cflag &= ~CRTSCTS;/* if (on) newtio.c_cflag |= CRTSCTS; else newtio.c_cflag &= ~CRTSCTS;*/ if (tcsetattr(m_fd, TCSANOW, &newtio)!=0) cerr<<"tcsetattr() 2 failed"<<endl; /*{ unsigned int i; char *c =(char*)&newtio; fprintf(stderr,"-----------------\n"); tcgetattr(m_fd, &newtio); for (i=0; i<sizeof(newtio); i++) { unsigned int t=*c; if (i%8 == 0) fprintf(stderr,"\n"); fprintf(stderr, " 0x%02x", t&0xff); c++; } }*/}void QCPPDialogImpl::readData(int fd){ if (fd!=m_fd) return; int bytesRead=::read(m_fd, m_buf, CUTECOMM_BUFSIZE); if (bytesRead<0) { cerr<<"read result: "<<bytesRead<<endl; perror("read: \n"); return; } const char* c=m_buf; if (m_sz!=0) {// cerr<<"readData() "<<bytesRead<<endl; QByteArray ba; ba.duplicate(m_buf, bytesRead);// ba.setRawData(m_buf, bytesRead); m_sz->writeToStdin(ba);// ba.resetRawData(m_buf, bytesRead); return; } QString text; char buf[16]; for (int i=0; i<bytesRead; i++) { if (m_hexOutputCb->isChecked()) { if ((m_hexBytes % 16) == 0) { snprintf(buf, 16, "%08x: ", m_hexBytes); text+=buf; } unsigned int b=*c; snprintf(buf, 16, "%02x ", b & 0xff); text+=buf; m_hexBytes++; if ((m_hexBytes % 16)==0) text+="\n"; else if ((m_hexBytes % 8)==0) text+=" "; } else { if ((isprint(*c)) || (*c=='\n') || (*c=='\r')) { if (*c!='\r') text+=(*c); } else { unsigned int b=*c; snprintf(buf, 16, "\\0x%02x", b & 0xff); text+=buf; } } c++; } addOutput(text);/* if (m_outputView->paragraphs()>1100) { m_outputView->setUpdatesEnabled(false); m_outputView->setSelection(0, 0, 100, 0); m_outputView->removeSelectedText(); m_outputView->scrollToBottom(); m_outputView->setCursorPosition(m_outputView->paragraphs()-1, m_outputView->paragraphLength(m_outputView->paragraphs()-1)); m_outputView->insert(text); m_outputView->setUpdatesEnabled(true); } else { m_outputView->setCursorPosition(m_outputView->paragraphs()-1, m_outputView->paragraphLength(m_outputView->paragraphs()-1)); m_outputView->insert(text); }*/}void QCPPDialogImpl::addOutput(const QString& text){ m_outputBuffer+=text; if (!m_outputTimer.isActive()) { doOutput(); m_outputTimerStart.restart(); m_outputTimer.start(50, true); } else { if ((m_outputTimerStart.elapsed()>400) || ((m_outputTimerStart.elapsed()>200) && (m_outputBuffer.length()<100))) { doOutput(); m_outputTimerStart.restart(); } m_outputTimer.start(50, true); }}void QCPPDialogImpl::doOutput(){ if (m_outputBuffer.isEmpty()) return;// cerr<<"*"; int pNumber=m_outputView->paragraphs(); if (pNumber>1100) { m_outputView->setUpdatesEnabled(false); m_outputView->setSelection(0, 0, pNumber-1000, 0); m_outputView->removeSelectedText(); m_outputView->scrollToBottom(); m_outputView->setCursorPosition(m_outputView->paragraphs()-1, m_outputView->paragraphLength(m_outputView->paragraphs()-1)); m_outputView->insert(m_outputBuffer); m_outputView->setUpdatesEnabled(true); } else { m_outputView->setCursorPosition(m_outputView->paragraphs()-1, m_outputView->paragraphLength(m_outputView->paragraphs()-1)); m_outputView->insert(m_outputBuffer); } m_outputBuffer="";}void QCPPDialogImpl::hexOutputClicked(bool on){ addOutput("\n"); m_hexBytes=0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -