summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--avr/1wire.c18
-rw-r--r--avr/main.c5
-rw-r--r--pc/__pycache__/analyze.cpython-34.pycbin0 -> 4154 bytes
-rw-r--r--pc/analyze.py80
4 files changed, 95 insertions, 8 deletions
diff --git a/avr/1wire.c b/avr/1wire.c
index 5dbca82..affd80d 100644
--- a/avr/1wire.c
+++ b/avr/1wire.c
@@ -79,15 +79,20 @@ uint8_t w1_bit_io( uint8_t b )
_delay_us( 1 );
if( b )
{
- //hard_vcc;
- //asm volatile("nop" ::: );
+ hard_vcc;
+ _delay_us(7 );
soft_vcc;
+ _delay_us( 15 - 1 - 7 );
+ }
+ else
+ {
+ _delay_us( 15 - 1 );
}
- _delay_us( 15 - 1 );
if( (W1_IN & (1<<W1_PIN)) == 0 )
b = 0;
_delay_us( 60 - 15 );
- soft_vcc;
+ //soft_vcc;
+ hard_vcc;
sei();
return b;
}
@@ -104,6 +109,7 @@ uint8_t w1_byte_wr( uint8_t b )
b |= 0x80;
}
while( --i );
+ soft_vcc;
return b;
}
@@ -113,7 +119,7 @@ uint8_t w1_byte_rd( void )
return w1_byte_wr( 0xFF );
}
-
+/*
uint8_t w1_rom_search( uint8_t diff, uint8_t *id )
{
uint8_t i, j, next_diff;
@@ -158,7 +164,7 @@ uint8_t w1_rom_search( uint8_t diff, uint8_t *id )
}
while( i );
return next_diff; // to continue search
-}
+}*/
void ds1992_read(uint16_t addr, uint8_t* buf, uint8_t len)
{
diff --git a/avr/main.c b/avr/main.c
index 5c9742f..e1a4099 100644
--- a/avr/main.c
+++ b/avr/main.c
@@ -72,7 +72,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
case FUNC_WRITE:
PORTC ^= LED_RED;
//strcpy(replyBuffer, "Hello world");
- len = strlen(replyBuffer)+1;
+ //len = strlen(replyBuffer)+1;
+ len = 130;
break;
}
@@ -159,7 +160,7 @@ int main(void)
if (result == 0)
{
PORTC &= ~LED_GREEN;
- ds1992_read(0x00, replyBuffer, 128);
+ ds1992_read(42, replyBuffer, 128);
}
else if (result == 1)
PORTC &= ~LED_RED;
diff --git a/pc/__pycache__/analyze.cpython-34.pyc b/pc/__pycache__/analyze.cpython-34.pyc
new file mode 100644
index 0000000..6980785
--- /dev/null
+++ b/pc/__pycache__/analyze.cpython-34.pyc
Binary files differ
diff --git a/pc/analyze.py b/pc/analyze.py
new file mode 100644
index 0000000..f3bb31b
--- /dev/null
+++ b/pc/analyze.py
@@ -0,0 +1,80 @@
+import re
+from collections import defaultdict
+
+class Dumps:
+ def __init__(self):
+ self.dumps = []
+
+ def load(self, f):
+ dump = []
+ tag = None
+ no = 0
+ for line in open(f,"r").readlines():
+ if re.match("[0-9A-Z]{2}( [0-9A-Z]{2}){25} *$", line):
+ # this is a line of a hexdump
+ dump += [int(s,16) for s in line.split()]
+ else:
+ if len(dump):
+ self.dumps += [(no,tag,dump)]
+ dump = []
+ tag = None
+ no+=1
+
+ if line.strip() != "":
+ if tag != None:
+ print("overriding tag %s with %s"%(tag,line))
+
+ tag = line.replace("\n","")
+ # else ignore
+
+ def show(self,xcols,xrows):
+ if xcols == None: xcols = []
+ if xrows == None: xrows = []
+
+ for n, tag, dump in self.filter(xcols,xrows):
+ for byte in dump:
+ print("%02X "%byte, end="") # TODO
+ print(tag)
+
+
+ def filter(self,xcols,xrows):
+ return [ (dump[0], dump[1], [byte for byte,pos in zip(dump[2],range(len(dump[2]))) if pos not in xcols ]) for dump in self.dumps if dump[0] not in xrows]
+
+def mirror(dumps):
+ n = len(dumps)
+ m = len(dumps[0][2])
+ result = [[None]*n for i in range(m)]
+ for i in range(n):
+ for j in range(m):
+ result[j][i] = dumps[i][2][j]
+ return result
+
+def stats(cols):
+ ncols = len(cols)
+
+ result = [defaultdict(lambda : 0) for i in range(ncols)]
+ for col,stat in zip(cols,result):
+ for a,b in zip(col,col[1:]):
+ stat[(b-a)%256]+=1./(len(col)-1)
+ return result
+
+def getconstcols(stats):
+ return [col for stat,col in zip(stats,range(len(stats))) if stat[0]>0.9999]
+
+def showstats(stats):
+ for stat,pos in zip(stats,range(len(stats))):
+ print("%i:\t%s"%(pos,str(dict(stat))))
+
+def prettydict(d):
+ for k,v in sorted(d.items(), key=lambda a:-a[1]):
+ print("%02X: %2.0f | "%(k,100*v),end="")
+ print("")
+
+d = Dumps()
+d.load("mydump.txt")
+
+cc = getconstcols(stats(mirror(d.filter([],[]))))
+d.show(cc,[])
+
+for i in stats(mirror(d.filter(cc,[]))):
+ prettydict(i)