BowlerKernel
NamespaceCommand.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.core;
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.InvalidResponseException;
21 
22 // TODO: Auto-generated Javadoc
27 
31  public NamespaceCommand() {
32  setOpCode("_nms");
34  }
35 
41  public NamespaceCommand(int name) {
42  setOpCode("_nms");
44  getCallingDataStorage().add(name);
45  }
46 
53  public NamespaceCommand(int name,boolean upstream) {
54  setOpCode("_nms");
55  if(upstream)
57  else
59  getCallingDataStorage().add(name);
60  }
61 
68  public NamespaceCommand(int index,String name) {
69  setOpCode("_nms");
71  getCallingDataStorage().add(name);
72  getCallingDataStorage().add(0);// null terminate the string
73  getCallingDataStorage().add(index);// set the size of the list of namespaces
74  }
75 
84  @Override
86  if (data==null){
87  // TODO: Correct this with JSDK-8
88  throw new InvalidResponseException("No response from device");
89  }
90  // throws
91  if( data.getRPC().equals("_err")) {
92  Integer zone=Integer.valueOf(data.getData().getByte(0));
93  Integer section=Integer.valueOf(data.getData().getByte(1));
94 
95  switch(zone) {
96  default:
97  throw new InvalidResponseException("Unknown error. (" + zone + " " + section + ")");
98  case 0:
99  switch(section) {
100  default:
101  throw new InvalidResponseException("Unknow error in the communications stack. (" + zone + " " + section + ")");
102  case 0x7f:
103  throw new InvalidResponseException("The method provided is invalid.");
104  case 0:
105  throw new InvalidResponseException("The packet was not sent syncronously.");
106  case 1:
107  throw new InvalidResponseException("The RPC sent in undefined with GET method.");
108  case 2:
109  throw new InvalidResponseException("The RPC sent in undefined with POST method.");
110  case 3:
111  throw new InvalidResponseException("The RPC sent in undefined with CRITICAL method.");
112  case 4:
113  throw new InvalidResponseException("Invalid namespace request");
114  case 5:
115  throw new InvalidResponseException("Invalid namespace index requested");
116  }
117  }
118  }
119 
120  return data;
121  }
122 }
synchronized boolean add(byte data)
Definition: ByteList.java:149