did some random stuff
This commit is contained in:
parent
4392fd99be
commit
49b3c85560
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "rx_esp2866/lib/cli"]
|
||||||
|
path = rx_esp2866/lib/cli
|
||||||
|
url = git@gitea.finnvanreenen.nl:HR/EMS31_submodules.git
|
||||||
1
rx_esp2866/lib/cli
Submodule
1
rx_esp2866/lib/cli
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 34f830bd1d23379f58b956f28cd6cd0171d46957
|
||||||
233
rx_esp2866/src/boats.c
Normal file
233
rx_esp2866/src/boats.c
Normal file
@ -0,0 +1,233 @@
|
|||||||
|
#include "FIFOBuffChar.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
bool FIFOBuffChar_put(FIFOBuffChar_t *fifo, char i) // Change the function parameters to match the declaration
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
if ((fifo->LastEl_p == NULL) && (fifo->FirstEl_p == NULL))
|
||||||
|
{
|
||||||
|
// buffer is empty. add first element
|
||||||
|
fifo->FirstEl_p = malloc(sizeof(FIFOBuffChar_element_t));
|
||||||
|
if (fifo->FirstEl_p != NULL)
|
||||||
|
{
|
||||||
|
fifo->FirstEl_p->character = i; // "value" to "character"
|
||||||
|
fifo->FirstEl_p->nextElement = NULL;
|
||||||
|
|
||||||
|
fifo->LastEl_p = fifo->FirstEl_p;
|
||||||
|
fifo->size = 1;
|
||||||
|
ok = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fifo->full = true;
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ((fifo->LastEl_p != NULL) && (fifo->FirstEl_p != NULL))
|
||||||
|
{
|
||||||
|
// add element to exsiting buffer
|
||||||
|
FIFOBuffChar_element_t* el = malloc(sizeof(FIFOBuffChar_element_t));
|
||||||
|
if (el != NULL)
|
||||||
|
{
|
||||||
|
el->character = i; // "value" to "character"
|
||||||
|
el->nextElement = NULL;
|
||||||
|
fifo->LastEl_p->nextElement = el;
|
||||||
|
fifo->LastEl_p = el;
|
||||||
|
fifo->size++;
|
||||||
|
ok = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fifo->full = true;
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// buffer is unhealthy. try to clear it and reinit
|
||||||
|
if (fifo->FirstEl_p == NULL)
|
||||||
|
{
|
||||||
|
printf("buffer_dyn - buffer_put(): ERROR: first pointer is NULL\n");
|
||||||
|
}
|
||||||
|
//TODO: this while loop is unsave
|
||||||
|
while (fifo->FirstEl_p != NULL)
|
||||||
|
{
|
||||||
|
FIFOBuffChar_get(fifo, NULL); // Replace buffer_get with FIFOBuffChar_get
|
||||||
|
}
|
||||||
|
if (fifo->LastEl_p != NULL)
|
||||||
|
{
|
||||||
|
free(fifo->LastEl_p);
|
||||||
|
fifo->LastEl_p = NULL;
|
||||||
|
printf("buffer_dyn - buffer_put(): ERROR: last pointer is NULL\n");
|
||||||
|
}
|
||||||
|
FIFOBuffChar_put(fifo, i); // Replace buffer_put with FIFOBuffChar_put
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FIFOBuffChar_get(FIFOBuffChar_t *fifo, char *p) // Change the function parameters to match the declaration
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
if (fifo->FirstEl_p != NULL)
|
||||||
|
{
|
||||||
|
*p = fifo->FirstEl_p->character; // "value" to "character"
|
||||||
|
FIFOBuffChar_element_t* next = fifo->FirstEl_p->nextElement;
|
||||||
|
free(fifo->FirstEl_p);
|
||||||
|
// fifo->FirstEl_p = NULL;
|
||||||
|
fifo->size--;
|
||||||
|
fifo->full = false;
|
||||||
|
if (next == NULL)
|
||||||
|
{
|
||||||
|
// this was the last element in the buffer
|
||||||
|
if (fifo->LastEl_p == fifo->FirstEl_p)
|
||||||
|
{
|
||||||
|
// clear last element becouse it's the same
|
||||||
|
fifo->LastEl_p = NULL;
|
||||||
|
fifo->FirstEl_p = NULL;
|
||||||
|
fifo->size = 0;
|
||||||
|
ok = true;
|
||||||
|
}
|
||||||
|
else if (fifo->LastEl_p != NULL)
|
||||||
|
{
|
||||||
|
// buffer chain is broken; skip to last element
|
||||||
|
fifo->FirstEl_p = fifo->LastEl_p;
|
||||||
|
printf("buffer_dyn - buffer_get(): ERROR: next element is NULL, but it's not the last element. skip to last element\n");
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// somehow the last element is NULL
|
||||||
|
fifo->size = 0;
|
||||||
|
fifo->FirstEl_p = NULL;
|
||||||
|
printf("buffer_dyn - buffer_get(): ERROR: last element pointer is NULL\n");
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// set first element pointer to next element
|
||||||
|
fifo->FirstEl_p = next;
|
||||||
|
ok = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FIFOBuffChar_pop(FIFOBuffChar_t *fifo)
|
||||||
|
{
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
switch (fifo->size){
|
||||||
|
case 0: // buffer is empty
|
||||||
|
ok = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1: // singel item in buffer
|
||||||
|
// make buffer empty
|
||||||
|
free(fifo->FirstEl_p);
|
||||||
|
fifo->FirstEl_p = NULL;
|
||||||
|
fifo->LastEl_p = NULL;
|
||||||
|
fifo->size = 0;
|
||||||
|
ok = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: // buffer is at least 2 element big
|
||||||
|
// find the second last element
|
||||||
|
{
|
||||||
|
FIFOBuffChar_element_t* secondLastEl = fifo->FirstEl_p;
|
||||||
|
while (
|
||||||
|
secondLastEl->nextElement != fifo->LastEl_p
|
||||||
|
&& ((FIFOBuffChar_element_t*)secondLastEl->nextElement)->nextElement != NULL
|
||||||
|
){
|
||||||
|
secondLastEl = secondLastEl->nextElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove last element
|
||||||
|
free(fifo->LastEl_p);
|
||||||
|
|
||||||
|
// update chain
|
||||||
|
secondLastEl->nextElement = NULL;
|
||||||
|
fifo->LastEl_p = secondLastEl;
|
||||||
|
fifo->size--;
|
||||||
|
ok = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FIFOBuffChar_is_full(FIFOBuffChar_t *fifo)
|
||||||
|
{
|
||||||
|
return fifo->full;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FIFOBuffChar_is_empty(FIFOBuffChar_t *fifo)
|
||||||
|
{
|
||||||
|
// printf("empty %s: %s; fifo->LastEl_p = %i; fifo->FirstEl_p = %i\n",
|
||||||
|
// (fifo->LastEl_p == NULL) && (fifo->FirstEl_p == NULL) ? "true" : "false",
|
||||||
|
// (fifo->LastEl_p == fifo->FirstEl_p) ? "same" : "diff",
|
||||||
|
// (int) fifo->LastEl_p,
|
||||||
|
// (int) fifo->FirstEl_p);
|
||||||
|
return ((fifo->LastEl_p == NULL) && (fifo->FirstEl_p == NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FIFOBuffChar_t* FIFOBuffChar_create(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Allocate memory for a new FIFOBuffChar_t
|
||||||
|
FIFOBuffChar_t* fifo = malloc(sizeof(FIFOBuffChar_t));
|
||||||
|
|
||||||
|
if (fifo == NULL) {
|
||||||
|
// Memory allocation failed
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the FIFO buffer
|
||||||
|
// Point the last element to the first one
|
||||||
|
// Initialize other fields of the FIFOBuffChar_t struct
|
||||||
|
|
||||||
|
fifo->FirstEl_p = NULL;
|
||||||
|
fifo->LastEl_p = NULL;
|
||||||
|
fifo->size = 0;
|
||||||
|
fifo->full = false;
|
||||||
|
|
||||||
|
return fifo;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FIFOBuffChar_delete(FIFOBuffChar_t *fifo)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Check if the buffer is already empty
|
||||||
|
if (fifo->FirstEl_p == NULL)
|
||||||
|
{
|
||||||
|
// Delete all elements in the buffer
|
||||||
|
FIFOBuffChar_element_t* currentElement = fifo->FirstEl_p;
|
||||||
|
while (currentElement != NULL)
|
||||||
|
{
|
||||||
|
FIFOBuffChar_element_t* nextElement = currentElement->nextElement;
|
||||||
|
free(currentElement);
|
||||||
|
currentElement = nextElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(fifo);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int FIFOBuffChar_getSize(FIFOBuffChar_t *fifo)
|
||||||
|
{
|
||||||
|
return fifo->size;
|
||||||
|
}
|
||||||
51
rx_esp2866/src/boats.h
Normal file
51
rx_esp2866/src/boats.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#ifndef BOATS_h
|
||||||
|
#define BOATS_h
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef struct Boats_s {
|
||||||
|
uint16_t id;
|
||||||
|
char* name;
|
||||||
|
bool avaliable;
|
||||||
|
bool locked;
|
||||||
|
} Boats_t;
|
||||||
|
|
||||||
|
typedef struct BoatsDB_el_s {
|
||||||
|
Boats_t boat;
|
||||||
|
void* nextEl;
|
||||||
|
} BoatsDB_el_t;
|
||||||
|
|
||||||
|
// defines all vars for the buffer to operate
|
||||||
|
typedef struct BoatsDB_s {
|
||||||
|
BoatsDB_el_t* FirstEl_p;
|
||||||
|
BoatsDB_el_t* LastEl_p;
|
||||||
|
unsigned char size;
|
||||||
|
bool full;
|
||||||
|
} BoatsDB_t;
|
||||||
|
|
||||||
|
// create a fifo buffer and initilizes it with zeros
|
||||||
|
extern BoatsDB_t* BoatsDB_init();
|
||||||
|
|
||||||
|
// destroy a fifo buffer (free up its space)
|
||||||
|
// returns true on success or false otherways
|
||||||
|
extern bool BoatsDB_deinit(BoatsDB_t* fifo);
|
||||||
|
|
||||||
|
// put value i in buffer if there is still memory avaliable
|
||||||
|
// returns true on success or false otherways
|
||||||
|
extern bool BoatsDB_put(BoatsDB_t *fifo, char i);
|
||||||
|
|
||||||
|
// get value from buffer and writes it to *p if buffer not empty
|
||||||
|
// returns true on success or false otherways
|
||||||
|
extern bool BoatsDB_getById(BoatsDB_t *fifo, uint16_t id, );
|
||||||
|
|
||||||
|
// returns false if last put fails to gain memory and no get is called afterwards or true otherwise
|
||||||
|
extern bool BoatsDB_is_full(BoatsDB_t *fifo);
|
||||||
|
|
||||||
|
// returns true when buffer is empty or false otherways
|
||||||
|
extern bool BoatsDB_is_empty(BoatsDB_t *fifo);
|
||||||
|
|
||||||
|
extern unsigned int BoatsDB_getSize(BoatsDB_t *fifo);
|
||||||
|
|
||||||
|
#endif
|
||||||
23
rx_esp2866/src/commands.c
Normal file
23
rx_esp2866/src/commands.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
#include "../lib/cli/CMDList/CMDList.h"
|
||||||
|
|
||||||
|
#include "commands.h"
|
||||||
|
|
||||||
|
int boads(char* line)
|
||||||
|
{
|
||||||
|
// do stuff
|
||||||
|
}
|
||||||
|
|
||||||
|
const CMD_t Commands[] = {
|
||||||
|
{ "ctrl", &test }
|
||||||
|
};
|
||||||
|
|
||||||
|
CMDList_t* getCMDList()
|
||||||
|
{
|
||||||
|
CMDList_t* list = CMDList_init();
|
||||||
|
for (int i = sizeof(Commands) / sizeof(CMD_t); i >= 0; i--)
|
||||||
|
{
|
||||||
|
CMDList_add(list, (CMD_t*)&Commands[i], Commands[i].cmd);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
8
rx_esp2866/src/commands.h
Normal file
8
rx_esp2866/src/commands.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef COMMAND_H
|
||||||
|
#define COMMAND_H
|
||||||
|
|
||||||
|
#include "../lib/cli/CMDList/CMDList.h"
|
||||||
|
|
||||||
|
extern CMDList_t* getCMDList();
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
x
Reference in New Issue
Block a user