Paul van der Wielen
/
MT382_serial
Reading Utility metering data using MBED
Diff: main.cpp
- Revision:
- 3:5b5166815cd4
- Parent:
- 2:b386810af678
- Child:
- 4:1ebd1aabaa16
--- a/main.cpp Sun Sep 30 11:38:39 2012 +0000 +++ b/main.cpp Sun Jan 19 14:21:01 2014 +0000 @@ -22,49 +22,125 @@ #include <stdlib.h> #include <string> -#include "mt382.h" +//#include "mt382.h" -MT382 mt382 ( p21, p28, p27); +//MT382 mt382 ( p21, p28, p27); Serial pc(USBTX, USBRX); -DigitalOut myled(LED1); +Serial db(p28, p27); +DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4); -Ticker tx; +//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)); - } -} +//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)); +// } +//} +unsigned char tmpValue[128] = {0}; + +void dis_cnt (int x_cnt); int main() { - pc.baud(460800); + pc.baud(9600); + db.baud(9600); // 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"); +// 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("Get data value by element\n"); - 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)); - double * arr2 = mt382.getArray(); - printf("Get array with data by pointer\n"); - 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]); - printf("Raw data was: \n%s\n\n", mt382.getRaw()); - } +// if (mt382.getReading() != 0) { +// printf("\nNo data found or time-out!\n"); +// } else { +// printf("\nDone, char cnt %d !!\n", mt382.getCount()); +// printf("Get data value by element\n"); +// 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)); +// double * arr2 = mt382.getArray(); +// printf("Get array with data by pointer\n"); +// 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]); +// printf("Raw data was: \n%s\n\n", mt382.getRaw()); +// } // now setup collection interval - tx.attach(&mt_ticker, 10.0); +// tx.attach(&mt_ticker, 10.0); + + int i = 0; while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); + + // while (pc.readable()) + // { + // tmpValue[i++] = pc.getc(); + // led1 = !led1; + // } + wait(1); + //dis_cnt (i); + // if ((tmpValue[0] != 0x00) && (i == 5)) // or (i == 11) + // { + // pc.printf("%c%c%c%c%c" , 0x02,0x00,0x0C,0x00,0x03); + // for(int j=0; j<i; j++) { + // db.printf("%c" , tmpValue[j]); + // } + // tmpValue[0] = 0x00; + // i = 0; + // wait(1); + // led1 = 0; + // wait(2); + // led2 = led3 = led4 = 0; + // } + + printf("$GPRMC,072539.000,A,5115.0956,N,00401.6560,E,0.00,116.20,280813,,,A*6A\n"); + printf("$GPGGA,072539.000,5115.0956,N,00401.6560,E,1,06,1.2,-11.6,M,46.0,M,,0000*40\n"); + printf("$GPGSA,M,3,24,12,15,14,22,04,,,,,,,1.7,1.2,1.2*38\n"); + printf("$GPGSV,3,1,10,01,00,359,,04,06,096,10,12,71,238,15,14,24,314,21*76\n"); + printf("$GPGSV,3,2,10,15,28,178,08,17,27,047,08,18,07,243,08,22,14,275,16*78\n"); + printf("$GPGSV,3,3,10,24,77,107,19,25,28,242,*79\n"); + printf("$GPGST,072539.000,64,,,,17,14,18*4B\n"); + + led1 = 1; + wait(60.2); + led1 = 0; + wait(.2); } } + +void dis_cnt (int x_cnt) +{ + switch (x_cnt) + { + case 0: + led2 = led3 = led4 = 0; + break; + case 1: + led2 = led3 = 0; + led4 = 1; + break; + case 2: + led2 = led4 = 0; + led3 = 1; + break; + case 3: + led2 = 0; + led3 = led4 = 1; + break; + case 4: + led2 = 1; + led3 = led4 = 0; + break; + case 5: + led2 = led4 = 1; + led3 = 0; + break; + case 6: + led2 = led3 = 1; + led4 = 0; + break; + case 7: + led2 = led3 = led4 = 1; + break; + default: + break; + } +} #endif \ No newline at end of file