BowlerKernel
SetChannelValueCommand.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.ISendable;
21 import com.neuronrobotics.sdk.common.InvalidResponseException;
22 import com.neuronrobotics.sdk.dyio.DyIOChannelMode;
23 import com.neuronrobotics.sdk.dyio.InvalidChannelOperationException;
24 
25 // TODO: Auto-generated Javadoc
30 
38  public SetChannelValueCommand(int channel, int value, DyIOChannelMode mode) {
40  setOpCode("schv");
41  getCallingDataStorage().add(channel);
42  switch(mode) {
43  case ANALOG_OUT:
45  break;
46  case COUNT_OUT_INT:
47  case COUNT_OUT_DIR:
48  case COUNT_OUT_HOME:
51  break;
52  default:
53  getCallingDataStorage().add(value);
54  break;
55  }
56  }
57 
71  public SetChannelValueCommand(int channel, int value, float time, DyIOChannelMode mode) {
73  setOpCode("schv");
74 
75  getCallingDataStorage().add(channel);
76  switch(mode){
77  case COUNT_OUT_INT:
78  case COUNT_OUT_DIR:
79  case COUNT_OUT_HOME:
81  //Time is in seconds, the converts to Ms then sends as 16 bit value
82  getCallingDataStorage().addAs32((int)(time*1000));
83  break;
84  case SERVO_OUT:
85  getCallingDataStorage().add(value);
86  //Time is in seconds, the converts to Ms then sends as 16 bit value
87  getCallingDataStorage().addAs16((int)(time*1000));
88  break;
89  default:
90  getCallingDataStorage().add(value);
91  }
92  }
93 
100  public SetChannelValueCommand(int channel, ISendable data) {
102  setOpCode("schv");
103 
104  getCallingDataStorage().add(channel);
106  }
107 
121  public SetChannelValueCommand(int channel, int value, DyIOChannelMode mode,boolean saveTheValue) {
122  switch(mode) {
123  case SERVO_OUT:
124  case PWM_OUT:
125  if(saveTheValue)
127  else
129  setOpCode("schv");
130  getCallingDataStorage().add(channel);
131  getCallingDataStorage().add(value);
132  break;
133  default:
135  }
136  }
137 
145  public SetChannelValueCommand(int channel, int [] value, DyIOChannelMode mode) {
146  switch(mode) {
147  case PPM_IN:
149  setOpCode("schv");
150  getCallingDataStorage().add(channel);
151  getCallingDataStorage().add(value);
152  break;
153  default:
155  }
156  }
157 
158 
159  /* (non-Javadoc)
160  * @see com.neuronrobotics.sdk.common.BowlerAbstractCommand#parseResponse(com.neuronrobotics.sdk.common.BowlerDatagram)
161  */
162  @Override
164  super.validate(data);
165  if (data==null)
166  throw new InvalidResponseException("Set Channel Value did not respond");
167  if(!data.getRPC().equals("_rdy") && !data.getRPC().equals("schv") ) {
168  throw new InvalidResponseException("Set Channel Value did not return '_rdy'.");
169  }
170 
171  return data;
172  }
173 
174 }
SetChannelValueCommand(int channel, int value, DyIOChannelMode mode, boolean saveTheValue)
SetChannelValueCommand(int channel, int value, DyIOChannelMode mode)
SetChannelValueCommand(int channel, int[] value, DyIOChannelMode mode)
SetChannelValueCommand(int channel, int value, float time, DyIOChannelMode mode)
synchronized boolean add(byte data)
Definition: ByteList.java:149