您尚未登录。

楼主 #1 2018-12-06 11:16:12

zhuacai
会员
注册时间: 2017-12-16
已发帖子: 234
积分: 233.5

关于C++编译代码出错,不知道是怎么回事,请大神们帮帮忙.......

char buffern[500];
TCPSocket *tcpsocketn;
rtos::Thread tcp_recv_thread,i2s_rx_thread;

void rx_thread(void)
{   
    while (true) {
       

      printf("录音中..\r\n"); 
    }
}
void tcp_recv(TCPSocket *tcpsockets,char *buffer, int Len)
{  uint16_t size=1;
   int ret;

      while(true){
     
           do {
            size = tcpsockets->recv(buffer,Len);
                if (buffer <= 0) {
                    printf("ERROR: TCP recv erropr, len is %d !\r\n", size);
                    break;
                }
                
                printf("TCP send len is %s !\r\n",buffer);
                
             }while (size > 0);
       }
   
}
void tcp_connect(TCPSocket *tcpsockets,char *addressn, uint16_t port,NetworkInterface *net_iface)
{    int ret,size;
    //tcpsocketn =new TCPSocket(net_iface);
    SocketAddress address(addressn,port);
   
    if (!address) {
         printf("地址错误\r\n");
         return;
    }
    ret = (int)tcpsockets->connect(address);
    if(ret != 0){
         printf("连接错误 = %d\r\n", ret);
         return;
    }
    printf("连接成功!%d\r\n", ret);
}

void tcp_send(TCPSocket *tcpsockets,char *buffern,uint16_t Len)
{   
    int size=0;
        size = tcpsockets->send("kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk",strlen("kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"));// - 1
    if (size <= 0) {
            printf("ERROR: TCP send error, len is %d !\r\n", size);
            //break;
        }else{
           printf("TCP send len is %d !\r\n", size);
       
        }             
}
int main()
{
   

    tcpsocketn =new TCPSocket(&wifi);
    tcp_connect(tcpsocketn,"192.168.1.104",8090,&wifi);
    tcp_send(tcpsocketn,"hhhhhhhhhh",500);
    i2s_rx_thread.start(rx_thread);
    tcp_recv_thread.start(tcp_recv,tcpsocketn,buffern,500);
   
   

    while (true) {
    aplay_wav("/sdc/mydir/14_00.wav");

    }
   
 
   
    rtos::Thread::wait(osWaitForever);

}



以上
tcp_recv_thread.start(tcp_recv,tcpsocketn,buffern,500);这行代码出错


"TESTS/TARGET_RDA/tcp/main.cpp", line 207: Error:  #304: no instance of overload
ed function "rtos::Thread::start"  matches the argument list
            argument types are: (void (TCPSocket *, char *, int), TCPSocket *, c
har [500], int)
            object type is: rtos::Thread
"TESTS/TARGET_RDA/tcp/main.cpp", line 221: Warning:  #111-D: statement is unreac
hable
TESTS/TARGET_RDA/tcp/main.cpp: 5 warnings, 1 error

如果这样就i2s_rx_thread.start(rx_thread);就没出错,大神们这个是什么问题,

最近编辑记录 zhuacai (2018-12-06 11:19:37)

离线

#2 2018-12-06 11:52:28

lilo
会员
注册时间: 2017-10-15
已发帖子: 215
积分: 215

Re: 关于C++编译代码出错,不知道是怎么回事,请大神们帮帮忙.......

i2s_rx_thread.start(rx_thread);
    tcp_recv_thread.start(tcp_recv,tcpsocketn,buffern,500);


这两个函数定义分别是什么?

离线

楼主 #3 2018-12-06 17:04:53

zhuacai
会员
注册时间: 2017-12-16
已发帖子: 234
积分: 233.5

Re: 关于C++编译代码出错,不知道是怎么回事,请大神们帮帮忙.......

lilo 说:

i2s_rx_thread.start(rx_thread);
    tcp_recv_thread.start(tcp_recv,tcpsocketn,buffern,500);


这两个函数定义分别是什么?

上面两个代码都是启动一个线程,rx_thread是自己写没带参数的函数
,tcp_recv是自己写的带三个参数的函数

最近编辑记录 zhuacai (2018-12-06 17:05:43)

离线

#4 2018-12-06 18:37:19

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,348
积分: 9202

Re: 关于C++编译代码出错,不知道是怎么回事,请大神们帮帮忙.......

把 start 函数的定义贴出来,肯定是你传参数的类型不匹配。





离线

楼主 #5 2018-12-07 09:30:36

zhuacai
会员
注册时间: 2017-12-16
已发帖子: 234
积分: 233.5

Re: 关于C++编译代码出错,不知道是怎么回事,请大神们帮帮忙.......

晕哥 说:

把 start 函数的定义贴出来,肯定是你传参数的类型不匹配。

晕哥,start 函数

