Decoding method for magnetic stripe card swiping terminal

文档序号:1477867 发布日期:2020-02-25 浏览:35次 中文

阅读说明:本技术 一种磁条卡刷卡终端解码方法 (Decoding method for magnetic stripe card swiping terminal ) 是由 李滨滨 于 2019-11-05 设计创作,主要内容包括:本发明公开了一种磁条卡刷卡终端解码方法,所述磁条卡中设置有磁卡芯片,所述刷卡终端内设置有处理器;所述解码方法包括,S1、刷卡时,所述磁卡芯片与所述处理器相连,判断处理器监测是否发生中断;若是,则处理器关闭中断,开启超时计时并执行步骤S2;若否,则退出中断;S2、更新计时计数;S3、所述处理器读取其外部三个IO的电平状态,判断是否有IO发生电平跳变,若是,则将发生电平跳变的IO与该IO上次跳变的时间间隔记录到该IO对应的数组中,各所述IO分别对应一个磁道,各磁道分别对应一个T数组,并执行S4;若否,则直接执行S4;等步骤。优点是:增加了解码的成功率,降低了上报误码概率,降低了设计成本,改善了用户使用体验。(The invention discloses a decoding method for a magnetic stripe card swiping terminal, wherein a magnetic card chip is arranged in a magnetic stripe card, and a processor is arranged in the card swiping terminal; s1, when the card is swiped, the magnetic card chip is connected with the processor to judge whether the processor monitors interruption; if yes, the processor closes the interrupt, starts the timeout timer and executes the step S2; if not, exiting the interruption; s2, updating the timing count; s3, the processor reads the level states of three external IOs, judges whether the IO has level jump or not, if so, records the IO with level jump and the time interval of the last jump of the IO into an array corresponding to the IO, each IO corresponds to one magnetic track, each magnetic track corresponds to one T array, and executes S4; if not, directly executing S4; and the like. The advantages are that: the success rate of decoding is increased, the probability of reporting error codes is reduced, the design cost is reduced, and the user experience is improved.)

1. A magnetic stripe card is provided with a magnetic card chip, and a card swiping terminal is internally provided with a processor; the method is characterized in that: the decoding method comprises the steps of, after decoding,

s1, when the card is swiped, the magnetic card chip is connected with the processor, and whether the monitoring of the processor is interrupted or not is judged; if yes, the processor closes the interrupt, starts the timeout timer and executes the step S2; if not, exiting the interruption;

s2, updating the timing count;

s3, the processor reads the level states of three external IOs, judges whether the IO has level jump or not, if so, records the IO with level jump and the time interval of the last jump of the IO into an array corresponding to the IO, each IO corresponds to one magnetic track, each magnetic track corresponds to one T array, and executes S4; if not, directly executing S4;

s4, the processor judges whether the overtime exceeds the preset time length, if yes, the step S5 is executed; if not, returning to the step S2;

s5, copying the T array content of one track into the p array by the processor;

s6, the processor decodes the time interval data in the p array into binary data, and the binary data is stored in the m array;

s7, the processor decodes the binary data according to the coding format to obtain decoded data, stores the decoded data in an m _ bit array, finds the corresponding ASCII code of the decoded data according to a table look-up mode to obtain corresponding data, and stores the corresponding data in an out array;

s8, the processor checks the decoded data and the corresponding data, if the check is passed, the step S9 is executed; if the verification fails, go to step S10;

s9, the processor transfers the corresponding data to the global data, the processor sets the successful flag of the magnetic track card swiping, and executes the step S11;

s10, the processor sets the failure flag of the magnetic track card swiping, and executes the step S11;

s11, repeating the steps S5 to S10; judging whether the T arrays corresponding to the three magnetic tracks are completely analyzed, and if so, exiting the interruption; if not, the process returns to step S5.

2. The magnetic stripe card swiping terminal decoding method according to claim 1, characterized in that: in step S6, the processor decodes the time interval data in the p array into binary data, specifically,

a1, acquiring an array pointer p of the p array, and setting the length of time interval data to be decoded to len and the initial reference value to bitlen;

a2, defining the count value as I, j, and endowing both I and j with an initial value of 0; defining a first skip and a second skip of the zone bits, and endowing the first skip and the second skip with an initial value of 0;

