Skip to content

Commit

Permalink
feat: display wake-up time when reading Master Sleep card
Browse files Browse the repository at this point in the history
  • Loading branch information
sembruk committed Jan 28, 2025
1 parent 56b8f87 commit 0462c2f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
66 changes: 39 additions & 27 deletions app/src/main/java/org/sportiduino/app/sportiduino/MasterCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public byte[][] read() throws ReadWriteCardException {
case MASTER_READ_BACKUP:
return adapter.readPages(CARD_PAGE_INFO1, adapter.getMaxPage(), true);
default:
return new byte[0][0];
return adapter.readPages(CARD_PAGE_INFO1, 2);
}
}

Expand All @@ -46,7 +46,7 @@ public CharSequence parseData(byte[][] data) {
State state = new State(data);
return Html.fromHtml((App.str(R.string.state_master_card) + "\n" + state.toString()).replace("\n", "<br/>"));
case MASTER_SLEEP:
return App.str(R.string.sleep_master_card);
return App.str(R.string.sleep_master_card) + "\n" + parseWakeupTime(data);
case MASTER_READ_BACKUP:
return parseBackupMaster(data);
case MASTER_CONFIG:
Expand All @@ -70,6 +70,43 @@ protected void writeImpl() throws ReadWriteCardException {
}
}

public static byte[][] packStationNumber(int stationNumber) {
return new byte[][] { {(byte) stationNumber, 0, 0, 0} };
}

public static byte[][] packTime(Calendar calendar) {
Calendar c = (Calendar) calendar.clone();
c.setTimeZone(TimeZone.getTimeZone("UTC"));
int year = c.get(Calendar.YEAR) - 2000;
int month = c.get(Calendar.MONTH) + 1;
int day = c.get(Calendar.DAY_OF_MONTH);
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
int second = c.get(Calendar.SECOND);
return new byte[][] {
{(byte) month, (byte) year, (byte) day, 0},
{(byte) hour, (byte) minute, (byte) second, 0}
};
}

public static byte[][] packNewPassword(Password password) {
return new byte[][] {
{(byte) password.getValue(2), (byte) password.getValue(1), (byte) password.getValue(0), 0}
};
}

public static String parseWakeupTime(byte[][] data) {
int year = data[0][1] + 2000;
int month = data[0][0];
int day = data[0][2];
int hour = data[1][0];
int minute = data[1][1];
int second = data[1][2];
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
c.set(year, month - 1, day, hour, minute, second);
return App.str(R.string.wakeup_time_) + " " + Util.dhmformat.format(new Date(c.getTimeInMillis()));
}

private String parseBackupMaster(byte[][] data) {
StringBuilder ret = new StringBuilder(App.str(R.string.backup_master_card));
int stationNumber = dataPage4[0] & 0xff;
Expand Down Expand Up @@ -120,30 +157,5 @@ private String parseBackupMaster(byte[][] data) {
}
return String.format(ret.toString(), recordCount);
}

public static byte[][] packStationNumber(int stationNumber) {
return new byte[][] { {(byte) stationNumber, 0, 0, 0} };
}

public static byte[][] packTime(Calendar calendar) {
Calendar c = (Calendar) calendar.clone();
c.setTimeZone(TimeZone.getTimeZone("UTC"));
int year = c.get(Calendar.YEAR) - 2000;
int month = c.get(Calendar.MONTH) + 1;
int day = c.get(Calendar.DAY_OF_MONTH);
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
int second = c.get(Calendar.SECOND);
return new byte[][] {
{(byte) month, (byte) year, (byte) day, 0},
{(byte) hour, (byte) minute, (byte) second, 0}
};
}

public static byte[][] packNewPassword(Password password) {
return new byte[][] {
{(byte) password.getValue(2), (byte) password.getValue(1), (byte) password.getValue(0), 0}
};
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

public class Util {
public static SimpleDateFormat dformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static SimpleDateFormat dhmformat = new SimpleDateFormat("yyyy-MM-dd HH:mm");

public static int byteToUint(byte b) {
return ((int) b) & 0xFF;
Expand Down

0 comments on commit 0462c2f

Please sign in to comment.