Skip to content

v1.1.0 - updates for v2 of the modem firmware #3

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 13 commits into from
Mar 28, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -116,99 +116,23 @@ void loop()

Serial.print(F("There are "));
Serial.print(count);
Serial.println(F(" messages in the TX queue"));
Serial.println(F(" unsent messages in the TX queue"));
Serial.println();

if (count > 0)
{
if (count > 10)
{
count = 10; // Limit the menu to the first ten messages
Serial.println(F("The first 10 messages are:"));
}
else
Serial.println(F("The messages are:"));

uint64_t *ids = new uint64_t[count]; // Create an array of uint64_t to store the message IDs
mySwarm.listTxMessagesIDs(ids, count); // Ask the modem for a list of the IDs

for (uint16_t i = 0; i < count; i++) // Print all the message IDs
{
Serial.print(i);
Serial.print(F(" : "));
serialPrintUint64_t(ids[i]);
Serial.println();
}

Serial.println();
Serial.println(F("Enter:"));
Serial.println(F("L followed by the message number to list a message. E.g. L1"));
Serial.println(F("D followed by the message number to delete a message. E.g. D0"));
Serial.println(F("A to delete all messages"));
Serial.println(F("A to delete all unsent messages"));

while (!Serial.available()) // Wait for the user to enter a character
mySwarm.checkUnsolicitedMsg(); // Keep emptying the backlog

char c = Serial.read(); // Read the serial character

if (c == 'L') // List a message
{
while (!Serial.available()) // Wait for the user to enter the message number
;
c = Serial.read(); // Read the serial character
if ((c >= '0') && (c < ('0' + count)) && (c <= '9')) // Check for a valid number
{
// Allocate storage for the message. The message could be up to 2 * 192 bytes long. Include space for a null on the end.
char *asciiHex = new char[385];
uint32_t epoch;
uint16_t appID;
mySwarm.listTxMessage(ids[c - '0'], asciiHex, 385, &epoch, &appID); // List the message
Serial.println();
Serial.print(F("Message contents in ASCII Hex: "));
Serial.println(asciiHex); // Print the message contents in ASCII Hex

// Convert the ASCII Hex into chars and print if printable
Serial.print(F("Message contents (if printable): "));
for (size_t i = 0; i < strlen(asciiHex); i+= 2)
{
uint8_t cc = ((asciiHex[i] >= '0') && (asciiHex[i] <= '9')) ? ((asciiHex[i] - '0') << 4) :
((asciiHex[i] >= 'a') && (asciiHex[i] <= 'f')) ? ((asciiHex[i] + 10 - 'a') << 4) :
((asciiHex[i] >= 'A') && (asciiHex[i] <= 'F')) ? ((asciiHex[i] + 10 - 'A') << 4) : 0;
cc = cc | (((asciiHex[i+1] >= '0') && (asciiHex[i+1] <= '9')) ? ((asciiHex[i+1] - '0') << 0) :
((asciiHex[i+1] >= 'a') && (asciiHex[i+1] <= 'f')) ? ((asciiHex[i+1] + 10 - 'a') << 0) :
((asciiHex[i+1] >= 'A') && (asciiHex[i+1] <= 'F')) ? ((asciiHex[i+1] + 10 - 'A') << 0) : 0);
if (((cc >= ' ') && (cc <= '~')) || (cc == '\r') || (cc == '\n')) // Check if cc is printable
Serial.write(cc);
}
Serial.println();

Serial.print(F("Message epoch: "));
Serial.print(epoch);
Serial.print(F(" Message appID: "));
Serial.println(appID);
Serial.println();

delete[] asciiHex; // Delete the char storage
}
}

else if (c == 'D') // Delete a message
{
while (!Serial.available()) // Wait for the user to enter the message number
;
c = Serial.read(); // Read the serial character
if ((c >= '0') && (c < ('0' + count)) && (c <= '9')) // Check for a valid number
{
mySwarm.deleteTxMessage(ids[c - '0']); // Delete the message
}
}

else if (c == 'A') // Delete all messages
if (c == 'A') // Delete all messages
{
mySwarm.deleteAllTxMessages();
}

delete[] ids; // Delete the ID storage
}
else
{
Expand Down
82 changes: 66 additions & 16 deletions examples/Example6_GPIO1Mode/Example6_GPIO1Mode.ino
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,22 @@ void setup()

// Set the GPIO1 pin mode
// Possible choices are:
// SWARM_M138_GPIO1_ANALOG
// SWARM_M138_GPIO1_EXIT_SLEEP_LOW_HIGH
// SWARM_M138_GPIO1_EXIT_SLEEP_HIGH_LOW
// SWARM_M138_GPIO1_OUTPUT_LOW
// SWARM_M138_GPIO1_OUTPUT_HIGH
// SWARM_M138_GPIO1_MESSAGES_PENDING_LOW
// SWARM_M138_GPIO1_MESSAGES_PENDING_HIGH
// SWARM_M138_GPIO1_SLEEP_MODE_LOW
// SWARM_M138_GPIO1_SLEEP_MODE_HIGH
Swarm_M138_Error_e err = mySwarm.setGPIO1Mode(SWARM_M138_GPIO1_OUTPUT_LOW);
// SWARM_M138_GPIO1_ANALOG
// SWARM_M138_GPIO1_ADC
// SWARM_M138_GPIO1_INPUT
// SWARM_M138_GPIO1_EXIT_SLEEP_LOW_HIGH
// SWARM_M138_GPIO1_EXIT_SLEEP_HIGH_LOW
// SWARM_M138_GPIO1_OUTPUT_LOW
// SWARM_M138_GPIO1_OUTPUT_HIGH
// SWARM_M138_GPIO1_MESSAGES_UNREAD_LOW
// SWARM_M138_GPIO1_MESSAGES_UNREAD_HIGH
// SWARM_M138_GPIO1_MESSAGES_UNSENT_LOW
// SWARM_M138_GPIO1_MESSAGES_UNSENT_HIGH
// SWARM_M138_GPIO1_MESSAGES_UNREAD_UNSENT_LOW
// SWARM_M138_GPIO1_MESSAGES_UNREAD_UNSENT_HIGH
// SWARM_M138_GPIO1_SLEEP_MODE_LOW
// SWARM_M138_GPIO1_SLEEP_MODE_HIGH
Swarm_M138_Error_e err = mySwarm.setGPIO1Mode(SWARM_M138_GPIO1_ADC);

if (err == SWARM_M138_SUCCESS)
{
Expand Down Expand Up @@ -95,6 +101,12 @@ void setup()
case SWARM_M138_GPIO1_ANALOG:
Serial.println(F(" Analog, pin is internally disconnected and not used (default)"));
break;
case SWARM_M138_GPIO1_ADC:
Serial.println(F(" Analog ADC, pin can be read to measure input voltage (0-3.3V)"));
break;
case SWARM_M138_GPIO1_INPUT:
Serial.println(F(" Input, pin can be read as a general purpose digital input (High or Low)"));
break;
case SWARM_M138_GPIO1_EXIT_SLEEP_LOW_HIGH:
Serial.println(F(" Input, low-to-high transition exits sleep mode"));
break;
Expand All @@ -107,22 +119,60 @@ void setup()
case SWARM_M138_GPIO1_OUTPUT_HIGH:
Serial.println(F(" Output (open drain), set high/open"));
break;
case SWARM_M138_GPIO1_MESSAGES_PENDING_LOW:
Serial.println(F(" Output (open drain), low indicates messages pending for client"));
case SWARM_M138_GPIO1_MESSAGES_UNREAD_LOW:
Serial.println(F(" Output (open drain), low indicates unread messages pending for user"));
break;
case SWARM_M138_GPIO1_MESSAGES_UNREAD_HIGH:
Serial.println(F(" Output (open drain), high/open indicates unread messages pending for user"));
break;
case SWARM_M138_GPIO1_MESSAGES_UNSENT_LOW:
Serial.println(F(" Output (open drain), low indicates unsent messages pending for transmit"));
break;
case SWARM_M138_GPIO1_MESSAGES_PENDING_HIGH:
Serial.println(F(" Output (open drain), high/open indicates messages pending for client"));
case SWARM_M138_GPIO1_MESSAGES_UNSENT_HIGH:
Serial.println(F(" Output (open drain), high/open indicates unsent messages pending for transmit"));
break;
case SWARM_M138_GPIO1_MESSAGES_UNREAD_UNSENT_LOW:
Serial.println(F(" Output (open drain), low indicates unread or unsent messages"));
break;
case SWARM_M138_GPIO1_MESSAGES_UNREAD_UNSENT_HIGH:
Serial.println(F(" Output (open drain), high/open indicates unread or unsent messages"));
break;
case SWARM_M138_GPIO1_SLEEP_MODE_LOW:
Serial.println(F(" Output (open drain), low indicates in sleep mode. Otherwise output is high/open"));
Serial.println(F(" Output (open drain), low indicates sleep mode is active. Otherwise output is high/open"));
break;
case SWARM_M138_GPIO1_SLEEP_MODE_HIGH:
Serial.println(F(" Output (open drain), high/open indicates in sleep mode. Otherwise output is low"));
Serial.println(F(" Output (open drain), high/open indicates sleep mode is active. Otherwise output is low"));
break;
default:
Serial.println(F(" UNKNOWN"));
break;
}

// Just to prove we can, call getGPIO1voltage to check the pin voltage (only valid for modes 1 and 2)
float voltage;
err = mySwarm.readGPIO1voltage(&voltage);

if (err == SWARM_M138_SUCCESS)
{
Serial.print(F("GPIO1 voltage is: "));
Serial.println(voltage, 3);
}
else
{
Serial.print(F("Swarm communication error: "));
Serial.print((int)err);
Serial.print(F(" : "));
Serial.print(mySwarm.modemErrorString(err)); // Convert the error into printable text
if (err == SWARM_M138_ERROR_ERR) // If we received a command error (ERR), print it
{
Serial.print(F(" : "));
Serial.print(mySwarm.commandError);
Serial.print(F(" : "));
Serial.println(mySwarm.commandErrorString((const char *)mySwarm.commandError));
}
else
Serial.println();
}
}

