- code format updates

pull/521/head
Michael Zillgith 1 year ago
parent c5ddf0b71f
commit 3772d80c42

@ -129,7 +129,8 @@ int main(int argc, char** argv)
int c; int c;
while ((c = getopt(argc, argv, "mifdh:p:l:t:a:r:g:j:x:v:c:y:z:")) != -1) { while ((c = getopt(argc, argv, "mifdh:p:l:t:a:r:g:j:x:v:c:y:z:")) != -1)
{
switch (c) { switch (c) {
case 'm': case 'm':
printRawMmsMessages = 1; printRawMmsMessages = 1;
@ -212,7 +213,8 @@ int main(int argc, char** argv)
if (printRawMmsMessages) if (printRawMmsMessages)
MmsConnection_setRawMessageHandler(con, (MmsRawMessageHandler) printRawMmsMessage, NULL); MmsConnection_setRawMessageHandler(con, (MmsRawMessageHandler) printRawMmsMessage, NULL);
if (!MmsConnection_connect(con, &error, hostname, tcpPort)) { if (!MmsConnection_connect(con, &error, hostname, tcpPort))
{
printf("MMS connect failed!\n"); printf("MMS connect failed!\n");
if (error != MMS_ERROR_NONE) if (error != MMS_ERROR_NONE)
@ -223,14 +225,16 @@ int main(int argc, char** argv)
else else
printf("MMS connected.\n"); printf("MMS connected.\n");
if (identifyDevice) { if (identifyDevice)
{
MmsServerIdentity* identity = MmsServerIdentity* identity =
MmsConnection_identify(con, &error); MmsConnection_identify(con, &error);
if (error != MMS_ERROR_NONE) if (error != MMS_ERROR_NONE)
returnCode = error; returnCode = error;
if (identity != NULL) { if (identity != NULL)
{
printf("\nServer identity:\n----------------\n"); printf("\nServer identity:\n----------------\n");
printf(" vendor:\t%s\n", identity->vendorName); printf(" vendor:\t%s\n", identity->vendorName);
printf(" model:\t%s\n", identity->modelName); printf(" model:\t%s\n", identity->modelName);
@ -240,32 +244,37 @@ int main(int argc, char** argv)
printf("Reading server identity failed!\n"); printf("Reading server identity failed!\n");
} }
if (readDeviceList) { if (readDeviceList)
{
printf("\nDomains present on server:\n--------------------------\n"); printf("\nDomains present on server:\n--------------------------\n");
LinkedList nameList = MmsConnection_getDomainNames(con, &error); LinkedList nameList = MmsConnection_getDomainNames(con, &error);
if (error != MMS_ERROR_NONE) if (error != MMS_ERROR_NONE)
returnCode = error; returnCode = error;
if (nameList) { if (nameList)
{
LinkedList_printStringList(nameList); LinkedList_printStringList(nameList);
LinkedList_destroy(nameList); LinkedList_destroy(nameList);
} }
} }
if (getDeviceDirectory) { if (getDeviceDirectory)
{
LinkedList variableList = MmsConnection_getDomainVariableNames(con, &error, LinkedList variableList = MmsConnection_getDomainVariableNames(con, &error,
domainName); domainName);
if (error != MMS_ERROR_NONE) if (error != MMS_ERROR_NONE)
returnCode = error; returnCode = error;
if (variableList) { if (variableList)
{
LinkedList element = LinkedList_getNext(variableList); LinkedList element = LinkedList_getNext(variableList);
printf("\nMMS domain variables for domain %s\n", domainName); printf("\nMMS domain variables for domain %s\n", domainName);
while (element != NULL) { while (element != NULL)
{
char* name = (char*) element->data; char* name = (char*) element->data;
printf(" %s\n", name); printf(" %s\n", name);
@ -284,8 +293,8 @@ int main(int argc, char** argv)
if (error != MMS_ERROR_NONE) if (error != MMS_ERROR_NONE)
returnCode = error; returnCode = error;
if (variableList) { if (variableList)
{
LinkedList element = variableList; LinkedList element = variableList;
printf("\nMMS journals for domain %s\n", domainName); printf("\nMMS journals for domain %s\n", domainName);
@ -301,18 +310,17 @@ int main(int argc, char** argv)
else { else {
printf("\nFailed to read domain journals (error=%d)\n", error); printf("\nFailed to read domain journals (error=%d)\n", error);
} }
} }
if (readJournal) { if (readJournal)
{
printf(" read journal %s...\n", journalName); printf(" read journal %s...\n", journalName);
char* logDomain = journalName; char* logDomain = journalName;
char* logName = strchr(journalName, '/'); char* logName = strchr(journalName, '/');
if (logName != NULL) { if (logName != NULL)
{
logName[0] = 0; logName[0] = 0;
logName++; logName++;
@ -335,11 +343,12 @@ int main(int argc, char** argv)
MmsValue_delete(startTime); MmsValue_delete(startTime);
MmsValue_delete(endTime); MmsValue_delete(endTime);
if (journalEntries != NULL) { if (journalEntries != NULL)
{
bool readNext; bool readNext;
do { do
{
readNext = false; readNext = false;
LinkedList lastEntry = LinkedList_getLastElement(journalEntries); LinkedList lastEntry = LinkedList_getLastElement(journalEntries);
@ -353,7 +362,8 @@ int main(int argc, char** argv)
LinkedList_destroyDeep(journalEntries, (LinkedListValueDeleteFunction) LinkedList_destroyDeep(journalEntries, (LinkedListValueDeleteFunction)
MmsJournalEntry_destroy); MmsJournalEntry_destroy);
if (moreFollows) { if (moreFollows)
{
char buf[100]; char buf[100];
MmsValue_printToBuffer(nextEntryId, buf, 100); MmsValue_printToBuffer(nextEntryId, buf, 100);
@ -374,12 +384,14 @@ int main(int argc, char** argv)
printf(" Invalid log name!\n"); printf(" Invalid log name!\n");
} }
if (readVariable) { if (readVariable)
if (readWriteHasDomain) { {
if (readWriteHasDomain)
{
MmsValue* result; MmsValue* result;
if (componentName == NULL) { if (componentName == NULL)
{
if (arrayIndex == -1) { if (arrayIndex == -1) {
result = MmsConnection_readVariable(con, &error, domainName, variableName); result = MmsConnection_readVariable(con, &error, domainName, variableName);
} }
@ -396,15 +408,18 @@ int main(int argc, char** argv)
} }
} }
if (error != MMS_ERROR_NONE) { if (error != MMS_ERROR_NONE)
{
printf("Reading variable failed: (ERROR %i)\n", error); printf("Reading variable failed: (ERROR %i)\n", error);
returnCode = error; returnCode = error;
} }
else { else
{
printf("Read SUCCESS\n"); printf("Read SUCCESS\n");
if (result != NULL) { if (result != NULL)
{
char outbuf[1024]; char outbuf[1024];
MmsValue_printToBuffer(result, outbuf, 1024); MmsValue_printToBuffer(result, outbuf, 1024);
@ -416,22 +431,27 @@ int main(int argc, char** argv)
else else
printf("result: NULL\n"); printf("result: NULL\n");
} }
} }
else else
{
printf("Reading VMD scope variable not yet supported!\n"); printf("Reading VMD scope variable not yet supported!\n");
}
} }
if (readVariableList) { if (readVariableList)
if (readWriteHasDomain) { {
if (readWriteHasDomain)
{
MmsValue* variables = MmsConnection_readNamedVariableListValues(con, &error, domainName, variableName, true); MmsValue* variables = MmsConnection_readNamedVariableListValues(con, &error, domainName, variableName, true);
if (error != MMS_ERROR_NONE) { if (error != MMS_ERROR_NONE)
{
printf("Reading variable failed: (ERROR %i)\n", error); printf("Reading variable failed: (ERROR %i)\n", error);
returnCode = error; returnCode = error;
} }
else { else
{
printf("Read SUCCESS\n"); printf("Read SUCCESS\n");
} }
} }
@ -439,24 +459,28 @@ int main(int argc, char** argv)
printf("Reading VMD scope variable list not yet supported!\n"); printf("Reading VMD scope variable list not yet supported!\n");
} }
if (readDataSetDirectory) { if (readDataSetDirectory)
if (readWriteHasDomain) { {
if (readWriteHasDomain)
{
bool deletable = false; bool deletable = false;
LinkedList varListDir = MmsConnection_readNamedVariableListDirectory(con, &error, domainName, variableName, &deletable); LinkedList varListDir = MmsConnection_readNamedVariableListDirectory(con, &error, domainName, variableName, &deletable);
if (error != MMS_ERROR_NONE) { if (error != MMS_ERROR_NONE)
{
printf("Reading variable list directory failed: (ERROR %i)\n", error); printf("Reading variable list directory failed: (ERROR %i)\n", error);
returnCode = error; returnCode = error;
} }
else { else
{
LinkedList varListElem = LinkedList_getNext(varListDir); LinkedList varListElem = LinkedList_getNext(varListDir);
int listIdx = 0; int listIdx = 0;
while (varListElem) { while (varListElem)
{
MmsVariableAccessSpecification* varAccessSpec = (MmsVariableAccessSpecification*)LinkedList_getData(varListElem); MmsVariableAccessSpecification* varAccessSpec = (MmsVariableAccessSpecification*)LinkedList_getData(varListElem);
if (varAccessSpec->arrayIndex) if (varAccessSpec->arrayIndex)
@ -476,14 +500,15 @@ int main(int argc, char** argv)
printf("Reading VMD scope variable list not yet supported!\n"); printf("Reading VMD scope variable list not yet supported!\n");
} }
if (showFileList) { if (showFileList)
{
char lastName[300]; char lastName[300];
lastName[0] = 0; lastName[0] = 0;
char* continueAfter = NULL; char* continueAfter = NULL;
while (MmsConnection_getFileDirectory(con, &error, "", continueAfter, mmsFileDirectoryHandler, lastName)) { while (MmsConnection_getFileDirectory(con, &error, "", continueAfter, mmsFileDirectoryHandler, lastName))
{
if (error != MMS_ERROR_NONE) if (error != MMS_ERROR_NONE)
returnCode = error; returnCode = error;
@ -491,21 +516,25 @@ int main(int argc, char** argv)
} }
} }
if (getFileAttributes) { if (getFileAttributes)
{
MmsConnection_getFileDirectory(con, &error, filename, NULL, mmsGetFileAttributeHandler, NULL); MmsConnection_getFileDirectory(con, &error, filename, NULL, mmsGetFileAttributeHandler, NULL);
if (error != MMS_ERROR_NONE) if (error != MMS_ERROR_NONE)
returnCode = error; returnCode = error;
} }
if (deleteFile) { if (deleteFile)
{
MmsConnection_fileDelete(con, &error, filename); MmsConnection_fileDelete(con, &error, filename);
if (error != MMS_ERROR_NONE) { if (error != MMS_ERROR_NONE)
{
printf("Delete file failed: (ERROR %i)\n", error); printf("Delete file failed: (ERROR %i)\n", error);
returnCode = error; returnCode = error;
} }
else { else
{
printf("File deleted\n"); printf("File deleted\n");
} }
} }
@ -521,4 +550,3 @@ exit:
return returnCode; return returnCode;
} }

@ -21,8 +21,8 @@ main(int argc, char** argv)
{ {
RSession rSession = RSession_create(); RSession rSession = RSession_create();
if (rSession) { if (rSession)
{
/* Call RSession_setLocalAddress to use a particular interface to send the R-GOOSE messages */ /* Call RSession_setLocalAddress to use a particular interface to send the R-GOOSE messages */
//RSession_setLocalAddress(rSession, "169.254.110.126", -1); //RSession_setLocalAddress(rSession, "169.254.110.126", -1);
RSession_setRemoteAddress(rSession, "230.0.10.10", 102); RSession_setRemoteAddress(rSession, "230.0.10.10", 102);
@ -32,8 +32,8 @@ main(int argc, char** argv)
uint32_t activeKeyId = 1; uint32_t activeKeyId = 1;
uint64_t nextKeyChangeTime = Hal_getTimeInMs() + 5000; uint64_t nextKeyChangeTime = Hal_getTimeInMs() + 5000;
if (svPublisher) { if (svPublisher)
{
signal(SIGINT, sigint_handler); signal(SIGINT, sigint_handler);
char* key1 = "0123456789ABCDEF"; char* key1 = "0123456789ABCDEF";
@ -63,7 +63,8 @@ main(int argc, char** argv)
RSession_start(rSession); RSession_start(rSession);
while (running) { while (running)
{
Timestamp ts; Timestamp ts;
Timestamp_clearFlags(&ts); Timestamp_clearFlags(&ts);
Timestamp_setTimeInMilliseconds(&ts, Hal_getTimeInMs()); Timestamp_setTimeInMilliseconds(&ts, Hal_getTimeInMs());
@ -84,7 +85,8 @@ main(int argc, char** argv)
SVPublisher_publish(svPublisher); SVPublisher_publish(svPublisher);
if (Hal_getTimeInMs() >= nextKeyChangeTime) { if (Hal_getTimeInMs() >= nextKeyChangeTime)
{
/* change key */ /* change key */
if (activeKeyId == 1) if (activeKeyId == 1)
@ -101,14 +103,15 @@ main(int argc, char** argv)
SVPublisher_destroy(svPublisher); SVPublisher_destroy(svPublisher);
} }
else { else
{
printf("Failed to create SV publisher\n"); printf("Failed to create SV publisher\n");
} }
RSession_destroy(rSession); RSession_destroy(rSession);
} }
else { else
{
printf("Failed to create remote session instance\n"); printf("Failed to create remote session instance\n");
} }
} }

Loading…
Cancel
Save