1

Spresense(arduino版)にて、現在録音とデータ送信を同時に行いたく、実装を進めております。
マルチスレッド化はpthreadを用いて実装をしておりますが、録音のエラーでストップしてしまいます。
原因や解決策お分かりの方いらっしゃいましたら、ご教示いただけませんでしょうか。
よろしくお願いいたします。

使用
・SPRESENSE メインボード
・SPRESENSE LTE拡張ボード
・pthread (nuttx)
・message queue

コード抜粋

スレッド作成

void * thread_LTE(void *data) {
    Serial.println("LTE_pthread");

    while(true){
        Serial.println("LTE_LOOP");
        String sendFileName;
        sendFileName = recvQueue();
        if (!sendFileName == ""){
            Serial.println("START LTE SEND");
            Serial.println(sendFileName);
            sendDataAws(sendFileName);
            sendFileName = "";
        }
    }

    return NULL;
}

void * thread_rec(void *data) {
    Serial.println("rec_pthread");
    startMP3Recording(Filename);
    return NULL;
}



int recLTE_pthread() {
    pthread_t th;
    void *th_ret;
    
    if (pthread_create(&th, NULL, thread_rec, (void *)100) != 0) {
    perror("pthread_create");
    return 1;
    }
    
    if (pthread_create(&th, NULL, thread_LTE, (void *)100) != 0) {
        perror("pthread_create");
        return 1;
    }

    Serial.println("Thread  was made");

    if (pthread_join(th, &th_ret) != 0) {
        perror("pthread_join");
        return 1;
    }

    return 0;
}

message queue

String recvQueue (){
    const char* que_name = "/recEnd";
    struct mq_attr attr;
    mqd_t q;
    char* buf;
    String fileName = "";
    enum abc{O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_NONBLOC};

    q = mq_open(que_name, O_RDONLY);
    mq_getattr( q ,&attr );
    buf = (char *)malloc(attr.mq_msgsize);
    mq_receive( q, (char*)buf, attr.mq_msgsize, NULL);

    Serial.println(fileName);
    fileName = String(buf);

    free(buf);
    mq_close(q);

    return fileName;
}

void sendQueue (char* fileName){
    const char* que_name = "/recEnd";
    struct mq_attr attr;
    mqd_t q;
    char* buf = fileName;
    enum abc{O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_NONBLOC};

    q =  q = mq_open(que_name, O_WRONLY | O_CREAT, NULL);
    mq_send( q, (const char *)(&buf) , sizeof(buf) , 0);
    Serial.println("rec data stocked");
    mq_close(q);
}

1 件の回答 1

0

以上の問題は確定できませんが、予感があります。

pthreadはいくつかのリソースを共通しています。pthread_createをtask_createに書き換え、試してみるのはいかがでしょうか?

NuttXのドキュメンテーションの参照先
https://cwiki.apache.org/confluence/display/NUTTX/Tasks+vs.+Threads+FAQ

If a task group receives a signal and more than one thread is waiting on that signal, then one and only one indeterminate thread out of that waiting group will receive the signal.

Here is the definitive list of what is shared. Most of these resources reside within the task group structure struct task_group_s:

  • Child task exit status
  • Pthread join data
  • Environment variables
  • File descriptors
  • FILE streams
  • Sockets
  • Opened message queues
  • pthread keys
  • Support data for atexit(), on_exit, and/or waitpid()

具体的なエラー番号やメッセージを追加すると助かります。

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。