mirror of
https://github.com/eclipse/upm.git
synced 2025-07-04 02:41:14 +03:00
grovegprs: Initial implementation
This driver provides support for the Grove GPRS shield, V2: http://www.seeedstudio.com/wiki/GPRS_Shield_V2.0 It provides a simple interface whereby a user can send and receive commands and data from the device. It is controlled by a standardized set of "AT" commands. A full description of these commands is available here: http://www.seeedstudio.com/wiki/images/7/72/AT_Commands_v1.11.pdf Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:

committed by
Mihai Tudor Panu

parent
b0625e11f1
commit
98f400e326
5
src/grovegprs/CMakeLists.txt
Normal file
5
src/grovegprs/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
set (libname "grovegprs")
|
||||
set (libdescription "upm grove GPRS module")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
upm_module_init()
|
74
src/grovegprs/grovegprs.cxx
Normal file
74
src/grovegprs/grovegprs.cxx
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "grovegprs.h"
|
||||
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
static const int defaultDelay = 100; // max wait time for read
|
||||
|
||||
GroveGPRS::GroveGPRS(int uart) :
|
||||
m_uart(uart)
|
||||
{
|
||||
}
|
||||
|
||||
GroveGPRS::~GroveGPRS()
|
||||
{
|
||||
}
|
||||
|
||||
bool GroveGPRS::dataAvailable(unsigned int millis)
|
||||
{
|
||||
return m_uart.dataAvailable(millis);
|
||||
}
|
||||
|
||||
int GroveGPRS::readData(char *buffer, unsigned int len)
|
||||
{
|
||||
return m_uart.read(buffer, len);
|
||||
}
|
||||
|
||||
std::string GroveGPRS::readDataStr(int len)
|
||||
{
|
||||
return m_uart.readStr(len);
|
||||
}
|
||||
|
||||
int GroveGPRS::writeData(char *buffer, unsigned int len)
|
||||
{
|
||||
m_uart.flush();
|
||||
return m_uart.write(buffer, len);
|
||||
}
|
||||
|
||||
int GroveGPRS::writeDataStr(std::string data)
|
||||
{
|
||||
m_uart.flush();
|
||||
return m_uart.writeStr(data);
|
||||
}
|
||||
|
||||
mraa_result_t GroveGPRS::setBaudRate(int baud)
|
||||
{
|
||||
return m_uart.setBaudRate(baud);
|
||||
}
|
||||
|
153
src/grovegprs/grovegprs.h
Normal file
153
src/grovegprs/grovegprs.h
Normal file
@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Thanks to Adafruit for supplying a google translated version of the
|
||||
* Chinese datasheet and some clues in their code.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mraa/uart.hpp>
|
||||
|
||||
#define GROVEGPRS_DEFAULT_UART 0
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @brief Grove GPRS Module library
|
||||
* @defgroup grovegprs libupm-grovegprs
|
||||
* @ingroup seeed uart wifi
|
||||
*/
|
||||
|
||||
/**
|
||||
* @library grovegprs
|
||||
* @sensor grovegprs
|
||||
* @comname Grove GPRS Module
|
||||
* @type wifi
|
||||
* @man seeed
|
||||
* @con uart
|
||||
* @web http://www.seeedstudio.com/wiki/GPRS_Shield_V2.0
|
||||
*
|
||||
* @brief API for the Grove GPRS Module
|
||||
*
|
||||
* The driver was tested with the Grove GPRS Module, V2. It's a
|
||||
* GSM GPRS module based on the SIM900. This module uses a
|
||||
* standard 'AT' command set. See the datasheet for a full list
|
||||
* of available commands and their possible responses:
|
||||
*
|
||||
* http://www.seeedstudio.com/wiki/images/7/72/AT_Commands_v1.11.pdf
|
||||
*
|
||||
* It is connected via a UART at 19200 baud.
|
||||
*
|
||||
* @image html grovegprs.jpg
|
||||
* @snippet grovegprs.cxx Interesting
|
||||
*/
|
||||
|
||||
class GroveGPRS {
|
||||
public:
|
||||
|
||||
/**
|
||||
* GroveGPRS object constructor
|
||||
*
|
||||
* @param uart Default UART to use (0 or 1). Default is 0.
|
||||
*/
|
||||
GroveGPRS(int uart=GROVEGPRS_DEFAULT_UART);
|
||||
|
||||
/**
|
||||
* GroveGPRS object destructor
|
||||
*/
|
||||
~GroveGPRS();
|
||||
|
||||
/**
|
||||
* Checks to see if there is data available for reading
|
||||
*
|
||||
* @param millis Number of milliseconds to wait; 0 means no waiting
|
||||
* @return true if there is data available for reading
|
||||
*/
|
||||
bool dataAvailable(unsigned int millis);
|
||||
|
||||
/**
|
||||
* Reads any available data into a user-supplied buffer. Note: the
|
||||
* call blocks until data is available for reading. Use
|
||||
* dataAvailable() to determine whether there is data available
|
||||
* beforehand, to avoid blocking.
|
||||
*
|
||||
* @param buffer Buffer to hold the data read
|
||||
* @param len Length of the buffer
|
||||
* @return Number of bytes read
|
||||
*/
|
||||
int readData(char *buffer, unsigned int len);
|
||||
|
||||
/**
|
||||
* Reads any available data and returns it in a std::string. Note:
|
||||
* the call blocks until data is available for reading. Use
|
||||
* dataAvailable() to determine whether there is data available
|
||||
* beforehand, to avoid blocking.
|
||||
*
|
||||
* @param len Maximum length of the data to be returned
|
||||
* @return Number of bytes read
|
||||
*/
|
||||
std::string readDataStr(int len);
|
||||
|
||||
/**
|
||||
* Writes the data in the buffer to the device. If you are
|
||||
* writing a command, be sure to terminate it with a carriage
|
||||
* return (\r)
|
||||
*
|
||||
* @param buffer Buffer to hold the data to write
|
||||
* @param len Length of the buffer
|
||||
* @return Number of bytes written
|
||||
*/
|
||||
int writeData(char *buffer, unsigned len);
|
||||
|
||||
/**
|
||||
* Writes the std:string data to the device. If you are writing a
|
||||
* command, be sure to terminate it with a carriage return (\r)
|
||||
*
|
||||
* @param data Buffer to write to the device
|
||||
* @return Number of bytes written
|
||||
*/
|
||||
int writeDataStr(std::string data);
|
||||
|
||||
/**
|
||||
* Sets the baud rate for the device. The default is 19200.
|
||||
*
|
||||
* @param baud Desired baud rate.
|
||||
* @return true if successful
|
||||
*/
|
||||
mraa_result_t setBaudRate(int baud=19200);
|
||||
|
||||
|
||||
protected:
|
||||
mraa::Uart m_uart;
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
|
11
src/grovegprs/javaupm_grovegprs.i
Normal file
11
src/grovegprs/javaupm_grovegprs.i
Normal file
@ -0,0 +1,11 @@
|
||||
%module javaupm_grovegprs
|
||||
%include "../upm.i"
|
||||
%include "carrays.i"
|
||||
%include "std_string.i"
|
||||
|
||||
%{
|
||||
#include "grovegprs.h"
|
||||
%}
|
||||
|
||||
%include "grovegprs.h"
|
||||
%array_class(char, charArray);
|
11
src/grovegprs/jsupm_grovegprs.i
Normal file
11
src/grovegprs/jsupm_grovegprs.i
Normal file
@ -0,0 +1,11 @@
|
||||
%module jsupm_grovegprs
|
||||
%include "../upm.i"
|
||||
%include "carrays.i"
|
||||
%include "std_string.i"
|
||||
|
||||
%{
|
||||
#include "grovegprs.h"
|
||||
%}
|
||||
|
||||
%include "grovegprs.h"
|
||||
%array_class(char, charArray);
|
12
src/grovegprs/pyupm_grovegprs.i
Normal file
12
src/grovegprs/pyupm_grovegprs.i
Normal file
@ -0,0 +1,12 @@
|
||||
%module pyupm_grovegprs
|
||||
%include "../upm.i"
|
||||
%include "carrays.i"
|
||||
%include "std_string.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%{
|
||||
#include "grovegprs.h"
|
||||
%}
|
||||
%include "grovegprs.h"
|
||||
%array_class(char, charArray);
|
Reference in New Issue
Block a user