osStatus Thread::start(Callback<void()> task) {
    _mutex.lock();

    if (_tid != 0) {
        _mutex.unlock();
        return osErrorParameter;
    }

.start不能传有参数的函数么

以下是Thread类代码

#include "Thread.h"

#include "mbed.h"
#include "rtos_idle.h"


#undef NULL
#include "rt_TypeDef.h"

extern "C" P_TCB rt_tid2ptcb(osThreadId thread_id);

namespace rtos {

void Thread::constructor(osPriority priority,
        uint32_t stack_size, unsigned char *stack_pointer) {
    _tid = 0;
    _dynamic_stack = (stack_pointer == NULL);

#if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
    _thread_def.tpriority = priority;
    _thread_def.stacksize = stack_size;
    _thread_def.stack_pointer = (uint32_t*)stack_pointer;
#endif
}

void Thread::constructor(Callback<void()> task,
        osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) {
    constructor(priority, stack_size, stack_pointer);

    switch (start(task)) {
        case osErrorResource:
            error("OS ran out of threads!");
            break;
        case osErrorParameter:
            error("Thread already running!");
            break;
        case osErrorNoMemory:
            error("Error allocating the stack memory");
        default:
            break;
    }
}

osStatus Thread::start(Callback<void()> task) {
    _mutex.lock();

    if (_tid != 0) {
        _mutex.unlock();
        return osErrorParameter;
    }

#if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
    _thread_def.pthread = Thread::_thunk;
    if (_thread_def.stack_pointer == NULL) {
        _thread_def.stack_pointer = new uint32_t[_thread_def.stacksize/sizeof(uint32_t)];
        if (_thread_def.stack_pointer == NULL) {
            _mutex.unlock();
            return osErrorNoMemory;
        }
    }


    for (uint32_t i = 0; i < (_thread_def.stacksize / sizeof(uint32_t)); i++) {
        _thread_def.stack_pointer = 0xE25A2EA5;
    }
#endif
    _task = task;
    _tid = osThreadCreate(&_thread_def, this);
    if (_tid == NULL) {
        if (_dynamic_stack) delete[] (_thread_def.stack_pointer);
        _mutex.unlock();
        return osErrorResource;
    }

    _mutex.unlock();
    return osOK;
}

osStatus Thread::terminate() {
    osStatus ret;
    _mutex.lock();

    osThreadId local_id = _tid;
    _join_sem.release();
    _tid = (osThreadId)NULL;

    ret = osThreadTerminate(local_id);

    _mutex.unlock();
    return ret;
}

osStatus Thread::join() {
    int32_t ret = _join_sem.wait();
    if (ret < 0) {
        return osErrorOS;
    }

    _mutex.lock();
    MBED_ASSERT(NULL == _tid);
    _mutex.unlock();

    _join_sem.release();
    return osOK;
}

osStatus Thread::set_priority(osPriority priority) {
    osStatus ret;
    _mutex.lock();

    ret = osThreadSetPriority(_tid, priority);

    _mutex.unlock();
    return ret;
}

osPriority Thread::get_priority() {
    osPriority ret;
    _mutex.lock();

    ret = osThreadGetPriority(_tid);

    _mutex.unlock();
    return ret;
}

int32_t Thread::signal_set(int32_t signals) {

    return osSignalSet(_tid, signals);
}

int32_t Thread::signal_clr(int32_t signals) {

    return osSignalClear(_tid, signals);
}

Thread::State Thread::get_state() {
#if !defined(__MBED_CMSIS_RTOS_CA9) && !defined(__MBED_CMSIS_RTOS_CM)
#ifdef CMSIS_OS_RTX
    State status = Deleted;
    _mutex.lock();

    if (_tid != NULL) {
        status = (State)_thread_def.tcb.state;
    }

    _mutex.unlock();
    return status;
#endif
#else
    State status = Deleted;
    _mutex.lock();

    if (_tid != NULL) {
        status = (State)osThreadGetState(_tid);
    }

    _mutex.unlock();
    return status;
#endif
}

uint32_t Thread::stack_size() {
#ifndef __MBED_CMSIS_RTOS_CA9
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
    uint32_t size = 0;
    _mutex.lock();

    if (_tid != NULL) {
        size = _thread_def.tcb.priv_stack;
    }

    _mutex.unlock();
    return size;
#else
    uint32_t size = 0;
    _mutex.lock();

    if (_tid != NULL) {
        P_TCB tcb = rt_tid2ptcb(_tid);
        size = tcb->priv_stack;
    }

    _mutex.unlock();
    return size;
#endif
#else
    return 0;
#endif
}

uint32_t Thread::free_stack() {
#ifndef __MBED_CMSIS_RTOS_CA9
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
    uint32_t size = 0;
    _mutex.lock();

    if (_tid != NULL) {
        uint32_t bottom = (uint32_t)_thread_def.tcb.stack;
        size = _thread_def.tcb.tsk_stack - bottom;
    }

    _mutex.unlock();
    return size;
#else
    uint32_t size = 0;
    _mutex.lock();

    if (_tid != NULL) {
        P_TCB tcb = rt_tid2ptcb(_tid);
        uint32_t bottom = (uint32_t)tcb->stack;
        size = tcb->tsk_stack - bottom;
    }

    _mutex.unlock();
    return size;
#endif
#else
    return 0;
#endif
}

uint32_t Thread::used_stack() {
#ifndef __MBED_CMSIS_RTOS_CA9
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
    uint32_t size = 0;
    _mutex.lock();

    if (_tid != NULL) {
        uint32_t top = (uint32_t)_thread_def.tcb.stack + _thread_def.tcb.priv_stack;
        size = top - _thread_def.tcb.tsk_stack;
    }

    _mutex.unlock();
    return size;
#else
    uint32_t size = 0;
    _mutex.lock();

    if (_tid != NULL) {
        P_TCB tcb = rt_tid2ptcb(_tid);
        uint32_t top = (uint32_t)tcb->stack + tcb->priv_stack;
        size =  top - tcb->tsk_stack;
    }

    _mutex.unlock();
    return size;
#endif
#else
    return 0;
#endif
}

uint32_t Thread::max_stack() {
#ifndef __MBED_CMSIS_RTOS_CA9
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
    uint32_t size = 0;
    _mutex.lock();

    if (_tid != NULL) {
        uint32_t high_mark = 0;
        while (_thread_def.tcb.stack[high_mark] == 0xE25A2EA5)
            high_mark++;
        size = _thread_def.tcb.priv_stack - (high_mark * 4);
    }

    _mutex.unlock();
    return size;
#else
    uint32_t size = 0;
    _mutex.lock();

    if (_tid != NULL) {
        P_TCB tcb = rt_tid2ptcb(_tid);
        uint32_t high_mark = 0;
        while (tcb->stack[high_mark] == 0xE25A2EA5)
            high_mark++;
        size = tcb->priv_stack - (high_mark * 4);
    }

    _mutex.unlock();
    return size;
#endif
#else
    return 0;
#endif
}

osEvent Thread::signal_wait(int32_t signals, uint32_t millisec) {
    return osSignalWait(signals, millisec);
}

osStatus Thread::wait(uint32_t millisec) {
    return osDelay(millisec);
}

osStatus Thread::yield() {
    return osThreadYield();
}

osThreadId Thread::gettid() {
    return osThreadGetId();
}

void Thread::attach_idle_hook(void (*fptr)(void)) {
    rtos_attach_idle_hook(fptr);
}

Thread::~Thread() {

    terminate();
#ifdef __MBED_CMSIS_RTOS_CM
    if (_dynamic_stack) {
        delete[] (_thread_def.stack_pointer);
    }
#endif
}

void Thread::_thunk(const void * thread_ptr)
{
    Thread *t = (Thread*)thread_ptr;
    t->_task();
    t->_mutex.lock();
    t->_tid = (osThreadId)NULL;
    t->_join_sem.release();

}

}

离线

#6 2018-12-07 09:36:02

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,348
积分: 9202

Re: 关于C++编译代码出错,不知道是怎么回事,请大神们帮帮忙.......

Thread::start(Callback<void()> task)

很明显只能传一个参数, 你传那么多肯定会编译错误,你看下别的demo怎么传其他参数,比如pthread创建线程的时候可以传一个指针进去。





离线

楼主 #7 2018-12-07 10:09:28

zhuacai
会员
注册时间: 2017-12-16
已发帖子: 234
积分: 233.5

Re: 关于C++编译代码出错,不知道是怎么回事,请大神们帮帮忙.......

晕哥 说:

Thread::start(Callback<void()> task)

很明显只能传一个参数, 你传那么多肯定会编译错误,你看下别的demo怎么传其他参数,比如pthread创建线程的时候可以传一个指针进去。

晕哥,demo没有看到有传其他参数,这是一个RDA5981的sdk,不知怎么搞个
指针进去传进去

离线

#8 2018-12-07 10:17:51

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,348
积分: 9202

Re: 关于C++编译代码出错,不知道是怎么回事,请大神们帮帮忙.......

zhuacai 说:
晕哥 说:

Thread::start(Callback<void()> task)

很明显只能传一个参数, 你传那么多肯定会编译错误,你看下别的demo怎么传其他参数,比如pthread创建线程的时候可以传一个指针进去。

晕哥,demo没有看到有传其他参数,这是一个RDA5981的sdk,不知怎么搞个
指针进去传进去

RDA5981 SDK 哪里有下载?有空我帮你看下.





离线

楼主 #9 2018-12-07 10:23:05

zhuacai
会员
注册时间: 2017-12-16
已发帖子: 234
积分: 233.5

Re: 关于C++编译代码出错,不知道是怎么回事,请大神们帮帮忙.......

晕哥 说:
zhuacai 说:
晕哥 说:

Thread::start(Callback<void()> task)

很明显只能传一个参数, 你传那么多肯定会编译错误,你看下别的demo怎么传其他参数,比如pthread创建线程的时候可以传一个指针进去。

晕哥,demo没有看到有传其他参数,这是一个RDA5981的sdk,不知怎么搞个
指针进去传进去

RDA5981 SDK 哪里有下载?有空我帮你看下.

先谢谢晕哥了,
链接:https://pan.baidu.com/s/1Ft6g4Z3FTFlckr7PIg-l2A 提取码:94m1 复制这段内容后打开百度网盘手机App,操作更方便哦

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn