Skip to content

Commit

Permalink
Traditional sport client update, Go2 enable api 1020, B2 add api 1040.
Browse files Browse the repository at this point in the history
  • Loading branch information
wjh committed Nov 25, 2024
1 parent 8254875 commit 01ead90
Show file tree
Hide file tree
Showing 66 changed files with 955 additions and 315 deletions.
6 changes: 3 additions & 3 deletions include/unitree/common/json/jsonize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#define __UT_JSONIZE_HPP__

#define JN_FROM_WEAK(m, name, value) \
if (m.find(name) != m.end()) { value = m[name]; }
if (m.find(name) != m.end()){ JN_FROM(m, name, value); }

#define JN_FROM(m, name, value) \
value = m[name]
unitree::common::FromJson(m[name], value)

#define JN_TO(m, name, value) \
m[name] = value
unitree::common::ToJson(value, m[name])

#include <unitree/common/json/json.hpp>

Expand Down
35 changes: 8 additions & 27 deletions include/unitree/common/log/log_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,30 @@ namespace common
class LogBuffer
{
public:
LogBuffer();
explicit LogBuffer();
virtual ~LogBuffer();

bool Append(const std::string& s);

const std::string& Get();
void Get(std::string& s);

void Clear();

bool Get(std::string& s);
bool Empty();

private:
protected:
std::string mData;
};

typedef std::shared_ptr<LogBuffer> LogBufferPtr;

class LogBlockBuffer
class LogBlockBuffer : public LogBuffer
{
public:
typedef std::shared_ptr<LogBuffer> LOG_BUFFER_PTR;

LogBlockBuffer();
explicit LogBlockBuffer();
~LogBlockBuffer();

bool Append(const std::string& s);

/*
* Get reference of data. [UNSAFE]
*/
const std::string& Get();
void Get(std::string& s);

/*
* Clear data.
*/
void Clear(bool lock = false);

void Exchange();
bool Get(std::string& s);
bool Empty();

private:
volatile bool mR;
std::vector<LOG_BUFFER_PTR> mChain;
Mutex mLock;
};

Expand Down
23 changes: 18 additions & 5 deletions include/unitree/common/log/log_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,29 @@
/*
* log buffer size
*/
#define UT_LOG_BUFFER_SIZE 65535 //64K
#define UT_LOG_MAX_BUFFER_SIZE 8388608 //8M
#define UT_LOG_BUFFER_SIZE 65535 //64K-1
#define UT_LOG_CRT_BUFFER_SIZE 64512 //63K
#define UT_LOG_MAX_BUFFER_SIZE 4194303 //4M-1
/*
* log file size
*/
#define UT_LOG_FILE_SIZE 104857600 //100M
#define UT_LOG_MAX_FILE_SIZE 10737418240 //10G
#define UT_LOG_MIN_FILE_SIZE UT_LOG_MAX_BUFFER_SIZE

/*
* log write interval(micro second)
*/
#define UT_LOG_WRITE_INTER 100000 //100ms
#define UT_LOG_MAX_WRITE_INTER 1000000 //1s
#define UT_LOG_MIN_WRITE_INTER 2000 //2ms

/*
* log file number
*/
#define UT_LOG_FILE_NUMBER 10
#define UT_LOG_MAX_FILE_NUMBER 1000
#define UT_LOG_FILE_NUMBER 2
#define UT_LOG_MAX_FILE_NUMBER 100
#define UT_LOG_MIN_FILE_NUMBER UT_LOG_FILE_NUMBER

#define UT_LOG_FILE_EXT ".LOG"

Expand Down Expand Up @@ -157,6 +166,8 @@
#define UT_LOG_STORE_STDERR 3

#define UT_LOG_STORE_DESC_FILE_ASYNC "FILEASYNC"
#define UT_LOG_STORE_DESC_ASYNC_FILE "ASYNCFILE"
#define UT_LOG_STORE_DESC_ASYNC "ASYNC"
#define UT_LOG_STORE_DESC_FILE "FILE"
#define UT_LOG_STORE_DESC_STDOUT "STDOUT"
#define UT_LOG_STORE_DESC_STDERR "STDERR"
Expand Down Expand Up @@ -214,7 +225,9 @@ static inline const char* GetLogLevelDesc(int32_t level)

