def test_get_fixed_width_object_from_serial_port(self): pn = MockSerialPortNode() #pn.debug = 5 # Initialize some data to be 'read' from our mock serial port node. for x in chr(0xAA) + chr(0x03) + chr(0xFF): pn.addbuffer(ord(x)) #print pn.get_buffer_str() conn = gc.FrameworkSerialPortWrapper(pn) lines = "" \ "# Single byte Class\n" \ "class singlebyte {\n" \ " uint8 preamble = 0xAA;\n" \ " uint8 data;\n" \ " uint8 postamble = 0xFF;\n" \ "}\n" lines = lines.split('\n') pc = ProtoCompiler() pc.parseLines(lines) c = pc.emitCode() pyfilename = os.path.join(properties.TEMP_DIR, "singlebyte.py") f = open(pyfilename, 'w') f.write(c) f.close() # Now try to import it. import singlebyte request_obj = singlebyte.singlebyte() response_obj = singlebyte.singlebyte() req_data_obj = request_obj.findChildByName('data') # resp_data_obj = response_obj.findChildByName('data') lh = gdlh.SimpleLineHandler(conn) req_data_obj.setValue(0x01) res = lh.send_request_with_response(request_obj, response_obj, 30) #print res os.remove(pyfilename)
def test_get_fixed_width_object_from_serial_port(self): pn = MockSerialPortNode() #pn.debug = 5 # Initialize some data to be 'read' from our mock serial port node. for x in chr(0xAA) + chr(0x03) + chr(0xFF): pn.addbuffer(ord(x)) #print pn.get_buffer_str() conn = gc.FrameworkSerialPortWrapper(pn) lines = "" \ "# Single byte Class\n" \ "class singlebyte {\n" \ " uint8 preamble = 0xAA;\n" \ " uint8 data;\n" \ " uint8 postamble = 0xFF;\n" \ "}\n" lines = lines.split('\n') pc = ProtoCompiler() pc.parseLines(lines) c = pc.emitCode() pyfilename = os.path.join(properties.TEMP_DIR, "singlebyte.py") f = open(pyfilename, 'w') f.write(c) f.close() # Now try to import it. import singlebyte request_obj = singlebyte.singlebyte() response_obj = singlebyte.singlebyte() req_data_obj = request_obj.findChildByName('data') # resp_data_obj = response_obj.findChildByName('data') lh = gdlh.SimpleLineHandler(conn) req_data_obj.setValue(0x01) res = lh.send_request_with_response(request_obj, response_obj, 30) #print res os.remove(pyfilename)
def test_case_singlebyte(self): lines = "" \ "# Single byte Class\n" \ "class singlebyte {\n" \ " uint8 preamble = 0xAA;\n" \ " uint8 data;\n" \ " uint8 postamble = 0xFF;\n" \ "}\n" pc = ProtoCompiler() fname = os.path.join(properties.TEMP_DIR, 'single_byte.class') f = open(fname, 'w') f.write(lines) f.close() pc.parseFile(fname) assert pc.classnames == ['singlebyte'], "Classnames != ['singlebyte']" my_class = pc._getClass('singlebyte') assert my_class.isPackCompatible( ) == 1, "Class should be pack compatible." exp_spec = '<B<B<B' assert my_class.packSpec( ) == exp_spec, "Class spec should be '%s', got '%s'." % ( exp_spec, my_class.packSpec()) assert my_class.isFixedWidth() == 1, "Width should be fixed." assert my_class.getWidth( ) == 3, "Width should be 3, got %d." % my_class.getWidth() c = pc.emitCode() pyfilename = os.path.join(properties.TEMP_DIR, "singlebyte.py") f = open(pyfilename, 'w') f.write(c) f.close() # Now try to import it. import singlebyte obj = singlebyte.singlebyte() assert obj.isFixedWidth() == 1, "isFixedWidth() should be 1" assert obj.isPackCompatible() == 1, "isPackCompatible() should be 1" assert obj.packSpec() == "<B<B<B", "packSpec() should be <B<B<B" assert obj.getWidth( ) == 3, "Width should be 3, got %d" % obj.getWidth() assert obj.getNumItems( ) == 3, "NumItems should be 3, got %d" % obj.getNumItems()