Skip to content

Commit

Permalink
activity heartbeat led
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertvanheusden committed Nov 9, 2024
1 parent 29ebebf commit 9370370
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
8 changes: 8 additions & 0 deletions microcontrollers/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ void fail_flash() {
digitalWrite(LED_BUILTIN, state);
#endif
write_led(led_red, state);
#if !defined(TEENSY4_1) && !defined(RP2040W)
ArduinoOTA.handle();
#endif
delay(1);
#ifdef LED_BUILTIN
digitalWrite(LED_BUILTIN, state);
Expand Down Expand Up @@ -365,6 +367,10 @@ void loopw(void *)
draw_status_ts = now;
}

#ifdef LED_BUILTIN
digitalWrite(LED_BUILTIN, s->is_active() && cu_count >= 20);
#endif

if (now - last_diskfree_update >= update_df_interval * 1000 && update_df_interval != 0) {
auto disk_act_pars = bs->get_idle_state();

Expand Down Expand Up @@ -601,8 +607,10 @@ void setup() {
bs = new backend_sdcard(led_green, led_yellow, pin_SD_MISO, pin_SD_MOSI, pin_SD_SCLK, pin_SD_CS, spi_speed, disk_name);
#endif

#if !defined(TEENSY4_1)
draw_status(12);
xTaskCreate(idle_task, "idle_task", 2048, nullptr, 0, nullptr);
#endif

draw_status(13);
init_snmp(&snmp_, &snmp_data_, &is, get_diskspace, bs, &bstats, &cpu_usage, &ram_free_kb, &stop, 161);
Expand Down
30 changes: 21 additions & 9 deletions server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,19 @@ iscsi_fail_reason server::push_response(com_client *const cc, session *const ses
return ifr;
}

void server::handler()
bool server::is_active()
{
std::vector<std::pair<std::thread *, std::atomic_bool *> > threads;
#if !defined(TEENSY4_1) && !defined(RP2040W)
bool active = false;
std::unique_lock<std::mutex> lck(threads_lock);
for(auto &e: threads)
active |= !e.second;
#endif
return active;
}

void server::handler()
{
while(!stop) {
com_client *cc = c->accept();
if (cc == nullptr) {
Expand All @@ -541,6 +550,7 @@ void server::handler()
}

#if !defined(TEENSY4_1) && !defined(RP2040W)
threads_lock.lock();
for(size_t i=0; i<threads.size();) {
if (*threads.at(i).second) {
DOLOG(logging::ll_debug, "server::handler", "-", "thread cleaned up");
Expand All @@ -553,10 +563,13 @@ void server::handler()
i++;
}
}
threads_lock.unlock();

std::atomic_bool *flag = new std::atomic_bool(false);

std::thread *th = new std::thread([=, this]() {
#else
active = true;
#endif
std::string endpoint = cc->get_endpoint_name();

Expand All @@ -574,9 +587,6 @@ void server::handler()
auto block_size = s->get_block_size();

do {
#if defined(LED_BUILTIN) && defined(ARDUINO)
digitalWrite(LED_BUILTIN, LOW);
#endif
auto incoming = receive_pdu(cc, &ses);
iscsi_pdu_bhs *pdu = std::get<0>(incoming);

Expand Down Expand Up @@ -695,10 +705,6 @@ void server::handler()
ses->reset_io_stats();
busy = 0;
}

#if defined(LED_BUILTIN) && defined(ARDUINO)
digitalWrite(LED_BUILTIN, HIGH);
#endif
}
while(ok);
#if defined(ESP32)
Expand All @@ -720,7 +726,11 @@ void server::handler()
*flag = true;
});

threads_lock.lock();
threads.push_back({ th, flag });
threads_lock.unlock();
#else
active = false;
#endif

#if defined(ESP32)
Expand All @@ -729,12 +739,14 @@ void server::handler()
}

#if !defined(TEENSY4_1) && !defined(RP2040W)
threads_lock.lock();
for(auto &e: threads) {
if (e.second) {
e.first->join();
delete e.first;
delete e.second;
}
}
threads_lock.unlock();
#endif
}
13 changes: 12 additions & 1 deletion server.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include <cstdint>
#include <utility>
#if !defined(TEENSY4_1) && !defined(RP2040W)
#include <atomic>
#include <mutex>
#include <thread>
#endif

#include "com.h"
#include "scsi.h"
Expand Down Expand Up @@ -29,6 +34,12 @@ class server
#if !defined(ARDUINO) && !defined(NDEBUG)
std::atomic_uint64_t cmd_use_count[64] { };
#endif
#if !defined(TEENSY4_1) && !defined(RP2040W)
std::mutex threads_lock;
std::vector<std::pair<std::thread *, std::atomic_bool *> > threads;
#else
bool active { false };
#endif

std::tuple<iscsi_pdu_bhs *, iscsi_fail_reason, uint64_t>
receive_pdu (com_client *const cc, session **const s);
Expand All @@ -39,6 +50,6 @@ class server
virtual ~server();

bool begin();

bool is_active();
void handler();
};

0 comments on commit 9370370

Please sign in to comment.