dynamic adding of xdr boat data for implemented n2k conversions
This commit is contained in:
parent
166d8d826b
commit
fb13a70ce6
|
@ -17,6 +17,8 @@ template<class T> GwBoatItem<T> *GwBoatData::getOrCreate(T initial, GwBoatItemNa
|
||||||
if (it != values.end()) {
|
if (it != values.end()) {
|
||||||
int expectedType=GwBoatItemTypes::getType(initial);
|
int expectedType=GwBoatItemTypes::getType(initial);
|
||||||
if (expectedType != it->second->getCurrentType()){
|
if (expectedType != it->second->getCurrentType()){
|
||||||
|
LOG_DEBUG(GwLog::DEBUG,"invalid type for boat item %s, expected %d, got %d",
|
||||||
|
name.c_str(),expectedType,it->second->getCurrentType());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return (GwBoatItem<T>*)(it->second);
|
return (GwBoatItem<T>*)(it->second);
|
||||||
|
@ -26,6 +28,8 @@ template<class T> GwBoatItem<T> *GwBoatData::getOrCreate(T initial, GwBoatItemNa
|
||||||
provider->getInvalidTime(),
|
provider->getInvalidTime(),
|
||||||
&values);
|
&values);
|
||||||
rt->update(initial);
|
rt->update(initial);
|
||||||
|
LOG_DEBUG(GwLog::LOG,"creating boatItem %s, type %d",
|
||||||
|
name.c_str(),rt->getCurrentType());
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
template<class T> bool GwBoatData::update(T value,int source,GwBoatItemNameProvider *provider){
|
template<class T> bool GwBoatData::update(T value,int source,GwBoatItemNameProvider *provider){
|
||||||
|
|
|
@ -80,7 +80,7 @@ template<class T> class GwBoatItem : public GwBoatItemBase{
|
||||||
public:
|
public:
|
||||||
GwBoatItem(int type,String name,String formatInfo,unsigned long invalidTime=INVALID_TIME,GwBoatItemMap *map=NULL):
|
GwBoatItem(int type,String name,String formatInfo,unsigned long invalidTime=INVALID_TIME,GwBoatItemMap *map=NULL):
|
||||||
GwBoatItemBase(name,formatInfo,invalidTime){
|
GwBoatItemBase(name,formatInfo,invalidTime){
|
||||||
type=type;
|
this->type=type;
|
||||||
if (map){
|
if (map){
|
||||||
(*map)[name]=this;
|
(*map)[name]=this;
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ template<class T> class GwBoatItem : public GwBoatItemBase{
|
||||||
//priority handling
|
//priority handling
|
||||||
//sources with lower ids will win
|
//sources with lower ids will win
|
||||||
//and we will not overwrite their value
|
//and we will not overwrite their value
|
||||||
if (lastUpdateSource < source){
|
if (lastUpdateSource < source && lastUpdateSource >= 0){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,10 @@ private:
|
||||||
return false;
|
return false;
|
||||||
return item->update(value,sourceId);
|
return item->update(value,sourceId);
|
||||||
}
|
}
|
||||||
|
bool updateDouble(GwXDRFoundMapping * mapping, double &value){
|
||||||
|
if (mapping->empty) return false;
|
||||||
|
return boatData->update(value,sourceId,mapping);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned long LastPosSend;
|
unsigned long LastPosSend;
|
||||||
unsigned long NextRMCSend;
|
unsigned long NextRMCSend;
|
||||||
|
@ -1187,7 +1191,7 @@ private:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GwXDRFoundMapping mapping=xdrMappings->getMapping(XDRTEMP,(int)TemperatureSource,0,TemperatureInstance);
|
GwXDRFoundMapping mapping=xdrMappings->getMapping(XDRTEMP,(int)TemperatureSource,0,TemperatureInstance);
|
||||||
if (mapping.empty) return;
|
if (! updateDouble(&mapping,Temperature)) return;
|
||||||
LOG_DEBUG(GwLog::DEBUG+1,"found temperature mapping %s",mapping.definition->toString().c_str());
|
LOG_DEBUG(GwLog::DEBUG+1,"found temperature mapping %s",mapping.definition->toString().c_str());
|
||||||
addToXdr(mapping.buildXdrEntry(Temperature));
|
addToXdr(mapping.buildXdrEntry(Temperature));
|
||||||
finalizeXdr();
|
finalizeXdr();
|
||||||
|
@ -1204,7 +1208,7 @@ private:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GwXDRFoundMapping mapping=xdrMappings->getMapping(XDRHUMIDITY,(int)HumiditySource,0,HumidityInstance);
|
GwXDRFoundMapping mapping=xdrMappings->getMapping(XDRHUMIDITY,(int)HumiditySource,0,HumidityInstance);
|
||||||
if (mapping.empty) return;
|
if (! updateDouble(&mapping,ActualHumidity)) return;
|
||||||
LOG_DEBUG(GwLog::DEBUG+1,"found humidity mapping %s",mapping.definition->toString().c_str());
|
LOG_DEBUG(GwLog::DEBUG+1,"found humidity mapping %s",mapping.definition->toString().c_str());
|
||||||
addToXdr(mapping.buildXdrEntry(ActualHumidity));
|
addToXdr(mapping.buildXdrEntry(ActualHumidity));
|
||||||
finalizeXdr();
|
finalizeXdr();
|
||||||
|
@ -1221,8 +1225,7 @@ private:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GwXDRFoundMapping mapping=xdrMappings->getMapping(XDRPRESSURE,(int)PressureSource,0,PressureInstance);
|
GwXDRFoundMapping mapping=xdrMappings->getMapping(XDRPRESSURE,(int)PressureSource,0,PressureInstance);
|
||||||
if (mapping.empty) return;
|
if (! updateDouble(&mapping,ActualPressure)) return;
|
||||||
if (! boatData->update(ActualPressure,sourceId,&mapping)) return;
|
|
||||||
LOG_DEBUG(GwLog::DEBUG+1,"found pressure mapping %s",mapping.definition->toString().c_str());
|
LOG_DEBUG(GwLog::DEBUG+1,"found pressure mapping %s",mapping.definition->toString().c_str());
|
||||||
addToXdr(mapping.buildXdrEntry(ActualPressure));
|
addToXdr(mapping.buildXdrEntry(ActualPressure));
|
||||||
finalizeXdr();
|
finalizeXdr();
|
||||||
|
|
|
@ -188,6 +188,10 @@ GwXDRMappingDef *GwXDRMappingDef::fromString(String s)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (rt->direction == GwXDRMappingDef::M_DISABLED || rt->xdrName == ""){
|
||||||
|
delete rt;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
String GwXDRMappingDef::getTransducerName(int instance)
|
String GwXDRMappingDef::getTransducerName(int instance)
|
||||||
|
|
|
@ -166,7 +166,7 @@ class GwXDRFoundMapping : public GwBoatItemNameProvider{
|
||||||
String buildXdrEntry(double value);
|
String buildXdrEntry(double value);
|
||||||
//boat Data info
|
//boat Data info
|
||||||
virtual String getBoatItemName(){
|
virtual String getBoatItemName(){
|
||||||
return getTransducerName();
|
return String("xdr")+getTransducerName();
|
||||||
};
|
};
|
||||||
virtual String getBoatItemFormat(){
|
virtual String getBoatItemFormat(){
|
||||||
return "formatXdr"+type->xdrunit; //TODO: use the type def for the correct format
|
return "formatXdr"+type->xdrunit; //TODO: use the type def for the correct format
|
||||||
|
|
|
@ -242,7 +242,7 @@ body{
|
||||||
}
|
}
|
||||||
|
|
||||||
.dash {
|
.dash {
|
||||||
width: 6em;
|
width: 6.5em;
|
||||||
height: 4em;
|
height: 4em;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
40
web/index.js
40
web/index.js
|
@ -1025,6 +1025,15 @@ let valueFormatters = {
|
||||||
u:'m'
|
u:'m'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function resizeFont(el,reset,maxIt){
|
||||||
|
if (maxIt === undefined) maxIt=10;
|
||||||
|
if (! el) return;
|
||||||
|
if (reset) el.style.fontSize='';
|
||||||
|
while (el.scrollWidth > el.clientWidth && maxIt){
|
||||||
|
let next=parseFloat(window.getComputedStyle(el).fontSize)*0.9;
|
||||||
|
el.style.fontSize=next+"px";
|
||||||
|
}
|
||||||
|
}
|
||||||
function createDashboardItem(name, def, parent) {
|
function createDashboardItem(name, def, parent) {
|
||||||
let frame = addEl('div', 'dash', parent);
|
let frame = addEl('div', 'dash', parent);
|
||||||
let title = addEl('span', 'dashTitle', frame, name);
|
let title = addEl('span', 'dashTitle', frame, name);
|
||||||
|
@ -1035,7 +1044,11 @@ function createDashboardItem(name, def, parent) {
|
||||||
let footer = addEl('div','footer',frame);
|
let footer = addEl('div','footer',frame);
|
||||||
let src= addEl('span','source',footer);
|
let src= addEl('span','source',footer);
|
||||||
src.setAttribute('id','source_'+name);
|
src.setAttribute('id','source_'+name);
|
||||||
addEl('span','unit',footer,fmt?fmt.u:'');
|
let u=fmt?fmt.u:'';
|
||||||
|
if (! fmt && def.format.match(/formatXdr/)){
|
||||||
|
u=def.format.replace(/formatXdr/,'');
|
||||||
|
}
|
||||||
|
addEl('span','unit',footer,u);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
function createDashboard() {
|
function createDashboard() {
|
||||||
|
@ -1057,9 +1070,14 @@ function sourceName(v){
|
||||||
return "---";
|
return "---";
|
||||||
}
|
}
|
||||||
function updateDashboard(data) {
|
function updateDashboard(data) {
|
||||||
|
let frame = document.getElementById('dashboardPage');
|
||||||
for (let n in data) {
|
for (let n in data) {
|
||||||
let de = document.getElementById('data_' + n);
|
let de = document.getElementById('data_' + n);
|
||||||
|
if (! de && frame){
|
||||||
|
de=createDashboardItem(n,data[n],frame);
|
||||||
|
}
|
||||||
if (de) {
|
if (de) {
|
||||||
|
let newContent='----';
|
||||||
if (data[n].valid) {
|
if (data[n].valid) {
|
||||||
let formatter;
|
let formatter;
|
||||||
if (data[n].format && data[n].format != "NULL") {
|
if (data[n].format && data[n].format != "NULL") {
|
||||||
|
@ -1067,26 +1085,38 @@ function updateDashboard(data) {
|
||||||
formatter = valueFormatters[key];
|
formatter = valueFormatters[key];
|
||||||
}
|
}
|
||||||
if (formatter) {
|
if (formatter) {
|
||||||
de.textContent = formatter.f(data[n].value);
|
newContent = formatter.f(data[n].value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let v = parseFloat(data[n].value);
|
let v = parseFloat(data[n].value);
|
||||||
if (!isNaN(v)) {
|
if (!isNaN(v)) {
|
||||||
v = v.toFixed(3)
|
v = v.toFixed(3)
|
||||||
de.textContent = v;
|
newContent = v;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
de.textContent = data[n].value;
|
newContent = data[n].value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else de.textContent = "---";
|
else newContent = "---";
|
||||||
|
if (newContent !== de.textContent){
|
||||||
|
de.textContent=newContent;
|
||||||
|
resizeFont(de,true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let src=document.getElementById('source_'+n);
|
let src=document.getElementById('source_'+n);
|
||||||
if (src){
|
if (src){
|
||||||
src.textContent=sourceName(data[n].source);
|
src.textContent=sourceName(data[n].source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
forEl('.dashValue',function(el){
|
||||||
|
let id=el.getAttribute('id');
|
||||||
|
if (id){
|
||||||
|
if (! data[id.replace(/^data_/,'')]){
|
||||||
|
el.parentElement.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
window.setInterval(update, 1000);
|
window.setInterval(update, 1000);
|
||||||
|
|
Loading…
Reference in New Issue