4
4
// Created by zhao hui jiang on 07/03/2020.
5
5
// Copyright (c). All rights reserved.
6
6
//
7
- #include " pack .h"
7
+ #include " pack_fat .h"
8
8
9
9
static const char *BASE_PATH = " /fatfs" ;
10
10
static RAM_handle_t s_ram_handle;
@@ -20,9 +20,9 @@ struct dirent_1 {
20
20
char d_name[256 ]; /* !< zero-terminated file name */
21
21
}dirent_t ;
22
22
23
- Pack::Pack ()
23
+ Pack_fat::Pack_fat ()
24
24
{}
25
- Pack ::~Pack ()
25
+ Pack_fat ::~Pack_fat ()
26
26
{}
27
27
28
28
/* *
@@ -31,7 +31,7 @@ Pack::~Pack()
31
31
* @param
32
32
* @return True or false.
33
33
*/
34
- bool Pack::fatfsMount (int s_imageSize) {
34
+ bool Pack_fat::fsMount (int s_imageSize) {
35
35
bool result;
36
36
esp_vfs_fat_mount_config_t mountConfig;
37
37
mountConfig.max_files = 4 ; // Max files.
@@ -47,7 +47,7 @@ bool Pack::fatfsMount(int s_imageSize) {
47
47
* @param
48
48
* @return True or false.
49
49
*/
50
- bool Pack::fatfsUnmount () {
50
+ bool Pack_fat::fsUnmount () {
51
51
bool result;
52
52
53
53
result = (ESP_OK == emulate_esp_vfs_fat_spiflash_unmount (BASE_PATH, s_ram_handle));
@@ -63,7 +63,7 @@ bool Pack::fatfsUnmount() {
63
63
return result;
64
64
}
65
65
66
- size_t Pack ::getFileSize (FILE* fp)
66
+ size_t Pack_fat ::getFileSize (FILE* fp)
67
67
{
68
68
fseek (fp, 0L , SEEK_END);
69
69
size_t size = (size_t ) ftell (fp);
@@ -77,7 +77,7 @@ size_t Pack::getFileSize(FILE* fp)
77
77
* @return True if exists otherwise false.
78
78
*
79
79
*/
80
- bool Pack ::dirExists (const char * path) {
80
+ bool Pack_fat ::dirExists (const char * path) {
81
81
DIR *d = opendir (path);
82
82
83
83
if (d) {
@@ -93,7 +93,7 @@ bool Pack::dirExists(const char* path) {
93
93
* @param path Directory path.
94
94
* @return True or false.
95
95
*/
96
- bool Pack ::dirCreate (const char * path) {
96
+ bool Pack_fat ::dirCreate (const char * path) {
97
97
// Check if directory also exists.
98
98
if (dirExists (path)) {
99
99
return false ;
@@ -117,7 +117,7 @@ bool Pack::dirCreate(const char* path) {
117
117
* @param path Directory name, full path.
118
118
* @return True or false.
119
119
*/
120
- int Pack ::parkDirToRamFS (const char * name) {
120
+ int Pack_fat ::parkDirToRamFS (const char * name) {
121
121
std::string fileName = name;
122
122
fileName += " /." ;
123
123
@@ -140,7 +140,7 @@ int Pack::parkDirToRamFS(const char* name) {
140
140
* @param path_des des Directory path, full path.
141
141
* @return True or false.
142
142
*/
143
- int Pack ::parkFileToRamFS (char * path_src, const char * path_des) {
143
+ int Pack_fat ::parkFileToRamFS (char * path_src, const char * path_des) {
144
144
FILE* f_src = fopen (path_src, " rb" ); // open file in pc.
145
145
if (!f_src) {
146
146
std::cerr << " error: failed to open " << path_src << " for reading" << std::endl;
@@ -200,7 +200,7 @@ int Pack::parkFileToRamFS(char* path_src, const char* path_des) {
200
200
* @return True if exists otherwise false.
201
201
*
202
202
*/
203
- bool Pack ::parkFilesToRamFS (const char * dirSrc, const char * dirDes)
203
+ bool Pack_fat ::parkFilesToRamFS (const char * dirSrc, const char * dirDes)
204
204
{
205
205
DIR *dir;
206
206
bool error = false ;
@@ -314,7 +314,7 @@ bool Pack::parkFilesToRamFS(const char* dirSrc, const char* dirDes)
314
314
* @param path_des: des file, to pc
315
315
* @return True or false.
316
316
*/
317
- int Pack ::unparkFileFromRamFS (const char * path_src, const char * path_des)
317
+ int Pack_fat ::unparkFileFromRamFS (const char * path_src, const char * path_des)
318
318
{
319
319
std::vector<uint8_t > temp_buf;
320
320
@@ -354,7 +354,7 @@ int Pack::unparkFileFromRamFS(const char* path_src, const char* path_des)
354
354
* @param dirDes directory/file in pc.
355
355
* @return True or false.
356
356
*/
357
- bool Pack ::unparkFilesFromRamFS (const char * dirSrc, const char * dirDes)
357
+ bool Pack_fat ::unparkFilesFromRamFS (const char * dirSrc, const char * dirDes)
358
358
{
359
359
DIR *dir;
360
360
struct dirent_1 *ent;
@@ -434,14 +434,14 @@ bool Pack::unparkFilesFromRamFS(const char* dirSrc, const char* dirDes)
434
434
* @param
435
435
* @return True or false.
436
436
*/
437
- int Pack ::actionPack (std::string s_dirName, std::string s_imageName, int s_imageSize) {
437
+ int Pack_fat ::actionPack (std::string s_dirName, std::string s_imageName, int s_imageSize) {
438
438
int ret = 0 ; // 0 - ok
439
439
440
440
// 1. resize g_flashmem and fill 0xff, it will used for RAM fat filesystem.
441
441
g_flashmem.resize (s_imageSize, 0xff );
442
442
443
443
// 2. mount g_flashmem(in RAM) as a fat filesystem, mount point is BASE_PATH(root directory of the RAM filesystem).
444
- if (fatfsMount (s_imageSize)) {
444
+ if (fsMount (s_imageSize)) {
445
445
if (g_debugLevel > 0 ) {
446
446
std::cout << " Mounted successfully" << std::endl;
447
447
}
@@ -454,7 +454,7 @@ int Pack::actionPack(std::string s_dirName, std::string s_imageName, int s_image
454
454
ret = parkFilesToRamFS (s_dirName.c_str (), BASE_PATH);
455
455
456
456
// 4. unmount the RAM fat filesystem.
457
- fatfsUnmount ();
457
+ fsUnmount ();
458
458
459
459
// 5. open *.bin file witch read from esp32.
460
460
FILE* fdres = fopen (s_imageName.c_str (), " wb" );
@@ -483,7 +483,7 @@ int Pack::actionPack(std::string s_dirName, std::string s_imageName, int s_image
483
483
* @param s_dirName directory in pc, we will read all files to it.
484
484
* @return 0 success, 1 error
485
485
*/
486
- int Pack ::actionUnpack (std::string s_imageName, std::string s_dirName,int s_imageSize)
486
+ int Pack_fat ::actionUnpack (std::string s_imageName, std::string s_dirName,int s_imageSize)
487
487
{
488
488
int ret = 0 ;
489
489
@@ -505,7 +505,7 @@ int Pack::actionUnpack(std::string s_imageName, std::string s_dirName,int s_imag
505
505
fclose (f_src);
506
506
507
507
// 3. mount RAM(g_flashmem) file system, so we can use vfs read file in RAM file system.
508
- if (fatfsMount (s_imageSize)) {
508
+ if (fsMount (s_imageSize)) {
509
509
if (g_debugLevel > 0 ) {
510
510
std::cout << " Mounted successfully" << std::endl;
511
511
}
@@ -523,7 +523,7 @@ int Pack::actionUnpack(std::string s_imageName, std::string s_dirName,int s_imag
523
523
}
524
524
525
525
// unmount file system
526
- fatfsUnmount ();
526
+ fsUnmount ();
527
527
528
528
return ret;
529
529
}
0 commit comments