@@ -741,7 +741,7 @@ int IridiumSBD::internalSendReceiveSBD(const char *txTxtMessage, const uint8_t *
741
741
diagprint (moCode);
742
742
diagprint (F (" \r\n " ));
743
743
744
- if (moCode >= 0 && moCode <= 4 ) // this range indicates successful return!
744
+ if (moCode <= 4 ) // this range indicates successful return!
745
745
{
746
746
diagprint (F (" SBDIX success!\r\n " ));
747
747
@@ -1101,7 +1101,11 @@ void IridiumSBD::power(bool on)
1101
1101
}
1102
1102
else
1103
1103
{
1104
- pinMode (this ->sleepPin , OUTPUT); // Make the sleep pin an output
1104
+ if (this ->sleepPinConfigured == false )
1105
+ {
1106
+ configureSleepPin ();
1107
+ this ->sleepPinConfigured = true ;
1108
+ }
1105
1109
}
1106
1110
}
1107
1111
@@ -1110,15 +1114,14 @@ void IridiumSBD::power(bool on)
1110
1114
diagprint (F (" Powering on modem...\r\n " ));
1111
1115
if (this ->useSerial )
1112
1116
{
1113
- digitalWrite ( this -> sleepPin , HIGH); // HIGH = awake
1117
+ setSleepPin ( HIGH); // HIGH = awake
1114
1118
}
1115
1119
else
1116
1120
{
1117
1121
enable9603 (true );
1118
1122
}
1119
1123
lastPowerOnTime = millis ();
1120
1124
}
1121
-
1122
1125
else
1123
1126
{
1124
1127
// Best Practices Guide suggests waiting at least 2 seconds
@@ -1130,7 +1133,7 @@ void IridiumSBD::power(bool on)
1130
1133
diagprint (F (" Powering off modem...\r\n " ));
1131
1134
if (this ->useSerial )
1132
1135
{
1133
- digitalWrite ( this -> sleepPin , LOW); // LOW = asleep
1136
+ setSleepPin ( LOW); // LOW = asleep
1134
1137
}
1135
1138
else
1136
1139
{
@@ -1139,6 +1142,22 @@ void IridiumSBD::power(bool on)
1139
1142
}
1140
1143
}
1141
1144
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
+
1142
1161
void IridiumSBD::send (FlashString str, bool beginLine, bool endLine)
1143
1162
{
1144
1163
if (beginLine)
@@ -1393,17 +1412,12 @@ void IridiumSBD::check9603data()
1393
1412
wireport->beginTransmission ((uint8_t )deviceaddress); // Talk to the I2C device
1394
1413
wireport->write (LEN_REG); // Point to the serial buffer length
1395
1414
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
1398
1416
{
1399
1417
uint8_t msb = wireport->read ();
1400
1418
uint8_t lsb = wireport->read ();
1401
1419
bytesAvailable = (((uint16_t )msb) << 8 ) | lsb;
1402
1420
}
1403
- while (wireport->available ())
1404
- {
1405
- wireport->read (); // Mop up any unexpected bytes
1406
- }
1407
1421
1408
1422
// Now read the serial bytes (if any)
1409
1423
if (bytesAvailable > 0 )
@@ -1416,14 +1430,14 @@ void IridiumSBD::check9603data()
1416
1430
wireport->endTransmission (); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
1417
1431
while (bytesAvailable > SER_PACKET_SIZE) // If there are _more_ than SER_PACKET_SIZE bytes to be read
1418
1432
{
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
1420
1434
while (wireport->available ())
1421
1435
{
1422
1436
i2cSerPoke (wireport->read ()); // Read and store each byte
1423
1437
}
1424
1438
bytesAvailable -= SER_PACKET_SIZE; // Decrease the number of bytes available by SER_PACKET_SIZE
1425
1439
}
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
1427
1441
while (wireport->available ())
1428
1442
{
1429
1443
i2cSerPoke (wireport->read ()); // Read and store each byte
@@ -1441,15 +1455,10 @@ void IridiumSBD::check9603pins()
1441
1455
wireport->beginTransmission ((uint8_t )deviceaddress); // Talk to the I2C device
1442
1456
wireport->write (IO_REG); // Point to the 'IO register'
1443
1457
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
1446
1459
{
1447
1460
IO_REGISTER = wireport->read (); // Read the IO register
1448
1461
}
1449
- while (wireport->available ())
1450
- {
1451
- wireport->read (); // Mop up any unexpected bytes (hopefully redundant!?)
1452
- }
1453
1462
}
1454
1463
1455
1464
// Set the IO pins
@@ -1476,17 +1485,12 @@ int IridiumSBD::internalPassThruI2Cread(uint8_t *rxBuffer, size_t &rxBufferSize,
1476
1485
wireport->beginTransmission ((uint8_t )deviceaddress); // Talk to the I2C device
1477
1486
wireport->write (LEN_REG); // Point to the serial buffer length
1478
1487
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
1481
1489
{
1482
1490
uint8_t msb = wireport->read ();
1483
1491
uint8_t lsb = wireport->read ();
1484
1492
bytesAvailable = (((uint16_t )msb) << 8 ) | lsb;
1485
1493
}
1486
- while (wireport->available ())
1487
- {
1488
- wireport->read (); // Mop up any unexpected bytes
1489
- }
1490
1494
1491
1495
numBytes = (size_t )bytesAvailable; // Store bytesAvailable in numBytes
1492
1496
@@ -1503,7 +1507,7 @@ int IridiumSBD::internalPassThruI2Cread(uint8_t *rxBuffer, size_t &rxBufferSize,
1503
1507
wireport->endTransmission (); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
1504
1508
while (bytesAvailable > SER_PACKET_SIZE) // If there are _more_ than SER_PACKET_SIZE bytes to be read
1505
1509
{
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
1507
1511
while (wireport->available ())
1508
1512
{
1509
1513
uint8_t dbyte = wireport->read (); // Read a byte
@@ -1515,7 +1519,7 @@ int IridiumSBD::internalPassThruI2Cread(uint8_t *rxBuffer, size_t &rxBufferSize,
1515
1519
}
1516
1520
bytesAvailable -= SER_PACKET_SIZE; // Decrease the number of bytes available by SER_PACKET_SIZE
1517
1521
}
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
1519
1523
while (wireport->available ())
1520
1524
{
1521
1525
uint8_t dbyte = wireport->read (); // Read a byte
0 commit comments