Skip to content
Merged
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
9 changes: 7 additions & 2 deletions data/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ var ui = {
// temp variable to store updates from Parameter Database
paramUpdates: "",

// Status of visibility of parameter categories. E.g. Motor, Inverter. true = visible, false = not visible.
// Status of visibility of parameter categories. E.g. Motor, Inverter. true = visible, false = not visible.
categoryVisible: {},

canMappingLoaded: false,

navbarIsBig: true,

// When true, fetch all parameters including hidden ones (via 'json hidden')
Expand Down Expand Up @@ -177,7 +179,6 @@ var ui = {
ui.updateTables();
plot.generateChart();
ui.parameterDatabaseCheckForUpdates();
inverter.canMapping(ui.populateExistingCanMappingTable);
wifi.populateWiFiTab();
settings.populateSettingsTab();
ui.populateFileList();
Expand Down Expand Up @@ -366,6 +367,10 @@ var ui = {
}
ui.populateVersion();
ui.populateSpotValueDropDown();
if (!ui.canMappingLoaded && Object.keys(values).length > 0) {
ui.canMappingLoaded = true;
inverter.canMapping(ui.populateExistingCanMappingTable);
}

document.getElementById("paramDownload").href = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(params, null, 2));
document.getElementById("spinner-div").style.visibility = "hidden";
Expand Down
6 changes: 4 additions & 2 deletions esp32-web-interface.ino
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,10 @@ static void handleCanMap() {
res = OICan::AddCanMapping(server.arg("edit"));
}

if (res == OICan::Ok)
OICan::SendCanMapping(server.client());
if (res == OICan::Ok) {
if (!OICan::SendCanMapping(server.client()))
server.send(500, "text/plain", "CAN communication error");
}
else if (res == OICan::CommError)
server.send(500, "text/plain", "CAN communication error");
else if (res == OICan::UnknownIndex)
Expand Down
14 changes: 10 additions & 4 deletions src/oi_can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
#define SDO_CMD_LOAD 1
#define SDO_CMD_RESET 2
#define SDO_CMD_DEFAULTS 3
#define SDO_CMD_CLEAR_CAN 4
#define SDO_CMD_START 4
#define SDO_CMD_STOP 5
#define SDO_CMD_CLEAR_CAN 6
#define PARAM_FLAG_HIDDEN 1
#define MAX_ERROR_LOG_ENTRIES 100

Expand Down Expand Up @@ -404,7 +404,12 @@ bool SendJson(WiFiClient client, bool includeHidden) {
return failed < 5;
}

void SendCanMapping(WiFiClient client) {
bool SendCanMapping(WiFiClient client) {
if (state != IDLE || updstate != UPD_IDLE) {
DBG_OUTPUT_PORT.printf("SendCanMapping rejected: CAN state=%d update state=%d\r\n", state, updstate);
return false;
}

enum ReqMapStt { START, COBID, DATAPOSLEN, GAINOFS, DONE };

twai_message_t rxframe;
Expand Down Expand Up @@ -509,6 +514,7 @@ void SendCanMapping(WiFiClient client) {

WriteBufferingStream bufferedWifiClient{client, 1000};
serializeJson(doc, bufferedWifiClient);
return true;
}

SetResult AddCanMapping(String json) {
Expand Down Expand Up @@ -916,9 +922,9 @@ void Loop() {

retries--;

if (recvdResponse || retries < 0)
if (state == IDLE || state == OBTAIN_JSON || retries < 0)
updstate = UPD_IDLE; //if request was successful
else
else if (!recvdResponse)
requestSdoElement(SDO_INDEX_SERIAL, 0);

delay(100);
Expand Down
Loading