mirror of
https://gitee.com/Lamdonn/varch.git
synced 2025-12-06 08:46:42 +08:00
95 lines
1.9 KiB
C
95 lines
1.9 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <float.h>
|
|
#include <math.h>
|
|
#if defined(TEST_TARGET_check)
|
|
#include <varch/command.h>
|
|
#include <varch/check.h>
|
|
#else
|
|
#include "init.h"
|
|
#include "command.h"
|
|
#include "check.h"
|
|
#endif
|
|
|
|
typedef uint8_t (*checkType)(uint8_t* data, uint32_t len);
|
|
|
|
static checkType checkFunTable[] = {
|
|
check_sum,
|
|
check_parity,
|
|
check_lrc,
|
|
check_xor,
|
|
};
|
|
|
|
static void usage(void)
|
|
{
|
|
printf(
|
|
"Usage: check [opt] [arg]\n"
|
|
"\n"
|
|
"options:\n"
|
|
" -h Print help\n"
|
|
" -v Print version\n"
|
|
"\n"
|
|
"argument:\n"
|
|
" <read> Test default read function\n"
|
|
" <write> Test default write function\n"
|
|
);
|
|
}
|
|
|
|
static int test(int argc, char *argv[])
|
|
{
|
|
/* reset getopt */
|
|
command_opt_init();
|
|
|
|
while (1)
|
|
{
|
|
int opt = command_getopt(argc, argv, "hv");
|
|
if (opt == -1) break;
|
|
|
|
switch (opt)
|
|
{
|
|
case 'v' :
|
|
printf("check version %d.%d.%d\r\n", CHECK_V_MAJOR, CHECK_V_MINOR, CHECK_V_PATCH);
|
|
return 0;
|
|
case '?':
|
|
printf("Unknown option `%c`\r\n", command_optopt);
|
|
return -1;
|
|
case 'h' :
|
|
default:
|
|
usage();
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
char *testSample[] = {
|
|
"Hello",
|
|
"check algorithms",
|
|
"123456789",
|
|
};
|
|
uint8_t check = 0;
|
|
for (int i = 0; i < sizeof(testSample) / sizeof(testSample[0]); i++)
|
|
{
|
|
printf("testSample %d\r\n", i);
|
|
for (int j = 0; j < sizeof(checkFunTable) / sizeof(checkFunTable[0]); j++)
|
|
{
|
|
check = (checkFunTable[j])(testSample[i], strlen(testSample[i]));
|
|
printf("Func %d, check %02X\r\n", j, check);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
#if defined(TEST_TARGET_check)
|
|
int main(int argc, char *argv[])
|
|
{
|
|
return test(argc, argv);
|
|
}
|
|
#else
|
|
void test_check(void)
|
|
{
|
|
command_export("check", test);
|
|
}
|
|
init_export_app(test_check);
|
|
#endif
|