|
|
@ -1,24 +1,51 @@ |
|
|
|
package com.example.beacondemo.Activity; |
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
import androidx.annotation.Nullable; |
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager; |
|
|
|
import androidx.recyclerview.widget.RecyclerView; |
|
|
|
|
|
|
|
import android.content.Intent; |
|
|
|
import android.graphics.Color; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.text.Html; |
|
|
|
import android.util.Log; |
|
|
|
import android.view.View; |
|
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
import com.example.beacondemo.R; |
|
|
|
import com.example.beacondemo.adapter.RecycleAdapter; |
|
|
|
import com.minew.beaconplus.sdk.MTCentralManager; |
|
|
|
import com.minew.beaconplus.sdk.MTConnectionHandler; |
|
|
|
import com.minew.beaconplus.sdk.MTFrameHandler; |
|
|
|
import com.minew.beaconplus.sdk.MTPeripheral; |
|
|
|
import com.minew.beaconplus.sdk.enums.FrameType; |
|
|
|
import com.minew.beaconplus.sdk.enums.TriggerType; |
|
|
|
import com.minew.beaconplus.sdk.enums.Version; |
|
|
|
import com.minew.beaconplus.sdk.exception.MTException; |
|
|
|
import com.minew.beaconplus.sdk.frames.AccFrame; |
|
|
|
import com.minew.beaconplus.sdk.frames.ForceFrame; |
|
|
|
import com.minew.beaconplus.sdk.frames.HTFrame; |
|
|
|
import com.minew.beaconplus.sdk.frames.IBeaconFrame; |
|
|
|
import com.minew.beaconplus.sdk.frames.InfoFrame; |
|
|
|
import com.minew.beaconplus.sdk.frames.LightFrame; |
|
|
|
import com.minew.beaconplus.sdk.frames.LineBeaconFrame; |
|
|
|
import com.minew.beaconplus.sdk.frames.MinewFrame; |
|
|
|
import com.minew.beaconplus.sdk.frames.PIRFrame; |
|
|
|
import com.minew.beaconplus.sdk.frames.TamperProofFrame; |
|
|
|
import com.minew.beaconplus.sdk.frames.TemperatureFrame; |
|
|
|
import com.minew.beaconplus.sdk.frames.TlmFrame; |
|
|
|
import com.minew.beaconplus.sdk.frames.TvocFrame; |
|
|
|
import com.minew.beaconplus.sdk.frames.UidFrame; |
|
|
|
import com.minew.beaconplus.sdk.frames.UrlFrame; |
|
|
|
import com.minew.beaconplus.sdk.interfaces.MTCentralManagerListener; |
|
|
|
import com.minew.beaconplus.sdk.interfaces.SetTriggerListener; |
|
|
|
import com.minew.beaconplus.sdk.model.Trigger; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
public class DetailActivity extends AppCompatActivity implements View.OnClickListener { |
|
|
|
|
|
|
|
private MTPeripheral mtPeripheral; |
|
|
@ -34,14 +61,22 @@ public class DetailActivity extends AppCompatActivity implements View.OnClickLis |
|
|
|
int mCurSlot = 2; |
|
|
|
|
|
|
|
TextView txt_name,txt_mac,txt_battery,txt_rssi,txt_device,txt_xaxis,txt_yaxis,txt_zaxis; |
|
|
|
String mac,name; |
|
|
|
String mac,name,xaxis,yaxis,zaxis;; |
|
|
|
int battery,rssi; |
|
|
|
|
|
|
|
private RecycleAdapter mAdapter; |
|
|
|
|
|
|
|
RecyclerView mRecycle; |
|
|
|
|
|
|
|
ArrayList<MinewFrame> advFrames; |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
setContentView(R.layout.activity_detail); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initView(); |
|
|
|
initData(); |
|
|
|
initListener(); |
|
|
@ -51,40 +86,212 @@ public class DetailActivity extends AppCompatActivity implements View.OnClickLis |
|
|
|
ivBack = findViewById(R.id.iv_back); |
|
|
|
tvSet = findViewById(R.id.tv_set); |
|
|
|
|
|
|
|
//txt_battery=findViewById(R.id.txt_battery); |
|
|
|
txt_battery=findViewById(R.id.txt_battery); |
|
|
|
txt_mac=findViewById(R.id.txt_mac); |
|
|
|
txt_name=findViewById(R.id.txt_name); |
|
|
|
//txt_rssi=findViewById(R.id.txt_rssi); |
|
|
|
txt_rssi=findViewById(R.id.txt_rssi); |
|
|
|
txt_device=findViewById(R.id.txt_device); |
|
|
|
txt_xaxis=findViewById(R.id.txt_xaxis); |
|
|
|
txt_yaxis=findViewById(R.id.txt_yaxis); |
|
|
|
txt_zaxis=findViewById(R.id.txt_zaxis); |
|
|
|
|
|
|
|
mRecycle = findViewById(R.id.recycle); |
|
|
|
|
|
|
|
Intent intent = getIntent(); |
|
|
|
String mac = intent.getStringExtra("mac"); |
|
|
|
String name = intent.getStringExtra("name"); |
|
|
|
int battery = intent.getIntExtra("battery",0); |
|
|
|
int rssi = intent.getIntExtra("rssi",0); |
|
|
|
|
|
|
|
System.out.println("Value of battery and rssi in DetailActivity : " + battery + " " + rssi ); |
|
|
|
String xaxis = intent.getStringExtra("xaxis"); |
|
|
|
String yaxis = intent.getStringExtra("yaxis"); |
|
|
|
String zaxis = intent.getStringExtra("zaxis"); |
|
|
|
|
|
|
|
txt_mac.setText("Mac Address : "+mac); |
|
|
|
txt_name.setText("Device Name : "+name); |
|
|
|
/*txt_rssi.setText(rssi); |
|
|
|
txt_battery.setText(battery);*/ |
|
|
|
txt_rssi.setText("Battery Status : "+ String.valueOf(rssi)); |
|
|
|
txt_battery.setText(" Rssi : "+String.valueOf(battery)); |
|
|
|
txt_xaxis.setText("X axis: " +xaxis); |
|
|
|
txt_yaxis.setText("Y axis: " +yaxis); |
|
|
|
txt_zaxis.setText("Z axis: " +zaxis); |
|
|
|
txt_device.setText("Device in range. "); |
|
|
|
txt_device.setTextColor(Color.BLUE); |
|
|
|
|
|
|
|
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this); |
|
|
|
mRecycle.setLayoutManager(layoutManager); |
|
|
|
mAdapter = new RecycleAdapter(); |
|
|
|
mRecycle.setAdapter(mAdapter); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void initData() { |
|
|
|
mtPeripheral = MainActivity.mtPeripheral; |
|
|
|
mMTConnectionHandler = mtPeripheral.mMTConnectionHandler; |
|
|
|
mMtCentralManager = MTCentralManager.getInstance(this); |
|
|
|
|
|
|
|
mMtCentralManager.startScan(); |
|
|
|
mMtCentralManager.setMTCentralManagerListener(new MTCentralManagerListener() { |
|
|
|
@Override |
|
|
|
public void onScanedPeripheral(final List<MTPeripheral> peripherals) { |
|
|
|
Log.e("Peripherals : ", String.valueOf(peripherals.size())); |
|
|
|
mAdapter.setData(peripherals); |
|
|
|
for (MTPeripheral mtPeripheral : peripherals) { |
|
|
|
// get FrameHandler of a device. |
|
|
|
MTFrameHandler mtFrameHandler = mtPeripheral.mMTFrameHandler; |
|
|
|
mac = mtFrameHandler.getMac(); //mac address of device |
|
|
|
name = mtFrameHandler.getName(); // name of device |
|
|
|
battery = mtFrameHandler.getBattery(); //battery |
|
|
|
rssi = mtFrameHandler.getRssi(); //rssi |
|
|
|
txt_device.setText("Device in range. "); |
|
|
|
txt_device.setTextColor(Color.BLUE); |
|
|
|
|
|
|
|
String html1 = "<font color=" + Color.BLACK |
|
|
|
+ ">Mac Address : </font><font color=" |
|
|
|
+ Color.BLACK + ">"+ mac+"</font>"; |
|
|
|
|
|
|
|
txt_mac.setText(Html.fromHtml(html1)); |
|
|
|
|
|
|
|
System.out.println("Value of battery and rssi in MainActivity : " + battery + " " + rssi ); |
|
|
|
|
|
|
|
txt_name.setText("Device Name : "+name); |
|
|
|
txt_battery.setText("Battery Status : "+battery); |
|
|
|
txt_rssi.setText(" Rssi : "+rssi); |
|
|
|
|
|
|
|
|
|
|
|
// all data frames of device(such as:iBeacon,UID,URL...) |
|
|
|
advFrames = mtFrameHandler.getAdvFrames(); |
|
|
|
Log.v("Device Log : ", advFrames.toString()); |
|
|
|
for (MinewFrame minewFrame : advFrames) { |
|
|
|
FrameType frameType = minewFrame.getFrameType(); |
|
|
|
switch (frameType) { |
|
|
|
case FrameiBeacon://iBeacon |
|
|
|
IBeaconFrame iBeaconFrame = (IBeaconFrame) minewFrame; |
|
|
|
Log.v("beaconplus1", iBeaconFrame.getUuid() + " "+ iBeaconFrame.getMajor() + " "+ iBeaconFrame.getMinor()); |
|
|
|
break; |
|
|
|
case FrameUID://uid |
|
|
|
UidFrame uidFrame = (UidFrame) minewFrame; |
|
|
|
Log.v("beaconplus2", uidFrame.getNamespaceId() + uidFrame.getInstanceId()); |
|
|
|
break; |
|
|
|
case FrameAccSensor: |
|
|
|
AccFrame accFrame = (AccFrame) minewFrame;//acc |
|
|
|
xaxis = String.valueOf(accFrame.getXAxis()); |
|
|
|
yaxis = String.valueOf(accFrame.getYAxis()); |
|
|
|
zaxis = String.valueOf(accFrame.getZAxis()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
txt_xaxis.setText("X axis: " + xaxis); |
|
|
|
txt_yaxis.setText("Y axis: " + yaxis); |
|
|
|
txt_zaxis.setText("Z axis: " + zaxis); |
|
|
|
|
|
|
|
if (accFrame.getXAxis() == Double.MIN_VALUE) { |
|
|
|
Log.v("tag","this value is not available."); |
|
|
|
} |
|
|
|
if (accFrame.getYAxis() == Double.MIN_VALUE) { |
|
|
|
Log.v("tag","this value is not available."); |
|
|
|
} |
|
|
|
if (accFrame.getZAxis() == Double.MIN_VALUE) { |
|
|
|
Log.v("tag","this value is not available."); |
|
|
|
} |
|
|
|
Log.v("beaconplus3", String.valueOf(accFrame.getXAxis() + " "+ accFrame.getYAxis() +" "+ accFrame.getZAxis())); |
|
|
|
break; |
|
|
|
case FrameHTSensor: |
|
|
|
HTFrame htFrame = (HTFrame) minewFrame;//ht |
|
|
|
Log.v("beaconplus4", String.valueOf(htFrame.getTemperature() + " "+ htFrame.getHumidity())); |
|
|
|
break; |
|
|
|
case FrameTLM: |
|
|
|
TlmFrame tlmFrame = (TlmFrame) minewFrame;//tlm |
|
|
|
Log.v("beaconplus5", String.valueOf(tlmFrame.getTemperature() + " "+ tlmFrame.getBatteryVol() + " "+ tlmFrame.getSecCount() + " "+ tlmFrame.getAdvCount())); |
|
|
|
break; |
|
|
|
case FrameURL: |
|
|
|
UrlFrame urlFrame = (UrlFrame) minewFrame;//url |
|
|
|
Log.v("beaconplus6", "Link:" + urlFrame.getUrlString() + "Rssi @ 0m:" + urlFrame.getTxPower()); |
|
|
|
break; |
|
|
|
case FrameLightSensor: |
|
|
|
LightFrame lightFrame = (LightFrame) minewFrame;//light |
|
|
|
Log.v("beaconplus7", "battery:" + lightFrame.getBattery() + "%" + lightFrame.getLuxValue()); |
|
|
|
break; |
|
|
|
case FrameForceSensor: |
|
|
|
ForceFrame forceFrame = ((ForceFrame) minewFrame);//force |
|
|
|
Log.v("beaconplus8", "battery:" + forceFrame.getBattery() + "%" + "force:" + forceFrame.getForce() + "gram"); |
|
|
|
break; |
|
|
|
case FramePIRSensor: |
|
|
|
PIRFrame pirFrame = ((PIRFrame) minewFrame);//pir |
|
|
|
Log.v("beaconplus9", "battery:" + pirFrame.getBattery() + "%" + "PIR:"+ pirFrame.getPirData()); |
|
|
|
break; |
|
|
|
case FrameTempSensor://temp |
|
|
|
TemperatureFrame temperatureFrame = (TemperatureFrame) minewFrame; |
|
|
|
Log.v("beaconplus10", "battery:" + temperatureFrame.getBattery() + "%,temperature:" + String.format("%.2f", temperatureFrame.getValue()) + "°C"); |
|
|
|
break; |
|
|
|
case FrameTVOCSensor://tvoc |
|
|
|
TvocFrame tvocFrame = (TvocFrame) minewFrame; |
|
|
|
Log.v("beaconplus11", "battery:" + tvocFrame.getBattery() + " "+ ",TVOC:"+ tvocFrame.getValue() + " "+ "ppb," + "battery:"+ " "+ +tvocFrame.getBattery() + "mV"); |
|
|
|
break; |
|
|
|
case FrameLineBeacon://FrameLineBeacon |
|
|
|
LineBeaconFrame lineBeacon = ((LineBeaconFrame) minewFrame); |
|
|
|
Log.v("beaconplus12", "Hwid:" + lineBeacon.getHwid() |
|
|
|
+" "+ ",Rssi@1m:"+ lineBeacon.getTxPower() |
|
|
|
+" "+ ",authentication:"+lineBeacon.getAuthentication() |
|
|
|
+" "+ ",timesTamp:" + lineBeacon.getTimesTamp()); |
|
|
|
break; |
|
|
|
case FrameTamperProof://TamperProofFrame |
|
|
|
TamperProofFrame tamperProofFrame = ((TamperProofFrame) minewFrame);// |
|
|
|
Log.v("beaconplus13", "battery:" + tamperProofFrame.getBattery()); |
|
|
|
break; |
|
|
|
case FrameDeviceInfo://InfoFrame |
|
|
|
InfoFrame infoFrame = ((InfoFrame) minewFrame);// |
|
|
|
Log.v("beaconplus14", infoFrame.getMajor() +" "+ infoFrame.getMinor() + " "+ infoFrame.getBatteryVoltage()); |
|
|
|
break; |
|
|
|
default: |
|
|
|
Log.v("Device range", "Device not found"); |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean equals(@Nullable Object obj) { |
|
|
|
Log.e("Equals", "equals"); |
|
|
|
return super.equals(obj); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
protected void finalize() throws Throwable { |
|
|
|
Log.e("Finalize", "finalize"); |
|
|
|
super.finalize(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public int hashCode() { |
|
|
|
Log.e("HashCode", "hashCode"); |
|
|
|
return super.hashCode(); |
|
|
|
} |
|
|
|
|
|
|
|
@NonNull |
|
|
|
@Override |
|
|
|
protected Object clone() throws CloneNotSupportedException { |
|
|
|
Log.e("Clone", "clone"); |
|
|
|
return super.clone(); |
|
|
|
} |
|
|
|
|
|
|
|
@NonNull |
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
Log.e("ToString", "toString"); |
|
|
|
return super.toString(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void initListener() { |
|
|
|