Exemplo n.º 1
0
//F8:返回电表ID
void GetEmId(void)
{
    static BYTE  i;
    
    Clear_Sms_Content();
    
    SmsContent[0] = 'F';
    SmsContent[1] = '8';
    SmsContent[2] = ':';

    for (i=0;i<6;i++)
    {
        SmsContent[3+i*2]   = HexToBcd(EmId[5-i]/0x10);
        SmsContent[3+i*2+1] = HexToBcd(EmId[5-i]%0x10);
    }
    
    SmsLength = 15;
    if (SysParam[SP_MODTYPE] == GSM_MG323)
    {
        Send_Pdu_SMS();
    }
    else if (SysParam[SP_MODTYPE] == CDMA_MC323)
    {
        Send_Txt_SMS(SmsNumber, SmsContent);
    }
}
Exemplo n.º 2
0
uint8 TIME_AddMon(uint8 *pDate, uint8 mon) //月增量
{
    uint8 temp, temp1, temp2;
    temp = BcdToHex(pDate[1]) + mon;
    temp1 = temp % 12;
    temp2 = temp / 12;
    pDate[4] = HexToBcd(temp1);
    if (temp2 != 0)  pDate[5] = HexToBcd(BcdToHex(pDate[5]) + temp2);
    return 0;
}
Exemplo n.º 3
0
/**
* @brief 终端参数F33操作
* @param flag 操作方式, 0-读, 1-写
* @param option 操作选项
* @return 0成功, 否则失败(参看POERR_XXX宏定义)
*/
int ParaOperationF33(int flag, unsigned short metpid, param_specialop_t *option)
{
	if(0 == flag) {
		int num, i, j, portid, actnum, periodnum;
		const unsigned char *prbuf;
		unsigned char *pwbuf;
		unsigned short wlen;

		num = (int)option->rbuf[0]&0xff;
		option->ractlen = num + 1;
		if(option->rlen < option->ractlen) return POERR_FATAL;

		wlen = 1;
		prbuf = option->rbuf + 1;
		pwbuf = option->wbuf + 1;
		actnum = 0;
		for(i=0; i<num; i++,prbuf++) {
			portid = (int)prbuf[0]&0xff;//得到端口号(1-31)
			if(portid == 0 || portid > MAX_COMMPORT) continue;
			if((wlen+14) > option->wlen) break;
			portid -= 1;//端口号减去1

			*pwbuf++ = prbuf[0];
			*pwbuf++ = ParaMixSave.commport[portid].flag & 0xff;
			*pwbuf++ = ParaMixSave.commport[portid].flag >> 8;
			*pwbuf++ = ParaMixSave.commport[portid].dateflag & 0xff;
			*pwbuf++ = (ParaMixSave.commport[portid].dateflag>>8) & 0xff;
			*pwbuf++ = (ParaMixSave.commport[portid].dateflag>>16) & 0xff;
			*pwbuf++ = (ParaMixSave.commport[portid].dateflag>>24) & 0xff;
			pwbuf[0] = ParaMixSave.commport[portid].time_minute;
			pwbuf[1] = ParaMixSave.commport[portid].time_hour;
			HexToBcd(pwbuf, 2); pwbuf += 2;
			*pwbuf++ = ParaMixSave.commport[portid].cycle;
			pwbuf[0] = ParaMixSave.commport[portid].chktime_minute;
			pwbuf[1] = ParaMixSave.commport[portid].chktime_hour;
			pwbuf[2] = ParaMixSave.commport[portid].chktime_day;
			HexToBcd(pwbuf, 3); pwbuf += 3;

			*pwbuf++ = ParaMixSave.commport[portid].periodnum;	
			periodnum = (int)ParaMixSave.commport[portid].periodnum&0xff;
			for(j=0; j<periodnum; j++) {
				pwbuf[0] = ParaMixSave.commport[portid].period[j].min_start;
				pwbuf[1] = ParaMixSave.commport[portid].period[j].hour_start;
				pwbuf[2] = ParaMixSave.commport[portid].period[j].min_end;
				pwbuf[3] = ParaMixSave.commport[portid].period[j].hour_end;
				HexToBcd(pwbuf, 4); pwbuf += 4;
			}
			wlen += 14;
			wlen += periodnum * 4;
			actnum++;
		}

		option->wactlen = wlen;
		option->wbuf[0] = actnum;
	}
Exemplo n.º 4
0
//将文本内容转化为PDU格式
BYTE ChangeContent(void)
{
    static WORD i,n;

    for (i=0;i<SMSMSGCOUNT*2;i++)
    {
        SmsContent2[i] = 0;
    }
    
    SmsLength2 = 0;
    // 固定字段
    mcpy(&SmsContent2[SmsLength2],"089168",6);
    SmsLength2 = 6;

    //中心号码
    mcpy(&SmsContent2[SmsLength2],CenterNumber,12);
    SmsLength2 += 12;
    
    mcpy(&SmsContent2[SmsLength2],"11000D9168",10);
    SmsLength2 += 10;
    
    //目的电话号码
    //SmsNumber
    mcpy(&SmsContent2[SmsLength2],SmsNumber,12);
    SmsLength2 += 12;
    

    //固定
    mcpy(&SmsContent2[SmsLength2],"0000C2",6);   // 8 bit 编码 ,有效期5分钟
    SmsLength2 += 6;

    //内容长度
    SmsContent2[SmsLength2]   = HexToBcd(SmsLength / 16);
    SmsContent2[SmsLength2+1] = HexToBcd(SmsLength % 16);
    SmsLength2 += 2;

    n = Encode7bit(SmsContent, SmsLength);
    
    //信息内容 -- BCD码
    for (i=0;i<n;i++)
    {
        SmsContent2[SmsLength2]   = HexToBcd(SmsContent[i] / 16);
        SmsContent2[SmsLength2+1] = HexToBcd(SmsContent[i] % 16);
        SmsLength2 += 2;
    }

    return n;
}
Exemplo n.º 5
0
//将文本内容转化为PDU格式
void ChangeContent(void)
{
    static BYTE i;

    for (i=0;i<SMSMSGCOUNT*2;i++)
    {
        SmsContent2[i] = 0;
    }
    
    SmsLength2 = 0;
    // 固定字段
    mcpy(&SmsContent2[SmsLength2],"0781",4);
    SmsLength2 += 4;

    //中心号码
    mcpy(&SmsContent2[SmsLength2],CenterNumber,12);
    SmsLength2 += 12;
    
    mcpy(&SmsContent2[SmsLength2],"11000B",6);
    SmsLength2 += 6;
    
    //目的电话号码
    //SmsNumber
    mcpy(&SmsContent2[SmsLength2],SmsNumber,12);
    SmsLength2 += 12;
    

    //固定
    mcpy(&SmsContent2[SmsLength2],"0004C2",6);   // 8 bit 编码 ,有效期5分钟
    SmsLength2 += 6;

    //内容长度
    SmsContent2[SmsLength2]   = HexToBcd(SmsLength / 16);
    SmsContent2[SmsLength2+1] = HexToBcd(SmsLength % 16);
    SmsLength2 += 2;
    
    //信息内容 -- BCD码
    for (i=0;i<SmsLength;i++)
    {
        SmsContent2[SmsLength2]   = HexToBcd(SmsContent[i] / 16);
        SmsContent2[SmsLength2+1] = HexToBcd(SmsContent[i] % 16);
        SmsLength2 += 2;
    }
}
Exemplo n.º 6
0
/**
* @brief 读取F1 终端版本信息
* @param buf 缓存区指针
* @param len 缓存区长度, 成功返回实际读取长度, 否则返回-1
*/
static int ReadVersionInfo(unsigned char *buf, int len)
{
	//unsigned char tmpbuf[32];
	//int i, projnum = 0;
        int i;

	if(len < VERSIONINFO_LEN) return -1;

	memcpy(buf, VersionInfo, VERSIONINFO_LEN);
	
	for(i=0; i<8; i++) {
		if(0 == ParaUni.manuno[i]) break;
		buf[i+4] = ParaUni.manuno[i];
	}
	buf[16] = RELEASE_DATE_DAY;
	buf[17] = RELEASE_DATE_MONTH;
	buf[18] = RELEASE_DATE_YEAR;
	HexToBcd(buf+16, 3);

	i = 0;
	if(i/10 != 0) {
		buf[28] = '0' + i/10;
		buf[29] = '0' + i%10;
	}
	else {
		buf[28] = '0'+i;
	}

#if 0
	if(PrintCMetProtoInfo(tmpbuf) > 0) {
		buf[30] = '0'+tmpbuf[5]/10;
		buf[31] = '0'+tmpbuf[5]%10;
		buf[32] = '0'+tmpbuf[6]/10;
		buf[33] = '0'+tmpbuf[6]%10;
	}
	if(ReadDriverVersion(tmpbuf, 4) > 0) {
		buf[34] = '0' + tmpbuf[0];
		buf[35] = '0' + tmpbuf[1];
		buf[36] = '0' + tmpbuf[2];
		buf[37] = '0' + tmpbuf[3];
	}

#endif
	/*
	if(ReadDriverVersion(tmpbuf, 8) > 0) {
		buf[34] = '0'+tmpbuf[0]/10;
		buf[35] = '0'+tmpbuf[0]%10;
		buf[36] = '0'+tmpbuf[1]/10;
		buf[37] = '0'+tmpbuf[1]%10;
		buf[38] = tmpbuf[4];
		buf[39] = tmpbuf[3];
		buf[40] = tmpbuf[2];
	}*/

	return VERSIONINFO_LEN;
}
Exemplo n.º 7
0
uint8 TIME_AddHour(uint8 *pDate, uint8 hour) //小时增量
{
    uint8 temp, temp1, temp2;
    temp = BcdToHex(pDate[2]) + hour;
    temp1 = temp % 24;
    temp2 = temp / 24;
    pDate[2] = HexToBcd(temp1);
    if (temp2 != 0)  TIME_AddDate(pDate, temp2);
    return 0;
}
Exemplo n.º 8
0
uint8 TIME_AddMin(uint8 *pDate, uint8 min) //分钟增量
{
    uint8 temp, temp1, temp2;
    temp = BcdToHex(pDate[1]) + min;
    temp1 = temp % 60;
    temp2 = temp / 60;
    pDate[1] = HexToBcd(temp1);
    if (temp2 != 0)  TIME_AddHour(pDate, temp2);
    return 0;

}
Exemplo n.º 9
0
uint8 TIME_AddSec(uint8 *pDate, uint8 sec) //秒增量
{
    uint8 temp, temp1, temp2;
    temp = BcdToHex(pDate[0]) + sec;
    temp1 = temp % 60;
    temp2 = temp / 60;
    pDate[0] = HexToBcd(temp1);
    if (temp2 != 0)  TIME_AddMin(pDate, temp2);
    return 0;

}
Exemplo n.º 10
0
static bool_t __Rtc_SetTime(s64 time)
{
    bool_t result = false;
    struct tm dtm;
    s64 time_s;
    u32 dtime,timout = 1500*mS;

    time_s = time/1000000;
    Tm_LocalTime_r(&time_s,&dtm);

    if((dtm.tm_year > 2000) && (dtm.tm_year < 2099))
    {
        RTC->RTC_CR |= RTC_CR_UPDTIM | RTC_CR_UPDCAL;

        while((RTC->RTC_SR & RTC_SR_ACKUPD) != RTC_SR_ACKUPD)
        {
            Djy_EventDelay(100*mS);
            timout -= 100*mS;
            if(timout <= 0)
            {
                RTC->RTC_CR &= ~(RTC_CR_UPDCAL | RTC_CR_UPDTIM) ;
                RTC->RTC_SCCR |= RTC_SCCR_SECCLR; /* clear SECENV in SCCR */
                return false;
            }
        }
//      while ((RTC->RTC_SR & RTC_SR_ACKUPD) != RTC_SR_ACKUPD) ;
        RTC->RTC_SCCR = RTC_SCCR_ACKCLR ;

        dtime = (HexToBcd(dtm.tm_hour) << RTC_TIMR_HOUR_Pos) |
                (HexToBcd(dtm.tm_min) << RTC_TIMR_MIN_Pos) |
                (HexToBcd(dtm.tm_sec) << RTC_TIMR_SEC_Pos);

        RTC->RTC_TIMR = dtime;
        if(dtm.tm_wday == 0)
            dtm.tm_wday = 7;
        dtime = (HexToBcd(dtm.tm_year - 2000) << RTC_CALR_YEAR_Pos) |
                (HexToBcd(dtm.tm_mon) << RTC_CALR_MONTH_Pos) |
                (HexToBcd(dtm.tm_mday) << RTC_CALR_DATE_Pos) |
                (HexToBcd(dtm.tm_wday) << RTC_CALR_DAY_Pos)|
                (HexToBcd(20) << RTC_CALR_CENT_Pos);

        RTC->RTC_CALR = dtime;

        RTC->RTC_CR &= ~(RTC_CR_UPDCAL | RTC_CR_UPDTIM) ;
        RTC->RTC_SCCR |= RTC_SCCR_SECCLR; /* clear SECENV in SCCR */
        result = !((RTC->RTC_VER & RTC_VER_NVTIM)
                | (RTC->RTC_VER & RTC_VER_NVCAL)) ;
    }

    return result;
}
Exemplo n.º 11
0
uint8 TIME_SubHour(uint8 *pDate, uint8 hour) //小时减法
{
    uint8 temp, temp1;
    temp = BcdToHex(pDate[1]);
    if (temp > hour) temp1 = temp - hour;
    else
    {
        temp1 = temp + 24 - hour;
        SubDate(pDate);
    }
    pDate[2] = HexToBcd(temp1);
    return 0;
}
Exemplo n.º 12
0
uint8 TIME_SubMin(uint8 *pDate, uint8 min) //分钟减法
{
    uint8 temp, temp1;
    temp = BcdToHex(pDate[1]);
    if (temp >= min) temp1 = temp - min;
    else
    {
        temp1 = temp + 60 - min;
        TIME_SubHour(pDate, 1);
    }
    pDate[1] = HexToBcd(temp1);
    return 0;

}
Exemplo n.º 13
0
//F8:返回电表ID
void GetEmId(void)
{
    static BYTE  i;
    
    Clear_Sms_Content();
    
    SmsContent[0] = 'F';
    SmsContent[1] = '8';
    SmsContent[2] = ':';
    SmsContent[3] = 'N';
    SmsContent[4] = 'O';
    SmsContent[5] = '1';
    SmsContent[6] = '.';
    for (i=0;i<6;i++)
    {
        SmsContent[7+i*2]   = HexToBcd(SysParam[SP_METERADDR1+5-i]/0x10);
        SmsContent[7+i*2+1] = HexToBcd(SysParam[SP_METERADDR1+5-i]%0x10);
    }
    SmsContent[19] = '\r';
    SmsContent[20] = '\n';
    
    SmsContent[21] = 'N';
    SmsContent[22] = 'O';
    SmsContent[23] = '2';
    SmsContent[24] = '.';
    for (i=0;i<6;i++)
    {
        SmsContent[25+i*2]   = HexToBcd(SysParam[SP_METERADDR2+5-i]/0x10);
        SmsContent[25+i*2+1] = HexToBcd(SysParam[SP_METERADDR2+5-i]%0x10);
    }
    SmsContent[37] = '\r';
    SmsContent[38] = '\n';
    
    SmsContent[39] = 'N';
    SmsContent[40] = 'O';
    SmsContent[41] = '3';
    SmsContent[42] = '.';
    for (i=0;i<6;i++)
    {
        SmsContent[43+i*2]   = HexToBcd(SysParam[SP_METERADDR3+5-i]/0x10);
        SmsContent[43+i*2+1] = HexToBcd(SysParam[SP_METERADDR3+5-i]%0x10);
    }
    SmsLength = 54;
    if (SysParam[SP_MODTYPE] == GSM_MG323)
    {
        Send_Pdu_SMS();
    }
    else if (SysParam[SP_MODTYPE] == CDMA_MC323)
    {
        Send_Txt_SMS(SmsNumber, SmsContent);
    }
}
Exemplo n.º 14
0
//-----更新RTC时钟---------------------------------------------------------------
//功能:将年月日时分秒写入到RTC时钟,更新RTC,由于RTC芯片存放的时间信息是基于BCD
//      编码格式,所以在写入时间前,需要将时间信息转化为相应的BCD格式
//参数:DateTime,rtc_tm结构类型的变量,里面存放着需更新RTC的时间信息
//返回:无
//-----------------------------------------------------------------------------
bool_t rtc_update_time(struct rtc_tm *DateTime)
{
    //判断是否需要初始化SPI,以防module_init_rtc未被调用
    if(!rtc_spi_Config)
    {
        rtc_spi_Config = &pg_spi_Config;
        rtc_spi_Config->freq=CFG_RTC_SPI_SPEED;
        Spi_Init(CFG_RTC_SPI_BUS,rtc_spi_Config);
    }

    __rtc_write (RTC_CMD_SECONDS,     HexToBcd (DateTime->tm_sec));
    __rtc_write (RTC_CMD_MINUTES,     HexToBcd (DateTime->tm_min));
    __rtc_write (RTC_CMD_HOURS,       HexToBcd (DateTime->tm_hour));
    __rtc_write (RTC_CMD_DAY_OF_WEEK, HexToBcd (DateTime->tm_wday + 1));//星期几
    __rtc_write (RTC_CMD_DATE_OF_MONTH, HexToBcd (DateTime->tm_mday));
    __rtc_write (RTC_CMD_MONTH,       HexToBcd (DateTime->tm_mon));
    __rtc_write (RTC_CMD_YEAR,        HexToBcd (DateTime->tm_year- 2000));

    return 1;
}
Exemplo n.º 15
0
// =============================================================================
// 功能:RTC时钟更新,将系统时间更新到RTC模块,由于时钟模块的年存储的最大值为99,因此
//       本RTC模块设计从2000为起始值,如2014,则RTC模块的rBCDYEAR存储的是14
// 参数:dtm,更新时间
// 返回:true,成功;false,失败
// =============================================================================
bool_t RTC_TimeUpdate(s64 time)
{
    bool_t result = false;
    struct tm dtm;
    s64 time_s;

    time_s = time/1000000;
    Tm_LocalTime_r(&time_s,&dtm);

    if((dtm.tm_year > 2000) && (dtm.tm_year < 2099))
    {
        rRTCCON = 1 ;       //RTC read and write enable
        rBCDYEAR = HexToBcd(dtm.tm_year - 2000);
        rBCDMON  = HexToBcd(dtm.tm_mon);
        rBCDDATE = HexToBcd(dtm.tm_mday);
        rBCDHOUR = HexToBcd(dtm.tm_hour);
        rBCDMIN  = HexToBcd(dtm.tm_min);
        rBCDSEC  = HexToBcd(dtm.tm_sec);
        rRTCCON &= ~1 ;     //RTC read and write disable
        result = true;
    }
    return result;
}
Exemplo n.º 16
0
/**
* @brief 市电状态监测
* @param pbuf 告警缓存区指针
*/
static void PowerMonitor(alarm_t *pbuf)
{
	int stat = GpioGetValue(GPIO_POWER_STATUS);

	#if 1
	if(stat) {  //power off
		if(0 == RunState.pwroff) {
			runstate_t *prun = RunStateModify();
			sysclock_t clock;

			PrintLog(LOGTYPE_ALARM, "power off!!\n");
			Sleep(200);

			prun->pwroff = 1;

			memset((unsigned char *)pbuf, 0, sizeof(alarm_t));
			pbuf->erc = 14;
			pbuf->len = 5;
			//记录停电时间	
			SysClockReadCurrent(&clock);
			prun->timepoweroff[0] = pbuf->min = clock.minute;
			prun->timepoweroff[1] = pbuf->hour = clock.hour;
			prun->timepoweroff[2] = pbuf->day = clock.day;
			prun->timepoweroff[3] = pbuf->mon = clock.month;
			prun->timepoweroff[4] = pbuf->year = clock.year;
			HexToBcd(&pbuf->min, 5);
			MakeAlarm(ALMFLAG_ABNOR, pbuf);
			
			if(TimerIdPowerOff >= 0) {
				SysStopCTimer(TimerIdPowerOff);
				TimerIdPowerOff = -1;
			}
			TimerIdPowerOff = SysAddCTimer(180, CTimerPowerOff, 0);
		}
		else {
			if(TimerIdPowerOff < 0)
				TimerIdPowerOff = SysAddCTimer(180, CTimerPowerOff, 0);
		}
	}
	else {  //power on
		if(RunState.pwroff) {
			sysclock_t clock;

			RunStateModify()->pwroff = 0;
			if(TimerIdPowerOff >= 0) {
				SysStopCTimer(TimerIdPowerOff);
				TimerIdPowerOff = -1;
			}

			memset((unsigned char *)pbuf, 0, sizeof(alarm_t));
			pbuf->erc = 14;
			pbuf->len = 5;
			//记录上次停电时间			
			pbuf->min = RunState.timepoweroff[0];
			pbuf->hour = RunState.timepoweroff[1];
			pbuf->day = RunState.timepoweroff[2];
			pbuf->mon = RunState.timepoweroff[3];
			pbuf->year = RunState.timepoweroff[4];
			HexToBcd(&pbuf->min, 5);

			SysClockReadCurrent(&clock);
			pbuf->data[0] = clock.minute;
			pbuf->data[1] = clock.hour;
			pbuf->data[2] = clock.day;
			pbuf->data[3] = clock.month;
			pbuf->data[4] = clock.year;
			HexToBcd(pbuf->data, 5);
			MakeAlarm(ALMFLAG_NORMAL, pbuf);
		}
	}
	#else
	runstate_t *prun = RunStateModify();

	prun->pwroff = 0;
	#endif
}
Exemplo n.º 17
0
/**
* @brief 读取载波表即时数据
* @param metpid 测量点号, MAX_CENMETP+1 ~ MAX_METP
* @param itemid 数据项编号
* @param buf 输出缓存区指针
* @param len 输出缓存区长度
* @return 成功返回实际读取长度, 失败返回负数, 无此数据项返回-2, 缓存区溢出返回-1
*/
static int ReadPlMdbCurrent(unsigned short metpid, unsigned short itemid, unsigned char *buf, int len)
{
#define RETRY_TIMES		3
	unsigned short mid;
	plc_dest_t dest;
	int i, retry;
	unsigned char databuf[4];
	sysclock_t clock;
	unsigned char point_read_receive_buf[256];
	int point_read_receive_len = 0;
	plc_packet_t pak;
	pak_645_t pak_645;
	unsigned char meter_addr_tmp[6];
	unsigned char ene_buf[20];
	int meter_postion = 0;

	PrintLog(0, "ReadPlMdbCurrent1\n");
	if(metpid <= PLC_BASEMETP || metpid > MAX_METER) return -2;
	mid = metpid - 1;
	if(ParaMeter[mid].metp_id == 0) return -2;
	
	PrintLog(0, "ReadPlMdbCurrent2\n");

	//MakePlcDest(mid, &dest);
	//dest.metid = 0;
	PrintLog(0, "itemid = %x\n",itemid);
	switch(itemid) {
	case 0x1001:  //F129 即时读,如果失败,则读库
	case 0x0401:  //F33 即时读,如果失败,则读库
		if(len < 11) return -1;
		PrintLog(0, "ReadPlMdbCurrent3\n");
		for(retry=0; retry<RETRY_TIMES; retry++) 
		{
			if(ParaMeter[mid].proto == PROTO_DL1997_376_1)
			{
				point_read_receive_len = point_read(0x9010,(unsigned char *)&ParaMeter[mid].addr[0],point_read_receive_buf);
				pak_645.proto = PROTO_DL1997;
			}
			else if(ParaMeter[mid].proto == PROTO_DL2007_376_1)
			{
				point_read_receive_len = point_read(0x00010000,(unsigned char *)&ParaMeter[mid].addr[0],point_read_receive_buf);
				pak_645.proto = PROTO_DL2007;
			}
			PrintLog(0, "ReadPlMdbCurrent4\n");
			//point_read_receive_len = point_read(0x9010,(unsigned char *)&ParaMeter[mid].addr[0],point_read_receive_buf);
			if(point_read_receive_len>0)	
			{
				printf("point_read_receive_len = %d\n",point_read_receive_len);
				printf("point_read_receive_buf = ");
				for(i=0;i<point_read_receive_len;i++)
					printf("%02X ",point_read_receive_buf[i]);
				printf("\n");
				PrintLog(0, "ReadPlMdbCurrent4\n");
				if(check_rcv_frame(point_read_receive_buf,point_read_receive_len) == 1)
				{
					printf("rcv_point_read_report_data...1\n");
					memset((unsigned char *)&pak.head,0x00,sizeof(pak));
					memset((unsigned char *)pak_645.meter_index,0x00,sizeof(pak_645));
					memcpy((unsigned char *)&pak.head,point_read_receive_buf,point_read_receive_len);
					if(pak.afn == 0x13 && pak.fn[0] == 0x01 && pak.fn[1] == 0x00)	
					{
						printf("rcv_point_read_report_data...2\n");
						memset(meter_addr_tmp,0x00,6);
						memset(ene_buf,0x00,20);
						//pak_645.proto = PROTO_DL1997;
						pak_645.len = pak.data[1];
						meter_postion = process_rcv_645_pak((unsigned char *)pak.data,pak_645.len,meter_addr_tmp,ene_buf);
						printf("meter_postion = %d\n",meter_postion);
						printf("rcv_point_read_report_data...3\n");
						//if(meter_postion>=8)
						//if(meter_postion>=2)	
						//if(process_rcv_645_pak((unsigned char *)pak.data,pak_645.len,pak_645.proto,meter_addr_tmp,ene_buf) == 1)
						//{
							//for(i=0; i<4; i++) ene_buf[i] = databuf[i];
							printf("rcv_point_read_report_data...4\n");
							for(i=0; i<4; i++) 
							{
								databuf[i] = ene_buf[i];
								PrintLog(0, "ene_buf[%d] = %x\n",i,ene_buf[i]);
							}
							PrintLog(0, "retry = %x\n",retry);
							break;
						//}
					}
				}
			}
		}
		if(retry >= RETRY_TIMES) 
		{
			sysclock_t clock2;

			if(PLTIME_EMTPY == PlMdbDay[mid-PLC_BASEMETP].readtime) return -2;

			SysClockReadCurrent(&clock);
			ReadTimeToClock(&clock, PlMdbDay[mid-PLC_BASEMETP].readtime, 0, &clock2);
			buf[0] = clock2.minute;
			buf[1] = clock2.hour;
			buf[2] = clock2.day;
			buf[3] = clock2.month;
			buf[4] = clock2.year;
			HexToBcd(buf, 5);
			buf[5] = 0;//费率数
			buf[6] = 0;
			for(i=0; i<4; i++) buf[i+7] = PlMdbDay[mid-PLC_BASEMETP].meter_ene[i];
		}
		else 
		{
			SysClockReadCurrent(&clock);
			buf[0] = clock.minute;
			buf[1] = clock.hour;
			buf[2] = clock.day;
			buf[3] = clock.month;
			buf[4] = clock.year;
			HexToBcd(buf, 5);
			buf[5] = 0;//费率数
			buf[6] = 0;
			for(i=0; i<4; i++) buf[i+7] = databuf[i];
		}

		return 11;
		break;

	case 0x1101: //F137
		//@change later 多费率, 重读
		if(len < 11) return -1;
		if(PlcRead(&dest, 0x9410, databuf, 4) <= 0) {
			sysclock_t clock2;

			if(PLTIME_EMTPY == PlMdbMonth[mid-PLC_BASEMETP].readtime) return -2;

			SysClockReadCurrent(&clock);
			ReadTimeToClock(&clock, PlMdbMonth[mid-PLC_BASEMETP].readtime, 1, &clock2);
			buf[0] = clock2.minute;
			buf[1] = clock2.hour;
			buf[2] = clock2.day;
			buf[3] = clock2.month;
			buf[4] = clock2.year;
			HexToBcd(buf, 5);
			buf[5] = 0;
			buf[6] = 0;
			for(i=0; i<4; i++) buf[i+7] = PlMdbMonth[mid-PLC_BASEMETP].ene[i];
		}
		else {
			SysClockReadCurrent(&clock);
			buf[0] = clock.minute;
			buf[1] = clock.hour;
			buf[2] = clock.day;
			buf[3] = clock.month;
			buf[4] = clock.year;
			HexToBcd(buf, 5);
			buf[5] = 0;
			buf[6] = 0;
			for(i=0; i<4; i++) buf[i+7] = databuf[i];
		}

		return 11;
		break;

	default: return -2;
	}

	return -2;
}
Exemplo n.º 18
0
VOID
EnableS5WakeOnRtc()
{
  UINT8             CmosData;
  UINTN             i;
  EFI_STATUS        Status;
  UINTN             VarSize;

  //
  // make sure EFI_SMM_VARIABLE_PROTOCOL is available
  //
  if (!mSmmVariable) {
    return;
  }

  VarSize = sizeof(SYSTEM_CONFIGURATION);

  //
  // read the variable into the buffer
  //
  Status = mSmmVariable->SmmGetVariable(
                           L"Setup",
                           &gEfiSetupVariableGuid,
                           NULL,
                           &VarSize,
                           &mSystemConfiguration
                           );
  if (EFI_ERROR(Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {
    //The setup variable is corrupted
    VarSize = sizeof(SYSTEM_CONFIGURATION);
    Status = mSmmVariable->SmmGetVariable(
              L"SetupRecovery",
              &gEfiSetupVariableGuid,
              NULL,
              &VarSize,
              &mSystemConfiguration
              );
    ASSERT_EFI_ERROR (Status);
  }

  if (!mSystemConfiguration.WakeOnRtcS5) {
    return;
  }
  mWakeupDay = HexToBcd((UINT8)mSystemConfiguration.RTCWakeupDate);
  mWakeupHour = HexToBcd((UINT8)mSystemConfiguration.RTCWakeupTimeHour);
  mWakeupMinute = HexToBcd((UINT8)mSystemConfiguration.RTCWakeupTimeMinute);
  mWakeupSecond = HexToBcd((UINT8)mSystemConfiguration.RTCWakeupTimeSecond);

  //
  // Check RTC alarm interrupt is enabled.  If enabled, someone already
  // grabbed RTC alarm.  Just return.
  //
  IoWrite8(PCAT_RTC_ADDRESS_REGISTER, RTC_ADDRESS_REGISTER_B);
  if(IoRead8(PCAT_RTC_DATA_REGISTER) & B_RTC_ALARM_INT_ENABLE){
    return;
  }

  //
  // Set Date
  //
  IoWrite8(PCAT_RTC_ADDRESS_REGISTER, RTC_ADDRESS_REGISTER_D);
  CmosData = IoRead8(PCAT_RTC_DATA_REGISTER);
  CmosData &= ~(B_RTC_DATE_ALARM_MASK);
  CmosData |= mWakeupDay ;
  for(i = 0 ; i < 0xffff ; i++){
    IoWrite8(PCAT_RTC_DATA_REGISTER, CmosData);
    SmmStall(1);
    if(((CmosData = IoRead8(PCAT_RTC_DATA_REGISTER)) & B_RTC_DATE_ALARM_MASK)
         == mWakeupDay){
      break;
    }
  }

  //
  // Set Second
  //
  IoWrite8(PCAT_RTC_ADDRESS_REGISTER, RTC_ADDRESS_SECOND_ALARM);
  for(i = 0 ; i < 0xffff ; i++){
    IoWrite8(PCAT_RTC_DATA_REGISTER, mWakeupSecond);
    SmmStall(1);
    if(IoRead8(PCAT_RTC_DATA_REGISTER) == mWakeupSecond){
      break;
    }
  }

  //
  // Set Minute
  //
  IoWrite8(PCAT_RTC_ADDRESS_REGISTER, RTC_ADDRESS_MINUTE_ALARM);
  for(i = 0 ; i < 0xffff ; i++){
    IoWrite8(PCAT_RTC_DATA_REGISTER, mWakeupMinute);
    SmmStall(1);
    if(IoRead8(PCAT_RTC_DATA_REGISTER) == mWakeupMinute){
      break;
    }
  }

  //
  // Set Hour
  //
  IoWrite8(PCAT_RTC_ADDRESS_REGISTER, RTC_ADDRESS_HOUR_ALARM);
  for(i = 0 ; i < 0xffff ; i++){
    IoWrite8(PCAT_RTC_DATA_REGISTER, mWakeupHour);
    SmmStall(1);
    if(IoRead8(PCAT_RTC_DATA_REGISTER) == mWakeupHour){
      break;
    }
  }

  //
  // Wait for UIP to arm RTC alarm
  //
  IoWrite8(PCAT_RTC_ADDRESS_REGISTER, RTC_ADDRESS_REGISTER_A);
  while (IoRead8(PCAT_RTC_DATA_REGISTER) & 0x80);

  //
  // Read RTC register 0C to clear pending RTC interrupts
  //
  IoWrite8(PCAT_RTC_ADDRESS_REGISTER, RTC_ADDRESS_REGISTER_C);
  IoRead8(PCAT_RTC_DATA_REGISTER);

  //
  // Enable RTC Alarm Interrupt
  //
  IoWrite8(PCAT_RTC_ADDRESS_REGISTER, RTC_ADDRESS_REGISTER_B);
  IoWrite8(PCAT_RTC_DATA_REGISTER, IoRead8(PCAT_RTC_DATA_REGISTER) | B_RTC_ALARM_INT_ENABLE);

  //
  // Clear ICH RTC Status
  //
  IoWrite16(mAcpiBaseAddr + R_PCH_ACPI_PM1_STS, B_PCH_ACPI_PM1_STS_RTC);

  //
  // Enable ICH RTC event
  //
  IoWrite16(mAcpiBaseAddr + R_PCH_ACPI_PM1_EN,
              (UINT16)(IoRead16(mAcpiBaseAddr + R_PCH_ACPI_PM1_EN) | B_PCH_ACPI_PM1_EN_RTC));
}
Exemplo n.º 19
0
uint8 TIME_AddDate(uint8 *pDate, uint8 date) //日增量
{
    uint8 year1;
    uint8 month1;
    uint8 day1;
    uint8 days[13];


    year1 = BcdToHex(pDate[5]);
    month1 = BcdToHex(pDate[4]);
    day1 = BcdToHex(pDate[3]);

    days[0] = 0;
    days[1] = 31;
    days[2] = 28;
    days[3] = 31;
    days[4] = 30;
    days[5] = 31;
    days[6] = 30;
    days[7] = 31;
    days[8] = 31;
    days[9] = 30;
    days[10] = 31;
    days[11] = 30;
    days[12] = 31;

    if( (!IsLeap(year1) || month1 != 2))
    {
        if ((day1 + date) <= days[month1] )
        {
            pDate[3] = HexToBcd(day1 + date);
            pDate[4] = HexToBcd(month1);
            pDate[5] = HexToBcd(year1);
        }
        else
        {
            pDate[3] = HexToBcd(day1 + date - days[month1]);
            if (month1 == 12)
            {
                pDate[5] = HexToBcd(year1 + 1);
                pDate[4] = 1;
            }
            else
            {
                pDate[5] = HexToBcd(year1);
                pDate[4] = HexToBcd(month1 + 1);
            }
        }

    }
    else
    {
        if ((day1 + date) < 29)
        {
            pDate[3] = HexToBcd(day1 + date);
            pDate[4] = 2;
            pDate[5] = HexToBcd(year1);
        }
        else
        {
            pDate[3] = HexToBcd(day1 + date - 29);
            pDate[4] = 3;
            pDate[5] = HexToBcd(year1);
        }
    }
    return 0;
}