LCU logic expression analysis and truth table calculation method

Through customized logical expression rules and Lua script template analysis, the complexity problem of LCU logical expression truth table calculation is solved, fast and accurate truth table calculation is achieved, and it is suitable for automated testing of LCU.

CN118732646APending Publication Date: 2024-10-01HENAN THINKER TRACK TRAFFIC TECH RES INST
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410666395.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-28
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

When manually calculating the truth table of LCU logical expressions, the workload is heavy and it is difficult to ensure correctness when there are many variables and complex calculation rules, especially when verifying the built-in software logic of LCU.

Method used

By customizing logical expression rules, a reserved dictionary is established, logical expressions are normalized, output variables and input variable lists are obtained, Lua script templates are generated, logical expressions are parsed and truth tables are calculated.

Benefits of technology

It achieves fast and accurate retrieval of input variables and output variables, identifies logical relationships, and calculates truth tables, which is suitable for automated testing of LCU.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118732646A_ABST
    Figure CN118732646A_ABST
Patent Text Reader

Abstract

The invention discloses an LCU (Logical Control Unit) logic expression analysis and truth table calculation method, which comprises the following steps of: customizing a rule of a logic expression according to functions and built-in logic characteristics of an LCU; establishing a reserved word dictionary RD according to a logic expression rule; obtaining any logic expression of the LCU, normalizing the logic expression, and obtaining an output variable list and an input variable list in the logic expression; according to the method, the Lua script template is generated, the logic expression is analyzed according to the output variable and the input variable, the truth table is calculated, the input variable and the output variable in the expression can be quickly retrieved, the logic relation between the expressions can be recognized, the truth table is quickly calculated and used for LCU automatic testing, and the method has the advantages of being quick and accurate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of rail vehicle logic control, and in particular relates to a method for analyzing an LCU logic expression and calculating a truth table. Background Art

[0002] LCU is the train's contactless programmable logic control unit Logic Cotrol Unit, an electronic device based on PLC technology. It is a set of on-board computer systems designed specifically for the logic control of rail vehicles. It uses computer and network technology to replace the train's traditional intermediate relays, time relays, bistable relays and other contact control circuits through contactless circuits such as optocouplers and field effect transistors to achieve train logic control, fault diagnosis and comprehensive protection functions.

[0003] LCU collects the switch input status of the train in real time, such as control signals of train switches, buttons, relay auxiliary contacts, etc., calculates the output control status in real time through built-in software logic, and refreshes the output results to realize train control.

[0004] In order to verify whether the built-in software logic of the LCU is correct, it is necessary to calculate the truth table based on the input signal and output signal of the LCU, and judge whether the output of the LCU is consistent with the truth table based on the truth table. For a specific model of LCU, its internal logic is fixed, and the truth table can be calculated manually. However, when there are many variables in the logical expression or the calculation rules are complicated, the manual calculation of the truth table is labor-intensive and it is difficult to ensure correctness. Summary of the invention

[0005] In order to solve the above technical problems, the present invention provides a method for analyzing an LCU logical expression and calculating a truth table.

[0006] The specific plan is as follows: A method for analyzing LCU logic expressions and calculating truth tables comprises the following steps: S1): Customize the rules of logical expressions according to the functions and built-in logic features of LCU; S2): According to the logic expression rules, a reserved word dictionary RD is established; S3): Obtain any logical expression of the LCU, normalize the logical expression, and obtain a list of output variables and input variables in the logical expression; S4): Generate a Lua script template, parse the logical expression according to the output variables and input variables, and calculate the truth table.

[0007] The logical expression rules include: a): The logical expression is a string; b): A logical expression uses an equal sign "=" to separate input variables and output variables. The variable on the left side of the equal sign is the output variable. A logical expression contains one and only one output variable. The output variable starts with "DO" or "VO". "DO" is used to indicate a dry contact, "VO" is used to indicate a wet contact, and a number after "DO" or "VO" indicates a different output variable. The variable on the right side of the equal sign is the input variable. There is at least one input variable in a logical expression. The input variable starts with "IN". A number number after "IN" indicates different input variables. c): The operators supported by the logical expression include "not", "and", "or" and "xor", the operators are lowercase letters, and the logical expression defines the operation priority through the left bracket "(" and the right bracket ")", the left bracket and the right bracket appear in pairs, and the brackets can be nested; d): Delay operations are supported between different logical expressions. This means that after the first logical expression is executed, the second logical expression is automatically executed after a certain delay. The format of the delay operation is "Ex delay T Ey", where Ex represents the xth logical expression, Ey represents the yth logical expression, delay is a reserved word indicating delay, and T is the delay time.

