Message Container Format formatter / parser.
Reading a MCF message can be done as follows:
void decodeMCF(uint8_t * ptr, int bufLen)
{
MFCState decoderState;
MFCMessage * msg = &decoderState.msg;
mfcInit(&decoderState, ptr, bufLen);
while (mfcDecodeNext(&decoderState))
{
printf("Current Message %u of %u\n", decoderState.msgCur, decoderState.msgCount);
printf("- Type: %u.%u\n", MFC_TYP2GROUP(msg->typ), MFC_TYP2SUB(msg->typ));
printf("- Time : %lu, Length: %u\n", msg->timestamp, msg->cntLength);
printf("- Class: %u, Identifer: %u\u", msg->clazz, msg->identifier);
}
}
Write one can also be done. The next example writes a MCF message with two commands, the first contains 'hello' and the second contains 'world'.
#define HELLO_GROUP 0x1
#define HELLO_HELLO MFC_2TYPE(HELLO_GROUP, 0x1)
#define HELLO_WORLD MFC_2TYPE(HELLO_GROUP, 0x2)
static int msgId;
void encodeMsgStr(MFCState * state, uint16_t typ, char * cnt, int cntLen)
{
MFCMessage * msg = encoderState->msg;
mfcEncodeNext(state);
msg->class = MFC_CLASS_CMD;
msg->typ = typ;
msg->identifier = msgId++;
msg->timestamp = timeGetDeayMillis();
memcopy(msg->cntPtr, cnt, cntLen);
msg->cntLen = cntLen;
}
void encodeMCF(uint8_t * ptr, int bufLen)
{
MFCState encoderState;
mfcInit(&encoderState, ptr, bufLen);
encodeMsgStr(&encoderState, HELLO_HELLO, "hello", 5);
encodeMsgStr(&encoderState, HELLO_WORLD, "world", 5);
mfcEncodeFinish(&encoderState);
}
Definition in file mcf.h.