123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #ifndef READFMI_SOURCE
- #define READFMI_SOURCE
- #include <stdint.h>
- #include <stdlib.h>
- #include <memory.h>
- #include "../tools/memory.h"
- #include "../tools/number.h"
- #include "../tools/error.h"
- #include "../plc/plc.h"
- signed ReadFMI (struct plc * plc, uint8_t MMV, uint16_t MMTYPE)
- {
- if (ReadMME (plc, MMV, MMTYPE) > 0)
- {
- struct homeplug * homeplug = (struct homeplug *)(plc->message);
- unsigned count = ((homeplug->homeplug.FMID >> 0) & 0x0F);
- unsigned extra = ((homeplug->homeplug.FMID >> 4) & 0x0F);
- unsigned length = sizeof (* homeplug) + extra * sizeof (homeplug->content);
- if ((plc->content = malloc (length)))
- {
- signed offset = plc->packetsize;
- memcpy (plc->content, homeplug, offset);
- while (count < extra)
- {
- if (ReadMME (plc, MMV, MMTYPE) <= 0)
- {
- free (plc->content);
- plc->content = NULL;
- return (- 1);
- }
- count = ((homeplug->homeplug.FMID >> 0) & 0x0F);
- extra = ((homeplug->homeplug.FMID >> 4) & 0x0F);
- plc->packetsize -= sizeof (struct ethernet_hdr);
- plc->packetsize -= sizeof (struct homeplug_fmi);
- memcpy ((uint8_t *)(plc->content) + offset, homeplug->content, plc->packetsize);
- offset += plc->packetsize;
- }
- plc->packetsize = offset;
- }
- else
- {
- error (1, errno, "%s", __func__);
- }
- }
- return (plc->packetsize);
- }
- #endif
|