a3, judging whether i is less than len-1, if yes, executing step S44; if not, executing the step A4;

a4, judging whether the first skip is equal to 0, if yes, executing S47, and if no, executing A5;

a5, assigning the first skip as 0;

adding 1 to the value of A6 and i, and returning to S43;

a7, judging p [ i ] < bitlen 0.7, namely judging whether the ith bit of p is less than 0.7 times of a reference value bitlen; if yes, A8 is executed; if not, executing A11;

a8, judging p [ i +1] < bitlen 0.7, namely judging whether the i +1 th bit of p is less than 0.7 times of a reference value bitlen; if yes, A9 is executed; if not, executing A11;

a9, judging whether the sum of the data of the ith bit and the i +1 bit of p is less than 1.4 times of a reference value or not, namely judging whether the sum of the data of the ith bit and the i +1 bit of p is less than 1.4 times of the reference value; if yes, A10 is executed; if not, executing A11;

a10, updating bitlen, and calculating bitlen ═ bitlen × 0.8+ (p [ i ] + p [ i +1]) × 0.2; taking the weight of 80% of the original reference value plus the weight of 20% of the sum of the ith bit and the (i + 1) th bit of p as a new reference value; executing m [ j + + ] -1, and the second Skip-1, namely the decoding result is 1, recording the data at the j position of the m array, and simultaneously adding 1 to the value of j, setting the second Skip as 1; and jumps to A6;

a11, judging p [ i ] < bitlen 0.8, namely judging whether the ith data of p is less than 0.8 times of a reference value bitlen; if yes, go to step S412; if not, executing A13;

a12, executing p [ i +1] ═ p [ i +1] - ((Bitlen-p [ i ]) 0.8), namely, updating the i +1 th bit data of p into the i +1 th bit data of p minus the 80% weight of the difference value between the reference value and the i-th bit data of p;

a13, executing BItlen 0.8+ p [ i ] 0.2m [ j + + ] -0, namely, the decoding result is 0, recording the result to j bits of the m arrays, and increasing the count value j by 1; jumping to execute A6;

wherein, p represents an array pointer of a p array; m represents an m array; len is the data length of the time interval to be decoded; bitlen is an initial reference value; i is a count value of a p array; j is the count value of the m array; the first skip is a zone bit of a p array, and the second skip is a zone bit of an m array; skip indicates whether the current flag bit is skipped.

3. The magnetic stripe card swiping terminal decoding method according to claim 1, characterized in that: the process of converting the binary data into ASCII code in step S7, specifically,

b1, substituting the parameters m, len, ch and out into a first analytical function;

b2, taking i, j as a count value, and respectively recording the position of binary data to be decoded and the position of storing an ASCII code; assigning initial values of i, j, start and c as 0;

b3, judging whether i is smaller than len, if so, adding 1 to i; if not, adding 1 to i and then executing B6;

b4, judging whether the ith bit in m is not 0, if yes, executing B5; if not, execute B3;

b5, assigning the data i to start, and indicating that the current position is assigned to start;

b6, judging whether ch is 0, namely judging whether the current magnetic track is a1 magnetic track; if yes, execute B7; if not, execute B9;

b7, updating the count value i to be the record value of start;

b8, judging whether i is smaller than the difference value of len-5, if yes, executing B10; if not, execute B9;

b9, updating the record value with the count value i as the start, and executing B15;

b10, calculation

c ═ c (m [ i +6] < <6) + (m [ i +5] < <5) + (m [ i +4] < <4) + (m [ i +3] < <3) + (m [ i +2] < <2) + (m [ i +1] < <1) + (m [ i ]); namely, 7 data are taken from the i position of m, calculated according to a formula and given to c;

b11, clearing the highest bit of c to 0;

b12, substituting the character c into the table track1cset, and if the position indicated by c is not 0, executing B14; if not, execute B13;

b13, adding 1 to the value of i, and jumping to execute A8;

b14, assigning the data of the position c in the table to the j bit of the out array, recording the value of c to the m _ bit array of the array, and adding 1 to j;

b15, judging whether the value i is smaller than the difference value of len-5, if yes, executing B16; if not, B21 is executed.

B16, calculation

