MCPcopy Create free account
hub / github.com/BruceDevices/firmware / receiveFile

Method receiveFile

src/core/connect/file_sharing.cpp:62–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62void FileSharing::receiveFile() {
63 drawMainBorderWithTitle("RECEIVE FILE");
64 padprintln("");
65 padprintln("Waiting...");
66
67 recvFileName = "";
68 recvQueue = {};
69 recvStatus = CONNECTING;
70
71 if (!beginEspnow()) return;
72
73 delay(100);
74
75 while (1) {
76 if (check(EscPress)) recvStatus = ABORTED;
77
78 if (recvStatus == ABORTED || recvStatus == FAILED) {
79 displayError("Error receiving file");
80 break;
81 }
82 if (recvStatus == SUCCESS) {
83 displaySuccess("File received");
84 break;
85 }
86
87 if (!recvQueue.empty()) {
88 Message recvFileMessage = recvQueue.front();
89 recvQueue.erase(recvQueue.begin());
90
91 progressHandler(recvFileMessage.bytesSent, recvFileMessage.totalBytes, "Receiving...");
92
93 if (!appendToFile(recvFileMessage)) {
94 recvStatus = FAILED;
95 Serial.println("Failed appending to file");
96 }
97 if (recvFileMessage.done) {
98 Serial.println("Recv done");
99 recvStatus = recvFileMessage.bytesSent == recvFileMessage.totalBytes ? SUCCESS : FAILED;
100 }
101 }
102
103 delay(100);
104 }
105
106 delay(1000);
107
108 if (recvStatus == SUCCESS) {
109 drawMainBorderWithTitle("RECEIVE FILE");
110 padprintln("");
111 padprintln("File received: ");
112 padprintln(recvFileName);
113 padprintln("\n");
114 padprintln("Press any key to leave");
115 while (!check(AnyKeyPress)) vTaskDelay(50 / portTICK_PERIOD_MS);
116 ;
117 }
118}
119

Callers 2

optionsMenuMethod · 0.80
optionsMenuMethod · 0.80

Calls 9

drawMainBorderWithTitleFunction · 0.85
padprintlnFunction · 0.85
checkFunction · 0.85
displayErrorFunction · 0.85
displaySuccessFunction · 0.85
progressHandlerFunction · 0.85
eraseMethod · 0.45
beginMethod · 0.45
printlnMethod · 0.45

Tested by

no test coverage detected