⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netadapterhost.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    * @param conn The connection to send/receive data.    *    */   private void processRequests(Connection conn)      throws IOException   {      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\      if(DEBUG)         System.out.println("\n------------------------------------------");      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\      // get the next command      byte cmd = 0x00;      cmd = conn.input.readByte();      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\      if(DEBUG)         System.out.println("CMD received: " + Integer.toHexString(cmd));      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\      try      {         // ... and fire the appropriate method         switch(cmd)         {            /* Connection keep-alive and close commands */            case CMD_PINGCONNECTION:               // no-op, might update timer of some sort later               conn.output.writeByte(RET_SUCCESS);               conn.output.flush();               break;            case CMD_CLOSECONNECTION:               close(conn);               break;            /* Raw Data commands */            case CMD_RESET:               adapterReset(conn);               break;            case CMD_PUTBIT:               adapterPutBit(conn);               break;            case CMD_PUTBYTE:               adapterPutByte(conn);               break;            case CMD_GETBIT:               adapterGetBit(conn);               break;            case CMD_GETBYTE:               adapterGetByte(conn);               break;            case CMD_GETBLOCK:               adapterGetBlock(conn);               break;            case CMD_DATABLOCK:               adapterDataBlock(conn);               break;            /* Power methods */            case CMD_SETPOWERDURATION:               adapterSetPowerDuration(conn);               break;            case CMD_STARTPOWERDELIVERY:               adapterStartPowerDelivery(conn);               break;            case CMD_SETPROGRAMPULSEDURATION:               adapterSetProgramPulseDuration(conn);               break;            case CMD_STARTPROGRAMPULSE:               adapterStartProgramPulse(conn);               break;            case CMD_STARTBREAK:               adapterStartBreak(conn);               break;            case CMD_SETPOWERNORMAL:               adapterSetPowerNormal(conn);               break;            /* Speed methods */            case CMD_SETSPEED:               adapterSetSpeed(conn);               break;            case CMD_GETSPEED:               adapterGetSpeed(conn);               break;            /* Network Semaphore methods */            case CMD_BEGINEXCLUSIVE:               adapterBeginExclusive(conn);               break;            case CMD_ENDEXCLUSIVE:               adapterEndExclusive(conn);               break;            /* Searching methods */            case CMD_FINDFIRSTDEVICE:               adapterFindFirstDevice(conn);               break;            case CMD_FINDNEXTDEVICE:               adapterFindNextDevice(conn);               break;            case CMD_GETADDRESS:               adapterGetAddress(conn);               break;            case CMD_SETSEARCHONLYALARMINGDEVICES:               adapterSetSearchOnlyAlarmingDevices(conn);               break;            case CMD_SETNORESETSEARCH:               adapterSetNoResetSearch(conn);               break;            case CMD_SETSEARCHALLDEVICES:               adapterSetSearchAllDevices(conn);               break;            case CMD_TARGETALLFAMILIES:               adapterTargetAllFamilies(conn);               break;            case CMD_TARGETFAMILY:               adapterTargetFamily(conn);               break;            case CMD_EXCLUDEFAMILY:               adapterExcludeFamily(conn);               break;            /* feature methods */            case CMD_CANBREAK:               adapterCanBreak(conn);               break;            case CMD_CANDELIVERPOWER:               adapterCanDeliverPower(conn);               break;            case CMD_CANDELIVERSMARTPOWER:               adapterCanDeliverSmartPower(conn);               break;            case CMD_CANFLEX:               adapterCanFlex(conn);               break;            case CMD_CANHYPERDRIVE:               adapterCanHyperdrive(conn);               break;            case CMD_CANOVERDRIVE:               adapterCanOverdrive(conn);               break;            case CMD_CANPROGRAM:               adapterCanProgram(conn);               break;            default:               //System.out.println("Unkown command: " + cmd);               break;         }      }      catch(OneWireException owe)      {         conn.output.writeByte(RET_FAILURE);         conn.output.writeUTF(owe.toString());         conn.output.flush();      }   }   /**    * Closes the provided connection.    *    * @param conn The connection to send/receive data.    */   private void close(Connection conn)   {      try      {         if(conn.sock!=null)         {            conn.sock.close();         }      }      catch(IOException ioe)      { /*drain*/; }      conn.sock = null;      conn.input = null;      conn.output = null;      // ensure that there is no exclusive use of the adapter      adapter.endExclusive();   }   //--------   //-------- Finding iButton/1-Wire device options   //--------   private void adapterFindFirstDevice (Connection conn)      throws IOException, OneWireException   {      boolean b = adapter.findFirstDevice();      if(DEBUG)      {         System.out.println("   findFirstDevice returned " + b);      }      conn.output.writeByte(RET_SUCCESS);      conn.output.writeBoolean(b);      conn.output.flush();   }   private void adapterFindNextDevice (Connection conn)      throws IOException, OneWireException   {      boolean b = adapter.findNextDevice();      if(DEBUG)      {         System.out.println("   findNextDevice returned " + b);      }      conn.output.writeByte(RET_SUCCESS);      conn.output.writeBoolean(b);      conn.output.flush();   }   private void adapterGetAddress (Connection conn)      throws IOException   {      // read in the address      byte[] address = new byte[8];      // call getAddress      adapter.getAddress(address);      if(DEBUG)      {         System.out.println("   adapter.getAddress(byte[]) called, speed=" + adapter.getSpeed());      }      conn.output.writeByte(RET_SUCCESS);      conn.output.write(address, 0, 8);      conn.output.flush();   }   private void adapterSetSearchOnlyAlarmingDevices (Connection conn)      throws IOException   {      if(DEBUG)      {         System.out.println("   setSearchOnlyAlarmingDevices called, speed=" + adapter.getSpeed());      }      adapter.setSearchOnlyAlarmingDevices();      conn.output.writeByte(RET_SUCCESS);      conn.output.flush();   }   private void adapterSetNoResetSearch (Connection conn)      throws IOException   {      if(DEBUG)      {         System.out.println("   setNoResetSearch called, speed=" + adapter.getSpeed());      }      adapter.setNoResetSearch();      conn.output.writeByte(RET_SUCCESS);      conn.output.flush();   }   private void adapterSetSearchAllDevices (Connection conn)      throws IOException   {      if(DEBUG)      {         System.out.println("   setSearchAllDevices called, speed=" + adapter.getSpeed());      }      adapter.setSearchAllDevices();      conn.output.writeByte(RET_SUCCESS);      conn.output.flush();   }   private void adapterTargetAllFamilies (Connection conn)      throws IOException   {      if(DEBUG)      {         System.out.println("   targetAllFamilies called, speed=" + adapter.getSpeed());      }      adapter.targetAllFamilies();      conn.output.writeByte(RET_SUCCESS);      conn.output.flush();   }   private void adapterTargetFamily (Connection conn)      throws IOException   {      // get the number of family codes to expect      int len = conn.input.readInt();      // get the family codes      byte[] family = new byte[len];      conn.input.readFully(family, 0, len);      if(DEBUG)      {         System.out.println("   targetFamily called, speed=" + adapter.getSpeed());         System.out.println("      families: " + Convert.toHexString(family));      }      // call targetFamily      adapter.targetFamily(family);      conn.output.writeByte(RET_SUCCESS);      conn.output.flush();   }   private void adapterExcludeFamily (Connection conn)      throws IOException   {      // get the number of family codes to expect      int len = conn.input.readInt();      // get the family codes      byte[] family = new byte[len];      conn.input.readFully(family, 0, len);      if(DEBUG)      {         System.out.println("   excludeFamily called, speed=" + adapter.getSpeed());         System.out.println("      families: " + Convert.toHexString(family));      }      // call excludeFamily      adapter.excludeFamily(family);      conn.output.writeByte(RET_SUCCESS);      conn.output.flush();   }   //--------   //-------- 1-Wire Network Semaphore methods   //--------   private void adapterBeginExclusive(Connection conn)      throws IOException, OneWireException   {      if(DEBUG)      {         System.out.println("   adapter.beginExclusive called, speed=" + adapter.getSpeed());      }      // get blocking boolean      boolean blocking = conn.input.readBoolean();      // call beginExclusive      boolean b = adapter.beginExclusive(blocking);      conn.output.writeByte(RET_SUCCESS);      conn.output.writeBoolean(b);      conn.output.flush();      if(DEBUG)      {         System.out.println("      adapter.beginExclusive returned " + b);      }   }   private void adapterEndExclusive(Connection conn)      throws IOException, OneWireException   {      if(DEBUG)      {         System.out.println("   adapter.endExclusive called, speed=" + adapter.getSpeed());      }      // call endExclusive      adapter.endExclusive();      conn.output.writeByte(RET_SUCCESS);      conn.output.flush();   }   //--------   //-------- Primitive 1-Wire Network data methods   //--------   private void adapterReset(Connection conn)      throws IOException, OneWireException   {      int i = adapter.reset();      if(DEBUG)      {         System.out.println("   reset, speed=" + adapter.getSpeed() + ", returned " + i);      }      conn.output.writeByte(RET_SUCCESS);      conn.output.writeInt(i);      conn.output.flush();   }   private void adapterPutBit(Connection conn)      throws IOException, OneWireException   {      // get the value of the bit      boolean bit = conn.input.readBoolean();      if(DEBUG)      {         System.out.println("   putBit called, speed=" + adapter.getSpeed());         System.out.println("      bit=" + bit);      }      adapter.putBit(bit);      conn.output.writeByte(RET_SUCCESS);      conn.output.flush();   }   private void adapterPutByte(Connection conn)      throws IOException, OneWireException   {      // get the value of the byte      byte b = conn.input.readByte();      if(DEBUG)      {         System.out.println("   putByte called, speed=" + adapter.getSpeed());         System.out.println("      byte=" + Convert.toHexString(b));      }      adapter.putByte(b);      conn.output.writeByte(RET_SUCCESS);      conn.output.flush();   }   private void adapterGetBit(Connection conn)      throws IOException, OneWireException   {      boolean bit = adapter.getBit();      if(DEBUG)      {         System.out.println("   getBit called, speed=" + adapter.getSpeed());         System.out.println("      bit=" + bit);      }      conn.output.writeByte(RET_SUCCESS);      conn.output.writeBoolean(bit);      conn.output.flush();   }   private void adapterGetByte(Connection conn)      throws IOException, OneWireException   {      int b = adapter.getByte();      if(DEBUG)      {         System.out.println("   getByte called, speed=" + adapter.getSpeed());         System.out.println("      byte=" + Convert.toHexString((byte)b));      }      conn.output.writeByte(RET_SUCCESS);      conn.output.writeByte(b);      conn.output.flush();   }   private void adapterGetBlock(Connection conn)      throws IOException, OneWireException   {      // get the number requested      int len = conn.input.readInt();      if(DEBUG)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -