fixed non-standard naming and usage

This commit is contained in:
pengyiqiang 2022-08-16 23:56:40 +08:00 committed by Xiang Xiao
parent 2af0fb3815
commit d3232585b0
12 changed files with 115 additions and 111 deletions

View File

@ -39,7 +39,7 @@
#define MONKEY_DEV_CREATE_MATCH(monkey, type_mask, type) \ #define MONKEY_DEV_CREATE_MATCH(monkey, type_mask, type) \
do { \ do { \
if ((type_mask & MONKEY_DEV_TYPE_##type) == MONKEY_DEV_TYPE_##type) \ if (((type_mask) & MONKEY_DEV_TYPE_##type) == MONKEY_DEV_TYPE_##type) \
{ \ { \
FAR struct monkey_dev_s *dev; \ FAR struct monkey_dev_s *dev; \
dev = monkey_dev_create(CONFIG_TESTING_MONKEY_DEV_PATH_##type, \ dev = monkey_dev_create(CONFIG_TESTING_MONKEY_DEV_PATH_##type, \
@ -48,8 +48,8 @@ do { \
{ \ { \
goto failed; \ goto failed; \
} \ } \
monkey->devs[monkey->dev_num] = dev; \ (monkey)->devs[(monkey)->dev_num] = dev; \
monkey->dev_num++; \ (monkey)->dev_num++; \
} \ } \
} while (0) } while (0)
@ -63,9 +63,8 @@ do { \
FAR struct monkey_s *monkey_create(int dev_type_mask) FAR struct monkey_s *monkey_create(int dev_type_mask)
{ {
FAR struct monkey_s *monkey = malloc(sizeof(struct monkey_s)); FAR struct monkey_s *monkey = calloc(1, sizeof(struct monkey_s));
MONKEY_ASSERT_NULL(monkey); MONKEY_ASSERT_NULL(monkey);
memset(monkey, 0, sizeof(struct monkey_s));
if (MONKEY_IS_UINPUT_TYPE(dev_type_mask)) if (MONKEY_IS_UINPUT_TYPE(dev_type_mask))
{ {
@ -106,7 +105,7 @@ void monkey_delete(FAR struct monkey_s *monkey)
for (i = 0; i < monkey->dev_num; i++) for (i = 0; i < monkey->dev_num; i++)
{ {
monkey_dev_delete(monkey->devs[i]); monkey_dev_delete(monkey->devs[i]);
} }
if (monkey->recorder) if (monkey->recorder)

View File

@ -18,8 +18,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __MONKEY_H__ #ifndef __APPS_TESTING_MONKEY_MONKEY_H
#define __MONKEY_H__ #define __APPS_TESTING_MONKEY_MONKEY_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -95,4 +95,4 @@ bool monkey_set_recorder_path(FAR struct monkey_s *monkey,
} }
#endif #endif
#endif /* __MONKEY_H__ */ #endif /* __APPS_TESTING_MONKEY_MONKEY_H */

View File

@ -18,8 +18,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __MONKEY_ASSERT_H__ #ifndef __APPS_TESTING_MONKEY_MONKEY_ASSERT_H
#define __MONKEY_ASSERT_H__ #define __APPS_TESTING_MONKEY_MONKEY_ASSERT_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -34,4 +34,4 @@
#define MONKEY_ASSERT(expr) DEBUGASSERT(expr) #define MONKEY_ASSERT(expr) DEBUGASSERT(expr)
#define MONKEY_ASSERT_NULL(ptr) MONKEY_ASSERT(ptr != NULL) #define MONKEY_ASSERT_NULL(ptr) MONKEY_ASSERT(ptr != NULL)
#endif /* __MONKEY_ASSERT_H__ */ #endif /* __APPS_TESTING_MONKEY_MONKEY_ASSERT_H */

View File

@ -134,6 +134,10 @@ static bool button_read(int fd, FAR uint32_t *value)
return true; return true;
} }
/****************************************************************************
* Public Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: monkey_dev_create * Name: monkey_dev_create
****************************************************************************/ ****************************************************************************/
@ -147,9 +151,8 @@ FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
MONKEY_ASSERT_NULL(dev_path); MONKEY_ASSERT_NULL(dev_path);
dev = malloc(sizeof(struct monkey_dev_s)); dev = calloc(1, sizeof(struct monkey_dev_s));
MONKEY_ASSERT_NULL(dev); MONKEY_ASSERT_NULL(dev);
memset(dev, 0, sizeof(struct monkey_dev_s));
if (MONKEY_IS_UINPUT_TYPE(type)) if (MONKEY_IS_UINPUT_TYPE(type))
{ {
@ -189,10 +192,6 @@ failed:
return NULL; return NULL;
} }
/****************************************************************************
* Public Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: monkey_dev_delete * Name: monkey_dev_delete
****************************************************************************/ ****************************************************************************/
@ -212,7 +211,6 @@ void monkey_dev_delete(FAR struct monkey_dev_s *dev)
MONKEY_LOG_NOTICE("close fd: %d", dev->fd); MONKEY_LOG_NOTICE("close fd: %d", dev->fd);
close(dev->fd); close(dev->fd);
dev->fd = -1;
} }
free(dev); free(dev);
@ -223,25 +221,25 @@ void monkey_dev_delete(FAR struct monkey_dev_s *dev)
****************************************************************************/ ****************************************************************************/
void monkey_dev_set_state(FAR struct monkey_dev_s *dev, void monkey_dev_set_state(FAR struct monkey_dev_s *dev,
FAR const struct monkey_dev_state_s *state) FAR const struct monkey_dev_state_s *state)
{ {
MONKEY_ASSERT_NULL(dev); MONKEY_ASSERT_NULL(dev);
switch (MONKEY_GET_DEV_TYPE(dev->type)) switch (MONKEY_GET_DEV_TYPE(dev->type))
{ {
case MONKEY_DEV_TYPE_TOUCH: case MONKEY_DEV_TYPE_TOUCH:
utouch_write(dev->fd, utouch_write(dev->fd,
state->data.touch.x, state->data.touch.x,
state->data.touch.y, state->data.touch.y,
state->data.touch.is_pressed); state->data.touch.is_pressed);
break; break;
case MONKEY_DEV_TYPE_BUTTON: case MONKEY_DEV_TYPE_BUTTON:
ubutton_write(dev->fd, state->data.button.value); ubutton_write(dev->fd, state->data.button.value);
break; break;
default: default:
break; break;
} }
} }
@ -261,19 +259,19 @@ bool monkey_dev_get_state(FAR struct monkey_dev_s *dev,
switch (dev->type) switch (dev->type)
{ {
case MONKEY_DEV_TYPE_TOUCH: case MONKEY_DEV_TYPE_TOUCH:
retval = touch_read(dev->fd, retval = touch_read(dev->fd,
&state->data.touch.x, &state->data.touch.x,
&state->data.touch.y, &state->data.touch.y,
&state->data.touch.is_pressed); &state->data.touch.is_pressed);
break; break;
case MONKEY_DEV_TYPE_BUTTON: case MONKEY_DEV_TYPE_BUTTON:
retval = button_read(dev->fd, &state->data.button.value); retval = button_read(dev->fd, &state->data.button.value);
break; break;
default: default:
break; break;
} }
return retval; return retval;

View File

@ -18,8 +18,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __MONKEY_DEV_H__ #ifndef __APPS_TESTING_MONKEY_MONKEY_DEV_H
#define __MONKEY_DEV_H__ #define __APPS_TESTING_MONKEY_MONKEY_DEV_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -94,4 +94,4 @@ int monkey_dev_get_available(FAR struct monkey_dev_s *devs[], int dev_num);
} }
#endif #endif
#endif /* __MONKEY_DEV_H__ */ #endif /* __APPS_TESTING_MONKEY_MONKEY_DEV_H */

View File

@ -56,9 +56,10 @@ void monkey_log_printf(enum monkey_log_level_type_e level,
struct va_format vaf; struct va_format vaf;
va_list ap; va_list ap;
static const int priority[_MONKEY_LOG_LEVEL_LAST] = { static const int priority[_MONKEY_LOG_LEVEL_LAST] =
LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR {
}; LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR
};
if (level < g_log_level) if (level < g_log_level)
{ {

View File

@ -18,8 +18,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __MONKEY_LOG_H__ #ifndef __APPS_TESTING_MONKEY_MONKEY_LOG_H
#define __MONKEY_LOG_H__ #define __APPS_TESTING_MONKEY_MONKEY_LOG_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -114,4 +114,4 @@ enum monkey_log_level_type_e monkey_log_get_level(void);
} }
#endif #endif
#endif /* __MONKEY_LOG_H__ */ #endif /* __APPS_TESTING_MONKEY_MONKEY_LOG_H */

View File

@ -43,7 +43,7 @@
do \ do \
{ \ { \
FAR char *ptr; \ FAR char *ptr; \
value = (type)strtoul(optarg, &ptr, base); \ (value) = (type)strtoul(optarg, &ptr, (base)); \
if (*ptr != '\0') \ if (*ptr != '\0') \
{ \ { \
printf(MONKEY_PREFIX "Parameter error: -%c %s\n", ch, optarg); \ printf(MONKEY_PREFIX "Parameter error: -%c %s\n", ch, optarg); \
@ -208,9 +208,11 @@ static void parse_commandline(int argc, FAR char **argv,
case 't': case 't':
OPTARG_TO_VALUE(param->dev_type_mask, int, 16); OPTARG_TO_VALUE(param->dev_type_mask, int, 16);
break; break;
case 'f': case 'f':
param->file_path = optarg; param->file_path = optarg;
break; break;
case 'p': case 'p':
converted = sscanf(optarg, "%d-%d", &period_min, &period_max); converted = sscanf(optarg, "%d-%d", &period_min, &period_max);
if (converted == 2 && period_min >= 0 && period_max >= 0) if (converted == 2 && period_min >= 0 && period_max >= 0)
@ -224,6 +226,7 @@ static void parse_commandline(int argc, FAR char **argv,
show_usage(argv[0], EXIT_FAILURE); show_usage(argv[0], EXIT_FAILURE);
} }
break; break;
case 's': case 's':
converted = sscanf(optarg, "%dx%d", &hor_res, &ver_res); converted = sscanf(optarg, "%dx%d", &hor_res, &ver_res);
if (converted == 2 && hor_res > 0 && ver_res > 0) if (converted == 2 && hor_res > 0 && ver_res > 0)
@ -238,6 +241,7 @@ static void parse_commandline(int argc, FAR char **argv,
show_usage(argv[0], EXIT_FAILURE); show_usage(argv[0], EXIT_FAILURE);
} }
break; break;
case '?': case '?':
printf(MONKEY_PREFIX ": Unknown option: %c\n", optopt); printf(MONKEY_PREFIX ": Unknown option: %c\n", optopt);
show_usage(argv[0], EXIT_FAILURE); show_usage(argv[0], EXIT_FAILURE);

View File

@ -135,9 +135,8 @@ FAR struct monkey_recorder_s *monkey_recorder_create(FAR const char *path,
MONKEY_ASSERT_NULL(path); MONKEY_ASSERT_NULL(path);
recorder = malloc(sizeof(struct monkey_recorder_s)); recorder = calloc(1, sizeof(struct monkey_recorder_s));
MONKEY_ASSERT_NULL(recorder); MONKEY_ASSERT_NULL(recorder);
memset(recorder, 0, sizeof(struct monkey_recorder_s));
if (mode == MONKEY_RECORDER_MODE_RECORD) if (mode == MONKEY_RECORDER_MODE_RECORD)
{ {
@ -198,7 +197,6 @@ void monkey_recorder_delete(FAR struct monkey_recorder_s *recorder)
{ {
MONKEY_LOG_NOTICE("close fd: %d", recorder->fd); MONKEY_LOG_NOTICE("close fd: %d", recorder->fd);
close(recorder->fd); close(recorder->fd);
recorder->fd = -1;
} }
free(recorder); free(recorder);
@ -223,24 +221,26 @@ enum monkey_recorder_res_e monkey_recorder_write(
cur_tick = monkey_tick_get(); cur_tick = monkey_tick_get();
switch (MONKEY_GET_DEV_TYPE(state->type)) switch (MONKEY_GET_DEV_TYPE(state->type))
{ {
case MONKEY_DEV_TYPE_TOUCH: case MONKEY_DEV_TYPE_TOUCH:
len = snprintf(buffer, sizeof(buffer), MONKEY_REC_TOUCH_FMT, len = snprintf(buffer, sizeof(buffer), MONKEY_REC_TOUCH_FMT,
cur_tick, cur_tick,
state->type, state->type,
state->data.touch.x, state->data.touch.x,
state->data.touch.y, state->data.touch.y,
state->data.touch.is_pressed); state->data.touch.is_pressed);
break; break;
case MONKEY_DEV_TYPE_BUTTON:
len = snprintf(buffer, sizeof(buffer), MONKEY_REC_BTN_FMT, case MONKEY_DEV_TYPE_BUTTON:
cur_tick, len = snprintf(buffer, sizeof(buffer), MONKEY_REC_BTN_FMT,
state->type, cur_tick,
state->data.button.value); state->type,
break; state->data.button.value);
default: break;
return MONKEY_RECORDER_RES_DEV_TYPE_ERROR;
} default:
return MONKEY_RECORDER_RES_DEV_TYPE_ERROR;
}
if (len <= 0) if (len <= 0)
{ {
@ -300,32 +300,34 @@ enum monkey_recorder_res_e monkey_recorder_read(
switch (MONKEY_GET_DEV_TYPE(state->type)) switch (MONKEY_GET_DEV_TYPE(state->type))
{ {
case MONKEY_DEV_TYPE_TOUCH: case MONKEY_DEV_TYPE_TOUCH:
converted = sscanf(buffer, converted = sscanf(buffer,
MONKEY_REC_TOUCH_FMT, MONKEY_REC_TOUCH_FMT,
time_stamp, time_stamp,
&dev_type, &dev_type,
&state->data.touch.x, &state->data.touch.x,
&state->data.touch.y, &state->data.touch.y,
&state->data.touch.is_pressed); &state->data.touch.is_pressed);
if (converted != 5) if (converted != 5)
{ {
return MONKEY_RECORDER_RES_PARSER_ERROR; return MONKEY_RECORDER_RES_PARSER_ERROR;
} }
break; break;
case MONKEY_DEV_TYPE_BUTTON:
converted = sscanf(buffer, case MONKEY_DEV_TYPE_BUTTON:
MONKEY_REC_BTN_FMT, converted = sscanf(buffer,
time_stamp, MONKEY_REC_BTN_FMT,
&dev_type, time_stamp,
&state->data.button.value); &dev_type,
if (converted != 3) &state->data.button.value);
{ if (converted != 3)
return MONKEY_RECORDER_RES_PARSER_ERROR; {
} return MONKEY_RECORDER_RES_PARSER_ERROR;
break; }
default: break;
return MONKEY_RECORDER_RES_DEV_TYPE_ERROR;
default:
return MONKEY_RECORDER_RES_DEV_TYPE_ERROR;
} }
return MONKEY_RECORDER_RES_OK; return MONKEY_RECORDER_RES_OK;

View File

@ -18,8 +18,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __MONKEY_RECORDER_H__ #ifndef __APPS_TESTING_MONKEY_MONKEY_RECORDER_H
#define __MONKEY_RECORDER_H__ #define __APPS_TESTING_MONKEY_MONKEY_RECORDER_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -107,4 +107,4 @@ enum monkey_recorder_res_e monkey_recorder_reset(
} }
#endif #endif
#endif /* __MONKEY_RECORDER_H__ */ #endif /* __APPS_TESTING_MONKEY_MONKEY_RECORDER_H */

View File

@ -18,8 +18,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __MONKEY_TYPE_H__ #ifndef __APPS_TESTING_MONKEY_MONKEY_TYPE_H
#define __MONKEY_TYPE_H__ #define __APPS_TESTING_MONKEY_MONKEY_TYPE_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -34,7 +34,7 @@
#define MONKEY_UINPUT_TYPE_MASK (0x10) #define MONKEY_UINPUT_TYPE_MASK (0x10)
#define MONKEY_IS_UINPUT_TYPE(type) (!!((type) & MONKEY_UINPUT_TYPE_MASK)) #define MONKEY_IS_UINPUT_TYPE(type) (!!((type) & MONKEY_UINPUT_TYPE_MASK))
#define MONKEY_GET_DEV_TYPE(type) (type & ~MONKEY_UINPUT_TYPE_MASK) #define MONKEY_GET_DEV_TYPE(type) ((type) & ~MONKEY_UINPUT_TYPE_MASK)
#define MONKEY_DEV_MAX_NUM 2 #define MONKEY_DEV_MAX_NUM 2
/**************************************************************************** /****************************************************************************
@ -110,9 +110,9 @@ struct monkey_s
FAR struct monkey_recorder_s *recorder; FAR struct monkey_recorder_s *recorder;
struct struct
{ {
struct monkey_dev_state_s state; struct monkey_dev_state_s state;
uint32_t time_stamp; uint32_t time_stamp;
} playback_ctx; } playback_ctx;
}; };
#endif /* __MONKEY_TYPE_H__ */ #endif /* __APPS_TESTING_MONKEY_MONKEY_TYPE_H */

View File

@ -18,8 +18,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __MONKEY_UTILS_H__ #ifndef __APPS_TESTING_MONKEY_MONKEY_UTILS_H
#define __MONKEY_UTILS_H__ #define __APPS_TESTING_MONKEY_MONKEY_UTILS_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -91,4 +91,4 @@ enum monkey_dev_type_e monkey_dev_name2type(FAR const char *name);
} }
#endif #endif
#endif /* __MONKEY_UTILS_H__ */ #endif /* __APPS_TESTING_MONKEY_MONKEY_UTILS_H */