Own fork of MbedSmartRestMain

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

Committer:
xinlei
Date:
Wed May 20 09:57:55 2015 +0000
Revision:
117:e831cdb799ab
Parent:
114:c54e9731b9de
Child:
123:311fa85af2b3
remove useless debug for measurement timeout

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xinlei 100:dbcd3bc51758 1 #include <stdio.h>
xinlei 114:c54e9731b9de 2 #include "rtos.h"
xinlei 100:dbcd3bc51758 3 #include "SmartRestConf.h"
xinlei 100:dbcd3bc51758 4 #include "Acceleration.h"
xinlei 100:dbcd3bc51758 5 #include "logging.h"
xinlei 100:dbcd3bc51758 6
xinlei 100:dbcd3bc51758 7 // Percentage cut-off for avoiding sending similar sensor reading.
xinlei 100:dbcd3bc51758 8 #define THRESHOLD_PERCENT_ACCE 0.1
xinlei 100:dbcd3bc51758 9 // Timeout for forcing a sending even if readings are similar [seconds].
xinlei 100:dbcd3bc51758 10 #define TIME_LIMIT_ACCE 900
xinlei 100:dbcd3bc51758 11
xinlei 100:dbcd3bc51758 12 size_t Acceleration::read(char *buf, size_t maxLen, char *status, size_t num)
xinlei 100:dbcd3bc51758 13 {
xinlei 100:dbcd3bc51758 14 static const char *fmt = "106,%ld,%f,%f,%f\r\n";
xinlei 100:dbcd3bc51758 15 if (!deviceReady)
xinlei 100:dbcd3bc51758 16 return 0;
xinlei 114:c54e9731b9de 17 float data[3] = {0.0, 0.0, 0.0};
xinlei 114:c54e9731b9de 18 // float min[3] = {100, 100, 100};
xinlei 114:c54e9731b9de 19 // float max[3] = {0, 0, 0};
xinlei 114:c54e9731b9de 20 // const unsigned short N = 10;
xinlei 114:c54e9731b9de 21 // for (unsigned short i = 0; i < N; ++i) {
xinlei 114:c54e9731b9de 22 // float d[3] = {0, 0, 0};
xinlei 114:c54e9731b9de 23 // sensor.readData(d);
xinlei 114:c54e9731b9de 24 // for (unsigned short j = 0; j < 3; ++j) {
xinlei 114:c54e9731b9de 25 // data[j] += d[j];
xinlei 114:c54e9731b9de 26 // if (d[j] < min[j]) min[j] = d[j];
xinlei 114:c54e9731b9de 27 // if (d[j] > max[j]) max[j] = d[j];
xinlei 114:c54e9731b9de 28 // }
xinlei 114:c54e9731b9de 29 // Thread::wait(5);
xinlei 114:c54e9731b9de 30 // }
xinlei 114:c54e9731b9de 31 // data[0] = (data[0]-min[0]-max[0]) / (N-2);
xinlei 114:c54e9731b9de 32 // data[1] = (data[1]-min[1]-max[1]) / (N-2);
xinlei 114:c54e9731b9de 33 // data[2] = (data[2]-min[2]-max[2]) / (N-2);
xinlei 100:dbcd3bc51758 34 sensor.readData(data);
xinlei 100:dbcd3bc51758 35 if ((0.15 > abs(data[0]) || abs(oldValues[0]-data[0]) <= abs(oldValues[0])*THRESHOLD_PERCENT_ACCE) &&
xinlei 100:dbcd3bc51758 36 (0.10 > abs(data[1]) || abs(oldValues[1]-data[1]) <= abs(oldValues[1])*THRESHOLD_PERCENT_ACCE)) {
xinlei 114:c54e9731b9de 37 // if (abs(oldValues[0]-data[0]) <= abs(oldValues[0])*THRESHOLD_PERCENT_ACCE ||
xinlei 114:c54e9731b9de 38 // abs(oldValues[1]-data[1]) <= abs(oldValues[1])*THRESHOLD_PERCENT_ACCE ||
xinlei 114:c54e9731b9de 39 // abs(oldValues[2]-data[2]) <= abs(oldValues[2])*THRESHOLD_PERCENT_ACCE) {
xinlei 100:dbcd3bc51758 40 time_t t_interval = time(NULL) - t_start;
xinlei 100:dbcd3bc51758 41 if (t_interval < TIME_LIMIT_ACCE) {
xinlei 100:dbcd3bc51758 42 return 0;
xinlei 100:dbcd3bc51758 43 }
xinlei 100:dbcd3bc51758 44 }
xinlei 100:dbcd3bc51758 45
xinlei 100:dbcd3bc51758 46 size_t l = snprintf(buf, maxLen, fmt, deviceID, data[0], data[1], data[2]);
xinlei 100:dbcd3bc51758 47 if (status) {
xinlei 100:dbcd3bc51758 48 snprintf(status, num, "Send Acc %.1f,%.1f,%.1f",
xinlei 100:dbcd3bc51758 49 data[0], data[1], data[2]);
xinlei 100:dbcd3bc51758 50 }
xinlei 100:dbcd3bc51758 51 oldValues[0] = data[0];
xinlei 100:dbcd3bc51758 52 oldValues[1] = data[1];
xinlei 100:dbcd3bc51758 53 oldValues[2] = data[2];
xinlei 100:dbcd3bc51758 54 t_start = time(NULL);
xinlei 100:dbcd3bc51758 55 return l;
xinlei 100:dbcd3bc51758 56 }