New file |
| | |
| | | package com.dayu.recharge.activity; |
| | | |
| | | import android.os.Bundle; |
| | | import android.text.TextUtils; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | |
| | | import com.dayu.recharge.databinding.ActivityPasswordCardBinding; |
| | | import com.dayu.recharge.dbBean.PassWordCardBean; |
| | | import com.dayu.recharge.dbBean.PowerBean; |
| | | import com.dayu.recharge.utils.TipUtil; |
| | | |
| | | /** |
| | | * author: zuo |
| | | * Date: 2024-03-01 |
| | | * Time: 16:21 |
| | | * 备注:密码卡设置界面 |
| | | */ |
| | | public class PasswordCardActivity extends BaseActivity { |
| | | |
| | | ActivityPasswordCardBinding binding; |
| | | |
| | | PassWordCardBean cardBean; |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | binding = ActivityPasswordCardBinding.inflate(LayoutInflater.from(this)); |
| | | setContentView(binding.getRoot()); |
| | | } |
| | | |
| | | |
| | | private void initData() { |
| | | PassWordCardBean powerBean = baseDao.passWordCardDao().findFirst(); |
| | | if (powerBean != null) { |
| | | this.cardBean = powerBean; |
| | | binding.villageOldNumber.setText(powerBean.getPassWord()); |
| | | } |
| | | } |
| | | |
| | | private void initView() { |
| | | binding.villageOk.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | String data = binding.villageNewNum.getText().toString(); |
| | | if (!TextUtils.isEmpty(data)) { |
| | | if (data.length()==12){ |
| | | cardBean.setPassWord(data); |
| | | baseDao.passWordCardDao().insert(cardBean); |
| | | TipUtil.show("保存成功"); |
| | | initData(); |
| | | }else { |
| | | TipUtil.show("请输入正确的12位字符的16进制卡密码"); |
| | | } |
| | | |
| | | } else { |
| | | TipUtil.show("请输入要设置的卡密码"); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | package com.dayu.recharge.card; |
| | | |
| | | import com.dayu.recharge.tools.HexUtil; |
| | | import com.dayu.recharge.utils.MyCommon; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * author: zuo |
| | |
| | | public class ElectricPriceCard implements Serializable { |
| | | public String cardType = MyCommon.ELECTRIC_PRICE; |
| | | |
| | | public String cardData = "A0B1C289";//1-4下标固定值 |
| | | |
| | | public Float electricPrice;// 电量单价(低)单位是元,3位小数点 |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | public byte[] toByte() { |
| | | ElectricPriceCard.Zero zero = new ElectricPriceCard.Zero(); |
| | | return zero.toByte(); |
| | | } |
| | | |
| | | |
| | | |
| | | public static ElectricPriceCard getBean(List<byte[]> data){ |
| | | ElectricPriceCard regionCard=new ElectricPriceCard(); |
| | | byte[] zero=data.get(0); |
| | | regionCard.cardType= HexUtil.byteToHex(zero[0]); |
| | | |
| | | byte[] cardDataByte = new byte[4]; |
| | | System.arraycopy(zero, 1, cardDataByte, 0, cardDataByte.length); |
| | | regionCard.cardData = HexUtil.bytesToHex(cardDataByte); |
| | | |
| | | |
| | | byte[] electricPriceByte = new byte[4]; |
| | | System.arraycopy(zero, 5, electricPriceByte, 0, electricPriceByte.length); |
| | | regionCard.electricPrice = HexUtil.bytesToFloat(electricPriceByte); |
| | | |
| | | |
| | | return regionCard; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 第1扇区0块 存储的数据 |
| | | */ |
| | | public class Zero extends BaseCard { |
| | | public byte[] toByte() { |
| | | byte[] data = new byte[16]; |
| | | data[0] = HexUtil.hexToByte(cardType); |
| | | |
| | | byte[] regionBytes = HexUtil.hexToByteArray(cardData); |
| | | if (regionBytes != null) { |
| | | System.arraycopy(regionBytes, 0, data, 1, regionBytes.length); |
| | | } |
| | | |
| | | byte[] controllerCodelBytes = HexUtil.folatToByte(electricPrice); |
| | | if (controllerCodelBytes != null) { |
| | | System.arraycopy(controllerCodelBytes, 0, data, 5, controllerCodelBytes.length); |
| | | } |
| | | |
| | | data[15] = getByteSum(data); |
| | | return data; |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | */ |
| | | public class ManageCard implements Serializable { |
| | | public String cardType = MyCommon.MANAGE_CRAD;//卡类型 |
| | | public String cardData = "3668F7A30119";//标识码 |
| | | public String cardData = "A0B1C289";//标识码 |
| | | |
| | | |
| | | /** |
| | | * M1卡的0扇区0块通常用于存储一些基本的卡片信息 |
| | | * 第0字节:卡片类型(M1卡为0x08) |
| | | * 第1字节:卡片地址(通常为0x00) |
| | | * 第2-5字节:卡片序列号(4字节) |
| | | * 第6-8字节:卡片制造商代码(3字节) |
| | | * 第9字节:卡片版本 |
| | | * 第10-15字节:预留区域 |
| | | */ |
| | | public byte[] userCard; //用户卡号 |
| | | |
| | | |
| | | public String getCardData() { |
| | | return cardData; |
| | |
| | | public byte[] toByte() { |
| | | byte[] data = new byte[16]; |
| | | data[0] = HexUtil.hexToByte(cardType); |
| | | byte[] cardDatas = HexUtil.hexToByteArray(cardData); |
| | | for (int i = 0; i < 6; i++) { |
| | | data[i + 1] = cardDatas[i]; |
| | | |
| | | byte[] cardDataByte = HexUtil.hexToByteArray(cardData); |
| | | if (cardDataByte != null) { |
| | | System.arraycopy(cardDataByte, 0, data, 1, cardDataByte.length); |
| | | } |
| | | |
| | | if (userCard!=null){ |
| | | System.arraycopy(userCard, 0, data, 5, userCard.length); |
| | | } |
| | | |
| | | data[15] = getByteSum(data); |
| | | return data; |
| | | } |
| | |
| | | import com.dayu.recharge.tools.HexUtil; |
| | | import com.dayu.recharge.utils.MyCommon; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * Copyright (C), 2023, |
| | | * Author: zuo |
| | |
| | | public class PassWordCard { |
| | | public String cardType = MyCommon.PASS_WORD_CRAD_TYPE;//卡类型 |
| | | public String cardData = "A0B1C289";//标识码 |
| | | public String passWord;//六位的密码 |
| | | |
| | | |
| | | |
| | | public static PassWordCard getBean(List<byte[]> data){ |
| | | |
| | | if (data!=null){ |
| | | PassWordCard passWordCard=new PassWordCard(); |
| | | |
| | | byte[] zero=data.get(0); |
| | | byte[] passWordByte=new byte[6]; |
| | | System.arraycopy(zero, 5, passWordByte, 0, passWordByte.length); |
| | | passWordCard.passWord = HexUtil.bytesToHex(passWordByte); |
| | | return passWordCard; |
| | | } |
| | | return null; |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | public byte[] toByte() { |
| | | Zero zero = new Zero(); |
| | | return zero.toByte(); |
| | | } |
| | | |
| | | |
| | | public class Zero extends BaseCard { |
| | | public void toByte() { |
| | | public byte[] toByte() { |
| | | byte[] data = new byte[16]; |
| | | data[0] = HexUtil.hexToByte(cardType); |
| | | byte[] cardDatas = HexUtil.hexToByteArray(cardData); |
| | | for (int i = 0; i < 4; i++) { |
| | | data[i + 1] = cardDatas[i]; |
| | | if (cardDatas != null) { |
| | | System.arraycopy(cardDatas, 0, data, 1, cardDatas.length); |
| | | } |
| | | |
| | | byte[] passWordBytes = HexUtil.hexToByteArray(passWord); |
| | | if (passWordBytes != null) { |
| | | System.arraycopy(passWordBytes, 0, data, 5, passWordBytes.length); |
| | | } |
| | | |
| | | data[15] = getByteSum(data); |
| | | return data; |
| | | } |
| | | |
| | | } |
| | |
| | | byte[] zero=data.get(0); |
| | | regionCard.cardType=HexUtil.byteToHex(zero[0]); |
| | | |
| | | byte[] regionByte = new byte[2]; |
| | | System.arraycopy(zero, 1, regionByte, 0, regionByte.length); |
| | | regionCard.region = (short) HexUtil.get16to10LowHigh(HexUtil.bytesToHex(regionByte)); |
| | | |
| | | |
| | | byte[] controllerCodelByte = new byte[2]; |
| | | System.arraycopy(zero, 3, controllerCodelByte, 0, controllerCodelByte.length); |
| | | regionCard.controllerCodel = (short) HexUtil.get16to10LowHigh(HexUtil.bytesToHex(controllerCodelByte)); |
| | | |
| | | |
| | | return regionCard; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 第1扇区0块 存储的数据 |
| | | */ |
| | | public class Zero extends BaseCard { |
| | | public byte[] toByte() { |
| | | byte[] data = new byte[16]; |
| | |
| | | import com.dayu.recharge.dbBean.IdentityBean; |
| | | import com.dayu.recharge.dbBean.IpBean; |
| | | import com.dayu.recharge.dbBean.PassWordBean; |
| | | import com.dayu.recharge.dbBean.PassWordCardBean; |
| | | import com.dayu.recharge.dbBean.PowerBean; |
| | | import com.dayu.recharge.dbBean.RechargeBean; |
| | | import com.dayu.recharge.dbBean.UserCardBean; |
| | |
| | | * Date: 2023-11-05 16:23 |
| | | * Description: |
| | | */ |
| | | @Database(entities = {CardData.class, DeviceNumber.class, IdentityBean.class, DomainBean.class, ElectricPriceBean.class, IpBean.class, AdminDataBean.class, PassWordBean.class, UserCardBean.class, RechargeBean.class, PowerBean.class}, version = 2, exportSchema = false) |
| | | @Database(entities = {PassWordCardBean.class,CardData.class, DeviceNumber.class, IdentityBean.class, DomainBean.class, ElectricPriceBean.class, IpBean.class, AdminDataBean.class, PassWordBean.class, UserCardBean.class, RechargeBean.class, PowerBean.class}, version = 3, exportSchema = false) |
| | | public abstract class AppDatabase extends RoomDatabase { |
| | | |
| | | |
| | |
| | | public abstract DeviceNumberDao deviceNumberDao(); |
| | | |
| | | public abstract CardDataDao cardDataDao(); |
| | | |
| | | public abstract PassWordCardDao passWordCardDao(); |
| | | } |
| | |
| | | * Copyright (C), 2023, |
| | | * Author: zuo |
| | | * Date: 2023-11-06 20:27 |
| | | * Description: |
| | | * Description: 登录密码保存 |
| | | */ |
| | | @Dao |
| | | public interface LoginPsDao { |
New file |
| | |
| | | package com.dayu.recharge.dao; |
| | | |
| | | import androidx.room.Dao; |
| | | import androidx.room.Delete; |
| | | import androidx.room.Insert; |
| | | import androidx.room.OnConflictStrategy; |
| | | import androidx.room.Query; |
| | | import androidx.room.Update; |
| | | |
| | | import com.dayu.recharge.dbBean.PassWordCardBean; |
| | | |
| | | /** |
| | | * Copyright (C), 2023, |
| | | * Author: zuo |
| | | * Date: 2023-11-08 21:27 |
| | | * Description: 密码卡 |
| | | */ |
| | | @Dao |
| | | public interface PassWordCardDao { |
| | | @Insert(onConflict = OnConflictStrategy.REPLACE) |
| | | void insert(PassWordCardBean passWordBean); |
| | | |
| | | @Update |
| | | void update(PassWordCardBean passWordBean); |
| | | |
| | | @Delete |
| | | void delete(PassWordCardBean passWordBean); |
| | | |
| | | @Query("select * from PassWordCardBean limit 1") |
| | | PassWordCardBean findFirst(); |
| | | } |
| | |
| | | * Copyright (C), 2023, |
| | | * Author: zuo |
| | | * Date: 2023-11-08 21:27 |
| | | * Description: 配置水泵功率 |
| | | * Description: |
| | | */ |
| | | @Dao |
| | | public interface PowerDao { |
| | |
| | | |
| | | import androidx.room.Entity; |
| | | import androidx.room.PrimaryKey; |
| | | |
| | | |
| | | /** |
| | | * 用户登录密码 |
| | | */ |
| | | @Entity |
| | | public class PassWordBean { |
| | | |
New file |
| | |
| | | package com.dayu.recharge.dbBean; |
| | | |
| | | import androidx.room.Entity; |
| | | import androidx.room.PrimaryKey; |
| | | |
| | | /** |
| | | * author: zuo |
| | | * Date: 2024-03-01 |
| | | * Time: 17:56 |
| | | * 备注:密码卡密码 |
| | | */ |
| | | @Entity |
| | | public class PassWordCardBean { |
| | | |
| | | @PrimaryKey(autoGenerate = true) |
| | | public long id; |
| | | private String passWord = ""; |
| | | |
| | | public long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getPassWord() { |
| | | return passWord; |
| | | } |
| | | |
| | | public void setPassWord(String passWord) { |
| | | this.passWord = passWord; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | package com.dayu.recharge.tools; |
| | | |
| | | import java.math.BigInteger; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | |
| | | return Integer.toHexString(Float.floatToIntBits(value)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 将带符号的32位浮点数装换byte数组 |
| | | * 低位在前高位在后 |
| | | * |
| | | * @param value |
| | | * @return |
| | | */ |
| | | public static byte[] folatToByte(Float value) { |
| | | ByteBuffer buffer = ByteBuffer.allocate(4); // 4个字节 |
| | | buffer.order(ByteOrder.LITTLE_ENDIAN); |
| | | buffer.putFloat(value); |
| | | byte[] byteArray = buffer.array(); |
| | | return byteArray; |
| | | } |
| | | |
| | | /** |
| | | * 将byte数组转换为带符号的32位浮点数 |
| | | * |
| | | * 低位在前高位在后 |
| | | * |
| | | * @param value |
| | | * @return |
| | | */ |
| | | public static Float bytesToFloat(byte[] value) { |
| | | ByteBuffer bufferLittleEndian = ByteBuffer.wrap(value); |
| | | bufferLittleEndian.order(ByteOrder.LITTLE_ENDIAN); |
| | | return bufferLittleEndian.getFloat(); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 十进制转16进制 |
| | | * |
| | |
| | | |
| | | /** |
| | | * short10进制转16进制 低位在前高位在后 |
| | | * |
| | | * @param number |
| | | * @return |
| | | */ |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * short10进制转16进制 低位在前高位在后 |
| | | * |
| | | * @param number |
| | | * @return |
| | | */ |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * short16进制转10进制 低位在前高位在后 |
| | | * |
| | | * @param hex |
| | | * @return |
| | | */ |
| | | public static short getShort10To16LowHigh(String hex){ |
| | | public static short getShort10To16LowHigh(String hex) { |
| | | try { |
| | | String str = ""; |
| | | str = spaceHex(hex); |
| | | str = HighLowHex(str); |
| | | return (short) Integer.parseInt(str, 16); |
| | | } catch (NumberFormatException e) { |
| | | e.printStackTrace(); |
| | | e.printStackTrace(); |
| | | } |
| | | return 0; |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| | | xmlns:app="http://schemas.android.com/apk/res-auto" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="match_parent" |
| | | android:orientation="vertical"> |
| | | |
| | | <com.dayu.recharge.view.TitleBar |
| | | android:id="@+id/titleBar" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="@dimen/dimen_title_height" |
| | | android:background="@drawable/title_bar_bg" |
| | | app:centerText="配置卡密码" |
| | | app:leftImage="@mipmap/icon_back" /> |
| | | |
| | | <LinearLayout |
| | | android:id="@+id/village_ll" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="wrap_content" |
| | | android:layout_below="@id/titleBar" |
| | | android:layout_margin="20dp" |
| | | android:orientation="horizontal"> |
| | | |
| | | <TextView |
| | | android:layout_width="wrap_content" |
| | | android:layout_height="wrap_content" |
| | | android:text="当前密码" |
| | | android:textSize="@dimen/text_size" /> |
| | | |
| | | <TextView |
| | | android:id="@+id/village_oldNumber" |
| | | android:layout_width="wrap_content" |
| | | android:layout_height="match_parent" |
| | | android:textSize="@dimen/text_size" /> |
| | | |
| | | </LinearLayout> |
| | | |
| | | |
| | | <EditText |
| | | android:id="@+id/village_newNum" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="wrap_content" |
| | | android:layout_below="@+id/village_ll" |
| | | android:layout_alignParentStart="true" |
| | | android:layout_marginStart="20dp" |
| | | android:layout_marginTop="20dp" |
| | | android:layout_marginEnd="20dp" |
| | | android:layout_marginBottom="20dp" |
| | | android:hint="请输入新设置的12位16进制卡密码" |
| | | android:inputType="number|numberDecimal" |
| | | android:digits="0123456789." /> |
| | | |
| | | <TextView |
| | | android:id="@+id/village_ok" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="50dp" |
| | | android:layout_alignParentBottom="true" |
| | | android:background="@color/title_bg" |
| | | android:gravity="center" |
| | | android:text="确 定" |
| | | android:textSize="@dimen/text_size" /> |
| | | </RelativeLayout> |