static inline int32_t GetLogStoreType(const std::string& desc)
{
if (desc == UT_LOG_STORE_DESC_FILE_ASYNC) {
if (desc == UT_LOG_STORE_DESC_FILE_ASYNC ||
desc == UT_LOG_STORE_DESC_ASYNC_FILE ||
desc == UT_LOG_STORE_DESC_ASYNC) {
return UT_LOG_STORE_FILE_ASYNC; }
else if (desc == UT_LOG_STORE_DESC_FILE) {
return UT_LOG_STORE_FILE; }
Expand Down
18 changes: 7 additions & 11 deletions include/unitree/common/log/log_initor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,28 @@ namespace common
class LogInitor
{
public:
static LogInitor* Instance()
{
static LogInitor inst;
return &inst;
}
explicit LogInitor();
~LogInitor();

void Init(const std::string& configFileName);
void Init(const std::string& configFileName, bool stdoutDefault = false);
Logger* GetLogger(const std::string& tag);

void Final();

private:
LogInitor();
void ParseConf(Any json);
void SetStdoutPolicy();
void InitLogger();

private:
bool mInited;
std::set<std::string> mStoreNames;
std::vector<LogPolicyPtr> mPolicis;
std::vector<LogStorePolicyPtr> mStorePolicis;
std::map<std::string, LoggerPtr> mLoggerMap;
Mutex mLock;
};

void LogInit(const std::string& configFileName = "");
using LogInitorPtr = std::shared_ptr<LogInitor>;

void LogInit(const std::string& configFileName = "", bool stdoutDefault = false);
void LogFinal();

Logger* GetLogger(const std::string& tag);
Expand Down
26 changes: 7 additions & 19 deletions include/unitree/common/log/log_keeper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define __UT_LOG_FILE_KEEPER_H__

#include <unitree/common/log/log_policy.hpp>
#include <unitree/common/log/log_writer.hpp>

namespace unitree
{
Expand All @@ -11,41 +10,30 @@ namespace common
class LogKeeper
{
public:
enum
{
ROLLING_WAIT_MICROSEC = 1000000
};

LogKeeper(LogStorePolicyPtr storePolicyPtr);
~LogKeeper();

void SetWriter(LogWriterPtr writerPtr);
void AppendDataSize(int64_t len);
LogStorePolicyPtr GetStorePolicy() const;

bool Append(const std::string& s, bool rotate);

private:
void Rolling();
void Rotate();

void AppendFile(const std::string& s);
void OpenFile();
void CloseFile();
bool CheckFile();

void ThreadRolling();

bool IsNeedToRolling(int64_t len);
void CheckRolling();
void CheckFileSize();

std::string MakeRegexExpress();

private:
bool mQuit;
int64_t mFileSize;
volatile int64_t mFileSize;
std::string mFileName;
std::string mDirectory;
FilePtr mFilePtr;
LogStorePolicyPtr mStorePolicyPtr;
LogWriterPtr mWriterPtr;
ThreadPtr mThreadPtr;
MutexCond mMutexCond;
};

typedef std::shared_ptr<LogKeeper> LogKeeperPtr;
Expand Down
4 changes: 3 additions & 1 deletion include/unitree/common/log/log_policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class LogStorePolicy
{
public:
LogStorePolicy();
LogStorePolicy(const std::string& name, int32_t type, int32_t fileNumber, int64_t fileSize, int32_t cpuId = UT_CPU_ID_NONE,
LogStorePolicy(const std::string& name, int32_t type, int32_t fileNumber, int64_t fileSize,
int64_t fileWriteInter = UT_LOG_WRITE_INTER, int32_t cpuId = UT_CPU_ID_NONE,
const std::string& fileName = "", const std::string& directory = "");

void Dump();
Expand All @@ -37,6 +38,7 @@ class LogStorePolicy
int32_t mType;
int32_t mFileNumber;
int64_t mFileSize;
int64_t mFileWriteInter;
int32_t mCpuId;
std::string mFileName;
std::string mDirectory;
Expand Down
41 changes: 18 additions & 23 deletions include/unitree/common/log/log_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,61 @@ namespace common
class LogStore
{
public:
explicit LogStore()
{}
virtual ~LogStore()
{
mWriterPtr.reset();
}

virtual void Append(const std::string& s) = 0;

protected:
LogWriterPtr mWriterPtr;
};

typedef std::shared_ptr<LogStore> LogStorePtr;

class LogStdoutStore : public LogStore
{
public:
LogStdoutStore();
explicit LogStdoutStore();
~LogStdoutStore();

void Append(const std::string& s);

protected:
LogWriterPtr mWriterPtr;
};

typedef std::shared_ptr<LogStdoutStore> LogStdoutStorePtr;

class LogStderrStore : public LogStore
{
public:
LogStderrStore();
explicit LogStderrStore();
~LogStderrStore();

void Append(const std::string& s);

protected:
LogWriterPtr mWriterPtr;
};

typedef std::shared_ptr<LogStderrStore> LogStderrStorePtr;

class LogFileStore : public LogStore
{
public:
LogFileStore(LogKeeperPtr keeperPtr);
explicit LogFileStore(LogKeeperPtr keeperPtr);
~LogFileStore();

void Append(const std::string& s);

private:
LogKeeperPtr mKeeperPtr;
LogWriterPtr mWriterPtr;
};

typedef std::shared_ptr<LogFileStore> LogFileStorePtr;

class LogFileAsyncStore : public LogStore
{
public:
enum
{
WRITE_INTERVAL = 100000,
};

LogFileAsyncStore(LogKeeperPtr keeperPtr);
explicit LogFileAsyncStore(LogKeeperPtr keeperPtr);
~LogFileAsyncStore();

void Append(const std::string& s);

private:
LogWriterPtr mWriterPtr;
LogKeeperPtr mKeeperPtr;
};

typedef std::shared_ptr<LogFileAsyncStore> LogFileAsyncStorePtr;
Expand Down
Loading

0 comments on commit 01ead90

Please sign in to comment.