[0008] The reserved word dictionary RD is a string List, which includes a string "not", a string "and", a string "or", a string "xor" and a string "delay".

[0009] The logical expression normalization process includes the following steps: S31): According to the industry-wide character search and replacement algorithm, search for the left bracket, right bracket, and equal sign in the logical expression, and insert space characters on both sides of the left bracket, right bracket, and equal sign; S32): Find the number of equal signs "=" in the logical expression. If the number of equal signs "=" is not equal to 1, an error is reported.

[0010] The method for obtaining the output variable and input variable list in the logical expression includes the following steps: P1): Convert all characters in the logical expression to lowercase characters; P2): Loop through the strings in the reserved word dictionary RD to find out whether there is a matching string in the logical expression. If there is a match, delete the matching string in the logical expression; P3): Create a string list SL containing N elements. At the same time, split the string in step P2) from left to right according to the brackets or spaces, and put the split strings into the string list SL in sequence; P4): Determine whether the first element SL[1] of the string list SL starts with "do" or "vo". If so, assign the first element SL[1] of the string list SL to the variable Varout. If not, the first element SL[1] of the string list SL is not a legal output variable, an error is reported and the analysis process is exited; P5): Determine whether the second element SL[2] of the string list SL is an equal sign "=". If not, the logical expression is considered illegal, an error is reported, and the analysis process is exited; P6): From the third element SL[3] to the last element SL[N] of the string list SL, determine whether each element starts with "IN". If so, add the corresponding element to the input variable list VarInL. When adding elements to the input variable list VarInL, remove the duplicate input variables and sort the input variable list in alphabetical order. The number of elements in the input variable list VarInL is the number of input variables M.

[0011] Parsing a logical expression includes the following steps: S41): Define a 32-bit integer U32 to represent the combination relationship of input variables, that is, a value of U32 represents a combination of input variables. 1 bit in U32 corresponds to an input variable. Each input variable has two values: True and False. Set the number of input variables to M. Then the combination relationship of input variables is 2 M The value range of U32 is 0 to 2 M -1; S42) Define a Lua script function, the function of which is to take out an input variable combination from U32 in turn, assign a value to each input variable according to the taken out input variable combination, calculate the corresponding output variable through a logical expression of the assigned input variable, and establish a truth table based on the assigned input variables and the corresponding calculated output variables.

[0012] The present invention discloses a method for analyzing LCU logic expressions and calculating a truth table, which can quickly retrieve input variables and output variables in expressions, identify logical relationships between expressions, and quickly calculate a truth table for use in LCU automated testing, and has the characteristics of being fast and accurate. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] Figure 1 It is a truth table built based on input variables and output variables. DETAILED DESCRIPTION

[0014] The following will be combined with the accompanying drawings in the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the implementation of the present invention, not all of the implementations. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0015] A method for analyzing LCU logic expressions and calculating truth tables comprises the following steps: S1): Customize the rules of logical expressions according to the functions and built-in logic features of LCU; S2): According to the logic expression rules, a reserved word dictionary RD is established; S3): Obtain any logical expression of the LCU, normalize the logical expression, and obtain a list of output variables and input variables in the logical expression; S4): Generate a Lua script template, parse the logical expression according to the output variables and input variables, and calculate the truth table.

