mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-09 08:38:03 -06:00
Change header byte length, add data view by field type
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.ridgebotics.ridgescout.utility;
|
||||
|
||||
import static com.ridgebotics.ridgescout.utility.fileEditor.lengthHeaderBytes;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -80,22 +82,22 @@ public class BuiltByteParser {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
public ArrayList<parsedObject> parse() throws byteParsingExeption {
|
||||
if(bytes.length < 3){throw new byteParsingExeption("Invalid length");}
|
||||
if(bytes.length < lengthHeaderBytes + 1){throw new byteParsingExeption("Invalid length");}
|
||||
int curIndex = 0;
|
||||
while(true){
|
||||
// Log.i("t", String.valueOf(curIndex));
|
||||
final int length = fileEditor.fromBytes(fileEditor.getByteBlock(bytes, curIndex, curIndex+2), 2);
|
||||
final int type = bytes[curIndex+2] & 0xFF;
|
||||
final int length = fileEditor.fromBytes(fileEditor.getByteBlock(bytes, curIndex, curIndex+lengthHeaderBytes), lengthHeaderBytes);
|
||||
final int type = bytes[curIndex+lengthHeaderBytes] & 0xFF;
|
||||
|
||||
if(length == 0){
|
||||
curIndex += 3;
|
||||
curIndex += lengthHeaderBytes;
|
||||
continue;
|
||||
}
|
||||
|
||||
final byte[] block;
|
||||
|
||||
try {
|
||||
block = fileEditor.getByteBlock(bytes, curIndex + 3, curIndex + length + 3);
|
||||
block = fileEditor.getByteBlock(bytes, curIndex + lengthHeaderBytes + 1, curIndex + length + lengthHeaderBytes + 1);
|
||||
} catch(Exception e){
|
||||
throw new byteParsingExeption("Array out of bounds");
|
||||
}
|
||||
@@ -158,7 +160,7 @@ public class BuiltByteParser {
|
||||
break;
|
||||
}
|
||||
|
||||
curIndex += length + 3;
|
||||
curIndex += length + lengthHeaderBytes + 1;
|
||||
|
||||
if(curIndex == bytes.length){
|
||||
break;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.ridgebotics.ridgescout.utility;
|
||||
|
||||
import static com.ridgebotics.ridgescout.utility.fileEditor.lengthHeaderBytes;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -71,7 +73,7 @@ public class ByteBuilder {
|
||||
public ByteBuilder addInt(int num, int precision) throws buildingException {
|
||||
if(precision <= 0){throw new buildingException("Invalid precision: " + precision);}
|
||||
|
||||
if(precision > 65536){throw new buildingException("Precision too large (greter than 65536)");}
|
||||
if(precision > Math.pow(lengthHeaderBytes,8)){throw new buildingException("Precision too large (greter than 16777216)");}
|
||||
if(precision < getLeastBytePrecision(num)){throw new buildingException("Precision too small");}
|
||||
|
||||
if(num > Integer.MAX_VALUE){throw new buildingException("Integer overflow");}
|
||||
@@ -96,7 +98,7 @@ public class ByteBuilder {
|
||||
}
|
||||
public ByteBuilder addString(String str) throws buildingException {
|
||||
str = blankStrNull(str);
|
||||
if(str.length() > 65536){throw new buildingException("String too long (greater than 65536)");}
|
||||
if(str.length() > Math.pow(lengthHeaderBytes,8)){throw new buildingException("String too long (greater than 16777216)");}
|
||||
|
||||
stringType stringType = new stringType();
|
||||
// To get the length correctly, the string bytes need to be precalculated
|
||||
@@ -175,7 +177,7 @@ public class ByteBuilder {
|
||||
public ByteBuilder addLong(long num, int precision) throws buildingException {
|
||||
if(precision <= 0){throw new buildingException("Invalid precision: " + precision);}
|
||||
|
||||
if(precision > 65536){throw new buildingException("Precision too large (greter than 65536)");}
|
||||
if(precision > Math.pow(lengthHeaderBytes,8)){throw new buildingException("Precision too large (greter than 16777216)");}
|
||||
if(precision < getLeastBytePrecision(num)){throw new buildingException("Precision too small");}
|
||||
|
||||
if(num > Long.MAX_VALUE){throw new buildingException("Long overflow");}
|
||||
@@ -200,7 +202,7 @@ public class ByteBuilder {
|
||||
}
|
||||
|
||||
public ByteBuilder addRaw(int type, byte[] bytes) throws buildingException {
|
||||
if(bytes.length > 65536){throw new buildingException("Byte array length to long (greater than 65536)");}
|
||||
if(bytes.length > 16777216){throw new buildingException("Byte array length to long (greater than 16777216)");}
|
||||
|
||||
rawType rawType = new rawType();
|
||||
rawType.type = type;
|
||||
@@ -213,7 +215,7 @@ public class ByteBuilder {
|
||||
public byte[] build() throws buildingException {
|
||||
if(bytesToBuild.size() == 0){throw new buildingException("Cannot build null data");}
|
||||
|
||||
int length = bytesToBuild.size() * 3;
|
||||
int length = bytesToBuild.size() * (lengthHeaderBytes + 1);
|
||||
for(byteType bt : bytesToBuild){
|
||||
length += bt.length();
|
||||
}
|
||||
@@ -223,12 +225,13 @@ public class ByteBuilder {
|
||||
|
||||
for(byteType bt : bytesToBuild){
|
||||
|
||||
byte[] blockLength = fileEditor.toBytes(bt.length(), 2);
|
||||
byte[] blockLength = fileEditor.toBytes(bt.length(), lengthHeaderBytes + 1);
|
||||
|
||||
for(int i = 0; i < lengthHeaderBytes; i++) {
|
||||
bytes[bytesFilled] = blockLength[i];
|
||||
bytesFilled += 1;
|
||||
}
|
||||
|
||||
bytes[bytesFilled] = blockLength[0];
|
||||
bytesFilled += 1;
|
||||
bytes[bytesFilled] = blockLength[1];
|
||||
bytesFilled += 1;
|
||||
bytes[bytesFilled] = bt.getType();
|
||||
bytesFilled += 1;
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ public class DataManager {
|
||||
public static String evcode;
|
||||
public static frcEvent event;
|
||||
public static void reload_event(){
|
||||
if(event != null) return;
|
||||
evcode = getevcode();
|
||||
|
||||
if(evcode.equals("unset")) return;
|
||||
@@ -25,6 +26,7 @@ public class DataManager {
|
||||
settingsManager.setEVCode("unset");
|
||||
evcode = "unset";
|
||||
}else{
|
||||
AlertManager.toast("Reloaded event!");
|
||||
reload_rescout_list();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ public final class fileEditor {
|
||||
public final static String baseDir = "/data/data/com.ridgebotics.ridgescout/";
|
||||
public static final byte internalDataVersion = 0x01;
|
||||
public static final int maxCompressedBlockSize = 4096;
|
||||
public static final int lengthHeaderBytes = 3;
|
||||
// private TimeZone localTimeZone = TimeZone.getDefault();
|
||||
|
||||
|
||||
@@ -58,7 +59,7 @@ public final class fileEditor {
|
||||
|
||||
|
||||
public static byte[] toBytes(int num, int byteCount){
|
||||
if(num > (Math.pow(2,byteCount*8)-1)){
|
||||
if(num > (Math.pow(lengthHeaderBytes,byteCount*8)-1)){
|
||||
throw new BufferOverflowException();
|
||||
}
|
||||
byte[] bytes = new byte[byteCount];
|
||||
@@ -69,7 +70,7 @@ public final class fileEditor {
|
||||
}
|
||||
|
||||
public static byte[] toBytes(long num, int byteCount){
|
||||
if(num > (Math.pow(2,byteCount*8)-1)){
|
||||
if(num > (Math.pow(lengthHeaderBytes,byteCount*8)-1)){
|
||||
throw new BufferOverflowException();
|
||||
}
|
||||
byte[] bytes = new byte[byteCount];
|
||||
|
||||
@@ -22,6 +22,7 @@ public class settingsManager {
|
||||
|
||||
public static final String WifiModeKey = "wifi_mode";
|
||||
public static final String DataModeKey = "data_view_mode";
|
||||
public static final String TeamsDataModeKey = "teams_data_view_mode";
|
||||
public static final String BtUUIDKey = "bt_uuid";
|
||||
public static final String FTPEnabled = "ftp_enabled";
|
||||
public static final String FTPServer = "ftp_server";
|
||||
@@ -42,6 +43,7 @@ public class settingsManager {
|
||||
hm.put(MatchNumKey, 0);
|
||||
hm.put(AllyPosKey, "red-1");
|
||||
hm.put(DataModeKey, 0);
|
||||
hm.put(TeamsDataModeKey, 0);
|
||||
hm.put(BtUUIDKey, UUID.randomUUID().toString());
|
||||
hm.put(FTPEnabled, false);
|
||||
hm.put(FTPServer, "0.0.0.0");
|
||||
@@ -67,6 +69,7 @@ public class settingsManager {
|
||||
getEditor() .putInt(MatchNumKey, (int) defaults.get( MatchNumKey )).apply();
|
||||
getEditor() .putString(AllyPosKey, (String) defaults.get( AllyPosKey )).apply();
|
||||
getEditor() .putInt(DataModeKey, (int) defaults.get( DataModeKey )).apply();
|
||||
getEditor() .putInt(TeamsDataModeKey, (int) defaults.get( TeamsDataModeKey )).apply();
|
||||
|
||||
getEditor() .putString(BtUUIDKey, (String) defaults.get( BtUUIDKey )).apply();
|
||||
|
||||
@@ -103,6 +106,8 @@ public class settingsManager {
|
||||
|
||||
public static int getDataMode(){return prefs.getInt( DataModeKey, (int) defaults.get(DataModeKey));}
|
||||
public static void setDataMode(int num){ getEditor().putInt( DataModeKey,num).apply();}
|
||||
public static int getTeamsDataMode(){return prefs.getInt( TeamsDataModeKey, (int) defaults.get(TeamsDataModeKey));}
|
||||
public static void setTeamsDataMode(int num){ getEditor().putInt( TeamsDataModeKey,num).apply();}
|
||||
|
||||
public static String getBtUUID(){return prefs.getString( BtUUIDKey, (String) defaults.get(BtUUIDKey));}
|
||||
public static void setBtUUID(String str){ getEditor().putString( BtUUIDKey,str).apply();}
|
||||
|
||||
Reference in New Issue
Block a user