Skip to content

Conversation

boylesg
Copy link

@boylesg boylesg commented Mar 10, 2018

Removed hard coding that limits you to using SoftwareSerial for Uno and Serial1 for Mega

You can now use the classes like this:

CSIMCOM900 gsm(&Serial1);
SoftwareSerial ss(8, 9);
CSIMCOM900 gsm(&Serial1);
//CSIMCOM900 gsm(&ss);
CSMSGSM sms(gsm);

void setup()
{
gsm.begin(115200);
}

Also wrapped all the literal strings in F() and added appropriate function versions to take flash strings rather than normal c strings.

Changed to Hungarian notation.

Changed int to int16_t etc

Changed some function return types to bool

boylesg added 8 commits March 11, 2018 03:38
Removed hard coding that limits you to using SoftwareSerial for Uno and Serial1 for Mega

You can now use the classes like this:

CSIMCOM900 gsm(&Serial1);
SoftwareSerial ss(8, 9);
CSIMCOM900 gsm(&Serial1);
//CSIMCOM900 gsm(&ss);
CSMSGSM sms(gsm);

void setup()
{
    gsm.begin(115200);
}

Also wrapped all the literal strings in F() and added appropriate function versions to take flash strings rather than normal c strings.
Examples sketches modified for library changes
This upload was simply to change the commit comment because I have no idea how to edit the comment of an existing commit.

Removed hard coding that limits you to using SoftwareSerial for Uno and Serial1 for Mega

You can now use the classes like this:

CSIMCOM900 gsm(&Serial1);
SoftwareSerial ss(8, 9);
CSIMCOM900 gsm(&Serial1);
//CSIMCOM900 gsm(&ss);
CSMSGSM sms(gsm);

void setup()
{
    gsm.begin(115200);
}

Also wrapped all the literal strings in F() and added appropriate function versions to take flash strings rather than normal c strings.

Changed class, data members and variable to use Hungarian notation.

Removed commented out, and presumably no longer needed, code.

Removed deprecated function and changed example sketch accordingly.

Cleaned up code indenting to make the code easier to read.

Changed WideTextFinder to CSWSerial so as to be consistent with CHWSerial (formerly HWSerial).

If you don't want all the cosmetic code changes then the key changes to removed the hard coding are as follows:
--------------------------------------------------------------------------------------------------------------------------------------------------------
GSMBase.h/cpp
class CGSMBase
{
	public:
		CGSMBase(CSIMCOM900& rSimComm900): m_rSimComm900(rSimComm900){};
	
	protected:
		CSIMCOM900& m_rSimComm900;
};
--------------------------------------------------------------------------------------------------------------------------------------------------------
SMS.h/cpp, InetGSM.h/cpp, GPSGSM.h.cpp, call.h/cpp

class CSMSGSM: protected CGSMBase
{
	public:
		CSMSGSM(CSIMCOM900& rSimComm900): CGSMBase(rSimComm900){};
--------------------------------------------------------------------------------------------------------------------------------------------------------
class CGSM
{
	public:
			
		// Constructors
               CGSM(const SoftwareSerial *pStream): m_nStatus(IDLE)
              {
	           m_pStream = (Stream*)pStream;
	           m_nSizeofStream = sizeof *pStream;
              }

              CGSM(const HardwareSerial *pStream): m_nStatus(IDLE)
              {
	           m_pStream = (Stream*)pStream;
	           m_nSizeofStream = sizeof *pStream;
              }
.
.
.
.
.
	protected:
		// Constructors
		CGSM(); // Don't want this constructor to be used

              void beginSerial(const uint32_t nBaud)
              {
	           if (m_nSizeofStream == sizeof(HardwareSerial))
	           {
		        ((HardwareSerial*)m_pStream)->begin(nBaud);
	           }
	           else if (m_nSizeofStream == sizeof(SoftwareSerial))
	           {
		        ((SoftwareSerial*)m_pStream)->begin(nBaud);
	           }
              }
              bool isUsingSS()
              {
	           return m_nSizeofStream == sizeof(SoftwareSerial);
              }

              bool isUsingHS()
              {
	           return m_nSizeofStream == sizeof(HardwareSerial);
              }


		// Serial source used to communicate with GSM
		Stream* m_pStream;			// Either a SoftwareSerial or a HardwareSerial object passed in through the constructor.
		uint16_t m_nSizeofStream;	// Size of the the SoftwareSerial or a HardwareSerial object so we can tell which type was used.
--------------------------------------------------------------------------------------------------------------------------------------------------------
HWSerial.h/cpp, SWSerial.h/cpp

These are now created as local objects so that the default empty constructor is not used.

class CHWSerial
{
	private:
		//Don't want this constructor to be used
		CHWSerial(): _rSerial(Serial)
		{
		}; 

	public:
		CHWSerial(HardwareSerial& rSerial);
		
		
		
class CSWSerial 
{
	private:
		SoftwareSerial& m_rSoftwareSerial;

		//Don't want this constructor to be used
		CSWSerial(): _rSerial(Serial)
		{
		}; 

	public:
		// Constructor: 
		CSWSerial(SoftwareSerial &rStream, int16_t nTimeout = 5);          // Ethernet constructor
--------------------------------------------------------------------------------------------------------------------------------------------------------
SIM900.h/cpp

class CSIMCOM900 : public virtual CGSM
{
	protected:
		CSIMCOM900(): CGSM(NULL)(); // Don't want this constructor to be used

	public:
		CSIMCOM900(const SoftwareSerial *pStream): CGSM(pStream){};
		CSIMCOM900(const HardwareSerial *pStream): : CGSM(pStream){};
--------------------------------------------------------------------------------------------------------------------------------------------------------
Added flash string versions of SendSMS(...)  and changed char* to const char* to eliminate compiler warning "deprecated conversion of const char* to char*"

		int8_t SendSMS(const char *strNumber, const char *strMessage);
		int8_t SendSMS(const __FlashStringHelper *fstrNumber, const __FlashStringHelper *fstrMessage);
		int8_t SendSMS(const char *strNumber, const __FlashStringHelper *fstrMessage);
		int8_t SendSMS(const __FlashStringHelper *fstrNumber, const char *strMessage);
		int8_t SendSMS(const uint8_t nSIMBookPos, const char *strMessage);
		int8_t SendSMS(const uint8_t nSIMBookPos, const __FlashStringHelper *fstrMessage);
Modified sketch to use CSMS::GetSMS rather than deprecated (and removed) CGSM::GetSMS(...)
Removed redundant SMS and call functions - correct functions are in CCall (call.cpp/h)
Changed some for char* parameters to const char* to eliminate compiler warning "deprecated conversion of const char* to char*"
Changed function return types to bool - more appropriate according to the way they were being used.

Also altered debug output because it was incorrectly informing me in serial monitor that the sms was successfully sent.

Now outputs this: Sending "Arduino SMS" to 61414318470...failed (3)!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant