SD卡统一管理接口,可实现监听SD卡插拔事件,挂载/卸载SD卡,格式化等操作 更多...

SDCard 的协作图:

class  Emx::SDCard
 提供操作设备SD卡相关接口 更多...
 
class  Emx::SDCardClient
 操作设备SD卡的客户端接口 更多...
 
class  Emx::SDCardClientEvent
 用于监听SD卡插拔事件 更多...
 
class  Emx::SDCardServerLib
 

详细描述

  sdcard模块提供服务程序SDCardServer,以及动态库libSDCard.so供客户使用,sdcard模块负责监控TF卡的热插拔,当TF卡插上时,模块会做快速插拔的过滤,当检测到TF卡稳定插上后会自动进行挂载操作,当挂载成功后会触发回调来通知监听的用户进程,同样当TF卡被拔出后用户会收到拔出事件,此时用户需要尽快将涉及TF卡的读写操作停止,使得TF卡被顺利卸载,sdcard模块会在后台持续尝试卸载TF卡。另外除了热插拔的被动监听,sdcard模块还提供主动获取tf卡容量状态以及格式化TF卡等操作的接口。sdcard模块需要配置文件sdcard.json如下所示

sdcard.json
[
{
"mountPoint": "/mnt/sdcard",
"devPart": "mmcblk0p1",
"devPartBak": "mmcblk0",
"devMajor": "mmcblk0"
}
]
Key Type Description
mountPoint string sd卡在设备上的挂载目录
devPart string 用于检测sd卡在dev目录下的挂载节点
devPartBak string 用于检测sd卡在dev目录下的备用挂载节点,有可能sd卡不存在p1分区,这个用来做备用
devMajor string sd卡挂载的主设备号,用于sd卡的格式化重新分区

  可以看到sdcard.json中是一个对象数组,也就是说sdcard模块是支持多个sd卡的

SDCard监听示例
// SD卡状态监听示例
class DemoSDCardEvent {
public:
void Create(EuvLoop &loop, char *buffer, int bufferSize) {
// 注册监听事件
m_event = new SDCardClientEvent(loop, buffer, bufferSize,
std::bind(&DemoSDCardEvent::OnSDCardEvent, this, ph_1, ph_2));
m_event->Create();
}
void Destroy() {
// 销毁监听
m_event->Destroy();
delete m_event;
}
private:
// 当SD卡状态发生变化的时候触发此回调
void OnSDCardEvent(int chn, SDCard::Info &info) {
emxlogi("chn[%d] dev[%s] stat[%d] fileSystem[%d] total[%u] free[%u] used[%u] mountPoint[%s]\n",
chn, info.dev, (int) info.stat, (int) info.fileSystem, info.total, info.free, info.used,
info.mountPoint);
}
private:
SDCardClientEvent *m_event; // 用于注册监听SDCard事件
};