I2C via rpc

Dependencies:   RPCInterface mbed

Fork of RPC_Serial by Michael Walker

Files at this revision

API Documentation at this revision

Comitter:
sammekevremde
Date:
Tue Apr 30 07:04:28 2013 +0000
Parent:
1:de34af25056a
Commit message:
Voor bjorn

Changed in this revision

RPCInterface.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r de34af25056a -r 1b38b24c66dc RPCInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RPCInterface.lib	Tue Apr 30 07:04:28 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/MichaelW/code/RPCInterface/#682c65afe534
diff -r de34af25056a -r 1b38b24c66dc main.cpp
--- a/main.cpp	Tue Aug 24 15:15:44 2010 +0000
+++ b/main.cpp	Tue Apr 30 07:04:28 2013 +0000
@@ -1,6 +1,59 @@
 #include "mbed.h"
 #include "rpc.h"
+#include "RPCFunction.h"
+#include "RPCVariable.h"
 Serial pc(USBTX, USBRX);
+I2C i2c(p28,p27);
+//functions definition
+void sendData(char * input, char * output);
+void readData(char * input, char * output);
+//RPC function calls
+RPCFunction send(&sendData, "send");
+RPCFunction read(&readData, "read");
+
+// Functions
+void sendData(char * input, char * output)
+{
+    int adress;
+    int length;
+    int offset;
+    char *data = &input[0];
+    int temp;
+    int i=0;
+    sscanf(data, "%x %x %n", &adress,&length, &offset);
+   // printf("adress = %#x \nlengte= %#x \n", adress , length);
+    data += offset;
+    char cmd[length];
+    while (1==sscanf(data, "%x %n", &temp, &offset))
+      {
+        cmd[i]=temp;
+        data += offset;
+        i++;
+      }
+  //    printf("adress = %#x \nlengte= %#x \ncmd[0]= %#x \ncmd[1]= %#x\n", adress , length ,cmd[0],cmd[1]);
+    i2c.write(adress,cmd,length);
+}
+void readData(char * input, char * output)
+{
+    strcpy(output,"");
+    int adress;
+    int length;
+    int offset;
+    char *data = &input[0];
+    sscanf(data, " %x %x%n", &adress,&length, &offset);
+    data += offset;
+    char cmd[length];
+
+    i2c.read(adress,cmd,length);
+    char temp[4];
+    for (int i=0;i<length;i++)
+    {
+    sprintf(temp,"%x",cmd[i]);
+    strcat(output,temp);
+    }
+   // printf("%#x %#x",cmd[0],cmd[1]);
+}
+
 int main() {
     // setup the classes that can be created dynamically
     Base::add_rpc_class<AnalogIn>();