source: rtos_arduino/trunk/arduino_lib/libraries/GSM/src/GSM3ShieldV1DirectModemProvider.cpp@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 3.4 KB
Line 
1/*
2This file is part of the GSM3 communications library for Arduino
3-- Multi-transport communications platform
4-- Fully asynchronous
5-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
6-- Voice calls
7-- SMS
8-- TCP/IP connections
9-- HTTP basic clients
10
11This library has been developed by Telefónica Digital - PDI -
12- Physical Internet Lab, as part as its collaboration with
13Arduino and the Open Hardware Community.
14
15September-December 2012
16
17This library is free software; you can redistribute it and/or
18modify it under the terms of the GNU Lesser General Public
19License as published by the Free Software Foundation; either
20version 2.1 of the License, or (at your option) any later version.
21
22This library is distributed in the hope that it will be useful,
23but WITHOUT ANY WARRANTY; without even the implied warranty of
24MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25Lesser General Public License for more details.
26
27You should have received a copy of the GNU Lesser General Public
28License along with this library; if not, write to the Free Software
29Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
31The latest version of this library can always be found at
32https://github.com/BlueVia/Official-Arduino
33*/
34#include <GSM3ShieldV1DirectModemProvider.h>
35#include <GSM3ShieldV1ModemCore.h>
36#include <HardwareSerial.h>
37#include <Arduino.h>
38
39#define __RESETPIN__ 7
40
41//Constructor
42GSM3ShieldV1DirectModemProvider::GSM3ShieldV1DirectModemProvider(bool t)
43{
44 trace=t;
45};
46
47void GSM3ShieldV1DirectModemProvider::begin()
48{
49 theGSM3ShieldV1ModemCore.gss.begin(9600);
50}
51
52void GSM3ShieldV1DirectModemProvider::restartModem()
53{
54 pinMode(__RESETPIN__, OUTPUT);
55 digitalWrite(__RESETPIN__, HIGH);
56 delay(12000);
57 digitalWrite(__RESETPIN__, LOW);
58 delay(1000);
59
60}
61
62//To enable the debug process
63void GSM3ShieldV1DirectModemProvider::connect()
64{
65 theGSM3ShieldV1ModemCore.registerActiveProvider(this);
66}
67
68//To disable the debug process
69void GSM3ShieldV1DirectModemProvider::disconnect()
70{
71 theGSM3ShieldV1ModemCore.registerActiveProvider(0);
72}
73
74//Write to the modem by means of SoftSerial
75size_t GSM3ShieldV1DirectModemProvider::write(uint8_t c)
76{
77 theGSM3ShieldV1ModemCore.write(c);
78}
79
80//Detect if data to be read
81int/*bool*/ GSM3ShieldV1DirectModemProvider::available()
82{
83 if (theGSM3ShieldV1ModemCore.gss.cb.peek(1)) return 1;
84 else return 0;
85}
86
87//Read data
88int/*char*/ GSM3ShieldV1DirectModemProvider::read()
89{
90 int dataRead;
91 dataRead = theGSM3ShieldV1ModemCore.gss.cb.read();
92 //In case last char in xof mode.
93 if (!(theGSM3ShieldV1ModemCore.gss.cb.peek(0))) {
94 theGSM3ShieldV1ModemCore.gss.spaceAvailable();
95 delay(100);
96 }
97 return dataRead;
98}
99
100//Peek data
101int/*char*/ GSM3ShieldV1DirectModemProvider::peek()
102{
103 return theGSM3ShieldV1ModemCore.gss.cb.peek(0);
104}
105
106//Flush data
107void GSM3ShieldV1DirectModemProvider::flush()
108{
109 return theGSM3ShieldV1ModemCore.gss.cb.flush();
110}
111
112String GSM3ShieldV1DirectModemProvider::writeModemCommand(String ATcommand, int responseDelay)
113{
114
115 if(trace)
116 Serial.println(ATcommand);
117
118 // Flush other texts
119 flush();
120
121 //Enter debug mode.
122 connect();
123 //Send the AT command.
124 println(ATcommand);
125
126 delay(responseDelay);
127
128 //Get response data from modem.
129 String result = "";
130 if(trace)
131 theGSM3ShieldV1ModemCore.gss.cb.debugBuffer();
132
133 while (available())
134 {
135 char c = read();
136 result += c;
137 }
138 if(trace)
139 Serial.println(result);
140 //Leave the debug mode.
141 disconnect();
142 return result;
143}
Note: See TracBrowser for help on using the repository browser.