c is (m [ i +4] < <4) + (m [ i +3] < <3) + (m [ i +2] < <2) + (m [ i +1] < <1) + (m [ i ]), namely 5 data are taken from the i position of m, calculated according to a formula and given to c;

b17, clearing the highest 3 bits of c to 0;

b18, substituting c into the table track3cset, judging whether the data of the c position in the table is not 0, if yes, executing B19; if not, execute B20;

b19, assigning the value of the position c in the table to the j bit in the out array, recording the value of c in the m _ bit array of the array, and adding 1 to j;

b20, i is added with 1, and the jump is executed B15;

b21, assigning the value of the j-1 position in the out array to be 0;

b22, returning the value of j and exiting the first analytical function;

wherein m is an m array; len is the data length decoded from binary data; ch is the track number; start is the track valid data position; c is the result of the current decoding; i is a count value in the m array; j is the count value in the out array.

4. The magnetic stripe card swiping terminal decoding method according to claim 1, characterized in that: in step S8, the processor performs a verification process on the decoded data and the corresponding data, specifically,

and C1, substituting the m _ bit array, the size and the ch of the parameters into a second analytic function.

C2, definition lrc, and assigned a value of 0; definition lrc _ p, assigned a value of 0; defining a code length value bits and defining counting values i and j;

c3, judging whether ch is 0, namely judging whether the current track is 0; if yes, go to C5; if not, go to C4;

c4, startb assigned 0x0 b; endb is assigned a value of 0x1 f; bits is assigned a value of 4; namely, the start flag bit 0x0b and the end flag bit 0x1f of the data length of 4 are determined, and C6 is performed;

c5, startb assigned 0x 45; endb is assigned a value of 0x1 f; the bits is assigned a value of 6; namely, the start bit flag 0x45 and the end bit flag 0x1f of the judgment data are 6 in data length;

c6, judging whether m _ bit [0] is equal to startb, namely judging whether the data head is correct; if yes, go to C7; if not, go to C23;

c7, assigning the count value i to be 0;

c8, judging whether i is smaller than size, if yes, executing C9; if not, go to C12;

c9, calculating lrc according to a formula, wherein lrc is lrc ^ m _ bit [ i ]; computing lrc exclusive or sum of valid data;

c10, judging whether the value of the i bit in the m _ bit array is equal to endb, namely judging whether an ending mark is found; if yes, go to C13; if not, go to C11;

c11, adding 1 to the value of i; jump execution C8;

c12, judging whether the value of the i bit in the m _ bit array is equal to endb, namely judging whether an ending mark is found; if yes, execute B13; if not, executing C22;

c13, assigning j to 0;

c14, judging whether j is smaller than bits, if so, executing B15; if not, go to C17;

c15, calculating lrc _ p ^ (lrc & (1< < j)) > > j according to a formula;

c16, j value plus 1; jump execution C14;

c17, calculating lrc _ p ^ 1 according to a formula;

c18, calculating lrc & (1< < bits) -1 according to a formula; lrc ═ lrc | (lrc _ p < < bits);

c19, determine whether m _ bit [ i +1] is equal to lrc, i.e., determine lrc is correct; if yes, go to C20; if not, go to C21;

c20, return data value 0;

c21, return data value 3;

c22, return data value 2;

c23, return data value 1;

wherein, size is data length; ch is track data; startb is track start data; endb is track end data; lrc is a check byte; lrc _ p is the parity bit of the check byte; bits is a data coding length mark; i is the count value of the m _ bit array; j is the count value of the second analytical function.

Technical Field

The invention relates to the field of electronic communication and financial payment, in particular to a decoding method for a magnetic stripe card swiping terminal.

Background

In daily life, the magnetic stripe card is used as a carrier for information recording, and has the advantages of low cost, high strength, and convenient, stable and reliable carrying. Is widely applied to the fields of various bank cards, gift cards, transportation cards and the like. The financial terminal is used as a card reading device and can read the magnetic stripe card. But with the wide application, some problems are brought. For example, after the magnetic stripe card is used for a period of time, the recognition rate is reduced due to abrasion; the card swiping speeds of users are inconsistent, and the habits of positive and negative swiping are different, so that the magnetic card is not easy to be identified and read by equipment; in order to ensure that the card reading and reading rate is increased with a plurality of software and hardware functions during design, the cost is increased.

Disclosure of Invention

