BowlerKernel
GetValueCommand.java
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright 2010 Neuron Robotics, LLC
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  ******************************************************************************/
15 package com.neuronrobotics.sdk.commands.bcs.io;
16 
17 import com.neuronrobotics.sdk.common.BowlerAbstractCommand;
18 import com.neuronrobotics.sdk.common.BowlerDatagram;
19 import com.neuronrobotics.sdk.common.BowlerMethod;
20 import com.neuronrobotics.sdk.common.ByteList;
21 import com.neuronrobotics.sdk.common.InvalidResponseException;
22 
23 // TODO: Auto-generated Javadoc
27 public class GetValueCommand extends BowlerAbstractCommand {
28 
30  private int channel;
31 
37  public GetValueCommand(int channel) {
38  this.channel = channel;
39  setOpCode("gchv");
41  }
42 
43  /* (non-Javadoc)
44  * @see com.neuronrobotics.sdk.common.BowlerAbstractCommand#getCallingData()
45  */
46  @Override
47  public byte[] getCallingData() {
48  return ByteList.wrap(channel);
49  }
50 
51  /* (non-Javadoc)
52  * @see com.neuronrobotics.sdk.common.BowlerAbstractCommand#parseResponse(com.neuronrobotics.sdk.common.BowlerDatagram)
53  */
54  @Override
56  super.validate(data);
57  if (data == null){
58  //System.err.println("No response to Get Value Command\n"+data);
59  throw new InvalidResponseException("Get Channel Value did not respond.");
60  }
61  if(!data.getRPC().equals(getOpCode())) {
62  //System.err.println("Wrong response to Get Value Command, expected:"+getOpCode()+", got:\n"+data);
63  throw new InvalidResponseException("Get Channel Value did not return with 'gchv'.\n"+data);
64  }
65 
66  return data;
67  }
68 }
static byte[] wrap(int value)
Definition: ByteList.java:554