Skip to content

Commit c6e18f9

Browse files
authored
Merge pull request #7426 from donatieng/nfc-spec
NFC APIs Design Specification
2 parents c7d6560 + 09ed420 commit c6e18f9

18 files changed

+1155
-0
lines changed
309 KB
Loading

docs/design-documents/nfc/nfc_design.md

Lines changed: 666 additions & 0 deletions
Large diffs are not rendered by default.
Loading
Loading
Loading
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@startuml
2+
class NFCController {
3+
+NFCController(NFCControllerDriver* driver, events::EventQueue* queue)
4+
+void set_delegate(NFCController::Delegate* delegate)
5+
+nfc_rf_protocols_bitmask_t get_supported_rf_protocols() const
6+
+nfc_err_t initialize()
7+
+nfc_err_t configure_rf_protocols(nfc_rf_protocols_bitmask_t rf_protocols)
8+
+nfc_err_t start_discovery()
9+
+nfc_err_t cancel_discovery()
10+
}
11+
12+
abstract class NFCController::Delegate {
13+
+{abstract} void on_discovery_terminated(nfc_discovery_terminated_reason_t reason)
14+
+{abstract} void on_nfc_target_discovered(const mbed::SharedPtr<NFCRemoteTarget>& target)
15+
+{abstract} void on_nfc_initiator_discovered(const mbed::SharedPtr<NFCRemoteInitiator>& initiator)
16+
}
17+
18+
abstract class NFCControllerDriver {
19+
+void set_delegate(Delegate* delegate)
20+
+{abstract} transceiver_t* initialize(scheduler_timer_t* pTimer)
21+
+{abstract} void get_supported_nfc_techs(nfc_tech_t* initiator, nfc_tech_t* target) const
22+
}
23+
24+
abstract class NFCControllerDriver::Delegate {
25+
+{abstract} void on_hw_interrupt()
26+
}
27+
28+
NFCController o-- NFCController::Delegate
29+
NFCController o-- NFCControllerDriver
30+
NFCControllerDriver o-- NFCControllerDriver::Delegate
31+
NFCControllerDriver::Delegate <-- NFCController
32+
33+
@enduml
Loading
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
@startuml
2+
3+
abstract class NFCNDEFCapable {
4+
+{abstract} bool is_ndef_supported() const
5+
6+
#void parse_ndef_message(const ac_buffer_t& buffer)
7+
#void build_ndef_message(ac_buffer_builder_t& buffer_builder)
8+
#ndef_msg_t* ndef_message()
9+
#{abstract} NFCNDEFCapable::Delegate* ndef_capable_delegate()
10+
}
11+
12+
abstract class NFCNDEFCapable::Delegate {
13+
+{abstract} void parse_ndef_message(const Span<const uint8_t> &buffer)
14+
+{abstract} size_t build_ndef_message(const Span<uint8_t> &buffer)
15+
}
16+
17+
abstract class NFCRemoteEndpoint {
18+
+{abstract} bool is_connected() const
19+
+{abstract} bool is_disconnected() const
20+
+{abstract} nfc_rf_protocols_bitmask_t rf_protocols() const
21+
+{abstract} nfc_err_t connect()
22+
+{abstract} nfc_err_t disconnect()
23+
}
24+
25+
abstract class NFCRemoteEndpoint::Delegate {
26+
+{abstract} void on_connected()
27+
+{abstract} void on_disconnected()
28+
}
29+
30+
abstract class NFCTarget {
31+
+void write_ndef_message()
32+
+void erase_ndef_message()
33+
+void read_ndef_message()
34+
}
35+
36+
abstract class NFCTarget::Delegate {
37+
+{abstract} void on_ndef_message_written(nfc_err_t result)
38+
+{abstract} void on_ndef_message_erased(nfc_err_t result)
39+
+{abstract} void on_ndef_message_read(nfc_err_t result)
40+
}
41+
42+
NFCNDEFCapable <-- NFCTarget
43+
NFCNDEFCapable::Delegate <-- NFCTarget::Delegate
44+
45+
class NFCEEPROM {
46+
+nfc_err_t initialize()
47+
+void set_delegate(NFCEEPROM::Delegate* delegate)
48+
}
49+
50+
abstract class NFCEEPROM::Delegate {
51+
52+
}
53+
54+
abstract class NFCEEPROMDriver {
55+
+void set_delegate(Delegate* delegate)
56+
+void set_event_queue(events::EventQueue* queue)
57+
58+
+{abstract} void reset()
59+
+{abstract} size_t get_max_size()
60+
+{abstract} void start_session(bool force = true)
61+
+{abstract} void end_session()
62+
+{abstract} void read_bytes(uint32_t address, size_t count)
63+
+{abstract} void write_bytes(uint32_t address, const uint8_t* bytes, size_t count)
64+
+{abstract} void write_size(size_t count)
65+
+{abstract} void read_size()
66+
+{abstract} void erase_bytes(uint32_t address, size_t size)
67+
#NFCEEPROMDriver::Delegate *delegate()
68+
#events::EventQueue *event_queue()
69+
}
70+
71+
abstract class NFCEEPROMDriver::Delegate {
72+
+{abstract} void on_session_started(bool success)
73+
+{abstract} void on_session_ended(bool success)
74+
+{abstract} void on_bytes_read(size_t count)
75+
+{abstract} void on_bytes_written(size_t count)
76+
+{abstract} void on_size_read(bool success, size_t size)
77+
+{abstract} void on_size_written(bool success)
78+
+{abstract} void on_bytes_erased(size_t count)
79+
}
80+
81+
NFCTarget <-- NFCEEPROM
82+
NFCTarget::Delegate <-- NFCEEPROM::Delegate
83+
NFCEEPROM o-- NFCEEPROM::Delegate
84+
NFCEEPROM o-- NFCEEPROMDriver
85+
NFCEEPROMDriver o-- NFCEEPROMDriver::Delegate
86+
NFCEEPROMDriver::Delegate <-- NFCEEPROM
87+
88+
class NFCRemoteInitiator {
89+
+void set_delegate(NFCRemoteInitiator::Delegate* delegate)
90+
91+
+{abstract}bool is_iso7816_supported() const
92+
+{abstract}void add_iso7816_application(nfc_tech_iso7816_app_t *application)
93+
94+
+{abstract} nfc_tag_type_t nfc_tag_type()
95+
+{abstract} bool is_ndef_supported()
96+
}
97+
98+
abstract class NFCRemoteInitiator::Delegate {
99+
100+
}
101+
102+
NFCNDEFCapable <-- NFCRemoteInitiator
103+
NFCRemoteEndpoint <-- NFCRemoteInitiator
104+
NFCRemoteEndpoint::Delegate <-- NFCRemoteInitiator::Delegate
105+
NFCNDEFCapable::Delegate <-- NFCRemoteInitiator::Delegate
106+
NFCRemoteInitiator o-- NFCRemoteInitiator::Delegate
107+
108+
@enduml
Loading
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
@startuml
2+
3+
package ndef {
4+
5+
abstract RecordParser {
6+
+RecordParser()
7+
+{abstract} bool parse(const Record&)
8+
#~RecordParser()
9+
}
10+
11+
abstract GenericRecordParser<ParserImplementation, ParsingResult> {
12+
+GenericRecordParser()
13+
+bool parse(const Record&)
14+
+void set_delegate(Delegate* delegate)
15+
#~GenericRecordParser()
16+
}
17+
18+
interface GenericRecordParser::Delegate<ParsingResult> {
19+
+{abstract} void on_record_parsed(const ParsingResult& result, const RecordID* id)
20+
#~Delegate()
21+
}
22+
23+
RecordParser <|- GenericRecordParser
24+
GenericRecordParser +- "0..1" GenericRecordParser::Delegate
25+
26+
}
27+
28+
package common {
29+
class URI {
30+
}
31+
class Mime {
32+
}
33+
class Text {
34+
}
35+
36+
class URIParser {
37+
bool do_parse(const ndef::Record& record, URI& uri)
38+
}
39+
40+
class TextParser {
41+
bool do_parse(const ndef::Record& record, Text& text)
42+
}
43+
44+
class MimeParser {
45+
bool do_parse(const ndef::Record& record, Mime& mime)
46+
}
47+
48+
URI -- URIParser: Produce <
49+
Text -- TextParser: Produce <
50+
Mime -- MimeParser: Produce <
51+
52+
URIParser --|> GenericRecordParser
53+
TextParser --|> GenericRecordParser
54+
MimeParser --|> GenericRecordParser
55+
}
56+
57+
58+
@enduml
Loading
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
@startuml
2+
3+
package ndef {
4+
5+
class MessageBuilder {
6+
+MessageBuilder(const Span<uint8_t> &buffer)
7+
+~MessageBuilder()
8+
+bool append_record(const RecordType &type, const RecordPayload &payload = RecordPayload(), bool is_last_record = false)
9+
+bool append_record(const RecordType &type, const PayloadBuilder &builder, bool is_last_record = false)
10+
+bool append_record(const Record &record, const PayloadBuilder *builder = NULL)
11+
+void reset();
12+
+void reset(const Span<uint8_t> &buffer);
13+
+bool is_message_complete() const
14+
+Span<const uint8_t> get_message() const
15+
}
16+
17+
class Record {
18+
}
19+
20+
class RecordType{
21+
}
22+
23+
class RecordPayload{
24+
}
25+
26+
class RecordID{
27+
}
28+
29+
interface MessageBuilder::PayloadBuilder {
30+
+{abstract} size_t size() const
31+
+{abstract} void build(const Span<uint8_t> &buffer) const
32+
# ~PayloadBuilder()
33+
}
34+
35+
36+
Record *-- RecordType
37+
Record *-- "0..1" RecordPayload
38+
Record *-- "0..1" RecordID
39+
40+
Record - MessageBuilder: insert >
41+
MessageBuilder - MessageBuilder::PayloadBuilder: < build payload at insertion
42+
43+
}
44+
45+
package common {
46+
47+
48+
class URI {
49+
+bool append_as_record(ndef::MessageBuilder &builder, bool is_last_record) const
50+
}
51+
52+
class Text {
53+
+bool append_as_record(ndef::MessageBuilder &builder, bool is_last_record) const
54+
}
55+
56+
class Mime {
57+
+bool append_as_record(ndef::MessageBuilder &builder, bool is_last_record) const
58+
}
59+
60+
URI -- MessageBuilder: uses >
61+
Text -- MessageBuilder: uses >
62+
Mime -- MessageBuilder: uses >
63+
64+
}
65+
66+
@enduml
Loading
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@startuml
2+
3+
package ndef {
4+
5+
class MessageParser {
6+
+MessageParser()
7+
+void set_delegate(Delegate *delegate)
8+
+void parse(const Span<const uint8_t> &data_buffer)
9+
}
10+
11+
interface MessageParser::Delegate {
12+
+{abstract} void on_parsing_started()
13+
+{abstract} void on_record_parsed(const Record &record)
14+
+{abstract} void on_parsing_terminated()
15+
+{abstract} void on_parsing_error(error_t error)
16+
# ~Delegate()
17+
}
18+
19+
enum MessageParser::error_t {
20+
}
21+
22+
MessageParser +-- "0..1" MessageParser::Delegate
23+
MessageParser +-- MessageParser::error_t
24+
25+
note top of "MessageParser::Delegate"
26+
Implemented by the client of the parsing operation.
27+
end note
28+
29+
class Record {
30+
}
31+
class RecordType {
32+
}
33+
class RecordPayload {
34+
}
35+
class RecordID {
36+
}
37+
38+
Record *-- RecordType
39+
Record *-- "0..1" RecordPayload
40+
Record *-- "0..1" RecordID
41+
42+
MessageParser - Record: Produce >
43+
44+
}
45+
46+
@enduml
Loading
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
@startuml
2+
3+
package ndef {
4+
5+
class Record {
6+
}
7+
class RecordType {
8+
}
9+
class RecordPayload {
10+
}
11+
class RecordID {
12+
}
13+
14+
Record *-- RecordType
15+
Record *-- "0..1" RecordPayload
16+
Record *-- "0..1" RecordID
17+
18+
abstract RecordParser {
19+
+RecordParser()
20+
+{abstract} bool parse(const Record&)
21+
#~RecordParser()
22+
}
23+
24+
abstract GenericRecordParser<ParserImplementation, ParsingResult> {
25+
+GenericRecordParser()
26+
+bool parse(const Record&)
27+
+void set_delegate(Delegate* delegate)
28+
#~GenericRecordParser()
29+
}
30+
31+
interface GenericRecordParserConcept<ParsingResult> {
32+
+bool do_parse(const Record& record, ParsingResult& parsing_result)
33+
}
34+
35+
interface GenericRecordParser::Delegate<ParsingResult> {
36+
+{abstract} void on_record_parsed(const ParsingResult& record, const RecordID* id)
37+
#~Delegate()
38+
}
39+
40+
RecordParser <|-- GenericRecordParser
41+
GenericRecordParser <|-- GenericRecordParserConcept
42+
GenericRecordParser +-- "0..1" GenericRecordParser::Delegate
43+
44+
note as N1
45+
GenericRecordParserConcept model the concept that must
46+
be implemented by GenericRecordParser childs.
47+
It doesn't exist in the hierarchy.
48+
end note
49+
50+
N1 - GenericRecordParser
51+
N1 - GenericRecordParserConcept
52+
53+
note bottom of "GenericRecordParser::Delegate"
54+
Implemented by the client of the parsing operation.
55+
end note
56+
57+
class RecordParserChain {
58+
+RecordParserChain()
59+
+~RecordParserChain()
60+
+bool parse(const Record& record)
61+
+void set_next_parser(RecordParser* parser)
62+
}
63+
64+
note bottom of "RecordParserChain"
65+
Chain of responsibility pattern.
66+
end note
67+
68+
Record - RecordParserChain: Parse >
69+
RecordParserChain o- "*" RecordParser
70+
71+
}
72+
73+
@enduml
Loading

0 commit comments

Comments
 (0)