prepair the use of the cli lib
This commit is contained in:
parent
65ffc134fa
commit
f4375bf5b8
@ -1 +1 @@
|
|||||||
Subproject commit 34f830bd1d23379f58b956f28cd6cd0171d46957
|
Subproject commit 09ae51070be1be5ebf6717649460510dd744cf65
|
||||||
@ -3,13 +3,13 @@
|
|||||||
|
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
|
|
||||||
int boads(char* line)
|
int contrl(char* line)
|
||||||
{
|
{
|
||||||
// do stuff
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const CMD_t Commands[] = {
|
const CMD_t Commands[] = {
|
||||||
{ "ctrl", &test }
|
{ "ctrl", &contrl }
|
||||||
};
|
};
|
||||||
|
|
||||||
CMDList_t* getCMDList()
|
CMDList_t* getCMDList()
|
||||||
|
|||||||
@ -1,25 +1,34 @@
|
|||||||
#include <arduino.h>
|
#include <arduino.h>
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
|
|
||||||
#define WIFI_SSID "MBCBootjes"
|
#include "../lib/cli/CLI/CLI.h"
|
||||||
#define WIFI_PASS "hetgrootedok"
|
#include "../lib/cli/CMDList/CMDList.h"
|
||||||
|
|
||||||
|
#include "commands.h"
|
||||||
|
|
||||||
|
#define WIFI_SSID "UPC46273"
|
||||||
|
#define WIFI_PASS "SPHZHKRY"
|
||||||
#define UDP_PORT 1234
|
#define UDP_PORT 1234
|
||||||
|
|
||||||
#define BOAT_ID 1
|
#define BOAT_ID 1
|
||||||
|
|
||||||
WiFiUDP UDP;
|
WiFiUDP UDP;
|
||||||
#define RX_BUFFER_SIZE 255
|
|
||||||
char rxBuffer[RX_BUFFER_SIZE];
|
bool running = true;
|
||||||
char lineBuffer[RX_BUFFER_SIZE];
|
CMDList_t* cmdList;
|
||||||
uint8_t rxBuffer_readPointer = 0;
|
|
||||||
uint8_t rxBuffer_lineStart = 0;
|
|
||||||
uint8_t rxBuffer_lineEnd = 0;
|
|
||||||
bool unProcessedLineAvailable = false;
|
|
||||||
|
|
||||||
bool rxBuffer_overflow = false;
|
bool rxBuffer_overflow = false;
|
||||||
|
|
||||||
|
int charOut(const char* line)
|
||||||
|
{
|
||||||
|
// don't print anything
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
||||||
while (WiFi.status() != WL_CONNECTED)
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
@ -29,75 +38,34 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UDP.begin(UDP_PORT);
|
UDP.begin(UDP_PORT);
|
||||||
}
|
|
||||||
|
|
||||||
void processLine()
|
running = true;
|
||||||
{
|
|
||||||
rxBuffer[rxBuffer_lineEnd] = 0;
|
|
||||||
uint8_t readPointer = rxBuffer_lineStart;
|
|
||||||
enum {
|
|
||||||
reading_id,
|
|
||||||
reading_cmd,
|
|
||||||
reading_value,
|
|
||||||
invalid_line
|
|
||||||
} readState = reading_id;
|
|
||||||
|
|
||||||
uint16_t id = 0;
|
cmdList = getCMDList();
|
||||||
|
|
||||||
while (rxBuffer_lineStart < rxBuffer_lineEnd)
|
// init cli
|
||||||
{
|
CLI_init((CLI_charOutFn)&charOut, cmdList);
|
||||||
switch (readState)
|
|
||||||
{
|
while (running)
|
||||||
case reading_id:
|
{
|
||||||
if (rxBuffer[readPointer] >= '0' && rxBuffer[readPointer] <= '9')
|
int packetSize = UDP.parsePacket();
|
||||||
{
|
while (packetSize) {
|
||||||
id = (id * 10) + (rxBuffer[readPointer] - '0');
|
char c;
|
||||||
}
|
int len = UDP.read(&c, 1);
|
||||||
else if ((rxBuffer[readPointer] == ':') && (id == BOAT_ID))
|
if (len == 1)
|
||||||
{
|
{
|
||||||
readState = reading_cmd;
|
CLI_charIn(c);
|
||||||
}
|
packetSize -= c;
|
||||||
else
|
}
|
||||||
{
|
|
||||||
readState = invalid_line;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case reading_cmd:
|
|
||||||
break;
|
|
||||||
case reading_value:
|
|
||||||
break;
|
|
||||||
case invalid_line:
|
|
||||||
rxBuffer_lineStart = rxBuffer_lineEnd;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
rxBuffer_lineStart++;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int readNextLine()
|
CLI_deinit();
|
||||||
{
|
CMDList_deinit(cmdList);
|
||||||
while (rxBuffer_readPointer < RX_BUFFER_SIZE)
|
|
||||||
{
|
|
||||||
if (rxBuffer[rxBuffer_readPointer] == '\n')
|
|
||||||
{
|
|
||||||
rxBuffer_lineEnd = rxBuffer_readPointer;
|
|
||||||
processLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
rxBuffer_readPointer++;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
int packetSize = UDP.parsePacket();
|
|
||||||
if (packetSize) {
|
|
||||||
int len = UDP.read(&rxBuffer[0], RX_BUFFER_SIZE);
|
|
||||||
|
|
||||||
rxBuffer_readPointer = 0;
|
|
||||||
rxBuffer_lineStart = 0;
|
|
||||||
rxBuffer_lineEnd = 0;
|
|
||||||
|
|
||||||
readNextLine();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
39
rx_esp2866/src/utils.c
Normal file
39
rx_esp2866/src/utils.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
char* getNextArg(char* args)
|
||||||
|
{
|
||||||
|
uint8_t step = 0;
|
||||||
|
int end = 0;
|
||||||
|
while (end == 0)
|
||||||
|
{
|
||||||
|
if (step < 255)
|
||||||
|
{
|
||||||
|
switch (*(args + step))
|
||||||
|
{
|
||||||
|
case ';':
|
||||||
|
end = 1; // found
|
||||||
|
case '\n':
|
||||||
|
case '\r':
|
||||||
|
case '\0':
|
||||||
|
end = 2; // end of line
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
end = 3; // line to long
|
||||||
|
}
|
||||||
|
step++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end != 3)
|
||||||
|
{
|
||||||
|
return args + step;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
6
rx_esp2866/src/utils.h
Normal file
6
rx_esp2866/src/utils.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef UTILS_H
|
||||||
|
#define UTILS_H
|
||||||
|
|
||||||
|
char* getNextArg(char* args);
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
x
Reference in New Issue
Block a user