123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #ifndef READMME_SOURCE
- #define READMME_SOURCE
- #include <sys/time.h>
- #include <stdint.h>
- #include <memory.h>
- #include <errno.h>
- #include "../tools/error.h"
- #include "../tools/timer.h"
- #include "../plc/plc.h"
- #include "../mme/mme.h"
- signed ReadMME (struct plc * plc, uint8_t MMV, uint16_t MMTYPE)
- {
- struct channel * channel = (struct channel *)(plc->channel);
- struct message * message = (struct message *)(plc->message);
- struct timeval ts;
- struct timeval tc;
- if (gettimeofday (&ts, NULL) == -1)
- {
- error (1, errno, CANT_START_TIMER);
- }
- while ((plc->packetsize = readpacket (channel, message, sizeof (* message))) >= 0)
- {
- if (UnwantedMessage (message, plc->packetsize, MMV, MMTYPE))
- {
- if (gettimeofday (&tc, NULL) == -1)
- {
- error (1, errno, CANT_RESET_TIMER);
- }
- if (channel->timeout < 0)
- {
- continue;
- }
- if (channel->timeout > MILLISECONDS (ts, tc))
- {
- continue;
- }
- plc->packetsize = 0;
- }
- break;
- }
- return (plc->packetsize);
- }
- #endif
|