Paul van der Wielen
/
MT382_serial
Reading Utility metering data using MBED
main.cpp@2:b386810af678, 2012-09-30 (annotated)
- Committer:
- pwheels
- Date:
- Sun Sep 30 11:38:39 2012 +0000
- Revision:
- 2:b386810af678
- Parent:
- 0:bacf1c9b9afc
- Child:
- 3:5b5166815cd4
Added function as to return pointer to data array, ; adjusted main() as to provide an example of it's usage
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pwheels | 0:bacf1c9b9afc | 1 | #if 1 |
pwheels | 0:bacf1c9b9afc | 2 | /* |
pwheels | 0:bacf1c9b9afc | 3 | * Copyright (c) 2012 Paul van der Wielen, Pro-Serv |
pwheels | 0:bacf1c9b9afc | 4 | * |
pwheels | 0:bacf1c9b9afc | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
pwheels | 0:bacf1c9b9afc | 6 | * of this software and associated documentation files (the "Software"), to use |
pwheels | 0:bacf1c9b9afc | 7 | * and implement the software for none commercial reason and usage only and |
pwheels | 0:bacf1c9b9afc | 8 | * subject to the following conditions: |
pwheels | 0:bacf1c9b9afc | 9 | * |
pwheels | 0:bacf1c9b9afc | 10 | * The above copyright notice and this permission notice shall be included in |
pwheels | 0:bacf1c9b9afc | 11 | * all copies or substantial portions of the Software. |
pwheels | 0:bacf1c9b9afc | 12 | * |
pwheels | 0:bacf1c9b9afc | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
pwheels | 0:bacf1c9b9afc | 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
pwheels | 0:bacf1c9b9afc | 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
pwheels | 0:bacf1c9b9afc | 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
pwheels | 0:bacf1c9b9afc | 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
pwheels | 0:bacf1c9b9afc | 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
pwheels | 0:bacf1c9b9afc | 19 | * THE SOFTWARE. |
pwheels | 0:bacf1c9b9afc | 20 | */ |
pwheels | 0:bacf1c9b9afc | 21 | #include "mbed.h" |
pwheels | 0:bacf1c9b9afc | 22 | #include <stdlib.h> |
pwheels | 0:bacf1c9b9afc | 23 | #include <string> |
pwheels | 0:bacf1c9b9afc | 24 | |
pwheels | 0:bacf1c9b9afc | 25 | #include "mt382.h" |
pwheels | 0:bacf1c9b9afc | 26 | |
pwheels | 0:bacf1c9b9afc | 27 | MT382 mt382 ( p21, p28, p27); |
pwheels | 0:bacf1c9b9afc | 28 | |
pwheels | 0:bacf1c9b9afc | 29 | Serial pc(USBTX, USBRX); |
pwheels | 0:bacf1c9b9afc | 30 | DigitalOut myled(LED1); |
pwheels | 0:bacf1c9b9afc | 31 | |
pwheels | 0:bacf1c9b9afc | 32 | Ticker tx; |
pwheels | 0:bacf1c9b9afc | 33 | |
pwheels | 0:bacf1c9b9afc | 34 | void mt_ticker() { |
pwheels | 0:bacf1c9b9afc | 35 | if (mt382.getReading() != 0) { |
pwheels | 0:bacf1c9b9afc | 36 | printf("\nNo data found or time-out!\n"); |
pwheels | 0:bacf1c9b9afc | 37 | } else { |
pwheels | 0:bacf1c9b9afc | 38 | printf("Val_0 %.3lf, Val_1 %.3lf, Val_2 %.3lf, Val_3 %.3lf, Val_4 %.3lf, Val_5 %.3lf, Val_6 %.3lf\n", mt382.getValue(0), mt382.getValue(1), mt382.getValue(2), mt382.getValue(3), mt382.getValue(4), mt382.getValue(5), mt382.getValue(6)); |
pwheels | 0:bacf1c9b9afc | 39 | } |
pwheels | 0:bacf1c9b9afc | 40 | } |
pwheels | 0:bacf1c9b9afc | 41 | |
pwheels | 0:bacf1c9b9afc | 42 | int main() { |
pwheels | 0:bacf1c9b9afc | 43 | |
pwheels | 0:bacf1c9b9afc | 44 | pc.baud(460800); |
pwheels | 0:bacf1c9b9afc | 45 | // init device driver |
pwheels | 0:bacf1c9b9afc | 46 | mt382.setComm(9600, 7, 2, 1); |
pwheels | 0:bacf1c9b9afc | 47 | mt382.setTime(5.0); |
pwheels | 0:bacf1c9b9afc | 48 | mt382.setMatch("1.8.1","1.8.2","2.8.1","2.8.2","1.7.0","2.7.0","24.2.1"); |
pwheels | 0:bacf1c9b9afc | 49 | // get first pass of MT382 'Smart Meter' data |
pwheels | 0:bacf1c9b9afc | 50 | if (mt382.getReading() != 0) { |
pwheels | 0:bacf1c9b9afc | 51 | printf("\nNo data found or time-out!\n"); |
pwheels | 0:bacf1c9b9afc | 52 | } else { |
pwheels | 0:bacf1c9b9afc | 53 | printf("\nDone, char cnt %d !!\n", mt382.getCount()); |
pwheels | 2:b386810af678 | 54 | printf("Get data value by element\n"); |
pwheels | 0:bacf1c9b9afc | 55 | printf("Val_0 %.3lf, Val_1 %.3lf, Val_2 %.3lf, Val_3 %.3lf, Val_4 %.3lf, Val_5 %.3lf, Val_6 %.3lf\n", mt382.getValue(0), mt382.getValue(1), mt382.getValue(2), mt382.getValue(3), mt382.getValue(4), mt382.getValue(5), mt382.getValue(6)); |
pwheels | 2:b386810af678 | 56 | double * arr2 = mt382.getArray(); |
pwheels | 2:b386810af678 | 57 | printf("Get array with data by pointer\n"); |
pwheels | 2:b386810af678 | 58 | printf("Val_0 %.3lf, Val_1 %.3lf, Val_2 %.3lf, Val_3 %.3lf, Val_4 %.3lf, Val_5 %.3lf, Val_6 %.3lf\n", arr2[0], arr2[1], arr2[2], arr2[3], arr2[4], arr2[5], arr2[6]); |
pwheels | 0:bacf1c9b9afc | 59 | printf("Raw data was: \n%s\n\n", mt382.getRaw()); |
pwheels | 0:bacf1c9b9afc | 60 | } |
pwheels | 0:bacf1c9b9afc | 61 | // now setup collection interval |
pwheels | 0:bacf1c9b9afc | 62 | tx.attach(&mt_ticker, 10.0); |
pwheels | 0:bacf1c9b9afc | 63 | while(1) { |
pwheels | 0:bacf1c9b9afc | 64 | myled = 1; |
pwheels | 0:bacf1c9b9afc | 65 | wait(0.2); |
pwheels | 0:bacf1c9b9afc | 66 | myled = 0; |
pwheels | 0:bacf1c9b9afc | 67 | wait(0.2); |
pwheels | 0:bacf1c9b9afc | 68 | } |
pwheels | 0:bacf1c9b9afc | 69 | } |
pwheels | 0:bacf1c9b9afc | 70 | #endif |