Browse Source

* improved serial console

* repaired /save
* removed yields (not allowed with async-web)
pull/283/head
lumapu 3 years ago
parent
commit
4561655d9d
  1. 5
      tools/esp8266/app.cpp
  2. 2
      tools/esp8266/app.h
  3. 7
      tools/esp8266/crc.cpp
  4. 4
      tools/esp8266/crc.h
  5. 12
      tools/esp8266/hmRadio.h
  6. 30
      tools/esp8266/html/serial.html
  7. 6
      tools/esp8266/html/setup.html
  8. 25
      tools/esp8266/html/style.css
  9. 1
      tools/esp8266/include/dbg.h

5
tools/esp8266/app.cpp

@ -289,12 +289,12 @@ bool app::buildPayload(uint8_t id) {
for(uint8_t i = 0; i < mPayload[id].maxPackId; i ++) { for(uint8_t i = 0; i < mPayload[id].maxPackId; i ++) {
if(mPayload[id].len[i] > 0) { if(mPayload[id].len[i] > 0) {
if(i == (mPayload[id].maxPackId-1)) { if(i == (mPayload[id].maxPackId-1)) {
crc = Hoymiles::crc16(mPayload[id].data[i], mPayload[id].len[i] - 2, crc); crc = Ahoy::crc16(mPayload[id].data[i], mPayload[id].len[i] - 2, crc);
crcRcv = (mPayload[id].data[i][mPayload[id].len[i] - 2] << 8) crcRcv = (mPayload[id].data[i][mPayload[id].len[i] - 2] << 8)
| (mPayload[id].data[i][mPayload[id].len[i] - 1]); | (mPayload[id].data[i][mPayload[id].len[i] - 1]);
} }
else else
crc = Hoymiles::crc16(mPayload[id].data[i], mPayload[id].len[i], crc); crc = Ahoy::crc16(mPayload[id].data[i], mPayload[id].len[i], crc);
} }
yield(); yield();
} }
@ -740,7 +740,6 @@ void app::saveValues(void) {
} }
updateCrc(); updateCrc();
mEep->commit();
} }

2
tools/esp8266/app.h

@ -164,7 +164,7 @@ class app {
while(length > 0) { while(length > 0) {
len = (length < 32) ? length : 32; len = (length < 32) ? length : 32;
mEep->read(start, buf, len); mEep->read(start, buf, len);
crc = Hoymiles::crc16(buf, len, crc); crc = Ahoy::crc16(buf, len, crc);
start += len; start += len;
length -= len; length -= len;
} }

7
tools/esp8266/crc.cpp

@ -5,8 +5,7 @@
#include "crc.h" #include "crc.h"
namespace Hoymiles { namespace Ahoy {
uint8_t crc8(uint8_t buf[], uint8_t len) { uint8_t crc8(uint8_t buf[], uint8_t len) {
uint8_t crc = CRC8_INIT; uint8_t crc = CRC8_INIT;
for(uint8_t i = 0; i < len; i++) { for(uint8_t i = 0; i < len; i++) {
@ -14,7 +13,6 @@ uint8_t crc8(uint8_t buf[], uint8_t len) {
for(uint8_t b = 0; b < 8; b ++) { for(uint8_t b = 0; b < 8; b ++) {
crc = (crc << 1) ^ ((crc & 0x80) ? CRC8_POLY : 0x00); crc = (crc << 1) ^ ((crc & 0x80) ? CRC8_POLY : 0x00);
} }
yield();
} }
return crc; return crc;
} }
@ -31,8 +29,7 @@ uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start) {
if(shift != 0) if(shift != 0)
crc = crc ^ CRC16_MODBUS_POLYNOM; crc = crc ^ CRC16_MODBUS_POLYNOM;
} }
yield();
} }
return crc; return crc;
} }
} // namespace Hoymiles }

4
tools/esp8266/crc.h

@ -14,10 +14,8 @@
#define CRC16_MODBUS_POLYNOM 0xA001 #define CRC16_MODBUS_POLYNOM 0xA001
namespace Hoymiles { namespace Ahoy {
uint8_t crc8(uint8_t buf[], uint8_t len); uint8_t crc8(uint8_t buf[], uint8_t len);
uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start = 0xffff); uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start = 0xffff);
} }
#endif /*__CRC_H__*/ #endif /*__CRC_H__*/

12
tools/esp8266/hmRadio.h

