Skip to content

Change to template structure #8

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 2 commits into from
Dec 4, 2023
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
Empty file removed src/sfe_lara_r6.cpp
Empty file.
8 changes: 4 additions & 4 deletions src/sfe_lara_r6.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include "sfe_ublox_cellular_voice.h"

// Base LARA-R6 class
class LARA_R6: virtual public UBX_CELL
class LARA_R6: public UBX_CELL
{

};

class LARA_R6001: public LARA_R6, public UBX_CELL_VOICE
class LARA_R6001: public LARA_R6, public UBX_CELL_VOICE<LARA_R6001>
{

};
Expand All @@ -20,7 +20,7 @@ class LARA_R6001D: public LARA_R6

};

class LARA_R6401: public LARA_R6, public UBX_CELL_VOICE
class LARA_R6401: public LARA_R6, public UBX_CELL_VOICE<LARA_R6401>
{

};
Expand All @@ -30,7 +30,7 @@ class LARA_R6401D: public LARA_R6

};

class LARA_R6801_00B: public LARA_R6, public UBX_CELL_VOICE
class LARA_R6801_00B: public LARA_R6, public UBX_CELL_VOICE<LARA_R6801_00B>
{

};
Expand Down
Empty file removed src/sfe_sara_r5.cpp
Empty file.
12 changes: 6 additions & 6 deletions src/sfe_ublox_cellular.h
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,12 @@ class UBX_CELL : public Print
UBX_CELL_error_t sendCustomCommandWithResponse(const char *command, const char *expectedResponse,
char *responseDest, unsigned long commandTimeout = UBX_CELL_STANDARD_RESPONSE_TIMEOUT, bool at = true);

// Send command with an expected (potentially partial) response, store entire response
UBX_CELL_error_t sendCommandWithResponse(const char *command, const char *expectedResponse,
char *responseDest, unsigned long commandTimeout, int destSize = minimumResponseAllocation, bool at = true);

char *ubx_cell_calloc_char(size_t num);

protected:
HardwareSerial *_hardSerial;
#ifdef UBX_CELL_SOFTWARE_SERIAL_ENABLED
Expand Down Expand Up @@ -1091,10 +1097,6 @@ class UBX_CELL : public Print
// Wait for an expected response (don't send a command)
UBX_CELL_error_t waitForResponse(const char *expectedResponse, const char *expectedError, uint16_t timeout);

// Send command with an expected (potentially partial) response, store entire response
UBX_CELL_error_t sendCommandWithResponse(const char *command, const char *expectedResponse,
char *responseDest, unsigned long commandTimeout, int destSize = minimumResponseAllocation, bool at = true);

// Send a command -- prepend AT if at is true
void sendCommand(const char *command, bool at);

Expand All @@ -1118,8 +1120,6 @@ class UBX_CELL : public Print

UBX_CELL_error_t autobaud(unsigned long desiredBaud);

char *ubx_cell_calloc_char(size_t num);

bool processURCEvent(const char *event);
void pruneBacklog(void);

Expand Down
112 changes: 0 additions & 112 deletions src/sfe_ublox_cellular_voice.cpp

This file was deleted.

120 changes: 112 additions & 8 deletions src/sfe_ublox_cellular_voice.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,120 @@ const char UBX_CELL_COMMAND_STOP_AUDIO[] = "+USAR"; // Stop audio resource
const char UBX_CELL_COMMAND_GENERATE_TONE[] = "+UTGN"; // Tone generator

