Skip to content

v3.0.3 #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ getIMEI KEYWORD2
isConnected KEYWORD2
passThruI2Cread KEYWORD2
passThruI2Cwrite KEYWORD2
configureSleepPin KEYWORD2
setSleepPin KEYWORD2

#######################################
# Constants (LITERAL1)
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=IridiumSBDi2c
version=3.0.2
version=3.0.3
author=Mikal Hart and Paul Clark (PaulZC)
maintainer=SparkFun Electronics <sparkfun.com>
sentence=This library supports satellite data transmissions from anywhere on earth using the RockBLOCK family of Iridium 9602 and 9603 modems.
Expand Down
58 changes: 31 additions & 27 deletions src/IridiumSBD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ int IridiumSBD::internalSendReceiveSBD(const char *txTxtMessage, const uint8_t *
diagprint(moCode);
diagprint(F("\r\n"));

if (moCode >= 0 && moCode <= 4) // this range indicates successful return!
if (moCode <= 4) // this range indicates successful return!
{
diagprint(F("SBDIX success!\r\n"));

Expand Down Expand Up @@ -1101,7 +1101,11 @@ void IridiumSBD::power(bool on)
}
else
{
pinMode(this->sleepPin, OUTPUT); // Make the sleep pin an output
if (this->sleepPinConfigured == false)
{
configureSleepPin();
this->sleepPinConfigured = true;
}
}
}

Expand All @@ -1110,15 +1114,14 @@ void IridiumSBD::power(bool on)
diagprint(F("Powering on modem...\r\n"));
if (this->useSerial)
{
digitalWrite(this->sleepPin, HIGH); // HIGH = awake
setSleepPin(HIGH); // HIGH = awake
}
else
{
enable9603(true);
}
lastPowerOnTime = millis();
}

else
{
// Best Practices Guide suggests waiting at least 2 seconds
Expand All @@ -1130,7 +1133,7 @@ void IridiumSBD::power(bool on)
diagprint(F("Powering off modem...\r\n"));
if (this->useSerial)
{
digitalWrite(this->sleepPin, LOW); // LOW = asleep
setSleepPin(LOW); // LOW = asleep
}
else
{
Expand All @@ -1139,6 +1142,22 @@ void IridiumSBD::power(bool on)
}
}

void IridiumSBD::configureSleepPin()
{
pinMode(this->sleepPin, OUTPUT); // Make the sleep pin an output
diagprint(F("configureSleepPin: sleepPin configured\r\n"));
}

void IridiumSBD::setSleepPin(uint8_t enable)
{
digitalWrite(this->sleepPin, enable); // HIGH = awake, LOW = asleep
diagprint(F("setSleepPin: sleepPin set "));
if (enable == HIGH)
diagprint(F("HIGH\r\n"));
else
diagprint(F("LOW\r\n"));
}