@ -175,12 +175,12 @@ class HmRadio {
mTxBuf[10 + (++cnt)] = ((data[1] ) ) & 0xff; // setting for persistens handling mTxBuf[10 + (++cnt)] = ((data[1] ) ) & 0xff; // setting for persistens handling
} }
// crc control data // crc control data
uint16_t crc = Hoymiles::crc16(&mTxBuf[10], cnt+1); uint16_t crc = Ahoy::crc16(&mTxBuf[10], cnt+1);
mTxBuf[10 + (++cnt)] = (crc >> 8) & 0xff; mTxBuf[10 + (++cnt)] = (crc >> 8) & 0xff;
mTxBuf[10 + (++cnt)] = (crc ) & 0xff; mTxBuf[10 + (++cnt)] = (crc ) & 0xff;
// crc over all // crc over all
cnt +=1; cnt +=1;
mTxBuf[10 + cnt] = Hoymiles::crc8(mTxBuf, 10 + cnt); mTxBuf[10 + cnt] = Ahoy::crc8(mTxBuf, 10 + cnt);
sendPacket(invId, mTxBuf, 10 + (++cnt), true); sendPacket(invId, mTxBuf, 10 + (++cnt), true);
} }
@ -198,10 +198,10 @@ class HmRadio {
mTxBuf[18] = 0x00; mTxBuf[18] = 0x00;
mTxBuf[19] = 0x00; mTxBuf[19] = 0x00;
} }
uint16_t crc = Hoymiles::crc16(&mTxBuf[10], 14); uint16_t crc = Ahoy::crc16(&mTxBuf[10], 14);
mTxBuf[24] = (crc >> 8) & 0xff; mTxBuf[24] = (crc >> 8) & 0xff;
mTxBuf[25] = (crc ) & 0xff; mTxBuf[25] = (crc ) & 0xff;
mTxBuf[26] = Hoymiles::crc8(mTxBuf, 26); mTxBuf[26] = Ahoy::crc8(mTxBuf, 26);
sendPacket(invId, mTxBuf, 27, true); sendPacket(invId, mTxBuf, 27, true);
} }
@ -214,7 +214,7 @@ class HmRadio {
CP_U32_BigEndian(&mTxBuf[5], (DTU_ID >> 8)); CP_U32_BigEndian(&mTxBuf[5], (DTU_ID >> 8));
mTxBuf[9] = pid; mTxBuf[9] = pid;
if(calcCrc) { if(calcCrc) {
mTxBuf[10] = Hoymiles::crc8(mTxBuf, 10); mTxBuf[10] = Ahoy::crc8(mTxBuf, 10);
sendPacket(invId, mTxBuf, 11, false); sendPacket(invId, mTxBuf, 11, false);
} }
} }
@ -228,7 +228,7 @@ class HmRadio {
buf[i-1] = (buf[i] << 1) | (buf[i+1] >> 7); buf[i-1] = (buf[i] << 1) | (buf[i+1] >> 7);
} }
uint8_t crc = Hoymiles::crc8(buf, *len-1); uint8_t crc = Ahoy::crc8(buf, *len-1);
bool valid = (crc == buf[*len-1]); bool valid = (crc == buf[*len-1]);
return valid; return valid;

30
tools/esp8266/html/serial.html

