Ejemplo n.º 1
0
 /// returns finite element. 
 const FiniteElement & GetFE (ElementId ei, LocalHeap & lh) const
 {
   return ei.IsBoundary() ? GetSFE(ei.Nr(), lh) : GetFE(ei.Nr(), lh);
 }
Ejemplo n.º 2
0
/***********************************************************
函数名称:Uart_Order_Pro()
函数功能:UART命令处理
入口参数:
出口参数:
备 	  注:1 帧格式检查;
		  2 命令处理;
***********************************************************/
uint8 DLT645Main(COM_TYPEDEF com)
{
    uint8 *pBuf;
    uint16 Len = 0;
    uint8 BUFFER1[6],BUFFER2[6],Address[6];

    Len = ProtocolDataRec(com, &pBuf);
    if(Len != 0)
    {
        uart_buff=(struct uart_buff_type *)(pBuf+GetFE(pBuf));		//丢弃0xFE
        if(Uart_Frame_Chk(uart_buff->Buffer))							//帧格式检查
        {
            MeterInfoParaGet(0x01020002, BUFFER2);
            Address_Change(Address,BUFFER2);
            Uart_Sub_33();
            uart_err.byte = 0x00;
            if((uart_buff->Buffer[1] == 0xaa)
                    && (uart_buff->Buffer[2] == 0xaa)
                    && (uart_buff->Buffer[3] == 0xaa)
                    && (uart_buff->Buffer[4] == 0xaa)
                    && (uart_buff->Buffer[5] == 0xaa)
                    && (uart_buff->Buffer[6] == 0xaa))
            {
                if((uart_buff->Buffer[8] == 0x13) && (uart_buff->Buffer[9] == 0x00))		//广播读地址
                {
                    Broadcast_Read_Addr(Address);
                }
                else if((uart_buff->Buffer[8] == 0x15) && (uart_buff->Buffer[9] == 0x06))
                {
                    Address_Change(BUFFER1,&uart_buff->Buffer[10]);
                    if(0 == MeterInfoParaSet(0x01020002, BUFFER1, 6))
                    {
                        Broadcast_write_Addr(BUFFER1);
                        //=======================================
                        //清电能及密码
                        BillingParaSet(0x09050081, NULL, 0);
                        PassWordSetDefault();
                        DisplayAlarm(DIS_ALARM_CLEAR_OK,TRUE);//显示OK
                        //=======================================
                    }
                    else
                    {
                        uart_err.byte=0xff; 				//0xff无需应答
                    }
                }
                else if((uart_buff->Buffer[8] == 0x11) && (uart_buff->Buffer[9] == 0x04))	//AA广播读地址
                {
                    if((uart_buff->Buffer[10] == 0x01)&&(uart_buff->Buffer[11] == 0x04)&&(uart_buff->Buffer[12] == 0x00)&&(uart_buff->Buffer[13] == 0x04))
                    {
                        AA_Read_Addr(Address);
                    }
                    else if((uart_buff->Buffer[10] == 0x02)&&(uart_buff->Buffer[11] == 0x04)&&(uart_buff->Buffer[12] == 0x00)&&(uart_buff->Buffer[13] == 0x04))
                    {
                        AA_Read_Meter_No();
                    }
                    else
                    {
                        uart_err.byte=0xff; 				//0xff无需应答
                    }
                }
                //-------- used for calibrate meter ----------
                else if(uart_buff->Buffer[8] == 0x11)//read data
                {
                    if((uart_buff->Buffer[13]==0xe0)||(uart_buff->Buffer[13]==0xe1)||(uart_buff->Buffer[13]==0x02))//calibrate meter
                    {
                        Drv_Calibrate_DLT6452007(0);
                    }
                }
                else if(uart_buff->Buffer[8] == 0x14)//write data
                {
                    if((uart_buff->Buffer[13]==0xe0)||(uart_buff->Buffer[13]==0xe1))//calibrate meter
                    {
                        Drv_Calibrate_DLT6452007(1);
                    }
                }
                else
                {
                    uart_err.byte=0xff; 			                //0xff无需应答.
                }
            }
            else if((uart_buff->Buffer[1] == 0x00)
                    && (uart_buff->Buffer[2] == 0x00)
                    && (uart_buff->Buffer[3] == 0x00)
                    && (uart_buff->Buffer[4] == 0x00)
                    && (uart_buff->Buffer[5] == 0x00)
                    && (uart_buff->Buffer[6] == 0x00))
            {
                //-------- used for calibrate meter ----------
                if(uart_buff->Buffer[8] == 0x11)//read data
                {
                    if((uart_buff->Buffer[13]==0xe0)||(uart_buff->Buffer[13]==0xe1)||(uart_buff->Buffer[13]==0x02))//calibrate meter
                    {
                        Drv_Calibrate_DLT6452007(0);
                    }
                }
                else if(uart_buff->Buffer[8] == 0x14)//write data
                {
                    if((uart_buff->Buffer[13]==0xe0)||(uart_buff->Buffer[13]==0xe1))//calibrate meter
                    {
                        Drv_Calibrate_DLT6452007(1);
                    }
                }
                //--------------end----------------------
                else
                {
                    uart_err.byte=0xff; 			                        //0xff无需应答.
                }
            }
            else if(memcmp(&uart_buff->Buffer[1],Address,6) == 0)
            {
                //-------- used for calibrate meter ----------
                if(uart_buff->Buffer[8] == 0x11)//read data
                {
                    if((uart_buff->Buffer[13]==0xe0)||(uart_buff->Buffer[13]==0xe1)||(uart_buff->Buffer[13]==0x02))//calibrate meter
                    {
                        Drv_Calibrate_DLT6452007(0);
                    }
                }
                else if(uart_buff->Buffer[8] == 0x14)//write data
                {
                    if((uart_buff->Buffer[13]==0xe0)||(uart_buff->Buffer[13]==0xe1))//calibrate meter
                    {
                        Drv_Calibrate_DLT6452007(1);
                    }
                }
                //--------------end----------------------
                else
                {
                    uart_err.byte=0xff; 				//0xff无需应答
                }
            }
            else
            {
                uart_err.byte=0xff; 			                        //0xff无需应答.
            }
        }
        else
        {
            uart_err.byte=0xff; 			                                //0xff无需应答.
        }

        if(uart_err.byte == 0xff)
        {   //不是645协义,不处理数据
            //			LDRV_CommRxEnable(com);
            return 0;
        }
        else
        {
            if(uart_err.byte == 0x00)			                        //正常应答
            {
                uart_buff->Buffer[8]|=0x80;		                        //从站正常应答命令
            }
            else	//异常应答
            {
                if(uart_buff->Buffer[8]==0x03)
                {   //安全认证命令异常应答
                    uart_buff->Buffer[8]|=0xc0;//cmd
                    uart_buff->Buffer[9]=2;//leng
                    uart_buff->Buffer[10]=uart_err.byte;//data
                    uart_buff->Buffer[11]=0x00;//data
                }
                else
                {
                    uart_buff->Buffer[8]|=0xc0;		//从站正常应答命令
                    uart_buff->Buffer[9]=1;//leng
                    uart_buff->Buffer[10]=uart_err.byte;//data
                }
            }
        }
        Uart_Tran_Frame();
        LDRV_UsartSend(com,(uint8 *)pBuf, uart_buff->Buffer[9]+12+GetFE(pBuf));	//应答是否要FE???
        return 1;
    }
    return 0;
}