libelec
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Data Structures | Macros | Typedefs | Enumerations | Functions
libelec.h File Reference
#include <stdarg.h>
#include <stdbool.h>
#include <acfutils/conf.h>
#include <acfutils/geom.h>
#include <acfutils/sysmacros.h>
Include dependency graph for libelec.h:

Go to the source code of this file.

Data Structures

struct  elec_batt_info_t
 
struct  elec_gen_info_t
 
struct  elec_tru_info_t
 
struct  elec_xfrmr_info_t
 
struct  elec_load_info_t
 
struct  elec_bus_info_t
 
struct  elec_cb_info_t
 
struct  elec_diode_info_t
 
struct  elec_label_box_info_t
 
struct  elec_comp_info_t
 

Macros

#define STATIC_ARRAY_LEN_ARG(len)
 
#define CONST_ARRAY_LEN_ARG(len)   len
 

Typedefs

typedef double(* elec_get_temp_cb_t) (elec_comp_t *comp, void *userinfo)
 
typedef double(* elec_get_rpm_cb_t) (elec_comp_t *comp, void *userinfo)
 
typedef double(* elec_get_load_cb_t) (elec_comp_t *comp, void *userinfo)
 
typedef void(* elec_user_cb_t) (elec_sys_t *sys, bool pre, void *userinfo)
 

Enumerations

enum  { ELEC_MAX_SRCS = 64 }
 
enum  elec_comp_type_t {
  ELEC_BATT , ELEC_GEN , ELEC_TRU , ELEC_INV ,
  ELEC_XFRMR , ELEC_LOAD , ELEC_BUS , ELEC_CB ,
  ELEC_SHUNT , ELEC_TIE , ELEC_DIODE , ELEC_LABEL_BOX
}
 
enum  gui_load_type_t { GUI_LOAD_GENERIC , GUI_LOAD_MOTOR }
 

Functions

elec_sys_t * libelec_new (const char *filename)
 
void libelec_destroy (elec_sys_t *sys)
 
const elec_comp_info_tlibelec_get_comp_infos (const elec_sys_t *sys, size_t *num_infos)
 
bool libelec_sys_start (elec_sys_t *sys)
 
void libelec_sys_stop (elec_sys_t *sys)
 
bool libelec_sys_is_started (const elec_sys_t *sys)
 
bool libelec_sys_can_start (const elec_sys_t *sys)
 
void libelec_sys_set_time_factor (elec_sys_t *sys, double time_factor)
 
double libelec_sys_get_time_factor (const elec_sys_t *sys)
 
void libelec_serialize (elec_sys_t *sys, conf_t *ser, const char *prefix)
 
bool libelec_deserialize (elec_sys_t *sys, const conf_t *ser, const char *prefix)
 
void libelec_add_user_cb (elec_sys_t *sys, bool pre, elec_user_cb_t cb, void *userinfo)
 
void libelec_remove_user_cb (elec_sys_t *sys, bool pre, elec_user_cb_t cb, void *userinfo)
 
elec_comp_t * libelec_comp_find (elec_sys_t *sys, const char *name)
 
void libelec_walk_comps (const elec_sys_t *sys, void(*cb)(elec_comp_t *, void *), void *userinfo)
 
const elec_comp_info_tlibelec_comp2info (const elec_comp_t *comp)
 
bool libelec_comp_is_AC (const elec_comp_t *comp)
 
elec_comp_type_t libelec_comp_get_type (const elec_comp_t *comp)
 
const char * libelec_comp_get_name (const elec_comp_t *comp)
 
const char * libelec_comp_get_location (const elec_comp_t *comp)
 
bool libelec_comp_get_autogen (const elec_comp_t *comp)
 
size_t libelec_comp_get_num_conns (const elec_comp_t *comp)
 
elec_comp_t * libelec_comp_get_conn (const elec_comp_t *comp, size_t i)
 
double libelec_comp_get_in_volts (const elec_comp_t *comp)
 
double libelec_comp_get_out_volts (const elec_comp_t *comp)
 
double libelec_comp_get_in_amps (const elec_comp_t *comp)
 
double libelec_comp_get_out_amps (const elec_comp_t *comp)
 
double libelec_comp_get_in_pwr (const elec_comp_t *comp)
 
double libelec_comp_get_out_pwr (const elec_comp_t *comp)
 
double libelec_comp_get_in_freq (const elec_comp_t *comp)
 
double libelec_comp_get_out_freq (const elec_comp_t *comp)
 
double libelec_comp_get_incap_volts (const elec_comp_t *comp)
 
bool libelec_comp_is_powered (const elec_comp_t *comp)
 
double libelec_comp_get_eff (const elec_comp_t *gen)
 
unsigned libelec_comp_get_srcs (const elec_comp_t *comp, elec_comp_t *srcs[ELEC_MAX_SRCS])
 
void libelec_comp_set_failed (elec_comp_t *comp, bool failed)
 
bool libelec_comp_get_failed (const elec_comp_t *comp)
 
void libelec_comp_set_shorted (elec_comp_t *comp, bool shorted)
 
bool libelec_comp_get_shorted (const elec_comp_t *comp)
 
double libelec_gen_set_random_volts (elec_comp_t *comp, double stddev)
 
double libelec_gen_set_random_freq (elec_comp_t *comp, double stddev)
 
void libelec_comp_set_userinfo (elec_comp_t *comp, void *userinfo)
 
void * libelec_comp_get_userinfo (const elec_comp_t *comp)
 
void libelec_batt_set_temp_cb (elec_comp_t *batt, elec_get_temp_cb_t cb)
 
elec_get_temp_cb_t libelec_batt_get_temp_cb (const elec_comp_t *batt)
 
void libelec_gen_set_rpm_cb (elec_comp_t *gen, elec_get_rpm_cb_t cb)
 
elec_get_rpm_cb_t libelec_gen_get_rpm_cb (const elec_comp_t *gen)
 
void libelec_load_set_load_cb (elec_comp_t *load, elec_get_load_cb_t cb)
 
elec_get_load_cb_t libelec_load_get_load_cb (elec_comp_t *load)
 
void libelec_cb_set (elec_comp_t *comp, bool set)
 
bool libelec_cb_get (const elec_comp_t *comp)
 
double libelec_cb_get_temp (const elec_comp_t *comp)
 
void libelec_tie_set_list (elec_comp_t *comp, size_t list_len, elec_comp_t *const bus_list[])
 
void libelec_tie_set (elec_comp_t *comp,...) SENTINEL_ATTR
 
void libelec_tie_set_v (elec_comp_t *comp, va_list ap)
 
void libelec_tie_set_all (elec_comp_t *comp, bool tied)
 
bool libelec_tie_get_all (elec_comp_t *comp)
 
size_t libelec_tie_get_list (elec_comp_t *comp, size_t cap, elec_comp_t *bus_list[])
 
size_t libelec_tie_get_num_buses (const elec_comp_t *comp)
 