void IridiumSBD::send(FlashString str, bool beginLine, bool endLine)
{
if (beginLine)
Expand Down Expand Up @@ -1393,17 +1412,12 @@ void IridiumSBD::check9603data()
wireport->beginTransmission((uint8_t)deviceaddress); // Talk to the I2C device
wireport->write(LEN_REG); // Point to the serial buffer length
wireport->endTransmission(); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
wireport->requestFrom((uint8_t)deviceaddress, 2); // Request two bytes
if (wireport->available() >= 2)
if (wireport->requestFrom((uint8_t)deviceaddress, (uint8_t)2) == 2) // Request two bytes
{
uint8_t msb = wireport->read();
uint8_t lsb = wireport->read();
bytesAvailable = (((uint16_t)msb) << 8) | lsb;
}
while (wireport->available())
{
wireport->read(); // Mop up any unexpected bytes
}

//Now read the serial bytes (if any)
if (bytesAvailable > 0)
Expand All @@ -1416,14 +1430,14 @@ void IridiumSBD::check9603data()
wireport->endTransmission(); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
while (bytesAvailable > SER_PACKET_SIZE) // If there are _more_ than SER_PACKET_SIZE bytes to be read
{
wireport->requestFrom((uint8_t)deviceaddress, SER_PACKET_SIZE, false); // Request SER_PACKET_SIZE bytes, don't release the bus
wireport->requestFrom((uint8_t)deviceaddress, (uint8_t)SER_PACKET_SIZE, (uint8_t)false); // Request SER_PACKET_SIZE bytes, don't release the bus
while (wireport->available())
{
i2cSerPoke(wireport->read()); // Read and store each byte
}
bytesAvailable -= SER_PACKET_SIZE; // Decrease the number of bytes available by SER_PACKET_SIZE
}
wireport->requestFrom((uint8_t)deviceaddress, bytesAvailable); // Request remaining bytes, release the bus
wireport->requestFrom((uint8_t)deviceaddress, (uint8_t)bytesAvailable); // Request remaining bytes, release the bus
while (wireport->available())
{
i2cSerPoke(wireport->read()); // Read and store each byte
Expand All @@ -1441,15 +1455,10 @@ void IridiumSBD::check9603pins()
wireport->beginTransmission((uint8_t)deviceaddress); // Talk to the I2C device
wireport->write(IO_REG); // Point to the 'IO register'
wireport->endTransmission(); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
wireport->requestFrom((uint8_t)deviceaddress, 1); // Request one byte from the IO register
if (wireport->available())
if (wireport->requestFrom((uint8_t)deviceaddress, (uint8_t)1) == 1) // Request one byte from the IO register
{
IO_REGISTER = wireport->read(); // Read the IO register
}
while (wireport->available())
{
wireport->read(); // Mop up any unexpected bytes (hopefully redundant!?)
}
}

//Set the IO pins
Expand All @@ -1476,17 +1485,12 @@ int IridiumSBD::internalPassThruI2Cread(uint8_t *rxBuffer, size_t &rxBufferSize,
wireport->beginTransmission((uint8_t)deviceaddress); // Talk to the I2C device
wireport->write(LEN_REG); // Point to the serial buffer length
wireport->endTransmission(); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
wireport->requestFrom((uint8_t)deviceaddress, 2); // Request two bytes
if (wireport->available() >= 2)
if (wireport->requestFrom((uint8_t)deviceaddress, (uint8_t)2) == 2) // Request two bytes
{
uint8_t msb = wireport->read();
uint8_t lsb = wireport->read();
bytesAvailable = (((uint16_t)msb) << 8) | lsb;
}
while (wireport->available())
{
wireport->read(); // Mop up any unexpected bytes
}

numBytes = (size_t)bytesAvailable; //Store bytesAvailable in numBytes

Expand All @@ -1503,7 +1507,7 @@ int IridiumSBD::internalPassThruI2Cread(uint8_t *rxBuffer, size_t &rxBufferSize,
wireport->endTransmission(); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
while (bytesAvailable > SER_PACKET_SIZE) // If there are _more_ than SER_PACKET_SIZE bytes to be read
{
wireport->requestFrom((uint8_t)deviceaddress, SER_PACKET_SIZE, false); // Request SER_PACKET_SIZE bytes, don't release the bus
wireport->requestFrom((uint8_t)deviceaddress, (uint8_t)SER_PACKET_SIZE, (uint8_t)false); // Request SER_PACKET_SIZE bytes, don't release the bus
while (wireport->available())
{
uint8_t dbyte = wireport->read(); // Read a byte
Expand All @@ -1515,7 +1519,7 @@ int IridiumSBD::internalPassThruI2Cread(uint8_t *rxBuffer, size_t &rxBufferSize,
}
bytesAvailable -= SER_PACKET_SIZE; // Decrease the number of bytes available by SER_PACKET_SIZE
}
wireport->requestFrom((uint8_t)deviceaddress, bytesAvailable); // Request remaining bytes, release the bus
wireport->requestFrom((uint8_t)deviceaddress, (uint8_t)bytesAvailable); // Request remaining bytes, release the bus
while (wireport->available())
{
uint8_t dbyte = wireport->read(); // Read a byte
Expand Down
7 changes: 7 additions & 0 deletions src/IridiumSBD.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class IridiumSBD
int passThruI2Cread(uint8_t *rxBuffer, size_t &rxBufferSize, size_t &numBytes);
int passThruI2Cwrite(uint8_t *txBuffer, size_t &txBufferSize);

// Weak functions to configure and set the sleep pin - user can overwrite with a custom functions if required
void configureSleepPin() __attribute__((weak));
void setSleepPin(uint8_t enable) __attribute__((weak));

IridiumSBD(Stream &str, int sleepPinNo = -1, int ringPinNo = -1)
{
useSerial = true;
Expand All @@ -146,6 +150,7 @@ class IridiumSBD
asleep = true;
reentrant = false;
sleepPin = sleepPinNo;
sleepPinConfigured = false;
ringPin = ringPinNo;
msstmWorkaroundRequested = true;
ringAlertsEnabled = {ringPinNo != -1};
Expand Down Expand Up @@ -175,6 +180,7 @@ class IridiumSBD
asleep = true;
reentrant = false;
sleepPin = -1;
sleepPinConfigured = false;
ringPin = -1;
msstmWorkaroundRequested = false;
ringAlertsEnabled = true;
Expand Down Expand Up @@ -218,6 +224,7 @@ class IridiumSBD
bool asleep;
bool reentrant;
int sleepPin;
bool sleepPinConfigured;
int ringPin;
bool msstmWorkaroundRequested;
bool ringAlertsEnabled;
Expand Down