Permalink
Browse files

fixed bug in reversing signal in server.py

  • Loading branch information...
1 parent 0a198f8 commit a265c0c0c0e94bea5b0f308f806f34e555f00ed9 @aaronj1335 committed Dec 13, 2011
Showing with 9 additions and 12 deletions.
  1. +9 −12 server.py
View
@@ -5,15 +5,13 @@
import sig
-def num(data_str, reverse=False):
+def num(data_str):
a = array.array('h')
- a.fromstring(reversed(data_str) if reverse else data_str)
+ a.fromstring(data_str)
s = sig.Signal(raw_signal=a)
d = sig.Decoder(signal=s)
bits = ''.join(str(b[0]) for b in d.bits())
cc = ''.join(n for n in sig.cc_num(bits))
- if len(cc) < 16:
- cc = ''.join(n for n in sig.cc_num(reversed(bits)))
return cc
class Server(SimpleHTTPRequestHandler):
@@ -31,14 +29,13 @@ def do_POST(self):
except Exception as e:
print 'ERROR: exception while decoding swipe:'
print e.message
- response_str = 'ERROR: could not decode swipe'
-
- try:
- r = num(data_str, reverse=True)
- print 'reversed swipe:',r
- except Exception as e:
- print 'ERROR: exception while decoding REVERSED swipe:'
- print e.message
+ try:
+ response_str = num(''.join(n for n in reversed(data_str)))
+ print 'reversed swipe:',response_str
+ except Exception as e:
+ print 'ERROR: exception while decoding REVERSED swipe:'
+ print e.message
+ response_str = 'ERROR: could not decode swipe'
self.send_response(200)
self.send_header("Content-Length", str(len(response_str)))

0 comments on commit a265c0c

Please sign in to comment.