forked from mirror/smcFanControl
Add -t option to read temperatures
This commit is contained in:
@ -549,12 +549,53 @@ kern_return_t SMCPrintFans(void)
|
|||||||
return kIOReturnSuccess;
|
return kIOReturnSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kern_return_t SMCPrintTemps(void)
|
||||||
|
{
|
||||||
|
kern_return_t result;
|
||||||
|
SMCKeyData_t inputStructure;
|
||||||
|
SMCKeyData_t outputStructure;
|
||||||
|
|
||||||
|
int totalKeys, i;
|
||||||
|
UInt32Char_t key;
|
||||||
|
SMCVal_t val;
|
||||||
|
|
||||||
|
totalKeys = SMCReadIndexCount();
|
||||||
|
for (i = 0; i < totalKeys; i++)
|
||||||
|
{
|
||||||
|
memset(&inputStructure, 0, sizeof(SMCKeyData_t));
|
||||||
|
memset(&outputStructure, 0, sizeof(SMCKeyData_t));
|
||||||
|
memset(&val, 0, sizeof(SMCVal_t));
|
||||||
|
|
||||||
|
inputStructure.data8 = SMC_CMD_READ_INDEX;
|
||||||
|
inputStructure.data32 = i;
|
||||||
|
|
||||||
|
result = SMCCall(KERNEL_INDEX_SMC, &inputStructure, &outputStructure);
|
||||||
|
if (result != kIOReturnSuccess)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
_ultostr(key, outputStructure.key);
|
||||||
|
if ( key[0] != 'T' )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
SMCReadKey(key, &val);
|
||||||
|
//printVal(val);
|
||||||
|
if (strcmp(val.dataType, DATATYPE_SP78) == 0 && val.dataSize == 2) {
|
||||||
|
printf("%-4s ", val.key);
|
||||||
|
printSP78(val);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return kIOReturnSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
void usage(char* prog)
|
void usage(char* prog)
|
||||||
{
|
{
|
||||||
printf("Apple System Management Control (SMC) tool %s\n", VERSION);
|
printf("Apple System Management Control (SMC) tool %s\n", VERSION);
|
||||||
printf("Usage:\n");
|
printf("Usage:\n");
|
||||||
printf("%s [options]\n", prog);
|
printf("%s [options]\n", prog);
|
||||||
printf(" -f : fan info decoded\n");
|
printf(" -f : fan info decoded\n");
|
||||||
|
printf(" -t : list all temperatures\n");
|
||||||
printf(" -h : help\n");
|
printf(" -h : help\n");
|
||||||
printf(" -k <key> : key to manipulate\n");
|
printf(" -k <key> : key to manipulate\n");
|
||||||
printf(" -l : list all keys and values\n");
|
printf(" -l : list all keys and values\n");
|
||||||
@ -595,13 +636,16 @@ int main(int argc, char *argv[])
|
|||||||
UInt32Char_t key = { 0 };
|
UInt32Char_t key = { 0 };
|
||||||
SMCVal_t val;
|
SMCVal_t val;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "fhk:lrw:v")) != -1)
|
while ((c = getopt(argc, argv, "fthk:lrw:v")) != -1)
|
||||||
{
|
{
|
||||||
switch(c)
|
switch(c)
|
||||||
{
|
{
|
||||||
case 'f':
|
case 'f':
|
||||||
op = OP_READ_FAN;
|
op = OP_READ_FAN;
|
||||||
break;
|
break;
|
||||||
|
case 't':
|
||||||
|
op = OP_READ_TEMPS;
|
||||||
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
strncpy(key, optarg, sizeof(key)); //fix for buffer overflow
|
strncpy(key, optarg, sizeof(key)); //fix for buffer overflow
|
||||||
key[sizeof(key) - 1] = '\0';
|
key[sizeof(key) - 1] = '\0';
|
||||||
@ -675,6 +719,11 @@ int main(int argc, char *argv[])
|
|||||||
if (result != kIOReturnSuccess)
|
if (result != kIOReturnSuccess)
|
||||||
printf("Error: SMCPrintFans() = %08x\n", result);
|
printf("Error: SMCPrintFans() = %08x\n", result);
|
||||||
break;
|
break;
|
||||||
|
case OP_READ_TEMPS:
|
||||||
|
result = SMCPrintTemps();
|
||||||
|
if (result != kIOReturnSuccess)
|
||||||
|
printf("Error: SMCPrintFans() = %08x\n", result);
|
||||||
|
break;
|
||||||
case OP_WRITE:
|
case OP_WRITE:
|
||||||
if (strlen(key) > 0)
|
if (strlen(key) > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -30,6 +30,7 @@
|
|||||||
#define OP_READ 2
|
#define OP_READ 2
|
||||||
#define OP_READ_FAN 3
|
#define OP_READ_FAN 3
|
||||||
#define OP_WRITE 4
|
#define OP_WRITE 4
|
||||||
|
#define OP_READ_TEMPS 5
|
||||||
|
|
||||||
#define KERNEL_INDEX_SMC 2
|
#define KERNEL_INDEX_SMC 2
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user