ByteSwap Class
(Automation::ByteSwap)The ByteSwap operator lets the user re-position bytes from the default input to default output. More...
Header: | #include <ByteSwapOperator.h> |
Inherits: | CDPOperator<T> |
Public Functions
Reimplemented Public Functions
virtual void | Configure(XMLPrimitive *operatorXML) override |
virtual void | Create(const char *shortName, CDPBaseObject *parent) override |
virtual void | FillNodeChildren(CDP::StudioAPI::NodeStream &stream) const override |
virtual unsigned int | Process() override |
- 18 public functions inherited from CDPOperator
- 17 public functions inherited from CDPOperatorBase
- 46 public functions inherited from CDPBaseObject
- 26 public functions inherited from CDP::StudioAPI::CDPNode
- 22 public functions inherited from CDP::StudioAPI::ICDPNode
Additional Inherited Members
- 1 public variable inherited from CDPOperatorBase
- 1 static public member inherited from CDPBaseObject
- 1 protected function inherited from CDP::StudioAPI::CDPNode
- 8 protected variables inherited from CDPOperator
- 5 protected variables inherited from CDPOperatorBase
- 11 protected variables inherited from CDPBaseObject
Detailed Description
The ByteSwap operator lets the user re-position bytes from the default input to default output.
Depending on the type size, the ByteSwap has up to 8 numbered 'BytePosition' properties. Each 'BytePosition' property can be assigned a value which indicates where that byte should be positioned in the output. The special BytePosition value '-1' means 'Skip processing of this byte'.
The following table describes the byte-positions in an 8-byte (uint64_t, int64_t, double) signal, and how they relate to Least Significant Byte (LSB) and the Most Significant Byte (MSB):
MSB | LSB | ||||||
---|---|---|---|---|---|---|---|
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Example
To reverse the order of bytes in an 8-byte type, the following 'BytePosition' property values could be set
Name | Value |
---|---|
BytePosition0 | 7 |
BytePosition1 | 6 |
BytePosition2 | 5 |
BytePosition3 | 4 |
BytePosition4 | 3 |
BytePosition5 | 2 |
BytePosition6 | 1 |
BytePosition7 | 0 |
...resulting in a value that is re-mapped to the byte positions shown in this table:
MSB | LSB | ||||||
---|---|---|---|---|---|---|---|
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
Arguments
Name | Description |
---|---|
In | The default input value. |
Out | The default output value. |
For example: Assume an Input='1' CDPSignal<uint64_t> with a ByteSwap<uint64_t>. If configured with the above BytePositions, a Value of 0x0011223344556677 would yield an InternalValue of 0x7766554433221100.
For signals with less bytes, the scheme is the same, but you only have 4 or 2 BytePosition properties to configure.
Note: There are no restrictions on BytePositions, so in theory it would be possible to map all bytes to position 0. Unused byte-positions will get the value '0', and the last BytePosition written would have precedence over the others.
When operator is used inside a signal its default input is automatically tied to signal's InternalValue or previous operator's output. Its default output is automatically tied to next operator's input or to signal's Value. See also CDP Operator Usage In CDP Signals.
Actual Processing Code of the ByteSwap
unsigned int ByteSwap<T>::Process() { const T input = static_cast<T>(m_input); T output = 0; const unsigned char* inputPtr = reinterpret_cast<const unsigned char*>(&input); unsigned char* outputPtr = reinterpret_cast<unsigned char*>(&output); for(std::size_t i=0;i<sizeof(T);++i) if((int)m_bytePosition[i]!=-1) outputPtr[m_bytePosition[i]] = inputPtr[i]; m_output = output; return STATUS_OK; }
See also Argument.
Member Function Documentation
ByteSwap::ByteSwap(const CDPPropertyBase &in)
Default constructs an instance of ByteSwap.
ByteSwap::~ByteSwap()
Destroys the instance of ByteSwap.
[override virtual]
void ByteSwap::Configure(XMLPrimitive *operatorXML)
[override virtual]
void ByteSwap::Create(const char *shortName, CDPBaseObject *parent)
[override virtual]
void ByteSwap::FillNodeChildren(CDP::StudioAPI::NodeStream &stream) const
[override virtual]
unsigned int ByteSwap::Process()
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.