UBC-Thunderbots / Software

Robot Soccer Playing AI
http://www.ubcthunderbots.ca
GNU Lesser General Public License v3.0
47 stars 98 forks source link

Thunderloop Send Error when Battery is Unstable #3199

Closed Mr-Anyone closed 6 days ago

Mr-Anyone commented 1 month ago

Description

resolve #3181. This essentially sends a message when the battery isn't stable.

Testing Done

ran the following code to make sure I can actually read the file!

#include <fstream>
#include <iostream>

static bool isPowerStable()
{
    std::ifstream dmesg_log_file("/var/log/dmesg");
    // if the log file cannot be open, we would return false. Chances are, the battery
    // power supply is indeed stable
    if (!dmesg_log_file.is_open())
    {
        //LOG(WARNING) << "Cannot dmesg log file. Do you have permission?";
        std::cout << "Cannot dmesg log file. Do you have permission?" << std::endl;
        return true;
    }

    std::string line;
    while (getline(dmesg_log_file, line))
    {
        if (line.find("kernel") != std::string::npos)
        {
            return false;
        }
    }

    return true;
}

int main(){
    if(isPowerStable()){
        std::cout << "Yay" << std::endl; 
    }else{
        std::cout << "this is expected as the log message is likely to contain the word 'kernel' " << std::endl; 
    }
}

Resolved Issues

resolves #3181

Review Checklist

Mr-Anyone commented 1 month ago

maybe pull from a buffer?