Show
Ignore:
Timestamp:
03/07/10 10:45:29 (15 years ago)
Author:
phil
Message:

- added watt history, SOLAR_WATT_HISTORY_STEPSIZE, SOLAR_WATT_HISTORYSIZE
- added SOLAR_FSM_INVALID_VALUE 0x4000 for wattages (after stuck)
- changed "solar FSM stuck" check in solarFSM()
- increased cCountBuf[] buffer size (to prevent overflow/mem corruption)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h

    r50 r56  
    2828meterItem meterItems[NUMBER_OF_METERS]; /* the data for all the meters */ 
    2929 
     30/* the history spans (SOLAR_WATT_HISTORYSIZE * SOLAR_WATT_HISTORY_STEPSIZE) / 1000 seconds */ 
     31 
     32/* how many old values of the three wattages do we keep? */ 
     33#define SOLAR_WATT_HISTORYSIZE        10 
     34/* how far are the values apart? in milliseconds */ 
     35#define SOLAR_WATT_HISTORY_STEPSIZE   3000 
     36extern int SolarHistory[SOLAR_WATT_HISTORYSIZE][3]; /* three watt values: P1, P2, P3 */ 
     37extern int historyRemainTime; /* how many ticks have we left until the next history entry must be written? */ 
     38 
  • webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c

    r44 r56  
    88#include "task.h" 
    99#include "serial.h" 
     10#include "MetersIncludes.h" 
     11 
     12 
     13static void advanceHistoryArray(void); 
    1014 
    1115#define solarSTACK_SIZE         configMINIMAL_STACK_SIZE+200 
    1216 
    1317#define SOLAR_READ_DELAY         500 
     18 
     19/* after what inactivity time (ms) do we determine the solar FSM as stuck? */ 
     20#define SOLAR_FSM_STUCK_TIMEOUT  2000 
     21 
     22/* means "unknown value", converted to "U" on rrdtool script side */ 
     23#define SOLAR_FSM_INVALID_VALUE  0x4000 /* 16384 */ 
     24 
     25 
     26 
     27int SolarHistory[SOLAR_WATT_HISTORYSIZE][3]; /* three watt values: P1, P2, P3 */ 
     28int historyRemainTime = SOLAR_WATT_HISTORY_STEPSIZE; /* how many ticks have we left until the next history entry must be written? */ 
     29 
     30 
     31 
    1432 
    1533// Pin I/O LED Control Maskbit 
     
    106124portTickType xLastSolarStateChangeTime; 
    107125 
     126 /* time when the elements of the history array were last moved on one step */ 
     127portTickType xLastSolarHistoryAdvance; 
     128 
     129 
    108130 
    109131int solarReadErrors = 0; 
     
    141163void initSolarFSM(void) 
    142164{ 
     165  int i; 
    143166  xLastSolarStateChangeTime = xTaskGetTickCount(); 
     167  xLastSolarHistoryAdvance = xTaskGetTickCount(); 
    144168  xLastReadTime = xTaskGetTickCount(); 
    145169  solarState = SOL_NO_INIT; 
     
    147171  rxBuf3NextFreeRxPos = 0; 
    148172  currentChannel = 0; 
     173 
     174  /* set data to invalid value */ 
     175  chanWatt[0] = SOLAR_FSM_INVALID_VALUE; 
     176  chanWatt[1] = SOLAR_FSM_INVALID_VALUE; 
     177  chanWatt[2] = SOLAR_FSM_INVALID_VALUE; 
     178 
     179  /* invalidate history */ 
     180  for (i = 0; i < SOLAR_WATT_HISTORYSIZE; i++) 
     181  { 
     182            SolarHistory[i][0] = SOLAR_FSM_INVALID_VALUE; 
     183            SolarHistory[i][1] = SOLAR_FSM_INVALID_VALUE; 
     184            SolarHistory[i][2] = SOLAR_FSM_INVALID_VALUE; 
     185  } 
     186 
    149187} /* initSolarFSM */ 
    150188 
     
    326364 
    327365  /* did the SolarFSM get stuck during reading? */ 
    328   if (xTaskGetTickCount() > xLastSolarStateChangeTime + 5000
     366  if (xTaskGetTickCount() > xLastSolarStateChangeTime + SOLAR_FSM_STUCK_TIMEOUT
    329367  { 
    330368    /* something has gone wrong (possible Rx Timeout). restart, state SOL_NO_INIT */ 
     
    332370    initSolarFSM(); 
    333371    solarReadErrors++; 
     372  } 
     373  else if (xTaskGetTickCount() < xLastSolarStateChangeTime) 
     374  { 
     375    /* overflow of timer, just recover. delay will be wrong. */ 
     376    xLastSolarStateChangeTime = xTaskGetTickCount(); 
     377  } 
     378 
     379 
     380  if (xTaskGetTickCount() > (xLastSolarHistoryAdvance + SOLAR_WATT_HISTORY_STEPSIZE)) 
     381  { 
     382    advanceHistoryArray(); 
     383  } 
     384  else if (xTaskGetTickCount() < xLastSolarHistoryAdvance) 
     385  { 
     386    /* overflow of timer, just recover. delay will be wrong. */ 
     387    xLastSolarHistoryAdvance = xTaskGetTickCount(); 
    334388  } 
    335389 
     
    454508        if ((currentChannel >= 0) && (currentChannel < 6)) 
    455509        { 
     510          portENTER_CRITICAL(); 
    456511          chanVolt[currentChannel] = rxUART3[11]; 
    457512          chanWatt[currentChannel] = (int)(rxUART3[7]) | (((int)(rxUART3[8])) << 8) /* index 7: LSB, index 8: MSB */; 
     513          portEXIT_CRITICAL(); 
    458514        } /* if */ 
    459515 
     
    495551 
    496552 
     553/* 
     554 * Check if we have to save the current data to the next history array set, and do it 
     555 * if necessary. 
     556 * 
     557 */ 
     558static void advanceHistoryArray(void) 
     559{ 
     560  int i; 
     561 
     562  /* advance entries by 1. we do not care about data locking here. */ 
     563  for (i = 0; i < (SOLAR_WATT_HISTORYSIZE-1); i++) 
     564  { 
     565    portENTER_CRITICAL(); 
     566    SolarHistory[i+1][0] = SolarHistory[i][0]; 
     567    SolarHistory[i+1][1] = SolarHistory[i][1]; 
     568    SolarHistory[i+1][2] = SolarHistory[i][2]; 
     569    portEXIT_CRITICAL(); 
     570  } /* for */ 
     571  /* get the most recent values to index 0 */ 
     572  portENTER_CRITICAL(); 
     573  SolarHistory[0][0] = chanWatt[0]; 
     574  SolarHistory[0][1] = chanWatt[1]; 
     575  SolarHistory[0][2] = chanWatt[2]; 
     576  portEXIT_CRITICAL(); 
     577 
     578} /* advanceHistoryArray() */ 
    497579 
    498580