int startwindowbf::opiucd_getPDN(void) { int totalcount=0; int i; opiucd_status(&com,&PACKAGE_tp[0]); for(i=0;i<5;i++) ucd[i]= PACKAGE_tp[0].payload[i]; if(PACKAGE_tp[0].payload[20]!=0xFF) { PDN_NUMBER[1]=PACKAGE_tp[0].payload[20]; totalcount++; } else PDN_NUMBER[1]=0xff; if(PACKAGE_tp[0].payload[21]!=0xFF) { PDN_NUMBER[2]=PACKAGE_tp[0].payload[21]; totalcount++; } else PDN_NUMBER[2]=0xff; if(PACKAGE_tp[0].payload[22]!=0xFF) { PDN_NUMBER[3]=PACKAGE_tp[0].payload[22]; totalcount++; } else PDN_NUMBER[3]=0xff; if(PACKAGE_tp[0].payload[23]!=0xFF) { PDN_NUMBER[4]=PACKAGE_tp[0].payload[23]; totalcount++; } else PDN_NUMBER[4]=0xff; zbchan=PACKAGE_tp[0].payload[28]; return totalcount; }
void startwindowbf::on_pushButton_2_clicked() { OPIPKT_t opipkttmp; quint8 tempui8arr[512]; int i; //re open the comport if((*comPortUserp==BFCOMPORTFREE||*comPortUserp==BFCOMPORTUSER)&&(!gamemode)) { if(portOn) opi_closeucd_com(&com); if(!firstfile) fclose(file); firstfile=true; *comPortUserp = BFCOMPORTFREE; hide_check_pdn(); portOn = false; if(opi_openucd_com(&com)==0) { portOn = true; *comPortUserp = BFCOMPORTUSER; get_opipkt_total=opiucd_getPDN(); if(!get_opipkt_total) { show_message.setText("there is no pdn devices"); show_message.show(); show_message.exec(); return ; } else show_check_pdn(); } else { portOn = false; *comPortUserp = BFCOMPORTFREE; show_message.setText("Connect the Device again"); show_message.show(); show_message.exec(); return ; } }//other device doesnt use comport else if((*comPortUserp==BFCOMPORTFREE||*comPortUserp==TGCOMPORTUSER)&&(gamemode)) { if(portOn) opi_closeucd_com(&com); if(!firstfile) fclose(file); firstfile=true; *comPortUserp = BFCOMPORTFREE; hide_check_pdn(); portOn = false; if(opi_openucd_com(&com)==0) { portOn = true; *comPortUserp = TGCOMPORTUSER; get_opipkt_total=opiucd_getPDN(); if(!get_opipkt_total) { show_message.setText("there is no pdn devices"); show_message.show(); show_message.exec(); return ; } else show_check_pdn(); } else { portOn = false; *comPortUserp = BFCOMPORTFREE; show_message.setText("Connect the Device again"); show_message.show(); show_message.exec(); return ; } }//other device doesnt use comport else { show_message.setText("Comport is busy,try again later"); show_message.show(); show_message.exec(); return ; } //re open the comport end if(!(portOn)) { *comPortUserp = BFCOMPORTFREE; show_message.setText("You have to connect a Device"); show_message.show(); show_message.exec(); return ; } else if(Show_count==0) { show_message.setText("You have to choose Devices"); show_message.show(); show_message.exec(); return ; } else { if(!gamemode) *comPortUserp = BFCOMPORTUSER; else *comPortUserp = TGCOMPORTUSER; //if user show the showdatawindow,user can't control whether write file or not ui->checkWriteFileBox->setDisabled(true); if(!firstfile) fclose(file); //regulatefilename = userfilename; opiucd_status(&com, &opipkttmp); // should have opened device successfully before QDateTime stDT = QDateTime::currentDateTime(); regulatefilename = QString("D%1_ALL").arg(stDT.toString("yyyyMMdd_hhmmss")); if(ui->checkWriteFileBox->isChecked()) //if true then write it { firstfile=false; file = fopen(regulatefilename.append(".opi").toAscii().data(), "wb+"); // write opihdr information fwrite(opipkttmp.payload, 1, OPIUCDSTLEN-1, file); for(i = 0; i < (512-(OPIUCDSTLEN-1)); i++) tempui8arr[i] = 0xFF; fwrite(tempui8arr, 1, (512-(OPIUCDSTLEN-1)), file); } else firstfile=true; //check which the pdn the user what to show for(i=1;i<OPIWANT_MAX_BF+1;i++) { if(pdnOn[i]) //if the user choose the pdn then we open the showdatawindow { qDebug()<<"sdw "<<i<<"= "<<sdw[i]; if(!sdw[i]->already_open) //if already open we will not open and reset again { firstpdn[i]=false; sdw[i]->reset(gamemode); sdw[i]->setPdnNum(PDN_NUMBER[i]); if(gamemode) { sdw[i]->showgamewindow(PDN_NUMBER[i]); sdw[i]->secretstart(gamemode); } else sdw[i]->show(); } } else //if the user don't choose the pdn then we close the showdatawindow { if(sdw[i]->isVisible()) { sdw[i]->close(); sdw[i]->already_open=false; } } } //to avoid reopening timer if(firsttimer) { timeid=QObject::startTimer(startwindow_fresh_time_BF); firsttimer=false; } } }
void ConfigWindow::on_ucStatusPB_clicked() { HANDLE comport; OPIPKT_t opipkt; qint64 ucdsn, ucCurrTS, ucRefEpochMSecs; qint32 ucfwv; qint16 ucMode, pdnList[PDNLISTLEN], uczbChan, ucusdStatus, ucChgStat; qint32 i, pdnCt; QString tempstr; if (opi_openucd_com(&comport)) { ErrorMsgBox(QString("No UC attached (COM1-COM50)")); opi_closeucd_com(&comport); return; } if(opiucd_status(&comport, &opipkt)) { ErrorMsgBox(QString("Could not get UC status")); opi_closeucd_com(&comport); return; } ucdsn = ((qint64) opipkt.payload[0] << 32) + ((qint64) opipkt.payload[1] << 24) + ((qint64) opipkt.payload[2] << 16) + ((qint64) opipkt.payload[3] << 8) + ((qint64) opipkt.payload[4]); ucCurrTS = ((qint64) opipkt.payload[5] << 40) + ((qint64) opipkt.payload[6] << 32) + ((qint64) opipkt.payload[7] << 24) + ((qint64) opipkt.payload[8] << 16) + ((qint64) opipkt.payload[9] << 8) + ((qint64) opipkt.payload[10]); ucRefEpochMSecs = ucCurrTS*1000/UCRTCFREQ; // Conversion to QDateTime, ref date & time for all sensors is 2012/sep/28 08:00:00.000 QDateTime ucDT = QDateTime::fromString("20120928080000000","yyyyMMddhhmmsszzz").addMSecs(ucRefEpochMSecs); ucfwv = (opipkt.payload[DSNLEN+TSLEN+6] << 8) + opipkt.payload[DSNLEN+TSLEN+6+1]; ucMode = opipkt.payload[DSNLEN+TSLEN+6+FWVLEN]; for (i = 0; i < PDNLISTLEN; i++) pdnList[i] = opipkt.payload[DSNLEN+TSLEN+6+FWVLEN+1+i]; uczbChan = opipkt.payload[DSNLEN+TSLEN+6+FWVLEN+1+PDNLISTLEN]; ucusdStatus = opipkt.payload[DSNLEN+TSLEN+6+FWVLEN+1+PDNLISTLEN+1]; ucChgStat = opipkt.payload[DSNLEN+TSLEN+6+FWVLEN+1+PDNLISTLEN+2]; if(ucusdStatus & 0x04) ui->ucModOnOffCB->setCurrentIndex(0); else ui->ucModOnOffCB->setCurrentIndex(1); ui->msgPTE->appendPlainText(QString(">> UC Status")); ui->msgPTE->appendPlainText(QString("Device ShortID: %1 Firmware Version: %2 Time: %3 ZigBee Channel: %4").arg(QChar(opipkt.payload[4]%26 + 65)).arg(ucfwv).arg(ucDT.toString("yyyyMMdd hhmmss")).arg(uczbChan)); if(ucusdStatus & 0x04) ui->msgPTE->appendPlainText("uSD sensor on"); else ui->msgPTE->appendPlainText("uSD sensor off"); if((ucusdStatus & 0x03) == 0) ui->msgPTE->appendPlainText("uSD Slot: Nothing"); else if((ucusdStatus & 0x03) == 1) ui->msgPTE->appendPlainText("uSD Slot: TS only"); else if((ucusdStatus & 0x03) == 2) ui->msgPTE->appendPlainText("uSD Slot: MM only"); else if((ucusdStatus & 0x03) == 3) ui->msgPTE->appendPlainText("uSD Slot: TS & MM"); if(ucChgStat & 0x30) ui->msgPTE->appendPlainText("Controller is in On Mode"); else ui->msgPTE->appendPlainText("Controller is in Off Mode"); if(ucusdStatus & 0x10) ui->msgPTE->appendPlainText("USD SPI is on"); else ui->msgPTE->appendPlainText("USD SPI is off"); pdnCt = 0; for(i = 0; i < PDNLISTLEN; i++) { if(pdnList[i] != 0xFF) { tempstr.append(QString("Slot %1-#%2, ").arg(i+1).arg(pdnList[i])); pdnCt++; } } if(!pdnCt) tempstr = QString("No paired devices"); else tempstr.prepend(QString("%1 Associated PDNs: ").arg(pdnCt)); ui->msgPTE->appendPlainText(tempstr); // update the current ZigBee Channel ui->ucZBValCB->setCurrentIndex(uczbChan-11); QDateTime currDT = QDateTime::currentDateTime(); ui->msgPTE->appendPlainText(QString("<< %1 >> Unified Controller Status").arg(currDT.toString("yyyy.MM.dd hh:mm:ss"))); ui->msgPTE->appendPlainText(QString(" ")); ui->msgPTE->ensureCursorVisible(); opi_closeucd_com(&comport); }
void ConfigWindow::on_ucWLMeasurePB_clicked() { HANDLE comport; OPIPKT_t ucOpipkt; qint32 result[16]; QString resTopLine, resBotLine; int i, uczbChan; QProgressDialog progQPD("Measuring ZigBee Channels", QString(), 0, 15); progQPD.setWindowModality(Qt::WindowModal); progQPD.setMinimumDuration(100); if(opi_openucd_com(&comport)) { ErrorMsgBox(QString("No UC attached (COM1-COM50)")); opi_closeucd_com(&comport); return; } if(opiucd_status(&comport, &ucOpipkt)) { ErrorMsgBox(QString("Couldn't get UC status")); opi_closeucd_com(&comport); return; } // save current channel uczbChan = ucOpipkt.payload[DSNLEN+TSLEN+6+FWVLEN+1+PDNLISTLEN]; ui->msgPTE->appendPlainText(QString("Original ZigBee Channel: %1").arg(uczbChan)); ui->msgPTE->appendPlainText("Measuring all zigbee channels, please wait"); qApp->processEvents(); // Go through each valid channel and get maximum out of 100 tries for(i = 0; i < 16; i++) { if (opiucd_setzbchan(&comport, i+11)) { ErrorMsgBox(QString("Could not set UC ZigBee Channel")); opi_closeucd_com(&comport); return; } result[i] = maxWLMeasure100(&comport); progQPD.setValue(i); qApp->processEvents(); } resTopLine.append("ZigBee Channel: 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26"); resBotLine.append("Maximum ED : "); for(i = 0; i < 16; i++) resBotLine.append(QString("%1 ").arg(result[i],2,10,QChar('0'))); ui->msgPTE->appendPlainText(resTopLine); ui->msgPTE->appendPlainText(resBotLine); // set original zb channel if (opiucd_setzbchan(&comport, uczbChan)) { ErrorMsgBox(QString("Could not set original UC ZigBee Channel")); opi_closeucd_com(&comport); return; } opi_closeucd_com(&comport); QDateTime currDT = QDateTime::currentDateTime(); ui->msgPTE->appendPlainText(QString("<< %1 >> Wireless Measurements done").arg(currDT.toString("yyyy.MM.dd hh:mm:ss"))); ui->msgPTE->appendPlainText(QString(" ")); ui->msgPTE->ensureCursorVisible(); }