Chat app update, EspNow v2 & GPS Info (#460)
This commit is contained in:
@@ -36,6 +36,7 @@ bool isEnabled() {
|
||||
if (service != nullptr) {
|
||||
return service->isEnabled();
|
||||
} else {
|
||||
LOGGER.error("Service not found");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -79,6 +80,21 @@ void unsubscribeReceiver(ReceiverSubscription subscription) {
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getVersion() {
|
||||
auto service = findService();
|
||||
if (service != nullptr) {
|
||||
return service->getVersion();
|
||||
}
|
||||
LOGGER.error("Service not found");
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t getMaxDataLength() {
|
||||
auto v = getVersion();
|
||||
if (v == 0) return 0;
|
||||
return v >= 2 ? MAX_DATA_LEN_V2 : MAX_DATA_LEN_V1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // CONFIG_SOC_WIFI_SUPPORTED && !CONFIG_SLAVE_SOC_WIFI_SUPPORTED
|
||||
|
||||
@@ -74,16 +74,23 @@ void EspNowService::enableFromDispatcher(const EspNowConfig& config) {
|
||||
return;
|
||||
}
|
||||
|
||||
//#if CONFIG_ESPNOW_ENABLE_POWER_SAVE
|
||||
// ESP_ERROR_CHECK( esp_now_set_wake_window(CONFIG_ESPNOW_WAKE_WINDOW) );
|
||||
// ESP_ERROR_CHECK( esp_wifi_connectionless_module_set_wake_interval(CONFIG_ESPNOW_WAKE_INTERVAL) );
|
||||
//#endif
|
||||
//#if CONFIG_ESPNOW_ENABLE_POWER_SAVE
|
||||
// ESP_ERROR_CHECK( esp_now_set_wake_window(CONFIG_ESPNOW_WAKE_WINDOW) );
|
||||
// ESP_ERROR_CHECK( esp_wifi_connectionless_module_set_wake_interval(CONFIG_ESPNOW_WAKE_INTERVAL) );
|
||||
//#endif
|
||||
|
||||
if (esp_now_set_pmk(config.masterKey) != ESP_OK) {
|
||||
LOGGER.error("esp_now_set_pmk() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
espnowVersion = 0;
|
||||
if (esp_now_get_version(&espnowVersion) == ESP_OK) {
|
||||
LOGGER.info("ESP-NOW version: {}.0", espnowVersion);
|
||||
} else {
|
||||
LOGGER.warn("Failed to get ESP-NOW version");
|
||||
}
|
||||
|
||||
// Add default unencrypted broadcast peer
|
||||
esp_now_peer_info_t broadcast_peer;
|
||||
memset(&broadcast_peer, 0, sizeof(esp_now_peer_info_t));
|
||||
@@ -119,6 +126,7 @@ void EspNowService::disableFromDispatcher() {
|
||||
LOGGER.error("deinitWifi() failed");
|
||||
}
|
||||
|
||||
espnowVersion = 0;
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
@@ -195,6 +203,12 @@ void EspNowService::unsubscribeReceiver(ReceiverSubscription subscriptionId) {
|
||||
std::erase_if(subscriptions, [subscriptionId](auto& subscription) { return subscription.id == subscriptionId; });
|
||||
}
|
||||
|
||||
uint32_t EspNowService::getVersion() const {
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
return espnowVersion;
|
||||
}
|
||||
|
||||
std::shared_ptr<EspNowService> findService() {
|
||||
return std::static_pointer_cast<EspNowService>(
|
||||
findServiceById(manifest.id)
|
||||
|
||||
@@ -37,7 +37,7 @@ void GpsService::addGpsDevice(const std::shared_ptr<GpsDevice>& device) {
|
||||
|
||||
GpsDeviceRecord record = {.device = device};
|
||||
|
||||
if (getState() == State::On) { // Ignore during OnPending due to risk of data corruptiohn
|
||||
if (getState() == State::On) { // Ignore during OnPending due to risk of data corruption
|
||||
startGpsDevice(record);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ void GpsService::removeGpsDevice(const std::shared_ptr<GpsDevice>& device) {
|
||||
|
||||
GpsDeviceRecord* record = findGpsRecord(device);
|
||||
|
||||
if (getState() == State::On) { // Ignore during OnPending due to risk of data corruptiohn
|
||||
if (getState() == State::On) { // Ignore during OnPending due to risk of data corruption
|
||||
stopGpsDevice(*record);
|
||||
}
|
||||
|
||||
@@ -87,6 +87,10 @@ bool GpsService::startGpsDevice(GpsDeviceRecord& record) {
|
||||
|
||||
record.satelliteSubscriptionId = device->subscribeGga([this](hal::Device::Id deviceId, auto& record) {
|
||||
mutex.lock();
|
||||
if (record.fix_quality > 0) {
|
||||
ggaRecord = record;
|
||||
ggaTime = kernel::getTicks();
|
||||
}
|
||||
onGgaSentence(deviceId, record);
|
||||
mutex.unlock();
|
||||
});
|
||||
@@ -156,14 +160,16 @@ bool GpsService::startReceiving() {
|
||||
addGpsDevice(device);
|
||||
}
|
||||
|
||||
// Reset times before starting devices to avoid race with incoming data
|
||||
rmcTime = 0;
|
||||
ggaTime = 0;
|
||||
|
||||
bool started_one_or_more = false;
|
||||
|
||||
for (auto& record: deviceRecords) {
|
||||
started_one_or_more |= startGpsDevice(record);
|
||||
}
|
||||
|
||||
rmcTime = 0;
|
||||
|
||||
if (started_one_or_more) {
|
||||
setState(State::On);
|
||||
return true;
|
||||
@@ -186,6 +192,7 @@ void GpsService::stopReceiving() {
|
||||
}
|
||||
|
||||
rmcTime = 0;
|
||||
ggaTime = 0;
|
||||
|
||||
setState(State::Off);
|
||||
}
|
||||
@@ -227,6 +234,16 @@ bool GpsService::getCoordinates(minmea_sentence_rmc& rmc) const {
|
||||
}
|
||||
}
|
||||
|
||||
bool GpsService::getGga(minmea_sentence_gga& gga) const {
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
if (getState() == State::On && ggaTime != 0 && !hasTimeElapsed(kernel::getTicks(), ggaTime, kernel::secondsToTicks(10))) {
|
||||
gga = ggaRecord;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<GpsService> findGpsService() {
|
||||
auto service = findServiceById(manifest.id);
|
||||
assert(service != nullptr);
|
||||
|
||||
Reference in New Issue
Block a user