Command processor to access I2C and SPI Takes URI coded commands and returns JSON array

Fork of SerialInterface by Greg Steiert

Revision:
2:3f6a8ac111a9
Parent:
1:0c22013818d7
Child:
3:601b78524967
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SerialInterface.h	Thu Dec 08 05:21:57 2016 +0000
@@ -0,0 +1,92 @@
+/* Pmod Interface Library
+ *
+ */
+#ifndef SERIALINTERFACE_H
+#define SERIALINTERFACE_H
+
+#include "mbed.h"
+#include "SerialInterface.h"
+
+/** RAPC Library, Provides utilities for remotely accessing peripherals
+ *
+ * Example:
+ * @code
+ * // Configure board to pass UART signals to peripheral connector.
+ *
+ * #include "SerialInterface.h"
+ *
+ * SerialInterface serInt;
+ *
+ * int main() {
+ *    char ibuf[256];
+ *    char obuf[256];
+ *    pInt.init();
+ *    while(1) {
+ *        scanf("%s", ibuf);
+ *        pInt.call(ibuf, obuf);
+ *        printf("%s=", ibuf);
+ *        printf("%s\n", obuf);
+ * }
+ * @endcode
+ */
+class SerialInterface
+{
+public:
+
+    /** Create a SerialInterface interface
+     *
+     */
+    SerialInterface();
+
+    ~SerialInterface();
+
+    /** Name the I2C arguments
+    */
+    enum PINTi2cArgs {
+        IA_CNT = 0, /**< Argument Count */
+        IA_ADD,     /**< Device Address */
+        IA_DATA,    /**< Data, Read = # bytes to read, Write = first data byte */
+        IA_RDDA     /**< Read Data, data to write prior to read */
+    };
+
+    /** Initialize the digital pins and PWM
+     *
+     */
+    void init(I2C* i2c, SPI* spi);
+
+    /** Process Remote Arduino Peripheral Module Command
+     *
+     *  @param input a pointer to the string containing the command
+     *  @param output a pointer to the string to write the result
+     */
+    void call(char* input, char* output);
+
+private:
+
+    // Internal Functions
+
+    /** Process I2C Command
+     *  
+     *  @param resp a pointer to the string to write the result
+     */
+    void fnc_i2c(char* resp);
+
+    /** Process SPI Command
+     *  
+     *  @param resp a pointer to the string to write the result
+     */
+    void fnc_spi(char* resp);
+
+    // Internal Resources
+    I2C *_i2c;
+
+    // Internal Resources
+    SPI *_spi;
+
+    // Internal Buffers
+    int _args[64];
+    char _dbuf[128];
+
+};
+
+#endif
\ No newline at end of file