FSK-Arduino-iOS
Dependencies for iOS Development, using Sofmodem Arduino library, with FSK communication.
=====
How to use
This libraries have a propouse work with an Arduino using a Sofmodem Shield* to communicate with iOS using FSK. Currently, the source code of the SoftModem is not made as a framework. If you want to use SoftModem in your project, you have two ways:
Adding FSK-Arduino-iOS to your project
CocoaPods
CocoaPods is the recommended way to add FSK-Arduino-iOS to your project.
- Add a pod entry for FSK-Arduino-iOS to your Podfile
pod 'FSK-Arduino-iOS', '~> 0.0.2'
- Install the pod(s) by running
pod install
.
Source files
Alternatively you can directly adding source files to your project.
- Download the latest code version or add the repository as a git submodule to your git-tracked project.
- The Folder /FSK must be copied from the source code of your project. The following is the list of source code related to FSK. Please copy these to the project source code.
* AudioQueueObject.h
* AudioQueueObject.m
* AudioSignalAnalyzer.h
* AudioSignalAnalyzer.m
* AudioSignalGenerator.h
* AudioSignalGenerator.m
* CharReceiver.h
* FSKModemConfig.h
* FSKByteQueue.h
* FSKRecognizer.h
* FSKRecognizer.mm
* FSKSerialGenerator.h
* FSKSerialGenerator.m
* lockfree.h
* MultiDelegate.h
* MultiDelegate.m
* PatternRecognizer.h
SoftModem uses the following two framework for audio input and output. Please add them to your project.
* AudioToolbox.framework
* AVFoundation.framework
Initialization
First, set the category of application with AVAudioSession class. To do voice recording and playback, AVAudioSessionCategoryPlayAndRecord need to be set.
AVAudioSession *session = [AVAudioSession sharedInstance];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interruption:) name:
AVAudioSessionInterruptionNotification object:nil];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
[session setActive:YES error:nil];
interruption selector method
- (void) interruption:(NSNotification*)notification
{
NSDictionary *interuptionDict = notification.userInfo;
NSUInteger interuptionType = (NSUInteger)[interuptionDict valueForKey:AVAudioSessionInterruptionTypeKey];
if (interuptionType == AVAudioSessionInterruptionTypeBegan)
[self beginInterruption];
# if __CC_PLATFORM_IOS >= 40000
else if (interuptionType == AVAudioSessionInterruptionTypeEnded)
[self endInterruptionWithFlags:(NSUInteger)[interuptionDict valueForKey:AVAudioSessionInterruptionOptionKey]];
# else
else if (interuptionType == AVAudioSessionInterruptionTypeEnded)
[self endInterruption];
# endif
}
Next, for analysis of the voice, make instance of class AudioSignalAnalyzer, FSKRecognizer and AudioSignalAnalyzer parses the input waveform from the microphone to detect the falling and rising edge of the waveform. FSKRecognizer restores the data bits based on the results of the analysis of AudioSignalAnalyzer.
recognizer = [[FSKRecognizer alloc] init];
[recognizer addReceiver:self];
analyzer = [[AudioSignalAnalyzer alloc] init];
[analyzer addRecognizer:recognizer];
Then create an instance of a class FSKSerialGenerator for sound output. FSKSerialGenerator converts the data bits to audio signal and output.
generator = [[FSKSerialGenerator alloc] init];
[generator play];
Receiving
Register the class that implements the CharReceiver protocol to the FSKRecognizer class, and AVAudioSessionDelegate.
@interface YourClass : NSObject <AVAudioSessionDelegate, CharReceiver>
Register FSKRecognizer class at initialization.
YourClass *yourClassInstance;
[recognizer addReceiver: yourClassInstance];
receivedChar: method is called when one byte of data is received.
- (void) receivedChar: (char) input
{
// Receive handling
}
Sending
Sending data is much easier than receiving data. FSKSerialGenerator class's writeByte: method to sends a single byte.
[generator writeByte: 0xff];
Links and Credits
arms22 - Creator of Softmodem hardware, libraries for Arduino and ARC version lib for iOS.
License
This code is distributed under the terms and conditions of the MIT license.