Merge pull request #6 from ntruchsess/searchcommands
Add conditional-search and resume commands
This commit is contained in:
commit
e694ed99d8
@ -46,6 +46,8 @@ byte OneWireSlave::receivingByte_;
|
|||||||
byte OneWireSlave::searchRomBytePos_;
|
byte OneWireSlave::searchRomBytePos_;
|
||||||
byte OneWireSlave::searchRomBitPos_;
|
byte OneWireSlave::searchRomBitPos_;
|
||||||
bool OneWireSlave::searchRomInverse_;
|
bool OneWireSlave::searchRomInverse_;
|
||||||
|
bool OneWireSlave::resumeCommandFlag_;
|
||||||
|
bool OneWireSlave::alarmedFlag_;
|
||||||
|
|
||||||
const byte* OneWireSlave::sendBuffer_;
|
const byte* OneWireSlave::sendBuffer_;
|
||||||
byte* OneWireSlave::recvBuffer_;
|
byte* OneWireSlave::recvBuffer_;
|
||||||
@ -77,6 +79,9 @@ void OneWireSlave::begin(const byte* rom, byte pinNumber)
|
|||||||
memcpy(rom_, rom, 7);
|
memcpy(rom_, rom, 7);
|
||||||
rom_[7] = crc8(rom_, 7);
|
rom_[7] = crc8(rom_, 7);
|
||||||
|
|
||||||
|
resumeCommandFlag_ = false;
|
||||||
|
alarmedFlag_ = false;
|
||||||
|
|
||||||
clientReceiveBitCallback_ = 0;
|
clientReceiveBitCallback_ = 0;
|
||||||
|
|
||||||
// log("Enabling 1-wire library")
|
// log("Enabling 1-wire library")
|
||||||
@ -146,6 +151,11 @@ void OneWireSlave::stopWrite()
|
|||||||
write(0, 0, 0);
|
write(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OneWireSlave::alarmed(bool value)
|
||||||
|
{
|
||||||
|
alarmedFlag_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
byte OneWireSlave::crc8(const byte* data, short numBytes)
|
byte OneWireSlave::crc8(const byte* data, short numBytes)
|
||||||
{
|
{
|
||||||
byte crc = 0;
|
byte crc = 0;
|
||||||
@ -407,18 +417,41 @@ void OneWireSlave::onBitReceived_(bool bit, bool error)
|
|||||||
switch (receivingByte_)
|
switch (receivingByte_)
|
||||||
{
|
{
|
||||||
case 0xF0: // SEARCH ROM
|
case 0xF0: // SEARCH ROM
|
||||||
|
resumeCommandFlag_ = false;
|
||||||
beginSearchRom_();
|
beginSearchRom_();
|
||||||
return;
|
return;
|
||||||
|
case 0xEC: // CONDITIONAL SEARCH ROM
|
||||||
|
resumeCommandFlag_ = false;
|
||||||
|
if (alarmedFlag_)
|
||||||
|
{
|
||||||
|
beginSearchRom_();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
beginWaitReset_();
|
||||||
|
}
|
||||||
|
return;
|
||||||
case 0x33: // READ ROM
|
case 0x33: // READ ROM
|
||||||
|
resumeCommandFlag_ = false;
|
||||||
beginWriteBytes_(rom_, 8, &OneWireSlave::noOpCallback_);
|
beginWriteBytes_(rom_, 8, &OneWireSlave::noOpCallback_);
|
||||||
return;
|
return;
|
||||||
case 0x55: // MATCH ROM
|
case 0x55: // MATCH ROM
|
||||||
|
resumeCommandFlag_ = false;
|
||||||
beginReceiveBytes_(scratchpad_, 8, &OneWireSlave::matchRomBytesReceived_);
|
beginReceiveBytes_(scratchpad_, 8, &OneWireSlave::matchRomBytesReceived_);
|
||||||
return;
|
return;
|
||||||
case 0xCC: // SKIP ROM
|
case 0xCC: // SKIP ROM
|
||||||
// emulate a match rom operation
|
resumeCommandFlag_ = false;
|
||||||
memcpy(scratchpad_, rom_, 8);
|
beginReceiveBytes_(scratchpad_, 1, &OneWireSlave::notifyClientByteReceived_);
|
||||||
matchRomBytesReceived_(false);
|
return;
|
||||||
|
case 0xA5: // RESUME
|
||||||
|
if (resumeCommandFlag_)
|
||||||
|
{
|
||||||
|
beginReceiveBytes_(scratchpad_, 1, &OneWireSlave::notifyClientByteReceived_);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
beginWaitReset_();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
ERROR("Unknown command");
|
ERROR("Unknown command");
|
||||||
@ -582,6 +615,7 @@ void OneWireSlave::matchRomBytesReceived_(bool error)
|
|||||||
{
|
{
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
|
resumeCommandFlag_ = false;
|
||||||
ERROR("error receiving match rom bytes");
|
ERROR("error receiving match rom bytes");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -589,13 +623,13 @@ void OneWireSlave::matchRomBytesReceived_(bool error)
|
|||||||
if (memcmp(rom_, scratchpad_, 8) == 0)
|
if (memcmp(rom_, scratchpad_, 8) == 0)
|
||||||
{
|
{
|
||||||
// log("ROM matched");
|
// log("ROM matched");
|
||||||
|
resumeCommandFlag_ = true;
|
||||||
beginReceiveBytes_(scratchpad_, 1, &OneWireSlave::notifyClientByteReceived_);
|
beginReceiveBytes_(scratchpad_, 1, &OneWireSlave::notifyClientByteReceived_);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// log("ROM not matched");
|
// log("ROM not matched");
|
||||||
|
resumeCommandFlag_ = false;
|
||||||
beginWaitReset_();
|
beginWaitReset_();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ public:
|
|||||||
//! Cancels any pending write operation, started by writeBit or write. If this function is called before the master asked for a bit, then nothing is sent to the master.
|
//! Cancels any pending write operation, started by writeBit or write. If this function is called before the master asked for a bit, then nothing is sent to the master.
|
||||||
void stopWrite();
|
void stopWrite();
|
||||||
|
|
||||||
|
void alarmed(bool value);
|
||||||
|
|
||||||
static byte crc8(const byte* data, short numBytes);
|
static byte crc8(const byte* data, short numBytes);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -102,6 +104,8 @@ private:
|
|||||||
static byte searchRomBytePos_;
|
static byte searchRomBytePos_;
|
||||||
static byte searchRomBitPos_;
|
static byte searchRomBitPos_;
|
||||||
static bool searchRomInverse_;
|
static bool searchRomInverse_;
|
||||||
|
static bool resumeCommandFlag_;
|
||||||
|
static bool alarmedFlag_;
|
||||||
|
|
||||||
static const byte* sendBuffer_;
|
static const byte* sendBuffer_;
|
||||||
static byte* recvBuffer_;
|
static byte* recvBuffer_;
|
||||||
|
Loading…
Reference in New Issue
Block a user