Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/plugins/rfid/rfidutils.py
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2013-07-18 21:32:35 (GMT)
committer Walter Bender <walter@sugarlabs.org>2013-07-18 21:32:35 (GMT)
commitcd53d44d51fe9ef89f05dfdb4e35b721ace4175d (patch)
tree748c304ca3cef575fff3aaefe4e7d3e2d76dd857 /plugins/rfid/rfidutils.py
parent3f6e427d5e9f45544d23b5af763a9507a17397d4 (diff)
create turtle flags
Diffstat (limited to 'plugins/rfid/rfidutils.py')
-rw-r--r--plugins/rfid/rfidutils.py123
1 files changed, 0 insertions, 123 deletions
diff --git a/plugins/rfid/rfidutils.py b/plugins/rfid/rfidutils.py
deleted file mode 100644
index 4e02619..0000000
--- a/plugins/rfid/rfidutils.py
+++ /dev/null
@@ -1,123 +0,0 @@
-# utils.py - Helper functions for tis2000.py
-# Copyright (C) 2010 Emiliano Pastorino <epastorino@plan.ceibal.edu.uy>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-import os
-import logging
-
-def find_device():
- """
- Search for devices.
- Return a device instance or None.
- """
- device = None
- for i in os.listdir(os.path.join('.', 'plugins/rfid')):
- if not os.path.isdir(os.path.join('.', 'plugins/rfid', i)):
- try:
- _tempmod = __import__('rfid.%s'%i.split('.')[0], globals(),
- locals(), ['RFIDReader'], -1)
- devtemp = _tempmod.RFIDReader()
- if devtemp.get_present() == True:
- device = devtemp
- except Exception, e:
- # logging.error("FIND_DEVICE: %s: %s"%(i, e))
- pass
- if device is None:
- logging.debug("No RFID device found")
- return device
-
-
-def strhex2bin(strhex):
- """
- Convert a string representing an hex value into a
- string representing the same value in binary format.
- """
- dic = { '0':"0000",
- '1':"0001",
- '2':"0010",
- '3':"0011",
- '4':"0100",
- '5':"0101",
- '6':"0110",
- '7':"0111",
- '8':"1000",
- '9':"1001",
- 'A':"1010",
- 'B':"1011",
- 'C':"1100",
- 'D':"1101",
- 'E':"1110",
- 'F':"1111"
- }
- binstr = ""
- for i in strhex:
- binstr = binstr + dic[i.upper()]
- return binstr
-
-def strbin2dec(strbin):
- """
- Convert a string representing a binary value into a
- string representing the same value in decimal format.
- """
- strdec = "0"
- for i in range(1, strbin.__len__()+1):
- strdec = str(int(strdec)+int(strbin[-i])*int(pow(2, i-1)))
- return strdec
-
-def dec2bin(ndec):
- """
- Convert a decimal number into a string representing
- the same value in binary format.
- """
- if ndec < 1:
- return "0"
- binary = []
- while ndec != 0:
- binary.append(ndec%2)
- ndec = ndec/2
- strbin = ""
- binary.reverse()
- for i in binary:
- strbin = strbin+str(i)
- return strbin
-
-def bin2hex(strbin):
- """
- Convert a string representing a binary number into a string
- representing the same value in hexadecimal format.
- """
- dic = { "0000":"0",
- "0001":"1",
- "0010":"2",
- "0011":"3",
- "0100":"4",
- "0101":"5",
- "0110":"6",
- "0111":"7",
- "1000":"8",
- "1001":"9",
- "1010":"A",
- "1011":"B",
- "1100":"C",
- "1101":"D",
- "1110":"E",
- "1111":"F"
- }
- while strbin.__len__()%4 != 0:
- strbin = '0' + strbin
- strh = ""
- for i in range(0, strbin.__len__()/4):
- strh = strh + dic[str(strbin[i*4:i*4+4])]
- return strh