Commit 7b0ef205 by chengchong

qweq

parent bc25d7a6
package com.example.blu.toys.activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
......@@ -38,7 +39,7 @@ public class SearchingActivity extends BaseActivity {
@RequiresApi(api = Build.VERSION_CODES.N)
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
@Subscribe(threadMode = ThreadMode.MAIN)
public void GoDeviceListPage(List<BleDevice> bleDevices) {
goActivity(SelectDeviceActivity.class);
}
......
......@@ -38,35 +38,31 @@ public class SelectDeviceActivity extends BaseActivity {
@Override
public void init(Bundle savedInstanceState) {
EventBus.getDefault().register(this);
}
@Override
public void initData() {
if (bleDevices == null) {
bleDevices = new ArrayList<>();
}
mRecyclerView.setLayoutManager(getLinearLayout());
bleDeviceAdapter = new BleDeviceAdapter(R.layout.ble_devices_item, bleDevices);
mRecyclerView.setAdapter(bleDeviceAdapter);
}
@Override
public void initData() {
bleDeviceAdapter.setOnItemClickListener((adapter, view, position) -> {
BleDevice bleDevice = (BleDevice) adapter.getItem(position);
BlePlay.getInstance().connectedBleDevice(bleDevice);
});
showBleDevices();
}
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
public void showBleDevices(List<BleDevice> bles) {
public void showBleDevices() {
List<BleDevice> bles = BlePlay.getInstance().getScanResultList();
if (CollectionUtils.isEmpty(bles)) {
return;
}
if (bleDevices == null) {
bleDevices = new ArrayList<>();
}
bleDevices.clear();
for (int i = 0; i < bles.size(); i++) {
BleDevice bleDevice = bles.get(i);
String deviceName = bleDevice.getName();
......
......@@ -47,6 +47,15 @@ public class BlePlay {
private SpUtils mSpUtils;
public List<BleDevice> getScanResultList() {
return scanResultList;
}
public void setScanResultList(List<BleDevice> scanResultList) {
this.scanResultList = scanResultList;
}
private List<BleDevice> scanResultList;
public static BlePlay getInstance() {
if (instance == null) {
......@@ -99,7 +108,8 @@ public class BlePlay {
@Override
public void onScanFinished(List<BleDevice> scanResultList) {
LogUtils.e("扫描介素获取设备列表");
EventBus.getDefault().postSticky(scanResultList);
setScanResultList(scanResultList);
EventBus.getDefault().post(scanResultList);
}
});
}
......
......@@ -5,142 +5,155 @@ import java.text.SimpleDateFormat;
import java.util.Date;
public class TrafficLightBean {
/**
* 固定头 1字节
*/
private byte begin=0x24;
/**
* 长度 1字节
*/
private byte length=0x11;
/**
* 协议编号 01:关机协议 02:暂停于继续协议 1字节
*/
private byte cmd;
/**
* 手机时间 yyMMddHHssmm 6个字节
*/
private byte[] phoneTime;
/**
* 暂停继续 0:暂停 1:继续 1字节
*/
private byte suspendAndContinue;
/**
* 剩余时间(小端) 秒为单位 2字节
*/
private byte[] timeRemaining;
/**
* 亮度调节 0-100 1字节
*/
private byte brightness;
/**
* 开机声音编号 1-20 1字节
*/
private byte openSoundNo;
/**
* 关机声音编号 1-20 1字节
*/
private byte closeSoundNo;
/**
* 红绿灯变更方式 0: 由绿变红 1:由红变黄 1字节
*/
private byte trafficLightUpdateSet;
/**
* 警报开关 0:关 1:开 1字节
*/
private byte alarm;
private byte key;
/**
*
* @param protocolNo 协议编号
* @param suspendAndContinue 暂停或者继续
* @param timeRemaining 剩余时间 毫秒
* @param brightness 亮度值 0-100 默认 50
* @param openSoundNo 开机声音编号 默认 1
* @param closeSoundNo 关机声音编号 默认 10
* @param trafficLightUpdateSet 红绿灯变更方式 默认 1
* @param alarm 报警状态 默认 0
*/
public TrafficLightBean(Integer protocolNo,Integer suspendAndContinue,Integer timeRemaining,Integer brightness,Integer openSoundNo,Integer closeSoundNo,Integer trafficLightUpdateSet,Integer alarm){
this.cmd= BitOperator.integerTo1Byte(protocolNo);
this.suspendAndContinue=BitOperator.integerTo1Byte(suspendAndContinue);
this.timeRemaining=BitOperator.integerTo2Bytes(timeRemaining);
this.brightness=BitOperator.integerTo1Byte(brightness);
this.openSoundNo=BitOperator.integerTo1Byte(openSoundNo);
this.closeSoundNo=BitOperator.integerTo1Byte(closeSoundNo);
this.trafficLightUpdateSet=BitOperator.integerTo1Byte(trafficLightUpdateSet);
this.alarm=BitOperator.integerTo1Byte(alarm);
SimpleDateFormat format= new SimpleDateFormat("yyMMddHHmmss");
String phoneTime= format.format(new Date());
this.phoneTime= BCD8421Operater.string2Bcd(phoneTime);
String yy= phoneTime.substring(0,2);
String MM= phoneTime.substring(2,4);
String dd= phoneTime.substring(4,6);
String HH= phoneTime.substring(6,8);
String mm= phoneTime.substring(8,10);
String ss= phoneTime.substring(10,12);
Integer bo1=BCD8421Operater.string2Bcd(yy)[0]+BCD8421Operater.string2Bcd(HH)[0];
Integer bo2=BCD8421Operater.string2Bcd(MM)[0]^BCD8421Operater.string2Bcd(mm)[0];
Integer bo3=BCD8421Operater.string2Bcd(dd)[0]+BCD8421Operater.string2Bcd(ss)[0];
Integer key=(bo1^bo2)+bo3;
this.key=BitOperator.integerTo1Byte(key);
System.out.println("时间:"+phoneTime);
System.out.println("key 10进制:"+key);
System.out.println("key byte:"+this.key);
}
public byte[] toByte(){
//数据要加密的
byte[] resData=new byte[17];
resData[0]=this.begin;
resData[1]=this.length;
resData[2]=BitOperator.integerTo1Byte(this.cmd+this.key);
resData[3]=this.phoneTime[0];//1 不需要加密
resData[4]=this.phoneTime[1];//2 不需要加密
resData[5]=this.phoneTime[2];//3 不需要加密
resData[6]=this.phoneTime[3];//4 不需要加密
resData[7]=this.phoneTime[4];//5 不需要急吗
resData[8]=this.phoneTime[5];//6 不需要加密
resData[9]=BitOperator.integerTo1Byte(this.suspendAndContinue+this.key);
resData[10]=BitOperator.integerTo1Byte(this.timeRemaining[0]+this.key);
resData[11]=BitOperator.integerTo1Byte(this.timeRemaining[1]+this.key);
resData[12]=BitOperator.integerTo1Byte(this.brightness+this.key);
resData[13]=BitOperator.integerTo1Byte(this.openSoundNo+this.key);
resData[14]=BitOperator.integerTo1Byte(this.closeSoundNo+this.key);
resData[15]=BitOperator.integerTo1Byte(this.trafficLightUpdateSet+this.key);
resData[16]=BitOperator.integerTo1Byte(this.alarm+this.key);
return resData;
}
public static void main(String[] args) {
TrafficLightBean trafficLightBean=new TrafficLightBean(2,0,
300,100,10,20,01,01);
System.out.println(HexStringUtils.toHexString(trafficLightBean.toByte()));
// System.out.printf("00000000");
}
/**
* 固定头 1字节
*/
private byte begin=0x24;
/**
* 长度 1字节
*/
private byte length=0x11;
/**
* 协议编号 01:关机协议 02:暂停于继续协议 1字节
*/
private byte cmd;
/**
* 手机时间 yyMMddHHssmm 6个字节
*/
private byte[] phoneTime;
/**
* 暂停继续 0:暂停 1:继续 1字节
*/
private byte suspendAndContinue;
/**
* 剩余时间(小端) 秒为单位 2字节
*/
private byte[] timeRemaining;
/**
* 亮度调节 0-100 1字节
*/
private byte brightness;
/**
* 开机声音编号 1-20 1字节
*/
private byte openSoundNo;
/**
* 关机声音编号 1-20 1字节
*/
private byte closeSoundNo;
/**
* 红绿灯变更方式 0: 由绿变红 1:由红变黄 1字节
*/
private byte trafficLightUpdateSet;
/**
* 警报开关 0:关 1:开 1字节
*/
private byte alarm;
private byte key;
/**
*
* @param protocolNo 协议编号
* @param suspendAndContinue 暂停或者继续
* @param timeRemaining 剩余时间 毫秒
* @param brightness 亮度值 0-100 默认 50
* @param openSoundNo 开机声音编号 默认 1
* @param closeSoundNo 关机声音编号 默认 10
* @param trafficLightUpdateSet 红绿灯变更方式 默认 1
* @param alarm 报警状态 默认 0
*/
public TrafficLightBean(Integer protocolNo,Integer suspendAndContinue,Integer timeRemaining,Integer brightness,Integer openSoundNo,Integer closeSoundNo,Integer trafficLightUpdateSet,Integer alarm){
this.cmd= BitOperator.integerTo1Byte(protocolNo);
this.suspendAndContinue=BitOperator.integerTo1Byte(suspendAndContinue);
System.out.println("传入的剩余时间:"+timeRemaining);
this.timeRemaining=toLH(timeRemaining); //BitOperator.integerTo2Bytes();
this.brightness=BitOperator.integerTo1Byte(brightness);
this.openSoundNo=BitOperator.integerTo1Byte(openSoundNo);
this.closeSoundNo=BitOperator.integerTo1Byte(closeSoundNo);
this.trafficLightUpdateSet=BitOperator.integerTo1Byte(trafficLightUpdateSet);
this.alarm=BitOperator.integerTo1Byte(alarm);
SimpleDateFormat format= new SimpleDateFormat("yyMMddHHmmss");
String phoneTime= format.format(new Date());
this.phoneTime= BCD8421Operater.string2Bcd(phoneTime);
String yy= phoneTime.substring(0,2);
String MM= phoneTime.substring(2,4);
String dd= phoneTime.substring(4,6);
String HH= phoneTime.substring(6,8);
String mm= phoneTime.substring(8,10);
String ss= phoneTime.substring(10,12);
Integer bo1=BCD8421Operater.string2Bcd(yy)[0]+BCD8421Operater.string2Bcd(HH)[0];
Integer bo2=BCD8421Operater.string2Bcd(MM)[0]^BCD8421Operater.string2Bcd(mm)[0];
Integer bo3=BCD8421Operater.string2Bcd(dd)[0]+BCD8421Operater.string2Bcd(ss)[0];
Integer key=(bo1^bo2)+bo3;
this.key=BitOperator.integerTo1Byte(key);
System.out.println("时间:"+phoneTime);
System.out.println("key 10进制:"+key);
System.out.println("key byte:"+this.key);
}
/**
* int 转换小端
* @param n
* @return
*/
public static byte[] toLH(int n) {
byte[] b = new byte[2];
b[0] = (byte) (n & 0xff);
b[1] = (byte) (n >> 8 & 0xff);
return b;
}
public byte[] toByte(){
//数据要加密的
byte[] resData=new byte[17];
resData[0]=this.begin;
resData[1]=this.length;
resData[2]=BitOperator.integerTo1Byte(this.cmd+this.key);
resData[3]=this.phoneTime[0];//1 不需要加密
resData[4]=this.phoneTime[1];//2 不需要加密
resData[5]=this.phoneTime[2];//3 不需要加密
resData[6]=this.phoneTime[3];//4 不需要加密
resData[7]=this.phoneTime[4];//5 不需要急吗
resData[8]=this.phoneTime[5];//6 不需要加密
resData[9]=BitOperator.integerTo1Byte(this.suspendAndContinue+this.key);
resData[10]=BitOperator.integerTo1Byte(this.timeRemaining[0]+this.key);
resData[11]=BitOperator.integerTo1Byte(this.timeRemaining[1]+this.key);
resData[12]=BitOperator.integerTo1Byte(this.brightness+this.key);
resData[13]=BitOperator.integerTo1Byte(this.openSoundNo+this.key);
resData[14]=BitOperator.integerTo1Byte(this.closeSoundNo+this.key);
resData[15]=BitOperator.integerTo1Byte(this.trafficLightUpdateSet+this.key);
resData[16]=BitOperator.integerTo1Byte(this.alarm+this.key);
return resData;
}
public static void main(String[] args) {
TrafficLightBean trafficLightBean=new TrafficLightBean(2,0,
300,100,10,20,01,01);
System.out.println(HexStringUtils.toHexString(trafficLightBean.toByte()));
// System.out.printf("00000000");
}
}
\ No newline at end of file
package com.example.blu.toys.utils;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
......@@ -158,6 +160,16 @@ public class LocalDateUtils {
return format(LocalTime.now(), TIME_PATTERN);
}
public static Date getDateTime(String time) {
SimpleDateFormat sdf = new SimpleDateFormat(TIME_PATTERN);//根据自己情况
try {
return sdf.parse(time);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
/**
* 获取当前星期字符串.
*
......@@ -623,9 +635,6 @@ public class LocalDateUtils {
}
public static void main(String[] args) {
System.out.println(getLocalDateTimeStr());
System.out.println(getLocalDateStr());
......@@ -708,9 +717,9 @@ public class LocalDateUtils {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date()); //放入Date类型数据
calendar.get(Calendar.HOUR); //时(12小时制)
calendar.get(Calendar.MINUTE); //分
calendar.setTime(new Date()); //放入Date类型数据
calendar.get(Calendar.HOUR); //时(12小时制)
calendar.get(Calendar.MINUTE); //分
calendar.get(Calendar.SECOND);
System.out.println(calendar.get(Calendar.HOUR) + "h" + calendar.get(Calendar.MINUTE) + "m" + calendar.get(Calendar.SECOND) + "s");
......
......@@ -80,8 +80,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_75"
android:background="@drawable/black_thumb"
>
android:background="@drawable/black_thumb">
<LinearLayout
android:layout_width="match_parent"
......@@ -132,12 +131,12 @@
android:layout_gravity="center_vertical" />
<com.example.blu.toys.view.WheelView
android:id="@+id/wheel_am_pm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp" />
<!-- <com.example.blu.toys.view.WheelView-->
<!-- android:id="@+id/wheel_am_pm"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- android:layout_marginLeft="20dp" />-->
</LinearLayout>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment