获取温度

背景:SDK将 温度传到底层,底层得到温度后用于温度补偿的算法运算

 

1、定义一个结构体,用于存储温度信息

typedef struct __attribute__((__packed__)) OBTemp_Compesation
{
    char data_laser[4];
    char data_ir[4];
}OBTemp_Compesation;

定义一个结构体,用于存储raw_cmd内容

typedef struct __attribute__((__packed__)) reg_raw_cmd
{
    uint8_t start;
    uint8_t error;
    uint8_t len;
    uint16_t cmd;
    uint8_t data[REG_RAW_CMD_DATA_LEN];
} reg_raw_cmd_t;

 

2、实习获取温度的功能

int raw_cmd_set_temperature()
{
    uint16_t len, off, size;
    float temp_ir, temp_laser;
    len = raw_cmd->len + 1;         //raw_data
    off = raw_cmd->data[0] | raw_cmd->data[1] << 8;//store the offset
    size =  sizeof(OBTemp_Compesation);

    memcpy((char *)&temp_string + off, raw_cmd->data[2], len - 2);

    if(len < 3 || len > 14)
    {
        return -1;
    }

    if((off + len - 2) > size)
    {
        return -2;
    }

    if(off == 0)
    {
        memcpy((char *)&temp_string, 0, size);
    }

    if((off + len - 2) == size)
    {
        memcpy((char *)&temp_ir, &temp_string.data_ir, 4);
        memcpy((char *)&temp_laser, &temp_string.data_laser, 4);
        Temperature_deflection_compensation(temp_ir, temp_laser);
    }

    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值