uint8_t getBusChannel()

in i2c_pkg/src/battery_node.cpp [60:89]


        uint8_t getBusChannel(){
            uint8_t busChannel = 7; // Default from previous release
            // ls -al /sys/class/i2c-dev/ 
            for (const auto & entry : std::filesystem::directory_iterator(SYSPATH)){
                auto filepath = entry.path();
                // grep "0000:00:17.3" 
                if(std::filesystem::exists(filepath) && std::filesystem::is_symlink(filepath)){
                    std::string symlinkTarget = std::filesystem::read_symlink(filepath).c_str();
                    if (symlinkTarget.find(BATDEV) != std::string::npos) {
                        auto tmp = symlinkTarget;
                        std::string delimiter = "/";
                        size_t pos = 0;
                        std::string token;
                        size_t tokenCount = 0;
                        // awk '{ print $9}'
                        while ((pos = tmp.find(delimiter)) != std::string::npos && tokenCount < 8) {
                            tmp.erase(0, pos + delimiter.length());
                            tokenCount++;
                        }
                        // awk -F "-" '{ print $2}'
                        delimiter = "-";
                        if ((pos = tmp.find(delimiter)) != std::string::npos) {
                            tmp.erase(0, pos + delimiter.length());
                        }
                        busChannel = std::stoi(tmp);
                    }
                }
            }
            return busChannel;
        }