def fn(): "Parse an individual component pin." [nm, sig] = yield count(name, 2) mod = yield name_only rem_line = yield rest_line rlc_vals = optional(count(number, 3), []).parse(rem_line) rlc_dict = {} if rlcs: rlc_dict.update(dict(zip(rlcs, rlc_vals))) return ((nm + "(" + sig + ")"), (mod, rlc_dict))
def typminmax(): "Parse Typ/Min/Max values." typ = yield number if DBG: print(f"Typ.: {typ}") minmax = yield optional(count(number, 2) | count(na, 2).result([]), []) if DBG: print(f"Min./Max.: {minmax}") yield ignore # So that ``typminmax`` behaves as a lexeme. res = [typ] res.extend(minmax) return res
def pins(): "Parse [Component].[Pin]." def filt(x): (_, (mod, _)) = x m = mod.upper() return (not ((m == "POWER") or (m == "GND") or (m == "NC"))) yield (lexeme(string("signal_name")) << lexeme(string("model_name"))) rlcs = yield optional(count(rlc, 3), []) prs = yield many1(pin(rlcs)) prs_filt = list(filter(filt, prs)) return dict(prs_filt)
def __init__(self, header): RINEXHeader.__init__(self, header) self._getMarkerInfo() self.receiver_number, self.receiver_type, receiver_version = p.Parser( p.count(n_ANY(20).parsecmap(trim_whitespace), 3)).parse(self.header_fields['REC # / TYPE / VERS']) self.antenna_number, self.antenna_type = p.Parser( p.count(n_ANY(20).parsecmap(trim_whitespace), 2)).parse(self.header_fields['ANT # / TYPE']) self.antenna_height, self.antenna_east, self.antenna_north = p.Parser( p.count(n_ANY(14).parsecmap(float), 3)).parse(self.header_fields['ANTENNA: DELTA H/E/N']) try: if self.header_fields['CRINEX VERS / TYPE']: self.compressed = True except KeyError: self.compressed = False
def n_A3(n): """Given n, return parser for space seperated list of n A3's A3 is a token for three successive alphanumeric characters """ return p.count(parsec.compose(parsec.spaces(), n_A(3)), n)
from parsec import count, joint from base import pid, label_as, field, to_dict from parsing import byte, uint16 from parsec import Parser, Value from emulator.beacon_parser import eps_controller_a_telemetry_parser, eps_controller_b_telemetry_parser, \ error_counting_telemetry, experiment_telemetry_parser, mcu_temperature_parser from emulator.beacon_parser.parser import BitArrayParser from math import ceil PayloadWhoAmI = pid(0x30) >> count(byte, 1) PayloadWhoAmI >>= label_as('Payload Who Am I') PayloadHousekeeping = pid(0x34) >> joint( field('INT 3V3D', uint16), field('OBC 3V3D', uint16), ).bind(to_dict) PayloadHousekeeping >>= label_as('Payload Housekeeping') ########################################################################## class PayloadOBCTelemetryParser: def __init__(self): self.storage = {} def write(self, category, name, value): if category not in self.storage.keys(): self.storage[category] = {}
def ramp(): "Parse [Ramp]." lines = yield count(ramp_line, 2) return dict(lines)
| na.result([0, 0])) if den: return num / den else: return None ramp_line = string("dV/dt_") >> ( (string("r").result("rising") | string("f").result("falling")) << ignore) + times(ratio, 1, 3) ex_line = word(string("Executable")) \ >> ((((string("L") | string("l")) >> string("inux")).result("linux") | \ ((string("W") | string("w")) >> string("indows")).result("windows")) \ << string("_") << many(none_of("_")) << string("_")) \ + lexeme(string("32") | string("64")) \ + count(name, 2) << ignore def manyTrue(p): "Run a parser multiple times, filtering ``False`` results." @generate("manyTrue") def fn(): "many(p) >> filter(True)" nodes = yield many(p) res = list(filter(None, nodes)) return res return fn
from parsec import count from base import pid, label_as from parsing import int32, int16 Magnetometer = pid(0x19) >> count(int32, 3) Magnetometer >>= label_as('Magnetometer') Dipoles = pid(0x20) >> count(int16, 3) Dipoles >>= label_as('Dipoles')