本文基于IDO-SBC3566-V1B Android11系統(tǒng)實(shí)現(xiàn)開機(jī)后以太網(wǎng)自動(dòng)共享4G網(wǎng)絡(luò)功能
IDO-SBC3566基于瑞芯微RK3566研發(fā)的一款高性能低功耗的智能主板,采用四核A55,主頻高達(dá)1.8GHz,專為個(gè)人移動(dòng)互聯(lián)網(wǎng)設(shè)備和AIOT設(shè)備而設(shè)計(jì),內(nèi)置了多種功能強(qiáng)大的嵌入式硬件引擎,為高端應(yīng)用提供了優(yōu)異的性能,支持幾乎全格式的4K編解碼,內(nèi)置3DGPU,能夠完全兼容OpenGL ES1.1/2.0/3.2、OpenCL2.0和Vulkan1.0.特殊的MMU2D硬件引擎,此外,憑借其強(qiáng)大的兼容性,可以輕松地轉(zhuǎn)換基于TensorFlow/MXNet/PyTorch/Caffe等一系列框架的網(wǎng)絡(luò)模型。
支持Android,Linux,OpenHarmony,麒麟OS等多種操作系統(tǒng),可廣泛應(yīng)用于平板、教育平板、帶屏音箱、詞典筆、云終端、視頻會(huì)議系統(tǒng)等安卓/Linux類應(yīng)用方案,以及其他帶屏消費(fèi)類、或輕量級(jí)AI應(yīng)用場(chǎng)景。
產(chǎn)品規(guī)格書:IDO-SBC3566-V1B 產(chǎn)品手冊(cè)
添加以太網(wǎng)共享服務(wù)
在源碼目錄下新建以太網(wǎng)共享服務(wù)文件,實(shí)現(xiàn)系統(tǒng)開機(jī)啟動(dòng)時(shí)開啟以太網(wǎng)共享。
packages/apps/Settings/src/com/android/settings/StartEth1ShareRunnable.java
文件內(nèi)容如下:
packagecom.android.settings;
//以太網(wǎng)共享
importandroid.app.Service;
importandroid.content.Context;
importandroid.os.Handler;
importandroid.util.Log;
importandroid.content.Intent;
importandroid.os.IBinder;
importandroid.net.ConnectivityManager;
importstaticandroid.net.TetheringManager.TETHERING_ETHERNET;
importandroid.net.ConnectivityManager.OnStartTetheringCallback;
publicclassStartEth1ShareRunnableextendsService{
privatestaticfinalString TAG = "StartEth1ShareRunnable";
privateContext mContext;
//以太網(wǎng)共享
privateConnectivityManager mCm;
privateOnStartTetheringCallback mStartTetheringCallback;
@Override
publicIBinder onBind(Intent arg0){
// TODO Auto-generated method stub
returnnull;
}
@Override
publicvoidonCreate(){
super.onCreate();
mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
mStartTetheringCallback = newOnStartTetheringCallback();
mHandler.post(StartEth1ShareRunnable);//啟用以太網(wǎng)
}
privateHandler mHandler = newHandler();
privateclassOnStartTetheringCallbackextendsConnectivityManager.OnStartTetheringCallback{
@Override
publicvoidonTetheringStarted(){
Log.d(TAG, "ethernet onTetheringStarted!\n");
}
@Override
publicvoidonTetheringFailed(){
Log.e(TAG, "ethernet onTetheringFailed!\n");
}
}
//以太網(wǎng)共享
privateRunnable StartEth1ShareRunnable = newRunnable() {
@Override
publicvoidrun(){
try{
if(mCm != null)
mCm.startTethering(TETHERING_ETHERNET, true, mStartTetheringCallback, mHandler);//開啟以太網(wǎng)共享
} catch(Exception e) {
Log.e(TAG, "ethernet startTethering error!\n");
e.printStackTrace();
mHandler.postDelayed(StartEth1ShareRunnable, 10000);//延遲10秒后重新執(zhí)行
}
}
};
}
在packages/apps/Settings/src/com/android/settings/ 添加一個(gè)廣播 MyBootReceiver.java 用于接收啟動(dòng)完成事件,在收到廣播后調(diào)用StartEth1ShareRunnable服務(wù)
packagecom.android.settings;
importandroid.content.BroadcastReceiver;
importandroid.content.Context;
importandroid.content.Intent;
publicclassMyBootReceiverextendsBroadcastReceiver{
@Override
publicvoidonReceive(Context context, Intent intent){
// TODO Auto-generated method stub
String action = intent.getAction();
if(action.equals(Intent.ACTION_BOOT_COMPLETED))
{
Intent service = newIntent(context, StartEth1ShareRunnable.class);
context.startService(service);
}
}
}
功能驗(yàn)證
SBC3566主板插入可使用的EC20 4G模塊以及SIM卡,如下圖所示:
?
從SBC3566主板網(wǎng)口接一根網(wǎng)線到另外一塊主板網(wǎng)口上,并給兩個(gè)主板供電。
在SBC3566系統(tǒng)查看網(wǎng)口及4G獲取的IP
共享的網(wǎng)口網(wǎng)絡(luò)IP:192.168.5.14G網(wǎng)卡IP:10.47.102.124
console:/ # ifconfig
eth0 Link encap:Ethernet HWaddr 02:ed:83:f3:50:c4 Driver rk_gmac-dwmac
inet addr:192.168.5.1 Bcast:192.168.5.255 Mask:255.255.255.0
inet6 addr: fe80::7a78:d959:9bff:28cd/64Scope: Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:133errors:0dropped:0overruns:0frame:0
TX packets:158errors:0dropped:0overruns:0carrier:0
collisions:0txqueuelen:1000
RX bytes:17758TX bytes:37405
Interrupt:38
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.47.102.124 P-t-P:10.64.64.64 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:104errors:0dropped:0overruns:0frame:0
TX packets:111errors:0dropped:0overruns:0carrier:0
collisions:0txqueuelen:3
RX bytes:27734TX bytes:11416
通過ping 百度地址能正常上網(wǎng)
console:/ # ping www.baidu.com
PING www.baidu.com (157.148.69.74) 56(84) bytes ofdata.
64bytes from157.148.69.74: icmp_seq=1ttl=52time=32.8ms
64bytes from157.148.69.74: icmp_seq=2ttl=52time=24.0ms
64bytes from157.148.69.74: icmp_seq=3ttl=52time=24.1ms
64bytes from157.148.69.74: icmp_seq=4ttl=52time=24.4ms
64bytes from157.148.69.74: icmp_seq=5ttl=52time=23.8ms
64bytes from157.148.69.74: icmp_seq=6ttl=52time=24.1ms
64bytes from157.148.69.74: icmp_seq=7ttl=52time=25.4ms
64bytes from157.148.69.74: icmp_seq=8ttl=52time=24.7ms
^C
--- www.baidu.com ping statistics ---
8packets transmitted, 8received, 0% packet loss, time 7012ms
rtt min/avg/max/mdev = 23.808/25.447/32.874/2.852ms
另外一塊主板通過網(wǎng)絡(luò)共享獲取到的IP 為192.168.5.X網(wǎng)段
console:/ # ifconfig
eth1 Link encap:Ethernet HWaddr 3a:1d:f7:26:49:0a Driver r8168
inet addr:192.168.5.199 Bcast:192.168.5.255 Mask:255.255.255.0
inet6 addr: fe80::4a59:7a31:cc45:1b53/64Scope: Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:286671errors:0dropped:0overruns:0frame:0
TX packets:586errors:0dropped:0overruns:0carrier:0
collisions:0txqueuelen:1000
RX bytes:27238966TX bytes:64962
Interrupt:169Base address:0x3000
通過測(cè)試可以ping通互聯(lián)網(wǎng)網(wǎng)址
console:/ # ping www.baidu.com
PING www.baidu.com (157.148.69.74) 56(84) bytes ofdata.
64bytes from157.148.69.74: icmp_seq=1ttl=51time=37.7ms
64bytes from157.148.69.74: icmp_seq=2ttl=51time=28.7ms
64bytes from157.148.69.74: icmp_seq=3ttl=51time=22.9ms
64bytes from157.148.69.74: icmp_seq=4ttl=51time=23.2ms
64bytes from157.148.69.74: icmp_seq=5ttl=51time=23.4ms
64bytes from157.148.69.74: icmp_seq=6ttl=51time=48.0ms
64bytes from157.148.69.74: icmp_seq=7ttl=51time=23.0ms
64bytes from157.148.69.74: icmp_seq=8ttl=51time=24.9ms
64bytes from157.148.69.74: icmp_seq=9ttl=51time=69.8ms
^C
--- www.baidu.com ping statistics ---
9packets transmitted, 9received, 0% packet loss, time 8012ms
rtt min/avg/max/mdev = 22.930/33.577/69.879/15.184ms
-
Android
+關(guān)注
關(guān)注
12文章
3937瀏覽量
127454 -
4G網(wǎng)絡(luò)
+關(guān)注
關(guān)注
1文章
142瀏覽量
26869 -
瑞芯微
+關(guān)注
關(guān)注
23文章
421瀏覽量
51355
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論