#include "plt.h" #include "mdl.h" int random_range(int min, int max) { return min + rand() / (RAND_MAX / (max - min + 1) + 1); } void mdl_sim() { MDL.co_ppm = random_range(42, 60); } void mdl_prepare() { MDL.co_ppm = random_range(42, 60); MDL.co_alarm = 0; } void from_modbus_to_dev() { // usHoldingRegisters[0x6020] = uab; return 0; } int from_dev_to_modbus() { // uab = usHoldingRegisters[0x6020]; return 0; } void update_states() { } static void *mdl_thrd_main(void *param) { mdl_prepare(); from_dev_to_modbus(); while (1) { from_modbus_to_dev(); mdl_sim(); from_dev_to_modbus(); usleep(10000); /* 10ms */ } return NULL; } int mdl_init() { log_dbg("%s, ++", __func__); int ret = 0; pthread_t xthrd; if (pthread_create(&xthrd, NULL, mdl_thrd_main, NULL) != 0) { log_dbg("%s, pthread_create fail", __func__); ret = -1; } log_dbg("%s, --, ret: %d", __func__, ret); return ret; }