Reading Utility metering data using MBED

Dependencies:   mbed

main.cpp

Committer:
pwheels
Date:
2012-09-24
Revision:
0:bacf1c9b9afc
Child:
2:b386810af678

File content as of revision 0:bacf1c9b9afc:

#if 1
/*
 * Copyright (c) 2012 Paul van der Wielen, Pro-Serv
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to use
 * and implement the software for none commercial reason and usage only and
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#include "mbed.h"
#include <stdlib.h>
#include <string>

#include "mt382.h"

MT382  mt382 ( p21, p28, p27);

Serial pc(USBTX, USBRX);
DigitalOut myled(LED1);

Ticker tx;

void mt_ticker() {
    if (mt382.getReading() != 0) {
        printf("\nNo data found or time-out!\n");
    } else {
        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));
    }
}

int main() {

    pc.baud(460800);
    // init device driver 
    mt382.setComm(9600, 7, 2, 1);
    mt382.setTime(5.0);
    mt382.setMatch("1.8.1","1.8.2","2.8.1","2.8.2","1.7.0","2.7.0","24.2.1");
    // get first pass of MT382 'Smart Meter' data
    if (mt382.getReading() != 0) {
        printf("\nNo data found or time-out!\n");
    } else {
        printf("\nDone, char cnt %d !!\n", mt382.getCount());
        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));
        printf("Raw data was: \n%s\n\n", mt382.getRaw());
    }
    // now setup collection interval
    tx.attach(&mt_ticker, 10.0);
    while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }
}
#endif