cycletime可选,优化显示

This commit is contained in:
Chinky 2024-01-14 14:47:33 +08:00
parent 8479266ba2
commit 1970f178fd

View File

@ -43,7 +43,7 @@
#define NSEC_PER_SEC 1000000000
#define EC_TIMEOUTMON 500
#define TEST_STEP_CYCLETIME (500 * 1000) // us
#define INPUT_CHECK_TIMEOUT (10 * 1000) // us
#define INPUT_CHECK_TIMEOUT (5 * 1000) // us
#define MAX_SLAVE 8
#define ROL_U16(a, n) ((uint16_t)((a) << (n) | (a) >> (16 - n)))
@ -54,13 +54,13 @@
#define SET_BIT(value, bit) ((value) &= ~(1 << (bit))) // 把某个位置0
#define CLR_BIT(value, bit) ((value) |= (1 << (bit))) // 把某个位置1
#define show_err(fmt, ...) \
do \
{ \
/* 擦除行, 输出 */ \
sprintf(err.str + strlen(err.str), CSI_START "K" fmt, ##__VA_ARGS__); \
err.cnt++; \
err.is_showed = false; \
#define show_err(fmt, ...) \
do \
{ \
/* 擦除行, 输出 */ \
sprintf(err.str + strlen(err.str), CSI_START "2K" fmt, ##__VA_ARGS__); \
err.cnt++; \
err.is_showed = false; \
} while (0)
#define time_cmp(a, b, CMP) \
@ -84,6 +84,7 @@ pthread_t thread1, thread2;
struct timeval tv, t1, t2;
int32_t dorun = 0;
int32_t test_step = 0;
int32_t test_cycle = 0;
int deltat, tmax = 0;
int64 toff, gl_delta;
int DCdiff;
@ -95,6 +96,7 @@ int expectedWKC;
volatile int wkc;
boolean inOP;
uint8 currentgroup = 0;
static int cycletime;
static struct
{
@ -205,14 +207,14 @@ static void show_check(void)
err.str[0] = '\0';
err.is_showed = true;
}
printf("ID | Type | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |\n"
"---+------+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+\n");
printf("ID | Type | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |\n"
"---+-------+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+\n");
for (int i = 1; i <= ec_slavecount; i++)
{
char buff[512];
char *p = buff;
// show output / input
p += sprintf(p, "%2d |Out/In|", i);
p += sprintf(p, "%2d | Out/In|", i);
int j = 0;
for (; j < io_test[i].output_bytes; j++)
{
@ -244,7 +246,7 @@ static void show_check(void)
p += sprintf(p, " | | | | | | | |");
}
// show diff
p += sprintf(p, "\n | Diff |");
p += sprintf(p, "\n |Diff/ms|");
j = 0;
for (; j < io_test[i].input_bytes; j++)
{
@ -267,7 +269,7 @@ static void show_check(void)
p += sprintf(p, " | | | | | | | |");
}
// show max
p += sprintf(p, "\n | Max |");
p += sprintf(p, "\n | Max/ms|");
j = 0;
for (; j < io_test[i].input_bytes; j++)
{
@ -307,12 +309,12 @@ static void show_check(void)
{
p += sprintf(p, " | | | | | | | |");
}
p += sprintf(p, "\n---+------+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+\n");
p += sprintf(p, "\n---+-------+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+\n");
printf("%s", buff);
}
printf("Processdata cycle %5d, test step %3d, Wck %3d, DCtime %12" PRId64 ", dt %6" PRId64 "ns\n",
dorun, test_step, wkc, ec_DCtime, gl_delta);
printf("Error count %lu " SET_COLOR(F_B_RED, "(Press 'q' to exit)\n"), err.cnt);
printf("Processdata cycle %5d, cycletime %dus, Wck %3d, DCtime %12" PRId64 "ns, dt " CSI_START "K" /*擦除到行尾*/ "%6" PRId64 "ns\n",
dorun, cycletime, wkc, ec_DCtime, gl_delta);
printf("Test cycle %d, Test step %3d, Error count %lu " SET_COLOR(F_B_RED, "(Press 'q' to exit)\n"), test_cycle, test_step, err.cnt);
fflush(stdout);
osal_usleep(50000);
@ -511,6 +513,7 @@ static void write_output(void)
if (list_idx >= ARRAY_SIZE(test_list))
{
list_idx = 0;
test_cycle++;
}
ec_timet current_time = osal_current_time();
@ -657,27 +660,29 @@ OSAL_THREAD_FUNC ecatcheck(void *ptr)
int main(int argc, char *argv[])
{
int ctime;
cycletime = 50;
printf("SOEM (Simple Open EtherCAT Master)\nIO test for TJ30-XXXX\n");
if (argc == 3)
switch (argc)
{
case 3:
cycletime = atoi(argv[2]);
[[fallthrough]];
case 2:
dorun = 0;
ctime = atoi(argv[2]);
/* create RT thread */
osal_thread_create_rt(&thread1, stack64k * 2, &ecatthread, (void *)&ctime);
osal_thread_create_rt(&thread1, stack64k * 2, &ecatthread, (void *)&cycletime);
/* create thread to handle slave error handling in OP */
osal_thread_create(&thread2, stack64k * 4, &ecatcheck, NULL);
/* start acyclic part */
tj30_test(argv[1]);
}
else
{
printf("Usage: red_test ifname1 cycletime\nifname = eth0 for example\ncycletime in us\n");
break;
default:
printf("Usage: tj30_test ifname [cycletime]\n"
"ifname = eth0 for example\n"
"cycletime in us(default is 50us)\n");
ec_adaptert *adapter = NULL;
printf("\nAvailable adapters:\n");