Skip to content

Commit 8eb49f6

Browse files
committed
Optimizations in data stream, added BMS bar graph
1 parent 7db1947 commit 8eb49f6

File tree

5 files changed

+112
-30
lines changed

5 files changed

+112
-30
lines changed

data/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ <h3 class="underline">Actions</h3>
426426
<!-- /icon-clock.png -->
427427
<img class="buttonimg" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAaNJREFUSInF1c9qU0EUBvCfdpNgEBLctfumvoN/HyD6BFZFfQWlj+PSlbq0LVgFQe1WbSO4MWtr6brExT1DJuU2MwbED4YLZ775vnPPzJzhH+NCYX6AuxhhiLWIT3CA13iJX39r3MUWjjEtjN/B7daKr2E/E3iDR1jHpRhDPMZ2xtvHao34JBYc4npFQjcwjjWTRSbdLPO36Ldw3sc4iz72Yu0ndNoMtrLM28SZlaMNA3yP+Wdtk2lDF5VlkQHcNNv4uSQfmm3oIpQMYCc49+FiBEfxfVFYXIOkMcqDh+G6Xlhc8wfD4BzkwZMI9ioN7mHlHE4vOCfLGHzITMbnGF2O+eM8WFuilRBNF2sapjnmSpQ2+Wt8rxUMTvEcG9gMkdMznHTMv+TBB+G6XTCowW5obebBgeZyTDW9ZVncDo0jLd0gtYofuLKEeN4qnrYROvgchL22DAri7xSaHU2rTe16rOktJdwyy/ynijdhNbJIx3AHTzQnpxfjasR2M97HGvGEjqblpo1fNI40NW8tS+nR7+OOpnFtmH/0v2ke/Vdh8n/wB7ImjnFjEwJCAAAAAElFTkSuQmCC">Launch gauges</button>
428428

429+
<!-- toggle between plot and BMS bar graph -->
430+
<button onclick="plot.toggleBargraph()" id="toggleBargraph">
431+
<!-- /icon-clock.png -->
432+
<img class="buttonimg" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAKJJREFUSIntlNENAiEQRHfMFWFN2obXhkbb0Da0p6vi+SPEkPUgB3yQOJ87ywxklhVgPTGVNEm6eHXgmj1b8gJJmNktKZ8BNTNIxbyah11WvRLjG0xmZpKOHgk8aw0EhCl5JdwhhFgTcjRYE/hPUVcU7aIcJD28OnBqEvJnCudE/w6omcEvfvyQxzeIYyppWWvcygeDfeYim/nvbdoc8R/0xBvkH4UjmI1+eAAAAABJRU5ErkJggg==" />Toggle BMS bar graph</button>
433+
429434
<h3 class="underline">Configure Plot</h3>
430435
Data points : <input type="number" id="maxValues" step="1" min="10" max="10000" value="1000" /><br>
431436
Burst length : <input type="number" id="burstLength" step="1" min="1" max="1000" value="10" />

data/inverter.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ var inverter = {
8282
console.log(req + ": " + xmlhttp.status);
8383
if (xmlhttp.status != 200) {
8484
paramsCache.failedFetchCount += 1;
85-
if ( paramsCache.failedFetchCount >= 2 ){
85+
if ( paramsCache.failedFetchCount >= 2 && typeof ui !== 'undefined'){
8686
ui.showCommunicationErrorBar();
8787
}
8888
}
8989
else {
9090
paramsCache.failedFetchCount = 0;
9191
}
92-
if ( paramsCache.failedFetchCount < 2 ) {
92+
if ( paramsCache.failedFetchCount < 2 && typeof ui !== 'undefined') {
9393
ui.hideCommunicationErrorBar();
9494
}
9595
}
@@ -182,10 +182,7 @@ var inverter = {
182182
replyFunc(values);
183183
};
184184

185-
if (inverter.firmwareVersion < 3.53 || items.length > 10)
186-
inverter.sendCmd("get " + items.join(','), process, repeat);
187-
else
188-
inverter.sendCmd("stream " + repeat + " " + items.join(','), process);
185+
inverter.sendCmd("stream " + repeat + " " + items.join(','), process);
189186
},
190187

191188

data/plot.js

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
var plot = {
2222

2323
stop: true,
24+
barGraph: false,
2425

2526
/** @brief launch new tab showing gauges based fields selected from the plot&gauge page */
2627
launchGauges: function()
@@ -33,6 +34,18 @@ var plot = {
3334
/** @brief generates chart at bottom of page */
3435
generateChart: function()
3536
{
37+
if (plot.barGraph)
38+
{
39+
chart = new Chart("canvas", {
40+
type: 'bar',
41+
options: {
42+
animation: false
43+
}
44+
});
45+
46+
}
47+
else
48+
{
3649
chart = new Chart("canvas", {
3750
type: "line",
3851
options: {
@@ -54,11 +67,19 @@ var plot = {
5467
}]
5568
}
5669
} });
70+
}
5771
},
5872

5973
/** @brief start plotting selected spot values */
6074
startPlot: function()
6175
{
76+
if (plot.barGraph)
77+
{
78+
items = {};
79+
items.names = [ "u0", "u1", "u2", "u3", "u4", "u5", "u6", "u7", "u8", "u9", "u10", "u11", "u12", "u13", "u14", "u15" ];
80+
}
81+
else
82+
{
6283
items = ui.getPlotItems();
6384
var colours = [ 'rgb(255, 99, 132)', 'rgb(54, 162, 235)', 'rgb(255, 159, 64)', 'rgb(153, 102, 255)', 'rgb(255, 205, 86)', 'rgb(75, 192, 192)' ];
6485

@@ -77,13 +98,14 @@ var plot = {
7798
};
7899
chart.config.data.datasets.push(newDataset);
79100
}
80-
81-
ui.setAutoReload(false);
82-
time = 0;
83101
chart.update();
84-
plot.stop = false;
85-
document.getElementById("pauseButton").disabled = false;
86-
plot.acquire();
102+
}
103+
104+
ui.setAutoReload(false);
105+
time = 0;
106+
plot.stop = false;
107+
document.getElementById("pauseButton").disabled = false;
108+
plot.acquire();
87109
},
88110

