#pragma once
#include "protocol.hpp"
#include "node_interface_hardware.hpp"

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

typedef void (*onPackageRxCallback)(void * args, char *data, uint16_t len, GobotRPCTypes type, GobotRPCNumber number);

enum NODE_TYPE: uint8_t {
    NODE_TYPE_VACUM = 0xa1,
    NODE_TYPE_HEAD = 0xa2,
};

struct InfoData {
    uint32_t addr;
    NODE_TYPE type;
};

class GobotRPC_NI {
private:
    onPackageRxCallback onPackageRx;
    void *onPackageRxArgs;

    QueueHandle_t txQueue;
    QueueHandle_t rxQueue;
    TaskHandle_t rxTaskHandle;
    
    InfoData info;

    unsigned int core;

public:
    GobotRPC_NI(unsigned int core, QueueHandle_t txQueue, QueueHandle_t rxQueue, InfoData info);
    
    void registerOnPackageRxCallback(onPackageRxCallback callback, void *context);
    void sendPackage(char *data, size_t len, GobotRPCTypes type, GobotRPCNumber number);
    
    InfoData getInfo();

    void rxTask();
};