![](/media/cache/group/u-blox_logo_trans.png.50x50_q85.png)
portable version of the cumulocity demo
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
SignalQualityMeasurement.cpp@56:2da813cc2f47, 2014-10-03 (annotated)
- Committer:
- ublox
- Date:
- Fri Oct 03 07:54:13 2014 +0000
- Revision:
- 56:2da813cc2f47
- Parent:
- 41:804f6a0bda26
update dependency
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Cumulocity | 41:804f6a0bda26 | 1 | #include "SignalQualityMeasurement.h" |
Cumulocity | 41:804f6a0bda26 | 2 | #include "ComposedRecord.h" |
Cumulocity | 41:804f6a0bda26 | 3 | #include "CharValue.h" |
Cumulocity | 41:804f6a0bda26 | 4 | #include "IntegerValue.h" |
Cumulocity | 41:804f6a0bda26 | 5 | #include "FloatValue.h" |
Cumulocity | 41:804f6a0bda26 | 6 | |
Cumulocity | 41:804f6a0bda26 | 7 | SignalQualityMeasurement::SignalQualityMeasurement(SmartRest& client, SmartRestTemplate& tpl, long& deviceId, DeviceInfo& deviceInfo) : |
Cumulocity | 41:804f6a0bda26 | 8 | _client(client), |
Cumulocity | 41:804f6a0bda26 | 9 | _tpl(tpl), |
Cumulocity | 41:804f6a0bda26 | 10 | _deviceId(deviceId), |
Cumulocity | 41:804f6a0bda26 | 11 | _deviceInfo(deviceInfo) |
Cumulocity | 41:804f6a0bda26 | 12 | { |
Cumulocity | 41:804f6a0bda26 | 13 | _init = false; |
Cumulocity | 41:804f6a0bda26 | 14 | } |
Cumulocity | 41:804f6a0bda26 | 15 | |
Cumulocity | 41:804f6a0bda26 | 16 | bool SignalQualityMeasurement::init() |
Cumulocity | 41:804f6a0bda26 | 17 | { |
Cumulocity | 41:804f6a0bda26 | 18 | if (_init) |
Cumulocity | 41:804f6a0bda26 | 19 | return false; |
Cumulocity | 41:804f6a0bda26 | 20 | |
Cumulocity | 41:804f6a0bda26 | 21 | // Insert measurement |
Cumulocity | 41:804f6a0bda26 | 22 | // USAGE: 104,<DEVICE/ID>,<RSSI>,<BER> |
Cumulocity | 41:804f6a0bda26 | 23 | if (!_tpl.add("10,104,POST,/measurement/measurements,application/vnd.com.nsn.cumulocity.measurement+json,application/vnd.com.nsn.cumulocity.measurement+json,%%,NOW UNSIGNED NUMBER UNSIGNED,\"{\"\"time\"\":\"\"%%\"\",\"\"source\"\":{\"\"id\"\":\"\"%%\"\"},\"\"type\"\":\"\"c8y_SignalStrength\"\",\"\"c8y_SignalStrength\"\":{\"\"rssi\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"dBm\"\"},\"\"ber\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"%\"\"}}}\"\r\n")) |
Cumulocity | 41:804f6a0bda26 | 24 | return false; |
Cumulocity | 41:804f6a0bda26 | 25 | |
Cumulocity | 41:804f6a0bda26 | 26 | _init = true; |
Cumulocity | 41:804f6a0bda26 | 27 | return true; |
Cumulocity | 41:804f6a0bda26 | 28 | } |
Cumulocity | 41:804f6a0bda26 | 29 | |
Cumulocity | 41:804f6a0bda26 | 30 | bool SignalQualityMeasurement::run() |
Cumulocity | 41:804f6a0bda26 | 31 | { |
Cumulocity | 41:804f6a0bda26 | 32 | DeviceInfo::SignalQuality *signalQuality; |
Cumulocity | 41:804f6a0bda26 | 33 | |
Cumulocity | 41:804f6a0bda26 | 34 | if ((signalQuality = _deviceInfo.signalQuality()) == NULL) |
Cumulocity | 41:804f6a0bda26 | 35 | return false; |
Cumulocity | 41:804f6a0bda26 | 36 | |
Cumulocity | 41:804f6a0bda26 | 37 | ComposedRecord record; |
Cumulocity | 41:804f6a0bda26 | 38 | IntegerValue msgId(104); |
Cumulocity | 41:804f6a0bda26 | 39 | IntegerValue devId(_deviceId); |
Cumulocity | 41:804f6a0bda26 | 40 | IntegerValue rssi(signalQuality->rssi); |
Cumulocity | 41:804f6a0bda26 | 41 | IntegerValue ber(signalQuality->ber); |
Cumulocity | 41:804f6a0bda26 | 42 | if ((!record.add(msgId)) || (!record.add(devId)) || (!record.add(rssi)) || (!record.add(ber))) |
Cumulocity | 41:804f6a0bda26 | 43 | return false; |
Cumulocity | 41:804f6a0bda26 | 44 | |
Cumulocity | 41:804f6a0bda26 | 45 | if (_client.send(record) != SMARTREST_SUCCESS) { |
Cumulocity | 41:804f6a0bda26 | 46 | puts("Signal measurement failed."); |
Cumulocity | 41:804f6a0bda26 | 47 | _client.stop(); |
Cumulocity | 41:804f6a0bda26 | 48 | return false; |
Cumulocity | 41:804f6a0bda26 | 49 | } |
Cumulocity | 41:804f6a0bda26 | 50 | _client.stop(); |
Cumulocity | 41:804f6a0bda26 | 51 | return true; |
Cumulocity | 41:804f6a0bda26 | 52 | } |