opc_ua/opcua_client_maker.py
branchwxPython4
changeset 3620 1cf21430ed4a
parent 3612 428fb2472f43
child 3633 837e7782d83e
equal deleted inserted replaced
3619:f75b11506fb2 3620:1cf21430ed4a
   562 #define LogInfo(...) _Log(LOG_INFO, __VA_ARGS__);
   562 #define LogInfo(...) _Log(LOG_INFO, __VA_ARGS__);
   563 #define LogError(...) _Log(LOG_CRITICAL, __VA_ARGS__);
   563 #define LogError(...) _Log(LOG_CRITICAL, __VA_ARGS__);
   564 #define LogWarning(...) _Log(LOG_WARNING, __VA_ARGS__);
   564 #define LogWarning(...) _Log(LOG_WARNING, __VA_ARGS__);
   565 
   565 
   566 #define INIT_NoAuth()                                                                              \\
   566 #define INIT_NoAuth()                                                                              \\
   567     LogInfo("OPC-UA Init no auth\\n");                                                             \\
   567     LogInfo("OPC-UA Init no auth");                                                                \\
   568     UA_ClientConfig_setDefault(cc);                                                                \\
   568     UA_ClientConfig_setDefault(cc);                                                                \\
   569     retval = UA_Client_connect(client, uri);
   569     retval = UA_Client_connect(client, uri);
   570 
   570 
   571 /* 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 */
   572 #define INIT_x509(Policy, UpperCaseMode, PrivateKey, Certificate)                                  \\
   572 #define INIT_x509(Policy, UpperCaseMode, PrivateKey, Certificate)                                  \\
   573     /* TODO try paths given in runtime CLI */                                                      \\
   573     /* TODO try paths given in runtime CLI */                                                      \\
   574     UA_ByteString certificate = loadFile(Certificate);                                             \\
   574     UA_ByteString certificate = loadFile(Certificate);                                             \\
   575     UA_ByteString privateKey  = loadFile(PrivateKey);                                              \\
   575     UA_ByteString privateKey  = loadFile(PrivateKey);                                              \\
   576                                                                                                    \\
   576                                                                                                    \\
   577     LogInfo("OPC-UA Init x509 %s,%s,%s,%s\\n", #Policy, #UpperCaseMode, PrivateKey, Certificate);  \\
   577     LogInfo("OPC-UA Init x509 %s,%s,%s,%s", #Policy, #UpperCaseMode, PrivateKey, Certificate);     \\
   578     cc->securityMode = UA_MESSAGESECURITYMODE_##UpperCaseMode;                                     \\
   578     cc->securityMode = UA_MESSAGESECURITYMODE_##UpperCaseMode;                                     \\
   579     UA_ClientConfig_setDefaultEncryption(cc, certificate, privateKey, NULL, 0, NULL, 0);           \\
   579     UA_ClientConfig_setDefaultEncryption(cc, certificate, privateKey, NULL, 0, NULL, 0);           \\
   580                                                                                                    \\
   580                                                                                                    \\
   581     retval = UA_Client_connect(client, uri);                                                       \\
   581     retval = UA_Client_connect(client, uri);                                                       \\
   582                                                                                                    \\
   582                                                                                                    \\
   583     UA_ByteString_clear(&certificate);                                                             \\
   583     UA_ByteString_clear(&certificate);                                                             \\
   584     UA_ByteString_clear(&privateKey);
   584     UA_ByteString_clear(&privateKey);
   585 
   585 
   586 #define INIT_UserPassword(User, Password)                                                          \\
   586 #define INIT_UserPassword(User, Password)                                                          \\
   587     LogInfo("OPC-UA Init UserPassword %s,%s\\n", User, Password);                                  \\
   587     LogInfo("OPC-UA Init UserPassword %s,%s", User, Password);                                     \\
   588     UA_ClientConfig_setDefault(cc);                                                                \\
   588     UA_ClientConfig_setDefault(cc);                                                                \\
   589     retval = UA_Client_connectUsername(client, uri, User, Password);
   589     retval = UA_Client_connectUsername(client, uri, User, Password);
   590 
   590 
   591 #define INIT_READ_VARIANT(ua_type, c_loc_name)                                                     \\
   591 #define INIT_READ_VARIANT(ua_type, c_loc_name)                                                     \\
   592     UA_Variant_init(&c_loc_name##_variant);
   592     UA_Variant_init(&c_loc_name##_variant);
   601     cc = UA_Client_getConfig(client);
   601     cc = UA_Client_getConfig(client);
   602     char *uri = "{uri}";
   602     char *uri = "{uri}";
   603 {init}
   603 {init}
   604 
   604 
   605     if(retval != UA_STATUSCODE_GOOD) {{
   605     if(retval != UA_STATUSCODE_GOOD) {{
   606         LogError("OPC-UA Init Failed %d\\n", retval);                                              \\
   606         LogError("OPC-UA Init Failed %d", retval);
   607         UA_Client_delete(client);
   607         UA_Client_delete(client);
   608         return EXIT_FAILURE;
   608         return EXIT_FAILURE;
   609     }}
   609     }}
   610     return 0;
   610     return 0;
   611 }}
   611 }}
   739 */
   739 */
   740 
   740 
   741 """%(path, path[:-2]) + modeldata.GenerateC(path, "test", config) + """
   741 """%(path, path[:-2]) + modeldata.GenerateC(path, "test", config) + """
   742 
   742 
   743 int LogMessage(uint8_t level, char* buf, uint32_t size){
   743 int LogMessage(uint8_t level, char* buf, uint32_t size){
   744     printf("log level:%d message:'%.*s'", level, size, buf);
   744     printf("log level:%d message:'%.*s'\\n", level, size, buf);
   745 };
   745 };
   746 
   746 
   747 int main(int argc, char *argv[]) {
   747 int main(int argc, char *argv[]) {
   748 
   748 
   749     __init_test(arc,argv);
   749     __init_test(arc,argv);