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"; |
---|
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: |
---|
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 | |
---|