/*
 * audi_immo.h
 *
 *  Created on: Sep 18, 2025
 *      Author: herli
 */

#ifndef IMMOBILISERS_AUDI_IMMO_H_
#define IMMOBILISERS_AUDI_IMMO_H_

#include <stdint.h>

/* Four 16-bit key parts exposed for CAN address replies.
   These are defined in audi_immo.c and can be referenced from can_db.c. */
extern volatile uint16_t audi_immo_key_part_0;  // default 0xE61A
extern volatile uint16_t audi_immo_key_part_1;  // default 0x2A66
extern volatile uint16_t audi_immo_key_part_2;  // default 0xFFE5
extern volatile uint16_t audi_immo_key_part_3;  // default 0xFC04

/* Optional: initialize to defaults (call once at boot if you like). */
void audi_immo_init(void);

/* Optional: simple setters/getters (handy if later loaded from flash/NVM). */
static inline void audi_immo_set_key_part(uint8_t idx, uint16_t v) {
    switch (idx) {
        case 0: audi_immo_key_part_0 = v; break;
        case 1: audi_immo_key_part_1 = v; break;
        case 2: audi_immo_key_part_2 = v; break;
        case 3: audi_immo_key_part_3 = v; break;
        default: break;
    }
}

static inline uint16_t audi_immo_get_key_part(uint8_t idx) {
    switch (idx) {
        case 0: return (uint16_t)audi_immo_key_part_0;
        case 1: return (uint16_t)audi_immo_key_part_1;
        case 2: return (uint16_t)audi_immo_key_part_2;
        case 3: return (uint16_t)audi_immo_key_part_3;
        default: return 0;
    }
}

#endif /* IMMOBILISERS_AUDI_IMMO_H_ */
