sim800, tcp, new way of disconnecting

sr9wxz_new_configuration_for_ZZ06
Mateusz Lubecki 2022-05-14 21:49:48 +02:00
rodzic c9cc5b6109
commit dbf464eb21
14 zmienionych plików z 230 dodań i 183 usunięć

Wyświetl plik

@ -15,19 +15,17 @@
#define _METEO // Enable meteo station
//#define _DIGI // Enable WIDE1-1 digipeater
//#define _DIGI_VISCOUS
//#define _DIGI_ONLY_789 // Limit digipeater to handle only -7, -8 and -9 SSIDs
//#define _VICTRON // Enable support for Victron VE.Direct protocol
#define _GSM // only for ParaMETEO
//#define _VICTRON // Enable support for Victron VE.Direct protocol
//#define _GSM // only for ParaMETEO
#define _WX_DOUBLE_TRANSMIT
/* MODES OF OPERATION */
/* ------------------ */
//#define PARATNC_HWREV_C
#define PARAMETEO
/* ---------------------------- */
/* WEATHER/METEO CONFIGURATION */
@ -130,11 +128,13 @@
#define _BCN_ON_STARTUP
#define _WX_INTERVAL 5 // WX packet interval in minutes
#define _BCN_INTERVAL 45 // Own beacon interval in minutes
#define _BCN_INTERVAL 125 // Own beacon interval in minutes
#define _PTT_PUSHPULL // Uncomment this if you want PTT line to work as Push-pull instead of Open Drain
#define _SERIAL_BAUDRATE 9600
#define _DIGI_VISCOUS_DEALY 2
// Transmitting delay
#define _DELAY_BASE 20 // * 50ms. For example setting 10 gives 500msec delay. Maximum value is 20
//#define _RANDOM_DELAY // adds random delay TO fixed time set by _DELAY_BASE. This additional time can be
@ -271,13 +271,6 @@
//#define _DIGI
//#endif
#if defined(PARATNC_HWREV_A) && (defined (_METEO) || defined (_DALLAS_AS_TELEM)) && !defined(_DALLAS_SPLIT_PIN)
#define _DALLAS_SPLIT_PIN
#endif
#if defined(PARATNC_HWREV_B) && (defined (_METEO) || defined (_DALLAS_AS_TELEM)) && !defined(_DALLAS_SPLIT_PIN)
#define _DALLAS_SPLIT_PIN
#endif
#if defined(_ANEMOMETER_TX20) && defined(_ANEMOMETER_ANALOGUE)
#error "You cannot use two anemometers at once!!!"

Wyświetl plik

@ -1,23 +0,0 @@
/*
* station_config_target_hw.h
*
* Created on: May 30, 2021
* Author: mateusz
*/
#ifndef STATION_CONFIG_TARGET_HW_H_
#define STATION_CONFIG_TARGET_HW_H_
//#define PARATNC_HWREV_A
//#define PARATNC_HWREV_B
//#define PARATNC_HWREV_C
#define PARAMETEO
#ifdef PARAMETEO
// those defines and an undef are only required for shitty Eclipse indexer to see anything from STM32L471xx target
#define STM32L471xx
#define USE_FULL_LL_DRIVER
#undef STM32F10X_MD_VL
#endif
#endif /* STATION_CONFIG_TARGET_HW_H_ */

Wyświetl plik