The invention aims to provide a decoding method for a magnetic stripe card swiping card terminal, so as to solve the problems in the prior art.

In order to achieve the purpose, the technical scheme adopted by the invention is as follows:

a magnetic stripe card is provided with a magnetic card chip, and a card swiping terminal is internally provided with a processor; the decoding method comprises the steps of, after decoding,

s1, when the card is swiped, the magnetic card chip is connected with the processor, and whether the monitoring of the processor is interrupted or not is judged; if yes, the processor closes the interrupt, starts the timeout timer and executes the step S2; if not, exiting the interruption;

s2, updating the timing count;

s3, the processor reads the level states of three external IOs, judges whether the IO has level jump or not, if so, records the IO with level jump and the time interval of the last jump of the IO into an array corresponding to the IO, each IO corresponds to one magnetic track, each magnetic track corresponds to one T array, and executes S4; if not, directly executing S4;

s4, the processor judges whether the overtime exceeds the preset time length, if yes, the step S5 is executed; if not, returning to the step S2;

s5, copying the T array content of one track into the p array by the processor;

s6, the processor decodes the time interval data in the p array into binary data, and the binary data is stored in the m array;

s7, the processor decodes the binary data according to the coding format to obtain decoded data, stores the decoded data in an m _ bit array, finds the corresponding ASCII code of the decoded data according to a table look-up mode to obtain corresponding data, and stores the corresponding data in an out array;

s8, the processor checks the decoded data and the corresponding data, if the check is passed, the step S9 is executed; if the verification fails, go to step S10;

s9, the processor transfers the corresponding data to the global data, the processor sets the successful flag of the magnetic track card swiping, and executes the step S11;

s10, the processor sets the failure flag of the magnetic track card swiping, and executes the step S11;

s11, repeating the steps S5 to S10; judging whether the T arrays corresponding to the three magnetic tracks are completely analyzed, and if so, exiting the interruption; if not, the process returns to step S5.

Preferably, the processor decodes the time interval data in the p array into binary data in step S6, specifically,

a1, acquiring an array pointer p of the p array, and setting the length of time interval data to be decoded to len and the initial reference value to bitlen;

a2, defining the count value as I, j, and endowing both I and j with an initial value of 0; defining a first skip and a second skip of the zone bits, and endowing the first skip and the second skip with an initial value of 0;

a3, judging whether i is less than len-1, if yes, executing step S44; if not, executing the step A4;

a4, judging whether the first skip is equal to 0, if yes, executing S47, and if no, executing A5;

a5, assigning the first skip as 0;

adding 1 to the value of A6 and i, and returning to S43;

a7, judging p [ i ] < bitlen 0.7, namely judging whether the ith bit of p is less than 0.7 times of a reference value bitlen; if yes, A8 is executed; if not, executing A11;

a8, judging p [ i +1] < bitlen 0.7, namely judging whether the i +1 th bit of p is less than 0.7 times of a reference value bitlen; if yes, A9 is executed; if not, executing A11;

a9, judging whether the sum of the data of the ith bit and the i +1 bit of p is less than 1.4 times of a reference value or not, namely judging whether the sum of the data of the ith bit and the i +1 bit of p is less than 1.4 times of the reference value; if yes, A10 is executed; if not, executing A11;

a10, updating bitlen, and calculating bitlen ═ bitlen × 0.8+ (p [ i ] + p [ i +1]) × 0.2; taking the weight of 80% of the original reference value plus the weight of 20% of the sum of the ith bit and the (i + 1) th bit of p as a new reference value; executing m [ j + + ] -1, and the second Skip-1, namely the decoding result is 1, recording the data at the j position of the m array, and simultaneously adding 1 to the value of j, setting the second Skip as 1; and jumps to A6;

a11, judging p [ i ] < bitlen 0.8, namely judging whether the ith data of p is less than 0.8 times of a reference value bitlen; if yes, go to step S412; if not, executing A13;

a12, executing p [ i +1] ═ p [ i +1] - ((Bitlen-p [ i ]) 0.8), namely, updating the i +1 th bit data of p into the i +1 th bit data of p minus the 80% weight of the difference value between the reference value and the i-th bit data of p;

