FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SPIFFS_Debug/SPIFFS_Debug.cpp at master · Hackerspace-io/SPIFFS_Debug · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
Hackerspace-io
/
SPIFFS_Debug
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
SPIFFS_Debug
/
SPIFFS_Debug.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
292 lines (271 loc) · 7.41 KB
Breadcrumbs
SPIFFS_Debug
/
SPIFFS_Debug.cpp
Copy path
File metadata and controls
292 lines (271 loc) · 7.41 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
SPIFFS_Debug.cpp - library for communicating to Server and saving DebugLog in SPIFFS.
Created by amin ;)
and its Free
*/
#
include
"
Arduino.h
"
#
include
"
SPIFFS_Debug.h
"
#
define
debugConf
"
/debugConf.txt
"
#
define
debug1
"
/debug1.txt
"
#
define
debug2
"
/debug2.txt
"
#
define
debug1size
2000
//
max size about 300kB
#
define
debug2size
2000
//
max size about 300kB
#
define
lastMsgCount
200
//
number of messages that should be saved in debug2
//
debugConf contains: 1 byte debug1Full flag + 3 byte debug1StartPointer + 1 byte debug2Full flag + 3 byte debug2StartPointer
//
debug1 contains full report
//
debug2 contains RTC and last lastMsgCount lines before restart
File fileConf, file1, file2;
int
SPIFFS_Debug::readAddrs
(File file,
int
addrs) {
file.
seek
(addrs, SeekSet);
return
file.
read
();
}
void
SPIFFS_Debug::writeAddrs
(File file,
int
addrs,
int
value) {
file.
seek
(addrs, SeekSet);
file.
write
(value);
}
SPIFFS_Debug::SPIFFS_Debug
() {
#
ifdef
Dragon_debug_spiffs
if
(
SPIFFS
.
begin
()) {
Serial.
println
(
"
mounted file system
"
);
}
else
{
Serial.
println
(
"
failed to mount FS
"
);
}
#
endif
}
bool
SPIFFS_Debug::rstDebugFiles
() {
bool
result1 =
SPIFFS
.
remove
(debug1);
bool
result2 =
SPIFFS
.
remove
(debug2);
bool
result3 =
SPIFFS
.
remove
(debugConf);
file1 =
SPIFFS
.
open
(debug1,
"
w+
"
);
//
creating new file for further usage
file1.
close
();
file2 =
SPIFFS
.
open
(debug2,
"
w+
"
);
//
creating new file for further usage
file2.
close
();
fileConf =
SPIFFS
.
open
(debugConf,
"
w+
"
);
//
creating new file for further usage
if
(fileConf) {
for
(
int
i=
0
; i<
8
; i++) {
//
Init fileConf
writeAddrs
(fileConf, i,
0
);
}
}
else
{
Serial.
println
(
"
fileConf open failed
"
);
}
fileConf.
close
();
if
(result1 && result2 && result3 ==
true
) {
return
true
;
}
else
{
return
false
;
}
}
void
SPIFFS_Debug::debugOnRst
(Date date, Time time) {
#
ifdef
Dragon_debug_spiffs
file1 =
SPIFFS
.
open
(debug1,
"
r
"
);
file2 =
SPIFFS
.
open
(debug2,
"
r+
"
);
fileConf =
SPIFFS
.
open
(debugConf,
"
r
"
);
if
(file1 && file2 && fileConf) {
int
confStartPoint;
int
startPoint;
if
(file1.
size
() < debug1size) {
//
just read the last 20 messages
confStartPoint = file1.
size
();
startPoint = confStartPoint-lastMsgCount;
if
(startPoint <
0
) {
startPoint =
0
;
}
}
else
{
confStartPoint =
readAddrs
(fileConf,
3
)*(
256
^
2
) +
readAddrs
(fileConf,
2
)*
256
+
readAddrs
(fileConf,
1
);
startPoint = confStartPoint-lastMsgCount;
if
(startPoint <
0
) {
startPoint =
0
;
}
}
String comment =
"
"
;
comment +=
"
\n
Time:
"
;
comment += date.
year
;
comment +=
"
-
"
;
comment += date.
month
;
comment +=
"
-
"
;
comment += date.
day
;
comment +=
"
\t
"
;
comment += time.
hour
;
comment +=
"
:
"
;
comment += time.
min
;
comment +=
"
:
"
;
comment += time.
sec
;
comment +=
"
\n
"
;
file1.
seek
(startPoint, SeekSet);
while
(file1.
position
() < confStartPoint) {
comment += (
char
)file1.
read
();
yield
();
}
if
(file2.
size
() < debug2size) {
//
we have space to write
file2.
seek
(file2.
size
(), SeekSet);
file2.
print
(comment);
}
else
{
//
file2 is full.
fileConf =
SPIFFS
.
open
(debugConf,
"
r+
"
);
if
(fileConf) {
if
(
readAddrs
(fileConf,
0
) ==
0
) {
writeAddrs
(fileConf,
0
,
1
);
}
int
startPoint =
readAddrs
(fileConf,
7
)*(
65536
) +
readAddrs
(fileConf,
6
)*
256
+
readAddrs
(fileConf,
5
);
file2.
seek
(startPoint, SeekSet);
file2.
print
(comment);
startPoint = file2.
position
();
if
(startPoint > file2.
size
()) {
while
(file2.
available
()) {
//
empty extra datas over useful length
file2.
write
(
0
);
}
startPoint =
0
;
}
//
write new startPoint to fileConf
writeAddrs
(fileConf,
7
, startPoint/(
65536
));
writeAddrs
(fileConf,
6
, (startPoint/
256
)%
256
);
writeAddrs
(fileConf,
5
, startPoint%
256
);
}
else
{
Serial.
println
(
"
fileConf open failed
"
);
}
}
}
else
{
Serial.
println
(
"
file1 open failed
"
);
}
file1.
close
();
file2.
close
();
fileConf.
close
();
#
endif
}
void
SPIFFS_Debug::debug
(String comment) {
#
ifdef
Dragon_debug_serial
Serial.
print
(
"
*DD*
"
);
Serial.
print
(comment);
#
endif
#
ifdef
Dragon_debug_spiffs
//
adding spaces
String commentLog =
"
"
;
for
(
int
i=
0
; i<spaces ; i++) {
commentLog +=
"
"
;
}
commentLog += comment;
file1 =
SPIFFS
.
open
(debug1,
"
r+
"
);
if
(file1) {
if
(file1.
size
() < debug1size) {
//
we have space to write
file1.
seek
(file1.
size
(), SeekSet);
file1.
print
(commentLog);
}
else
{
//
file1 is full.
fileConf =
SPIFFS
.
open
(debugConf,
"
r+
"
);
if
(fileConf) {
if
(
readAddrs
(fileConf,
0
) ==
0
) {
writeAddrs
(fileConf,
0
,
1
);
}
int
startPoint =
readAddrs
(fileConf,
3
)*(
65536
) +
readAddrs
(fileConf,
2
)*
256
+
readAddrs
(fileConf,
1
);
file1.
seek
(startPoint, SeekSet);
file1.
print
(commentLog);
startPoint = file1.
position
();
if
(startPoint > debug1size) {
while
(file1.
available
()) {
//
empty extra datas over useful length
file1.
write
(
0
);
}
startPoint =
0
;
}
//
write new startPoint to fileConf
writeAddrs
(fileConf,
3
, startPoint/(
65536
));
writeAddrs
(fileConf,
2
, (startPoint/
256
)%
256
);
writeAddrs
(fileConf,
1
, startPoint%
256
);
}
else
{
Serial.
println
(
"
fileConf open failed
"
);
}
fileConf.
close
();
}
}
else
{
Serial.
println
(
"
file1 open failed
"
);
}
file1.
close
();
#
endif
}
void
SPIFFS_Debug::debugSOF
(String comment) {
++spaces;
debug
(comment);
}
void
SPIFFS_Debug::debugEOF
(String comment) {
if
(spaces <
0
) {
spaces =
0
;
}
debug
(comment);
--spaces;
}
void
SPIFFS_Debug::debugReadDebug1
() {
file1 =
SPIFFS
.
open
(debug1,
"
r
"
);
if
(file1) {
fileConf =
SPIFFS
.
open
(debugConf,
"
r
"
);
int
startPoint =
readAddrs
(fileConf,
3
)*(
256
^
2
) +
readAddrs
(fileConf,
2
)*
256
+
readAddrs
(fileConf,
1
);
file1.
seek
(startPoint, SeekSet);
Serial.
print
(
"
file size is:
"
);
Serial.
println
(file1.
size
());
Serial.
println
(
"
====== Reading from debug1 file =======
"
);
while
(file1.
available
()){
String lineContent = file1.
readStringUntil
(
'
\n
'
);
Serial.
println
(lineContent);
}
file1.
seek
(
0
, SeekSet);
while
(file1.
position
() < startPoint){
String lineContent = file1.
readStringUntil
(
'
\n
'
);
Serial.
println
(lineContent);
}
Serial.
println
(
"
====== end of file =======
"
);
}
else
{
Serial.
println
(
"
file open failed
"
);
}
file1.
close
();
}
void
SPIFFS_Debug::debugReadDebug2
() {
file2 =
SPIFFS
.
open
(debug2,
"
r
"
);
if
(file2) {
fileConf =
SPIFFS
.
open
(debugConf,
"
r
"
);
int
startPoint =
readAddrs
(fileConf,
7
)*(
256
^
2
) +
readAddrs
(fileConf,
6
)*
256
+
readAddrs
(fileConf,
5
);
file1.
seek
(startPoint, SeekSet);
Serial.
print
(
"
file size is:
"
);
Serial.
println
(file2.
size
());
Serial.
println
(
"
====== Reading from debug2 file =======
"
);
while
(file2.
available
()){
String lineContent = file2.
readStringUntil
(
'
\n
'
);
Serial.
println
(lineContent);
}
file1.
seek
(
0
, SeekSet);
while
(file2.
position
() < startPoint){
String lineContent = file2.
readStringUntil
(
'
\n
'
);
Serial.
println
(lineContent);
}
Serial.
println
(
"
====== end of file =======
"
);
}
else
{
Serial.
println
(
"
file open failed
"
);
}
file2.
close
();
}
void
SPIFFS_Debug::debugReadDebugConf
() {
fileConf =
SPIFFS
.
open
(debugConf,
"
r
"
);
if
(fileConf) {
Serial.
println
(
"
====== Reading from SPIFFS file =======
"
);
int
readedByte;
int
pointer =
0
;
while
(fileConf.
available
()){
readedByte = fileConf.
read
();
Serial.
print
(pointer);
Serial.
print
(
"
:
\t
"
);
Serial.
println
(readedByte);
++pointer;
}
Serial.
print
(
"
\n
"
);
}
else
{
Serial.
println
(
"
fileConf open failed
"
);
}
fileConf.
close
();
}
Back
|
FazBrowse Home
|
New Git URL