Changeset 73
- Timestamp:
- 10/23/10 21:39:51 (14 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
webserver/example/EnergyMeters/EnergyMeters/ARM7_LPC2368_Rowley/webserver/httpd-cgi.c
r71 r73 73 73 74 74 75 extern int dayRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* daily yield data */ 75 extern int dayRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* daily yield data (last day) */ 76 extern int hourRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* hourly yield data (last hour) */ 76 77 77 78 extern int resultValueRaw; /* last raw yield value */ … … 289 290 strcat( uip_appdata, cCountBuf ); 290 291 291 292 292 sprintf( cCountBuf, "LASTHOUR %u %u %u\n", hourRxYield[0], hourRxYield[1], hourRxYield[2] ); 293 strcat( uip_appdata, cCountBuf ); 293 294 294 295 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 63 63 #define SOL_QUERY_TIME 4 /* querying the time on the SC */ 64 64 #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 */ 67 69 #define SOL_FINISHED 0xA /* finished */ 68 70 //#define SOL_ … … 103 105 104 106 105 int dayRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* daily yield data */106 107 int dayRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* daily yield data (last day) */ 108 int hourRxYield[NUMBER_OF_SOLAR_CHANNELS]; /* hourly yield data (last hour) */ 107 109 108 110 const unsigned char query_sc_time[] = "\x02\xB0\xF0\x03\x00\x04\xAB\xB9\x03"; // Zeit abfragen … … 132 134 133 135 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";136 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() 137 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"; 138 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"; 137 139 138 140 … … 450 452 unsigned char power; /* variable for conversions */ 451 453 unsigned char checkDate; /* temp variable for day of month */ 454 unsigned char checkHour; /* temp variable for hour */ 452 455 unsigned char rxYieldChkSum; /* temp checksum for rx yield */ 456 453 457 454 458 /* always get Rx data */ … … 569 573 570 574 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 */ 572 576 } 573 577 else … … 578 582 break; 579 583 580 case SOL_QUERY_YIELD: 584 ////// begin day queries 585 586 case SOL_QUERY_LASTDAY_YIELD: 581 587 582 588 xLastSolarStateChangeTime = xTaskGetTickCount(); 583 584 /* first, fill in data for tx */585 // TODO586 587 589 588 590 if (currentChannel >= 6) 589 591 { 590 592 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 */ 592 594 } 593 595 else … … 633 635 send_yield_query_day(/* channel: */ currentChannel, /* day: (yesterday) */ checkDate ); 634 636 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 */ 636 638 637 639 } 638 640 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: 655 644 656 645 cmpResult = checkUart3Received(yield_day_rsp, yield_day_r_m, sizeof(yield_day_rsp)-1); 657 658 659 646 660 647 /* wait for reply to request, check if full response has arrived */ … … 681 668 else 682 669 { 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 */ 684 671 } 685 672 } … … 698 685 currentChannel++; /* increment channel counter so we query the next channel in the next round */ 699 686 xLastSolarStateChangeTime = xTaskGetTickCount(); 700 solarState = SOL_QUERY_ YIELD; /* go ahead */687 solarState = SOL_QUERY_LASTDAY_YIELD; /* go ahead */ 701 688 } 702 689 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 704 786 705 787