]> pilppa.com Git - lib1wire.git/commitdiff
Initial support for reading log-data.
authorMika Laitio <lamikr@pilppa.org>
Sun, 28 Nov 2010 11:37:11 +0000 (13:37 +0200)
committerMika Laitio <lamikr@pilppa.org>
Sun, 28 Nov 2010 11:37:11 +0000 (13:37 +0200)
It is now possible also to query the stored data for sensors.
The directory structure for storing and reading data was changed
from the previous version.

Signed-off-by: Mika Laitio <lamikr@pilppa.org>
23 files changed:
.cproject
.project
.settings/org.eclipse.ltk.core.refactoring.prefs [new file with mode: 0644]
configure.ac
src/Makefile.am
src/W1Configure.hh [new file with mode: 0644]
src/W1CounterDevice.cc
src/W1CounterDevice.hh
src/W1DataList.cc [new file with mode: 0644]
src/W1DataList.hh [new file with mode: 0644]
src/W1Device.cc
src/W1Device.hh
src/W1Scanner.cc
src/W1Scanner.hh
src/W1Store.cc
src/W1Store.hh
src/W1TemperatureSensor.cc
src/W1TemperatureSensor.hh
src/W1Util.cc [new file with mode: 0644]
src/W1Util.hh [new file with mode: 0644]
src_test/Makefile.am
src_test/test_w1.cc
src_test/test_w1_datalog_read.cc [new file with mode: 0644]

index 28280ce4390616e177d2af9a57be25fcd91f758c..26c3c24cf5eb003781a84d2f328868662832a90e 100644 (file)
--- a/.cproject
+++ b/.cproject
@@ -20,7 +20,7 @@
                                        <folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1197314700." name="/" resourcePath="">
                                                <toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.1864928771" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
                                                        <targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.693951810" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
-                                                       <builder buildPath="${workspace_loc:/lib1wire/Debug}" id="cdt.managedbuild.target.gnu.builder.exe.debug.75526737" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
+                                                       <builder buildPath="${workspace_loc:/lib1wire}" enableAutoBuild="false" enableCleanBuild="true" enabledIncrementalBuild="true" id="cdt.managedbuild.target.gnu.builder.exe.debug.75526737" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
                                                        <tool id="cdt.managedbuild.tool.gnu.archiver.base.532459675" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
                                                        <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1103546535" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
                                                                <option id="gnu.cpp.compiler.exe.debug.option.optimization.level.2116807624" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
@@ -48,6 +48,7 @@
                        </storageModule>
                        <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
                        <storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
+                       <storageModule moduleId="org.eclipse.cdt.core.language.mapping"/>
                        <storageModule moduleId="scannerConfiguration">
                                <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
                                <profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
                                                </scannerInfoProvider>
                                        </profile>
                                </scannerConfigBuildInfo>
-                               <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.1197314700;cdt.managedbuild.config.gnu.exe.debug.1197314700.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1103546535;cdt.managedbuild.tool.gnu.cpp.compiler.input.617172525">
+                               <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1622260442;cdt.managedbuild.config.gnu.exe.release.1622260442.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.1185874448;cdt.managedbuild.tool.gnu.cpp.compiler.input.541154833">
                                        <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
                                        <profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
                                                <buildOutputProvider>
                                                </scannerInfoProvider>
                                        </profile>
                                </scannerConfigBuildInfo>
-                               <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1622260442;cdt.managedbuild.config.gnu.exe.release.1622260442.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.1185874448;cdt.managedbuild.tool.gnu.cpp.compiler.input.541154833">
+                               <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.1197314700;cdt.managedbuild.config.gnu.exe.debug.1197314700.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1103546535;cdt.managedbuild.tool.gnu.cpp.compiler.input.617172525">
                                        <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
                                        <profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
                                                <buildOutputProvider>
index 5ab55168ea336fe19b797784d8853f0f33266c2a..c7ec9299e3868dec9a45f6c384352c3622813117 100644 (file)
--- a/.project
+++ b/.project
@@ -31,7 +31,7 @@
                                </dictionary>
                                <dictionary>
                                        <key>org.eclipse.cdt.make.core.buildLocation</key>
-                                       <value>${workspace_loc:/lib1wire/Debug}</value>
+                                       <value>${workspace_loc:/lib1wire}</value>
                                </dictionary>
                                <dictionary>
                                        <key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
diff --git a/.settings/org.eclipse.ltk.core.refactoring.prefs b/.settings/org.eclipse.ltk.core.refactoring.prefs
new file mode 100644 (file)
index 0000000..6e68364
--- /dev/null
@@ -0,0 +1,3 @@
+#Mon Nov 22 23:52:54 EET 2010
+eclipse.preferences.version=1
+org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
index 7be10618422ffae17f0a76779da032c9fb6e2f30..010f01f7a0a14de1fe118a37659a059098d75e9e 100644 (file)
@@ -5,7 +5,7 @@ AC_CONFIG_MACRO_DIR([m4])
 PACKAGE=lib1wire
 VERSION=0.1.0
 
-CFLAGS="$CFLAGS -g -Wall -Werror"
+CFLAGS="$CFLAGS -ggdb -Wall -Werror"
 LDFLAGS="$LDFLAGS"
 AC_SUBST(CFLAGS)
 AC_SUBST(LDFLAGS)
index f1fb5ca996bec9c5251522956fd870349e2ea609..8065dbad93b8d6c565805b2db5362af285855123 100644 (file)
@@ -4,7 +4,10 @@ lib1wire_la_SOURCES = \
        W1Scanner.cc W1Scanner.hh \
        W1Store.cc W1Store.hh \
        W1TemperatureSensor.cc W1TemperatureSensor.hh \
-       W1CounterDevice.cc W1CounterDevice.hh
+       W1CounterDevice.cc W1CounterDevice.hh \
+       W1Util.cc W1Util.hh \
+       W1DataList.cc W1DataList.hh \
+       W1Configure.hh
 lib1wire_la_LDFLAGS = $(SRC_LIBS) $(all_libraries) -version-info 1:0:0 -no-undefined
 AM_CPPFLAGS = $(SRC_CFLAGS) -Iidl
 
