rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Data Structures | Namespaces | Typedefs | Functions
efilib.h File Reference

Detailed Description

Date
Feb 21, 2014
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file efilib.h.

Data Structures

struct  efi::remove_reference< _Ty >
 
struct  efi::remove_reference< _Ty & >
 
struct  efi::remove_reference< _Ty && >
 

Namespaces

namespace  efi
 

Typedefs

template<class _Ty >
using efi::remove_reference_t = typename remove_reference< _Ty >::type
 

Functions

int djb2lowerCase (const char *str)
 
uint16_t SWAP_UINT16 (uint16_t x)
 
uint32_t SWAP_UINT32 (uint32_t x)
 
const charboolToString (bool value)
 
charefiTrim (char *param)
 
int efiPow10 (int param)
 
float efiRound (float value, float precision)
 
charitoa10 (char *p, int num)
 
float limitRateOfChange (float newValue, float oldValue, float incrLimitPerSec, float decrLimitPerSec, float secsPassed)
 
bool isPhaseInRange (float test, float current, float next)
 
template<typename T >
bool isInRange (T min, T val, T max)
 
constexpr size_t operator- (Gpio a, Gpio b)
 
constexpr Gpio operator- (Gpio a, size_t b)
 
constexpr Gpio operator+ (Gpio a, size_t b)
 
constexpr Gpio operator+ (size_t a, Gpio b)
 
template<class _Ty >
constexpr remove_reference_t< _Ty > && efi::move (_Ty &&_Arg) noexcept
 
int getBitRangeLsb (const uint8_t data[], int bitIndex, int bitWidth)
 
int getBitRangeMsb (const uint8_t data[], int bitIndex, int bitWidth)
 
void setBitRangeMsb (uint8_t data[], int totalBitIndex, int bitWidth, int value)
 
int motorolaMagicFromDbc (int b, int length)
 
int getBitRangeMoto (const uint8_t data[], int bitIndex, int bitWidth)
 
void setBitRangeMoto (uint8_t data[], int totalBitIndex, int bitWidth, int value)
 

Function Documentation

◆ boolToString()

const char * boolToString ( bool  value)

◆ djb2lowerCase()

int djb2lowerCase ( const char str)

Definition at line 135 of file efilib.cpp.

135 {
136 unsigned long hash = 5381;
137 int c;
138
139 while ( (c = *str++) ) {
140 c = std::tolower(c);
141 hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
142 }
143
144 return hash;
145}

Referenced by getConfigValueByName(), getOutputValueByName(), and setConfigValueByName().

Here is the caller graph for this function:

◆ efiPow10()

int efiPow10 ( int  param)

Definition at line 111 of file efilib.cpp.

111 {
112 switch (param) {
113 case 0:
114 return 1;
115 case 1:
116 return 10;
117 case 2:
118 return 100;
119 case 3:
120 return 1000;
121 case 4:
122 return 10000;
123 case 5:
124 return 100000;
125 case 6:
126 return 1000000;
127 case 7:
128 return 10000000;
129 case 8:
130 return 100000000;
131 }
132 return 10 * efiPow10(10 - 1);
133}
int efiPow10(int param)
Definition efilib.cpp:111
static tstrWifiInitParam param

Referenced by DisplayErrorCode(), and efiPow10().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ efiRound()

float efiRound ( float  value,
float  precision 
)

Rounds value to specified precision.

Parameters
precisionsome pow of 10 value - for example, 100 for two digit precision
precisionfor example '0.1' for one digit fractional part

Definition at line 34 of file efilib.cpp.

34 {
35 efiAssert(ObdCode::CUSTOM_ERR_ASSERT, precision != 0, "Zero precision is not valid for efiRound maybe you mean '1'?", NAN);
36 float a = round(value / precision);
37 return fixNegativeZero(a * precision);
38}
@ CUSTOM_ERR_ASSERT

Referenced by StepperMotorBase::doIteration(), getDacValue(), obdSendValue(), setHysteresis(), StepperMotorBase::setInitialPosition(), setLinearCurve(), setRpmBin(), TriggerWaveform::setTriggerSynchronizationGap3(), and DynoView::update().

Here is the caller graph for this function:

◆ efiTrim()

char * efiTrim ( char param)

Definition at line 40 of file efilib.cpp.

