15 if (readThisTime == 0) {
28#define HONDA_K_BCM_STATUS_NIBBLE 0x0
29#define HONDA_K_BCM_REQ_NIBBLE 0x1
36 uint8_t statusByte1 = bufferIn[1];
38 uint8_t statusByte2 = bufferIn[2];
41 efiPrintf(
"honda status packet with 0x%02x 0x%02x state %d", statusByte1, statusByte2,
kAcRequestState);
45static SerialDriver*
const klDriver = &KLINE_SERIAL_DEVICE;
52 bool ignoreRecentTransmit =
false;
66 size_t len =
readWhileGives(serialSource, bufferIn,
sizeof(bufferIn));
75 efiPrintf(
"kline: got count 0x%02x", len);
77 for (
size_t i =0;i<len;i++) {
79 efiPrintf(
"kline: got 0x%02x", bufferIn[i]);
85 uint8_t low = bufferIn[0] & 0xF;
86 if (crc == bufferIn[len - 1]) {
88 efiPrintf(
"happy CRC 0x%02x", crc);
90 if (low == HONDA_K_BCM_STATUS_NIBBLE) {
94 if (low == HONDA_K_BCM_REQ_NIBBLE) {
96 efiPrintf(
"BCM request 0x%02x", bufferIn[0]);
100 }
else if (low == HONDA_K_BCM_STATUS_NIBBLE && bufferIn[4] ==
crc_hondak_calc(bufferIn, 4)) {
102 efiPrintf(
"hack for now, happy CRC 0x%02x", crc);
118 if (sendCounter % 30 == 0) {
128 efiPrintf(
"kline doSend");
130 int positiveCltWithHighishValueInCaseOfSensorIssue = maxI(1,
131#ifdef HW_HELLEN_HONDA
133 config->hondaKcltGaugeAdder
142 kvalues[3] = positiveCltWithHighishValueInCaseOfSensorIssue;
146 chnWrite(
klDriver, (
const uint8_t *)&crc, 1);
147 ignoreRecentTransmit =
true;
149 ignoreRecentTransmit =
false;
163 efiSetPadMode(
"K-Line UART RX", Gpio::KLINE_SERIAL_DEVICE_RX, PAL_MODE_ALTERNATE(TS_SERIAL_AF));
164 efiSetPadMode(
"K-Line UART TX", Gpio::KLINE_SERIAL_DEVICE_TX, PAL_MODE_ALTERNATE(TS_SERIAL_AF));
167 static SerialConfig cfg = {
171 .cr2 = USART_CR2_STOP1_BITS | USART_CR2_LINEN,
208 chThdCreateStatic(klThreadStack,
sizeof(klThreadStack), NORMALPRIO + 1,
kLineThread,
nullptr);
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
virtual SensorResult get() const =0
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
void addConsoleActionII(const char *token, VoidIntInt callback)
Register a console command with two Integer parameters.
uint8_t crc_hondak_calc(const uint8_t *data, size_t len)
engine_configuration_s & activeConfiguration
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
void efiSetPadUnused(brain_pin_e brainPin)
static THD_WORKING_AREA(klThreadStack, UTILITY_THREAD_STACK_SIZE)
static void handleHonda(uint8_t *bufferIn)
size_t readWhileGives(ByteSource source, uint8_t *buffer, size_t bufferSize)
static SerialDriver *const klDriver
static uint8_t kvalues[8]
size_t(* ByteSource)(uint8_t *, int)
static BigBufferHandle buffer