Paul van der Wielen
/
MT382_serial
Reading Utility metering data using MBED
Revision 4:1ebd1aabaa16, committed 2014-05-16
- Comitter:
- pwheels
- Date:
- Fri May 16 21:44:01 2014 +0000
- Parent:
- 3:5b5166815cd4
- Commit message:
- unfortunnally the driver had some odd gps test code in it, this has been corrected
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Jan 19 14:21:01 2014 +0000 +++ b/main.cpp Fri May 16 21:44:01 2014 +0000 @@ -22,23 +22,23 @@ #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); 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); @@ -47,57 +47,49 @@ 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"); + //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("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) { - // while (pc.readable()) - // { - // tmpValue[i++] = pc.getc(); - // led1 = !led1; - // } + 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; - // } + 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;