mbed-os-examples / Mbed OS mbed-os-example-nfc-SmartPoster
Committer:
mbed_official
Date:
Fri Nov 29 13:01:40 2019 +0000
Revision:
6:52cd72e84703
Parent:
0:9a16c3f036b0
Merge pull request #50 from jamesbeyond/update

Update readme with PN512 shield info
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-nfc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:9a16c3f036b0 1 /* mbed Microcontroller Library
mbed_official 0:9a16c3f036b0 2 * Copyright (c) 2018-2018 ARM Limited
mbed_official 0:9a16c3f036b0 3 *
mbed_official 0:9a16c3f036b0 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 0:9a16c3f036b0 5 * you may not use this file except in compliance with the License.
mbed_official 0:9a16c3f036b0 6 * You may obtain a copy of the License at
mbed_official 0:9a16c3f036b0 7 *
mbed_official 0:9a16c3f036b0 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 0:9a16c3f036b0 9 *
mbed_official 0:9a16c3f036b0 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 0:9a16c3f036b0 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 0:9a16c3f036b0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 0:9a16c3f036b0 13 * See the License for the specific language governing permissions and
mbed_official 0:9a16c3f036b0 14 * limitations under the License.
mbed_official 0:9a16c3f036b0 15 */
mbed_official 0:9a16c3f036b0 16
mbed_official 0:9a16c3f036b0 17 #ifndef SMARTPOSTER_H_
mbed_official 0:9a16c3f036b0 18 #define SMARTPOSTER_H_
mbed_official 0:9a16c3f036b0 19
mbed_official 0:9a16c3f036b0 20 #include "nfc/ndef/common/Text.h"
mbed_official 0:9a16c3f036b0 21 #include "nfc/ndef/common/URI.h"
mbed_official 0:9a16c3f036b0 22 #include "nfc/ndef/common/Mime.h"
mbed_official 0:9a16c3f036b0 23 #include "nfc/ndef/MessageBuilder.h"
mbed_official 0:9a16c3f036b0 24
mbed_official 0:9a16c3f036b0 25 /**
mbed_official 0:9a16c3f036b0 26 * Smart poster object.
mbed_official 0:9a16c3f036b0 27 *
mbed_official 0:9a16c3f036b0 28 * A smart poster is one of the basic use case of NFC. It encapsulates a URI to
mbed_official 0:9a16c3f036b0 29 * a resource and meta-data of the resource.
mbed_official 0:9a16c3f036b0 30 *
mbed_official 0:9a16c3f036b0 31 * Meta-data are optional, they can be:
mbed_official 0:9a16c3f036b0 32 * - title: name of the resource
mbed_official 0:9a16c3f036b0 33 * - icon: image/media associated to the resource
mbed_official 0:9a16c3f036b0 34 * - action: Action the peer should execute upon reception of the smart poster
mbed_official 0:9a16c3f036b0 35 * - size: The size of the resource.
mbed_official 0:9a16c3f036b0 36 * - type: Mime type of the resource.
mbed_official 0:9a16c3f036b0 37 *
mbed_official 0:9a16c3f036b0 38 * @note It obeys to value semantic and can be copied around.
mbed_official 0:9a16c3f036b0 39 */
mbed_official 0:9a16c3f036b0 40 class SmartPoster {
mbed_official 0:9a16c3f036b0 41 public:
mbed_official 0:9a16c3f036b0 42 typedef mbed::nfc::ndef::common::Mime Mime;
mbed_official 0:9a16c3f036b0 43 typedef mbed::nfc::ndef::common::Text Text;
mbed_official 0:9a16c3f036b0 44 typedef mbed::nfc::ndef::common::URI URI;
mbed_official 0:9a16c3f036b0 45 typedef mbed::nfc::ndef::MessageBuilder MessageBuilder;
mbed_official 0:9a16c3f036b0 46
mbed_official 0:9a16c3f036b0 47 /**
mbed_official 0:9a16c3f036b0 48 * Type of actions that should be executed upon smart poster reception.
mbed_official 0:9a16c3f036b0 49 */
mbed_official 0:9a16c3f036b0 50 enum action_t {
mbed_official 0:9a16c3f036b0 51 EXECUTE,//!< EXECUTE
mbed_official 0:9a16c3f036b0 52 SAVE, //!< SAVE
mbed_official 0:9a16c3f036b0 53 EDIT //!< EDIT
mbed_official 0:9a16c3f036b0 54 };
mbed_official 0:9a16c3f036b0 55
mbed_official 0:9a16c3f036b0 56 /**
mbed_official 0:9a16c3f036b0 57 * Construct a smart poster.
mbed_official 0:9a16c3f036b0 58 *
mbed_official 0:9a16c3f036b0 59 * @param uri The URI to the resource.
mbed_official 0:9a16c3f036b0 60 */
mbed_official 0:9a16c3f036b0 61 SmartPoster(const URI &uri);
mbed_official 0:9a16c3f036b0 62
mbed_official 0:9a16c3f036b0 63 /**
mbed_official 0:9a16c3f036b0 64 * Set the title of the resource.
mbed_official 0:9a16c3f036b0 65 *
mbed_official 0:9a16c3f036b0 66 * @param text The title of the resource to set.
mbed_official 0:9a16c3f036b0 67 */
mbed_official 0:9a16c3f036b0 68 void set_title(const Text &text);
mbed_official 0:9a16c3f036b0 69
mbed_official 0:9a16c3f036b0 70 /**
mbed_official 0:9a16c3f036b0 71 * Set the icon of the resource.
mbed_official 0:9a16c3f036b0 72 *
mbed_official 0:9a16c3f036b0 73 * @param icon The icon to set.
mbed_official 0:9a16c3f036b0 74 */
mbed_official 0:9a16c3f036b0 75 void set_icon(const Mime &icon);
mbed_official 0:9a16c3f036b0 76
mbed_official 0:9a16c3f036b0 77 /**
mbed_official 0:9a16c3f036b0 78 * Set the action to trigger upon smart poster reception.
mbed_official 0:9a16c3f036b0 79 *
mbed_official 0:9a16c3f036b0 80 * @param action The action to do upon reception.
mbed_official 0:9a16c3f036b0 81 */
mbed_official 0:9a16c3f036b0 82 void set_action(action_t action);
mbed_official 0:9a16c3f036b0 83
mbed_official 0:9a16c3f036b0 84 /**
mbed_official 0:9a16c3f036b0 85 * Set the size of the resource.
mbed_official 0:9a16c3f036b0 86 *
mbed_official 0:9a16c3f036b0 87 * @param size The size of the resource.
mbed_official 0:9a16c3f036b0 88 */
mbed_official 0:9a16c3f036b0 89 void set_resource_size(uint32_t size);
mbed_official 0:9a16c3f036b0 90
mbed_official 0:9a16c3f036b0 91 /**
mbed_official 0:9a16c3f036b0 92 * Set the type of the resource.
mbed_official 0:9a16c3f036b0 93 *
mbed_official 0:9a16c3f036b0 94 * @param resource_type The type of the resource pointed by the URI.
mbed_official 0:9a16c3f036b0 95 */
mbed_official 0:9a16c3f036b0 96 void set_resource_type(mbed::Span<const uint8_t> &resource_type);
mbed_official 0:9a16c3f036b0 97
mbed_official 0:9a16c3f036b0 98 /**
mbed_official 0:9a16c3f036b0 99 * Append the smart poster as a ndef record.
mbed_official 0:9a16c3f036b0 100 *
mbed_official 0:9a16c3f036b0 101 * @param ndef_builder The message builder where the record is appended.
mbed_official 0:9a16c3f036b0 102 * @param is_last_record Indicates if this message is the last one.
mbed_official 0:9a16c3f036b0 103 *
mbed_official 0:9a16c3f036b0 104 * @return true if the message has been appended to the builder or false
mbed_official 0:9a16c3f036b0 105 * otherwise.
mbed_official 0:9a16c3f036b0 106 */
mbed_official 0:9a16c3f036b0 107 bool append_record(MessageBuilder &ndef_builder, bool is_last_record) const;
mbed_official 0:9a16c3f036b0 108
mbed_official 0:9a16c3f036b0 109 private:
mbed_official 0:9a16c3f036b0 110 void append_uri(MessageBuilder &builder) const;
mbed_official 0:9a16c3f036b0 111 size_t get_uri_record_size() const;
mbed_official 0:9a16c3f036b0 112
mbed_official 0:9a16c3f036b0 113 void append_title(MessageBuilder &builder) const;
mbed_official 0:9a16c3f036b0 114 size_t get_title_record_size() const;
mbed_official 0:9a16c3f036b0 115
mbed_official 0:9a16c3f036b0 116 void append_icon(MessageBuilder &builder) const;
mbed_official 0:9a16c3f036b0 117 size_t get_icon_record_size() const;
mbed_official 0:9a16c3f036b0 118
mbed_official 0:9a16c3f036b0 119 void append_action(MessageBuilder &builder) const;
mbed_official 0:9a16c3f036b0 120 size_t get_action_record_size() const;
mbed_official 0:9a16c3f036b0 121
mbed_official 0:9a16c3f036b0 122 void append_resource_size(MessageBuilder &builder) const;
mbed_official 0:9a16c3f036b0 123 size_t get_resource_size_record_size() const;
mbed_official 0:9a16c3f036b0 124
mbed_official 0:9a16c3f036b0 125 void append_type(MessageBuilder &builder) const;
mbed_official 0:9a16c3f036b0 126 size_t get_type_record_size() const;
mbed_official 0:9a16c3f036b0 127
mbed_official 0:9a16c3f036b0 128 URI _uri;
mbed_official 0:9a16c3f036b0 129 Text _title;
mbed_official 0:9a16c3f036b0 130 Mime _icon;
mbed_official 0:9a16c3f036b0 131 action_t _action;
mbed_official 0:9a16c3f036b0 132 uint32_t _resource_size;
mbed_official 0:9a16c3f036b0 133 Text _type;
mbed_official 0:9a16c3f036b0 134
mbed_official 0:9a16c3f036b0 135 bool _action_set:1;
mbed_official 0:9a16c3f036b0 136 bool _resource_size_set:1;
mbed_official 0:9a16c3f036b0 137 };
mbed_official 0:9a16c3f036b0 138
mbed_official 0:9a16c3f036b0 139
mbed_official 0:9a16c3f036b0 140 #endif /* SMARTPOSTER_H_ */