sv: add support for decoding smpMod, smpRate and datSet attributes in ASDUs

pull/39/head
Steffen Vogel 8 years ago
parent 10f0d84349
commit f407c6e6ca

@ -70,20 +70,20 @@ struct sSVSubscriber {
struct sSVSubscriber_ASDU { struct sSVSubscriber_ASDU {
char* svId; char* svId;
char* datSet;
uint8_t* smpCnt; uint8_t* smpCnt;
uint8_t* confRev; uint8_t* confRev;
uint8_t* refrTm; uint8_t* refrTm;
uint8_t* smpSynch; uint8_t* smpSynch;
uint8_t* smpMod;
uint8_t* smpRate;
int dataBufferLength; int dataBufferLength;
uint8_t* dataBuffer; uint8_t* dataBuffer;
}; };
SVReceiver SVReceiver
SVReceiver_create(void) SVReceiver_create(void)
{ {
@ -236,6 +236,7 @@ parseASDU(SVReceiver self, SVSubscriber subscriber, uint8_t* buffer, int length)
{ {
int bufPos = 0; int bufPos = 0;
int svIdLength = 0; int svIdLength = 0;
int datSetLength = 0;
struct sSVSubscriber_ASDU asdu; struct sSVSubscriber_ASDU asdu;
memset(&asdu, 0, sizeof(struct sSVSubscriber_ASDU)); memset(&asdu, 0, sizeof(struct sSVSubscriber_ASDU));
@ -258,6 +259,11 @@ parseASDU(SVReceiver self, SVSubscriber subscriber, uint8_t* buffer, int length)
svIdLength = elementLength; svIdLength = elementLength;
break; break;
case 0x81:
asdu.datSet = (char*) (buffer + bufPos);
datSetLength = elementLength;
break;
case 0x82: case 0x82:
asdu.smpCnt = buffer + bufPos; asdu.smpCnt = buffer + bufPos;
break; break;
@ -274,11 +280,19 @@ parseASDU(SVReceiver self, SVSubscriber subscriber, uint8_t* buffer, int length)
asdu.smpSynch = buffer + bufPos; asdu.smpSynch = buffer + bufPos;
break; break;
case 0x86:
asdu.smpRate = buffer + bufPos;
break;
case 0x87: case 0x87:
asdu.dataBuffer = buffer + bufPos; asdu.dataBuffer = buffer + bufPos;
asdu.dataBufferLength = elementLength; asdu.dataBufferLength = elementLength;
break; break;
case 0x88:
asdu.smpMod = buffer + bufPos;
break;
default: /* ignore unknown tag */ default: /* ignore unknown tag */
break; break;
} }
@ -288,6 +302,8 @@ parseASDU(SVReceiver self, SVSubscriber subscriber, uint8_t* buffer, int length)
if (asdu.svId != NULL) if (asdu.svId != NULL)
asdu.svId[svIdLength] = 0; asdu.svId[svIdLength] = 0;
if (asdu.datSet != NULL)
asdu.datSet[datSetLength] = 0;
/* Call callback handler */ /* Call callback handler */
if (subscriber->listener != NULL) if (subscriber->listener != NULL)
@ -595,6 +611,23 @@ SVSubscriber_ASDU_hasRefrTm(SVSubscriber_ASDU self)
return (self->refrTm != NULL); return (self->refrTm != NULL);
} }
bool
SVSubscriber_ASDU_hasDatSet(SVSubscriber_ASDU self)
{
return (self->datSet != NULL);
}
bool
SVSubscriber_ASDU_hasSmpRate(SVSubscriber_ASDU self)
{
return (self->smpRate != NULL);
}
bool
SVSubscriber_ASDU_hasSmpMod(SVSubscriber_ASDU self)
{
return (self->smpMod != NULL);
}
const char* const char*
SVSubscriber_ASDU_getSvId(SVSubscriber_ASDU self) SVSubscriber_ASDU_getSvId(SVSubscriber_ASDU self)
@ -602,6 +635,12 @@ SVSubscriber_ASDU_getSvId(SVSubscriber_ASDU self)
return self->svId; return self->svId;
} }
const char*
SVSubscriber_ASDU_getDatSet(SVSubscriber_ASDU self)
{
return self->datSet;
}
uint32_t uint32_t
SVSubscriber_ASDU_getConfRev(SVSubscriber_ASDU self) SVSubscriber_ASDU_getConfRev(SVSubscriber_ASDU self)
{ {
@ -616,6 +655,28 @@ SVSubscriber_ASDU_getConfRev(SVSubscriber_ASDU self)
return retVal; return retVal;
} }
uint8_t
SVSubscriber_ASDU_getSmpMod(SVSubscriber_ASDU self)
{
uint8_t retVal = *((uint8_t*) (self->smpMod));
return retVal;
}
uint16_t
SVSubscriber_ASDU_getSmpRate(SVSubscriber_ASDU self)
{
uint16_t retVal = *((uint16_t*) (self->smpRate));
#if (ORDER_LITTLE_ENDIAN == 1)
uint8_t* buf = (uint8_t*) (&retVal);
BerEncoder_revertByteOrder(buf, 2);
#endif
return retVal;
}
int8_t int8_t
SVSubscriber_ASDU_getINT8(SVSubscriber_ASDU self, int index) SVSubscriber_ASDU_getINT8(SVSubscriber_ASDU self, int index)
{ {

@ -277,6 +277,14 @@ SVSubscriber_ASDU_getSmpCnt(SVSubscriber_ASDU self);
const char* const char*
SVSubscriber_ASDU_getSvId(SVSubscriber_ASDU self); SVSubscriber_ASDU_getSvId(SVSubscriber_ASDU self);
/**
* \brief return the DatSet value included in the SV ASDU
*
* \param self ASDU object instance
*/
const char*
SVSubscriber_ASDU_getDatSet(SVSubscriber_ASDU self);
/** /**
* \brief return the ConfRev value included in the SV ASDU * \brief return the ConfRev value included in the SV ASDU
* *
@ -285,6 +293,32 @@ SVSubscriber_ASDU_getSvId(SVSubscriber_ASDU self);
uint32_t uint32_t
SVSubscriber_ASDU_getConfRev(SVSubscriber_ASDU self); SVSubscriber_ASDU_getConfRev(SVSubscriber_ASDU self);
/**
* \brief return the SmpMod value included in the SV ASDU
*
* \param self ASDU object instance
*/
uint8_t
SVSubscriber_ASDU_getSmpMod(SVSubscriber_ASDU self);
/**
* \brief return the SmpRate value included in the SV ASDU
*
* \param self ASDU object instance
*/
uint16_t
SVSubscriber_ASDU_getSmpRate(SVSubscriber_ASDU self);
/**
* \brief Check if DatSet value is included in the SV ASDU
*
* \param self ASDU object instance
*
* \return true if DatSet value is present, false otherwise
*/
bool
SVSubscriber_ASDU_hasDatSet(SVSubscriber_ASDU self);
/** /**
* \brief Check if RefrTm value is included in the SV ASDU * \brief Check if RefrTm value is included in the SV ASDU
* *
@ -295,6 +329,26 @@ SVSubscriber_ASDU_getConfRev(SVSubscriber_ASDU self);
bool bool
SVSubscriber_ASDU_hasRefrTm(SVSubscriber_ASDU self); SVSubscriber_ASDU_hasRefrTm(SVSubscriber_ASDU self);
/**
* \brief Check if SmpMod value is included in the SV ASDU
*
* \param self ASDU object instance
*
* \return true if SmpMod value is present, false otherwise
*/
bool
SVSubscriber_ASDU_hasSmpMod(SVSubscriber_ASDU self);
/**
* \brief Check if SmpRate value is included in the SV ASDU
*
* \param self ASDU object instance
*
* \return true if SmpRate value is present, false otherwise
*/
bool
SVSubscriber_ASDU_hasSmpRate(SVSubscriber_ASDU self);
/** /**
* \brief Get the RefrTim value included in SV ASDU as ms timestamp * \brief Get the RefrTim value included in SV ASDU as ms timestamp
* *

Loading…
Cancel
Save