[vz-dev] vzlogger: wieder ein bug im d0-parser
Thorben Thuermer
r00t at constancy.org
Thu Jan 10 23:21:43 CET 2013
On Thu, 10 Jan 2013 23:18:50 +0100
Thorben Thuermer <r00t at constancy.org> wrote:
> ich wuerde folgenden patch vorschlagen (ungetestet),
> um das byte optinal herauszuparsen, falls es vorhanden ist:
vergessen:
--- a/src/protocols/d0.c
+++ b/src/protocols/d0.c
@@ -137,7 +137,7 @@ int meter_close_d0(meter_t *mtr) {
size_t meter_read_d0(meter_t *mtr, reading_t rds[], size_t max_readings) {
meter_handle_d0_t *handle = &mtr->handle.d0;
- enum { START, VENDOR, BAUDRATE, IDENTIFICATION, START_LINE, OBIS_CODE, VALUE, UNIT, END_LINE, END } context;
+ enum { START, VENDOR, BAUDRATE, IDENTIFICATION, START_LINE, STX, OBIS_CODE, VALUE, UNIT, END_LINE, END } context;
char vendor[3+1]; /* 3 upper case vendor + '\0' termination */
char identification[16+1]; /* 16 meter specific + '\0' termination */
> --- a/src/protocols/d0.c
> +++ b/src/protocols/d0.c
> @@ -204,7 +204,7 @@ size_t meter_read_d0(meter_t *mtr, reading_t rds[], size_t max_readings) {
> case IDENTIFICATION: /* IDENTIFICATION has 16 bytes */
> if (byte == '\r' || byte == '\n') { /* detect line end */
> identification[byte_iterator] = '\0'; /* termination */
> - context = OBIS_CODE; /* set new context: IDENTIFICATION -> OBIS_CODE */
> + context = STX;
> byte_iterator = 0;
> }
> else identification[byte_iterator++] = byte;
>
> @@ -212,6 +212,10 @@ size_t meter_read_d0(meter_t *mtr, reading_t rds[], size_t max_readings) {
>
> case START_LINE:
> break;
> + case STX:
> + context = OBIS_CODE;
> + if (byte == 0x02) break;
> + // fall through
> case OBIS_CODE:
> if ((byte != '\n') && (byte != '\r'))
> {
- Thorben
More information about the volkszaehler-dev
mailing list