a13, executing BItlen 0.8+ p [ i ] 0.2m [ j + + ] -0, namely, the decoding result is 0, recording the result to j bits of the m arrays, and increasing the count value j by 1; jumping to execute A6;

wherein, p represents an array pointer of a p array; m represents an m array; len is the data length of the time interval to be decoded; bitlen is an initial reference value; i is a count value of a p array; j is the count value of the m array; the first skip is a zone bit of a p array, and the second skip is a zone bit of an m array; skip indicates whether the current flag bit is skipped.

Preferably, the process of converting the binary data into ASCII code in step S7, specifically,

b1, substituting the parameters m, len, ch and out into a first analytical function;

b2, taking i, j as a count value, and respectively recording the position of binary data to be decoded and the position of storing an ASCII code; assigning initial values of i, j, start and c as 0;

b3, judging whether i is smaller than len, if so, adding 1 to i; if not, adding 1 to i and then executing B6;

b4, judging whether the ith bit in m is not 0, if yes, executing B5; if not, execute B3;

b5, assigning the data i to start, and indicating that the current position is assigned to start;

b6, judging whether ch is 0, namely judging whether the current magnetic track is a1 magnetic track; if yes, execute B7; if not, execute B9;

b7, updating the count value i to be the record value of start;

b8, judging whether i is smaller than the difference value of len-5, if yes, executing B10; if not, execute B9;

b9, updating the record value with the count value i as the start, and executing B15;

b10, calculation

c ═ c (m [ i +6] < <6) + (m [ i +5] < <5) + (m [ i +4] < <4) + (m [ i +3] < <3) + (m [ i +2] < <2) + (m [ i +1] < <1) + (m [ i ]); namely, 7 data are taken from the i position of m, calculated according to a formula and given to c;

b11, clearing the highest bit of c to 0;

b12, substituting the character c into the table track1cset, and if the position indicated by c is not 0, executing B14; if not, execute B13;

b13, adding 1 to the value of i, and jumping to execute A8;

b14, assigning the data of the position c in the table to the j bit of the out array, recording the value of c to the m _ bit array of the array, and adding 1 to j;

b15, judging whether the value i is smaller than the difference value of len-5, if yes, executing B16; if not, B21 is executed.

B16, calculation

c is (m [ i +4] < <4) + (m [ i +3] < <3) + (m [ i +2] < <2) + (m [ i +1] < <1) + (m [ i ]), namely 5 data are taken from the i position of m, calculated according to a formula and given to c;

b17, clearing the highest 3 bits of c to 0;

b18, substituting c into the table track3cset, judging whether the data of the c position in the table is not 0, if yes, executing B19; if not, execute B20;

b19, assigning the value of the position c in the table to the j bit in the out array, recording the value of c in the m _ bit array of the array, and adding 1 to j;

b20, i is added with 1, and the jump is executed B15;

b21, assigning the value of the j-1 position in the out array to be 0;

b22, returning the value of j and exiting the first analytical function;

wherein m is an m array; len is the data length decoded from binary data; ch is the track number; start is the track valid data position; c is the result of the current decoding; i is a count value in the m array; j is the count value in the out array.

Preferably, the processor performs a verification process on the decoded data and the corresponding data in step S8, specifically,

and C1, substituting the m _ bit array, the size and the ch of the parameters into a second analytic function.

C2, definition lrc, and assigned a value of 0; definition lrc _ p, assigned a value of 0; defining a code length value bits and defining counting values i and j;

c3, judging whether ch is 0, namely judging whether the current track is 0; if yes, go to C5; if not, go to C4;

c4, startb assigned 0x0 b; endb is assigned a value of 0x1 f; bits is assigned a value of 4; namely, the start flag bit 0x0b and the end flag bit 0x1f of the data length of 4 are determined, and C6 is performed;

c5, startb assigned 0x 45; endb is assigned a value of 0x1 f; the bits is assigned a value of 6; namely, the start bit flag 0x45 and the end bit flag 0x1f of the judgment data are 6 in data length;

c6, judging whether m _ bit [0] is equal to startb, namely judging whether the data head is correct; if yes, go to C7; if not, go to C23;

c7, assigning the count value i to be 0;

c8, judging whether i is smaller than size, if yes, executing C9; if not, go to C12;

c9, calculating lrc according to a formula, wherein lrc is lrc ^ m _ bit [ i ]; computing lrc exclusive or sum of valid data;

