|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ENABLE_DEBUG
|
|
|
#include "debug.h"
|
|
|
|
|
|
#include "uniparser.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using std::cout;
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define TEST_MIXED_FOUR_ARGS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern bool test_bench( void );
|
|
|
|
|
|
|
|
|
extern void my_noarg_function( void );
|
|
|
|
|
|
template <typename Ta>
|
|
|
extern void my_function( Ta arg_a );
|
|
|
|
|
|
template <typename Ta, typename Tb>
|
|
|
extern void my_function( Ta arg_a, Tb arg_b );
|
|
|
|
|
|
template <typename Ta, typename Tb, typename Tc>
|
|
|
extern void my_function( Ta arg_a, Tb arg_b, Tc arg_c );
|
|
|
|
|
|
template <typename Ta, typename Tb, typename Tc, typename Td>
|
|
|
extern void my_function( Ta arg_a, Tb arg_b, Tc arg_c, Td arg_d );
|
|
|
|
|
|
|
|
|
extern void parser_executor( Orangebot::Uniparser &my_parser, uint8_t *ptr );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DSTART( 0 );
|
|
|
|
|
|
DENTER();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cout << "OrangeBot Projects\n";
|
|
|
|
|
|
DPRINT("OrangeBot Projects\n");
|
|
|
|
|
|
test_bench();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DRETURN();
|
|
|
|
|
|
DSTOP();
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool test_bench( void )
|
|
|
{
|
|
|
|
|
|
DENTER();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Orangebot::Uniparser my_parser;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TEST_SYNTAX
|
|
|
int test_index = 0;
|
|
|
|
|
|
if (my_parser.add_cmd( "A", (void *)nullptr ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", test_index, my_parser.get_error());
|
|
|
}
|
|
|
test_index++;
|
|
|
|
|
|
if (my_parser.add_cmd( "1", (void *)&my_handler_noarg ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", test_index, my_parser.get_error());
|
|
|
}
|
|
|
test_index++;
|
|
|
|
|
|
if (my_parser.add_cmd( "V%x", (void *)&my_handler_noarg ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", test_index, my_parser.get_error());
|
|
|
}
|
|
|
test_index++;
|
|
|
|
|
|
if (my_parser.add_cmd( "P%u%u", (void *)&my_handler_noarg ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", test_index, my_parser.get_error());
|
|
|
}
|
|
|
test_index++;
|
|
|
|
|
|
if (my_parser.add_cmd( "P%uR%U", (void *)&my_handler_noarg ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", test_index, my_parser.get_error());
|
|
|
}
|
|
|
test_index++;
|
|
|
|
|
|
if (my_parser.add_cmd( "uA%uB%uC%uD%uE%u", (void *)&my_handler_noarg ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", test_index, my_parser.get_error());
|
|
|
}
|
|
|
test_index++;
|
|
|
|
|
|
if (my_parser.add_cmd( "dA%dB%dC%d", (void *)&my_handler_noarg ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", test_index, my_parser.get_error());
|
|
|
}
|
|
|
test_index++;
|
|
|
printf("number of tests: %d\n", test_index +1);
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TEST_EMPTY_DICTIONARY
|
|
|
|
|
|
int cmd_index = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parser_executor( my_parser, (uint8_t *)"P\0" );
|
|
|
|
|
|
printf("---------------------------------------------------\n");
|
|
|
|
|
|
|
|
|
if (my_parser.add_cmd( "P", (void *)&my_noarg_function ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", cmd_index, my_parser.get_error());
|
|
|
}
|
|
|
cmd_index++;
|
|
|
|
|
|
printf("Commands added: %d\n", cmd_index);
|
|
|
|
|
|
printf("---------------------------------------------------\n");
|
|
|
|
|
|
parser_executor( my_parser, (uint8_t *)"P\0" );
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TEST_ONECHAR
|
|
|
|
|
|
int cmd_index = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (my_parser.add_cmd( "P", (void *)&my_noarg_function ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", cmd_index, my_parser.get_error());
|
|
|
}
|
|
|
cmd_index++;
|
|
|
|
|
|
if (my_parser.add_cmd( "F", (void *)&my_noarg_function ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", cmd_index, my_parser.get_error());
|
|
|
}
|
|
|
cmd_index++;
|
|
|
printf("Commands added: %d\n", cmd_index);
|
|
|
|
|
|
printf("---------------------------------------------------\n");
|
|
|
|
|
|
parser_executor( my_parser, (uint8_t *)"P\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"F\0" );
|
|
|
|
|
|
parser_executor( my_parser, (uint8_t *)"H\0" );
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TEST_ONECHAR_ARG
|
|
|
|
|
|
int cmd_index = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (my_parser.add_cmd( "X%u", (void *)&my_function<uint8_t> ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", cmd_index, my_parser.get_error());
|
|
|
}
|
|
|
cmd_index++;
|
|
|
|
|
|
if (my_parser.add_cmd( "VEL%u", (void *)&my_function<uint8_t> ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", cmd_index, my_parser.get_error());
|
|
|
}
|
|
|
cmd_index++;
|
|
|
printf("Commands added: %d\n", cmd_index);
|
|
|
|
|
|
|
|
|
printf("---------------------------------------------------\n");
|
|
|
|
|
|
parser_executor( my_parser, (uint8_t *)"X7T\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"VEL++255\0" );
|
|
|
|
|
|
printf("---------------------------------------------------\n");
|
|
|
|
|
|
parser_executor( my_parser, (uint8_t *)"X7\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"VEL+255\0" );
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TEST_MULTICHAR
|
|
|
|
|
|
int cmd_index = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (my_parser.add_cmd( "XENOSCUM", (void *)&my_noarg_function ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", cmd_index, my_parser.get_error());
|
|
|
}
|
|
|
cmd_index++;
|
|
|
|
|
|
printf("Commands added: %d\n", cmd_index);
|
|
|
|
|
|
|
|
|
printf("---------------------------------------------------\n");
|
|
|
parser_executor( my_parser, (uint8_t *)"XENORUM\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"XENOXENOSCUM\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"HXENOSCUM\0" );
|
|
|
|
|
|
|
|
|
printf("---------------------------------------------------\n");
|
|
|
parser_executor( my_parser, (uint8_t *)"XENOSCUM\0" );
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TEST_TWO_S32
|
|
|
|
|
|
int cmd_index = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (my_parser.add_cmd( "POS%dNEG%dSHAKA\0", (void *)&my_function<int32_t, int32_t> ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", cmd_index, my_parser.get_error());
|
|
|
}
|
|
|
cmd_index++;
|
|
|
printf("Commands added: %d\n", cmd_index);
|
|
|
|
|
|
|
|
|
printf("---------------------------------------------------\n");
|
|
|
parser_executor( my_parser, (uint8_t *)"POS-2147483648NEG++2147483647SHAKA\0" );
|
|
|
|
|
|
printf("---------------------------------------------------\n");
|
|
|
parser_executor( my_parser, (uint8_t *)"POS-2147483648NEG+2147483647SHAKA\0" );
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TEST_ALL_FOUR
|
|
|
|
|
|
int cmd_index = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (my_parser.add_cmd( "POS%dNEG%dSHAKA\0", (void *)&my_function<int32_t, int32_t> ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", cmd_index, my_parser.get_error());
|
|
|
}
|
|
|
cmd_index++;
|
|
|
|
|
|
if (my_parser.add_cmd( "SA%sB%sC%sD%s\0", (void *)&my_function<int8_t, int8_t, int8_t, int8_t> ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", cmd_index, my_parser.get_error());
|
|
|
}
|
|
|
cmd_index++;
|
|
|
|
|
|
if (my_parser.add_cmd( "SSA%SB%SC%SD%S\0", (void *)&my_function<int16_t, int16_t, int16_t, int16_t> ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", cmd_index, my_parser.get_error());
|
|
|
}
|
|
|
cmd_index++;
|
|
|
|
|
|
if (my_parser.add_cmd( "A%uB%uC%uD%u\0", (void *)&my_function<uint8_t, uint8_t, uint8_t, uint8_t> ) == true)
|
|
|
{
|
|
|
printf("Test %d | ERR: %d\n", cmd_index, my_parser.get_error());
|
|
|
}
|
|
|
cmd_index++;
|
|
|
printf("Commands added: %d\n", cmd_index);
|
|
|
|
|
|
printf("---------------------------------------------------\n");
|
|
|
parser_executor( my_parser, (uint8_t *)"SSA-32768B+32767C-0D-1\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"SA-5B+127C0D-128\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"A+5B+200C0D+88\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"POS+1NEG-1SHAKA\0" );
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef TEST_SEEKER_OF_WAYS_B
|
|
|
|
|
|
|
|
|
my_parser.add_cmd( "PWMR%SL%S\0", (void *)&my_function<int16_t, int16_t> );
|
|
|
|
|
|
printf("---------------------------------------------------\n");
|
|
|
parser_executor( my_parser, (uint8_t *)"PWMR127L127\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"PWMR-127L-127\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"PWMR127L-127\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"PWMR-127L127\0" );
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef TEST_MIXED_TWO_ARGS
|
|
|
|
|
|
bool f_ret = false;
|
|
|
f_ret |= my_parser.add_cmd( "MIXA%u:%U\0", (void *)&my_function<uint8_t,uint16_t> );
|
|
|
f_ret |= my_parser.add_cmd( "MIXB%u:%D\0", (void *)&my_function<uint8_t,uint32_t> );
|
|
|
f_ret |= my_parser.add_cmd( "MIXC%d:%U\0", (void *)&my_function<int32_t,uint16_t> );
|
|
|
|
|
|
if (f_ret == true)
|
|
|
{
|
|
|
printf("Failed to register command!!!\n");
|
|
|
}
|
|
|
|
|
|
printf("---------------------------------------------------\n");
|
|
|
|
|
|
parser_executor( my_parser, (uint8_t *)"MIXA255:65535\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"MIXB255:99999999\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"MIXC-99999999:+9999\0" );
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef TEST_MIXED_THREE_ARGS
|
|
|
|
|
|
bool f_ret = false;
|
|
|
f_ret |= my_parser.add_cmd( "MIXA%u:%U:%D\0", (void *)&my_function<uint8_t,uint16_t,uint32_t> );
|
|
|
f_ret |= my_parser.add_cmd( "MIXB%u:%D:%s\0", (void *)&my_function<uint8_t,uint32_t,int8_t> );
|
|
|
f_ret |= my_parser.add_cmd( "MIXC%d:%U:%U\0", (void *)&my_function<int32_t,uint16_t,uint16_t> );
|
|
|
|
|
|
if (f_ret == true)
|
|
|
{
|
|
|
printf("Failed to register command!!!\n");
|
|
|
}
|
|
|
|
|
|
printf("---------------------------------------------------\n");
|
|
|
|
|
|
parser_executor( my_parser, (uint8_t *)"MIXA255:65535:99999999\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"MIXB255:99999999:-99\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"MIXC-99999999:+9999:9999\0" );
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef TEST_MIXED_FOUR_ARGS
|
|
|
|
|
|
bool f_ret = false;
|
|
|
f_ret |= my_parser.add_cmd( "MIXA%u:%s:%u:%s\0", (void *)&my_function<uint8_t,int8_t,uint8_t,int8_t> );
|
|
|
f_ret |= my_parser.add_cmd( "MIXB%u:%D:%s:%S\0", (void *)&my_function<uint8_t,uint32_t,int8_t,int16_t> );
|
|
|
f_ret |= my_parser.add_cmd( "MIXC%S:%U:%U:%S\0", (void *)&my_function<int16_t,uint16_t,uint16_t,int16_t> );
|
|
|
|
|
|
if (f_ret == true)
|
|
|
{
|
|
|
printf("Failed to register command!!!\n");
|
|
|
}
|
|
|
|
|
|
printf("---------------------------------------------------\n");
|
|
|
|
|
|
parser_executor( my_parser, (uint8_t *)"MIXA255:-128:99:127\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"MIXB255:99999999:-99:-9999\0" );
|
|
|
parser_executor( my_parser, (uint8_t *)"MIXC-9999:+9999:9999:9999\0" );
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DRETURN_ARG("out: %d\n", 0);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void my_noarg_function( void )
|
|
|
{
|
|
|
DENTER();
|
|
|
printf( "EXE | %s -> void\n", __FUNCTION__ );
|
|
|
DRETURN();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
template <typename Ta>
|
|
|
void my_function( Ta arg_a )
|
|
|
{
|
|
|
DENTER_ARG("in: %d\n", arg_a );
|
|
|
printf("EXE | %s -> void | arg: %d\n", __FUNCTION__, arg_a );
|
|
|
DRETURN();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
template <typename Ta, typename Tb>
|
|
|
void my_function( Ta arg_a, Tb arg_b )
|
|
|
{
|
|
|
DENTER_ARG("in: %d %d\n", arg_a, arg_b );
|
|
|
printf("EXE | %s -> void | arg: %d %d\n", __FUNCTION__, arg_a, arg_b );
|
|
|
DRETURN();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
template <typename Ta, typename Tb, typename Tc>
|
|
|
void my_function( Ta arg_a, Tb arg_b, Tc arg_c )
|
|
|
{
|
|
|
DENTER_ARG("in: %d %d %d\n", arg_a, arg_b, arg_c );
|
|
|
printf("EXE | %s -> void | arg: %d %d %d\n", __FUNCTION__, arg_a, arg_b, arg_c );
|
|
|
DRETURN();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
template <typename Ta, typename Tb, typename Tc, typename Td>
|
|
|
void my_function( Ta arg_a, Tb arg_b, Tc arg_c, Td arg_d )
|
|
|
{
|
|
|
DENTER_ARG("in: %d %d %d %d\n", arg_a, arg_b, arg_c, arg_d );
|
|
|
printf("EXE | %s -> void | arg: %d %d %d %d\n", __FUNCTION__, arg_a, arg_b, arg_c, arg_d );
|
|
|
DRETURN();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void parser_executor( Orangebot::Uniparser &my_parser, uint8_t *ptr )
|
|
|
{
|
|
|
|
|
|
DENTER_ARG("in: %d\n", 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t t = 0;
|
|
|
|
|
|
while ((t == 0) || ((t >= 1) && !((ptr[t] == '\0') && (ptr[t-1] == '\0'))))
|
|
|
{
|
|
|
|
|
|
if ((ptr[t] >= '0') || (ptr[t] >= 'z') || (ptr[t] == '-') || (ptr[t] == '+'))
|
|
|
{
|
|
|
printf("feed: >0x%x< >%c<\n", ptr[t], ptr[t]);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf("feed: >0x%x<\n", ptr[t]);
|
|
|
}
|
|
|
|
|
|
my_parser.parse(ptr[t]);
|
|
|
|
|
|
t++;
|
|
|
if (t> 128)
|
|
|
{
|
|
|
printf("infinite loop detected. Maybe you forgot \\0 at end of string?\n");
|
|
|
exit(0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DRETURN();
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
|