#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 pushPackage(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 appData = *((AppData *)pvParameters);
    GobotRPC_TI_Hardware_RP2040_I2C gobotrpc_ti_hardware(I2C_CORE_MASK, i2c0);

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

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