Skip to content

Commit 63fa8b1

Browse files
authored
Add files via upload
1 parent 3f11b57 commit 63fa8b1

14 files changed

+815
-519
lines changed

servers/dmesg_functions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
- Use dmesg telnet command to display messages in message queue.
1010
11-
March 12, 2023, Bojan Jurca
11+
December 25, 2023, Bojan Jurca
1212
1313
*/
1414

@@ -94,19 +94,19 @@
9494

9595
__dmesgType__ __dmesgCircularQueue__ [DMESG_CIRCULAR_QUEUE_LENGTH];
9696

97-
RTC_DATA_ATTR unsigned int bootCount = 0;
97+
// RTC_DATA_ATTR unsigned int bootCount = 0;
9898

9999
bool __initializeDmesgCircularQueue__ () {
100100
__dmesgCircularQueue__ [0].message = fsString<DMESG_MAX_MESSAGE_LENGTH> ("[ESP32] CPU0 reset reason: ") + resetReason (rtc_get_reset_reason (0));
101101
__dmesgCircularQueue__ [1].message = fsString<DMESG_MAX_MESSAGE_LENGTH> ("[ESP32] CPU1 reset reason: ") + resetReason (rtc_get_reset_reason (1));
102102
__dmesgCircularQueue__ [2].message = fsString<DMESG_MAX_MESSAGE_LENGTH> ("[ESP32] wakeup reason: ") + wakeupReason ();
103-
__dmesgCircularQueue__ [3].message = fsString<DMESG_MAX_MESSAGE_LENGTH> ("[ESP32] (re)started ") + fsString<DMESG_MAX_MESSAGE_LENGTH> (++ bootCount) + (char *) " times";
103+
// __dmesgCircularQueue__ [3].message = fsString<DMESG_MAX_MESSAGE_LENGTH> ("[ESP32] (re)started ") + fsString<DMESG_MAX_MESSAGE_LENGTH> (++ bootCount) + (char *) " times";
104104
return true;
105105
}
106106
bool __initializedDmesgCircularQueue__ = __initializeDmesgCircularQueue__ ();
107107

108108
byte __dmesgBeginning__ = 0; // first used location
109-
byte __dmesgEnd__ = 4; // the location next to be used
109+
byte __dmesgEnd__ = 3; // 4; // the location next to be used
110110
static SemaphoreHandle_t __dmesgSemaphore__= xSemaphoreCreateMutex ();
111111

112112
// adds message to dmesg circular queue

servers/ftpClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
}
113113
}
114114
else if (ftpReplyIs ("230 ")) { // server said that we have logged in, initiate pasive data connection
115-
if (sendAll (controlConnectionSocket, (char *) "PASV\r\n", FTP_CLIENT_TIME_OUT) == -1) {
115+
if (sendAll (controlConnectionSocket, "PASV\r\n", FTP_CLIENT_TIME_OUT) == -1) {
116116
string e = string (errno) + (char *) " " + strerror (errno);
117117
close (controlConnectionSocket);
118118
return string ("send error: ") + e;

servers/ftpServer.hpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
FTP server reads and executes FTP commands. The transfer of files in active in passive mode is supported but some of the commands may
88
9-
October 23, 2023, Bojan Jurca
9+
December 25, 2023, Bojan Jurca
1010
1111
Nomenclature used here for easier understaning of the code:
1212
@@ -90,6 +90,11 @@
9090
// control ftpServer critical sections
9191
static SemaphoreHandle_t __ftpServerSemaphore__ = xSemaphoreCreateMutex ();
9292

93+
// log what is going on within telnetServer
94+
byte ftpServerConcurentTasks = 0;
95+
byte ftpServerConcurentTasksHighWatermark = 0;
96+
97+
9398
// cycle through set of port numbers when FTP server is working in pasive mode
9499
int __pasiveDataPort__ () {
95100
static int lastPasiveDataPort = 1024; // change pasive data port range if needed
@@ -132,12 +137,24 @@
132137
if (pdPASS != taskCreated) {
133138
dmesg ("[ftpControlConnection] xTaskCreate error");
134139
} else {
135-
__state__ = RUNNING;
136-
}
140+
__state__ = RUNNING;
137141

142+
xSemaphoreTake (__ftpServerSemaphore__, portMAX_DELAY);
143+
ftpServerConcurentTasks++;
144+
if (ftpServerConcurentTasks > ftpServerConcurentTasksHighWatermark)
145+
ftpServerConcurentTasksHighWatermark = ftpServerConcurentTasks;
146+
xSemaphoreGive (__ftpServerSemaphore__);
147+
148+
return; // success
149+
}
150+
dmesg ("[ftpConnection] xTaskCreate error"); // failure
138151
}
139152

140153
~ftpControlConnection () {
154+
xSemaphoreTake (__ftpServerSemaphore__, portMAX_DELAY);
155+
ftpServerConcurentTasks--;
156+
xSemaphoreGive (__ftpServerSemaphore__);
157+
141158
closeControlConnection ();
142159
closeDataConnection ();
143160
}
@@ -182,7 +199,7 @@
182199

183200
// writing output to FTP control connection with error logging (dmesg)
184201
int sendFtp (char *buf) {
185-
int i = sendAll (__controlConnectionSocket__, buf, strlen (buf), FTP_CONTROL_CONNECTION_TIME_OUT);
202+
int i = sendAll (__controlConnectionSocket__, buf, FTP_CONTROL_CONNECTION_TIME_OUT);
186203
if (i <= 0)
187204
dmesg ("[ftpControlConnection] send error: ", errno, strerror (errno));
188205
return i;
@@ -716,9 +733,9 @@
716733
STATE_TYPE state () { return __state__; }
717734

718735
ftpServer ( // the following parameters will be handeled by ftpServer instance
719-
const char *serverIP, // FTP server IP address, 0.0.0.0 for all available IP addresses
720-
int serverPort, // FTP server port
721-
bool (*firewallCallback) (char *connectingIP) // a reference to callback function that will be celled when new connection arrives
736+
const char *serverIP = "0.0.0.0", // FTP server IP address, 0.0.0.0 for all available IP addresses
737+
int serverPort = 21, // FTP server port
738+
bool (*firewallCallback) (char *connectingIP) = NULL // a reference to callback function that will be celled when new connection arrives
722739
) {
723740
// create a local copy of parameters for later use
724741
strncpy (__serverIP__, serverIP, sizeof (__serverIP__)); __serverIP__ [sizeof (__serverIP__) - 1] = 0;
@@ -834,7 +851,7 @@
834851
close (connectingSocket); // normally ftpControlConnection would do this but if it is not created we have to do it here
835852
} else {
836853
if (fcn->state () != ftpControlConnection::RUNNING) {
837-
sendAll (connectingSocket, ftpServiceUnavailable, strlen (ftpServiceUnavailable), FTP_CONTROL_CONNECTION_TIME_OUT);
854+
sendAll (connectingSocket, ftpServiceUnavailable, FTP_CONTROL_CONNECTION_TIME_OUT);
838855
delete (fcn); // normally ftpControlConnection would do this but if it is not running we have to do it here
839856
}
840857
}

servers/httpClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
close (connectionSocket);
102102
return "Out of memory";
103103
}
104-
if (sendAll (connectionSocket, (char *) httpRequest, timeOut) == -1) {
104+
if (sendAll (connectionSocket, httpRequest, timeOut) == -1) {
105105
int e = errno;
106106
close (connectionSocket);
107107
return "[httpClient] send() error: " + String (e) + " " + strerror (e);

0 commit comments

Comments
 (0)