diff --git a/src/W1Configure.hh b/src/W1Configure.hh
new file mode 100644 (file)
index 0000000..0d02eb2
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * W1Configure.hh
+ *
+ *  Created on: Nov 14, 2010
+ *      Author: lamikr
+ */
+
+#ifndef W1CONFIGURE_HH_
+#define W1CONFIGURE_HH_
+
+#define DEFAULT_STORAGE_BASE_DIR       "/tmp"
+#define DATAFILE_SUFFIX                        ".txt"
+
+#endif /* W1CONFIGURE_HH_ */
index 2566e1d4888114c0ccad31f28965a510948f39a0..4f500e9007f4bcf4a9e2bbbb116dda8d88589e17 100644 (file)
@@ -17,14 +17,12 @@ W1CounterDevice::W1CounterDevice(dirent *direntry,
                                int family_code_param,
                                string id_param): W1Device(direntry, family_code_param, id_param) {
        ifstream ifs(slave_file.c_str());
-       if (ifs.is_open() == false) {
+       if (ifs.is_open() == true) {
                string text;
 
                text    = get_time() + ": device type = " + get_devicetype_name() + ", id = " + id + ", could not read file: " + slave_file;
                cout << text << endl;
                cout << "verify that you have w1_ds2423 kernel module loaded." << endl;
-       }
-       else {
                ifs.close();
        }
 }
@@ -45,7 +43,7 @@ bool W1CounterDevice::is_supported_family_code(int family_code) {
        return ret_val;
 }
 
-string W1CounterDevice::get_value() {
+string W1CounterDevice::get_raw_value() {
        string          ret_val;
        string          value_line;
        int             pos;
index 816f3b823f51150f415e9638a86d201b6caf7465..b2080e044a680039bc9cdd18ed2aea62c8b433ff 100644 (file)
@@ -15,7 +15,7 @@ namespace w1 {
                public:
                        W1CounterDevice(dirent *direntry, int family_code_param, std::string id_param);
                        virtual ~W1CounterDevice();
-                       std::string get_value();
+                       std::string get_raw_value();
                        std::string get_unit();
                        std::string get_devicetype_name();
                protected:
diff --git a/src/W1DataList.cc b/src/W1DataList.cc
new file mode 100644 (file)
index 0000000..3d04f95
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * W1DataList.cc
+ *
+ *  Created on: Nov 7, 2010
+ *      Author: lamikr
+ */
+#include <dirent.h>
+#include <malloc.h>
+
+#include "W1Util.hh"
+#include "W1DataList.hh"
+#include "W1Store.hh"
+
+using namespace w1;
+using namespace std;
+
+Data::~Data() {
+       free(date_time);
+}
+
+DataRange::~DataRange() {
+       if (first_data != NULL) {
+               delete(first_data);
+               first_data      = NULL;
+       }
+       if (last_data != NULL) {
+               delete(last_data);
+               last_data       = NULL;
+       }
+}
+
+W1DataList::W1DataList(string device_id_param) {
+       string          base_dir;
+
+       device_id       = device_id_param;
+       base_dir        = W1Store::get_location_base_dir();
+       device_dir      = W1Util::concat_paths(base_dir.c_str(), device_id.c_str());
+}
+
+W1DataList::~W1DataList() {
+       //delete(device_dir);
+}
+
+Data *W1DataList::find_first_data(vector<string> year_vector) {
+       int             ii;
+       string          year_dir;
+       string          month_dir;
+       vector<string>  month_vector;
+       vector<string>  data_vector;
+       string          first_file;
+       Data            *ret_val;
+
+       ret_val = NULL;
+       if (year_vector.size() > 0) {
+               // dirs are alphabetically sorted
+               year_dir        = year_vector.at(0);
+               year_dir        = W1Util::concat_paths(device_dir.c_str(), year_dir.c_str());
+               month_vector    = W1Util::get_subdirectories(year_dir);
+               for (ii = 0; ii < month_vector.size(); ii++) {
+                       month_dir       = month_vector.at(ii);
+                       month_dir       = W1Util::concat_paths(year_dir.c_str(), month_dir.c_str());
+                       // scan data files from month dir
+                       data_vector     = W1Util::get_data_files(month_dir);
+                       if (data_vector.size() > 0) {
+                               first_file      = data_vector.at(0);
+                               first_file      = W1Util::concat_paths(month_dir.c_str(), first_file.c_str());
+                               ret_val         = W1Util::load_first_data_row(first_file.c_str());
+                               break;
+                       }
+               }
+       }
+       return ret_val;
+}
+
+Data *W1DataList::find_last_data(vector<string> year_vector) {
+       int             ii;
+       string          year_dir;
+       string          month_dir;
+       vector<string>  month_vector;
+       vector<string>  data_vector;
+       string          last_file;
+       Data            *ret_val;
+       int             size;
+
+       ret_val = NULL;
+       size    = year_vector.size();
+       if (size > 0) {
+               // dirs are alphabetically sorted
+               year_dir        = year_vector.at(size - 1);
+               year_dir        = W1Util::concat_paths(device_dir.c_str(), year_dir.c_str());
+               month_vector    = W1Util::get_subdirectories(year_dir);
+               for (ii = month_vector.size() - 1; ii >= 0; ii--) {
+                       month_dir       = month_vector.at(ii);
+                       month_dir       = W1Util::concat_paths(year_dir.c_str(), month_dir.c_str());
+                       // scan data files from month dir
+                       data_vector     = W1Util::get_data_files(month_dir);
+                       size    = data_vector.size();
+                       if (size > 0) {
+                               last_file       = data_vector.at(size - 1);
+                               last_file       = W1Util::concat_paths(month_dir.c_str(), last_file.c_str());
+                               ret_val         = W1Util::load_last_data_row(last_file.c_str());
+                               break;
+                       }
+               }
+       }
+       return ret_val;
+}
+
+DataRange *W1DataList::get_data_range() {
+       DataRange       *ret_val;
+       DIR             *data_dir;
+       struct dirent   *year_dirent;
+       vector<string>  year_list;
+       Data            *first_data;
+       Data            *last_data;
+
+       ret_val         = NULL;
+       year_list       = W1Util::get_subdirectories(device_dir);
+       first_data      = find_first_data(year_list);
+       if (first_data != NULL) {
+               last_data       = find_last_data(year_list);
+               if (last_data != NULL) {
+                       ret_val = new DataRange();
+                       ret_val->first_data     = first_data;
+                       ret_val->last_data      = last_data;
+               }
+       }
+       return ret_val;
+}
diff --git a/src/W1DataList.hh b/src/W1DataList.hh
new file mode 100644 (file)
index 0000000..7823876
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * W1DataList.hh
+ *
+ *  Created on: Nov 7, 2010
+ *      Author: lamikr
+ */
+
+#ifndef W1DATALIST_H_
+#define W1DATALIST_H_
+
+#include <string>
+#include <vector>
+#include <time.h>
+
+struct Data {
+       public:
+               virtual ~Data();
+               struct tm               *date_time;
+               std::vector<double>     data_list;
+};
+
+struct DataRange {
+       public:
+               virtual ~DataRange();
+               Data    *first_data;
+               Data    *last_data;
+};
+
+namespace w1 {
+       class W1DataList {
+               public:
+                       W1DataList(std::string device_id);
+                       virtual ~W1DataList();
+                       DataRange *get_data_range();
+               protected:
+                       std::string     device_id;
+                       std::string     device_dir;
+                       Data *find_first_data(std::vector<std::string> year_vector);
+                       Data *find_last_data(std::vector<std::string> year_vector);
+
+       };
+}
+
+#endif /* W1DATALIST_H_ */
index bc86d830fc6580c786d142f173f423a06151f138..843910ac9764bca9a59257ce25eebbd0411399c7 100644 (file)
@@ -66,20 +66,20 @@ string W1Device::get_time() {
 void W1Device::printout() {
        string text;
 
-       text    = get_formatted_data();
+       text    = get_formatted_value();
        cout << text << endl;
 }
 
-string W1Device::get_formatted_data() {
+string W1Device::get_formatted_value() {
        string ret_val;
        string val;
 
-       val     = get_value();
-       ret_val = get_formatted_data(val);
+       val     = get_raw_value();
+       ret_val = get_formatted_value(val);
        return ret_val;
 }
 
-string W1Device::get_formatted_data(string value) {
+string W1Device::get_formatted_value(string value) {
        string ret_val;
 
        ret_val = get_time() + "|" + get_devicetype_name() + "|" + id + "|" + value + " " + get_unit();
index 15deba21b7d09bd7210a43792b28cfecf6e8eb69..9eab016288075cb646072d383654465b900728a3 100644 (file)
@@ -31,7 +31,8 @@ namespace w1 {
                        std::string get_id();
                        std::string get_name();
                        void set_name(std::string name_param);
-                       virtual std::string get_value() = 0;
+                       virtual std::string get_raw_value() = 0;
+                       std::string get_formatted_value();
                        virtual std::string get_unit() = 0;
                        virtual std::string get_devicetype_name() = 0;
                        std::string get_time();
@@ -39,8 +40,7 @@ namespace w1 {
                        virtual void store();
                protected:
                        void add_to_memory_cache(std::string formatted_data);
-                       std::string get_formatted_data();
-                       std::string get_formatted_data(std::string value);
+                       std::string get_formatted_value(std::string value);
                        virtual bool is_supported_family_code(int family_code) = 0;
                        int family_code;
                        std::string id;
index a27b23d5d41430c749f26e23b0521bd70f858a01..390c2510576f4267747b6ef5064d76a1b4bd93ae 100644 (file)
@@ -13,6 +13,8 @@
 #include <iostream>
 
 #include <plp/log.h>
+
+#include "W1Util.hh"
 #include "W1Scanner.hh"
 #include "W1TemperatureSensor.hh"
 #include "W1CounterDevice.hh"
 using namespace w1;
 using namespace std;
 
-W1Scanner::W1Scanner() {
-       log_debug("created\n");
-}
-
-W1Scanner::~W1Scanner() {
-       log_debug("destroyed\n");
-}
-
-bool W1Scanner::is_subdirectory(dirent *direntry) {
-       bool ret_val    = true;
-       if (strcmp(direntry->d_name, ".") == 0 ||
-               (strcmp(direntry->d_name, "..") == 0)) {
-                       ret_val = false;
-       }
-       return ret_val;
-}
-
-template <class T>
-bool string_to_number(T& result,
+template <class NumberDataType>
+bool string_to_number(NumberDataType& result,
                  const std::string& string_param,
                  std::ios_base& (*format)(std::ios_base&))
 {
@@ -46,35 +31,45 @@ bool string_to_number(T& result,
        return !(iss >> format >> result).fail();
 }
 
+W1Scanner::W1Scanner() {
+       log_debug("W1Scanner created\n");
+}
+
+W1Scanner::~W1Scanner() {
+}
+
 W1Device *W1Scanner::create_device(dirent *direntry) {
        string          folder_name;
-       string          temp_str;
+       string          tmp_str;
        string          device_name;
        int             pos;
-       int                     family_code;
-       bool            sucFlg;
+       int             family_code;
+       bool            suc_flg;
        W1Device        *ret_val;
 
        ret_val         = NULL;
        folder_name     = direntry->d_name;
-       pos                     = folder_name.find("-");
+       pos             = folder_name.find("-");
        if (pos > 0) {
-               temp_str        = folder_name.substr(0, pos);
+               tmp_str = folder_name.substr(0, pos);
                // number in string is in hex format, convert to int
-               sucFlg          = string_to_number<int>(family_code, temp_str, hex);
-               if (sucFlg == true) {
-                       cout << "family_code: " << family_code << endl;
+               suc_flg = string_to_number<int>(family_code, tmp_str, hex);
+               if (suc_flg == true) {
+                       log_debug("family_code: %d\n", family_code);
                        device_name     = folder_name.substr(pos + 1, folder_name.length() - pos);
                        switch(family_code) {
                                case    0x10:
                                case    0x28:
-                                       cout << "temperature sensor: " << family_code << endl;
                                        ret_val = new W1TemperatureSensor(direntry, family_code, device_name);
+                                       log_debug("temperature sensor: %d\n", ret_val->get_family_code());
                                        break;
                                case    0x1d:
-                                       cout << "counter device: " << family_code << endl;
+                                       log_debug("counter device: %d\n", family_code);
                                        ret_val = new W1CounterDevice(direntry, family_code, device_name);
                                        break;
+                               default:
+                                       log_debug("device not created the device, unsupported device type: %d\n", family_code);
+                                       break;
                        }
                }
        }
@@ -87,17 +82,24 @@ list<W1Device *> W1Scanner::get_device_list() {
        struct dirent           *direntry;
        W1Device                *device;
        list<W1Device *>        ret_val;
+       bool                    is_subdir;
 
+       printf("get_device_list() started\n");
        dir     = opendir(W1_SCAN_ROOTDIR);
        if (dir != NULL) {
                direntry        = readdir(dir);
                while(direntry != NULL) {
-                       if (is_subdirectory(direntry) == true) {
-                               log_debug("dir_name: %s\n", direntry->d_name);
+                       is_subdir       = W1Util::is_subdirectory(W1_SCAN_ROOTDIR, direntry);
+                       if (is_subdir == true) {
+                               log_info("dir_name: %s\n", direntry->d_name);
                                device  = create_device(direntry);
                                if (device != NULL) {
+                                       log_info("device: %d\n", device->get_family_code());
                                        ret_val.push_back(device);
                                }
+                               else {
+                                       log_info("unsupported device-directory: %s\n", direntry->d_name);
+                               }
                        }
                        direntry        = readdir(dir);
                }
index 2369948d53179dee44ff3a0e2dc052cceb293e10..c5e55294f451867423846d69b6ab10e4caa001ec 100644 (file)
@@ -27,7 +27,6 @@ namespace w1 {
                private:
                        //int parse_family_code(std::string folder_name);
                        W1Device *create_device(dirent *direntry);
-                       bool is_subdirectory(dirent *direntry);
        };
 }
 
index a6bbaa0b1be78a7ee650fcfa4e7d5061c20139dd..f40623e6c3a9ff3b2268d984a68d871727dc6be7 100644 (file)
@@ -7,7 +7,6 @@
 
 #include <list>
 #include <string>
-#include <iostream>
 #include <fstream>
 
 #include <time.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include <plp/log.h>
+
+#include "W1Configure.hh"
 #include "W1Store.hh"
+#include "W1Util.hh"
 
 using namespace std;
 using namespace w1;
 
-std::string W1Store::location = "/tmp/";
+#define DIR_BUFFER_SIZE        20
+
+std::string W1Store::location_base_dir = DEFAULT_STORAGE_BASE_DIR;
+
 
 W1Store::W1Store() {
        // TODO Auto-generated constructor stub
@@ -31,66 +37,80 @@ W1Store::~W1Store() {
        // TODO Auto-generated destructor stub
 }
 
-void W1Store::set_location(string location_param) {
-       string::size_type pos;
+void W1Store::set_location_base_dir(string location_param) {
+       int     pos;
+       int     b_count;
 
-       location        = location_param;
-       pos             = location.find_last_of("/");
-       if (pos != location.length()) {
-               location        = location + "/";
+       pos     = location_param.find_last_of("/");
+       b_count = location_param.length();
+       if (pos == (b_count - 1)) {
+               location_base_dir       = location_param;
        }
+       else {
+               location_base_dir       = location_param + "/";
+       }
+}
 
+string W1Store::get_location_base_dir() {
+       return location_base_dir;
 }
 
-void W1Store::store(std::string device_id, std::list<std::string> *string_list) {
+string W1Store::get_location_dir(string device_id, struct tm *ltime) {
+       char    buffer[DIR_BUFFER_SIZE];
+       string  year;
+       string  month;
+       string  ret_val;
+
+       strftime(buffer, DIR_BUFFER_SIZE, "%Y", ltime);
+       year    = buffer;
+       strftime(buffer, DIR_BUFFER_SIZE, "%m", ltime);
+       month   = buffer;
+       ret_val = W1Util::concat_paths(location_base_dir, device_id);
+       ret_val = ret_val + "/" + year + "/" + month;
+       return ret_val;
+}
 
-       string file_path;
-       string text_line;
+string W1Store::get_location_file(string device_id, struct tm *ltime) {
+       char    buffer[DIR_BUFFER_SIZE];
+       string  ret_val;
 
+       strftime(buffer, DIR_BUFFER_SIZE, "%Y-%m-%d", ltime);
+       ret_val = get_location_dir(device_id, ltime);
+       ret_val = ret_val + "/" + buffer + DATAFILE_SUFFIX;
+       return ret_val;
+}
+
+void W1Store::store(std::string device_id, std::list<std::string> *string_list) {
+       string          f_path;
+       string          line;
        time_t          wtime;
        struct tm       *ltime;
-       char            buffer[80];
-       string          year;
-       string          month;
-       string          date;
+       ofstream        *ostream;
 
        time(&wtime);
        ltime   = localtime(&wtime);
-       strftime(buffer, 80, "%Y", ltime);
-       year    = buffer;
-       strftime(buffer, 80, "%m", ltime);
-       month   = buffer;
-       strftime(buffer, 80, "%Y-%m-%d", ltime);
-       date    = buffer;
-
-       struct tm * gmtime(const time_t *timer);
-       struct tm * localtime(const time_t * timer);
-       struct stat st;
-
-       file_path       = location + year;
-       if (stat(file_path.c_str() ,&st) != 0) {
-               mkdir(file_path.c_str(), 0755);
-       }
-       file_path       = file_path + "/" + month;
-       if (stat(file_path.c_str() ,&st) != 0) {
-               mkdir(file_path.c_str(), 0755);
-       }
-       file_path       = file_path + "/" + device_id + "_" + date + ".txt";
-       ofstream data_file(file_path.c_str(), ios::app);
-       cout << "storing to " << file_path << ", data size " << string_list->size() << endl;
+       f_path  = get_location_file(device_id, ltime);
+       ostream = W1Util::open_for_writing(f_path.c_str());
        // TODO: add mutex to protect string_list while it's read and emptied
-       if (data_file.is_open()) {
-               while(string_list->size() > 0) {
-                       text_line       = string_list->front();
-                       string_list->pop_front();
-                       if (text_line.length() > 0) {
-                               cout << "storing line: " << text_line << endl;
-                               data_file << text_line << endl;
+       if (ostream != NULL) {
+               if (ostream->is_open()) {
+                       log_info("[%s] writing %d data values to file: %s\n", device_id.c_str(), string_list->size(), f_path.c_str());
+                       while(string_list->size() > 0) {
+                               line    = string_list->front();
+                               string_list->pop_front();
+                               if (line.length() > 0) {
+                                       log_debug("storing line: %s\n", line.c_str());
+                                       *ostream << line << endl;
+                               }
                        }
+                       ostream->close();
+               }
+               else {
+                       log_error("[%s] Could not store data to file: %s\n", device_id.c_str(), f_path.c_str());
                }
-               data_file.close();
+               delete(ostream);
        }
        else {
-               cout << "could not open file " << file_path << " for writing data." << endl;
+               log_error("[%s] Could not store data to file: %s\n", device_id.c_str(), f_path.c_str());
        }
 }
index c096816533e5f9c07bdb2d38ddc5c59910944a55..396b419d005d5d6ca89bcb6175ccbc8d3428b76e 100644 (file)
@@ -16,9 +16,13 @@ namespace w1 {
                public:
                        W1Store();
                        virtual ~W1Store();
-                       static std::string location;
-                       static void set_location(std::string location_param);
+                       static std::string get_location_base_dir();
+                       static void set_location_base_dir(std::string location_param);
+                       static std::string get_location_dir(std::string device_id, struct tm *ltime);
+                       static std::string get_location_file(std::string device_id, struct tm *ltime);
                        static void store(std::string device_id, std::list<std::string> *string_list);
+               protected:
+                       static std::string location_base_dir;
        };
 }
 
index b5445c3e58ed309a96065e1b3eb0e92574d7a9af..bfa72912943e0b9daf942c6d68f55b3b3a6eb8ad 100644 (file)
@@ -9,13 +9,16 @@
 #include <sstream>
 #include <iomanip>
 
+#include "W1Util.hh"
 #include "W1TemperatureSensor.hh"
 
+#include <plp/log.h>
+
 using namespace std;
 using namespace w1;
 
-template <class T>
-bool string_to_number(T& result,
+template <class NumberDataType>
+bool string_to_number(NumberDataType& result,
                  const std::string& string_param,
                  std::ios_base& (*format)(std::ios_base&))
 {
@@ -23,14 +26,14 @@ bool string_to_number(T& result,
        return !(iss >> format >> result).fail();
 }
 
-string convert_for_3_digits_value(string raw_value) {
+string convert_celcius_value_to_three_digits(string raw_value) {
        string  ret_val;
-       int             int_val;
-       bool    sucFlg;
+       int     int_val;
+       bool    suc_flg;
        double  dbl_val;
 
-       sucFlg          = string_to_number<double>(dbl_val, raw_value, dec);
-       if (sucFlg == true) {
+       suc_flg = string_to_number<double>(dbl_val, raw_value, dec);
+       if (suc_flg == true) {
                dbl_val = dbl_val / 1000;
                std::ostringstream out;
                out << fixed << setprecision(3) << dbl_val;
@@ -42,16 +45,17 @@ string convert_for_3_digits_value(string raw_value) {
        return ret_val;
 }
 
-W1TemperatureSensor::W1TemperatureSensor(dirent *direntry, int family_code_param, string id_param): W1Device(direntry, family_code_param, id_param) {
+W1TemperatureSensor::W1TemperatureSensor(dirent *direntry,
+                               int family_code_param,
+                               string id_param): W1Device(direntry, family_code_param, id_param) {
+       log_debug("trying to open file: %s\n", slave_file.c_str());
        ifstream ifs(slave_file.c_str());
        if (ifs.is_open() == false) {
                string text;
 
-               text    = get_time() + ": device type = " + get_devicetype_name() + ", id = " + id + ", could not read file: " + slave_file;
-               cout << text << endl;
-               cout << "verify that you have w1_therm kernel module loaded." << endl;
-       }
-       else {
+               text    = get_time() + ": device type = " + get_devicetype_name() + ", id = " + id + ", could not read file: " + slave_file + "\n";
+               log_debug(text.c_str());
+               log_debug("verify that you have w1_therm kernel module loaded.\n");
                ifs.close();
        }
 }
@@ -72,7 +76,7 @@ bool W1TemperatureSensor::is_supported_family_code(int family_code) {
        return ret_val;
 }
 
-string W1TemperatureSensor::get_value() {
+string W1TemperatureSensor::get_raw_value() {
        string          temp;
        string          ret_val;
        string          last_line;
@@ -87,20 +91,19 @@ string W1TemperatureSensor::get_value() {
                while(getline(ifs, temp)) {
                        if (temp.length() > 0) {
                                last_line       = temp;
-                               //cout << ret_val << endl;
                        }
                }
                ifs.close();
                length  = last_line.length();
                if (length > 0) {
-                       pos             = last_line.find("t=");
+                       pos     = last_line.find("t=");
                        if ((pos >= 0) &&
                                (pos + 2 < length)) {
                                ret_val = last_line.substr(pos + 2);
                        }
                }
        }
-       ret_val         = convert_for_3_digits_value(ret_val);
+       ret_val = convert_celcius_value_to_three_digits(ret_val);
        return ret_val;
 }
 
@@ -111,18 +114,3 @@ string W1TemperatureSensor::get_unit() {
 string W1TemperatureSensor::get_devicetype_name() {
        return "Temperature Sensor";
 }
-/*
-void W1TemperatureSensor::printout() {
-       string text;
-
-       text    = get_formatted_data();
-       cout << text << endl;
-}
-
-string W1TemperatureSensor::get_formatted_data() {
-       string ret_val;
-
-       ret_val = get_time() + ": device type = temperature sensor, id = " + id + ", value = " + get_value() + " " + get_unit();
-       return ret_val;
-}
-*/
index bf55522f963f81c4eab8b40531f1d6bd82ca31b3..f5235d63c88399116ada28e4ad508c0d0d4421ec 100644 (file)
@@ -15,7 +15,7 @@ namespace w1 {
                public:
                        W1TemperatureSensor(dirent *direntry, int family_code_param, std::string id_param);
                        virtual ~W1TemperatureSensor();
-                       std::string get_value();
+                       std::string get_raw_value();
                        std::string get_unit();
                        std::string get_devicetype_name();
                protected:
diff --git a/src/W1Util.cc b/src/W1Util.cc
new file mode 100644 (file)
index 0000000..001f9f6
--- /dev/null
@@ -0,0 +1,385 @@
+/*
+ * W1Util.cc
+ *
+ *  Created on: Nov 14, 2010
+ *      Author: lamikr
+ */
+#include <algorithm>
+#include <string>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+
+#include <errno.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <stdbool.h>
+
+#include <plp/log.h>
+
+#include "W1Util.hh"
+#include "W1Configure.hh"
+
+using namespace std;
+using namespace w1;
+
+template <class NumberDataType>
+bool string_to_number(NumberDataType& result,
+                 const std::string& string_param,
+                 std::ios_base& (*format)(std::ios_base&))
+{
+       std::istringstream iss(string_param);
+       return !(iss >> format >> result).fail();
+}
+
+W1Util::W1Util() {
+}
+
+W1Util::~W1Util() {
+}
+
+void W1Util::printout_date(struct tm *date_time) {
+       cout << "date: " << date_time->tm_year << " " << date_time->tm_mon << " " << date_time->tm_mday << " " << date_time->tm_hour << " " << date_time->tm_min << " " << date_time->tm_sec << endl;
+}
+
+void W1Util::printout_data(Data *data) {
+       int     ii;
+       if (data != NULL) {
+               printout_date(data->date_time);
+               for (ii = 0; ii < data->data_list.size(); ii++) {
+                       log_debug("  data[%d] = %f\n", ii, data->data_list.at(ii));
+               }
+       }
+}
+
+char *W1Util::parse_directory_path(const char *file_path) {
+       char    *p;
+       size_t  b_count;
+       size_t  f_size;
+       char    *ret_val;
+
+       ret_val = NULL;
+       if (file_path != NULL) {
+               f_size  = 0;
+               b_count = strlen(file_path);
+               for (p = &((char *)file_path)[b_count]; p != (char *)file_path; p--) {
+                       f_size++;
+                       if ((*p == '/') ||
+                           (*p == '\\')) {
+                               b_count = (b_count - f_size) + 1;
+                               ret_val = strndup(file_path, b_count);
+                               log_debug("dir: %s\n", ret_val);
+                               break;
+                       }
+               }
+       }
+       return ret_val;
+}
+
+bool W1Util::mkdirs(char *path) {
+       bool    ret_val;
+       char    *p;
+       int     err_flg;
+
+       ret_val = true;
+       if (path != NULL) {
+               // go through each directory one by and and create if not exist
+               for (p = path; *p; p++) {
+                   if ((p != path) &&
+                       ((*p == '/') ||
+                        (*p == '\\'))) {
+                               *p = '\0';
+                               // test whether directory exist and is writable
+                               if (access(path, F_OK)) {
+                                       log_debug("trying to create directory: %s\n", path);
+                                       err_flg = mkdir(path, S_IRWXU);
+                                       if (err_flg != 0) {
+                                               ret_val = false;
+                                               break;
+                                       }
+                               }
+                               *p = '/';
+                       }
+               }
+               if (ret_val == true) {
+                       // test also the existense of whole directory
+                       if (access(path, F_OK)) {
+                               log_debug("trying to create directory: %s\n", path);
+                               err_flg = mkdir(path, S_IRWXU);
+                               if (err_flg != 0) {
+                                       ret_val = false;
+                               }
+                       }
+               }
+       }
+       else {
+               ret_val = false;
+               log_error("Could not create NULL directory\n");
+       }
+       return ret_val;
+}
+
+std::ofstream *W1Util::open_for_writing(const char *f_path) {
+       char            *d_path;
+       char            *p;
+       size_t          b_count;
+       int             ii;
+       ofstream        *ret_val;
+       bool            b_flg;
+
+       ret_val = NULL;
+       if (f_path != NULL) {
+               b_count = strlen(f_path);
+               if ((f_path[b_count - 1] != '/') &&
+                   (f_path[b_count - 1] != '\\')) {
+                       ret_val = new ofstream();
+                       ret_val->open(f_path, ios::app);
+                       if (ret_val->is_open() == false) {
+                               d_path  = parse_directory_path(f_path);
+                               if (d_path != NULL) {
+                                       b_flg   = mkdirs(d_path);
+                                       free(d_path);
+                               }
+                               if (b_flg == true) {
+                                       ret_val->open(f_path, ios::app);
+                               }
+                       }
+               }
+               else {
+                       log_error("Could not open file, invalid file name. (%s)\n", f_path);
+               }
+       }
+       else {
+               log_error("Could not open file, invalid file name. (= NULL)\n");
+       }
+       return ret_val;
+}
+
+string W1Util::concat_paths(string path_start, string path_end) {
+       return concat_paths(path_start.c_str(), path_end.c_str());
+}
+
+string W1Util::concat_paths(const char *path_start, const char *path_end) {
+       string  ret_val;
+       string  end_str;
+       int     pos;
+       int     b_count;
+
+       if (path_start != NULL) {
+               ret_val = path_start;
+               if (path_end != NULL) {
+                       end_str = path_end;
+                       b_count = ret_val.length();
+                       pos     = ret_val.find_last_of("/");
+                       if (pos == (b_count -1)) {
+                               ret_val.append(end_str);
+                       }
+                       else {
+                               pos     = end_str.find_first_of("/");
+                               if (pos == 0) {
+                                       ret_val.append(end_str);
+                               }
+                               else {
+                                       ret_val.append("/");
+                                       ret_val.append(end_str);
+                               }
+                       }
+               }
+       }
+       else {
+               if (path_end != NULL) {
+                       ret_val = path_end;
+               }
+       }
+       return ret_val;
+}
+
+bool W1Util::is_subdirectory(const char *path, dirent *direntry) {
+       bool            ret_val;
+       struct stat     stat_info;
+       string          fname;
+
+       ret_val = false;
+       if (direntry != NULL) {
+               if ((strcmp(direntry->d_name, ".") == 0) ||
+                   (strcmp(direntry->d_name, "..") == 0)) {
+                       ret_val = false;
+               }
+               else {
+                       fname   = concat_paths(path, direntry->d_name);
+                       stat(fname.c_str(), &stat_info);
+                       ret_val = S_ISDIR(stat_info.st_mode);
+                       //log_debug("stat for: %s: %d\n", fname.c_str(), ret_val);
+               }
+       }
+       return ret_val;
+}
+
+bool W1Util::is_datafile(const char *path, dirent *direntry) {
+       bool            ret_val;
+       struct stat     stat_info;
+       string          name;
+       int             pos;
+       string          fname;
+
+       ret_val = false;
+       if (direntry != NULL) {
+               name    = direntry->d_name;
+               pos     = name.find(DATAFILE_SUFFIX);
+               if (pos > 0) {
+                       fname   = concat_paths(path, direntry->d_name);
+                       stat(fname.c_str(), &stat_info);
+                       ret_val = S_ISREG(stat_info.st_mode);
+               }
+       }
+       return ret_val;
+}
+
+/**
+ * get sub-directories sorted in alphabetical order.
+ */
+vector<string> W1Util::get_subdirectories(const string& path) {
+       dirent          *direntry;
+       DIR             *dir;
+       bool            bool_flg;
+       vector<string>  ret_val;
+
+       log_debug("scanning path: %s\n", path.c_str());
+       errno   = 0;
+       if (path.empty() == false) {
+               dir     = opendir(path.c_str());
+               if (dir) {
+                       while (true) {
+                               errno           = 0;
+                               direntry        = readdir(dir);
+                               if (direntry != NULL) {
+                                       bool_flg        = is_subdirectory(path.c_str(), direntry);
+                                       if (bool_flg == true) {
+                                               ret_val.push_back(string(direntry->d_name));
+                                               //log_debug("added dir: %s\n", direntry->d_name);
+                                       }
+                               }
+                               else {
+                                       break;
+                               }
+                       }
+                       closedir(dir);
+                       sort(ret_val.begin(), ret_val.end());
+               }
+       }
+       return ret_val;
+}
+
+/**
+ * get sub-directories sorted in alphabetical order.
+ */
+vector<string> W1Util::get_data_files(const string& path) {
+       dirent          *direntry;
+       DIR             *dir;
+       vector<string>  ret_val;
+
+       errno   = 0;
+       if (path.empty() == false) {
+               dir     = opendir(path.c_str());
+               if (dir) {
+                       while (true) {
+                               errno           = 0;
+                               direntry        = readdir(dir);
+                               if (direntry != NULL) {
+                                       if (is_datafile(path.c_str(), direntry) == true) {
+                                               ret_val.push_back(string(direntry->d_name));
+                                       }
+                               }
+                               else {
+                                       break;
+                               }
+                       }
+                       closedir(dir);
+                       sort(ret_val.begin(), ret_val.end());
+               }
+       }
+       return ret_val;
+}
+
+struct tm *W1Util::parse_date_str(string date_str) {
+       stringstream ss(date_str);
+       struct tm *ret_val = NULL;
+
+       //ss << "2007-07-19 17:18:01";
+       int year;
+       int month;
+       int day;
+       int hour;
+       int min;
+       int sec;
+       char c;
+
+       ret_val = (struct tm*)malloc(sizeof(struct tm));
+       ss >>ret_val->tm_year >>c >>ret_val->tm_mon >>c >>ret_val->tm_mday >>ret_val->tm_hour >>c >>ret_val->tm_min >>c >>ret_val->tm_sec;
+       mktime(ret_val);
+       //printout_date(ret_val);
+       return ret_val;
+}
+
+Data *W1Util::parse_data_line(const string& dataline) {
+       stringstream    ss(dataline);
+       string          item;
+       double          dbl;
+       Data            *ret_val;
+       int             ii;
+       bool            suc_flg;
+
+       ret_val = new Data();
+       ii      = 0;
+       while(getline(ss, item, '|')) {
+               if (ii == 0) {
+                       // parse date
+                       ret_val->date_time      = parse_date_str(item);
+               }
+               else if (ii == 1) {
+                       // skip the device type for now.Maybe better to store only once under the year dir...
+               }
+               else if (ii >= 2) {
+                       suc_flg = string_to_number<double>(dbl, item, dec);
+                       if (suc_flg) {
+                               ret_val->data_list.push_back(dbl);
+                       }
+               }
+               ii++;
+       }
+       return ret_val;
+}
+
+Data *W1Util::load_first_data_row(const string& datafile_path) {
+       Data            *ret_val;
+       ifstream        in;
+       string          line;
+
+       ret_val = NULL;
+       in.open(datafile_path.c_str());
+       if (in.eof() == false) {
+               getline(in, line);
+               ret_val = parse_data_line(line);
+       }
+       return ret_val;
+}
+
+Data *W1Util::load_last_data_row(const string& datafile_path) {
+       Data            *ret_val;
+       ifstream        in;
+       string          line;
+       string          prev_line;
+
+       ret_val = NULL;
+       in.open(datafile_path.c_str());
+       while (in.eof() == false) {
+               getline(in, line);
+               if (line.empty() == false) {
+                       prev_line       = line;
+               }
+       }
+       if (prev_line.empty() == false) {
+               ret_val = parse_data_line(prev_line);
+       }
+       return ret_val;
+}
diff --git a/src/W1Util.hh b/src/W1Util.hh
new file mode 100644 (file)
index 0000000..57a7daf
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * W1Util.hh
+ *
+ *  Created on: Nov 14, 2010
+ *      Author: lamikr
+ */
+
+#ifndef W1UTIL_HH_
+#define W1UTIL_HH_
+
+#include <fstream>
+#include <string>
+#include <vector>
+
+#include <stdbool.h>
+#include <dirent.h>
+#include <stdbool.h>
+
+#include "W1DataList.hh"
+
+namespace w1 {
+       class W1Util {
+               public:
+                       W1Util();
+                       virtual ~W1Util();
+                       static std::string concat_paths(std::string path_start, std::string path_end);
+                       static std::string concat_paths(const char *path_start, const char *path_end);
+                       static bool is_subdirectory(const char *path, dirent *direntry);
+                       static bool is_datafile(const char *path, dirent *direntry);
+                       static std::vector<std::string> get_subdirectories(const std::string& path);
+                       static std::vector<std::string> get_data_files(const std::string& path);
+                       static struct tm *parse_date_str(std::string date_str);
+                       static Data *parse_data_line(const std::string& dataline);
+                       static Data *load_first_data_row(const std::string& datafile_path);
+                       static Data *load_last_data_row(const std::string& datafile_path);
+                       static void printout_date(struct tm *date_time);
+                       static void printout_data(Data *data);
+                       static char *parse_directory_path(const char *file_path);
+                       static bool mkdirs(char *path);
+                       static std::ofstream *open_for_writing(const char *path);
+       };
+}
+
+#endif /* W1UTIL_HH_ */
index f7bc8361136ea3fba4c3c9a3b7167592c43bd290..27a5c41cceb8935dff726856e5e600397fd12546 100644 (file)
@@ -1,8 +1,13 @@
-noinst_PROGRAMS = test_w1
+noinst_PROGRAMS = \
+               test_w1\
+               test_w1_datalog_read 
 
 test_w1_SOURCES = test_w1.cc
 test_w1_LDADD = $(SRC_LIBS) ../src/.libs/lib1wire.a
 
+test_w1_datalog_read_SOURCES = test_w1_datalog_read.cc
+test_w1_datalog_read_LDADD = $(SRC_LIBS) ../src/.libs/lib1wire.a
+
 AM_CPPFLAGS = $(SRC_CFLAGS) -I../src
 
 DISTCLEANFILES = Makefile.in
\ No newline at end of file
index 6aa372fb3e05e2f9e2bfe7303d22ac3428408ba7..5b5e6eb8d80d2dbe135a52eadc11e4758a4c29d0 100644 (file)
@@ -44,7 +44,7 @@ bool try_parse_long(const char *str, long *result) {
 
 int main(int argc, char** argv) {
        W1Scanner               *scanner;
-       list<W1Device *>        device_list;
+       list<W1Device *>        device_list;
        int                     round;
        long                    scan_interval;
        long                    store_interval;
@@ -52,27 +52,27 @@ int main(int argc, char** argv) {
        bool                    err_flg;
 
        // default values than can be overwritten with parameters
-       location                = "/tmp/";
+       location        = "/tmp/";
        scan_interval   = 600;
-       store_interval          = 6;
+       store_interval  = 6;
        if (argc > 1) {
                location        = argv[1];
                log_info("storage location: %s\n", location.c_str());
        }
        else {
-               log_warning("storage location was not given as a parameter, using default location: %s\n", location.c_str());
+               log_warning("No storage location parameter given, using default location: %s\n", location.c_str());
        }
        if (argc > 2) {
                try_parse_long(argv[2], &scan_interval);
        }
        if (argc > 3) {
-                       try_parse_long(argv[3], &store_interval);
+               try_parse_long(argv[3], &store_interval);
        }
        log_info("start scanning, data saved to location: %s, scan interval: %d, store interval: %d\n", location.c_str(), scan_interval, store_interval);
-       W1Store::set_location(location.c_str());
-       scanner                 = new W1Scanner();
-       device_list             = scanner->get_device_list();
-       round                   = 0;
+       W1Store::set_location_base_dir(location.c_str());
+       scanner         = new W1Scanner();
+       device_list     = scanner->get_device_list();
+       round           = 0;
        if (device_list.size() > 0) {
                while(1) {
                        round++;
diff --git a/src_test/test_w1_datalog_read.cc b/src_test/test_w1_datalog_read.cc
new file mode 100644 (file)
index 0000000..49c567e
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * test_data_read.cc
+ *
+ *  Created on: Nov 15, 2010
+ *      Author: lamikr
+ */
+#include <list>
+#include <string>
+#include <iostream>
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include <plp/log.h>
+
+#include "W1DataList.hh"
+#include "W1Store.hh"
+#include "W1Scanner.hh"
+
+#include "W1Util.hh"
+
+using namespace w1;
+using namespace std;
+
+bool try_parse_long(const char *str, long *result) {
+       int     new_result;
+       char    *endptr;
+       bool    ret_val;
+
+       ret_val         = false;
+       errno           = 0;
+       new_result      = strtol(str, &endptr, 10);
+       if (errno != 0) {
+               log_error("invalid input %s, could not convert to integer.\n", str);
+       }
+       else {
+               if (endptr == str) {
+                       log_error("invalid input %s, could not convert to integer.\n", str);
+               }
+               else {
+                       *result = new_result;
+                       ret_val = true;
+               }
+       }
+       return ret_val;
+}
+
+int main(int argc, char** argv) {
+       int             round;
+       string          location;
+       bool            err_flg;
+       W1DataList      *datalist;
+       DataRange       *dr;
+
+       // default values than can be overwritten with parameters
+       //location      = "/tmp/";
+       location        = "/home/lamikr/own/src/plp/w1data2/";
+       if (argc > 1) {
+               location        = argv[1];
+               log_info("storage location: %s\n", location.c_str());
+       }
+       else {
+               log_warning("No storage location parameter given, using default location: %s\n", location.c_str());
+       }
+       W1Store::set_location_base_dir(location.c_str());
+       datalist        = new W1DataList("00080160c563");
+       if (datalist != NULL) {
+               dr      = datalist->get_data_range();
+               if (dr != NULL) {
+                       W1Util::printout_data(dr->first_data);
+                       delete(dr);
+               }
+               delete(datalist);
+       }
+       return 0;
+}