From fc734c73e993ff15f13cfaf9519107c230a5f52e Mon Sep 17 00:00:00 2001 From: MMS Date: Wed, 13 Dec 2023 12:47:34 -0500 Subject: [PATCH] 7.3.1 --- bin/Termite.ini | 28 +++++++ bin/qspy_exit.bat | 2 + fsdata.h | 5 -- qspy/include/pal.h | 5 +- qspy/include/qspy.h | 6 +- qspy/posix/qspy_pal.c | 6 +- qspy/py/README.txt | 11 --- qspy/qspy_exit.py | 159 ++++++++++++++++++++++++++++++++++++++++ qspy/source/qspy.c | 4 - qspy/source/qspy_be.c | 21 ++++-- qspy/source/qspy_main.c | 14 ++-- qspy/tcl/README.txt | 11 --- qspy/win32/make-vs.bat | 24 ------ qspy/win32/qspy_pal.c | 14 +++- 14 files changed, 232 insertions(+), 78 deletions(-) create mode 100644 bin/Termite.ini create mode 100644 bin/qspy_exit.bat delete mode 100644 fsdata.h delete mode 100644 qspy/py/README.txt create mode 100644 qspy/qspy_exit.py delete mode 100644 qspy/tcl/README.txt delete mode 100644 qspy/win32/make-vs.bat diff --git a/bin/Termite.ini b/bin/Termite.ini new file mode 100644 index 0000000..b37cf63 --- /dev/null +++ b/bin/Termite.ini @@ -0,0 +1,28 @@ +[Settings] +Port=COM16 +Baud=115200 +DataBits=8 +StopBits=1 +Parity=0 +Handshake=0 +ForwardPort= +[Options] +LocalEcho=1 +AppendLine=0 +Window=156 1460 639 504 +FontType=1 +Polling=100 +MaxLines=0 +WordWrap=1 +AutoComplete=1 +KeepHistory=0 +CloseOnCancel=1 +Topmost=0 +AutoClosePort=0 +Language=English (en) +[History] +cmd1=x +cmd2=y +cmd3=s +cmd4=a +cmd5=dfsdfa diff --git a/bin/qspy_exit.bat b/bin/qspy_exit.bat new file mode 100644 index 0000000..6b0a02b --- /dev/null +++ b/bin/qspy_exit.bat @@ -0,0 +1,2 @@ +@echo off +@%~dp0..\Python3\python.exe %~dp0..\qspy\qspy_exit.py %1 %2 %3 %4 diff --git a/fsdata.h b/fsdata.h deleted file mode 100644 index f156d9b..0000000 --- a/fsdata.h +++ /dev/null @@ -1,5 +0,0 @@ -/* This file has been generated with the qfsgen utility. */ - -#define FS_ROOT (struct fsdata_file *)0 - -#define FS_NUMFILES 0 diff --git a/qspy/include/pal.h b/qspy/include/pal.h index 7595cf9..626cb3f 100644 --- a/qspy/include/pal.h +++ b/qspy/include/pal.h @@ -23,8 +23,8 @@ * ============================================================================*/ /*! -* @date Last updated on: 2023-08-22 -* @version Last updated for version: 7.3.0 +* @date Last updated on: 2023-12-12 +* @version Last updated for version: 7.3.1 * * @file * @brief Platform Abstraction Layer (PAL) @@ -77,6 +77,7 @@ QSpyStatus PAL_openTargetFile(char const *fName); QSpyStatus PAL_openKbd(bool kbd_inp, bool color); void PAL_closeKbd(void); +void PAL_exit(void); QSPYEvtType PAL_receiveBe (unsigned char *buf, uint32_t *pBytes); QSPYEvtType PAL_receiveKbd(unsigned char *buf, uint32_t *pBytes); diff --git a/qspy/include/qspy.h b/qspy/include/qspy.h index 53523f2..fb904bc 100644 --- a/qspy/include/qspy.h +++ b/qspy/include/qspy.h @@ -28,8 +28,8 @@ * ============================================================================*/ /*! -* @date Last updated on: 2023-09-26 -* @version Last updated for version: 7.3.0 +* @date Last updated on: 2023-12-12 +* @version Last updated for version: 7.3.1 * * @file * @brief Host API @@ -37,7 +37,7 @@ #ifndef QSPY_H_ #define QSPY_H_ -#define QSPY_VER "7.3.0" +#define QSPY_VER "7.3.1" #ifdef __cplusplus extern "C" { diff --git a/qspy/posix/qspy_pal.c b/qspy/posix/qspy_pal.c index 54b04e9..94d4c02 100644 --- a/qspy/posix/qspy_pal.c +++ b/qspy/posix/qspy_pal.c @@ -152,7 +152,11 @@ void PAL_closeKbd(void) { l_kbd_inp = false; } } - +/*..........................................................................*/ +void PAL_exit(void) { + QSPY_cleanup(); + exit(0); +} /*==========================================================================*/ /* POSIX serial communication with the Target */ QSpyStatus PAL_openTargetSer(char const *comName, int baudRate) { diff --git a/qspy/py/README.txt b/qspy/py/README.txt deleted file mode 100644 index d11c8f9..0000000 --- a/qspy/py/README.txt +++ /dev/null @@ -1,11 +0,0 @@ -About this Directory -==================== -This directory is left for backwards-compatibility only -and will be removed in the future. - -The "qutest.py" Python script has been moved to directory qtools/qutest -and that location should be used in Makefiles and other build scripts -for QUTest unit testing. - -Quantum Leaps -August 1, 2020 diff --git a/qspy/qspy_exit.py b/qspy/qspy_exit.py new file mode 100644 index 0000000..7cd1657 --- /dev/null +++ b/qspy/qspy_exit.py @@ -0,0 +1,159 @@ +#============================================================================= +# QUTest Python scripting support +# Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. +# +# SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial +# +# This software is dual-licensed under the terms of the open source GNU +# General Public License version 3 (or any later version), or alternatively, +# under the terms of one of the closed source Quantum Leaps commercial +# licenses. +# +# The terms of the open source GNU General Public License version 3 +# can be found at: +# +# The terms of the closed source Quantum Leaps commercial licenses +# can be found at: +# +# Redistributions in source code must retain this top-level comment block. +# Plagiarizing this software to sidestep the license obligations is illegal. +# +# Contact information: +# +# +#============================================================================= +## +# @date Last updated on: 2023-12-13 +# @version Last updated for version: 7.3.1 +# +# @file +# @brief QUTest Python scripting support (implementation) +# @ingroup qutest + +import argparse +import socket +import struct +import sys +import os +if os.name == "nt": + import msvcrt +else: + import select + +from platform import python_version + +#============================================================================= +# Helper class for communication with the QSpy front-end +# +class QSpy: + VERSION = 731 + + # private class variables... + _sock = None + _is_attached = False + _tx_seq = 0 + _host_udp = ["localhost", 7701] # list, to be converted to a tuple + _local_port = 0 # let the OS decide the best local port + + # timeout value [seconds] + _TOUT = 1.000 + + # packets to QSpy only... + _QSPY_ATTACH = 128 + _QSPY_DETACH = 129 + _QSPY_SAVE_DICT = 130 + _QSPY_TEXT_OUT = 131 + _QSPY_BIN_OUT = 132 + _QSPY_MATLAB_OUT = 133 + _QSPY_SEQUENCE_OUT = 134 + _QSPY_CLEAR_SCREEN = 140 + _QSPY_SHOW_NOTE = 141 + + # packets to QSpy to be "massaged" and forwarded to the Target... + _QSPY_SEND_EVENT = 135 + _QSPY_SEND_AO_FILTER = 136 + _QSPY_SEND_CURR_OBJ = 137 + _QSPY_SEND_COMMAND = 138 + _QSPY_SEND_TEST_PROBE = 139 + + @staticmethod + def _init(): + # Create socket + QSpy._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + QSpy._sock.settimeout(QSpy._TOUT) # timeout for blocking socket + #bufsize = QSpy._sock.getsockopt(socket.SOL_UDP, socket.SO_RCVBUF) + #print("SO_RCVBUF ", bufsize) + try: + QSpy._sock.bind(("0.0.0.0", QSpy._local_port)) + #print("bind: ", ("0.0.0.0", QSpy._local_port)) + except: + messagebox.showerror("UDP Socket Error", + "Can't bind the UDP socket\nto the specified local_host") + QSpyView._gui.destroy() + return -1 + return 0 + + @staticmethod + def _sendTo(packet, str=None): + tx_packet = bytearray([QSpy._tx_seq]) + tx_packet.extend(packet) + if str is not None: + tx_packet.extend(bytes(str, "utf-8")) + tx_packet.extend(b"\0") # zero-terminate + QSpy._sock.sendto(tx_packet, QSpy._host_udp) + QSpy._tx_seq = (QSpy._tx_seq + 1) & 0xFF + #print("sendTo", QSpy._tx_seq) + +#============================================================================= +# main entry point to QUTest +def main(): + # parse command-line arguments... + parser = argparse.ArgumentParser( + prog="python qspy_exit.py", + description="QSPY-exit", + epilog="More info: https://www.state-machine.com/qspy.html#qspy_exit") + parser.add_argument('-v', '--version', + action='version', + version="QSPY-exit %d.%d.%d on Python %s"%( + QSpy.VERSION//100, (QSpy.VERSION//10) % 10, + QSpy.VERSION % 10, + python_version()), + help='Display QSPY-exit version') + + parser.add_argument('-q', '--qspy', nargs='?', default='', const='', + help="optional qspy host, [:ud_port]") + args = parser.parse_args() + #print(args) + + print("\nQSPY-exit %d.%d.%d running on Python %s"%( + QSpy.VERSION//100, + (QSpy.VERSION//10) % 10, + QSpy.VERSION % 10, python_version())) + print("Copyright (c) 2005-2023 Quantum Leaps, www.state-machine.com") + + # process command-line argumens... + if args.qspy != '': + qspy_conf = args.qspy.split(":") + if len(qspy_conf) > 0 and not qspy_conf[0] == '': + QSpy._host_udp[0] = qspy_conf[0] + if len(qspy_conf) > 1 and not qspy_conf[1] == '': + QSpy._host_udp[1] = int(qspy_conf[1]) + + #print("host_udp:", QSpy._host_udp) + #return 0 + + # convert to immutable tuple + QSpy._host_udp = tuple(QSpy._host_udp) + + # init QSpy socket + err = QSpy._init() + if err: + return sys.exit(err) + + QSpy._sendTo(struct.pack(" ============================================================================*/ /*! -* @date Last updated on: 2022-12-15 -* @version Last updated for version: 7.2.0 +* @date Last updated on: 2023-12-13 +* @version Last updated for version: 7.3.1 * * @file * @brief Back-End connection point for the external Front-Ends @@ -170,10 +170,19 @@ void BE_parseRecFromFE(QSpyRecord * const qrec) { } case QSPY_DETACH: { /* detach from the Front-End */ PAL_detachFE(); - l_channels = 0U; /* detached from a Front-End */ - SNPRINTF_LINE(" Detached %s", - "######################################"); - QSPY_printInfo(); + l_channels = 0U; /* mark as detached from the Front-End */ + + if (qrec->tot_len > 2U) { /* payload contains exit request? */ + SNPRINTF_LINE(" Forced EXIT %s", + "###################################"); + QSPY_printInfo(); + PAL_exit(); + } + else { /* detach request without exit */ + SNPRINTF_LINE(" Detached %s", + "######################################"); + QSPY_printInfo(); + } break; } case QSPY_SAVE_DICT: { /* save dictionaries collected so far */ diff --git a/qspy/source/qspy_main.c b/qspy/source/qspy_main.c index e7c0285..513ea75 100644 --- a/qspy/source/qspy_main.c +++ b/qspy/source/qspy_main.c @@ -23,8 +23,8 @@ * ============================================================================*/ /*! -* @date Last updated on: 2023-08-22 -* @version Last updated for version: 7.3.0 +* @date Last updated on: 2023-12-12 +* @version Last updated for version: 7.3.1 * * @file * @brief main for QSPY host utility @@ -143,7 +143,6 @@ static char const l_kbdHelpStr[] = /*..........................................................................*/ static QSpyStatus configure(int argc, char *argv[]); -static void cleanup(void); static void colorPrintLn(void); static uint8_t l_buf[8*1024]; /* process input in 8K chunks */ @@ -203,14 +202,12 @@ int main(int argc, char *argv[]) { } /* cleanup .............................................................*/ - cleanup(); + QSPY_cleanup(); return status; } /*..........................................................................*/ -static void cleanup(void) { - QSPY_cleanup(); - +void QSPY_cleanup(void) { PAL_closeKbd(); /* close the keyboard input (if open) */ if (l_savFile != (FILE *)0) { @@ -221,6 +218,7 @@ static void cleanup(void) { } QSEQ_configFile((void*)0); + QSPY_configMatFile((void*)0); if (l_bePort != 0) { PAL_closeBE(); /* close the Back-End connection */ @@ -237,7 +235,7 @@ static void cleanup(void) { void Q_onError(char const * const module, int const id) { PRINTF_S("\n QSPY ASSERTION failed in Module=%s:%d\n", module, id); - cleanup(); + QSPY_cleanup(); exit(-1); } diff --git a/qspy/tcl/README.txt b/qspy/tcl/README.txt deleted file mode 100644 index 42299a0..0000000 --- a/qspy/tcl/README.txt +++ /dev/null @@ -1,11 +0,0 @@ -About this Directory -==================== -This directory is left for backwards-compatibility only -and will be removed in the future. - -The Tcl/Tk versions of QUTest and QSpyView have been superceded -by the Python versions located in qtools/qutest and qtools/qview -directories, respectively. - -Quantum Leaps -August 1, 2020 diff --git a/qspy/win32/make-vs.bat b/qspy/win32/make-vs.bat deleted file mode 100644 index 859417c..0000000 --- a/qspy/win32/make-vs.bat +++ /dev/null @@ -1,24 +0,0 @@ -:: Batch file for building the specified PROJ (solution) prepared for -:: Microsoft Visual Studio -:: -:: usage: -:: make -:: -@setlocal - -:: specifiy project and build configuration (Debug|Release|Spy) -@set PROJ=qspy -@set CONF=Release - -:: adjust the MSBuild location for your system -@set MSBuild="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" - -:: execute the build... -%MSBuild% %PROJ%.sln -t:Build -p:Configuration=%CONF% -p:Platform=Win32 - -:: cleanup after the build... -::rmdir /S /Q %CONF%\%PROJ%.tlog -::del %CONF%\%PROJ%.vcxproj* %CONF%\%PROJ%.log %CONF%\*.obj %CONF%\*.pdb - -@endlocal - diff --git a/qspy/win32/qspy_pal.c b/qspy/win32/qspy_pal.c index 024c159..65474a3 100644 --- a/qspy/win32/qspy_pal.c +++ b/qspy/win32/qspy_pal.c @@ -23,8 +23,8 @@ * ============================================================================*/ /*! -* @date Last updated on: 2023-03-12 -* @version Last updated for version: 7.2.2 +* @date Last updated on: 2023-12-12 +* @version Last updated for version: 7.3.1 * * @file * @brief QSPY PAL implementation for Win32 @@ -98,7 +98,8 @@ static FILE *l_file = (FILE *)0; static BOOL WINAPI CtrlHandler(_In_ DWORD dwCtrlType) { (void)dwCtrlType; /* unused parameter */ QSPY_cleanup(); - exit(0); + //exit(-1); + return true; // signal handled } /* Keyboard input */ @@ -116,8 +117,14 @@ QSpyStatus PAL_openKbd(bool kbd_inp, bool color) { void PAL_closeKbd(void) { if (l_color) { fputs("\033[0m", stdout); /* switch default colors */ + l_color = false; } } +/*..........................................................................*/ +void PAL_exit(void) { + QSPY_cleanup(); + exit(0); +} /*==========================================================================*/ /* Win32 serial communication with the Target */ @@ -370,6 +377,7 @@ QSpyStatus PAL_openTargetTcp(int portNum) { static void tcp_cleanup(void) { if (l_serverSock != INVALID_SOCKET) { closesocket(l_serverSock); + l_serverSock = INVALID_SOCKET; } WSACleanup(); }