更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
watch_shellcmd.c 文件参考

浏览源代码.

结构体

struct  WatchCB
 

函数

STATIC VOID PrintTime (VOID)
 
STATIC VOID OsShellCmdDoWatch (UINTPTR arg1)
 
STATIC INLINE VOID OsWatchCmdUsage (VOID)
 
STATIC UINT32 OsWatchOverFunc (VOID)
 
INT32 OsWatchOptionParsed (UINT32 argc, UINT32 *argoff, const CHAR **argv, WatchCB *watchItem)
 
INT32 OsWatchCmdSplice (UINT32 argc, UINT32 argoff, const CHAR **argv, WatchCB *watchItem)
 
UINT32 OsWatchTaskCreate (WatchCB *watchItem)
 
UINT32 OsShellCmdWatch (UINT32 argc, const CHAR **argv)
 
 SHELLCMD_ENTRY (watch_shellcmd, CMD_TYPE_EX, "watch", XARGS,(CmdCallBackFunc) OsShellCmdWatch)
 

变量

STATIC WatchCBg_watchCmd
 

函数说明

◆ OsShellCmdDoWatch()

STATIC VOID OsShellCmdDoWatch ( UINTPTR  arg1)

在文件 watch_shellcmd.c69 行定义.

70{
71 WatchCB *watchItem = (WatchCB *)arg1;
72 UINT32 ret;
73 g_watchCmd = watchItem;
74
75 while (watchItem->count--) {
76 printf("\033[2J\n");
77 if (watchItem->title) {
78 PrintTime();
79 }
80 (VOID)ShellMsgParse(watchItem->cmdbuf);
81 ret = LOS_EventRead(&watchItem->watchEvent, 0x01, LOS_WAITMODE_OR | LOS_WAITMODE_CLR, watchItem->interval);
82 if (ret == 0x01) {
83 break;
84 }
85 }
86
87 (VOID)LOS_EventDestroy(&watchItem->watchEvent);
89 g_watchCmd = NULL;
90}
LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB)
销毁指定的事件控制块
Definition: los_event.c:334
LITE_OS_SEC_TEXT UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout)
读取指定事件类型,超时时间为相对时间:单位为Tick
Definition: los_event.c:313
unsigned int UINT32
Definition: los_typedef.h:57
void free(void *ptr)
释放ptr所指向的内存空间
Definition: malloc.c:66
UINT32 ShellMsgParse(const VOID *msg)
命令内容解析
Definition: shmsg.c:289
UINT32 count
UINT32 interval
CHAR cmdbuf[CMD_MAX_LEN]
BOOL title
EVENT_CB_S watchEvent
STATIC WatchCB * g_watchCmd
STATIC VOID PrintTime(VOID)
函数调用图:
这是这个函数的调用关系图:

◆ OsShellCmdWatch()

UINT32 OsShellCmdWatch ( UINT32  argc,
const CHAR **  argv 
)

在文件 watch_shellcmd.c216 行定义.

217{
218 WatchCB *watchItem = NULL;
219 UINT32 argoff = 0;
220 UINT32 ret;
221 INT32 err;
222
223 if (argc == 0) {
225 return OS_ERROR;
226 }
227
228 if (argv == NULL) {
230 return OS_ERROR;
231 }
232
233 if ((argc == 1) && (strcmp(argv[0], "--over") == 0)) {
234 ret = OsWatchOverFunc();
235 return ret;
236 }
237
238 if (g_watchCmd != NULL) {
239 PRINTK("Please turn off previous watch before to start a new watch.\n");
240 return OS_ERROR;
241 }
242
243 watchItem = (WatchCB *)malloc(sizeof(WatchCB));
244 if (watchItem == NULL) {
245 PRINTK("Malloc error!\n");
246 return OS_ERROR;
247 }
248 (VOID)memset_s(watchItem, sizeof(WatchCB), 0, sizeof(WatchCB));
249 watchItem->title = TRUE;
250 watchItem->count = WATCH_COUNT_MAX;
251 watchItem->interval = g_tickPerSecond;
252
253 err = OsWatchOptionParsed(argc, &argoff, argv, watchItem);
254 if (err != 0) {
255 goto WATCH_ERROR;
256 }
257
258 err = OsWatchCmdSplice(argc, argoff, argv, watchItem);
259 if (err != 0) {
260 goto WATCH_ERROR;
261 }
262
263 ret = OsWatchTaskCreate(watchItem);
264 if (ret != 0) {
265 goto WATCH_ERROR;
266 }
267
268 return LOS_OK;
269
270WATCH_ERROR:
271 free(watchItem);
272 return OS_ERROR;
273}
LITE_OS_SEC_DATA_INIT UINT32 g_tickPerSecond
每秒Tick数,鸿蒙默认是每秒100次,即:10ms
Definition: los_tick.c:41
signed int INT32
Definition: los_typedef.h:60
void * malloc(size_t size)
动态分配内存块大小
Definition: malloc.c:81
STATIC UINT32 OsWatchOverFunc(VOID)
INT32 OsWatchOptionParsed(UINT32 argc, UINT32 *argoff, const CHAR **argv, WatchCB *watchItem)
STATIC INLINE VOID OsWatchCmdUsage(VOID)
INT32 OsWatchCmdSplice(UINT32 argc, UINT32 argoff, const CHAR **argv, WatchCB *watchItem)
UINT32 OsWatchTaskCreate(WatchCB *watchItem)
函数调用图:

