Skip to content

RoboticsBrno/RB3201-RBProtocol-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

bd433ef · Dec 27, 2024
Nov 21, 2023
Jan 5, 2019
Jul 11, 2023
Dec 27, 2024
Nov 21, 2023
Apr 5, 2020
Jan 5, 2019
May 28, 2024
Jul 10, 2018
Jul 6, 2018
Jan 7, 2019
Dec 27, 2024
Jul 6, 2018
Jul 11, 2023

Repository files navigation

RbProtocol

A library faciliating communication with RbController Android app: https://play.google.com/store/apps/details?id=com.tassadar.rbcontroller

#include <esp_log.h>
#include <lwip/sockets.h>
#include <string.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <esp_system.h>

#include "rbprotocol.h"
#include "rbwebserver.h"

void onPktReceived(const std::string& command, rbjson::Object *pkt) {
    if(command == "joy") {
        printf("Joy: ");
        rbjson::Array *data = pkt->getArray("data");
        for(size_t i = 0; i < data->size(); ++i) {
            rbjson::Object *ax = data->getObject(i);
            printf("#%d %6lld %6lld | ", i, ax->getInt("x"), ax->getInt("y")); 
        }
        printf("\r");
    } else if(command == "fire") {
        printf("\n\nFIRE THE MISSILESS\n\n");
    }
}

extern "C" void app_main() {
    // Create web server, serves static files from the spiffs memory
    rb_web_start(80);
    
    rb::Protocol prot("Foo", "Bar", "The very best bar", &onPktReceived);
    prot.start();

    printf("Hello world!\n");

    int i = 0;
    while(true) {
        vTaskDelay(1000 / portTICK_PERIOD_MS);
        if(prot.is_possessed()) {
            prot.send_log("Tick #%d\n", i++);
        }
    }
}