09_memcpy的实现

memcpy的实现

简单版本

/**
 * @description: 
 * @param {void*} src 原串指针
 * @param {void*} dest 目的串指针
 * @param {int} len 长度
 * @return {*}
 */
void* memcpy(void* src, void* dest, int len)
{
    // 不在函数内申请空间,所以需要进行判断
    if(dest == NULL || src == NULL )
    {
        return dest;
    }

    
    char* d = (char*)dest;
    char* s = (char*)src;
    
    // 考虑 src + len > dest,即dest地址在src + len的里面,那么如果按顺序拷贝,src后部分数据将会丢失,所以需要变更下拷贝方式
    if(dest > src && src + len > dest)
    {
        while(len-- > 0)
        {
            *(d+len) = *(s + len);
            
        }
    }

    while(len-->0)
    {
        *(d++) = *(s++);
    }
    return dest;
}

/* * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2022-09-21 baijinhui the first version */ #include "app_actuator.h" #if (ACTUATOR_TYPE == 25) #include <rtthread.h> #include <rtdevice.h> #include "board.h" #include <stdio.h> #include "bsp_can.h" #include "app_location.h" #include "app_chassis.h" #include "lib_inc.h" #include "app_chassis_fork.h" #include "app_qrps.h" #define DBG_TAG "actuator" #define DBG_LVL DBG_LOG #include <ulog.h> /*-------------------------外部引用-------------------------*/ /*-------------------------公共变量-------------------------*/ /*-------------------------局部变量-------------------------*/ #define Pi 3.14159265359f static struct msg_actuator_status msg1; static struct msg_actuator_ctrl msg2; static struct msg_actuator_para msg3; static struct msg_qrps_status qrpsMsg1; static struct msg_location_status locationMsg1; static struct msg_chassis_ctrl chassisMsg2; static struct msg_chassis_para chassisMsg3; static struct msg_chassis_fork_status forkMsg1; static struct msg_chassis_fork_ctrl forkMsg2; static struct rt_messagequeue mq_actuatorDriver; static char msg_pool_actuatorDriver[128]; struct rx_actuatorDriver { unsigned short int id; unsigned char cmd; unsigned short int index; unsigned char sub_index; unsigned char dat[4]; }; static unsigned int actStatus[3] = { 0 }; // 动作执行状态 static unsigned int timeCount[3] = { 0 }; //动作执行计时 static unsigned int hightNeedCal = 1; //高度需要校准 0不需要 1需要 static unsigned int slideNeedCal = 1; //横移需要校准 0不需要 1需要 static unsigned int locBiasError = 0; //上装定位偏差错误 /*-------------------------函数实现-------------------------*/ void app_actuator_status(struct msg_actuator_status *status) { RT_ASSERT(status != RT_NULL); rt_memcpy(status, &msg1, sizeof(msg1)); } void app_actuator_ctrl(struct msg_actuator_ctrl *ctrl) { RT_ASSERT(ctrl != RT_NULL); rt_memcp
03-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值