Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: tools/battor_agent/battor_protocol_types.h

Issue 1524873002: Creates a BattOrConnection for communicating with the BattOr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/battor_agent/battor_protocol_types.h
diff --git a/tools/battor_agent/battor_protocol_types.h b/tools/battor_agent/battor_protocol_types.h
new file mode 100644
index 0000000000000000000000000000000000000000..47125f46e8a6f26cc30c5e3dc0165c406dca1dda
--- /dev/null
+++ b/tools/battor_agent/battor_protocol_types.h
@@ -0,0 +1,77 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TOOLS_BATTOR_AGENT_BATTOR_PROTOCOL_H_
+#define TOOLS_BATTOR_AGENT_BATTOR_PROTOCOL_H_
+
+namespace battor {
+
+// Control characters in the BattOr protocol.
+enum BattOrControlByte : uint8_t {
Primiano Tucci (use gerrit) 2015/12/15 11:07:20 I wonder if all these should be c++11 enum classes
charliea (OOO until 10-5) 2015/12/15 23:50:04 Definitely not an expert in this area, but it seem
Primiano Tucci (use gerrit) 2015/12/16 16:47:43 ah ok got it, makes sense
+ // Indicates the start of a message in the protocol. All other instances of
+ // this byte must be escaped (with BATTOR_SPECIAL_BYTE_ESCAPE).
+ BATTOR_SPECIAL_BYTE_START = 0x00,
+ // Indicates the end of a message in the protocol. All other instances of
+ // this byte must be escaped (with BATTOR_SPECIAL_BYTE_ESCAPE).
+ BATTOR_SPECIAL_BYTE_END,
Zhen Wang 2015/12/14 23:39:47 I think explicitly writing the values here would m
Primiano Tucci (use gerrit) 2015/12/15 11:07:20 +1
charliea (OOO until 10-5) 2015/12/15 23:50:04 Done.
+ // Indicates that the next byte should not be interpreted as a special
+ // character, but should instead be interpreted as itself.
+ BATTOR_SPECIAL_BYTE_ESCAPE,
+};
+
+// Types of BattOr messages that can be sent.
+enum BattOrMessageType : uint8_t {
+ // Indicates a control message sent from the client to the BattOr to tell the
+ // BattOr to do something.
+ BATTOR_MESSAGE_TYPE_CONTROL = 0x03,
+ // Indicates a control message ack sent from the BattOr back to the client to
+ // signal that the BattOr received the control message.
+ BATTOR_MESSAGE_TYPE_CONTROL_ACK,
+ // Indicates that the message contains Voltage and current measurements.
+ BATTOR_MESSAGE_TYPE_SAMPLES,
+ // TODO(charliea): Figure out what this is.
+ BATTOR_MESSAGE_TYPE_PRINT,
+};
+
+// Types of BattOr control messages that can be sent.
+enum BattOrControlMessageType : uint8_t {
+ // Tells the BattOr to initialize itself.
+ BATTOR_CONTROL_MESSAGE_TYPE_INIT = 0x00,
+ // Sets the current measurement's gain.
+ BATTOR_CONTROL_MESSAGE_TYPE_SET_GAIN,
+ // Tells the BattOr to start taking samples and sending them over the
+ // connection.
+ BATTOR_CONTROL_MESSAGE_TYPE_START_SAMPLING_UART,
+ // Tells the BattOr to start taking samples and storing them on its SD card.
+ BATTOR_CONTROL_MESSAGE_TYPE_START_SAMPLING_SD,
+ // Tells the BattOr to start streaming the samples stored on its SD card over
+ // the connection.
+ BATTOR_CONTROL_MESSAGE_TYPE_READ_SD_UART,
+ // Tells the BattOr to send its EEPROM contents over the serial connection.
+ BATTOR_CONTROL_MESSAGE_TYPE_READ_EEPROM,
+ // Tells the BattOr to reset itself.
+ BATTOR_CONTROL_MESSAGE_TYPE_RESET,
+ // Tells the BattOr to run a self test.
+ BATTOR_CONTROL_MESSAGE_TYPE_SELF_TEST,
+};
+
+// See: BattOrMessageType::BATTOR_MESSAGE_TYPE_CONTROL above.
+struct BattOrControlMessage {
Primiano Tucci (use gerrit) 2015/12/15 11:07:20 Not really a huge fan of packed structs, make the
charliea (OOO until 10-5) 2015/12/15 23:50:04 In our case, the BattOr firmware expects the struc
Primiano Tucci (use gerrit) 2015/12/16 16:47:43 ok makes sense
+ BattOrControlMessageType type;
+ uint16_t param1;
+ uint16_t param2;
+} __attribute__((packed));
+
+// See: BattOrMessageType::BATTOR_MESSAGE_TYPE_CONTROL_ACK above.
+struct BattOrControlMessageAck {
Primiano Tucci (use gerrit) 2015/12/15 11:07:20 nothing seems to use this
charliea (OOO until 10-5) 2015/12/15 23:50:04 Ah, sorry. I'll add this back in when the next CL
Primiano Tucci (use gerrit) 2015/12/16 16:47:43 ah nevermind if you are going to use it. I though
charliea (OOO until 10-5) 2015/12/16 18:27:55 SG. In that case, I went ahead and added it back i
+ BattOrControlMessageType type;
+ uint8_t param;
+} __attribute__((packed));
+
+// The gain level for the BattOr to use.
+enum BattOrGain : uint8_t { BATTOR_GAIN_LOW = 0, BATTOR_GAIN_HIGH };
+
+} // namespace battor
+
+#endif // TOOLS_BATTOR_AGENT_BATTOR_PROTOCOL_H_
« tools/battor_agent/battor_connection_unittest.cc ('K') | « tools/battor_agent/battor_error.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698