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 3 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
31 changes: 31 additions & 0 deletions SmartDeviceLink/SDLRadioControlData.h
Expand Up @@ -41,6 +41,37 @@ 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
/// @return An instance of the SDLRadioControlData class
- (instancetype)initFMWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger frequencyFraction:(nullable NSNumber<SDLInt> *)frequencyFraction;

/// Constructs a newly allocated SDLRadioControlCapabilities object with given parameters.
///
/// @param hdChannel Must be between 0 and 7
/// @return An instance of the SDLRadioControlData class
- (instancetype)initFMWithHdChannel:(nullable NSNumber<SDLInt> *)hdChannel;
joeljfischer marked this conversation as resolved.
Show resolved Hide resolved

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above comment


/// 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
61 changes: 61 additions & 0 deletions SmartDeviceLink/SDLRadioControlData.m
Expand Up @@ -43,6 +43,67 @@ - (instancetype)initWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyI
return self;
}

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

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

return self;
}

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

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

return self;
}

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

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

return self;
}

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

self.hdChannel = hdChannel;
joeljfischer marked this conversation as resolved.
Show resolved Hide resolved
self.band = SDLRadioBandFM;

return self;
}

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

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

return self;
}

- (void)setFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger {
[self.store sdl_setObject:frequencyInteger forName:SDLRPCParameterNameFrequencyInteger];
}
Expand Down
Expand Up @@ -155,6 +155,44 @@
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];

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

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

expect(testStruct.hdChannel).to(equal(@5));
expect(testStruct.band).to(equal(SDLRadioBandFM));
});

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

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

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

expect(testStruct.hdChannel).to(equal(@5));
expect(testStruct.band).to(equal(SDLRadioBandAM));
});

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