@@ -741,7 +741,7 @@ int IridiumSBD::internalSendReceiveSBD(const char *txTxtMessage, const uint8_t *
741741 diagprint (moCode);
742742 diagprint (F (" \r\n " ));
743743
744- if (moCode >= 0 && moCode <= 4 ) // this range indicates successful return!
744+ if (moCode <= 4 ) // this range indicates successful return!
745745 {
746746 diagprint (F (" SBDIX success!\r\n " ));
747747
@@ -1101,7 +1101,11 @@ void IridiumSBD::power(bool on)
11011101 }
11021102 else
11031103 {
1104- pinMode (this ->sleepPin , OUTPUT); // Make the sleep pin an output
1104+ if (this ->sleepPinConfigured == false )
1105+ {
1106+ configureSleepPin ();
1107+ this ->sleepPinConfigured = true ;
1108+ }
11051109 }
11061110 }
11071111
@@ -1110,15 +1114,14 @@ void IridiumSBD::power(bool on)
11101114 diagprint (F (" Powering on modem...\r\n " ));
11111115 if (this ->useSerial )
11121116 {
1113- digitalWrite ( this -> sleepPin , HIGH); // HIGH = awake
1117+ setSleepPin ( HIGH); // HIGH = awake
11141118 }
11151119 else
11161120 {
11171121 enable9603 (true );
11181122 }
11191123 lastPowerOnTime = millis ();
11201124 }
1121-
11221125 else
11231126 {
11241127 // Best Practices Guide suggests waiting at least 2 seconds
@@ -1130,7 +1133,7 @@ void IridiumSBD::power(bool on)
11301133 diagprint (F (" Powering off modem...\r\n " ));
11311134 if (this ->useSerial )
11321135 {
1133- digitalWrite ( this -> sleepPin , LOW); // LOW = asleep
1136+ setSleepPin ( LOW); // LOW = asleep
11341137 }
11351138 else
11361139 {
@@ -1139,6 +1142,22 @@ void IridiumSBD::power(bool on)
11391142 }
11401143}
11411144
1145+ void IridiumSBD::configureSleepPin ()
1146+ {
1147+ pinMode (this ->sleepPin , OUTPUT); // Make the sleep pin an output
1148+ diagprint (F (" configureSleepPin: sleepPin configured\r\n " ));
1149+ }
1150+
1151+ void IridiumSBD::setSleepPin (uint8_t enable)
1152+ {
1153+ digitalWrite (this ->sleepPin , enable); // HIGH = awake, LOW = asleep
1154+ diagprint (F (" setSleepPin: sleepPin set " ));
1155+ if (enable == HIGH)
1156+ diagprint (F (" HIGH\r\n " ));
1157+ else
1158+ diagprint (F (" LOW\r\n " ));
1159+ }
1160+
11421161void IridiumSBD::send (FlashString str, bool beginLine, bool endLine)
11431162{
11441163 if (beginLine)
@@ -1393,17 +1412,12 @@ void IridiumSBD::check9603data()
13931412 wireport->beginTransmission ((uint8_t )deviceaddress); // Talk to the I2C device
13941413 wireport->write (LEN_REG); // Point to the serial buffer length
13951414 wireport->endTransmission (); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
1396- wireport->requestFrom ((uint8_t )deviceaddress, 2 ); // Request two bytes
1397- if (wireport->available () >= 2 )
1415+ if (wireport->requestFrom ((uint8_t )deviceaddress, (uint8_t )2 ) == 2 ) // Request two bytes
13981416 {
13991417 uint8_t msb = wireport->read ();
14001418 uint8_t lsb = wireport->read ();
14011419 bytesAvailable = (((uint16_t )msb) << 8 ) | lsb;
14021420 }
1403- while (wireport->available ())
1404- {
1405- wireport->read (); // Mop up any unexpected bytes
1406- }
14071421
14081422 // Now read the serial bytes (if any)
14091423 if (bytesAvailable > 0 )
@@ -1416,14 +1430,14 @@ void IridiumSBD::check9603data()
14161430 wireport->endTransmission (); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
14171431 while (bytesAvailable > SER_PACKET_SIZE) // If there are _more_ than SER_PACKET_SIZE bytes to be read
14181432 {
1419- wireport->requestFrom ((uint8_t )deviceaddress, SER_PACKET_SIZE, false ); // Request SER_PACKET_SIZE bytes, don't release the bus
1433+ wireport->requestFrom ((uint8_t )deviceaddress, ( uint8_t ) SER_PACKET_SIZE, ( uint8_t ) false ); // Request SER_PACKET_SIZE bytes, don't release the bus
14201434 while (wireport->available ())
14211435 {
14221436 i2cSerPoke (wireport->read ()); // Read and store each byte
14231437 }
14241438 bytesAvailable -= SER_PACKET_SIZE; // Decrease the number of bytes available by SER_PACKET_SIZE
14251439 }
1426- wireport->requestFrom ((uint8_t )deviceaddress, bytesAvailable); // Request remaining bytes, release the bus
1440+ wireport->requestFrom ((uint8_t )deviceaddress, ( uint8_t ) bytesAvailable); // Request remaining bytes, release the bus
14271441 while (wireport->available ())
14281442 {
14291443 i2cSerPoke (wireport->read ()); // Read and store each byte
@@ -1441,15 +1455,10 @@ void IridiumSBD::check9603pins()
14411455 wireport->beginTransmission ((uint8_t )deviceaddress); // Talk to the I2C device
14421456 wireport->write (IO_REG); // Point to the 'IO register'
14431457 wireport->endTransmission (); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
1444- wireport->requestFrom ((uint8_t )deviceaddress, 1 ); // Request one byte from the IO register
1445- if (wireport->available ())
1458+ if (wireport->requestFrom ((uint8_t )deviceaddress, (uint8_t )1 ) == 1 ) // Request one byte from the IO register
14461459 {
14471460 IO_REGISTER = wireport->read (); // Read the IO register
14481461 }
1449- while (wireport->available ())
1450- {
1451- wireport->read (); // Mop up any unexpected bytes (hopefully redundant!?)
1452- }
14531462}
14541463
14551464// Set the IO pins
@@ -1476,17 +1485,12 @@ int IridiumSBD::internalPassThruI2Cread(uint8_t *rxBuffer, size_t &rxBufferSize,
14761485 wireport->beginTransmission ((uint8_t )deviceaddress); // Talk to the I2C device
14771486 wireport->write (LEN_REG); // Point to the serial buffer length
14781487 wireport->endTransmission (); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
1479- wireport->requestFrom ((uint8_t )deviceaddress, 2 ); // Request two bytes
1480- if (wireport->available () >= 2 )
1488+ if (wireport->requestFrom ((uint8_t )deviceaddress, (uint8_t )2 ) == 2 ) // Request two bytes
14811489 {
14821490 uint8_t msb = wireport->read ();
14831491 uint8_t lsb = wireport->read ();
14841492 bytesAvailable = (((uint16_t )msb) << 8 ) | lsb;
14851493 }
1486- while (wireport->available ())
1487- {
1488- wireport->read (); // Mop up any unexpected bytes
1489- }
14901494
14911495 numBytes = (size_t )bytesAvailable; // Store bytesAvailable in numBytes
14921496
@@ -1503,7 +1507,7 @@ int IridiumSBD::internalPassThruI2Cread(uint8_t *rxBuffer, size_t &rxBufferSize,
15031507 wireport->endTransmission (); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
15041508 while (bytesAvailable > SER_PACKET_SIZE) // If there are _more_ than SER_PACKET_SIZE bytes to be read
15051509 {
1506- wireport->requestFrom ((uint8_t )deviceaddress, SER_PACKET_SIZE, false ); // Request SER_PACKET_SIZE bytes, don't release the bus
1510+ wireport->requestFrom ((uint8_t )deviceaddress, ( uint8_t ) SER_PACKET_SIZE, ( uint8_t ) false ); // Request SER_PACKET_SIZE bytes, don't release the bus
15071511 while (wireport->available ())
15081512 {
15091513 uint8_t dbyte = wireport->read (); // Read a byte
@@ -1515,7 +1519,7 @@ int IridiumSBD::internalPassThruI2Cread(uint8_t *rxBuffer, size_t &rxBufferSize,
15151519 }
15161520 bytesAvailable -= SER_PACKET_SIZE; // Decrease the number of bytes available by SER_PACKET_SIZE
15171521 }
1518- wireport->requestFrom ((uint8_t )deviceaddress, bytesAvailable); // Request remaining bytes, release the bus
1522+ wireport->requestFrom ((uint8_t )deviceaddress, ( uint8_t ) bytesAvailable); // Request remaining bytes, release the bus
15191523 while (wireport->available ())
15201524 {
15211525 uint8_t dbyte = wireport->read (); // Read a byte
0 commit comments