opc_ua/opcua_client_maker.py
branchwxPython4
changeset 3612 428fb2472f43
parent 3591 50600b946ea7
child 3620 1cf21430ed4a
equal deleted inserted replaced
3611:2c041d3d6ee3 3612:428fb2472f43
   550     UA_Client_disconnect(client);
   550     UA_Client_disconnect(client);
   551     UA_Client_delete(client);
   551     UA_Client_delete(client);
   552 }}
   552 }}
   553 
   553 
   554 
   554 
       
   555 #define _Log(level, ...)                                                                           \\
       
   556     {{                                                                                             \\
       
   557         char mstr[256];                                                                            \\
       
   558         snprintf(mstr, 255, __VA_ARGS__);                                                          \\
       
   559         LogMessage(level, mstr, strlen(mstr));                                                     \\
       
   560     }}
       
   561 
       
   562 #define LogInfo(...) _Log(LOG_INFO, __VA_ARGS__);
       
   563 #define LogError(...) _Log(LOG_CRITICAL, __VA_ARGS__);
       
   564 #define LogWarning(...) _Log(LOG_WARNING, __VA_ARGS__);
       
   565 
   555 #define INIT_NoAuth()                                                                              \\
   566 #define INIT_NoAuth()                                                                              \\
       
   567     LogInfo("OPC-UA Init no auth\\n");                                                             \\
   556     UA_ClientConfig_setDefault(cc);                                                                \\
   568     UA_ClientConfig_setDefault(cc);                                                                \\
   557     retval = UA_Client_connect(client, uri);
   569     retval = UA_Client_connect(client, uri);
   558 
   570 
   559 /* Note : Policy is ignored here since open62541 client supports all policies by default */
   571 /* Note : Policy is ignored here since open62541 client supports all policies by default */
   560 #define INIT_x509(Policy, UpperCaseMode, PrivateKey, Certificate)                                  \\
   572 #define INIT_x509(Policy, UpperCaseMode, PrivateKey, Certificate)                                  \\
   561     /* TODO try paths given in runtime CLI */                                                      \\
   573     /* TODO try paths given in runtime CLI */                                                      \\
   562     UA_ByteString certificate = loadFile(Certificate);                                             \\
   574     UA_ByteString certificate = loadFile(Certificate);                                             \\
   563     UA_ByteString privateKey  = loadFile(PrivateKey);                                              \\
   575     UA_ByteString privateKey  = loadFile(PrivateKey);                                              \\
   564                                                                                                    \\
   576                                                                                                    \\
   565     printf("INIT_x509 %s,%s,%s,%s\\n", #Policy, #UpperCaseMode, PrivateKey, Certificate);          \\
   577     LogInfo("OPC-UA Init x509 %s,%s,%s,%s\\n", #Policy, #UpperCaseMode, PrivateKey, Certificate);  \\
   566     cc->securityMode = UA_MESSAGESECURITYMODE_##UpperCaseMode;                                     \\
   578     cc->securityMode = UA_MESSAGESECURITYMODE_##UpperCaseMode;                                     \\
   567     UA_ClientConfig_setDefaultEncryption(cc, certificate, privateKey, NULL, 0, NULL, 0);           \\
   579     UA_ClientConfig_setDefaultEncryption(cc, certificate, privateKey, NULL, 0, NULL, 0);           \\
   568                                                                                                    \\
   580                                                                                                    \\
   569     retval = UA_Client_connect(client, uri);                                                       \\
   581     retval = UA_Client_connect(client, uri);                                                       \\
   570                                                                                                    \\
   582                                                                                                    \\
   571     UA_ByteString_clear(&certificate);                                                             \\
   583     UA_ByteString_clear(&certificate);                                                             \\
   572     UA_ByteString_clear(&privateKey);
   584     UA_ByteString_clear(&privateKey);
   573 
   585 
   574 #define INIT_UserPassword(User, Password)                                                          \\
   586 #define INIT_UserPassword(User, Password)                                                          \\
   575     printf("TODO INIT_UserPassword %s,%s\\n", User, Password);                                     \\
   587     LogInfo("OPC-UA Init UserPassword %s,%s\\n", User, Password);                                  \\
       
   588     UA_ClientConfig_setDefault(cc);                                                                \\
   576     retval = UA_Client_connectUsername(client, uri, User, Password);
   589     retval = UA_Client_connectUsername(client, uri, User, Password);
   577 
   590 
   578 #define INIT_READ_VARIANT(ua_type, c_loc_name)                                                     \\
   591 #define INIT_READ_VARIANT(ua_type, c_loc_name)                                                     \\
   579     UA_Variant_init(&c_loc_name##_variant);
   592     UA_Variant_init(&c_loc_name##_variant);
   580 
   593 
   588     cc = UA_Client_getConfig(client);
   601     cc = UA_Client_getConfig(client);
   589     char *uri = "{uri}";
   602     char *uri = "{uri}";
   590 {init}
   603 {init}
   591 
   604 
   592     if(retval != UA_STATUSCODE_GOOD) {{
   605     if(retval != UA_STATUSCODE_GOOD) {{
       
   606         LogError("OPC-UA Init Failed %d\\n", retval);                                              \\
   593         UA_Client_delete(client);
   607         UA_Client_delete(client);
   594         return EXIT_FAILURE;
   608         return EXIT_FAILURE;
   595     }}
   609     }}
       
   610     return 0;
   596 }}
   611 }}
   597 
   612 
   598 #define READ_VALUE(ua_type, ua_type_enum, c_loc_name, ua_nodeid_type, ua_nsidx, ua_node_id)        \\
   613 #define READ_VALUE(ua_type, ua_type_enum, c_loc_name, ua_nodeid_type, ua_nsidx, ua_node_id)        \\
   599     retval = UA_Client_readValueAttribute(                                                         \\
   614     retval = UA_Client_readValueAttribute(                                                         \\
   600         client, ua_nodeid_type(ua_nsidx, ua_node_id), &c_loc_name##_variant);                      \\
   615         client, ua_nodeid_type(ua_nsidx, ua_node_id), &c_loc_name##_variant);                      \\
   723     -I ../../open62541/arch/ ../../open62541/build/bin/libopen62541.a
   738     -I ../../open62541/arch/ ../../open62541/build/bin/libopen62541.a
   724 */
   739 */
   725 
   740 
   726 """%(path, path[:-2]) + modeldata.GenerateC(path, "test", config) + """
   741 """%(path, path[:-2]) + modeldata.GenerateC(path, "test", config) + """
   727 
   742 
       
   743 int LogMessage(uint8_t level, char* buf, uint32_t size){
       
   744     printf("log level:%d message:'%.*s'", level, size, buf);
       
   745 };
       
   746 
   728 int main(int argc, char *argv[]) {
   747 int main(int argc, char *argv[]) {
   729 
   748 
   730     __init_test(arc,argv);
   749     __init_test(arc,argv);
   731    
   750    
   732     __retrieve_test();
   751     __retrieve_test();