Пример #1
0
   def __init__(self,node):
      if isinstance(node, apx.Node):
          self.node=node
          context=apx.Context()
          context.append(node)
          apx_text=context.dumps()
      elif isinstance(node, str):
         parser = apx.Parser()
         apx_text=node
         self.node = parser.loads(apx_text)
      else:
         raise NotImplementedError(type(node))

      compiler = apx.compiler.Compiler()
      self.name=self.node.name
      self.inPortByteMap = [] #length: length of self.inPortDataFile
      self.inPortDataMap = [] #length: number of require ports
      self.outPortDataMap = [] #length: number of provide ports
      self.inPortPrograms = [] #length: number of require ports
      self.outPortPrograms = [] #length: number of provide ports
      self.outPortValues = [] #length: number of provide ports
      self.inPortDataFile = self._createInPortDataFile(self.node, compiler) if len(self.node.requirePorts)>0 else None
      self.outPortDataFile = self._createOutPortDataFile(self.node, compiler) if len(self.node.providePorts)>0 else None
      self.definitionFile = self._createDefinitionFile(node.name,apx_text)
      self.vm = apx.VM()
      self.lock=threading.Lock() #the virtual machine is not thread-safe, use this lock to protect it in case users try to read/write ports from multiple threads
      if self.inPortDataFile is not None:
         self.inPortDataFile.nodeDataHandler=self
      self.nodeDataClient=None
Пример #2
0
def _create_apx_context_from_autosar_workspace(ws):
    context = apx.Context()
    for swc in ws.findall('/ComponentType/*'):
        if isinstance(swc, autosar.component.AtomicSoftwareComponent):
            node = apx.Node().import_autosar_swc(swc)
            context.append(node)
    return context
Пример #3
0
    def test_copy_ports_between_nodes(self):
        apx_text = """APX/1.2
N"TestNode1"
T"Repetitions_T"C
T"SoundId_T"S
T"Volume_T"C
T"SoundRequest_T"{"SoundId"T["SoundId_T"]"Volume"T["Volume_T"]"Repetitions"T["Repetitions_T"]}
P"SoundRequest"T["SoundRequest_T"]:={65535,255,255}
"""
        node1 = apx.Node.from_text(apx_text)
        self.assertIsInstance(node1, apx.Node)
        node1.finalize()
        node2 = apx.Node('MyCopy')
        self.assertIsInstance(node2, apx.Node)
        port1 = node1.find('SoundRequest')
        self.assertIsInstance(port1, apx.ProvidePort)
        port2 = node2.add_port_from_node(node1, port1)
        self.assertIsInstance(port2, apx.ProvidePort)
        node2.finalize(sort=True)
        result = apx.Context().append(node2).dumps()
        expected = """APX/1.2
N"MyCopy"
T"Repetitions_T"C
T"SoundId_T"S
T"SoundRequest_T"{"SoundId"T[1]"Volume"T[3]"Repetitions"T[0]}
T"Volume_T"C
P"SoundRequest"T[2]:={65535,255,255}
"""
        self.assertEqual(expected, result)
Пример #4
0
   def test_load_dumped_apx_text(self):
      node1 = apx.Node('Simulator')
      node1.dataTypes.append(apx.DataType('InactiveActive_T','C(0,3)'))
      node1.providePorts.append(apx.ProvidePort('VehicleSpeed','S','=65535'))
      node1.providePorts.append(apx.ProvidePort('MainBeam','T[0]','=3'))
      node1.providePorts.append(apx.ProvidePort('FuelLevel','C'))
      node1.providePorts.append(apx.ProvidePort('ParkBrakeActive','T[0]','=3'))
      node1.requirePorts.append(apx.RequirePort('RheostatLevelRqst','C','=255'))
      self.assertFalse(node1.providePorts[0].dsg.isComplexType())

      node1.finalize()
      context = apx.Context()
      context.append(node1)
      text=context.dumps()

      apx_parser = apx.Parser()
      node2 = apx_parser.loads(text)
      self.assertFalse(node2.providePorts[0].dsg.isComplexType())
