Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:bacf1c9b9afc, 2012-09-24 (annotated)
- Committer:
- pwheels
- Date:
- Mon Sep 24 12:33:58 2012 +0000
- Revision:
- 0:bacf1c9b9afc
- Child:
- 2:b386810af678
MT382 (Smart Meter) interface using P1 port - initial release
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 | 0:bacf1c9b9afc | 54 | 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 | 55 | printf("Raw data was: \n%s\n\n", mt382.getRaw()); |
| pwheels | 0:bacf1c9b9afc | 56 | } |
| pwheels | 0:bacf1c9b9afc | 57 | // now setup collection interval |
| pwheels | 0:bacf1c9b9afc | 58 | tx.attach(&mt_ticker, 10.0); |
| pwheels | 0:bacf1c9b9afc | 59 | while(1) { |
| pwheels | 0:bacf1c9b9afc | 60 | myled = 1; |
| pwheels | 0:bacf1c9b9afc | 61 | wait(0.2); |
| pwheels | 0:bacf1c9b9afc | 62 | myled = 0; |
| pwheels | 0:bacf1c9b9afc | 63 | wait(0.2); |
| pwheels | 0:bacf1c9b9afc | 64 | } |
| pwheels | 0:bacf1c9b9afc | 65 | } |
| pwheels | 0:bacf1c9b9afc | 66 | #endif |