mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-16 02:16:37 +02:00
* improved serial console
* repaired /save * removed yields (not allowed with async-web)
This commit is contained in:
parent
c32927a94e
commit
4561655d9d
9 changed files with 88 additions and 60 deletions
|
@ -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();
|
||||
}
|
||||
|
@ -740,7 +740,6 @@ void app::saveValues(void) {
|
|||
}
|
||||
|
||||
updateCrc();
|
||||
mEep->commit();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -5,21 +5,19 @@
|
|||
|
||||
#include "crc.h"
|
||||
|
||||
namespace Hoymiles {
|
||||
|
||||
uint8_t crc8(uint8_t buf[], uint8_t len) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start) {
|
||||
uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start) {
|
||||
uint16_t crc = start;
|
||||
uint8_t shift = 0;
|
||||
|
||||
|
@ -31,8 +29,7 @@ uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start) {
|
|||
if(shift != 0)
|
||||
crc = crc ^ CRC16_MODBUS_POLYNOM;
|
||||
}
|
||||
yield();
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
}
|
||||
} // namespace Hoymiles
|
|
@ -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__*/
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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">© 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;
|
||||
|
|
|
@ -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"]));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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…
Add table
Add a link
Reference in a new issue