From 95dfefbe139f9f7c6c34a42ca5d6ae89a419429d Mon Sep 17 00:00:00 2001 From: Denis Ahrens Date: Thu, 31 Jan 2013 18:36:00 +0100 Subject: [PATCH 01/10] correctly read out int values, this fixes the wrong number of keys displayed and all other values which are ints with more than one byte --- smc-command/smc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smc-command/smc.c b/smc-command/smc.c index ff1e48b..e8add92 100644 --- a/smc-command/smc.c +++ b/smc-command/smc.c @@ -37,7 +37,7 @@ UInt32 _strtoul(char *str, int size, int base) if (base == 16) total += str[i] << (size - 1 - i) * 8; else - total += (unsigned char) (str[i] << (size - 1 - i) * 8); + total += ((unsigned char) (str[i]) << (size - 1 - i) * 8); } return total; } From afb554fc6644e637902740a7b870adfa261c15dc Mon Sep 17 00:00:00 2001 From: Denis Ahrens Date: Thu, 31 Jan 2013 18:43:03 +0100 Subject: [PATCH 02/10] add the ID of the fan to the output --- smc-command/smc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/smc-command/smc.c b/smc-command/smc.c index e8add92..9b46a1c 100644 --- a/smc-command/smc.c +++ b/smc-command/smc.c @@ -381,6 +381,9 @@ kern_return_t SMCPrintFans(void) for (i = 0; i < totalFans; i++) { printf("\nFan #%d:\n", i); + sprintf(key, "F%dID", i); + SMCReadKey(key, &val); + printf(" Fan ID : %s\n", val.bytes+4); sprintf(key, "F%dAc", i); SMCReadKey(key, &val); printf(" Actual speed : %.0f\n", _strtof(val.bytes, val.dataSize, 2)); From b125097a0715da4309b54aee7b32bc9a79f2c01b Mon Sep 17 00:00:00 2001 From: Denis Ahrens Date: Thu, 31 Jan 2013 20:31:11 +0100 Subject: [PATCH 03/10] add support for the sp78 format --- smc-command/smc.c | 7 +++++++ smc-command/smc.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/smc-command/smc.c b/smc-command/smc.c index 9b46a1c..9a17e4a 100644 --- a/smc-command/smc.c +++ b/smc-command/smc.c @@ -87,6 +87,11 @@ void printUInt(SMCVal_t val) printf("%u ", (unsigned int) _strtoul(val.bytes, val.dataSize, 10)); } +void printSP78(SMCVal_t val) +{ + printf("%u.%02u ", *val.bytes, (*(val.bytes+1)) * 100 / 256); +} + void printBytesHex(SMCVal_t val) { int i; @@ -108,6 +113,8 @@ void printVal(SMCVal_t val) printUInt(val); else if (strcmp(val.dataType, DATATYPE_FPE2) == 0) printFPE2(val); + else if (strcmp(val.dataType, DATATYPE_SP78) == 0 && val.dataSize == 2) + printSP78(val); printBytesHex(val); } diff --git a/smc-command/smc.h b/smc-command/smc.h index f001abf..b6f57ac 100644 --- a/smc-command/smc.h +++ b/smc-command/smc.h @@ -42,6 +42,7 @@ #define DATATYPE_UINT8 "ui8 " #define DATATYPE_UINT16 "ui16" #define DATATYPE_UINT32 "ui32" +#define DATATYPE_SP78 "sp78" typedef struct { char major; @@ -65,7 +66,7 @@ typedef struct { char dataAttributes; } SMCKeyData_keyInfo_t; -typedef char SMCBytes_t[32]; +typedef unsigned char SMCBytes_t[32]; typedef struct { UInt32 key; From 3b87cc972d986fb167b5f24659f8a4ee699f2bb0 Mon Sep 17 00:00:00 2001 From: Denis Ahrens Date: Fri, 1 Feb 2013 01:47:35 +0100 Subject: [PATCH 04/10] added the two missing bits to the result when decoding FPE2 values --- smc-command/smc.c | 8 ++++---- smc-command/smc.h | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/smc-command/smc.c b/smc-command/smc.c index 9a17e4a..693d8c1 100644 --- a/smc-command/smc.c +++ b/smc-command/smc.c @@ -52,7 +52,7 @@ void _ultostr(char *str, UInt32 val) (unsigned int) val); } -float _strtof(char *str, int size, int e) +float _strtof(unsigned char *str, int size, int e) { float total = 0; int i; @@ -65,6 +65,8 @@ float _strtof(char *str, int size, int e) total += str[i] << (size - 1 - i) * (8 - e); } + total += (str[size-1] & 0x03) * 0.25; + return total; } @@ -77,9 +79,7 @@ void smc_close(){ } void printFPE2(SMCVal_t val) { - /* FIXME: This decode is incomplete, last 2 bits are dropped */ - - printf("%.0f ", _strtof(val.bytes, val.dataSize, 2)); + printf("%.02f ", _strtof(val.bytes, val.dataSize, 2)); } void printUInt(SMCVal_t val) diff --git a/smc-command/smc.h b/smc-command/smc.h index b6f57ac..3a31b8f 100644 --- a/smc-command/smc.h +++ b/smc-command/smc.h @@ -98,5 +98,4 @@ kern_return_t SMCClose(io_connect_t conn); void smc_init(); void smc_close(); -float _strtof(char *str, int size, int e); - +float _strtof(unsigned char *str, int size, int e); From dd63c6565570f51d5bc5693ba0e007ef9a779d07 Mon Sep 17 00:00:00 2001 From: Denis Ahrens Date: Sat, 2 Feb 2013 16:33:23 +0100 Subject: [PATCH 05/10] add support for SI8 signed integer type --- smc-command/smc.c | 7 +++++++ smc-command/smc.h | 1 + 2 files changed, 8 insertions(+) diff --git a/smc-command/smc.c b/smc-command/smc.c index 693d8c1..8a3a780 100644 --- a/smc-command/smc.c +++ b/smc-command/smc.c @@ -92,6 +92,11 @@ void printSP78(SMCVal_t val) printf("%u.%02u ", *val.bytes, (*(val.bytes+1)) * 100 / 256); } +void printSI8(SMCVal_t val) +{ + printf("%d ", (signed char)*val.bytes); +} + void printBytesHex(SMCVal_t val) { int i; @@ -115,6 +120,8 @@ void printVal(SMCVal_t val) printFPE2(val); else if (strcmp(val.dataType, DATATYPE_SP78) == 0 && val.dataSize == 2) printSP78(val); + else if (strcmp(val.dataType, DATATYPE_SI8) == 0 && val.dataSize == 1) + printSI8(val); printBytesHex(val); } diff --git a/smc-command/smc.h b/smc-command/smc.h index 3a31b8f..8f4312d 100644 --- a/smc-command/smc.h +++ b/smc-command/smc.h @@ -43,6 +43,7 @@ #define DATATYPE_UINT16 "ui16" #define DATATYPE_UINT32 "ui32" #define DATATYPE_SP78 "sp78" +#define DATATYPE_SI8 "si8 " typedef struct { char major; From 44c4e1d15ac345d169cd9dbbcffa1f1c29d569f3 Mon Sep 17 00:00:00 2001 From: Denis Ahrens Date: Sat, 2 Feb 2013 16:36:42 +0100 Subject: [PATCH 06/10] add support for SI16 signed integer type --- smc-command/smc.c | 7 +++++++ smc-command/smc.h | 1 + 2 files changed, 8 insertions(+) diff --git a/smc-command/smc.c b/smc-command/smc.c index 8a3a780..2acf9a1 100644 --- a/smc-command/smc.c +++ b/smc-command/smc.c @@ -97,6 +97,11 @@ void printSI8(SMCVal_t val) printf("%d ", (signed char)*val.bytes); } +void printSI16(SMCVal_t val) +{ + printf("%d ", ntohs(*(SInt16*)val.bytes)); +} + void printBytesHex(SMCVal_t val) { int i; @@ -122,6 +127,8 @@ void printVal(SMCVal_t val) printSP78(val); else if (strcmp(val.dataType, DATATYPE_SI8) == 0 && val.dataSize == 1) printSI8(val); + else if (strcmp(val.dataType, DATATYPE_SI16) == 0 && val.dataSize == 2) + printSI16(val); printBytesHex(val); } diff --git a/smc-command/smc.h b/smc-command/smc.h index 8f4312d..f19179e 100644 --- a/smc-command/smc.h +++ b/smc-command/smc.h @@ -44,6 +44,7 @@ #define DATATYPE_UINT32 "ui32" #define DATATYPE_SP78 "sp78" #define DATATYPE_SI8 "si8 " +#define DATATYPE_SI16 "si16" typedef struct { char major; From de8d762534f6134db1b65b8b19b26b8d2168c584 Mon Sep 17 00:00:00 2001 From: Denis Ahrens Date: Sun, 3 Feb 2013 04:00:55 +0100 Subject: [PATCH 07/10] SP78 is signed, so print it that way --- smc-command/smc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smc-command/smc.c b/smc-command/smc.c index 2acf9a1..d8f2311 100644 --- a/smc-command/smc.c +++ b/smc-command/smc.c @@ -89,7 +89,7 @@ void printUInt(SMCVal_t val) void printSP78(SMCVal_t val) { - printf("%u.%02u ", *val.bytes, (*(val.bytes+1)) * 100 / 256); + printf("%d.%02u ", (signed char)*val.bytes, (*(val.bytes+1)) * 100 / 256); } void printSI8(SMCVal_t val) From 7ea2001e4987dc2c712dc9d19ace5810828f5302 Mon Sep 17 00:00:00 2001 From: Denis Ahrens Date: Sun, 3 Feb 2013 04:38:00 +0100 Subject: [PATCH 08/10] add '{pwm' decoding support --- smc-command/smc.c | 7 +++++++ smc-command/smc.h | 1 + 2 files changed, 8 insertions(+) diff --git a/smc-command/smc.c b/smc-command/smc.c index d8f2311..033606a 100644 --- a/smc-command/smc.c +++ b/smc-command/smc.c @@ -102,6 +102,11 @@ void printSI16(SMCVal_t val) printf("%d ", ntohs(*(SInt16*)val.bytes)); } +void printPWM(SMCVal_t val) +{ + printf("%.1f%% ", ntohs(*(UInt16*)val.bytes) * 100 / 65536.0); +} + void printBytesHex(SMCVal_t val) { int i; @@ -129,6 +134,8 @@ void printVal(SMCVal_t val) printSI8(val); else if (strcmp(val.dataType, DATATYPE_SI16) == 0 && val.dataSize == 2) printSI16(val); + else if (strcmp(val.dataType, DATATYPE_PWM) == 0 && val.dataSize == 2) + printPWM(val); printBytesHex(val); } diff --git a/smc-command/smc.h b/smc-command/smc.h index f19179e..9176543 100644 --- a/smc-command/smc.h +++ b/smc-command/smc.h @@ -45,6 +45,7 @@ #define DATATYPE_SP78 "sp78" #define DATATYPE_SI8 "si8 " #define DATATYPE_SI16 "si16" +#define DATATYPE_PWM "{pwm" typedef struct { char major; From 77280ab43ced774d670c995bf57eded697f66109 Mon Sep 17 00:00:00 2001 From: Denis Ahrens Date: Tue, 5 Feb 2013 20:54:26 +0100 Subject: [PATCH 09/10] support all found sp/fp oocurances I found so far --- smc-command/smc.c | 91 +++++++++++++++++++++++++++++++++++++++++++++-- smc-command/smc.h | 18 +++++++++- 2 files changed, 105 insertions(+), 4 deletions(-) diff --git a/smc-command/smc.c b/smc-command/smc.c index 033606a..b2f4851 100644 --- a/smc-command/smc.c +++ b/smc-command/smc.c @@ -77,9 +77,50 @@ void smc_init(){ void smc_close(){ SMCClose(conn); } + +void printFP1F(SMCVal_t val) +{ + printf("%.5f ", ntohs(*(UInt16*)val.bytes) / 32768.0); +} + +void printFP4C(SMCVal_t val) +{ + printf("%.5f ", ntohs(*(UInt16*)val.bytes) / 4096.0); +} + +void printFP5B(SMCVal_t val) +{ + printf("%.5f ", ntohs(*(UInt16*)val.bytes) / 2048.0); +} + +void printFP6A(SMCVal_t val) +{ + printf("%.4f ", ntohs(*(UInt16*)val.bytes) / 1024.0); +} + +void printFP79(SMCVal_t val) +{ + printf("%.4f ", ntohs(*(UInt16*)val.bytes) / 512.0); +} + +void printFP88(SMCVal_t val) +{ + printf("%.3f ", ntohs(*(UInt16*)val.bytes) / 256.0); +} + +void printFPA6(SMCVal_t val) +{ + printf("%.2f ", ntohs(*(UInt16*)val.bytes) / 64.0); +} + +void printFPC4(SMCVal_t val) +{ + printf("%.2f ", ntohs(*(UInt16*)val.bytes) / 16.0); +} + void printFPE2(SMCVal_t val) { - printf("%.02f ", _strtof(val.bytes, val.dataSize, 2)); + printf("%.2f ", ntohs(*(UInt16*)val.bytes) / 4.0); } void printUInt(SMCVal_t val) @@ -89,7 +130,27 @@ void printUInt(SMCVal_t val) void printSP78(SMCVal_t val) { - printf("%d.%02u ", (signed char)*val.bytes, (*(val.bytes+1)) * 100 / 256); + printf("%.3f ", ((SInt16)ntohs(*(UInt16*)val.bytes)) / 256.0); +} + +void printSP87(SMCVal_t val) +{ + printf("%.3f ", ((SInt16)ntohs(*(UInt16*)val.bytes)) / 128.0); +} + +void printSP96(SMCVal_t val) +{ + printf("%.2f ", ((SInt16)ntohs(*(UInt16*)val.bytes)) / 64.0); +} + +void printSPB4(SMCVal_t val) +{ + printf("%.2f ", ((SInt16)ntohs(*(UInt16*)val.bytes)) / 16.0); +} + +void printSPF0(SMCVal_t val) +{ + printf("%.0f ", (float)ntohs(*(UInt16*)val.bytes)); } void printSI8(SMCVal_t val) @@ -126,10 +187,34 @@ void printVal(SMCVal_t val) (strcmp(val.dataType, DATATYPE_UINT16) == 0) || (strcmp(val.dataType, DATATYPE_UINT32) == 0)) printUInt(val); - else if (strcmp(val.dataType, DATATYPE_FPE2) == 0) + else if (strcmp(val.dataType, DATATYPE_FP1F) == 0 && val.dataSize == 2) + printFP1F(val); + else if (strcmp(val.dataType, DATATYPE_FP4C) == 0 && val.dataSize == 2) + printFP4C(val); + else if (strcmp(val.dataType, DATATYPE_FP5B) == 0 && val.dataSize == 2) + printFP5B(val); + else if (strcmp(val.dataType, DATATYPE_FP6A) == 0 && val.dataSize == 2) + printFP6A(val); + else if (strcmp(val.dataType, DATATYPE_FP79) == 0 && val.dataSize == 2) + printFP79(val); + else if (strcmp(val.dataType, DATATYPE_FP88) == 0 && val.dataSize == 2) + printFP88(val); + else if (strcmp(val.dataType, DATATYPE_FPA6) == 0 && val.dataSize == 2) + printFPA6(val); + else if (strcmp(val.dataType, DATATYPE_FPC4) == 0 && val.dataSize == 2) + printFPC4(val); + else if (strcmp(val.dataType, DATATYPE_FPE2) == 0 && val.dataSize == 2) printFPE2(val); else if (strcmp(val.dataType, DATATYPE_SP78) == 0 && val.dataSize == 2) printSP78(val); + else if (strcmp(val.dataType, DATATYPE_SP87) == 0 && val.dataSize == 2) + printSP87(val); + else if (strcmp(val.dataType, DATATYPE_SP96) == 0 && val.dataSize == 2) + printSP96(val); + else if (strcmp(val.dataType, DATATYPE_SPB4) == 0 && val.dataSize == 2) + printSPB4(val); + else if (strcmp(val.dataType, DATATYPE_SPF0) == 0 && val.dataSize == 2) + printSPF0(val); else if (strcmp(val.dataType, DATATYPE_SI8) == 0 && val.dataSize == 1) printSI8(val); else if (strcmp(val.dataType, DATATYPE_SI16) == 0 && val.dataSize == 2) diff --git a/smc-command/smc.h b/smc-command/smc.h index 9176543..15e766f 100644 --- a/smc-command/smc.h +++ b/smc-command/smc.h @@ -38,13 +38,29 @@ #define SMC_CMD_READ_PLIMIT 11 #define SMC_CMD_READ_VERS 12 +#define DATATYPE_FP1F "fp1f" +#define DATATYPE_FP4C "fp4c" +#define DATATYPE_FP5B "fp5b" +#define DATATYPE_FP6A "fp6a" +#define DATATYPE_FP79 "fp79" +#define DATATYPE_FP88 "fp88" +#define DATATYPE_FPA6 "fpa6" +#define DATATYPE_FPC4 "fpc4" #define DATATYPE_FPE2 "fpe2" + +#define DATATYPE_SP78 "sp78" +#define DATATYPE_SP87 "sp87" +#define DATATYPE_SP96 "sp96" +#define DATATYPE_SPB4 "spb4" +#define DATATYPE_SPF0 "spf0" + #define DATATYPE_UINT8 "ui8 " #define DATATYPE_UINT16 "ui16" #define DATATYPE_UINT32 "ui32" -#define DATATYPE_SP78 "sp78" + #define DATATYPE_SI8 "si8 " #define DATATYPE_SI16 "si16" + #define DATATYPE_PWM "{pwm" typedef struct { From afebcc65f1dea63ccb41140e0d8a4f27b2cd3862 Mon Sep 17 00:00:00 2001 From: Denis Ahrens Date: Tue, 5 Feb 2013 21:45:39 +0100 Subject: [PATCH 10/10] add more encoding types --- smc-command/smc.c | 35 +++++++++++++++++++++++++++++++++++ smc-command/smc.h | 5 +++++ 2 files changed, 40 insertions(+) diff --git a/smc-command/smc.c b/smc-command/smc.c index b2f4851..ba8defc 100644 --- a/smc-command/smc.c +++ b/smc-command/smc.c @@ -128,6 +128,31 @@ void printUInt(SMCVal_t val) printf("%u ", (unsigned int) _strtoul(val.bytes, val.dataSize, 10)); } +void printSP1E(SMCVal_t val) +{ + printf("%.5f ", ((SInt16)ntohs(*(UInt16*)val.bytes)) / 16384.0); +} + +void printSP3C(SMCVal_t val) +{ + printf("%.5f ", ((SInt16)ntohs(*(UInt16*)val.bytes)) / 4096.0); +} + +void printSP4B(SMCVal_t val) +{ + printf("%.4f ", ((SInt16)ntohs(*(UInt16*)val.bytes)) / 2048.0); +} + +void printSP5A(SMCVal_t val) +{ + printf("%.4f ", ((SInt16)ntohs(*(UInt16*)val.bytes)) / 1024.0); +} + +void printSP69(SMCVal_t val) +{ + printf("%.3f ", ((SInt16)ntohs(*(UInt16*)val.bytes)) / 512.0); +} + void printSP78(SMCVal_t val) { printf("%.3f ", ((SInt16)ntohs(*(UInt16*)val.bytes)) / 256.0); @@ -205,6 +230,16 @@ void printVal(SMCVal_t val) printFPC4(val); else if (strcmp(val.dataType, DATATYPE_FPE2) == 0 && val.dataSize == 2) printFPE2(val); + else if (strcmp(val.dataType, DATATYPE_SP1E) == 0 && val.dataSize == 2) + printSP1E(val); + else if (strcmp(val.dataType, DATATYPE_SP3C) == 0 && val.dataSize == 2) + printSP3C(val); + else if (strcmp(val.dataType, DATATYPE_SP4B) == 0 && val.dataSize == 2) + printSP4B(val); + else if (strcmp(val.dataType, DATATYPE_SP5A) == 0 && val.dataSize == 2) + printSP5A(val); + else if (strcmp(val.dataType, DATATYPE_SP69) == 0 && val.dataSize == 2) + printSP69(val); else if (strcmp(val.dataType, DATATYPE_SP78) == 0 && val.dataSize == 2) printSP78(val); else if (strcmp(val.dataType, DATATYPE_SP87) == 0 && val.dataSize == 2) diff --git a/smc-command/smc.h b/smc-command/smc.h index 15e766f..4ad4798 100644 --- a/smc-command/smc.h +++ b/smc-command/smc.h @@ -48,6 +48,11 @@ #define DATATYPE_FPC4 "fpc4" #define DATATYPE_FPE2 "fpe2" +#define DATATYPE_SP1E "sp1e" +#define DATATYPE_SP3C "sp3c" +#define DATATYPE_SP4B "sp4b" +#define DATATYPE_SP5A "sp5a" +#define DATATYPE_SP69 "sp69" #define DATATYPE_SP78 "sp78" #define DATATYPE_SP87 "sp87" #define DATATYPE_SP96 "sp96"