Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to calculate checksum?

Status
Not open for further replies.

I14R10

Full Member level 3
Full Member level 3
Joined
May 31, 2015
Messages
185
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,750
Weather station is sending packets of 48 bits. Last 4 are checksum of all previous. For example, this is a real packet.

1001 0100 0100 1111 0101 1000 0100 0101 0100 1011 1010 and checksum is 1111

How is this checksum calculated?
 

Could be just about anything. Maybe just a running sum of all data. Maybe something totally different.

I would look at some other packets and see if my running sum theory is correct.
 

OK, so there is not only one way to calculate checksum, like: count of all "1"s in a signal?
 

Have you checked if it's just a simple checksum using a calculator before posting question?
Code:
#include <stdio.h>

#define N	12

const char *n[N] = {
	"1001",
	"0100",
	"0100",
	"1111",
	"0101",
	"1000",
	"0100",
	"0101",
	"0100",
	"1011",
	"1010",
	"1111"
};

unsigned tra(const char *s){//binary string to unsigned
	unsigned x = 0;
	while(*s){
		x <<= 1;
		if(*s == '1')
			x |= 1;
		s++;
	}
	return x;
}

void get(unsigned *v,const char **n,int k){
	while(k-->0)
		v[k] = tra(n[k]);
}

unsigned add(unsigned *v,int n){
	unsigned sum = 0;
	while(n-->0)
		sum += v[n];
	return sum;
}

int main(void){
	unsigned v[N];
	get(v,n,N);
	printf("sum= %x\n",add(v,N-1));
	return 0;
}
Code:
result:
sum= 4f


It could be the last 4 bits of the checksum of the first 11 elements.
It seems ok for this packet.
Of course you need more packets to confirm it.
 

OK, so there is not only one way to calculate checksum, like: count of all "1"s in a signal?
There are many, many,many ways to calculate a checksum. The documentation for your device should tell you what method it uses.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top