aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <swo-dev@marcschink.de>2016-09-18 11:03:41 +0200
committerMarc Schink <swo-dev@marcschink.de>2016-09-18 21:59:20 +0200
commit1cde7260e97cf1f5843022ffeec45c727c599d47 (patch)
treeaa11b1734298a5a9dcfffd226a63b6c6053976ce
parentb34382ab5fe443ea342dea420775570aee8f351c (diff)
bindings: Add string representation for packets
-rw-r--r--bindings/cxx/Extension.cpp25
-rw-r--r--bindings/cxx/GlobalTimestamp1.cpp14
-rw-r--r--bindings/cxx/GlobalTimestamp2.cpp12
-rw-r--r--bindings/cxx/Hardware.cpp13
-rw-r--r--bindings/cxx/Instrumentation.cpp13
-rw-r--r--bindings/cxx/LocalTimestamp.cpp31
-rw-r--r--bindings/cxx/Overflow.cpp11
-rw-r--r--bindings/cxx/Synchronization.cpp16
-rw-r--r--bindings/cxx/Unknown.cpp11
-rw-r--r--bindings/cxx/libswocxx.h19
-rw-r--r--bindings/python/swopy.i2
11 files changed, 167 insertions, 0 deletions
diff --git a/bindings/cxx/Extension.cpp b/bindings/cxx/Extension.cpp
index a254c9d..840f210 100644
--- a/bindings/cxx/Extension.cpp
+++ b/bindings/cxx/Extension.cpp
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <sstream>
+
#include "libswocxx.h"
namespace libswo
@@ -42,4 +44,27 @@ uint32_t Extension::get_value(void) const
return _packet.ext.value;
}
+const std::string Extension::to_string(void) const
+{
+ std::stringstream ss;
+
+ ss << "Extension (source = ";
+
+ switch (get_source()) {
+ case EXT_SRC_ITM:
+ ss << "ITM";
+ break;
+ case EXT_SRC_HW:
+ ss << "HW";
+ break;
+ default:
+ ss << "unknown";
+ }
+
+ ss << ", value = " << std::hex << get_value();
+ ss << ", size = " << get_size() << " bytes)";
+
+ return ss.str();
+}
+
}
diff --git a/bindings/cxx/GlobalTimestamp1.cpp b/bindings/cxx/GlobalTimestamp1.cpp
index e72c253..b6cab9a 100644
--- a/bindings/cxx/GlobalTimestamp1.cpp
+++ b/bindings/cxx/GlobalTimestamp1.cpp
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <sstream>
+
#include "libswocxx.h"
namespace libswo
@@ -47,4 +49,16 @@ bool GlobalTimestamp1::get_wrap(void) const
return _packet.gts1.wrap;
}
+const std::string GlobalTimestamp1::to_string(void) const
+{
+ std::stringstream ss;
+
+ ss << "Global timestamp (GTS1) (wrap = " << get_wrap();
+ ss << ", clkch = " << get_clkch();
+ ss << ", value = " << std::hex << get_value();
+ ss << ", size = " << get_size() << " bytes)";
+
+ return ss.str();
+}
+
}
diff --git a/bindings/cxx/GlobalTimestamp2.cpp b/bindings/cxx/GlobalTimestamp2.cpp
index 2cd0f1c..e651642 100644
--- a/bindings/cxx/GlobalTimestamp2.cpp
+++ b/bindings/cxx/GlobalTimestamp2.cpp
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <sstream>
+
#include "libswocxx.h"
namespace libswo
@@ -37,4 +39,14 @@ uint32_t GlobalTimestamp2::get_value(void) const
return _packet.gts1.value;
}
+const std::string GlobalTimestamp2::to_string(void) const
+{
+ std::stringstream ss;
+
+ ss << "Global timestamp (GTS2) (value = " << std::hex << get_value();
+ ss << ", size = " << get_size() << " bytes)";
+
+ return ss.str();
+}
+
}
diff --git a/bindings/cxx/Hardware.cpp b/bindings/cxx/Hardware.cpp
index 2365d2b..5026ef5 100644
--- a/bindings/cxx/Hardware.cpp
+++ b/bindings/cxx/Hardware.cpp
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <sstream>
+
#include "libswocxx.h"
namespace libswo
@@ -47,4 +49,15 @@ uint32_t Hardware::get_value(void) const
return _packet.hw.value;
}
+const std::string Hardware::to_string(void) const
+{
+ std::stringstream ss;
+
+ ss << "Hardware source (address = " << (unsigned int)get_address();
+ ss << ", value = " << std::hex << get_value();
+ ss << ", size = " << get_size() << " bytes)";
+
+ return ss.str();
+}
+
}
diff --git a/bindings/cxx/Instrumentation.cpp b/bindings/cxx/Instrumentation.cpp
index 2111bca..b9bdb6f 100644
--- a/bindings/cxx/Instrumentation.cpp
+++ b/bindings/cxx/Instrumentation.cpp
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <sstream>
+
#include "libswocxx.h"
namespace libswo
@@ -48,4 +50,15 @@ uint32_t Instrumentation::get_value(void) const
return _packet.inst.value;
}
+const std::string Instrumentation::to_string(void) const
+{
+ std::stringstream ss;
+
+ ss << "Instrumentation (address = " << (unsigned int)get_address();
+ ss << ", value = " << std::hex << get_value();
+ ss << ", size = " << get_size() << " bytes)";
+
+ return ss.str();
+}
+
}
diff --git a/bindings/cxx/LocalTimestamp.cpp b/bindings/cxx/LocalTimestamp.cpp
index b8d1b76..cd594f8 100644
--- a/bindings/cxx/LocalTimestamp.cpp
+++ b/bindings/cxx/LocalTimestamp.cpp
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <sstream>
+
#include "libswocxx.h"
namespace libswo
@@ -42,4 +44,33 @@ enum LocalTimestampRelation LocalTimestamp::get_relation(void) const
return static_cast<enum LocalTimestampRelation>(_packet.lts.relation);
}
+const std::string LocalTimestamp::to_string(void) const
+{
+ std::stringstream ss;
+
+ ss << "Local timestamp (relation = ";
+
+ switch (get_relation()) {
+ case LTS_REL_SYNC:
+ ss << "synchronous";
+ break;
+ case LTS_REL_TS:
+ ss << "timestamp delayed";
+ break;
+ case LTS_REL_SRC:
+ ss << "data delayed";
+ break;
+ case LTS_REL_BOTH:
+ ss << "data and timestamp delayed";
+ break;
+ default:
+ ss << "unknown";
+ }
+
+ ss << ", value = " << std::hex << get_value();
+ ss << ", size = " << get_size() << " bytes)";
+
+ return ss.str();
+}
+
}
diff --git a/bindings/cxx/Overflow.cpp b/bindings/cxx/Overflow.cpp
index 10e2399..49aafab 100644
--- a/bindings/cxx/Overflow.cpp
+++ b/bindings/cxx/Overflow.cpp
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <sstream>
+
#include "libswocxx.h"
namespace libswo
@@ -32,4 +34,13 @@ Overflow::Overflow(const union libswo_packet *packet)
_packet = *packet;
}
+const std::string Overflow::to_string(void) const
+{
+ std::stringstream ss;
+
+ ss << "Overflow (size = " << get_size() << " bytes)";
+
+ return ss.str();
+}
+
}
diff --git a/bindings/cxx/Synchronization.cpp b/bindings/cxx/Synchronization.cpp
index 749611c..afac6cb 100644
--- a/bindings/cxx/Synchronization.cpp
+++ b/bindings/cxx/Synchronization.cpp
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <sstream>
+
#include "libswocxx.h"
namespace libswo
@@ -32,4 +34,18 @@ Synchronization::Synchronization(const union libswo_packet *packet)
_packet = *packet;
}
+const std::string Synchronization::to_string(void) const
+{
+ std::stringstream ss;
+
+ ss << "Synchronization (size = ";
+
+ if (get_size() % 8 > 0)
+ ss << get_size() << " bits)";
+ else
+ ss << get_size() / 8 << " bytes)";
+
+ return ss.str();
+}
+
}
diff --git a/bindings/cxx/Unknown.cpp b/bindings/cxx/Unknown.cpp
index 05209f2..b7e989d 100644
--- a/bindings/cxx/Unknown.cpp
+++ b/bindings/cxx/Unknown.cpp
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <sstream>
+
#include "libswocxx.h"
namespace libswo
@@ -32,4 +34,13 @@ Unknown::Unknown(const union libswo_packet *packet)
_packet = *packet;
}
+const std::string Unknown::to_string(void) const
+{
+ std::stringstream ss;
+
+ ss << "Unknown data (size = " << get_size() << " bytes)";
+
+ return ss.str();
+}
+
}
diff --git a/bindings/cxx/libswocxx.h b/bindings/cxx/libswocxx.h
index 01325a8..f835cc4 100644
--- a/bindings/cxx/libswocxx.h
+++ b/bindings/cxx/libswocxx.h
@@ -85,6 +85,7 @@ public:
enum PacketType get_type(void) const;
size_t get_size(void) const;
+ virtual const string to_string(void) const = 0;
protected:
union libswo_packet _packet;
};
@@ -106,6 +107,8 @@ class LIBSWO_API Synchronization : public Packet
public:
Synchronization(const struct libswo_packet_sync *packet);
Synchronization(const union libswo_packet *packet);
+
+ const string to_string(void) const;
};
class LIBSWO_API Overflow : public PayloadPacket
@@ -113,6 +116,8 @@ class LIBSWO_API Overflow : public PayloadPacket
public:
Overflow(const struct libswo_packet_of *packet);
Overflow(const union libswo_packet *packet);
+
+ const string to_string(void) const;
};
class LIBSWO_API LocalTimestamp : public PayloadPacket
@@ -123,6 +128,8 @@ public:
enum LocalTimestampRelation get_relation() const;
uint32_t get_value(void) const;
+
+ const string to_string(void) const;
};
class LIBSWO_API GlobalTimestamp1 : public PayloadPacket
@@ -134,6 +141,8 @@ public:
uint32_t get_value(void) const;
bool get_clkch(void) const;
bool get_wrap(void) const;
+
+ const string to_string(void) const;
};
class LIBSWO_API GlobalTimestamp2 : public PayloadPacket
@@ -143,6 +152,8 @@ public:
GlobalTimestamp2(const union libswo_packet *packet);
uint32_t get_value(void) const;
+
+ const string to_string(void) const;
};
class LIBSWO_API Extension : public PayloadPacket
@@ -153,6 +164,8 @@ public:
enum ExtensionSource get_source(void) const;
uint32_t get_value(void) const;
+
+ const string to_string(void) const;
};
class LIBSWO_API Instrumentation : public PayloadPacket
@@ -164,6 +177,8 @@ public:
uint8_t get_address(void) const;
const vector<uint8_t> get_payload(void) const;
uint32_t get_value(void) const;
+
+ const string to_string(void) const;
};
class LIBSWO_API Hardware : public PayloadPacket
@@ -175,6 +190,8 @@ public:
uint8_t get_address(void) const;
const vector<uint8_t> get_payload(void) const;
uint32_t get_value(void) const;
+
+ const string to_string(void) const;
};
class LIBSWO_API Unknown : public PayloadPacket
@@ -182,6 +199,8 @@ class LIBSWO_API Unknown : public PayloadPacket
public:
Unknown(const struct libswo_packet_unknown *packet);
Unknown(const union libswo_packet *packet);
+
+ const string to_string(void) const;
};
class LIBSWO_PRIV DecoderCallbackHelper
diff --git a/bindings/python/swopy.i b/bindings/python/swopy.i
index fbb664b..1507a23 100644
--- a/bindings/python/swopy.i
+++ b/bindings/python/swopy.i
@@ -57,6 +57,8 @@ static int swig_exception_code(int code)
}
%}
+%rename(__str__) libswo::Packet::to_string;
+
%pybuffer_binary(const uint8_t *data, size_t length)
void libswo::Context::feed(const uint8_t *data, size_t length);