Class Wire

Nested Relationships

Nested Types

Inheritance Relationships

Derived Type

Class Documentation

class Wire

General Purpose wire model.

This class models a logical line used to represents digital/analog electrical signals. Its main purpose is to serve as base class for the MCU pin models and can be used by external component models to simulate digital or analog signals connected to a MCU model.

Wires need to be attached to each other. An attachment represents an electrical connection between two input and/or output circuits. Wires have a individual state (one of the State enum values) representing how the local circuit is driving them (or not driving) and a resolved state, shared by all attached Wires representing the common state.

For example, if Wires A and B are attached, A’s state is Floating, B’s state is High, the common resolved state is High.

As for the rest of the library, analog voltage levels are relative to VCC, hence limited to the range [0.0, 1.0].

See also

Pin

Subclassed by Pin

Public Types

enum StateEnum

Pin state enum. All the possible logical/analog electrical states that the wire can take.

Values:

enumerator State_Floating
enumerator State_PullUp
enumerator State_PullDown
enumerator State_Analog
enumerator State_High
enumerator State_Low
enumerator State_Shorted
enumerator State_Error
enum SignalId

Signal IDs raised by the pin. For all signals, the index is set to the pin ID.

Values:

enumerator Signal_StateChange

Signal raised for any change of the resolved state. data is set to the new state (one of State enum values)

enumerator Signal_DigitalChange

Signal raised for any change of the resolved digital state. data is set to the new digital state (0 or 1).

enumerator Signal_VoltageChange

Signal raised for any change to the analog value, including when induced by a digital state change. data is set to the analog value (double, in range [0;1])

Public Functions

Wire()

Build a Wire.

Wire(Wire &other)

Build a Wire by copy and attach to another Wire.

Wire(const Wire &other)

Build a Wire by copy. The new instance is not attached to the other Wire.

virtual ~Wire()
inline DataSignal &signal()
Returns:

the signal raising the state/value changes

inline const state_t &state() const
Returns:

the resolved state

bool digital_state() const

Returns the resolved state reduced to a boolean.

inline double voltage() const
Returns:

the pin voltage value

void set_state(const state_t &state)

Set the state of the Wire.

inline void set_state(StateEnum state, double v = 0.0)

Set the state of the wire using one of the StateEnum values

Parameters:
  • state – new Wire state

  • level – voltage level (only for the Analog state)

inline void set_state(char state, double v = 0.0)

Set the state of the wire using a charcode

See also

char2state

Parameters:
  • state – new Wire state

  • level – voltage level (only for the Analog state)

void attach(Wire &other)

Attach another Wire.

Note

if a and b are standalone Wire objects (i.e. not already attached), “a.attach(b)” and “b.attach(a)” have the same functional result. If a or b are already attached to other Wire objects, the effect is essentially to merge both groups of Wire objects.

void detach()

Detach from all Wire ‘this’ is attached to.

bool attached(const Wire &other) const
Returns:

whether ‘this’ is attached to the other Wire object.

bool attached() const
Returns:

whether ‘this’ is attached to any other Wire object.

std::vector<Wire*> siblings() const

Return all Wire objects ‘this’ is attached to. The returned vector also contains ‘this’.

If a and b are Wire objects attached to each other, “a.siblings()” and “b.siblings()” will return the same result, albeit possibly in a different order.

Wire &operator=(Wire &other)

Copy assignment with attachment

Wire &operator=(const Wire &other)

Copy assignment without attachment

Public Static Functions

static StateEnum char2state(char c)

Converts an ASCII charcode into a wire state enum value :

  • ’Z’/’z’ : Floating

  • ’H’/’h’ : High

  • ’L’/’l’ : Low

  • ’U’/’u’ : PullUp

  • ’D’/’d’ : PullDown

  • ’A’/’a’ : Analog

  • ’S’/’s’ : Shorted

  • any other value : Error

static state_t resolve_two_states(const state_t &a, const state_t &b)

Resolution algorithm for combining two state_t structures representing the logical state of two Wires attached together and returning the common resolved state.

Protected Functions

void auto_resolve_state()
virtual void notify_digital_state(bool state)
virtual state_t state_for_resolution() const
class state_t

Public Functions

inline state_t()
inline constexpr state_t(StateEnum s, double v = 0.0)
state_t(const state_t &other) = default
inline bool is_digital() const
inline bool is_driven() const
inline bool digital_value() const
std::string to_string() const

Returns a string representation of the wire state

inline bool operator==(StateEnum s) const
inline bool operator!=(StateEnum s) const
inline bool operator==(const state_t &s) const
inline bool operator!=(const state_t &s) const
inline StateEnum value() const
inline double level() const
state_t &operator=(const state_t &other) = default