[0016] The logical expression rules include: a): A logical expression is a string; in this embodiment, a logical expression is represented by "E", where "E" is the first letter of the expression. For example, "E: DO1= IN1 and IN2" is a logical expression; b): A logical expression uses an equal sign "=" to separate input variables and output variables. The variable on the left side of the equal sign is the output variable. A logical expression contains one and only one output variable. The output variable starts with "DO" or "VO". "DO" is used to indicate a dry contact, "VO" is used to indicate a wet contact, and a number after "DO" or "VO" indicates a different output variable. For example, in the expression "E: DO1= IN1 and IN2", DO1 on the left side of the equal sign is the output variable. The variable on the right side of the equal sign is the input variable. There is at least one input variable in a logical expression. The input variable starts with "IN". A number after "IN" indicates different input variables. The expression "E: DO1= IN1 and IN2" contains two input variables IN1 and IN2. c): The operators supported by the logical expression include "not", "and", "or" and "xor", the operators are lowercase letters, and the logical expression defines the operation priority through the left bracket "(" and the right bracket ")", the left bracket and the right bracket appear in pairs, and the brackets can be nested; not means a negation operation, which is to perform a negation operation on the input variable, and means an AND operation, or means an OR operation, and xor means an XOR operation; d): Delay operations are supported between different logical expressions. This means that after the first logical expression is executed, the second logical expression is automatically executed after a certain delay. The format of the delay operation is "Ex delay T Ey", where Ex represents the xth logical expression, Ey represents the yth logical expression, delay is a reserved word indicating delay, and T is the delay time in milliseconds.

[0017] For example, "E1delay 5000 E 21 ", which means that after executing the first logic expression, the twenty-first logic expression will be automatically executed after a delay of 5000 milliseconds. An example in the real world is that in a rail vehicle, after turning off the lights in the car, the lights will go out after a delay of 5000 milliseconds.

[0018] The reserved word dictionary RD is a string List, which includes a string “not”, a string “and”, a string “or”, a string “xor” and a string “delay.” In this embodiment, the number of strings in the reserved word dictionary RD is five.

[0019] Assume that there is a logical expression E1: DO1=(IN1 And IN20)or((IN1 and IN15)xorIN4). The normalization process of the logical expression includes the following steps: S31): According to the industry-wide character search and replacement algorithm, search for the left bracket, right bracket, and equal sign in the logical expression, and insert space characters on both sides of the left bracket, right bracket, and equal sign; After executing this step, the logical expression E1 becomes DO1 = ( IN1 And IN20 ) or ( ( IN1 andIN15 ) xor IN4 ); S32): Find the number of equal signs "=" in the logical expression. If the number of equal signs "=" is not equal to 1, an error is reported.

[0020] The method for obtaining the output variable and input variable list in the logical expression includes the following steps: P1): Convert all characters in the logical expression to lowercase characters; after executing step P1), the logical expression E1 becomes do1 = ( in1 and in20 )or ( ( in1 and in15 ) xor in4 ); P2): Loop through the strings in the reserved word dictionary RD to find out whether there is a matching string in the logical expression. If there is a match, delete the matching string in the logical expression; The reserved word dictionary RD includes five strings: "not", "and", "or", "xor", and "delay". Take a string from the reserved word dictionary RD in turn to find out whether there is a matching string in the logical expression. Specifically: First, take out the string "not" and match it with the logical expression E1. The search result is that there is no string matching "not" in E1. Then, the string "and" is taken out to match the logical expression E1. If a string matching "and" is found in E1, the matching string in E1 is deleted. The execution result is do1 = ( in1 in20 ) or (( in1 in15 ) xor in4 ); Then take out the string "or" and match it with the logical expression E1. If a string matching "or" is found in E1, the matching string in E1 will be deleted. The execution result is do1 = (in1 in20) ((in1 in15)xor in4) Then take out the string "xor" and match it with the logical expression E1. If a string matching "xor" is found in E1, the matching string in E1 will be deleted. The execution result is do1 = ( in1 in20 ) ( ( in1in15 ) in4 ); Finally, the string "delay" is matched with the logical expression E1, and the search result is that there is no string matching "delay" in E1; P3): Create a string list SL containing N elements. At the same time, split the string in step P2) from left to right according to the brackets or spaces, and put the split strings into the string list SL in sequence; For expression E1, the result of splitting the string in step P2) from left to right is: do1 = in1 in20 in1 in15 in4; Then the string list SL[]={"do1","="","in1","in20","in1","in15","in4"}; P4): Determine whether the first element SL[0] of the string list SL starts with "do" or "vo". If so, assign the first element SL[0] of the string list SL to the variable Varout. If not, the first element SL[1] of the string list SL is not a legal output variable, an error is reported and the analysis process is exited. In this embodiment, the first element SL[0] of SL is "do1" and starts with do, then Varout=SL[0], that is, Varout=do1; P5): Determine whether the second element SL[1] of the string list SL is an equal sign "=". If not, the logical expression is determined to be illegal, an error is reported, and the analysis process is exited. In this embodiment, the first element SL[1] of SL is an equal sign; P6): From the third element SL[2] to the last element SL[N] of the string list SL, determine whether each element starts with "IN". If so, add the corresponding element to the input variable list VarInL. When adding elements to the input variable list VarInL, remove the repeated input variables and sort the input variable list in alphabetical order. The number of elements in the input variable list VarInL is the number of input variables M. In this embodiment, elements SL[2] to SL[6] in SL all begin with "IN". After removing duplicate input variables and reordering, VarINL includes four character strings "in1", "in4", "in15" and "in20".

[0021] Parsing a logical expression includes the following steps: S41): Define a 32-bit integer U32 to represent the combination relationship of input variables, that is, a value of U32 represents a combination of input variables. 1 bit in U32 corresponds to an input variable. Each input variable has two values: True and False. Set the number of input variables to M. Then the combination relationship of input variables is 2 M The value range of U32 is 0 to 2 M -1; The number of input pins of LCU will not exceed 32, so a 32-bit integer U32 is defined to represent the combination relationship of input variables; In this embodiment, four input variables can be obtained from VarINL after analyzing the logical expression E1, so the value of the number of input variables M is 4, and the number of the four input variables is 2 4 The value range of U32 is 0 to 2.4 -1, that is, 0 to 15.

