Vaisala CRC16

简介: CRC-16 COMPUTATION  The computation of the CRC is performed on the data response before parity is added.

CRC-16 COMPUTATION
  The computation of the CRC is performed on the data response before parity is added. All operations are assumed to be on 16 bit unsigned integers. The least significant bit is on the right. Numbers preceded by 0x are in hexadecimal. All shifts shift in a zero. The algorithm is:
Initialize the CRC to zero. For each character beginning with the address, up to but not including the carriage return (<cr>), do as follows:
{
  Set the CRC equal to the exclusive OR of the character and itself
  for count =1 to 8
  {
    if the least significant bit of the CRC is one
    {
      right shift the CRC one bit
      set CRC equal to the exclusive OR of 0xA001 and itself
    }else{
      right shift the CRC one bit
    }
  }
}


Encoding the CRC as ASCII Characters
  The 16 bit CRC is encoded to three ASCII characters by using the following algorithm:
  1st character = 0x40 OR (CRC shifted right 12 bits)
  2nd character = 0x40 OR ((CRC shifted right 6 bits) AND 0x3F)
  3rd character = 0x40 OR (CRC AND 0x3F)

  The three ASCII characters are placed between the data and <cr><lf>.
  Parity is applied to all three characters, if selected for the character frame.
  The CRC computation code is added to the end of the response, if the first letter of the command is sent by using lower case.


void CRC16(BYTE *Array, BYTE *Rcvbuf,unsigned int Len)
{
  unsigned int IX,IY,CRC;
  CRC=0;
  if (Len<=0)
  {
    CRC = 0;
  }else{
    Len--;
    for (IX=0;IX<=Len;IX++)
    {
      CRC=CRC^(unsigned int)(Array[IX]);
      for(IY=0;IY<=7;IY++)
      {
        if ((CRC&1)!=0)
        {
          CRC=(CRC>>1)^0xA001;
        }else{
          CRC=CRC>>1;
        }
      }
    }
  }
   Rcvbuf[0] = 0x40 | (CRC >> 12);//高位置
   Rcvbuf[1] = 0x40 | ((CRC >> 6) & 0x3F);//中位置
   Rcvbuf[2] = 0x40 | (CRC & 0x3F);//低位置
}

目录
相关文章
|
Dubbo 应用服务中间件 数据库
浅谈订单重构之路
浅谈订单重构之路
331 0
|
Linux Android开发
LINUX编译Android FFmpeg:fatal error: errno.h: No such file or directory
LINUX编译Android FFmpeg:fatal error: errno.h: No such file or directory
525 0
|
1天前
|
人工智能 运维 安全
|
4天前
|
SpringCloudAlibaba 负载均衡 Dubbo
微服务架构下Feign和Dubbo的性能大比拼,到底鹿死谁手?
本文对比分析了SpringCloudAlibaba框架下Feign与Dubbo的服务调用性能及差异。Feign基于HTTP协议,使用简单,适合轻量级微服务架构;Dubbo采用RPC通信,性能更优,支持丰富的服务治理功能。通过实际测试,Dubbo在调用性能、负载均衡和服务发现方面表现更出色。两者各有适用场景,可根据项目需求灵活选择。
377 124
微服务架构下Feign和Dubbo的性能大比拼,到底鹿死谁手?
|
6天前
|
人工智能 JavaScript 测试技术
Qwen3-Coder入门教程|10分钟搞定安装配置
Qwen3-Coder 挑战赛简介:无论你是编程小白还是办公达人,都能通过本教程快速上手 Qwen-Code CLI,利用 AI 轻松实现代码编写、文档处理等任务。内容涵盖 API 配置、CLI 安装及多种实用案例,助你提升效率,体验智能编码的乐趣。
627 107
|
3天前
|
Java 数据库 数据安全/隐私保护
Spring 微服务和多租户:处理多个客户端
本文介绍了如何在 Spring Boot 微服务架构中实现多租户。多租户允许单个应用实例为多个客户提供独立服务,尤其适用于 SaaS 应用。文章探讨了多租户的类型、优势与挑战,并详细说明了如何通过 Spring Boot 的灵活配置实现租户隔离、动态租户管理及数据源路由,同时确保数据安全与系统可扩展性。结合微服务的优势,开发者可以构建高效、可维护的多租户系统。
200 127
|
3天前
|
Web App开发 前端开发 API
在折叠屏应用中,如何处理不同屏幕尺寸和设备类型的样式兼容性?
在折叠屏应用中,如何处理不同屏幕尺寸和设备类型的样式兼容性?
226 124