def test_code_generator(self): node = apx.Node("TestCallbackFirst") node.append(apx.RequirePort('RS32Port', 'l', '=-2147483648')) node.append(apx.RequirePort('RU8Port', 'C', '=255')) callback_map = {'RS32Port': 'RS32Port_cb_func'} output_dir = 'derived' output_dir_full = os.path.join(os.path.dirname(__file__), output_dir) if not os.path.exists(output_dir_full): os.makedirs(output_dir_full) time.sleep(0.1) apx.NodeGenerator().generate(output_dir_full, node, callbacks=callback_map) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.h'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.h'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.c'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.c'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) shutil.rmtree(output_dir_full)
def test_code_generator(self): node = apx.Node("TestSimpleOnlyP") node.append(apx.ProvidePort('PS8Port', 'c', '=-1')) output_dir = 'derived' output_dir_full = os.path.join(os.path.dirname(__file__), output_dir) if not os.path.exists(output_dir_full): os.makedirs(output_dir_full) time.sleep(0.1) apx.NodeGenerator().generate(output_dir_full, node) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.h'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.h'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.c'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.c'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) shutil.rmtree(output_dir_full)
def test_code_generator(self): node = apx.Node("TestSimple") node.append(apx.RequirePort('RS32Port', 'l', '=-2147483648')) node.append(apx.RequirePort('RU8Port', 'C', '=255')) node.append(apx.RequirePort('PS16ARPort256', 's[256]')) node.append(apx.ProvidePort('PS16ARPort256', 's[256]')) node.append(apx.ProvidePort('PS8Port', 'c', '=-1')) node.append(apx.ProvidePort('PU32Port', 'L', '=4294967295')) output_dir = 'derived' output_dir_full = os.path.join(os.path.dirname(__file__), output_dir) if not os.path.exists(output_dir_full): os.makedirs(output_dir_full) time.sleep(0.1) apx.NodeGenerator().generate(output_dir_full, node) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.h'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.h'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.c'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.c'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) shutil.rmtree(output_dir_full)
def test_code_generator(self): node = apx.Node("TestSimpleOnlyR") node.append(apx.RequirePort('RU16Port','S','=0xffFF')) output_dir = 'derived' output_dir_full = os.path.join(os.path.dirname(__file__),output_dir) if not os.path.exists(output_dir_full): os.makedirs(output_dir_full) time.sleep(0.1) apx.NodeGenerator().generate(output_dir_full, node, with_inport_synced_status_flags=False) with open (os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.h'.format(node)), "r") as fp: generated=fp.read() with open (os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.h'.format(node)), "r") as fp: expected=fp.read() self.assertEqual(expected, generated) with open (os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.c'.format(node)), "r") as fp: generated=fp.read() with open (os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.c'.format(node)), "r") as fp: expected=fp.read() self.assertEqual(expected, generated) shutil.rmtree(output_dir_full)
def test_code_generator(self): node = apx.Node("Test") node.append(apx.DataType('SoundRequest_T', '{"SoundId"S"Volume"C}')) node.append(apx.RequirePort('U8Port', 'C', '=255')) node.append(apx.RequirePort('U8ARPort', 'C[3]', '={255, 255, 255}')) node.append( apx.RequirePort('SoundRequest', 'T["SoundRequest_T"]', '={65535,255}')) node.append( apx.ProvidePort('U16ARPort', 'S[4]', '={65535, 65535, 65535, 65535}')) node.append(apx.ProvidePort('U32Port', 'L', '=4294967295')) output_dir = 'derived' output_dir_full = os.path.join(os.path.dirname(__file__), output_dir) if not os.path.exists(output_dir_full): os.makedirs(output_dir_full) time.sleep(0.1) apx.NodeGenerator().generate(output_dir_full, node) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.h'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.h'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.c'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.c'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) shutil.rmtree(output_dir_full)
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)))
'FuelLevelPercent_I', autosar.DataElement('FuelLevelPercent', 'Percent_T')) 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('.')
def test_code_generator(self): node = apx.Node("Test") node.append(apx.DataType('SoundRequest_T', '{"SoundId"S"Volume"C}')) node.append(apx.DataType('LightRequest_T', '{"LightId"S"Intensity"C}')) node.append( apx.DataType('HapticRequest_T', '{"HapticId"S"Intensity"C}')) node.append(apx.RequirePort('RU8FirstPort', 'C', '=12')) node.append(apx.RequirePort('RS16ARPort', 's[3]', '={32767, 1, 0}')) node.append(apx.RequirePort('RS32Port', 'l', '=1')) node.append(apx.RequirePort('RU8Port', 'C', '=255')) node.append(apx.RequirePort('RU8ARPort', 'C[3]', '={255, 255, 255}')) node.append( apx.RequirePort('LightRequest', 'T["LightRequest_T"]', '={65535,255}')) node.append( apx.RequirePort('SoundRequest', 'T["SoundRequest_T"]', '={65535,255}')) node.append(apx.RequirePort('RU8LastPort', 'C', '=210')) node.append( apx.ProvidePort('SoundRequestAck', 'T["SoundRequest_T"]', '={65535,255}')) node.append( apx.ProvidePort('HapticRequest', 'T["HapticRequest_T"]', '={65535,255}')) node.append(apx.ProvidePort('PS8ARPort', 'c[1]', '={1}')) node.append(apx.ProvidePort('PS8Port', 'c', '=0')) node.append( apx.ProvidePort('PU16ARPort', 'S[4]', '={65535, 65535, 65535, 65535}')) node.append(apx.ProvidePort('PU32Port', 'L', '=4294967295')) callback_map = { 'RU8Port': 'RU8Port_cb_func', 'RS16ARPort': 'RS16ARPort_cb_func', 'SoundRequest': 'SoundRequest_cb_func' } output_dir = 'derived' output_dir_full = os.path.join(os.path.dirname(__file__), output_dir) if not os.path.exists(output_dir_full): os.makedirs(output_dir_full) time.sleep(0.1) # If we want ports in the order appended; explicitly finalize the node before generator node.finalize(sort=False, compact=True) apx.NodeGenerator().generate(output_dir_full, node, callbacks=callback_map) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.h'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.h'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.c'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.c'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}_Cbk.h'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}_Cbk.h'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) node.name = "Test_compact" apx.NodeGenerator().generate(output_dir_full, node, callbacks=callback_map, compact=True) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.h'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.h'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.c'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.c'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}_Cbk.h'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}_Cbk.h'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) shutil.rmtree(output_dir_full)
#!/usr/bin/env python3 import apx if __name__ == '__main__': node1 = apx.Node('TestNode1') node1.append(apx.ProvidePort('WheelBasedVehicleSpeed','S')) node1.append(apx.ProvidePort('CabTiltLockWarning','C(0,7)')) node1.append(apx.RequirePort('VehicleMode','C(0,15)')) node1.append(apx.RequirePort('GearSelectionMode','C(0,7)')) apx.NodeGenerator().generate('.', node1, includes=['Std_Types.h']) node2 = apx.Node('TestNode2') node2.append(apx.ProvidePort('ParkBrakeAlert','C(0,3)','=3')) apx.NodeGenerator().generate('.', node2, includes=['Std_Types.h'])
'T["PushButtonStatus_T"]', '=0')) node.append( apx.ProvidePort('SWS_PushbuttonStatus_Home', 'T["PushButtonStatus_T"]', '=0')) node.append( apx.ProvidePort('SWS_PushbuttonStatus_Left', 'T["PushButtonStatus_T"]', '=0')) node.append( apx.ProvidePort('SWS_PushbuttonStatus_Right', 'T["PushButtonStatus_T"]', '=0')) node.append( apx.ProvidePort('SWS_PushbuttonStatus_Up', 'T["PushButtonStatus_T"]', '=0')) node.append(apx.RequirePort('VehicleMode', 'T["VehicleMode_T"]', '=15')) node.finalize() apx.NodeGenerator().generate('.', node, includes=['ApxTypeDefs.h']) apx.NodeGenerator().generate('.', node, name='ButtonStatusDirect', includes=['ApxTypeDefs.h'], direct_write=[ 'SWS_PushbuttonStatus_Back', 'SWS_PushbuttonStatus_Down', 'SWS_PushbuttonStatus_Back', 'SWS_PushbuttonStatus_Enter', 'SWS_PushbuttonStatus_Home', 'SWS_PushbuttonStatus_Left', 'SWS_PushbuttonStatus_Back', 'SWS_PushbuttonStatus_Right', 'SWS_PushbuttonStatus_Up', ])
#com.apply(Signals.SystemTime.Receive) #com.apply(Signals.SystemDate.Receive) #com.apply(Signals.VehicleModeInternal.Send) partition.addComponent(com) partition.autoConnect() partition.finalize() typeGenerator = autosar.rte.TypeGenerator(partition) typeGenerator.generate(derived_dir) headerGenerator = autosar.rte.ComponentHeaderGenerator(partition) headerGenerator.generate(derived_dir) rteGenerator = autosar.rte.RteGenerator(partition) rteGenerator.generate(derived_dir) comGenerator = apx.generator.ComGenerator(com) comGenerator.generateHeader(derived_dir) comGenerator.generateSource(derived_dir) nodeGenerator = apx.NodeGenerator() nodeGenerator.generate(derived_dir, comGenerator.apx_node, includes=['Rte_Type.h']) os_cfg = create_os_config(partition) osConfigGenerator = autosar.bsw.OsConfigGenerator(os_cfg) osConfigGenerator.generate(derived_dir) rteTaskGenerator = autosar.rte.RteTaskGenerator(partition, os_cfg) rteTaskGenerator.generate(derived_dir) delta = float(time.time() - start) * 1000 print('%dms' % (round(delta)))
import apx node = apx.Node('TestNode') node.append(apx.ProvidePort('TestSignal2','C')) node.append(apx.RequirePort('TestSignal1','S')) callback_map={'TestSignal1': 'TestSignal1_CallbackFunc'} apx.NodeGenerator().generate('.', node, includes=['Rte_Type.h'], callbacks=callback_map)
def generate_apx_node(context, derived_dir): node_generator = apx.NodeGenerator() for node in context.nodes: node_generator.generate(derived_dir, node, includes=['Rte_Type.h'])