summaryrefslogtreecommitdiff
path: root/maximus/python/lib/fcVf/crc24/crc24.py
blob: 3f453d62719761566a9e6668264279bf1e72664c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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