bool libelec_tie_get (elec_comp_t *tie, bool_t exhaustive,...) SENTINEL_ATTR
 
bool libelec_tie_get_v (elec_comp_t *tie, bool exhaustive, va_list ap)
 
void libelec_gen_set_rpm (elec_comp_t *gen, double rpm)
 
double libelec_gen_get_rpm (const elec_comp_t *gen)
 
double libelec_batt_get_chg_rel (const elec_comp_t *batt)
 
void libelec_batt_set_chg_rel (elec_comp_t *batt, double chg_rel)
 
double libelec_batt_get_temp (const elec_comp_t *batt)
 
void libelec_batt_set_temp (elec_comp_t *batt, double T)
 
bool libelec_chgr_get_working (const elec_comp_t *chgr)
 
double libelec_phys_get_batt_voltage (double U_nominal, double chg_rel, double I_rel)
 

Detailed Description

This is the master libelec include file. You should include this file to interface with libelec.

Definition in file libelec.h.

Typedef Documentation

◆ elec_get_load_cb_t

typedef double(* elec_get_load_cb_t) (elec_comp_t *comp, void *userinfo)

This is the callback type used by electrical loads for cases where the caller has installed a custom load demand callback using libelec_load_set_load_cb().

Parameters
compThe component for which the load demand is being queried.
userinfoCustom userinfo pointer, which was previously set up on the component using libelec_comp_set_userinfo().
Returns
  1. For components with stabilized power supplies (STAB TRUE in the definition file), this callback must return the power demand of the load in Watts.
  2. For components with unstabilized power supplies (STAB FALSE in the definition file, the default), this callback must return the current demand of the load in Amps.

Definition at line 316 of file libelec.h.

◆ elec_get_rpm_cb_t

typedef double(* elec_get_rpm_cb_t) (elec_comp_t *comp, void *userinfo)

This is the callback type used by generators to determine the speed of the generator's input shaft, which is then used for determining the generator's output voltage and frequency behavior. This callback is installed for generators using libelec_gen_set_rpm_cb().

Note
You DON'T have to set a generator rpm callback. You can instead call libelec_gen_set_rpm() regularly to set the rpm value directly.
Parameters
compThe component for which the generator rpm is being queried.
userinfoCustom userinfo pointer, which was previously set up on the component using libelec_comp_set_userinfo().
Returns
The generator rpm, using the same units as what you have used for the EXC_RPM, MIN_RPM and MAX_RPM stanzas when defining the generator in the config file. libelec doesn't enforce any specific type of units for generator, so you can use whatever units are most convenient.
See also
libelec_gen_set_rpm()

Definition at line 249 of file libelec.h.

◆ elec_get_temp_cb_t

typedef double(* elec_get_temp_cb_t) (elec_comp_t *comp, void *userinfo)

This is the callback type used by batteries to determine the temperature of the battery. Temperature has a significant effect on a battery's ability to provide current, as well as its absolute energy capacity.

Returns
The temperature the battery in Kelvin.

Definition at line 216 of file libelec.h.

◆ elec_user_cb_t

typedef void(* elec_user_cb_t) (elec_sys_t *sys, bool pre, void *userinfo)

Custom physics callback, which you can install using libelec_add_user_cb(), or remove using libelec_remove_user_cb(). This will be called from the physics calculation thread, allowing you perform precise accounting of all physics state as it's being calculated.

See also
libelec_add_user_cb()
libelec_remove_user_cb()

Definition at line 445 of file libelec.h.

Enumeration Type Documentation

◆ elec_comp_type_t

Identifies the type of electrical component. Every component in a libelec network must be one of these enumerations.

Enumerator
ELEC_BATT 

