1 | # |
---|

2 | # FIX parsing prototype |
---|

3 | # Robert D. Cameron Aug. 17, 2011 |
---|

4 | # |
---|

5 | |
---|

6 | |
---|

7 | class Basis_bits(): |
---|

8 | bit_0 = 0 |
---|

9 | bit_1 = 0 |
---|

10 | bit_2 = 0 |
---|

11 | bit_3 = 0 |
---|

12 | bit_4 = 0 |
---|

13 | bit_5 = 0 |
---|

14 | bit_6 = 0 |
---|

15 | bit_7 = 0 |
---|

16 | |
---|

17 | class Fix_lex(): |
---|

18 | SOH = 0 |
---|

19 | Equals = 0 |
---|

20 | Digit = 0 |
---|

21 | Zero = 0 |
---|

22 | |
---|

23 | class Fix_callout(): |
---|

24 | Header_end = 0 |
---|

25 | |
---|

26 | def Classify_bytes(basis_bits, fix_lex): |
---|

27 | temp1 = (basis_bits.bit_0 | basis_bits.bit_1) |
---|

28 | temp2 = (basis_bits.bit_2 | basis_bits.bit_3) |
---|

29 | temp3 = (temp1 | temp2) |
---|

30 | temp4 = (basis_bits.bit_4 | basis_bits.bit_5) |
---|

31 | temp5 = (basis_bits.bit_7 &~ basis_bits.bit_6) |
---|

32 | temp6 = (temp5 &~ temp4) |
---|

33 | fix_lex.SOH = (temp6 &~ temp3) |
---|

34 | temp7 = (basis_bits.bit_2 & basis_bits.bit_3) |
---|

35 | temp8 = (temp7 &~ temp1) |
---|

36 | temp9 = (basis_bits.bit_4 & basis_bits.bit_5) |
---|

37 | temp10 = (temp9 & temp5) |
---|

38 | fix_lex.Equals = (temp8 & temp10) |
---|

39 | temp11 = (basis_bits.bit_5 | basis_bits.bit_6) |
---|

40 | temp12 = (basis_bits.bit_4 & temp11) |
---|

41 | fix_lex.Digit = (temp8 &~ temp12) |
---|

42 | temp13 = (basis_bits.bit_6 | basis_bits.bit_7) |
---|

43 | temp14 = (temp4 | temp13) |
---|

44 | fix_lex.Zero = (temp8 &~ temp14) |
---|

45 | |
---|

46 | def Parse_fields(fix_lex, fix_callout): |
---|

47 | # Assume for now that all SOHs are field separators, not data. |
---|

48 | marker = fix_lex.SOH |
---|

49 | header1 = bitutil.Advance(marker) |
---|

50 | header2 = bitutil.ScanThru(marker, fix_lex.Digit) |
---|

51 | error1 = header1 & fix_lex.Zero |
---|

52 | error2 = header1 & header2 |
---|

53 | error3 = header2 &~ fix_lex.Equals |
---|

54 | error = error1 | error2 | error3 |
---|

55 | if error: |
---|

56 | error_tracker.NoteError("Potential error in header field", error) |
---|

57 | fix_callout.Header_end = header2 |
---|

58 | |
---|

59 | def main(basis_bits, fix_lex): |
---|

60 | Classify_bytes(basis_bits, fix_lex) |
---|

61 | |
---|

62 | Parse_fields(fix_lex, fix_callout) |
---|

63 | |
---|

64 | |
---|