Changeset 69
- Timestamp:
- 09/18/10 13:47:23 (14 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
webserver/example/EnergyMeters/EnergyMeters/ARM7_LPC2368_Rowley/webserver/httpd-cgi.c
r68 r69 70 70 extern int solarReadCounter; 71 71 extern unsigned char scDate[6]; /* date received from solar count */ 72 73 extern int resultValueRaw; /* last raw yield value */ 72 74 73 75 extern int solarStateWhenFail; … … 253 255 254 256 255 sprintf( cCountBuf, "<h2>Watt_CRCok=%u\r\nWatt_CRCfail=%u\r\nSC_Date=20%02d-%02d-%02d_%02d:%02d\r\nTimeQueries %d\r\nStateWhenFail=%u , chanWhenFail=%u </h2>",256 correctVoltWattRx, failedVoltWattRx, scDate[0], scDate[1], scDate[2], scDate[3], scDate[4], queryTimeCounter, solarStateWhenFail, currentChannelWhenFail 257 sprintf( cCountBuf, "<h2>Watt_CRCok=%u\r\nWatt_CRCfail=%u\r\nSC_Date=20%02d-%02d-%02d_%02d:%02d\r\nTimeQueries %d\r\nStateWhenFail=%u , chanWhenFail=%u , resultValueRaw=%u</h2>", 258 correctVoltWattRx, failedVoltWattRx, scDate[0], scDate[1], scDate[2], scDate[3], scDate[4], queryTimeCounter, solarStateWhenFail, currentChannelWhenFail, resultValueRaw 257 259 ); 258 260 strcat( uip_appdata, cCountBuf ); webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h
r67 r69 2 2 void initMeterItems(void); 3 3 4 portCHAR checkRxOneByteCheckSum(void); 5 portCHAR checkRxTwoByteCheckSum(unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ); 4 portCHAR checkRxOneByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte); 5 portCHAR checkRxTwoByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ); 6 7 int extractBinaryHexDigitString(unsigned char* srcDataStart, 8 unsigned char firstSrcByte, 9 unsigned char lastSrcByte 10 ); 11 6 12 7 13 unsigned long long getEpochTimeWithMs(void); webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c
r68 r69 40 40 unsigned long queryTimeCounter = 0; /* counter attempted queries for the time */ 41 41 42 int resultValueRaw = 0; /* last yield result value (raw) */ 43 42 44 static unsigned short staticCRC; 43 45 46 static unsigned short calculatedCrc2Byte; /* last calculated CRC (by checkRxTwoByteCheckSum() ) */ 47 static unsigned char calculatedCrc1Byte; /* last calculated CRC (by checkRxOneByteCheckSum() ) */ 44 48 45 49 // Pin I/O LED Control Maskbit … … 59 63 #define SOL_QUERY_TIME 4 /* querying the time on the SC */ 60 64 #define SOL_WAIT_FOR_TIME_RSP 5 /* waiting for reply on time query */ 65 #define SOL_QUERY_YIELD 6 /* querying yield data */ 66 #define SOL_QUERY_YIELD_WAIT_REPLY 7 /* waiting for yield data reply */ 61 67 #define SOL_FINISHED 0xA /* finished */ 62 68 //#define SOL_ … … 100 106 const unsigned char query_sc_time_rsp[] = "\x02\xF0\xB0\x08\x00\x84\x00\x00\x00\x00\x00\x00\x00\x03"; // Zeit abfragen 101 107 const unsigned char query_sc_time_r_m[] = "\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff"; // Zeit abfragen 108 109 // Query month 110 // Time Stamp:Year=10:Month=1 111 // ---> 01-Jun-2010 14:41:21 : 02 31 3c 4d 30 31 30 30 30 31 b0 03 112 // <--- 01-Jun-2010 14:41:21 : 02 31 4d 30 31 30 30 30 31 30 30 30 30 31 34 38 36 aa 03 03 113 114 // tt (time) values: m=minute , h = hour, D = day, M = month (\x31), Y = year 115 // cc (channel) values: x30 + channel number 116 // m1: month BCD msb, m2: month BCD lsb 117 // ck: checksum 118 // ad: unit address 119 // ad tt cc m1 m2 ck 120 //specification: unsigned char req_month_yield[] = "\x02\x31\x3c\x4d\x30\x31\x30\x30\x03"; // Frame for querying the yield. Will be filled in by solQueryYield() 121 122 // 02 31 3c 4d 30 30 30 30 30 31 fd 03 123 unsigned char req_month_yield[] = "\x02\x31\x3c\x4d\x30\x30\x30\x30\x30\x31\xfd\x03"; // Frame for querying the yield. Will be filled in by solQueryYield() 124 125 // tt (time) values: m=minute , h = hour, D = day, M = month (\x31), Y = year 126 // cc (channel) values: x30 + channel number 127 // m1: month BCD msb, m2: month BCD lsb 128 // ck: checksum 129 // ad: unit address 130 // r1 to r7: result binary coded hex 131 // ad tt cc m1 m2 r1 r2 r3 r4 r5 r6 r7 ck 132 //specification: unsigned char yield_month_rsp[] = "\x02\x31\x4d\x30\x00\x00\x09\x0c\x04\x0a\x26\x86\xcd\x00\x03"; /* exp. query yield response. Will be filled in by solQueryYield() */ 133 //specification: unsigned char yield_month_r_m[] = "\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff"; /* exp. query yield seq response mask. Will be filled in by solQueryYield() */ 134 135 // 02 31 4d 30 30 30 30 30 31 30 30 30 30 31 35 44 43 9a 03 03 136 // 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 137 unsigned char yield_month_rsp[] = "\x02\x31\x4d\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03"; /* exp. query yield response. Will be filled in by solQueryYield() */ 138 unsigned char yield_month_r_m[] = "\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff"; /* exp. query yield seq response mask. Will be filled in by solQueryYield() */ 139 102 140 103 141 //char init1[] = "abcdef"; … … 476 514 /* we have got a match! */ 477 515 478 if (checkRxTwoByteCheckSum( 1, 10, 11) == 1) /* checksum in bytes 11 and 12, check bytes 1 to 10 */516 if (checkRxTwoByteCheckSum(&(rxUART3[0]), 1, 10, 11) == 1) /* checksum in bytes 11 and 12, check bytes 1 to 10 */ 479 517 { 480 518 … … 497 535 498 536 xLastSolarStateChangeTime = xTaskGetTickCount(); 499 solarState = SOL_NO_INIT; /* change state: time response received, now init and query the channels */ 537 538 currentChannel = 0; /* start yield scan on channel 0 */ 539 solarState = SOL_QUERY_YIELD; /* change state: time response received, now init and query the channels */ 500 540 } 501 541 else … … 505 545 506 546 break; 547 548 case SOL_QUERY_YIELD: 549 550 xLastSolarStateChangeTime = xTaskGetTickCount(); 551 552 /* first, fill in data for tx */ 553 // TODO 554 555 556 // req_month_yield[4] = 0x30 + 1; // channel 557 // req_month_yield[8] = 0x30 + 0; // month MSB (binary coded hex) 558 // req_month_yield[9] = 0x30 + 4; // month LSB (binary coded hex) 559 560 /* then, calculate the CRC for tx */ 561 (void)checkRxOneByteCheckSum(&(req_month_yield[0]), 1, 7, 8); 562 /* checksum now in calculatedCrc1Byte */ 563 564 565 // crc 566 //req_month_yield[7] = calculatedCrc1Byte; /* fill in checksum */ 567 568 resetUart3RxBuf(); 569 send_uart3((unsigned char *)req_month_yield, sizeof(req_month_yield)); 570 571 solarState = SOL_QUERY_YIELD_WAIT_REPLY; /* change state: now wait for response */ 572 573 break; /* end of case SOL_QUERY_YIELD */ 574 575 case SOL_QUERY_YIELD_WAIT_REPLY: 576 577 578 579 cmpResult = checkUart3Received(yield_month_rsp, yield_month_r_m, sizeof(yield_month_rsp)-1); 580 581 582 /* wait for reply to request, check if full response has arrived */ 583 if (cmpResult == 0) 584 { 585 /* we have got a match! */ 586 587 588 resultValueRaw = extractBinaryHexDigitString( &(rxUART3[0]), 589 9, /* first byte of binary hex string */ 590 16 /* last byte of binary hex string */ 591 ); 592 593 594 595 solarState = SOL_NO_INIT; /* go ahead */ 596 597 } 598 #if 0 599 currentChannel++; /* next channel */ 600 601 if (currentChannel >= 6) 602 { 603 solarState = SOL_NO_INIT; /* change state: last channel done */ 604 } /* if */ 605 else 606 { 607 solarState = SOL_QUERY_YIELD; /* scan next channel */ 608 } /* else */ 609 #endif 610 611 break; /* end of case SOL_QUERY_YIELD_WAIT_REPLY */ 507 612 508 613 … … 616 721 { 617 722 618 if (checkRxTwoByteCheckSum( 1, 12, 13) == 1) /* checksum in bytes 13 and 14, check bytes 1 to 12 */723 if (checkRxTwoByteCheckSum(&(rxUART3[0]), 1, 12, 13) == 1) /* checksum in bytes 13 and 14, check bytes 1 to 12 */ 619 724 { 620 725 /* checksum correct */ … … 907 1012 908 1013 909 portCHAR checkRxOneByteCheckSum( void)1014 portCHAR checkRxOneByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte) 910 1015 { 911 1016 portCHAR retVal; /* return value */ … … 921 1026 922 1027 /* use bytes 1 to 13 for the checksum */ 923 for (x = 1; x <= 13; x++)1028 for (x = firstByte; x <= lastByte; x++) 924 1029 { 925 1030 926 1031 /* overflow? */ 927 // if (((portSHORT)crc + (portSHORT)( rxUART3[x])) > 0xFF)1032 // if (((portSHORT)crc + (portSHORT)(dataStart[x])) > 0xFF) 928 1033 // { 929 1034 // carry++; 930 1035 // } 931 1036 932 crcLONG = (crcLONG + rxUART3[x]); /* add and truncate to 8 bit */1037 crcLONG = (crcLONG + dataStart[x]); /* add and truncate to 8 bit */ 933 1038 } 934 1039 … … 941 1046 942 1047 943 if (crcCHARinv == rxUART3[14]) 1048 calculatedCrc1Byte = crcCHARinv; /* save calculated CRC (for use in case of checksum generation) */ 1049 1050 if (crcCHARinv == dataStart[charCheckSumStartByte]) 944 1051 { 945 1052 retVal = 1; /* checksum OK, data is valid */ … … 953 1060 954 1061 955 portCHAR checkRxTwoByteCheckSum(unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte )1062 portCHAR checkRxTwoByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ) 956 1063 { 957 1064 unsigned short cmpValue; … … 965 1072 { 966 1073 967 crc16_ccitt(rxUART3[x]); 968 } 969 970 971 972 cmpValue = ((((unsigned short)rxUART3[charCheckSumStartByte+1])<<8) | rxUART3[charCheckSumStartByte]); 1074 crc16_ccitt(dataStart[x]); 1075 } 1076 1077 1078 1079 cmpValue = ((((unsigned short)dataStart[charCheckSumStartByte+1])<<8) | dataStart[charCheckSumStartByte]); 1080 1081 calculatedCrc2Byte = staticCRC; /* save calculated CRC (for use in case of checksum generation) */ 1082 973 1083 if (cmpValue == (staticCRC & 0xFFFF)) 974 1084 { … … 996 1106 997 1107 1108 1109 1110 int extractBinaryHexDigitString(unsigned char* srcDataStart, 1111 unsigned char firstSrcByte, 1112 unsigned char lastSrcByte 1113 ) 1114 { 1115 1116 unsigned char x; 1117 int resultValue = 0; /* initial value */ 1118 unsigned char round = 0; /* which digit? 0 = LSB */ 1119 unsigned char currentCharValue; 1120 1121 /* go through the bytes backwards (least significant to most significant) */ 1122 for (x = lastSrcByte; x >= firstSrcByte; x--) 1123 { 1124 1125 currentCharValue = (srcDataStart[x]) - 0x30; 1126 resultValue = resultValue + (currentCharValue << (4 * round)); 1127 1128 round++; 1129 } /* for */ 1130 1131 return resultValue; 1132 1133 } /* extractBinaryHexDigitString() */