Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / mapping / python / colony.py @ 902

History | View | Annotate | Download (943 Bytes)

1
#!/usr/bin/env python3.0
2
import sys, time
3
from socket import *
4

    
5
hostname='localhost'
6

    
7
def inp(str):
8
    return input(str).encode('ascii')
9

    
10
def main():
11

    
12
    funcs = {31 : 'print_range_info'}
13

    
14
    buf = []
15
    sock = socket()
16
    sock.connect((hostname, int(sys.argv[1])))
17
    
18
    while (True):
19
        buf = sock.recv(100)
20
        
21
        if (buf):
22
            type = buf[2]
23
            if type in funcs.keys():
24
                globals()[funcs[type]](buf)
25

    
26
        
27
def print_range_info(packet):
28
    print ('Info from %d' % packet[0])
29
    src = packet[0]
30
    len = packet[1]
31
    print(len)
32
    data = packet[3:]
33
    for i in range(len // 2):
34
        bot_id = data[i*2]
35
        max_range_id = data[i*2+1]
36
        print ('Max to bot %d is %d' % (bot_id, max_range_id))
37
    
38

    
39

    
40

    
41
if __name__=='__main__':
42

    
43
    if len(sys.argv) < 2 or not str.isdecimal(sys.argv[1]):
44
        print("Usage: %s <portno>" % sys.argv[0])
45
        sys.exit()
46

    
47
    main()