◆ OsWatchCmdSplice()

INT32 OsWatchCmdSplice ( UINT32  argc,
UINT32  argoff,
const CHAR **  argv,
WatchCB watchItem 
)

在文件 watch_shellcmd.c166 行定义.

167{
168 INT32 err = 0;
169 if ((argc - argoff) == 0) {
170 PRINT_ERR("no watch command!\n");
171 return -1;
172 }
173 while (argc - argoff) {
174 err = strcat_s(watchItem->cmdbuf, sizeof(watchItem->cmdbuf), argv[argoff]);
175 if (err != EOK) {
176 PRINT_ERR("%s, %d strcat_s failed!\n", __FUNCTION__, __LINE__);
177 return -1;
178 }
179 err = strcat_s(watchItem->cmdbuf, sizeof(watchItem->cmdbuf), " ");
180 if (err != EOK) {
181 PRINT_ERR("%s, %d strcat_s failed!\n", __FUNCTION__, __LINE__);
182 return -1;
183 }
184 argoff++;
185 }
186 return err;
187}
这是这个函数的调用关系图:

◆ OsWatchCmdUsage()

STATIC INLINE VOID OsWatchCmdUsage ( VOID  )

在文件 watch_shellcmd.c92 行定义.

93{
94 PRINTK("\nUsage: watch\n");
95 PRINTK("watch [options] command\n");
96}
这是这个函数的调用关系图:

◆ OsWatchOptionParsed()

INT32 OsWatchOptionParsed ( UINT32  argc,
UINT32 argoff,
const CHAR **  argv,
WatchCB watchItem 
)

在文件 watch_shellcmd.c114 行定义.

115{
116 long tmpVal;
117 CHAR *strPtr = NULL;
118 UINT32 argcount = argc;
119
120 while (argv[*argoff][0] == '-') {
121 if (argcount <= 1) {
123 return -1;
124 }
125
126 if ((strcmp(argv[*argoff], "-n") == 0) || (strcmp(argv[*argoff], "--interval") == 0)) {
127 if (argcount <= 2) { /* 2:count of parameter */
129 return -1;
130 }
131 tmpVal = (long)strtoul(argv[*argoff + 1], &strPtr, 0);
132 if ((*strPtr != 0) || (tmpVal <= 0) || (tmpVal > WATCH_INTERTVAL_MAX)) {
133 PRINTK("\ninterval time is invalid\n");
135 return -1;
136 }
137 watchItem->interval = g_tickPerSecond * (UINT32)tmpVal;
138 argcount -= 2; /* 2:offset of argv */
139 (*argoff) += 2; /* 2:offset of argv */
140 } else if ((strcmp(argv[*argoff], "-t") == 0) || (strcmp(argv[*argoff], "-no-title") == 0)) {
141 watchItem->title = FALSE;
142 argcount--;
143 (*argoff)++;
144 } else if ((strcmp(argv[*argoff], "-c") == 0) || (strcmp(argv[*argoff], "--count") == 0)) {
145 if (argcount <= 2) { /* 2:count of parameter */
147 return -1;
148 }
149 tmpVal = (long)strtoul(argv[*argoff + 1], &strPtr, 0);
150 if ((*strPtr != 0) || (tmpVal <= 0) || (tmpVal > WATCH_COUNT_MAX)) {
151 PRINTK("\ncount is invalid\n");
153 return -1;
154 }
155 watchItem->count = (UINT32)tmpVal;
156 argcount -= 2; /* 2:offset of argv */
157 (*argoff) += 2; /* 2:offset of argv */
158 } else {
159 PRINTK("Unknown option.\n");
160 return -1;
161 }
162 }
163 return 0;
164}
char CHAR
Definition: los_typedef.h:63
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 ARG_NUM_0 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_6 ARG_NUM_3 ARG_NUM_5 ARG_NUM_7 ARG_NUM_1 ARG_NUM_4 ARG_NUM_5 ARG_NUM_4 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_7 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_7 ARG_NUM_3 ARG_NUM_2 char ARG_NUM_2 ARG_NUM_1 ARG_NUM_0 ARG_NUM_0 ARG_NUM_3 void ARG_NUM_1 ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_5 ARG_NUM_3 ARG_NUM_3 ARG_NUM_4 ARG_NUM_1 ARG_NUM_1 ARG_NUM_3 ARG_NUM_2 ARG_NUM_1 ARG_NUM_4 ARG_NUM_4 ARG_NUM_5 ARG_NUM_3 ARG_NUM_2 void ARG_NUM_6 unsigned ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_3 ARG_NUM_3 ARG_NUM_2 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_1 char ARG_NUM_0 ARG_NUM_4 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_2 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_6 ARG_NUM_6 ARG_NUM_5 ARG_NUM_3 void ARG_NUM_3 ARG_NUM_3 ARG_NUM_5 ARG_NUM_1 unsigned ARG_NUM_3 long
函数调用图:
这是这个函数的调用关系图:

