Package com.mattibal.meshnet

Source Code of com.mattibal.meshnet.MeshNetTest

package com.mattibal.meshnet;

import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;
import gnu.io.UnsupportedCommOperationException;

import java.io.IOException;
import java.util.TooManyListenersException;

import com.mattibal.meshnet.devices.Led1Analog2Device;
import com.mattibal.meshnet.devices.LedLamp1Device;
import com.mattibal.meshnet.devices.LedTestDevice;
import com.mattibal.meshnet.utils.color.AbsoluteColor;
import com.mattibal.meshnet.utils.color.gui.ChromaticityJFrame;

/**
* Coso di test che fa partire la base della MeshNet, e poi scambia qualche
* messaggio con i device
*/
public class MeshNetTest {

  public static void main(String[] args) {
   
    try {
     
      Layer3Base base = new Layer3Base();
      SerialRXTXComm serial = new SerialRXTXComm("/dev/ttyUSB0", base);
      Thread.sleep(4000);
      Layer3Base.NetworkSetupThread setup = base.new NetworkSetupThread();
      Thread setupThread = new Thread(setup);
      setupThread.start();
      setupThread.join();
      // Alè, la rete è pronta, adesso posso giocare con i device
     
      Device device = Device.getDeviceFromUniqueId(384932);
      if(device!=null && device instanceof LedTestDevice){
        LedTestDevice ledDevice = (LedTestDevice) device;
        for(int i=0; i<5000; i++){
          ledDevice.setLedState(true);
          Thread.sleep(20);
          ledDevice.setLedState(false);
          Thread.sleep(50);
        }
      } else if(device!=null && device instanceof Led1Analog2Device){
        Led1Analog2Device ledDev = (Led1Analog2Device) device;
        for(int a=0; a<50; a++){
          for(int i=0; i<255; i+=2){
            ledDev.setLedPwmState(ledTable8bit[i]);
            //Thread.sleep(10);
          }
          for(int i=255; i>0; i-=2){
            ledDev.setLedPwmState(ledTable8bit[i]);
            //Thread.sleep(10);
          }
        }
      } else {
        System.out.println("Errore get device");
      }
     
      Device dev = Device.getDeviceFromUniqueId(484333);
      if(dev!=null && dev instanceof LedLamp1Device){
        LedLamp1Device lamp = (LedLamp1Device) dev;
       
        /*for(int i=0; i<6; i++){
          AbsoluteColor color1 = new AbsoluteColor(0, 0, 0);
          lamp.setColor(color1);
          Thread.sleep(1000);
        }*/
       
       
      } else {
        System.out.println("Error getting led lamp device");
      }
     
    } catch (Exception e) {
      e.printStackTrace();
    }
   
   
  }
 
 
 
  private final static int ledTable8bit[] = new int[]{
        0,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,
        1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,
        1,   2,   2,   2,   2,   2,   2,   2,   2,   3,   3,   3,   3,   3,   4,   4,
        4,   4,   4,   5,   5,   5,   5,   6,   6,   6,   6,   7,   7,   7,   7,   8,
        8,   8,   9,   9,   91010101111121212131314,
       14151515161617171818191920202122,
       22232324252526262728282930303132,
       33333435363637383940404142434445,
       46464748495051525354555657585960,
       61626364656768697071727375767778,
       80818283858687899091939495979899,
      101, 102, 104, 105, 107, 108, 110, 111, 113, 114, 116, 117, 119, 121, 122, 124,
      125, 127, 129, 130, 132, 134, 135, 137, 139, 141, 142, 144, 146, 148, 150, 151,
      153, 155, 157, 159, 161, 163, 165, 166, 168, 170, 172, 174, 176, 178, 180, 182,
      184, 186, 189, 191, 193, 195, 197, 199, 201, 204, 206, 208, 210, 212, 215, 217,
      219, 221, 224, 226, 228, 231, 233, 235, 238, 240, 243, 245, 248, 250, 253, 255 };

}
TOP

Related Classes of com.mattibal.meshnet.MeshNetTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.