fix: force little endian
This commit is contained in:
parent
db2b976999
commit
e1f2ca1de1
File diff suppressed because one or more lines are too long
@ -3,7 +3,7 @@
|
|||||||
<title>ESP32 timed Switch</title>
|
<title>ESP32 timed Switch</title>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.8.3/angular.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.8.3/angular.js"></script>
|
||||||
<link rel="manifest" href="manifest.json" />
|
<link rel="manifest" href="manifest.json" />
|
||||||
|
<meta charset="UTF-8">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Scheduler</h1>
|
<h1>Scheduler</h1>
|
||||||
@ -28,7 +28,7 @@ class Schedule {
|
|||||||
// Load from binary data
|
// Load from binary data
|
||||||
var view = new DataView(buffer);
|
var view = new DataView(buffer);
|
||||||
for (var i = 0; i < 24; i++) {
|
for (var i = 0; i < 24; i++) {
|
||||||
this.schedule[i] = view.getUint16(i * 2);
|
this.schedule[i] = view.getUint16(i * 2, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -101,10 +101,11 @@ class Schedule {
|
|||||||
// Convert to binary data
|
// Convert to binary data
|
||||||
var buffer = new ArrayBuffer(24 * 2);
|
var buffer = new ArrayBuffer(24 * 2);
|
||||||
var view = new DataView(buffer);
|
var view = new DataView(buffer);
|
||||||
for (var i = 0; i < this.schedule.length; i++) {
|
for (var i = 0; i < 24; i++) {
|
||||||
view.setUint16(i * 2, this.schedule[i]);
|
view.setUint8( i*2 , (this.schedule[i] & 65280) >> 8, true);
|
||||||
|
view.setUint8( i*2 + 1, this.schedule[i] & 255 , true);
|
||||||
}
|
}
|
||||||
return view;
|
return buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
APP_PATH=$(cd $(dirname $0) && pwd)
|
APP_PATH=$(cd $(dirname $0) && pwd)
|
||||||
TMP_FILE=$(mktemp)
|
TMP_FILE=$(mktemp)
|
||||||
FINAL_FILE=minify.html
|
FINAL_FILE="${APP_PATH}/minify.html"
|
||||||
cp "$APP_PATH/index.html" "$TMP_FILE"
|
cp "$APP_PATH/index.html" "$TMP_FILE"
|
||||||
sed -ri "s/^\s+//" "$TMP_FILE"
|
sed -ri "s/^\s+//" "$TMP_FILE"
|
||||||
sed -ri "s=^//.*$==" "$TMP_FILE"
|
sed -ri "s=^//.*$==" "$TMP_FILE"
|
||||||
sed -ri 's="=\\"=g' "$TMP_FILE"
|
sed -ri 's="=\\"=g' "$TMP_FILE"
|
||||||
tr -d '\n' < "$TMP_FILE" > "$FINAL_FILE"
|
tr -d '\n' < "$TMP_FILE" > "$FINAL_FILE"
|
||||||
|
sed -Ei 's= {2,}= =g' "$FINAL_FILE"
|
||||||
cat "$FINAL_FILE"
|
cat "$FINAL_FILE"
|
||||||
|
rm "$TMP_FILE"
|
||||||
|
@ -29,7 +29,7 @@ def serve_file_in_dir(path):
|
|||||||
|
|
||||||
# Generate a random 12-bit integer (0 to 4095)
|
# Generate a random 12-bit integer (0 to 4095)
|
||||||
def random_12_bit_int():
|
def random_12_bit_int():
|
||||||
return random.randint(0, 0b111111111111)
|
return random.randint(0, 0b111111111111)
|
||||||
|
|
||||||
|
|
||||||
# Convert a binary stream to 24 integers
|
# Convert a binary stream to 24 integers
|
||||||
@ -37,7 +37,7 @@ def binary_stream_to_ints(binary_data):
|
|||||||
integers = []
|
integers = []
|
||||||
# Every 32-bit integer is represented by 2 bytes
|
# Every 32-bit integer is represented by 2 bytes
|
||||||
for i in range(0, len(binary_data), 2):
|
for i in range(0, len(binary_data), 2):
|
||||||
integers.append(int.from_bytes(binary_data[i:i + 2], byteorder='big') & 0b111111111111) # Extract 32-bit value
|
integers.append(int.from_bytes(binary_data[i:i + 2]) & 0b111111111111) # Extract 32-bit value
|
||||||
return integers
|
return integers
|
||||||
|
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ def get_schedule(plug_id):
|
|||||||
# Ensure integer is in 12-bit range
|
# Ensure integer is in 12-bit range
|
||||||
integer &= 0b111111111111
|
integer &= 0b111111111111
|
||||||
# Convert to bytes and append
|
# Convert to bytes and append
|
||||||
yield integer.to_bytes(2, byteorder='big') # 2 bytes per integer
|
yield integer.to_bytes(2) # 2 bytes per integer
|
||||||
|
|
||||||
# Return as a binary stream
|
# Return as a binary stream
|
||||||
return Response(ints_to_binary_stream(schedule), status=200, content_type='application/octet-stream')
|
return Response(ints_to_binary_stream(schedule), status=200, content_type='application/octet-stream')
|
||||||
|
Loading…
Reference in New Issue
Block a user