Show
Ignore:
Timestamp:
10/17/10 18:13:03 (14 years ago)
Author:
phil
Message:

we now query and display the solar yields of the previous days (day - 1) for all the channels

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • webserver/example/EnergyMeters/EnergyMeters/ARM7_LPC2368_Rowley/EnergyMeters.hzs

    r68 r70  
    1414 </Memory3> 
    1515 <Memory4> 
    16   <MemoryWindow autoEvaluate="0" addressText="" numColumns="16" sizeText="" dataSize="1" radix="16" addressSpace="" /> 
     16  <MemoryWindow autoEvaluate="0" addressText="0x40005cc8" numColumns="16" sizeText="60" dataSize="1" radix="16" addressSpace="" /> 
    1717 </Memory4> 
    1818 <Project> 
    1919  <ProjectSessionItem path="EnergyMetersEmbedded" name="unnamed" /> 
    2020  <ProjectSessionItem path="EnergyMetersEmbedded;EnergyMetersEmbedded" name="unnamed" /> 
     21  <ProjectSessionItem path="EnergyMetersEmbedded;EnergyMetersEmbedded;Demo Source" name="unnamed" /> 
    2122  <ProjectSessionItem path="EnergyMetersEmbedded;EnergyMetersEmbedded;EnergyMeters" name="unnamed" /> 
     23  <ProjectSessionItem path="EnergyMetersEmbedded;EnergyMetersEmbedded;FreeRTOS.org Source" name="unnamed" /> 
     24  <ProjectSessionItem path="EnergyMetersEmbedded;EnergyMetersEmbedded;uIP Source" name="unnamed" /> 
    2225 </Project> 
    2326 <Register1> 
     
    3942 <Watch1> 
    4043  <Watches active="0" update="Three Seconds" > 
    41    <Watchpoint evalMode="2" linenumber="312" numelements="10" evalType="0" radix="16" name="rxUART3" expression="rxUART3" filename="c:/dokumente und einstellungen/phil/desktop/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    42    <Watchpoint evalMode="2" linenumber="72" numelements="10" evalType="0" radix="16" name="meterItems" expression="meterItems" filename="d:/energymetersproject/source/energymeters/meters_isrs.c" /> 
    4344   <Watchpoint linenumber="64" radix="-1" name="currentTime" expression="currentTime" filename="d:/energymetersproject/source/energymeters/meters_isrs.c" /> 
    4445   <Watchpoint linenumber="547" radix="16" name="PINSEL0" expression="PINSEL0" filename="c:/dokumente und einstellungen/phil/desktop/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
     46   <Watchpoint evalMode="2" linenumber="72" numelements="10" evalType="0" radix="16" name="meterItems" expression="meterItems" filename="d:/energymetersproject/source/energymeters/meters_isrs.c" /> 
     47   <Watchpoint evalMode="2" linenumber="312" numelements="10" evalType="0" radix="16" name="rxUART3" expression="rxUART3" filename="c:/dokumente und einstellungen/phil/desktop/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    4548  </Watches> 
    4649 </Watch1> 
     
    5558 <Watch4> 
    5659  <Watches active="1" update="Twice a Second" > 
    57    <Watchpoint linenumber="948" radix="-1" name="carry" expression="carry" filename="d:/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    58    <Watchpoint evalMode="2" linenumber="111" numelements="11" evalType="0" radix="-1" name="meterItems" expression="meterItems" filename="c:/dokumente und einstellungen/phil/desktop/repo/webserver/example/energymeters/source/energymeters/meters_isrs.c" /> 
    59    <Watchpoint linenumber="951" radix="-1" name="crcCHAR" expression="crcCHAR" filename="d:/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    60    <Watchpoint linenumber="381" radix="-1" name="cmpResult" expression="cmpResult" filename="d:/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    61    <Watchpoint linenumber="981" radix="-1" name="cmpValue" expression="cmpValue" filename="d:/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    62    <Watchpoint linenumber="940" radix="-1" name="crcLONG" expression="crcLONG" filename="d:/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    63    <Watchpoint linenumber="637" radix="-1" name="ch" expression="ch" filename="c:/dokumente und einstellungen/phil/desktop/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    64    <Watchpoint evalMode="2" linenumber="539" numelements="100" evalType="0" radix="-1" name="rxUART3" expression="rxUART3" filename="c:/dokumente und einstellungen/phil/desktop/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    65    <Watchpoint linenumber="573" radix="-1" name="xLastSolarStateChangeTime" expression="xLastSolarStateChangeTime" filename="d:/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    66    <Watchpoint evalMode="2" linenumber="488" numelements="6" evalType="0" radix="10" name="chanWatt" expression="chanWatt" filename="c:/dokumente und einstellungen/phil/desktop/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    67    <Watchpoint evalMode="2" linenumber="485" numelements="6" evalType="0" radix="10" name="scDate" expression="scDate" filename="d:/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    68    <Watchpoint evalMode="2" linenumber="488" numelements="6" evalType="0" radix="11" name="chanVolt" expression="chanVolt" filename="c:/dokumente und einstellungen/phil/desktop/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    69    <Watchpoint evalMode="0" linenumber="396" evalType="1" radix="-1" name="uip_appdata" expression="uip_appdata" filename="c:/dokumente und einstellungen/phil/desktop/repo/webserver/example/energymeters/energymeters/arm7_lpc2368_rowley/webserver/httpd-cgi.c" /> 
    70    <Watchpoint linenumber="951" radix="-1" name="crcCHARinv" expression="crcCHARinv" filename="d:/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    71    <Watchpoint linenumber="109" radix="16" name="solarReadErrors" expression="solarReadErrors" filename="c:/dokumente und einstellungen/phil/desktop/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    72    <Watchpoint linenumber="969" radix="-1" name="staticCRC" expression="staticCRC" filename="d:/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    73    <Watchpoint linenumber="55" radix="16" name="solarState" expression="solarState" filename="c:/dokumente und einstellungen/phil/desktop/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    74    <Watchpoint evalMode="0" linenumber="428" evalType="0" radix="-1" name="init1" expression="init1" filename="d:/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    75    <Watchpoint linenumber="676" radix="-1" name="xLastTimeCheckTime" expression="xLastTimeCheckTime" filename="d:/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    76    <Watchpoint evalMode="0" linenumber="396" evalType="1" radix="-1" name="uip_appdata" expression="uip_appdata" filename="c:/dokumente und einstellungen/phil/desktop/repo/webserver/example/energymeters/energymeters/arm7_lpc2368_rowley/webserver/httpd-cgi.c" /> 
     60   <Watchpoint evalMode="2" linenumber="679" numelements="21" evalType="0" radix="-1" name="yield_day_rsp" expression="yield_day_rsp" filename="d:/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
     61   <Watchpoint evalMode="2" linenumber="668" numelements="6" evalType="0" radix="16" name="dayRxYield" expression="dayRxYield" filename="d:/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
     62   <Watchpoint evalMode="2" linenumber="669" numelements="100" evalType="0" radix="-1" name="rxUART3" expression="rxUART3" filename="d:/repo/webserver/example/energymeters/source/energymeters/solarcountuart.c" /> 
    7763  </Watches> 
    7864 </Watch4> 
    7965 <Files> 
    80   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\Dokumente und Einstellungen\phil\Lokale Einstellungen\Anwendungsdaten\Rowley Associates Limited\CrossWorks for ARM\packages\targets\Philips_LPC210X\Philips_LPC230X_Startup.s" y="278" path="C:\Dokumente und Einstellungen\phil\Lokale Einstellungen\Anwendungsdaten\Rowley Associates Limited\CrossWorks for ARM\packages\targets\Philips_LPC210X\Philips_LPC230X_Startup.s" left="0" selected="0" name="unnamed" top="261" /> 
    81   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\Source\tasks.c" y="1133" path="D:\repo\webserver\example\EnergyMeters\Source\tasks.c" left="0" selected="0" name="unnamed" top="1105" /> 
    82   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\EnergyMeters\ARM7_LPC2368_Rowley\webserver\httpd.c" y="9" path="D:\repo\webserver\example\EnergyMeters\EnergyMeters\ARM7_LPC2368_Rowley\webserver\httpd.c" left="0" selected="0" name="unnamed" top="0" /> 
    83   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\EnergyMeters\ARM7_LPC2368_Rowley\LCD\portlcd.c" y="24" path="D:\repo\webserver\example\EnergyMeters\EnergyMeters\ARM7_LPC2368_Rowley\LCD\portlcd.c" left="0" selected="0" name="unnamed" top="9" /> 
    84   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\Source\portable\GCC\ARM7_LPC23xx\port.c" y="172" path="D:\repo\webserver\example\EnergyMeters\Source\portable\GCC\ARM7_LPC23xx\port.c" left="0" selected="0" name="unnamed" top="152" /> 
    85   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\Source\EnergyMeters\MetersIncludes.h" y="0" path="D:\repo\webserver\example\EnergyMeters\Source\EnergyMeters\MetersIncludes.h" left="0" selected="0" name="unnamed" top="21" /> 
    86   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\Source\list.c" y="108" path="D:\repo\webserver\example\EnergyMeters\Source\list.c" left="0" selected="0" name="unnamed" top="89" /> 
    87   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\Source\include\portable.h" y="105" path="D:\repo\webserver\example\EnergyMeters\Source\include\portable.h" left="0" selected="0" name="unnamed" top="89" /> 
    88   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\Source\portable\GCC\ARM7_LPC23xx\portmacro.h" y="0" path="D:\repo\webserver\example\EnergyMeters\Source\portable\GCC\ARM7_LPC23xx\portmacro.h" left="0" selected="0" name="unnamed" top="75" /> 
     66  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="40" debugPath="D:\repo\webserver\example\EnergyMeters\Source\EnergyMeters\SolarCountUART.c" y="612" path="D:\repo\webserver\example\EnergyMeters\Source\EnergyMeters\SolarCountUART.c" left="0" selected="1" name="unnamed" top="592" /> 
     67  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="29" debugPath="D:\repo\webserver\example\EnergyMeters\Source\EnergyMeters\MetersIncludes.h" y="36" path="D:\repo\webserver\example\EnergyMeters\Source\EnergyMeters\MetersIncludes.h" left="0" selected="0" name="unnamed" top="51" /> 
    8968  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\EnergyMeters\ARM7_LPC2368_Rowley\main.c" y="115" path="D:\repo\webserver\example\EnergyMeters\EnergyMeters\ARM7_LPC2368_Rowley\main.c" left="0" selected="0" name="unnamed" top="99" /> 
    90   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\EnergyMeters\ARM7_LPC2368_Rowley\webserver\httpd-cgi.c" y="0" path="D:\repo\webserver\example\EnergyMeters\EnergyMeters\ARM7_LPC2368_Rowley\webserver\httpd-cgi.c" left="0" selected="0" name="unnamed" top="114" /> 
    91   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="29" debugPath="D:\repo\webserver\example\EnergyMeters\Source\EnergyMeters\SolarCountUART.c" y="565" path="D:\repo\webserver\example\EnergyMeters\Source\EnergyMeters\SolarCountUART.c" left="0" selected="1" name="unnamed" top="582" /> 
    92   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\Source\portable\GCC\ARM7_LPC23xx\portISR.c" y="216" path="D:\repo\webserver\example\EnergyMeters\Source\portable\GCC\ARM7_LPC23xx\portISR.c" left="0" selected="0" name="unnamed" top="26" /> 
    93   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\Source\queue.c" y="132" path="D:\repo\webserver\example\EnergyMeters\Source\queue.c" left="0" selected="0" name="unnamed" top="132" /> 
    94   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\Source\serial.c" y="226" path="D:\repo\webserver\example\EnergyMeters\Source\serial.c" left="0" selected="0" name="unnamed" top="210" /> 
    95   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\Dokumente und Einstellungen\phil\Lokale Einstellungen\Anwendungsdaten\Rowley Associates Limited\CrossWorks for ARM\packages\targets\Philips_LPC210X\LPC230x.c" y="69" path="C:\Dokumente und Einstellungen\phil\Lokale Einstellungen\Anwendungsdaten\Rowley Associates Limited\CrossWorks for ARM\packages\targets\Philips_LPC210X\LPC230x.c" left="0" selected="0" name="unnamed" top="53" /> 
    96   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\Source\EnergyMeters\Meters_ISRs.c" y="12" path="D:\repo\webserver\example\EnergyMeters\Source\EnergyMeters\Meters_ISRs.c" left="0" selected="0" name="unnamed" top="0" /> 
    97   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\Source\include\FreeRTOS.h" y="367" path="D:\repo\webserver\example\EnergyMeters\Source\include\FreeRTOS.h" left="0" selected="0" name="unnamed" top="353" /> 
    98   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\EnergyMeters\ARM7_LPC2368_Rowley\FreeRTOSConfig.h" y="81" path="D:\repo\webserver\example\EnergyMeters\EnergyMeters\ARM7_LPC2368_Rowley\FreeRTOSConfig.h" left="0" selected="0" name="unnamed" top="63" /> 
     69  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\Source\portable\GCC\ARM7_LPC23xx\portISR.c" y="216" path="D:\repo\webserver\example\EnergyMeters\Source\portable\GCC\ARM7_LPC23xx\portISR.c" left="0" selected="0" name="unnamed" top="195" /> 
     70  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\Source\queue.c" y="799" path="D:\repo\webserver\example\EnergyMeters\Source\queue.c" left="0" selected="0" name="unnamed" top="781" /> 
     71  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\repo\webserver\example\EnergyMeters\Source\tasks.c" y="1128" path="D:\repo\webserver\example\EnergyMeters\Source\tasks.c" left="0" selected="0" name="unnamed" top="1104" /> 
     72  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="21" debugPath="D:\repo\webserver\example\EnergyMeters\EnergyMeters\ARM7_LPC2368_Rowley\webserver\httpd-cgi.c" y="286" path="D:\repo\webserver\example\EnergyMeters\EnergyMeters\ARM7_LPC2368_Rowley\webserver\httpd-cgi.c" left="0" selected="0" name="unnamed" top="278" /> 
    9973 </Files> 
    100  <ARMCrossStudioWindow activeProject="EnergyMetersEmbedded" autoConnectTarget="Macraigor Wiggler (20 Pin)" debugSearchFileMap="" fileDialogInitialDirectory="C:\Dokumente und Einstellungen\phil\Desktop\repo\webserver\example\EnergyMeters\Source" fileDialogDefaultFilter="*.c" autoConnectCapabilities="388479" debugSearchPath="" buildConfiguration="ARM Flash Release" /> 
     74 <ARMCrossStudioWindow activeProject="EnergyMetersEmbedded" autoConnectTarget="Segger J-Link" debugSearchFileMap="" fileDialogInitialDirectory="C:\Dokumente und Einstellungen\phil\Desktop\repo\webserver\example\EnergyMeters\Source" fileDialogDefaultFilter="*.c" autoConnectCapabilities="388479" debugSearchPath="" buildConfiguration="ARM Flash Debug" /> 
    10175</session> 
  • webserver/example/EnergyMeters/EnergyMeters/ARM7_LPC2368_Rowley/webserver/httpd-cgi.c

    r69 r70  
    7070extern int solarReadCounter; 
    7171extern unsigned char scDate[6]; /* date received from solar count */ 
     72 
     73 
     74 
     75extern int dayRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* daily yield data */ 
    7276 
    7377extern int resultValueRaw; /* last raw yield value */ 
     
    233237{ 
    234238        int i; 
     239        unsigned char k; 
    235240 
    236241        unsigned long long currentTime = getEpochTimeWithMs(); 
     
    280285      } /* for */ 
    281286 
     287      for (i = 0; i < NUMBER_OF_SOLAR_CHANNELS; i++) 
     288      { 
     289         sprintf( cCountBuf, "DAY %u %u\n", (int)i, dayRxYield[i] ); 
     290         strcat( uip_appdata, cCountBuf ); 
     291      } 
     292 
     293      strcat( uip_appdata, cCountBuf ); 
    282294 
    283295 
  • webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h

    r69 r70  
    22void initMeterItems(void); 
    33 
    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 ); 
     4portCHAR checkRxOneByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned char CheckSumStartByte); 
     5portCHAR checkRxTwoByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned char CheckSumStartByte ); 
     6 
     7 
     8static unsigned char calculate_crc8(unsigned char * d_serdata_tuc, unsigned char nbytes); 
    69 
    710int extractBinaryHexDigitString(unsigned char* srcDataStart,  
     
    1215 
    1316unsigned long long getEpochTimeWithMs(void); 
     17 
     18 
     19void send_yield_query_day(unsigned char channel /* 0 to 5 */, unsigned char day /* 1 to 31 */); 
     20void send_yield_query_hour(unsigned char channel /* 0 to 5 */, unsigned char hour /* 0 to 23 */); 
     21void send_yield_query_minute(unsigned char channel /* 0 to 5 */, unsigned char minute /* 0 to 59 */); 
    1422 
    1523#define NUMBER_OF_METERS 6 /* the number of meters we use */ 
     
    2432 
    2533#define METERS_INT_CHECK_INTERVAL_MS 100 /* how often (in ms) do we check if one of the I/O lines has triggered */ 
     34 
     35 
     36#define NUMBER_OF_SOLAR_CHANNELS 6 /* number of solar channels */ 
     37#define DAILY_RX_YIELD_LENGTH 9 /* length of the rx data */ 
     38 
    2639 
    2740 
     
    5063extern int historyRemainTime; /* how many ticks have we left until the next history entry must be written? */ 
    5164 
     65/* bit values for calculate_crc8() */ 
     66 
     67#define BIT0 (1U << 0) 
     68#define BIT1 (1U << 1) 
     69#define BIT2 (1U << 2) 
     70#define BIT3 (1U << 3) 
     71#define BIT4 (1U << 4) 
     72#define BIT5 (1U << 5) 
     73#define BIT6 (1U << 6) 
     74#define BIT7 (1U << 7) 
     75 
     76 
  • webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c

    r69 r70  
    103103 
    104104 
     105int dayRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* daily yield data */ 
     106 
     107 
    105108const unsigned char query_sc_time[] = "\x02\xB0\xF0\x03\x00\x04\xAB\xB9\x03"; // Zeit abfragen 
    106109const unsigned char query_sc_time_rsp[] = "\x02\xF0\xB0\x08\x00\x84\x00\x00\x00\x00\x00\x00\x00\x03"; // Zeit abfragen 
     
    120123//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() 
    121124 
    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() 
     125//                                   
     126unsigned char req_month_yield[] = "\x02\x31\x3C\x6d\x30\x32\x30\x30\x30\x32\xff\x03"; // Frame for querying the monthly yield. Will be filled in by solQueryYield() 
     127 
     128 
     129unsigned char req_minute_yield[] = "\x02\x31\x3C\x6D\x30\x32\x30\x30\x30\x32\x00\x03"; // Frame for querying the minutely yield. Will be filled in by solQueryYield() 
     130const unsigned char yield_minute_rsp[] = "\x02\x31\x6D\x30\x31\x30\x30\x30\x32\x30\x30\x30\x30\x30\x32\x41\x44\xC8\x03\x03"; 
     131const unsigned char yield_minute_r_m[] = "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF"; 
     132 
     133 
     134unsigned 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() 
     135const 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"; 
     136const 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"; 
     137 
     138 
     139unsigned char req_hour_yield[]    = "\x02\x31\x3c\x68\x30\x32\x30\x30\x30\x32\x00\x03"; // Frame for querying the minutely yield. Will be filled in by solQueryYield() 
     140const unsigned char yield_hour_rsp[]    = "\x02\x31\x68\x30\x31\x30\x30\x30\x32\x30\x30\x30\x30\x30\x30\x30\x30\x30\x03\x03"; 
     141const unsigned char yield_hour_r_m[]    = "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF"; 
     142 
     143 
     144 
     145 
     146 
    124147 
    125148// tt (time) values: m=minute , h = hour, D = day, M = month (\x31), Y = year 
     
    129152// ad: unit address 
    130153// 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() */ 
     154 
     155 
     156//                                   02  31  4d  30  30  30  30  30  31  30  30  30  30  31  35  44  43 
     157//                                   00  01  02  03  04  05  06  07  08  09  10  11  12  13  14  15  16 
     158unsigned char yield_month_rsp[] = "\x02\x31\x4d\x33\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03"; /* exp. query yield response. Will be filled in by solQueryYield() */ 
     159unsigned char yield_month_r_m[] = "\xff\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() */ 
    139160 
    140161 
     
    229250{ 
    230251  int i; 
     252  int k; 
     253 
    231254  xLastSolarStateChangeTime = xTaskGetTickCount(); 
    232255  xLastTimeCheckTime = xTaskGetTickCount(); 
     
    243266 
    244267  /* do not invalidate history here so we do not lose all data */ 
     268 
     269  /* init daily rx yield array with 0 */ 
     270  for (i = 0; i < NUMBER_OF_SOLAR_CHANNELS; i++) 
     271  { 
     272      dayRxYield[i] = 0; 
     273  } /* for */ 
    245274 
    246275 
     
    417446void solarFSM(void) 
    418447{ 
     448  unsigned char i; 
    419449  int cmpResult; 
     450  unsigned char power; /* variable for conversions */ 
     451  unsigned char checkDate; /* temp variable for day of month */ 
    420452 
    421453 
     
    537569 
    538570        currentChannel = 0; /* start yield scan on channel 0 */ 
    539         solarState = SOL_QUERY_YIELD; /* change state: time response received, now init and query the channels */ 
     571        solarState = SOL_QUERY_YIELD; //xxxxxxx SOL_NO_INIT; //SOL_QUERY_YIELD; /* change state: time response received, now init and query the channels */ 
    540572      } 
    541573      else 
     
    552584        /* first, fill in data for tx */ 
    553585        // 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 */ 
     586 
     587 
     588        if (currentChannel >= 6) 
     589        { 
     590          currentChannel = 0; 
     591          solarState = SOL_NO_INIT; /* we are done with all the channels. go ahead */ 
     592        } 
     593        else 
     594        { 
     595          /* query the next channel */ 
     596 
     597          checkDate = scDate[2]-1; /* we query the previous day */ 
     598 
     599          if (checkDate == 0) 
     600          { 
     601            /* first day of month */ 
     602 
     603            /* check new month */ 
     604            if (scDate[1] == 3) 
     605            { 
     606              /* looking for end of february? handle leap years */ 
     607              if ((scDate[0] % 4) == 0) 
     608              { 
     609                checkDate = 29; /* leap year */ 
     610              } 
     611              else 
     612              { 
     613                checkDate = 28; /* not a leap year */ 
     614              } 
     615            } 
     616            else if  
     617                 ((scDate[1] == 1) || 
     618                 (scDate[1] == 5) || 
     619                 (scDate[1] == 7) || 
     620                 (scDate[1] == 8) || 
     621                 (scDate[1] == 10) || 
     622                 (scDate[1] == 12)) 
     623                 {  
     624                    checkDate = 31; 
     625                 } 
     626                 else 
     627                 { 
     628                    checkDate = 30; 
     629                 } 
     630          } 
     631 
     632          send_yield_query_day(/* channel: */ currentChannel, /* day: (yesterday) */ checkDate ); 
     633          xLastSolarStateChangeTime = xTaskGetTickCount(); 
     634          solarState = SOL_QUERY_YIELD_WAIT_REPLY; /* query next channel. change state: now wait for response */ 
     635 
     636        } 
     637 
     638        //send_yield_query_minute(/* channel: */ 1, /* minute: */ 40 ); 
     639         
     640        // hour is broken... ?! 
     641        //send_yield_query_hour(/* channel: */ 1, /* hour: */ 11 ); 
     642 
     643 
    572644 
    573645    break; /* end of case SOL_QUERY_YIELD */ 
     
    576648 
    577649 
    578  
    579        cmpResult = checkUart3Received(yield_month_rsp, yield_month_r_m,  sizeof(yield_month_rsp)-1); 
     650       // cmpResult = checkUart3Received(yield_minute_rsp, yield_minute_r_m,  sizeof(yield_minute_rsp)-1); 
     651 
     652        // the query for hour is broken... ?! 
     653        //cmpResult = checkUart3Received(yield_hour_rsp, yield_hour_r_m,  sizeof(yield_hour_rsp)-1); 
     654 
     655       cmpResult = checkUart3Received(yield_day_rsp, yield_day_r_m,  sizeof(yield_day_rsp)-1); 
     656 
    580657 
    581658 
     
    584661      { 
    585662        /* 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   
     663        
     664          if (currentChannel <= 5) 
     665          { 
     666 
     667 
     668              dayRxYield[currentChannel] = 
     669                extractBinaryHexDigitString( &(rxUART3[0]), 13, 16 ); 
     670 
     671          } /* if */ 
     672          else 
     673          { 
     674            /* all channels done. nothing to do, we leave via SOL_QUERY_YIELD */ 
     675          } 
     676 
     677 
     678          currentChannel++; /* increment channel counter so we query the next channel in the next round */ 
     679          xLastSolarStateChangeTime = xTaskGetTickCount(); 
     680          solarState = SOL_QUERY_YIELD; /* go ahead */ 
    597681     } 
    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 
    610682 
    611683    break; /* end of case SOL_QUERY_YIELD_WAIT_REPLY */ 
     
    10121084 
    10131085 
    1014 portCHAR checkRxOneByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte) 
     1086portCHAR checkRxOneByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned char CheckSumStartByte) 
    10151087{ 
    10161088  portCHAR retVal; /* return value */ 
     
    10201092  int x; 
    10211093 
    1022   unsigned long crcLONG = 0
     1094  unsigned long crcLONG
    10231095  unsigned char crcCHAR; 
    10241096  unsigned char crcCHARinv; 
    1025   unsigned char carry = 0; 
     1097  unsigned char carry; 
     1098 
     1099  crcLONG = 0; 
     1100  crcCHAR = 0; 
     1101  crcCHARinv = 0; 
     1102  carry = 0; 
     1103 
    10261104 
    10271105  /* use bytes 1 to 13 for the checksum */ 
     
    10291107  { 
    10301108 
    1031     /* overflow? */ 
    1032  //   if (((portSHORT)crc + (portSHORT)(dataStart[x])) > 0xFF) 
    1033  //   { 
    1034  //     carry++; 
    1035  //   } 
    1036  
    10371109    crcLONG = (crcLONG + dataStart[x]); /* add and truncate to 8 bit */ 
    10381110  } 
     
    10401112  carry = (unsigned char)(((crcLONG & 0xFF00) >> 8)); 
    10411113 
    1042   crcCHAR = (unsigned char)(crcLONG & 0xFF); 
    1043  
    1044   crcCHAR = (unsigned char)(crcCHAR + carry); 
     1114  crcCHAR = ((unsigned char)crcLONG) + carry; 
    10451115  crcCHARinv = (unsigned char)(~crcCHAR); 
    10461116 
     
    10481118  calculatedCrc1Byte = crcCHARinv; /* save calculated CRC (for use in case of checksum generation) */ 
    10491119 
    1050   if (crcCHARinv == dataStart[charCheckSumStartByte]) 
     1120  if (crcCHARinv == dataStart[CheckSumStartByte]) 
    10511121  { 
    10521122    retVal = 1; /* checksum OK, data is valid */ 
     
    10601130 
    10611131 
    1062 portCHAR checkRxTwoByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ) 
     1132portCHAR checkRxTwoByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned char CheckSumStartByte ) 
    10631133{ 
    10641134  unsigned short cmpValue; 
     
    10771147 
    10781148 
    1079   cmpValue = ((((unsigned short)dataStart[charCheckSumStartByte+1])<<8) | dataStart[charCheckSumStartByte]); 
     1149  cmpValue = ((((unsigned short)dataStart[CheckSumStartByte+1])<<8) | dataStart[CheckSumStartByte]); 
    10801150 
    10811151  calculatedCrc2Byte = staticCRC; /* save calculated CRC (for use in case of checksum generation) */ 
     
    11321202 
    11331203 } /* extractBinaryHexDigitString() */ 
     1204 
     1205 
     1206static unsigned char calculate_crc8(unsigned char * d_serdata_tuc, unsigned char nbytes) 
     1207{ 
     1208   unsigned char i; 
     1209   unsigned char j; 
     1210   unsigned char d_currbyte_tuc; 
     1211   unsigned char d_crc_tuc; 
     1212    
     1213   /* start with BISISTX and repeat the checksum calculation for all bytes until CHKS8 (excl.) */ 
     1214    d_crc_tuc = 0; //   init the checksum 
     1215 
     1216    for( j = 1; j < (nbytes-2); j ++  ) 
     1217    { 
     1218 
     1219      d_currbyte_tuc = d_serdata_tuc[ j ]; 
     1220 
     1221      for( i = 8; i > 0; i --  ) 
     1222      { 
     1223         /*  if  current bit != 0 */ 
     1224         if (( (d_crc_tuc ^ d_currbyte_tuc) & BIT0  ) != 0) 
     1225         { 
     1226            d_crc_tuc ^= 0x18; 
     1227            d_crc_tuc >>= 1; 
     1228            d_crc_tuc |= BIT7; 
     1229         } 
     1230         else 
     1231         { 
     1232          d_crc_tuc >>= 1; 
     1233         } 
     1234         d_currbyte_tuc >>= 1;   //       prepare for next databit 
     1235      } /* for */ 
     1236    } // this byte is finished 
     1237 
     1238  /* checksum is complete now - result always ORed with 0x80  and then compare */ 
     1239  /* calculated and received checksum */ 
     1240  d_crc_tuc |= BIT7; 
     1241  return d_crc_tuc; 
     1242} 
     1243 
     1244 
     1245void send_yield_query_day(unsigned char channel /* 0 to 5 */, unsigned char day /* 1 to 31 */) 
     1246{ 
     1247        unsigned char newChkSum; 
     1248 
     1249        req_day_yield[5] = 0x30 + channel; // channel 
     1250 
     1251 
     1252        /* convert day to binary coded hex */ 
     1253        if (day > 15) 
     1254        { 
     1255            req_day_yield[8] = 0x31; /* hex MSB day is 1 */ 
     1256            day = day - 16;          /* decrease day (is now remainder */ 
     1257        } 
     1258        else 
     1259        { 
     1260            req_day_yield[8] = 0x30; /* hex MSB day is 0 */ 
     1261        } 
     1262        req_day_yield[9] = 0x30 + day; /* hex LSB day */ 
     1263 
     1264        newChkSum = calculate_crc8(  (&(req_day_yield[0])), (sizeof(req_day_yield)-1)); 
     1265        req_day_yield[10] = newChkSum; /* fill in checksum */ 
     1266 
     1267        resetUart3RxBuf(); 
     1268        send_uart3((unsigned char *)req_day_yield, sizeof(req_day_yield)); 
     1269 
     1270} /* prepare_yield_query_day() */ 
     1271 
     1272 
     1273void send_yield_query_hour(unsigned char channel /* 0 to 5 */, unsigned char hour /* 0 to 23 */) 
     1274{ 
     1275 
     1276        unsigned char newChkSum; 
     1277        unsigned char hourMSB; 
     1278        unsigned char hourLSB; 
     1279 
     1280        req_hour_yield[5] = 0x30 + channel; // channel 
     1281 
     1282      
     1283        hourMSB = hour % 16; 
     1284        hourLSB = hour - hourMSB; 
     1285         
     1286        req_hour_yield[8] = 0x30 + hourMSB; // minute MSB (binary coded hex)  
     1287        req_hour_yield[9] = 0x30 + hourLSB; // minute LSB (binary coded hex) 
     1288 
     1289        newChkSum = calculate_crc8(  (&(req_hour_yield[0])), (sizeof(req_hour_yield)-1)); 
     1290 
     1291        // crc 
     1292        req_hour_yield[10] = newChkSum; /* fill in checksum */ 
     1293 
     1294        resetUart3RxBuf(); 
     1295        send_uart3((unsigned char *)req_hour_yield, sizeof(req_hour_yield)); 
     1296 
     1297 
     1298 
     1299} /* prepare_yield_query_hour() */ 
     1300 
     1301 
     1302void send_yield_query_minute(unsigned char channel /* 0 to 5 */, unsigned char minute /* 0 to 59 */) 
     1303{ 
     1304        unsigned char newChkSum; 
     1305        unsigned char minuteMSB; 
     1306        unsigned char minuteLSB; 
     1307 
     1308        req_minute_yield[5] = 0x30 + channel; // channel 
     1309 
     1310      
     1311        minuteMSB = minute % 16; 
     1312        minuteLSB = minute - minuteMSB; 
     1313         
     1314        req_minute_yield[6] = 0x30 + minuteMSB; // minute MSB (binary coded hex)  
     1315        req_minute_yield[7] = 0x30 + minuteLSB; // minute LSB (binary coded hex) 
     1316 
     1317        newChkSum = calculate_crc8(  (&(req_minute_yield[0])), (sizeof(req_minute_yield)-1)); 
     1318 
     1319        // crc 
     1320        req_minute_yield[10] = newChkSum; /* fill in checksum */ 
     1321 
     1322        resetUart3RxBuf(); 
     1323        send_uart3((unsigned char *)req_minute_yield, sizeof(req_minute_yield)); 
     1324 
     1325 
     1326} /* prepare_yield_query_minute() */