Dynamic instruction general generation method based on Lua language
By designing basic binary and floating-point number processing methods in Lua language, as well as Redis memory database interface access method, it is packaged into an algorithm library, and the binary operation and floating-point number conversion problems of Lua language in spacecraft testing is solved, and dynamic instruction generation is improved timeliness and standardization reduces maintenance costs.
Patent Information
- Application Number
- CN202411122178.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-15
- Publication Date
- 2024-12-06
AI Technical Summary
The Lua scripting language lacks support for binary data operations in spacecraft tests, cannot convert floating point memory formats, and the Redis memory database does not support enough, resulting in insufficient timeliness for dynamic instruction generation and difficulty in maintaining.
A general generation method for dynamic instructions based on Lua language is designed, including basic binary standardized processing methods, floating point processing methods and Redis memory database interface access methods, encapsulated into algorithm library files, providing a unified algorithm library to realize dynamic instructions generation Standardization and timeliness.
It solves the shortcomings of Lua's language for binary data and floating-point numbers processing, improves the timeliness and standardization of dynamic instruction generation, reduces maintenance costs, and realizes unified management and generation of dynamic instructions.
Smart Images

Figure CN119088360A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a general method for generating dynamic instructions based on Lua language, belonging to the technical field of spacecraft testing. Background Art
[0002] When conducting tests, spacecraft need to send a large number of remote control commands to control the working status of the spacecraft, one of which is dynamic commands. The codewords of other types of remote control commands can be known in advance and are generally generated in advance. The codewords of dynamic commands can only be determined when they are sent and cannot be generated in advance. The working principle of dynamic commands is that the relevant parameters (such as calibration time, temperature setting value, antenna rotation angle, etc.) can only be known at the time of sending. The background system generates remote control command codewords in real time according to the parameter values, and then sends these remote control command codewords to the spacecraft in time for execution, so as to realize the control and management of the spacecraft. The whole process is automatically completed within a few seconds.
[0003] At present, considering that dynamic instructions need to frequently change parameters and be generated in real time, Lua scripting language is generally used to implement it. After the script is changed, it does not need to be recompiled, which saves compilation time and the system does not need to be restarted, so it can be released as soon as it is changed. Compared with other high-level languages, the biggest advantage of Lua scripting language is that it does not need to be compiled and takes effect after the change.
[0004] The main deficiencies are: (1) Lua scripting language is a lightweight language that supports few data types. The early version does not support binary data operations, and the new version also supports binary data in a relatively simple way. Dynamic instruction generation requires a large number of binary operations, and many binary calculations and numerical conversions cannot be completed. Spacecraft testers generally write their own binary conversion methods based on the overall design of the instructions for this model, which only covers some of the functions of binary data processing. There are incomplete and non-standard binary operations, and new requirements must be handled temporarily; (2) Lua scripting language does not provide memory-based floating-point format conversion, so the functions of some dynamic instructions cannot be realized, and it cannot meet the implementation of some spacecraft test dynamic instructions. Previously, some spacecraft test implementers had written floating-point calculation methods. However, due to the complexity of the international standards for floating-point calculations, there were problems with understanding and implementation, and only partial numerical ranges could be supported. Numerical calculations outside the range could not be processed or there were calculation errors, which would affect the correctness of dynamic instruction generation. (3) There was insufficient support for the Redis memory database, and it was impossible to obtain the spacecraft telemetry parameter values in real time to use as parameters for dynamic instruction generation, resulting in insufficient timeliness of some dynamic instructions, such as onboard time calibration instructions. (4) Each spacecraft tester had to write and implement the algorithm by himself. Many algorithms were repeatedly designed and implemented, with inconsistent versions, making maintenance difficult and troubleshooting difficult. (5) There were large differences between the generation methods and process models of dynamic instructions, resulting in inconsistencies and lack of standardization. Summary of the invention
[0005] The technical problem solved by the present invention is: to overcome the deficiencies of the prior art, to provide a general method for generating dynamic instructions based on the Lua language, to solve the problem that the Lua scripting language has insufficient support for binary data operations and floating-point type memory format conversion, to provide a general algorithm library, to achieve algorithm unification, to reduce maintenance costs, to facilitate testers to use and generate dynamic instructions, and to make the dynamic instruction generation method more standardized.
[0006] The technical solution of the present invention is: a general method for generating dynamic instructions based on Lua language, comprising:
[0007] Use Lua language to design general functional algorithms, including: basic binary standardization processing method, checksum calculation method, floating point number processing method; also use Lua language to design Redis memory database interface access method;
[0008] Encapsulate the above functional algorithms and Redis memory database interface access method into an interface Lua format file as an algorithm library file;
[0009] A dynamic instruction management directory is established for each spacecraft, and the dynamic instruction generation master file and algorithm library file are placed in it. At the same time, a call link to the algorithm library file, spacecraft model identification, Redis address and port are added to the dynamic instruction generation master file of each spacecraft;
[0010] The tester designs and implements the dynamic instruction generation function in the dynamic instruction generation master file according to the dynamic instruction format and parameters;
[0011] After the background dynamic instruction generation main program is started, the dynamic instruction generation main file and algorithm library file in the dynamic instruction management directory of the spacecraft are loaded, so that the dynamic instruction generation main file is connected to the Redis memory database of the spacecraft through the Redis memory database interface in the algorithm library file;
[0012] Select the dynamic command to be sent on the console, fill in the parameters to be set according to the spacecraft status, and send the dynamic command to the background to generate the main program;
[0013] After receiving the dynamic instruction, the background dynamic instruction generation main program parses it, parses out the basic information of the dynamic instruction, and checks the validity of the dynamic instruction; when the dynamic instruction is valid, the background dynamic instruction generation main program calls the dynamic instruction generation function and algorithm library file in the dynamic instruction generation main file to calculate and generate the remote control instruction codeword; when the dynamic instruction is invalid, the background dynamic instruction generation main program prompts the error type and error location in the running interface;
[0014] The background dynamic command generation main program sends the generated remote control command code to the spacecraft for execution, and saves the remote control command code together with the sending time information and the command code into an archive file in the specified directory of the spacecraft.
[0015] Preferably, there are a plurality of dynamic instruction generation functions, and each dynamic instruction generation function generates a certain type or types of dynamic instruction remote control codewords by calling a method in an algorithm library file.
[0016] Preferably, the remote control command codeword is generated in any of the following ways:
[0017] The dynamic instruction generation function in the dynamic instruction generation main file calls the general algorithm in the algorithm library file to generate the remote control instruction codeword.
[0018] The real-time telemetry engineering values of the spacecraft in the Redis memory database are obtained through the Redis memory database interface, and remote control command codewords with stronger timeliness are calculated and generated, so that the spacecraft can execute according to the latest status.
[0019] Preferably, the basic binary standardization processing method provides the following interfaces: binary AND / OR operation, conversion between binary / decimal / hexadecimal, complement calculation, and binary accumulation and addition.
[0020] Preferably, when the checksum calculation method is designed and implemented using the Lua language, the international standard CRC-8 / CRC-16 / CRC-32 method is adopted.
[0021] Preferably, when the floating point number processing method is designed and implemented using the Lua language, the method for converting single-precision floating point numbers to hexadecimal and double-precision floating point numbers to hexadecimal is based on the IEEE 754 international standard.
[0022] Preferably, the Redis memory database interface provides the Redis address and port, so that the dynamic instruction generation master file can obtain the telemetry engineering values, telemetry source code, and ground equipment data engineering values in the Redis memory database in real time.
[0023] Preferably, when the dynamic instruction is valid, the background dynamic instruction generation main program calls the dynamic instruction generation function and algorithm library file in the dynamic instruction generation main file to perform calculation:
[0024] When the algorithm calculation is normal, a remote control command code word is generated;
[0025] When the algorithm calculation is abnormal, the exception is reported on the execution interface, and the error location and misalignment type are located.
[0026] Compared with the prior art, the present invention has the following advantages:
[0027] (1) The present invention implements binary data processing, floating-point memory conversion processing, etc. in Lua language, solving the problem that Lua language lacks these functions and cannot process binary values and floating-point memory conversion through Lua language, so that Lua language can support all dynamic instruction generation;
[0028] (2) The expanded Redis memory database data acquisition method enables dynamic instruction generation based on the real-time telemetry values on board, thus improving the timeliness of dynamic instruction generation;
[0029] (3) A universal library designed and implemented to meet the common needs of various spacecraft models has achieved the unification of the Lua language dynamic instruction generation function library of each spacecraft, reducing maintenance workload and improving deployment efficiency;
[0030] (4) The method of generating dynamic instructions is standardized, making the management, sending, generation and execution of dynamic instructions more standardized. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1This is a flow chart of the dynamic instruction generation process of the present invention. DETAILED DESCRIPTION
[0032] The technical solution of the present invention is: a general method for generating dynamic instructions based on Lua language. It is characterized by the following implementation steps:
[0033] (1) Design and implement basic binary standardization processing methods using Lua language, covering standardization processing methods similar to other standard languages (such as C / Java language, etc.), and providing the following interfaces: binary AND / OR operation, binary / decimal / hexadecimal conversion, complement calculation, binary accumulation, etc.;
[0034] (2) Use Lua language to design and implement the checksum calculation method, checksum calculation (international standard CRC-8 / CRC-16 / CRC-32 method);
[0035] (3) Use Lua language to design and implement floating point number processing methods, such as IEEE 754 international standard single-precision floating point number conversion to hexadecimal and double-precision floating point number conversion to hexadecimal;
[0036] (4) Design a Redis memory data interface access method using Lua language: Design and implement the Redis memory database interface so that the master file can obtain the telemetry engineering values, telemetry source code, ground equipment data engineering values, etc. in the Redis memory database in real time through this interface.
[0037] (5) Encapsulate the algorithm library, and put the above functional algorithms and Redis memory database interface access methods as standardized methods into an interface Lua format file, which is called the algorithm library file.
[0038] Each spacecraft establishes its own dynamic instruction management directory, named after the model code, and puts the dynamic instruction generation master file and algorithm library file in it; in the dynamic instruction generation master file of each spacecraft, a call link to the algorithm library file is added, so that the dynamic instruction generation master file can call the common functional algorithm therein to achieve standardized processing of binary data, floating point memory format conversion, etc.; and in the dynamic instruction generation master file, a model identifier, Redis address and port are added to call the Redis memory database interface to access the Redis memory database of this model;
[0039] (6) Spacecraft test personnel design and implement dynamic instruction generation functions in the dynamic instruction generation master file based on the dynamic instruction format and parameters. Each dynamic instruction generation function is used to generate a certain type of dynamic instruction remote control codeword. Specifically, the dynamic instruction generation function generates a certain type of dynamic instruction remote control codeword by calling the method in the algorithm library file.
[0040] (7) After the background dynamic instruction generation main program is started, the dynamic instruction generation main file and algorithm library file in the dynamic instruction management directory of the spacecraft are loaded. The dynamic instruction generation main file connects to the Redis memory database of the spacecraft through the Redis memory database interface in the algorithm library file;
[0041] (8) When the spacecraft needs to set the working state, the tester selects the command to be sent on the console, fills in the parameters to be set according to the current state of the spacecraft, and sends a dynamic command to the background to generate the main program;
[0042] (9) After receiving the dynamic instruction, the background dynamic instruction generation main program parses the received dynamic instruction, parses out the basic information of the dynamic instruction, and checks the validity of the dynamic instruction; when the dynamic instruction is valid, the background dynamic instruction generation main program calls the dynamic instruction generation function and algorithm library file in the dynamic instruction generation main file to perform calculations and generate remote control instruction code words; when the dynamic instruction is invalid, the background dynamic instruction generation main program prompts the error type and error location on the running interface;
[0043] When generating remote control command codewords: the dynamic command generation function in the dynamic command generation master file can call the general function algorithm in the algorithm library file to generate remote control command codewords, or obtain the spacecraft real-time telemetry engineering value in the Redis memory database through the Redis memory database interface to generate remote control command codewords with stronger timeliness, so that the spacecraft can be executed according to the latest status;
[0044] When the algorithm calculation is normal, the remote control command codeword is generated; when the algorithm calculation is abnormal, the abnormality is reported in the execution interface, and the error position and misalignment type are located;
[0045] (10) The remote control command code is generated by the background dynamic command generation main program and sent to the spacecraft for execution. At the same time, in order to facilitate tracking the correctness of the command generation at the time when there is a problem, the remote control command code is added with the sending time information and the command code and saved in an archive file under the specified directory of this spacecraft.
[0046] Specifically, the background dynamic instruction generation main program receives the dynamic instruction command, parses the basic information of the dynamic instruction, calls the algorithm for calculation, and generates the remote control instruction codeword, and performs the following calculation according to the instruction parameters:
[0047] 1) Convert integer to binary, calculate the value of each bit of the integer bit by bit, integrate it into a binary string, and fill it to an integer multiple of 8 according to the settings;
[0048] 2) Convert the hexadecimal number to binary, calculate the value of each bit of the integer bit by bit, integrate it into a binary string, and fill it to an integer multiple of 4;
[0049] 3) Convert binary to integer and calculate the integer value by bit;
[0050] 4) Convert binary to hexadecimal: convert the binary string to a hexadecimal string, and perform padding if the binary length is not an integer multiple of 4;
[0051] 5) Convert floating point numbers to hexadecimal. According to the algorithm specified in the international standard IEEE 754, combined with the binary and integer interchange algorithm, single-precision floating point numbers and double-precision floating point numbers are calculated to obtain hexadecimal numbers;
[0052] 6) Convert non-standard floating point numbers to hexadecimal. According to the algorithm specified by the relevant research institute, combined with the binary and integer interchange algorithm, the non-standard floating point number is calculated to obtain the hexadecimal number.
[0053] 7) Complement calculation: convert the decimal integer into 2-byte / 4-byte / 8-byte hexadecimal complement as required;
[0054] 8) Binary sum calculation: perform sum calculation on one or two binary numbers as words / bytes as required;
[0055] 9) Binary AND operation, perform AND operation calculation on binary numbers bit by bit
[0056] 10) Binary OR operation, perform bitwise OR operation on binary numbers
[0057] 11) Binary AND or operation, perform AND or operation calculation on binary numbers bit by bit
[0058] 12) Parity bit calculation, perform parity calculation on binary numbers bit by bit;
[0059] 13) Checksum calculation: checksum calculation of input data, supporting common checksum algorithms;
[0060] 14) Data scrambling: scrambling the input data;
[0061] 15) Temperature threshold conversion, calculate the temperature threshold according to the preset value;
[0062] 16) Get the telemetry engineering value from the Redis memory database, access the Redis memory database, and get the telemetry parameter engineering value;
[0063] 17) Get the telemetry source code from the Redis memory database, access the Redis memory database, and get the telemetry parameter source code.
[0064] 18) Remote control command code saving: save the generated dynamic command remote control code to a file and record key information, including remote control command code, generation time, etc.
[0065] Example:
[0066] The implementation of the present invention includes a binary standardized data processing method based on Lua scripting language, a general algorithm processing method based on Lua scripting language, a Lua scripting language and Redis memory database access interface, and a standardized dynamic instruction generation method. The implementation process is as follows.
[0067] In the implementation of steps (1), (2), (3), (4), (5), (6), (7), (8), (9), and (10) in the technical solution of the present invention, the specific process is as follows.
[0068] A. Based on the integer and string processing method provided by Lua language itself, modulo 2 processing is used to obtain binary numbers. Referring to the binary processing methods of other standard languages (such as C / Java language, etc.), the processing methods are designed according to the conversion between integer and binary numbers, the conversion between hexadecimal numbers and binary numbers, the bitwise operation of binary numbers, the complement calculation, etc., to realize various operations and number system conversions on binary data, and save them in the algorithm library file; the binary data processing method of Lua scripting language is shown in Table 1.
[0069] Table 1 Binary data processing method of Lua scripting language
[0070]
[0071]
[0072] B. Use Lua language to design and implement methods used for dynamic instruction generation, including: various checksum calculations, instruction file storage, etc., which are saved in the algorithm library file.
[0073] Table 2. Spacecraft dynamic command generation method using Lua scripting language
[0074]
[0075] C. Using Lua language, in accordance with the algorithm standard specified in the IEEE 754 international standard, and referring to other standard languages (such as C / Java language, etc.), an algorithm function is designed and implemented to convert floating-point numbers that conform to the IEEE 754 international standard, as shown in Table 3, and saved in the algorithm library file.
[0076] Table 3 Floating point number processing method of Lua scripting language
[0077]
[0078]
[0079] D. Using Lua language, design and implement the calling interface with Redis memory database, including methods such as obtaining telemetry parameter engineering values and source code from Redis memory database in real time, as shown in Table 4, and save in the algorithm library file.
[0080] Table 4 Lua scripting language and Redis memory database access interface
[0081]
[0082] E. Create a dynamic instruction management directory according to the spacecraft model code, put the dynamic instruction generation main file and algorithm library file into the directory, and add a reference to the algorithm library, model code, Redis memory database address and port to the head of the dynamic instruction generation main file. In the dynamic instruction generation main file, add the following content to load the algorithm library:
[0083] obj = io.popen("cd")
[0084] path=obj:read("*all"):sub(1,-2)
[0085] obj:close()
[0086] path = ". / lua_util.lua"
[0087] dofile(path)
[0088] To realize data transfer between Lua and Redis, add the following content to the main file for dynamic instruction generation:
[0089] package.path=" / src / ?.lua;src / ?.lua;"..package.path
[0090] pcall(require,"luarocks.require")
[0091] F. The spacecraft test personnel shall add a generation function for each dynamic instruction in the dynamic instruction generation master file according to the dynamic instruction format and specifications of this spacecraft, define the parameters and processing steps to be input for the dynamic instruction, and reference the algorithm library for calculation and processing.
[0092] G. Start the background dynamic instruction generation main program, load the algorithm library into the background dynamic instruction generation main program, and connect to the Redis memory database of this spacecraft.
[0093] H. The tester selects the dynamic instruction through the console, fills in the values of each parameter of the dynamic instruction, and sends it to the background dynamic instruction to generate the main program.
[0094] I. The main program of background dynamic instruction generation analyzes the dynamic instruction, determines which functions in the Lua language algorithm library need to be used, calls and executes these functions, and generates the remote control code of the dynamic instruction. When the execution is abnormal, the abnormal information is reported in the execution interface, including the location of the error in the code and the error type, which is convenient for testers to locate the problem and handle it.
[0095] J. After the remote control codeword is generated, the background dynamic instruction generation main program calls the save function in the Lua language's dynamic instruction general processing function library to save the remote control codeword and related instruction information to the archive directory for subsequent comparison and analysis. At the same time, the background dynamic instruction generation main program sends it to the spacecraft for execution.
[0096] The contents not described in detail in the specification of the present invention belong to the prior art known to the professional and technical personnel in this field.
Claims
1. A general method for generating dynamic instructions based on Lua language, characterized in that include: Use Lua language to design general functional algorithms, including: basic binary standardization processing method, checksum calculation method, floating point number processing method; also use Lua language to design Redis memory database interface access method; Encapsulate the above functional algorithms and Redis memory database interface access method into an interface Lua format file as an algorithm library file; A dynamic instruction management directory is established for each spacecraft, and the dynamic instruction generation master file and algorithm library file are placed in it. At the same time, a call link to the algorithm library file, spacecraft model identification, Redis address and port are added to the dynamic instruction generation master file of each spacecraft; The tester designs and implements the dynamic instruction generation function in the dynamic instruction generation master file according to the dynamic instruction format and parameters; After the background dynamic instruction generation main program is started, the dynamic instruction generation main file and algorithm library file in the dynamic instruction management directory of the spacecraft are loaded, so that the dynamic instruction generation main file is connected to the Redis memory database of the spacecraft through the Redis memory database interface in the algorithm library file; Select the dynamic command to be sent on the console, fill in the parameters to be set according to the spacecraft status, and send the dynamic command to the background to generate the main program; After receiving the dynamic instruction, the background dynamic instruction generation main program parses it, parses out the basic information of the dynamic instruction, and checks the validity of the dynamic instruction; when the dynamic instruction is valid, the background dynamic instruction generation main program calls the dynamic instruction generation function and algorithm library file in the dynamic instruction generation main file to calculate and generate the remote control instruction codeword; when the dynamic instruction is invalid, the background dynamic instruction generation main program prompts the error type and error location in the running interface; The background dynamic command generation main program sends the generated remote control command code to the spacecraft for execution, and saves the remote control command code together with the sending time information and the command code into an archive file in the specified directory of the spacecraft.
2. The general method for generating dynamic instructions based on Lua language according to claim 1, characterized in that: There are many dynamic instruction generation functions, and each dynamic instruction generation function generates a certain type of dynamic instruction remote control codeword by calling a method in an algorithm library file.
3. The general method for generating dynamic instructions based on Lua language according to claim 1, characterized in that: Generate remote control command codewords in any of the following ways: The dynamic instruction generation function in the dynamic instruction generation main file calls the general algorithm in the algorithm library file to generate the remote control instruction codeword. The real-time telemetry engineering values of the spacecraft in the Redis memory database are obtained through the Redis memory database interface, and remote control command codewords with stronger timeliness are calculated and generated, so that the spacecraft can execute according to the latest status.
4. The general method for generating dynamic instructions based on Lua language according to claim 1, characterized in that: The basic binary normalization processing method provides the following interfaces: binary AND / OR operation, conversion between binary / decimal / hexadecimal, complement calculation, and binary accumulation and addition.
5. The general method for generating dynamic instructions based on Lua language according to claim 1, characterized in that: When the Lua language is used to design and implement the checksum calculation method, the international standard CRC-8 / CRC-16 / CRC-32 method is adopted.
6. The general method for generating dynamic instructions based on Lua language according to claim 1, characterized in that: When the Lua language is used to design and implement the floating point number processing method, the method of converting single-precision floating point numbers to hexadecimal and double-precision floating point numbers to hexadecimal is based on the IEEE 754 international standard.
7. The general method for generating dynamic instructions based on Lua language according to claim 1, characterized in that: The Redis memory database interface provides the Redis address and port, so that the dynamic instruction generation master file can obtain the telemetry engineering values, telemetry source code, and ground equipment data engineering values in the Redis memory database in real time.
8. The general method for generating dynamic instructions based on Lua language according to claim 1, characterized in that: When the dynamic instruction is valid, the background dynamic instruction generation main program calls the dynamic instruction generation function and algorithm library file in the dynamic instruction generation main file to perform calculations: When the algorithm calculation is normal, a remote control command code word is generated; When the algorithm calculation is abnormal, the exception is reported on the execution interface, and the error location and misalignment type are located.
