Interface module for driving LEDs
+ start shaping up main.cpp + make the usage of namespaces and class names more consistent throughout the whole project + refactor related unit tests accordinglypull/13/head
parent
7611b98830
commit
fce2195558
|
|
@ -184,7 +184,7 @@ target_include_directories(firmware PRIVATE include src)
|
|||
target_compile_options(firmware PRIVATE -Wdouble-promotion)
|
||||
target_sources(
|
||||
firmware PRIVATE src/main.cpp src/hal/avr/cpu.cpp src/hal/avr/usart.cpp src/modules/protocol.cpp
|
||||
src/modules/buttons.cpp
|
||||
src/modules/buttons.cpp src/modules/leds.cpp
|
||||
)
|
||||
|
||||
set_property(
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
/// Hardware Abstraction Layer for the ADC's
|
||||
|
||||
namespace hal {
|
||||
namespace ADC {
|
||||
namespace adc {
|
||||
|
||||
/// ADC access routines
|
||||
uint16_t ReadADC(uint8_t adc);
|
||||
|
||||
} // namespace ADC
|
||||
} // namespace adc
|
||||
} // namespace hal
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include "../cpu.h"
|
||||
|
||||
namespace hal {
|
||||
namespace CPU {
|
||||
namespace cpu {
|
||||
|
||||
void Init() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
/// Hardware Abstraction Layer for the CPU
|
||||
|
||||
namespace hal {
|
||||
namespace CPU {
|
||||
namespace cpu {
|
||||
|
||||
/// CPU init routines (not really necessary for the AVR)
|
||||
void Init();
|
||||
|
||||
} // namespace CPU
|
||||
} // namespace cpu
|
||||
} // namespace hal
|
||||
|
|
|
|||
157
src/main.cpp
157
src/main.cpp
|
|
@ -1,52 +1,53 @@
|
|||
#include "logic/mm_control.h"
|
||||
#include "hal/cpu.h"
|
||||
#include "hal/adc.h"
|
||||
#include "hal/gpio.h"
|
||||
#include "hal/spi.h"
|
||||
#include "hal/usart.h"
|
||||
|
||||
#include "pins.h"
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
/// One-time setup of HW and SW components
|
||||
/// Called before entering the loop() function
|
||||
void setup() {
|
||||
#include "modules/buttons.h"
|
||||
#include "modules/leds.h"
|
||||
#include "modules/protocol.h"
|
||||
|
||||
#include "logic/mm_control.h"
|
||||
|
||||
static hal::UART uart;
|
||||
|
||||
static modules::protocol::Protocol protocol;
|
||||
static modules::buttons::Buttons buttons;
|
||||
static modules::leds::LEDs leds;
|
||||
|
||||
// examples and test code shall be located here
|
||||
void TmpPlayground() {
|
||||
using namespace hal;
|
||||
|
||||
// spi::SPI_InitTypeDef spi_conf = {
|
||||
// .miso_pin = gpio::GPIO_pin(TMC2130_SPI_MISO_PIN),
|
||||
// .mosi_pin = gpio::GPIO_pin(TMC2130_SPI_MOSI_PIN),
|
||||
// .sck_pin = gpio::GPIO_pin(TMC2130_SPI_SCK_PIN),
|
||||
// .ss_pin = gpio::GPIO_pin(TMC2130_SPI_SS_PIN),
|
||||
// .prescaler = 2, //4mhz
|
||||
// .cpha = 1,
|
||||
// .cpol = 1,
|
||||
// };
|
||||
// spi::Init(SPI0, &spi_conf);
|
||||
// SPI example
|
||||
gpio::Init(gpio::GPIO_pin(GPIOC, 6), gpio::GPIO_InitTypeDef(gpio::Mode::output, gpio::Level::high));
|
||||
uint8_t dat[5];
|
||||
gpio::WritePin(gpio::GPIO_pin(GPIOC, 6), gpio::Level::low);
|
||||
spi::TxRx(SPI0, 0x01);
|
||||
spi::TxRx(SPI0, 0x00);
|
||||
spi::TxRx(SPI0, 0x00);
|
||||
spi::TxRx(SPI0, 0x00);
|
||||
spi::TxRx(SPI0, 0x00);
|
||||
gpio::WritePin(gpio::GPIO_pin(GPIOC, 6), gpio::Level::high);
|
||||
gpio::WritePin(gpio::GPIO_pin(GPIOC, 6), gpio::Level::low);
|
||||
dat[0] = spi::TxRx(SPI0, 0x00);
|
||||
dat[1] = spi::TxRx(SPI0, 0x00);
|
||||
dat[2] = spi::TxRx(SPI0, 0x00);
|
||||
dat[3] = spi::TxRx(SPI0, 0x00);
|
||||
dat[4] = spi::TxRx(SPI0, 0x00);
|
||||
gpio::WritePin(gpio::GPIO_pin(GPIOC, 6), gpio::Level::high);
|
||||
(void)dat;
|
||||
|
||||
// // SPI example
|
||||
// gpio::Init(gpio::GPIO_pin(GPIOC, 6), gpio::GPIO_InitTypeDef(gpio::Mode::output, gpio::Level::high));
|
||||
// uint8_t dat[5];
|
||||
// gpio::WritePin(gpio::GPIO_pin(GPIOC, 6), gpio::Level::low);
|
||||
// spi::TxRx(SPI0, 0x01);
|
||||
// spi::TxRx(SPI0, 0x00);
|
||||
// spi::TxRx(SPI0, 0x00);
|
||||
// spi::TxRx(SPI0, 0x00);
|
||||
// spi::TxRx(SPI0, 0x00);
|
||||
// gpio::WritePin(gpio::GPIO_pin(GPIOC, 6), gpio::Level::high);
|
||||
// gpio::WritePin(gpio::GPIO_pin(GPIOC, 6), gpio::Level::low);
|
||||
// dat[0] = spi::TxRx(SPI0, 0x00);
|
||||
// dat[1] = spi::TxRx(SPI0, 0x00);
|
||||
// dat[2] = spi::TxRx(SPI0, 0x00);
|
||||
// dat[3] = spi::TxRx(SPI0, 0x00);
|
||||
// dat[4] = spi::TxRx(SPI0, 0x00);
|
||||
// gpio::WritePin(gpio::GPIO_pin(GPIOC, 6), gpio::Level::high);
|
||||
// (void)dat;
|
||||
// using namespace hal::gpio;
|
||||
// WritePin(GPIO_pin(GPIOB, 5), Level::low);
|
||||
// TogglePin(GPIO_pin(GPIOB, 6));
|
||||
// if (hal::gpio::ReadPin(GPIO_pin(GPIOB, 7)) == hal::gpio::Level::low)
|
||||
// break;
|
||||
|
||||
USART::USART_InitTypeDef usart_conf = {
|
||||
.rx_pin = gpio::GPIO_pin(GPIOD, 2),
|
||||
.tx_pin = gpio::GPIO_pin(GPIOD, 3),
|
||||
.baudrate = 115200,
|
||||
};
|
||||
|
||||
usart1.Init(&usart_conf);
|
||||
sei();
|
||||
usart1.puts("1234567890\n");
|
||||
usart1.puts("1234567890\n");
|
||||
|
|
@ -59,7 +60,76 @@ void setup() {
|
|||
usart1.puts("1234567890\n");
|
||||
usart1.puts("1234567890\n");
|
||||
usart1.puts("1234567890\n");
|
||||
// usart1.Flush();
|
||||
}
|
||||
|
||||
/// One-time setup of HW and SW components
|
||||
/// Called before entering the loop() function
|
||||
/// Green LEDs signalize the progress of initialization. If anything goes wrong we shall turn on a red LED
|
||||
void setup() {
|
||||
using namespace hal;
|
||||
|
||||
cpu::Init();
|
||||
|
||||
// shr::Init()
|
||||
leds.SetMode(4, false, modules::leds::Mode::blink0);
|
||||
// shr::Send(leds.Step(0));
|
||||
|
||||
// @@TODO if the shift register doesn't work we really can't signalize anything, only internal variables will be accessible if the UART works
|
||||
|
||||
USART::USART_InitTypeDef usart_conf = {
|
||||
.rx_pin = gpio::GPIO_pin(GPIOD, 2),
|
||||
.tx_pin = gpio::GPIO_pin(GPIOD, 3),
|
||||
.baudrate = 115200,
|
||||
usart1.Init(&usart_conf);
|
||||
|
||||
leds.SetMode(3, false, modules::leds::Mode::on);
|
||||
// shr::Send(leds.Step(0));
|
||||
|
||||
// @@TODO if both shift register and the UART are dead, we are sitting ducks :(
|
||||
|
||||
spi::SPI_InitTypeDef spi_conf = {
|
||||
.miso_pin = gpio::GPIO_pin(TMC2130_SPI_MISO_PIN),
|
||||
.mosi_pin = gpio::GPIO_pin(TMC2130_SPI_MOSI_PIN),
|
||||
.sck_pin = gpio::GPIO_pin(TMC2130_SPI_SCK_PIN),
|
||||
.ss_pin = gpio::GPIO_pin(TMC2130_SPI_SS_PIN),
|
||||
.prescaler = 2, //4mhz
|
||||
.cpha = 1,
|
||||
.cpol = 1,
|
||||
};
|
||||
spi::Init(SPI0, &spi_conf);
|
||||
leds.SetMode(2, false, modules::leds::Mode::on);
|
||||
//shr::Send(leds.Step(0));
|
||||
|
||||
// tmc::Init()
|
||||
leds.SetMode(1, false, modules::leds::Mode::on);
|
||||
//shr::Send(leds.Step(0));
|
||||
|
||||
// adc::Init();
|
||||
leds.SetMode(0, false, modules::leds::Mode::on);
|
||||
//shr::Send(leds.Step(0));
|
||||
}
|
||||
|
||||
void ProcessRequestMsg(const modules::protocol::RequestMsg &rq) {
|
||||
}
|
||||
|
||||
/// @returns true if a request was successfully finished
|
||||
bool CheckMsgs() {
|
||||
using mpd = modules::protocol::DecodeStatus;
|
||||
while (!uart.ReadEmpty()) {
|
||||
switch (protocol.DecodeRequest(uart.Read())) {
|
||||
case mpd::MessageCompleted:
|
||||
// process the input message
|
||||
return true;
|
||||
break;
|
||||
case mpd::NeedMoreData:
|
||||
// just continue reading
|
||||
break;
|
||||
case mpd::Error:
|
||||
// what shall we do? Start some watchdog?
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Main loop of the firmware
|
||||
|
|
@ -77,13 +147,16 @@ void setup() {
|
|||
/// The idea behind the Step* routines is to keep each automaton non-blocking allowing for some “concurrency”.
|
||||
/// Some FW components will leverage ISR to do their stuff (UART, motor stepping?, etc.)
|
||||
void loop() {
|
||||
if (CheckMsgs()) {
|
||||
ProcessRequestMsg(protocol.GetRequestMsg());
|
||||
}
|
||||
buttons.Step(hal::adc::ReadADC(0));
|
||||
// shr.Send(leds.Step(0));
|
||||
}
|
||||
|
||||
int main() {
|
||||
setup();
|
||||
for (;;) {
|
||||
if (!usart1.ReadEmpty())
|
||||
usart1.Write(usart1.Read());
|
||||
loop();
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include "buttons.h"
|
||||
#include "../hal/adc.h"
|
||||
|
||||
namespace modules {
|
||||
namespace buttons {
|
||||
|
||||
uint16_t Buttons::tmpTiming = 0;
|
||||
|
||||
|
|
@ -41,32 +41,31 @@ void Button::Step(uint16_t time, bool press) {
|
|||
}
|
||||
}
|
||||
|
||||
int8_t Buttons::Sample() {
|
||||
int8_t Buttons::Sample(uint16_t rawADC) {
|
||||
// decode 3 buttons' levels from one ADC
|
||||
uint16_t raw = hal::ADC::ReadADC(0);
|
||||
|
||||
// Button 1 - 0
|
||||
// Button 2 - 344
|
||||
// Button 3 - 516
|
||||
// Doesn't handle multiple pressed buttons at once
|
||||
|
||||
if (raw < 10)
|
||||
if (rawADC < 10)
|
||||
return 0;
|
||||
else if (raw > 320 && raw < 360)
|
||||
else if (rawADC > 320 && rawADC < 360)
|
||||
return 1;
|
||||
else if (raw > 500 && raw < 530)
|
||||
else if (rawADC > 500 && rawADC < 530)
|
||||
return 2;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Buttons::Step() {
|
||||
void Buttons::Step(uint16_t rawADC) {
|
||||
// @@TODO temporary timing
|
||||
++tmpTiming;
|
||||
int8_t currentState = Sample();
|
||||
int8_t currentState = Sample(rawADC);
|
||||
for (uint_fast8_t b = 0; b < N; ++b) {
|
||||
// this button was pressed if b == currentState, released otherwise
|
||||
buttons[b].Step(tmpTiming, b == currentState);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace buttons
|
||||
} // namespace modules
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
/// This layer should contain debouncing of buttons and their logical interpretation
|
||||
|
||||
namespace modules {
|
||||
namespace buttons {
|
||||
|
||||
struct Button {
|
||||
inline constexpr Button()
|
||||
|
|
@ -56,7 +57,7 @@ public:
|
|||
inline constexpr Buttons() = default;
|
||||
|
||||
/// State machine step - reads the ADC, processes debouncing, updates states of individual buttons
|
||||
void Step();
|
||||
void Step(uint16_t rawADC);
|
||||
|
||||
/// @return true if button at index is pressed
|
||||
/// @@TODO add range checking if necessary
|
||||
|
|
@ -67,7 +68,8 @@ private:
|
|||
|
||||
/// Call to the ADC and decode its output into a button index
|
||||
/// @returns index of the button pressed or -1 in case no button is pressed
|
||||
static int8_t Sample();
|
||||
static int8_t Sample(uint16_t rawADC);
|
||||
};
|
||||
|
||||
} // namespace buttons
|
||||
} // namespace modules
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
#include "leds.h"
|
||||
|
||||
namespace modules {
|
||||
namespace leds {
|
||||
|
||||
void LED::SetMode(Mode mode) {
|
||||
state.mode = mode;
|
||||
// set initial state of LEDs correctly - transition from one mode to another
|
||||
switch (state.mode) {
|
||||
case Mode::blink1:
|
||||
case Mode::off:
|
||||
state.on = 0;
|
||||
break;
|
||||
|
||||
case Mode::blink0:
|
||||
case Mode::on:
|
||||
state.on = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool LED::Step(bool oddPeriod) {
|
||||
switch (state.mode) {
|
||||
// on and off don't change while stepping
|
||||
case Mode::blink0:
|
||||
state.on = oddPeriod;
|
||||
break;
|
||||
case Mode::blink1:
|
||||
state.on = !oddPeriod;
|
||||
break;
|
||||
default: // do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t LEDs::Step(uint8_t delta_ms) {
|
||||
ms += delta_ms;
|
||||
bool oddPeriod = ((ms / 1000U) & 0x01U) != 0;
|
||||
uint16_t result = 0;
|
||||
for (uint8_t i = 0; i < ledPairs * 2; ++i) {
|
||||
result <<= 1;
|
||||
result |= leds[i].Step(oddPeriod);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace leds
|
||||
} // namespace modules
|
||||
|
|
@ -1,3 +1,119 @@
|
|||
#pragma once
|
||||
|
||||
/// @@TODO @leptun design some nice API ;)
|
||||
#include <stdint.h>
|
||||
|
||||
/// We have 5 pairs of LEDs
|
||||
/// In each pair there is a green and a red LED
|
||||
///
|
||||
/// A typical scenario in the past was visualization of error states.
|
||||
/// The combination of colors with blinking frequency had a specific meaning.
|
||||
///
|
||||
/// We'd like to drive each pair? separately, which includes:
|
||||
/// - blinking (none/slow/fast)
|
||||
/// - what shall blink (red/green/both-at-once/both-interlaced)
|
||||
///
|
||||
/// The physical connection is not important on this level (i.e. how and what shall be sent into the shift registers)
|
||||
|
||||
namespace modules {
|
||||
namespace leds {
|
||||
|
||||
/// Mode of LED
|
||||
/// blink0 and blink1 allow for interlaced blinking of LEDs (one is on and the other off)
|
||||
enum Mode {
|
||||
off,
|
||||
on,
|
||||
blink0, ///< start blinking at even periods
|
||||
blink1 ///< start blinking at odd periods
|
||||
};
|
||||
|
||||
/// a single LED
|
||||
class LED {
|
||||
public:
|
||||
constexpr inline LED() = default;
|
||||
void SetMode(Mode mode);
|
||||
|
||||
/// @returns true if the LED shines
|
||||
bool Step(bool oddPeriod);
|
||||
inline bool On() const { return state.on; }
|
||||
|
||||
private:
|
||||
struct State {
|
||||
uint8_t on : 1;
|
||||
uint8_t mode : 2;
|
||||
constexpr inline State()
|
||||
: on(0)
|
||||
, mode(Mode::off) {}
|
||||
};
|
||||
|
||||
State state;
|
||||
};
|
||||
|
||||
/// main LED API
|
||||
class LEDs {
|
||||
public:
|
||||
constexpr inline LEDs()
|
||||
: ms(0) {};
|
||||
|
||||
/// step LED automaton
|
||||
/// @returns statuses of LEDs - one bit per LED and 1 = on, 0 = off
|
||||
uint16_t Step(uint8_t delta_ms);
|
||||
|
||||
inline constexpr uint8_t LedPairsCount() const { return ledPairs; }
|
||||
|
||||
inline void SetMode(uint8_t slot, bool red, Mode mode) {
|
||||
SetMode(slot * 2 + red, mode);
|
||||
}
|
||||
inline void SetMode(uint8_t index, Mode mode) {
|
||||
leds[index].SetMode(mode);
|
||||
}
|
||||
|
||||
inline bool LedOn(uint8_t index) const {
|
||||
return leds[index].On();
|
||||
}
|
||||
inline bool LedOn(uint8_t slot, bool red) const {
|
||||
return leds[slot * 2 + red].On();
|
||||
}
|
||||
|
||||
private:
|
||||
constexpr static const uint8_t ledPairs = 5;
|
||||
LED leds[ledPairs * 2];
|
||||
uint16_t ms;
|
||||
};
|
||||
|
||||
//// asi nechame moznost jednu blikat rychle a druhou pomalu
|
||||
|
||||
//// tohle ale nevyresi, ze jedna LED ma blikat a druha svitit
|
||||
|
||||
//// problem je, ze zapnuti/vypnuti led je blink none ... mozna by to chtelo blink none-on a none-off
|
||||
//// jaka bude mnozina rezimu?
|
||||
//// green-off green-on green-blink-slow green-blink-fast
|
||||
//// red-off + + + +
|
||||
//// red-on + + + +
|
||||
//// red-blink-slow + + 2 x
|
||||
//// red-blink-fast + + x 2
|
||||
////
|
||||
//// rezim 2 muze mit jeste varianty - blink-sync, blink-interlaced, coz v podstate znamena rezimy:
|
||||
//// blink-slow1, blink-slow2, blink-fast1, blink-fast2, pricemz nemaji smysl kombinace:
|
||||
//// blink-slow + blink-fast
|
||||
|
||||
//// revize
|
||||
//// v aktualnim FW led jen blikaji jednou rychlosti
|
||||
//// takze to spis udelam jako pole LED, pricemz cervene budou na sudych a zelene na lichych indexech
|
||||
//// stav ledky bude: off, on, blink0 a blink1
|
||||
//// blink0 znamena zacni pocitat blikaci interval od sude periody
|
||||
//// blink1 od liche
|
||||
//// tim pujde zmodelovat jak sync tak async blikani
|
||||
//// Dale je otazka, jestli chceme rychle a pomale blikani... asi ne, kdyz bude report na LCD tiskarny
|
||||
|
||||
//// Dale castecne souvisejici
|
||||
//// Start MMU by mel reportovat progress, pricemz aktualni stav je takovy, ze nabihaji LED a kazda neco znamena
|
||||
//// Tiskarna by klidne mohla posilat Q a dostavat odpoved ve stylu "starting" a progress/state code
|
||||
////
|
||||
//// Mozna taky budeme potrebovat nastavovat ruzne vnitrni promenne (treba use slots 1-3 namisto 0-4), takze operace SetVar a k tomu obracena GetVar
|
||||
//// Dava mi smysl modifikovat protokol V jako getvar (zamerne ne G, aby to nekolidovalo s gcodes) a S jako setvar
|
||||
//// cislo je index variable a odpovi se A_hodnota, cili accepted a hodnota odpovedi
|
||||
|
||||
//void SetLEDs(uint8_t slot0, uint8_t slot1, uint8_t slot2, uint8_t slot3, uint8_t slot4);
|
||||
|
||||
} // namespace LEDs
|
||||
} // namespace modules
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
// <OID> F : operation finished - will be repeated to "Q" messages until a new command is issued
|
||||
|
||||
namespace modules {
|
||||
namespace protocol {
|
||||
|
||||
// decoding automaton
|
||||
// states: input -> transition into state
|
||||
|
|
@ -24,7 +25,7 @@ namespace modules {
|
|||
// msgvalue 0-9 ->msgvalue
|
||||
// \n ->start successfully accepted command
|
||||
|
||||
Protocol::DecodeStatus Protocol::DecodeRequest(uint8_t c) {
|
||||
DecodeStatus Protocol::DecodeRequest(uint8_t c) {
|
||||
switch (rqState) {
|
||||
case RequestStates::Code:
|
||||
switch (c) {
|
||||
|
|
@ -81,7 +82,7 @@ uint8_t Protocol::EncodeRequest(const RequestMsg &msg, uint8_t *txbuff) {
|
|||
return 3;
|
||||
}
|
||||
|
||||
Protocol::DecodeStatus Protocol::DecodeResponse(uint8_t c) {
|
||||
DecodeStatus Protocol::DecodeResponse(uint8_t c) {
|
||||
switch (rspState) {
|
||||
case ResponseStates::RequestCode:
|
||||
switch (c) {
|
||||
|
|
@ -218,4 +219,5 @@ uint8_t Protocol::EncodeResponseQueryOperation(const RequestMsg &msg, ResponseMs
|
|||
return dst - txbuff + 1;
|
||||
}
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace modules
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
/// @@TODO possibly add some checksum to verify the correctness of messages
|
||||
|
||||
namespace modules {
|
||||
namespace protocol {
|
||||
|
||||
enum class RequestMsgCodes : uint8_t {
|
||||
unknown = 0,
|
||||
|
|
@ -56,11 +57,6 @@ struct ResponseMsg {
|
|||
, paramValue(paramValue) {}
|
||||
};
|
||||
|
||||
/// Protocol class is responsible for creating/decoding messages in Rx/Tx buffer
|
||||
/// Beware - in the decoding more, it is meant to be a statefull instance which works through public methods
|
||||
/// processing one input byte per call
|
||||
class Protocol {
|
||||
public:
|
||||
/// Message decoding return value
|
||||
enum class DecodeStatus : uint_fast8_t {
|
||||
MessageCompleted, ///< message completed and successfully lexed
|
||||
|
|
@ -68,6 +64,11 @@ public:
|
|||
Error, ///< input character broke message decoding
|
||||
};
|
||||
|
||||
/// Protocol class is responsible for creating/decoding messages in Rx/Tx buffer
|
||||
/// Beware - in the decoding more, it is meant to be a statefull instance which works through public methods
|
||||
/// processing one input byte per call
|
||||
class Protocol {
|
||||
public:
|
||||
inline Protocol()
|
||||
: rqState(RequestStates::Code)
|
||||
, requestMsg(RequestMsgCodes::unknown, 0)
|
||||
|
|
@ -140,4 +141,5 @@ private:
|
|||
ResponseMsg responseMsg;
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace modules
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include <vector>
|
||||
|
||||
namespace hal {
|
||||
namespace ADC {
|
||||
namespace adc {
|
||||
|
||||
static TADCData values2Return;
|
||||
static TADCData::const_iterator rdptr = values2Return.cbegin();
|
||||
|
|
@ -28,5 +28,5 @@ namespace ADC {
|
|||
return rdptr != values2Return.end() ? *rdptr : 1023;
|
||||
}
|
||||
|
||||
} // namespace ADC
|
||||
} // namespace adc
|
||||
} // namespace hal
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@
|
|||
#include <vector>
|
||||
|
||||
namespace hal {
|
||||
namespace ADC {
|
||||
namespace adc {
|
||||
|
||||
using TADCData = std::vector<uint16_t>;
|
||||
|
||||
void ReinitADC(TADCData &&d, uint8_t ovsmpl);
|
||||
|
||||
} // namespace ADC
|
||||
} // namespace adc
|
||||
} // namespace hal
|
||||
|
|
|
|||
|
|
@ -4,21 +4,21 @@
|
|||
|
||||
using Catch::Matchers::Equals;
|
||||
|
||||
bool Step_Basic_One_Button_Test(modules::Buttons &b, uint8_t oversampleFactor, uint8_t testedButtonIndex, uint8_t otherButton1, uint8_t otherButton2) {
|
||||
bool Step_Basic_One_Button_Test(modules::buttons::Buttons &b, uint8_t oversampleFactor, uint8_t testedButtonIndex, uint8_t otherButton1, uint8_t otherButton2) {
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i)
|
||||
b.Step(); // should detect the press but remain in detected state - wait for debounce
|
||||
b.Step(hal::adc::ReadADC(0)); // should detect the press but remain in detected state - wait for debounce
|
||||
CHECK(!b.ButtonPressed(testedButtonIndex));
|
||||
CHECK(!b.ButtonPressed(otherButton1));
|
||||
CHECK(!b.ButtonPressed(otherButton2));
|
||||
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i)
|
||||
b.Step(); // reset to waiting
|
||||
b.Step(hal::adc::ReadADC(0)); // reset to waiting
|
||||
CHECK(b.ButtonPressed(testedButtonIndex));
|
||||
CHECK(!b.ButtonPressed(otherButton1));
|
||||
CHECK(!b.ButtonPressed(otherButton2));
|
||||
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i)
|
||||
b.Step(); // pressed again, still in debouncing state
|
||||
b.Step(hal::adc::ReadADC(0)); // pressed again, still in debouncing state
|
||||
CHECK(!b.ButtonPressed(testedButtonIndex));
|
||||
CHECK(!b.ButtonPressed(otherButton1));
|
||||
CHECK(!b.ButtonPressed(otherButton2));
|
||||
|
|
@ -27,14 +27,14 @@ bool Step_Basic_One_Button_Test(modules::Buttons &b, uint8_t oversampleFactor, u
|
|||
}
|
||||
|
||||
/// This test verifies the behaviour of a single button. The other buttons must remain intact.
|
||||
bool Step_Basic_One_Button(hal::ADC::TADCData &&d, uint8_t testedButtonIndex) {
|
||||
using namespace modules;
|
||||
bool Step_Basic_One_Button(hal::adc::TADCData &&d, uint8_t testedButtonIndex) {
|
||||
using namespace modules::buttons;
|
||||
|
||||
Buttons b;
|
||||
|
||||
// need to oversample the data as debouncing takes 100 cycles to accept a pressed button
|
||||
constexpr uint8_t oversampleFactor = 100;
|
||||
hal::ADC::ReinitADC(std::move(d), oversampleFactor);
|
||||
hal::adc::ReinitADC(std::move(d), oversampleFactor);
|
||||
|
||||
uint8_t otherButton1 = 1, otherButton2 = 2;
|
||||
switch (testedButtonIndex) {
|
||||
|
|
@ -53,15 +53,15 @@ bool Step_Basic_One_Button(hal::ADC::TADCData &&d, uint8_t testedButtonIndex) {
|
|||
|
||||
TEST_CASE("buttons::Step-basic-button", "[buttons]") {
|
||||
{
|
||||
hal::ADC::TADCData d({ 5, 6, 1023 });
|
||||
hal::adc::TADCData d({ 5, 6, 1023 });
|
||||
CHECK(Step_Basic_One_Button(std::move(d), 0));
|
||||
}
|
||||
{
|
||||
hal::ADC::TADCData d({ 321, 359, 1023 });
|
||||
hal::adc::TADCData d({ 321, 359, 1023 });
|
||||
CHECK(Step_Basic_One_Button(std::move(d), 1));
|
||||
}
|
||||
{
|
||||
hal::ADC::TADCData d({ 501, 529, 1023 });
|
||||
hal::adc::TADCData d({ 501, 529, 1023 });
|
||||
CHECK(Step_Basic_One_Button(std::move(d), 2));
|
||||
}
|
||||
}
|
||||
|
|
@ -70,13 +70,13 @@ TEST_CASE("buttons::Step-basic-button", "[buttons]") {
|
|||
/// and the Buttons class should press first button and release, then the second one and then the third one
|
||||
/// without being reinitialized.
|
||||
TEST_CASE("buttons::Step-basic-button-one-after-other", "[buttons]") {
|
||||
using namespace modules;
|
||||
hal::ADC::TADCData d({ 5, 6, 1023, 321, 359, 1023, 501, 529, 1023 });
|
||||
using namespace modules::buttons;
|
||||
hal::adc::TADCData d({ 5, 6, 1023, 321, 359, 1023, 501, 529, 1023 });
|
||||
Buttons b;
|
||||
|
||||
// need to oversample the data as debouncing takes 100 cycles to accept a pressed button
|
||||
constexpr uint8_t oversampleFactor = 100;
|
||||
hal::ADC::ReinitADC(std::move(d), oversampleFactor);
|
||||
hal::adc::ReinitADC(std::move(d), oversampleFactor);
|
||||
|
||||
CHECK(Step_Basic_One_Button_Test(b, oversampleFactor, 0, 1, 2));
|
||||
CHECK(Step_Basic_One_Button_Test(b, oversampleFactor, 1, 0, 2));
|
||||
|
|
@ -85,76 +85,76 @@ TEST_CASE("buttons::Step-basic-button-one-after-other", "[buttons]") {
|
|||
|
||||
/// This test tries to simulate a bouncing effect on data from ADC on the first button
|
||||
TEST_CASE("buttons::Step-debounce-one-button", "[buttons]") {
|
||||
using namespace modules;
|
||||
using namespace modules::buttons;
|
||||
|
||||
// make a bounce event on the first press
|
||||
hal::ADC::TADCData d({ 5, 1023, 5, 9, 6, 7, 8, 1023, 1023 });
|
||||
hal::adc::TADCData d({ 5, 1023, 5, 9, 6, 7, 8, 1023, 1023 });
|
||||
|
||||
// need to oversample the data as debouncing takes 100 cycles to accept a pressed button
|
||||
constexpr uint8_t oversampleFactor = 25;
|
||||
hal::ADC::ReinitADC(std::move(d), oversampleFactor);
|
||||
hal::adc::ReinitADC(std::move(d), oversampleFactor);
|
||||
|
||||
Buttons b;
|
||||
|
||||
// 5
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i)
|
||||
b.Step(); // should detect the press but remain in detected state - wait for debounce
|
||||
b.Step(hal::adc::ReadADC(0)); // should detect the press but remain in detected state - wait for debounce
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
|
||||
// 1023
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i)
|
||||
b.Step(); // reset to waiting
|
||||
b.Step(hal::adc::ReadADC(0)); // reset to waiting
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
|
||||
// 5
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i)
|
||||
b.Step(); // pressed again, still in debouncing state
|
||||
b.Step(hal::adc::ReadADC(0)); // pressed again, still in debouncing state
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
|
||||
// 9
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i)
|
||||
b.Step(); // no change
|
||||
b.Step(hal::adc::ReadADC(0)); // no change
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
|
||||
// 6
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i)
|
||||
b.Step(); // no change
|
||||
b.Step(hal::adc::ReadADC(0)); // no change
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
|
||||
// 7
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i)
|
||||
b.Step(); // one step from "pressed"
|
||||
b.Step(hal::adc::ReadADC(0)); // one step from "pressed"
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
|
||||
// 8
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i)
|
||||
b.Step(); // fifth set of samples - should report "pressed" finally
|
||||
b.Step(hal::adc::ReadADC(0)); // fifth set of samples - should report "pressed" finally
|
||||
CHECK(b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
|
||||
// 1023
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i)
|
||||
b.Step(); // sixth set of samples - button released (no debouncing on release)
|
||||
b.Step(hal::adc::ReadADC(0)); // sixth set of samples - button released (no debouncing on release)
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
|
||||
// 1023
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i)
|
||||
b.Step(); // seventh set of samples - still released
|
||||
b.Step(hal::adc::ReadADC(0)); // seventh set of samples - still released
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
using Catch::Matchers::Equals;
|
||||
|
||||
TEST_CASE("protocol::EncodeRequests", "[protocol]") {
|
||||
using namespace modules;
|
||||
using namespace modules::protocol;
|
||||
|
||||
RequestMsgCodes code;
|
||||
uint8_t value;
|
||||
|
|
@ -45,7 +45,7 @@ TEST_CASE("protocol::EncodeRequests", "[protocol]") {
|
|||
}
|
||||
|
||||
TEST_CASE("protocol::EncodeResponseCmdAR", "[protocol]") {
|
||||
using namespace modules;
|
||||
using namespace modules::protocol;
|
||||
|
||||
auto requestMsg = GENERATE(
|
||||
RequestMsg(RequestMsgCodes::Button, 0),
|
||||
|
|
@ -93,7 +93,7 @@ TEST_CASE("protocol::EncodeResponseCmdAR", "[protocol]") {
|
|||
}
|
||||
|
||||
TEST_CASE("protocol::EncodeResponseReadFINDA", "[protocol]") {
|
||||
using namespace modules;
|
||||
using namespace modules::protocol;
|
||||
auto requestMsg = RequestMsg(RequestMsgCodes::Finda, 0);
|
||||
|
||||
uint8_t findaStatus = GENERATE(0, 1);
|
||||
|
|
@ -111,7 +111,7 @@ TEST_CASE("protocol::EncodeResponseReadFINDA", "[protocol]") {
|
|||
}
|
||||
|
||||
TEST_CASE("protocol::EncodeResponseVersion", "[protocol]") {
|
||||
using namespace modules;
|
||||
using namespace modules::protocol;
|
||||
|
||||
std::uint8_t versionQueryType = GENERATE(0, 1, 2, 3);
|
||||
auto requestMsg = RequestMsg(RequestMsgCodes::Version, versionQueryType);
|
||||
|
|
@ -142,7 +142,7 @@ TEST_CASE("protocol::EncodeResponseVersion", "[protocol]") {
|
|||
}
|
||||
|
||||
TEST_CASE("protocol::EncodeResponseQueryOperation", "[protocol]") {
|
||||
using namespace modules;
|
||||
using namespace modules::protocol;
|
||||
|
||||
auto requestMsg = GENERATE(
|
||||
RequestMsg(RequestMsgCodes::Cut, 0),
|
||||
|
|
@ -202,7 +202,7 @@ TEST_CASE("protocol::EncodeResponseQueryOperation", "[protocol]") {
|
|||
}
|
||||
|
||||
TEST_CASE("protocol::DecodeRequest", "[protocol]") {
|
||||
using namespace modules;
|
||||
using namespace modules::protocol;
|
||||
Protocol p;
|
||||
const char *rxbuff = GENERATE(
|
||||
"B0\n", "B1\n", "B2\n",
|
||||
|
|
@ -226,9 +226,9 @@ TEST_CASE("protocol::DecodeRequest", "[protocol]") {
|
|||
break;
|
||||
} else if (c == '\n') {
|
||||
// regular end of message line
|
||||
CHECK(p.DecodeRequest(c) == Protocol::DecodeStatus::MessageCompleted);
|
||||
CHECK(p.DecodeRequest(c) == DecodeStatus::MessageCompleted);
|
||||
} else {
|
||||
CHECK(p.DecodeRequest(c) == Protocol::DecodeStatus::NeedMoreData);
|
||||
CHECK(p.DecodeRequest(c) == DecodeStatus::NeedMoreData);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -239,7 +239,7 @@ TEST_CASE("protocol::DecodeRequest", "[protocol]") {
|
|||
}
|
||||
|
||||
TEST_CASE("protocol::DecodeResponseReadFinda", "[protocol]") {
|
||||
using namespace modules;
|
||||
using namespace modules::protocol;
|
||||
Protocol p;
|
||||
const char *rxbuff = GENERATE(
|
||||
"P0 A0\n",
|
||||
|
|
@ -253,9 +253,9 @@ TEST_CASE("protocol::DecodeResponseReadFinda", "[protocol]") {
|
|||
break;
|
||||
} else if (c == '\n') {
|
||||
// regular end of message line
|
||||
CHECK(p.DecodeResponse(c) == Protocol::DecodeStatus::MessageCompleted);
|
||||
CHECK(p.DecodeResponse(c) == DecodeStatus::MessageCompleted);
|
||||
} else {
|
||||
CHECK(p.DecodeResponse(c) == Protocol::DecodeStatus::NeedMoreData);
|
||||
CHECK(p.DecodeResponse(c) == DecodeStatus::NeedMoreData);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -268,7 +268,7 @@ TEST_CASE("protocol::DecodeResponseReadFinda", "[protocol]") {
|
|||
}
|
||||
|
||||
TEST_CASE("protocol::DecodeResponseQueryOperation", "[protocol]") {
|
||||
using namespace modules;
|
||||
using namespace modules::protocol;
|
||||
Protocol p;
|
||||
const char *cmdReference = GENERATE(
|
||||
"E0", "E1", "E2", "E3", "E4",
|
||||
|
|
@ -294,9 +294,9 @@ TEST_CASE("protocol::DecodeResponseQueryOperation", "[protocol]") {
|
|||
break;
|
||||
} else if (c == '\n') {
|
||||
// regular end of message line
|
||||
CHECK(p.DecodeResponse(c) == Protocol::DecodeStatus::MessageCompleted);
|
||||
CHECK(p.DecodeResponse(c) == DecodeStatus::MessageCompleted);
|
||||
} else {
|
||||
CHECK(p.DecodeResponse(c) == Protocol::DecodeStatus::NeedMoreData);
|
||||
CHECK(p.DecodeResponse(c) == DecodeStatus::NeedMoreData);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -311,81 +311,81 @@ TEST_CASE("protocol::DecodeResponseQueryOperation", "[protocol]") {
|
|||
}
|
||||
|
||||
TEST_CASE("protocol::DecodeRequestErrors", "[protocol]") {
|
||||
using namespace modules;
|
||||
using namespace modules::protocol;
|
||||
Protocol p;
|
||||
const char b0[] = "b0";
|
||||
CHECK(p.DecodeRequest(b0[0]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(b0[0]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest(b0[1]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(b0[1]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
|
||||
// reset protokol decoder
|
||||
CHECK(p.DecodeRequest('\n') == Protocol::DecodeStatus::MessageCompleted);
|
||||
CHECK(p.DecodeRequest('\n') == DecodeStatus::MessageCompleted);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
|
||||
const char B1_[] = "B1 \n";
|
||||
CHECK(p.DecodeRequest(B1_[0]) == Protocol::DecodeStatus::NeedMoreData);
|
||||
CHECK(p.DecodeRequest(B1_[1]) == Protocol::DecodeStatus::NeedMoreData);
|
||||
CHECK(p.DecodeRequest(B1_[2]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(B1_[0]) == DecodeStatus::NeedMoreData);
|
||||
CHECK(p.DecodeRequest(B1_[1]) == DecodeStatus::NeedMoreData);
|
||||
CHECK(p.DecodeRequest(B1_[2]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest(B1_[3]) == Protocol::DecodeStatus::MessageCompleted);
|
||||
CHECK(p.DecodeRequest(B1_[3]) == DecodeStatus::MessageCompleted);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
|
||||
const char _B2[] = " B2\n";
|
||||
CHECK(p.DecodeRequest(_B2[0]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(_B2[0]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest(_B2[1]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(_B2[1]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest(_B2[2]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(_B2[2]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest(_B2[3]) == Protocol::DecodeStatus::MessageCompleted);
|
||||
CHECK(p.DecodeRequest(_B2[3]) == DecodeStatus::MessageCompleted);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
|
||||
const char _B0_[] = " B0 ";
|
||||
CHECK(p.DecodeRequest(_B0_[0]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(_B0_[0]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest(_B0_[1]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(_B0_[1]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest(_B0_[2]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(_B0_[2]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest(_B0_[3]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(_B0_[3]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest('\n') == Protocol::DecodeStatus::MessageCompleted);
|
||||
CHECK(p.DecodeRequest('\n') == DecodeStatus::MessageCompleted);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
}
|
||||
|
||||
TEST_CASE("protocol::DecodeResponseErrors", "[protocol]") {
|
||||
using namespace modules;
|
||||
using namespace modules::protocol;
|
||||
Protocol p;
|
||||
|
||||
const char b0[] = "b0 A\n";
|
||||
CHECK(p.DecodeRequest(b0[0]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(b0[0]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest(b0[1]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(b0[1]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest(b0[2]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(b0[2]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest(b0[3]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(b0[3]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest(b0[4]) == Protocol::DecodeStatus::MessageCompleted);
|
||||
CHECK(p.DecodeRequest(b0[4]) == DecodeStatus::MessageCompleted);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
|
||||
const char b1[] = "b0A\n";
|
||||
CHECK(p.DecodeRequest(b1[0]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(b1[0]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest(b1[1]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(b1[1]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest(b1[2]) == Protocol::DecodeStatus::Error);
|
||||
CHECK(p.DecodeRequest(b1[2]) == DecodeStatus::Error);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
CHECK(p.DecodeRequest(b1[3]) == Protocol::DecodeStatus::MessageCompleted);
|
||||
CHECK(p.DecodeRequest(b1[3]) == DecodeStatus::MessageCompleted);
|
||||
CHECK(p.GetRequestMsg().code == RequestMsgCodes::unknown);
|
||||
}
|
||||
|
||||
// Beware - this test makes 18M+ combinations, run only when changing the implementation of the codec
|
||||
// Therefore it is disabled [.] by default
|
||||
TEST_CASE("protocol::DecodeResponseErrorsCross", "[protocol][.]") {
|
||||
using namespace modules;
|
||||
using namespace modules::protocol;
|
||||
Protocol p;
|
||||
|
||||
const char *validInitialSpaces = "";
|
||||
|
|
@ -434,7 +434,7 @@ TEST_CASE("protocol::DecodeResponseErrorsCross", "[protocol][.]") {
|
|||
bool shouldPass = viInitialSpace && viReqCode && /*viReqValue && */ viSpace && viRspCode && viTerminatingSpaces;
|
||||
bool failed = false;
|
||||
std::for_each(msg.cbegin(), msg.cend(), [&](uint8_t c) {
|
||||
if (p.DecodeResponse(c) == Protocol::DecodeStatus::Error) {
|
||||
if (p.DecodeResponse(c) == DecodeStatus::Error) {
|
||||
failed = true;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue