From 39e4539925687d46c7bbe04681dcc09757dc9ae2 Mon Sep 17 00:00:00 2001 From: wanglu Date: Thu, 28 Mar 2019 09:31:38 +0800 Subject: Fix review problems: 1.Add autobuild 2.Replace literal with notation in tsutils/tsrecorder/tsrecorder.c 3.Update LICENSE and COPYRIGHT This is a logging app with following functions included: 1.video recording 2.Audio recording 3.Can data recording & playing 4.Screen touch event recording & playing Change-Id: Id7942e16f87e69d25240f4985d3c47bc262d25c2 Signed-off-by: wanglu --- tsutils/tsplayer/tsplayer.c | 332 ++++++++++++++++++++++++++++++++++++++ tsutils/tsplayer/tsplayer.pro | 7 + tsutils/tsrecorder/tsrecorder.c | 150 +++++++++++++++++ tsutils/tsrecorder/tsrecorder.pro | 7 + tsutils/tsutils.c | 95 +++++++++++ tsutils/tsutils.pro | 2 + 6 files changed, 593 insertions(+) create mode 100644 tsutils/tsplayer/tsplayer.c create mode 100644 tsutils/tsplayer/tsplayer.pro create mode 100644 tsutils/tsrecorder/tsrecorder.c create mode 100644 tsutils/tsrecorder/tsrecorder.pro create mode 100644 tsutils/tsutils.c create mode 100644 tsutils/tsutils.pro (limited to 'tsutils') diff --git a/tsutils/tsplayer/tsplayer.c b/tsutils/tsplayer/tsplayer.c new file mode 100644 index 0000000..f0ab6f7 --- /dev/null +++ b/tsutils/tsplayer/tsplayer.c @@ -0,0 +1,332 @@ +/* + * Copyright (c) 2019 TOYOTA MOTOR CORPORATION + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +typedef struct List +{ + int operIndex; + int seconds; + int microseconds; + uint16_t event_Type; + uint16_t event_Code; + float event_Value; + struct List *nextGp; +}List; + +List *eventListHeader; +List *eventListLast1; +List *eventListLast2; +List *eventListLast3; + +int touchScreenFd; + +extern char* getTouchScreenInfo(); + +void deleteEventList() { + List *prevItem = eventListHeader; + List *nextItem = prevItem->nextGp; + while(prevItem && nextItem) { + free(prevItem); + prevItem = nextItem; + nextItem = nextItem->nextGp; + } + + if (prevItem) { + free(prevItem); + } +} + +void initEventList() +{ + eventListHeader = (struct List*)malloc(sizeof(struct List)); + + if (!eventListHeader) + { + printf("init event list failed. Exit\n"); + exit(0); + } + else + { + memset(eventListHeader,0,sizeof(struct List)); + eventListHeader->nextGp = NULL; + } + + eventListLast1 = NULL; + eventListLast2 = NULL; + eventListLast3 = NULL; +} + +void checkTouchUp(List *temp) +{ + if((temp->event_Type == 3) && (temp->event_Code == 57) && (temp->event_Value == -1)) + { + if(eventListLast1 == NULL) + { + eventListLast1 = temp; + } + else if(eventListLast2 == NULL) + { + eventListLast2 = eventListLast1; + eventListLast1 = temp; + } + else + { + eventListLast3 = eventListLast2; + eventListLast2 = eventListLast1; + eventListLast1 = temp; + } + } +} + +void deleteRedundantData() +{ + List *prevItem = eventListLast3->nextGp->nextGp->nextGp; + List *nextItem = prevItem->nextGp; + while(prevItem && nextItem) { + free(prevItem); + prevItem = nextItem; + nextItem = nextItem->nextGp; + } + + if (prevItem) { + free(prevItem); + } +} + +bool tailCreatList(char *fname) +{ + List *tmpData; + List *tail; + + char buffer[512]; + + FILE *inFile; + inFile = fopen(fname,"r"); + + if (inFile == NULL) + { + printf("\nFailed to open the file : %s . Exit\n",fname); + exit(0); + } + + initEventList(); + tail = eventListHeader; + + memset(buffer,0,sizeof(buffer)); + + while(fgets(buffer,sizeof(buffer),inFile)) + { + tmpData = (struct List*)malloc(sizeof(struct List)); + if (!tmpData) + { + printf("Faild to create event list. Exit\n"); + fclose(inFile); + exit(0); + } + + memset(tmpData,0,sizeof(struct List)); + + tmpData->nextGp = NULL; + sscanf(buffer,"%d %d %d %hu %hu %f",&(tmpData->operIndex),&(tmpData->seconds),&(tmpData->microseconds),&(tmpData->event_Type),&(tmpData->event_Code),&(tmpData->event_Value)); + + checkTouchUp(tmpData); + tail->nextGp = tmpData; + tail = tmpData; + + memset(buffer,0,sizeof(buffer)); + } + + if(eventListLast3 != NULL) + { + tail = eventListLast3->nextGp->nextGp; + deleteRedundantData(); + } + else + { + deleteEventList(); + return false; + } + + tail->nextGp = NULL; + + fclose(inFile); + + return true; +} + +int reportKey(int fd, uint16_t type, uint16_t code, int32_t value) +{ + struct input_event event; + event.type = type; + event.code = code; + event.value = value; + + gettimeofday(&event.time, 0); + + if (write(fd, &event, sizeof(struct input_event)) < 0) { + printf("report key error!\n"); + return -1; + } + + return 0; +} + +void touchEventTest(List *listHeader, int screenWidth, int screenHeight, + int delayTime) +{ + List *p = listHeader->nextGp; + printf("--------Touch Event Test Start!!!--------\n"); + + while(p != NULL) + { + if ((p->event_Type == 3) && ((p->event_Code == 53) || (p->event_Code == 0))) + { + reportKey(touchScreenFd,p->event_Type,p->event_Code,p->event_Value * screenWidth); + } + else if ((p->event_Type == 3) && ((p->event_Code == 54) || (p->event_Code == 1))) + { + reportKey(touchScreenFd,p->event_Type,p->event_Code,p->event_Value * screenHeight); + } + else + { + reportKey(touchScreenFd,p->event_Type,p->event_Code,p->event_Value); + } + + if (p->nextGp != NULL) + { + usleep((p->nextGp->seconds - p->seconds) * 1000000 + (p->nextGp->microseconds - p->microseconds)); + } + + p = p->nextGp; + + } + printf("--------Touch Event Test End!!!--------\n"); +} + +int appNeedEventTestStart(int tsWidth, int tsHeight, char* eventNode, + char* eventFile, int delayTime) +{ + touchScreenFd = open(eventNode, O_RDWR); + + if (touchScreenFd < 0) + { + printf("Open %s failed.\n", eventNode); + return -1; + } + + if(tailCreatList(eventFile)) + { + touchEventTest(eventListHeader, tsWidth, tsHeight, delayTime); + deleteEventList(); + } + + close(touchScreenFd); + + return 1; +} + +void printUsage(char* myName) +{ + printf("usage:\n \ + %s -a -d -c -e -f \n \ + -a : application name(must)\n \ + -d : the time interval(> 0) for capturing logs(unit:ms)(must).\n \ + -c : child process name(s).If more than one, sperated by ','. \n\t\tEg. -c process1,prcocess2,process3.\n \ + -f : file name for recorded event. If -e is 1, then -f must be specified.\n \ + -e : 1 for apps that need events, 0 for apps that does not need events.Default is 0. \n", myName); +} + +int main(int argc,char *argv[]) +{ + int index = 0; + int screenWidth, screenHeight; + char eventFileName[100]; + char eventNode[50]; + const char* tsInfo; + int needEvents = 0; + int delayTime = 0; + + if (argc < 5) + { + printUsage(argv[0]); + return -1; + } + + memset(eventFileName, 0, sizeof(eventFileName)); + memset(eventNode, 0, sizeof(eventNode)); + + for (index = 1; index < argc; index ++) + { + if (strcmp(argv[index], "-f") == 0) + { + memcpy(eventFileName, argv[++index], strlen(argv[index])); + } + else if (strcmp(argv[index], "-d") == 0) + { + delayTime = atoi(argv[++index]); + } + else if (strcmp(argv[index], "-e") == 0) + { + needEvents = atoi(argv[++index]); + } + else + { + printUsage(argv[0]); + return -1; + } + } + + if (0 == delayTime) { + printf("Please specify an interval time(> 0)\n"); + printUsage(argv[0]); + return -1; + } + + printf("step %d. \n", __LINE__); + if ((1 == needEvents) && (0 == strlen(eventFileName))) { + printf("You should specify a file for recorded event.\n"); + printUsage(argv[0]); + return -1; + } + printf("step %d. \n", __LINE__); + + if (1 == needEvents) + { + printf("step %d. \n", __LINE__); + tsInfo = getTouchScreenInfo(); + printf("step %d. \n", __LINE__); + if (NULL == tsInfo) { + printf("Failed to get touch screen info.\n"); + return -1; + } + printf("step %d. tsInfo = %s. \n", __LINE__, tsInfo); + + sscanf(tsInfo, "%s %d %d", eventNode, &screenWidth, &screenHeight); + appNeedEventTestStart(screenWidth, screenHeight, eventNode, eventFileName, + delayTime); + printf("step %d. \n", __LINE__); + + } + return 0; +} diff --git a/tsutils/tsplayer/tsplayer.pro b/tsutils/tsplayer/tsplayer.pro new file mode 100644 index 0000000..8ff7cce --- /dev/null +++ b/tsutils/tsplayer/tsplayer.pro @@ -0,0 +1,7 @@ +TARGET = tsplayer + +DESTDIR = $${OUT_PWD}/../../package/root/bin + +SOURCES += \ + tsplayer.c \ + ../tsutils.c diff --git a/tsutils/tsrecorder/tsrecorder.c b/tsutils/tsrecorder/tsrecorder.c new file mode 100644 index 0000000..9c2e466 --- /dev/null +++ b/tsutils/tsrecorder/tsrecorder.c @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2019 TOYOTA MOTOR CORPORATION + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +static int eventFd = -1; +static FILE* pfile; +struct input_event ev0[64]; +static int screenWidth = 0; +static int screenHeight = 0; + +extern char* getTouchScreenInfo(); + +static int handle_event() +{ + int i, rd; + char str[256]; + float x = 0, y = 0; + + rd = read(eventFd, ev0, sizeof(struct input_event)* 64); + + if(rd < sizeof(struct input_event)) + return 0; + + for(i=0;i\n \ + -f : file name for recording event\n", myName); +} + +int main(int argc,char *argv[]) +{ + int done = 1; + int index = 0; + char* fName = NULL; + char eventNode[50]; + const char* tsInfo; + + if (argc < 3) + { + printUsage(argv[0]); + return -1; + } + + for (index = 1; index < argc; index++) + { + if (strcmp(argv[index], "-f") == 0) + { + fName = argv[++index]; + } + else + { + printUsage(argv[0]); + return -1; + } + } + + tsInfo = getTouchScreenInfo(); + if (NULL == tsInfo) { + printf("Failed to get touch screen info.\n"); + return -1; + } + + memset(eventNode, 0, sizeof(eventNode)); + sscanf(tsInfo, "%s %d %d", eventNode, &screenWidth, &screenHeight); + + eventFd = open(eventNode, O_RDWR); + if(eventFd <0) { + printf("open input device error\n"); + return -1; + } + + pfile = fopen(fName, "wb+"); + if(pfile == NULL) + { + printf("Failed to create file!\n"); + return -1; + } + + while (done) + { + printf("begin %s...\n", eventNode); + done = handle_event(); + printf("end %s...\n", eventNode); + } + + fclose(pfile); + + if(eventFd > 0) + { + close(eventFd); + eventFd = -1; + } + + return 0; +} diff --git a/tsutils/tsrecorder/tsrecorder.pro b/tsutils/tsrecorder/tsrecorder.pro new file mode 100644 index 0000000..3c3988b --- /dev/null +++ b/tsutils/tsrecorder/tsrecorder.pro @@ -0,0 +1,7 @@ +TARGET = tsrecorder + +DESTDIR = $${OUT_PWD}/../../package/root/bin + +SOURCES += \ + tsrecorder.c \ + ../tsutils.c diff --git a/tsutils/tsutils.c b/tsutils/tsutils.c new file mode 100644 index 0000000..79385d1 --- /dev/null +++ b/tsutils/tsutils.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2019 TOYOTA MOTOR CORPORATION + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include + +#define LONG_BITS (sizeof(long) << 3) +#define NUM_LONGS(bits) (((bits) + LONG_BITS - 1) / LONG_BITS) +#define DEV_INPUT "/dev/input" + +char tsInfo[200]; + +static inline int testBit(long bit, const long *array) { + return (array[bit / LONG_BITS] >> bit % LONG_BITS) & 1; +} + +char* getTouchScreenInfo() { + DIR* dir; + struct dirent* itemPtr; + int fd; + int isSingleTouch = 0, hasTouchScreen = 0; + long absbits[NUM_LONGS(ABS_CNT)]; + char tsDevNode[100]; + struct input_absinfo absInfo; + + int maxX, maxY; + + memset(tsDevNode, 0, sizeof(tsDevNode)); + memset(tsInfo, 0, sizeof(tsInfo)); + + if ((dir = opendir(DEV_INPUT)) == NULL) { + printf("open %s failed.\n", DEV_INPUT); + return NULL; + } + + while ((itemPtr = readdir(dir)) != NULL) { + //printf("name : %s---type : %d\n", itemPtr->d_name, itemPtr->d_type); + if ((strstr(itemPtr->d_name, "event") != NULL) && (2 == itemPtr->d_type)) { + sprintf(tsDevNode, "%s/%s", DEV_INPUT, itemPtr->d_name); + fd = open(tsDevNode, O_RDONLY); + if (fd < 0) { + printf("open %s failed.\n", tsDevNode); + return NULL; + } + + if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits) >= 0) { + isSingleTouch = !testBit(ABS_MT_POSITION_X, absbits); + } else { + close(fd); + continue; + } + + if (ioctl(fd, EVIOCGABS((isSingleTouch ? ABS_X : ABS_MT_POSITION_X)), &absInfo) >= 0) { + maxX = absInfo.maximum; + } else { + close(fd); + continue; + } + + if (ioctl(fd, EVIOCGABS((isSingleTouch ? ABS_Y : ABS_MT_POSITION_Y)), &absInfo) >= 0) { + maxY = absInfo.maximum; + } else { + close(fd); + continue; + } + + hasTouchScreen = 1; + break; + } + } + + if (!hasTouchScreen) return NULL; + + sprintf(tsInfo, "%s %d %d", tsDevNode, maxX, maxY); + + close(fd); + closedir(dir); + return tsInfo; +} diff --git a/tsutils/tsutils.pro b/tsutils/tsutils.pro new file mode 100644 index 0000000..ed02c62 --- /dev/null +++ b/tsutils/tsutils.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = tsplayer tsrecorder \ No newline at end of file -- cgit 1.2.3-korg