/**
   * Activate this <tt>UDPTerminal</tt>.
   *
   * @throws Exception if there is a network failure.
   */
  public synchronized void activate() throws Exception {
    if (!isActive()) {
      if (Modbus.debug)
        CCLog.info(
            "UDPMasterTerminal::activate()::laddr=:" + m_LocalAddress + ":lport=" + m_LocalPort);

      if (m_Socket == null) {
        if (m_LocalAddress != null && m_LocalPort != -1) {
          m_Socket = new DatagramSocket(m_LocalPort, m_LocalAddress);
        } else {
          m_Socket = new DatagramSocket();
          m_LocalPort = m_Socket.getLocalPort();
          m_LocalAddress = m_Socket.getLocalAddress();
        }
      }
      if (Modbus.debug) CCLog.info("UDPMasterTerminal::haveSocket():" + m_Socket.toString());
      if (Modbus.debug)
        CCLog.info(
            "UDPMasterTerminal::laddr=:" + m_LocalAddress.toString() + ":lport=" + m_LocalPort);
      if (Modbus.debug)
        CCLog.info(
            "UDPMasterTerminal::raddr=:" + m_RemoteAddress.toString() + ":rport=" + m_RemotePort);

      m_Socket.setReceiveBufferSize(1024);
      m_Socket.setSendBufferSize(1024);

      m_ModbusTransport = new ModbusUDPTransport(this);
      m_Active = true;
    }
    if (Modbus.debug) CCLog.info("UDPMasterTerminal::activated");
  }
예제 #2
0
  public void run() {
    try {
      while (true) {
        CCLog.info(_myTime);
        long myTime = System.currentTimeMillis();
        if (!_myStartedProcess && _myTime >= _myWaitTime * 1000) {
          //					System.out.println(CCIOUtil.dataPath(thePath));
          _myProcess = _myProcessBuilder.start();
          _myStartedProcess = true;
        }

        if (_myStartedProcess) {
          try {
            CCLog.info(_myProcess.exitValue());
            CCLog.info("RESTART");
            _myWaitTime = _myRestartTime;
            _myStartedProcess = false;
            _myTime = 0;
          } catch (IllegalThreadStateException e) {
            // ignore this process is still running which is exactly what we want
          }

          Scanner scanner = new Scanner(_myProcess.getInputStream());
          while (scanner.hasNextLine()) {
            _myOffTime = 0;
            parseTextLine(scanner.nextLine());
          }
          scanner.close();

          scanner = new Scanner(_myProcess.getErrorStream());
          while (scanner.hasNextLine()) CCLog.info(scanner.nextLine());
          scanner.close();
        }
        Thread.sleep(10);

        _myTime += System.currentTimeMillis() - myTime;
        _myOffTime += System.currentTimeMillis() - myTime;

        if (_myMaxOffTime > 0 && _myOffTime > _myMaxOffTime) {
          endProcess();
        }
      }

    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
예제 #3
0
 /* (non-Javadoc)
  * @see cc.creativecomputing.app.CCWatchDog.CCWatchDogCommandHandler#onCommand(java.lang.String)
  */
 public void onCommand(String theValue) {
   try {
     float myFrameRate = Float.parseFloat(theValue);
     if (myFrameRate < _myMinFrameRate) endProcess();
   } catch (NumberFormatException e) {
     CCLog.error("# COULD NOT READ FRAMERATE:" + theValue);
   }
 }
  /** Deactivates this <tt>UDPSlaveTerminal</tt>. */
  public void deactivate() {
    try {
      if (Modbus.debug) CCLog.info("UDPMasterTerminal::deactivate()");

      m_Socket.close();
      m_ModbusTransport = null;
      m_Active = false;
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
예제 #5
0
  private void parseTextLine(final String theLine) {
    if (!theLine.startsWith("-")) {
      CCLog.error("Can not parse arguments:" + theLine);
      return;
    }

    String[] myCommandArray = theLine.split(" ", 2);
    String myCommand = myCommandArray[0];
    String myValue = "";
    if (myCommandArray.length > 1) {
      myValue = myCommandArray[0];
    }

    List<CCWatchDogCommandHandler> myCommandHandlers = _myCommandHandlerMap.get(myCommand);
    if (myCommandHandlers != null) {
      for (CCWatchDogCommandHandler myCommandHandler : myCommandHandlers) {
        myCommandHandler.onCommand(myValue);
      }
    }
  }
예제 #6
0
  public static GLTexture load(ReadableByteChannel theInputChannel) {
    if (theInputChannel == null) return null;

    GLKTXHeader myHeader = new GLKTXHeader();
    myHeader.read(theInputChannel);
    //	    GLuint temp = 0;
    //	    GLuint retval = 0;
    //
    //	    size_t data_start, data_end;
    //	    unsigned char * data;
    //	    GLTextureTarget target = GL_NONE;

    if (myHeader.endianness == 0x04030201) {
      // No swap needed
    } else if (myHeader.endianness == 0x01020304) {
      // Swap needed
      myHeader.endianness = Integer.reverseBytes(myHeader.endianness);
      myHeader.gltype = Integer.reverseBytes(myHeader.gltype);
      myHeader.gltypesize = Integer.reverseBytes(myHeader.gltypesize);
      myHeader.glformat = Integer.reverseBytes(myHeader.glformat);
      myHeader.glinternalformat = Integer.reverseBytes(myHeader.glinternalformat);
      myHeader.glbaseinternalformat = Integer.reverseBytes(myHeader.glbaseinternalformat);
      myHeader.pixelwidth = Integer.reverseBytes(myHeader.pixelwidth);
      myHeader.pixelheight = Integer.reverseBytes(myHeader.pixelheight);
      myHeader.pixeldepth = Integer.reverseBytes(myHeader.pixeldepth);
      myHeader.arrayelements = Integer.reverseBytes(myHeader.arrayelements);
      myHeader.faces = Integer.reverseBytes(myHeader.faces);
      myHeader.miplevels = Integer.reverseBytes(myHeader.miplevels);
      myHeader.keypairbytes = Integer.reverseBytes(myHeader.keypairbytes);
    }

    GLTextureTarget target = null;

    // Guess target (texture type)
    if (myHeader.pixelheight == 0) {
      if (myHeader.arrayelements == 0) {
        target = GLTextureTarget.TEXTURE_1D;
      } else {
        target = GLTextureTarget.TEXTURE_1D_ARRAY;
      }
    } else if (myHeader.pixeldepth == 0) {
      if (myHeader.arrayelements == 0) {
        if (myHeader.faces == 0 || myHeader.faces == 1) {
          target = GLTextureTarget.TEXTURE_2D;
        } else {
          target = GLTextureTarget.TEXTURE_CUBE_MAP;
        }
      } else {
        if (myHeader.faces == 0) {
          target = GLTextureTarget.TEXTURE_2D_ARRAY;
        } else {
          target = GLTextureTarget.TEXTURE_CUBE_MAP_ARRAY;
        }
      }
    } else {
      target = GLTextureTarget.TEXTURE_3D;
    }

    if (target == null) throw new RuntimeException("Couldn't figure out target");
    if (myHeader.pixelwidth == 0) throw new RuntimeException("Texture has no width???");
    if (myHeader.pixelheight == 0 && myHeader.pixeldepth != 0)
      throw new RuntimeException("Texture has depth but no height???");

    ByteBuffer data = null;

    if (theInputChannel instanceof FileChannel) {
      try {
        FileChannel myFileChannel = (FileChannel) theInputChannel;
        data = ByteBuffer.allocateDirect((int) (myFileChannel.size() - myFileChannel.position()));
        myFileChannel.read(data);
        data.rewind();
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }

    if (myHeader.miplevels == 0) {
      myHeader.miplevels = 1;
    }

    GLPixelDataInternalFormat myInternalFormat =
        GLPixelDataInternalFormat.fromGLID(myHeader.glinternalformat);
    GLPixelDataFormat myFormat = GLPixelDataFormat.fromGLID(myHeader.glformat);
    GLPixelDataType myType = GLPixelDataType.fromGLID(myHeader.gltype);

    CCLog.info(
        myInternalFormat
            + " ; "
            + myFormat
            + " ; "
            + myType
            + " ; "
            + Integer.toHexString(myHeader.glinternalformat));

    GL4 gl = GLGraphics.currentGL();
    GLTexture myResult = null;

    switch (target) {
      case TEXTURE_1D:
        GLTexture1D myTexture1D =
            new GLTexture1D(myHeader.miplevels, myInternalFormat, myHeader.pixelwidth);
        myTexture1D.texSubImage1D(0, 0, myHeader.pixelwidth, myFormat, myType, data);
        myResult = myTexture1D;
        break;
      case TEXTURE_2D:
        GLTexture2D myTexture2D =
            new GLTexture2D(
                myHeader.miplevels, myInternalFormat, myHeader.pixelwidth, myHeader.pixelheight);

        {
          int height = myHeader.pixelheight;
          int width = myHeader.pixelwidth;
          gl.glPixelStorei(GL4.GL_UNPACK_ALIGNMENT, 1);
          for (int i = 0; i < myHeader.miplevels; i++) {
            myTexture2D.texSubImage2D(i, 0, 0, width, height, myFormat, myType, data);
            //	                    ptr += height * calculate_stride(h, width, 1);

            height >>= 1;
            width >>= 1;
            if (height <= 0) height = 1;
            if (width <= 0) width = 1;
          }
        }
        myResult = myTexture2D;
        break;
      case TEXTURE_3D:
        GLTexture3D myTexture3D =
            new GLTexture3D(
                myHeader.miplevels,
                myInternalFormat,
                myHeader.pixelwidth,
                myHeader.pixelheight,
                myHeader.pixeldepth);
        myTexture3D.texSubImage3D(
            0,
            0,
            0,
            0,
            myHeader.pixelwidth,
            myHeader.pixelheight,
            myHeader.pixeldepth,
            myFormat,
            myType,
            data);
        myResult = myTexture3D;
        break;
      case TEXTURE_1D_ARRAY:
        GLTexture1DArray myTexture1DArray =
            new GLTexture1DArray(
                myHeader.miplevels, myInternalFormat, myHeader.pixelwidth, myHeader.arrayelements);
        myTexture1DArray.texSubImage(
            0, 0, 0, myHeader.pixelwidth, myHeader.arrayelements, myFormat, myType, data);
        myResult = myTexture1DArray;
        break;
      case TEXTURE_2D_ARRAY:
        GLTexture2DArray myTexture2DArray =
            new GLTexture2DArray(
                myHeader.miplevels,
                myInternalFormat,
                myHeader.pixelwidth,
                myHeader.pixelheight,
                myHeader.arrayelements);
        myTexture2DArray.texSubImage(
            0,
            0,
            0,
            0,
            myHeader.pixelwidth,
            myHeader.pixelheight,
            myHeader.arrayelements,
            myFormat,
            myType,
            data);
        myResult = myTexture2DArray;
        break;
        //	        case TEXTURE_CUBE_MAP:
        //	            glTexStorage2D(GL_TEXTURE_CUBE_MAP, myHeader.miplevels,
        // myHeader.glinternalformat, myHeader.pixelwidth, myHeader.pixelheight);
        //	            // glTexSubImage3D(GL_TEXTURE_CUBE_MAP, 0, 0, 0, 0, myHeader.pixelwidth,
        // myHeader.pixelheight, myHeader.faces, myHeader.glformat, myHeader.gltype, data);
        //	            {
        //	                int face_size = calculate_face_size(h);
        //	                for (int i = 0; i < myHeader.faces; i++)
        //	                {
        //	                    glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0,
        // myHeader.pixelwidth, myHeader.pixelheight, myHeader.glformat, myHeader.gltype, data +
        // face_size * i);
        //	                }
        //	            }
        //	            break;
        //	        case TEXTURE_CUBE_MAP_ARRAY:
        //	            glTexStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY, myHeader.miplevels,
        // myHeader.glinternalformat, myHeader.pixelwidth, myHeader.pixelheight,
        // myHeader.arrayelements);
        //	            glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, 0, 0, 0, myHeader.pixelwidth,
        // myHeader.pixelheight, myHeader.faces * myHeader.arrayelements, myHeader.glformat,
        // myHeader.gltype, data);
        //	            break;
        //	        default:                                               // Should never happen
        //	            goto fail_target;
    }

    if (myHeader.miplevels == 1) {
      myResult.generateMipMaps();
    }
    return myResult;
  }
예제 #7
0
 @Override
 public void stop() {
   CCLog.info("STOP APP");
 }
예제 #8
0
 @Override
 public void stop(CCAnimator theAnimator) {
   CCLog.info("STOP ANIMATOR");
 }
예제 #9
0
 @Override
 public void update(CCAnimator theAnimator) {
   CCLog.info(
       theAnimator.frames() + " : " + theAnimator.frameRate() + " : " + theAnimator.deltaTime());
 }
예제 #10
0
 @Override
 public void start(CCAnimator theAnimator) {
   CCLog.info("START ANIMATOR");
 }
예제 #11
0
 @Override
 public void start() {
   CCLog.info("START APP");
 }