Changeset 56 for webserver/example/EnergyMeters/Source
- Timestamp:
- 03/07/10 10:45:29 (15 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h
r50 r56 28 28 meterItem meterItems[NUMBER_OF_METERS]; /* the data for all the meters */ 29 29 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 36 extern int SolarHistory[SOLAR_WATT_HISTORYSIZE][3]; /* three watt values: P1, P2, P3 */ 37 extern 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 8 8 #include "task.h" 9 9 #include "serial.h" 10 #include "MetersIncludes.h" 11 12 13 static void advanceHistoryArray(void); 10 14 11 15 #define solarSTACK_SIZE configMINIMAL_STACK_SIZE+200 12 16 13 17 #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 27 int SolarHistory[SOLAR_WATT_HISTORYSIZE][3]; /* three watt values: P1, P2, P3 */ 28 int historyRemainTime = SOLAR_WATT_HISTORY_STEPSIZE; /* how many ticks have we left until the next history entry must be written? */ 29 30 31 14 32 15 33 // Pin I/O LED Control Maskbit … … 106 124 portTickType xLastSolarStateChangeTime; 107 125 126 /* time when the elements of the history array were last moved on one step */ 127 portTickType xLastSolarHistoryAdvance; 128 129 108 130 109 131 int solarReadErrors = 0; … … 141 163 void initSolarFSM(void) 142 164 { 165 int i; 143 166 xLastSolarStateChangeTime = xTaskGetTickCount(); 167 xLastSolarHistoryAdvance = xTaskGetTickCount(); 144 168 xLastReadTime = xTaskGetTickCount(); 145 169 solarState = SOL_NO_INIT; … … 147 171 rxBuf3NextFreeRxPos = 0; 148 172 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 149 187 } /* initSolarFSM */ 150 188 … … 326 364 327 365 /* did the SolarFSM get stuck during reading? */ 328 if (xTaskGetTickCount() > xLastSolarStateChangeTime + 5000)366 if (xTaskGetTickCount() > xLastSolarStateChangeTime + SOLAR_FSM_STUCK_TIMEOUT) 329 367 { 330 368 /* something has gone wrong (possible Rx Timeout). restart, state SOL_NO_INIT */ … … 332 370 initSolarFSM(); 333 371 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(); 334 388 } 335 389 … … 454 508 if ((currentChannel >= 0) && (currentChannel < 6)) 455 509 { 510 portENTER_CRITICAL(); 456 511 chanVolt[currentChannel] = rxUART3[11]; 457 512 chanWatt[currentChannel] = (int)(rxUART3[7]) | (((int)(rxUART3[8])) << 8) /* index 7: LSB, index 8: MSB */; 513 portEXIT_CRITICAL(); 458 514 } /* if */ 459 515 … … 495 551 496 552 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 */ 558 static 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() */ 497 579 498 580