40 {
41 while (param[0] == ' ') {
42 param++; // that would skip leading spaces
43 }
44 int len = std::strlen(param);
45 while (len > 0 && param[len - 1] == ' ') {
46 param[len - 1] = 0;
47 len--;
48 }
49 return param;
50}

Referenced by TunerStudio::handleExecuteCommand().

Here is the caller graph for this function:

◆ getBitRangeLsb()

int getBitRangeLsb ( const uint8_t  data[],
int  bitIndex,
int  bitWidth 
)

Definition at line 207 of file efilib.cpp.

207 {
208 return getBitRangeCommon(data, bitIndex, bitWidth, 1);
209}
static int getBitRangeCommon(const uint8_t data[], int bitIndex, int bitWidth, int secondByteOffset)
Definition efilib.cpp:195

Referenced by processHyundai().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBitRangeMoto()

int getBitRangeMoto ( const uint8_t  data[],
int  bitIndex,
int  bitWidth 
)

Definition at line 243 of file efilib.cpp.

243 {
244 const int b = motorolaMagicFromDbc(bitIndex, bitWidth);
245 return getBitRangeMsb(data, b, bitWidth);
246}
int motorolaMagicFromDbc(int b, int length)
Definition efilib.cpp:232
int getBitRangeMsb(const uint8_t data[], int bitIndex, int bitWidth)
Definition efilib.cpp:212
Here is the call graph for this function:

◆ getBitRangeMsb()

int getBitRangeMsb ( const uint8_t  data[],
int  bitIndex,
int  bitWidth 
)

for instance DBC 8|16@0

Definition at line 212 of file efilib.cpp.

212 {
213 return getBitRangeCommon(data, bitIndex, bitWidth, -1);
214}

Referenced by getBitRangeMoto().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isInRange()

template<typename T >
bool isInRange ( min,
val,
max 
)

Definition at line 82 of file efilib.h.

82 {
83 return val >= min && val <= max;
84}

Referenced by TriggerDecoderBase::isSyncPoint(), and TriggerDecoderBase::printGaps().

Here is the caller graph for this function:

◆ isPhaseInRange()

bool isPhaseInRange ( float  test,
float  current,
float  next 
)

Definition at line 176 of file efilib.cpp.

176 {
177 bool afterCurrent = test >= current;
178 bool beforeNext = test < next;
179
180 if (next > current) {
181 // we're not near the end of the cycle, comparison is simple
182 // 0 |------------------------| 720
183 // next current
184 return afterCurrent && beforeNext;
185 } else {
186 // we're near the end of the cycle so we have to check the wraparound
187 // 0 -----------| |------ 720
188 // next current
189 // Check whether test is after current (ie, between current tooth and end of cycle)
190 // or if test if before next (ie, between start of cycle and next tooth)
191 return afterCurrent || beforeNext;
192 }
193}
union test_buffers test
Definition test.c:50

Referenced by MapAveragingModule::onEnginePhase(), onTriggerEventSparkLogic(), InjectionEvent::onTriggerTooth(), and AngleBasedEvent::shouldSchedule().

Here is the caller graph for this function:

◆ itoa10()

char * itoa10 ( char p,
int  num 
)

Integer to string

Returns
pointer at the end zero symbol after the digits

Definition at line 107 of file efilib.cpp.

107 {
108 return itoa_signed(p, num, 10);
109}
static char * itoa_signed(char *p, int num, unsigned radix)
Definition efilib.cpp:90

Referenced by addEngineSnifferCrankEvent(), addEngineSnifferTdcEvent(), WaveChart::addEvent3(), incLogFileName(), prepareLogFileName(), and putTwoSymbolDecimal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ limitRateOfChange()

float limitRateOfChange ( float  newValue,
float  oldValue,
float  incrLimitPerSec,
float  decrLimitPerSec,
float  secsPassed 
)

Definition at line 170 of file efilib.cpp.

170 {
171 if (newValue >= oldValue)
172 return (incrLimitPerSec <= 0.0f) ? newValue : oldValue + std::min(newValue - oldValue, incrLimitPerSec * secsPassed);
173 return (decrLimitPerSec <= 0.0f) ? newValue : oldValue - std::min(oldValue - newValue, decrLimitPerSec * secsPassed);
174}

Referenced by EngineState::updateTChargeK().

