summaryrefslogtreecommitdiff
path: root/src/common.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.hpp')
-rw-r--r--src/common.hpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/common.hpp b/src/common.hpp
new file mode 100644
index 0000000..6ec7a82
--- /dev/null
+++ b/src/common.hpp
@@ -0,0 +1,82 @@
+// -*- mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*-
+// ***** BEGIN LICENSE BLOCK *****
+////////////////////////////////////////////////////////////////////
+// Copyright (c) 2011-2013 RALOVICH, Kristóf //
+// //
+// This program is free software; you can redistribute it and/or //
+// modify it under the terms of the GNU General Public License //
+// version 2 as published by the Free Software Foundation. //
+// //
+////////////////////////////////////////////////////////////////////
+// ***** END LICENSE BLOCK *****
+#pragma once
+
+#include <ostream>
+#include <string>
+#include <vector>
+#include "antdefs.hpp"
+
+#define CHECK_RETURN_FALSE(x) do { if(!(x)) { printf("E: %s\n", #x); return false; } /*else { printf("ok: %s\n", #x); }*/ } while(0)
+#define CHECK_RETURN_FALSE_LOG_OK(x) do { if(!(x)) { printf("E: %s\n", #x); return false; } else { printf("ok: %s\n", #x); } } while(0)
+#define CHECK_RETURN_RV(x, rv) do { if(!(x)) { printf("E: %s\n", #x); return rv; } /*else { printf("ok: %s\n", #x); }*/ } while(0)
+#define CHECK_RETURN_RV_LOG_OK(x, rv) do { if(!(x)) { printf("E: %s\n", #x); return rv; } else { printf("ok: %s\n", #x); } } while(0)
+#define CHECK_RETURN(x) do { if(!(x)) { printf("E: %s\n", #x); return; } else { printf("ok: %s\n", #x); } fflush(stdout); } while(0)
+#define LOG_VAR(x) do { logger() << #x << "= " << x << std::endl; logger().flush(); } while(0)
+#define LOG_VAR2(x,y) do { logger() << #x << "= " << x << ", " #y << "= " << y << std::endl; logger().flush(); } while(0)
+#define LOG_VAR3(x,y, z) do { logger() << #x "= " << x << ", " #y "= " << y << ", " #z "= " << z << std::endl; logger().flush(); } while(0)
+#define LOG_VAR4(x,y, z, w) do { logger() << #x "= " << x << ", " #y "= " << y << ", " #z "= " << z << ", " #w "= " << w << std::endl; logger().flush(); } while(0)
+
+std::ostream& logger();
+FILE* loggerc();
+
+void sleepms(const size_t timeout_ms);
+
+#ifndef _MSC_VER
+char* itoa(int value, char* result, int base);
+#endif
+
+///
+template < class T >
+const std::string
+toString(const T& val, const int width = -1, const char fill = ' ');
+template < class T >
+const std::string
+toStringDec(const T& val, const int width = -1, const char fill = ' ');
+
+const std::vector<std::string> tokenize(const std::string& text, const char* delims);
+
+extern
+const std::string
+getDateString();
+
+const std::string
+getConfigFileName();
+
+const std::string
+getConfigFolder();
+
+void
+readUInt64(const uint clientSN, uint64_t& pairedKey);
+
+void
+writeUInt64(const uint clientSN, const uint64_t& ui);
+
+std::vector<uchar>
+readFile(const char* fileName);
+
+bool
+mkDir(const char* dirName);
+
+enum
+{
+ ANTPM_RETRIES=10,
+ ANTPM_RETRY_MS=1000,
+ ANTPM_MAX_CHANNELS=56
+};
+
+#define APP_NAME "antpm"
+#ifndef _WIN32
+# define ANTPM_SERIAL_IMPL SerialTty
+#else
+# define ANTPM_SERIAL_IMPL SerialUsb
+#endif