// Base class for any modules supporting voice calls
class UBX_CELL_VOICE: virtual public UBX_CELL
template <typename T>
class UBX_CELL_VOICE
{
public:
UBX_CELL_error_t dial(String number);
UBX_CELL_error_t answer(void);
UBX_CELL_error_t hangUp(void);
UBX_CELL_error_t playAudioResource(uint8_t audio_resource, uint8_t tone_id, uint8_t nof_repeat);
UBX_CELL_error_t stopAudioResource(uint8_t audio_resource);
UBX_CELL_error_t generateToneFreq(uint16_t frequency, uint16_t duration, uint8_t volume);
UBX_CELL_error_t generateToneDTMF(char dtmf_character, uint16_t duration, uint8_t volume);
UBX_CELL_error_t dial(String number)
{
char *command;
char *numberCStr;
UBX_CELL_error_t err;

numberCStr = static_cast<T*>(this)->ubx_cell_calloc_char(number.length() + 1);
if (numberCStr == nullptr)
return UBX_CELL_ERROR_OUT_OF_MEMORY;
number.toCharArray(numberCStr, number.length() + 1);

command = static_cast<T*>(this)->ubx_cell_calloc_char(strlen(UBX_CELL_COMMAND_DIAL) + strlen(numberCStr) + 3);
if (command != nullptr)
{
// Heads up! The dial command is one of the only commands that requires a
// semicolon at the end of it!
sprintf(command, "%s=%s;", UBX_CELL_COMMAND_DIAL, numberCStr);

err = static_cast<T*>(this)->sendCommandWithResponse(command, UBX_CELL_RESPONSE_OK,
nullptr, UBX_CELL_10_SEC_TIMEOUT);

free(command);
}
else
{
err = UBX_CELL_ERROR_OUT_OF_MEMORY;
}

free(numberCStr);

return err;
}

UBX_CELL_error_t answer(void)
{
return static_cast<T*>(this)->sendCommandWithResponse(UBX_CELL_COMMAND_ANSWER, UBX_CELL_RESPONSE_OK_OR_ERROR,
nullptr, UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
}

UBX_CELL_error_t hangUp(void)
{
return static_cast<T*>(this)->sendCommandWithResponse(UBX_CELL_COMMAND_HANG_UP, UBX_CELL_RESPONSE_OK_OR_ERROR,
nullptr, UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
}

UBX_CELL_error_t playAudioResource(uint8_t audio_resource, uint8_t tone_id, uint8_t nof_repeat)
{
UBX_CELL_error_t err;
char *command;

command = static_cast<T*>(this)->ubx_cell_calloc_char(strlen(UBX_CELL_COMMAND_PLAY_AUDIO) + 13);
if (command == nullptr)
return UBX_CELL_ERROR_OUT_OF_MEMORY;
sprintf(command, "%s=%d,%d,%d", UBX_CELL_COMMAND_PLAY_AUDIO, audio_resource, tone_id, nof_repeat);

err = static_cast<T*>(this)->sendCommandWithResponse(command, UBX_CELL_RESPONSE_OK_OR_ERROR,
nullptr, UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
free(command);
return err;
}

UBX_CELL_error_t stopAudioResource(uint8_t audio_resource)
{
UBX_CELL_error_t err;
char *command;

command = static_cast<T*>(this)->ubx_cell_calloc_char(strlen(UBX_CELL_COMMAND_STOP_AUDIO) + 5);
if (command == nullptr)
return UBX_CELL_ERROR_OUT_OF_MEMORY;
sprintf(command, "%s=%d", UBX_CELL_COMMAND_STOP_AUDIO, audio_resource);

err = static_cast<T*>(this)->sendCommandWithResponse(command, UBX_CELL_RESPONSE_OK_OR_ERROR,
nullptr, UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
free(command);
return err;
}

UBX_CELL_error_t generateToneFreq(uint16_t frequency, uint16_t duration, uint8_t volume)
{
UBX_CELL_error_t err;
char *command;
char response[] = "\r\nOK\r\n\r\n+UUTGN: 0\r\n";

command = static_cast<T*>(this)->ubx_cell_calloc_char(strlen(UBX_CELL_COMMAND_GENERATE_TONE) + 15);
if (command == nullptr)
return UBX_CELL_ERROR_OUT_OF_MEMORY;
sprintf(command, "%s=%d,%d,%d", UBX_CELL_COMMAND_GENERATE_TONE, frequency, duration, volume);

err = static_cast<T*>(this)->sendCommandWithResponse(command, response,
nullptr, UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
free(command);
return err;
}

UBX_CELL_error_t generateToneDTMF(char dtmf_character, uint16_t duration, uint8_t volume)
{
UBX_CELL_error_t err;
char *command;
char response[] = "\r\nOK\r\n\r\n+UUTGN: 0\r\n";

command = static_cast<T*>(this)->ubx_cell_calloc_char(strlen(UBX_CELL_COMMAND_GENERATE_TONE) + 14);
if (command == nullptr)
return UBX_CELL_ERROR_OUT_OF_MEMORY;
sprintf(command, "%s=\"%c\",%d,%d", UBX_CELL_COMMAND_GENERATE_TONE, dtmf_character, duration, volume);

err = static_cast<T*>(this)->sendCommandWithResponse(command, response,
nullptr, UBX_CELL_STANDARD_RESPONSE_TIMEOUT);
free(command);
return err;
}
};

#endif