void jsonCmdReceiveHandler(){
	int cmdType = jsonCmdReceive["T"].as<int>();
	switch(cmdType){
	case CMD_Gripper_JOINT_ANGLE:	Gripper_JointCtrlRad(
												jsonCmdReceive["angle"],
												jsonCmdReceive["spd"],
												jsonCmdReceive["acc"],
                        jsonCmdReceive["torque"]
												);break;
  case CMD_TORQUE_CTRL:	servoTorqueCtrl(254,
												jsonCmdReceive["cmd"]
												);break;  
  case CMD_SERVO_RAD_FEEDBACK:
												Gripper_getFeedBack();
												Gripper_infoFeedback();
												break;
  case CMD_DYNAMIC_ADAPTATION: 
												Gripper_dynamicAdaptation(
												jsonCmdReceive["mode"],
												jsonCmdReceive["g"]
												);break;
  case CMD_Gripper_open: 
												Gripper_open(
												jsonCmdReceive["spd"],
												jsonCmdReceive["acc"],
                        jsonCmdReceive["torque"]
												);break;
   case CMD_Gripper_close: 
												Gripper_close(
												jsonCmdReceive["spd"],
												jsonCmdReceive["acc"],
                        jsonCmdReceive["torque"]
												);break;
  case CMD_INFO_PRINT:	
                        configInfoPrint(
												jsonCmdReceive["cmd"]
												);break;
  case CMD_SET_MIDDLE:	
                        setMiddle(
												jsonCmdReceive["id"]
												);break;
  case CMD_SET_EleMode:	
                        setEleMode(
												jsonCmdReceive["id"],
                        jsonCmdReceive["tor"]
												);break;                                                                                                                                   
	}
}


void serialCtrl() {
  static String receivedData;

  while (Serial.available() > 0) {
    char receivedChar = Serial.read();
    receivedData += receivedChar;

    // Detect the end of the JSON string based on a specific termination character
    if (receivedChar == '\n') {
      // Now we have received the complete JSON string
      DeserializationError err = deserializeJson(jsonCmdReceive, receivedData);
      if (err == DeserializationError::Ok) {
  			if (InfoPrint == 1) {
  				Serial.println(receivedData);
  			}
        jsonCmdReceiveHandler();
      } else {
        // Handle JSON parsing error here
      }
      // Reset the receivedData for the next JSON string
      receivedData = "";
    }
  }
}