亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? emeter-multirate.c

?? msp430F437三相電表DEMO(編譯器 IAR 3.42A)
?? C
?? 第 1 頁(yè) / 共 2 頁(yè)
字號(hào):
//--------------------------------------------------------------------------
//
//  Software for MSP430 based e-meters.
//
//  You may not use the Program in non-TI devices.
//
//  File: emeter-multirate.c
//
//  Steve Underwood <steve-underwood@ti.com>
//  Texas Instruments Hong Kong Ltd.
//
//  $Id: emeter-multirate.c,v 1.3 2005/12/20 10:17:57 a0754793 Exp $
//
/*! \file emeter-multirate.h */
//
//--------------------------------------------------------------------------
//
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#if !defined(__MSP430__)
#include <stdio.h>
#endif
#include <io.h>
#include <emeter-toolkit.h>
#include "emeter.h"
#include "emeter-structs.h"
#include "emeter-multirate.h"

#if MULTI_RATE_SUPPORT

uint8_t tariff_flags;

eeprom_history_t current_history;
uint8_t current_history_dirty;

/*! The current slot number in the usage history table */
uint8_t current_history_slot;

/*! The tariff type of the current day */
uint8_t current_day_type;

uint8_t current_tariff = 0xFF;

eeprom_daily_peak_t daily_peak;
uint8_t daily_peak_slot;

/*! The current slot in the five minute usage table. */
uint8_t current_five_minute_slot;

/*! This table is 30 minutes long, in 5 minute chunks. Usage is accumulated in
    5 minute chunks, to the centre of the 30 minute period of peak usage may be
    assessed to 5 minute accuracy. */
uint16_t five_minute_usages[6];

/* Add a one byte sumcheck to the passed message, in the byte after the message */
void add_sumcheck(void *buf, int len)
{
    uint8_t *s;
    int sum;

    sum = 0;
    s = (uint8_t *) buf;
    while (--len > 0)
        sum += *s++;
    *s = 0xFF - sum;
}

/* Check the passed message, which must include a one byte sumcheck, is OK */
int test_sumcheck(const void *buf, int len)
{
    const uint8_t *s;
    int sum;

    sum = 0;
    s = (uint8_t *) buf;
    while (len-- > 0)
        sum += *s++;
    return ((sum & 0xFF) == 0xFF);
}

void multirate_energy_pulse(void)
{
    five_minute_usages[current_five_minute_slot]++;
    if (++current_history.energy_lo == 0)
        ++current_history.energy_hi;
    current_history_dirty = TRUE;
}

int find_next_cutoff_date(void)
{
    int year;
    int month;
    int day;
    int best_year;
    int best_month;
    int best_day;
    int best_slot;
    int i;
    eeprom_cutoff_date_t cutoff_date;

    /* We need to find the smallest date which is greater than the current date */
    inhibit_rtc_updates();
    year = rtc.year;
    month = rtc.month;
    day = rtc.day;
    enable_rtc_updates();
    best_year = 99;
    best_month = 12;
    best_day = 31;
    best_slot = -1;
    for (i = 0;  i < MULTIRATE_MAX_CUTOFF_DATES;  i++)
    {
        iicEEPROM_read(EEPROM_START_CUTOFF_DATES + i*sizeof(eeprom_cutoff_date_t), (void *) &cutoff_date, sizeof(cutoff_date));
        if (year < cutoff_date.year
            ||
                (year == cutoff_date.year
                &&
                    (month < cutoff_date.month
                    ||
                    (month == cutoff_date.month  &&  day < cutoff_date.day))))
        {
            if (best_year > cutoff_date.year
                ||
                    (best_year == cutoff_date.year
                    &&
                        (best_month > cutoff_date.month
                        ||
                        (best_month == cutoff_date.month  &&  best_day > cutoff_date.day))))
            {
                /* This is earlier, so use it */
                best_slot = i;
                best_year = cutoff_date.year;
                best_month = cutoff_date.month;
                best_day = cutoff_date.day;
            }
        }
    }
    return best_slot;
}

