-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBitStreamFrameDetector.h
47 lines (38 loc) · 1.92 KB
/
BitStreamFrameDetector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// -*- Mode: ObjC -*-
//
// Copyright (C) 2011, Brad Howes. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "BitDetectorObserver.h"
#import "BitStreamFrameDetectorObserver.h"
/** The BitStreamFrameDetector attemps to find sequences of bit values ('0' and '1') with length frameSize, where the
start of the frame consists of a predefined prefix (such as 0xAA or '10101010') and ends with a predefined suffix
(such as 0x55 or b01010101). The approach taken is quite simple: accumulate bits from a BitDetector and when there are
frameSize bits, check if the string starts with a given prefix value and ends with a given suffix value. If so, fire a
frameContentBitStream: message to the registered observer with the frame contents, and clear the bits accumulator.
*/
@interface BitStreamFrameDetector : NSObject <BitDetectorObserver> {
@private
NSMutableString* bits; // Bit accumulator
NSString* prefix; // Prefix that signals the start of a valid frame
NSString* suffix; // Suffix that signals the end of a valid frame
NSUInteger frameSize; // The number of bits that make up a valid frame
NSUInteger contentSize; // frameSize - [prefix length] - [suffix length]
NSString* frameContents; // The contents from the last valid frame found
NSObject<BitStreamFrameDetectorObserver>* observer;
}
@property (nonatomic, retain, readonly) NSMutableString* bits;
@property (nonatomic, assign) NSUInteger contentSize;
@property (nonatomic, retain) NSString* prefix;
@property (nonatomic, retain) NSString* suffix;
@property (nonatomic, retain, readonly) NSString* frameContents;
@property (nonatomic, retain) NSObject<BitStreamFrameDetectorObserver>* observer;
/** Factory method to create and initialize a new BitStreamFrameDetector object.
*/
+ (id)create;
/** Initialize a new BitStreamFrameDetector object.
*/
- (id)init;
- (void)reset;
- (void)updateFromSettings;
@end