Saturday, March 17, 2012

DLMS Frame Type

How to calculate the DLMS frame type field value ? It is simple just follow the below algorithm.
Easy to integrate in your program just call the below function.



u8 GetFrameTypeValue(u8 CodeType)
{
        // define "g_FrameTypeValue" as global variable and initialize its value to 0.
// u8  g_FrameTypeValue ;


// define " g_PrevLongCode" as global variable and initialize its value to 0.
        // u8  g_PrevLongCode;


if(CodeType == SHORT_CODE)
{
if(g_FrameTypeValue == 0xFE)
{
g_SSS = 1;
}
g_FrameTypeValue = (( g_RRR & 0x07 ) << 5) | 0x11;
}
else if(CodeType == LONG_CODE)
{
if(g_FrameTypeValue == 0xFE)
{
g_FrameTypeValue = 0x10;
g_SSS = 1;
g_RRR = 1;
}
else if( (g_PrevLongCode & 0x0F) == 0x0E )
{
g_FrameTypeValue = ((( g_RRR & 0x07 ) << 5) | 0x10);
g_SSS = 1;
}
else
{
g_FrameTypeValue = ((( g_RRR & 0x07 ) << 5) | 0x11) + g_SSS;         
g_SSS = g_SSS + 2; if(g_SSS > 13) { g_SSS = 1; }
}
g_PrevLongCode = g_FrameTypeValue;
}
else
{
//do nothing
}
if(g_FrameTypeValue != 0x10)
{
g_RRR = g_RRR + 1; if(g_RRR > 7) { g_RRR = 0; }
}
return g_FrameTypeValue;
}