a library to use GPRS like ethernet or wifi, which makes it possible to connect to the internet with your GPRS module
Dependencies: BufferedSerial
Dependents: ThinkSpeak_Test roam_v1 roam_v2 finalv3
Fork of GPRSInterface by
TCPSocketConnection.cpp
00001 /* 00002 TCPSocketConnection.cpp 00003 2014 Copyright (c) Seeed Technology Inc. All right reserved. 00004 00005 Author:lawliet zou(lawliet.zou@gmail.com) 00006 2014-2-24 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #include "TCPSocketConnection.h" 00024 00025 TCPSocketConnection::TCPSocketConnection() 00026 { 00027 } 00028 00029 int TCPSocketConnection::connect(const char* host, const int port) 00030 { 00031 if (_sock_fd < 0) { 00032 _sock_fd = gprs->new_socket(); 00033 if (_sock_fd < 0) { 00034 return -1; 00035 } 00036 } 00037 00038 if (!gprs->connect(_sock_fd, TCP, host, port)) { 00039 return -1; 00040 } 00041 return 0; 00042 } 00043 00044 bool TCPSocketConnection::is_connected(void) 00045 { 00046 if (_sock_fd < 0) { 00047 return false; 00048 } 00049 return gprs->is_connected(_sock_fd); 00050 } 00051 00052 int TCPSocketConnection::send(char* data, int length) 00053 { 00054 return gprs->sock_send(_sock_fd, data, length); 00055 } 00056 00057 int TCPSocketConnection::send_all(char* data, int length) 00058 { 00059 return send(data, length); 00060 } 00061 00062 int TCPSocketConnection::receive(char* data, int length) 00063 { 00064 return gprs->sock_recv(_sock_fd, data, length); 00065 } 00066 00067 int TCPSocketConnection::receive_all(char* data, int length) 00068 { 00069 return receive(data,length); 00070 }
Generated on Tue Jul 12 2022 16:57:21 by 1.7.2