BowlerKernel
DyIOChannelEvent.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.dyio;
16 
17 import com.neuronrobotics.sdk.common.ByteList;
18 
19 // TODO: Auto-generated Javadoc
25 public class DyIOChannelEvent {
26 
28  private ByteList data;
29 
32 
34  private Integer integer;
35 
43  this.channel = channel;
44  this.data = data;
45  }
46 
53  public DyIOChannelEvent(DyIOChannel c, Integer integer) {
54  // TODO Auto-generated constructor stub
55  this.channel =c;
56  this.integer = integer;
57 
58  }
59 
66  return channel;
67  }
68 
74  public ByteList getData() {
75  return data;
76  }
77 
83  public int getValue() {
84  if(integer!=null)
85  return integer;
86  int value;
89  return 0;
90  switch(mode){
91  case COUNT_IN_DIR:
92  case COUNT_IN_INT:
93  case COUNT_OUT_DIR:
94  case COUNT_OUT_INT:
95  value = getSignedValue();
96  break;
97  default:
98  value = getUnsignedValue();
99  break;
100  }
101  return value;
102  }
103 
109  public int getUnsignedValue() {
110  if(integer!=null)
111  return integer;
112  return ByteList.convertToInt(getData().getBytes(),false);
113  }
114 
120  public int getSignedValue() {
121  if(integer!=null)
122  return integer;
123  int value =ByteList.convertToInt(getData().getBytes(),true);
124  return value;
125  }
126 }
static final int convertToInt(byte[] b)
Definition: ByteList.java:911
DyIOChannelEvent(DyIOChannel c, Integer integer)
DyIOChannelEvent(DyIOChannel channel, ByteList data)