Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_GENERATO R_H_ | |
| 6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_GENERATO R_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include <memory> | |
| 12 #include <string> | |
| 13 #include <vector> | |
| 14 | |
| 15 namespace proximity_auth { | |
| 16 // Generates the messages sent using the uWeave protocol. | |
| 17 // Internally tracks the packet number. | |
|
Kyle Horimoto
2016/06/06 19:30:55
nit: This is an implementation detail of this clas
Kyle Horimoto
2016/06/08 00:06:29
Ping.
jingxuy
2016/06/08 21:30:36
Done.
| |
| 18 class BluetoothLowEnergyWeavePacketGenerator { | |
| 19 public: | |
| 20 class Factory { | |
| 21 public: | |
| 22 Factory(); | |
| 23 | |
| 24 static std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator> | |
| 25 NewInstance(); | |
|
Kyle Horimoto
2016/06/06 19:30:55
nit: +4 spaces.
Kyle Horimoto
2016/06/08 00:06:29
Ping.
jingxuy
2016/06/08 21:30:36
I had 4 spaces but git cl format deleted them
| |
| 26 | |
| 27 // Exposed for testing. | |
| 28 static void SetInstanceForTesting(Factory* factory); | |
| 29 | |
| 30 protected: | |
| 31 // Exposed for testing. | |
| 32 BluetoothLowEnergyWeavePacketGenerator* BuildInstance(); | |
| 33 | |
| 34 private: | |
| 35 static Factory* factory_instance_; | |
|
Kyle Horimoto
2016/06/06 19:30:55
You need to statically initialize this to nullptr.
jingxuy
2016/06/08 21:30:36
Done.
| |
| 36 }; | |
| 37 | |
| 38 enum ReasonForClose { | |
|
Kyle Horimoto
2016/06/06 19:30:55
nit: Add a description over this enum which lets r
Kyle Horimoto
2016/06/08 00:06:29
Ping.
jingxuy
2016/06/08 21:30:36
Done.
| |
| 39 CLOSE_WITHOUT_ERROR = 0x00, | |
| 40 UNKNOWN_ERROR = 0x01, | |
| 41 NO_COMMON_VERSION_SUPPORTED = 0x02, | |
| 42 RECEIVED_PACKET_OUT_OF_SEQUENCE = 0x03, | |
| 43 APPLICATION_ERROR = 0x80 | |
|
Kyle Horimoto
2016/06/06 19:30:55
nit: Why does this jump from 0x03 to 0x80?
Kyle Horimoto
2016/06/08 00:06:29
Nevermind - this is part of the spec. Disregard.
jingxuy
2016/06/08 21:30:36
Done.
| |
| 44 }; | |
| 45 | |
| 46 typedef std::vector<uint8_t> Packet; | |
|
Kyle Horimoto
2016/06/06 19:30:55
Hmm, are we sure this works correctly regarding en
jingxuy
2016/06/08 21:30:36
You can check out the example from the legacy impl
sacomoto
2016/06/13 16:05:18
Jing is correct. The endianess only matter for mul
| |
| 47 | |
| 48 std::unique_ptr<Packet> CreateConnectionRequest(); | |
| 49 std::unique_ptr<Packet> CreateConnectionResponse(); | |
| 50 std::unique_ptr<Packet> CreateConnectionClose( | |
| 51 ReasonForClose reason_for_close); | |
| 52 | |
| 53 void SetDataPacketSize(uint32_t size); | |
| 54 | |
| 55 std::unique_ptr<std::vector<Packet>> EncodeDataMessage(std::string message); | |
| 56 | |
| 57 protected: | |
| 58 BluetoothLowEnergyWeavePacketGenerator(); | |
| 59 | |
| 60 private: | |
| 61 static const int kWeaveVersion = 1; | |
|
Kyle Horimoto
2016/06/06 19:30:55
This and kControlPacketSize should be moved to the
Kyle Horimoto
2016/06/08 00:06:29
Ping. Same with these other constants.
jingxuy
2016/06/08 22:43:15
This is done but I think they need to be in the cl
| |
| 62 static const int kControlPacketSize = 20; | |
| 63 | |
| 64 Packet* CreateControlPacket(); | |
| 65 | |
| 66 // For error checking. | |
| 67 bool IsBit(uint8_t val); | |
| 68 | |
| 69 void SetIntField(Packet* packet, uint32_t index, uint16_t val); | |
| 70 void SetPacketTypeBit(Packet* packet, uint32_t index, uint8_t val); | |
| 71 void SetControlCmd(Packet* packet, uint32_t index, uint8_t val); | |
| 72 void SetPacketCounter(Packet* packet, uint32_t index); | |
| 73 void SetDataFirstBit(Packet* packet, uint32_t index, uint8_t val); | |
| 74 void SetDataLastBit(Packet* packet, uint32_t index, uint8_t val); | |
| 75 | |
| 76 // The default data packet length is 20 unless setDataPacketLength() is called | |
| 77 // and specified otherwise. | |
| 78 uint32_t packet_size_; | |
|
Kyle Horimoto
2016/06/06 19:30:55
This is only for data packets, right? If so, pleas
Kyle Horimoto
2016/06/08 00:06:29
Ping.
jingxuy
2016/06/08 21:30:36
They are already addressed.
Kyle Horimoto
2016/06/09 22:55:43
I addressed this in the .cc, but please make this
jingxuy
2016/06/11 00:49:32
Since we have this discussion elsewhere, will clos
| |
| 79 | |
| 80 // Counter for the number of packets sent, starting at 0. | |
| 81 uint32_t packet_number_; | |
| 82 }; | |
| 83 | |
| 84 } // namespace proximity_auth | |
| 85 | |
| 86 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_PACKET_GENER ATOR_H_ | |
| OLD | NEW |