Index: /webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c =================================================================== --- /webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c (revision 66) +++ /webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c (revision 67) @@ -53,4 +53,6 @@ #define SOL_CHAN 2 /* querying channel currentChannel */ #define SOL_CHAN_WAIT_REPLY 3 /* waiting for reply on channel currentChannel = 0; */ +#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_FINISHED 0xA /* finished */ //#define SOL_ @@ -88,4 +90,10 @@ int uart3_buf[50]; +unsigned char scDate[6]; /* date received from solar count */ + + +const unsigned char query_sc_time[] = "\x02\xB0\xF0\x03\x00\x04\xAB\xB9\x03"; // Zeit abfragen +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 //char init1[] = "abcdef"; @@ -421,5 +429,5 @@ /* now ready to query channel 0 data in next state */ xLastSolarStateChangeTime = xTaskGetTickCount(); - solarState = SOL_CHAN; + solarState = SOL_QUERY_TIME; } else @@ -427,7 +435,57 @@ /* no match (yet), stay in state */ } - - break; + + + case SOL_QUERY_TIME: + + resetUart3RxBuf(); /* init */ + currentChannel = 0; /* the channel we query first */ + + /* send query_sc_time */ + send_uart3((unsigned char *)query_sc_time, sizeof(query_sc_time)); + xLastSolarStateChangeTime = xTaskGetTickCount(); + solarState = SOL_WAIT_FOR_TIME_RSP; /* query sent wait for response */ + break; + + + case SOL_WAIT_FOR_TIME_RSP: + + + cmpResult = checkUart3Received(query_sc_time_rsp, query_sc_time_r_m, sizeof(query_sc_time_rsp)-1); + if (cmpResult == 0) + { + /* we have got a match! */ + + if (checkRxTwoByteCheckSum(1, 10, 11) == 1) /* checksum in bytes 11 and 12, check bytes 1 to 10 */ + { + + /* use data only if checksum correct */ + + scDate[0] = rxUART3[6]; /* year */ + scDate[1] = rxUART3[7]; /* month */ + scDate[2] = rxUART3[8]; /* day */ + scDate[3] = rxUART3[9]; /* hour */ + scDate[4] = rxUART3[10]; /* min */ + + } + else + { + ; + } + + /* finally, discard data from buffer */ + resetUart3RxBuf(); + + + solarState = SOL_CHAN; /* change state: time response received, now query the channels */ + } + else + { + /* stay in state */ + } + + break; + case SOL_CHAN: @@ -512,5 +570,5 @@ { - if (checkRxTwoByteCheckSum() == 1) + if (checkRxTwoByteCheckSum(1, 12, 13) == 1) /* checksum in bytes 13 and 14, check bytes 1 to 12 */ { /* checksum correct */ @@ -824,5 +882,5 @@ -portCHAR checkRxTwoByteCheckSum(void) +portCHAR checkRxTwoByteCheckSum(unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ) { unsigned short cmpValue; @@ -832,6 +890,6 @@ staticCRC = 0xFFFF; /* init 16 bit checksum CRC start value */ - /* use bytes 1 to 13 for the checksum */ - for (x = 1; x <= 12; x++) + /* use bytes first to last for the checksum */ + for (x = firstByte; x <= lastByte; x++) { @@ -841,5 +899,5 @@ - cmpValue = ((((unsigned short)rxUART3[14])<<8) | rxUART3[13]); + cmpValue = ((((unsigned short)rxUART3[charCheckSumStartByte+1])<<8) | rxUART3[charCheckSumStartByte]); if (cmpValue == (staticCRC & 0xFFFF)) { Index: /webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h =================================================================== --- /webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h (revision 66) +++ /webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h (revision 67) @@ -3,5 +3,5 @@ portCHAR checkRxOneByteCheckSum(void); -portCHAR checkRxTwoByteCheckSum(void); +portCHAR checkRxTwoByteCheckSum(unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ); 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 66) +++ /webserver/example/EnergyMeters/EnergyMeters/ARM7_LPC2368_Rowley/webserver/httpd-cgi.c (revision 67) @@ -68,4 +68,5 @@ extern int solarReadErrors; extern int solarReadCounter; +extern unsigned char scDate[6]; /* date received from solar count */ HTTPD_CGI_CALL(file, "file-stats", file_stats); @@ -248,6 +249,6 @@ - sprintf( cCountBuf, "

Watt_CRCok=%u\r\nWatt_CRCfail=%u\r\n

", - correctVoltWattRx, failedVoltWattRx + sprintf( cCountBuf, "

Watt_CRCok=%u\r\nWatt_CRCfail=%u\r\nSC_Date=20%02d-%02d-%02d_%02d:%02d

", + correctVoltWattRx, failedVoltWattRx, scDate[0], scDate[1], scDate[2], scDate[3], scDate[4] ); strcat( uip_appdata, cCountBuf );