def hex2data( h ): if isinstance(h, (str, unicode)): if sys.version_info < (3,): if h[:2] == '0x': return h[2:].decode('hex') return h.decode('hex') else: if h[:2] == '0x': return bytes.fromhex(h[2:]) return bytes.fromhex(h[2:]) else: if h[:2] == b'0x': return codecs.decode(h[2:], 'hex') return codecs.decode(h, 'hex')
def test_tektds224_data_source_read_waveform(): with expected_protocol( ik.tektronix.TekTDS224, [ "DAT:SOU?", "DAT:SOU CH2", "DAT:ENC RIB", "DATA:WIDTH?", "CURVE?", "WFMP:CH2:YOF?", "WFMP:CH2:YMU?", "WFMP:CH2:YZE?", "WFMP:XZE?", "WFMP:XIN?", "WFMP:CH2:NR_P?", "DAT:SOU CH1" ], [ "CH1", "2", # pylint: disable=no-member "#210" + bytes.fromhex("00000001000200030004").decode("utf-8") + "0", "1", "0", "0", "1", "5" ] ) as tek: data = np.array([0, 1, 2, 3, 4]) (x, y) = tek.channel[1].read_waveform() assert (x == data).all() assert (y == data).all()
def export_sections_dxf(self, graph, filename): with self.connect() as con: cur = con.cursor() cur.execute(""" with hole_idx as ( select s.id as section_id, h.id as hole_id from _albion.named_section as s join _albion.hole as h on s.geom && h.geom and st_intersects(s.geom, st_startpoint(h.geom)) ) select st_collectionhomogenize(st_collect(ef.geom)) from albion.all_edge as e join hole_idx as hs on hs.hole_id = e.start_ join hole_idx as he on he.hole_id = e.end_ and he.section_id = hs.section_id join albion.edge_face as ef on ef.start_ = e.start_ and ef.end_ = e.end_ and not st_isempty(ef.geom) where ef.graph_id='{}' """.format(graph)) drawing = dxf.drawing(filename) m = wkb.loads(bytes.fromhex(cur.fetchone()[0])) for p in m: r = p.exterior.coords drawing.add( dxf.face3d( [tuple(r[0]), tuple(r[1]), tuple(r[2])], flags=1)) drawing.save()
def test_instrument_binblockread_too_many_reads(): inst = ik.Instrument.open_test() data = bytes.fromhex("00000001000200030004") inst._file.read_raw = mock.MagicMock( side_effect=[b"#", b"2", b"10", data[:6], b"", b"", b""]) _ = inst.binblockread(2)
def export_elementary_volume_dxf(self, graph_id, cell_ids, outdir, closed_only=False): with self.connect() as con: cur = con.cursor() cur.execute(""" select cell_id, row_number() over(partition by cell_id order by closed desc), geom, closed from ( select cell_id, triangulation as geom, albion.is_closed_volume(triangulation) as closed from albion.volume where cell_id in ({}) and graph_id='{}' ) as t """.format(','.join(["'{}'".format(c) for c in cell_ids]), graph_id)) for cell_id, i, wkb_geom, closed in cur.fetchall(): geom = wkb.loads(bytes.fromhex(wkb_geom)) if closed_only and not closed: continue filename = '{}_{}_{}_{}.dxf'.format( cell_id, graph_id, "closed" if closed else "opened", i) path = os.path.join(outdir, filename) drawing = dxf.drawing(path) for p in geom: r = p.exterior.coords drawing.add( dxf.face3d([tuple(r[0]), tuple(r[1]), tuple(r[2])], flags=1)) drawing.save()
def main(): parser = argparse.ArgumentParser( prog="hashcalc", usage='%(prog)s [OPTION]... [FILE]', description='Print MD5 (128-bit) or SHA1 (160-bit) checksum.', epilog="[+] Written by 15520599") parser.add_argument( 'FILE', nargs='?', type=argparse.FileType('rb'), default=sys.stdin, help="With no FILE, or when FILE is -, read from standard input.") parser.add_argument( '-m', '--mode', help='Choose hash algorithm: MD5 or SHA1 (Default MD5).', choices=['md5', 'sha1']) parser.add_argument( '-x', '--hex', action="store_true", help='Read input encoded in hex mode.', ) args = parser.parse_args() logger.debug(args.FILE) hash_func = None file_name = None content = None if not args.mode: hash_func = 'md5' else: hash_func = args.mode # if input is stdin or input encoded in hex if (args.FILE is sys.stdin) or args.hex: # be careful with newline character content = args.FILE.read() if args.hex: content = bytes.fromhex(content) hash_func += 'sumhex' else: # read from opened file hash_func += 'filehex' file_name = args.FILE.name hash_func = getattr(hashcalc, hash_func) logger.debug("hash func: %r" % hash_func) checksum = None if file_name: checksum = hash_func(file_name) else: checksum = hash_func(content) print("%s" % checksum)
def test_instrument_binblockread_too_many_reads(): inst = ik.Instrument.open_test() data = bytes.fromhex("00000001000200030004") inst._file.read_raw = mock.MagicMock( side_effect=[b"#", b"2", b"10", data[:6], b"", b"", b""] ) _ = inst.binblockread(2)
def serialize_job_ids(self, job_ids): """ Returns job_ids serialized for storage in Redis """ if len(job_ids) == 0 or self.use_large_ids: return job_ids elif isinstance(job_ids[0], ObjectId): return [x.binary for x in job_ids] else: return [bytes.fromhex(str(x)) for x in job_ids]
def decrypt_message(KEY_AuthID, message, KEY_UPDATE_ENC_C, KEY_UPDATE_MAC_C) -> MemoryUpdateInfo: k1 = mp_kdf(KEY_AuthID, KEY_UPDATE_ENC_C) k2 = mp_kdf(KEY_AuthID, KEY_UPDATE_MAC_C) UID = bytes.fromhex(message.M1.hex()[0:30]) ID = int(message.M1.hex()[30], 16) AuthID = int(message.M1.hex()[31], 16) dec = decrypt_cbc(k1, message.M2).hex() C_ID = int(dec[0:7], 16) F_ID = int(dec[7:9], 16) >> 2 KEY_NEW = bytes.fromhex(dec[32:64]) if (verify_cmac(k2, message.M1 + message.M2, message.M3)): return True, MemoryUpdateInfo(KEY_NEW, KEY_AuthID, UID, ID, AuthID, C_ID, F_ID) else: return False, MemoryUpdateInfo(KEY_NEW, KEY_AuthID, UID, ID, AuthID, C_ID, F_ID)
def dehex(hextext): """ Convert from hex string to binary data stripping whitespaces from `hextext` if necessary. """ if PY3K: return bytes.fromhex(hextext) else: hextext = "".join(hextext.split()) return hextext.decode('hex')
def test_instrument_binblockread(): with expected_protocol( ik.Instrument, [], [ b"#210" + bytes.fromhex("00000001000200030004") + b"0", ], sep="\n" ) as inst: np.testing.assert_array_equal(inst.binblockread(2), [0, 1, 2, 3, 4])
def test_agilent34410a_r(): with expected_protocol( ik.agilent.Agilent34410a, ["CONF?", "FORM:DATA REAL,64", "R? 1"], [ "VOLT +1.000000E+01,+3.000000E-06", # pylint: disable=no-member b"#18" + bytes.fromhex("3FF0000000000000") ]) as dmm: unit_eq(dmm.r(1), np.array([1]) * pq.volt)
def test_instrument_binblockread_two_reads(): inst = ik.Instrument.open_test() data = bytes.fromhex("00000001000200030004") inst._file.read_raw = mock.MagicMock( side_effect=[b"#", b"2", b"10", data[:6], data[6:]]) np.testing.assert_array_equal(inst.binblockread(2), [0, 1, 2, 3, 4]) calls_expected = [1, 1, 2, 10, 4] calls_actual = [call[0][0] for call in inst._file.read_raw.call_args_list] np.testing.assert_array_equal(calls_expected, calls_actual)
def test_instrument_binblockread_two_reads(): inst = ik.Instrument.open_test() data = bytes.fromhex("00000001000200030004") inst._file.read_raw = mock.MagicMock( side_effect=[b"#", b"2", b"10", data[:6], data[6:]] ) np.testing.assert_array_equal(inst.binblockread(2), [0, 1, 2, 3, 4]) calls_expected = [1, 1, 2, 10, 4] calls_actual = [call[0][0] for call in inst._file.read_raw.call_args_list] np.testing.assert_array_equal(calls_expected, calls_actual)
def export_layer_dxf(self, table, filename): with self.connect() as con: cur = con.cursor() cur.execute(""" select st_collect(albion.hole_piece(from_, to_, hole_id)) from albion.{} """.format(table)) drawing = dxf.drawing(filename) m = wkb.loads(bytes.fromhex(cur.fetchone()[0])) for l in m: r = l.coords drawing.add(dxf.polyline(list(l.coords))) drawing.save()
def export_holes_dxf(self, filename): with self.connect() as con: cur = con.cursor() cur.execute(""" select st_collect(geom) from albion.hole """) drawing = dxf.drawing(filename) m = wkb.loads(bytes.fromhex(cur.fetchone()[0])) for l in m: r = l.coords drawing.add(dxf.polyline(list(l.coords))) drawing.save()
def send_auth_cap(self, myaddr, mylun, clientaddr, clientlun, sockaddr): header = b'\x06\x00\xff\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10' headerdata = (clientaddr, clientlun | (7 << 2)) headersum = self._checksum(*headerdata) header += struct.pack('BBBBBB', *(headerdata + (headersum, myaddr, mylun, 0x38))) header += self.authcap bodydata = struct.unpack('B' * len(header[17:]), header[17:]) header += bytes.fromhex(str(self._checksum(*bodydata))) self.session.stage += 1 logger.debug('Connection established with %s', sockaddr) self.session.send_data(header, sockaddr)
def test_agilent34410a_r(): with expected_protocol( ik.agilent.Agilent34410a, [ "CONF?", "FORM:DATA REAL,64", "R? 1" ], [ "VOLT +1.000000E+01,+3.000000E-06", # pylint: disable=no-member b"#18" + bytes.fromhex("3FF0000000000000") ] ) as dmm: unit_eq(dmm.r(1), np.array([1]) * pq.volt)
def export_dxf(self, graph_id, filename): with self.connect() as con: cur = con.cursor() cur.execute(""" select albion.volume_union(st_collectionhomogenize(st_collect(triangulation))) from albion.volume where graph_id='{}' and albion.is_closed_volume(triangulation) and albion.volume_of_geom(triangulation) > 1 """.format(graph_id)) drawing = dxf.drawing(filename) m = wkb.loads(bytes.fromhex(cur.fetchone()[0])) for p in m: r = p.exterior.coords drawing.add( dxf.face3d( [tuple(r[0]), tuple(r[1]), tuple(r[2])], flags=1)) drawing.save()
def export_elementary_volume_dxf(self, graph_id, cell_id, outdir, closed): with self.connect() as con: closed_sql = "" if not closed: closed_sql = "not" cur = con.cursor() cur.execute(""" select geom from albion.dynamic_volume where cell_id='{}' and graph_id='{}' and {} albion.is_closed_volume(geom) """.format(cell_id, graph_id, closed_sql)) status = "opened" if closed: status = "closed" i = 0 for wkb_geom in cur.fetchall(): geom = wkb.loads(bytes.fromhex(wkb_geom[0])) filename = '{}_{}_{}_{}.dxf'.format(cell_id, graph_id, status, i) path = os.path.join(outdir, filename) drawing = dxf.drawing(path) for p in geom: r = p.exterior.coords drawing.add( dxf.face3d([tuple(r[0]), tuple(r[1]), tuple(r[2])], flags=1)) drawing.save() i += 1
def test_tektds224_data_source_read_waveform(): with expected_protocol( ik.tektronix.TekTDS224, [ "DAT:SOU?", "DAT:SOU CH2", "DAT:ENC RIB", "DATA:WIDTH?", "CURVE?", "WFMP:CH2:YOF?", "WFMP:CH2:YMU?", "WFMP:CH2:YZE?", "WFMP:XZE?", "WFMP:XIN?", "WFMP:CH2:NR_P?", "DAT:SOU CH1" ], [ "CH1", "2", # pylint: disable=no-member "#210" + bytes.fromhex("00000001000200030004").decode("utf-8") + "0", "1", "0", "0", "1", "5" ]) as tek: data = np.array([0, 1, 2, 3, 4]) (x, y) = tek.channel[1].read_waveform() assert (x == data).all() assert (y == data).all()
class EFICapsuleTester(TypeTester): static = bytes.fromhex("".join( "BD 86 66 3B 76 0D 30 40 B7 0E B5 51 9E 2F C5 A0".split())) parser = FirmwareCapsule
def drawForeground(self, painter, rect): #print "BoreHoleScene.drawForeground" if self.__redraw: with self.__project.connect() as con: cur = con.cursor() self.__redraw = False self.clear() fm = painter.fontMetrics() if self.__id is None: QGraphicsScene.drawForeground(self, painter, rect) return cur.execute( "SELECT geom FROM albion.hole WHERE id='{}'".format( self.__id)) res = cur.fetchone() if not res: QGraphicsScene.drawForeground(self, painter, rect) return hole = wkb.loads(bytes.fromhex(res[0])) line = [p[2] for p in hole.coords] tick_width = 20 spacing = 5 tick_text_offset = -10 tabs = [50, 75, 150, 250, 350, 400, 500] zmin, zmax = min(line), max(line) zpmin, zpmax = 0, ((zmin - zmax) - 5) / self.m_per_pixel text = self.addText(self.__id) text.setPos(tabs[1], -5 * fm.height()) label = 'Depth [m]' text = self.addText(label) text.setRotation(-90) text.setPos(0, 0) text = self.addText('Formation') text.setPos(tabs[1], -3 * fm.height()) text = self.addText('Radiometry') text.setPos(tabs[2], -3 * fm.height()) text = self.addText('Resistivity') text.setPos(tabs[3], -3 * fm.height()) text = self.addText('Mineralization') text.setPos(tabs[4], -3 * fm.height()) top = zpmin - 3 * fm.height() pen = QPen() pen.setWidth(3) for tab in [tabs[1], tabs[2], tabs[3], tabs[4], tabs[6]]: self.addLine(tab, top, tab, zpmax, pen) self.addLine(tabs[1], zpmin, tabs[-1], zpmin, pen) self.addLine(tabs[1], zpmax, tabs[-1], zpmax, pen) self.addLine(tabs[1], top, tabs[-1], top, pen) # depth ticks for z in range(0, int(-(zmax - zmin) - 5), -10): text = "% 4.0f" % (max(line) + z) z /= self.m_per_pixel width = fm.width(text) text = self.addText(text) text.setPos(tabs[0] - width - spacing, tick_text_offset + int(z)) self.addLine(tabs[0], z, tabs[1], z) self.addLine(tabs[2], z, tabs[4], z) #res = cur.execute("SELECT AsText(GEOMETRY), code FROM lithologies WHERE forage={}".format(self.__id)).fetchall() ## litho image #for geom, code in res: # line = [(float(pt.split()[2])-z_tube+h_tube_sol) # for pt in geom.replace('LINESTRING Z(','').replace(')','').split(',')] # z_start = line[0]/self.m_per_pixel # z_end = line[-1]/self.m_per_pixel # brush = QBrush() # brush.setTextureImage(self.texture(code)) # self.addRect(tabs[1], z_start, tabs[2]-tabs[1], z_end-z_start, brush=brush) ## bar diagram grid #for i in range(1, 10): # pen.setWidth(1 if i != 5 else 2) # x = tabs[3]+(tabs[4]-tabs[3])*float(i)/10 # self.addLine(x, zmin, x, zmax, pen) # formation color cur.execute( "SELECT geom, code FROM albion.formation WHERE hole_id='{}'" .format(self.__id)) for geom, code in cur.fetchall(): line = [ p[2] for p in wkb.loads(bytes.fromhex(geom)).coords ] z_start = (line[0] - zmax) / self.m_per_pixel z_end = (line[-1] - zmax) / self.m_per_pixel brush = QBrush() brush.setStyle(Qt.SolidPattern) brush.setColor(self.formation_color(code)) self.addRect(tabs[1], z_start, tabs[2] - tabs[1], z_end - z_start, brush=brush) #width = fm.width(code); #text = self.addText(code) #text.setPos(tabs[2]+spacing, tick_text_offset+int(.5*(z_start+z_end))) self.addLine(tabs[2], z_start, tabs[2], z_start) self.addLine(tabs[2], z_end, tabs[2], z_end) # radiometry diagram cur.execute( "SELECT max(gamma) FROM albion.radiometry WHERE hole_id='{}'" .format(self.__id)) gamma_max = cur.fetchone()[0] cur.execute( "SELECT geom, gamma FROM albion.radiometry WHERE hole_id='{}' AND gamma>=0" .format(self.__id)) for geom, gamma in cur.fetchall(): line = [ p[2] for p in wkb.loads(bytes.fromhex(geom)).coords ] z_start = (line[0] - zmax) / self.m_per_pixel z_end = (line[-1] - zmax) / self.m_per_pixel brush = QBrush() brush.setStyle(Qt.SolidPattern) brush.setColor(QColor(55, 51, 149)) self.addRect(tabs[2], z_start, (tabs[3] - tabs[2]) * gamma / gamma_max, z_end - z_start, pen=QPen(Qt.NoPen), brush=brush) # resistivity diagram cur.execute( "SELECT max(rho) FROM albion.resistivity WHERE hole_id='{}'" .format(self.__id)) rho_max = cur.fetchone()[0] cur.execute( "SELECT geom, rho FROM albion.resistivity WHERE hole_id='{}' AND rho>=0" .format(self.__id)) for geom, rho in cur.fetchall(): line = [ p[2] for p in wkb.loads(bytes.fromhex(geom)).coords ] z_start = (line[0] - zmax) / self.m_per_pixel z_end = (line[-1] - zmax) / self.m_per_pixel brush = QBrush() brush.setStyle(Qt.SolidPattern) brush.setColor(QColor(155, 51, 49)) self.addRect(tabs[3], z_start, (tabs[4] - tabs[3]) * rho / rho_max, z_end - z_start, pen=QPen(Qt.NoPen), brush=brush) # mineralization cur.execute( "SELECT geom, oc, accu, grade FROM albion.mineralization WHERE hole_id='{}'" .format(self.__id)) for geom, oc, accu, grade in cur.fetchall(): line = [ p[2] for p in wkb.loads(bytes.fromhex(geom)).coords ] z_start = (line[0] - zmax) / self.m_per_pixel z_end = (line[-1] - zmax) / self.m_per_pixel brush = QBrush() brush.setStyle(Qt.SolidPattern) brush.setColor(QColor(250, 250, 50)) self.addRect(tabs[4], z_start, tabs[5] - tabs[4], z_end - z_start, brush=brush) txt = "oc=" + str(oc) + "\naccu=" + str( accu) + "\ngrade=" + str(grade) width = fm.width(txt) text = self.addText(txt) text.setPos( tabs[5] + spacing, -int(1.5 * fm.height()) + int(.5 * (z_start + z_end))) self.addLine(tabs[4], z_start, tabs[6], z_start) self.addLine(tabs[4], z_end, tabs[6], z_end) self.setSceneRect(self.itemsBoundingRect()) QGraphicsScene.drawForeground(self, painter, rect)
def s2aguid(s): '''RFC4122 string GUID as int array.''' guid = [ s[:8], s[8 + 1:9 + 4], s[13 + 1:14 + 4], s[18 + 1:19 + 4] + s[-12:] ] return aguid(b"".join([bytes.fromhex(part) for part in guid]), True)
cur.execute(""" insert into albion.section(id, triangulation, graph_id, grid_id) select _albion.unique_id()::varchar, st_collectionhomogenize(st_collect(albion.triangulate_edge(ceil_, wall_))), graph_id, grid_id from albion.edge where graph_id='{}' group by graph_id, grid_id """.format(sys.argv[2])) cur.execute(""" select st_collectionhomogenize(st_collect(triangulation)) from albion.section where graph_id='{}' """.format(sys.argv[2])) drawing = dxf.drawing(sys.argv[3] + '.dxf') m = wkb.loads(bytes.fromhex(cur.fetchone()[0])) for p in m: r = p.exterior.coords drawing.add(dxf.face3d([tuple(r[0]), tuple(r[1]), tuple(r[2])], flags=1)) drawing.save() cur.execute(""" select albion.to_obj(st_collectionhomogenize(st_collect(triangulation))) from albion.section where graph_id='{}' """.format(sys.argv[2])) open(sys.argv[3] + '.obj', 'w').write(cur.fetchone()[0])
def update(self, layer): with self.__project.connect() as con: cur = con.cursor() if layer == 'label': self.__labels = [] cur.execute(""" select hole_id, st_x(geom), st_y(geom), st_z(geom) from (select hole_id, st_startpoint(geom) as geom from albion.node where graph_id='{}' ) as t """.format(self.__param["graph_id"])) for id_, x, y, z in cur.fetchall(): scene = QGraphicsScene() scene.setSceneRect(scene.itemsBoundingRect()) scene.addText(id_) #, QFont('Arial', 32)) image = QImage(scene.sceneRect().size().toSize(), QImage.Format_ARGB32) image.fill(Qt.transparent) painter = QPainter(image) image.save('/tmp/test.png') scene.render(painter) del painter scat = { 'point': [ x + self.__offset[0], y + self.__offset[1], (z + self.__offset[2]) * self.__param["z_scale"] ], 'image': image } scat['texture'] = self.__textureBinder(scat['image']) self.__labels.append(scat) elif layer == 'node': cur.execute(""" select array_agg(id), coalesce(st_collect(geom), 'GEOMETRYCOLLECTION EMPTY'::geometry) from albion.node where graph_id='{}' """.format(self.__param["graph_id"])) res = cur.fetchone() lines = wkb.loads(bytes.fromhex(res[1])) lines_ids = res[0] if lines_ids is None: return vtx = [] idx = [] colors = [] for line, id_ in zip(lines, lines_ids): elt = len(idx) self.idx_to_id_map[layer][elt] = id_ colors += [(elt >> 16 & 0xff, elt >> 8 & 0xff, elt >> 0 & 0xff, 255)] * len(line.coords) idx += [(i, i + 1) for i in range(len(vtx), len(vtx) + len(line.coords) - 1)] vtx += list(line.coords) self.vtx[layer] = numpy.array(vtx, dtype=numpy.float32) if len(vtx): self.vtx[layer] += self.__offset self.vtx[layer][:, 2] *= self.__param["z_scale"] self.idx[layer] = numpy.array(idx, dtype=numpy.int32) self.pick_color[layer] = numpy.array(colors, dtype=numpy.uint8) elif layer == 'end': cur.execute(""" select array_agg(n.id), coalesce(st_collect(e.geom), 'GEOMETRYCOLLECTION EMPTY'::geometry), coalesce(st_collect(st_makeline( st_3dlineinterpolatepoint(n.geom,.5), st_3dlineinterpolatepoint(e.geom,.5))), 'GEOMETRYCOLLECTION EMPTY'::geometry) from albion.end_node as e join albion.node as n on n.id=e.node_id where e.graph_id='{}' """.format(self.__param["graph_id"])) res = cur.fetchone() lines = wkb.loads(bytes.fromhex(res[1])) edges = wkb.loads(bytes.fromhex(res[2])) lines_ids = res[0] if lines_ids is None: return vtx = [] idx = [] colors = [] for line, edge, id_ in zip(lines, edges, lines_ids): elt = len(idx) self.idx_to_id_map[layer][elt] = id_ colors += [(elt >> 16 & 0xff, elt >> 8 & 0xff, elt >> 0 & 0xff, 255) ] * (len(line.coords) + len(edge.coords)) idx += [(i, i + 1) for i in range(len(vtx), len(vtx) + len(line.coords) - 1)] vtx += list(line.coords) idx += [(i, i + 1) for i in range(len(vtx), len(vtx) + len(edge.coords) - 1)] vtx += list(edge.coords) self.vtx[layer] = numpy.array(vtx, dtype=numpy.float32) if len(vtx): self.vtx[layer] += self.__offset self.vtx[layer][:, 2] *= self.__param["z_scale"] self.idx[layer] = numpy.array(idx, dtype=numpy.int32) self.pick_color[layer] = numpy.array(colors, dtype=numpy.uint8) elif layer == 'section': cur.execute(""" select coalesce(st_collect(n.geom), 'GEOMETRYCOLLECTION EMPTY'::geometry) from albion.section as s join albion.collar as c on st_intersects(s.geom, c.geom) join albion.hole as h on h.collar_id=c.id join albion.node as n on n.hole_id=h.id where n.graph_id='{}' """.format(self.__param["graph_id"])) lines = wkb.loads(bytes.fromhex(cur.fetchone()[0])) vtx = [] idx = [] if not len(lines): return for line in lines: idx += [(i, i + 1) for i in range(len(vtx), len(vtx) + len(line.coords) - 1)] vtx += list(line.coords) vtx = numpy.array(vtx, dtype=numpy.float32) if len(vtx): vtx += self.__offset vtx[:, 2] *= self.__param['z_scale'] self.vtx[layer] = vtx self.idx[layer] = numpy.array(idx, dtype=numpy.int32) elif layer == 'edge': cur.execute(""" select array_agg(id), coalesce(st_collect(geom), 'GEOMETRYCOLLECTION EMPTY'::geometry) from albion.edge where graph_id='{}' """.format(self.__param["graph_id"])) res = cur.fetchone() lines = wkb.loads(bytes.fromhex(res[1])) lines_ids = res[0] if lines_ids is None: return vtx = [] idx = [] colors = [] for line, id_ in zip(lines, lines_ids): new_idx = [(i, i + 1) for i in range(len(vtx), len(vtx) + len(line.coords) - 1)] elt = len(idx) self.idx_to_id_map[layer][elt] = id_ colors += [(elt >> 16 & 0xff, elt >> 8 & 0xff, elt >> 0 & 0xff, 255)] * len(line.coords) idx += [(i, i + 1) for i in range(len(vtx), len(vtx) + len(line.coords) - 1)] vtx += list(line.coords) self.vtx[layer] = numpy.array(vtx, dtype=numpy.float32) if len(vtx): self.vtx[layer] += self.__offset self.vtx[layer][:, 2] *= self.__param["z_scale"] self.idx[layer] = numpy.array(idx, dtype=numpy.int32) self.pick_color[layer] = numpy.array(colors, dtype=numpy.uint8) elif layer == 'volume': cur.execute(""" select albion.volume_union(st_collectionhomogenize(coalesce(st_collect(triangulation), 'GEOMETRYCOLLECTION EMPTY'::geometry))) from albion.volume where graph_id='{}' and albion.is_closed_volume(triangulation) and albion.volume_of_geom(triangulation) > 1 """.format(self.__param["graph_id"])) geom = wkb.loads(bytes.fromhex(cur.fetchone()[0])) self.vtx[layer] = numpy.require( numpy.array([tri.exterior.coords[:-1] for tri in geom]).reshape((-1, 3)), numpy.float32, 'C') if len(self.vtx[layer]): self.vtx[layer] += self.__offset self.vtx[layer][:, 2] *= self.__param["z_scale"] self.idx[layer] = numpy.require( numpy.arange(len(self.vtx[layer])).reshape((-1, 3)), numpy.int32, 'C') self.nrml[layer] = computeNormals(self.vtx[layer], self.idx[layer]) elif layer == 'error': cur.execute(""" select st_collectionhomogenize(coalesce(st_collect(triangulation), 'GEOMETRYCOLLECTION EMPTY'::geometry)) from albion.volume where graph_id='{}' and (not albion.is_closed_volume(triangulation) or albion.volume_of_geom(triangulation) <= 1) """.format(self.__param["graph_id"])) geom = wkb.loads(bytes.fromhex(cur.fetchone()[0])) self.vtx[layer] = numpy.require( numpy.array([tri.exterior.coords[:-1] for tri in geom]).reshape((-1, 3)), numpy.float32, 'C') if len(self.vtx[layer]): self.vtx[layer] += self.__offset self.vtx[layer][:, 2] *= self.__param["z_scale"] self.idx[layer] = numpy.require( numpy.arange(len(self.vtx[layer])).reshape((-1, 3)), numpy.int32, 'C') self.nrml[layer] = computeNormals(self.vtx[layer], self.idx[layer]) self.__old_param[layer] = self.__param[layer]
def generate_message_basic(info) -> MemoryUpdateMessage: return generate_message(info, bytes.fromhex('010153484500800000000000000000B0'), bytes.fromhex('010253484500800000000000000000B0'))
def h2b(s): """Converts a hex string to bytes; Python 2/3 compatible.""" return bytes.fromhex(s)
def generate_message_extend(info) -> MemoryUpdateMessage: return generate_message(info, bytes.fromhex('018153484500800000000000000000B0'), bytes.fromhex('018253484500800000000000000000B0'))
def test_instrument_binblockread(): with expected_protocol(ik.Instrument, [], [ b"#210" + bytes.fromhex("00000001000200030004") + b"0", ], sep="\n") as inst: np.testing.assert_array_equal(inst.binblockread(2), [0, 1, 2, 3, 4])
def sz(x): s = hex(x if isinstance(x, int) else len(x))[2:].rjust(4, '0') if sys.version_info[0] == 3: from builtins import bytes s = bytes.fromhex(s) if sys.version_info[0] == 3 else s.decode('hex') return s[::-1]
def colorize(self, red_pct, green_pct, blue_pct, fill): fill_r, fill_g, fill_b = bytes.fromhex(fill) mode, data = self.engine.image_data_as_rgb() imgdata = _colorize.apply(mode.encode('utf-8'), red_pct, green_pct, blue_pct, fill_r, fill_g, fill_b, data) self.engine.set_image_data(imgdata)
class IntelMEPartitionManifestTester(TypeTester): static = bytes.fromhex("".join("04 00 00 00 A1 00 00 00".split())) parser = MeManifestHeader
# Settings for JK-B2A24S JK-B1A24S # getInfo = '\xaa\x55\x90\xeb\x97\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11' # getInfoData = array.array('B', bytes.fromhex('55aaeb9003b44a4b2d42314132345300000000000000332e300000000000332e312e32000000b0b878000f000000506f7765722057616c6c203200000000313233340000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000abaa5590ebc8010100000000000000000000000044')) # getCellInfo = '\xaa\x55\x90\xeb\x96\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10' # getCellInfoDataInitial = array.array('B', bytes.fromhex('55aaeb9001f30000803f000000000000000000000000000000000000000000000000100000009a993940000000000000000000000000000000000000000000000000000000000000000011bc3a40000000000000000000000000000000000000000000000000000000000ad7233c9a99993e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007aaa5590ebc8010100000000000000000000000044')) # getCellInfoDataRepeat = array.array('B', bytes.fromhex('55aaeb9002f3ec426140f3466240011c6240593a62403f976240bbc16240cbb96240edb762404c6c62401fa762400fb662400da16240739b6240b47b62408c3e6240d7876240000000000000000000000000000000000000000000000000000000000000000013315c3d0636143d26e0113d8021f03c1153363d8980123d7e7c033dac41233d1ad83c3d9d6f4f3d8eb51e3d6a2c293deb28653d189c523da3724e3deb94493d9ab2c23d0000000000000000000000000000000000000000000000000000000000000000947162408067bf3c00000000ffff000005000000000000000000000000000086324e4c4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009435500cde4a33fae77a43f0095')) # Settings for JK-BD6A20S10P # getInfo = "\xaa\x55\x90\xeb\x97\x00\xdf\x52\x88\x67\x9d\x0a\x09\x6b\x9a\xf6\x70\x9a\x17\xfd" getInfoData = array.array( 'B', bytes.fromhex( '55aaeb9003b54a4b2d42443641323053313050000000342e300000000000342e312e37000000541d1600040000004e6f7468696e67204a4b31000000000031323334000000000000000000000000323030373038000032303036323834303735000000000000496e707574205573657264617461000031323334353600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c4aa5590ebc8010100000000000000000000000044' )) # getCellInfo = "\xaa\x55\x90\xeb\x96\x00\xf4\x5f\xe2\x03\x6d\xfb\xe0\x38\xaa\xbc\x44\x12\x34\xb8" getCellInfoDataInitial = array.array( 'B', bytes.fromhex( '55aaeb9001b558020000280a0000b80b0000100e0000480d00000500000000000000000000000000000000000000c4090000b88800001e0000003c000000a08601001e0000003c0000003c00000058020000bc02000058020000bc0200005802000038ffffff9cffffff84030000bc02000010000000010000000100000000000000400d030010270000dc0500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032aa5590ebc8010100000000000000000000000044' )) # getCellInfoDataRepeat = array.array('B', bytes.fromhex('55aaeb9002b52e0d280dfa0c2e0d2f0d220d220d130d190d1d0d1d0d170d1f0d160dfb0c1f0d00000000000000000000000000000000ffff00001c0d350004029b00c600a000b300bc00cc00be00b100b4002d013d01b000a100ab00b200ad0000000000000000000000000000000000000000000000bcd1000000000000000000001e0116013c010000000000636b0c0300400d030000000000dc4d010064000000781e16000101480a000000000000000000000000070101000000980400000000260141400000000037feffff00000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080')) with open('testinput.txt') as f: data = f.read() data = data.replace('\n', '') crc = crc8(data)
class UEFICapsuleTester(TypeTester): static = bytes.fromhex("".join( "B9 82 91 53 B5 AB 91 43 B6 9A E3 A9 43 F7 2F CC".split())) parser = FirmwareCapsule