rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
efilib.cpp File Reference

Detailed Description

We cannot use stdlib because we do not have malloc - so, we have to implement these functions

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

Definition in file efilib.cpp.

Functions

const charboolToString (bool value)
 
float efiRound (float value, float precision)
 
charefiTrim (char *param)
 
static charltoa_internal (char *p, uint32_t num, unsigned radix)
 
static charitoa_signed (char *p, int num, unsigned radix)
 
charitoa10 (char *p, int num)
 
int efiPow10 (int param)
 
int djb2lowerCase (const char *str)
 
void printHistogram (Logging *logging, histogram_s *histogram)
 This function knows how to print a histogram_s summary.
 
float limitRateOfChange (float newValue, float oldValue, float incrLimitPerSec, float decrLimitPerSec, float secsPassed)
 
bool isPhaseInRange (float test, float current, float next)
 
static int getBitRangeCommon (const uint8_t data[], int bitIndex, int bitWidth, int secondByteOffset)
 
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[], const int totalBitIndex, const int bitWidth, const int value)
 
int motorolaMagicFromDbc (int b, int length)
 
int getBitRangeMoto (const uint8_t data[], int bitIndex, int bitWidth)
 
void setBitRangeMoto (uint8_t data[], const int totalBitIndex, const int bitWidth, const 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 
)
Parameters
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:

◆ getBitRangeCommon()

static int getBitRangeCommon ( const uint8_t  data[],
int  bitIndex,
int  bitWidth,
int  secondByteOffset 
)
static

Definition at line 195 of file efilib.cpp.

195 {
196 int byteIndex = bitIndex >> 3;
197 int shift = bitIndex - byteIndex * 8;
198 int value = data[byteIndex];
199 if (shift + bitWidth > 8) {
200 value = value + data[secondByteOffset + byteIndex] * 256;
201 }
202 int mask = (1 << bitWidth) - 1;
203 return (value >> shift) & mask;
204}

Referenced by getBitRangeLsb(), and getBitRangeMsb().

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:

◆ 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:

◆ itoa_signed()

static char * itoa_signed ( char p,
int  num,
unsigned  radix 
)
static
Returns
pointer at the end zero symbol after the digits

Definition at line 90 of file efilib.cpp.

90 {
91 if (num < 0) {
92 *p++ = '-';
93 char *end = ltoa_internal(p, -num, radix);
94 *end = 0;
95 return end;
96 }
97 char *end = ltoa_internal(p, num, radix);
98 *end = 0;
99 return end;
100}
static char * ltoa_internal(char *p, uint32_t num, unsigned radix)
Definition efilib.cpp:52

Referenced by itoa10().

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:

◆ ltoa_internal()

static char * ltoa_internal ( char p,
uint32_t  num,
unsigned  radix 
)
static

Definition at line 52 of file efilib.cpp.

52 {
53 constexpr int bufferLength = 10;
54
55 char buffer[bufferLength];
56
57 size_t idx = bufferLength - 1;
58
59 // First, we write from right-to-left so that we don't have to compute
60 // log(num)/log(radix)
61 do
62 {
63 auto digit = num % radix;
64
65 // Digits 0-9 -> '0'-'9'
66 // Digits 10-15 -> 'a'-'f'
67 char c = digit < 10
68 ? digit + '0'
69 : digit + 'a' - 10;
70
71 // Write this digit in to the buffer
72 buffer[idx] = c;
73 idx--;
74 } while ((num /= radix) != 0);
75
76 idx++;
77
78 // Now, we copy characters in to place in the final buffer
79 while (idx < bufferLength)
80 {
81 *p++ = buffer[idx++];
82 }
83
84 return p;
85}
static BigBufferHandle buffer

Referenced by itoa_signed().

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:

◆ printHistogram()

void printHistogram ( Logging logging,
histogram_s histogram 
)

This function knows how to print a histogram_s summary.

Definition at line 150 of file efilib.cpp.

150 {
151#if EFI_HISTOGRAMS && ! EFI_UNIT_TEST
152 int report[5];
153 int len = hsReport(histogram, report);
154
155 logging->reset();
156 logging.append(PROTOCOL_MSG LOG_DELIMITER);
157 logging.appendPrintf("histogram %s *", histogram->name);
158 for (int i = 0; i < len; i++)
159 logging.appendPrintf("%d ", report[i]);
160 logging.appendPrintf("*");
161 logging.append(LOG_DELIMITER);
162 scheduleLogging(logging);
163#else
164 UNUSED(logging);
165 UNUSED(histogram);
166
167#endif /* EFI_HISTOGRAMS */
168}
void reset()
void appendPrintf(const char *fmt,...) __attribute__((format(printf
int hsReport(histogram_s *h, int *report)
Prepare histogram report.
UNUSED(samplingTimeSeconds)
void scheduleLogging(Logging *logging)
char name[16]
Definition histogram.h:28
Here is the call graph for this function:

◆ setBitRangeMoto()

void setBitRangeMoto ( uint8_t  data[],
const int  totalBitIndex,
const int  bitWidth,
const 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[],
const int  totalBitIndex,
const int  bitWidth,
const 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:

Go to the source code of this file.