◆ OsWatchOverFunc()

STATIC UINT32 OsWatchOverFunc ( VOID  )

在文件 watch_shellcmd.c98 行定义.

99{
100 UINT32 ret;
101 if (g_watchCmd != NULL) {
102 ret = LOS_EventWrite(&g_watchCmd->watchEvent, 0x01);
103 if (ret != LOS_OK) {
104 PRINT_ERR("Write event failed in %s,%d\n", __FUNCTION__, __LINE__);
105 return OS_ERROR;
106 }
107 return LOS_OK;
108 } else {
109 PRINTK("No watch task to turn off.\n");
110 return OS_ERROR;
111 }
112}
LITE_OS_SEC_TEXT UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events)
写指定的事件类型
Definition: los_event.c:318
函数调用图:
这是这个函数的调用关系图:

◆ OsWatchTaskCreate()

UINT32 OsWatchTaskCreate ( WatchCB watchItem)

在文件 watch_shellcmd.c189 行定义.

190{
191 TSK_INIT_PARAM_S initParam = {0};
192 UINT32 watchTaskId = 0;
193 UINT32 ret;
194
195 ret = LOS_EventInit(&watchItem->watchEvent);
196 if (ret != 0) {
197 PRINT_ERR("Watch event init failed in %s, %d\n", __FUNCTION__, __LINE__);
198 return ret;
199 }
200
202 initParam.usTaskPrio = 10; /* 10:shellcmd_watch task priority */
203 initParam.auwArgs[0] = (UINTPTR)watchItem;
204 initParam.uwStackSize = 0x3000; /* 0x3000:stack size of shellcmd_watch task */
205 initParam.pcName = "shellcmd_watch";
206 initParam.uwResved = LOS_TASK_STATUS_DETACHED;
207
208 ret = LOS_TaskCreate(&watchTaskId, &initParam);
209 if (ret != 0) {
210 PRINT_ERR("Watch task init failed in %s, %d\n", __FUNCTION__, __LINE__);
211 return ret;
212 }
213 return ret;
214}
LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventInit(PEVENT_CB_S eventCB)
初始化一个事件控制块
Definition: los_event.c:95
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskID, TSK_INIT_PARAM_S *initParam)
创建任务,并使该任务进入ready状态,如果就绪队列中没有更高优先级的任务,则运行该任务
Definition: los_task.c:718
VOID *(* TSK_ENTRY_FUNC)(UINTPTR param1, UINTPTR param2, UINTPTR param3, UINTPTR param4)
Define the type of a task entrance function.
Definition: los_task.h:480
unsigned long UINTPTR
Definition: los_typedef.h:68
UINT16 usTaskPrio
Definition: los_task.h:505
UINTPTR auwArgs[4]
Definition: los_task.h:507
UINT32 uwStackSize
Definition: los_task.h:508
CHAR * pcName
Definition: los_task.h:509
TSK_ENTRY_FUNC pfnTaskEntry
Definition: los_task.h:504
UINT32 uwResved
Definition: los_task.h:513
STATIC VOID OsShellCmdDoWatch(UINTPTR arg1)
函数调用图:
这是这个函数的调用关系图:

◆ PrintTime()

STATIC VOID PrintTime ( VOID  )

在文件 watch_shellcmd.c60 行定义.

61{
62 struct timeval64 stNowTime = {0};
63
64 if (gettimeofday64(&stNowTime, NULL) == 0) {
65 PRINTK("%s", ctime64(&(stNowTime.tv_sec)));
66 }
67}
int gettimeofday64(struct timeval64 *tv, struct timezone *tz)
Definition: time.c:391
函数调用图:
这是这个函数的调用关系图:

◆ SHELLCMD_ENTRY()

SHELLCMD_ENTRY ( watch_shellcmd  ,
CMD_TYPE_EX  ,
"watch"  ,
XARGS  ,
(CmdCallBackFunc OsShellCmdWatch 
)

变量说明

◆ g_watchCmd

STATIC WatchCB* g_watchCmd

在文件 watch_shellcmd.c55 行定义.