int om_gsm_power_swap(int value) { const char* power_path = om_gsm_power_path(); if (power_path == NULL) return -1; const char* val = om_sysfs_readfile(power_path); if (val == NULL) return -1; int old_val = atoi(val); // If we are setting it to what it already is, don't bother if (value == old_val) return old_val; if (value) { // Note: the logic here is Enrico cargo-culting Lindi // Turn on const char* reset_path = om_gsm_reset_path(); if (reset_path == NULL) return -1; if (om_sysfs_writefile(power_path, "0\n") < 0) return -1; if (om_sysfs_writefile(power_path, "1\n") < 0) return -1; if (om_sysfs_writefile(reset_path, "1\n") < 0) return -1; } else { // Turn off if (om_sysfs_writefile(power_path, "0\n") < 0) return -1; } return old_val; }
int om_gsm_power_get() { const char* path = om_gsm_power_path(); if (path == NULL) return -1; const char* val = om_sysfs_readfile(path); if (val == NULL) return -1; return atoi(val); }
const char* om_sysfs_swap(const char* name, const char* val) { const char* path = om_sysfs_path(name); const char* res = NULL; if (path == NULL) return NULL; res = om_sysfs_readfile(path); if (om_sysfs_writefile(path, val) != 0) return NULL; return res; }
const char* om_sysfs_get(const char* name) { const char* path = om_sysfs_path(name); if (path == NULL) return NULL; return om_sysfs_readfile(path); }