Skip to content

Commit db22ea3

Browse files
committed
add line simple beacon :0.8
1 parent dcd2710 commit db22ea3

15 files changed

Lines changed: 398 additions & 19 deletions

File tree

0 Bytes
Binary file not shown.

.idea/encodings.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "com.alfaloop.android.alfabeacon"
88
minSdkVersion 21
99
targetSdkVersion 26
10-
versionCode 7
11-
versionName "0.7"
10+
versionCode 8
11+
versionName "0.8"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313
externalNativeBuild {
1414
cmake {

app/src/main/java/com/alfaloop/android/alfabeacon/adapter/DeviceAdapter.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
7777
@Override
7878
public void onBindViewHolder(MyViewHolder holder, int position) {
7979
final LeBeacon item = mFilterItems.get(position);
80+
boolean correct = false;
8081

8182
if (item.getType() == LeBeacon.LEBEACON_TYPE_AA) {
8283
holder.imvBeaconType.setImageResource(R.drawable.ic_beacon_alfa_aa);
@@ -134,8 +135,30 @@ public void onClick(View v) {
134135
holder.tvIBeaconMajor.setText(String.format("Major • %d", item.getiBeacon().getMajor()));
135136
holder.tvIBeaconMinor.setText(String.format("Minor • %d", item.getiBeacon().getMinor()));
136137
holder.tvIBeaconTx.setText(String.format("Tx • %d dBm", item.getiBeacon().getTxInMeter()));
138+
correct = true;
137139
} else {
138140
holder.vIBeacon.setVisibility(View.GONE);
141+
}
142+
143+
if (item.getLineSimpleBeacon() != null) {
144+
holder.vBeaconContainer.setVisibility(View.VISIBLE);
145+
holder.vBeaconContainer.setOnClickListener(new View.OnClickListener() {
146+
@Override
147+
public void onClick(View v) {
148+
if (itemClickListener != null) {
149+
itemClickListener.onConnectClick(item);
150+
}
151+
}
152+
});
153+
holder.vLSBBeacon.setVisibility(View.VISIBLE);
154+
holder.tvLSBBeaconHwid.setText(String.format("Hwid • %s", item.getLineSimpleBeacon().getHwid()));
155+
holder.tvLSBBeaconDm.setText(String.format("DM • %s", item.getLineSimpleBeacon().getDeviceMessage()));
156+
correct = true;
157+
} else {
158+
holder.vLSBBeacon.setVisibility(View.GONE);
159+
}
160+
161+
if (!correct) {
139162
holder.vBeaconContainer.setVisibility(View.GONE);
140163
}
141164

@@ -162,6 +185,9 @@ class MyViewHolder extends RecyclerView.ViewHolder {
162185
private TextView tvIBeaconMajor;
163186
private TextView tvIBeaconMinor;
164187
private TextView tvIBeaconTx;
188+
private View vLSBBeacon;
189+
private TextView tvLSBBeaconHwid;
190+
private TextView tvLSBBeaconDm;
165191
private View vRSSIContainer;
166192
private TextView tvRssi;
167193
private View vBatteryContainer;
@@ -185,6 +211,12 @@ public MyViewHolder(View itemView) {
185211
tvIBeaconMinor = (TextView) vIBeacon.findViewById(R.id.minor);
186212
tvIBeaconTx = (TextView) vIBeacon.findViewById(R.id.tx);
187213

214+
// LSB View
215+
vLSBBeacon = (View) vBeaconContainer.findViewById(R.id.lsb_item);
216+
// LINE Simple Beacon View
217+
tvLSBBeaconHwid = (TextView) vLSBBeacon.findViewById(R.id.proximity_hwid);
218+
tvLSBBeaconDm = (TextView) vLSBBeacon.findViewById(R.id.proximity_dm);
219+
188220
// Rssi View
189221
vRSSIContainer = (View) itemView.findViewById(R.id.rssi_container);
190222
tvRssi = (TextView) vRSSIContainer.findViewById(R.id.rssi);

app/src/main/java/com/alfaloop/android/alfabeacon/fragment/ConnectedFragment.java

Lines changed: 118 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.alfaloop.android.alfabeacon.utility.UuidUtils;
4848
import com.dd.morphingbutton.MorphingButton;
4949
import com.dd.morphingbutton.impl.IndeterminateProgressButton;
50+
import com.github.aakira.expandablelayout.Utils;
5051
import com.polidea.rxandroidble2.RxBleClient;
5152
import com.polidea.rxandroidble2.RxBleConnection;
5253
import com.polidea.rxandroidble2.RxBleDevice;
@@ -110,6 +111,9 @@ public class ConnectedFragment extends BaseBackFragment implements View.OnClickL
110111
public final static UUID UUID_ALFA_LINESIMPLEBEACON_SERVICE = UUID.fromString("A78D0001-F6C2-09A3-E9F9-128ABCA31297");
111112
public static final UUID UUID_ALFA_LINESIMPLEBEACON_CHARACTER_HWID = UUID.fromString("A78D0002-F6C2-09A3-E9F9-128ABCA31297");
112113
public static final UUID UUID_ALFA_LINESIMPLEBEACON_CHARACTER_DM = UUID.fromString("A78D0003-F6C2-09A3-E9F9-128ABCA31297");
114+
private BluetoothGattService mLSBService;
115+
private BluetoothGattCharacteristic mLSBHwidCharacteristic;
116+
private BluetoothGattCharacteristic mLSBDmCharacteristic;
113117

114118
// RX Android
115119
private RxBleClient rxBleClient;
@@ -137,6 +141,12 @@ public class ConnectedFragment extends BaseBackFragment implements View.OnClickL
137141
private EditText iBeaconMinorEdit;
138142
private EditText iBeaconTxmEdit;
139143
private IndeterminateProgressButton iBeaconMorphingButton;
144+
// GUI components - Line simple beacon
145+
private View LSBView;
146+
private TextView LSBHeaderText;
147+
private EditText LSBHwidEdit;
148+
private EditText LSBDmEdit;
149+
private IndeterminateProgressButton LSBMorphingButton;
140150
// GUI components - Radio
141151
private View radioView;
142152
private TextView radioIntervalTextView;
@@ -149,7 +159,6 @@ public class ConnectedFragment extends BaseBackFragment implements View.OnClickL
149159
private TextView alfa2477sRfatteTextView;
150160
private SeekBar alfa2477sRfatteSeekBar;
151161
private IndeterminateProgressButton alfa2477sMorphingButton;
152-
153162
// Data
154163
private String macAddress;
155164
private String deviceName;
@@ -207,6 +216,7 @@ public void onClick(View v) {
207216
byte[] disconnect_command = new byte[1];
208217
disconnect_command[0] = 0x01;
209218
if (mAlfaRadioConnCharacteristic != null && rxBleConnection != null) {
219+
Log.d(TAG, String.format("AlfaRadioConnCharacteristic != null send disconnect packets"));
210220
rxBleConnection.writeCharacteristic(mAlfaRadioConnCharacteristic, disconnect_command)
211221
.observeOn(AndroidSchedulers.mainThread())
212222
.subscribe(bytes -> {
@@ -215,7 +225,7 @@ public void onClick(View v) {
215225
} else {
216226
if (connectionDisposable != null) {
217227
connectionDisposable.dispose();
218-
}
228+
}
219229
}
220230
}
221231
});
@@ -226,6 +236,7 @@ public void onClick(View v) {
226236

227237
initHeaderView(view);
228238
initAppleBeaconView(view);
239+
initLSBView(view);
229240
initRadioView(view);
230241
initAlfa2477sView(view);
231242
}
@@ -259,6 +270,60 @@ private void updateHeaderRssi(int rssi) {
259270
mHeaderRssi.setText(String.format("Rssi: %d dBm", rssi));
260271
}
261272

273+
private void initLSBView(View view) {
274+
LSBView = (View) view.findViewById(R.id.lsb_edit);
275+
276+
LSBMorphingButton = (IndeterminateProgressButton) LSBView.findViewById(R.id.lsb_save_button);
277+
LSBMorphingButton.setOnClickListener(this);
278+
morphToSquare(LSBMorphingButton, 0);
279+
280+
LSBHeaderText = (TextView) LSBView.findViewById(R.id.lsb_header_text);
281+
LSBHwidEdit = (EditText) LSBView.findViewById(R.id.input_lsb_hwid);
282+
LSBDmEdit = (EditText) LSBView.findViewById(R.id.input_lsb_dm);
283+
284+
LSBHwidEdit.setText("01135373db");
285+
LSBHwidEdit.setOnFocusChangeListener(this);
286+
LSBHwidEdit.addTextChangedListener(new TextWatcher() {
287+
@Override
288+
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
289+
}
290+
@Override
291+
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
292+
}
293+
@Override
294+
public void afterTextChanged(Editable editable) {
295+
/* if (inputValidation(editable)) {
296+
input_validation.setVisibility(View.VISIBLE);
297+
input_validation.setText("You must enter your Age");
298+
} else {
299+
input_validation.setVisibility(View.GONE);
300+
final_input_value = Integer.parseInt(editable.toString());
301+
}*/
302+
}
303+
});
304+
305+
LSBDmEdit.setText("0102030405060708090A0B0C0D");
306+
LSBDmEdit.setOnFocusChangeListener(this);
307+
LSBDmEdit.addTextChangedListener(new TextWatcher() {
308+
@Override
309+
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
310+
}
311+
@Override
312+
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
313+
}
314+
@Override
315+
public void afterTextChanged(Editable editable) {
316+
/* if (inputValidation(editable)) {
317+
input_validation.setVisibility(View.VISIBLE);
318+
input_validation.setText("You must enter your Age");
319+
} else {
320+
input_validation.setVisibility(View.GONE);
321+
final_input_value = Integer.parseInt(editable.toString());
322+
}*/
323+
}
324+
});
325+
}
326+
262327
private void initAppleBeaconView(View view) {
263328
iBeaconView = (View) view.findViewById(R.id.ibeacon_edit);
264329

@@ -293,6 +358,7 @@ public void afterTextChanged(Editable editable) {
293358
}
294359
});
295360
iBeaconMajorEdit.setText(String.format("1234"));
361+
iBeaconMajorEdit.setOnFocusChangeListener(this);
296362
iBeaconMajorEdit.addTextChangedListener(new TextWatcher() {
297363
@Override
298364
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
@@ -312,8 +378,9 @@ public void afterTextChanged(Editable editable) {
312378
}*/
313379
}
314380
});
315-
iBeaconMajorEdit.setOnFocusChangeListener(this);
381+
316382
iBeaconMinorEdit.setText(String.format("8"));
383+
iBeaconMinorEdit.setOnFocusChangeListener(this);
317384
iBeaconMinorEdit.addTextChangedListener(new TextWatcher() {
318385
@Override
319386
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
@@ -333,7 +400,6 @@ public void afterTextChanged(Editable editable) {
333400
}*/
334401
}
335402
});
336-
iBeaconMinorEdit.setOnFocusChangeListener(this);
337403
iBeaconTxmEdit.setText(String.format("-58"));
338404
iBeaconTxmEdit.setOnFocusChangeListener(this);
339405
}
@@ -493,6 +559,8 @@ public void onFocusChange(View v, boolean hasFocus) {
493559
public void onClick(View v) {
494560
if (v.getId() == R.id.ibeacon_save_button) {
495561
morphingBeaconButtonClicked();
562+
} else if(v.getId() == R.id.lsb_save_button) {
563+
morphingLSBButtonClicked();
496564
} else if(v.getId() == R.id.radio_save_button) {
497565
morphingRadioButtonClicked();
498566
} else if(v.getId() == R.id.alfa2477s_save_button) {
@@ -547,6 +615,28 @@ private void morphingBeaconButtonClicked( ) {
547615
}, this::onConnectionFailure);
548616
}
549617

618+
private void morphingLSBButtonClicked() {
619+
morphToProcess(LSBMorphingButton);
620+
621+
byte[] hwidArray = ParserUtils.hexStringToByteArray(LSBHwidEdit.getText().toString());
622+
byte[] dmArray = ParserUtils.hexStringToByteArray(LSBDmEdit.getText().toString());
623+
624+
List<Single<byte[]>> singles = new ArrayList<>();
625+
singles.add(rxBleConnection.writeCharacteristic(mLSBHwidCharacteristic, hwidArray));
626+
singles.add(rxBleConnection.writeCharacteristic(mLSBDmCharacteristic, dmArray));
627+
mergeProcessCounter = 0;
628+
Single.merge(singles)
629+
.observeOn(AndroidSchedulers.mainThread())
630+
.subscribe(bytes -> {
631+
Log.d(TAG, String.format("update radio profile Success"));
632+
mergeProcessCounter++;
633+
if (mergeProcessCounter == singles.size()) {
634+
mergeProcessCounter = 0;
635+
morphToCompleted(LSBMorphingButton);
636+
}
637+
}, this::onConnectionFailure);
638+
}
639+
550640
private void morphingRadioButtonClicked() {
551641

552642
morphToProcess(radioMorphingButton);
@@ -704,6 +794,29 @@ private void onConnectionReceived(RxBleConnection connection) {
704794
}
705795
}
706796
alfa2477sView.setVisibility(View.VISIBLE);
797+
} else if (service.getUuid().equals(UUID_ALFA_LINESIMPLEBEACON_SERVICE)) {
798+
mLSBService = service;
799+
for (BluetoothGattCharacteristic character: service.getCharacteristics()) {
800+
Log.i(TAG, String.format("character: %s", character.getUuid().toString()));
801+
if (character.getUuid().equals(UUID_ALFA_LINESIMPLEBEACON_CHARACTER_HWID)) {
802+
Log.i(TAG, String.format("found LSB hwid characteristic"));
803+
mLSBHwidCharacteristic = character;
804+
rxBleConnection.readCharacteristic(mLSBHwidCharacteristic)
805+
.observeOn(AndroidSchedulers.mainThread())
806+
.subscribe( value -> {
807+
LSBHwidEdit.setText(ParserUtils.bytesToHex(value));
808+
}, this::onConnectionFailure);
809+
} else if (character.getUuid().equals(UUID_ALFA_LINESIMPLEBEACON_CHARACTER_DM)) {
810+
Log.i(TAG, String.format("found LSB Device message characteristic"));
811+
mLSBDmCharacteristic = character;
812+
rxBleConnection.readCharacteristic(mLSBDmCharacteristic)
813+
.observeOn(AndroidSchedulers.mainThread())
814+
.subscribe( value -> {
815+
LSBDmEdit.setText(ParserUtils.bytesToHex(value));
816+
}, this::onConnectionFailure);
817+
}
818+
}
819+
LSBView.setVisibility(View.VISIBLE);
707820
}
708821
}
709822
if (mAlfaRadioService == null) {
@@ -752,6 +865,7 @@ public void onClick(DialogInterface dialog, int which) {
752865
private void onConnectionDispose() {
753866
Log.d(TAG, "onConnectionDispose");
754867
connectionDisposable = null;
868+
mAlfaRadioService = null;
755869
pop();
756870
}
757871

app/src/main/java/com/alfaloop/android/alfabeacon/fragment/ScannerFragment.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.alfaloop.android.alfabeacon.base.BaseMainFragment;
5151
import com.alfaloop.android.alfabeacon.base.RecyclerViewEmptySupport;
5252
import com.alfaloop.android.alfabeacon.models.AppleBeacon;
53+
import com.alfaloop.android.alfabeacon.models.LINESimpleBeacon;
5354
import com.alfaloop.android.alfabeacon.models.LeBeacon;
5455
import com.alfaloop.android.alfabeacon.utility.ParserUtils;
5556
import com.alfaloop.android.alfabeacon.utility.ScanFilterUtils;
@@ -88,6 +89,7 @@ public class ScannerFragment extends BaseMainFragment implements View.OnFocusCha
8889
private RxBleClient rxBleClient;
8990
private HashMap<String, LeBeacon> mLeBeaconHashMap = new HashMap<String, LeBeacon>();
9091
private UUID ALFABEACON_UUID = UUID.fromString("0000a55a-0000-1000-8000-00805f9b34fb");
92+
9193
private Rx2Timer mCountTimer = null;
9294

9395
private Disposable scanSubscription;
@@ -365,6 +367,8 @@ private boolean stopScan(){
365367

366368
private void scanResultParser(ScanResult result) {
367369
boolean hasUuid = false;
370+
byte[] lsbHwid = new byte[5];
371+
byte[] lsbDm = new byte[13];
368372
int type = 0;
369373
int battery = 0;
370374
ScanRecord record = result.getScanRecord();
@@ -394,18 +398,26 @@ private void scanResultParser(ScanResult result) {
394398
deviceName, result.getBleDevice().getMacAddress(),
395399
result.getRssi(), battery, new Date());
396400

397-
final Pair<Boolean, AppleBeacon> isAppleBeacon = ScanFilterUtils.isBeaconPattern(result);
401+
final Pair<Boolean, AppleBeacon> isAppleBeacon = ScanFilterUtils.isAppleBeaconPattern(result);
398402
if (isAppleBeacon.first) {
399403
beacon.setiBeacon(isAppleBeacon.second);
400404
}
405+
final Pair<Boolean, LINESimpleBeacon> isLineSimpleBeacon = ScanFilterUtils.isLineSimpleBeaconPattern(result);
406+
if (isLineSimpleBeacon.first) {
407+
beacon.setLineSimpleBeacon(isLineSimpleBeacon.second);
408+
}
401409
mLeBeaconHashMap.put(result.getBleDevice().getMacAddress(), beacon);
402410
} else {
403411
if (previous.getiBeacon() == null) {
404412
// parser for the iBeacon
405-
final Pair<Boolean, AppleBeacon> isAppleBeacon = ScanFilterUtils.isBeaconPattern(result);
413+
final Pair<Boolean, AppleBeacon> isAppleBeacon = ScanFilterUtils.isAppleBeaconPattern(result);
406414
if (isAppleBeacon.first) {
407415
previous.setiBeacon(isAppleBeacon.second);
408416
}
417+
final Pair<Boolean, LINESimpleBeacon> isLineSimpleBeacon = ScanFilterUtils.isLineSimpleBeaconPattern(result);
418+
if (isLineSimpleBeacon.first) {
419+
previous.setLineSimpleBeacon(isLineSimpleBeacon.second);
420+
}
409421
}
410422
previous.setRssi(result.getRssi());
411423
previous.setDatetime(new Date());

0 commit comments

Comments
 (0)