예제 #1
0
def test_decode_command_2():
	"Decode Command -Test 2 - SET command decoding test"
	
	d = decode_command(chr(187))
	
	assert d['command_type'] == 'SET'
	assert d['status'] == 'OFF'
예제 #2
0
def test_decode_command_1():
	"Decode Command - Test 1 - GET command decoding test"

	d = decode_command(chr(107)) 
	
	assert d['command_type'] == 'GET'
	assert d['status'] == 'ON'
예제 #3
0
 def get_device_status(self, section_name, device_name):
     """
     This function returns the status of device
     :param section_name: Character string for the section 
     :param device_name: Character string for the device
     """
     #self.rev_section_friendly_names[section_number] = sectiom_number
     #self.rev_device_friendly_names[device_number] = device_number
     #
     #cmd = C.encode_command(command_type, status, section_number, device_number )
     
     section_number = self.get_section_number(section_name)
     device_number = self.get_device_number(section_number, device_name)
     
     cmd = encode_command('GET', 'OFF', section_number, device_number)
     self.outfile.write(cmd)
     self.outfile.flush()
     
     self.infile.seek(0,2)
     while 0 == self.infile.tell():
         self.infile.seek(0,2)
         time.sleep(1)
     
     self.infile.seek(-1,2)
     byte = self.infile.read()
     
     cmd_response = decode_command(byte)
     return cmd_response['status']
예제 #4
0
def send_command():
    
    byte = encode_command(command_type, status, section_number, device_number)
    ser.open()
    
    txData = byte;
    ser.write(txData);
    
    time.sleep(10)

    rxData = ser.read(byte);
    new_byte = decode_command(rxData)
    
    
    ser.close()
    
    return new_byte
예제 #5
0
 def process_requests(self, infile, outfile):
     """
     This method reads the first byte form infile and after processing writes the encoded command in the outfile. 
     This method uses infinite loop that will process request after evry second.  
     
     """
     
     print("Running dummy PCB and waiting to process requests...")
     prev_byte = ''
     
     while True:
         time.sleep(1)
         #first check if file is not empty
         infile.seek(0,2)
         if 0 == infile.tell():
             continue
         
         infile.seek(-1,2)
         byte = infile.read(1)
         
         if byte==prev_byte:
             continue  #only do processing if there is a new command
         
         prev_byte = byte
         cmd = decode_command(byte)
         print("    Got command" + repr(cmd))
         
         if 'GET' == cmd['command_type']:
             status = self.get_status(cmd['section_number'], cmd['device_number'])
             new_byte = encode_command(cmd['command_type'], status, cmd['section_number'], cmd['device_number'] )
             
         elif 'SET' == cmd['command_type']:
             self.set_status(cmd['section_number'], cmd['device_number'], cmd['status'])
             new_byte = byte
         
         outfile.write(new_byte)
         outfile.flush()