Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
89dd97b
added enum for unsupported file insert but not mounted
palak-ckar Oct 3, 2024
30bc5bd
Create c-cpp.yml
yashrajsapra Aug 5, 2024
96c6377
Update c-cpp.yml
yashrajsapra Aug 5, 2024
7386cbd
Update c-cpp.yml
yashrajsapra Aug 5, 2024
b02c406
Update c-cpp.yml
yashrajsapra Aug 5, 2024
183971f
Update c-cpp.yml
omkarsm Nov 7, 2025
c8d25b3
Initial version of Generic I2C interface for async communication
Aug 8, 2024
cabdf7e
removed redundent code
Aug 9, 2024
d90e445
Updated parameter names in the constructor
Aug 12, 2024
c88bd03
1. included all the interfaces in aprautils header
Aug 13, 2024
9a047e6
Updated Macros for header file
Aug 13, 2024
75dd2bd
Removed NO_TYPE as it was redundent
Aug 13, 2024
687a7e8
made changes in eventcallback and added setSize
srikaranth Aug 21, 2024
47ae3ff
added functions for extract and merging of Bytes
srikaranth Nov 7, 2025
3d54d11
Update I2CTransactionMessage.h
omkarsm Nov 7, 2025
1818382
Added Linux platform check and fixed protected member access in I2CIn…
Nov 7, 2025
dab5076
Fixed missing stdexcept include in I2CInterface.cpp
Nov 7, 2025
21cfd6a
Fixed missing cstdint include in StorageMinimalInfo.h
Nov 7, 2025
f811ccb
Fixed missing time.h include in Macro.h
Nov 10, 2025
85d88e2
Complete preparation of ApraUtils for public open-source release unde…
Nov 10, 2025
536d31f
Fix test_message.cpp to use correct MESSAGE_TYPE enum values
Nov 10, 2025
ff06f73
1. Test Coverage improved
Nov 10, 2025
e730c85
1. Updated build script to use proper binary name
Nov 10, 2025
e446866
removed unsupported test cases
Nov 10, 2025
7075bc2
Fixed UT
Nov 10, 2025
39dfb4f
Bug fix in decoding
Nov 10, 2025
87e8e33
Updated pipeline to remove depricated method implementaiton
Nov 10, 2025
e37ed70
ignoring deps
Nov 10, 2025
2e4daba
added support for fat32 and detection of unsupported storage type
yashrajsapra Nov 11, 2025
7762b9b
Added Unsupported type in storage
Nov 11, 2025
7e49052
Merge branch 'main' into dev/palak
omkarsm Nov 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"stdexcept": "cpp"
}
}
2 changes: 2 additions & 0 deletions examples/usb_storage_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ string storageStateToString(STORAGE_STATE state) {
switch (state) {
case STORAGE_INSERTED:
return "INSERTED (not mounted)";
case STORAGE_INSERTED_UNSUPPORTED:
return "INSERTED_UNSUPPORTED (unsupported filesystem)";
case STORAGE_MOUNTED:
return "MOUNTED (ready for use)";
case STORAGE_UNSAFE_EJECT:
Expand Down
2 changes: 1 addition & 1 deletion includes/constants/StorageState.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace apra
{
enum STORAGE_STATE
{
STORAGE_INSERTED, STORAGE_MOUNTED, STORAGE_UNSAFE_EJECT, STORAGE_SAFE_EJECT
STORAGE_INSERTED, STORAGE_INSERTED_UNMOUNTED, STORAGE_MOUNTED, STORAGE_UNSAFE_EJECT, STORAGE_SAFE_EJECT
};
}

Expand Down
2 changes: 1 addition & 1 deletion includes/constants/StorageType.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace apra
{
enum STORAGE_TYPE
{
FAT32, NTFS, EXT4
FAT32, NTFS, EXT4, UNSUPPORTED
};

class STORAGE_TYPE_STRING
Expand Down
2 changes: 2 additions & 0 deletions includes/utils/StorageUSB.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class StorageUSB
bool mountWithoutPrivilege(StorageMinimalInfo storageDevice);
StorageMinimalInfo getHighCapacityPartition(std::string deviceNode);
bool isDeviceNodeConnected();
void checkDeviceNode();

bool m_shouldPrint;
std::vector<STORAGE_TYPE> m_supportedTypes;
Expand All @@ -60,6 +61,7 @@ class StorageUSB
bool m_skipMount;
STORAGE_STATE m_state;
std::string m_manualPath;
int8_t m_retryCount;
};

} /* namespace apra */
Expand Down
8 changes: 7 additions & 1 deletion src/constants/StorageType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ std::string STORAGE_TYPE_STRING::getString(STORAGE_TYPE type)
return "ntfs";
case EXT4:
return "ext4";
case UNSUPPORTED:
return "";
default:
return "";
}
Expand All @@ -39,10 +41,14 @@ STORAGE_TYPE STORAGE_TYPE_STRING::getEnum(std::string typeStr)
{
return EXT4;
}
else
else if (typeStr == getString(FAT32))
{
return FAT32;
}
else
{
return UNSUPPORTED;
}
}

} /* namespace apra */
2 changes: 1 addition & 1 deletion src/utils/GPIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ int GPIO::ReadWithInterrupt(unsigned long uSecTout)
}
else if (rc == 0)
{
printf("timeout \n");
// printf("timeout \n");
return -1;
}

Expand Down
69 changes: 52 additions & 17 deletions src/utils/StorageUSB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "utils/Utils.h"
#include <utils/StorageUSB.h>
#include "utils/Macro.h"
#include <algorithm>
#include <iostream>

