Add LPC1768
Dependencies: mbed-rtos mbed Xbus
Fork of MTi-1_example by
Revision 23:8171449f0dc3, committed 2015-05-20
- Comitter:
- Alex Young
- Date:
- Wed May 20 12:39:11 2015 +0200
- Parent:
- 22:3eab999c5076
- Child:
- 24:2cc49dc854e3
- Commit message:
- Factor out specific message parsing functions.
Changed in this revision
| xbus/xbusparser.c | Show annotated file Show diff for this revision Revisions of this file |
--- a/xbus/xbusparser.c Tue May 19 16:59:53 2015 +0200
+++ b/xbus/xbusparser.c Wed May 20 12:39:11 2015 +0200
@@ -91,47 +91,54 @@
}
}
+static void parseDeviceId(struct XbusParser* parser)
+{
+ uint32_t* deviceId = parser->callbacks.allocateBuffer(sizeof(uint32_t));
+ if (deviceId)
+ {
+ XbusUtility_readU32(deviceId, parser->rxBuffer);
+ parser->currentMessage.data = deviceId;
+ parser->currentMessage.length = 1;
+ }
+ else
+ {
+ parser->currentMessage.data = NULL;
+ }
+}
+
+static void parseOutputConfig(struct XbusParser* parser)
+{
+ uint8_t fields = parser->currentMessage.length / 4;
+ struct OutputConfiguration* conf = parser->callbacks.allocateBuffer(fields * sizeof(struct OutputConfiguration));
+ uint8_t const* dptr = parser->rxBuffer;
+ if (conf)
+ {
+ parser->currentMessage.data = conf;
+ parser->currentMessage.length = fields;
+
+ for (int i = 0; i < fields; ++i)
+ {
+ dptr = XbusUtility_readU16((uint16_t*)&conf->dtype, dptr);
+ dptr = XbusUtility_readU16(&conf->freq, dptr);
+ ++conf;
+ }
+ }
+ else
+ {
+ parser->currentMessage.data = NULL;
+ }
+}
+
static void parseMessagePayload(struct XbusParser* parser)
{
switch (parser->currentMessage.mid)
{
case XMID_DeviceId:
- {
- uint32_t* deviceId = parser->callbacks.allocateBuffer(sizeof(uint32_t));
- if (deviceId)
- {
- XbusUtility_readU32(deviceId, parser->rxBuffer);
- parser->currentMessage.data = deviceId;
- }
- else
- {
- parser->currentMessage.data = NULL;
- }
- }
+ parseDeviceId(parser);
break;
case XMID_OutputConfig:
- {
- uint8_t fields = parser->currentMessage.length / 4;
- struct OutputConfiguration* conf = parser->callbacks.allocateBuffer(fields * sizeof(struct OutputConfiguration));
- uint8_t const* dptr = parser->rxBuffer;
- if (conf)
- {
- parser->currentMessage.data = conf;
- parser->currentMessage.length = fields;
-
- for (int i = 0; i < fields; ++i)
- {
- dptr = XbusUtility_readU16((uint16_t*)&conf->dtype, dptr);
- dptr = XbusUtility_readU16(&conf->freq, dptr);
- ++conf;
- }
- }
- else
- {
- parser->currentMessage.data = NULL;
- }
- }
+ parseOutputConfig(parser);
break;
default:
David Khosravi
