Skip to content

Commit

Permalink
Silence unnecessary GCC warning about string truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
hg committed Nov 16, 2020
1 parent 3a2feb2 commit cfb51ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
10 changes: 7 additions & 3 deletions firmware/main/app_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct PmMeasurementSum {

void addMeasurement(const PmsResponse &resp);
void reset();
} __attribute__((packed));
};

enum class MeasurementType { MS_TEMPERATURE, MS_PARTICULATES };

Expand Down Expand Up @@ -745,10 +745,14 @@ static void initWifi() {
.pmf_cfg{.capable = true, .required = false},
},
};
strncpy((char *)wf_conf.sta.ssid, appSettings.wifi.ssid,

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
strncpy(reinterpret_cast<char *>(wf_conf.sta.ssid), appSettings.wifi.ssid,
sizeof(wf_conf.sta.ssid));
strncpy((char *)wf_conf.sta.password, appSettings.wifi.pass,
strncpy(reinterpret_cast<char *>(wf_conf.sta.password), appSettings.wifi.pass,
sizeof(wf_conf.sta.password));
#pragma GCC diagnostic pop

ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wf_conf));
Expand Down
15 changes: 11 additions & 4 deletions firmware/main/timer.hh
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
#pragma once

#include "freertos/FreeRTOS.h"
#include <chrono>
#include <numeric>

class Timer {
public:
// creates and starts the timer
Timer() { ticks = xTaskGetTickCount(); }
Timer() { start = xTaskGetTickCount(); }

// returns passed time in seconds
TickType_t seconds() {
return (xTaskGetTickCount() - ticks) / configTICK_RATE_HZ;
const TickType_t now = xTaskGetTickCount();

const TickType_t passed =
now >= start
? now - start
: std::numeric_limits<decltype(start)>::max() - start + now;

return passed / configTICK_RATE_HZ;
}

private:
TickType_t ticks;
TickType_t start;
};

0 comments on commit cfb51ce

Please sign in to comment.