summaryrefslogtreecommitdiff
path: root/cesar/maximus/python/lib/fcVf/crc24/crc24.py
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/maximus/python/lib/fcVf/crc24/crc24.py')
-rw-r--r--cesar/maximus/python/lib/fcVf/crc24/crc24.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/cesar/maximus/python/lib/fcVf/crc24/crc24.py b/cesar/maximus/python/lib/fcVf/crc24/crc24.py
new file mode 100644
index 0000000000..3f453d6271
--- /dev/null
+++ b/cesar/maximus/python/lib/fcVf/crc24/crc24.py
@@ -0,0 +1,84 @@
+# -*- coding: Latin-1 -*-
+
+
+# Class Options
+###############################################################################
+class Options(object):
+ """
+ The options parsing and validationg class
+ """
+
+ """
+ Bitmap of the algorithms
+ """
+ Algo_None = 0x00
+ Algo_Bit_by_Bit = 0x01
+ Algo_Bit_by_Bit_Fast = 0x02
+ Algo_Table_Driven = 0x04
+
+ # Class constructor
+ ###############################################################################
+ def __init__(self, version):
+ self.ProgramName = "pycrc"
+ self.Version = version
+ self.VersionStr = "%s v%s" % (self.ProgramName, self.Version)
+ self.WebAddress = "http://www.tty1.net/pycrc/"
+ self.Width = None
+ self.Poly = None
+ self.ReflectIn = None
+ self.XorIn = None
+ self.ReflectOut = None
+ self.XorOut = None
+ self.TableIdxWidth = 8
+ self.TableWidth = 1 << self.TableIdxWidth
+ self.Verbose = False
+ self.CheckString = "123456789"
+
+ self.Algorithm = self.Algo_None
+ self.SymbolPrefix = "crc_"
+ self.OutputFile = None
+ self.Action = "check_string"
+ self.CStd = None
+
+
+ #CRC24 :
+ self.Width=24
+ self.Poly=0x864cfbL
+ self.ReflectIn=False
+ self.XorIn=0xb704ceL
+ self.ReflectOut=False
+ self.XorOut=0x0L
+ self.parse()
+
+
+ # function parse
+ ###############################################################################
+ def parse(self):
+ """
+ Parses and validates the options given as arguments
+ """
+ if self.Width != None:
+ if self.Width <= 0:
+ sys.stderr.write("Error: Width must be strictly positive\n")
+ sys.exit(1)
+ self.MSB_Mask = 0x1 << (self.Width - 1)
+ self.Mask = ((self.MSB_Mask - 1) << 1) | 1
+ if self.Poly != None:
+ self.Poly = self.Poly & self.Mask
+ if self.XorIn != None:
+ self.XorIn = self.XorIn & self.Mask
+ if self.XorOut != None:
+ self.XorOut = self.XorOut & self.Mask
+ else:
+ self.MSB_Mask = None
+ self.Mask = None
+
+ if self.Width == None or \
+ self.Poly == None or \
+ self.ReflectIn == None or \
+ self.XorIn == None or \
+ self.ReflectOut == None or \
+ self.XorOut == None:
+ self.UndefinedCrcParameters = True
+ else:
+ self.UndefinedCrcParameters = False