Homebus解码和加码

最近发现Homebus,将电源和通信数据经过MAX22088处理后叠加在一起了,所有设备都通过电源进行通信,省去了额外的通讯线。

软件要处理的就是在每个byte里插入aa,如下

int16    HbusSendData(uint8 *destin,   uint8 * src,   int16  src_len )   

    uint8 i = 0;

    for (i = 0; i < src_len; i++) 

    {

        //发送低位

        destin[(i*2) + 0] = (( src[i] & 0x08) << 3 ) +

                           (( src[i] & 0x04) << 2 ) +

                           (( src[i] & 0x02) << 1 ) +

                           (( src[i] & 0x01)) + 0xaa;

        //发送高位

        destin[(i*2) + 1] = (( src[i] & 0x80) >> 1 ) +

                           (( src[i] & 0x40) >> 2 ) +

                           (( src[i] & 0x20) >> 3 ) +

                           (( src[i] & 0x10) >> 4 ) + 0xaa;                    

    }

    return src_len*2;

int16    HbusRecData(uint8 *destin,   uint8 * src,   int  src_len )   

    uint8 i = 0;

    src_len = src_len/2;

    for (i = 0; i < src_len; i++) 

    {       

        //接收低位低位

        destin[i] = 0xf&(((( src[(i*2) + 0] & 0x40) >> 3 ) +\

                           (( src[(i*2) + 0] & 0x10) >> 2 ) +\

                           (( src[(i*2) + 0] & 0x04) >> 1 ) +\

                           (( src[(i*2) + 0] & 0x1))));

        //接收高位低位    

        destin[i] |= 0xf0&((( src[(i*2) + 1] & 0x40) << 1 ) +\

                           (( src[(i*2) + 1] & 0x10) << 2 ) +\

                           (( src[(i*2) + 1] & 0x04) << 3 ) +\

                           (( src[(i*2) + 1] & 0x1) << 4 )); 

    }

    return src_len;

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值