auto-sync

This commit is contained in:
rusEfi 2014-09-13 21:02:41 -05:00
parent 2e75ad587d
commit 24fd721d9b
8 changed files with 27 additions and 20 deletions

View File

@ -88,7 +88,7 @@ static bool validateBuffer(Logging *logging, uint32_t extraLen, const char *text
void append(Logging *logging, const char *text) { void append(Logging *logging, const char *text) {
efiAssertVoid(text != NULL, "append NULL"); efiAssertVoid(text != NULL, "append NULL");
uint32_t extraLen = strlen(text); uint32_t extraLen = efiStrlen(text);
int isError = validateBuffer(logging, extraLen, text); int isError = validateBuffer(logging, extraLen, text);
if (isError) { if (isError) {
return; return;
@ -108,7 +108,7 @@ void appendFast(Logging *logging, const char *text) {
// c = *s++; // c = *s++;
// *logging->linePointer++ = c; // *logging->linePointer++ = c;
// } while (c != '\0'); // } while (c != '\0');
int extraLen = strlen(text); int extraLen = efiStrlen(text);
strcpy(logging->linePointer, text); strcpy(logging->linePointer, text);
logging->linePointer += extraLen; logging->linePointer += extraLen;
} }
@ -281,9 +281,9 @@ static void printWithLength(char *line) {
* When we work with actual hardware, it is faster to invoke 'chSequentialStreamWrite' for the * When we work with actual hardware, it is faster to invoke 'chSequentialStreamWrite' for the
* whole buffer then to invoke 'chSequentialStreamPut' once per character. * whole buffer then to invoke 'chSequentialStreamPut' once per character.
*/ */
int len = strlen(line); int len = efiStrlen(line);
strcpy(header, "line:"); strcpy(header, "line:");
char *p = header + strlen(header); char *p = header + efiStrlen(header);
p = itoa10(p, len); p = itoa10(p, len);
*p++ = ':'; *p++ = ':';
*p++ = '\0'; *p++ = '\0';
@ -365,11 +365,11 @@ void scheduleIntValue(Logging *logging, const char *msg, int value) {
void scheduleLogging(Logging *logging) { void scheduleLogging(Logging *logging) {
// this could be done without locking // this could be done without locking
int newLength = strlen(logging->buffer); int newLength = efiStrlen(logging->buffer);
bool alreadyLocked = lockOutputBuffer(); bool alreadyLocked = lockOutputBuffer();
// I hope this is fast enough to operate under sys lock // I hope this is fast enough to operate under sys lock
int curLength = strlen(pendingBuffer); int curLength = efiStrlen(pendingBuffer);
if (curLength + newLength >= DL_OUTPUT_BUFFER) { if (curLength + newLength >= DL_OUTPUT_BUFFER) {
/** /**
* if no one is consuming the data we have to drop it * if no one is consuming the data we have to drop it
@ -407,7 +407,7 @@ void printPending(void) {
pendingBuffer[0] = 0; // reset pending buffer pendingBuffer[0] = 0; // reset pending buffer
unlockOutputBuffer(); unlockOutputBuffer();
if (strlen(outputBuffer) > 0) { if (efiStrlen(outputBuffer) > 0) {
printWithLength(outputBuffer); printWithLength(outputBuffer);
} }
} }

View File

@ -23,7 +23,7 @@ extern engine_configuration_s *engineConfiguration;
#define NUMBER_OF_DIFFERENT_LINES 4 #define NUMBER_OF_DIFFERENT_LINES 4
char * appendStr(char *ptr, const char *suffix) { char * appendStr(char *ptr, const char *suffix) {
for (uint32_t i = 0; i < strlen(suffix); i++) { for (uint32_t i = 0; i < efiStrlen(suffix); i++) {
*ptr++ = suffix[i]; *ptr++ = suffix[i];
} }
return ptr; return ptr;

View File

@ -129,6 +129,6 @@ void configureMazdaProtegeLx(trigger_shape_s *s) {
// s->shaftPositionEventCount = 2 + 8; // s->shaftPositionEventCount = 2 + 8;
s->shaftPositionEventCount = 8; s->shaftPositionEventCount = s->getSize();
s->isSynchronizationNeeded = false; s->isSynchronizationNeeded = false;
} }

View File

@ -11,7 +11,6 @@ void configureFordAspireTriggerShape(trigger_shape_s * s) {
s->isSynchronizationNeeded = false; s->isSynchronizationNeeded = false;
s->reset(FOUR_STROKE_CAM_SENSOR); s->reset(FOUR_STROKE_CAM_SENSOR);
s->shaftPositionEventCount = 10;
float x = 121.90; float x = 121.90;
float y = 110.86; float y = 110.86;
@ -27,6 +26,8 @@ void configureFordAspireTriggerShape(trigger_shape_s * s) {
s->addEvent(x + 360 + y, T_SECONDARY, TV_HIGH); s->addEvent(x + 360 + y, T_SECONDARY, TV_HIGH);
s->addEvent(x + 540, T_SECONDARY, TV_LOW); s->addEvent(x + 540, T_SECONDARY, TV_LOW);
s->addEvent(720, T_PRIMARY, TV_LOW); s->addEvent(720, T_PRIMARY, TV_LOW);
s->shaftPositionEventCount = s->getSize();
} }
void initializeMitsubishi4g18(trigger_shape_s *s) { void initializeMitsubishi4g18(trigger_shape_s *s) {

View File

@ -49,9 +49,13 @@ float maxF(float i1, float i2) {
return i1 > i2 ? i1 : i2; return i1 > i2 ? i1 : i2;
} }
int efiStrlen(const char *param) {
return strlen(param);
}
int indexOf(const char *string, char ch) { int indexOf(const char *string, char ch) {
// todo: there should be a standard function for this // todo: there should be a standard function for this
int len = strlen(string); int len = efiStrlen(string);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
if (string[i] == ch) { if (string[i] == ch) {
return i; return i;

View File

@ -33,6 +33,7 @@ extern "C"
const char * boolToString(bool value); const char * boolToString(bool value);
int efiStrlen(const char *param);
int indexOf(const char *string, char ch); int indexOf(const char *string, char ch);
float atoff(const char *string); float atoff(const char *string);
int atoi(const char *string); int atoi(const char *string);

View File

@ -82,9 +82,9 @@ int histogramGetIndex(int64_t value) {
* @brief Reset histogram_s to orignal state * @brief Reset histogram_s to orignal state
*/ */
void initHistogram(histogram_s *h, const char *name) { void initHistogram(histogram_s *h, const char *name) {
if(strlen(name) > sizeof(h->name) - 1) { if (efiStrlen(name) > sizeof(h->name) - 1) {
firmwareError("Histogram name [%s] too long", name); firmwareError("Histogram name [%s] too long", name);
} }
strcpy(h->name, name); strcpy(h->name, name);
h->total_value = 0; h->total_value = 0;
h->total_count = 0; h->total_count = 0;
@ -99,7 +99,7 @@ void hsAdd(histogram_s *h, int64_t value) {
int count = 1; int count = 1;
h->total_value += value; h->total_value += value;
h->total_count += count; h->total_count += count;
efiAssertVoid(index < BOUND_LENGTH, "histogram issue" ); efiAssertVoid(index < BOUND_LENGTH, "histogram issue");
h->values[index] += count; h->values[index] += count;
} }
@ -112,18 +112,18 @@ int hsReport(histogram_s *h, int* report) {
int index = 0; int index = 0;
if (h->total_count <= 5) { if (h->total_count <= 5) {
for (int j = 0; j < BOUND_LENGTH; j++) { for (int j = 0; j < BOUND_LENGTH; j++) {
for (int k = 0; k < h->values[j]; k++) { for (int k = 0; k < h->values[j]; k++) {
report[index++] = (bounds[j] + bounds[j + 1]) / 2; report[index++] = (bounds[j] + bounds[j + 1]) / 2;
} }
} }
return index; return index;
} }
int minIndex = 0; int minIndex = 0;
while (h->values[minIndex] == 0) { while (h->values[minIndex] == 0) {
minIndex++; minIndex++;
} }
report[index++] = h->values[minIndex]; report[index++] = h->values[minIndex];
int64_t acc = 0; int64_t acc = 0;
@ -133,10 +133,10 @@ int hsReport(histogram_s *h, int* report) {
// Always drop at least 1 'non-confident' sample... // Always drop at least 1 'non-confident' sample...
if (k == 0) { if (k == 0) {
k = 1; k = 1;
} }
if (k == h->total_count) { if (k == h->total_count) {
k = h->total_count - 1; k = h->total_count - 1;
} }
// 'k' is desired number of samples. // 'k' is desired number of samples.
while (acc + h->values[minIndex] < k) while (acc + h->values[minIndex] < k)
acc += h->values[minIndex++]; acc += h->values[minIndex++];
@ -148,7 +148,7 @@ int hsReport(histogram_s *h, int* report) {
float d = bounds[minIndex]; float d = bounds[minIndex];
if (acc != k) if (acc != k)
d += (bounds[minIndex + 1] - 1 - bounds[minIndex]) * (k - acc) / h->values[minIndex]; d += (bounds[minIndex + 1] - 1 - bounds[minIndex]) * (k - acc) / h->values[minIndex];
report[index++] = (int)d; report[index++] = (int) d;
} }
int maxIndex = BOUND_LENGTH - 1; int maxIndex = BOUND_LENGTH - 1;

View File

@ -19,6 +19,7 @@
#define EFI_SUPPORT_NISSAN_PRIMERA TRUE #define EFI_SUPPORT_NISSAN_PRIMERA TRUE
#define EFI_SIGNAL_EXECUTOR_ONE_TIMER TRUE #define EFI_SIGNAL_EXECUTOR_ONE_TIMER TRUE
#define EFI_SIGNAL_EXECUTOR_SLEEP FALSE
#define EFI_SHAFT_POSITION_INPUT TRUE #define EFI_SHAFT_POSITION_INPUT TRUE
#define EFI_ENGINE_CONTROL TRUE #define EFI_ENGINE_CONTROL TRUE