I am trying to decipher the protocol used for RS485 communication between several HVAC controllers. I was able to identify single messages as you can see in the list below.
00020003400012A9
00030103400012A7
00010303400012A7
2001030A400012010104FFFFFFFF7E
00010303400016A3
200103094000160C0C010400441C
000103074100000024A003ED
2001030A4100000024A0030895BA73
0001032A90020030000200310700013000020131070002300002023107060330000203310700043000FF053000FF1F
2001030290004A
00020003400012A9
00030103400012A7
00010302D10227
20010312D140200100002101000022010000230100002F
00020003400012A9
00030103400012A7
00010302D20226
20010302D240C8
00020003400012A9
00030103400012A7
00010302D10227
20010312D140200100002101000022010000230100002F
00020003400012A9
00030103400012A7
00010302D20226
20010302D240C8
00020003400012A9
00030103400012A7
00010302D20226
20010302D240C8
00020003400012A9
00030103400012A7
00010302D20226
20010302D240C8
00020003400012A9
00030103400012A7
00010302D20226
20010302D240C8
Each line contains one complete message in hex format. I think the last byte (last two hex characters) is the checksum of the previous data, but that is only a guess of me.
Which algorithm is used to calculate this checksum?
I now discovered the algorithm. Its only summing up data and building some kind of 2s complement. Here is an example:
data: 0x20010312D14020010000210100002201000023010000
binary sum: 1 1101 0001 (0x1D1)
last byte: 1101 1110 (0xD1)
invert: 0010 1110 (0x2E)
add 1: 0010 1111 (0x2F)
use only last byte of calculated CS
CS: 0x2F
Related
I have a variables of type PIC S9(09)V99 COMP-3 and PIC S9(07) COMP-3 in a file. I need to parse it and get the value in node js. Could you please help me understand it with simple examples. Also help me understand how data is stored for the same
Cobol natural way of working with number is Binary coded decimal a.k.a BCD.
"Classic" PIC (USAGE IS DISPLAY)
THEORY :
When you write PIC S9(4)V9(3) with a USAGE value of DISPLAY, that is to say without writing COMP-3, it is BCD.
In this way of writing number, a digit takes one octet (i.e. 8 bits) to be stored.
Each octet can be divided in two quartet, also know as nibble. A quartet is a group of 4 bits. So writing a digit takes two quartet, that is to say 2*4 bits which adds up to 8 bits = 1 octet.
When writing a digit the first quartet will hold a value wich represent the sign carried by the digit. The only digit that carry the sign is the last. The positive value is C (like credit) in hexadecimal and 1100 in binary. The negative is D (like Debit) in hexadecimal and 1101 in binary. The neutral letter is F in hex and 1111 in binary.
The second quartet will hold the binary value for your digit. For instance if my digit is 7, the quartet will be 0111.
EXAMPLE :
If I take the example I have written above PIC S9(4)V9(3), it has 4 + 3 = 7 digits. It needs 7 octets to be stored. Let's say that I want to store the number +0036.421
then the 7 octets would be 0033421
First digit 0 : 1111 0000 ; which in Hex is : F0
Second digit 0 : 1111 0000 ; which in Hex is : F0
Third digit 3 : 1111 0011 ; which in Hew is : F3
Fourth digit 6 : 1111 0110 ; which in Hex is : F6
Fifth digit 4 : 1111 0100 ; which in Hex is : F4
Sixth digit 2 : 1111 0010 ; which in Hex is : F2
Seventh digit 1 : 1100 0001 ; which in Hex is : C1. This digit carrie the sign for the whole number. The first quartet is C, because the number is positive.
COMP-3 PIC (Packed decimal)
THEORY :
As you can see you takes up a lot of space (7 octets !!!) for writing a rather small number. for comparisons, in binary with seven octets you can store 2^56 values !
So in order to keep some memory there is another format, the packed decimal, which you can use by adding COMP-3 to your declaration.
In this format instead of storing a digit in a whole octet, you just take a quartet. The trick is not to store the signs for the digits that aren't the last digit. Because as you can see above, most of the quartet just have a F value for the first quartet which convey little to no information.
The last quartet of the last octet contains the sign of the whole number. Therefore if we have n digits, we need n+1 quartets to store the number in packed decimal. So the space occupied by a number with n digits in packed decimal would be foor((n+1)/2). That is to say the lowest number of octet that contains n+1 quartet.
EXAMPLE :
My pic is 7 digits long, so I need 7+1=8 quartet = 4 octet.
First octet : 0000 0000 ; which is 00 in Hex (The first digit is 0, the second digit is 0)
Second Octet : 0011 0110 ; wich is 36 in Hex ( the third digit is 3, the fourth is 6)
Third Octet : 0100 0010 ; which is 42 in Hex ( the fifth digit is 4, the sixth is 2)
Fourth octet : 0001 1100 ; which is 1C in Hex ( the seventh digit is 1 and the sign of the whole number is +)
I am trying to connect a pedometer watch to my phone with bluetooth and want to read the steps from it to an app I have made. The connection is made successfully and I am able to read the data from the watch but I am not so clear how to interpret it.
Below is the document,
Eigenvalue content:
(1) all the eigenvalue content inside the endian order are small endian order.
(2) current_pedometer_measurement
The value of the current_pedometer_measurement consists of four parts
Value type description
Flag Uint8 0x01: Number of Steps (Required)
0x02: Distance (optional)
0x04: Calories (optional)
Such as 0x05 that contains the number of steps and calories
StepCount Uint24 The number of steps
StepDistancer Uint24 How far, in meters
StepCalorie Uint24 calories
Description:
1. Distance and calories are optional, may or may not appear
If only the number of steps, then the value is: 01 (steps) 10 27 00 (1 million steps)
If there are steps and distances, then the value is: 03 (number of steps, distance) 10 27 00 (1 million steps) 70 17 00 (6 km)
Other cases and so on.
2. Time value to mobile phone time as the standard, that is, the moment the phone receives the data that is the time of this data.
(3) target
The target value is
Value type description
Flag Uint8 0x01: Number of Steps (Required)
StepCount Uint24 The number of steps
Description:
1. If the target is 10,000 steps, then the value is: 01 (steps) 10 27 00 (1 million steps)
2. If the device writes to the target value, the device is updated. If the device updates the target value, notify the phone.
The reading I am getting from the pedometer watch is:
[7, 64, 1, 0, 144, 0, 0, 24, 0, 0]
Can anyone help me to interpret it?
The data appears to follow your description exactly. The first byte is the flag field and in this case it indicates that all 3 measurement types are being reported. Or`ing bits 1 and 2 and 3 equals 7.
The next 9 bytes are the 3 24-bit data values, where 64,1,0 are steps, 144,0,0 are distance, and 24,0,0 are calories. How you convert the bytes is a bit confusing, but if you use little-endian format and assume you printed them in decimal do these values make sense?
Steps: 00 01 64 = 0x000140 = 320
Distance: 00 00 144 = 0x000090 = 144
Calories: 00 00 24 = 0x000018 = 24
From your examples above the values are probably in hex:
10 27 00 = 0x002710 = 10000
70 17 00 = 0x001770 = 6000
Hope that helps!
grace
I have a table which contains 13.931 rows and 2 columns, the first column is SKU's, second is Options (Size, Colour, etc..);
SKU Option
0001 Size:S
0001 Size:M
0001 Size:L
0001 Size:XL
0001 Colour:Red
0001 Colour:Blue
0002 Size:S
0002 Size:M
0002 Size:L
0002 Colour:Navy
0002 Leg:G
and goes on like this. What I need to do is generate every combination of these options (there are 7 option types in total; some SKU's has 2 types some has 4, some non) within SKU's, so it'll be like this;
SKU Option
0001 Size:S;Colour:Red
0001 Size:M;Colour:Red
0001 Size:L;Colour:Red
0001 Size:XL;Colour:Red
0001 Size:S;Colour:Blue
0001 Size:M;Colour:Blue
0001 Size:L;Colour:Blue
0001 Size:XL;Colour:Blue
0002 Size:S;Colour:Navy;Leg:G
0002 Size:M;Colour:Navy;Leg:G
0002 Size:L;Colour:Navy;Leg:G
I can seperate Option column into 2 for option types and option values if it makes it easier.
My question is: Is it doable using macros? Because it is going to be a huge pain if I manually do these.
I´m sitting here and I´m not able to solve a problem related to the hamming distance.
I have a block like this:
100
000
111
When I use the vertical redundancy Check now I get:
100-1
000-0
111-1
||| |
011-0
because I add an 1 to each row and column, if I have an odd number of 1´s or I add an 0 to each row and column, if i have an odd number of 0´s.
Now I should have 6 words right?
w1: 1001
w2: 0000
w3: 1110
w4: 1010
w5: 0011
w6: 0011
Are the created (through VRC) bits words too? So are 1000 and 0110 words too?
If I compare the words and check the Hamming Distance, I get an minimal Hamming Distance of 2 (0 should not count, because if the Hamming Distance is 0, the words are the same). E.g. compare w1 and w2.
In our lecture, the professor said, that the Hamming Distance for this example is 3. How can it be 3?!
Were is my mistake? :-(
I hope someone can help me.
Have a great Sunday!
I understand that each gray code differs from its preceding code by one bit, but i don't exactly understand why its called reflected. I came across this website https://www.pc-control.co.uk/gray_code.htm, where it says " The gray code is sometimes referred to as reflected binary, because the first eight values compare with those of the last 8 values, but in reverse order", but the first 8 gray codes are not comparable to the last 8 gray codes in reverse order as can be seen from the gray code table on their website. To add to my confusion the gray code table differs from the gray code table on my textbook, for eg gray code for 9 = 1000 on my textbook while on the website its 9 = 1101.
Consider the sequence on the linked page:
0000
0001
0011
0010
0110
0111
0101
0100
1100
1101
1111
1110
1010
1011
1001
1000
Remove the most significant bit and you obtain a nice reflected sequence:
x000
x001
x011
x010
x110
x111
x101
x100
-------- mirror
x100
x101
x111
x110
x010
x011
x001
x000
Please note that the same kind of reflection can be found for Gray sequences of any width.