EM260 client is finally showing signs of life!
[goodfet] / client / GoodFETEM260.py
1 #!/usr/bin/env python
2 # GoodFET EM260 Radio Client
3
4 # (C) 2010 Travis Goodspeed <travis at radiantmachines.com>
5 #
6 # This code is being rewritten and refactored.  You've been warned!
7
8 # The EM260 is almost textbook SPI, except that the response cannot be
9 # read until after the nHOST_INT pin of the EM260 drops low and a dummy
10 # byte is read.  That is, the sequence will look like the following:
11
12 # Transmit Host->Slave Data
13 # while(nHOST_INT); //Sleep until ready.
14 # Recv Dummy Byte
15 # Recv Slave->Host Data
16
17 # The delay is mandatory.
18
19 import sys, time, string, cStringIO, struct, glob, serial, os;
20
21 from GoodFETSPI import GoodFETSPI;
22
23 class GoodFETEM260(GoodFETSPI):
24     EM260APP=0x01;
25     seq=0;
26     def EM260trans(self,data):
27         """Exchange data by EM260 SPI. (Slightly nonstandard.)"""
28         self.data=data;
29         self.writecmd(0x01,0x82,len(data),data);
30         return self.data;
31     
32     
33     def peek8(self,adr):
34         """Read a byte from the given address."""
35         data=self.EM260trans([0xfe,0x01,self.seq,0x00,
36                             0x49,
37                             0xA7]);
38         s="";
39         for foo in data:
40             s=s+"%02x " % ord(foo);
41         print s;
42         
43         return ord(data[0]);
44     def info(self):
45         """Read the info bytes."""
46         #data=self.EM260trans([0x0A,0xA7]); 
47         #data=self.EM260trans([0xFE,0x04,
48         #                      0x00,0x00,0x00,0x02,
49         #                      0xA7]); 
50         data=self.EM260trans([0x0B,0xA7]);
51         
52         #data=self.EM260trans([]);
53         
54         #data=self.EM260trans([0x0B,0x0B,0x0B,0x0B,0xA7]);
55         
56         s="";
57         for foo in data:
58             s=s+"%02x " % ord(foo);
59         print s;
60