A battery is a component which can hold a certain amount of energy. This energy can then either be discharged (when a load is connected to the battery), or recharged (when a generator or energy source of a higher voltage than the battery's output voltage is attached). The rate of recharge is controlled by the battery's internal resistance, while the rate of discharge is largely driven by the demands of the downstream loads. To simulate the effects of internal battery resistance to discharge, a battery will depress its output voltage as it approaches its power flow limits.

ELEC_GEN 

A generator is a component which converts mechanical input energy into electrical output energy. You MUST supply a callback using libelec_gen_set_rpm_cb(), which informs libelec how fast the input shaft of the generator is turning.

See also
libelec_gen_set_rpm_cb()
elec_get_rpm_cb_t
ELEC_TRU 

A Transformer-Rectifier Unit is a component which performs two tasks:

  1. It transforms the voltage of the input to a different voltage on the output.
  2. It rectifies AC to DC

libelec's TRUs are simple devices, whose output voltage always scales in proportion to their input voltage. Thus, they do not provide a stabilized output voltage, but instead depend on the ability of the AC-side generator to supply a stable voltage. A TRU doesn't permit reverse current flow from its output side to the input.

ELEC_INV 

An inverter is conceptually the opposite of a TRU. It changes DC power into AC power, and optionally also changes the input voltage to a different output voltage.

See also
ELEC_TRU
ELEC_XFRMR 

A transformer changes the AC voltage on its input into a different AC voltage on its output. The voltage ratio is fixed based on the ratio of the number of turns between the transformer's primary and secondary windings.

ELEC_LOAD 

A load is a consumer of electrical energy. This can be anything you need it to be. libelec tells you if the load is powered (and how much energy it is consuming), and you then implement your custom systems behaviors based on that energy usage. Loads can either have internal power supplies, or be simple unregulated energy consumers. You can customize all of this behavior to suit your needs.

ELEC_BUS 

Buses are the interconnecting "tissue" of the libelec network. Every component on the network must connect to one or more buses, and the buses themselves serve to distribute energy flows throughout the network. libelec buses are idealized power distribution mechanisms with no internal resistance.

ELEC_CB 

Circuit breakers are devices which allow the passage of electrical current when closed. If open, current is not allowed to flow. A breaker can become open by either by manual pilot action, or automatically if the current flowing through the breaker exceeds the breaker's maximum rating. As such, circuit breakers are safety devices which prevent excessive current draw to protect the electrical network from damage due to faults or short-circuits.

libelec assumes CBs as being specifically thermal circuit breakers, which are breakers where a small amount of energy is used to heat up an internal filament. This amount of energy loss is carefully callibrated such that when current flow through the breaker exceeds its rating, the filament deforms sufficiently to trigger an internal control circuit, which then opens the breaker. As such, thermal breakers have a certain amount of "inertia" before responding. If the current exceedance is very brief and/or not very high, the filament's thermal inertia might cause the breaker not to "trip." Conversely, when the breaker trips, the filament might remain very hot and must cool off - the operator must wait a few seconds before attempting to close the breaker again, to account for this cooling period.

ELEC_SHUNT 

Shunts are current measuring devices inserted in-line with a circuit. In reality, shunts are very small, carefully callibrated resistors, which cause a small amount of voltage drop across their leads. This amount of voltage drop is then measured using a voltmeter and converted into a current measurement mathematically.

Since a properly sized shunt is meant to only cause a very small voltage drop in the circuit, libelec shunts are idealized devices which cause no voltage drop at all. You can also use these idealized shunts to represent other current measuring devices, such as AC current clamps (which cause no voltage drop in the circuit).

ELEC_TIE 

Ties are devices which connect two or more buses together. You can think of ties as a generalization of contactors and relays. Each of the endpoints of a tie has two possible states: tied or not tied. When tied, the endpoint allows current to pass (in any direction) to all other endpoints which are currently tied. Conceptually, the tie behaves as a single electrical node, with links to the outside world which can be dynamically connected and disconnected:

4-pole tie fully open B & C tied, A & D open
(no current can flow) (current can flow between B & C)
A o o C A o o B
/
+ +
/
B o o D C o o D
A & B tied, C & D open All endpoints tied
(current can flow between A & B) (current can flow between all)
A o o B A o o B
\ / \ /
+ +
/ \
C o o D C o o D
ELEC_DIODE 

A diode is a component which prevents current flow opposite to the diode's forward sense. libelec's diode are DC-only devices and cannot be used on AC circuits. Use a component of type ELEC_TRU to implement an AC-to-DC rectifier.

ELEC_LABEL_BOX 

This is a pseudo component, only used placing text labels on the graphical network drawing. It plays no role in the actual electrical simulation.

Definition at line 51 of file libelec.h.

Function Documentation

◆ libelec_add_user_cb()

void libelec_add_user_cb ( elec_sys_t *  sys,
bool  pre,
elec_user_cb_t  cb,
void *  userinfo 
)

Adds a custom user callback to the library. This will be called from the physics calculation thread, allowing you perform precise accounting of all physics state as it's being calculated.

Parameters
preIf set to true, the callback will be called just before the physics integration is run. If set to false, will be called immediately after the physics integration.
cbThe callback to be called.
userinfoA custom userinfo pointer parameter, which will be passed to the callback function every time it is called.
Note
You must NOT register the exact same pre + callback + userinfo pointer combo more than once.
See also
libelec_remove_user_cb()

Definition at line 2048 of file libelec.c.

◆ libelec_batt_get_chg_rel()

double libelec_batt_get_chg_rel ( const elec_comp_t *  batt)
Returns
The relative state-of-charge of the battery batt. This MUST be a component of type ELEC_BATT.
See also
libelec_batt_set_chg_rel()

Definition at line 4938 of file libelec.c.

◆ libelec_batt_get_temp()

double libelec_batt_get_temp ( const elec_comp_t *  batt)
Returns
The temperature of the battery batt in Kelvin. This MUST be a component of type ELEC_BATT.
See also
libelec_batt_set_temp()

Definition at line 4974 of file libelec.c.

◆ libelec_batt_get_temp_cb()

elec_get_temp_cb_t libelec_batt_get_temp_cb ( const elec_comp_t *  batt)
Returns
The battery temperature callback, which was previously set using libelec_batt_set_temp_cb(), or NULL if no callback was set.
See also
libelec_batt_set_temp_cb()

Definition at line 2933 of file libelec.c.

◆ libelec_batt_set_chg_rel()

void libelec_batt_set_chg_rel ( elec_comp_t *  batt,
double  chg_rel 
)

Sets the relative state-of-charge of a battery. Due to the temperature-dependent behavior of batteries, libelec uses relative state of charge, rather than absolute energy content.

See also
libelec_batt_get_chg_rel()

Definition at line 4953 of file libelec.c.

◆ libelec_batt_set_temp()

void libelec_batt_set_temp ( elec_comp_t *  batt,
double  T 
)

Sets the temperature of a battery. This affects the battery's capability to output current and total energy content, due to temperature significantly affecting how the chemistry inside of the battery behaves.

Parameters
TThe new temperature of the battery in Kelvin. Must NOT be negative.
See also
libelec_batt_get_temp()

Definition at line 4994 of file libelec.c.

◆ libelec_batt_set_temp_cb()

void libelec_batt_set_temp_cb ( elec_comp_t *  batt,
elec_get_temp_cb_t  cb 
)

Sets the battery temperature callback. libelec doesn't itself implement battery heat flow. Rather, it relies on external code to tell it what temperature the battery is. libelec then employs that value to determine the battery's electrical properties (such as voltage, max current, capacity, etc.)

Note
You must NOT call this function after the network has been started by a call to libelec_sys_start(). The network MUST be stopped before attempting to reconfigure it.
Parameters
battThe battery for which to configure the callback. Must be a component of type ELEC_BATT.
cbThe callback to set. You may pass NULL here to remove the callback. You may also use libelec_batt_set_temp() to set the battery's temperature directly.
See also
elec_get_temp_cb_t

Definition at line 2918 of file libelec.c.

◆ libelec_cb_get()

bool libelec_cb_get ( const elec_comp_t *  comp)
Returns
True if the circuit breaker is currently closed, false if it is open.
Note
The passed comp MUST be of type ELEC_CB.

Definition at line 4569 of file libelec.c.

◆ libelec_cb_get_temp()

double libelec_cb_get_temp ( const elec_comp_t *  comp)
Returns
The non-dimensional temperature of the circuit breaker's control filament.
Note
The passed comp MUST be of type ELEC_CB.

Definition at line 4584 of file libelec.c.

◆ libelec_cb_set()

void libelec_cb_set ( elec_comp_t *  comp,
bool  set 
)

Sets whether a circuit breaker is current set (closed) or reset (open).

Note
The passed comp MUST be of type ELEC_CB.

Definition at line 4551 of file libelec.c.

◆ libelec_chgr_get_working()

bool libelec_chgr_get_working ( const elec_comp_t *  chgr)
Returns
Bool indicating if the battery charger is operating normally.

Definition at line 5009 of file libelec.c.

◆ libelec_comp2info()

const elec_comp_info_t* libelec_comp2info ( const elec_comp_t *  comp)
Returns
The elec_comp_info_t in use by a particular electrical component in a network. This function never fails, since every electrical component MUST have an associated info structure.

Definition at line 2131 of file libelec.c.

◆ libelec_comp_find()

elec_comp_t* libelec_comp_find ( elec_sys_t *  sys,
const char *  name 
)

Locates an electrical component on the network by name.

Parameters
nameThe name of the component to find.
Returns
If found on the network, a pointer to the electrical component. You can then interrogate this component using other libelec functions. If no component of the specified name exists, returns NULL instead.

Definition at line 2147 of file libelec.c.

◆ libelec_comp_get_conn()

elec_comp_t* libelec_comp_get_conn ( const elec_comp_t *  comp,
size_t  i 
)
Returns
The electrical component which is connected to this component using connection i.
Parameters
iThe index of the connection. This MUST be less than the return value of libelec_comp_get_num_conns().

Definition at line 2194 of file libelec.c.

◆ libelec_comp_get_eff()

double libelec_comp_get_eff ( const elec_comp_t *  comp)
Returns
The current efficiency of the component comp. This MUST be a component of type ELEC_GEN, ELEC_TRU, ELEC_INV or ELEC_XFRMR.

Definition at line 2682 of file libelec.c.

◆ libelec_comp_get_failed()

bool libelec_comp_get_failed ( const elec_comp_t *  comp)
Returns
True if the component is set to failed, false if is not.
See also
libelec_comp_set_failed()

Definition at line 2755 of file libelec.c.

◆ libelec_comp_get_in_amps()

double libelec_comp_get_in_amps ( const elec_comp_t *  comp)
Returns
The input current of the component. While every component has a notion of an input and output current, their physical meaning changes depending on component type:
  • ELEC_BATT : the charging current (if any)
  • ELEC_TRU : the input current on the AC side of the TRU
  • ELEC_INV : the input current on the DC side of the inverter
  • ELEC_XFRMR : the input current to the transformer
  • ELEC_LOAD : the input current into the power supply of the load. If the load has no input capacitance in its power supply, this will always be equal to the actual current consumption of the load. However, with input capacitance, some input current is also generated by the charging of this input capacitance. The inrush current can actually be quite significant, so you should balance the charging resistance of the power supply carefully against the breaker ratings on the bus.
  • ELEC_GEN : input current is an approximation of the mechanical load (but expressed in electrical terms as a fake current), which the generator puts on its input drive, accounting for generator efficiency losses. Simply put, the input current is equal to the output current divided by the generator's efficiency.
  • ELEC_BUS, ELEC_CB, ELEC_SHUNT, ELEC_TIE and ELEC_DIODE : always equal to the output current. These components are assumed to have zero resistance, thus resulting in no energy loss for current passing through them.
Note
Input current demand also accounts for leakage current due to a simulated short-circuit in the component.
See also
libelec_comp_get_out_amps()

Definition at line 2323 of file libelec.c.

◆ libelec_comp_get_in_freq()

double libelec_comp_get_in_freq ( const elec_comp_t *  comp)
Returns
The input frequency of the component. While every component has a notion of an input and output frequency, their physical meaning changes depending on component type:
  • ELEC_BATT and ELEC_DIODE : these are DC-only devices, so this will always be zero.
  • ELEC_TRU : the AC frequency on the AC side input of the TRU.
  • ELEC_INV : always zero, since the inverter input is DC.
  • ELEC_XFRMR : the frequency of the AC current flowing through the transformer. Both input and output frequency will always be equal to each other.
  • ELEC_LOAD : the AC frequency of the input bus into the load's power supply. If the load is DC, this will always be zero.
  • ELEC_GEN : always equal to the output frequency (see libelec_comp_get_out_freq()).
  • ELEC_BUS, ELEC_CB, ELEC_SHUNT and ELEC_TIE : always equal to the output frequency. These components do not do anything with AC frequency, and so they simply pass the parameter through.

Definition at line 2504 of file libelec.c.

◆ libelec_comp_get_in_pwr()

double libelec_comp_get_in_pwr ( const elec_comp_t *  comp)
Returns
The input power demand of the component.
Note
libelec has no notion of apparent power, power factor or cos-Phi. All power flows are assumed to be completely resistive. As such, input power is simply the product of input voltage and input current.
Returns
While every component has a notion of an input and output power, their physical meaning changes depending on component type:
  • ELEC_BATT : the charging power flow (if any)
  • ELEC_TRU : the input power on the AC side of the TRU. This will be higher than the output power on the DC side because of the efficiency losses during rectification and voltage transformation inside of the TRU.
  • ELEC_INV : the input power on the DC side of the inverter. This will be higher than the output power on the AC side because of the efficiency losses during inversion and voltage transformation inside of the inverter.
  • ELEC_XFRMR : the input power into the transformer. This will be higher than the output power because of the efficiency losses during voltage transformation.
  • ELEC_LOAD : the input power into the power supply of the load.
  • ELEC_GEN : the mechanical load which the generator causes on its input shaft. You can use this to account for generator-induced engine drag. The input power will always be greater than the generator's electrical output power, because the generator has a sub-100% efficiency during electrical power generation.
  • ELEC_BUS, ELEC_CB , ELEC_SHUNT, ELEC_TIE and ELEC_DIODE : always equal to the output power. These components are assumed to have zero resistance, thus resulting in no energy loss for power passing through them.
See also
libelec_comp_get_out_pwr()

Definition at line 2410 of file libelec.c.

◆ libelec_comp_get_in_volts()

double libelec_comp_get_in_volts ( const elec_comp_t *  comp)
Returns
The input voltage of the component. While every component has a notion of an input and output voltage, their physical meaning changes depending on component type:
  • ELEC_BATT : the charging voltage (if any)
  • ELEC_TRU : the input voltage on the AC side of the TRU
  • ELEC_INV : the input voltage on the DC side of the inverter
  • ELEC_XFRMR : the input voltage to the transformer
  • ELEC_LOAD : the input voltage into the power supply of the load. This will immediately follow the bus voltage to which the load is attached. Please note that simply seeing the voltage drop to zero doesn't mean the load immediately becomes unpowered. If the load has a power supply with non-zero input capacitance, its output voltage out of this power supply will decay more slowly, allowing the load to "bridge" short periods of loss of input power (e.g. during bus contactor switching).
  • ELEC_GEN, ELEC_BUS, ELEC_CB, ELEC_SHUNT and ELEC_TIE : always equal to the output voltage
  • ELEC_DIODE : voltage at the input side of the diode. If the input voltage of any source on the input side of the diode is higher than that of any source on the output side, the diode allows current flow from input to output. Otherwise, the diode blocks current flow.
See also
libelec_comp_get_out_volts()

Definition at line 2232 of file libelec.c.

◆ libelec_comp_get_incap_volts()

double libelec_comp_get_incap_volts ( const elec_comp_t *  comp)
Parameters
compThe component for which to return the input capacitance voltage. This MUST be a component of type ELEC_LOAD.
Returns
The voltage of the internal power supply imaginary "capacitor" used to model power supply input capacitance. This can be used to estimate the "state of charge" of the power supply's capacitance. If the input voltage into the load is higher than this capacitor voltage, the imaginary capacitor will begin to charge up. If the input voltage is lower than the power supply capacitance voltage, the capacitance will begin to "make up the difference" to the desired energy flow to the load's electrical demand. Loads with no power supply capacitance always return 0.

Definition at line 2574 of file libelec.c.

◆ libelec_comp_get_num_conns()

size_t libelec_comp_get_num_conns ( const elec_comp_t *  comp)
Returns
The number of connections of a particular component. This can be used to dynamically figure out the network structure. You can then retrieve individual connected components using libelec_comp_get_conn().

Definition at line 2164 of file libelec.c.

◆ libelec_comp_get_out_amps()

double libelec_comp_get_out_amps ( const elec_comp_t *  comp)
Returns
The output current of the component. While every component has a notion of an input and output current, their physical meaning changes depending on component type:
  • ELEC_BATT : the discharging current (if any)
  • ELEC_TRU : the output current on the DC side of the TRU
  • ELEC_INV : the output current on the AC side of the inverter
  • ELEC_XFRMR : the output current out of the transformer
  • ELEC_LOAD : the output current out of the power supply of the load into its internal working components.
  • ELEC_GEN : output current demand on the generator. This is dictated by the current demands of all downstream components powered by the generator.
  • ELEC_BUS, ELEC_CB, ELEC_SHUNT , ELEC_TIE and ELEC_DIODE : always equal to the input current. These components are assumed to have zero resistance, thus resulting in no energy loss for current passing through them.
Note
Output current demand also accounts for leakage current due to a simulated short-circuit in the component.
See also
libelec_comp_get_in_amps()

Definition at line 2360 of file libelec.c.

◆ libelec_comp_get_out_freq()

double libelec_comp_get_out_freq ( const elec_comp_t *  comp)
Returns
The output frequency of the component. While every component has a notion of an input and output frequency, their physical meaning changes depending on component type:
  • ELEC_BATT and ELEC_DIODE : these are DC-only devices, so this will always be zero.
  • ELEC_TRU : always zero, since the TRU performs AC-to-DC rectification.
  • ELEC_INV : the AC frequency generated by the inverter.
  • ELEC_XFRMR : the frequency of the AC current flowing through the transformer. Both input and output frequency will always be equal to each other.
  • ELEC_LOAD : the AC frequency of the input bus into the load's power supply. If the load is DC, this will always be zero. If the load is unpowered, this remains at the last value to which it was set. You should probably not really rely on this value to do anything sensible.
  • ELEC_GEN : for AC generators, this is the output frequency of the generator. For DC generators, this is always zero. AC generator frequency behavior depends on the input rpm and stabilization limits defined for the generator in the network definition file.
  • ELEC_BUS, ELEC_CB, ELEC_SHUNT and ELEC_TIE : always equal to the input frequency. These components do not do anything with AC frequency, and so they simply pass the parameter through.

Definition at line 2546 of file libelec.c.

◆ libelec_comp_get_out_pwr()

double libelec_comp_get_out_pwr ( const elec_comp_t *  comp)
Returns
The output power demand flow out of the component.
Note
libelec has no notion of apparent power, power factor or cos-Phi. All power flows are assumed to be completely resistive. As such, output power is simply the product of output voltage and output current.
Returns
While every component has a notion of an input and output power, their physical meaning changes depending on component type:
  • ELEC_BATT : the discharging power flow out of the battery. Note that libelec doesn't simulate battery self-discharge. You will want to implement that yourself, by slowly reducing the battery's state of charge (using libelec_batt_set_chg_rel()) over time, according to your battery's behavioral characteristics.
  • ELEC_TRU : the output power on the DC side of the TRU. This will be lower than the input power on the AC side because of the efficiency losses during rectification and voltage transformation inside of the TRU.
  • ELEC_INV : the output power on the AC side of the inverter. This will be lower than the input power on the DC side because of the efficiency losses during inversion and voltage transformation inside of the inverter.
  • ELEC_XFRMR : the output power out of the transformer. This will be lower than the input power because of efficiency losses during voltage transformation.
  • ELEC_LOAD : the output power out of the load's power supply and into the load's internal electronics. If you see this drop to zero, you can be sure that the load is no longer powered (you should use libelec_comp_is_powered() for components which have a MIN_VOLTS value defined, as that communicates intent better than simply checking the output power).
  • ELEC_GEN : the electrical power load on the generator, caused by all of its downstream loads. Note that this wiill always be lower than the input power load on the mechanical input of the generator due to efficiency losses.
  • ELEC_BUS, ELEC_CB, ELEC_SHUNT, ELEC_TIE and ELEC_DIODE : always equal to the input power. These components are assumed to have zero resistance, thus resulting in no energy loss for power passing through them.
See also
libelec_comp_get_in_pwr()

Definition at line 2469 of file libelec.c.

◆ libelec_comp_get_out_volts()

double libelec_comp_get_out_volts ( const elec_comp_t *  comp)
Returns
The Output voltage of the component. While every component has a notion of an input and output voltage, their physical meaning changes depending on component type:
  • ELEC_BATT : the voltage the battery puts on the connected bus and which can be used by downstream components to extract energy out of the battery.
  • ELEC_TRU : the output voltage on the DC side of the TRU
  • ELEC_INV : the output voltage on the AC side of the inverter
  • ELEC_XFRMR : the output voltage of the transformer
  • ELEC_LOAD : the output voltage out of the power supply of the load. If the load's power supply has no input capacitance, this will immediately follow the input voltage from the bus the load is attached to. However, if the load's power supply has non-zero input capacitance, the output voltage out of this power supply will decay more slowly, allowing the load to "bridge" short periods of loss of input power (e.g. during bus contactor switching).
  • ELEC_GEN, ELEC_BUS, ELEC_CB, ELEC_SHUNT and ELEC_TIE : always equal to the input voltage
  • ELEC_DIODE : voltage at the output side of the diode. If the input voltage of any source on the input side of the diode is higher than that of any source on the output side, the diode allows current flow from input to output. Otherwise, the diode blocks current flow.
See also
libelec_comp_get_in_volts()

Definition at line 2276 of file libelec.c.

◆ libelec_comp_get_shorted()

bool libelec_comp_get_shorted ( const elec_comp_t *  comp)
Returns
True if the component's short-circuit failure is set, or false if it is not.
See also
libelec_comp_set_shorted()

Definition at line 2789 of file libelec.c.

◆ libelec_comp_get_userinfo()

void* libelec_comp_get_userinfo ( const elec_comp_t *  comp)
Returns
The userinfo pointer previously passed to libelec_comp_set_userinfo(). If no userinfo pointer was ever set, returns NULL.

Definition at line 2895 of file libelec.c.

◆ libelec_comp_is_AC()

bool libelec_comp_is_AC ( const elec_comp_t *  comp)
Returns
Depending on component type:

Definition at line 2590 of file libelec.c.

◆ libelec_comp_is_powered()

bool libelec_comp_is_powered ( const elec_comp_t *  comp)
Returns
True if the component is powered, false if it isn't. A component is considered powered if its output voltage is greater than zero. For most component this requires that the component be connected to a suitable energy source.
Components of type ELEC_LOAD get special treatment.
  • If the input voltage into the load is insufficient, but the component's power supply has some input capacitance, the residual capacitance of the power supply will serve to briefly power the load's power demand. As such, libelec_comp_is_powered() might actually return true briefly, even if there is no power generator or battery connected to the load.
  • Loads which declare MIN_VOLTS stanza will be considered unpowered if their power supply output voltage drops below the MIN_VOLTS requirement.

Definition at line 2670 of file libelec.c.

◆ libelec_comp_set_failed()

void libelec_comp_set_failed ( elec_comp_t *  comp,
bool  failed 
)

Sets a component's failed status. The behavior of a failed component depends on its type:

  • ELEC_BATT: provides no output voltage and cannot be charged.
  • ELEC_DIODE, ELEC_BUS, ELEC_CB, ELEC_SHUNT and ELEC_TIE: doesn't allow any current to pass through the component.
  • ELEC_TRU: generates no electrical load on its AC input and provides no voltage on its DC output.
  • ELEC_INV: generates no electrical load on its DC input and provides no voltage on its AC output.
  • ELEC_XFRMR: generates no electrical load on its input and provides no voltage on its output.
  • ELEC_GEN: generates no voltage on its output and requires no mechanical input power.
  • ELEC_LOAD: draws no electrical current and is permanently unpowered (libelec_comp_is_powered() always returns false).
    See also
    libelec_comp_get_failed()

Definition at line 2742 of file libelec.c.

◆ libelec_comp_set_shorted()

void libelec_comp_set_shorted ( elec_comp_t *  comp,
bool  shorted 
)

Sets a component's short-circuit failure status. Short circuits are simulated by creating a random massive increase in a leakage current entering the component. This energy is not directed to any other connected components, or accounted for in a load's output power, but is rather "lost" to ground. The amount of leakage current is randomized and depends on the component's normal input current flow. It will typically oscillate somewhere between 30-40x the normal current. This should guarantee that any breaker protecting this device will trip in fairly short order.

See also
libelec_comp_get_shorted()

Definition at line 2775 of file libelec.c.

◆ libelec_comp_set_userinfo()

void libelec_comp_set_userinfo ( elec_comp_t *  comp,
void *  userinfo 
)

Sets the userinfo pointer of a component. This userinfo pointer is passed to all callbacks (such as those set up using libelec_batt_set_temp_cb() or ibelec_gen_set_rpm_cb()) in the second argument of the callback. You can use this information to pass along any extra information to the callbacks that you may need.

Definition at line 2882 of file libelec.c.

◆ libelec_deserialize()

bool libelec_deserialize ( elec_sys_t *  sys,
const conf_t *  ser,
const char *  prefix 
)

Deserializes a serialized network state previously saved using libelec_serialize(). Before attempting deserialization, the library compares the saved state to the currently running one. If there were any alterations done to the electrical definition file, no attempt is made to try to reload the serialized state and this function aborts with an error.

Parameters
serA libacfutils conf_t object, which was reloaded from persistent storage after having been previously populated with libelec_serialize().
prefixThe same conf key prefix as was passed to libelec_serialize().
Returns
True if the network state was reloaded successfully. If an error occurred, false is returned instead. The error reason is logged using libacfutils' logging facility.

Definition at line 1245 of file libelec.c.

◆ libelec_destroy()

void libelec_destroy ( elec_sys_t *  sys)

Destroys a libelec network, which was previously loaded using libelec_new(). You MUST stop the network using libelec_sys_stop() before attempting to destroy it.

Definition at line 1287 of file libelec.c.

◆ libelec_gen_get_rpm()

double libelec_gen_get_rpm ( const elec_comp_t *  gen)
Returns
The current generator RPM of gen. This MUST be a component of type ELEC_GEN.
Note
Despite its name, the units of speed are arbitrary and are dependent on what you set with either libelec_gen_set_rpm(), or what the elec_gen_rpm_cb_t callback returned for the generator.
See also
libelec_gen_set_rpm()
elec_gen_rpm_cb_t

Definition at line 4920 of file libelec.c.

◆ libelec_gen_get_rpm_cb()

elec_get_rpm_cb_t libelec_gen_get_rpm_cb ( const elec_comp_t *  gen)
Returns
The generator rpm callback, which was previously set using libelec_gen_set_rpm_cb(), or NULL if no callback was set.
See also
libelec_gen_set_rpm_cb()

Definition at line 2970 of file libelec.c.

◆ libelec_gen_set_random_freq()

double libelec_gen_set_random_freq ( elec_comp_t *  comp,
double  stddev 
)

Same as libelec_gen_set_random_volts(), but operates on an AC generator's frequency stability.

See also
libelec_gen_set_random_volts()

Definition at line 2864 of file libelec.c.

◆ libelec_gen_set_random_volts()

double libelec_gen_set_random_volts ( elec_comp_t *  comp,
double  stddev 
)

Sets up a random under- or over-voltage failure condition on a generator.

Parameters
compThe generator for which to set the failure up. This MUST be a component of type ELEC_GEN.
stddevStandard deviation of the error. The library will use a Gaussian random number generator to pick a value which is at least 0.5x stddev and at most 1.5x stddev away from the nominal voltage of the generator. The standard deviation MUST be less than 66% of the nominal voltage (to guarantee that the random voltage value doesn't go to zero or negative). For example, a good value for a 115V generator would be something like 30V. This would generate a random voltage deviation of 15-45V from the nominal (randomly selected to either be an over-voltage or under-voltage condition). To disable the failure, simply set stddev to zero.
Returns
The new random voltage target of the generator. If stddev was zero, returns the nominal voltage of the generator.
See also
libelec_gen_set_random_freq()

Definition at line 2849 of file libelec.c.

◆ libelec_gen_set_rpm()

void libelec_gen_set_rpm ( elec_comp_t *  gen,
double  rpm 
)

Sets the generator's RPM value.

Parameters
genThe generator for which to set the rpm. This MUST be a component of type ELEC_GEN.
rpmThe RPM to set on the generator.
Note
Despite its name, the units of rpm are arbitrary. You can use whatever units you prefer. You simply need to be consistent with the EXC_RPM, MIN_RPM and MAX_RPM stanzas when defining the generator in the config file.
See also
libelec_gen_get_rpm()

Definition at line 4893 of file libelec.c.

◆ libelec_gen_set_rpm_cb()

void libelec_gen_set_rpm_cb ( elec_comp_t *  gen,
elec_get_rpm_cb_t  cb 
)

Sets the generator rpm callback. libelec uses this callback to determine the rotational speed of the generator's input shaft, which it then uses to calculate the output voltage and frequency.

Note
You must NOT call this function after the network has been started by a call to libelec_sys_start(). The network MUST be stopped before attempting to reconfigure it.
Parameters
battThe generator for which to configure the callback. Must be a component of type ELEC_GEN.
cbThe callback to set. You may pass NULL here to remove the calllback. You can use libelec_gen_set_rpm() to set the rpm directly.
See also
elec_get_rpm_cb_t
libelec_gen_set_rpm()

Definition at line 2956 of file libelec.c.

◆ libelec_get_comp_infos()

const elec_comp_info_t* libelec_get_comp_infos ( const elec_sys_t *  sys,
size_t *  num_infos 
)
Returns
All component info structures in the network as a flat array. This can be useful for enumerating all infos during debugging. You must NOT free the returned pointer, since the library retains ownership over it.
Parameters
num_infosMandatory return parameter, which will be filled with the number of elements in the returned array.

Definition at line 539 of file libelec.c.

◆ libelec_load_get_load_cb()

elec_get_load_cb_t libelec_load_get_load_cb ( elec_comp_t *  load)
Returns
The load demand callback, which was previously set using libelec_load_set_load_cb(), or NULL if no callback was set.
See also
elec_get_load_cb_t

Definition at line 3007 of file libelec.c.

◆ libelec_load_set_load_cb()

void libelec_load_set_load_cb ( elec_comp_t *  load,
elec_get_load_cb_t  cb 
)

Sets the load demand callback for an electrical load. libelec can use this callback to determine the electrical load demand of the component.

Note
You must NOT call this function after the network has been started by a call to libelec_sys_start(). The network MUST be stopped before attempting to reconfigure it.
Parameters
battThe load for which to configure the callback. Must be a component of type ELEC_LOAD.
cbThe callback to set. You may pass NULL here to remove the callback. A load which does not have a custom load callback configured can still fall back to its standard load demand, as set using the STD_LOAD configuration stanza.
See also
elec_get_load_cb_t

Definition at line 2993 of file libelec.c.

◆ libelec_new()

elec_sys_t* libelec_new ( const char *  filename)

Allocates and initializes a new electrical system. You must supply a file, which holds the definition of the electrical network layout. See Electrical Network File Format for more information.

After initialization, the electrical network is in a stopped state. This means, the simulation isn't yet running, allowing you to configure the network by setting up custom callbacks, or manipulating the parsed info structures in the components. Use libelec_comp_find() to locate components by name and libelec_comp2info() to extract the parsed info structures for the respective component and modify the info structure as necessary.

Once you are satisfied with the configuration of the network, you can start the simulation up by running libelec_sys_start(). This spawns a background thread, running the physics simulation of the network. You should only call this when the host simulator has finished loading your airplane (i.e. on the first frame of the simulator actually running).

On unload, first stop the network using libelec_sys_stop(). After stopping the network, you could potentially modify the info structs and restart the network again. A stopped network can be freed using libelec_destroy().

Parameters
filenameFull file path and name to the electrical network definition file. This must conform to the syntax described in Configuration File Format.
Returns
The parsed and initialized electrical network, if the network could be successfully constructuted. The networked is a stopped state, meaning, the physics worker thread isn't operating yet and no simulation is taking place. After you have performed any runtime configuration of the network, it must be started using libelec_sys_start() on the first simulator frame.
If an error occurred, this function returns NULL instead. You MUST be prepared to handle a NULL return out of this function, since it's easy to make a mistake in the definition file and this is your primary method of detecting such a failure. The failure reason is printed to the system log using the logMsg() function of libacfutils (you must initialize libacfutils' logging subsystem beforehand).
See also
libelec_sys_start()
libelec_sys_stop()
libelec_destroy()
libelec_comp_find()
libelec_comp2info()

Definition at line 737 of file libelec.c.

◆ libelec_phys_get_batt_voltage()

double libelec_phys_get_batt_voltage ( double  U_nominal,
double  chg_rel,
double  I_rel 
)

Utility function which allows you to determine the battery voltage of a custom battery, mirroring the same algorithm which libelec uses to calculate battery voltage.

Parameters
U_nominalNominal battery voltage when at full state of charge and standard temperature (typically around 20°C).
chg_relRelative state of charge from 0.0 to 1.0.
I_relRelative current draw out of the battery, compared to its nominal design current draw rating. Higher current draws cause the battery voltage to depress more, due to the effects of internal resistance.

Definition at line 5033 of file libelec.c.

◆ libelec_remove_user_cb()

void libelec_remove_user_cb ( elec_sys_t *  sys,
bool  pre,
elec_user_cb_t  cb,
void *  userinfo 
)

Removes a custom user callback, which was previously registered using libelec_add_user_cb(). You must pass the exact same combination of pre, cb and userinfo as was previously used during the registration. The callback MUST exist, otherwise an assertion failure is triggered.

See also
libelec_add_user_cb()

Definition at line 2076 of file libelec.c.

◆ libelec_serialize()

void libelec_serialize ( elec_sys_t *  sys,
conf_t *  ser,
const char *  prefix 
)

Serializes the run-time state of the network. You can use this to implement aircraft state persistence. When saving your aircraft state, call this function to save all electrical network state. Use libelec_deserialize() to restore a previously serialized state.

This function is safe to call after the network has been started (in fact, that is its intended purpose - you don't have to stop the network to perform state serializations). Since this function can block while trying to interlock with the network's physics worker thread, it is recommended not to call this from the simulator's main thread (to prevent micro-stutter), but instead from a dedicated state saving background thread.

Parameters
serA libacfutils conf_t object, which will be filled with the serialized network state. This is the object which you should write to persistence storage to later reload.
prefixA name prefix which will be prepended to the configuration keys that will be placed into the ser conf_t object. This is to prevent namespace clashing with any other data you might be using that conf_t object for. A common name prefix would be something like "libelec".

Definition at line 1205 of file libelec.c.

◆ libelec_sys_can_start()

bool libelec_sys_can_start ( const elec_sys_t *  sys)

Performs a validation check on the electrical network to see if it is ready for start.

Returns
True if the network has passed validation checks and is ready to be started. If the validation checks failed, returns false instead and logs the error reason to the logging subsystem. If the network is already started, always returns false.

Definition at line 951 of file libelec.c.

◆ libelec_sys_get_time_factor()

double libelec_sys_get_time_factor ( const elec_sys_t *  sys)
Returns
The current simulation time factor.
See also
libelec_sys_set_time_factor()

Definition at line 1081 of file libelec.c.

◆ libelec_sys_is_started()

bool libelec_sys_is_started ( const elec_sys_t *  sys)
Returns
True if the network has been started (libelec_sys_start() has been called successfully), false if the network is stopped. Please note that this doesn't detect a paused state of the simulator. When the host simulator is paused, the network simulation doesn't "stop", it simply pauses.

Definition at line 936 of file libelec.c.

◆ libelec_sys_set_time_factor()

void libelec_sys_set_time_factor ( elec_sys_t *  sys,
double  time_factor 
)

Sets the simulation rate of libelec. This can be used to adapt libelec's physics to the host simulator's simulation rate, in case the simulator is running faster or slower than real time, or is paused.

Note
If libelec was built with the XPLANE macro ddefined, this function does nothing, as libelec automatically adapts to X-Plane's simulation rate.
Parameters
time_factorThe non-negative factor by which time is accelerated. Normal real-time operation is 1.0. If the simulator is running twice as fast as real time, time_factor is 2.0. If the simulator is running half as fast as real time, time_factor is 0.5. To tell libelec that the simulator is paused, set time_factor to 0.
Note
Faster simulation rates simply speed up the rate at which libelec performs its physics calculations. This comes with an inherent CPU cost. If running real-time libelec's worker thread consumes 5% of one CPU core, then running it with time_factor=10 will consume 50% of one CPU core. libelec cannot run faster than a single CPU core on the machine, imposing a hard cap on the maximum time_factor that can be effectively followed. If the CPU cannot keep up, libelec will appear to be lagging behind the desired simulation rate.

Definition at line 1044 of file libelec.c.

◆ libelec_sys_start()

bool libelec_sys_start ( elec_sys_t *  sys)

Starts a stopped libelec network. If the network was already started, this function does nothing.

Initially, after loading with libelec_new(), a libelec instance is stopped and not performing any physics simulation. You should configure the returned network as you see fit prior to starting - any modifications to the component info structure are not allowed after the network has been started, as that can lead to race conditions and unpredictable behavior.

Since there is usually a significant delay between your aircraft loading into the simulator and the simulation actually starting up, you should delay starting the electrical network until the first simulator frame.

Returns
True if starting the network succeeded, or false if there was a network configuration error. To allow for more dynamic reconfiguration of the network

Definition at line 977 of file libelec.c.

◆ libelec_sys_stop()

void libelec_sys_stop ( elec_sys_t *  sys)

Stops the electrical network after it has been started using libelec_sys_start(). If the network was already stopped, this function does nothing.

Note
You MUST stop the network manually using libelec_sys_stop() prior to calling libelec_destroy() to free the network.

Definition at line 1003 of file libelec.c.

◆ libelec_tie_get()

bool libelec_tie_get ( elec_comp_t *  tie,
bool_t  exhaustive,
  ... 
)

Given a variadic argument list of buses, determines if the buses are currently tied.

Parameters
tieThe tie to examine. This must be a component of type ELEC_TIE.
exhaustiveSee description of return value below.
...List elec_comp_t pointers to the buses which are to be examined. The argument list MUST be terminated by a NULL pointer (sentinel).
Returns
True if all of the buses specified in the argument list are tied. If even a single one of the buses is untied, this function returns false. In addition, if exhaustive is set to true, this function returns false if the argument list doesn't mention all of the buses currently tied (meaning, the argument list must be an exhaustive list of buses which are currently tied).

Definition at line 4825 of file libelec.c.

◆ libelec_tie_get_all()

bool libelec_tie_get_all ( elec_comp_t *  comp)
Parameters
compThe tie to examine. This must be of type ELEC_TIE.
Returns
True if all endpoints of the tie are currently tied together, or false otherwise. This is useful for ties which you are utilizing as a simple switch. Use libelec_tie_set_all() to either open and close the switch, and libelec_tie_get_all() to examine if the switch is open or closed.
See also
libelec_tie_set_all()

Definition at line 4738 of file libelec.c.

◆ libelec_tie_get_list()

size_t libelec_tie_get_list ( elec_comp_t *  comp,
size_t  cap,
elec_comp_t *  bus_list[] 
)

Retrieves the exact list of tied buses for a ELEC_TIE component.

Parameters
compThe tie for which to retrieve the list. This MUST be a component of ELEC_TIE.
capCapacity of bus_list. This MUST be greater than or equal to the return value of libelec_tie_get_num_buses().
bus_listA return argument, which will be filled with the list of buses currently tied. Any buses NOT mentioned in this list are currently NOT tied. This array MUST be able to hold at least libelec_tie_get_num_buses() elements.
Returns
The actual number of buses filled into bus_list.
See also
libelec_tie_get_num_buses()

Definition at line 4768 of file libelec.c.

◆ libelec_tie_get_num_buses()

size_t libelec_tie_get_num_buses ( const elec_comp_t *  comp)
Returns
The total number of bus connections in tie comp. This MUST be a component of ELEC_TIE. The returned number DOESN'T signify that that number of buses are currently tied together, only that the tie is connected to this number of buses and CAN be tied together. Use libelec_tie_get_list() to determine the exact buses which are currently tied together.
See also
libelec_tie_get_list()

Definition at line 4799 of file libelec.c.

◆ libelec_tie_get_v()

bool libelec_tie_get_v ( elec_comp_t *  tie,
bool  exclusive,
va_list  ap 
)

Same as libelec_tie_get(), but takes a va_list argument for the bus list, to allow for nesting inside of other variadic functions.

Definition at line 4844 of file libelec.c.

◆ libelec_tie_set()

void libelec_tie_set ( elec_comp_t *  comp,
  ... 
)

A convenience variadic version of libelec_tie_set_list().

Parameters
compThe tie to reconfigure. This must be of type ELEC_TIE.
...A variadic list of elec_comp_t pointers to buses, which should be tied together. This list MUST be terminated by a single NULL pointer (sentinel). Any buses which the tie is connected to but are not mentioned on this list become untied.

Definition at line 4659 of file libelec.c.

◆ libelec_tie_set_all()

void libelec_tie_set_all ( elec_comp_t *  comp,
bool  tied 
)

Convenience function, which allows either tying all connections of an ELEC_TIE component, or untying all of them. This is equivalent to calling libelec_tie_set_list() with a list of all buses to which the tie is connected.

Parameters
compThe tie to reconfigure. This must be of type ELEC_TIE.
tiedFlag indicating whether all endpoints of the tie should be tied, or untied.
See also
libelec_tie_get_all()

Definition at line 4713 of file libelec.c.

◆ libelec_tie_set_list()

void libelec_tie_set_list ( elec_comp_t *  comp,
size_t  list_len,
elec_comp_t *const  bus_list[] 
)

Reconfigures a tie's current state to tie together the bus connections matching a list of elec_comp_t pointers.

Parameters
compThe tie to reconfigure. This must be of type ELEC_TIE.
list_lenNumber of elements in bus_list.
bus_listList of elec_comp_t pointers, which should be tied together. The tie MUST be connected to these buses. Any buses which the tie is connected to but are not mentioned on this list become untied.
See also
ELEC_TIE

Definition at line 4605 of file libelec.c.

◆ libelec_tie_set_v()

void libelec_tie_set_v ( elec_comp_t *  comp,
va_list  ap 
)

Same as libelec_tie_set(), but takes a va_list argument, allowing for nesting within other variadic functions.

Parameters
compThe tie to reconfigure. This must be of type ELEC_TIE.

Definition at line 4676 of file libelec.c.

◆ libelec_walk_comps()

void libelec_walk_comps ( const elec_sys_t *  sys,
void(*)(elec_comp_t *, void *)  cb,
void *  userinfo 
)

Walker function, which will go through all components on the network. This is mostly used for debugging.

Parameters
cbA callback, which you must supply and will be called in turn with every electrical component on the network in its first argument.
userinfoAn optional custom pointer parameter. This will be passed in the second argument to the cb callback you supply above.

Definition at line 2108 of file libelec.c.