4747import com .alfaloop .android .alfabeacon .utility .UuidUtils ;
4848import com .dd .morphingbutton .MorphingButton ;
4949import com .dd .morphingbutton .impl .IndeterminateProgressButton ;
50+ import com .github .aakira .expandablelayout .Utils ;
5051import com .polidea .rxandroidble2 .RxBleClient ;
5152import com .polidea .rxandroidble2 .RxBleConnection ;
5253import 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
0 commit comments