#include "main.hpp"
#include "transmission_interface.hpp"

#include "FreeRTOSConfig.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"

#include "pinConfig.hpp"

extern AppData appData;

void pullPackageCB(GoRPCPackage_Transport * dest, void *args) {
    QueueHandle_t queue = appData.txQueue;
    xQueueReceive(queue, dest, portMAX_DELAY);
}

void pushPackageCB(GoRPCPackage_Transport * src, void *args) {
    QueueHandle_t queue = appData.rxQueue;
    xQueueSend(queue, src, portMAX_DELAY);
}

void pushCIInstruction(CI_Instruction_Transport * src, void *args) {
    QueueHandle_t queue = appData.ciInstructionQueue;
    xQueueSend(queue, src, portMAX_DELAY);
}

void main_core2(void * pvParameters) {
    AppData appData1 = *(AppData *)pvParameters;

    GobotRPC_TI_Hardware_RP2040_I2C gobotrpc_ti_hardware(UART_CORE_MASK, i2c0, appData1.ciInstructionReverseQueue);
    //gobotrpc_ti_hardware.setAddrMap(0x21, 0);

    gobotrpc_ti_hardware.registerPullPackageCB(pullPackageCB, appData.txQueue);
    gobotrpc_ti_hardware.registerPushPackageCB(pushPackageCB, appData.rxQueue);
    gobotrpc_ti_hardware.registerPushCIInstructionCB(pushCIInstruction, appData.ciInstructionQueue);

    gobotrpc_ti_hardware.raiseInfoReset();

    while(1) {
        vTaskDelay(pdMS_TO_TICKS(10000));
    }
}
