개발자 모드/C언어

C언어 해양 [NMEA] AIS Checksum 계산

인생은직구 2021. 4. 4. 09:55
728x90
int main()

{
	//char GPRMCBuf[] ={
	//	// checksum calculation starts with the next byte (0x47)
	//	0x41, 0x49, 0x56, 0x44, 0x4D, 0x2C,                    // AIVDM,
	//	0x31, 0x2C, 0x31, 0x2C, 0x2C, 0x42, 0x2C, 0x2C, 0x30,  // 1,1,,B,,0
	//	
	//	// checksum calculation ends here
	//};


	char GPRMCBuf[] ={
		// checksum calculation starts with the next byte (0x47)
		0x41, 0x49, 0x56, 0x44, 0x4D, 0x2C,                    // AIVDM,
		0x31, 0x2C, 0x31, 0x2C, 0x2C, 0x41, 0x2C, 0x2C, 0x30,  // 1,1,,A,,0

		// checksum calculation ends here
	};


	unsigned short chk=0;
	int len=sizeof(GPRMCBuf);
	for(int i=0; i<len; i++)
	{
		chk ^=GPRMCBuf[i];
	}


	return chk;


}


//!AIVDM,1,1,,B,,0*25    
//!AIVDM,1,1,,A,,0*26

 

결과의 코드는

 

The checksum, '2' and '5'

The checksum, '2' and '6'

 

 

 

728x90