Apply astyle --style=otbs *.h *.cpp *.ino

This commit is contained in:
luc lebosse 2016-10-09 10:40:17 +02:00
parent fabf6c133f
commit 3ee67c022b
9 changed files with 1038 additions and 996 deletions

View File

@ -27,7 +27,8 @@ WiFiServer * data_server;
WiFiClient serverClients[MAX_SRV_CLIENTS];
#endif
bool BRIDGE::processFromSerial2TCP(){
bool BRIDGE::processFromSerial2TCP()
{
uint8_t i;
//check UART for data
if(Serial.available()) {
@ -46,11 +47,13 @@ WiFiClient serverClients[MAX_SRV_CLIENTS];
//process data if any
COMMAND::read_buffer_serial(sbuf, len);
return true;
} else {
return false;
}
else return false;
}
#ifdef TCP_IP_DATA_FEATURE
void BRIDGE::processFromTCP2Serial(){
void BRIDGE::processFromTCP2Serial()
{
uint8_t i,data;
//check if there are any new clients
if (data_server->hasClient()) {

View File

@ -44,18 +44,30 @@ String COMMAND::get_param(String & cmd_params, const char * id, bool withspace)
int end = -1;
parameter = "";
//if no id it means it is first part of cmd
if (strlen(id) == 0) start = 0;
if (strlen(id) == 0) {
start = 0;
}
//else find id position
else start = cmd_params.indexOf(id);
else {
start = cmd_params.indexOf(id);
}
//if no id found and not first part leave
if (start == -1 ) return parameter;
if (start == -1 ) {
return parameter;
}
//password and SSID can have space so handle it
//if no space expected use space as delimiter
if (!withspace)end = cmd_params.indexOf(" ",start);
if (!withspace) {
end = cmd_params.indexOf(" ",start);
}
//if space expected only one parameter but additional password may be present
else if (sid!="pwd=")end = cmd_params.indexOf("pwd=",start);
else if (sid!="pwd=") {
end = cmd_params.indexOf("pwd=",start);
}
//if no end found - take all
if (end == -1) end = cmd_params.length();
if (end == -1) {
end = cmd_params.length();
}
//extract parameter
parameter = cmd_params.substring(start+strlen(id),end);
//be sure no extra space
@ -75,8 +87,9 @@ bool COMMAND::isadmin(String & cmd_params)
if (!sadminPassword.equals(adminpassword)) {
LOG("Not allowed \n")
return false;
} else {
return true;
}
else return true;
}
#endif
void COMMAND::execute_command(int cmd,String cmd_params)
@ -89,12 +102,13 @@ void COMMAND::execute_command(int cmd,String cmd_params)
//[ESP100]<SSID>[pwd=<admin password>]
case 100:
parameter = get_param(cmd_params,"", true);
if (!CONFIG::isSSIDValid(parameter.c_str()))Serial.println(INCORRECT_CMD_MSG);
if (!CONFIG::isSSIDValid(parameter.c_str())) {
Serial.println(INCORRECT_CMD_MSG);
}
#ifdef AUTHENTICATION_FEATURE
if (!isadmin(cmd_params)) {
Serial.println(INCORRECT_CMD_MSG);
}
else
} else
#endif
if(!CONFIG::write_string(EP_STA_SSID,parameter.c_str())) {
Serial.println(ERROR_CMD_MSG);
@ -106,12 +120,13 @@ void COMMAND::execute_command(int cmd,String cmd_params)
//[ESP101]<Password>[pwd=<admin password>]
case 101:
parameter = get_param(cmd_params,"", true);
if (!CONFIG::isPasswordValid(parameter.c_str()))Serial.println(INCORRECT_CMD_MSG);
if (!CONFIG::isPasswordValid(parameter.c_str())) {
Serial.println(INCORRECT_CMD_MSG);
}
#ifdef AUTHENTICATION_FEATURE
if (!isadmin(cmd_params)) {
Serial.println(INCORRECT_CMD_MSG);
}
else
} else
#endif
if(!CONFIG::write_string(EP_STA_PASSWORD,parameter.c_str())) {
Serial.println(ERROR_CMD_MSG);
@ -123,12 +138,13 @@ void COMMAND::execute_command(int cmd,String cmd_params)
//[ESP102]<hostname>[pwd=<admin password>]
case 102:
parameter = get_param(cmd_params,"", true);
if (!CONFIG::isHostnameValid(parameter.c_str()))Serial.println(INCORRECT_CMD_MSG);
if (!CONFIG::isHostnameValid(parameter.c_str())) {
Serial.println(INCORRECT_CMD_MSG);
}
#ifdef AUTHENTICATION_FEATURE
if (!isadmin(cmd_params)) {
Serial.println(INCORRECT_CMD_MSG);
}
else
} else
#endif
if(!CONFIG::write_string(EP_HOSTNAME,parameter.c_str())) {
Serial.println(ERROR_CMD_MSG);
@ -151,8 +167,7 @@ void COMMAND::execute_command(int cmd,String cmd_params)
#ifdef AUTHENTICATION_FEATURE
if (!isadmin(cmd_params)) {
Serial.println(INCORRECT_CMD_MSG);
}
else
} else
#endif
if(!CONFIG::write_byte(EP_WIFI_MODE,mode)) {
Serial.println(ERROR_CMD_MSG);
@ -176,8 +191,7 @@ void COMMAND::execute_command(int cmd,String cmd_params)
#ifdef AUTHENTICATION_FEATURE
if (!isadmin(cmd_params)) {
Serial.println(INCORRECT_CMD_MSG);
}
else
} else
#endif
if(!CONFIG::write_byte(EP_STA_IP_MODE,mode)) {
Serial.println(ERROR_CMD_MSG);
@ -190,12 +204,13 @@ void COMMAND::execute_command(int cmd,String cmd_params)
//[ESP105]<SSID>[pwd=<admin password>]
case 105:
parameter = get_param(cmd_params,"", true);
if (!CONFIG::isSSIDValid(parameter.c_str()))Serial.println(INCORRECT_CMD_MSG);
if (!CONFIG::isSSIDValid(parameter.c_str())) {
Serial.println(INCORRECT_CMD_MSG);
}
#ifdef AUTHENTICATION_FEATURE
if (!isadmin(cmd_params)) {
Serial.println(INCORRECT_CMD_MSG);
}
else
} else
#endif
if(!CONFIG::write_string(EP_AP_SSID,parameter.c_str())) {
Serial.println(ERROR_CMD_MSG);
@ -207,12 +222,13 @@ void COMMAND::execute_command(int cmd,String cmd_params)
//[ESP106]<Password>[pwd=<admin password>]
case 106:
parameter = get_param(cmd_params,"", true);
if (!CONFIG::isPasswordValid(parameter.c_str()))Serial.println(INCORRECT_CMD_MSG);
if (!CONFIG::isPasswordValid(parameter.c_str())) {
Serial.println(INCORRECT_CMD_MSG);
}
#ifdef AUTHENTICATION_FEATURE
if (!isadmin(cmd_params)) {
Serial.println(INCORRECT_CMD_MSG);
}
else
} else
#endif
if(!CONFIG::write_string(EP_AP_PASSWORD,parameter.c_str())) {
Serial.println(ERROR_CMD_MSG);
@ -235,8 +251,7 @@ void COMMAND::execute_command(int cmd,String cmd_params)
#ifdef AUTHENTICATION_FEATURE
if (!isadmin(cmd_params)) {
Serial.println(INCORRECT_CMD_MSG);
}
else
} else
#endif
if(!CONFIG::write_byte(EP_AP_IP_MODE,mode)) {
Serial.println(ERROR_CMD_MSG);
@ -282,40 +297,40 @@ void COMMAND::execute_command(int cmd,String cmd_params)
parameter = get_param(cmd_params,"P", true);
LOG(parameter)
LOG("\n")
if (parameter == "")
{
if (parameter == "") {
Serial.println(INCORRECT_CMD_MSG);
}
else{
} else {
int pin = parameter.toInt();
//check pin is valid and not serial used pins
if ((pin >= 0) && (pin <= 16) && !((pin == 1) || (pin == 3)))
{
if ((pin >= 0) && (pin <= 16) && !((pin == 1) || (pin == 3))) {
//check if is set or get
parameter = get_param(cmd_params,"V", true);
//it is a get
if (parameter == "")
{ //GPIO16 is different than
if (pin <16) pinMode(pin, INPUT_PULLUP);
else pinMode(pin, INPUT_PULLDOWN_16);
if (parameter == "") {
//GPIO16 is different than
if (pin <16) {
pinMode(pin, INPUT_PULLUP);
} else {
pinMode(pin, INPUT_PULLDOWN_16);
}
delay(10);
int value = digitalRead(pin);
Serial.println(String(value));
}
else{
} else {
//it is a set
int value = parameter.toInt();
//verify it is a 0 or a 1
if ((value == 0) || (value == 1))
{
if ((value == 0) || (value == 1)) {
pinMode(pin, OUTPUT);
delay(10);
digitalWrite(pin, (value == 0)?LOW:HIGH);
}
else Serial.println(INCORRECT_CMD_MSG);
} else {
Serial.println(INCORRECT_CMD_MSG);
}
}
else Serial.println(INCORRECT_CMD_MSG);
} else {
Serial.println(INCORRECT_CMD_MSG);
}
}
}
break;
@ -329,8 +344,7 @@ void COMMAND::execute_command(int cmd,String cmd_params)
#ifdef AUTHENTICATION_FEATURE
if (!isadmin(cmd_params)) {
Serial.println(INCORRECT_CMD_MSG);
}
else
} else
#endif
{
if (parameter=="RESET") {
@ -350,39 +364,42 @@ void COMMAND::execute_command(int cmd,String cmd_params)
#ifdef AUTHENTICATION_FEATURE
//Change / Reset user password
//[ESP555]<password>pwd=<admin password>
case 555:
{
case 555: {
if (isadmin(cmd_params)) {
parameter = get_param(cmd_params,"", true);
if (parameter.length() == 0) {
if(CONFIG::write_string(EP_USER_PWD,FPSTR(DEFAULT_USER_PWD))) {
Serial.println(OK_CMD_MSG);
}
else {
} else {
Serial.println(ERROR_CMD_MSG);
}
} else {
if (CONFIG::isLocalPasswordValid(parameter.c_str())) {
if(CONFIG::write_string(EP_USER_PWD,parameter.c_str())) {
Serial.println(OK_CMD_MSG);
}
else {
} else {
Serial.println(ERROR_CMD_MSG);
}
}
else Serial.println(INCORRECT_CMD_MSG);
} else {
Serial.println(INCORRECT_CMD_MSG);
}
}
else Serial.println(INCORRECT_CMD_MSG);
} else {
Serial.println(INCORRECT_CMD_MSG);
}
break;
}
#endif
//[ESP700]<filename>
case 700: //read local file
{//be sure serial is locked
if ((web_interface->blockserial)) break;
case 700: { //read local file
//be sure serial is locked
if ((web_interface->blockserial)) {
break;
}
cmd_params.trim() ;
if ((cmd_params.length() > 0) && (cmd_params[0] != '/')) cmd_params = "/" + cmd_params;
if ((cmd_params.length() > 0) && (cmd_params[0] != '/')) {
cmd_params = "/" + cmd_params;
}
FSFILE currentfile = SPIFFS.open(cmd_params, "r");
if (currentfile) {//if file open success
//flush to be sure send buffer is empty
@ -390,8 +407,8 @@ void COMMAND::execute_command(int cmd,String cmd_params)
//read content
String currentline = currentfile.readString();
//until no line in file
while (currentline.length() >0)
{ //send line to serial
while (currentline.length() >0) {
//send line to serial
Serial.println(currentline);
//flush to be sure send buffer is empty
delay(0);
@ -649,12 +666,16 @@ void COMMAND::read_buffer_tcp(uint8_t b)
iscomment = false;
}
//is comment ?
if (char(b) == ';') iscomment = true;
if (char(b) == ';') {
iscomment = true;
}
//it is a char so add it to buffer
if (isPrintable(b)) {
previous_was_char=true;
//add char if not a comment
if (!iscomment)buffer_tcp+=char(b);
if (!iscomment) {
buffer_tcp+=char(b);
}
} else {
previous_was_char=false; //next call will reset the buffer
}
@ -680,11 +701,15 @@ void COMMAND::read_buffer_serial(uint8_t b)
iscomment = false;
}
//is comment ?
if (char(b) == ';') iscomment = true;
if (char(b) == ';') {
iscomment = true;
}
//it is a char so add it to buffer
if (isPrintable(b)) {
previous_was_char=true;
if (!iscomment)buffer_serial+=char(b);
if (!iscomment) {
buffer_serial+=char(b);
}
} else {
previous_was_char=false; //next call will reset the buffer
}

View File

@ -25,7 +25,8 @@ extern "C" {
}
void CONFIG::esp_restart(){
void CONFIG::esp_restart()
{
LOG("Restarting\n")
Serial.flush();
delay(500);
@ -270,7 +271,9 @@ bool CONFIG::read_string(int pos, String & sbuffer, int size_max)
//read until max size is reached or \0 is found
while (i < size_max && b != 0) {
b = EEPROM.read(pos+i);
if (b!=0)sbuffer+=char(b);
if (b!=0) {
sbuffer+=char(b);
}
i++;
}
EEPROM.end();
@ -324,8 +327,7 @@ bool CONFIG::write_string(int pos, const char * byte_buffer)
int maxsize = EEPROM_SIZE;
size_buffer= strlen(byte_buffer);
//check if parameters are acceptable
switch (pos)
{
switch (pos) {
case EP_ADMIN_PWD:
case EP_USER_PWD:
maxsize = MAX_LOCAL_PASSWORD_LENGTH;

View File

@ -417,8 +417,11 @@ void WEBINTERFACE_CLASS::GeLogin(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLA
if (auth_level != LEVEL_GUEST) {
ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE));
KeysList.add(FPSTR(KEY_LOGIN_ID));
if (auth_level == LEVEL_ADMIN) ValuesList.add(FPSTR(DEFAULT_ADMIN_LOGIN));
else ValuesList.add(FPSTR(DEFAULT_USER_LOGIN));
if (auth_level == LEVEL_ADMIN) {
ValuesList.add(FPSTR(DEFAULT_ADMIN_LOGIN));
} else {
ValuesList.add(FPSTR(DEFAULT_USER_LOGIN));
}
} else
#endif
{
@ -1176,8 +1179,11 @@ void handle_password()
if (msg_alert_error==false) {
//save
bool res;
if (auth_level == LEVEL_ADMIN) res = CONFIG::write_string(EP_ADMIN_PWD,sPassword.c_str()) ;
else res = CONFIG::write_string(EP_USER_PWD,sPassword.c_str()) ;
if (auth_level == LEVEL_ADMIN) {
res = CONFIG::write_string(EP_ADMIN_PWD,sPassword.c_str()) ;
} else {
res = CONFIG::write_string(EP_USER_PWD,sPassword.c_str()) ;
}
if (!res) {
msg_alert_error=true;
smsg = FPSTR(EEPROM_NOWRITE);
@ -2311,8 +2317,7 @@ void SPIFFSFileupload()
//get authentication status
level_authenticate_type auth_level= web_interface->is_authenticated();
//Guest cannot upload
if (auth_level == LEVEL_GUEST)
{
if (auth_level == LEVEL_GUEST) {
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
Serial.println("M117 Error ESP upload");
return;
@ -2324,33 +2329,33 @@ void SPIFFSFileupload()
if(upload.status == UPLOAD_FILE_START) {
String filename;
//according User or Admin the root is different as user is isolate to /user when admin has full access
if(auth_level == LEVEL_ADMIN) filename = upload.filename;
else filename = "/user" + upload.filename;
if(auth_level == LEVEL_ADMIN) {
filename = upload.filename;
} else {
filename = "/user" + upload.filename;
}
Serial.println("M117 Start ESP upload");
//create file
web_interface->fsUploadFile = SPIFFS.open(filename, "w");
filename = String();
//check If creation succeed
if (web_interface->fsUploadFile)
{ //if yes upload is started
if (web_interface->fsUploadFile) {
//if yes upload is started
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
}
else
{ //if no set cancel flag
} else {
//if no set cancel flag
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
Serial.println("M117 Error ESP create");
}
//Upload write
//**************
} else if(upload.status == UPLOAD_FILE_WRITE)
{ //check if file is availble and no error
if(web_interface->fsUploadFile && web_interface->_upload_status == UPLOAD_STATUS_ONGOING)
{
} else if(upload.status == UPLOAD_FILE_WRITE) {
//check if file is availble and no error
if(web_interface->fsUploadFile && web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
//no error so write post date
web_interface->fsUploadFile.write(upload.buf, upload.currentSize);
}
else
{ //we have a proble set flag UPLOAD_STATUS_CANCELLED
} else {
//we have a proble set flag UPLOAD_STATUS_CANCELLED
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
Serial.println("M117 Error ESP write");
}
@ -2359,13 +2364,12 @@ void SPIFFSFileupload()
} else if(upload.status == UPLOAD_FILE_END) {
Serial.println("M117 End ESP upload");
//check if file is still open
if(web_interface->fsUploadFile)
{ //close it
if(web_interface->fsUploadFile) {
//close it
web_interface->fsUploadFile.close();
web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL;
}
else
{ //we have a proble set flag UPLOAD_STATUS_CANCELLED
} else {
//we have a proble set flag UPLOAD_STATUS_CANCELLED
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
Serial.println("M117 Error ESP close");
}
@ -2390,8 +2394,7 @@ void SDFileupload()
static bool is_comment = false;
String response;
//Guest cannot upload - only admin and user
if(web_interface->is_authenticated() == LEVEL_GUEST)
{
if(web_interface->is_authenticated() == LEVEL_GUEST) {
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
Serial.println("M117 SD upload failed");
LOG("SD upload failed\n");
@ -2433,7 +2436,9 @@ void SDFileupload()
//use string because easier to handle
response = (const char*)sbuf;
//if there is a wait it means purge is done
if (response.indexOf("wait")>-1)break;
if (response.indexOf("wait")>-1) {
break;
}
}
delay(5);
}
@ -2442,10 +2447,8 @@ void SDFileupload()
//upload is on going with data coming by 2K blocks
} else if((upload.status == UPLOAD_FILE_WRITE) && (com_error == false)) { //if com error no need to send more data to serial
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
for (int pos = 0; pos < upload.currentSize;pos++) //parse full post data
{
if (buffer_size < MAX_RESEND_BUFFER-1) //raise error/handle if overbuffer - copy is space available
{
for (int pos = 0; pos < upload.currentSize; pos++) { //parse full post data
if (buffer_size < MAX_RESEND_BUFFER-1) { //raise error/handle if overbuffer - copy is space available
//remove/ignore every comment to save transfert time and avoid over buffer issues
if (upload.buf[pos] == ';') {
is_comment = true;
@ -2457,22 +2460,19 @@ void SDFileupload()
//convert buffer to zero end array
buffer_line[buffer_size] = '\0';
//check it is not an end line char and line is not empty
if (((buffer_line[0] == '\n') && (buffer_size==1)) ||((buffer_line[1] == '\n') && (buffer_line[0] == '\r') && (buffer_size==2)) || ((buffer_line[0] == ' ') && (buffer_size==1)) )
{
if (((buffer_line[0] == '\n') && (buffer_size==1)) ||((buffer_line[1] == '\n') && (buffer_line[0] == '\r') && (buffer_size==2)) || ((buffer_line[0] == ' ') && (buffer_size==1)) ) {
//ignore empty line
buffer_size=0;
buffer_line[buffer_size] = '\0';
}
//line is not empty so check if last char is an end line
//if error no need to proceed
else if (((buffer_line[buffer_size-1] == '\n')) && (com_error == false)) //end of line and no error
{
else if (((buffer_line[buffer_size-1] == '\n')) && (com_error == false)) { //end of line and no error
//if resend use buffer
bool success = false;
//check NB_RETRY times if get no error when send line
for (int r = 0 ; r < NB_RETRY ; r++)
{
for (int r = 0 ; r < NB_RETRY ; r++) {
response = "";
//print out line
Serial.print(buffer_line);
@ -2510,7 +2510,9 @@ void SDFileupload()
delay(5);
}
//if command is pass no need to retry
if (success == true)break;
if (success == true) {
break;
}
//purge extra serial if any
if(Serial.available()) {
//get size of available data
@ -2533,25 +2535,25 @@ void SDFileupload()
buffer_size = 0;
buffer_line[buffer_size] = '\0';
}
}
else { //it is a comment
} else { //it is a comment
if (upload.buf[pos] == '\r') { //store if CR
previous = '\r';
}
else if (upload.buf[pos] == '\n'){ //this is the end of the comment
} else if (upload.buf[pos] == '\n') { //this is the end of the comment
is_comment = false;
if (buffer_size > 0) {
if (previous == '\r') pos--;
if (previous == '\r') {
pos--;
}
pos--; //do a loop back and process as normal
}
previous = '\n';
}//if not just ignore and continue
else previous = upload.buf[pos];
else {
previous = upload.buf[pos];
}
}
}
else //raise error
{
} else { //raise error
LOG("\nlong line detected\n");
LOG(buffer_line);
com_error = true;
@ -2563,14 +2565,16 @@ void SDFileupload()
if (buffer_size > 0) { //if last part does not have '\n'
//print the line
Serial.print(buffer_line);
if (is_comment && (previous == '\r'))Serial.print("\r\n");
else Serial.print("\n");
if (is_comment && (previous == '\r')) {
Serial.print("\r\n");
} else {
Serial.print("\n");
}
Serial.flush();
//if resend use buffer
bool success = false;
//check NB_RETRY times if get no error when send line
for (int r = 0 ; r < NB_RETRY ; r++)
{
for (int r = 0 ; r < NB_RETRY ; r++) {
response = "";
Serial.print(buffer_line);
Serial.flush();
@ -2593,7 +2597,9 @@ void SDFileupload()
}
delay(5);
}
if (success == true)break;
if (success == true) {
break;
}
}
if (!success) {
//raise error
@ -2622,9 +2628,7 @@ void SDFileupload()
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
Serial.println("M117 SD upload failed");
Serial.flush();
}
else
{
} else {
LOG("with success\n");
web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL;
Serial.println("M117 SD upload done");
@ -2657,8 +2661,7 @@ void WebUpdateUpload()
static size_t last_upload_update;
static uint32_t maxSketchSpace ;
//only admin can update FW
if(web_interface->is_authenticated() != LEVEL_ADMIN)
{
if(web_interface->is_authenticated() != LEVEL_ADMIN) {
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
Serial.println("M117 Update failed");
LOG("SD Update failed\n");
@ -2676,14 +2679,14 @@ void WebUpdateUpload()
last_upload_update = 0;
if(!Update.begin(maxSketchSpace)) { //start with max available size
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
} else {
Serial.println(F("M117 Update 0%"));
}
else Serial.println(F("M117 Update 0%"));
//Upload write
//**************
} else if(upload.status == UPLOAD_FILE_WRITE) {
//check if no error
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING)
{
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
//we do not know the total file size yet but we know the available space so let's use it
if ( ((100 * upload.totalSize) / maxSketchSpace) !=last_upload_update) {
last_upload_update = (100 * upload.totalSize) / maxSketchSpace;
@ -2691,8 +2694,7 @@ void WebUpdateUpload()
Serial.print(last_upload_update);
Serial.println(F("%"));
}
if(Update.write(upload.buf, upload.currentSize) != upload.currentSize)
{
if(Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
}
}
@ -2738,14 +2740,21 @@ void handleFileList()
String path ;
String status = "Ok";
//be sure root is correct according authentication
if (auth_level == LEVEL_ADMIN) path = "/";
else path = "/user";
if (auth_level == LEVEL_ADMIN) {
path = "/";
} else {
path = "/user";
}
//get current path
if(web_interface->WebServer.hasArg("path"))path += web_interface->WebServer.arg("path") ;
if(web_interface->WebServer.hasArg("path")) {
path += web_interface->WebServer.arg("path") ;
}
//to have a clean path
path.trim();
path.replace("//","/");
if (path[path.length()-1] !='/')path +="/";
if (path[path.length()-1] !='/') {
path +="/";
}
//check if query need some action
if(web_interface->WebServer.hasArg("action")) {
//delete a file
@ -2758,18 +2767,18 @@ void handleFileList()
if(!SPIFFS.exists(filename)) {
status = shortname + F(" does not exists!");
} else {
if (SPIFFS.remove(filename))
{
if (SPIFFS.remove(filename)) {
status = shortname + F(" deleted");
//what happen if no "/." and no other subfiles ?
FSDIR dir = SPIFFS.openDir(path);
if (!dir.next())
{ //keep directory alive even empty
if (!dir.next()) {
//keep directory alive even empty
FSFILE r = SPIFFS.open(path+"/.","w");
if (r)r.close();
if (r) {
r.close();
}
}
else {
} else {
status = F("Cannot deleted ") ;
status+=shortname ;
}
@ -2783,8 +2792,7 @@ void handleFileList()
filename = path + web_interface->WebServer.arg("filename");
filename += "/.";
filename.replace("//","/");
if (filename != "/")
{
if (filename != "/") {
bool delete_error = false;
FSDIR dir = SPIFFS.openDir(path + shortname);
{
@ -2817,8 +2825,7 @@ void handleFileList()
if (!r) {
status = F("Cannot create ");
status += shortname ;
}
else {
} else {
r.close();
status = shortname + F(" created");
}
@ -2844,33 +2851,26 @@ void handleFileList()
filename = filename.substring(0,filename.indexOf("/"));
String tag="*";
tag = filename + "*";
if (subdirlist.indexOf(tag)>-1) //already in list
{
if (subdirlist.indexOf(tag)>-1) { //already in list
addtolist = false; //no need to add
}
else
{
} else {
size = -1; //it is subfile so display only directory, size will be -1 to describe it is directory
if (subdirlist.length()==0)subdirlist+="*";
if (subdirlist.length()==0) {
subdirlist+="*";
}
subdirlist += filename + "*"; //add to list
}
}
else
{
} else {
//do not add "." file
if (filename!=".")
{
if (filename!=".") {
FSFILE f = dir.openFile("r");
size = CONFIG::formatBytes(f.size());
f.close();
}
else
{
} else {
addtolist = false;
}
}
if(addtolist)
{
if(addtolist) {
if (!firstentry) {
jsonfile+=",";
} else {
@ -2913,11 +2913,15 @@ void handleSDFileList()
uint32_t totalspace = 0;
uint32_t usedspace = 0;
//get current path
if(web_interface->WebServer.hasArg("path"))path += web_interface->WebServer.arg("path") ;
if(web_interface->WebServer.hasArg("path")) {
path += web_interface->WebServer.arg("path") ;
}
//to have a clean path
path.trim();
path.replace("//","/");
if (path[path.length()-1] !='/')path +="/";
if (path[path.length()-1] !='/') {
path +="/";
}
//check if query need some action
if(web_interface->WebServer.hasArg("action")) {
LOG("action requested\n")
@ -2974,8 +2978,7 @@ void handleSDFileList()
if ((web_interface->blockserial)) {
LOG("Wait, blocking\n");
jsonfile+="\"status\":\"processing\",\"mode\":\"serial\"}";
}
else
} else
#endif
{
jsonfile+="\"files\":[";
@ -2992,22 +2995,18 @@ void handleSDFileList()
sname = web_interface->fileslist.get(i);
#if FIRMWARE_TARGET == REPETIER4DV || FIRMWARE_TARGET == REPETIER
//check if directory or file
if (sname[0] == '/' || sname[sname.length()-1]=='/')
{
if (sname[0] == '/' || sname[sname.length()-1]=='/') {
jsonfile+=sname;
jsonfile+="\",\"size\":\"";
LOG(String(i+1));
LOG(sname);
jsonfile+="-1";
LOG(" -1");
}
else //it is a file
{
} else { //it is a file
//get size position
int posspace = sname.indexOf(" ");
String ssize;
if (posspace !=-1)
{
if (posspace !=-1) {
ssize = sname.substring(posspace+1);
sname = sname.substring(0,posspace);
}
@ -3025,13 +3024,11 @@ void handleSDFileList()
jsonfile+="\",\"size\":\"";
LOG(String(i+1));
LOG(sname);
if (sname[0] == '/' || sname[sname.length()-1]=='/')
{
if (sname[0] == '/' || sname[sname.length()-1]=='/') {
jsonfile+="-1";
LOG(" -1");
}
else
{//nothing to add
} else {
//nothing to add
jsonfile+="";
}
LOG("\n");
@ -3085,10 +3082,11 @@ void handle_not_found()
web_interface->WebServer.streamFile(file, contentType);
file.close();
return;
} else page_not_found = true;
} else {
page_not_found = true;
}
if (page_not_found )
{
if (page_not_found ) {
LOG("Page not found it \n")
if (SPIFFS.exists("/404.tpl")) {
STORESTRINGS_CLASS KeysList ;
@ -3195,8 +3193,11 @@ void handle_login()
if (msg_alert_error==false) {
#ifdef AUTHENTICATION_FEATURE
auth_ip * current_auth = new auth_ip;
if(sUser==FPSTR(DEFAULT_ADMIN_LOGIN))current_auth->level = LEVEL_ADMIN;
else current_auth->level = LEVEL_USER;
if(sUser==FPSTR(DEFAULT_ADMIN_LOGIN)) {
current_auth->level = LEVEL_ADMIN;
} else {
current_auth->level = LEVEL_USER;
}
current_auth->ip=web_interface->WebServer.client().remoteIP();
strcpy(current_auth->sessionID,web_interface->create_session_ID());
current_auth->last_time=millis();
@ -3328,11 +3329,12 @@ void handle_web_command()
}
//if not is not a valid [ESPXXX] command
}
}
else {
} else {
//send command to serial as no need to transfer ESP command
//to avoid any pollution if Uploading file to SDCard
if ((web_interface->blockserial) == false)Serial.println(scmd);
if ((web_interface->blockserial) == false) {
Serial.println(scmd);
}
}
}
}
@ -3540,8 +3542,7 @@ String WEBINTERFACE_CLASS::getContentType(String filename)
return "image/gif";
} else if(filename.endsWith(".jpeg")) {
return "image/jpeg";
}
else if(filename.endsWith(".jpg")) {
} else if(filename.endsWith(".jpg")) {
return "image/jpeg";
} else if(filename.endsWith(".ico")) {
return "image/x-icon";

View File

@ -43,8 +43,12 @@ WIFI_CONFIG::WIFI_CONFIG()
int32_t WIFI_CONFIG::getSignal(int32_t RSSI)
{
if (RSSI <= -100) return 0;
if (RSSI >= -50) return 100;
if (RSSI <= -100) {
return 0;
}
if (RSSI >= -50) {
return 100;
}
return (2* (RSSI+100));
}
@ -114,8 +118,7 @@ bool WIFI_CONFIG::Setup(bool force_ap)
sleep_mode=bflag;
if (force_ap) {
bmode = AP_MODE;
}
else {
} else {
//AP or client ?
if (!CONFIG::read_byte(EP_WIFI_MODE, &bmode ) ) {
LOG("Error read wifi mode\n")
@ -128,8 +131,12 @@ bool WIFI_CONFIG::Setup(bool force_ap)
//this is AP mode
if (bmode==AP_MODE) {
LOG("Set AP mode\n")
if(!CONFIG::read_string(EP_AP_SSID, sbuf , MAX_SSID_LENGTH))return false;
if(!CONFIG::read_string(EP_AP_PASSWORD, pwd , MAX_PASSWORD_LENGTH))return false;
if(!CONFIG::read_string(EP_AP_SSID, sbuf , MAX_SSID_LENGTH)) {
return false;
}
if(!CONFIG::read_string(EP_AP_PASSWORD, pwd , MAX_PASSWORD_LENGTH)) {
return false;
}
Serial.print(FPSTR(M117_));
Serial.print(F("SSID "));
Serial.println(sbuf);
@ -222,8 +229,12 @@ bool WIFI_CONFIG::Setup(bool force_ap)
}
} else {
LOG("Set STA mode\n")
if(!CONFIG::read_string(EP_STA_SSID, sbuf , MAX_SSID_LENGTH))return false;
if(!CONFIG::read_string(EP_STA_PASSWORD, pwd , MAX_PASSWORD_LENGTH))return false;
if(!CONFIG::read_string(EP_STA_SSID, sbuf , MAX_SSID_LENGTH)) {
return false;
}
if(!CONFIG::read_string(EP_STA_PASSWORD, pwd , MAX_PASSWORD_LENGTH)) {
return false;
}
Serial.print(FPSTR(M117_));
Serial.print(F("SSID "));
Serial.println(sbuf);