清空記錄
歷史記錄
取消
清空記錄
歷史記錄
本文基于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ù)文件,實(shí)現(xiàn)系統(tǒng)開機(jī)啟動(dòng)時(shí)開啟以太網(wǎng)共享。
packages/apps/Settings/src/com/android/settings/StartEth1ShareRunnable.java
文件內(nèi)容如下:
package com.android.settings;
//以太網(wǎng)共享
import android.app.Service;
import android.content.Context;
import android.os.Handler;
import android.util.Log;
import android.content.Intent;
import android.os.IBinder;
import android.net.ConnectivityManager;
import static android.net.TetheringManager.TETHERING_ETHERNET;
import android.net.ConnectivityManager.OnStartTetheringCallback;
public class StartEth1ShareRunnable extends Service {
private static final String TAG = "StartEth1ShareRunnable";
private Context mContext;
//以太網(wǎng)共享
private ConnectivityManager mCm;
private OnStartTetheringCallback mStartTetheringCallback;
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
super.onCreate();
mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
mStartTetheringCallback = new OnStartTetheringCallback();
mHandler.post(StartEth1ShareRunnable);//啟用以太網(wǎng)
}
private Handler mHandler = new Handler();
private class OnStartTetheringCallback extends ConnectivityManager.OnStartTetheringCallback {
@Override
public void onTetheringStarted() {
Log.d(TAG, "ethernet onTetheringStarted!\n");
}
@Override
public void onTetheringFailed() {
Log.e(TAG, "ethernet onTetheringFailed!\n");
}
}
//以太網(wǎng)共享
private Runnable StartEth1ShareRunnable = new Runnable() {
@Override
public void run() {
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ù)
package com.android.settings;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class MyBootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String action = intent.getAction();
if (action.equals(Intent.ACTION_BOOT_COMPLETED))
{
Intent service = new Intent(context, StartEth1ShareRunnable.class);
context.startService(service);
}
}
}
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.1 4G網(wǎng)卡IP:10.47.102.124
console:/ # ifconfig
eth0 Link encap:Ethernet HWaddr