int find_previous_cutoff_date(void)
{
    int year;
    int month;
    int day;
    int best_year;
    int best_month;
    int best_day;
    int best_slot;
    int i;
    eeprom_cutoff_date_t cutoff_date;
    
    /* We need to find the largest date which is less than the current date */
    inhibit_rtc_updates();
    year = rtc.year;
    month = rtc.month;
    day = rtc.day;
    enable_rtc_updates();
    best_year = 0;
    best_month = 0;
    best_day = 0;
    best_slot = -1;
    for (i = 0;  i < MULTIRATE_MAX_CUTOFF_DATES;  i++)
    {
        iicEEPROM_read(EEPROM_START_CUTOFF_DATES + i*sizeof(eeprom_cutoff_date_t), (void *) &cutoff_date, sizeof(cutoff_date));
        if (year > cutoff_date.year
            ||
                (year == cutoff_date.year
                &&
                    (month > cutoff_date.month
                    ||
                    (month == cutoff_date.month  &&  day >= cutoff_date.day))))
        {
            if (best_year < cutoff_date.year
                ||
                    (best_year == cutoff_date.year
                    &&
                        (best_month < cutoff_date.month
                        ||
                        (best_month == cutoff_date.month  &&  best_day < cutoff_date.day))))
            {
                /* This is later, so use it */
                best_slot = i;
                best_year = cutoff_date.year;
                best_month = cutoff_date.month;
                best_day = cutoff_date.day;
            }
        }
    }
    return best_slot;
}

void new_tariff_day(void)
{
    int i;
    uint8_t day_type;
    int year;
    int month;
    int day;
    int wday;
    eeprom_holiday_t holiday;
    eeprom_cutoff_date_t cutoff_date;

    /* Should be called when the day changes and at reset, to work out
       today's type */
    inhibit_rtc_updates();
    year = rtc.year;
    month = rtc.month;
    day = rtc.day;
    enable_rtc_updates();
    for (i = 0;  i < MULTIRATE_MAX_HOLIDAYS;  i++)
    {
        iicEEPROM_read(EEPROM_START_HOLIDAYS + i*sizeof(eeprom_holiday_t), (void *) &holiday, sizeof(holiday));
        if (year == holiday.year
            &&
            month == holiday.month
            &&
            day == holiday.day)
        {
            /* Its a holiday */
            current_day_type = holiday.day_type;
            return;
        }
    }
    /* Not a holiday. Just use the regular weekday pattern */
    wday = weekday();
    iicEEPROM_read(EEPROM_START_WEEKDAYS + (wday >> 1), (void *) &day_type, sizeof(day_type));
    current_day_type = ((wday & 1)  ?  (day_type >> 4)  :  day_type) & 0x0F;

    /* TODO: what if the real peak were a little before midnight */
    iicEEPROM_write(EEPROM_START_PEAKS + daily_peak_slot*sizeof(eeprom_daily_peak_t), (void *) &daily_peak, sizeof(daily_peak));
    if (++daily_peak_slot >= MULTIRATE_MAX_DAILY_PEAKS)
        daily_peak_slot = 0;

    daily_peak.usage = 0;
    daily_peak.hour = 0;
    daily_peak.minute = 0;
    
    /* Check if we have reached a billing cutoff point */
    iicEEPROM_read(EEPROM_START_CUTOFF_DATES + current_history_slot*sizeof(eeprom_cutoff_date_t), (void *) &cutoff_date, sizeof(cutoff_date));
    if (year > cutoff_date.year
        ||
        (year == cutoff_date.year
            &&
                (month > cutoff_date.month
                ||
                (month == cutoff_date.month  &&  day > cutoff_date.day))))
    {
        /* Its a cutoff point - find the next cutoff point, and start using the
           history slot specified for it. */
        /* If we didn't find a suitable slot, we continue accumulating where we
           are. At least that way we are gathering all the usage. */
        if ((i = find_next_cutoff_date()) >= 0)
            current_history_slot = i;
    }
}