void loop()
Expand Down
16 changes: 13 additions & 3 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ setGeospatialInfoRate KEYWORD2

getGPIO1Mode KEYWORD2
setGPIO1Mode KEYWORD2
readGPIO1voltage KEYWORD2

getGpsFixQuality KEYWORD2
getGpsFixQualityRate KEYWORD2
Expand All @@ -57,6 +58,7 @@ getPowerStatus KEYWORD2
getPowerStatusRate KEYWORD2
setPowerStatusRate KEYWORD2
getTemperature KEYWORD2
getCPUvoltage KEYWORD2

restartDevice KEYWORD2

Expand All @@ -74,6 +76,7 @@ markRxMessage KEYWORD2
markAllRxMessages KEYWORD2
getMessageNotifications KEYWORD2
setMessageNotifications KEYWORD2
listMessage KEYWORD2
readMessage KEYWORD2
readOldestMessage KEYWORD2
readNewestMessage KEYWORD2
Expand All @@ -82,7 +85,7 @@ getUnsentMessageCount KEYWORD2
deleteTxMessage KEYWORD2
deleteAllTxMessages KEYWORD2
listTxMessage KEYWORD2
listTxMessagesIDs KEYWORD2
# listTxMessagesIDs KEYWORD2

transmitText KEYWORD2
transmitTextHold KEYWORD2
Expand Down Expand Up @@ -128,12 +131,18 @@ SWARM_M138_ERROR_ERR LITERAL1
SWARM_M138_SUCCESS LITERAL1