c10, judging whether the value of the i bit in the m _ bit array is equal to endb, namely judging whether an ending mark is found; if yes, go to C13; if not, go to C11;

c11, adding 1 to the value of i; jump execution C8;

c12, judging whether the value of the i bit in the m _ bit array is equal to endb, namely judging whether an ending mark is found; if yes, execute B13; if not, executing C22;

c13, assigning j to 0;

c14, judging whether j is smaller than bits, if so, executing B15; if not, go to C17;

c15, calculating lrc _ p ^ (lrc & (1< < j)) > > j according to a formula;

c16, j value plus 1; jump execution C14;

c17, calculating lrc _ p ^ 1 according to a formula;

c18, calculating lrc & (1< < bits) -1 according to a formula; lrc ═ lrc | (lrc _ p < < bits);

c19, determine whether m _ bit [ i +1] is equal to lrc, i.e., determine lrc is correct; if yes, go to C20; if not, go to C21;

c20, return data value 0;

c21, return data value 3;

c22, return data value 2;

c23, return data value 1;

wherein, size is data length; ch is track data; startb is track start data; endb is track end data; lrc is a check byte; lrc _ p is the parity bit of the check byte; bits is a data coding length mark; i is the count value of the m _ bit array; j is the count value of the second analytical function.

The invention has the beneficial effects that: the success rate of decoding is increased, the probability of reporting error codes is reduced, the design cost is reduced, and the user experience is improved.

Drawings

FIG. 1 is a flow chart of a decoding method according to an embodiment of the present invention;

fig. 2 is a schematic structural diagram of a processor and a magnetic card chip according to an embodiment of the present invention.

Detailed Description

In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is further described in detail below with reference to the accompanying drawings. It should be understood that the detailed description and specific examples, while indicating the invention, are intended for purposes of illustration only and are not intended to limit the scope of the invention.

As shown in fig. 1 to 2, the present embodiment provides a decoding method for a card swiping terminal of a magnetic stripe card, wherein the magnetic stripe card is provided with a magnetic card chip, and the card swiping terminal is provided with a processor; the decoding method comprises the steps of, after decoding,

s1, when the card is swiped, the magnetic card chip is connected with the processor, and whether the monitoring of the processor is interrupted or not is judged; if yes, the processor closes the interrupt, starts the timeout timer and executes the step S2; if not, exiting the interruption;

s2, updating the timing count;

s3, the processor reads the level states of three external IOs, judges whether the IO has level jump or not, if so, records the IO with level jump and the time interval of the last jump of the IO into an array corresponding to the IO, each IO corresponds to one magnetic track, each magnetic track corresponds to one T array, and executes S4; if not, directly executing S4;

s4, the processor judges whether the overtime exceeds the preset time length, if yes, the step S5 is executed; if not, returning to the step S2;

s5, copying the T array content of one track into the p array by the processor;

s6, the processor decodes the time interval data in the p array into binary data, and the binary data is stored in the m array;

s7, the processor decodes the binary data according to the coding format to obtain decoded data, stores the decoded data in an m _ bit array, finds the corresponding ASCII code of the decoded data according to a table look-up mode to obtain corresponding data, and stores the corresponding data in an out array;

s8, the processor checks the decoded data and the corresponding data, if the check is passed, the step S9 is executed; if the verification fails, go to step S10;

s9, the processor transfers the corresponding data to the global data, the processor sets the successful flag of the magnetic track card swiping, and executes the step S11;

s10, the processor sets the failure flag of the magnetic track card swiping, and executes the step S11;

s11, repeating the steps S5 to S10; judging whether the T arrays corresponding to the three magnetic tracks are completely analyzed, and if so, exiting the interruption; if not, the process returns to step S5.

In this embodiment, in step S1, the processor IO may generate a jump due to the card swiping event being affected by the magnetic card chip, and the IO jump of the processor may trigger the monitoring interrupt. Referring to fig. 2, the processor includes three IOs, each IO corresponds to one track, each track corresponds to one T array, the three IOs are IO1, IO2, and IO3, and the corresponding T arrays are T1 array, T2 array, and T3 array, respectively. Any IO transition will cause processor interrupt.

