rusEFI
The most advanced open source ECU
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 char * boolToString (bool value)
 
float efiRound (float value, float precision)
 
char * efiTrim (char *param)
 
bool startsWith (const char *line, const char *prefix)
 
static char * ltoa_internal (char *p, uint32_t num, unsigned radix)
 
static char * itoa_signed (char *p, int num, unsigned radix)
 
char * itoa10 (char *p, int num)
 
int efiPow10 (int param)
 
int mytolower (const char c)
 
int djb2lowerCase (const char *str)
 
void printHistogram (Logging *logging, histogram_s *histogram)
 This function knows how to print a histogram_s summary. More...
 
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)
 

Function Documentation

◆ boolToString()

const char* boolToString ( bool  value)

◆ djb2lowerCase()

int djb2lowerCase ( const char *  str)

Definition at line 154 of file efilib.cpp.

154  {
155  unsigned long hash = 5381;
156  int c;
157 
158  while ( (c = *str++) ) {
159  c = TO_LOWER(c);
160  hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
161  }
162 
163  return hash;
164 }

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

Here is the caller graph for this function:

◆ efiPow10()

int efiPow10 ( int  param)

Definition at line 123 of file efilib.cpp.

123  {
124  switch (param) {
125  case 0:
126  return 1;
127  case 1:
128  return 10;
129  case 2:
130  return 100;
131  case 3:
132  return 1000;
133  case 4:
134  return 10000;
135  case 5:
136  return 100000;
137  case 6:
138  return 1000000;
139  case 7:
140  return 10000000;
141  case 8:
142  return 100000000;
143  }
144  return 10 * efiPow10(10 - 1);
145 }
int efiPow10(int param)
Definition: efilib.cpp:123
static tstrWifiInitParam param

Referenced by DisplayErrorCode().

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 33 of file efilib.cpp.

33  {
34  efiAssert(ObdCode::CUSTOM_ERR_ASSERT, precision != 0, "zero precision", NAN);
35  float a = round(value / precision);
36  return fixNegativeZero(a * precision);
37 }
@ 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 39 of file efilib.cpp.

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

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 214 of file efilib.cpp.

214  {
215  int byteIndex = bitIndex >> 3;
216  int shift = bitIndex - byteIndex * 8;
217  int value = data[byteIndex];
218  if (shift + bitWidth > 8) {
219  value = value + data[secondByteOffset + byteIndex] * 256;
220  }
221  int mask = (1 << bitWidth) - 1;
222  return (value >> shift) & mask;
223 }

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 226 of file efilib.cpp.

226  {
227  return getBitRangeCommon(data, bitIndex, bitWidth, 1);
228 }
static int getBitRangeCommon(const uint8_t data[], int bitIndex, int bitWidth, int secondByteOffset)
Definition: efilib.cpp:214

Referenced by processHyundai().

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

◆ getBitRangeMsb()

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

for instance DBC 8|16@0

Definition at line 231 of file efilib.cpp.

231  {
232  return getBitRangeCommon(data, bitIndex, bitWidth, -1);
233 }
Here is the call graph for this function:

◆ isPhaseInRange()

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

Definition at line 195 of file efilib.cpp.

195  {
196  bool afterCurrent = test >= current;
197  bool beforeNext = test < next;
198 
199  if (next > current) {
200  // we're not near the end of the cycle, comparison is simple
201  // 0 |------------------------| 720
202  // next current
203  return afterCurrent && beforeNext;
204  } else {
205  // we're near the end of the cycle so we have to check the wraparound
206  // 0 -----------| |------ 720
207  // next current
208  // Check whether test is after current (ie, between current tooth and end of cycle)
209  // or if test if before next (ie, between start of cycle and next tooth)
210  return afterCurrent || beforeNext;
211  }
212 }
union test_buffers test
Definition: test.c:50

Referenced by 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 119 of file efilib.cpp.

119  {
120  return itoa_signed(p, num, 10);
121 }
static char * itoa_signed(char *p, int num, unsigned radix)
Definition: efilib.cpp:102

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

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 102 of file efilib.cpp.

102  {
103  if (num < 0) {
104  *p++ = '-';
105  char *end = ltoa_internal(p, -num, radix);
106  *end = 0;
107  return end;
108  }
109  char *end = ltoa_internal(p, num, radix);
110  *end = 0;
111  return end;
112 }
static char * ltoa_internal(char *p, uint32_t num, unsigned radix)
Definition: efilib.cpp:64

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 189 of file efilib.cpp.

189  {
190  if (newValue >= oldValue)
191  return (incrLimitPerSec <= 0.0f) ? newValue : oldValue + minF(newValue - oldValue, incrLimitPerSec * secsPassed);
192  return (decrLimitPerSec <= 0.0f) ? newValue : oldValue - minF(oldValue - newValue, decrLimitPerSec * secsPassed);
193 }

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 64 of file efilib.cpp.

64  {
65  constexpr int bufferLength = 10;
66 
67  char buffer[bufferLength];
68 
69  size_t idx = bufferLength - 1;
70 
71  // First, we write from right-to-left so that we don't have to compute
72  // log(num)/log(radix)
73  do
74  {
75  auto digit = num % radix;
76 
77  // Digits 0-9 -> '0'-'9'
78  // Digits 10-15 -> 'a'-'f'
79  char c = digit < 10
80  ? digit + '0'
81  : digit + 'a' - 10;
82 
83  // Write this digit in to the buffer
84  buffer[idx] = c;
85  idx--;
86  } while ((num /= radix) != 0);
87 
88  idx++;
89 
90  // Now, we copy characters in to place in the final buffer
91  while (idx < bufferLength)
92  {
93  *p++ = buffer[idx++];
94  }
95 
96  return p;
97 }
static BigBufferHandle buffer

Referenced by itoa_signed().

Here is the caller graph for this function:

◆ mytolower()

int mytolower ( const char  c)

Definition at line 150 of file efilib.cpp.

150  {
151  return TO_LOWER(c);
152 }

Referenced by mystrncasecmp().

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 169 of file efilib.cpp.

169  {
170 #if EFI_HISTOGRAMS && ! EFI_UNIT_TEST
171  int report[5];
172  int len = hsReport(histogram, report);
173 
174  logging->reset();
175  logging.append(PROTOCOL_MSG LOG_DELIMITER);
176  logging.appendPrintf("histogram %s *", histogram->name);
177  for (int i = 0; i < len; i++)
178  logging.appendPrintf("%d ", report[i]);
179  logging.appendPrintf("*");
180  logging.append(LOG_DELIMITER);
181  scheduleLogging(logging);
182 #else
183  UNUSED(logging);
184  UNUSED(histogram);
185 
186 #endif /* EFI_HISTOGRAMS */
187 }
void appendPrintf(const char *fmt,...)
Definition: datalogging.cpp:80
void reset()
int hsReport(histogram_s *h, int *report)
Prepare histogram report.
Definition: histogram.cpp:116
UNUSED(samplingTimeSeconds)
void scheduleLogging(Logging *logging)
char name[16]
Definition: histogram.h:28
Here is the call graph for this function:

◆ startsWith()

bool startsWith ( const char *  line,
const char *  prefix 
)

Definition at line 51 of file efilib.cpp.

51  {
52  uint32_t len = efiStrlen(prefix);
53  if (efiStrlen(line) < len) {
54  return false;
55  }
56  for (uint32_t i = 0; i < len; i++) {
57  if (line[i] != prefix[i]) {
58  return false;
59  }
60  }
61  return true;
62 }

Go to the source code of this file.