Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/helpers/CommonCLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re
sprintf(reply, "%s (Build: %s)", _callbacks->getFirmwareVer(), _callbacks->getBuildDate());
} else if (memcmp(command, "board", 5) == 0) {
sprintf(reply, "%s", _board->getManufacturerName());
} else if (memcmp(command, "sensors", 7) == 0) {
_sensors->formatActiveSensorsReply(reply);
} else if (memcmp(command, "sensor get ", 11) == 0) {
const char* key = command + 11;
const char* val = _sensors->getSettingByKey(key);
Expand Down
1 change: 1 addition & 0 deletions src/helpers/SensorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SensorManager {
virtual const char* getSettingValue(int i) const { return NULL; }
virtual bool setSettingValue(const char* name, const char* value) { return false; }
virtual LocationProvider* getLocationProvider() { return NULL; }
virtual void formatActiveSensorsReply(char* reply) { strcpy(reply, "no sensors"); }

// Helper functions to manage setting by keys (useful in many places ...)
const char* getSettingByKey(const char* key) {
Expand Down
28 changes: 27 additions & 1 deletion src/helpers/sensors/EnvironmentSensorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ bool EnvironmentSensorManager::begin() {
}
MESH_DEBUG_PRINTLN("Found %s at address: %02X", def.name, def.address);
for (uint8_t sub = 0; sub < n && _active_sensor_count < MAX_ACTIVE_SENSORS; sub++) {
_active_sensors[_active_sensor_count++] = { def.query, sub };
_active_sensors[_active_sensor_count++] = { def.query, sub, def.name, def.address };
}
}

Expand Down Expand Up @@ -681,6 +681,32 @@ bool EnvironmentSensorManager::querySensors(uint8_t requester_permissions, Cayen
return true;
}

// ============================================================
// formatActiveSensorsReply() — lists each detected sensor with
// its assigned telemetry channel and I2C address, for the
// "sensors" CLI command. Channel numbering mirrors the order
// querySensors() assigns at runtime.
// ============================================================

void EnvironmentSensorManager::formatActiveSensorsReply(char* reply) {
if (_active_sensor_count == 0) {
strcpy(reply, "no sensors detected");
return;
}

char* dp = reply;
int i;
for (i = 0; i < _active_sensor_count && (dp - reply < 140); i++) {
uint8_t channel = TELEM_CHANNEL_SELF + 1 + i;
sprintf(dp, "ch%d: %s @ 0x%02X\n", channel, _active_sensors[i].name, _active_sensors[i].address);
dp = strchr(dp, 0);
}
if (i < _active_sensor_count) {
sprintf(dp, "... +%d more", _active_sensor_count - i);
} else {
*(dp - 1) = 0; // remove trailing newline
}
}

int EnvironmentSensorManager::getNumSettings() const {
int settings = 0;
Expand Down
5 changes: 4 additions & 1 deletion src/helpers/sensors/EnvironmentSensorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class EnvironmentSensorManager : public SensorManager {
// Sub-channel is 0 for all single-output sensors.
struct ActiveSensor {
void (*query)(uint8_t channel, uint8_t sub_channel, CayenneLPP& telemetry);
uint8_t sub_channel;
uint8_t sub_channel;
const char* name; // points into SENSOR_TABLE's static string, not owned
uint8_t address;
};

ActiveSensor _active_sensors[MAX_ACTIVE_SENSORS];
Expand Down Expand Up @@ -50,4 +52,5 @@ class EnvironmentSensorManager : public SensorManager {
const char* getSettingName(int i) const override;
const char* getSettingValue(int i) const override;
bool setSettingValue(const char* name, const char* value) override;
void formatActiveSensorsReply(char* reply) override;
};