[0022] like Figure 1 As shown, in U32, each of the 16 combinations includes four storage bits, each of which stores the value of an input variable. That is to say, each combination corresponds to the values ​​of four input variables, the first bit Bit0 corresponds to in1, the second bit Bit1 corresponds to in4, the third bit Bit2 corresponds to in15, and the fourth bit Bit3 corresponds to in20; S42) Define a Lua script function, the function of which is to take out an input variable combination from U32 in turn, assign a value to each input variable according to the taken out input variable combination, calculate the corresponding output variable through a logical expression of the assigned input variable, and establish a truth table based on the assigned input variables and the corresponding calculated output variables.

[0023] Lua is an interpreted scripting language that is fast and lightweight and can dynamically change the scripting language of the code at runtime to parse logical expressions; In this embodiment, the pseudo code of the Lua script function is as follows “ function getExpressionResult( ) Assign values ​​to input variables respectively Expression E Return DO End ” In U32, take out a combination value from 0 to 15 in turn and assign it to the four input variables respectively; execute the Lua script to obtain the execution result, which is the output value of the logical expression E under the current combination state of the input variables. Record the values ​​of the input variables and the output variables in the truth table to generate a row of the truth table. After the loop is completed, all combination relationships of the input variables are traversed and the truth table calculation is completed.

[0024] For example, first, take out the 0 combination from U32 and assign values ​​to four variables. At this time, in1=0, in4=0, in15=0, and in20=0. Perform logical operations on the four variables after assignment according to the logical expression E1: DO1=(IN1 And IN20)or((IN1 and IN15)xorIN4). The calculation result of the output variable DO1 is 0. At this time, DO1=0. Then, 1 is taken out from U32 and assigned to four variables. At this time, in1=1, in4=0, in15=0, and in20=0. The four variables after assignment are logically operated according to the logical expression E1: DO1=(IN1 And IN20)or((IN1 and IN15)xorIN4). The calculation result of the output variable DO1 is 0, so DO1=0 at this time. Then take out 2 combinations, 3 combinations, and so on until 15 combinations in turn, and record the value of the output variable DO calculated for each combination.

[0025] The values ​​of the input variables in different combinations and the values ​​of the calculated output variables are used to establish a corresponding relationship table, which is a truth table, such as Figure 1 shown.

[0026] The present invention discloses a method for analyzing LCU logic expressions and calculating a truth table, which can quickly retrieve input variables and output variables in expressions, identify logical relationships between expressions, and quickly calculate a truth table for use in LCU automated testing, and has the characteristics of being fast and accurate.

[0027] The technical means disclosed in the scheme of the present invention are not limited to the technical means disclosed in the above-mentioned implementation mode, but also include technical schemes composed of any combination of the above-mentioned technical features. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications are also regarded as the protection scope of the present invention.

Claims

