RUI3 (RAK Unified Interface 3) - RAK4631
RAKSystem.h
Go to the documentation of this file.
1 #ifndef __RAK_SYSTEM_H__
2 #define __RAK_STSTEM_H__
3 
4 #include "WString.h"
5 
6 #include "sleep.h"
7 #include "wdt.h"
8 #include "atcmd.h"
9 #include "udrv_errno.h"
10 #include "udrv_system.h"
11 #include "udrv_serial.h"
12 #include "udrv_delay.h"
13 #include "service_mode_cli.h"
14 #include "service_battery.h"
15 #include "service_nvm.h"
16 #ifdef SUPPORT_FS
17 #include "service_fs.h"
18 #endif
19 
20 using namespace std;
21 
29 /* ATCMD PERMISSION */
30 typedef enum {
36 
40 typedef enum {
47 } RAK_TIMER_ID;
48 
52 typedef void (*RAK_TIMER_HANDLER) (void *data);
53 
54 typedef enum {
58 
62 typedef void (*RAK_TASK_HANDLER) (void);
63 
96 #define CHANGE_ATCMD_PERM(_atcmd_name,_atcmd_perm) \
97  ATCMD_ITEM(atcmd_queue, atcmd_permission_item UNIQUE_NAME(permissions)) = \
98  { \
99  .atcmd_id = _atcmd_name, \
100  .permission = _atcmd_perm, \
101  }
102 
103 #ifdef SUPPORT_FS
104 
108 #define RAK_FS_OK SERVICE_FS_OK
109 #define RAK_FS_ERR_NOT_MOUNTED SERVICE_FS_ERR_NOT_MOUNTED
110 #define RAK_FS_ERR_FULL SERVICE_FS_ERR_FULL
111 #define RAK_FS_ERR_NOT_FOUND SERVICE_FS_ERR_NOT_FOUND
112 #define RAK_FS_ERR_END_OF_OBJECT SERVICE_FS_ERR_END_OF_OBJECT
113 #define RAK_FS_ERR_DELETED SERVICE_FS_ERR_DELETED
114 #define RAK_FS_ERR_NOT_FINALIZED SERVICE_FS_ERR_NOT_FINALIZED
115 #define RAK_FS_ERR_NOT_INDEX SERVICE_FS_ERR_NOT_INDEX
116 #define RAK_FS_ERR_OUT_OF_FILE_DESCS SERVICE_FS_ERR_OUT_OF_FILE_DESCS
117 #define RAK_FS_ERR_FILE_CLOSED SERVICE_FS_ERR_FILE_CLOSED
118 #define RAK_FS_ERR_FILE_DELETED SERVICE_FS_ERR_FILE_DELETED
119 #define RAK_FS_ERR_BAD_DESCRIPTOR SERVICE_FS_ERR_BAD_DESCRIPTOR
120 #define RAK_FS_ERR_IS_INDEX SERVICE_FS_ERR_IS_INDEX
121 #define RAK_FS_ERR_IS_FREE SERVICE_FS_ERR_IS_FREE
122 #define RAK_FS_ERR_INDEX_SPAN_MISMATCH SERVICE_FS_ERR_INDEX_SPAN_MISMATCH
123 #define RAK_FS_ERR_DATA_SPAN_MISMATCH SERVICE_FS_ERR_DATA_SPAN_MISMATCH
124 #define RAK_FS_ERR_INDEX_REF_FREE SERVICE_FS_ERR_INDEX_REF_FREE
125 #define RAK_FS_ERR_INDEX_REF_LU SERVICE_FS_ERR_INDEX_REF_LU
126 #define RAK_FS_ERR_INDEX_REF_INVALID SERVICE_FS_ERR_INDEX_REF_INVALID
127 #define RAK_FS_ERR_INDEX_FREE SERVICE_FS_ERR_INDEX_FREE
128 #define RAK_FS_ERR_INDEX_LU SERVICE_FS_ERR_INDEX_LU
129 #define RAK_FS_ERR_INDEX_INVALID SERVICE_FS_ERR_INDEX_INVALID
130 #define RAK_FS_ERR_NOT_WRITABLE SERVICE_FS_ERR_NOT_WRITABLE
131 #define RAK_FS_ERR_NOT_READABLE SERVICE_FS_ERR_NOT_READABLE
132 #define RAK_FS_ERR_CONFLICTING_NAME SERVICE_FS_ERR_CONFLICTING_NAME
133 #define RAK_FS_ERR_NOT_CONFIGURED SERVICE_FS_ERR_NOT_CONFIGURED
134 #define RAK_FS_ERR_NOT_A_FS SERVICE_FS_ERR_NOT_A_FS
135 #define RAK_FS_ERR_MOUNTED SERVICE_FS_ERR_MOUNTED
136 #define RAK_FS_ERR_ERASE_FAIL SERVICE_FS_ERR_ERASE_FAIL
137 #define RAK_FS_ERR_MAGIC_NOT_POSSIBLE SERVICE_FS_ERR_MAGIC_NOT_POSSIBLE
138 #define RAK_FS_ERR_NO_DELETED_BLOCKS SERVICE_FS_ERR_NO_DELETED_BLOCKS
139 #define RAK_FS_ERR_FILE_EXISTS SERVICE_FS_ERR_FILE_EXISTS
140 #define RAK_FS_ERR_NOT_A_FILE SERVICE_FS_ERR_NOT_A_FILE
141 #define RAK_FS_ERR_RO_NOT_IMPL SERVICE_FS_ERR_RO_NOT_IMPL
142 #define RAK_FS_ERR_RO_ABORTED_OPERATION SERVICE_FS_ERR_RO_ABORTED_OPERATION
143 #define RAK_FS_ERR_PROBE_TOO_FEW_BLOCKS SERVICE_FS_ERR_PROBE_TOO_FEW_BLOCKS
144 #define RAK_FS_ERR_PROBE_NOT_A_FS SERVICE_FS_ERR_PROBE_NOT_A_FS
145 #define RAK_FS_ERR_NAME_TOO_LONG SERVICE_FS_ERR_NAME_TOO_LONG
146 #define RAK_FS_ERR_IX_MAP_UNMAPPED SERVICE_FS_ERR_IX_MAP_UNMAPPED
147 #define RAK_FS_ERR_IX_MAP_MAPPED SERVICE_FS_ERR_IX_MAP_MAPPED
148 #define RAK_FS_ERR_IX_MAP_BAD_RANGE SERVICE_FS_ERR_IX_MAP_BAD_RANGE
149 #define RAK_FS_ERR_SEEK_BOUNDS SERVICE_FS_ERR_SEEK_BOUNDS
150 #define RAK_FS_ERR_INTERNAL SERVICE_FS_ERR_INTERNAL
151 #define RAK_FS_ERR_TEST SERVICE_FS_ERR_TEST
152 #define RAK_FS_ERR_CONTINUE SERVICE_FS_ERR_CONTINUE
153 
154 
155 #endif
156 
157 class RAKSystem {
158  public:
159  RAKSystem();
160  class sleep sleep;
161  class lpm lpm;
162  class wdt wdt;
163 
165  private:
166  String ver;
167 
168  public:
169  firmwareVersion();
170 
193  String get();
218  bool set(String version);
219  };
220 
221  class cliVersion {
222  private:
223  String ver;
224 
225  public:
226  cliVersion();
227 
251  String get();
278  bool set(String version);
279  };
280 
281  class apiVersion {
282  private:
283  String ver;
284 
285  public:
286  apiVersion();
287 
309  const String get();
310  };
311 
312  class modelId {
313  private:
314  String id;
315 
316  public:
317  modelId();
318 
342  String get();
368  bool set(String model);
369  };
370 
371  class chipId {
372  private:
373  String id;
374 
375  public:
376  chipId();
377 
399  const String get();
400  };
401 
410 
436  void reboot();
437 
456  void restoreDefault();
457 
458  class pword {
459  public:
494  bool set(char *passwd, uint32_t len);
495  bool set(String passwd);
496 
527  void lock(void);
528 
558  void unlock(void);
559  };
560 
561  class bat {
562  public:
584  float get(void);
585  };
586 
589  class atMode {
590  public:
644  bool add(char *cmd, char *usage, char *title, PF_handle handle,unsigned int perm = RAK_ATCMD_PERM_WRITE | RAK_ATCMD_PERM_READ);
645  };
646 
647 #ifdef SUPPORT_FS
648  class fs {
649  public:
650 
664  int32_t ferrno(SERVICE_FS_FILE file);
665 
679  int32_t derrno(SERVICE_FS_DIR dir);
680 
690  SERVICE_FS init(void);
691 
701  SERVICE_FS reset(void);
702 
745  int32_t list(SERVICE_FS fs, SERVICE_FS_DIR *d, SERVICE_FS_DIRENT *entry);
746 
761  SERVICE_FS_FILE open(SERVICE_FS fs, const char* path, uint32_t flags, uint32_t mode);
762 
778  int32_t read(SERVICE_FS fs, SERVICE_FS_FILE file, void* buf, uint32_t len);
779 
795  int32_t write(SERVICE_FS fs, SERVICE_FS_FILE file, void* buf, uint32_t len);
796 
811  int32_t lseek(SERVICE_FS fs, SERVICE_FS_FILE file, int32_t offs, uint32_t whence);
812 
825  int32_t remove(SERVICE_FS fs, const char* path);
826 
839  int32_t fremove(SERVICE_FS fs, SERVICE_FS_FILE file);
840 
854  int32_t stat(SERVICE_FS fs, const char* path, SERVICE_FS_FILE_STAT* stat);
855 
869  int32_t fstat(SERVICE_FS fs, SERVICE_FS_FILE file, SERVICE_FS_FILE_STAT* stat);
870 
883  int32_t flush(SERVICE_FS fs, SERVICE_FS_FILE file);
884 
897  int32_t close(SERVICE_FS fs, SERVICE_FS_FILE file);
898 
912  int32_t rename(SERVICE_FS fs, const char* old_name, const char* new_name);
913 
927  int32_t opendir(SERVICE_FS fs, const char* name, SERVICE_FS_DIR* d);
928 
941  int32_t closedir(SERVICE_FS fs, SERVICE_FS_DIR* d);
942 
957 
970  int32_t feof(SERVICE_FS fs, SERVICE_FS_FILE file);
971 
984  int32_t ftell(SERVICE_FS fs, SERVICE_FS_FILE file);
985  };
986 #else
987  class flash {
988  public:
1001  bool get(uint32_t offset, uint8_t *buf, uint32_t len);
1014  bool set(uint32_t offset, uint8_t *buf, uint32_t len);
1015  };
1016 #endif
1017  class alias {
1018  public :
1044  bool set(char * buf,uint32_t len);
1070  bool get(char * buf,uint32_t len);
1071  };
1072  class timer {
1073  public :
1106  bool create(RAK_TIMER_ID id, RAK_TIMER_HANDLER handler, RAK_TIMER_MODE mode);
1139  bool start(RAK_TIMER_ID id, uint32_t ms, void *data);
1175  bool stop(RAK_TIMER_ID id);
1176  };
1177  class scheduler {
1178  public :
1179  class task {
1180  public :
1211  bool create(char *name, RAK_TASK_HANDLER handler);
1247  bool destroy(char *name);
1248  bool destroy(void);
1249  };
1251  };
1255 #ifdef SUPPORT_FS
1256  fs fs;
1257 #else
1259 #endif
1263 };
1264 
1268 #endif
flash flash
Definition: RAKSystem.h:1258
Definition: atcmd.h:38
This file contains all error code for the hardware independent driver layer.
Definition: RAKSystem.h:371
this is the number of all available timers
Definition: RAKSystem.h:46
Definition: service_fs.h:135
cliVersion cliVer
Definition: RAKSystem.h:404
Definition: RAKSystem.h:987
Definition: udrv_timer.h:16
apiVersion apiVersion
Definition: RAKSystem.h:406
Definition: sleep.h:169
Definition: udrv_timer.h:30
Disables the AT command from being used.
Definition: RAKSystem.h:34
pword pword
Definition: RAKSystem.h:1252
Provide filesystem service layer.
Definition: wdt.h:14
cliVersion cliVersion
Definition: RAKSystem.h:405
Definition: udrv_timer.h:12
Definition: RAKSystem.h:1017
Definition: RAKSystem.h:1179
firmwareVersion firmwareVersion
Definition: RAKSystem.h:403
timer ID #2
Definition: RAKSystem.h:43
Definition: udrv_timer.h:29
Definition: WString.h:22
timer ID #0
Definition: RAKSystem.h:41
Provide battery service layer.
timer timer
Definition: RAKSystem.h:1261
void * SERVICE_FS
Definition: service_fs.h:161
void(* RAK_TIMER_HANDLER)(void *data)
Definition: RAKSystem.h:52
The C++ wrapper for watch dog functions.
modelId modelId
Definition: RAKSystem.h:408
This timer is only triggered one time.
Definition: RAKSystem.h:55
task task
Definition: RAKSystem.h:1250
Definition: udrv_timer.h:11
void(* RAK_TASK_HANDLER)(void)
Definition: RAKSystem.h:62
alias alias
Definition: RAKSystem.h:1260
Definition: udrv_timer.h:13
atMode atMode
Definition: RAKSystem.h:1254
Definition: service_fs.h:111
Write permission allows for writting a variable data only and disables any read functionality.
Definition: RAKSystem.h:31
firmwareVersion firmwareVer
Definition: RAKSystem.h:402
Definition: service_fs.h:124
Special functionality that allows for setting variable once and only allows for reading after...
Definition: RAKSystem.h:33
Definition: RAKSystem.h:221
This timer is triggered periodically.
Definition: RAKSystem.h:56
Definition: RAKSystem.h:281
RAK_TIMER_MODE
Definition: RAKSystem.h:54
Definition: RAKSystem.h:164
Definition: RAKSystem.h:1177
Provide a hardware independent serial driver layer for API layer to use.
Definition: service_fs.h:147
modelId hwModel
Definition: RAKSystem.h:407
Definition: udrv_timer.h:15
Definition: sleep.h:33
Read permission allows for reading a variable data only and disables any write functionality.
Definition: RAKSystem.h:32
bat bat
Definition: RAKSystem.h:1253
Definition: RAKSystem.h:561
RAK_AT_PERMISSION
Definition: RAKSystem.h:30
Definition: RAKSystem.h:458
int(* PF_handle)(SERIAL_PORT port, char *cmd, stParam *param)
Definition: atcmd.h:65
Definition: atcmd.h:37
timer ID #4
Definition: RAKSystem.h:45
timer ID #3
Definition: RAKSystem.h:44
Definition: RAKSystem.h:589
Definition: atcmd.h:41
timer ID #1
Definition: RAKSystem.h:42
chipId chipId
Definition: RAKSystem.h:409
scheduler scheduler
Definition: RAKSystem.h:1262
Provide NVM service layer.
Definition: RAKSystem.h:312
Definition: RAKSystem.h:157
Definition: udrv_timer.h:14
Definition: RAKSystem.h:1072
RAK_TIMER_ID
Definition: RAKSystem.h:40
Definition: atcmd.h:39
The c++ wrapper for sleep functions.