コード例 #1
0
ファイル: Example_GET_ADC.py プロジェクト: perikods/PAPP_lib
def main():    
    ## Generate Get ADC frame
    my_frame=PAPP_frame()
    my_frame.addr=int(sys.argv[2],16)                ## Destination address
    my_frame.flen=2                                  ## CMD + channel 
    my_frame.data_cmd=PAPP_frame_cmd.GET_ADC         ## Type
    my_frame.data= channel                       ## PORTA value to set in remote node
    
    my_frame.WritePAPPFrame(s.write)                 ## Write to COM port
    print ('Raw frame sent:')
    my_frame.WritePAPPFrame(print_raw_frame)         ## Write to console raw frame
    print ('--------------------')
    print my_frame                                   ## Write to console object details
    print ('--------------------')
    
    my_read_frame=ReadPAPPFrame(s.read, timeout=10)
    if my_read_frame is not None and my_read_frame.data_cmd==PAPP_frame_cmd.GET_ADC_RSP:
        print ('Raw frame received:')        
        my_read_frame.WritePAPPFrame(print_raw_frame) ## Write to console raw frame
        print ('--------------------')
        print my_read_frame                           ## Write to console object details
        ## Unpack ADC channel, data and RSSI (last two bytes)
        ADC_channel, ADC_data, RSSI_lr, RSSI_rl= unpack('<BHBB',my_read_frame.data)
        print ('\nADC data of channel (%d): %d' % (ADC_channel, ADC_data)) 
        ## Print RSSI, both directions   
        print ('RSSI (local -> remote): %d' %((RSSI_lr/1.9)-127))
        print ('RSSI (local <- remote): %d' %((RSSI_rl/1.9)-127))          
    
    else:
        print ('Timeout')
    s.close()
コード例 #2
0
def main():
    ## Generate Set PORTA frame
    my_frame = PAPP_frame()
    my_frame.addr = int(sys.argv[2], 16)  ## Destination address
    my_frame.flen = 2  ## CMD + PORTA
    my_frame.data_cmd = PAPP_frame_cmd.SET_PORTA  ## Type
    my_frame.data = PORTA_data  ## PORTA value to set in remote node

    my_frame.WritePAPPFrame(s.write)  ## Write to COM port
    print ("Raw frame sent:")
    my_frame.WritePAPPFrame(print_raw_frame)  ## Write to console raw frame
    print ("--------------------")
    print my_frame  ## Write to console object details
    print ("--------------------")

    my_read_frame = ReadPAPPFrame(s.read, timeout=10)
    if my_read_frame is not None and my_read_frame.data_cmd == PAPP_frame_cmd.ACK_RSP:
        print ("Raw frame received:")
        my_read_frame.WritePAPPFrame(print_raw_frame)  ## Write to console raw frame
        print ("--------------------")
        print my_read_frame  ## Write to console object details
        RSSI_lr, RSSI_rl = unpack("BB", my_read_frame.data[-2:])  ## Unpack RSSI (last two bytes)
        ## Print RSSI, both directions
        print ("\nRSSI (local -> remote): %d" % ((RSSI_lr / 1.9) - 127))
        print ("RSSI (local <- remote): %d" % ((RSSI_rl / 1.9) - 127))

    else:
        print ("Timeout")
    s.close()
コード例 #3
0
ファイル: Example_SET_RGB.py プロジェクト: perikods/PAPP_lib
def main():    
    ## Generate Set RGB frame
    my_frame=PAPP_frame()
    my_frame.addr=int(sys.argv[2],16)                ## Destination address
    my_frame.flen=4                                  ## CMD + RGB
    my_frame.data_cmd=PAPP_frame_cmd.SET_RGB         ## Type
    my_frame.data= RGB_data                          ## PWM values to set in remote node
    
    my_frame.WritePAPPFrame(s.write)                 ## Write to COM port
    print ('Raw frame sent:')
    my_frame.WritePAPPFrame(print_raw_frame)         ## Write to console raw frame
    print ('--------------------')
    print my_frame                                   ## Write to console object details
    print ('--------------------')
    
    my_read_frame=ReadPAPPFrame(s.read, timeout=10)
    if my_read_frame is not None and my_read_frame.data_cmd==PAPP_frame_cmd.ACK_RSP:
        print ('Raw frame received:')        
        my_read_frame.WritePAPPFrame(print_raw_frame) ## Write to console raw frame
        print ('--------------------')
        print my_read_frame                           ## Write to console object details
        RSSI_lr, RSSI_rl= unpack('BB',my_read_frame.data[-2:])  ## Unpack RSSI (last two bytes)
        ## Print RSSI, both directions   
        print ('\nRSSI (local -> remote): %d' %((RSSI_lr/1.9)-127))
        print ('RSSI (local <- remote): %d' %((RSSI_rl/1.9)-127))          
    
    else:
        print ('Timeout')
    s.close()
