【正文】
the drawback of this solution is the consumption of device resources(.,CPU time,memory and thus energy from the battery)for the runtime middleware environment. software development flowOther works[4]propose to use a library(there is a specific version of the library for each platform)which provides a standard interface to application ,additional device resources are used at runtime to translate application calls into native ,[8],[9]propose to develop the mobile application as a web application which is portable across all browserenabled main drawback regards the impossibility to access directly to hardware features of the mobile device and the difficulty to achieve userinterface effects not usually present in web pages.ModelDriven Design[10]and PlatformIndependent Models(PIM)[11]offer a reasonable solution to model the application independently of the target device and automating the porting to different platforms.The contribution of this work is a ModelDriven Design methodology to develop smartphone applications independently of a specific from the analysis of the main smartphone platforms,we introduce a UML2 profile to represent the elements of the application independently of the target platform。后期則是對應(yīng)用進(jìn)行一些普及的開發(fā),即每個(gè)應(yīng)用一般都有的“注冊”“設(shè)置”功能,又或是對脈搏數(shù)據(jù)的一些簡單分析,隨著工作的逐步進(jìn)行,功能漸漸完善,也越來越像一個(gè)真正的應(yīng)用軟件了。 總結(jié)此次畢業(yè)設(shè)計(jì),名為“基于Android的便攜式健康監(jiān)測系統(tǒng)”,從技術(shù)上來說,難點(diǎn)在于“基于Android”,即移動(dòng)開發(fā);從內(nèi)容上來說,難點(diǎn)在于“健康監(jiān)測”,即應(yīng)用功能中就具備健康分析與建議模塊。 }}第一個(gè)方法放在主界面下,即添加管理員用戶,第二個(gè)方法放在設(shè)置界面,因?yàn)楣芾韱T主要是在設(shè)置中擁有較大的權(quán)限,比如刪除用戶。 if ((admin)) { (true)??梢詮拇a中看出,注銷以后需要將權(quán)限恢復(fù)至未注冊的狀態(tài);同樣地,對于管理員權(quán)限也是進(jìn)行同樣的判斷,同樣是在主界面中判斷當(dāng)前用戶是否為管理員用戶;此處也存在一個(gè)問題,即“設(shè)置”中的查詢用戶功能可以查看當(dāng)前所有用戶的用戶名與密碼,為了彌補(bǔ)此漏洞,設(shè)計(jì)者將顯示列表中的管理員用戶的密碼設(shè)置為“******”,即防止注冊用戶看到密碼后用管理員用戶進(jìn)行登錄;管理員用戶應(yīng)該是內(nèi)置的,即程序本身已經(jīng)創(chuàng)建的,而不是通過注冊界面進(jìn)行創(chuàng)建的,這就需要在啟動(dòng)應(yīng)用時(shí)就創(chuàng)建一個(gè)管理員用戶,并且在其后的啟動(dòng)過程中判斷用戶數(shù)據(jù)庫中是否有此管理員用戶,如果不存在,則創(chuàng)建管理員用戶,且此管理員是固定用戶名和密碼的;private void addAdmin() { ListUser users = ()。 }}上述代碼放在主界面中,即一進(jìn)入應(yīng)用就進(jìn)行判斷工作,以方便用戶;此外,有登錄功能,肯定也要有相應(yīng)的注銷功能,;().mit()。 (true)。2. 注冊權(quán)限開放問題(包括管理數(shù)據(jù)庫)本設(shè)計(jì)中將權(quán)限分為三級,管理員擁有最高權(quán)限,普通注冊用戶,未注冊用戶;這其中要對用戶使用應(yīng)用的功能部分做一定的限制,而限制用戶,首先要判斷目前是否有登錄的用戶,或是登錄的用戶是屬于哪一類用戶。 else = 2。 }。Handler mHandler = new Handler() { public void handleMessage(Message msg) { switch () { case 1: refreshChart()。 (this, 20)。Android的線程操作有效的主要有兩種方法,如下:方法一:Runable+Handlerstatic Handler pluseHandler=new Handler()。解決的方法較為簡單,即測試時(shí)用指肚將傳感器的發(fā)光燈完全覆蓋住,光沒有在邊緣漏出時(shí)效果最好,傳輸?shù)臄?shù)據(jù)也最穩(wěn)定。 (adapter)。 (username, ())。 for (int i = 0。除此之外,還有設(shè)置繪圖中的自動(dòng)定時(shí)功能,和個(gè)人用戶的密碼修改功能。 } else { (false)。 (true)。 (user)。 (e, (existFlag))。以上代碼為設(shè)置對話三個(gè)按鈕的響應(yīng)事件,可以看到為“注冊”“登錄”兩個(gè)按鈕都設(shè)置了相應(yīng)的監(jiān)聽器,并將文本編輯框中填寫的文本傳入處理方法中。 (().toString(), ().toString())。而注冊界面,因?yàn)闀簳r(shí)不需要輸入太多信息的緣故,采用了彈出對話框的模式,設(shè)置“用戶名”和“密碼”兩個(gè)文本編輯框,三個(gè)按鈕“取消”“注冊”“登錄”,用戶不論是注冊還是登錄都在此對話框中進(jìn)行。 圖形開發(fā)界面應(yīng)用用戶分為三種,未注冊用戶,注冊用戶,管理員。接收數(shù)據(jù)處理并繪圖其實(shí)在代碼中存在于一個(gè)類中(),故而可以用整體的流程圖說明其工作流程。 for (int i = 0。 i++) { x[i] = (i)。 } // 以下為保留原圖曲線和新增數(shù)據(jù)點(diǎn) count = ()。 // 將縱坐標(biāo)賦值為最新接收到的數(shù)據(jù) yTemp = (dataListSize 1)。 ()。在接收數(shù)據(jù)的基礎(chǔ),將數(shù)據(jù)以2:1的比例用于繪圖,這是因?yàn)槔L圖時(shí)給刷新整個(gè)界面并保留原有數(shù)據(jù),線程工作量較大,如果以過高頻率刷新界面,那么很容易引起界面的崩潰乃至應(yīng)用的退出,代碼如下:// 將接收到的數(shù)據(jù)疏散五倍進(jìn)行繪圖 if (() % 2 == 0) { // 將接收到的數(shù)據(jù)疏散五倍加入繪圖數(shù)據(jù)集合 ((() 1))。 // 用于存放所有需要繪制的XYSeries private static XYMultipleSeriesDataset mDataset。Android下繪圖方法很多,Path類,SurfaceView類,Canvas類……等等都可以繪出圖形,不過由于對波形要求較高且數(shù)據(jù)量相對較大,所以采用已經(jīng)成熟的外置繪圖引擎AChartEngine來繪制圖形。數(shù)據(jù)存入文件時(shí),為了方便二次調(diào)用和查看,在每個(gè)數(shù)據(jù)后面追加了換行符,結(jié)果就是每個(gè)數(shù)據(jù)會(huì)在文件中單獨(dú)成行。 ()。 Bpm = (int) (Bpp * 60)。 // 將每次調(diào)用此方法的時(shí)間加入時(shí)間集合 (curTime)。 ((pluse) + \r\n)。 // 接收的數(shù)據(jù)超過200,則將集合清0 if (() = 200) { ()。部分代碼如下:// 從藍(lán)牙接收數(shù)據(jù)的方法體 public static void recData(String str, byte[] data, String uuid) { if (()) { int pluse = ~data[1]。()即得到藍(lán)牙設(shè)備的UUID值,整個(gè)應(yīng)用中也是通過判斷UUID值來確定是否為配套的設(shè)備[12]。 } //收到BLE終端寫入數(shù)據(jù)回調(diào) Override public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { ((characteristic .getValue()), (), characteristic .getUuid().toString())。 }...}5 搜索到藍(lán)牙設(shè)備后,可以由一個(gè)列表將之顯示出來,如下用一個(gè)配置文件將之列出(),;?xml version= encoding=utf8?LinearLayout xmlns:android= android:orientation=vertical android:layout_width=match_parent android:layout_height=wrap_content TextView android:id=+id/device_name android:layout_width=match_parent android:layout_height=wrap_content android:text=name android:textSize=32sp / TextView android:id=+id/device_address android:layout_width=match_parent android:layout_height=wrap_content android:text=address android:textSize=16dp / TextView android:id=+id/device_txPower_rssi android:layout_width=match_parent android:layout_height=wrap_content android:text=txPower_rssi android:textSize=26sp / /LinearLayout6 接下來還需連接到GATT服務(wù)端并讀取藍(lán)牙的一些固定屬性值,此處不再贅述。 } else { mScanning = true。 private static final long SCAN_PERIOD = 10000。 private boolean mScanning。 startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)。 (BluetoothManager) getSystemService()。:否獲取藍(lán)牙適配器開始開啟藍(lán)牙服務(wù)搜索BLE設(shè)備連接到GATT服務(wù)端搜索到?讀取BLE屬性接收服務(wù)端信息結(jié)束設(shè)備列表是 藍(lán)牙模塊流程圖以下為使用BLE設(shè)備必要的開發(fā)步驟[11]:1 ,因?yàn)橛玫搅薆LE設(shè)備,因此需加上BLE設(shè)備的支持聲明;usespermission android:name=/usespermission android:name=/usesfeature android:name= android:required=true/2 在確定開發(fā)環(huán)境是Android ,取得藍(lán)牙適配器;// Initializes Bluetooth adapter.final BluetoothManager bluetoothManager =軟件整體工作流程可分為以下幾步:1 通過藍(lán)牙基類尋找BLE設(shè)備,并顯示設(shè)備列表2 點(diǎn)擊列表中的設(shè)備,獲取藍(lán)牙服務(wù)3 接收藍(lán)牙傳遞的數(shù)據(jù)4 處理數(shù)據(jù),并以字符流形式存入文件5 由傳遞的數(shù)據(jù)顯示出實(shí)時(shí)的波形圖6 計(jì)算出BPM7 其他功能根據(jù)軟件整體完成的工作流程,:開始獲取藍(lán)牙服務(wù)接收數(shù)據(jù)處理數(shù)據(jù)顯示波形圖存入文件計(jì)算BPM其他功能結(jié)束 整體流程圖藍(lán)牙傳輸是建立在藍(lán)牙硬件平臺(tái)搭建正確的基礎(chǔ)上的,其中包括藍(lán)牙模塊芯片CC254x與開發(fā)板的連接,開發(fā)板與傳感器的連接,以及在開發(fā)板中寫入控制藍(lán)牙的程序。調(diào)試環(huán)境分為模擬環(huán)境與真機(jī)環(huán)境,模擬器使用Genymotion,可調(diào)試不涉及硬件操作的功能模擬,真機(jī)則沒有限制,當(dāng)然真機(jī)最好選擇接口較多,功能較全的手機(jī)型號。 光