@ -11,14 +11,17 @@
#include "stdint.h"
#include "main.h"
extern volatile uint16_t delay_cnt;
extern volatile int32_t delay_cnt;
void delay_set(uint16_t delay_in_msecs, uint8_t randomize);
void delay_fixed(uint16_t delay_in_msecs);
uint32_t delay_fixed_with_count(uint16_t delay_in_msecs);
void delay_fixed(int32_t delay_in_msecs);
uint32_t delay_fixed_with_count(int32_t delay_in_msecs);
void delay_from_preset(void);
void delay_random(void);
void delay_stop();
void delay_start();
inline void delay_decrement_counter(void) {
if (delay_cnt > 0)
delay_cnt -= SYSTICK_TICKS_PERIOD;

Wyświetl plik

@ -21,6 +21,8 @@
#include <stm32l4xx.h>
#endif
void io_uart_init(void);
void io_oc_init(void);
void io_oc_output_low(void);
void io_oc_output_hiz(void);
@ -124,6 +126,14 @@ inline void io___cntrl_gprs_pwrkey_release() {
}
inline void io___cntrl_gprs_dtr_low() {
GPIOB->BSRR |= GPIO_BSRR_BR8;
}
inline void io___cntrl_gprs_dtr_high() {
GPIOB->BSRR |= GPIO_BSRR_BS8;
}
inline uint8_t io_get_cntrl_vbat_c(void) {
uint8_t out = 0;

Wyświetl plik

@ -7,8 +7,8 @@
#include "drivers/serial.h"
#include "config_data.h"
#define SW_VER "EA05"
#define SW_DATE "09052022"
#define SW_VER "EA06"
#define SW_DATE "14052022"
#define SYSTICK_TICKS_PER_SECONDS 100
#define SYSTICK_TICKS_PERIOD 10

Wyświetl plik

@ -7,13 +7,13 @@
#include "main.h"
uint16_t preset_delay_msecs = 0;
int32_t preset_delay_msecs = 0;
uint8_t preset_use_random = 0;
// counter decrement in Systick handler
volatile uint16_t delay_cnt = 0;
volatile int32_t delay_cnt = 0;
void delay_fixed(uint16_t delay_in_msecs) {
void delay_fixed(int32_t delay_in_msecs) {
delay_cnt = delay_in_msecs;
@ -23,7 +23,7 @@ void delay_fixed(uint16_t delay_in_msecs) {
}
uint32_t delay_fixed_with_count(uint16_t delay_in_msecs) {
uint32_t delay_fixed_with_count(int32_t delay_in_msecs) {
uint32_t ret = 0;
@ -41,7 +41,7 @@ void delay_random(void) {
uint16_t sample = main_get_adc_sample();
// random element of delay value could vary from 0 to 300msecs in 20msec steps
delay_cnt = (uint16_t)(preset_delay_msecs / 4) + (sample % 15) * 20;
delay_cnt = (int32_t)(preset_delay_msecs / 4) + (sample % 15) * 20;
}
@ -60,11 +60,12 @@ void delay_from_preset(void) {
delay_cnt = preset_delay_msecs;
while(delay_cnt > (uint16_t)0);
while(delay_cnt > (int32_t)0);
if (preset_use_random == 1) {
delay_random();
}
}

Wyświetl plik

@ -35,6 +35,101 @@ static uint8_t io_vbatt_history_it = 0;
#define MINIMUM_SENSEFUL_VBATT_VOLTAGE 512u
#endif
void io_uart_init(void) {
#if defined(STM32F10X_MD_VL)
// Configure I/O pins for USART1 (Kiss modem)
Configure_GPIO(GPIOA,10,PUD_INPUT); // RX
Configure_GPIO(GPIOA,9,AFPP_OUTPUT_2MHZ); // TX
// Configure I/O pins for USART2 (wx meteo comm)
Configure_GPIO(GPIOA,3,PUD_INPUT); // RX
Configure_GPIO(GPIOA,2,AFPP_OUTPUT_2MHZ); // TX
#endif
#if defined(STM32F10X_MD_VL)
Configure_GPIO(GPIOA,8,GPPP_OUTPUT_2MHZ); // re/te
GPIO_ResetBits(GPIOA, GPIO_Pin_8);
#endif
#if defined(STM32L471xx)
// USART1 - KISS
GPIO_InitTypeDef.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitTypeDef.Pin = LL_GPIO_PIN_10;
GPIO_InitTypeDef.Pull = LL_GPIO_PULL_NO;
GPIO_InitTypeDef.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitTypeDef.Alternate = LL_GPIO_AF_7;
GPIO_InitTypeDef.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOA, &GPIO_InitTypeDef); // RX
GPIO_InitTypeDef.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitTypeDef.Pin = LL_GPIO_PIN_9;
GPIO_InitTypeDef.Pull = LL_GPIO_PULL_NO;
GPIO_InitTypeDef.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitTypeDef.Alternate = LL_GPIO_AF_7;
GPIO_InitTypeDef.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOA, &GPIO_InitTypeDef); // TX
// USART2 - METEO
GPIO_InitTypeDef.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitTypeDef.Pin = LL_GPIO_PIN_3;
GPIO_InitTypeDef.Pull = LL_GPIO_PULL_NO;
GPIO_InitTypeDef.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitTypeDef.Alternate = LL_GPIO_AF_7;
GPIO_InitTypeDef.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOA, &GPIO_InitTypeDef); // RX
GPIO_InitTypeDef.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitTypeDef.Pin = LL_GPIO_PIN_2;
GPIO_InitTypeDef.Pull = LL_GPIO_PULL_NO;
GPIO_InitTypeDef.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitTypeDef.Alternate = LL_GPIO_AF_7;
GPIO_InitTypeDef.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOA, &GPIO_InitTypeDef); // TX
// USART3 - GSM
GPIO_InitTypeDef.Mode = LL_GPIO_MODE_ALTERNATE; // LL_GPIO_MODE_ALTERNATE
GPIO_InitTypeDef.Pin = LL_GPIO_PIN_10;
GPIO_InitTypeDef.Pull = LL_GPIO_PULL_NO;
GPIO_InitTypeDef.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitTypeDef.Alternate = LL_GPIO_AF_7;
GPIO_InitTypeDef.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOB, &GPIO_InitTypeDef); // TX
GPIO_InitTypeDef.Mode = LL_GPIO_MODE_ALTERNATE; // LL_GPIO_MODE_ALTERNATE
GPIO_InitTypeDef.Pin = LL_GPIO_PIN_11;
GPIO_InitTypeDef.Pull = LL_GPIO_PULL_NO;
GPIO_InitTypeDef.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitTypeDef.Alternate = LL_GPIO_AF_7;
GPIO_InitTypeDef.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOB, &GPIO_InitTypeDef); // RX
#endif
#if defined(STM32L471xx)
GPIO_InitTypeDef.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitTypeDef.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitTypeDef.Pin = LL_GPIO_PIN_2;
GPIO_InitTypeDef.Pull = LL_GPIO_PULL_NO;
GPIO_InitTypeDef.Speed = LL_GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitTypeDef.Alternate = LL_GPIO_AF_7;
LL_GPIO_Init(GPIOA, &GPIO_InitTypeDef); // RE-TE
GPIO_InitTypeDef.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitTypeDef.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitTypeDef.Pin = LL_GPIO_PIN_8;
GPIO_InitTypeDef.Pull = LL_GPIO_PULL_NO;
GPIO_InitTypeDef.Speed = LL_GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitTypeDef.Alternate = LL_GPIO_AF_7;
LL_GPIO_Init(GPIOB, &GPIO_InitTypeDef); // DTR = Disconnect
io___cntrl_gprs_dtr_high();
#endif
}
void io_oc_init(void) {
#ifdef STM32F10X_MD_VL
GPIO_InitTypeDef GPIO_InitStructure;

Wyświetl plik

@ -177,8 +177,9 @@ void I2C1_ER_IRQHandler(void) {
void TIM2_IRQHandler( void ) {
TIM2->SR &= ~(1<<0);
if (delay_5us > 0)
if (delay_5us > 0) {
delay_5us--;
}
}

Wyświetl plik

@ -546,86 +546,8 @@ int main(int argc, char* argv[]){
// waiting for 1 second to count number of ticks when the CPU is idle
main_idle_cpu_ticks = delay_fixed_with_count(1000);
#if defined(STM32F10X_MD_VL)
// Configure I/O pins for USART1 (Kiss modem)
Configure_GPIO(GPIOA,10,PUD_INPUT); // RX
Configure_GPIO(GPIOA,9,AFPP_OUTPUT_2MHZ); // TX
// Configure I/O pins for USART2 (wx meteo comm)
Configure_GPIO(GPIOA,3,PUD_INPUT); // RX
Configure_GPIO(GPIOA,2,AFPP_OUTPUT_2MHZ); // TX
#endif
#if defined(STM32L471xx)
// USART1 - KISS
GPIO_InitTypeDef.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitTypeDef.Pin = LL_GPIO_PIN_10;
GPIO_InitTypeDef.Pull = LL_GPIO_PULL_NO;
GPIO_InitTypeDef.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitTypeDef.Alternate = LL_GPIO_AF_7;
GPIO_InitTypeDef.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOA, &GPIO_InitTypeDef); // RX
GPIO_InitTypeDef.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitTypeDef.Pin = LL_GPIO_PIN_9;
GPIO_InitTypeDef.Pull = LL_GPIO_PULL_NO;
GPIO_InitTypeDef.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitTypeDef.Alternate = LL_GPIO_AF_7;
GPIO_InitTypeDef.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOA, &GPIO_InitTypeDef); // TX
// USART2 - METEO
GPIO_InitTypeDef.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitTypeDef.Pin = LL_GPIO_PIN_3;
GPIO_InitTypeDef.Pull = LL_GPIO_PULL_NO;
GPIO_InitTypeDef.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitTypeDef.Alternate = LL_GPIO_AF_7;
GPIO_InitTypeDef.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOA, &GPIO_InitTypeDef); // RX
GPIO_InitTypeDef.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitTypeDef.Pin = LL_GPIO_PIN_2;
GPIO_InitTypeDef.Pull = LL_GPIO_PULL_NO;
GPIO_InitTypeDef.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitTypeDef.Alternate = LL_GPIO_AF_7;
GPIO_InitTypeDef.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOA, &GPIO_InitTypeDef); // TX
// USART3 - GSM
GPIO_InitTypeDef.Mode = LL_GPIO_MODE_ALTERNATE; // LL_GPIO_MODE_ALTERNATE
GPIO_InitTypeDef.Pin = LL_GPIO_PIN_10;
GPIO_InitTypeDef.Pull = LL_GPIO_PULL_NO;
GPIO_InitTypeDef.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitTypeDef.Alternate = LL_GPIO_AF_7;
GPIO_InitTypeDef.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOB, &GPIO_InitTypeDef); // TX
GPIO_InitTypeDef.Mode = LL_GPIO_MODE_ALTERNATE; // LL_GPIO_MODE_ALTERNATE
GPIO_InitTypeDef.Pin = LL_GPIO_PIN_11;
GPIO_InitTypeDef.Pull = LL_GPIO_PULL_NO;
GPIO_InitTypeDef.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitTypeDef.Alternate = LL_GPIO_AF_7;
GPIO_InitTypeDef.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOB, &GPIO_InitTypeDef); // RX
#endif
#if defined(STM32F10X_MD_VL)
Configure_GPIO(GPIOA,8,GPPP_OUTPUT_2MHZ); // re/te
GPIO_ResetBits(GPIOA, GPIO_Pin_8);
#endif
#if defined(STM32L471xx)
GPIO_InitTypeDef.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitTypeDef.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitTypeDef.Pin = LL_GPIO_PIN_2;
GPIO_InitTypeDef.Pull = LL_GPIO_PULL_NO;
GPIO_InitTypeDef.Speed = LL_GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitTypeDef.Alternate = LL_GPIO_AF_7;
LL_GPIO_Init(GPIOA, &GPIO_InitTypeDef); // RE-TE
#endif
// initializing UART gpio pins
io_uart_init();
#if defined(STM32F10X_MD_VL)
// enabling the clock for both USARTs