In this embodiment, in step S4, the timeout exceeds the preset duration, which indicates that all three IOs are jumping within the timeout period. The preset duration can be specifically set according to actual needs so as to better meet the actual needs.

In this embodiment, in step S6, the processor decodes the time interval data in the p array into binary data, specifically,

a1, acquiring an array pointer p of the p array, and setting the length of time interval data to be decoded to len and the initial reference value to bitlen;

a2, defining the count value as I, j, and endowing both I and j with an initial value of 0; defining a first skip and a second skip of the zone bits, and endowing the first skip and the second skip with an initial value of 0;

a3, judging whether i is less than len-1, if yes, executing step S44; if not, executing the step A4;

a4, judging whether the first skip is equal to 0, if yes, executing S47, and if no, executing A5;

a5, assigning the first skip as 0;

adding 1 to the value of A6 and i, and returning to S43;

a7, judging p [ i ] < bitlen 0.7, namely judging whether the ith bit of p is less than 0.7 times of a reference value bitlen; if yes, A8 is executed; if not, executing A11;

a8, judging p [ i +1] < bitlen 0.7, namely judging whether the i +1 th bit of p is less than 0.7 times of a reference value bitlen; if yes, A9 is executed; if not, executing A11;

a9, judging whether the sum of the data of the ith bit and the i +1 bit of p is less than 1.4 times of a reference value or not, namely judging whether the sum of the data of the ith bit and the i +1 bit of p is less than 1.4 times of the reference value; if yes, A10 is executed; if not, executing A11;

a10, updating bitlen, and calculating bitlen ═ bitlen × 0.8+ (p [ i ] + p [ i +1]) × 0.2; taking the weight of 80% of the original reference value plus the weight of 20% of the sum of the ith bit and the (i + 1) th bit of p as a new reference value; executing m [ j + + ] -1, and the second Skip-1, namely the decoding result is 1, recording the data at the j position of the m array, and simultaneously adding 1 to the value of j, setting the second Skip as 1; and jumps to A6;

a11, judging p [ i ] < bitlen 0.8, namely judging whether the ith data of p is less than 0.8 times of a reference value bitlen; if yes, go to step S412; if not, executing A13;

a12, executing p [ i +1] ═ p [ i +1] - ((Bitlen-p [ i ]) 0.8), namely, updating the i +1 th bit data of p into the i +1 th bit data of p minus the 80% weight of the difference value between the reference value and the i-th bit data of p;

a13, executing BItlen 0.8+ p [ i ] 0.2m [ j + + ] -0, namely, the decoding result is 0, recording the result to j bits of the m arrays, and increasing the count value j by 1; jumping to execute A6;

wherein, p represents an array pointer of a p array; m represents an m array; len is the data length of the time interval to be decoded; bitlen is an initial reference value; i is a count value of a p array; j is the count value of the m array; the first skip is a zone bit of a p array, and the second skip is a zone bit of an m array; skip indicates whether the current flag bit is skipped.

In this embodiment, the process of converting the binary data into ASCII code in step S7 is, specifically,

b1, substituting the parameters m, len, ch and out into a first analytical function;

b2, taking i, j as a count value, and respectively recording the position of binary data to be decoded and the position of storing an ASCII code; assigning initial values of i, j, start and c as 0;

b3, judging whether i is smaller than len, if so, adding 1 to i; if not, adding 1 to i and then executing B6;

b4, judging whether the ith bit in m is not 0, if yes, executing B5; if not, execute B3;

b5, assigning the data i to start, and indicating that the current position is assigned to start;

b6, judging whether ch is 0, namely judging whether the current magnetic track is a1 magnetic track; if yes, execute B7; if not, execute B9;

b7, updating the count value i to be the record value of start;

b8, judging whether i is smaller than the difference value of len-5, if yes, executing B10; if not, execute B9;

b9, updating the record value with the count value i as the start, and executing B15;

b10, calculation

c ═ c (m [ i +6] < <6) + (m [ i +5] < <5) + (m [ i +4] < <4) + (m [ i +3] < <3) + (m [ i +2] < <2) + (m [ i +1] < <1) + (m [ i ]); namely, 7 data are taken from the i position of m, calculated according to a formula and given to c;

b11, clearing the highest bit of c to 0;

b12, substituting the character c into the table track1cset, and if the position indicated by c is not 0, executing B14; if not, execute B13;

