DCSModulesAPI  1.0.0
DCS sub project containing all the control modules as libraries.
internal.h
Go to the documentation of this file.
1 #pragma once
2 #include <vector>
3 #include <array>
4 #include <thread>
5 #include <atomic>
6 #include <condition_variable>
7 #include <mutex>
8 #include <functional>
9 #include <type_traits>
10 #include "../../DCS_Utils/include/DCS_ModuleUtils.h"
11 
12 #define DCS_SHA256_DIGEST_LENGTH 32
13 
27 namespace DCS
28 {
29  namespace Threading
30  {
36  {
37  std::vector<std::thread> workers;
38  std::mutex lock;
39  std::condition_variable signal;
40  std::array<std::atomic_int, 16> flags;
41  };
42 
50  DCS_INTERNAL_TEST TPool* CreatePersistentPool(u16 size, std::vector<std::function<void(std::mutex*, std::condition_variable*, std::array<std::atomic_int, 16>*)>> workers);
51 
58  DCS_INTERNAL_TEST void JoinPool(TPool* pool);
59 
64  DCS_INTERNAL_TEST u64 GetPoolWorkCount(TPool* pool);
65 
71  DCS_INTERNAL_TEST void DestroyPool(TPool* pool);
72  }
73 
80  namespace DB // TODO : Add user login statistics / trace
81  {
82 #pragma pack( push )
83  // NOTE : Using a salt is nice but requires to send the plain text password which is okay but such security is not needed.
84  // Just ensure the user has a strong password.
85 
90  struct User
91  {
92  char u[32];
93  u8 p[32];
94  };
95 #pragma pack( pop )
96 
101  DCS_INTERNAL_TEST void LoadDefaultDB();
102 
107  DCS_INTERNAL_TEST void CloseDB();
108 
113  DCS_INTERNAL_TEST void LoadUsers();
114 
119  DCS_INTERNAL_TEST void AddUser(const char* username, const char* password);
120 
125  DCS_INTERNAL_TEST void RemoveUserByUsername(const char* username);
126 
132  DCS_INTERNAL_TEST u64 FindUserByUsername(const char* username);
133 
139  DCS_INTERNAL_TEST User GetUser(const char* username);
140 
146  DCS_INTERNAL_TEST const User* GetAllUsers();
147 
153  DCS_INTERNAL_TEST u64 GetUserCount();
154  }
155 
156  namespace Auth
157  {
162  DCS_INTERNAL_TEST void InitCryptoRand();
163 
168  DCS_INTERNAL_TEST void GenerateSalt(DCS::u8 salt[8]);
169 
174  DCS_INTERNAL_TEST void GenerateRandSafeIV128(DCS::u8 iv[16]);
175 
180  DCS_INTERNAL_TEST void SHA256Str(const char* string, DCS::u8 hash[DCS_SHA256_DIGEST_LENGTH]);
181 
186  DCS_INTERNAL_TEST void HexStringifyBytes(char* out, DCS::u8* hash, DCS::u64 size);
187 
192  DCS_INTERNAL_TEST void EncryptAES256(DCS::u8* to_encrypt, int to_encrypt_size,
193  DCS::u8* aad, int aad_size, DCS::u8* key,
194  DCS::u8* iv, DCS::u8* encrypted_out, DCS::u8* tag);
195 
200  DCS_INTERNAL_TEST int DecryptAES256(DCS::u8* cipher, int cipher_size,
201  DCS::u8* aad, int aad_size, DCS::u8* key,
202  DCS::u8* iv, DCS::u8* plain_out, DCS::u8* tag);
203  }
204 
205  namespace Core // NOTE : Might deprecate this (using external firmware)
206  {
208  {
209  public:
210  PID(float min, float max, float Kp, float Kd, float Ki);
211 
212  void setTargetAndBias(float target, float bias);
213 
214  float calculate(float value);
215 
216  float calculate(float value, float dt);
217 
218  private:
219  float min;
220  float max;
221  float Kp;
222  float Kd;
223  float Ki;
224 
225  float dt;
226 
227  float target;
228  float bias;
229 
230  float le;
231  float integral;
232 
233  std::chrono::steady_clock::time_point last_point;
234  };
235  }
236 }
Definition: internal.h:90
unsigned short u16
Equivalent to uint_16t.
Definition: DCS_ModuleUtils.h:56
Definition: internal.h:35
Definition: internal.h:207
Definition: registry.h:70
#define DCS_INTERNAL_TEST
Defines the export interface acessible via the dll-interface applicable for internal functions only...
Definition: exports.h:137
unsigned long long u64
Equivalent to uint_64t.
Definition: DCS_ModuleUtils.h:52
unsigned char u8
Equivalent to uint_8t.
Definition: DCS_ModuleUtils.h:58