Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
prof_r
firmware
Commits
d29f8f95
Commit
d29f8f95
authored
5 years ago
by
schneider
Browse files
Options
Downloads
Plain Diff
Merge branch 'ble-file-transfer-dir' into 'master'
BLE: FileTrans: Create a directory if needed See merge request
!152
parents
638ab1d5
00578959
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
epicardium/ble/filetransfer.c
+51
-8
51 additions, 8 deletions
epicardium/ble/filetransfer.c
with
51 additions
and
8 deletions
epicardium/ble/filetransfer.c
+
51
−
8
View file @
d29f8f95
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
#include
"hci_vs.h"
#include
"hci_vs.h"
#include
<epicardium.h>
#include
<epicardium.h>
#include
"modules/log.h"
#include
"util/bstream.h"
#include
"util/bstream.h"
#include
"att_api.h"
#include
"att_api.h"
...
@@ -40,6 +41,7 @@
...
@@ -40,6 +41,7 @@
#include
"FreeRTOS.h"
#include
"FreeRTOS.h"
#include
"crc32.h"
#include
"crc32.h"
#include
<stdlib.h>
#include
<stdio.h>
#include
<stdio.h>
#include
<string.h>
#include
<string.h>
#include
<stdbool.h>
#include
<stdbool.h>
...
@@ -217,9 +219,11 @@ static void sendCrcResponse(
...
@@ -217,9 +219,11 @@ static void sendCrcResponse(
msg
,
msg
,
sizeof
(
answer
)
-
len
);
sizeof
(
answer
)
-
len
);
len
+=
strlen
(
msg
);
len
+=
strlen
(
msg
);
printf
(
"BLE
file
trans
fer:
%s
\n
"
,
msg
);
LOG_ERR
(
"
filetrans
"
,
"
%s
\n
"
,
msg
);
}
else
{
}
else
{
printf
(
"error message
\"
%s
\"
too long
\n
"
,
msg
);
LOG_ERR
(
"filetrans"
,
"error message
\"
%s
\"
too long
\n
"
,
msg
);
}
}
}
}
...
@@ -227,6 +231,41 @@ static void sendCrcResponse(
...
@@ -227,6 +231,41 @@ static void sendCrcResponse(
AttsHandleValueNtf
(
connId
,
FILE_TRANS_CENTRAL_RX_VAL_HDL
,
len
,
answer
);
AttsHandleValueNtf
(
connId
,
FILE_TRANS_CENTRAL_RX_VAL_HDL
,
len
,
answer
);
}
}
/*
* This function splits the path into the folders and the file name and
* creates all the missing folders.
*/
static
int
bleFileCreateOrOpen
(
char
*
filepath
)
{
char
*
pathEnd
;
int
pos
=
0
;
int
ret
;
while
(
true
)
{
pathEnd
=
strchr
(
filepath
+
pos
,
'/'
);
if
(
!
pathEnd
)
return
epic_file_open
(
filepath
,
"w"
);
pathEnd
[
0
]
=
'\00'
;
pos
=
pathEnd
-
filepath
+
1
;
if
(
strlen
(
filepath
))
{
ret
=
epic_file_stat
(
filepath
,
NULL
);
if
(
ret
==
-
ENOENT
)
{
ret
=
epic_file_mkdir
(
filepath
);
if
(
ret
)
{
LOG_ERR
(
"filetrans"
,
"mkdir failed: %s, ret: %i
\n
"
,
filepath
,
ret
);
return
ret
;
}
}
}
pathEnd
[
0
]
=
'/'
;
}
}
static
uint8_t
bleFileOpen
(
dmConnId_t
connId
,
uint8_t
*
pValue
,
uint16_t
len
)
static
uint8_t
bleFileOpen
(
dmConnId_t
connId
,
uint8_t
*
pValue
,
uint16_t
len
)
{
{
char
filepath
[
100
];
char
filepath
[
100
];
...
@@ -238,11 +277,12 @@ static uint8_t bleFileOpen(dmConnId_t connId, uint8_t *pValue, uint16_t len)
...
@@ -238,11 +277,12 @@ static uint8_t bleFileOpen(dmConnId_t connId, uint8_t *pValue, uint16_t len)
/* Copy only file path and not type, make sure this is NULL terminated */
/* Copy only file path and not type, make sure this is NULL terminated */
strncpy
(
filepath
,
(
char
*
)
pValue
+
1
,
len
-
1
);
strncpy
(
filepath
,
(
char
*
)
pValue
+
1
,
len
-
1
);
filepath
[
len
-
1
]
=
0
;
if
(
file_fd
!=
-
1
)
if
(
file_fd
!=
-
1
)
epic_file_close
(
file_fd
);
epic_file_close
(
file_fd
);
file_fd
=
epic_file_o
pen
(
filepath
,
"w"
);
file_fd
=
bleFileCreateOrO
pen
(
filepath
);
if
(
file_fd
<
0
)
{
if
(
file_fd
<
0
)
{
sendCrcResponse
(
connId
,
'e'
,
0
,
NULL
,
"open failed"
);
sendCrcResponse
(
connId
,
'e'
,
0
,
NULL
,
"open failed"
);
return
ATT_ERR_RESOURCES
;
return
ATT_ERR_RESOURCES
;
...
@@ -305,7 +345,8 @@ static uint8_t handleCentralTX(
...
@@ -305,7 +345,8 @@ static uint8_t handleCentralTX(
}
else
if
(
}
else
if
(
operation
!=
ATT_PDU_EXEC_WRITE_REQ
&&
operation
!=
ATT_PDU_EXEC_WRITE_REQ
&&
operation
!=
ATT_PDU_WRITE_CMD
)
{
operation
!=
ATT_PDU_WRITE_CMD
)
{
printf
(
"operation 0x%x not supported, try normal write
\n
"
,
LOG_ERR
(
"filetrans"
,
"operation 0x%x not supported, try normal write
\n
"
,
operation
);
operation
);
return
ATT_ERR_INVALID_PDU
;
return
ATT_ERR_INVALID_PDU
;
}
}
...
@@ -334,7 +375,7 @@ static uint8_t handleCentralTX(
...
@@ -334,7 +375,7 @@ static uint8_t handleCentralTX(
return
ATT_SUCCESS
;
return
ATT_SUCCESS
;
case
'E'
:
case
'E'
:
printf
(
"Error was acked"
);
LOG_ERR
(
"filetrans"
,
"Error was acked"
);
return
ATT_SUCCESS
;
return
ATT_SUCCESS
;
default:
default:
...
@@ -365,7 +406,9 @@ static uint8_t writeCallback(
...
@@ -365,7 +406,9 @@ static uint8_t writeCallback(
connId
,
handle
,
operation
,
offset
,
len
,
pValue
,
pAttr
connId
,
handle
,
operation
,
offset
,
len
,
pValue
,
pAttr
);
);
default:
default:
printf
(
"unsupported characteristic: %c
\n
"
,
handle
);
LOG_ERR
(
"filetrans"
,
"unsupported characteristic: %c
\n
"
,
handle
);
return
ATT_ERR_HANDLE
;
return
ATT_ERR_HANDLE
;
}
}
}
}
...
@@ -377,7 +420,7 @@ static uint8_t readCallback(
...
@@ -377,7 +420,7 @@ static uint8_t readCallback(
uint16_t
offset
,
uint16_t
offset
,
attsAttr_t
*
pAttr
attsAttr_t
*
pAttr
)
{
)
{
printf
(
"read callback
\n
"
);
LOG_ERR
(
"filetrans"
,
"read callback
\n
"
);
return
ATT_SUCCESS
;
return
ATT_SUCCESS
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment