Package remote.protocol.motecontrol

Source Code of remote.protocol.motecontrol.MsgRequest

package remote.protocol.motecontrol;

import java.io.DataInput;
import java.io.DataOutput;

import remote.protocol.MsgIO;
import remote.protocol.MsgPayload;

public class MsgRequest extends MsgIO {

  private MsgCommand command;
  private MsgPayload flashImage;

  public MsgRequest() {
    super();
    command = new MsgCommand();
    flashImage = new MsgPayload();
  }

  public void read(DataInput is) throws Exception
  {
    command.read(is);

    switch(command.getValue())
    {
      case MsgCommand.PROGRAM:
        flashImage.read(is);
        break;
      case MsgCommand.RESET:
      case MsgCommand.START:
      case MsgCommand.STOP:
      case MsgCommand.STATUS:
        break;
      default:
        throw new Exception("Invalid command in request!");
    }
  }

  public void write(DataOutput os) throws Exception
  {
    switch(command.getValue())
    {
      case MsgCommand.PROGRAM:
        command.write(os);
        flashImage.write(os);
        break;
      case MsgCommand.RESET:
      case MsgCommand.START:
      case MsgCommand.STOP:
      case MsgCommand.STATUS:
      case MsgCommand.CANCELPROGRAMMING:
        command.write(os);
        break;
      default:
        throw new Exception("Invalid command in request!");
    }
  }

  public MsgCommand getCommand() {
    return command;
  }

  public MsgPayload getFlashImage() {
    return flashImage;
  }


}
TOP

Related Classes of remote.protocol.motecontrol.MsgRequest

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.