@ -9,7 +9,10 @@
<body> <body>
<h1>Serial Console</h1> <h1>Serial Console</h1>
<div id="content" class="content"> <div id="content" class="content">
<textarea rows="20" cols="90" id="serial" readonly></textarea> <div class="serial">
<textarea id="serial" cols="80" rows="20" readonly></textarea><br/>
conntected: <span class="dot" id="connected"></span><input type="button" value="clear" class="btn" id="clear"/> <input type="button" value="autoscroll" class="btn" id="scroll"/>
</div>
</div> </div>
<div id="footer"> <div id="footer">
<p class="left">&copy 2022</p> <p class="left">&copy 2022</p>
@ -17,34 +20,43 @@
<p class="right" id="version"></p> <p class="right" id="version"></p>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var printTime = true; var mPrintTime = true;
var mAutoScroll = true;
var con = document.getElementById("serial");
function parseSys(obj) { function parseSys(obj) {
document.getElementById("version").innerHTML = "Git SHA: " + obj["build"] + " :: " + obj["version"]; document.getElementById("version").innerHTML = "Git SHA: " + obj["build"] + " :: " + obj["version"];
} }
var con = document.getElementById("serial");
document.getElementById("clear").addEventListener("click", function() {
con.value = "";
});
document.getElementById("scroll").addEventListener("click", function() {
mAutoScroll = !mAutoScroll;
this.value = (mAutoScroll) ? "autoscroll" : "manual scoll";
});
if (!!window.EventSource) { if (!!window.EventSource) {
var source = new EventSource('/events'); var source = new EventSource('/events');
source.addEventListener('open', function(e) { source.addEventListener('open', function(e) {
//console.log("Events Connected"); document.getElementById("connected").style.backgroundColor = "#0c0";
}, false); }, false);
source.addEventListener('error', function(e) { source.addEventListener('error', function(e) {
if (e.target.readyState != EventSource.OPEN) { if (e.target.readyState != EventSource.OPEN) {
//console.log("Events Disconnected"); document.getElementById("connected").style.backgroundColor = "#f00";
} }
}, false); }, false);
source.addEventListener('serial', function(e) { source.addEventListener('serial', function(e) {
if(printTime) { if(mPrintTime) {
var d = new Date(); var d = new Date();
con.value += d.toLocaleTimeString() + ": "; con.value += d.toLocaleTimeString() + ": ";
printTime = false; mPrintTime = false;
} }
if(e.data.includes('<rn>')) if(e.data.includes('<rn>'))
printTime = true; mPrintTime = true;
con.value += e.data.replace(/\<rn\>/g, '\r\n'); con.value += e.data.replace(/\<rn\>/g, '\r\n');
con.scrollTop = con.scrollHeight; con.scrollTop = con.scrollHeight;

6
tools/esp8266/html/setup.html

@ -168,8 +168,8 @@
iv.appendChild(inp(id + i[0], obj[i[1]], i[3])); iv.appendChild(inp(id + i[0], obj[i[1]], i[3]));
} }
iv.appendChild(lbl(id + "ActivePowerLimitConType", "Active Power Limit Control Type")); iv.appendChild(lbl(id + "PowerLimitControl", "Active Power Limit Control Type"));
iv.appendChild(sel(id + "ActivePowerLimitConType", [ iv.appendChild(sel(id + "PowerLimitControl", [
[65535, "no power limit"], [65535, "no power limit"],
[0, "absolute in Watt non persistent"], [0, "absolute in Watt non persistent"],
[1, "absolute in Watt persistent"], [1, "absolute in Watt persistent"],
@ -179,7 +179,7 @@
for(var j of [["ModPwr", "ch_max_power", "Max Module Power (Wp)"], ["ModName", "ch_name", "Module Name"]]) { for(var j of [["ModPwr", "ch_max_power", "Max Module Power (Wp)"], ["ModName", "ch_name", "Module Name"]]) {
iv.appendChild(lbl(id + j[0], j[2])); iv.appendChild(lbl(id + j[0], j[2]));
d = div(j[0]); d = div([j[0]]);
i = 0; i = 0;
for(it of obj[j[1]]) { for(it of obj[j[1]]) {
d.appendChild(inp(id + j[0] + i, it, 4, ["text", "sh"])); d.appendChild(inp(id + j[0] + i, it, 4, ["text", "sh"]));

25
tools/esp8266/html/style.css

@ -134,8 +134,14 @@ input.btn {
color: #fff; color: #fff;
border: 0px; border: 0px;
float: right; float: right;
margin: 10px 0 30px; margin: 10px 0px 30px 10px;
padding: 7px 20px 7px 20px;
text-transform: uppercase; text-transform: uppercase;
cursor: pointer;
}
input.btn:hover {
background-color: #044e86;
} }
input.cb { input.cb {
@ -271,3 +277,20 @@ div.ModPwr, div.ModName {
width: 180px; width: 180px;
} }
} }
#serial {
width: 100%;
}
#content .serial {
max-width: 1000px;
}
.dot {
height: 15px;
width: 15px;
background-color: #f00;
border-radius: 50%;
display: inline-block;
margin-top: 15px;
}

1
tools/esp8266/include/dbg.h

@ -35,7 +35,6 @@
#ifdef ARDUINO #ifdef ARDUINO
#define DBG_CB std::function<void(String)> #define DBG_CB std::function<void(String)>
extern DBG_CB mCb; extern DBG_CB mCb;
//static DBG_CB mCb;
inline void registerDebugCb(DBG_CB cb) { inline void registerDebugCb(DBG_CB cb) {
mCb = cb; mCb = cb;

Loading…
Cancel
Save