added test parts of the code for various errors

pull/25/head
Miroslav Pivovarsky 2024-05-13 21:53:56 +02:00
parent 41f32f7033
commit 49f89e94fd
6 changed files with 49 additions and 13 deletions

View File

@ -277,6 +277,7 @@ void Camera::CapturePhoto() {
log->AddEvent(LogLevel_Info, F("Taking photo..."));
/* capture final photo */
delay(5); // delay for camera stabilization. test it
FrameBuffer = esp_camera_fb_get();
if (!FrameBuffer) {
log->AddEvent(LogLevel_Error, F("Camera capture failed! photo"));
@ -476,7 +477,8 @@ void Camera::CopyPhoto(String* i_data, int i_from, int i_to) {
* @return int - photo size
*/
int Camera::GetPhotoSize() {
return FrameBuffer->len;
log->AddEvent(LogLevel_Verbose, "Photo size: " + String(FrameBuffer->len));
return (int) FrameBuffer->len;
}
/**

View File

@ -258,7 +258,13 @@ void Configuration::GetFingerprint() {
*/
void Configuration::SaveUint8(uint16_t address, uint8_t data) {
EEPROM.write(address, data);
EEPROM.commit();
if (EEPROM.commit()) {
Log->AddEvent(LogLevel_Verbose, F("Write uint8_t done"));
} else {
Log->AddEvent(LogLevel_Error, F("Failed to write uint8_t"));
EEPROM.commit(); // try again
}
}
/**
@info Function for save int8_t to EEPROM
@ -268,7 +274,13 @@ void Configuration::SaveUint8(uint16_t address, uint8_t data) {
*/
void Configuration::SaveInt8(uint16_t address, int8_t data) {
EEPROM.write(address, data);
EEPROM.commit();
if (EEPROM.commit()) {
Log->AddEvent(LogLevel_Verbose, F("Write int8_t done"));
} else {
Log->AddEvent(LogLevel_Error, F("Failed to write int8_t"));
EEPROM.commit(); // try again
}
}
/**
@info Function for save bool to EEPROM
@ -278,7 +290,13 @@ void Configuration::SaveInt8(uint16_t address, int8_t data) {
*/
void Configuration::SaveBool(uint16_t address, bool data) {
EEPROM.write(address, data);
EEPROM.commit();
if (EEPROM.commit()) {
Log->AddEvent(LogLevel_Verbose, F("Write bool done"));
} else {
Log->AddEvent(LogLevel_Error, F("Failed to write bool"));
EEPROM.commit(); // try again
}
}
/**
@info Function for save uint16_t to EEPROM
@ -292,7 +310,13 @@ void Configuration::SaveUint16(uint16_t address, uint16_t data) {
EEPROM.write(address, highByte);
EEPROM.write(address + 1, lowByte);
EEPROM.commit();
if (EEPROM.commit()) {
Log->AddEvent(LogLevel_Verbose, F("Write uint16_t done"));
} else {
Log->AddEvent(LogLevel_Error, F("Failed to write uint16_t"));
EEPROM.commit(); // try again
}
}
/**
@ -311,8 +335,13 @@ void Configuration::SaveString(uint16_t address, uint16_t max_length, String dat
for (uint16_t i = address + 1, j = 0; j < data.length(); i++, j++) {
EEPROM.write(i, data.charAt(j));
}
EEPROM.commit();
if (EEPROM.commit()) {
Log->AddEvent(LogLevel_Verbose, F("Write string done"));
} else {
Log->AddEvent(LogLevel_Error, F("Failed to write string"));
EEPROM.commit(); // try again
}
} else {
Log->AddEvent(LogLevel_Verbose, F("Skip write string"));
}
@ -331,7 +360,12 @@ void Configuration::SaveIpAddress(uint16_t address, String data) {
EEPROM.write(address + 1, ip[1]);
EEPROM.write(address + 2, ip[2]);
EEPROM.write(address + 3, ip[3]);
EEPROM.commit();
if (EEPROM.commit()) {
Log->AddEvent(LogLevel_Verbose, F("Write IP address done"));
} else {
Log->AddEvent(LogLevel_Error, F("Failed to write IP address"));
}
}
}

View File

@ -78,7 +78,7 @@ bool PrusaConnect::SendDataToBackend(String *i_data, int i_data_length, String i
WiFiClientSecure client;
BackendReceivedStatus = "";
bool ret = false;
log->AddEvent(LogLevel_Info, "Sending " + i_type + " to PrusaConnect");
log->AddEvent(LogLevel_Info, "Sending " + i_type + " to PrusaConnect, " + String(i_data_length) + " bytes");
/* check fingerprint and token length */
if ((Fingerprint.length() > 0) && (Token.length() > 0)) {
@ -119,7 +119,7 @@ bool PrusaConnect::SendDataToBackend(String *i_data, int i_data_length, String i
log->AddEvent(LogLevel_Verbose, F("Send data photo"));
int index = 0;
/* send data in fragments */
for (index = 0; index < i_data_length; index = index + PHOTO_FRAGMENT_SIZE) {
for (index = 0; index < i_data_length; index += PHOTO_FRAGMENT_SIZE) {
camera->CopyPhoto(i_data, index, index + PHOTO_FRAGMENT_SIZE);
client.print(*i_data);
log->AddEvent(LogLevel_Verbose, String(i_data_length) + "/" + String(index));

View File

@ -62,7 +62,7 @@ private:
Logs *log; ///< pointer to logs object
Camera *camera; ///< pointer to camera object
bool SendDataToBackend(String *,int, String, String, String, SendDataToBackendType);
bool SendDataToBackend(String *, int, String, String, String, SendDataToBackendType);
public:
PrusaConnect(Configuration*, Logs*, Camera*);

View File

@ -253,7 +253,7 @@ String Logs::GetSystemTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
#if (true == CONSOLE_VERBOSE_DEBUG)
Serial.println("Failed to obtain time");
Serial.println(F("Failed to obtain time"));
#endif
return ret;
}

View File

@ -146,7 +146,7 @@ String lastTwoChars = command.substring(command.length() - 2);
ESP.restart();
} else if (command.startsWith("commandslist") && command.endsWith(";")) {
log->AddEvent(LogLevel_Warning, "--> Available commands");
log->AddEvent(LogLevel_Warning, F("--> Available commands"));
PrintAvailableCommands();
} else {