Пример #5
0
 def test_dumps_from_raw(self):
    node = apx.Node('Simulator')
    node.dataTypes.append(apx.DataType('InactiveActive_T','C(0,3)'))
    node.providePorts.append(apx.ProvidePort('VehicleSpeed','S','=65535'))
    node.providePorts.append(apx.ProvidePort('MainBeam','T[0]','=3'))
    node.providePorts.append(apx.ProvidePort('FuelLevel','C'))
    node.providePorts.append(apx.ProvidePort('ParkBrakeActive','T[0]','=3'))
    node.requirePorts.append(apx.RequirePort('RheostatLevelRqst','C','=255'))
    node.finalize()
    context = apx.Context()
    context.append(node)
    text=context.dumps()
    lines=re.compile(r'\r\n|\n').split(text)
    self.assertEqual(len(lines),9)
    self.assertEqual(lines[0],'APX/1.2')
    self.assertEqual(lines[1],'N"Simulator"')
    self.assertEqual(lines[2],'T"InactiveActive_T"C(0,3)')
    self.assertEqual(lines[3],'P"VehicleSpeed"S:=65535')
    self.assertEqual(lines[4],'P"MainBeam"T[0]:=3')
    self.assertEqual(lines[5],'P"FuelLevel"C')
    self.assertEqual(lines[6],'P"ParkBrakeActive"T[0]:=3')
    self.assertEqual(lines[7],'R"RheostatLevelRqst"C:=255')
    self.assertEqual(lines[8],'')
Пример #6
0
            swc.apply(UpButtonPressed.Receive)
            swc.apply(DownButtonPressed.Receive)

            swc.apply(HomeButtonLED.Send)
            swc.apply(BackButtonLED.Send)
            swc.apply(EnterButtonLED.Send)
            swc.apply(LeftButtonLED.Send)
            swc.apply(RightButtonLED.Send)
            swc.apply(UpButtonLED.Send)
            swc.apply(DownButtonLED.Send)


if __name__ == '__main__':
    start = time.time()
    gen_dir = os.path.abspath('source/apx_proxy')
    header_dir = os.path.abspath('inc/apx_proxy')

    ws = autosar.workspace()
    ws.apply(BspServiceProxy)
    node = apx.Node.from_autosar_swc(ws.find('/ComponentType/BspServiceProxy'))
    context = apx.Context()
    #context.append(node)
    #context.generateAPX('.')
    apx.NodeGenerator().generate(gen_dir,
                                 node,
                                 includes=['Rte_Type.h'],
                                 header_dir=header_dir)

    delta = float(time.time() - start) * 1000
    print('%dms' % (round(delta)))
Пример #7
0
portInterfaces.createSenderReceiverInterface(
    'VehicleSpeed_I', autosar.DataElement('VehicleSpeed', 'VehicleSpeed_T'))
components = ws.createPackage('ComponentType', role='ComponentType')
swc = components.createApplicationSoftwareComponent('test_client')
swc.createRequirePort('EngineRunningStatus',
                      'EngineRunningStatus_I',
                      initValueRef=constants['C_EngineRunningStatus_IV'].ref)
swc.createRequirePort('FuelLevelPercent',
                      'FuelLevelPercent_I',
                      initValueRef=constants['C_FuelLevelPercent_IV'].ref)
swc.createRequirePort('VehicleSpeed',
                      'VehicleSpeed_I',
                      initValueRef=constants['C_VehicleSpeed_IV'].ref)

swc.behavior.createRunnable(swc.name + '_Init',
                            portAccess=[x.name for x in swc.providePorts])
swc.behavior.createRunnable(
    swc.name + '_Run',
    portAccess=[x.name for x in swc.requirePorts + swc.providePorts])

partition = autosar.rte.Partition()
partition.addComponent(swc)
typeGenerator = autosar.rte.TypeGenerator(partition)
typeGenerator.generate()

node = apx.Node()
node.import_autosar_swc(swc)
node.append(apx.ProvidePort('VehicleMode', 'C(0,15)', '=15'))
apx.NodeGenerator().generate('.', node, includes=['Rte_Type.h'])
apx.Context().append(node).generateAPX('.')
Пример #8
0
import apx

node = apx.Node('Example')
node.append(apx.DataType('BatteryVoltage_T', 'S'))
node.append(apx.DataType('Date_T', '{"Year"C"Month"C(1,13)"Day"C(1,32)}'))
node.append(
    apx.DataType(
        'InactiveActive_T', 'C(0,3)',
        'VT("InactiveActive_Inactive", "InactiveActive_Active", "InactiveActive_Error", "InactiveActive_NotAvailable")'
    ))

node.append(
    apx.ProvidePort('BatteryVoltage', 'T["BatteryVoltage_T"]', '=65535'))
node.append(apx.RequirePort('CurrentDate', 'T["Date_T"]', '={255, 13, 32}'))
node.append(
    apx.RequirePort('ExteriorLightsActive', 'T["InactiveActive_T"]', '=3'))

print(apx.Context().append(node).dumps())