Disclosure of Invention
The invention aims to provide a flexible and efficient compression mechanism for black and white screens, so that the data volume of dot matrix data transmitted to the screens by a management CPU is minimized, the data transmission efficiency is improved, and the user experience is improved.
In order to achieve the purpose, the technical scheme adopted by the invention is as follows:
the compression algorithm of black and white dot matrix data in the power system protection device comprises the following steps
S01, reading original dot matrix data of one byte, judging whether the current byte is 0 or 0xFF, if not, copying the read original data to a compressed data writing position, and if so, carrying out the next step;
s02, copying the read original data into the compressed data and starting counting, wherein the counted number is the same as the number of the continuous original data of the current byte;
when the S03 reads a byte different from the original data in the step S02, the process returns to the step S01.
Further, in the step S02, the counter is counted by using a counter.
Further, when the count number reaches 255 in the step S02, the count number is copied to the compressed data, and then the counter is cleared by 0, and then the process returns to S01.
Further, the counting rule is: in step S01, if the read data is 0 or 0xFF, the counter is set to 1, otherwise the counter is cleared to 0.
Further, when the original data of the previous byte is the same as the original data of the current byte, the counter is added by 1, if the counter reaches 0xFF, the counter value is copied to the current position of the compressed data, and then the counter is cleared by 0.
The invention also relates to a decompression algorithm for the black and white dot matrix data compression algorithm in the power system protection device, which comprises the following steps
S01, reading one byte of compressed data from the read pointer position of the source data;
s02 if the data is not 0x00 or 0xFF, copying the data to a destination buffer; otherwise, repeatedly copying 0x00 or 0xFF to the destination buffer; wherein the number of repetitions is determined by the value of the next position of the read pointer in the source data buffer.
The beneficial effects produced by the invention comprise: the next byte of each 0xFF or 0 in the compression algorithm represents the number of 0xFF or 0. Bytes other than 0 and 0xFF remain unchanged. After the compression by the algorithm, in practical engineering application, the black-and-white dot matrix data per second is reduced from 480K bytes to about 168K bytes, which is about 35% of the original data. Preferably, the amount of data transferred is only 0.78% of the original amount when the screen is fully black or fully white.
The algorithm is a lossless compression algorithm, the algorithm can copy data and compress the data at the same time without traversing the data for two times, the algorithm can copy the data and decompress the data at the same time, the decompression of the front data is irrelevant to the rear data, the actual engineering application effect of the algorithm is good, the data volume is reduced by 35 percent on average, and the data volume of the special interface is reduced by 99 percent.
Detailed Description
The present invention is explained in further detail below with reference to the drawings and the specific embodiments, but it should be understood that the scope of the present invention is not limited to the specific embodiments.
As shown in FIG. 1, the method of the present invention
The method comprises the following steps:
1. the method comprises the steps that a management CPU reads original dot matrix data of one byte first, if the read data are 0 or 0xFF, a counter in the management CPU starts counting, and if the read data are not 0x00 or 0xFF, the counter does not count, and the counter is zero;
2. if the compressed data counter of the management CPU has started counting, go to step 3; otherwise, jumping to the step 5;
3. if the original data of the previous byte is the same as the original data of the current byte, directly going to step 4; otherwise, the value of the counter is copied to the compressed data writing position, and then the original data of the current byte is copied to the next position of the compressed data. If the copied data is 0x00 or 0xFF, the counter is set to 1, otherwise the counter is cleared to 0 and the process returns to step 1.
4. And when the data of the previous byte is the same as the data of the current byte, the counter is added by one. If the counter reaches 255, the counter is copied to the current position of the compressed data, then the counter is cleared, and the step 1 is returned to.
5. The counter is 0, which indicates that the previous original byte data is not 0x00 or 0xFF, the latest original data is read and the value is copied into the compressed data, and if the value is not 0x00 or 0xFF, the step 1 is directly returned to; otherwise, the counter is set to 1, and then the procedure returns to step 1.
The above summary is to read the original data, if the original data is 0x00, the counter shows 1, then sequentially reads the following bytes, if the following data is next to n 0x00, the counter finally shows n +1, then the n +1 0 final compression result is 0x00 n +1, where n +1 < 255;
if n +1 ≧ 255, the compression reaches 255 as 0x 00255, and then recounted and compressed to 0x00 n-254.
The counting method of 0xFF is the same as 0x 00.
If the original data is not 0x00 or 0xFF, the read original data is directly written into the compressed data.
And compressing the bytes in sequence according to the method to form new compressed data.
Examples of the invention
The compressed data is as follows:
0x50,0xFF,0xFF,0xFF,0x03,0x0,0xFF,0x00,0x03,0x03
the above row of compressed data is explained in detail as follows:
the first byte: 0x50 represents an uncompressed data
Second, three bytes: 0xFF,0xFF represents 255 0 xFFs
Fourth, five bytes: 0xFF,0x03 denotes 3 0 xFFs
Sixth, seven bytes: 0x00,0xFF represents 255 0x00
Eighth, nine bytes: 0x00,0x03 represents 3 pieces of 0x00
The tenth byte: 0x03 represents an uncompressed data.
The following is a decompression flow of the FF0 decompression algorithm, and it is assumed that data compressed by the relay protection device is placed in a source data buffer and a decompressed result is placed in a destination data buffer.
1. One byte of compressed data is first read from the read pointer location of the source data buffer.
2. If the data is not 0x00 or 0xFF, copying the data to a destination data buffer; otherwise, repeatedly copying the 0x00 or 0xFF data to the destination data buffer; where the number of repetitions is determined by the next position of the source data buffer read pointer.
A typical black-white liquid crystal lattice interface shown in the following figure 2 is compressed by an FF0 compression algorithm, and the transmitted data volume is actually measured to be reduced to 23.36 percent of the original data volume
The above description is only a preferred embodiment of the present invention, and the present invention is not limited to the content of the embodiment. It will be apparent to those skilled in the art that various changes and modifications can be made within the technical scope of the present invention, and any changes and modifications made are within the protective scope of the present invention.