コード例 #4
0
def main():    
    ## Generate Get PORTA frame
    my_frame=PAPP_frame()
    my_frame.addr=int(sys.argv[2],16)                ## Destination address
    my_frame.flen=1                                  ## CMD 
    my_frame.data_cmd=PAPP_frame_cmd.GET_PORTA       ## Type
    
    my_frame.WritePAPPFrame(s.write)                 ## Write to COM port
    print ('Raw frame sent:')
    my_frame.WritePAPPFrame(print_raw_frame)         ## Write to console raw frame
    print ('--------------------')
    print my_frame                                   ## Write to console object details
    print ('--------------------')
    
    my_read_frame=ReadPAPPFrame(s.read, timeout=10)
    if my_read_frame is not None and my_read_frame.data_cmd==PAPP_frame_cmd.GET_PORTA_RSP:
        print ('Raw frame received:')        
        my_read_frame.WritePAPPFrame(print_raw_frame) ## Write to console raw frame
        print ('--------------------')
        print my_read_frame                           ## Write to console object details
        ## Unpack PORTA data and RSSI (last two bytes)
        PORTA, RSSI_lr, RSSI_rl= unpack('BBB',my_read_frame.data)
        print ('\nPORTA data: 0x%02X' % PORTA) 
        ## Print RSSI, both directions   
        print ('RSSI (local -> remote): %d' %((RSSI_lr/1.9)-127))
        print ('RSSI (local <- remote): %d' %((RSSI_rl/1.9)-127))          
    
    else:
        print ('Timeout')
    s.close()
コード例 #5
0
ファイル: Example_DISCOVER.py プロジェクト: perikods/PAPP_lib
def main():    
    ## Generate DISCOVER frame
    my_frame=PAPP_frame()
    my_frame.addr= PAPP_frame.BROADCAST_ADDR         ## Destination address (0xFFFF if BROADCAST)
    my_frame.flen=1                                  ## CMD 
    my_frame.data_cmd=PAPP_frame_cmd.DISCOVER        ## Type
    
    my_frame.WritePAPPFrame(s.write)                 ## Write to COM port
    print ('Raw frame sent:')
    my_frame.WritePAPPFrame(print_raw_frame)         ## Write to console raw frame
    print ('--------------------')
    print my_frame                                   ## Write to console object details
    print ('--------------------')
    
    discover_again = True
    
    while discover_again:
        my_read_frame = ReadPAPPFrame(s.read, timeout=10)
        
        discover_again = False
        
        if my_read_frame is not None and my_read_frame.data_cmd==PAPP_frame_cmd.DISCOVER_RSP:
            print ('Raw frame received:')        
            my_read_frame.WritePAPPFrame(print_raw_frame) ## Write to console raw frame
            print ('--------------------')
            print my_read_frame                           ## Write to console object details
            ## Unpack DISCOVER NAME and RSSI (last two bytes)
            NAME, RSSI_lr, RSSI_rl= unpack('10sBB',my_read_frame.data)
            print ('\nNAME: %s' % NAME) 
            ## Print RSSI, both directions   
            print ('RSSI (local -> remote): %d' %((RSSI_lr/1.9)-127))
            print ('RSSI (local <- remote): %d' %((RSSI_rl/1.9)-127))
            
            discover_again = True          
        
        else:            
            print ('Stop discovering')
    s.close()