Wyświetl plik

@ -20,6 +20,7 @@ extern const char * ENABLE_EDGE;
extern const char * START_GPRS;
extern const char * GET_IP_ADDRESS;
extern const char * GET_CONNECTION_STATUS;
extern const char * CONFIGURE_DTR;
extern int8_t gsm_sim800_gprs_ready;

Wyświetl plik

@ -25,6 +25,25 @@ volatile char timm = 0;
dallas_struct_t dallas;
static void dallas_delay_stop(void) {
TIM2->CR1 &= (0xFFFFFFFF ^ TIM_CR1_CEN);
NVIC_DisableIRQ( TIM2_IRQn );
}
static void dallas_delay_start(void) {
TIM2->CR1 &= (0xFFFFFFFF ^ TIM_CR1_CEN);
NVIC_SetPriority(TIM2_IRQn, 1);
TIM2->PSC = 0;
TIM2->ARR = 119;
TIM2->CR1 |= TIM_CR1_DIR;
TIM2->CR1 &= (0xFFFFFFFF ^ TIM_CR1_DIR);
TIM2->CR1 |= TIM_CR1_CEN;
TIM2->DIER |= 1;
NVIC_EnableIRQ( TIM2_IRQn ); // enabling in case that it wasn't been enabled earlier
}
void dallas_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint16_t GPIO_PinSource, dallas_average_t* average) {
#ifdef STM32F10X_MD_VL
@ -88,14 +107,9 @@ void dallas_config_timer(void) {
NVIC_DisableIRQ( TIM7_IRQn ); // data transmission initializer
//NVIC_DisableIRQ( 25 ); // TODO: probably remainder of TX20 driver to be deleted
NVIC_SetPriority(TIM2_IRQn, 1);
TIM2->PSC = 0;
TIM2->ARR = 119;
TIM2->CR1 |= TIM_CR1_DIR;
TIM2->CR1 &= (0xFFFFFFFF ^ TIM_CR1_DIR);
TIM2->CR1 |= TIM_CR1_CEN;
TIM2->DIER |= 1;
NVIC_EnableIRQ( TIM2_IRQn ); // enabling in case that it weren't been enabled earlier
dallas_delay_start();
//timm = 1;
}
@ -107,14 +121,7 @@ void dallas_deconfig_timer(void) {
NVIC_EnableIRQ( TIM7_IRQn ); // data transmission initializer
//NVIC_EnableIRQ( 25 ); // TODO: probably remainder of TX20 driver to be deleted
// reverting back to APRS timings
//NVIC_SetPriority(TIM4_IRQn, 1);
//TIM4->PSC = 0;
//TIM4->ARR = 2499;
//TIM4->CR1 |= TIM_CR1_DIR;
//TIM4->CR1 &= (0xFFFFFFFF ^ TIM_CR1_DIR);
//TIM4->DIER |= 1;
// NVIC_EnableIRQ( TIM4_IRQn );
dallas_delay_stop();
//timm = 0;
}

Wyświetl plik

@ -456,6 +456,29 @@ void gsm_sim800_initialization_pool(srl_context_t * srl_context, gsm_sim800_stat
gsm_time_of_last_command_send_to_module = main_get_master_time();
}
else if (gsm_at_command_sent_last == TRANSPARENT_MODE_ON) {
srl_send_data(srl_context, (const uint8_t*) CONFIGURE_DTR, SRL_MODE_ZERO, strlen(CONFIGURE_DTR), SRL_INTERNAL);
// wait for command completion
srl_wait_for_tx_completion(srl_context);
gsm_at_command_sent_last = CONFIGURE_DTR;
gsm_waiting_for_command_response = 1;
srl_receive_data_with_callback(srl_context, gsm_sim800_rx_terminating_callback);
// starting GPRS session has maximum response time of 65 seconds
srl_switch_timeout(srl_context, 1, 1000); // TODO
// start timeout calculation
srl_context->srl_rx_timeout_calc_started = 1;
// record when the command has been sent
gsm_time_of_last_command_send_to_module = main_get_master_time();
}
else if (gsm_at_command_sent_last == CONFIGURE_DTR) {
// create GPRS APN configuration string
sim800_gprs_create_apn_config_str((char * )srl_context->srl_tx_buf_pointer, srl_context->srl_tx_buf_ln);

Wyświetl plik

@ -15,6 +15,7 @@ const char * ENABLE_EDGE = "AT+CEGPRS=1,10\r\0";
const char * START_GPRS = "AT+CIICR\r\0";
const char * GET_IP_ADDRESS = "AT+CIFSR\r\0";
const char * GET_CONNECTION_STATUS = "AT+CIPSTATUS\r\0";
const char * CONFIGURE_DTR = "AT&D1\r\0";
static const char * OK = "OK\r\n\0";
@ -121,6 +122,9 @@ void sim800_gprs_response_callback(srl_context_t * srl_context, gsm_sim800_state
gsm_sim800_replace_non_printable_with_space(gsm_sim800_ip_address);
}
else if (gsm_at_command_sent_last == CONFIGURE_DTR) {
comparision_result = strncmp(OK, (const char *)(srl_context->srl_rx_buf_pointer + gsm_response_start_idx), 2);
}
else if (gsm_at_command_sent_last == GET_CONNECTION_STATUS ) {
memset(gsm_sim800_connection_status_str, 0x00, 24);
@ -162,6 +166,7 @@ void sim800_gprs_response_callback(srl_context_t * srl_context, gsm_sim800_state
comparision_result = strncmp(OK, (const char *)(srl_context->srl_rx_buf_pointer + gsm_response_start_idx), 2);
}
// check if modem response is the same with what the library actualy expects to get
if (comparision_result != 0) {
*state = SIM800_NOT_YET_COMM; // if not reset the state to start reinitializing

Wyświetl plik

@ -4,6 +4,7 @@
#include "main.h"
#include "delay.h"
#include "io.h"
#include <string.h>
@ -229,51 +230,59 @@ void gsm_sim800_tcpip_close(srl_context_t * srl_context, gsm_sim800_state_t * st
uint8_t receive_result = 0;
volatile uint8_t escape_counter = 0;
if (*state == SIM800_TCP_CONNECTED || force == 1) {
do {
// set default timeout of 1200msec
srl_switch_timeout(srl_context, SRL_TIMEOUT_ENABLE, 2222);
// do {
// // set default timeout of 1200msec
// srl_switch_timeout(srl_context, SRL_TIMEOUT_ENABLE, 2222);
//
// // send escape sequence to exit connection mode
// srl_send_data(srl_context, (const uint8_t*) ESCAPE, SRL_MODE_ZERO, strlen(ESCAPE), SRL_INTERNAL);
//
// // wait for transmission to finish
// srl_wait_for_tx_completion(srl_context);
//
// // wait for OK to be received
// srl_receive_data(srl_context, 4, SRL_NO_START_CHR, SRL_NO_STOP_CHR, SRL_ECHO_DISABLE, 0x7F, 0);
//
// // start timeout calculation
// srl_switch_timeout_for_waiting(srl_context, SRL_TIMEOUT_ENABLE);
//
// // wait for it to finish
// srl_wait_for_rx_completion_or_timeout(srl_context, & receive_result);
//
// // check if we escaped from data mode
// if (strncmp((const char *) (srl_context->srl_rx_buf_pointer), NEWLINE, 1) == 0) {
// break;
// }
// else if (strncmp((const char *) (srl_context->srl_rx_buf_pointer), OK, 2) == 0) {
// break;
// }
// else if (strncmp((const char *) (srl_context->srl_rx_buf_pointer), ESCAPE, 3) == 0) {
// // if module has already returned to command mode it will echo all input
// break;
// }
// else {
// if (receive_result == SRL_OK) {
// delay_fixed(200);
//
// }
// }
//
//
// } while(escape_counter++ < 3);
// send escape sequence to exit connection mode
srl_send_data(srl_context, (const uint8_t*) ESCAPE, SRL_MODE_ZERO, strlen(ESCAPE), SRL_INTERNAL);
io___cntrl_gprs_dtr_low();
// wait for transmission to finish
srl_wait_for_tx_completion(srl_context);
// one second delay
delay_fixed(500);
// wait for OK to be received
srl_receive_data(srl_context, 4, SRL_NO_START_CHR, SRL_NO_STOP_CHR, SRL_ECHO_DISABLE, 0x7F, 0);
// release DTR
io___cntrl_gprs_dtr_high();
// start timeout calculation
srl_switch_timeout_for_waiting(srl_context, SRL_TIMEOUT_ENABLE);
delay_fixed(500);
// wait for it to finish
srl_wait_for_rx_completion_or_timeout(srl_context, & receive_result);
// check if we escaped from data mode
if (strncmp((const char *) (srl_context->srl_rx_buf_pointer), NEWLINE, 1) == 0) {
break;
}
else if (strncmp((const char *) (srl_context->srl_rx_buf_pointer), OK, 2) == 0) {
break;
}
else if (strncmp((const char *) (srl_context->srl_rx_buf_pointer), ESCAPE, 3) == 0) {
// if module has already returned to command mode it will echo all input
break;
}
else {
if (receive_result == SRL_OK) {
delay_fixed(200);
}
}
} while(escape_counter++ < 3);
// send escape sequence to exit connection mode
// send tcp close command
srl_send_data(srl_context, (const uint8_t*) CLOSE_TCP, SRL_MODE_ZERO, strlen(CLOSE_TCP), SRL_INTERNAL);
// wait for transmission to finish