opcua_builtInDatatypes.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * opcua_BuiltInDatatypes.c
  3. *
  4. * Created on: Dec 19, 2013
  5. * Author: opcua
  6. */
  7. #include "opcua_builtInDatatypes.h"
  8. #include <stdio.h>
  9. UA_ExtensionObject the_empty_UA_ExtensionObject = { { NIEVT_TWO_BYTE, 0 }, NO_BODY_IS_ENCODED};
  10. UA_DiagnosticInfo the_empty_UA_DiagnosticInfo = { 0x00 };
  11. Int32 UA_String_compare(UA_String *string1, UA_String *string2) {
  12. Int32 i;
  13. Boolean equal;
  14. if (string1->Length == string2->Length&&
  15. string1->Length > 0 &&
  16. string1->Data != NULL && string2->Data != NULL) {for(i = 0; i < string1->Length; i++)
  17. {
  18. if(string1->Data[i] != string2->Data[i])
  19. {
  20. return UA_NOT_EQUAL;
  21. }
  22. }
  23. }
  24. else
  25. {
  26. return UA_NOT_EQUAL;
  27. }
  28. return UA_EQUAL;
  29. }
  30. Int32 UA_ByteString_compare(UA_ByteString *string1, UA_ByteString *string2) {
  31. return UA_String_compare((UA_String*) string1, (UA_String*) string2);
  32. }
  33. void UA_String_printf(char* label, UA_ByteString* string) {
  34. printf("%s {Length=%d, Data=%.*s}\n", label, string->Length, string->Length,
  35. (char*) string->Data);
  36. }
  37. void UA_ByteString_printx(char* label, UA_ByteString* string) {
  38. int i;
  39. printf("%s {Length=%d, Data=", label, string->Length);
  40. if (string->Length > 0) {
  41. for (i = 0; i < string->Length; i++) {
  42. printf("%c%d", i == 0 ? '{' : ',', (string->Data)[i]);
  43. if (i > 0 && !(i%20)) { printf("\n\t"); }
  44. }
  45. } else {
  46. printf("{");
  47. }
  48. printf("}}\n");
  49. }
  50. void UA_NodeId_printf(char* label, UA_NodeId* node) {
  51. printf("%s {EncodingByte=%d, Namespace=%d, ", label,
  52. (int) node->EncodingByte, (int) node->Namespace);
  53. switch (node->EncodingByte) {
  54. case NIEVT_TWO_BYTE:
  55. case NIEVT_FOUR_BYTE:
  56. case NIEVT_NUMERIC:
  57. printf("Identifier=%d", node->Identifier.Numeric);
  58. break;
  59. case NIEVT_STRING:
  60. case NIEVT_BYTESTRING:
  61. // TODO: This implementation does not distinguish between String and Bytestring. Error?
  62. printf("Identifier={Length=%d, Data=%.*s}",
  63. node->Identifier.String.Length, node->Identifier.String.Length,
  64. (char*) (node->Identifier.String.Data));
  65. break;
  66. case NIEVT_GUID:
  67. printf(
  68. "Guid={Data1=%d, Data2=%d, Data3=%d, Data4=={Length=%d, Data=%.*s}}",
  69. node->Identifier.Guid.Data1, node->Identifier.Guid.Data2,
  70. node->Identifier.Guid.Data3, node->Identifier.Guid.Data4.Length,
  71. node->Identifier.Guid.Data4.Length,
  72. (char*) (node->Identifier.Guid.Data4.Data));
  73. break;
  74. default:
  75. printf("ups! shit happens");
  76. break;
  77. }
  78. printf("}\n");
  79. }