2021-02-12 23:42:12 +00:00
|
|
|
//
|
|
|
|
// ReactiveDevice.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 12/02/2021.
|
|
|
|
// Copyright © 2021 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ReactiveDevice_hpp
|
|
|
|
#define ReactiveDevice_hpp
|
|
|
|
|
|
|
|
#include "Bus.hpp"
|
|
|
|
|
2021-02-16 01:33:10 +00:00
|
|
|
#include <atomic>
|
2021-02-12 23:42:12 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-05-10 21:02:18 +00:00
|
|
|
namespace Apple::ADB {
|
2021-02-12 23:42:12 +00:00
|
|
|
|
|
|
|
class ReactiveDevice: public Bus::Device {
|
|
|
|
protected:
|
2021-02-13 22:53:40 +00:00
|
|
|
ReactiveDevice(Bus &bus, uint8_t adb_device_id);
|
2021-02-12 23:42:12 +00:00
|
|
|
|
|
|
|
void post_response(const std::vector<uint8_t> &&response);
|
2021-02-14 23:54:22 +00:00
|
|
|
void post_service_request();
|
2021-02-15 01:37:33 +00:00
|
|
|
void receive_bytes(size_t count);
|
|
|
|
|
2021-02-13 22:53:40 +00:00
|
|
|
virtual void perform_command(const Command &command) = 0;
|
2021-02-15 01:37:33 +00:00
|
|
|
virtual void did_receive_data(const Command &, const std::vector<uint8_t> &) {}
|
2021-02-13 22:53:40 +00:00
|
|
|
|
|
|
|
private:
|
2021-02-14 23:54:22 +00:00
|
|
|
void advance_state(double microseconds, bool current_level) override;
|
2021-02-13 22:53:40 +00:00
|
|
|
void adb_bus_did_observe_event(Bus::Event event, uint8_t value) override;
|
2021-02-12 23:42:12 +00:00
|
|
|
|
|
|
|
private:
|
2021-02-12 23:56:43 +00:00
|
|
|
Bus &bus_;
|
2021-02-12 23:42:12 +00:00
|
|
|
const size_t device_id_;
|
2021-02-12 23:56:43 +00:00
|
|
|
|
2021-02-12 23:42:12 +00:00
|
|
|
std::vector<uint8_t> response_;
|
2021-02-12 23:56:43 +00:00
|
|
|
int bit_offset_ = 0;
|
|
|
|
double microseconds_at_bit_ = 0;
|
2021-02-13 22:53:40 +00:00
|
|
|
|
2021-02-15 01:37:33 +00:00
|
|
|
enum class Phase {
|
|
|
|
AwaitingAttention,
|
|
|
|
AwaitingCommand,
|
|
|
|
AwaitingContent,
|
2021-02-16 01:33:10 +00:00
|
|
|
ServiceRequestPending,
|
2021-02-15 01:37:33 +00:00
|
|
|
} phase_ = Phase::AwaitingAttention;
|
|
|
|
std::vector<uint8_t> content_;
|
|
|
|
size_t expected_content_size_ = 0;
|
|
|
|
Command command_;
|
2021-02-16 01:33:10 +00:00
|
|
|
bool stop_has_begin_ = false;
|
2021-02-15 01:37:33 +00:00
|
|
|
|
|
|
|
uint16_t register3_;
|
|
|
|
const uint8_t default_adb_device_id_;
|
|
|
|
|
2021-02-16 01:33:10 +00:00
|
|
|
std::atomic<bool> service_desired_ = false;
|
|
|
|
|
2021-02-15 01:37:33 +00:00
|
|
|
void reset();
|
2021-02-12 23:42:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ReactiveDevice_hpp */
|