void new_tariff_minute(void)
{
    int i;
    int n;
    int hour;
    int minute;
    eeprom_day_schedule_timeslot_t tariff;
    uint32_t energy;

    inhibit_rtc_updates();
    hour = rtc.hour;
    minute = rtc.minute;
    enable_rtc_updates();
    /* Default to the first timeslot */
    iicEEPROM_read(EEPROM_START_DAY_SCHEDULES + current_day_type*MULTIRATE_DAY_SCHEDULE_TIMESLOTS*sizeof(eeprom_day_schedule_timeslot_t), (void *) &tariff, sizeof(tariff));
    n = tariff.tariff;
    for (i = 1;  i < MULTIRATE_DAY_SCHEDULE_TIMESLOTS;  i++)
    {
        iicEEPROM_read(EEPROM_START_DAY_SCHEDULES + (current_day_type*MULTIRATE_DAY_SCHEDULE_TIMESLOTS + i)*sizeof(eeprom_day_schedule_timeslot_t), (void *) &tariff, sizeof(tariff));
        if (tariff.tariff)
        {
            if (tariff.start_hour > hour
                ||
                (tariff.start_hour == hour  &&  tariff.start_minute > minute))
            {
                n = tariff.tariff;
                break;
            }
        }
    }
    
    if (n != current_tariff)
    {
        /* Save current tariff values, and load the new set */
        write_history_slot(current_history_slot, current_tariff);
        read_history_slot(current_history_slot, n);
        current_tariff = n;
    }
    
    if (rtc.minute%5 == 0)
    {
        /* Deal with the time and size of the daily peak demand */
        energy = 0;
        for (i = 0;  i < 6;  i++)
            energy += five_minute_usages[i];
        if (energy > daily_peak.usage)
        {
            daily_peak.usage = energy;
            daily_peak.hour = rtc.hour;
            daily_peak.minute = rtc.minute;
        }
        five_minute_usages[current_five_minute_slot] = 0;
        if (++current_five_minute_slot >= 6)
            current_five_minute_slot = 0;
    }
    current_tariff = n;
}

