From 7968f96ef92a00b42123bf794442d54005284db3 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Tue, 26 Mar 2024 00:23:45 +0100 Subject: [PATCH] Python interface moved to pyorb repo. --- Python/orbcat.py | 12 ---- Python/pyorb/__init__.py | 116 --------------------------------------- README.md | 2 +- 3 files changed, 1 insertion(+), 129 deletions(-) delete mode 100644 Python/orbcat.py delete mode 100644 Python/pyorb/__init__.py diff --git a/Python/orbcat.py b/Python/orbcat.py deleted file mode 100644 index 29b5c9e9..00000000 --- a/Python/orbcat.py +++ /dev/null @@ -1,12 +0,0 @@ -from pyorb import * - -o = Orb() -while (True): - p = o.rx() - - match p.__class__.__name__: - case "swMsg": - print(''.join(chr((p.value >> (n * 8)) & 0xff) for n in range(p.len)), end = '') - - case other: - continue diff --git a/Python/pyorb/__init__.py b/Python/pyorb/__init__.py deleted file mode 100644 index 92ae75ed..00000000 --- a/Python/pyorb/__init__.py +++ /dev/null @@ -1,116 +0,0 @@ -from ctypes import * -import socket - -orb = CDLL("liborb.so.1") - -# Ensure restype is the correct length for platform -class my_void_p(c_void_p): - pass - -class TSMsg(Structure): - _fields_ = [ ("ts", c_longlong), - ("timeStatus", c_int,8), - ("timeInc", c_int)] - -class swMsg(Structure): - _fields_ = [ ("ts", c_longlong), - ("srcAddr", c_int,8), - ("len", c_int,8), - ("value", c_int)] - -class nisyncMsg(Structure): - _fields_ = [ ("ts", c_longlong), - ("type", c_int,8), - ("addr", c_int)] - -class pcSampleMsg(Structure): - _fields_ = [ ("ts", c_longlong), - ("sleep", c_bool,1), - ("pc", c_int)] - - -class oswMsg(Structure): - _fields_ = [ ("ts", c_longlong), - ("comp", c_int,8), - ("offset", c_int)] - -class wptMsg(Structure): - _fields_ = [ ("ts", c_longlong), - ("comp", c_int,8), - ("data", c_int)] - -class watchMsg(Structure): - _fields_ = [ ("ts", c_longlong), - ("comp", c_int,8), - ("isWrite", c_bool,1), - ("data", c_int)] - -class dwtMsg(Structure): - _fields_ = [ ("ts", c_longlong), - ("event", c_int,8)] - -class Empty(Structure): - _fields_ = [ ("ts", c_longlong)] - - -class excMsg(Structure): - _fields_ = [ ("ts", c_longlong), - ("exceptionNumber",c_int), - ("eventType", c_int,8)] - -class msgUnion(Union): - _fields_ = [ ("Unknown", Empty), - ("Reserved", Empty), - ("Error", Empty), - ("None", Empty), - ("swMsg", swMsg), - ("nisyncMsg", nisyncMsg), - ("oswMsg", oswMsg), - ("watchMsg", watchMsg), - ("wptMsg", wptMsg), - ("pcSampleMsg", pcSampleMsg), - ("dwtMsg", dwtMsg), - ("excMsg", excMsg), - ("TSMsg", TSMsg)] - -class msg(Structure): - _fields_ = [ ("msgtype", c_int), - ("m", msgUnion) ] - -orb.ITMDecoderCreate.restype = my_void_p -orb.ITMDecoderInit.argtypes = [ my_void_p, c_bool ] -orb.ITMPump.argtypes = [ my_void_p, c_char ] -orb.ITMGetDecodedPacket.argtypes = [my_void_p, my_void_p] -orb.ITMGetDecodedPacket.restype = c_bool - -orb.ITM_EV_NONE = 0 -orb.ITM_EV_PACKET_RXED= 1 -orb.ITM_EV_UNSYNCED = 2 -orb.ITM_EV_SYNCED = 3 -orb.ITM_EV_OVERFLOW = 4 -orb.ITM_EV_ERROR = 5 - -class Orb: - def __init__(self, addr=("localhost",3443), withTPIU=False, forceSync=True, sock=None): - self.addr = addr - - if sock is None: - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - else: - self.sock = sock - - self.sock.connect(self.addr) - self.itm = orb.ITMDecoderCreate() - orb.ITMDecoderInit( self.itm, forceSync ) - - def rx(self): - while (True): - c = self.sock.recv(1) - if (orb.ITM_EV_PACKET_RXED==orb.ITMPump( self.itm, c[0] )): - p = msg() - orb.ITMGetDecodedPacket( self.itm, byref(p)) - try: - return(getattr(p.m,p.m._fields_[p.msgtype][0])) - except IndexError: - return Empty - diff --git a/README.md b/README.md index 78767046..b2857d0e 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ is a very powerful code performance analysis tool. * orblcd: LCD emulator on the host computer. -There is also Python support in the `Python` directory. +There is also Python support in the [pyorb](https://github.com/orbcode/pyorb) repository. A few simple use cases are documented in the last section of this document, as are example outputs of using orbtop to report on the