Skip to content

Commit

Permalink
0.9.3
Browse files Browse the repository at this point in the history
better real support
fix failure with more VIFEs
  • Loading branch information
Zeppelin500 committed Apr 11, 2024
1 parent 9e3f17d commit c0e7053
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.9.3] - 2024-04-11

### Changed

- better real support
- fix failure with more VIFEs

## [0.9.2] - 2024-04-09

### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MBusinoLib - an Arduino M-Bus Decoder Library

[![version](https://img.shields.io/badge/version-0.9.2-brightgreen.svg)](CHANGELOG.md)
[![version](https://img.shields.io/badge/version-0.9.3-brightgreen.svg)](CHANGELOG.md)
[![license](https://img.shields.io/badge/license-GPL--3.0-orange.svg)](LICENSE)


Expand Down
2 changes: 1 addition & 1 deletion examples/MbusinoLibExample/MbusinoLibExample.ino
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void loop() {
uint8_t code = root[i]["code"].as<int>();
const char* name = root[i]["name"];
const char* units = root[i]["units"];
double value = root[i]["value_scaled"].as<double>();
float value = root[i]["value_scaled"].as<float>();
const char* valueString = root[i]["value_string"];

//values comes as number or as ASCII string or both
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "git",
"url": "https://github.com/Zeppelin500/MBusinoLib.git"
},
"version": "0.9.2",
"version": "0.9.3",
"license": "GPL-3.0",
"frameworks": "arduino",
"platforms": ["atmelavr", "atmelsam", "espressif8266"],
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=MBusinoLib
version=0.9.2
version=0.9.3
author=Zeppelin500 <[email protected]>
maintainer=Zeppelin500 <[email protected]>
sentence=an Arduino M-Bus decode Library
Expand Down
23 changes: 16 additions & 7 deletions src/MBusinoLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,21 @@ uint8_t MBusinoLib::decode(uint8_t *buffer, uint8_t size, JsonArray& root) {
_error = MBUS_ERROR::BUFFER_OVERFLOW;
return 0;
}
vifarray[vifcounter] = buffer[index];
vifarray[vifcounter] = buffer[index++];
if(vifcounter < 2){ // only vif and first vife will be stored
vif = (vif << 8) + vifarray[vifcounter];
}
vifcounter++;
vif = (vif << 8) + buffer[index++];
} while ((vif & 0x80) == 0x80);
} while ((vifarray[vifcounter-1] & 0x80) == 0x80);

if(((vifarray[0] & 0x80) == 0x80) && (vifarray[1] != 0x00 ) && (vifarray[0] != 0XFD) && (vifarray[0] != 0XFC)&& (vifarray[0] != 0XFB) && (vifarray[0] != 0XFF)){
vif = (vifarray[0] & 0x7F);
}

if((vifarray[1] & 0x80) == 0x80){ // set se first bit of first VIFE from 1 to 0 to find the right def
vif = (vif & 0xFF7F);
}

// Find definition
int8_t def = _findDefinition(vif);
if (def < 0) {
Expand Down Expand Up @@ -449,9 +455,13 @@ uint8_t MBusinoLib::decode(uint8_t *buffer, uint8_t size, JsonArray& root) {

// scaled value
double scaled = 0;
int8_t scalar = vif_defs[def].scalar + vif - vif_defs[def].base;
int8_t scalar = vif_defs[def].scalar + vif - vif_defs[def].base;
if(dataCodingType == 3){
scaled = valueFloat;
if(vifarray[0] != 0xFF){
for (int8_t i=0; i<scalar; i++) scaled *= 10;
for (int8_t i=scalar; i<0; i++) scaled /= 10;
}
}
else if(vifarray[0]==0xFF){
scaled = value;
Expand Down Expand Up @@ -503,9 +513,8 @@ uint8_t MBusinoLib::decode(uint8_t *buffer, uint8_t size, JsonArray& root) {
}
*/
if(buffer[index] == 0x0F ||buffer[index] == 0x1F){ // If last byte 1F/0F --> More records follow in next telegram
index++;
}
yield();
break;
}
}
return count;
}
Expand Down

0 comments on commit c0e7053

Please sign in to comment.