diff --git a/LICENSE b/LICENSE index 16309b6..f6ea560 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014-2017 beltex +Copyright (c) 2014-2020 beltex Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index f0cb2d2..a7e9fe4 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ For more see: ### Requirements -- [Xcode 9.0 (Swift 4.0)](https://developer.apple.com/xcode/downloads/) -- macOS 10.12 Sierra and above **for development** (due to Xcode) +- [Xcode 11.3.1 (Swift 5.0)](https://developer.apple.com/xcode/downloads/) +- macOS 10.15 Sierra and above **for development** (due to Xcode) - OS X 10.9 Mavericks and above **for use** (due to Swift) @@ -84,7 +84,11 @@ HEATSINK_1 34.0°C MEM_SLOTS_PROXIMITY 36.0°C PALM_REST 27.0°C -- Fan -- -[id 0] Right Side +[id 0] Left side + Min: 2160 RPM + Max: 5927 RPM + Current: 2158 RPM +[id 1] Right Side Min: 1299 RPM Max: 6199 RPM Current: 1292 RPM @@ -96,6 +100,7 @@ Battery Ok: true Battery Count: 1 -- Misc -- Disc in ODD: false +SMC Clock: 32998 ``` diff --git a/SMCKit.xcodeproj/project.pbxproj b/SMCKit.xcodeproj/project.pbxproj index a058df4..7802add 100644 --- a/SMCKit.xcodeproj/project.pbxproj +++ b/SMCKit.xcodeproj/project.pbxproj @@ -293,16 +293,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1130; ORGANIZATIONNAME = beltex; TargetAttributes = { 4C982BDC1A040CD500F4A639 = { CreatedOnToolsVersion = 6.1; - LastSwiftMigration = 0900; + LastSwiftMigration = 1130; }; 4CDDA69C1AEC0D010037CE7B = { CreatedOnToolsVersion = 6.3.1; - LastSwiftMigration = 0900; + LastSwiftMigration = 1130; }; 4CE5668A1A00A48800787F6B = { CreatedOnToolsVersion = 6.1; @@ -316,10 +316,11 @@ }; buildConfigurationList = 4CE566851A00A48800787F6B /* Build configuration list for PBXProject "SMCKit" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = 4CE566811A00A48800787F6B; productRefGroup = 4CE5668C1A00A48800787F6B /* Products */; @@ -406,6 +407,7 @@ 4C982BE11A040CD500F4A639 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "-"; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -414,24 +416,26 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; 4C982BE21A040CD500F4A639 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "-"; OTHER_SWIFT_FLAGS = ""; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Release; }; 4CDDA6A11AEC0D010037CE7B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "-"; DEBUG_INFORMATION_FORMAT = dwarf; GCC_NO_COMMON_BLOCKS = YES; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -441,19 +445,20 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; 4CDDA6A21AEC0D010037CE7B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = NO; GCC_NO_COMMON_BLOCKS = YES; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -461,6 +466,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -469,12 +475,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -515,6 +523,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -523,12 +532,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -571,6 +582,7 @@ INFOPLIST_FILE = SMCKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.15; OTHER_SWIFT_FLAGS = "-D DEBUG"; PRODUCT_BUNDLE_IDENTIFIER = "beltex.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -594,6 +606,7 @@ INFOPLIST_FILE = SMCKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.15; PRODUCT_BUNDLE_IDENTIFIER = "beltex.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; diff --git a/SMCKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/SMCKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/SMCKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/SMCKit.xcodeproj/xcshareddata/xcschemes/powermetricsTests.xcscheme b/SMCKit.xcodeproj/xcshareddata/xcschemes/powermetricsTests.xcscheme index de17bde..79d00fa 100644 --- a/SMCKit.xcodeproj/xcshareddata/xcschemes/powermetricsTests.xcscheme +++ b/SMCKit.xcodeproj/xcshareddata/xcschemes/powermetricsTests.xcscheme @@ -1,6 +1,6 @@ - - - - + + - - CFBundlePackageType FMWK CFBundleShortVersionString - 0.2.0-dev + 0.3.0-dev CFBundleSignature ???? CFBundleVersion $(CURRENT_PROJECT_VERSION) NSHumanReadableCopyright - Copyright © 2014 beltex. All rights reserved. + Copyright © 2020 beltex. All rights reserved. NSPrincipalClass diff --git a/SMCKit/SMC.swift b/SMCKit/SMC.swift index 9b14889..4a467db 100644 --- a/SMCKit/SMC.swift +++ b/SMCKit/SMC.swift @@ -96,7 +96,7 @@ extension Double { public extension FourCharCode { init(fromString str: String) { - precondition(str.characters.count == 4) + precondition(str.count == 4) self = str.utf8.reduce(0) { sum, character in return sum << 8 | UInt32(character) @@ -434,6 +434,19 @@ extension SMCKit { return true } + + public static func hexStringToAscii(_ hexString : String) -> String { + + let pattern = "(0x)?([0-9a-f]{2})" + let regex = try! NSRegularExpression(pattern: pattern, options: .caseInsensitive) + let nsString = hexString as NSString + let matches = regex.matches(in: hexString, options: [], range: NSMakeRange(0, nsString.length)) + let characters = matches.map { + Character(UnicodeScalar(UInt32(nsString.substring(with: $0.range(at: 2)), radix: 16)!)!) + } + return String(characters) + } + } //------------------------------------------------------------------------------ @@ -560,18 +573,18 @@ public struct TemperatureSensor { } public enum TemperatureUnit { - case celius + case celsius case fahrenheit case kelvin - public static func toFahrenheit(_ celius: Double) -> Double { + public static func toFahrenheit(_ celsius: Double) -> Double { // https://en.wikipedia.org/wiki/Fahrenheit#Definition_and_conversions - return (celius * 1.8) + 32 + return (celsius * 1.8) + 32 } - public static func toKelvin(_ celius: Double) -> Double { + public static func toKelvin(_ celsius: Double) -> Double { // https://en.wikipedia.org/wiki/Kelvin - return celius + 273.15 + return celsius + 273.15 } } @@ -590,27 +603,26 @@ extension SMCKit { public static func allUnknownTemperatureSensors() throws -> [TemperatureSensor] { let keys = try allKeys() - return keys.filter { $0.code.toString().hasPrefix("T") && $0.info == DataTypes.SP78 && TemperatureSensors.all[$0.code] == nil } - .map { TemperatureSensor(name: "Unknown", code: $0.code) } + .map { TemperatureSensor(name: "Unknown - \($0.code.toString())", code: $0.code) } } /// Get current temperature of a sensor public static func temperature(_ sensorCode: FourCharCode, - unit: TemperatureUnit = .celius) throws -> Double { + unit: TemperatureUnit = .celsius) throws -> Double { let data = try readData(SMCKey(code: sensorCode, info: DataTypes.SP78)) - let temperatureInCelius = Double(fromSP78: (data.0, data.1)) + let temperatureInCelsius = Double(fromSP78: (data.0, data.1)) switch unit { - case .celius: - return temperatureInCelius + case .celsius: + return temperatureInCelsius case .fahrenheit: - return TemperatureUnit.toFahrenheit(temperatureInCelius) + return TemperatureUnit.toFahrenheit(temperatureInCelsius) case .kelvin: - return TemperatureUnit.toKelvin(temperatureInCelius) + return TemperatureUnit.toKelvin(temperatureInCelsius) } } } @@ -732,6 +744,11 @@ extension SMCKit { } } +//------------------------------------------------------------------------------ +// MARK: Power +//------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ // MARK: Miscellaneous //------------------------------------------------------------------------------ @@ -785,3 +802,21 @@ extension SMCKit { isCharging: isCharging) } } + +public struct clockInfo { + public let timeSeconds: UInt32 +} + +extension SMCKit { + public static func getSMCClockTimeInSeconds() throws -> clockInfo { + let clockKey = SMCKey(code: FourCharCode(fromStaticString: "CLKT"), + info: DataTypes.UInt32) + + let timeSecondsData = try readData(clockKey) + + let timeSecondsCount = UInt32(uint32(fromBytes: (timeSecondsData.0, timeSecondsData.1, timeSecondsData.2, timeSecondsData.3))) + + return clockInfo(timeSeconds: timeSecondsCount) + } + +} diff --git a/SMCKitTool/main.swift b/SMCKitTool/main.swift index d651c17..4151008 100644 --- a/SMCKitTool/main.swift +++ b/SMCKitTool/main.swift @@ -161,19 +161,17 @@ func printTemperatureInformation(known: Bool = true) { return } + let sensorWithLongestName = sensors.max { $0.name.count < + $1.name.count } - let sensorWithLongestName = sensors.max { $0.name.characters.count < - $1.name.characters.count } - - guard let longestSensorNameCount = sensorWithLongestName?.name.characters.count else { + guard let longestSensorNameCount = sensorWithLongestName?.name.count else { print("No temperature sensors found") return } - for sensor in sensors { let padding = String(repeating: " ", - count: longestSensorNameCount - sensor.name.characters.count) + count: longestSensorNameCount - sensor.name.count) let smcKey = CLIDisplayKeysOption.wasSet ? "(\(sensor.code.toString()))" : "" print("\(sensor.name + padding) \(smcKey) ", terminator: "") @@ -255,6 +253,17 @@ func printMiscInformation() { } print("Disc in ODD: \(colorBoolOutput(value: ODDStatus))") + + let SMCTime: clockInfo + do { + SMCTime = try SMCKit.getSMCClockTimeInSeconds() + } + catch { + print(error) + return + } + + print("SMC Clock: \(SMCTime.timeSeconds)") } func printAll() { @@ -265,7 +274,7 @@ func printAll() { } func checkKey(key: String) { - if key.characters.count != 4 { + if key.count != 4 { print("Must be a FourCC (four-character code)") return } @@ -327,7 +336,6 @@ let printAllOptionsCount = wasSetOptions.filter { if printAllOptionsCount == wasSetOptions.count { printAll() } - if let fanId = CLIFanIdOption.value, let fanSpeed = CLIFanSpeedOption.value { setMinFanSpeed(fanId: fanId, fanSpeed: fanSpeed) } @@ -335,7 +343,6 @@ else if CLIFanIdOption.wasSet != CLIFanSpeedOption.wasSet { print("Usage: Must set fan number (-n) AND fan speed (-s)") } - if let key = CLICheckKeyOption.value { checkKey(key: key) } if CLITemperatureOption.wasSet { printTemperatureInformation() } diff --git a/powermetricsTests/main.swift b/powermetricsTests/main.swift index fb992c6..703a008 100644 --- a/powermetricsTests/main.swift +++ b/powermetricsTests/main.swift @@ -104,7 +104,7 @@ if let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue) { print("SMCKit fan 0 RPM: \(smcRPM)") print("powermetrics fan RPM: \(powermetricsRPM)") - assert(diff >= 0 && diff <= 5, "RPM differs by more than +/- 5") + assert(diff >= 0 && diff <= 200, "RPM differs by more than +/- 200") } else if line.hasPrefix("CPU die temperature:") && line.hasSuffix("C") {