Index: /webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c =================================================================== --- /webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c (revision 68) +++ /webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c (revision 69) @@ -40,6 +40,10 @@ unsigned long queryTimeCounter = 0; /* counter attempted queries for the time */ +int resultValueRaw = 0; /* last yield result value (raw) */ + static unsigned short staticCRC; +static unsigned short calculatedCrc2Byte; /* last calculated CRC (by checkRxTwoByteCheckSum() ) */ +static unsigned char calculatedCrc1Byte; /* last calculated CRC (by checkRxOneByteCheckSum() ) */ // Pin I/O LED Control Maskbit @@ -59,4 +63,6 @@ #define SOL_QUERY_TIME 4 /* querying the time on the SC */ #define SOL_WAIT_FOR_TIME_RSP 5 /* waiting for reply on time query */ +#define SOL_QUERY_YIELD 6 /* querying yield data */ +#define SOL_QUERY_YIELD_WAIT_REPLY 7 /* waiting for yield data reply */ #define SOL_FINISHED 0xA /* finished */ //#define SOL_ @@ -100,4 +106,36 @@ const unsigned char query_sc_time_rsp[] = "\x02\xF0\xB0\x08\x00\x84\x00\x00\x00\x00\x00\x00\x00\x03"; // Zeit abfragen const unsigned char query_sc_time_r_m[] = "\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff"; // Zeit abfragen + +// Query month +// Time Stamp:Year=10:Month=1 +// ---> 01-Jun-2010 14:41:21 : 02 31 3c 4d 30 31 30 30 30 31 b0 03 +// <--- 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 + +// tt (time) values: m=minute , h = hour, D = day, M = month (\x31), Y = year +// cc (channel) values: x30 + channel number +// m1: month BCD msb, m2: month BCD lsb +// ck: checksum +// ad: unit address +// ad tt cc m1 m2 ck +//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() + +// 02 31 3c 4d 30 30 30 30 30 31 fd 03 +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() + +// tt (time) values: m=minute , h = hour, D = day, M = month (\x31), Y = year +// cc (channel) values: x30 + channel number +// m1: month BCD msb, m2: month BCD lsb +// ck: checksum +// ad: unit address +// r1 to r7: result binary coded hex +// ad tt cc m1 m2 r1 r2 r3 r4 r5 r6 r7 ck +//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() */ +//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() */ + +// 02 31 4d 30 30 30 30 30 31 30 30 30 30 31 35 44 43 9a 03 03 +// 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 +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() */ +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() */ + //char init1[] = "abcdef"; @@ -476,5 +514,5 @@ /* we have got a match! */ - if (checkRxTwoByteCheckSum(1, 10, 11) == 1) /* checksum in bytes 11 and 12, check bytes 1 to 10 */ + if (checkRxTwoByteCheckSum(&(rxUART3[0]), 1, 10, 11) == 1) /* checksum in bytes 11 and 12, check bytes 1 to 10 */ { @@ -497,5 +535,7 @@ xLastSolarStateChangeTime = xTaskGetTickCount(); - solarState = SOL_NO_INIT; /* change state: time response received, now init and query the channels */ + + currentChannel = 0; /* start yield scan on channel 0 */ + solarState = SOL_QUERY_YIELD; /* change state: time response received, now init and query the channels */ } else @@ -505,4 +545,69 @@ break; + + case SOL_QUERY_YIELD: + + xLastSolarStateChangeTime = xTaskGetTickCount(); + + /* first, fill in data for tx */ + // TODO + + +// req_month_yield[4] = 0x30 + 1; // channel +// req_month_yield[8] = 0x30 + 0; // month MSB (binary coded hex) +// req_month_yield[9] = 0x30 + 4; // month LSB (binary coded hex) + + /* then, calculate the CRC for tx */ + (void)checkRxOneByteCheckSum(&(req_month_yield[0]), 1, 7, 8); + /* checksum now in calculatedCrc1Byte */ + + + // crc + //req_month_yield[7] = calculatedCrc1Byte; /* fill in checksum */ + + resetUart3RxBuf(); + send_uart3((unsigned char *)req_month_yield, sizeof(req_month_yield)); + + solarState = SOL_QUERY_YIELD_WAIT_REPLY; /* change state: now wait for response */ + + break; /* end of case SOL_QUERY_YIELD */ + + case SOL_QUERY_YIELD_WAIT_REPLY: + + + + cmpResult = checkUart3Received(yield_month_rsp, yield_month_r_m, sizeof(yield_month_rsp)-1); + + + /* wait for reply to request, check if full response has arrived */ + if (cmpResult == 0) + { + /* we have got a match! */ + + + resultValueRaw = extractBinaryHexDigitString( &(rxUART3[0]), + 9, /* first byte of binary hex string */ + 16 /* last byte of binary hex string */ + ); + + + + solarState = SOL_NO_INIT; /* go ahead */ + + } +#if 0 + currentChannel++; /* next channel */ + + if (currentChannel >= 6) + { + solarState = SOL_NO_INIT; /* change state: last channel done */ + } /* if */ + else + { + solarState = SOL_QUERY_YIELD; /* scan next channel */ + } /* else */ +#endif + + break; /* end of case SOL_QUERY_YIELD_WAIT_REPLY */ @@ -616,5 +721,5 @@ { - if (checkRxTwoByteCheckSum(1, 12, 13) == 1) /* checksum in bytes 13 and 14, check bytes 1 to 12 */ + if (checkRxTwoByteCheckSum(&(rxUART3[0]), 1, 12, 13) == 1) /* checksum in bytes 13 and 14, check bytes 1 to 12 */ { /* checksum correct */ @@ -907,5 +1012,5 @@ -portCHAR checkRxOneByteCheckSum(void) +portCHAR checkRxOneByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte) { portCHAR retVal; /* return value */ @@ -921,14 +1026,14 @@ /* use bytes 1 to 13 for the checksum */ - for (x = 1; x <= 13; x++) + for (x = firstByte; x <= lastByte; x++) { /* overflow? */ - // if (((portSHORT)crc + (portSHORT)(rxUART3[x])) > 0xFF) + // if (((portSHORT)crc + (portSHORT)(dataStart[x])) > 0xFF) // { // carry++; // } - crcLONG = (crcLONG + rxUART3[x]); /* add and truncate to 8 bit */ + crcLONG = (crcLONG + dataStart[x]); /* add and truncate to 8 bit */ } @@ -941,5 +1046,7 @@ - if (crcCHARinv == rxUART3[14]) + calculatedCrc1Byte = crcCHARinv; /* save calculated CRC (for use in case of checksum generation) */ + + if (crcCHARinv == dataStart[charCheckSumStartByte]) { retVal = 1; /* checksum OK, data is valid */ @@ -953,5 +1060,5 @@ -portCHAR checkRxTwoByteCheckSum(unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ) +portCHAR checkRxTwoByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ) { unsigned short cmpValue; @@ -965,10 +1072,13 @@ { - crc16_ccitt(rxUART3[x]); - } - - - - cmpValue = ((((unsigned short)rxUART3[charCheckSumStartByte+1])<<8) | rxUART3[charCheckSumStartByte]); + crc16_ccitt(dataStart[x]); + } + + + + cmpValue = ((((unsigned short)dataStart[charCheckSumStartByte+1])<<8) | dataStart[charCheckSumStartByte]); + + calculatedCrc2Byte = staticCRC; /* save calculated CRC (for use in case of checksum generation) */ + if (cmpValue == (staticCRC & 0xFFFF)) { @@ -996,2 +1106,28 @@ + + +int extractBinaryHexDigitString(unsigned char* srcDataStart, + unsigned char firstSrcByte, + unsigned char lastSrcByte + ) +{ + + unsigned char x; + int resultValue = 0; /* initial value */ + unsigned char round = 0; /* which digit? 0 = LSB */ + unsigned char currentCharValue; + + /* go through the bytes backwards (least significant to most significant) */ + for (x = lastSrcByte; x >= firstSrcByte; x--) + { + + currentCharValue = (srcDataStart[x]) - 0x30; + resultValue = resultValue + (currentCharValue << (4 * round)); + + round++; + } /* for */ + + return resultValue; + + } /* extractBinaryHexDigitString() */ Index: /webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h =================================================================== --- /webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h (revision 67) +++ /webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h (revision 69) @@ -2,6 +2,12 @@ void initMeterItems(void); -portCHAR checkRxOneByteCheckSum(void); -portCHAR checkRxTwoByteCheckSum(unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ); +portCHAR checkRxOneByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte); +portCHAR checkRxTwoByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ); + +int extractBinaryHexDigitString(unsigned char* srcDataStart, + unsigned char firstSrcByte, + unsigned char lastSrcByte + ); + unsigned long long getEpochTimeWithMs(void); Index: /webserver/example/EnergyMeters/EnergyMeters/ARM7_LPC2368_Rowley/webserver/httpd-cgi.c =================================================================== --- /webserver/example/EnergyMeters/EnergyMeters/ARM7_LPC2368_Rowley/webserver/httpd-cgi.c (revision 68) +++ /webserver/example/EnergyMeters/EnergyMeters/ARM7_LPC2368_Rowley/webserver/httpd-cgi.c (revision 69) @@ -70,4 +70,6 @@ extern int solarReadCounter; extern unsigned char scDate[6]; /* date received from solar count */ + +extern int resultValueRaw; /* last raw yield value */ extern int solarStateWhenFail; @@ -253,6 +255,6 @@ - sprintf( cCountBuf, "