Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create XM, AM and FM Convenience inits #1525

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions SmartDeviceLink/SDLRadioControlData.h
Expand Up @@ -41,6 +41,27 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (instancetype)initWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger frequencyFraction:(nullable NSNumber<SDLInt> *)frequencyFraction band:(nullable SDLRadioBand)band hdChannel:(nullable NSNumber<SDLInt> *)hdChannel radioEnable:(nullable NSNumber<SDLBool> *)radioEnable hdRadioEnable:(nullable NSNumber<SDLBool> *)hdRadioEnable;

/// Constructs a newly allocated SDLRadioControlCapabilities object with given parameters.
///
/// @param frequencyInteger Must be between 0 and 1710
/// @param frequencyFraction Must be between 0 and 9
/// @param hdChannel Must be between 0 and 7
/// @return An instance of the SDLRadioControlData class
- (instancetype)initFMWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger frequencyFraction:(nullable NSNumber<SDLInt> *)frequencyFraction hdChannel:(nullable NSNumber<SDLInt> *)hdChannel;

/// Constructs a newly allocated SDLRadioControlCapabilities object with given parameters.
///
/// @param frequencyInteger Must be between 0 and 1710
/// @param hdChannel Must be between 0 and 7
/// @return An instance of the SDLRadioControlData class
- (instancetype)initAMWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger hdChannel:(nullable NSNumber<SDLInt> *)hdChannel;

/// Constructs a newly allocated SDLRadioControlCapabilities object with given parameters.
///
/// @param frequencyInteger Must be between 1 and 1710
/// @return An instance of the SDLRadioControlData class
- (instancetype)initXMWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger;

/**
* The integer part of the frequency ie for 101.7 this value should be 101
*
Expand Down
39 changes: 39 additions & 0 deletions SmartDeviceLink/SDLRadioControlData.m
Expand Up @@ -43,6 +43,45 @@ - (instancetype)initWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyI
return self;
}

- (instancetype)initFMWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger frequencyFraction:(nullable NSNumber<SDLInt> *)frequencyFraction hdChannel:(nullable NSNumber<SDLInt> *)hdChannel {
self = [self init];
if(!self) {
return nil;
}

self.band = SDLRadioBandFM;
self.frequencyInteger = frequencyInteger;
self.frequencyFraction = frequencyFraction;
self.hdChannel = hdChannel;

return self;
}

- (instancetype)initAMWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger hdChannel:(nullable NSNumber<SDLInt> *)hdChannel {
self = [self init];
if(!self) {
return nil;
}

self.band = SDLRadioBandAM;
self.frequencyInteger = frequencyInteger;
self.hdChannel = hdChannel;

return self;
}

- (instancetype)initXMWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger {
self = [self init];
if(!self) {
return nil;
}

self.frequencyInteger = frequencyInteger;
self.band = SDLRadioBandXM;

return self;
}

- (void)setFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger {
[self.store sdl_setObject:frequencyInteger forName:SDLRPCParameterNameFrequencyInteger];
}
Expand Down
Expand Up @@ -155,6 +155,32 @@
expect(testStruct.hdRadioEnable).to(equal(@YES));
});

it(@"Should get correctly when initialized FM radio control capabilities parameters", ^ {
SDLRadioControlData* testStruct = [[SDLRadioControlData alloc] initFMWithFrequencyInteger:@101 frequencyFraction:@7 hdChannel:@2];

expect(testStruct.frequencyInteger).to(equal(@101));
expect(testStruct.frequencyFraction).to(equal(@7));
expect(testStruct.band).to(equal(SDLRadioBandFM));
expect(testStruct.hdChannel).to(equal(@2));
});

it(@"Should get correctly when initialized AM radio control capabilities parameters", ^ {
SDLRadioControlData* testStruct = [[SDLRadioControlData alloc] initAMWithFrequencyInteger:@101 hdChannel:@2];

expect(testStruct.frequencyInteger).to(equal(@101));
expect(testStruct.band).to(equal(SDLRadioBandAM));
expect(testStruct.hdChannel).to(equal(@2));
});

it(@"Should get correctly when initialized XM radio control capabilities parameters", ^ {
SDLRadioControlData* testStruct = [[SDLRadioControlData alloc] initXMWithFrequencyInteger:@101];

expect(testStruct.frequencyInteger).to(equal(@101));
expect(testStruct.band).to(equal(SDLRadioBandXM));
});



});

QuickSpecEnd