rusEFI
The most advanced open source ECU
Functions | Variables
knock_spectrogram.cpp File Reference

Detailed Description

Date
Feb 20, 2024
Author
Alexey Ershov, (c) 2023-2024

Definition in file knock_spectrogram.cpp.

Functions

static char compressToByte (const float &v, const float &min, const float &max)
 
void base64 (Logging &l, const float *data, size_t size, const float &min, const float &max)
 
void knockSpectorgramAddLine (float main_freq, float *data, size_t size)
 

Variables

static char PROTOCOL_KNOCK_SPECTROGRAMM_BUFFER[128] CCM_OPTIONAL
 
static Logging scLogging ("knock_spectrogram", PROTOCOL_KNOCK_SPECTROGRAMM_BUFFER, sizeof(PROTOCOL_KNOCK_SPECTROGRAMM_BUFFER))
 

Function Documentation

◆ base64()

void base64 ( Logging l,
const float *  data,
size_t  size,
const float &  min,
const float &  max 
)

Definition at line 27 of file knock_spectrogram.cpp.

27  {
28  static constexpr char encTable[] = {
29  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
30  'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
31  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
32  'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
33  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};
34 
35  size_t in_len = size;
36  size_t out_len = 4 * ((in_len + 2) / 3);
37  size_t i;
38 
39  l.appendChar((char)out_len);
40 
41  for (i = 0; in_len > 2 && i < in_len - 2; i += 3) {
42  l.appendChar(encTable[(compressToByte(data[i], min, max) >> 2) & 0x3F]);
43  l.appendChar(encTable[((compressToByte(data[i], min, max) & 0x3) << 4) |
44  ((int)(compressToByte(data[i + 1], min, max) & 0xF0) >> 4)]);
45  l.appendChar(encTable[((compressToByte(data[i + 1], min, max) & 0xF) << 2) |
46  ((int)(compressToByte(data[i + 2], min, max) & 0xC0) >> 6)]);
47  l.appendChar(encTable[compressToByte(data[i + 2], min, max) & 0x3F]);
48  }
49  if (i < in_len) {
50  l.appendChar(encTable[(compressToByte(data[i], min, max) >> 2) & 0x3F]);
51 
52  if (i == (in_len - 1)) {
53  l.appendChar(encTable[((compressToByte(data[i], min, max) & 0x3) << 4)]);
54  l.appendChar('=');
55  } else {
56  l.appendChar(encTable[((compressToByte(data[i], min, max) & 0x3) << 4) |
57  ((int)(compressToByte(data[i + 1], min, max) & 0xF0) >> 4)]);
58  l.appendChar(encTable[((compressToByte(data[i + 1], min, max) & 0xF) << 2)]);
59  }
60 
61  l.appendChar('=');
62  }
63 }
void appendChar(char c)
Definition: datalogging.h:40
static char compressToByte(const float &v, const float &min, const float &max)
composite packet size

Referenced by knockSpectorgramAddLine().

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

◆ compressToByte()

static char compressToByte ( const float &  v,
const float &  min,
const float &  max 
)
static

Definition at line 19 of file knock_spectrogram.cpp.

19  {
20  float vn = (v-min) / (max-min);
21  int iv =int((float)256 * vn);
22 
23  char compressed = (char)(iv-128);
24  return compressed;
25 }

Referenced by base64().

Here is the caller graph for this function:

◆ knockSpectorgramAddLine()

void knockSpectorgramAddLine ( float  main_freq,
float *  data,
size_t  size 
)

Definition at line 66 of file knock_spectrogram.cpp.

66  {
67 #if EFI_TEXT_LOGGING
68  if (scLogging.remainingSize() > size) {
69 
70  float min = 99999999999;
71  float max = -99999999999;
72  for(size_t i = 0; i < size; ++i) {
73  float v = data[i];
74  if(v < min) {
75  min = v;
76  }
77 
78  if(v > max) {
79  max = v;
80  }
81  }
82 
83  scLogging.reset();
84  scLogging.appendPrintf(PROTOCOL_KNOCK_SPECTROGRAMM LOG_DELIMITER);
85 
86  scLogging.appendFloat(main_freq, 2);
88 
89  scLogging.appendChar((char)size);
90 
91  base64(scLogging, data, size, min, max);
92 
93  scLogging.append(LOG_DELIMITER);
94 
96  }
97 
98 #endif /* EFI_TEXT_LOGGING */
99 }
void void appendFloat(float value, int precision)
Definition: datalogging.cpp:97
size_t remainingSize() const
Definition: datalogging.h:49
void reset()
void appendPrintf(const char *fmt,...) __attribute__((format(printf
Definition: datalogging.cpp:80
void base64(Logging &l, const float *data, size_t size, const float &min, const float &max)
static Logging scLogging("knock_spectrogram", PROTOCOL_KNOCK_SPECTROGRAMM_BUFFER, sizeof(PROTOCOL_KNOCK_SPECTROGRAMM_BUFFER))
void scheduleLogging(Logging *logging)

Referenced by processLastKnockEvent().

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

Variable Documentation

◆ CCM_OPTIONAL

char PROTOCOL_KNOCK_SPECTROGRAMM_BUFFER [128] CCM_OPTIONAL
static

Definition at line 16 of file knock_spectrogram.cpp.

◆ scLogging

Logging scLogging("knock_spectrogram", PROTOCOL_KNOCK_SPECTROGRAMM_BUFFER, sizeof(PROTOCOL_KNOCK_SPECTROGRAMM_BUFFER)) ( "knock_spectrogram"  ,
PROTOCOL_KNOCK_SPECTROGRAMM_BUFFER  ,
sizeof(PROTOCOL_KNOCK_SPECTROGRAMM_BUFFER)   
)
static

Referenced by knockSpectorgramAddLine().

Go to the source code of this file.