Implemented RX on Node

This commit is contained in:
AlexanderHD27
2025-01-06 03:28:10 +01:00
parent caf7586b5b
commit 1e317adedd
29 changed files with 1646 additions and 2298 deletions

View File

@@ -1,5 +1,5 @@
#include "vacum.hpp"
#include "pinConfig.hpp"
#include "pinConfigNode.hpp"
#include "FreeRTOS.h"
#include "task.h"
@@ -17,13 +17,14 @@ void vButtonTaskFn(void *pvParameters) {
vacumControl->buttonTaskFn();
}
VacumControl::VacumControl() {
VacumControl::VacumControl(uint coreMask) {
this->coreMask = coreMask;
initVacumPins();
state = false;
vacumMutex = xSemaphoreCreateMutex();
interruptionSemaphore = xSemaphoreCreateBinary();
xTaskCreate(vInterruptionTaskFn, "Interruption Task", 1024, this, 3, &interruptionTask);
xTaskCreate(vButtonTaskFn, "Button Task", 1024, this, 2, &buttonTask);
xTaskCreateAffinitySet(vInterruptionTaskFn, "Interruption Task", 1024, this, 3, coreMask, &interruptionTask);
xTaskCreateAffinitySet(vButtonTaskFn, "Button Task", 1024, this, 2, coreMask, &buttonTask);
}
void VacumControl::initVacumPins() {

View File

@@ -1,4 +1,5 @@
#include <stdio.h>
#include <string.h>
#include "pico/stdlib.h"
#include "vacum.hpp"
@@ -6,22 +7,88 @@
#include "FreeRTOSConfig.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
void vTaskFunction(void *pvParameters) {
while (true) {
printf("Button: %d\n", gpio_get(BUTTON_PIN));
vTaskDelay(pdMS_TO_TICKS(1000));
#include "hardware/i2c.h"
#include "pinConfigNode.hpp"
#include "node_interface_hardware.hpp"
#include "node_interface.hpp"
#include "protocol.hpp"
struct AppData {
xQueueHandle txQueue;
xQueueHandle rxQueue;
VacumControl * vacumControl;
GobotRPC_NI * gobotrpc_ni;
};
AppData g_appData;
void onRxPackage(void * args, char *data, uint16_t len, GobotRPCTypes type, GobotRPCNumber number) {
AppData * appData = (AppData *) args;
char txBuffer[32];
switch (number) {
case GobotRPCNumber::VACUM: {
GobotRPCPackage_Req_Vacum * pkg = (GobotRPCPackage_Req_Vacum *) data;
appData->vacumControl->setState(pkg->enable);
g_appData.gobotrpc_ni->sendPackage(txBuffer, 0, GobotRPCTypes::RESPONSE, GobotRPCNumber::VACUM);
break;
}
default: {
break;
}
}
}
void core1_main(void *pvParameters) {
AppData * appData = (AppData *) pvParameters;
GobotRPC_NI_Hardware_RP2040_I2C gobotrpc_ni_hardware(
appData->txQueue, appData->rxQueue, CORE_MASK_VACUM,
i2c0, 0x21, GORPC_SDA_PIN, GORPC_SCL_PIN, GORPC_INT_PIN
);
while (true) {
gpio_put(LED2_PIN, 0);
vTaskDelay(500 / portTICK_PERIOD_MS);
gpio_put(LED2_PIN, 1);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
TaskHandle_t xCore0TaskHandle = NULL;
TaskHandle_t xCore1TaskHandle = NULL;
int main() {
stdio_init_all();
printf("Hello, world!\n");
VacumControl vacumControl;
gpio_init(LED1_PIN);
gpio_set_dir(LED1_PIN, GPIO_OUT);
gpio_put(LED1_PIN, 1);
gpio_init(LED2_PIN);
gpio_set_dir(LED2_PIN, GPIO_OUT);
gpio_put(LED2_PIN, 1);
g_appData.txQueue = xQueueCreate(16, sizeof(GobotRPC_NI_Package_Transport));
g_appData.rxQueue = xQueueCreate(16, sizeof(GobotRPC_NI_Package_Transport));
VacumControl vacumControl = VacumControl(CORE_MASK_VACUM);
vacumControl.setState(false);
xTaskCreate(vTaskFunction, "Main Task", 1024, NULL, tskIDLE_PRIORITY, NULL);
g_appData.vacumControl = &vacumControl;
GobotRPC_NI gobotrpc_ni(CORE_MASK_VACUM, g_appData.txQueue, g_appData.rxQueue);
gobotrpc_ni.registerOnPackageRxCallback(onRxPackage, &g_appData);
g_appData.gobotrpc_ni = &gobotrpc_ni;
xTaskCreateAffinitySet(
core1_main, "Core 1 Main", 2048, &g_appData, 1, CORE_MASK_VACUM, &xCore1TaskHandle
);
vTaskStartScheduler();
while (true) {