1. A method for analyzing LCU logical expressions and calculating truth tables, characterized in that: The steps include: S1): Customize the rules of logical expressions according to the functions and built-in logic features of LCU; S2): According to the logic expression rules, a reserved word dictionary RD is established; S3): Obtain any logical expression of the LCU, normalize the logical expression, and obtain a list of output variables and input variables in the logical expression; S4): Generate a Lua script template, parse the logical expression according to the output variables and input variables, and calculate the truth table.

2. The LCU logic expression analysis and truth table calculation method according to claim 1 is characterized in that: The logical expression rules include: a): The logical expression is a string; b): A logical expression uses an equal sign "=" to separate the input variable and the output variable. The variable on the left side of the equal sign is the output variable. A logical expression contains one and only one output variable. The output variable starts with "DO" or "VO". "DO" is used to indicate a dry contact, and "VO" is used to indicate a wet contact. A number number after "DO" or "VO" indicates a different output variable. The variable on the right side of the equal sign is the input variable. There is at least one input variable in a logical expression. The input variable starts with "IN". "IN" followed by a number indicates different input variables. c): The operators supported by the logical expression include "not", "and", "or" and "xor", the operators are lowercase letters, and the logical expression defines the operation priority through the left bracket "(" and the right bracket ")", the left bracket and the right bracket appear in pairs, and brackets can be nested; d): Different logical expressions support associated delay operations, which means that after executing the first logical expression, the second logical expression will be automatically executed after a certain delay. The format of the delay operation is "E x delay TE y ”, where E x represents the xth logical expression, E y It represents the yth logical expression. Delay is a reserved word, indicating delay, and T is the delay time.

3. The LCU logic expression analysis and truth table calculation method according to claim 1 is characterized in that: The reserved word dictionary RD is a string List, which includes a string "not", a string "and", a string "or", a string "xor" and a string "delay".

4. The LCU logic expression analysis and truth table calculation method according to claim 1 is characterized in that: The logical expression normalization process includes the following steps: S31): According to the industry-wide character search and replacement algorithm, search for the left bracket, right bracket, and equal sign in the logical expression, and insert space characters on both sides of the left bracket, right bracket, and equal sign; S32): Find the number of equal signs "=" in the logical expression. If the number of equal signs "=" is not equal to 1, an error is reported.

5. The LCU logic expression analysis and truth table calculation method according to claim 1 is characterized in that: The method for obtaining the output variable and input variable list in the logical expression includes the following steps: P1): Convert all characters in the logical expression to lowercase characters; P2): Loop through the strings in the reserved word dictionary RD to find out whether there is a matching string in the logical expression. If there is a match, delete the matching string in the logical expression; P3): Create a string list SL containing N elements. At the same time, split the string in step P2) from left to right according to the brackets or spaces, and put the split strings into the string list SL in sequence; P4): Determine whether the first element SL[1] of the string list SL starts with "do" or "vo". If so, assign the first element SL[1] of the string list SL to the variable Varout. If not, the first element SL[1] of the string list SL is not a legal output variable, an error is reported and the analysis process is exited; P5): Determine whether the second element SL[2] of the string list SL is an equal sign "=". If not, the logical expression is considered illegal, an error is reported, and the analysis process is exited; P6): From the third element SL[3] to the last element SL[N] of the string list SL, determine whether each element starts with "IN". If so, add the corresponding element to the input variable list VarInL. When adding elements to the input variable list VarInL, remove the duplicate input variables and sort the input variable list in alphabetical order. The number of elements in the input variable list VarInL is the number of input variables M.

6. The LCU logic expression analysis and truth table calculation method according to claim 1 is characterized in that: Parsing a logical expression includes the following steps: S41): Define a 32-bit integer U32 to represent the combination relationship of input variables, that is, a value of U32 represents a combination of input variables. 1 bit in U32 corresponds to an input variable. Each input variable has two values: True and False. Set the number of input variables to M. Then the combination relationship of input variables is 2 M The value range of U32 is 0 to 2 M -1; S42) Define a Lua script function, the function of which is to take out an input variable combination from U32 in turn, assign a value to each input variable according to the taken out input variable combination, calculate the corresponding output variable through a logical expression of the assigned input variable, and establish a truth table based on the assigned input variables and the corresponding calculated output variables.