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

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

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

File size: 4.3 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 <GSM3MobileServerService.h>
35#include <GSM3MobileServerProvider.h>
36#include <GSM3MobileClientProvider.h>
37
38
39#define __TOUTSERVER__ 10000
40#define BUFFERSIZETWEET 100
41
42#define GSM3MOBILESERVERSERVICE_SYNCH 0x01 // 1: TRUE, compatible with other clients 0: FALSE
43
44// While there is only a shield (ShieldV1) we will include it by default
45#include <GSM3ShieldV1ServerProvider.h>
46GSM3ShieldV1ServerProvider theShieldV1ServerProvider;
47
48
49GSM3MobileServerService::GSM3MobileServerService(uint8_t port, bool synch)
50{
51 mySocket=0;
52 _port=port;
53 flags = 0;
54
55 // If synchronous
56 if(synch)
57 flags |= GSM3MOBILESERVERSERVICE_SYNCH;
58}
59
60// Returns 0 if last command is still executing
61// 1 if success
62// >1 if error
63int GSM3MobileServerService::ready()
64{
65 return theGSM3MobileServerProvider->ready();
66}
67
68void GSM3MobileServerService::begin()
69{
70 if(theGSM3MobileServerProvider==0)
71 return;
72 theGSM3MobileServerProvider->connectTCPServer(_port);
73
74 if(flags & GSM3MOBILESERVERSERVICE_SYNCH)
75 waitForAnswer();
76}
77
78GSM3MobileClientService GSM3MobileServerService::available(bool synch)
79{
80 int newSocket;
81 // In case we are debugging, we'll need to force a look at the buffer
82 ready();
83
84 newSocket=theGSM3MobileServerProvider->getNewOccupiedSocketAsServer();
85
86 // Instatiate new client. If we are synch, the client is synchronous/blocking
87 GSM3MobileClientService client((uint8_t)(newSocket), (flags & GSM3MOBILESERVERSERVICE_SYNCH));
88
89 return client;
90}
91
92size_t GSM3MobileServerService::write(uint8_t c)
93{
94// Adapt to the new, lean implementation
95// theGSM3MobileServerProvider->writeSocket(c);
96 return 1;
97}
98
99void GSM3MobileServerService::beginWrite()
100{
101// Adapt to the new, lean implementation
102// theGSM3MobileServerProvider->beginWriteSocket(local1Remote0, mySocket);
103}
104
105size_t GSM3MobileServerService::write(const uint8_t* buf)
106{
107// Adapt to the new, lean implementation
108// theGSM3MobileServerProvider->writeSocket((const char*)(buf));
109 return strlen((const char*)buf);
110}
111
112size_t GSM3MobileServerService::write(const uint8_t* buf, size_t sz)
113{
114// Adapt to the new, lean implementation
115// theGSM3MobileServerProvider->writeSocket((const char*)(buf));
116}
117
118void GSM3MobileServerService::endWrite()
119{
120// Adapt to the new, lean implementation
121// theGSM3MobileServerProvider->endWriteSocket();
122}
123
124void GSM3MobileServerService::stop()
125{
126
127 // Review, should be the server?
128 theGSM3MobileClientProvider->disconnectTCP(local1Remote0, mySocket);
129 if(flags & GSM3MOBILESERVERSERVICE_SYNCH)
130 waitForAnswer();
131 theGSM3MobileClientProvider->releaseSocket(mySocket);
132 mySocket = -1;
133}
134
135
136/*int GSM3MobileServerService::getIP(char* LocalIP, int LocalIPlength)
137{
138 return theGSM3MobileServerProvider->getIP(LocalIP, LocalIPlength);
139}*/
140
141int GSM3MobileServerService::waitForAnswer()
142{
143 unsigned long m;
144 m=millis();
145 int res;
146
147 while(((millis()-m)< __TOUTSERVER__ )&&(ready()==0))
148 delay(10);
149
150 res=ready();
151
152 // If we get something different from a 1, we are having a problem
153 if(res!=1)
154 res=0;
155
156 return res;
157}
158
159
Note: See TracBrowser for help on using the repository browser.