Changeset 73 for webserver/example

Show
Ignore:
Timestamp:
10/23/10 21:39:51 (14 years ago)
Author:
phil
Message:

- state machine now also does hourly queries
- added LASTHOUR entry to web interface showing the yield of the last hour for first 3 channels

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • webserver/example/EnergyMeters/EnergyMeters/ARM7_LPC2368_Rowley/webserver/httpd-cgi.c

    r71 r73  
    7373 
    7474 
    75 extern int dayRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* daily yield data */ 
     75extern int dayRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* daily yield data (last day) */ 
     76extern int hourRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* hourly yield data (last hour) */ 
    7677 
    7778extern int resultValueRaw; /* last raw yield value */ 
     
    289290      strcat( uip_appdata, cCountBuf ); 
    290291 
    291  
    292  
     292      sprintf( cCountBuf, "LASTHOUR %u %u %u\n", hourRxYield[0], hourRxYield[1], hourRxYield[2] ); 
     293      strcat( uip_appdata, cCountBuf ); 
    293294 
    294295        sprintf( cCountBuf, "<p><br>\r\nTSTmeter %u %u %u %u %u %u %u %u\r\n", 
  • webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c

    r72 r73  
    6363#define SOL_QUERY_TIME 4 /* querying the time on the SC */ 
    6464#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 */ 
     65#define SOL_QUERY_LASTDAY_YIELD 6 /* querying yield data */ 
     66#define SOL_QUERY_LASTDAY_YIELD_WAIT_REPLY 7 /* waiting for yield data reply */ 
     67#define SOL_QUERY_LASTHOUR_YIELD 8 /* querying yield data */ 
     68#define SOL_QUERY_LASTHOUR_YIELD_WAIT_REPLY 9 /* waiting for yield data reply */ 
    6769#define SOL_FINISHED 0xA /* finished */ 
    6870//#define SOL_ 
     
    103105 
    104106 
    105 int dayRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* daily yield data */ 
    106  
     107int dayRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* daily yield data (last day) */ 
     108int hourRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* hourly yield data (last hour) */ 
    107109 
    108110const unsigned char query_sc_time[] = "\x02\xB0\xF0\x03\x00\x04\xAB\xB9\x03"; // Zeit abfragen 
     
    132134 
    133135 
    134 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() 
    135 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"; 
    136 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"; 
     136unsigned 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() 
     137const 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"; 
     138const 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"; 
    137139 
    138140 
     
    450452  unsigned char power; /* variable for conversions */ 
    451453  unsigned char checkDate; /* temp variable for day of month */ 
     454  unsigned char checkHour; /* temp variable for hour */ 
    452455  unsigned char rxYieldChkSum; /* temp checksum for rx yield */ 
     456 
    453457 
    454458  /* always get Rx data */ 
     
    569573 
    570574        currentChannel = 0; /* start yield scan on channel 0 */ 
    571         solarState = SOL_QUERY_YIELD; //xxxxxxx SOL_NO_INIT; //SOL_QUERY_YIELD; /* change state: time response received, now init and query the channels */ 
     575        solarState = SOL_QUERY_LASTDAY_YIELD; //xxxxxxx SOL_NO_INIT; //SOL_QUERY_YIELD; /* change state: time response received, now init and query the channels */ 
    572576      } 
    573577      else 
     
    578582    break; 
    579583 
    580     case SOL_QUERY_YIELD: 
     584////// begin day queries 
     585 
     586    case SOL_QUERY_LASTDAY_YIELD: 
    581587 
    582588        xLastSolarStateChangeTime = xTaskGetTickCount(); 
    583  
    584         /* first, fill in data for tx */ 
    585         // TODO 
    586  
    587589 
    588590        if (currentChannel >= 6) 
    589591        { 
    590592          currentChannel = 0; 
    591           solarState = SOL_NO_INIT; /* we are done with all the channels. go ahead */ 
     593          solarState = SOL_QUERY_LASTHOUR_YIELD; /* we are done with all the channels. go ahead */ 
    592594        } 
    593595        else 
     
    633635          send_yield_query_day(/* channel: */ currentChannel, /* day: (yesterday) */ checkDate ); 
    634636          xLastSolarStateChangeTime = xTaskGetTickCount(); 
    635           solarState = SOL_QUERY_YIELD_WAIT_REPLY; /* query next channel. change state: now wait for response */ 
     637          solarState = SOL_QUERY_LASTDAY_YIELD_WAIT_REPLY; /* query next channel. change state: now wait for response */ 
    636638 
    637639        } 
    638640 
    639         //send_yield_query_minute(/* channel: */ 1, /* minute: */ 40 ); 
    640          
    641         // hour is broken... ?! 
    642         //send_yield_query_hour(/* channel: */ 1, /* hour: */ 11 ); 
    643  
    644  
    645  
    646     break; /* end of case SOL_QUERY_YIELD */ 
    647  
    648     case SOL_QUERY_YIELD_WAIT_REPLY: 
    649  
    650  
    651        // cmpResult = checkUart3Received(yield_minute_rsp, yield_minute_r_m,  sizeof(yield_minute_rsp)-1); 
    652  
    653         // the query for hour is broken... ?! 
    654         //cmpResult = checkUart3Received(yield_hour_rsp, yield_hour_r_m,  sizeof(yield_hour_rsp)-1); 
     641    break; /* end of case SOL_QUERY_LASTDAY_YIELD */ 
     642 
     643    case SOL_QUERY_LASTDAY_YIELD_WAIT_REPLY: 
    655644 
    656645       cmpResult = checkUart3Received(yield_day_rsp, yield_day_r_m,  sizeof(yield_day_rsp)-1); 
    657  
    658  
    659646 
    660647      /* wait for reply to request, check if full response has arrived */ 
     
    681668            else 
    682669            { 
    683               /* all channels done. nothing to do, we leave via SOL_QUERY_YIELD */ 
     670              /* all channels done. nothing to do, we leave via SOL_QUERY_LASTDAY_YIELD */ 
    684671            } 
    685672          } 
     
    698685          currentChannel++; /* increment channel counter so we query the next channel in the next round */ 
    699686          xLastSolarStateChangeTime = xTaskGetTickCount(); 
    700           solarState = SOL_QUERY_YIELD; /* go ahead */ 
     687          solarState = SOL_QUERY_LASTDAY_YIELD; /* go ahead */ 
    701688     } 
    702689 
    703     break; /* end of case SOL_QUERY_YIELD_WAIT_REPLY */ 
     690    break; /* end of case SOL_QUERY_LASTDAY_YIELD_WAIT_REPLY */ 
     691 
     692////// end day queries 
     693 
     694 
     695////// begin hour queries 
     696 
     697   case SOL_QUERY_LASTHOUR_YIELD: 
     698 
     699        xLastSolarStateChangeTime = xTaskGetTickCount(); 
     700 
     701        if (currentChannel >= 6) 
     702        { 
     703          currentChannel = 0; 
     704          solarState = SOL_NO_INIT; /* we are done with all the channels. go ahead */ 
     705        } 
     706        else 
     707        { 
     708          /* query the next channel */ 
     709 
     710          checkHour = scDate[3]; /* we query the previous hour. From doc: 22 means 21h to 22h */ 
     711           
     712          if (checkHour == 0) 
     713          { 
     714              checkHour = 23; /* in case of hour 0: we want to get the 23h to midnight yield */  
     715          } 
     716 
     717          send_yield_query_hour(/* channel: */ currentChannel, /* hour: last hour */ checkHour ); 
     718          xLastSolarStateChangeTime = xTaskGetTickCount(); 
     719          solarState = SOL_QUERY_LASTHOUR_YIELD_WAIT_REPLY; /* query next channel. change state: now wait for response */ 
     720 
     721        } 
     722 
     723    break; /* end of case SOL_QUERY_LASTDAY_YIELD */ 
     724 
     725    case SOL_QUERY_LASTHOUR_YIELD_WAIT_REPLY: 
     726 
     727       cmpResult = checkUart3Received(yield_hour_rsp, yield_hour_r_m,  sizeof(yield_hour_rsp)-1); 
     728 
     729      /* wait for reply to request, check if full response has arrived */ 
     730      if (cmpResult == 0) 
     731      { 
     732          /* we have got a match (i.e. expected frame received) ! */ 
     733           
     734          /* calculate the checksum of the received data */ 
     735 
     736          rxYieldChkSum = calculate_crc8(  (&(rxUART3[0])), (sizeof(yield_hour_rsp)-2)); 
     737 
     738          if (rxYieldChkSum == rxUART3[17]) 
     739          { 
     740            /* checksum is correct! */ 
     741 
     742            if (currentChannel <= 5) 
     743            { 
     744 
     745                /* convert and copy value. hourly values must be divided by 60 */ 
     746                hourRxYield[currentChannel] = 
     747                 ( extractBinaryHexDigitString( &(rxUART3[0]), 13, 16 ) ) / 60; 
     748   
     749            } /* if */ 
     750            else 
     751            { 
     752              /* all channels done. nothing to do, we leave via SOL_QUERY_LASTHOUR_YIELD */ 
     753            } 
     754          } 
     755          else if (currentChannel <= 5) 
     756          { 
     757            /* valid channel index. but checksum is incorrect ! */ 
     758            hourRxYield[currentChannel] = 65535; /* invalid value */ 
     759          } 
     760          else 
     761          { 
     762            /* checksum incorrect and channel index out of range. do nothing. */ 
     763          } 
     764 
     765          /* always move on to the next value... */ 
     766 
     767          currentChannel++; /* increment channel counter so we query the next channel in the next round */ 
     768          xLastSolarStateChangeTime = xTaskGetTickCount(); 
     769          solarState = SOL_QUERY_LASTHOUR_YIELD; /* go ahead */ 
     770     } 
     771 
     772    break; /* end of case SOL_QUERY_LASTHOUR_YIELD_WAIT_REPLY */ 
     773 
     774 
     775///// end hour queries 
     776 
     777 
     778 
     779 
     780 
     781 
     782 
     783 
     784 
     785 
    704786 
    705787