Skip to content

Commit

Permalink
mqtt fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Feb 27, 2020
1 parent c014785 commit 08c0619
Show file tree
Hide file tree
Showing 14 changed files with 42,843 additions and 40,680 deletions.
1,956 changes: 1,743 additions & 213 deletions modular-psu-firmware.eez-project

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/eez/file_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace eez {

static const char *fileTypeExtension[] = {
nullptr,
nullptr,
LIST_EXT,
PROFILE_EXT,
Expand All @@ -37,6 +38,7 @@ static const char *fileTypeExtension[] = {
};

static const char *scpiFileTypeNames[] = {
nullptr,
"FOLD",
"LIST",
"PROF",
Expand Down
1 change: 1 addition & 0 deletions src/eez/file_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace eez {

enum FileType {
FILE_TYPE_NONE,
FILE_TYPE_DIRECTORY,
FILE_TYPE_LIST,
FILE_TYPE_PROFILE,
Expand Down
9 changes: 9 additions & 0 deletions src/eez/gui/action_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <eez/system.h>
#include <eez/sound.h>
#include <eez/index.h>
#include <eez/mqtt.h>

#include <eez/gui/gui.h>

Expand Down Expand Up @@ -250,6 +251,14 @@ void action_show_sys_settings_ethernet() {
pushPage(PAGE_ID_SYS_SETTINGS_ETHERNET);
}

void action_show_sys_settings_ethernet_error() {
if (persist_conf::devConf.mqttEnabled && mqtt::g_connectionState == mqtt::CONNECTION_STATE_ERROR) {
pushPage(PAGE_ID_SYS_SETTINGS_MQTT);
} else {
pushPage(PAGE_ID_SYS_SETTINGS_ETHERNET);
}
}

void action_show_sys_settings_protections() {
pushPage(PAGE_ID_SYS_SETTINGS_PROTECTIONS);
}
Expand Down
46,346 changes: 23,320 additions & 23,026 deletions src/eez/gui/document_simulator.cpp

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/eez/gui/document_simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,8 @@ enum ActionsEnum {
ACTION_ID_DATE_TIME_TOGGLE_AM_PM = 221,
ACTION_ID_EDIT_NO_FOCUS = 222,
ACTION_ID_UNTRACK_ALL = 223,
ACTION_ID_CH_SETTINGS_COPY = 224
ACTION_ID_CH_SETTINGS_COPY = 224,
ACTION_ID_SHOW_SYS_SETTINGS_ETHERNET_ERROR = 225
};

void action_channel_toggle_output();
Expand Down Expand Up @@ -1204,6 +1205,7 @@ void action_date_time_toggle_am_pm();
void action_edit_no_focus();
void action_untrack_all();
void action_ch_settings_copy();
void action_show_sys_settings_ethernet_error();

extern ActionExecFunc g_actionExecFunctions[];

Expand Down Expand Up @@ -1605,7 +1607,7 @@ enum PagesEnum {
};

#ifdef OPTION_SDRAM
extern const uint8_t assets[394904];
extern const uint8_t assets[396147];
#else
extern const uint8_t assets[3866388];
extern const uint8_t assets[3869828];
#endif
35,137 changes: 17,714 additions & 17,423 deletions src/eez/gui/document_stm32.cpp

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/eez/gui/document_stm32.h
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,8 @@ enum ActionsEnum {
ACTION_ID_DATE_TIME_TOGGLE_AM_PM = 217,
ACTION_ID_EDIT_NO_FOCUS = 218,
ACTION_ID_UNTRACK_ALL = 219,
ACTION_ID_CH_SETTINGS_COPY = 220
ACTION_ID_CH_SETTINGS_COPY = 220,
ACTION_ID_SHOW_SYS_SETTINGS_ETHERNET_ERROR = 221
};

void action_channel_toggle_output();
Expand Down Expand Up @@ -1180,6 +1181,7 @@ void action_date_time_toggle_am_pm();
void action_edit_no_focus();
void action_untrack_all();
void action_ch_settings_copy();
void action_show_sys_settings_ethernet_error();

extern ActionExecFunc g_actionExecFunctions[];

Expand Down Expand Up @@ -1572,7 +1574,7 @@ enum PagesEnum {
};

#ifdef OPTION_SDRAM
extern const uint8_t assets[302318];
extern const uint8_t assets[303512];
#else
extern const uint8_t assets[1315936];
extern const uint8_t assets[1319376];
#endif
6 changes: 1 addition & 5 deletions src/eez/modules/psu/event_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,6 @@ static void refreshEvents() {
g_numEvents = file.size() / 4;
file.close();
}

if (g_numEvents == 0) {
pushEvent(EVENT_INFO_WELCOME);
}
}

static bool writeToLog(QueueEvent *event, uint32_t &logOffset, int &eventType) {
Expand Down Expand Up @@ -519,7 +515,7 @@ static void writeEvent(QueueEvent *event) {
return;
}

if (eventType >= g_filter) {
if (eventType >= g_filter) {
g_refreshEvents = true;
}

Expand Down
21 changes: 19 additions & 2 deletions src/eez/modules/psu/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3546,7 +3546,24 @@ void data_ethernet_enabled(data::DataOperationEnum operation, data::Cursor &curs
void data_ethernet_status(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
#if OPTION_ETHERNET
if (operation == data::DATA_OPERATION_GET) {
value = data::Value(ethernet::g_testResult);
if (
ethernet::g_testResult == TEST_CONNECTING ||
(
persist_conf::devConf.mqttEnabled &&
(
mqtt::g_connectionState == mqtt::CONNECTION_STATE_STARTING ||
mqtt::g_connectionState == mqtt::CONNECTION_STATE_DNS_IN_PROGRESS ||
mqtt::g_connectionState == mqtt::CONNECTION_STATE_DNS_FOUND ||
mqtt::g_connectionState == mqtt::CONNECTION_STATE_CONNECTING
)
)
) {
value = data::Value(TEST_CONNECTING);
} else if (ethernet::g_testResult == TEST_FAILED || (persist_conf::devConf.mqttEnabled && mqtt::g_connectionState == mqtt::CONNECTION_STATE_ERROR)) {
value = data::Value(TEST_FAILED);
} else {
value = data::Value(ethernet::g_testResult);
}
}
#endif
}
Expand Down Expand Up @@ -5207,7 +5224,7 @@ void data_file_manager_is_root_directory(data::DataOperationEnum operation, data

void data_file_manager_files(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_COUNT) {
value = (int)file_manager::getFilesCount();
value = (int)MAX(file_manager::getFilesCount(), file_manager::getFilesPageSize());
} else if (operation == DATA_OPERATION_YT_DATA_GET_SIZE) {
value = Value(file_manager::getFilesCount(), VALUE_TYPE_UINT32);
} else if (operation == DATA_OPERATION_YT_DATA_GET_POSITION) {
Expand Down
2 changes: 1 addition & 1 deletion src/eez/modules/psu/gui/file_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ bool isDirectory(uint32_t fileIndex) {

FileType getFileType(uint32_t fileIndex) {
auto fileItem = getFileItem(fileIndex);
return fileItem ? fileItem->type : FILE_TYPE_OTHER;
return fileItem ? fileItem->type : FILE_TYPE_NONE;
}

const char *getFileName(uint32_t fileIndex) {
Expand Down
2 changes: 1 addition & 1 deletion src/eez/modules/psu/scpi/syst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ scpi_result_t scpi_cmd_systemChannelModelQ(scpi_t *context) {

if (channel->isInstalled()) {
auto &slot = g_slots[channel->slotIndex];
char text[100];
char text[50];
sprintf(text, "%s_R%dB%d", slot.moduleInfo->moduleName, (int)(slot.moduleRevision >> 8), (int)(slot.moduleRevision & 0xFF));
SCPI_ResultText(context, text);
} else {
Expand Down
22 changes: 21 additions & 1 deletion src/eez/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ using namespace psu;

namespace mqtt {

static const uint32_t RECONNECT_AFTER_ERROR_MS = 1000;
static const uint32_t RECONNECT_AFTER_ERROR_MS = 10000;
static const uint32_t CONF_DNS_TIMEOUT_MS = 10000;
static const uint32_t CONF_STARTING_TIMEOUT_MS = 2000; // wait a acouple of seconds, after ethernet is ready, before starting MQTT connect

Expand All @@ -82,6 +82,7 @@ static const char *PUB_TOPIC_SYSTEM_TOTAL_ONTIME = "%s/system/total_ontime";
static const char *PUB_TOPIC_SYSTEM_LAST_ONTIME = "%s/system/last_ontime";
static const char *PUB_TOPIC_SYSTEM_FAN_STATUS = "%s/system/fan";

static const char *PUB_TOPIC_DCPSUPPLY_MODEL = "%s/dcpsupply/ch/%d/model";
static const char *PUB_TOPIC_DCPSUPPLY_OE = "%s/dcpsupply/ch/%d/oe";
static const char *PUB_TOPIC_DCPSUPPLY_U_SET = "%s/dcpsupply/ch/%d/uset";
static const char *PUB_TOPIC_DCPSUPPLY_I_SET = "%s/dcpsupply/ch/%d/iset";
Expand Down Expand Up @@ -128,6 +129,8 @@ struct {
} g_eventQueue;

static struct {
bool modelPublished;

int oe;

float uSet;
Expand Down Expand Up @@ -473,6 +476,13 @@ bool publish(int channelIndex, const char *pubTopic, float value, bool retain) {
return publish(topic, payload, retain);
}

bool publish(int channelIndex, const char *pubTopic, char *payload, bool retain) {
char topic[MAX_PUB_TOPIC_LENGTH + 1];
sprintf(topic, pubTopic, persist_conf::devConf.ethernetHostName, channelIndex + 1);

return publish(topic, payload, retain);
}

bool publishOnTimeCounter(int channelIndex, const char *pubTopic, uint32_t value, bool retain) {
char topic[MAX_PUB_TOPIC_LENGTH + 1];
sprintf(topic, pubTopic, persist_conf::devConf.ethernetHostName, channelIndex + 1);
Expand Down Expand Up @@ -523,6 +533,7 @@ void setState(ConnectionState connectionState) {
#endif

for(int i = 0; i < CH_NUM; i++) {
g_channelStates[i].modelPublished = false;
g_channelStates[i].oe = -1;
g_channelStates[i].uSet = NAN;
g_channelStates[i].iSet = NAN;
Expand Down Expand Up @@ -650,6 +661,15 @@ void tick() {
int oe = channel.isOutputEnabled() ? 1 : 0;

if (g_lastValueIndex == 0) {
if (!g_channelStates[channelIndex].modelPublished) {
char moduleInfo[50];
auto &slot = g_slots[channel.slotIndex];
sprintf(moduleInfo, "%s_R%dB%d", slot.moduleInfo->moduleName, (int)(slot.moduleRevision >> 8), (int)(slot.moduleRevision & 0xFF));
if (publish(channelIndex, PUB_TOPIC_DCPSUPPLY_MODEL, moduleInfo, true)) {
g_channelStates[channelIndex].modelPublished = true;
}
}

if (oe != g_channelStates[channelIndex].oe) {
if (publish(channelIndex, PUB_TOPIC_DCPSUPPLY_OE, oe, true)) {
g_channelStates[channelIndex].oe = oe;
Expand Down
3 changes: 1 addition & 2 deletions src/eez/mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ enum ConnectionState {
CONNECTION_STATE_STARTING,
CONNECTION_STATE_IDLE,
CONNECTION_STATE_CONNECTED,
CONNECTION_STATE_TRANSIENT,
CONNECTION_STATE_CONNECT = CONNECTION_STATE_TRANSIENT,
CONNECTION_STATE_CONNECT,
CONNECTION_STATE_CONNECTING,
CONNECTION_STATE_DNS_IN_PROGRESS,
CONNECTION_STATE_DNS_FOUND,
Expand Down

0 comments on commit 08c0619

Please sign in to comment.