Here is the caller graph for this function:

◆ motorolaMagicFromDbc()

int motorolaMagicFromDbc ( int  b,
int  length 
)

Definition at line 232 of file efilib.cpp.

232 {
233 // https://github.com/ebroecker/canmatrix/wiki/signal-Byteorder
234 // convert from lsb0 bit numbering to msb0 bit numbering (or msb0 to lsb0)
235 b = b - (b % 8) + 7 - (b % 8);
236 // convert from lsbit of signal data to msbit of signal data, when bit numbering is msb0
237 b = b + length - 1;
238 // convert from msbit of signal data to lsbit of signal data, when bit numbering is msb0
239 b = b - (b % 8) + 7 - (b % 8);
240 return b;
241}

Referenced by getBitRangeMoto(), and setBitRangeMoto().

Here is the caller graph for this function:

◆ operator+() [1/2]

constexpr Gpio operator+ ( Gpio  a,
size_t  b 
)
inlineconstexpr

Definition at line 94 of file efilib.h.

94 {
95 return (Gpio)((size_t)a + b);
96}

◆ operator+() [2/2]

constexpr Gpio operator+ ( size_t  a,
Gpio  b 
)
inlineconstexpr

Definition at line 98 of file efilib.h.

98 {
99 // addition is commutative, just use the other operator
100 return b + a;
101}

◆ operator-() [1/2]

constexpr size_t operator- ( Gpio  a,
Gpio  b 
)
inlineconstexpr

Definition at line 86 of file efilib.h.

86 {
87 return (size_t)a - (size_t)b;
88}

◆ operator-() [2/2]

constexpr Gpio operator- ( Gpio  a,
size_t  b 
)
inlineconstexpr

Definition at line 90 of file efilib.h.

90 {
91 return (Gpio)((size_t)a - b);
92}

◆ setBitRangeMoto()

void setBitRangeMoto ( uint8_t  data[],
int  totalBitIndex,
int  bitWidth,
int  value 
)

Definition at line 248 of file efilib.cpp.

248 {
249 const int b = motorolaMagicFromDbc(totalBitIndex, bitWidth);
250 return setBitRangeMsb(data, b, bitWidth, value);
251}
void setBitRangeMsb(uint8_t data[], const int totalBitIndex, const int bitWidth, const int value)
Definition efilib.cpp:216
Here is the call graph for this function:

◆ setBitRangeMsb()

void setBitRangeMsb ( uint8_t  data[],
int  totalBitIndex,
int  bitWidth,
int  value 
)

Definition at line 216 of file efilib.cpp.

216 {
217 int leftBitWidh = bitWidth;
218 const int byteIndex = totalBitIndex >> 3;
219 const int bitInByteIndex = totalBitIndex - byteIndex * 8;
220 if (bitInByteIndex + leftBitWidh > 8) {
221 const int bitsToHandleNow = 8 - bitInByteIndex;
222 setBitRangeMsb(data, (byteIndex - 1) * 8, leftBitWidh - bitsToHandleNow, value >> bitsToHandleNow);
223 leftBitWidh = bitsToHandleNow;
224 }
225 const int mask = (1 << leftBitWidh) - 1;
226 data[byteIndex] = data[byteIndex] & (~(mask << bitInByteIndex));
227 const int maskedValue = value & mask;
228 const int shiftedValue = maskedValue << bitInByteIndex;
229 data[byteIndex] = data[byteIndex] | shiftedValue;
230}

Referenced by setBitRangeMoto(), and setBitRangeMsb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SWAP_UINT16()

uint16_t SWAP_UINT16 ( uint16_t  x)
inline

◆ SWAP_UINT32()

uint32_t SWAP_UINT32 ( uint32_t  x)
inline

Definition at line 27 of file efilib.h.

28{
29 return (((x >> 24) & 0x000000ff) | ((x << 8) & 0x00ff0000) |
30 ((x >> 8) & 0x0000ff00) | ((x << 24) & 0xff000000));
31}

Referenced by TsChannelBase::crcAndWriteBuffer(), TunerStudio::handleCrc32Check(), TunerStudio::handleScatteredReadCommand(), CanStreamerState::receiveFrame(), tsProcessOne(), and TsChannelBase::writeCrcPacketLarge().

Here is the caller graph for this function:

Go to the source code of this file.