📄 xnp.java
字号:
else TxtStatus.setText("Rcvd INCORRECT program id after rebooting " + Integer.toString(((short)(CodeInj.m_prog_id_rcvd) & 0xffff), 16) ); return; } TxtStatus.setText("No response on query for program id after rebooting"); }/*----------------------------------------------------------------------------- * Cmd to start/abort the download *-----------------------------------------------------------------------------*/ void jBtnDwnLoad_actionPerformed(ActionEvent e) { if (bDownLoading){ jBtnDwnLoad.setText("Download"); TxtStatus.setText("Download aborted"); bDownLoading = false; if ( bThreadRunning) rt2.stop(); if ( bThread2Running) rt3.stop(); bThreadRunning = false; bThread2Running = false; return; } else { if (!MoteParamsOK()) return; //check for valid mote_id and group_id jBtnDwnLoad.setText("Abort"); bDownLoading = true; if (bDownLoadBcast)DownloadBcast(); //load code to all motes else DownloadMote(); //load code to single mote if (!bDownLoading){ jBtnDwnLoad.setText("Download"); } } }/*----------------------------------------------------------------------------- * Download code to single mote *----------------------------------------------------------------------------*/ void DownloadMote(){ int iSleep = 50; if (!bDownLoading) return; TxtStatus.setText("Sending request to start program download"); boolean bRet = CodeInj.CmdStartDwnload(wMoteId, true, 1,iSleep); if (!bRet){ TxtStatus.setText("No response from Mote after initiating download "); bDownLoading = false; return; } if (!CodeInj.m_bCmdAccepted){ TxtStatus.setText("Command refused by Mote after initiating download "); bDownLoading = false; return; } // if (!CodeInj.m_bBatteryVoltsOK){ // TxtStatus.setText("Mote battery voltage too low to program"); // return; //} double fBV = ((float)CodeInj.m_BatteryVolts)/1000.0; TxtBatteryVolts.setText(Double.toString(fBV)); //dply mote battery volts//xmit code capsules to mote TxtStatus.setText("Downloading code"); XDwn = new xnpXmitCode(this,CodeInj,wMoteId); //start thread rt2 = new Thread(XDwn); //create thread for MicaCodeInj rt2.setDaemon(true); //thread dies when Main dies rt2.start(); bThreadRunning = true; }/*----------------------------------------------------------------------------- * Bcast download code to all motes *----------------------------------------------------------------------------*/ void DownloadBcast(){ int itries = 10; // modified from 3 int iSleep = 25; TxtStatus.setText("Sending request to start program download"); CodeInj.CmdStartDwnload(wMoteId, false, itries,iSleep);//xmit code capsules to mote TxtStatus.setText("Downloading code"); XDwn = new xnpXmitCode(this,CodeInj,wMoteId); //start thread rt2 = new Thread(XDwn); //create thread for MicaCodeInj rt2.setDaemon(true); //thread dies when Main dies rt2.start(); bThreadRunning = true; }/*-----------------------------------------------------------------------------* EndDownLoad* -End download of code capsules.* -If single mote xfer then this is the end of the download before ISP.* -If bcast mote xfer then this is end of bcast of code capsules to all motes* before entering the query state to ask for missing capsules.*-----------------------------------------------------------------------------*/ public void EndDownLoad(){ bDownLoading = false; int MAX_RETRY = 10; // MODIFIED from 5 if (bDownLoadBcast){ //broadcast download? TxtStatus.setText("Terminating download"); CodeInj.CmdTerminateLoad((short)TOS_BROADCAST_ADDR, false, MAX_RETRY, 40); //request termination XDwn2 = new xnpQry(this,CodeInj,wMoteId, radixID); //start qry thread for missing packets rt3 = new Thread(XDwn2); //create qry thread rt3.setDaemon(true); rt3.start(); bThread2Running = true; } if (!bDownLoadBcast){ jBtnDwnLoad.setText("Download"); //download complete TxtStatus.setText("Waiting for mote to terminate download"); boolean bRet = CodeInj.CmdTerminateLoad(wMoteId,true, MAX_RETRY, 10); //request termination if (bRet) TxtStatus.setText("Download terminated after capsule# " + Integer.toString((short)(CodeInj.m_NmbCodeCapsulesXmitted) ) ); else TxtStatus.setText("No response on termination request"); bRet = CodeInj.CmdQryCapsules(wMoteId,wMoteId,false, 2, 100); if ( bThreadRunning) rt2.stop(); bThreadRunning = false; } }/*-----------------------------------------------------------------------------* EndBcastDownLoad* -Terminate bcast download of code capsules*-----------------------------------------------------------------------------*/ public void EndBcastDownLoad(){ if (bThread2Running){ bThread2Running = false; bDownLoading = false; jBtnDwnLoad.setText("Download"); rt3.stop(); } }/*-----------------------------------------------------------------------------* MoteParamsOK* -if not promiscous download then chk for goot mote_id* else set wMoteId to broadcast address;* -Chk for good group_id* -Set group_id*-----------------------------------------------------------------------------*/ boolean MoteParamsOK() {//check for valid mote_id wMoteId = (short)TOS_BROADCAST_ADDR; if (!bDownLoadBcast){ wMoteId = Short.parseShort(TxtMoteId.getText()); //mode id to download if ((wMoteId < 0) || (wMoteId > 65535)){ // mote id's are good through 65535 TxtStatus.setText("Aborting: Bad Mote ID"); return false; } }//check for valid group_id group_id = Short.parseShort(TxtGroupId.getText()); //group id to download if ((group_id < 0) || (group_id > 255)){ TxtStatus.setText("Aborting: Bad Group ID"); return false; } CodeInj.setGroupID(group_id); return true; }/*-----------------------------------------------------------------------------* Display a status message in the text box*-----------------------------------------------------------------------------*/public void SetStatusTxt(String sStatus){ TxtStatus.setText(sStatus);}/*-----------------------------------------------------------------------------* Select an .srec file to download*-----------------------------------------------------------------------------*/ void jBtnReloadSrec_actionPerformed(ActionEvent e) { if( sSrecFileName != null ) openSrecFile( sSrecFileName ); } void openSrecFile( String filename ) { TxtSrecFileName.setText(filename); if (CodeInj.readSrecCode(filename)){ if (bCommOpen){ TxtProgramID.setText(Integer.toString(((short)(xnpUtil.prog_id) & 0xffff), 16)); TxtLength.setText(Integer.toString(xnpUtil.m_NmbCodeCapsules)); jBtnDwnLoad.setEnabled(true); jBtnReProg.setEnabled(true); jBtnQry.setEnabled(true); } else TxtStatus.setText("Download disabled: Comm port not open"); } } void jFileChooser1_actionPerformed(ActionEvent e) { String ActionCommand = e.getActionCommand(); if (ActionCommand == "ApproveSelection"){ File fileSrec = jFileChooser1.getSelectedFile(); sSrecFileName = fileSrec.getPath(); openSrecFile( sSrecFileName ); } else{ TxtSrecFileName.setText("Invalid file"); } } public String getClassName(){ String thisClassName; thisClassName = this.getClass().getName(); thisClassName = thisClassName.substring(thisClassName.lastIndexOf(".")+1,thisClassName.length()); thisClassName += ".class"; return thisClassName; } public String getLocalDirName(){ String localDirName; java.net.URL myURL = this.getClass().getResource(getClassName()); localDirName = myURL.getPath(); localDirName = localDirName.substring(0,localDirName.lastIndexOf("/")); return localDirName; }/*-----------------------------------------------------------------------------* SrecFileFilter Class: Add a file filter to a file chooser object*-----------------------------------------------------------------------------*/public class SrecFileFilter extends FileFilter { public SrecFileFilter() { }// Accept all directories and .srec files. public boolean accept(File f) { if (f.isDirectory()) return true; String extension = getExtension(f); if (extension != null) { if (extension.equals("srec")) return true; else return false; } return false; }// The description of this filter public String getDescription() { return ".srec files"; }// Find extension of file private String getExtension(File f) { String ext = null; String s = f.getName(); int i = s.lastIndexOf('.'); if (i > 0 && i < s.length() - 1) { ext = s.substring(i+1).toLowerCase(); } return ext; } public final static String srec = "srec";} public void processCmdline( String[] args ) { boolean help = false; int n = 0; while( (n < args.length) && args[n].startsWith("-") ) { String opt = args[n++]; if( opt.equals("-help") ) { help = true; } else if( opt.equals("-hexid") ) { bIDsInHex = true; radixID = 16; } else if( opt.equals("-group") ) { TxtGroupId.setText(args[n++]); } else if( opt.equals("-mote") ) { TxtMoteId.setText(args[n++]); } else if( opt.equals("-bcast") ) { jCheckBox1.doClick(); } else if( opt.equals("-file") ) { sSrecFileName = args[n++]; } else { System.out.println( "unknown command line option "+opt ); System.exit(1); } } if( help ) { System.out.println( "usage: xnp (-help|-group #|-mote #|-bcast|-file spec)\n" + "By default, xnp is connected to sf@localhost:9001\n" + "To change the source, modify MOTECOM environment variable.\n" + "e.g. sf@localhost:9000, serial@COM1:mica2" + "\n" ); System.exit(0); } try { mote = new MoteMsgIF(PrintStreamMessenger.err, group_id); CodeInj = new xnpUtil( mote ); mote.registerListener(new XnpMsg(), CodeInj); bCommOpen = true; } catch (Exception e) { System.out.println( "ERROR: " + e ); e.printStackTrace(); bCommOpen = false; } } public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { e.printStackTrace(); } xnp XFrame = new xnp(); XFrame.processCmdline( args ); XFrame.show(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -