+simplepacketcount=0;
+def handlesimplicitipacket(packet):
+ s="";
+ i=0;
+ global simplepacketcount;
+ simplepacketcount=simplepacketcount+1;
+
+ len=packet[0];
+ if len<12: return;
+
+ dst=[packet[1],
+ packet[2],
+ packet[3],
+ packet[4]];
+ src=[packet[5],
+ packet[6],
+ packet[7],
+ packet[8]];
+ port=packet[9];
+ info=packet[10];
+ seq=packet[11];
+ #payload begins at byte 10.
+
+ if packet[len+2]&0x80==0:
+ print "# Dropped broken packet.";
+ elif port==0x20:
+ #data packet
+ counter=packet[11];
+ button=packet[12];
+ x=packet[13];
+ if x>=128: x=0-(x^0xFF)-1;
+ y=packet[14];
+ if y>=128: y=0-(y^0xFF)-1;
+ z=packet[15];
+ if z>=128: z=0-(z^0xFF)-1;
+
+ print "%09i %03i %4i %4i %4i" % (simplepacketcount,button,x,y,z);
+ sys.stdout.flush();
+ elif port==0x02:
+ #Link request. Gotta send a proper reply to get data.
+ tid=packet[13];
+ #14 ff ff ff ff 3c b7 e3 98
+ #02 03 c9
+ #01 97
+ #ef be ad de 3d 00 02
+ reply=[0x10,
+ src[0], src[1], src[2], src[3],
+ 0x78,0x56,0x34,0x10, #my address.
+ port, 0x21, seq,
+ 0x81, tid, #reply, tid
+
+ 0x20,0x00,0xad,0xde, #link token
+ 0x00]; #no security
+ #printpacket(reply);
+ print "#FIXME FAST: repeatedly broadcasting ACK to catch LINK on the next attempt.";
+ for foo in range(1,50):
+ client.RF_txpacket(reply);
+
+ pass;
+ elif port==0x03:
+ #print "Join request.";
+ #printpacket(packet);
+ if packet[12]!=1:
+ print "Not a join request. WTF?";
+ return;
+ tid=packet[13];
+ reply=[0x12, #reply is one byte shorter
+ src[0], src[1], src[2], src[3],
+ 0x78,0x56,0x34,0x10, #my address.
+ port, 0x21, seq,
+ 0x81, tid, #reply, tid
+
+ 0xef,0xbe,0xad,0xde, #Join token
+ 0x00]; #no security
+ #printpacket(reply);
+ print "#FIXME FAST: repeatedly broadcasting ACK to catch JOIN on the next attempt.";
+ #printpacket(reply);
+ for foo in range(1,50):
+ client.RF_txpacket(reply);
+
+
+ elif port==0x04:
+ print "Security request.";
+ elif port==0x05:
+ print "Frequency request.";
+ elif port==0x06:
+ print "Management request.";
+ else:
+ print "Unknown Port %02x" %port;
+