b13, adding 1 to the value of i, and jumping to execute A8;

b14, assigning the data of the position c in the table to the j bit of the out array, recording the value of c to the m _ bit array of the array, and adding 1 to j;

b15, judging whether the value i is smaller than the difference value of len-5, if yes, executing B16; if not, B21 is executed.

B16, calculation

c is (m [ i +4] < <4) + (m [ i +3] < <3) + (m [ i +2] < <2) + (m [ i +1] < <1) + (m [ i ]), namely 5 data are taken from the i position of m, calculated according to a formula and given to c;

b17, clearing the highest 3 bits of c to 0;

b18, substituting c into the table track3cset, judging whether the data of the c position in the table is not 0, if yes, executing B19; if not, execute B20;

b19, assigning the value of the position c in the table to the j bit in the out array, recording the value of c in the m _ bit array of the array, and adding 1 to j;

b20, i is added with 1, and the jump is executed B15;

b21, assigning the value of the j-1 position in the out array to be 0;

b22, returning the value of j and exiting the first analytical function;

wherein m is an m array; len is the data length decoded from binary data; ch is the track number; start is the track valid data position; c is the result of the current decoding; i is a count value in the m array; j is the count value in the out array.

In this embodiment, the processor in step S8 performs a verification process on the decoded data and the corresponding data, specifically,

and C1, substituting the m _ bit array, the size and the ch of the parameters into a second analytic function.

C2, definition lrc, and assigned a value of 0; definition lrc _ p, assigned a value of 0; defining a code length value bits and defining counting values i and j;

c3, judging whether ch is 0, namely judging whether the current track is 0; if yes, go to C5; if not, go to C4;

c4, startb assigned 0x0 b; endb is assigned a value of 0x1 f; bits is assigned a value of 4; namely, the start flag bit 0x0b and the end flag bit 0x1f of the data length of 4 are determined, and C6 is performed;

c5, startb assigned 0x 45; endb is assigned a value of 0x1 f; the bits is assigned a value of 6; namely, the start bit flag 0x45 and the end bit flag 0x1f of the judgment data are 6 in data length;

c6, judging whether m _ bit [0] is equal to startb, namely judging whether the data head is correct; if yes, go to C7; if not, go to C23;

c7, assigning the count value i to be 0;

c8, judging whether i is smaller than size, if yes, executing C9; if not, go to C12;

c9, calculating lrc according to a formula, wherein lrc is lrc ^ m _ bit [ i ]; computing lrc exclusive or sum of valid data;

c10, judging whether the value of the i bit in the m _ bit array is equal to endb, namely judging whether an ending mark is found; if yes, go to C13; if not, go to C11;

c11, adding 1 to the value of i; jump execution C8;

c12, judging whether the value of the i bit in the m _ bit array is equal to endb, namely judging whether an ending mark is found; if yes, execute B13; if not, executing C22;

c13, assigning j to 0;

c14, judging whether j is smaller than bits, if so, executing B15; if not, go to C17;

c15, calculating lrc _ p ^ (lrc & (1< < j)) > > j according to a formula;

c16, j value plus 1; jump execution C14;

c17, calculating lrc _ p ^ 1 according to a formula;

c18, calculating lrc & (1< < bits) -1 according to a formula; lrc ═ lrc | (lrc _ p < < bits);

c19, determine whether m _ bit [ i +1] is equal to lrc, i.e., determine lrc is correct; if yes, go to C20; if not, go to C21;

c20, return data value 0;

c21, return data value 3;

c22, return data value 2;

c23, return data value 1;

wherein, size is data length; ch is track data; startb is track start data; endb is track end data; lrc is a check byte; lrc _ p is the parity bit of the check byte; bits is a data coding length mark; i is the count value of the m _ bit array; j is the count value of the second analytical function.

By adopting the technical scheme disclosed by the invention, the following beneficial effects are obtained:

the invention provides a decoding method for a magnetic stripe card swiping terminal, which increases the success rate of decoding, reduces the probability of reporting error codes, reduces the design cost and improves the use experience of users.

The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and improvements can be made without departing from the principle of the present invention, and such modifications and improvements should also be considered within the scope of the present invention.

15页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:自动售货方法、自动售货机及服务器

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!