Skip to content

Commit b325203

Browse files
committed
Library w/o progress updates
1 parent bb77b46 commit b325203

File tree

4 files changed

+38
-26
lines changed

4 files changed

+38
-26
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ android {
2020
dependencies {
2121
compile fileTree(dir: 'libs', include: ['*.jar'])
2222
compile 'com.android.support:support-annotations:+'
23-
compile 'com.android.support:support-v4:19.0.+'
23+
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
2424
}
2525

2626

src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.samsung.dfulibrary"
2+
package="org.microbit.partialflashing"
33
android:versionCode="1"
44
android:versionName="1.0" >
55

src/main/java/org/microbit/android/partialflashing/HexUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ public class HexUtils {
5050

5151
int magicLines = 0;
5252

53-
/*
54-
Unused initializer
55-
*/
56-
public void HexUtils(String filePath){
53+
public HexUtils(String filePath){
5754
// Hex Utils initialization
5855
// Open File
5956
try {
@@ -90,6 +87,10 @@ public Boolean openHexFile(String filePath) throws IOException {
9087
return true;
9188
}
9289

90+
public int numOfLines() {
91+
return hexLines.size();
92+
}
93+
9394
public int searchForData(String search) throws IOException {
9495
// Iterate through
9596
ListIterator i = hexLines.listIterator();

src/main/java/org/microbit/android/partialflashing/PartialFlashingBaseService.java

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ public abstract class PartialFlashingBaseService extends IntentService {
4040

4141
public static final UUID PARTIAL_FLASH_CHARACTERISTIC = UUID.fromString("e97d3b10-251d-470a-a062-fa1922dfa9a8");
4242
public static final UUID PARTIAL_FLASHING_SERVICE = UUID.fromString("e97dd91d-251d-470a-a062-fa1922dfa9a8");
43+
44+
public static final String PXT_MAGIC = "708E3B92C615A841C49866C975EE5197";
4345

4446
private final static String TAG = PartialFlashingBaseService.class.getSimpleName();
47+
48+
public static final String BROADCAST_ACTION = "org.microbit.android.partialflashing.broadcast.BROADCAST_ACTION";
4549

4650
private BluetoothManager mBluetoothManager;
4751
private BluetoothAdapter mBluetoothAdapter;
@@ -94,7 +98,13 @@ public abstract class PartialFlashingBaseService extends IntentService {
9498
"com.example.bluetooth.le.ACTION_DATA_AVAILABLE";
9599
public final static String EXTRA_DATA =
96100
"com.example.bluetooth.le.EXTRA_DATA";
97-
LocalBroadcastManager localBroadcast;
101+
102+
@Override
103+
public void onCreate() {
104+
super.onCreate();
105+
106+
final LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this);
107+
}
98108

99109
// Various callback methods defined by the BLE API.
100110
private final BluetoothGattCallback mGattCallback =
@@ -228,32 +238,33 @@ public Boolean attemptPartialFlash(String filePath) {
228238
int count = 0;
229239
int progressBar = 0;
230240
int numOfLines = 0;
231-
HexUtils hex;
232241
try {
233-
hex = new HexUtils();
234-
if (hex.findHexMetaData(filePath)) {
235242

236-
if(!hex.getTemplateHash().equals(dalHash)){
237-
Log.v(TAG, "Received DAL hash:" + dalHash + " Template: " + hex.getTemplateHash());
238-
}
243+
Log.v(TAG, "starting pf");
239244

240-
numOfLines = hex.numOfLines(filePath);
241-
numOfLines = numOfLines - hex.getMagicLines();
245+
HexUtils hex = new HexUtils(filePath);
246+
int magicIndex = hex.searchForData(PXT_MAGIC);
247+
if (magicIndex > -1) {
248+
249+
Log.v(TAG, "found meta");
250+
251+
numOfLines = hex.numOfLines() - magicIndex;
242252
Log.v(TAG, "Total lines: " + numOfLines);
243253

244254
// Ready to flash!
245255
// Loop through data
246256
String hexData;
247257
int packetNum = 0;
258+
int lineCount = 0;
248259
while(true){
249260
// Get next data to write
250-
hexData = hex.getNextData();
261+
hexData = hex.getDataFromIndex(magicIndex + lineCount);
251262
// Check if EOF
252-
if(hex.getRecordType() != 0) break;
263+
if(hex.getRecordTypeFromIndex(magicIndex + lineCount) != 0) break;
253264

254265
// Log record being written
255266
Log.v(TAG, "Hex Data : " + hexData);
256-
Log.v(TAG, "Hex Offset: " + Integer.toHexString(hex.getRecordOffset()));
267+
Log.v(TAG, "Hex Offset: " + Integer.toHexString(hex.getRecordAddressFromIndex(magicIndex + lineCount)));
257268

258269
// If Hex Data is Embedded Source Magic
259270
if(hexData.length() == 32) {
@@ -273,11 +284,11 @@ public Boolean attemptPartialFlash(String filePath) {
273284
// Split into bytes
274285
int offsetToSend = 0;
275286
if(count == 0) {
276-
offsetToSend = hex.getRecordOffset();
287+
offsetToSend = hex.getRecordAddressFromIndex(magicIndex + lineCount);
277288
}
278289

279290
if(count == 1) {
280-
offsetToSend = hex.getSectionAddress();
291+
offsetToSend = hex.getSegmentAddress(magicIndex + lineCount);
281292
}
282293

283294
Log.v(TAG, "OFFSET_TO_SEND: " + offsetToSend);
@@ -306,14 +317,14 @@ public Boolean attemptPartialFlash(String filePath) {
306317
// If notification is retransmit -> retransmit last block.
307318
// Else set start of new block
308319
if(packetState == PACKET_STATE_RETRANSMIT) {
309-
hex.rewind();
320+
lineCount = lineCount - 4;
310321
} else {
311-
hex.setMark();
312322
// TODO update UI
313323
}
314324

315325
// Increment packet #
316326
packetNum = packetNum + 1;
327+
lineCount = lineCount + 1;
317328

318329
}
319330

@@ -415,10 +426,8 @@ private boolean initialize(String deviceId) {
415426
BluetoothGattDescriptor descriptor = partialFlashCharacteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG);
416427
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
417428

418-
if(bluetoothStatus) {
419-
bluetoothStatus = BLE_WAITING;
420-
mBluetoothGatt.writeDescriptor(descriptor);
421-
}
429+
bluetoothStatus = BLE_WAITING;
430+
mBluetoothGatt.writeDescriptor(descriptor);
422431
while(!bluetoothStatus);
423432

424433
return true;
@@ -431,7 +440,9 @@ protected void onHandleIntent(@Nullable Intent intent) {
431440
final String filePath = intent.getStringExtra("filepath");
432441
final String deviceAddress = intent.getStringExtra("deviceAddress");
433442

443+
Log.v(TAG, "Initialise");
434444
initialize(deviceAddress);
445+
Log.v(TAG, "/Initialise");
435446
readMemoryMap();
436447
// If fails attempt full flash
437448
if(!attemptPartialFlash(filePath))

0 commit comments

Comments
 (0)