2016-08-22 17 views
1

私は、mbed-cliツールを使用してmbed-osの新しいコピーをプルダウンしました。mbed-osから利用可能なライブラリを使用するには?

$ mbed new mbed-os-test 
[mbed] Creating new program "mbed-os-test" (git) 
[mbed] Adding library "mbed-os" from "https://github.com/ARMmbed/mbed-os" at latest revision in the current branch 
[mbed] Updating reference "mbed-os" -> "https://github.com/ARMmbed/mbed-os/#dda7f7d77abd4330b05e686ce3bbe58230eb7876" 

最終的に私は私のNXP FRDM-K64Fデバイス上uVisorを有効にするために働いていますが、今の私はuVisorを有効にせずに作業を簡単な例を取得するためにQuickStartチュートリアルを使用しています。

上記のリンクで提案されているように、私はMBED-OSの新規作成されたクローンでsourceディレクトリを作る:

$ mkdir mbed-os-test/mbed-os/source 

私は基本main.cppにコピーしてコンパイルします。できます。しかし、いくつかのライブラリルーチンを使用して問題を作成しようとすると、特にEthernetInterfaceが発生します。

上記のリンクから(EthernetInterfaceを使用して)、より複雑なものとuVisorの例から私の簡単なmain.cppの交換:私は、コンパイルと会ってい

mbed compile -m K64F -t GCC_ARM

:してコンパイル

#include "mbed.h" 
#include "EthernetInterface.h" 

int main() { 
    EthernetInterface eth; 
    eth.init(); //Use DHCP 
    eth.connect(); 
    printf("IP Address is %s\n", eth.getIPAddress()); 

    TCPSocketConnection sock; 
    sock.connect("mbed.org", 80); 

    char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n"; 
    sock.send_all(http_cmd, sizeof(http_cmd)-1); 

    char buffer[300]; 
    int ret; 
    while (true) { 
     ret = sock.receive(buffer, sizeof(buffer)-1); 
     if (ret <= 0) 
      break; 
     buffer[ret] = '\0'; 
     printf("Received %d chars from server:\n%s\n", ret, buffer); 
    } 

    sock.close(); 

    eth.disconnect(); 

    while(1) {} 
} 

EthernetInterfaceクラスに、私が呼び出しようとしているメンバーがないことを示すエラーが表示されます。もちろん、EthernetInterfaceクラスは、このようなメンバーをていない、

../../mbed-os/source/main.cpp: In function 'int main()': 
../../mbed-os/source/main.cpp:34:9: error: 'class EthernetInterface' has no member named 'init' 
    eth.init(); //Use DHCP 
     ^
../../mbed-os/source/main.cpp:36:38: error: 'class EthernetInterface' has no member named 'getIPAddress' 
    printf("IP Address is %s\n", eth.getIPAddress()); 
            ^
../../mbed-os/source/main.cpp:38:5: error: 'TCPSocketConnection' was not declared in this scope 
    TCPSocketConnection sock; 
    ^
../../mbed-os/source/main.cpp:39:5: error: 'sock' was not declared in this scope 
    sock.connect("mbed.org", 80); 
    ^

。私は問題はmbedユーティリティが正しいソースコードに対してコンパイルされていないことに関連していると思うので、ヘッダーを見つけるようだ。 --source=オプションをmbedコンパイルに追加すると、EthernetInterface.cppに含まれるものに関して他のエラーが発生しました。

mbed compile -m K64F -t GCC_ARM --source=../libraries/net/eth/EthernetInterface/

ファイルは確かにMBED-OSに含まれている
[ERROR] In file included from ../libraries/net/eth/EthernetInterface/EthernetInterface.cpp:19:0: 
../libraries/net/eth/EthernetInterface/EthernetInterface.h:27:18: fatal error: rtos.h: No such file or directory 

は、私がどれだけに、実際に 使用それらを確認していません。

$ find . -name EthernetInterface.cpp 
./libraries/net/eth/EthernetInterface/EthernetInterface.cpp 
./features/net/FEATURE_IPV4/lwip-interface/EthernetInterface.cpp 

TL; DR - どのように私たちはlibraries/で与えられたライブラリコードをリンクすることができますか?私は直接ファイルを直接インクルードすることでヘッダファイルをインクルードすることができますが、対応するソースはlibraries/のディレクトリではなくfeatures/ディレクトリにあるようです。

+1

質問にはmbed OSがありますが、リンクしているドキュメントはmbed Classic用です。これは同じものではありません。 [ここにinit()メンバーはありません](https://docs.mbed.com/docs/mbed-os-api/en/mbed-os-5.1.0/api/features_2net_2FEATURE__IPV4_2lwip-interface_2EthernetInterface_8h_source) html)(スーパークラスでも)。 – Notlikethat

+0

@Notlikethat、違いは何ですか?質問の終わりの最後の 'find'コマンドには2つの結果があります:' libraries'の最初のものはドキュメント[ここ]に対応するソースです(https://developer.mbed.org/handbook/Ethernet-Interface )、後者の 'features 'はあなたのコメントにリンクしているのと同じソースです。私のソースに "EthernetInterface.h"を含めると、前者(これは 'init'などのようなより多くの機能があります)ではなく、後者を含むようです。 – sherrellbc

+1

_ "このドキュメントでは、mbed 2で利用可能なネットワーキングライブラリについて説明しています。mbed 5では、追加のネットワークスタックとスレッドの安全性を向上させるために、ネットワーキングライブラリが改訂されました[こちら](https://docs.md.com/docs/mbed mbed Classic(バージョン2)は基本的にHALライブラリのセットですが、mbed OS(バージョン5)はHALライブラリのセットです。本格的な接続性に焦点を当てたRTOSであり、両者のソースレベルの互換性が大幅に失われています。私は実際にどちらか自分自身を使用したとは言えません。 – Notlikethat

答えて

2

これが私のために働くので、私は、あなたは、私が欠けていることをやっていることを思ったんだけど:

$ mbed new ethernet-test 
$ cd ethernet-test 
$ mbed target K64F 
$ mbed toolchain GCC_ARM 

オープンethernet-test/main.cppと入れ:次に

#include "mbed.h" 
#include "EthernetInterface.h" 

int main(int, char**) { 
    EthernetInterface eth; 
    eth.connect(); 
} 

$ mbed compile 
... 
Total Flash memory (text + data + misc): 108092 bytes 
Image: ./.build/K64F/GCC_ARM/ethernet-test.bin 
+0

実際には動作しますが、わかったように、DHCPを使用するよりも静的な割り当てなど、より多くの機能を備えたEthernetInterfaceの実装は、[ここ](https://developer.mbed.org/handbook/Ethernet-Interface)、まだmbed5に入っていません([source](https://developer.mbed.org/questions/73258/How-does-mbed-cli-create-includes-and-li/))。どちらの実装もmbedリポジトリに含まれていますが、[this](https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/communication/network_sockets/)のみが実際にコンパイルされますリンクされています。 – sherrellbc

+0

興味深いことに、上記のAPI(https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/communication/ethernet/))は、実際に働く。 'features'ディレクトリ内のソースファイルを見ると(' OP'ライブラリは完全な実装を持ち、 'features'はサブセットを持つように見えます)、' Public Members Functions'のコードだけを持ち、そのリンクから「静的なパブリックメンバー関数」を選択します。ステータスメンバー関数の1つ、たとえば.e.g EthernetInterface.init()などを試してください。それは動作しません。 – sherrellbc

関連する問題