summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorChristian Pointner <equinox@mur.at>2012-01-04 03:23:17 +0000
committerChristian Pointner <equinox@mur.at>2012-01-04 03:23:17 +0000
commit722d539ab6f89018657faaaec1778b086c395e7a (patch)
tree322f0e5013925115859815db78fabd4df8a6c796 /tools
parentfirst solar power calc tests (diff)
solar power calculations work now
git-svn-id: https://svn.spreadspace.org/mur.sat@231 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'tools')
-rw-r--r--tools/solarmeter/solarmeter.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/tools/solarmeter/solarmeter.c b/tools/solarmeter/solarmeter.c
index 1ddca80..9aace5b 100644
--- a/tools/solarmeter/solarmeter.c
+++ b/tools/solarmeter/solarmeter.c
@@ -11,7 +11,7 @@ int main (int argc, char* argv[])
{
u_int8_t tmp = 0;
u_int8_t buffer[12];
- u_int16_t power = 0;
+ u_int32_t power[2];
int infile_fd = -1;
if (argc > 1) {
@@ -26,22 +26,30 @@ int main (int argc, char* argv[])
while (read(infile_fd, &tmp, 1) == 1) {
if (tmp == 255) {
- if (read(infile_fd, &buffer, sizeof(buffer)) != sizeof(buffer)) {
- perror("read error:");
+ int ret = read(infile_fd, &buffer, sizeof(buffer));
+ if(ret < 0) {
+ perror("read error");
return 2;
+ } else if(!ret) {
+ return 0;
+ } else if(ret != sizeof(buffer)) {
+ continue;
}
- power = (buffer[10]<<8) + buffer[11];
- printf("%5d (", power);
+ power[0] = (buffer[10]<<8) + buffer[11];
+ printf("%5d (", power[0]);
int i;
for(i=0; i<10; i++)
printf("%3d ", buffer[i]);
- power = (((u_int16_t)buffer[0] + (u_int16_t)buffer[1] + (u_int16_t)buffer[2] + (u_int16_t)buffer[3]) * (u_int16_t)buffer[4]) +
- (((u_int16_t)buffer[5] + (u_int16_t)buffer[6] + (u_int16_t)buffer[7] + (u_int16_t)buffer[8]) * (u_int16_t)buffer[9]);
-
- printf(") -> %5d\r", power);
+ power[1] = (((u_int16_t)buffer[0] + (u_int16_t)buffer[1] + (u_int16_t)buffer[2] + (u_int16_t)buffer[3]) * (u_int32_t)buffer[4]) +
+ (((u_int16_t)buffer[5] + (u_int16_t)buffer[6] + (u_int16_t)buffer[7] + (u_int16_t)buffer[8]) * (u_int32_t)buffer[9]);
+ int tmp = 0;
+ if(power[1]%128 >= 64) tmp=1;
+ power[1] /= 128;
+ power[1] += tmp;
+ printf(") -> %s (%5d) \n", power[1] == power[0] ? "ok" : "xx", power[1]);
}
}
printf("\n");