#define MAX_BUF_LEN 1024

Expand All @@ -36,7 +38,7 @@ StorageUSB::StorageUSB(string mountPath, vector<STORAGE_TYPE> supportedTypes,
bool shouldPrint, bool skipMount) :
m_shouldPrint(shouldPrint), m_supportedTypes(supportedTypes), m_mountPoint(
mountPath), m_deviceNode(), m_partitionNode(), m_skipMount(
skipMount), m_state(STORAGE_SAFE_EJECT), m_manualPath(mountPath)
skipMount), m_state(STORAGE_SAFE_EJECT), m_manualPath(mountPath), m_retryCount(3)
{
string error;
if (m_supportedTypes.empty())
Expand Down Expand Up @@ -147,6 +149,10 @@ string StorageUSB::insertCheck()
m_state = STORAGE_INSERTED;
m_deviceNode = devicePath;
}
if (m_shouldPrint)
{
std::cout << "Device Node is ==========>>>" << m_deviceNode << std::endl;
}
return devicePath;
}
return m_deviceNode;
Expand All @@ -156,6 +162,7 @@ string StorageUSB::mountDevice()
{
string usbMountPath;
string devNode = insertCheck();
bool isSupportedFs = false;
if (m_skipMount)
{
StorageMinimalInfo highPartition = getHighCapacityPartition(devNode);
Expand All @@ -165,6 +172,12 @@ string StorageUSB::mountDevice()
m_mountPoint = usbMountPath;
m_partitionNode = highPartition.m_partition;
}
STORAGE_TYPE type = STORAGE_TYPE_STRING::getEnum(highPartition.m_fsType);
auto it = std::find(m_supportedTypes.begin(),
m_supportedTypes.end(),
type);
isSupportedFs = (it != m_supportedTypes.end());
m_retryCount--;
}
else
{
Expand All @@ -173,10 +186,19 @@ string StorageUSB::mountDevice()
usbMountPath = m_mountPoint;
}
}
if (!usbMountPath.empty())
if (!isSupportedFs)
{
m_state = STORAGE_INSERTED_UNMOUNTED;
}
else if (!usbMountPath.empty())
{
m_state = STORAGE_MOUNTED;
}
else if (!isSupportedFs && !m_retryCount)
{
m_state = STORAGE_INSERTED_UNMOUNTED;
m_retryCount = 0;
}
else
{
if (m_shouldPrint)
Expand Down Expand Up @@ -211,6 +233,8 @@ bool StorageUSB::isUnsafeEject()
if (findMountDeviceBylsblk(m_partitionNode).empty())
{
m_state = STORAGE_UNSAFE_EJECT;
m_deviceNode.clear();
m_retryCount = 3;
return true;
}
return false;
Expand All @@ -231,6 +255,10 @@ StorageMinimalInfo StorageUSB::getHighCapacityPartition(std::string deviceNode)
}
}
}
if (m_shouldPrint)
{
std::cout << "High Capacity Partition is " << highCapacityPartition.m_partition << " == " << highCapacityPartition.m_fsType << " === " << highCapacityPartition.m_size << std::endl;
}
return highCapacityPartition;
}

Expand Down Expand Up @@ -496,22 +524,9 @@ bool StorageUSB::ejectDevice()
{
if (unMountUSBDevice())
{
string ejectCommand = "udisksctl power-off -b " + m_deviceNode;
try
{
string ejectResponse = Utils::exec(ejectCommand, m_shouldPrint);
if (Utils::caseInsensitiveSearch(ejectResponse, "error"))
{
printf("Eject error!\n%s\n", ejectResponse.c_str());
return false;
}
} catch (std::runtime_error &e)
{
printf("eject error: %s\n", e.what());
return false;
}
string ejectCommand = "";
m_state = STORAGE_SAFE_EJECT;

m_retryCount = 3;
m_mountPoint.clear();
m_deviceNode.clear();
m_partitionNode.clear();
Expand All @@ -528,6 +543,10 @@ string StorageUSB::findMountDeviceBylsblk(string devicePartitionNode)
"lsblk " + devicePartitionNode + " --noheadings -o MOUNTPOINT",
m_shouldPrint);
string mountPath = Utils::trim(cmdResponse);
if (m_shouldPrint)
{
std::cout<<"\t mountPath ->" <<mountPath.c_str()<<std::endl;
}
if (mountPath.length()
&& Utils::caseInsensitiveSearch(mountPath,
"not a block device"))
Expand Down Expand Up @@ -624,6 +643,22 @@ bool StorageUSB::getStorageInfo(uint64_t &freeSpaceInMB,
return true;
}

void StorageUSB::checkDeviceNode()
{
struct stat buffer;
string path = m_deviceNode;
if (path.length() && stat(path.c_str(), &buffer) == 0)
{
if (S_ISBLK(buffer.st_mode))
{
return;
}
}
m_state = STORAGE_SAFE_EJECT;
m_deviceNode.clear();
m_retryCount = 3;
}

}
/* namespace apra */

7 changes: 2 additions & 5 deletions src/utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,9 @@ std::string Utils::exec(const std::string &cmd, bool debug)
{
throw std::runtime_error(string("popen() failed for") + cmd);
}
while (!feof(pipe.get()))
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
{
if (fgets(buffer.data(), 128, pipe.get()) != nullptr)
{
result += buffer.data();
}
result += buffer.data();
}
return result;
}
Expand Down