配网长度提醒

This commit is contained in:
jia 2024-10-16 22:08:28 +08:00
parent 59625c2e9f
commit a65d5e8ac5
7 changed files with 88 additions and 72 deletions

View File

@ -26,5 +26,5 @@ android.enableJetifier=true
android.useAndroidX=true android.useAndroidX=true
android.useDeprecatedNdk=true android.useDeprecatedNdk=true
versionCode=56 versionCode=57
versionName=4.11.16 versionName=4.11.17

View File

@ -1,15 +1,12 @@
package com.ifish.activity; package com.ifish.activity;
import android.app.Activity;
import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.View;
import com.ifish.baseclass.BaseActivity; import com.ifish.baseclass.BaseActivity;
import com.ifish.tcp.BackFunctionCode7_11; import com.ifish.tcp.BackFunctionCode7_11;
import com.ifish.tcp.Context;
import com.ifish.tcp.ModelCodec; import com.ifish.tcp.ModelCodec;
import com.ifish.tcp.OrderModel; import com.ifish.tcp.OrderModel;
import com.ifish.tcp.ResetDeviceModel; import com.ifish.tcp.ResetDeviceModel;

View File

@ -614,7 +614,7 @@ public class NewBindDeviceActivity extends AppCompatActivity {
dataByte[i] = data[i]; dataByte[i] = data[i];
} }
Object object = ModelCodec.deCode(dataByte); Object object = ModelCodec.deCode(dataByte,Commons.IoBuffer);
if (object!=null && object instanceof BackFunctionCode7_11){ if (object!=null && object instanceof BackFunctionCode7_11){
BackFunctionCode7_11 model = (BackFunctionCode7_11) object; BackFunctionCode7_11 model = (BackFunctionCode7_11) object;
String status = ByteUtil.toHex(model.getStatus()); String status = ByteUtil.toHex(model.getStatus());
@ -644,7 +644,7 @@ public class NewBindDeviceActivity extends AppCompatActivity {
String pwd = tvWifiPwd.getText().toString(); String pwd = tvWifiPwd.getText().toString();
OrderDeviceConnectModel model = OrderModel.OrderDeviceConnectModel(ssid, pwd,true);//设置正式环境域名 OrderDeviceConnectModel model = OrderModel.OrderDeviceConnectModel(ssid, pwd,true);//设置正式环境域名
byte[] data = ModelCodec.enCode(model); byte[] data = ModelCodec.enCode(model, Commons.IoBuffer);
BleManager.getInstance().write(currentDevice, SERVICE_UUID, WRITE_UUID, data,false, new BleWriteCallback() { BleManager.getInstance().write(currentDevice, SERVICE_UUID, WRITE_UUID, data,false, new BleWriteCallback() {
@Override @Override
public void onWriteSuccess(int current, int total, byte[] justWrite) { public void onWriteSuccess(int current, int total, byte[] justWrite) {

View File

@ -1,51 +1,51 @@
package com.ifish.tcp; //package com.ifish.tcp;
//
import com.ifish.utils.Commons; //import com.ifish.utils.Commons;
//
import java.nio.charset.Charset; //import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder; //import java.nio.charset.CharsetDecoder;
//
import org.apache.mina.core.buffer.IoBuffer; //import org.apache.mina.core.buffer.IoBuffer;
//
public class Context { //public class Context {
private final CharsetDecoder decoder; // private final CharsetDecoder decoder;
private IoBuffer buf; // private IoBuffer buf;
private int matchCount = 0; // private int matchCount = 0;
private int overflowPosition = 0; // private int overflowPosition = 0;
//
public Context(Charset charset) { // public Context(Charset charset) {
decoder = charset.newDecoder(); // decoder = charset.newDecoder();
buf = IoBuffer.allocate(Commons.IoBuffer).setAutoExpand(true); // buf = IoBuffer.allocate(Commons.IoBuffer).setAutoExpand(true);
//buf.order(ByteOrder.LITTLE_ENDIAN); // //buf.order(ByteOrder.LITTLE_ENDIAN);
} // }
//
public CharsetDecoder getDecoder() { // public CharsetDecoder getDecoder() {
return decoder; // return decoder;
} // }
//
public IoBuffer getBuffer() { // public IoBuffer getBuffer() {
return buf; // return buf;
} // }
//
public int getOverflowPosition() { // public int getOverflowPosition() {
return overflowPosition; // return overflowPosition;
} // }
//
public int getMatchCount() { // public int getMatchCount() {
return matchCount; // return matchCount;
} // }
//
public void setMatchCount(int matchCount) { // public void setMatchCount(int matchCount) {
this.matchCount = matchCount; // this.matchCount = matchCount;
} // }
//
public void reset() { // public void reset() {
overflowPosition = 0; // overflowPosition = 0;
matchCount = 0; // matchCount = 0;
decoder.reset(); // decoder.reset();
} // }
//
public void append(IoBuffer in) { // public void append(IoBuffer in) {
getBuffer().put(in); // getBuffer().put(in);
} // }
} //}

View File

@ -23,8 +23,12 @@ public class ModelCodec {
* @param obj * @param obj
* @return * @return
*/ */
public static byte[] enCode(Object obj) { public static byte[] enCode(Object obj){
IoBuffer buffer = IoBuffer.allocate(Commons.IoBuffer).setAutoExpand(true); return enCode(obj,100);
}
public static byte[] enCode(Object obj,int len) {
IoBuffer buffer = IoBuffer.allocate(len).setAutoExpand(true);
if(obj instanceof BackInfoSix_4F_XunHuanTimes){ //设置循环模式时间 if(obj instanceof BackInfoSix_4F_XunHuanTimes){ //设置循环模式时间
BackInfoSix_4F_XunHuanTimes model = (BackInfoSix_4F_XunHuanTimes) obj; BackInfoSix_4F_XunHuanTimes model = (BackInfoSix_4F_XunHuanTimes) obj;
@ -426,10 +430,13 @@ public class ModelCodec {
* 把字节数组转成对象 * 把字节数组转成对象
*/ */
public static Object deCode(byte[] bys) { public static Object deCode(byte[] bys) {
return deCode(bys,100);
}
public static Object deCode(byte[] bys,int len) {
int Check_code = getCheck_code(bys); int Check_code = getCheck_code(bys);
int length = bys.length; int length = bys.length;
Log.i("---------start", Check_code + "---" + ByteUtil.bytesToHexString(bys)); Log.i("---------start", Check_code + "---" + ByteUtil.bytesToHexString(bys));
IoBuffer buf = ByteUtil.byteToIoBuffer(bys, length); IoBuffer buf = ByteUtil.byteToIoBuffer(bys, length,len);
if (Check_code == 21) { if (Check_code == 21) {
return decodexuanduo_set(buf); return decodexuanduo_set(buf);
} else if (Check_code == 22) { } else if (Check_code == 22) {

View File

@ -15,15 +15,18 @@ import java.io.Serializable;
* @Description: 设备设置tcp域名命令39字节(17字节+22字节) * @Description: 设备设置tcp域名命令39字节(17字节+22字节)
*/ */
public class OrderDeviceConnectModel extends HeadModel implements Serializable { public class OrderDeviceConnectModel extends HeadModel implements Serializable {
private boolean isNew = false;
public OrderDeviceConnectModel(boolean x){
this.isNew = x;
}
//路由器wifi名 //路由器wifi名
private byte[] ssid_name = new byte[ isNew ?Commons.SSID_LENGTH:20]; private byte[] ssid_name;
//路由器wifi密码 //路由器wifi密码
private byte[] ssid_password = new byte[isNew?Commons.SSID_LENGTH:20]; private byte[] ssid_password;
public OrderDeviceConnectModel(boolean isNew){
ssid_name = new byte[ isNew ?Commons.SSID_LENGTH:20];
ssid_password = new byte[isNew?Commons.SSID_LENGTH:20];
}
// private byte[] ssid_name = new byte[ isNew ?Commons.SSID_LENGTH:20];
// //路由器wifi密码
// private byte[]
public byte[] getSsid_name() { public byte[] getSsid_name() {
return ssid_name; return ssid_name;

View File

@ -71,11 +71,20 @@ public class ByteUtil{
* 将byte[]转换成IoBuffer * 将byte[]转换成IoBuffer
* @param str * @param str
*/ */
public static IoBuffer byteToIoBuffer(byte [] bt,int length){ public static IoBuffer byteToIoBuffer(byte [] bt,int length){
IoBuffer ioBuffer = IoBuffer.allocate(Commons.IoBuffer).setAutoExpand(true); // IoBuffer ioBuffer = IoBuffer.allocate(Commons.IoBuffer).setAutoExpand(true);
// //ioBuffer.order(ByteOrder.LITTLE_ENDIAN);// 修改此缓冲区的字节顺大端模式
// ioBuffer.put(bt, 0, length);
// ioBuffer.flip();
// return ioBuffer;
return byteToIoBuffer(bt,length,100);
}
public static IoBuffer byteToIoBuffer(byte [] bt,int length,int xx){
IoBuffer ioBuffer = IoBuffer.allocate(xx).setAutoExpand(true);
//ioBuffer.order(ByteOrder.LITTLE_ENDIAN);// 修改此缓冲区的字节顺大端模式 //ioBuffer.order(ByteOrder.LITTLE_ENDIAN);// 修改此缓冲区的字节顺大端模式
ioBuffer.put(bt, 0, length); ioBuffer.put(bt, 0, length);
ioBuffer.flip(); ioBuffer.flip();
return ioBuffer; return ioBuffer;
} }