この比較の残りの部分を読み込んでいます。

Untitled diff

作成日 差分は期限切れになりません
86 削除
692 行
110 追加
690 行
/*
/*
******************************************************************************
******************************************************************************
* Copyright (c) 2015 Particle Industries, Inc. All rights reserved.
* Copyright (c) 2015 Particle Industries, Inc. All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
* version 3 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
******************************************************************************
******************************************************************************
*/
*/


#ifndef HAL_CELLULAR_EXCLUDE
#ifndef HAL_CELLULAR_EXCLUDE


/* Includes -----------------------------------------------------------------*/
/* Includes -----------------------------------------------------------------*/
#include <stdio.h>
#include <stdio.h>
#include <stdint.h>
#include <stdint.h>
#include <stdarg.h>
#include <stdarg.h>
#include <string.h>
#include <string.h>


#include "mdm_hal.h"
#include "mdm_hal.h"
#include "timer_hal.h"
#include "timer_hal.h"
#include "delay_hal.h"
#include "delay_hal.h"
#include "pinmap_hal.h"
#include "pinmap_hal.h"
#include "pinmap_impl.h"
#include "pinmap_impl.h"
#include "gpio_hal.h"
#include "gpio_hal.h"
#include "mdmapn_hal.h"
#include "mdmapn_hal.h"
#include "stm32f2xx.h"
#include "stm32f2xx.h"
#include "dns_client.h"
#include "service_debug.h"
#include "service_debug.h"
#include "bytes2hexbuf.h"
#include "hex_to_bytes.h"
#include "concurrent_hal.h"
#include "concurrent_hal.h"
#include <mutex>
#include <mutex>
#include "net_hal.h"
#include "net_hal.h"
#include <limits>
#include <limits>


std::recursive_mutex mdm_mutex;
std::recursive_mutex mdm_mutex;


/* Private typedef ----------------------------------------------------------*/
/* Private typedef ----------------------------------------------------------*/


/* Private define -----------------------------------------------------------*/
/* Private define -----------------------------------------------------------*/
/* Private macro ------------------------------------------------------------*/
/* Private macro ------------------------------------------------------------*/


#define PROFILE "0" //!< this is the psd profile used
#define PROFILE "0" //!< this is the psd profile used
#define MAX_SIZE 1024 //!< max expected messages (used with RX)
#define MAX_SIZE 1024 //!< max expected messages (used with RX)
#define USO_MAX_WRITE 1024 //!< maximum number of bytes to write to socket (used with TX)
#define USO_MAX_WRITE 1024 //!< maximum number of bytes to write to socket (used with TX)

// ID of the PDP context used to configure the default EPS bearer when registering in an LTE network
// Note: There are no PDP contexts in LTE, SARA-R4 uses this naming for the sake of simplicity
#define PDP_CONTEXT 1

// Enable hex mode for socket commands. SARA-R410M-01B has a bug which causes truncation of
// data read from a socket if the data contains a null byte
// #define SOCKET_HEX_MODE

// Timeout for socket write operations
#define SOCKET_WRITE_TIMEOUT 30000
// Timeout for +COPS command
#define COPS_TIMEOUT (3 * 60 * 1000)

// num sockets
// num sockets
#define NUMSOCKETS ((int)(sizeof(_sockets)/sizeof(*_sockets)))
#define NUMSOCKETS ((int)(sizeof(_sockets)/sizeof(*_sockets)))
//! test if it is a socket is ok to use
//! test if it is a socket is ok to use
#define ISSOCKET(s) (((s) >= 0) && ((s) < NUMSOCKETS) && (_sockets[s].handle != MDM_SOCKET_ERROR))
#define ISSOCKET(s) (((s) >= 0) && ((s) < NUMSOCKETS) && (_sockets[s].handle != MDM_SOCKET_ERROR))
//! check for timeout
//! check for timeout
#define TIMEOUT(t, ms) ((ms != TIMEOUT_BLOCKING) && ((HAL_Timer_Get_Milli_Seconds() - t) > ms))
#define TIMEOUT(t, ms) ((ms != TIMEOUT_BLOCKING) && ((HAL_Timer_Get_Milli_Seconds() - t) > ms))
//! registration ok check helper
//! registration ok check helper
#define REG_OK(r) ((r == REG_HOME) || (r == REG_ROAMING))
#define REG_OK(r) ((r == REG_HOME) || (r == REG_ROAMING))
//! registration done check helper (no need to poll further)
//! registration done check helper (no need to poll further)
#define REG_DONE(r) ((r == REG_HOME) || (r == REG_ROAMING) || (r == REG_DENIED))
#define REG_DONE(r) ((r == REG_HOME) || (r == REG_ROAMING) || (r == REG_DENIED))
//! helper to make sure that lock unlock pair is always balanced
//! helper to make sure that lock unlock pair is always balanced
#define LOCK() std::lock_guard<std::recursive_mutex> __mdm_guard(mdm_mutex);
#define LOCK() std::lock_guard<std::recursive_mutex> __mdm_guard(mdm_mutex);
//! helper to make sure that lock unlock pair is always balanced
//! helper to make sure that lock unlock pair is always balanced
#define UNLOCK()
#define UNLOCK()


static volatile uint32_t gprs_timeout_start;
static volatile uint32_t gprs_timeout_start;
static volatile uint32_t gprs_timeout_duration;
static volatile uint32_t gprs_timeout_duration;


inline void ARM_GPRS_TIMEOUT(uint32_t dur) {
inline void ARM_GPRS_TIMEOUT(uint32_t dur) {
gprs_timeout_start = HAL_Timer_Get_Milli_Seconds();
gprs_timeout_start = HAL_Timer_Get_Milli_Seconds();
gprs_timeout_duration = dur;
gprs_timeout_duration = dur;
DEBUG("GPRS WD Set %d",(dur));
DEBUG("GPRS WD Set %d",(dur));
}
}
inline bool IS_GPRS_TIMEOUT() {
inline bool IS_GPRS_TIMEOUT() {
return gprs_timeout_duration && ((HAL_Timer_Get_Milli_Seconds()-gprs_timeout_start)>gprs_timeout_duration);
return gprs_timeout_duration && ((HAL_Timer_Get_Milli_Seconds()-gprs_timeout_start)>gprs_timeout_duration);
}
}


inline void CLR_GPRS_TIMEOUT() {
inline void CLR_GPRS_TIMEOUT() {
gprs_timeout_duration = 0;
gprs_timeout_duration = 0;
DEBUG("GPRS WD Cleared, was %d", gprs_timeout_duration);
DEBUG("GPRS WD Cleared, was %d", gprs_timeout_duration);
}
}


#ifdef MDM_DEBUG
#ifdef MDM_DEBUG
#if 0 // colored terminal output using ANSI escape sequences
#if 0 // colored terminal output using ANSI escape sequences
#define COL(c) "\033[" c
#define COL(c) "\033[" c
#else
#else
#define COL(c) ""
#define COL(c) ""
#endif
#endif
#define DEF COL("39m")
#define DEF COL("39m")
#define BLA COL("30m")
#define BLA COL("30m")
#define RED COL("31m")
#define RED COL("31m")
#define GRE COL("32m")
#define GRE COL("32m")
#define YEL COL("33m")
#define YEL COL("33m")
#define BLU COL("34m")
#define BLU COL("34m")
#define MAG COL("35m")
#define MAG COL("35m")
#define CYA COL("36m")
#define CYA COL("36m")