#if 0
#include <Arduino.h>
#include <driver/gpio.h>
#include <driver/can.h>
#include <driver/adc.h>

#include <stdio.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "sdkconfig.h"

void setup()
{
    Serial.begin(115200);
    //---------------------Konfigurácia a Inštalácia--------------------------

    //Konfigurácia
    can_general_config_t g_config = CAN_GENERAL_CONFIG_DEFAULT(GPIO_NUM_21, GPIO_NUM_22, CAN_MODE_NORMAL);
    can_timing_config_t t_config = CAN_TIMING_CONFIG_500KBITS();
    can_filter_config_t f_config = CAN_FILTER_CONFIG_ACCEPT_ALL();

    //Inštalácia
    if (can_driver_install(&g_config, &t_config, &f_config) == ESP_OK) {
        printf("Driver installed\n");
    } else {
        printf("Failed to install driver\n");
        return;
    }

    //Štart CAN drivera
    if (can_start() == ESP_OK) {
        printf("Driver started\n");
    } else {
        printf("Failed to start driver\n");
        return;
    }
}

void loop()
{
    //--------------------Odoslanie správy-------------------------
    #if 0
    //Konfigurácia správy na odoslanie
    can_message_t message;
    message.identifier = 0xAAAA;
    message.extd = 1;
    message.data_length_code = 4;
    for (int i = 0; i < message.data_length_code; i++) {
        message.data[i] = 0;
    }

    //Zaradenie správy do rady
    if (can_transmit(&message, pdMS_TO_TICKS(1000)) == ESP_OK) {
        printf("Message queued for transmission\n");
    } else {
        printf("Failed to queue message for transmission\n");
    }
    #endif
    
    //--------------------------Prijatie správy--------------------------
    #if 0
    //Čakanie na prijatie správy
    can_message_t message;
    if (can_receive(&message, pdMS_TO_TICKS(10000)) == ESP_OK) {
        printf("Message received\n");
    } else {
        printf("Failed to receive message\n");
        return;
    }

    //Prečítanie správy
    if (message.extd) {
        printf("Message is in Extended Format\n");
    } else {
        printf("Message is in Standard Format\n");
    }
    printf("ID is %d\n", message.identifier);
    if (!(message.rtr)) {
        for (int i = 0; i < message.data_length_code; i++) {
            printf("Data byte %d = %d\n", i, message.data[i]);
        }
    }
    #endif
    
    //------------------Rekonfigurácia a Čítanie výstrah--------------------------
    #if 0
    //Rekonfigurovanie výstrah na detekovanie Error Passive a Bus-Off chybových stavov
    uint32_t alerts_to_enable = CAN_ALERT_ERR_PASS | CAN_ALERT_BUS_OFF;
    if (can_reconfigure_alerts(alerts_to_enable, NULL) == ESP_OK) {
        printf("Alerts reconfigured\n");
    } else {
        printf("Failed to reconfigure alerts");
    }

    //Blokovať, kým sa neobjaví výstraha
    uint32_t alerts_triggered;
    can_read_alerts(&alerts_triggered, portMAX_DELAY);
    #endif

    //---------------------Zastavenie a Odinštalácia drivera-------------------------------------
    #if 0
    //Zastavenie CAN drivera
    if (can_stop() == ESP_OK) {
        printf("Driver stopped\n");
    } else {
        printf("Failed to stop driver\n");
        return;
    }

    //Odinštalácia drivera
    if (can_driver_uninstall() == ESP_OK) {
        printf("Driver uninstalled\n");
    } else {
        printf("Failed to uninstall driver\n");
        return;
    }
    #endif
}


#endif