FibaroPlug() { logger = zlog_create(stdout, Critical); zway = NULL; #ifdef _WINDOWS ZWError r = zway_init(&zway, ZSTR("COM3"), NULL, NULL, NULL, NULL, logger); #endif #ifdef __MACH__ ZWError r = zway_init(&zway, ZSTR("/dev/cu.SLAB_USBtoUART"), NULL, NULL, NULL, NULL, logger); #endif #ifdef __linux__ //Aus der Doku: //ZWEXPORT ZWError zway_init(ZWay *pzway, ZWCSTR port, ZWCSTR config_folder, ZWCSTR translations_folder, ZWCSTR zddx_folder, ZWCSTR name, ZWLog logger); ZWError r = zway_init(&zway, ZSTR("/dev/ttyAMA0"), ZSTR("/opt/z-way-server/config/"), ZSTR("/opt/z-way-server/translations/"), ZSTR("/opt/z-way-server/ZDDX/"), NULL, logger); zway_log(zway, Debug, ZSTR("ZWAY device successfully created")); #endif if (r != NoError) { std::cout << "Failed to init ZWay\n"; exit(EXIT_FAILURE); } r = zway_start(zway, print_zway_terminated, NULL); if (r != NoError) { std::cout << "Failed to start ZWay\n"; exit(EXIT_FAILURE); } r = zway_discover(zway); if (r != NoError) { std::cout << "Failed to negotiate with Z-Wave stick\n"; exit(EXIT_FAILURE); } }
int main(int argc, const char * argv[]) { ZWLog logger = zlog_create(stdout, Debug); // ZWLog logger = NULL; ZWay zway = NULL; #ifdef _WINDOWS ZWError r = zway_init(&zway, ZSTR("COM3"), NULL, NULL, NULL, NULL, logger); #endif #ifdef __MACH__ ZWError r = zway_init(&zway, ZSTR("/dev/cu.SLAB_USBtoUART"), NULL, NULL, NULL, NULL, logger); #endif #ifdef __linux__ // ZWError r = zway_init(&zway, ZSTR("/dev/ttyUSB0"), NULL, NULL, NULL, NULL, logger); ZWError r = zway_init(&zway, ZSTR("/dev/ttyAMA0"), NULL, NULL, NULL, NULL, logger); #endif if (r != NoError) { printf("\n initError \n"); zway_log_error(zway, Critical, "Failed to init ZWay", r); return -1; } printf("\ncallback\n"); zway_device_add_callback(zway, DeviceAdded | DeviceRemoved | InstanceAdded | InstanceRemoved | CommandAdded | CommandRemoved, print_D_I_CC_event, NULL); printf("\nstart\n"); r = zway_start(zway, print_zway_terminated, NULL); if (r != NoError) { printf("\nstartError\n"); zway_log_error(zway, Critical, "Failed to start ZWay", r); return -1; } r = zway_discover(zway); if (r != NoError) { zway_log_error(zway, Critical, "Failed to negotiate with Z-Wave stick", r); return -1; } pin_init(); printf("\ndowork\n"); // Application code int code = do_work(zway); //int code =0; r = zway_stop(zway); zway_terminate(&zway); return code; }
int main(int argc, const char *argv[]) { ZWLog logger = zlog_create(stdout, Silent); ZWay zway = NULL; #ifdef _WINDOWS ZWError r = zway_init(&zway, ZSTR("COM3"), NULL, NULL, NULL, NULL, logger); #endif #ifdef __MACH__ ZWError r = zway_init(&zway, ZSTR("/dev/cu.SLAB_USBtoUART"), NULL, NULL, NULL, NULL, logger); #endif #ifdef __linux__ ZWError r = zway_init(&zway, ZSTR("/dev/ttyAMA0"), ZSTR("/opt/z-way-server/config/"), ZSTR("/opt/z-way-server/translations/"), ZSTR("/opt/z-way-server/ZDDX/"), NULL, logger); zway_log(zway, Debug, ZSTR("ZWAY device successfully created")); #endif if (r != NoError) { zway_log_error(zway, Critical, "Failed to init ZWay", r); return -1; } r = zway_start(zway, print_zway_terminated, NULL); if (r != NoError) { zway_log_error(zway, Critical, "Failed to start ZWay", r); return -1; } r = zway_discover(zway); if (r != NoError) { zway_log_error(zway, Critical, "Failed to negotiate with Z-Wave stick", r); return -1; } // Application code do_work(zway); r = zway_stop(zway); zway_terminate(&zway); return 0; }
PHP_METHOD(ZWLog, __construct) { php_zwlog_t *pz = php_zwlog_fetch(getThis()); zend_long level = PHP_ZWLOG_DEBUG; zend_string *file = CG(empty_string), *mode = CG(empty_string); if (ZEND_NUM_ARGS() > 1) { if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "SS|l", &file, &mode, &level) != SUCCESS) { return; } } else if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|l", &level) != SUCCESS) { return; } pz->level = level; if ((file && ZSTR_LEN(file)) && (mode && ZSTR_LEN(mode))) { FILE *stdio = fopen(ZSTR_VAL(file), ZSTR_VAL(mode)); if (!stdio) { zend_throw_exception_ex(spl_ce_RuntimeException, errno, "cannot open %s(%s) for logging", ZSTR_VAL(file), ZSTR_VAL(mode)); } else pz->zw = zlog_create(stdio, pz->level); } else pz->zw = zlog_create_syslog(pz->level); }