 /*
  * Deal with a full request and determine function to call
  */
-void process() {
-  strncpy(cmd, request, 2);      cmd[2] = '\0';
-  strncpy(pin, request + 2, 2);  pin[2] = '\0';
-  strncpy(val, request + 4, 3);  val[3] = '\0';
-
+void process(char *request) {
+   char cmd[3];  strncpy(cmd, request, 2);      cmd[2] = '\0';
+   char pin[3];  strncpy(pin, request + 2, 2);  pin[2] = '\0';
+   char val[4];  strncpy(val, request + 4, 3);  val[3] = '\0';
+  
   // if (debug) Serial.println(request);  
-  int p = getPin(pin);
-  if (p == -1) return; // Should raise some kind of "bad pin" error.
+  int rawPin = getPin(pin);
+  if (rawPin == -1) return; // Should raise some kind of "bad pin" error.
  
   int cmdid = atoi(cmd);
   switch(cmdid) {
-    case 0:  setMode    (p, val);       break;
-    case 1:  dWrite     (p, val);       break;
-    case 2:  dRead      (p);            break;
-    case 3:  aWrite     (p, val);       break;
-    case 4:  aRead      (p);            break;
-    case 99: toggleDebug(val);          break;
-    default:                            break;
+    case 0:  setMode    (rawPin, val);             break;
+    case 1:  dWrite     (rawPin, val);             break;
+    case 2:  dRead      (rawPin, &response);       break;
+    case 3:  aWrite     (rawPin, val);             break;
+    case 4:  aRead      (rawPin, &response, pin);  break;
+    case 99: toggleDebug(val);                     break;
+    default:                                       break;
   }
 }
 

    digitalWrite(p, HIGH);
  }
}
void dRead(int p) { 
  pinMode(p, INPUT);
  int oraw = digitalRead(p);
  char m[7];
  sprintf(m, "%02d::%02d", p, oraw);
  response = m;
}
void aRead(int p) {
  pinMode(p, INPUT);
  int rval = analogRead(p);
  char m[8];
  sprintf(m, "%s::%03d", pin, rval);
  response = m;
}
void aWrite(int p, char *val) {
  pinMode(p, OUTPUT);
  analogWrite(p,atoi(val));
}




    
    // Catch the request's ending delimiter and process the request.
    else if (c == '.') {
      process(request);
      if(response != "") Serial.println(response);
    }
       