SWARM_M138_GPIO1_ANALOG LITERAL1
SWARM_M138_GPIO1_ADC LITERAL1
SWARM_M138_GPIO1_INPUT LITERAL1
SWARM_M138_GPIO1_EXIT_SLEEP_LOW_HIGH LITERAL1
SWARM_M138_GPIO1_EXIT_SLEEP_HIGH_LOW LITERAL1
SWARM_M138_GPIO1_OUTPUT_LOW LITERAL1
SWARM_M138_GPIO1_OUTPUT_HIGH LITERAL1
SWARM_M138_GPIO1_MESSAGES_PENDING_LOW LITERAL1
SWARM_M138_GPIO1_MESSAGES_PENDING_HIGH LITERAL1
SWARM_M138_GPIO1_MESSAGES_UNREAD_LOW LITERAL1
SWARM_M138_GPIO1_MESSAGES_UNREAD_HIGH LITERAL1
SWARM_M138_GPIO1_MESSAGES_UNSENT_LOW LITERAL1
SWARM_M138_GPIO1_MESSAGES_UNSENT_HIGH LITERAL1
SWARM_M138_GPIO1_MESSAGES_UNREAD_UNSENT_LOW LITERAL1
SWARM_M138_GPIO1_MESSAGES_UNREAD_UNSENT_HIGH LITERAL1
SWARM_M138_GPIO1_SLEEP_MODE_LOW LITERAL1
SWARM_M138_GPIO1_SLEEP_MODE_HIGH LITERAL1
SWARM_M138_GPIO1_INVALID LITERAL1
Expand All @@ -158,6 +167,7 @@ SWARM_M138_MODEM_STATUS_BOOT_POWERON LITERAL1
SWARM_M138_MODEM_STATUS_BOOT_RUNNING LITERAL1
SWARM_M138_MODEM_STATUS_BOOT_UPDATED LITERAL1
SWARM_M138_MODEM_STATUS_BOOT_VERSION LITERAL1
SWARM_M138_MODEM_STATUS_BOOT_DEVICEID LITERAL1
SWARM_M138_MODEM_STATUS_BOOT_RESTART LITERAL1
SWARM_M138_MODEM_STATUS_BOOT_SHUTDOWN LITERAL1
SWARM_M138_MODEM_STATUS_DATETIME 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=SparkFun Swarm Satellite Arduino Library
version=1.0.0
version=1.1.0
author=SparkFun Electronics <techsupport@sparkfun.com>
maintainer=SparkFun Electronics <sparkfun.com>
sentence=Library for the Swarm M138 satellite modem<br/><br/>
Expand Down
Loading