This commit is contained in:
Jelmer
2023-01-22 01:46:16 +01:00
5 changed files with 11 additions and 8 deletions

View File

@@ -26,6 +26,7 @@
<form action="send_image" method="POST" target="empty">
DST:<input name="dst" class="dst" size=12 maxlength=12 type="text" placeholder="001122334455">
Filename:<input name="filename" type="text" placeholder="default.bmp">
Next check-in:<input name="ttl" type="text" placeholder="1"> min
<input type="submit" value="Send Image">
</form>
</div>

View File

@@ -45,15 +45,14 @@ struct AvailDataInfo {
uint64_t dataVer;
uint32_t dataSize;
uint8_t dataType;
uint16_t nextCheckIn;
} __packed;
struct pendingData {
struct AvailDataInfo availdatainfo;
uint8_t attemptsLeft;
uint16_t attemptsLeft;
uint8_t targetMac[8];
} __packed;
#define BLOCK_DATA_SIZE 4096
#define BLOCK_XFER_BUFFER_SIZE BLOCK_DATA_SIZE + sizeof(struct blockData)

View File

@@ -4,7 +4,7 @@ extern void addCRC(void* p, uint8_t len);
extern bool checkCRC(void* p, uint8_t len);
extern void processBlockRequest(struct espBlockRequest* br);
extern bool prepareDataAvail(String* filename, uint8_t dataType, uint8_t* dst);
extern bool prepareDataAvail(String* filename, uint8_t dataType, uint8_t* dst, uint16_t nextCheckin);
extern void processJoinNetwork(struct espJoinNetwork* xjn);
extern void processXferComplete(struct espXferComplete* xfc);
extern void processDataReq(struct espAvailDataReq* adr);

View File

@@ -47,7 +47,7 @@ void prepareCancelPending(uint64_t ver) {
sendCancelPending(&pending);
}
bool prepareDataAvail(String* filename, uint8_t dataType, uint8_t* dst) {
bool prepareDataAvail(String* filename, uint8_t dataType, uint8_t* dst, uint16_t nextCheckin) {
*filename = "/" + *filename;
if (!LittleFS.exists(*filename)) return false;
File file = LittleFS.open(*filename);
@@ -72,6 +72,7 @@ bool prepareDataAvail(String* filename, uint8_t dataType, uint8_t* dst) {
pending.availdatainfo.dataType = dataType;
pending.availdatainfo.dataVer = *((uint64_t*)md5bytes);
pending.availdatainfo.dataSize = file.size();
pending.availdatainfo.nextCheckIn = nextCheckin;
pending.attemptsLeft = 10;
sendDataAvail(&pending);

View File

@@ -234,9 +234,11 @@ void init_web() {
server.on("/send_image", HTTP_POST, [](AsyncWebServerRequest *request) {
String filename;
String dst;
uint16_t nextCheckin;
if (request->hasParam("filename", true) && request->hasParam("dst", true)) {
filename = request->getParam("filename", true)->value();
dst = request->getParam("dst", true)->value();
nextCheckin = request->getParam("ttl",true)->value().toInt();
uint8_t mac_addr[12]; // I expected this to return like 8 values, but if I make the array 8 bytes long, things die.
mac_addr[0] = 0x00;
mac_addr[1] = 0x00;
@@ -250,7 +252,7 @@ void init_web() {
request->send(200, "text/plain", "Something went wrong trying to parse the mac address");
} else {
*((uint64_t *)mac_addr) = swap64(*((uint64_t *)mac_addr));
if (prepareDataAvail(&filename, DATATYPE_IMGRAW, mac_addr)) {
if (prepareDataAvail(&filename, DATATYPE_IMGRAW, mac_addr, nextCheckin)) {
request->send(200, "text/plain", "Sending to " + dst);
} else {
request->send(200, "text/plain", "Couldn't find filename :(");
@@ -281,7 +283,7 @@ void init_web() {
request->send(200, "text/plain", "Something went wrong trying to parse the mac address");
} else {
*((uint64_t *)mac_addr) = swap64(*((uint64_t *)mac_addr));
if (prepareDataAvail(&filename, DATATYPE_UPDATE, mac_addr)) {
if (prepareDataAvail(&filename, DATATYPE_UPDATE, mac_addr, 0)) {
request->send(200, "text/plain", "Sending FW to " + dst);
} else {
request->send(200, "text/plain", "Couldn't find filename :(");
@@ -311,7 +313,7 @@ void init_web() {
request->send(200, "text/plain", "Something went wrong trying to parse the mac address");
} else {
*((uint64_t *)mac_addr) = swap64(*((uint64_t *)mac_addr));
if (prepareDataAvail(&filename, DATATYPE_NOUPDATE, mac_addr)) {
if (prepareDataAvail(&filename, DATATYPE_NOUPDATE, mac_addr,0)) {
request->send(200, "text/plain", "Sending check-in request to " + dst);
}
}