mirror of https://github.com/rusefi/rusefi.git
rusEFI needs K-line firmware support #3248
something seems to not be working right, test time
This commit is contained in:
parent
21d38c60ed
commit
5ff4db0d65
|
@ -3,6 +3,19 @@
|
|||
#include "hellen_meta.h"
|
||||
#include "crc8hondak.h"
|
||||
|
||||
size_t readWhileGives(ByteSource source, uint8_t *buffer, int bufferSize) {
|
||||
size_t totalBytes = 0;
|
||||
while (totalBytes < bufferSize) {
|
||||
int readThisTime = source(&buffer[totalBytes], bufferSize - totalBytes);
|
||||
if (readThisTime == 0) {
|
||||
// looks like idle gap
|
||||
break;
|
||||
}
|
||||
totalBytes += readThisTime;
|
||||
}
|
||||
return totalBytes;
|
||||
}
|
||||
|
||||
#ifdef EFI_KLINE
|
||||
static SerialDriver* const klDriver = &KLINE_SERIAL_DEVICE;
|
||||
static THD_WORKING_AREA(klThreadStack, UTILITY_THREAD_STACK_SIZE);
|
||||
|
@ -18,17 +31,13 @@ void kLineThread(void*) {
|
|||
*/
|
||||
|
||||
uint8_t bufferIn[16];
|
||||
size_t totalBytes = 0;
|
||||
// a bit of a busy read open question if this would affect performance?
|
||||
// on 2003 Honda for instance the bus seems to be 70%-ish busy. 9600 baud is 1.04ms per byte, a bit below 1kHz
|
||||
while (totalBytes < sizeof(bufferIn)) {
|
||||
int readThisTime = chnReadTimeout(klDriver, &bufferIn[totalBytes], sizeof(bufferIn) - totalBytes, KLINE_READ_TIMEOUT);
|
||||
if (readThisTime == 0) {
|
||||
// looks like idle gap
|
||||
break;
|
||||
}
|
||||
totalBytes += readThisTime;
|
||||
}
|
||||
ByteSource serialSource = [] (uint8_t * buffer, int maxSize) {
|
||||
return chnReadTimeout(klDriver,buffer, maxSize, KLINE_READ_TIMEOUT);
|
||||
};
|
||||
int totalBytes = readWhileGives(serialSource, bufferIn, sizeof(serialSource));
|
||||
|
||||
// to begin with just write byte to console
|
||||
if (totalBytes > 0) {
|
||||
efiPrintf("kline: got count 0x%02x", totalBytes);
|
||||
|
|
|
@ -21,3 +21,6 @@ void initKLine();
|
|||
/* Stop/Start for config update */
|
||||
void startKLine();
|
||||
void stopKLine();
|
||||
|
||||
typedef size_t (*ByteSource)(uint8_t *, int);
|
||||
size_t readWhileGives(ByteSource source, uint8_t *buffer, int bufferSize);
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include "kline.h"
|
||||
|
||||
static int sourceTotal = 11;
|
||||
|
||||
TEST(kline, source) {
|
||||
ByteSource source = [] (uint8_t * buffer, int maxSize) {
|
||||
if (sourceTotal == 0)
|
||||
return (size_t)0;
|
||||
buffer[0] = sourceTotal;
|
||||
sourceTotal--;
|
||||
return (size_t)1;
|
||||
};
|
||||
|
||||
uint8_t b[16];
|
||||
|
||||
// there is a bit of pointer logic there so test coverage it is!
|
||||
int actual = readWhileGives(source, b, sizeof(b));
|
||||
ASSERT_EQ(actual, 11);
|
||||
ASSERT_EQ(b[0], 11);
|
||||
ASSERT_EQ(b[7], 4);
|
||||
}
|
|
@ -55,6 +55,7 @@ TESTS_SRC_CPP = \
|
|||
tests/test_start_stop.cpp \
|
||||
tests/test_hardware_reinit.cpp \
|
||||
tests/test_ion.cpp \
|
||||
tests/test_kline_bytes_aggregator.cpp \
|
||||
tests/test_hip9011.cpp \
|
||||
tests/test_engine_math.cpp \
|
||||
tests/test_fasterEngineSpinningUp.cpp \
|
||||
|
|
Loading…
Reference in New Issue