/*
 * kline.h
 *
 *  Created on: Aug 18, 2025
 *      Author: herli
 */

#ifndef INC_KLINE_H_
#define INC_KLINE_H_

#include "IKW1281Connection.h"

#define ECU_INIT_ADDRESS 0xF1

#define KLINE_GPIO_PORT GPIOA
#define KLINE_PIN       GPIO_PIN_9

extern uint8_t BitBang;

typedef struct {
    uint8_t dtc;     // Primary DTC byte
    uint8_t status;  // Status byte
    uint8_t extra;   // Third byte in the 3-byte header (kept for parity with C#)
} FaultCode;

extern ControllerInfo ReadEcuInfo(void);
int WakeUp(uint8_t controllerAddress, uint8_t evenParity);
void IdentifyEcu(void);
int ReadFaultCodes(FaultCode* outCodes, int maxCodes);
uint8_t ReadVoltage(uint16_t* volt);
extern void KLINE_THROW_NONALIVE_EXCEPTION(uint8_t id);
int  FaultCode_ToString(const FaultCode* fc, char* dst, int dst_len);

#endif /* INC_KLINE_H_ */
