12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #include "plt.h"
- #include "mdl.h"
- //uint8_t DO_status[8] = {0};
- void mdl_sim()
- {
- int i = 0;
- for(i = 1; i <= 8; i++){
- //DO_status[i - 1] = 0;
- chan_write_gpio(i,MDL.DO[i - 1]);
- }
- for(i = 1; i <= 4; i++){
- chan_read_gpio(i + 8,&MDL.DI[i - 1]);
- }
- }
- void mdl_prepare()
- {
- int i = 0;
- chan_init();
- for(i = 1; i <= 8; i++){
- MDL.DO[i - 1] = 0;
- chan_write_gpio(i,0);
- }
- for(i = 1; i <= 4; i++){
- chan_read_gpio(i + 8,&MDL.DI[i - 1]);
- }
- }
- void from_modbus_to_dev()
- {
- //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;
- }
|