- fixed bug with setting groups
This commit is contained in:
parent
a6652dc643
commit
66da568bea
11 changed files with 100 additions and 34 deletions
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "mms_value.h"
|
#include "mms_value.h"
|
||||||
#include "goose_publisher.h"
|
#include "goose_publisher.h"
|
||||||
|
#include "hal_thread.h"
|
||||||
|
|
||||||
// has to be executed as root!
|
// has to be executed as root!
|
||||||
int
|
int
|
||||||
|
@ -44,7 +45,7 @@ main(int argc, char** argv)
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
sleep(1);
|
Thread_sleep(1000);
|
||||||
|
|
||||||
if (GoosePublisher_publish(publisher, dataSetValues) == -1) {
|
if (GoosePublisher_publish(publisher, dataSetValues) == -1) {
|
||||||
printf("Error sending message!\n");
|
printf("Error sending message!\n");
|
||||||
|
|
|
@ -28,9 +28,12 @@
|
||||||
static int
|
static int
|
||||||
encodeArrayAccessResult(MmsValue* value, uint8_t* buffer, int bufPos, bool encode)
|
encodeArrayAccessResult(MmsValue* value, uint8_t* buffer, int bufPos, bool encode)
|
||||||
{
|
{
|
||||||
int elementsSize = 0;
|
if (value == NULL) // TODO report internal error
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int elementsSize = 0;
|
||||||
int i;
|
int i;
|
||||||
|
int size;
|
||||||
|
|
||||||
int arraySize = MmsValue_getArraySize(value);
|
int arraySize = MmsValue_getArraySize(value);
|
||||||
|
|
||||||
|
@ -50,21 +53,24 @@ encodeArrayAccessResult(MmsValue* value, uint8_t* buffer, int bufPos, bool encod
|
||||||
bufPos = mmsServer_encodeAccessResult(element, buffer, bufPos, true);
|
bufPos = mmsServer_encodeAccessResult(element, buffer, bufPos, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bufPos;
|
size = bufPos;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int size = 1 + elementsSize + BerEncoder_determineLengthSize(elementsSize);
|
size = 1 + elementsSize + BerEncoder_determineLengthSize(elementsSize);
|
||||||
|
}
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
encodeStructuredAccessResult(MmsValue* value, uint8_t* buffer, int bufPos, bool encode)
|
encodeStructuredAccessResult(MmsValue* value, uint8_t* buffer, int bufPos, bool encode)
|
||||||
{
|
{
|
||||||
int componentsSize = 0;
|
if (value == NULL) // TODO report internal error
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int componentsSize = 0;
|
||||||
int i;
|
int i;
|
||||||
|
int size;
|
||||||
|
|
||||||
int components = value->value.structure.size;
|
int components = value->value.structure.size;
|
||||||
|
|
||||||
|
@ -84,18 +90,21 @@ encodeStructuredAccessResult(MmsValue* value, uint8_t* buffer, int bufPos, bool
|
||||||
bufPos = mmsServer_encodeAccessResult(component, buffer, bufPos, true);
|
bufPos = mmsServer_encodeAccessResult(component, buffer, bufPos, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bufPos;
|
size = bufPos;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int size = 1 + componentsSize + BerEncoder_determineLengthSize(componentsSize);
|
size = 1 + componentsSize + BerEncoder_determineLengthSize(componentsSize);
|
||||||
|
}
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
mmsServer_encodeAccessResult(MmsValue* value, uint8_t* buffer, int bufPos, bool encode)
|
mmsServer_encodeAccessResult(MmsValue* value, uint8_t* buffer, int bufPos, bool encode)
|
||||||
{
|
{
|
||||||
|
if (value == NULL) // TODO report internal error
|
||||||
|
return 0;
|
||||||
|
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
switch (value->type) {
|
switch (value->type) {
|
||||||
|
|
|
@ -69,16 +69,22 @@ addNamedVariableValue(MmsVariableSpecification* namedVariable, MmsServerConnecti
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < componentCount; i++) {
|
for (i = 0; i < componentCount; i++) {
|
||||||
char* newNameIdStr = createString(3, itemId, "$",
|
char newNameIdStr[65];
|
||||||
|
|
||||||
|
createStringInBuffer(newNameIdStr, 3, itemId, "$",
|
||||||
namedVariable->typeSpec.structure.elements[i]->name);
|
namedVariable->typeSpec.structure.elements[i]->name);
|
||||||
|
|
||||||
MmsValue* element =
|
MmsValue* element =
|
||||||
addNamedVariableValue(namedVariable->typeSpec.structure.elements[i],
|
addNamedVariableValue(namedVariable->typeSpec.structure.elements[i],
|
||||||
connection, domain, newNameIdStr);
|
connection, domain, newNameIdStr);
|
||||||
|
|
||||||
MmsValue_setElement(value, i, element);
|
if (element == NULL) {
|
||||||
|
MmsValue_delete(value);
|
||||||
|
value = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
GLOBAL_FREEMEM(newNameIdStr);
|
MmsValue_setElement(value, i, element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,9 +151,8 @@ MmsServer_getValueFromCache(MmsServer self, MmsDomain* domain, char* itemId)
|
||||||
{
|
{
|
||||||
MmsValueCache cache = (MmsValueCache) Map_getEntry(self->valueCaches, domain);
|
MmsValueCache cache = (MmsValueCache) Map_getEntry(self->valueCaches, domain);
|
||||||
|
|
||||||
if (cache != NULL) {
|
if (cache != NULL)
|
||||||
return MmsValueCache_lookupValue(cache, itemId);
|
return MmsValueCache_lookupValue(cache, itemId);
|
||||||
}
|
|
||||||
|
|
||||||
return NULL ;
|
return NULL ;
|
||||||
}
|
}
|
||||||
|
@ -205,8 +204,11 @@ mmsServer_getValue(MmsServer self, MmsDomain* domain, char* itemId, MmsServerCon
|
||||||
MmsDataAccessError accessError =
|
MmsDataAccessError accessError =
|
||||||
self->readAccessHandler(self->readAccessHandlerParameter, domain, itemId, connection);
|
self->readAccessHandler(self->readAccessHandlerParameter, domain, itemId, connection);
|
||||||
|
|
||||||
if (accessError != DATA_ACCESS_ERROR_SUCCESS)
|
if (accessError != DATA_ACCESS_ERROR_SUCCESS) {
|
||||||
return NULL;
|
value = MmsValue_newDataAccessError(accessError);
|
||||||
|
MmsValue_setDeletable(value);
|
||||||
|
goto exit_function;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
value = MmsServer_getValueFromCache(self, domain, itemId);
|
value = MmsServer_getValueFromCache(self, domain, itemId);
|
||||||
|
@ -216,6 +218,7 @@ mmsServer_getValue(MmsServer self, MmsDomain* domain, char* itemId, MmsServerCon
|
||||||
value = self->readHandler(self->readHandlerParameter, domain,
|
value = self->readHandler(self->readHandlerParameter, domain,
|
||||||
itemId, connection);
|
itemId, connection);
|
||||||
|
|
||||||
|
exit_function:
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -130,21 +130,20 @@ IsoConnection_addHandleSet(const IsoConnection self, HandleSet handles)
|
||||||
void
|
void
|
||||||
IsoConnection_handleTcpConnection(IsoConnection self)
|
IsoConnection_handleTcpConnection(IsoConnection self)
|
||||||
{
|
{
|
||||||
assert(self->msgRcvdHandler != NULL);
|
|
||||||
|
|
||||||
TpktState tpktState = CotpConnection_readToTpktBuffer(self->cotpConnection);
|
TpktState tpktState = CotpConnection_readToTpktBuffer(self->cotpConnection);
|
||||||
|
|
||||||
if (tpktState == TPKT_ERROR)
|
if (tpktState == TPKT_ERROR)
|
||||||
self->state = ISO_CON_STATE_STOPPED;
|
self->state = ISO_CON_STATE_STOPPED;
|
||||||
|
|
||||||
if (tpktState != TPKT_PACKET_COMPLETE)
|
if (tpktState != TPKT_PACKET_COMPLETE)
|
||||||
return;
|
goto exit_function;
|
||||||
|
|
||||||
CotpIndication cotpIndication = CotpConnection_parseIncomingMessage(self->cotpConnection);
|
CotpIndication cotpIndication = CotpConnection_parseIncomingMessage(self->cotpConnection);
|
||||||
|
|
||||||
switch (cotpIndication) {
|
switch (cotpIndication) {
|
||||||
case COTP_MORE_FRAGMENTS_FOLLOW:
|
case COTP_MORE_FRAGMENTS_FOLLOW:
|
||||||
return;
|
goto exit_function;
|
||||||
|
|
||||||
case COTP_CONNECT_INDICATION:
|
case COTP_CONNECT_INDICATION:
|
||||||
if (DEBUG_ISO_SERVER)
|
if (DEBUG_ISO_SERVER)
|
||||||
printf("ISO_SERVER: COTP connection indication\n");
|
printf("ISO_SERVER: COTP connection indication\n");
|
||||||
|
@ -418,6 +417,9 @@ IsoConnection_handleTcpConnection(IsoConnection self)
|
||||||
self->state = ISO_CON_STATE_STOPPED;
|
self->state = ISO_CON_STATE_STOPPED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exit_function:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (CONFIG_MMS_SINGLE_THREADED == 0)
|
#if (CONFIG_MMS_SINGLE_THREADED == 0)
|
||||||
|
@ -509,7 +511,7 @@ IsoConnection_sendMessage(IsoConnection self, ByteBuffer* message, bool handlerM
|
||||||
if (self->state == ISO_CON_STATE_STOPPED) {
|
if (self->state == ISO_CON_STATE_STOPPED) {
|
||||||
if (DEBUG_ISO_SERVER)
|
if (DEBUG_ISO_SERVER)
|
||||||
printf("DEBUG_ISO_SERVER: sendMessage: connection already stopped!\n");
|
printf("DEBUG_ISO_SERVER: sendMessage: connection already stopped!\n");
|
||||||
return;
|
goto exit_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
||||||
|
@ -554,6 +556,9 @@ IsoConnection_sendMessage(IsoConnection self, ByteBuffer* message, bool handlerM
|
||||||
if (self->isInsideCallback == false)
|
if (self->isInsideCallback == false)
|
||||||
Semaphore_post(self->conMutex);
|
Semaphore_post(self->conMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
exit_error:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -109,15 +109,10 @@ public class DataAttributeDefinition {
|
||||||
|
|
||||||
String value = elementNode.getTextContent();
|
String value = elementNode.getTextContent();
|
||||||
|
|
||||||
if (attributeType != AttributeType.ENUMERATED)
|
if (attributeType != AttributeType.ENUMERATED) {
|
||||||
try {
|
this.value = new DataModelValue(attributeType, this.type, value);
|
||||||
this.value = new DataModelValue(attributeType, null, value);
|
|
||||||
} catch (IllegalValueException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,18 @@ package com.libiec61850.scl.model;
|
||||||
import com.libiec61850.scl.types.EnumerationType;
|
import com.libiec61850.scl.types.EnumerationType;
|
||||||
import com.libiec61850.scl.types.IllegalValueException;
|
import com.libiec61850.scl.types.IllegalValueException;
|
||||||
import com.libiec61850.scl.types.SclType;
|
import com.libiec61850.scl.types.SclType;
|
||||||
|
import com.libiec61850.scl.types.TypeDeclarations;
|
||||||
|
|
||||||
public class DataModelValue {
|
public class DataModelValue {
|
||||||
|
|
||||||
private Object value = null;
|
private Object value = null;
|
||||||
|
private String unknownEnumValue = null;
|
||||||
|
private String enumType = null;
|
||||||
|
|
||||||
|
public DataModelValue(AttributeType type, String enumType, String value) {
|
||||||
|
this.unknownEnumValue = value;
|
||||||
|
this.enumType = enumType;
|
||||||
|
}
|
||||||
|
|
||||||
public DataModelValue(AttributeType type, SclType sclType, String value) throws IllegalValueException {
|
public DataModelValue(AttributeType type, SclType sclType, String value) throws IllegalValueException {
|
||||||
|
|
||||||
|
@ -37,6 +45,7 @@ public class DataModelValue {
|
||||||
case ENUMERATED:
|
case ENUMERATED:
|
||||||
EnumerationType enumType = (EnumerationType) sclType;
|
EnumerationType enumType = (EnumerationType) sclType;
|
||||||
this.value = (Object) (new Integer(enumType.getOrdByEnumString(value)));
|
this.value = (Object) (new Integer(enumType.getOrdByEnumString(value)));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case INT8:
|
case INT8:
|
||||||
case INT16:
|
case INT16:
|
||||||
|
@ -95,6 +104,32 @@ public class DataModelValue {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUnknownEnumValue() {
|
||||||
|
return unknownEnumValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateEnumOrdValue(TypeDeclarations typeDecls)
|
||||||
|
{
|
||||||
|
if (enumType != null) {
|
||||||
|
|
||||||
|
System.out.println("Lookup enum type " + enumType);
|
||||||
|
|
||||||
|
SclType sclType = typeDecls.lookupType(enumType);
|
||||||
|
|
||||||
|
if (sclType != null) {
|
||||||
|
|
||||||
|
EnumerationType enumType = (EnumerationType) sclType;
|
||||||
|
try {
|
||||||
|
this.value = (Object) (new Integer(enumType.getOrdByEnumString(unknownEnumValue)));
|
||||||
|
} catch (IllegalValueException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
System.out.println(" failed!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public long getLongValue() {
|
public long getLongValue() {
|
||||||
return (Long) value;
|
return (Long) value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import com.libiec61850.scl.types.TypeDeclarations;
|
||||||
public class IED {
|
public class IED {
|
||||||
private String name;
|
private String name;
|
||||||
private List<AccessPoint> accessPoints;
|
private List<AccessPoint> accessPoints;
|
||||||
|
private TypeDeclarations typeDeclarations;
|
||||||
|
|
||||||
public IED(Node iedNode, TypeDeclarations typeDeclarations)
|
public IED(Node iedNode, TypeDeclarations typeDeclarations)
|
||||||
throws SclParserException {
|
throws SclParserException {
|
||||||
|
@ -48,6 +49,12 @@ public class IED {
|
||||||
for (Node accessPointNode : accessPointNodes) {
|
for (Node accessPointNode : accessPointNodes) {
|
||||||
this.accessPoints.add(new AccessPoint(accessPointNode, typeDeclarations));
|
this.accessPoints.add(new AccessPoint(accessPointNode, typeDeclarations));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.typeDeclarations = typeDeclarations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TypeDeclarations getTypeDeclarations() {
|
||||||
|
return typeDeclarations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
|
@ -284,9 +284,14 @@ public class DynamicModelGenerator {
|
||||||
DataModelValue value = dataAttribute.getValue();
|
DataModelValue value = dataAttribute.getValue();
|
||||||
|
|
||||||
/* if no value is given use default value for type if present */
|
/* if no value is given use default value for type if present */
|
||||||
if (value == null)
|
if (value == null) {
|
||||||
value = dataAttribute.getDefinition().getValue();
|
value = dataAttribute.getDefinition().getValue();
|
||||||
|
|
||||||
|
if (value != null)
|
||||||
|
if (value.getValue() == null)
|
||||||
|
value.updateEnumOrdValue(ied.getTypeDeclarations());
|
||||||
|
}
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
|
|
||||||
switch (dataAttribute.getType()) {
|
switch (dataAttribute.getType()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue