i2c: Implement open and close

Implement open() and close() function, and invoke open() on creating
I2CDevice, and invoke close() in destructor.

Tested: Manually write test codet and run on Witherspoon that it opens
        and closes the i2c device correctly.

Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: I709fcc80474a4a0cef067748a78256ceb76430a5
diff --git a/tools/i2c/i2c.cpp b/tools/i2c/i2c.cpp
index fdf0732..aa565b4 100644
--- a/tools/i2c/i2c.cpp
+++ b/tools/i2c/i2c.cpp
@@ -1,8 +1,28 @@
 #include "i2c.hpp"
 
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <cerrno>
+
 namespace i2c
 {
 
+void I2CDevice::open()
+{
+    fd = ::open(busStr.c_str(), O_RDWR);
+    if (fd == -1)
+    {
+        throw I2CException("Failed to open", busStr, devAddr, errno);
+    }
+}
+
+void I2CDevice::close()
+{
+    ::close(fd);
+}
+
 void I2CDevice::read(uint8_t& data)
 {
     // TODO