Skip to content

Commit

Permalink
Version 2.1.11
Browse files Browse the repository at this point in the history
- Slightly increased FOC angle multiplicator default values (36v/48v)
- New Controller OTA FW update process (Watchdog reset instead of Power OFF/ON)
- New Battery Overcurrent Error
- Old Log file deletion Bug Fix
  • Loading branch information
mspider65 committed Jul 26, 2021
1 parent 5f94c32 commit c199900
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 47 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "spider65.ebike.tsdz2_esp32"
minSdkVersion 23
targetSdkVersion 28
versionCode 17
versionName "2.1.10"
versionCode 18
versionName "2.1.11"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ public boolean onSwipe(Direction direction) {
title = getString(R.string.error_torque_sensor);
message = getString(R.string.check_torque_sensor);
break;
case TSDZConst.ERROR_LOW_CONTROLLER_VOLTAGE:
title = getString(R.string.error_low_voltage);
message = getString(R.string.check_low_voltage);
case TSDZConst.ERROR_BATTERY_OVERCURRENT:
title = getString(R.string.error_battery_overcurrent);
message = getString(R.string.check_battery_overcurrent);
break;
case TSDZConst.ERROR_OVERVOLTAGE:
title = getString(R.string.error_high_voltage);
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/spider65/ebike/tsdz2_esp32/TSDZConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ public interface TSDZConst {
int ERROR_BRAKE_APPLIED_DURING_POWER_ON = 3; // currently not used
int ERROR_THROTTLE_APPLIED_DURING_POWER_ON = 4; // currently not used
int ERROR_NO_SPEED_SENSOR_DETECTED = 5; // currently not used
*/
int ERROR_LOW_CONTROLLER_VOLTAGE = 6; // controller works with no less than 15 V so give error code if voltage is too low
*/
int ERROR_BATTERY_OVERCURRENT = 7;
int ERROR_OVERVOLTAGE = 8;
int ERROR_TEMPERATURE_LIMIT = 9;
int ERROR_TEMPERATURE_MAX = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class SystemSetupActivity extends AppCompatActivity {

private static final String TAG = "MotorSetupActivity";

private static final int DEFAULT_36V_FOC_MULTI = 24;
private static final int DEFAULT_48V_FOC_MULTI = 32;
private static final int DEFAULT_36V_FOC_MULTI = 27;
private static final int DEFAULT_48V_FOC_MULTI = 35;

private TSDZ_Config cfg = new TSDZ_Config();
private IntentFilter mIntentFilter = new IntentFilter();
Expand Down
71 changes: 35 additions & 36 deletions app/src/main/java/spider65/ebike/tsdz2_esp32/data/LogManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ public static class TimeInterval {

// max time interval between two log entries in a single log file. If more, a new log file is started.
private static final long MAX_LOG_PAUSE = 1000 * 60 * 20;
// log file retention is 7 days (in msec)
// Max nr of Log entries
private static final int MAX_LOG_FILES = 20;
// if there are more than MAX_LOG_FILES log entries, delete the entries older than 7 days (in msec)
private static final long MAX_LOG_HISTORY = 1000 * 60 * 60 * 24 * 7;
// max single log file time is 6 hours (in msec)
private static final long MAX_FILE_HISTORY = 1000 * 60 * 60 * 6;
Expand Down Expand Up @@ -254,6 +255,26 @@ public void queryLogData(int minuteFrom, int minuteTo) {
mHandler.sendMessage(msg);
}

// Return a sorted array of status or debug files according to the prefix parameter
// first is the older, last is the newer
private File[] getFiles(String prefix) {
final File folder = MyApp.getInstance().getFilesDir();
final File[] files = folder.listFiles( (dir, name) ->
name.matches( prefix + ".log\\.\\d+\\.\\d+$" ));
if (files != null)
Arrays.sort(files, (f1, f2) -> {
final long t1 = Long.parseLong(f1.getName().substring(f1.getName().lastIndexOf('.') + 1));
final long t2 = Long.parseLong(f2.getName().substring(f2.getName().lastIndexOf('.') + 1));
if (t1 > t2)
return 1;
else if (t1 < t2)
return -1;
return 0;
});

return files;
}

private void saveStatusLog(long startTime, long endTime, byte[] data, int length) {
Log.d(TAG, "saveStatusLog");

Expand Down Expand Up @@ -310,19 +331,14 @@ private void saveDebugLog(long startTime, long endTime, byte[] data, int length)

private void swapStatusFile() {
Log.d(TAG, "swapStatusFile");
// remove log file with all data older than MAX_LOG_HISTORY
final File folder = MyApp.getInstance().getFilesDir();
final File[] files = folder.listFiles( (dir, name) ->
name.matches( STATUS_LOG_FILENAME + ".log\\.\\d+\\.\\d+$" ));
final File[] files = getFiles(STATUS_LOG_FILENAME);

// If there are more than MAX_LOG_FILES, remove log file with all data older than MAX_LOG_HISTORY
if ((files != null) && (files.length > MAX_LOG_FILES)) {
Arrays.sort(files, (object1, object2) ->
object1.getName().compareTo(object2.getName()));
long now = System.currentTimeMillis();
for (int i = MAX_LOG_FILES; i < files.length; i++) {
for (int i = 0; i < (files.length - MAX_LOG_FILES); i++) {
File f = files[i];
String s1 = f.getName();
String[] s = s1.split("\\.");
long endTime = Long.parseLong(s[3]);
long endTime = Long.parseLong(f.getName().substring(f.getName().lastIndexOf('.') + 1));
if ((now - endTime) > MAX_LOG_HISTORY) {
Log.d(TAG,"Removing file: "+f.getName()+" File end Time:"+endTime+" now="+now);
if (!f.delete()) {
Expand All @@ -348,21 +364,14 @@ private void swapStatusFile() {

private void swapDebugFile() {
Log.d(TAG, "swapDebugFile");
// remove log file with all data older than MAX_LOG_HISTORY
final File folder = MyApp.getInstance().getFilesDir();
final File[] files = folder.listFiles( (dir, name ) ->
name.matches( DEBUG_LOG_FILENAME + ".log\\.\\d+\\.\\d+$" ));
final File[] files = getFiles(DEBUG_LOG_FILENAME);

// remove old log files
// If there are more than MAX_LOG_FILES, remove log file with all data older than MAX_LOG_HISTORY
if ((files != null) && (files.length > MAX_LOG_FILES)) {
Arrays.sort(files, (object1, object2) ->
object1.getName().compareTo(object2.getName()));
long now = System.currentTimeMillis();
for (int i = MAX_LOG_FILES; i < files.length; i++) {
for (int i = 0; i < (files.length - MAX_LOG_FILES); i++) {
File f = files[i];
String s1 = f.getName();
String[] s = s1.split("\\.");
long endTime = Long.parseLong(s[3]);
long endTime = Long.parseLong(f.getName().substring(f.getName().lastIndexOf('.') + 1));
if ((now - endTime) > MAX_LOG_HISTORY) {
Log.d(TAG,"Removing file: "+f.getName()+" File end Time:"+endTime+" now="+now);
if (!f.delete()) {
Expand Down Expand Up @@ -478,13 +487,9 @@ private ArrayList<TimeInterval> getLogIntervals () {
ArrayList<TimeInterval> ret = new ArrayList<>();
TimeInterval ti;
try {
final File folder = MyApp.getInstance().getFilesDir();
final File[] files = folder.listFiles((dir, name) ->
name.matches(STATUS_LOG_FILENAME + ".log\\.\\d+\\.\\d+$"));
final File[] files = getFiles(STATUS_LOG_FILENAME);
long startTime, endTime;
if (files != null) {
Arrays.sort(files, (object1, object2) ->
object1.getName().compareTo(object2.getName()));
for (File file : files) {
String[] s = file.getName().split("\\.");
startTime = Long.parseLong(s[2]);
Expand Down Expand Up @@ -543,13 +548,10 @@ private ArrayList<LogStatusEntry> getStatusData (int fromMinute, int toMinute) {
}
return ret;
}

final File folder = MyApp.getInstance().getFilesDir();
final File[] files = folder.listFiles((dir, name) ->
name.matches(STATUS_LOG_FILENAME + ".log\\.\\d+\\.\\d+$"));

final File[] files = getFiles(STATUS_LOG_FILENAME);
long startTime, endTime;
if (files != null) {
Arrays.sort(files, (object1, object2) -> object1.getName().compareTo(object2.getName()));
for (File file : files) {
String[] s = file.getName().split("\\.");
startTime = Long.parseLong(s[2]);
Expand Down Expand Up @@ -621,12 +623,9 @@ private ArrayList<LogDebugEntry> getDebugData (int fromMinute, int toMinute) {
return ret;
}

final File folder = MyApp.getInstance().getFilesDir();
final File[] files = folder.listFiles((dir, name) ->
name.matches(DEBUG_LOG_FILENAME + ".log\\.\\d+\\.\\d+$"));
final File[] files = getFiles(DEBUG_LOG_FILENAME);
long startTime, endTime;
if (files != null) {
Arrays.sort(files, (object1, object2) -> object1.getName().compareTo(object2.getName()));
for (File file : files) {
String[] s = file.getName().split("\\.");
startTime = Long.parseLong(s[2]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ void showStatus(int status, int value) {
}
}

private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
private final BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "onReceive " + intent.getAction());
Expand All @@ -473,8 +473,7 @@ public void onReceive(Context context, Intent intent) {
if (data[1] != (byte)0x0) {
stopUpdate();
showDialog(getString(R.string.error), getString(R.string.updateError), false);
} else
showDialog(getString(R.string.update_start_procedure), getString(R.string.update_start_description), false);
}
break;
// Get Version response
case CMD_GET_APP_VERSION:
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<string name="check_torque_sensor">Take your feet off the pedals and restart the bike</string>
<string name="error_low_voltage">Battery low voltage!</string>
<string name="check_low_voltage">Check battery voltage or battery configuration parameters</string>
<string name="error_battery_overcurrent">Battery current too High!</string>
<string name="check_battery_overcurrent">Switch Off the bike and check motor connections</string>
<string name="error_high_voltage">Battery overvoltage!</string>
<string name="check_high_voltage">Check battery voltage or battery configuration parameters</string>
<string name="error_limit_temperature">Warning temperature</string>
Expand Down Expand Up @@ -110,6 +112,8 @@
<string name="uploadDone">Upload completed</string>
<string name="write_init">write initialization …</string>
<string name="start_programming">Start of programming …</string>
<string name="stm8_ota_started">OTA Started</string>
<string name="sync_done">Bootloader Sync done</string>
<string name="writing">Writing: %1$d%%</string>
<string name="upgrade_ok">Firmware upgraded</string>
<string name="stm8_upgrade_message">Bike firmware successfully updated!</string>
Expand Down

0 comments on commit c199900

Please sign in to comment.