Fotobot
Get data from your photovoltaic plant
fronius_response.cpp
Go to the documentation of this file.
1 
7 #include "fronius_response.h"
8 
9 
10 FRONIUS_response::FRONIUS_response() {
11  hdr0=0;
12  hdr1=0;
13  hdr2=0;
14  length=0;
15  device_option=0;
16  device_number=0;
17  command=0;
18 }
19 
20 
27  return (hdr0==0x80 && hdr1==0x80 && hdr2==0x80);
28 }
29 
33 unsigned char FRONIUS_response::checksum() {
34  return buffer.buffer[length];
35 }
36 
37 
44  unsigned char chsum = \
45  length + \
46  device_option + \
47  device_number + \
48  command;
49  for (int i=0; i<length; i++) {
50  chsum += buffer.buffer[i];
51  }
52  return (chsum == checksum());
53 
54 }
55 
56 
61  int value;
62  signed char exponent = buffer.Value.exponent;
63 
64  if (exponent == 0xb) {
65  throw(QString(tr("overflow")));
66  }
67 
68  if (exponent == -4) {
69  throw(QString(tr("underflow")));
70  }
71 
72  value = buffer.Value.lsb;
73  value += buffer.Value.msb * 256;
74 
75  if (value > 32768) {
76  value = value - 65536;
77  }
78 
79  if (exponent == 0) {
80  return QVariant(value);
81  }
82 
83  if (exponent > 0) {
84  return QVariant( (int) (value * (pow(10, exponent)) ) );
85  }
86 
87  if (exponent < 0) {
88  return QVariant( ((double)value) * pow(10, exponent) );
89  }
90 
91  return QVariant();
92 }
93 
94 
QVariant value()
Decodes and returns value stored in response.
unsigned char checksum
Returns checksum of the response.
bool isChecksumValid()
Check header validity.
bool isHeaderValid()
Check header validity.