Browse Source

* improved serial console

* repaired /save
* removed yields (not allowed with async-web)
pull/283/head
lumapu 2 years ago
parent
commit
4561655d9d
  1. 23
      tools/esp8266/app.cpp
  2. 2
      tools/esp8266/app.h
  3. 45
      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

23
tools/esp8266/app.cpp

@ -289,12 +289,12 @@ bool app::buildPayload(uint8_t id) {
for(uint8_t i = 0; i < mPayload[id].maxPackId; i ++) {
if(mPayload[id].len[i] > 0) {
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)
| (mPayload[id].data[i][mPayload[id].len[i] - 1]);
}
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();
}
@ -728,19 +728,18 @@ void app::saveValues(void) {
Inverter<> *iv;
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
iv = mSys->getInverterByPos(i, false);
mEep->write(ADDR_INV_ADDR + (i * 8), iv->serial.u64);
mEep->write(ADDR_INV_PWR_LIM + i * 2, iv->powerLimit[0]);
mEep->write(ADDR_INV_PWR_LIM_CON + i * 2, iv->powerLimit[1]);
mEep->write(ADDR_INV_NAME + (i * MAX_NAME_LENGTH), iv->name, MAX_NAME_LENGTH);
// max channel power / name
for(uint8_t j = 0; j < 4; j++) {
mEep->write(ADDR_INV_CH_PWR + (i * 2 * 4) + (j*2), iv->chMaxPwr[j]);
mEep->write(ADDR_INV_CH_NAME + (i * 4 * MAX_NAME_LENGTH) + j * MAX_NAME_LENGTH, iv->chName[j], MAX_NAME_LENGTH);
}
mEep->write(ADDR_INV_ADDR + (i * 8), iv->serial.u64);
mEep->write(ADDR_INV_PWR_LIM + i * 2, iv->powerLimit[0]);
mEep->write(ADDR_INV_PWR_LIM_CON + i * 2, iv->powerLimit[1]);
mEep->write(ADDR_INV_NAME + (i * MAX_NAME_LENGTH), iv->name, MAX_NAME_LENGTH);
// max channel power / name
for(uint8_t j = 0; j < 4; j++) {
mEep->write(ADDR_INV_CH_PWR + (i * 2 * 4) + (j*2), iv->chMaxPwr[j]);
mEep->write(ADDR_INV_CH_NAME + (i * 4 * MAX_NAME_LENGTH) + j * MAX_NAME_LENGTH, iv->chName[j], MAX_NAME_LENGTH);
}
}
updateCrc();
mEep->commit();
}

2
tools/esp8266/app.h

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

45
tools/esp8266/crc.cpp

