diff options
author | charliea <charliea@chromium.org> | 2016-01-12 05:34:50 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-12 13:35:45 +0000 |
commit | bf22c76e62e2798fc6ebbfd37bfe101f7c0a6e05 (patch) | |
tree | 0ecbd3cfe05cdf96dbea7bea5c3cd6c97bde0262 /tools/battor_agent | |
parent | d5381865384abd054ad9382ff3df504c64c92ed3 (diff) | |
download | chromium_src-bf22c76e62e2798fc6ebbfd37bfe101f7c0a6e05.zip chromium_src-bf22c76e62e2798fc6ebbfd37bfe101f7c0a6e05.tar.gz chromium_src-bf22c76e62e2798fc6ebbfd37bfe101f7c0a6e05.tar.bz2 |
Changes frame length to mean bytes of samples in frame
I misunderstood the meaning of the frame header's "length" field: I
thought that it meant the number of samples in the frame. It actually
means the number of bytes of samples in the frame. This CL fixes that
mistake.
BUG=542837
Review URL: https://codereview.chromium.org/1579753002
Cr-Commit-Position: refs/heads/master@{#368863}
Diffstat (limited to 'tools/battor_agent')
-rw-r--r-- | tools/battor_agent/battor_agent.cc | 14 | ||||
-rw-r--r-- | tools/battor_agent/battor_agent_unittest.cc | 18 | ||||
-rw-r--r-- | tools/battor_agent/battor_protocol_types.h | 2 |
3 files changed, 14 insertions, 20 deletions
diff --git a/tools/battor_agent/battor_agent.cc b/tools/battor_agent/battor_agent.cc index a613566..077aa7f 100644 --- a/tools/battor_agent/battor_agent.cc +++ b/tools/battor_agent/battor_agent.cc @@ -71,18 +71,12 @@ bool ParseSampleFrame(BattOrMessageType type, memcpy(frame_header, frame_ptr, sizeof(BattOrFrameHeader)); frame_ptr += sizeof(BattOrFrameHeader); - // The remaining bytes in the frame contain an array of raw samples. - // Therefore, the number of samples in the frame should correspond to number - // of total bytes remaining in the frame. - uint8_t samples_in_frame = - (msg.size() - sizeof(BattOrFrameHeader)) / sizeof(RawBattOrSample); - - if (samples_in_frame != frame_header->length) + size_t remaining_bytes = msg.size() - sizeof(BattOrFrameHeader); + if (remaining_bytes != frame_header->length) return false; - samples->resize(samples_in_frame); - memcpy(samples->data(), frame_ptr, - samples_in_frame * sizeof(RawBattOrSample)); + samples->resize(remaining_bytes / sizeof(RawBattOrSample)); + memcpy(samples->data(), frame_ptr, remaining_bytes); return true; } diff --git a/tools/battor_agent/battor_agent_unittest.cc b/tools/battor_agent/battor_agent_unittest.cc index 15b7205..f7bf70e 100644 --- a/tools/battor_agent/battor_agent_unittest.cc +++ b/tools/battor_agent/battor_agent_unittest.cc @@ -429,7 +429,7 @@ TEST_F(BattOrAgentTest, StopTracing) { RunStopTracingTo(BattOrAgentState::SAMPLES_REQUEST_SENT); // Send the calibration frame. - BattOrFrameHeader cal_frame_header{0, 2}; + BattOrFrameHeader cal_frame_header{0, 2 * sizeof(RawBattOrSample)}; RawBattOrSample cal_frame[] = { RawBattOrSample{1, 1}, RawBattOrSample{2, 2}, }; @@ -437,20 +437,20 @@ TEST_F(BattOrAgentTest, StopTracing) { CreateFrame(cal_frame_header, cal_frame, 2)); // Send the two real data frames. - BattOrFrameHeader frame_header1{0, 3}; + BattOrFrameHeader frame_header1{0, 3 * sizeof(RawBattOrSample)}; RawBattOrSample frame1[] = { RawBattOrSample{1, 1}, RawBattOrSample{2, 2}, RawBattOrSample{3, 3}, }; GetAgent()->OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, CreateFrame(frame_header1, frame1, 3)); - BattOrFrameHeader frame_header2{0, 1}; + BattOrFrameHeader frame_header2{0, 1 * sizeof(RawBattOrSample)}; RawBattOrSample frame2[] = {RawBattOrSample{1, 1}}; GetAgent()->OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, CreateFrame(frame_header2, frame2, 1)); // Send an empty last frame to indicate that we're done. - BattOrFrameHeader frame_header3{0, 0}; + BattOrFrameHeader frame_header3{0, 0 * sizeof(RawBattOrSample)}; RawBattOrSample frame3[] = {}; GetAgent()->OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, CreateFrame(frame_header3, frame3, 0)); @@ -531,7 +531,7 @@ TEST_F(BattOrAgentTest, StopTracingFailsIfCalibrationFrameHasWrongLength) { // Send a calibration frame with a mismatch between the frame length in the // header and the actual frame length. - BattOrFrameHeader cal_frame_header{0, 1}; + BattOrFrameHeader cal_frame_header{0, 1 * sizeof(RawBattOrSample)}; RawBattOrSample cal_frame[] = { RawBattOrSample{1, 1}, RawBattOrSample{2, 2}, }; @@ -545,7 +545,7 @@ TEST_F(BattOrAgentTest, StopTracingFailsIfCalibrationFrameHasWrongLength) { TEST_F(BattOrAgentTest, StopTracingFailsIfDataFrameHasWrongLength) { RunStopTracingTo(BattOrAgentState::SAMPLES_REQUEST_SENT); - BattOrFrameHeader cal_frame_header{0, 1}; + BattOrFrameHeader cal_frame_header{0, 1 * sizeof(RawBattOrSample)}; RawBattOrSample cal_frame[] = { RawBattOrSample{1, 1}, }; @@ -554,7 +554,7 @@ TEST_F(BattOrAgentTest, StopTracingFailsIfDataFrameHasWrongLength) { // Send a data frame with a mismatch between the frame length in the // header and the actual frame length. - BattOrFrameHeader frame_header{0, 2}; + BattOrFrameHeader frame_header{0, 2 * sizeof(RawBattOrSample)}; RawBattOrSample frame[] = {RawBattOrSample{1, 1}}; GetAgent()->OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, CreateFrame(frame_header, frame, 1)); @@ -567,7 +567,7 @@ TEST_F(BattOrAgentTest, StopTracingFailsIfDataFrameHasWrongLength) { TEST_F(BattOrAgentTest, StopTracingFailsIfCalibrationFrameMissingByte) { RunStopTracingTo(BattOrAgentState::SAMPLES_REQUEST_SENT); - BattOrFrameHeader cal_frame_header{0, 2}; + BattOrFrameHeader cal_frame_header{0, 2 * sizeof(RawBattOrSample)}; RawBattOrSample cal_frame[] = { RawBattOrSample{1, 1}, RawBattOrSample{2, 2}, }; @@ -587,7 +587,7 @@ TEST_F(BattOrAgentTest, StopTracingFailsIfCalibrationFrameMissingByte) { TEST_F(BattOrAgentTest, StopTracingFailsIfDataFrameMissingByte) { RunStopTracingTo(BattOrAgentState::SAMPLES_REQUEST_SENT); - BattOrFrameHeader cal_frame_header{0, 1}; + BattOrFrameHeader cal_frame_header{0, 1 * sizeof(RawBattOrSample)}; RawBattOrSample cal_frame[] = { RawBattOrSample{1, 1}, }; diff --git a/tools/battor_agent/battor_protocol_types.h b/tools/battor_agent/battor_protocol_types.h index 292c6d9..48a96a6 100644 --- a/tools/battor_agent/battor_protocol_types.h +++ b/tools/battor_agent/battor_protocol_types.h @@ -115,7 +115,7 @@ struct BattOrEEPROM { struct BattOrFrameHeader { // The number of frames that have preceded this one. uint32_t sequence_no; - // The number of samples in this frame. + // The number of bytes of raw samples in this frame. uint16_t length; }; |