QTools  7.2.1
Collection of Host-Based Tools
Loading...
Searching...
No Matches
qspy.h
Go to the documentation of this file.
1/*============================================================================
2* QP/C Real-Time Embedded Framework (RTEF)
3* Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
4*
5* SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
6*
7* This software is dual-licensed under the terms of the open source GNU
8* General Public License version 3 (or any later version), or alternatively,
9* under the terms of one of the closed source Quantum Leaps commercial
10* licenses.
11*
12* The terms of the open source GNU General Public License version 3
13* can be found at: <www.gnu.org/licenses/gpl-3.0>
14*
15* The terms of the closed source Quantum Leaps commercial licenses
16* can be found at: <www.state-machine.com/licensing>
17*
18* Redistributions in source code must retain this top-level comment block.
19* Plagiarizing this software to sidestep the license obligations is illegal.
20*
21* Contact information:
22* <www.state-machine.com>
23* <info@state-machine.com>
24============================================================================*/
25/*!
26* @date Last updated on: 2023-02-12
27* @version Last updated for version: 7.2.2
28*
29* @file
30* @brief Host API
31*/
32#ifndef QSPY_H_
33#define QSPY_H_
34
35#define QSPY_VER "7.2.2"
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/*! low-level facilities for configuring QSpy and parsing QS records ...*/
42typedef enum {
46
47/*! QSPY record being processed */
48typedef struct {
49 uint8_t const *start; /*!< start of the record */
50 uint8_t const *pos; /*!< current position in the stream */
51 uint32_t tot_len; /*!< total length of the record, including chksum */
52 int32_t len; /*!< current length of the stream */
53 uint8_t rec; /*!< the record-ID (see enum QSpyRecords in qs.h) */
55
56/* limits */
57enum {
58 QS_RECORD_SIZE_MAX = 512, /* max QS record size [bytes] */
59 QS_LINE_LEN_MAX = 1000, /* max length of a QSPY line [chars] */
60 QS_FNAME_LEN_MAX = 256, /* max length of filenames [chars] */
61 QS_SEQ_LIST_LEN_MAX = 300, /* max length of the Seq list [chars] */
62 QS_DNAME_LEN_MAX = 64, /* max dictionary name length [chars] */
63};
64
65/* pointer to the callback function for customized QS record parsing */
66typedef int (*QSPY_CustParseFun)(QSpyRecord * const me);
67typedef void (*QSPY_resetFun)(void);
68
69void QSpyRecord_init (QSpyRecord * const me,
70 uint8_t const *start, uint32_t tot_len);
72uint32_t QSpyRecord_getUint32(QSpyRecord * const me, uint8_t size);
73int32_t QSpyRecord_getInt32 (QSpyRecord * const me, uint8_t size);
74uint64_t QSpyRecord_getUint64(QSpyRecord * const me, uint8_t size);
75int64_t QSpyRecord_getInt64 (QSpyRecord * const me, uint8_t size);
76char const *QSpyRecord_getStr (QSpyRecord * const me);
77uint8_t const *QSpyRecord_getMem(QSpyRecord * const me,
78 uint8_t size,
79 uint32_t *pNum);
80
81/* QSPY configuration and high-level interface .............................*/
82/*! QSPY configuration parameters. @sa QSPY_config() */
83typedef struct {
84 uint16_t version;
85 uint8_t endianness;
86 uint8_t objPtrSize;
87 uint8_t funPtrSize;
88 uint8_t tstampSize;
89 uint8_t sigSize;
90 uint8_t evtSize;
91 uint8_t queueCtrSize;
92 uint8_t poolCtrSize;
93 uint8_t poolBlkSize;
94 uint8_t tevtCtrSize;
95 uint8_t tstamp[6];
97
98typedef uint64_t KeyType;
99typedef uint32_t SigType;
100typedef uint64_t ObjType;
101
102void QSPY_config(QSpyConfig const *config,
103 QSPY_CustParseFun custParseFun);
105void QSPY_configMatFile(void *matFile);
106
107void QSPY_reset(void);
108void QSPY_parse(uint8_t const *buf, uint32_t nBytes);
109void QSPY_txReset(void);
110
111/* command options */
112enum {
116};
117bool QSPY_command(uint8_t cmdId, uint8_t opt);
118
119void QSPY_sendEvt(QSpyRecord const * const qrec);
120void QSPY_sendObj(QSpyRecord const * const qrec);
121void QSPY_sendCmd(QSpyRecord const * const qrec);
122void QSPY_sendTP (QSpyRecord const * const qrec);
123void QSPY_showNote(QSpyRecord const * const qrec);
124
125uint32_t QSPY_encode(uint8_t *dstBuf, uint32_t dstSize,
126 uint8_t const *srcBuf, uint32_t srcBytes);
127uint32_t QSPY_encodeResetCmd(uint8_t *dstBuf, uint32_t dstSize);
128uint32_t QSPY_encodeInfoCmd (uint8_t *dstBuf, uint32_t dstSize);
129uint32_t QSPY_encodeTickCmd (uint8_t *dstBuf, uint32_t dstSize, uint8_t rate);
130
131SigType QSPY_findSig(char const *name, ObjType obj);
132KeyType QSPY_findObj(char const *name);
133KeyType QSPY_findFun(char const *name);
134KeyType QSPY_findUsr(char const *name);
135KeyType QSPY_findEnum(char const *name, uint8_t group);
136
137#define SIG_NOT_FOUND ((SigType)-1)
138#define KEY_NOT_FOUND ((KeyType)-1)
139
140void QSPY_cleanup(void); /* cleanup after the run */
141
142char const* QSPY_tstampStr(void);
143
144void QSPY_onPrintLn(void); /* callback to print the last line of output */
145
146/* prints information message to the QSPY output (without sending it to FE) */
147void QSPY_printInfo(void);
148
149/* prints error message to the QSPY output (sending it to FE) */
151
152/* last human-readable line of output from QSPY ............................*/
153#define QS_LINE_OFFSET 8
155 /* output forwarded to the back-end... */
156 REG_OUT, /* regular output from the Target */
157 ERR_OUT, /* error output from QSPY */
158 /* ... */
159 BE_OUT, /* last message forwarded to the back-end */
160
161 /* output NOT forwarded to the back-end... */
162 INF_OUT, /* internal info from QSPY */
163 USR_OUT, /* generic user message from BE */
164 TST_OUT, /* test message from BE */
165};
166typedef struct {
168 int len; /* the length of the composed string */
169 int rec; /* the corresponding QS record ID */
170 int type; /* the type of the output */
171 int rx_status; /* the type of the RX status */
173
188 GRP_USR
190
191typedef struct {
192 char const *name; /* name of the record, e.g. "QS_QF_PUBLISH" */
193 int const group; /* group of the record (for rendering/coloring) */
195
196/* last output generated */
198
199/* beginning of QSPY line to print */
200extern char const * const QSPY_line;
201
202/* rendering information for QSPY records */
203extern QSpyRecRender const QSPY_rec[];
204
205#define SNPRINTF_LINE(format_, ...) do { \
206 int n_ = SNPRINTF_S(&QSPY_output.buf[QS_LINE_OFFSET], \
207 (QS_LINE_LEN_MAX - QS_LINE_OFFSET), \
208 format_, __VA_ARGS__); \
209 if ((0 < n_) && (n_ < QS_LINE_LEN_MAX - QS_LINE_OFFSET)) { \
210 QSPY_output.len = n_; \
211 } \
212 else { \
213 QSPY_output.len = QS_LINE_LEN_MAX - QS_LINE_OFFSET; \
214 } \
215} while (0)
216
217#define SNPRINTF_APPEND(format_, ...) do { \
218 int n_ = SNPRINTF_S(&QSPY_output.buf[QS_LINE_OFFSET + QSPY_output.len],\
219 (QS_LINE_LEN_MAX - QS_LINE_OFFSET - QSPY_output.len), \
220 format_, __VA_ARGS__); \
221 if ((0 < n_) \
222 && (n_ < QS_LINE_LEN_MAX - QS_LINE_OFFSET - QSPY_output.len)) { \
223 QSPY_output.len += n_; \
224 } \
225 else { \
226 QSPY_output.len = QS_LINE_LEN_MAX - QS_LINE_OFFSET; \
227 } \
228} while (0)
229
230#define CONFIG_UPDATE(member_, new_, diff_) \
231 if (QSPY_conf.member_ != (new_)) { \
232 QSPY_conf.member_ = (new_); \
233 (diff_) = 1U; \
234 } else (void)0
235
236/* Dictionaries ............................................................*/
237typedef struct {
240} DictEntry;
241
242typedef struct {
248} Dictionary;
249
251 DictEntry* sto, uint32_t capacity);
252void Dictionary_config(Dictionary* const me, int keySize);
253char const* Dictionary_at(Dictionary* const me, unsigned idx);
254void Dictionary_put(Dictionary* const me, KeyType key, char const* name);
255char const* Dictionary_get(Dictionary* const me, KeyType key, char* buf);
257KeyType Dictionary_findKey(Dictionary* const me, char const* name);
259
260typedef struct {
265
266typedef struct {
273
275 SigDictEntry* sto, uint32_t capacity);
276void SigDictionary_config(SigDictionary* const me, int ptrSize);
278 SigType sig, ObjType obj, char const* name);
279char const* SigDictionary_get(SigDictionary* const me,
280 SigType sig, ObjType obj, char* buf);
282 SigType sig, ObjType obj);
284 char const* name, ObjType obj);
287
288/*==========================================================================*/
289/* facilities used by the QSPY host app only (but not for QSPY parser) */
290#ifdef QSPY_APP
291
292/*! commands to QSPY; @sa "packet IDs" in qutest.py or qview.py scripts */
293typedef enum {
294 QSPY_ATTACH = 128, /*!< attach to the QSPY Back-End */
295 QSPY_DETACH, /*!< detach from the QSPY Back-End */
296 QSPY_SAVE_DICT, /*!< save dictionaries to a file in QSPY */
297 QSPY_TEXT_OUT, /*!< toggle text output to a file in QSPY */
298 QSPY_BIN_OUT, /*!< toggle binary output to a file in QSPY */
299 QSPY_MATLAB_OUT, /*!< toggle Matlab output to a file in QSPY */
300 QSPY_SEQUENCE_OUT, /*!< toggle Sequence output to a file in QSPY */
301 QSPY_SEND_EVENT, /*!< send event (QSPY supplying signal) */
302 QSPY_SEND_AO_FILTER, /*!< send Local Filter (QSPY supplying addr) */
303 QSPY_SEND_CURR_OBJ, /*!< send current Object (QSPY supplying addr) */
304 QSPY_SEND_COMMAND, /*!< send command (QSPY supplying cmdId) */
305 QSPY_SEND_TEST_PROBE, /*!< send Test-Probe (QSPY supplying apiId) */
306 QSPY_CLEAR_SCREEN, /*!< clear the QSPY screen */
307 QSPY_SHOW_NOTE, /*!< show a note in QSPY output */
308 /* ... */
309} QSpyCommands;
310
311extern QSpyConfig QSPY_conf;
312extern Dictionary QSPY_funDict;
313extern Dictionary QSPY_objDict;
314extern Dictionary QSPY_usrDict;
315extern SigDictionary QSPY_sigDict;
316extern Dictionary QSPY_enumDict[8];
317
318void QSPY_setExternDict(char const* dictName);
319QSpyStatus QSPY_readDict(void);
320QSpyStatus QSPY_writeDict(void);
321
322bool QDIC_isActive(void);
323
324void Dictionary_write(Dictionary const* const me, FILE* stream);
325bool Dictionary_read(Dictionary* const me, FILE* stream);
326
327void SigDictionary_write(SigDictionary const* const me, FILE* stream);
328bool SigDictionary_read(SigDictionary* const me, FILE* stream);
329char const* QSPY_getMatDict(char const* s);
330
331void QSEQ_configFile(void *seqFile);
332bool QSEQ_isActive(void);
333void QSEQ_config(void* seqFile, const char* seqList);
334void QSEQ_updateDictionary(char const* name, KeyType key);
335int QSEQ_find(KeyType key);
336void QSEQ_genHeader(void);
337void QSEQ_genPost(uint32_t tstamp, int src, int dst, char const* sig,
338 bool isAttempt);
339void QSEQ_genPostLIFO(uint32_t tstamp, int src, char const* sig);
340void QSEQ_genTran(uint32_t tstamp, int obj, char const* state);
341void QSEQ_genPublish(uint32_t tstamp, int obj, char const* sig);
342void QSEQ_genAnnotation(uint32_t tstamp, int obj, char const* ann);
343void QSEQ_genTick(uint32_t rate, uint32_t nTick);
344void QSEQ_dictionaryReset(void);
345
346#endif /* QSPY_APP */
347
348#ifdef __cplusplus
349}
350#endif
351
352#endif /* QSPY_H_ */
QSpyStatus
Definition: qspy.h:42
@ QSPY_SUCCESS
Definition: qspy.h:44
@ QSPY_ERROR
Definition: qspy.h:43
ObjType obj
Definition: qspy.h:262
uint8_t poolCtrSize
Definition: qspy.h:92
void Dictionary_config(Dictionary *const me, int keySize)
int entries
Definition: qspy.h:246
@ QS_SEQ_LIST_LEN_MAX
Definition: qspy.h:61
@ QS_RECORD_SIZE_MAX
Definition: qspy.h:58
@ QS_DNAME_LEN_MAX
Definition: qspy.h:62
@ QS_FNAME_LEN_MAX
Definition: qspy.h:60
@ QS_LINE_LEN_MAX
Definition: qspy.h:59
void QSPY_sendTP(QSpyRecord const *const qrec)
SigType QSPY_findSig(char const *name, ObjType obj)
void SigDictionary_reset(SigDictionary *const me)
void Dictionary_ctor(Dictionary *const me, DictEntry *sto, uint32_t capacity)
KeyType key
Definition: qspy.h:238
char const * Dictionary_at(Dictionary *const me, unsigned idx)
int32_t QSpyRecord_getInt32(QSpyRecord *const me, uint8_t size)
int ptrSize
Definition: qspy.h:271
uint8_t endianness
Definition: qspy.h:85
uint8_t const * start
Definition: qspy.h:49
QSpyRecRender const QSPY_rec[]
QSpyStatus QSpyRecord_OK(QSpyRecord *const me)
void QSPY_resetAllDictionaries(void)
uint32_t QSpyRecord_getUint32(QSpyRecord *const me, uint8_t size)
uint8_t sigSize
Definition: qspy.h:89
int rx_status
Definition: qspy.h:171
uint64_t KeyType
Definition: qspy.h:98
uint8_t tstampSize
Definition: qspy.h:88
uint8_t const * pos
Definition: qspy.h:50
uint32_t QSPY_encodeResetCmd(uint8_t *dstBuf, uint32_t dstSize)
uint64_t QSpyRecord_getUint64(QSpyRecord *const me, uint8_t size)
uint32_t SigType
Definition: qspy.h:99
int64_t QSpyRecord_getInt64(QSpyRecord *const me, uint8_t size)
int SigDictionary_find(SigDictionary *const me, SigType sig, ObjType obj)
int(* QSPY_CustParseFun)(QSpyRecord *const me)
Definition: qspy.h:66
void SigDictionary_ctor(SigDictionary *const me, SigDictEntry *sto, uint32_t capacity)
DictEntry notFound
Definition: qspy.h:243
uint8_t funPtrSize
Definition: qspy.h:87
char const * name
Definition: qspy.h:192
QSPY_LastOutputType
Definition: qspy.h:154
@ INF_OUT
Definition: qspy.h:162
@ BE_OUT
Definition: qspy.h:159
@ ERR_OUT
Definition: qspy.h:157
@ USR_OUT
Definition: qspy.h:163
@ REG_OUT
Definition: qspy.h:156
@ TST_OUT
Definition: qspy.h:164
char const * Dictionary_get(Dictionary *const me, KeyType key, char *buf)
void QSPY_reset(void)
int32_t len
Definition: qspy.h:52
KeyType Dictionary_findKey(Dictionary *const me, char const *name)
int const group
Definition: qspy.h:193
char const * SigDictionary_get(SigDictionary *const me, SigType sig, ObjType obj, char *buf)
void QSPY_sendCmd(QSpyRecord const *const qrec)
SigDictEntry * sto
Definition: qspy.h:268
void QSPY_cleanup(void)
void SigDictionary_config(SigDictionary *const me, int ptrSize)
char const * QSPY_tstampStr(void)
void QSPY_printInfo(void)
QSPY_LastOutput QSPY_output
DictEntry * sto
Definition: qspy.h:244
QSRreRecGroup
Definition: qspy.h:174
@ GRP_MP
Definition: qspy.h:182
@ GRP_TST
Definition: qspy.h:178
@ GRP_INF
Definition: qspy.h:176
@ GRP_TE
Definition: qspy.h:183
@ GRP_EQ
Definition: qspy.h:181
@ GRP_USR
Definition: qspy.h:188
@ GRP_DIC
Definition: qspy.h:177
@ GRP_MTX
Definition: qspy.h:187
@ GRP_ERR
Definition: qspy.h:175
@ GRP_QF
Definition: qspy.h:184
@ GRP_SEM
Definition: qspy.h:186
@ GRP_AO
Definition: qspy.h:180
@ GRP_SM
Definition: qspy.h:179
@ GRP_SC
Definition: qspy.h:185
char const * QSpyRecord_getStr(QSpyRecord *const me)
uint8_t rec
Definition: qspy.h:53
int keySize
Definition: qspy.h:247
void QSPY_sendEvt(QSpyRecord const *const qrec)
uint8_t tevtCtrSize
Definition: qspy.h:94
void QSPY_parse(uint8_t const *buf, uint32_t nBytes)
SigDictEntry notFound
Definition: qspy.h:267
char const *const QSPY_line
SigType SigDictionary_findSig(SigDictionary *const me, char const *name, ObjType obj)
void Dictionary_put(Dictionary *const me, KeyType key, char const *name)
void QSPY_configTxReset(QSPY_resetFun txResetFun)
KeyType QSPY_findObj(char const *name)
uint8_t queueCtrSize
Definition: qspy.h:91
uint16_t version
Definition: qspy.h:84
void QSPY_onPrintLn(void)
uint32_t QSPY_encodeTickCmd(uint8_t *dstBuf, uint32_t dstSize, uint8_t rate)
KeyType QSPY_findEnum(char const *name, uint8_t group)
void QSPY_printError(void)
void QSPY_config(QSpyConfig const *config, QSPY_CustParseFun custParseFun)
void QSPY_showNote(QSpyRecord const *const qrec)
uint64_t ObjType
Definition: qspy.h:100
uint8_t poolBlkSize
Definition: qspy.h:93
uint32_t QSPY_encodeInfoCmd(uint8_t *dstBuf, uint32_t dstSize)
void QSPY_configMatFile(void *matFile)
uint8_t objPtrSize
Definition: qspy.h:86
uint32_t QSPY_encode(uint8_t *dstBuf, uint32_t dstSize, uint8_t const *srcBuf, uint32_t srcBytes)
int Dictionary_find(Dictionary *const me, KeyType key)
uint32_t tot_len
Definition: qspy.h:51
uint8_t const * QSpyRecord_getMem(QSpyRecord *const me, uint8_t size, uint32_t *pNum)
void(* QSPY_resetFun)(void)
Definition: qspy.h:67
int capacity
Definition: qspy.h:245
void QSpyRecord_init(QSpyRecord *const me, uint8_t const *start, uint32_t tot_len)
@ CMD_OPT_OFF
Definition: qspy.h:113
@ CMD_OPT_TOGGLE
Definition: qspy.h:115
@ CMD_OPT_ON
Definition: qspy.h:114
void QSPY_sendObj(QSpyRecord const *const qrec)
#define QS_LINE_OFFSET
Definition: qspy.h:153
SigType sig
Definition: qspy.h:261
KeyType QSPY_findFun(char const *name)
void Dictionary_reset(Dictionary *const me)
void QSPY_txReset(void)
uint8_t evtSize
Definition: qspy.h:90
bool QSPY_command(uint8_t cmdId, uint8_t opt)
KeyType QSPY_findUsr(char const *name)
void SigDictionary_put(SigDictionary *const me, SigType sig, ObjType obj, char const *name)
Definition: qspy.h:237
Definition: qspy.h:260