Paul van der Wielen
/
MT382_serial
Reading Utility metering data using MBED
main.cpp@3:5b5166815cd4, 2014-01-19 (annotated)
- Committer:
- pwheels
- Date:
- Sun Jan 19 14:21:01 2014 +0000
- Revision:
- 3:5b5166815cd4
- Parent:
- 2:b386810af678
- Child:
- 4:1ebd1aabaa16
no detail
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 | 3:5b5166815cd4 | 25 | //#include "mt382.h" |
pwheels | 0:bacf1c9b9afc | 26 | |
pwheels | 3:5b5166815cd4 | 27 | //MT382 mt382 ( p21, p28, p27); |
pwheels | 0:bacf1c9b9afc | 28 | |
pwheels | 0:bacf1c9b9afc | 29 | Serial pc(USBTX, USBRX); |
pwheels | 3:5b5166815cd4 | 30 | Serial db(p28, p27); |
pwheels | 3:5b5166815cd4 | 31 | DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4); |
pwheels | 0:bacf1c9b9afc | 32 | |
pwheels | 3:5b5166815cd4 | 33 | //Ticker tx; |
pwheels | 0:bacf1c9b9afc | 34 | |
pwheels | 3:5b5166815cd4 | 35 | //void mt_ticker() { |
pwheels | 3:5b5166815cd4 | 36 | // if (mt382.getReading() != 0) { |
pwheels | 3:5b5166815cd4 | 37 | // printf("\nNo data found or time-out!\n"); |
pwheels | 3:5b5166815cd4 | 38 | // } else { |
pwheels | 3:5b5166815cd4 | 39 | // 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 | 3:5b5166815cd4 | 40 | // } |
pwheels | 3:5b5166815cd4 | 41 | //} |
pwheels | 3:5b5166815cd4 | 42 | unsigned char tmpValue[128] = {0}; |
pwheels | 3:5b5166815cd4 | 43 | |
pwheels | 3:5b5166815cd4 | 44 | void dis_cnt (int x_cnt); |
pwheels | 0:bacf1c9b9afc | 45 | |
pwheels | 0:bacf1c9b9afc | 46 | int main() { |
pwheels | 0:bacf1c9b9afc | 47 | |
pwheels | 3:5b5166815cd4 | 48 | pc.baud(9600); |
pwheels | 3:5b5166815cd4 | 49 | db.baud(9600); |
pwheels | 0:bacf1c9b9afc | 50 | // init device driver |
pwheels | 3:5b5166815cd4 | 51 | // mt382.setComm(9600, 7, 2, 1); |
pwheels | 3:5b5166815cd4 | 52 | // mt382.setTime(5.0); |
pwheels | 3:5b5166815cd4 | 53 | // 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 | 54 | // get first pass of MT382 'Smart Meter' data |
pwheels | 3:5b5166815cd4 | 55 | // if (mt382.getReading() != 0) { |
pwheels | 3:5b5166815cd4 | 56 | // printf("\nNo data found or time-out!\n"); |
pwheels | 3:5b5166815cd4 | 57 | // } else { |
pwheels | 3:5b5166815cd4 | 58 | // printf("\nDone, char cnt %d !!\n", mt382.getCount()); |
pwheels | 3:5b5166815cd4 | 59 | // printf("Get data value by element\n"); |
pwheels | 3:5b5166815cd4 | 60 | // 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 | 3:5b5166815cd4 | 61 | // double * arr2 = mt382.getArray(); |
pwheels | 3:5b5166815cd4 | 62 | // printf("Get array with data by pointer\n"); |
pwheels | 3:5b5166815cd4 | 63 | // 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 | 3:5b5166815cd4 | 64 | // printf("Raw data was: \n%s\n\n", mt382.getRaw()); |
pwheels | 3:5b5166815cd4 | 65 | // } |
pwheels | 0:bacf1c9b9afc | 66 | // now setup collection interval |
pwheels | 3:5b5166815cd4 | 67 | // tx.attach(&mt_ticker, 10.0); |
pwheels | 3:5b5166815cd4 | 68 | |
pwheels | 3:5b5166815cd4 | 69 | int i = 0; |
pwheels | 0:bacf1c9b9afc | 70 | while(1) { |
pwheels | 3:5b5166815cd4 | 71 | |
pwheels | 3:5b5166815cd4 | 72 | // while (pc.readable()) |
pwheels | 3:5b5166815cd4 | 73 | // { |
pwheels | 3:5b5166815cd4 | 74 | // tmpValue[i++] = pc.getc(); |
pwheels | 3:5b5166815cd4 | 75 | // led1 = !led1; |
pwheels | 3:5b5166815cd4 | 76 | // } |
pwheels | 3:5b5166815cd4 | 77 | wait(1); |
pwheels | 3:5b5166815cd4 | 78 | //dis_cnt (i); |
pwheels | 3:5b5166815cd4 | 79 | // if ((tmpValue[0] != 0x00) && (i == 5)) // or (i == 11) |
pwheels | 3:5b5166815cd4 | 80 | // { |
pwheels | 3:5b5166815cd4 | 81 | // pc.printf("%c%c%c%c%c" , 0x02,0x00,0x0C,0x00,0x03); |
pwheels | 3:5b5166815cd4 | 82 | // for(int j=0; j<i; j++) { |
pwheels | 3:5b5166815cd4 | 83 | // db.printf("%c" , tmpValue[j]); |
pwheels | 3:5b5166815cd4 | 84 | // } |
pwheels | 3:5b5166815cd4 | 85 | // tmpValue[0] = 0x00; |
pwheels | 3:5b5166815cd4 | 86 | // i = 0; |
pwheels | 3:5b5166815cd4 | 87 | // wait(1); |
pwheels | 3:5b5166815cd4 | 88 | // led1 = 0; |
pwheels | 3:5b5166815cd4 | 89 | // wait(2); |
pwheels | 3:5b5166815cd4 | 90 | // led2 = led3 = led4 = 0; |
pwheels | 3:5b5166815cd4 | 91 | // } |
pwheels | 3:5b5166815cd4 | 92 | |
pwheels | 3:5b5166815cd4 | 93 | printf("$GPRMC,072539.000,A,5115.0956,N,00401.6560,E,0.00,116.20,280813,,,A*6A\n"); |
pwheels | 3:5b5166815cd4 | 94 | printf("$GPGGA,072539.000,5115.0956,N,00401.6560,E,1,06,1.2,-11.6,M,46.0,M,,0000*40\n"); |
pwheels | 3:5b5166815cd4 | 95 | printf("$GPGSA,M,3,24,12,15,14,22,04,,,,,,,1.7,1.2,1.2*38\n"); |
pwheels | 3:5b5166815cd4 | 96 | printf("$GPGSV,3,1,10,01,00,359,,04,06,096,10,12,71,238,15,14,24,314,21*76\n"); |
pwheels | 3:5b5166815cd4 | 97 | printf("$GPGSV,3,2,10,15,28,178,08,17,27,047,08,18,07,243,08,22,14,275,16*78\n"); |
pwheels | 3:5b5166815cd4 | 98 | printf("$GPGSV,3,3,10,24,77,107,19,25,28,242,*79\n"); |
pwheels | 3:5b5166815cd4 | 99 | printf("$GPGST,072539.000,64,,,,17,14,18*4B\n"); |
pwheels | 3:5b5166815cd4 | 100 | |
pwheels | 3:5b5166815cd4 | 101 | led1 = 1; |
pwheels | 3:5b5166815cd4 | 102 | wait(60.2); |
pwheels | 3:5b5166815cd4 | 103 | led1 = 0; |
pwheels | 3:5b5166815cd4 | 104 | wait(.2); |
pwheels | 0:bacf1c9b9afc | 105 | } |
pwheels | 0:bacf1c9b9afc | 106 | } |
pwheels | 3:5b5166815cd4 | 107 | |
pwheels | 3:5b5166815cd4 | 108 | void dis_cnt (int x_cnt) |
pwheels | 3:5b5166815cd4 | 109 | { |
pwheels | 3:5b5166815cd4 | 110 | switch (x_cnt) |
pwheels | 3:5b5166815cd4 | 111 | { |
pwheels | 3:5b5166815cd4 | 112 | case 0: |
pwheels | 3:5b5166815cd4 | 113 | led2 = led3 = led4 = 0; |
pwheels | 3:5b5166815cd4 | 114 | break; |
pwheels | 3:5b5166815cd4 | 115 | case 1: |
pwheels | 3:5b5166815cd4 | 116 | led2 = led3 = 0; |
pwheels | 3:5b5166815cd4 | 117 | led4 = 1; |
pwheels | 3:5b5166815cd4 | 118 | break; |
pwheels | 3:5b5166815cd4 | 119 | case 2: |
pwheels | 3:5b5166815cd4 | 120 | led2 = led4 = 0; |
pwheels | 3:5b5166815cd4 | 121 | led3 = 1; |
pwheels | 3:5b5166815cd4 | 122 | break; |
pwheels | 3:5b5166815cd4 | 123 | case 3: |
pwheels | 3:5b5166815cd4 | 124 | led2 = 0; |
pwheels | 3:5b5166815cd4 | 125 | led3 = led4 = 1; |
pwheels | 3:5b5166815cd4 | 126 | break; |
pwheels | 3:5b5166815cd4 | 127 | case 4: |
pwheels | 3:5b5166815cd4 | 128 | led2 = 1; |
pwheels | 3:5b5166815cd4 | 129 | led3 = led4 = 0; |
pwheels | 3:5b5166815cd4 | 130 | break; |
pwheels | 3:5b5166815cd4 | 131 | case 5: |
pwheels | 3:5b5166815cd4 | 132 | led2 = led4 = 1; |
pwheels | 3:5b5166815cd4 | 133 | led3 = 0; |
pwheels | 3:5b5166815cd4 | 134 | break; |
pwheels | 3:5b5166815cd4 | 135 | case 6: |
pwheels | 3:5b5166815cd4 | 136 | led2 = led3 = 1; |
pwheels | 3:5b5166815cd4 | 137 | led4 = 0; |
pwheels | 3:5b5166815cd4 | 138 | break; |
pwheels | 3:5b5166815cd4 | 139 | case 7: |
pwheels | 3:5b5166815cd4 | 140 | led2 = led3 = led4 = 1; |
pwheels | 3:5b5166815cd4 | 141 | break; |
pwheels | 3:5b5166815cd4 | 142 | default: |
pwheels | 3:5b5166815cd4 | 143 | break; |
pwheels | 3:5b5166815cd4 | 144 | } |
pwheels | 3:5b5166815cd4 | 145 | } |
pwheels | 0:bacf1c9b9afc | 146 | #endif |