| | |
| | | #ifndef _APPTIMER_H_ |
| | | #define _APPTIMER_H_ |
| | | // |
| | | // Created by YY on 2021/3/16. |
| | | // |
| | | |
| | | #include <stdint.h> |
| | | #include <signal.h> |
| | | #ifndef NDKADV_APPTIMER_H |
| | | #define NDKADV_APPTIMER_H |
| | | |
| | | #include <cstdint> |
| | | #include <functional> |
| | | #include <thread> |
| | | #include <chrono> |
| | | #include <atomic> |
| | | #include <mutex> |
| | | #include <condition_variable> |
| | | #include <string> |
| | | #include <ctime> |
| | | |
| | | #define D_SEC(n) ((n)*1000UL) |
| | | #define D_MIN(n) ((n)*1000UL*60UL) |
| | | #define D_HOUR(n) ((n)*1000UL*60UL*60UL) |
| | | |
| | | extern void AppTimer_Init(void); |
| | | typedef struct { |
| | | int var1; |
| | | int var2; |
| | | void * var_ptr; |
| | | int var_length; |
| | | } apptimer_var_t; |
| | | |
| | | extern void AppTimer_add(void (*func)(union sigval), int timeMS); |
| | | class CTimer { |
| | | public: |
| | | CTimer(); |
| | | virtual ~CTimer(); |
| | | static bool _updateStatus(CTimer *timer); |
| | | static void _do_task_func(uint32_t msec, CTimer *timer, std::function<void(apptimer_var_t)> callback); |
| | | bool start(uint32_t msec, std::function<void(apptimer_var_t)> callback); |
| | | void stop(); |
| | | void copy(int value1, int value2, const void *data, int length); |
| | | static void clear(CTimer *timer); |
| | | private: |
| | | std::mutex cv_mtx; |
| | | std::condition_variable cv; |
| | | // std::thread callbackThread; |
| | | std::thread *pthread; |
| | | apptimer_var_t var; |
| | | public: |
| | | std::atomic_int flag; |
| | | }; |
| | | |
| | | extern void AppTimer_add(void (*func)(union sigval), int timeMS, uint8_t *data, int length); |
| | | void AppTimer_init(void); |
| | | |
| | | extern void AppTimer_add(void (*func)(union sigval), int timeMS, int value); |
| | | void AppTimer_add(void(*cb)(apptimer_var_t), uint32_t msec); |
| | | |
| | | extern void AppTimer_delete(void (*func)(union sigval)); |
| | | void AppTimer_add(void(*cb)(apptimer_var_t), uint32_t msec, int value1, int value2 = 0); |
| | | |
| | | extern uint32_t AppTimer_GetTickCount(void); |
| | | void AppTimer_add(void(*cb)(apptimer_var_t), uint32_t msec, void *data, int lenght); |
| | | |
| | | #endif |
| | | void AppTimer_delete(void (*cb) (apptimer_var_t)); |
| | | |
| | | uint32_t AppTimer_GetTickCount(void); |
| | | |
| | | uint32_t AppTimer_GetGmtTickCount(void); |
| | | |
| | | std::string FormatTime(const char *fmt); |
| | | |
| | | std::time_t MktimeString(const char *str, const char *fmt); |
| | | |
| | | time_t TimeStamp(int year, int mon, int day, int hour, int min, int sec); |
| | | |
| | | #endif //NDKADV_APPTIMER_H |