I heard about Finite State Machine in university, but at that time, I don't know how to program it. I remember at the begin year of my career, I coded with "swith / case" always. That is painful, especially when developing a medium-sized project. It's hard to find out what had happened, and what is going to happen next. The behavior of my program is often out of my control.
Things were changed soon. I was so luck to expose to FSM, about 500 lines of C source. I read them again and again until I'm sure its pros and cons. Years later, I coded my FSM for times, every time, there were a little changes. I hope it could be easier for applications to use.... read more
After days effort, memory service works now. It provides a track-able memory service; and avoid memory fraction as well.
It defines 2 different memory behaviors:
1, Memory allocated but may never deleted, in most case;
2, Memory allocated and will free soon.
For the first case, we have to estimate the memory size per nodal; while the second case, we need evaluate the throughput of concurrency.
zMemory provides different strategy to them. In addition, zMessage is based on share memory (sending a handle instead of a real buffer), zMemory applies verification method to memory handle and address when mapping to each other.
Knowing the system reset reason is a common basic requirement; although it is often overlooked by developers. On the other side, since it's not easy to give a solution, some developers stand mute.
Today the team I'm working for is experiencing it.
At least a guy though it is very easy, so he added some simple print to the log. He believe reset reason can be easy logged; he insist this in his unit test report.... read more
I have been working on TIMER for hours; however, there are still concerns that can't be solved easily.
What an accuracy it shall have?
This becomes a big problem in my mind. I used to define 50 milliseconds. It's not bad for certain projects, but mustn't be a part of an universal platform.
Shall I have schedule feature involved?
Recent months, I saw people are struggling on scheduling an event. The source they provides is pretty interesting; it will start an event at middle night although it is supposed to be at the morning.
Same thing was seen before. I had bought a cell phone, which was made by ALCATEL. I dare not use its' clock feature, since it often wakes me on a wrong time.
I believe the designers had a bad understanding on schedule design. The worst thing is that they even don't know how to test it. This drives me make it as a part of platform service; then application designers can focus on what their customer wan't, but not how to implement an alarm function.... read more
I had thought to post out a zTIMER implementation first; but soon I know it is not a good idea. I must allows every feature work on Linux (or cygwin), although they are for embedded development.
What is the next? I think TASK design has the first priority. Then TIMER, FSM, ...
Why shall we have FM (fault management) service? This is always confusing teams that had less long term products development knowledge, I believe. I do not mean to imply that this function does not need in a short term project.
Here is DEFINITION copied from Internet:
Fault management is the component of network management concerned with detecting, isolating and resolving problems. Properly implemented, fault management can keep a network running at an optimum level, provide a measure of fault tolerance and minimize downtime. A set of functions or applications designed specifically for this purpose is called a fault-management platform.
Important functions of fault management include:
Definition of thresholds for potential failure conditions.
Constant monitoring of system status and usage levels.
Continuous scanning for threats such as viruses and Trojans.
General diagnostics.
Remote control of system elements including workstations and servers from a single location.
Alarms that notify administrators and users of impending and actual malfunctions.
Tracing the locations of potential and actual malfunctions.
Automatic correction of potential problem-causing conditions.
Automatic resolution of actual malfunctions.
Detailed logging of system status and actions taken.... read more
About ten years ago, I code trace like below:
#ifdef DEBUG_TRACE #define DebugTrace(fmt, arg...) do{ \ printf("%s [%d]", __FILE__, __LINE__); \ printf(fmt, ##arg); \ }while(0) #else #define DebugTrace(fmt, arg...) do{}while(0) #endif
This is not bad, if we are coding small tools; however a project can't benefit from such design. We must removed off the conditional compile:
extern unsigned gDebugTraceEnableFlag; #define DebugTrace(fmt, arg...) do{ \ if(gDebugTraceEnableFlag) { \ printf("%s [%d]", __FILE__, __LINE__); \ printf(fmt, ##arg); \ } }while(0)... [read more](/p/zprj/blog/2013/05/ztrace-introduce/)
Developers who ever worked on vxWorks must have experienced its' WindShell. It's so powerful, we can debug our problem online.
zSHELL is a clone of WindShell. With it, we can look and change those global variables, executes all your functions. Also, we have document those commands in text, and load it as a batch file.
This shall be exciting if you still don't know how to debug your problem while GDB is not available.... read more
Years ago, when I started my software developer career, I often struggled with verifying functions, global data. However, there was only SDB (an older debug tool than GDB), nothing else. This always became a big problem after release builds. We can no longer debug it. We have to relay on logs.
I could never forget that our system crashed sometimes. There must be critical bugs in my source, although no evidence shows my source caused these crashes. No one can tell what had happened.... read more
Administrator mode can be accessed with a password. In this mode, users can use global variables, functions, with C coding format.
In an embedded system, developers can define their own authentication hook.
value = 1 = 0x1
->list
DATA : 0x00613620 -- yyr2
FUNCTION: 0x004032c4 -- z_Bsearch
FUNCTION: 0x0040324d -- z_Ntohs
FUNCTION: 0x0040326a -- z_Qsort
FUNCTION: 0x00404a47 -- z_TaskEnableDeleteHook
DATA : 0x00612198 -- g_zLog2ConsoleOutputCbk
DATA : 0x00612190 -- g_zTraceCommonLevel
FUNCTION: 0x00403710 -- z_ShellLog
FUNCTION: 0x00404a80 -- z_TaskShellIdSet
FUNCTION: 0x00401485 -- zTraceMemoryReset
FUNCTION: 0x0040481c -- list
FUNCTION: 0x004035cd -- sysMsec64TimeGet
FUNCTION: 0x00401b0e -- zTraceTaskName
FUNCTION: 0x00403d0f -- z_TaskLogHex
FUNCTION: 0x004010dd -- zPrjUserAudit
FUNCTION: 0x00403c39 -- z_IntLogHex
FUNCTION: 0x0040348f -- z_sysMemTop
FUNCTION: 0x004036dc -- z_Log2FileCbkSet
FUNCTION: 0x004034a5 -- z_ValidMemory
FUNCTION: 0x00407048 -- yyparse
FUNCTION: 0x004034ee -- z_Memcpy
FUNCTION: 0x00401a98 -- _zTraceNodalCompare
FUNCTION: 0x00404802 -- lkup
FUNCTION: 0x00404a95 -- z_InShell
FUNCTION: 0x004044b3 -- symLookupByName
FUNCTION: 0x00403f07 -- z_ShellPrintHex
FUNCTION: 0x0040332b -- z_Dword2String
FUNCTION: 0x0040198a -- zTraceMemoryShowStop
FUNCTION: 0x00403552 -- z_Memset
FUNCTION: 0x00403204 -- z_Htonl
FUNCTION: 0x0040397a -- z_TaskLog
FUNCTION: 0x00403606 -- sysHealthValueSet
FUNCTION: 0x004031a0 -- z_GetTimeSpec
FUNCTION: 0x00401b38 -- zTraceLevelSet
DATA : 0x00612660 -- yyact
FUNCTION: 0x00401a63 -- zTraceLevelReset
FUNCTION: 0x004036f6 -- z_Log2MemoryCbkSet
FUNCTION: 0x00404bd6 -- execute
FUNCTION: 0x00403f92 -- z_Log2ConsoleDefault
FUNCTION: 0x00404a59 -- z_TaskEnableSwiHook
FUNCTION: 0x00404086 -- symFuncNameLen
FUNCTION: 0x0040574a -- yystart
FUNCTION: 0x00401998 -- zTraceServiceInit
FUNCTION: 0x00401098 -- test_fun0
FUNCTION: 0x00404aec -- execShell
FUNCTION: 0x00401bfa -- zTraceLevelClear
FUNCTION: 0x004040c6 -- symFindByName
FUNCTION: 0x0040346a -- z_Free
FUNCTION: 0x00403af2 -- z_ShellLogHex
FUNCTION: 0x00404a6b -- z_TaskNop
FUNCTION: 0x00404378 -- symAdd
FUNCTION: 0x00404adc -- z_IntUnlock
DATA : 0x00613900 -- yydef
FUNCTION: 0x004049d4 -- z_TaskCreate
FUNCTION: 0x004047de -- z_FuncNameGet
FUNCTION: 0x004042c6 -- symFindByValue
DATA : 0x00612184 -- test_data0
FUNCTION: 0x004036c2 -- z_Log2ZcnCbkSet
DATA : 0x00612260 -- lexStateTable
FUNCTION: 0x004014a8 -- zTraceMemoryInit
FUNCTION: 0x00404abb -- z_InKernal
FUNCTION: 0x00404a18 -- z_TaskIdVerify
FUNCTION: 0x004017ee -- _zTraceMemoryShow
FUNCTION: 0x00403fec -- symUserAuditHookSet
FUNCTION: 0x00401c8e -- testTrace
FUNCTION: 0x00403e61 -- z_ShellPrint
DATA : 0x0061218c -- g_zTraceCommonMode
FUNCTION: 0x00403162 -- z_Ticks2Msec
DATA : 0x00613720 -- yychk
FUNCTION: 0x00403386 -- z_Word2String
FUNCTION: 0x00404909 -- symAddCommand
FUNCTION: 0x00404a35 -- z_TaskEnableCreateHook
FUNCTION: 0x00404a0d -- z_TaskIdSelf
FUNCTION: 0x004049ff -- z_TaskName
FUNCTION: 0x0040364a -- z_Ip2String
FUNCTION: 0x004033e5 -- z_Byte2String
FUNCTION: 0x0040466c -- showSymTable
FUNCTION: 0x0040359e -- sysMsec32TimeGet
FUNCTION: 0x0040387a -- z_IntLog
FUNCTION: 0x004030b8 -- z_Time
DATA : 0x00613500 -- yypgo
FUNCTION: 0x004031f7 -- z_ErrnoGet
FUNCTION: 0x004018f8 -- zTraceMemoryShow
FUNCTION: 0x0040113a -- zPrjMain
FUNCTION: 0x00403629 -- sysFeedDog
FUNCTION: 0x004049f1 -- z_TaskDelete
DATA : 0x006121a0 -- lexNclasses
FUNCTION: 0x00404c10 -- stringTrimRight
FUNCTION: 0x0040349a -- z_sysMemBottom
FUNCTION: 0x00404836 -- help
FUNCTION: 0x00403236 -- z_Ntohl
FUNCTION: 0x00403141 -- z_Msec2Ticks
FUNCTION: 0x0040321b -- z_Htons
DATA : 0x00613520 -- yyr1
FUNCTION: 0x00404a26 -- z_TaskName2Id
FUNCTION: 0x00401ab8 -- zTraceTaskLevel
FUNCTION: 0x00404cac -- lexActions
DATA : 0x00612630 -- yyexca
DATA : 0x006121c0 -- lexClass
FUNCTION: 0x00404ac6 -- z_InInterrupt
FUNCTION: 0x00401c65 -- zTraceLevelSetAll
DATA : 0x00613320 -- yypact
FUNCTION: 0x00403183 -- z_SleepMsec
FUNCTION: 0x00404ad1 -- z_IntLock
FUNCTION: 0x00404006 -- symSu
FUNCTION: 0x004030c8 -- z_CTime
FUNCTION: 0x00401388 -- _zTrace2MemoryCbk
FUNCTION: 0x00403443 -- z_Malloc
FUNCTION: 0x004036a8 -- z_Log2ConsoleCbkSet
FUNCTION: 0x0040361d -- sysHealthValueGet
value = 110 = 0x6e = 'n'
->test_fun0(1,'a',"sample string")
[test_fun0:19] Your input: 1 a sample string
value = 1 = 0x1
->test_data0
test_data0 = 0x612184: value = 1 = 0x1
->su
value = 0 = 0x0
->
In general user mode, users can only execute certain commands that registered by developers. The help provides a list of those available commands.
task_level -- zTraceTaskLevel(int tid)
task_name -- zTraceTaskName(int tid)
trace_init -- zTraceServiceInit()
trace_reset -- zTraceLevelReset()
trace_set -- zTraceLevelSet(const char taskName, byte_t ucLevel)
trace_clr -- zTraceLevelClear(const char taskName, byte_t ucLevel)
trace_all -- zTraceLevelSetAll(byte_t ucLevel)
log_memory -- zTraceMemoryInit(int size)
log_show -- zTraceMemoryShow(int detail)
log_test -- testTrace()
value = 0 = 0x0
->log_memory 10240
[Debug 0x519c9341]NA:zLog.c zTraceMemoryInit 92::Trace2Mem alloced: 0x01ec7340 10240
value = 0 = 0x0
->log_test
[Fatal 0x519c9344]NA:zTrace.c testTrace 163::hahhaha 2
[Alarm 0x519c9344]NA:zTrace.c testTrace 164::hahhaha 2
[Error 0x519c9344]NA:zTrace.c testTrace 165::hahhaha 2
[Warn 0x519c9344]NA:zTrace.c testTrace 166::hahhaha 2
[Info 0x519c9344]NA:zTrace.c testTrace 167::hahhaha 2
[Debug 0x519c9344]NA:zTrace.c testTrace 168::hahhaha 2
hahhaha 2
hahhaha 2
hahhaha 2
hahhaha 2
hahhaha 2
hahhaha 2
hahhaha 2
[Fatal 0x519c9344]NA:zTrace.c testTrace 178::01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
[Alarm 0x519c9344]NA:zTrace.c testTrace 179::01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
[Error 0x519c9344]NA:zTrace.c testTrace 180::01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
[Warn 0x519c9344]NA:zTrace.c testTrace 181::01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
[Info 0x519c9344]NA:zTrace.c testTrace 182::01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
[Debug 0x519c9344]NA:zTrace.c testTrace 183::01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
value = 0 = 0x0
->log_show 1
Trace Memory: 0x01ec7340 Current Offset: 1378
Total: 10240 Saved: 1378... read more