Package intera_io :: Module io_command
[hide private]
[frames] | no frames]

Source Code for Module intera_io.io_command

 1  # Copyright (c) 2013-2017, Rethink Robotics Inc. 
 2  # 
 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 -class IOCommand(object):
16 ''' 17 Container for a generic io command 18 '''
19 - def __init__(self, op, args=None):
20 self.op = op 21 self.args = args if args else {}
22
23 -class SetCommand(IOCommand):
24 ''' 25 Container for a port or signal set command 26 '''
27 - def __init__(self, args=None):
28 super(SetCommand, self).__init__('set', args)
29
30 - def _set(self, components, component_name, 31 data_type, dimensions, *component_value):
32 ''' 33 add a set component command 34 ''' 35 self.args.setdefault(components, {}) 36 self.args[components][component_name] = { 37 'format' : {'type' : data_type}, 38 'data' : [val for val in component_value] 39 } 40 if dimensions > 1: 41 self.args[components][component_name]['format']['dimensions'] = [dimensions]
42
43 - def set_signal(self, signal_name, data_type, *signal_value):
44 ''' 45 add a set signal command 46 ''' 47 dimensions = len(signal_value) 48 self._set('signals', signal_name, data_type, dimensions, *signal_value) 49 return self
50
51 - def set_port(self, port_name, data_type, *port_value):
52 ''' 53 add a set port command 54 ''' 55 dimensions = len(port_value) 56 self._set('ports', port_name, data_type, dimensions, *port_value) 57 return self
58