@ -5,34 +5,31 @@
#include "crc.h"
namespace Hoymiles {
uint8_t crc8(uint8_t buf[], uint8_t len) {
uint8_t crc = CRC8_INIT;
for(uint8_t i = 0; i < len; i++) {
crc ^= buf[i];
for(uint8_t b = 0; b < 8; b ++) {
crc = (crc << 1) ^ ((crc & 0x80) ? CRC8_POLY : 0x00);
namespace Ahoy {
uint8_t crc8(uint8_t buf[], uint8_t len) {
uint8_t crc = CRC8_INIT;
for(uint8_t i = 0; i < len; i++) {
crc ^= buf[i];
for(uint8_t b = 0; b < 8; b ++) {
crc = (crc << 1) ^ ((crc & 0x80) ? CRC8_POLY : 0x00);
}
}
yield();
return crc;
}
return crc;
}
uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start) {
uint16_t crc = start;
uint8_t shift = 0;
uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start) {
uint16_t crc = start;
uint8_t shift = 0;
for(uint8_t i = 0; i < len; i ++) {
crc = crc ^ buf[i];
for(uint8_t bit = 0; bit < 8; bit ++) {
shift = (crc & 0x0001);
crc = crc >> 1;
if(shift != 0)
crc = crc ^ CRC16_MODBUS_POLYNOM;
for(uint8_t i = 0; i < len; i ++) {
crc = crc ^ buf[i];
for(uint8_t bit = 0; bit < 8; bit ++) {
shift = (crc & 0x0001);
crc = crc >> 1;
if(shift != 0)
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
namespace Hoymiles {
namespace Ahoy {
uint8_t crc8(uint8_t buf[], uint8_t len);
uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start = 0xffff);
}
#endif /*__CRC_H__*/

12
tools/esp8266/hmRadio.h

@ -175,12 +175,12 @@ class HmRadio {
mTxBuf[10 + (++cnt)] = ((data[1] ) ) & 0xff; // setting for persistens handling
}
// 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 ) & 0xff;
// crc over all
cnt +=1;
mTxBuf[10 + cnt] = Hoymiles::crc8(mTxBuf, 10 + cnt);
mTxBuf[10 + cnt] = Ahoy::crc8(mTxBuf, 10 + cnt);
sendPacket(invId, mTxBuf, 10 + (++cnt), true);
}
@ -198,10 +198,10 @@ class HmRadio {
mTxBuf[18] = 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[25] = (crc ) & 0xff;
mTxBuf[26] = Hoymiles::crc8(mTxBuf, 26);
mTxBuf[26] = Ahoy::crc8(mTxBuf, 26);
sendPacket(invId, mTxBuf, 27, true);
}
@ -214,7 +214,7 @@ class HmRadio {
CP_U32_BigEndian(&mTxBuf[5], (DTU_ID >> 8));
mTxBuf[9] = pid;
if(calcCrc) {
mTxBuf[10] = Hoymiles::crc8(mTxBuf, 10);
mTxBuf[10] = Ahoy::crc8(mTxBuf, 10);
sendPacket(invId, mTxBuf, 11, false);
}
}
@ -228,7 +228,7 @@ class HmRadio {
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]);
return valid;

30
tools/esp8266/html/serial.html

@ -9,7 +9,10 @@
<body>
<h1>Serial Console</h1>
<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 id="footer">
<p class="left">&copy 2022</p>
@ -17,34 +20,43 @@
<p class="right" id="version"></p>
</div>
<script type="text/javascript">
var printTime = true;
var mPrintTime = true;
var mAutoScroll = true;
var con = document.getElementById("serial");
function parseSys(obj) {
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) {
var source = new EventSource('/events');
source.addEventListener('open', function(e) {
//console.log("Events Connected");
document.getElementById("connected").style.backgroundColor = "#0c0";
}, false);
source.addEventListener('error', function(e) {
if (e.target.readyState != EventSource.OPEN) {
//console.log("Events Disconnected");
document.getElementById("connected").style.backgroundColor = "#f00";
}
}, false);
source.addEventListener('serial', function(e) {
if(printTime) {
if(mPrintTime) {
var d = new Date();
con.value += d.toLocaleTimeString() + ": ";
printTime = false;
mPrintTime = false;
}
if(e.data.includes('<rn>'))
printTime = true;
mPrintTime = true;
con.value += e.data.replace(/\<rn\>/g, '\r\n');
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(lbl(id + "ActivePowerLimitConType", "Active Power Limit Control Type"));
iv.appendChild(sel(id + "ActivePowerLimitConType", [
iv.appendChild(lbl(id + "PowerLimitControl", "Active Power Limit Control Type"));
iv.appendChild(sel(id + "PowerLimitControl", [
[65535, "no power limit"],
[0, "absolute in Watt non 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"]]) {
iv.appendChild(lbl(id + j[0], j[2]));
d = div(j[0]);
d = div([j[0]]);
i = 0;
for(it of obj[j[1]]) {
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;
border: 0px;
float: right;
margin: 10px 0 30px;
margin: 10px 0px 30px 10px;
padding: 7px 20px 7px 20px;
text-transform: uppercase;
cursor: pointer;
}
input.btn:hover {
background-color: #044e86;
}
input.cb {
@ -271,3 +277,20 @@ div.ModPwr, div.ModName {
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
#define DBG_CB std::function<void(String)>
extern DBG_CB mCb;
//static DBG_CB mCb;
inline void registerDebugCb(DBG_CB cb) {
mCb = cb;

Loading…
Cancel
Save