def read(self, addr, length=None, burst="incr"): length_int = 1 if length is None else length # prepare packet record = EtherboneRecord() incr = (burst == "incr") record.reads = EtherboneReads(addrs=[ self.base_address + addr + 4 * incr * j for j in range(length_int) ]) record.rcount = len(record.reads) # send packet packet = EtherbonePacket() packet.records = [record] packet.encode() self.send_packet(self.socket, packet[:]) # receive response packet = EtherbonePacket(self.receive_packet(self.socket)) packet.decode() datas = packet.records.pop().writes.get_datas() if self.debug: for i, data in enumerate(datas): print("read {:08x} @ {:08x}".format( data, self.base_address + addr + 4 * i)) return datas[0] if length is None else datas
def _serve_thread(self): while True: client_socket, addr = self.socket.accept() print("Connected with " + addr[0] + ":" + str(addr[1])) try: while True: try: packet = self.receive_packet(client_socket) if packet == 0: break except: break packet = EtherbonePacket(packet) packet.decode() record = packet.records.pop() # Wait for lock while self.lock: time.sleep(0.01) # Set lock self.lock = True # Handle writes: if record.writes != None: self.comm.write(record.writes.base_addr, record.writes.get_datas()) # Handle reads if record.reads != None: max_length = { "CommUART": 256, "CommUDP": 1, }.get(self.comm.__class__.__name__, 1) bursts = { "CommUART": ["incr", "fixed"] }.get(self.comm.__class__.__name__, ["incr"]) reads = [] for addr, length, burst in _read_merger( record.reads.get_addrs(), max_length=max_length, bursts=bursts): reads += self.comm.read(addr, length, burst) record = EtherboneRecord() record.writes = EtherboneWrites(datas=reads) record.wcount = len(record.writes) packet = EtherbonePacket() packet.records = [record] packet.encode() self.send_packet(client_socket, packet) # release lock self.lock = False finally: print("Disconnect") client_socket.close()
def read(self, addr, length=None, burst="incr"): """ addr = start address in [bytes], should be 32 bit aligned length = number of 32 bit words to read. Maximum is 255. """ length_int = 1 if length is None else length # Prepare packet record = EtherboneRecord() incr = (burst == "incr") record.reads = EtherboneReads(addrs=[ self.base_address + addr + 4 * incr * j for j in range(length_int) ]) record.rcount = len(record.reads) # Send packet packet = EtherbonePacket() packet.records = [record] packet.encode() self.send_packet(self.socket, packet) # Receive response packet = EtherbonePacket(self.receive_packet(self.socket)) packet.decode() datas = packet.records.pop().writes.get_datas() if self.debug: for i, data in enumerate(datas): print("read 0x{:08x} @ 0x{:08x}".format( data, self.base_address + addr + 4 * i)) return datas[0] if length is None else datas
def _serve_thread(self): while True: client_socket, addr = self.socket.accept() print("Connected with " + addr[0] + ":" + str(addr[1])) try: while True: try: packet = self.receive_packet(client_socket) if packet == 0: break except: break packet = EtherbonePacket(packet) packet.decode() record = packet.records.pop() # wait for lock while self.lock: time.sleep(0.01) # set lock self.lock = True # handle writes: if record.writes != None: self.comm.write(record.writes.base_addr, record.writes.get_datas()) # handle reads if record.reads != None: reads = [] for addr in record.reads.get_addrs(): reads.append(self.comm.read(addr)) record = EtherboneRecord() record.writes = EtherboneWrites(datas=reads) record.wcount = len(record.writes) packet = EtherbonePacket() packet.records = [record] packet.encode() self.send_packet(client_socket, packet) # release lock self.lock = False finally: print("Disconnect") client_socket.close()
def probe(self, ip, port, loose=False): try: # Send probe request to server... packet = EtherbonePacket() packet.pf = 1 packet.encode() self.socket.sendto(packet.bytes, (ip, port)) # ...and get/check server's response. datas, dummy = self.socket.recvfrom(8192) packet = EtherbonePacket(datas) packet.decode() assert packet.pr == 1 return 1 except: if not loose: self.close() raise Exception( f"Unable to probe Etherbone server at {self.server}.") return 0
def read(self, addr, length=None): length_int = 1 if length is None else length record = EtherboneRecord() record.reads = EtherboneReads( addrs=[addr + 4 * j for j in range(length_int)]) record.rcount = len(record.reads) packet = EtherbonePacket() packet.records = [record] packet.encode() self.socket.sendto(bytes(packet), (self.server, self.port)) datas, dummy = self.socket.recvfrom(8192) packet = EtherbonePacket(datas) packet.decode() datas = packet.records.pop().writes.get_datas() if self.debug: for i, value in enumerate(datas): print("read {:08x} @ {:08x}".format(value, addr + 4 * i)) return datas[0] if length is None else datas