示例#1
0
 def set_fasttext(self, data, mag):
     self.fasttext = True
     self.links = []
     for n in range(4):
         nn = n*6
         (p,e) = page(data[nn+3:nn+5])
         ((s,m),e) = subcode_bcd(data[nn+5:nn+9])
         m = (mag^m)&0x7
         if m == 0:
             m = 8
         self.links.append("%1d%02x" % (m,p))
示例#2
0
def do_print(tt):
    if type(tt) == type(''):
        tt = np.fromstring(tt, dtype=np.uint8)
    ret = ""
    ((m, r),e) = mrag(tt[:2])
    ret += "%1d %2d" % (m, r)
    if r == 0:
        (p,e) = page(tt[2:4])
        ((s,c),e) = subcode_bcd(tt[4:10])
        ret += "   P%1d%02x " % (m,p)
        ret += Printer(tt[10:]).string_ansi()
        ret += " %04x %x" % (s,c)
    elif r == 30: # broadcast service data
        # designation code
        (d,e) = unhamm84(tt[2])
        # initial page
        (p,e) = page(tt[3:5])
        ((s,m),e) = subcode_bcd(np.fromstring(tt[5:9], dtype=np.uint8))
        ret += " %1d I%1d%02x:%04x " % (d, m, p, s)
        if d&2:
            ret += "(PDC) "
        else:
            ret += "(NET) "
        ret += Printer(tt[22:]).string_ansi()
    elif r == 27: # broadcast service data
        # designation code
        (d,e) = unhamm84(tt[2])
        ret += " %1d " % (d)
        for n in range(6):
            nn = n*6
            (p,e) = page(tt[nn+3:nn+5])
            ((s,m),e) = subcode_bcd(tt[nn+5:nn+9])
            ret += " %1d%02x:%04x " % (m,p,s)
    else:
        ret += Printer(tt[2:]).string_ansi()

    return ret
示例#3
0
    def __init__(self, a):
        
        self.array = a.reshape((26,42))
        #do_print(self.array[0])
        ((self.m,self.r),e) = mrag(self.array[0][:2])
        (self.p,e) = page(self.array[0][2:4])
        (self.s,self.c),self.e = subcode_bcd(self.array[0][4:10])

        # remove parity
        self.array[2:,2:] &= 0x7f

        # check if row n-1 is double height
        self.no_double_on_prev = ((self.array[1:-1,2:]) != 0x0d).all(axis=1)
        # row 1 can't contain double but might due to not being printable
        self.no_double_on_prev[0] = True

        # calculate a target threshold for each line
        # based on the number of non-blank characters

        # first count non-blanks
        self.threshold = ((self.array[2:,2:] != ord(' ')).sum(axis=1))

        # if non-blanks <= 5, don't require a match (set threshold to 0)
        # also ignore rows following a double height row
        self.threshold *= ((self.threshold > 5) & (self.no_double_on_prev))

        # some proportion of non-blanks must match in the rest of the lines
        self.threshold *= 0.5

        # sum required threshold for each line to get total threshold
        self.threshold_sum = self.threshold.sum() * 1.5

        try:
            self.ds = int("%x" % self.s, 10)
        except ValueError:
            self.ds = 1000
        rows = np.array([mrag(self.array[n][:2])[0][1] for n in range(26)])
        self.goodrows = (rows == Page.rows)