int read_history_slot(int slot, int tariff)
{
    int i;
    int pos;
    eeprom_history_t history[3];
    int ok[3];

    if (!current_history_dirty)
        return 0;
    current_history_dirty = FALSE;
    pos = (slot*MULTIRATE_DAY_SCHEDULES + tariff)*sizeof(eeprom_history_t);

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线视频你懂得一区| 国产精品久久久久久久久图文区| 欧美亚洲一区二区三区四区| 99在线热播精品免费| 国产不卡视频在线观看| 国产电影精品久久禁18| 国产精品香蕉一区二区三区| 国产老肥熟一区二区三区| 国产原创一区二区三区| 国产在线视频一区二区三区| 国产麻豆成人传媒免费观看| 国产成人免费xxxxxxxx| 成人教育av在线| 91视频免费观看| 在线观看三级视频欧美| 69精品人人人人| 亚洲精品一区二区三区福利| 国产亚洲欧洲一区高清在线观看| 国产欧美视频一区二区三区| 亚洲天堂久久久久久久| 亚洲第一电影网| 免费观看一级特黄欧美大片| 国内精品免费在线观看| 国产精品456| 91视频免费看| 欧美一级片在线看| 国产欧美日本一区二区三区| 日韩码欧中文字| 午夜国产精品一区| 韩国精品一区二区| 99久久99久久精品国产片果冻| 欧美三级一区二区| 日韩精品一区二区三区视频播放| 国产欧美一区二区三区在线看蜜臀 | 三级精品在线观看| 久久成人免费网| 成人免费毛片嘿嘿连载视频| 欧洲视频一区二区| 日韩午夜在线观看| 亚洲欧洲精品一区二区三区不卡| 一区二区三区精密机械公司| 青草国产精品久久久久久| 粉嫩高潮美女一区二区三区| 欧美视频一区二区三区四区| 久久男人中文字幕资源站| 一区二区在线观看视频| 久久99精品久久久久| av中文一区二区三区| 欧美一区二区三区视频免费| 国产精品视频看| 蜜臀av国产精品久久久久| 成人av网站在线观看| 7777精品伊人久久久大香线蕉经典版下载| 欧美成人女星排行榜| 亚洲免费在线电影| 狠狠色丁香婷婷综合久久片| 色国产精品一区在线观看| 欧美成人精品福利| 亚洲综合网站在线观看| 国产高清不卡二三区| 在线91免费看| 中文字幕在线不卡一区| 久久激五月天综合精品| 在线观看91精品国产入口| 欧美激情一区二区三区四区| 手机精品视频在线观看| av日韩在线网站| 久久精品一区二区| 日韩av中文在线观看| 91麻豆国产福利精品| 久久嫩草精品久久久精品一| 日本欧美韩国一区三区| 欧美性淫爽ww久久久久无| 国产精品久久久久久福利一牛影视 | 美女一区二区久久| 欧美色综合天天久久综合精品| 日本一区二区动态图| 免费成人你懂的| 欧美日韩黄色一区二区| 亚洲欧美偷拍卡通变态| 成人激情动漫在线观看| 久久久精品国产免费观看同学| 日本亚洲免费观看| 欧美私模裸体表演在线观看| 亚洲男人的天堂一区二区| 成人精品电影在线观看| 久久久国产精品麻豆| 麻豆成人久久精品二区三区红| 欧美喷水一区二区| 亚洲成a人片在线不卡一二三区| 色综合久久66| 亚洲欧美一区二区久久| 99riav一区二区三区| 国产精品久久久久毛片软件| 国产黄人亚洲片| 中文字幕精品一区二区三区精品| 久久国产免费看| 久久伊99综合婷婷久久伊| 黑人巨大精品欧美黑白配亚洲| 日韩欧美国产精品一区| 另类小说综合欧美亚洲| 精品毛片乱码1区2区3区| 久草这里只有精品视频| 日韩视频一区二区| 久久99精品一区二区三区三区| 欧美精品日韩一区| 日本免费在线视频不卡一不卡二 | 欧美精彩视频一区二区三区| 国产成人激情av| 国产精品久久久久影院色老大| 成人激情综合网站| 亚洲人成精品久久久久| 欧美综合一区二区| 亚洲bdsm女犯bdsm网站| 91精品国产综合久久国产大片| 日韩电影在线免费| 久久在线免费观看| 成人涩涩免费视频| 亚洲少妇30p| 欧美精品免费视频| 美国三级日本三级久久99| 久久久久久夜精品精品免费| 丁香婷婷综合五月| 亚洲精品日日夜夜| 欧美一区永久视频免费观看| 黄色资源网久久资源365| 欧美国产一区视频在线观看| 在线观看亚洲一区| 美女视频一区二区三区| 国产日韩欧美精品综合| 99国产精品久久久久久久久久 | 色综合久久综合网欧美综合网| 一区二区三区四区精品在线视频| 欧美综合视频在线观看| 久久精品久久综合| 国产精品乱码一区二区三区软件 | 美女网站一区二区| 中文字幕成人av| 欧美午夜精品久久久久久超碰 | 极品尤物av久久免费看| 国产精品―色哟哟| 欧美日韩免费观看一区三区| 免费成人在线播放| 亚洲视频一区在线| 这里只有精品电影| 成人av动漫在线| 三级久久三级久久| 国产精品免费aⅴ片在线观看| 欧美日韩aaaaa| 成人激情免费视频| 日韩电影免费一区| 国产精品对白交换视频| 91精品国产欧美一区二区成人 | 欧美亚日韩国产aⅴ精品中极品| 美女高潮久久久| 一区二区三区在线观看网站| 日韩免费高清电影| 91国产丝袜在线播放| 国产综合久久久久影院| 亚洲综合一区二区三区| 久久久精品黄色| 在线播放欧美女士性生活| www.日韩在线| 美女网站色91| 性欧美疯狂xxxxbbbb| 中文字幕日韩精品一区| 26uuu精品一区二区在线观看| 日本道在线观看一区二区| 黄页视频在线91| 日韩精品欧美成人高清一区二区| 国产精品进线69影院| 精品久久人人做人人爱| 欧美日韩中文一区| gogogo免费视频观看亚洲一| 精品一区二区三区视频在线观看 | 亚洲一区自拍偷拍| 国产精品丝袜一区| 精品国精品自拍自在线| 欧美精品在线一区二区| 色婷婷久久久久swag精品| 国产成人免费视频一区| 久久精品免费观看| 日本系列欧美系列| 亚洲高清免费在线| 国产精品久久久久影院老司 | 亚洲综合999| 中文字幕亚洲区| 国产精品美女久久久久av爽李琼| 久久久亚洲精品石原莉奈| 日韩欧美一级片| 91精品国产高清一区二区三区| 在线一区二区三区做爰视频网站| 成人一区二区三区| 国产传媒久久文化传媒| 精品无人区卡一卡二卡三乱码免费卡 | 一区二区欧美视频| 18成人在线视频| 中国av一区二区三区| 亚洲国产精品t66y| 欧美极品美女视频|