Index: webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c =================================================================== --- webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c (revision 72) +++ webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c (revision 73) @@ -63,6 +63,8 @@ #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_QUERY_LASTDAY_YIELD 6 /* querying yield data */ +#define SOL_QUERY_LASTDAY_YIELD_WAIT_REPLY 7 /* waiting for yield data reply */ +#define SOL_QUERY_LASTHOUR_YIELD 8 /* querying yield data */ +#define SOL_QUERY_LASTHOUR_YIELD_WAIT_REPLY 9 /* waiting for yield data reply */ #define SOL_FINISHED 0xA /* finished */ //#define SOL_ @@ -103,6 +105,6 @@ -int dayRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* daily yield data */ - +int dayRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* daily yield data (last day) */ +int hourRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* hourly yield data (last hour) */ const unsigned char query_sc_time[] = "\x02\xB0\xF0\x03\x00\x04\xAB\xB9\x03"; // Zeit abfragen @@ -132,7 +134,7 @@ -unsigned char req_day_yield[] = "\x02\x31\x3c\x44\x30\x32\x30\x30\x30\x32\x00\x03"; // Frame for querying the minutely yield. Will be filled in by solQueryYield() -const unsigned char yield_day_rsp[] = "\x02\x31\x44\x30\x31\x30\x30\x30\x32\x30\x30\x30\x30\x30\x32\x41\x44\xC8\x03\x03"; -const unsigned char yield_day_r_m[] = "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF"; +unsigned char req_day_yield[] = "\x02\x31\x3c\x44\x30\x32\x30\x30\x30\x32\x00\x03"; // Frame for querying the minutely yield. Will be filled in by solQueryYield() +const unsigned char yield_day_rsp[] = "\x02\x31\x44\x30\x31\x30\x30\x30\x32\x30\x30\x30\x30\x30\x32\x41\x44\xC8\x03\x03"; +const unsigned char yield_day_r_m[] = "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF"; @@ -450,5 +452,7 @@ unsigned char power; /* variable for conversions */ unsigned char checkDate; /* temp variable for day of month */ + unsigned char checkHour; /* temp variable for hour */ unsigned char rxYieldChkSum; /* temp checksum for rx yield */ + /* always get Rx data */ @@ -569,5 +573,5 @@ currentChannel = 0; /* start yield scan on channel 0 */ - solarState = SOL_QUERY_YIELD; //xxxxxxx SOL_NO_INIT; //SOL_QUERY_YIELD; /* change state: time response received, now init and query the channels */ + solarState = SOL_QUERY_LASTDAY_YIELD; //xxxxxxx SOL_NO_INIT; //SOL_QUERY_YIELD; /* change state: time response received, now init and query the channels */ } else @@ -578,16 +582,14 @@ break; - case SOL_QUERY_YIELD: +////// begin day queries + + case SOL_QUERY_LASTDAY_YIELD: xLastSolarStateChangeTime = xTaskGetTickCount(); - - /* first, fill in data for tx */ - // TODO - if (currentChannel >= 6) { currentChannel = 0; - solarState = SOL_NO_INIT; /* we are done with all the channels. go ahead */ + solarState = SOL_QUERY_LASTHOUR_YIELD; /* we are done with all the channels. go ahead */ } else @@ -633,28 +635,13 @@ send_yield_query_day(/* channel: */ currentChannel, /* day: (yesterday) */ checkDate ); xLastSolarStateChangeTime = xTaskGetTickCount(); - solarState = SOL_QUERY_YIELD_WAIT_REPLY; /* query next channel. change state: now wait for response */ + solarState = SOL_QUERY_LASTDAY_YIELD_WAIT_REPLY; /* query next channel. change state: now wait for response */ } - //send_yield_query_minute(/* channel: */ 1, /* minute: */ 40 ); - - // hour is broken... ?! - //send_yield_query_hour(/* channel: */ 1, /* hour: */ 11 ); - - - - break; /* end of case SOL_QUERY_YIELD */ - - case SOL_QUERY_YIELD_WAIT_REPLY: - - - // cmpResult = checkUart3Received(yield_minute_rsp, yield_minute_r_m, sizeof(yield_minute_rsp)-1); - - // the query for hour is broken... ?! - //cmpResult = checkUart3Received(yield_hour_rsp, yield_hour_r_m, sizeof(yield_hour_rsp)-1); + break; /* end of case SOL_QUERY_LASTDAY_YIELD */ + + case SOL_QUERY_LASTDAY_YIELD_WAIT_REPLY: cmpResult = checkUart3Received(yield_day_rsp, yield_day_r_m, sizeof(yield_day_rsp)-1); - - /* wait for reply to request, check if full response has arrived */ @@ -681,5 +668,5 @@ else { - /* all channels done. nothing to do, we leave via SOL_QUERY_YIELD */ + /* all channels done. nothing to do, we leave via SOL_QUERY_LASTDAY_YIELD */ } } @@ -698,8 +685,103 @@ currentChannel++; /* increment channel counter so we query the next channel in the next round */ xLastSolarStateChangeTime = xTaskGetTickCount(); - solarState = SOL_QUERY_YIELD; /* go ahead */ + solarState = SOL_QUERY_LASTDAY_YIELD; /* go ahead */ } - break; /* end of case SOL_QUERY_YIELD_WAIT_REPLY */ + break; /* end of case SOL_QUERY_LASTDAY_YIELD_WAIT_REPLY */ + +////// end day queries + + +////// begin hour queries + + case SOL_QUERY_LASTHOUR_YIELD: + + xLastSolarStateChangeTime = xTaskGetTickCount(); + + if (currentChannel >= 6) + { + currentChannel = 0; + solarState = SOL_NO_INIT; /* we are done with all the channels. go ahead */ + } + else + { + /* query the next channel */ + + checkHour = scDate[3]; /* we query the previous hour. From doc: 22 means 21h to 22h */ + + if (checkHour == 0) + { + checkHour = 23; /* in case of hour 0: we want to get the 23h to midnight yield */ + } + + send_yield_query_hour(/* channel: */ currentChannel, /* hour: last hour */ checkHour ); + xLastSolarStateChangeTime = xTaskGetTickCount(); + solarState = SOL_QUERY_LASTHOUR_YIELD_WAIT_REPLY; /* query next channel. change state: now wait for response */ + + } + + break; /* end of case SOL_QUERY_LASTDAY_YIELD */ + + case SOL_QUERY_LASTHOUR_YIELD_WAIT_REPLY: + + cmpResult = checkUart3Received(yield_hour_rsp, yield_hour_r_m, sizeof(yield_hour_rsp)-1); + + /* wait for reply to request, check if full response has arrived */ + if (cmpResult == 0) + { + /* we have got a match (i.e. expected frame received) ! */ + + /* calculate the checksum of the received data */ + + rxYieldChkSum = calculate_crc8( (&(rxUART3[0])), (sizeof(yield_hour_rsp)-2)); + + if (rxYieldChkSum == rxUART3[17]) + { + /* checksum is correct! */ + + if (currentChannel <= 5) + { + + /* convert and copy value. hourly values must be divided by 60 */ + hourRxYield[currentChannel] = + ( extractBinaryHexDigitString( &(rxUART3[0]), 13, 16 ) ) / 60; + + } /* if */ + else + { + /* all channels done. nothing to do, we leave via SOL_QUERY_LASTHOUR_YIELD */ + } + } + else if (currentChannel <= 5) + { + /* valid channel index. but checksum is incorrect ! */ + hourRxYield[currentChannel] = 65535; /* invalid value */ + } + else + { + /* checksum incorrect and channel index out of range. do nothing. */ + } + + /* always move on to the next value... */ + + currentChannel++; /* increment channel counter so we query the next channel in the next round */ + xLastSolarStateChangeTime = xTaskGetTickCount(); + solarState = SOL_QUERY_LASTHOUR_YIELD; /* go ahead */ + } + + break; /* end of case SOL_QUERY_LASTHOUR_YIELD_WAIT_REPLY */ + + +///// end hour queries + + + + + + + + + +