89111
/** @brief Stop plotting */
@@ -108,16 +130,44 @@ var plot = {
108130
}
109131
},
110132

133+
toggleBargraph: function()
134+
{
135+
chart.destroy();
136+
plot.barGraph = !plot.barGraph;
137+
plot.generateChart();
138+
chart.draw();
139+
140+
if (plot.barGraph)
141+
{
142+
}
143+
else
144+
{
145+
}
146+
},
147+
111148
acquire: function()
112149
{
113150
if (plot.stop) return;
114151
if (!items.names.length) return;
115-
var burstLength = document.getElementById('burstLength').value;
152+
var burstLength = plot.barGraph ? 1 : document.getElementById('burstLength').value;
116153
var maxValues = document.getElementById('maxValues').value;
117154

118155
inverter.getValues(items.names, burstLength,
119156
function(values)
120157
{
158+
if (plot.barGraph)
159+
{
160+
chart.config.data = {
161+
labels: items.names,
162+
datasets: [{
163+
label: "Cell voltages",
164+
backgroundColor: 'rgba(54, 162, 235, 0.7)',
165+
data: Object.values(values).map(function(a) { return a[0]; })
166+
}]
167+
};
168+
}
169+
else
170+
{
121171
for (var i = 0; i < burstLength; i++)
122172
{
123173
chart.config.data.labels.push(time);
@@ -135,9 +185,35 @@ var plot = {
135185
data.splice(0, Math.max(data.length - maxValues, 0));
136186
}
137187
}
188+
}
138189

139-
chart.update();
140-
plot.acquire();
190+
chart.update();
191+
plot.acquire();
141192
});
142193
},
143194
}
195+
196+
197+
var bmsBarGraph = {
198+
bargraph: {},
199+
200+
acquire: function ()
201+
{
202+
var items = [ "u0", "u1", "u2", "u3", "u4", "u5", "u6", "u7", "u8", "u9", "u10", "u11", "u12", "u13", "u14", "u15" ];
203+
204+
inverter.getValues(items, 1,
205+
function(values)
206+
{
207+
bmsBarGraph.bargraph.config.data = {
208+
labels: items,
209+
datasets: [{
210+
label: "Cell voltages",
211+
backgroundColor: 'rgba(54, 162, 235, 0.7)',
212+
data: Object.values(values).map(function(a) { return a[0]; })
213+
}]
214+
};
215+
bmsBarGraph.bargraph.update();
216+
bmsBarGraph.acquire();
217+
});
218+
}
219+
}

esp32-web-interface.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ static void handleSettings()
639639
if (updated)
640640
{
641641
File file = SPIFFS.open("/settings-updated.html", "r");
642-
size_t sent = server.streamFile(file, getContentType("settings-updated.html"));
642+
server.streamFile(file, getContentType("settings-updated.html"));
643643
file.close();
644644
}
645645
}

src/oi_can.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -607,37 +607,41 @@ bool StartStop(int opmode)
607607
String StreamValues(String names, int samples) {
608608
if (state != IDLE) return "";
609609

610+
JsonDocument doc;
610611
twai_message_t rxframe;
611612

613+
File file = SPIFFS.open(jsonFileName, "r");
614+
deserializeJson(doc, file);
615+
file.close();
616+
612617
int ids[30], numItems = 0;
613618
String result;
614619

615620
for (int pos = 0; pos >= 0; pos = names.indexOf(',', pos + 1)) {
616621
String name = names.substring(pos + 1, names.indexOf(',', pos + 1));
617-
ids[numItems++] = getId(name);
622+
ids[numItems++] = doc[name]["id"].as<int>();
618623
}
619624

620625
for (int i = 0; i < samples; i++) {
621626
for (int item = 0; item < numItems; item++) {
622627
int id = ids[item];
623628
requestSdoElement(SDO_INDEX_PARAM_UID | (id >> 8), id & 0xFF);
624-
}
625629

626-
int item = 0;
627-
while (twai_receive(&rxframe, pdMS_TO_TICKS(10)) == ESP_OK) {
628-
if (item > 0) result += ",";
629-
if (rxframe.data[0] == 0x80)
630-
result += "0";
631-
else {
632-
int receivedItem = (rxframe.data[1] << 8) + rxframe.data[3];
633-
634-
if (receivedItem == ids[item])
635-
result += String(((double)*(int32_t*)&rxframe.data[4]) / 32, 2);
636-
else
630+
if (twai_receive(&rxframe, pdMS_TO_TICKS(10)) == ESP_OK) {
631+
if (item > 0) result += ",";
632+
if (rxframe.data[0] == 0x80)
637633
result += "0";
634+
else {
635+
int receivedItem = (rxframe.data[1] << 8) + rxframe.data[3];
636+
637+
if (receivedItem == id)
638+
result += String(((double)*(int32_t*)&rxframe.data[4]) / 32, 2);
639+
else
640+
result += "0";
641+
}
638642
}
639-
item++;
640643
}
644+
641645
result += "\r\n";
642646
}
643647
return result;

0 commit comments

Comments
 (0)