more reliable way of disconnecting tcp connection and establishing APRS-IS connection

master
Mateusz Lubecki 2023-06-11 12:25:50 +02:00
rodzic 83526ea506
commit 9c329270bd
12 zmienionych plików z 263 dodań i 131 usunięć

Wyświetl plik

@ -14,7 +14,7 @@
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="${cross_rm} -rf" description="ParaTNC" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser" id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.827603628" name="STM32F100_ParaTNC" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.enablement=null,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.connection=null,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.image=null" parent="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug">
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="${cross_rm} -rf" description="ParaTNC" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser" id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.827603628" name="STM32F100_ParaTNC" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.enablement=null,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.image=null,org.eclipse.cdt.docker.launcher.containerbuild.property.connection=null" parent="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug">
<folderInfo id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.827603628." name="/" resourcePath="">
<toolChain id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.elf.debug.334630505" name="Cross ARM GCC" superClass="ilg.gnuarmeclipse.managedbuild.cross.toolchain.elf.debug">
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level.1849839382" name="Optimization Level" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level" useByScannerDiscovery="true" value="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level.debug" valueType="enumerated"/>
@ -170,7 +170,7 @@
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.nomoveloopinvariants.2101974172.1976488731" name="Disable loop invariant move (-fno-move-loop-invariants)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.nomoveloopinvariants.2101974172"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.name.130401718.1764267206" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.name.130401718"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.1369261238.1453667842" name="Architecture" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.1369261238"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family.1103879624.1080321056" name="ARM family" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family.1103879624"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family.1103879624.1080321056" name="Arm family (-mcpu)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family.1103879624"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset.2123591525.106687733" name="Instruction set" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset.2123591525"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.prefix.1937875134.1471866726" name="Prefix" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.prefix.1937875134"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.c.609388155.884845432" name="C compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.c.609388155"/>
@ -214,7 +214,7 @@
</toolChain>
</folderInfo>
<sourceEntries>
<entry excluding="nvm.c|aprsis.c|api.c|pwr_save.c|Timer.cpp" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
<entry excluding="button_parameteo.c|nvm.c|aprsis.c|api.c|pwr_save.c|Timer.cpp" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
<entry excluding="src/drivers/max31865.c|src/fatfs|src/gsm|src/cmsis/stm32l4xx|src/drivers/l4|src/stm32l4-hal-driver|src/dsp|src/stm32f1-stdperiph/stm32f10x_adc.c|src/stm32f1-stdperiph/stm32f10x_wwdg.c|src/drivers/tm_stm32fonewire/tm_stm32f1_onewire.c|src/stm32f1-stdperiph/stm32f10x_bkp.c|src/stm32f1-stdperiph/stm32f10x_dac.c|src/stm32f1-stdperiph/stm32f10x_can.c|src/stm32f1-stdperiph/stm32f10x_spi.c|src/stm32f1-stdperiph/stm32f10x_pwr.c|src/stm32f1-stdperiph/stm32f10x_sdio.c|src/stm32f1-stdperiph/stm32f10x_fsmc.c|src/stm32f1-stdperiph/stm32f10x_cec.c" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="system"/>
</sourceEntries>
</configuration>
@ -495,7 +495,7 @@
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="include/api"/>
<entry excluding="Timer.cpp" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
<entry excluding="button_paratnc.c|Timer.cpp" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
<entry excluding="src/newlib|src/drivers/f1|src/cmsis/vectors_stm32f10x.c|src/cmsis/system_stm32f10x.c|src/cortexm|src/stm32f1-stdperiph|src/stm32f1-stdperiph/stm32f10x_adc.c|src/stm32f1-stdperiph/stm32f10x_wwdg.c|src/drivers/tm_stm32fonewire/tm_stm32f1_onewire.c|src/stm32f1-stdperiph/stm32f10x_bkp.c|src/stm32f1-stdperiph/stm32f10x_dac.c|src/stm32f1-stdperiph/stm32f10x_can.c|src/stm32f1-stdperiph/stm32f10x_spi.c|src/stm32f1-stdperiph/stm32f10x_pwr.c|src/stm32f1-stdperiph/stm32f10x_sdio.c|src/stm32f1-stdperiph/stm32f10x_fsmc.c|src/stm32f1-stdperiph/stm32f10x_cec.c" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="system"/>
</sourceEntries>
</configuration>

Wyświetl plik

@ -2,7 +2,7 @@
<project>
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.827603628" name="STM32F100_ParaTNC">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="838199035882065652" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
@ -13,7 +13,7 @@
</configuration>
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.827603628.109360039" name="STM32L476_ParaMETEO">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="813754081161391399" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">

Wyświetl plik

@ -7,6 +7,9 @@
#include "aprsis.h"
#include "main.h"
#include "text.h"
#include "gsm/sim800c.h"
#include <stdio.h>
#include <string.h>
@ -120,12 +123,15 @@ aprsis_return_t aprsis_connect_and_login(const char * address, uint8_t address_l
int8_t retval = 0xFF;
uint8_t offset = 0;
int offset = 0;
memset(port_str, 0x00, 0x6);
snprintf(port_str, 6, "%d", port);
// result of a disconnecting from APRS-IS server
sim800_return_t disconnection_result = SIM800_UNSET;
// connecting has blocking I/O
retval = gsm_sim800_tcpip_connect(address, address_ln, port_str, 0x6, aprsis_serial_port, aprsis_gsm_modem_state);
@ -137,8 +143,12 @@ aprsis_return_t aprsis_connect_and_login(const char * address, uint8_t address_l
if (retval == 0) {
receive_buff = srl_get_rx_buffer(aprsis_serial_port);
// check if receive buffer starts from printable character and needs fast forward or not
// maybe APRS-IS put a newline before hello message
offset = text_fast_forward_to_first_printable((char*)receive_buff, srl_get_num_bytes_rxed(aprsis_serial_port));
// if hello message has been received
if (*receive_buff == '#' && *(receive_buff + 1) == ' ') {
if (offset >= 0 && (*(receive_buff + offset) == '#' && *(receive_buff + offset + 1) == ' ')) {
// send long string to server
gsm_sim800_tcpip_write((uint8_t *)aprsis_login_string, strlen(aprsis_login_string), aprsis_serial_port, aprsis_gsm_modem_state);
@ -150,12 +160,8 @@ aprsis_return_t aprsis_connect_and_login(const char * address, uint8_t address_l
aprsis_connected = 1;
// fast forward to beginning of response
for (offset = 0; offset < 8; offset++) {
if (*(receive_buff + offset) == '#') {
break;
}
}
// fast forward to the beginning of a response
offset = text_fast_forward_to_first_printable((char*)receive_buff, srl_get_num_bytes_rxed(aprsis_serial_port));
// check if authorization has been successfull
retval = strncmp(aprsis_sucessfull_login, (const char * )(receive_buff + offset), (size_t)9);
@ -180,18 +186,23 @@ aprsis_return_t aprsis_connect_and_login(const char * address, uint8_t address_l
}
else {
// if authoruzation wasn't successfull drop a connection
gsm_sim800_tcpip_close(aprsis_serial_port, aprsis_gsm_modem_state, 0);
disconnection_result = gsm_sim800_tcpip_close(aprsis_serial_port, aprsis_gsm_modem_state, 0);
}
}
}
else {
gsm_sim800_tcpip_close(aprsis_serial_port, aprsis_gsm_modem_state, 0);
disconnection_result = gsm_sim800_tcpip_close(aprsis_serial_port, aprsis_gsm_modem_state, 0);
}
}
else {
gsm_sim800_tcpip_close(aprsis_serial_port, aprsis_gsm_modem_state, 1);
disconnection_result = gsm_sim800_tcpip_close(aprsis_serial_port, aprsis_gsm_modem_state, 1);
}
}
// if a connection has been ordered to close, but there were severe errors during that
if (disconnection_result == SIM800_TCP_CLOSE_UNCERTAIN || disconnection_result == SIM800_RECEIVING_TIMEOUT) {
gsm_sim800_reset(aprsis_gsm_modem_state);
}
}
return out;

Wyświetl plik

@ -1411,8 +1411,6 @@ int main(int argc, char* argv[]){
NVIC_SystemReset();
}
gsm_sim800_poolers_one_minute(main_gsm_srl_ctx_ptr, &main_gsm_state);
//aprsis_connect_and_login_default(1);
// if (gsm_sim800_gprs_ready == 1) {
@ -1547,6 +1545,8 @@ int main(int argc, char* argv[]){
#ifdef STM32L471xx
if (main_config_data_mode->gsm == 1) {
gsm_sim800_poolers_ten_seconds(main_gsm_srl_ctx_ptr, &main_gsm_state);
packet_tx_tcp_handler();
}
#endif

Wyświetl plik

@ -271,6 +271,9 @@ void packet_tx_handler(const config_data_basic_t * const config_basic, const con
// and trigger API wx packet transmission
packet_tx_trigger_tcp |= API_TRIGGER_METEO;
}
else if (main_config_data_gsm->aprsis_enable == 1 && main_config_data_gsm->api_enable == 0) {
packet_tx_trigger_tcp |= APRSIS_TRIGGER_METEO;
}
else {
packet_tx_trigger_tcp = 0;
}

Wyświetl plik

@ -8,19 +8,26 @@
#ifndef INCLUDE_GSM_SIM800_RETURN_T_H_
#define INCLUDE_GSM_SIM800_RETURN_T_H_
/**
* Possible return values from any SIM800 GPRS module related function
*/
typedef enum sim800_return_t {
SIM800_OK = 0,
SIM800_RX_TERMINATED = 1,
SIM800_WRONG_STATE_TO_RX = 100,
SIM800_WRONG_STATE_TO_TX = 101,
SIM800_WRONG_STATE_TO_CONNECT = 102,
SIM800_ADDRESS_AND_PORT_TO_LONG = 103,
SIM800_CONNECTING_FAILED = 104,
SIM800_RECEIVING_TIMEOUT = 105,
SIM800_SEND_FAILED = 106,
SIM800_OK = 0, /**< SIM800_OK */
SIM800_RX_TERMINATED = 1, /**< SIM800_RX_TERMINATED */
SIM800_WRONG_STATE_TO_RX = 100, /**< SIM800_WRONG_STATE_TO_RX */
SIM800_WRONG_STATE_TO_TX = 101, /**< SIM800_WRONG_STATE_TO_TX */
SIM800_WRONG_STATE_TO_CONNECT = 102, /**< SIM800_WRONG_STATE_TO_CONNECT */
SIM800_WRONG_STATE_TO_CLOSE = 103, /**< SIM800_WRONG_STATE_TO_CLOSE */
SIM800_ADDRESS_AND_PORT_TO_LONG = 104, /**< SIM800_ADDRESS_AND_PORT_TO_LONG */
SIM800_CONNECTING_FAILED = 105, /**< SIM800_CONNECTING_FAILED */
SIM800_RECEIVING_TIMEOUT = 106, /**< SIM800_RECEIVING_TIMEOUT Timeout during waiting for GPRS module response, if TCP connection is established
in the transparent mode this might be also caused by no response from remote server */
SIM800_SEND_FAILED = 107, /**< SIM800_SEND_FAILED */
SIM800_TCP_CLOSE_UNCERTAIN = 108, /**< SIM800_TCP_CLOSE_UNCERTAIN */
SIM800_TCP_CLOSE_ALREADY = 109, /**< SIM800_TCP_CLOSE_ALREADY */
SIM800_UNSET = -1
SIM800_UNSET = -1 /**< SIM800_UNSET */
} sim800_return_t;

Wyświetl plik

@ -12,7 +12,7 @@
#include "gsm/sim800_state_t.h"
#include "config_data.h"
void gsm_sim800_poolers_one_minute(srl_context_t * srl_context, gsm_sim800_state_t * state);
void gsm_sim800_poolers_ten_seconds(srl_context_t * srl_context, gsm_sim800_state_t * state);
void gsm_sim800_poolers_one_second(srl_context_t * srl_context, gsm_sim800_state_t * state, const config_data_gsm_t * config);
#endif /* INCLUDE_GSM_SIM800C_POOLERS_H_ */

Wyświetl plik

@ -29,7 +29,7 @@ sim800_return_t gsm_sim800_tcpip_async_receive(srl_context_t * srl_context, gsm_
sim800_return_t gsm_sim800_tcpip_receive(uint8_t * buffer, uint16_t buffer_size, srl_context_t * srl_context, gsm_sim800_state_t * state, srl_rx_termination_callback_t rx_callback, uint32_t timeout);
sim800_return_t gsm_sim800_tcpip_async_write(uint8_t * data, uint16_t data_len, srl_context_t * srl_context, gsm_sim800_state_t * state);
sim800_return_t gsm_sim800_tcpip_write(uint8_t * data, uint16_t data_len, srl_context_t * srl_context, gsm_sim800_state_t * state);
void gsm_sim800_tcpip_close(srl_context_t * srl_context, gsm_sim800_state_t * state, uint8_t force);
sim800_return_t gsm_sim800_tcpip_close(srl_context_t * srl_context, gsm_sim800_state_t * state, uint8_t force);
void gsm_sim800_tcpip_rx_done_callback(srl_context_t * srl_context, gsm_sim800_state_t * state);
void gsm_sim800_tcpip_tx_done_callback(srl_context_t * srl_context, gsm_sim800_state_t * state);

Wyświetl plik

@ -0,0 +1,125 @@
/*
* text.h
*
* Auxiliary functions to do weird things with text strings
*
* Created on: Jun 10, 2023
* Author: mateusz
*/
#ifndef INCLUDE_TEXT_H_
#define INCLUDE_TEXT_H_
#include <stdint.h>
/**
* Replace all non printable TABs, NEWLINEs etc with a space. Stops on null terminator
* or a size of an input string
* @param str pointer to a string to be modified
* @param size its size
*/
inline static void text_replace_non_printable_with_space(char * str, uint16_t size) {
for (int i = 0; i < size; i++) {
// currently processed character
char current = *(str + i);
if (current != 0x00) {
if (current < 0x21 || current > 0x7A) {
*(str + i) = ' ';
}
}
else {
// stop processing on null terminator
break;
}
}
}
inline static void text_replace_space_with_null(char * str, uint16_t size) {
// it goes from the end of a buffer towards its begining
for (int i = size - 1; i > 0; i--) {
char current = *(str + i);
if (current == '\"') {
// also replace this with null terminator
*(str + i) = 0x00;
break;
}
if (current == 0x20) {
*(str + i) = 0x00;
}
}
}
/**
* Fast forward text string to first printable character if it not begin from it.
* NULL terminator ends processing
* @param str pointer to string to process
* @param size lenght of a text although if null terminator will be detected before
* processing will finish before reaching this size.
* @return an offset from the beginning of the text where first printable character is.
* if the text starts from printable character zero is returned.
* if null is detected before first printable character negative is returned.
*/
inline static int text_fast_forward_to_first_printable(char * str, uint16_t size) {
int out = 0;
// check if input pointer is set to something
if (str != 0) {
while (*(str + out) < 0x21 || *(str + out) > 0x7F) {
// if null terminator is detected before a printable character
if (*(str + out) == 0x00) {
out = -1;
break;
}
// the same if an end of string is reached
if (out >= size) {
out = -1;
break;
}
// move iterator forward
out++;
}
}
return out;
}
inline static int text_rewind_front_end_till_first_printable(char * str, uint16_t size) {
int out = size;
if (str != 0) {
while (*(str + out) < 0x21 || *(str + out) > 0x7F) {
// end and return if a begining of a text is reached
// and no printable character is found
if (out < 0) {
break;
}
// if null terminator is detected before a printable character
if (*(str + out) == 0x00) {
out = -1;
break;
}
// move iterator forward
out--;
}
}
return out;
}
#endif /* INCLUDE_TEXT_H_ */

Wyświetl plik

@ -18,6 +18,8 @@
#include "main.h"
#include "io.h"
#include "text.h"
#include <string.h>
#include <stdlib.h>
@ -95,47 +97,6 @@ char gsm_sim800_cellid[5] = {0, 0, 0, 0, 0};
char gsm_sim800_lac[5] = {0, 0, 0, 0, 0};
/**
* Replace all non printable TABs, NEWLINEs etc with a space. Stops on null terminator
* or a size of an input string
* @param str pointer to a string to be modified
* @param size its size
*/
inline static void gsm_sim800_replace_non_printable_with_space(char * str, int8_t size) {
for (int i = 0; i < size; i++) {
// currently processed character
char current = *(str + i);
if (current != 0x00) {
if (current < 0x21 || current > 0x7A) {
*(str + i) = ' ';
}
}
else {
// stop processing on null terminator
break;
}
}
}
inline static void gsm_sim800_replace_space_with_null(char * str, int8_t size) {
// it goes from the end of a buffer towards its begining
for (int i = size - 1; i > 0; i--) {
char current = *(str + i);
if (current == '\"') {
// also replace this with null terminator
*(str + i) = 0x00;
break;
}
if (current == 0x20) {
*(str + i) = 0x00;
}
}
}
inline static void gsm_sim800_power_off(void) {
io___cntrl_vbat_g_disable();
}
@ -777,9 +738,9 @@ void gsm_sim800_rx_done_event_handler(srl_context_t * srl_context, gsm_sim800_st
if (comparision_result == 0) {
strncpy(gsm_sim800_simcard_status_string, (const char *)(srl_context->srl_rx_buf_pointer + gsm_response_start_idx + 7), 10);
gsm_sim800_replace_non_printable_with_space(gsm_sim800_simcard_status_string, SIM_STATUS_LENGHT);
text_replace_non_printable_with_space(gsm_sim800_simcard_status_string, SIM_STATUS_LENGHT);
gsm_sim800_replace_space_with_null(gsm_sim800_simcard_status_string, SIM_STATUS_LENGHT);
text_replace_space_with_null(gsm_sim800_simcard_status_string, SIM_STATUS_LENGHT);
gsm_sim800_simcard_status = SIMCARD_READY;
}
@ -809,9 +770,9 @@ void gsm_sim800_rx_done_event_handler(srl_context_t * srl_context, gsm_sim800_st
strncpy(gsm_sim800_registered_network, (const char *)(srl_context->srl_rx_buf_pointer + gsm_response_start_idx + 12), 16);
gsm_sim800_replace_non_printable_with_space(gsm_sim800_registered_network, REGISTERED_NETWORK_LN);
text_replace_non_printable_with_space(gsm_sim800_registered_network, REGISTERED_NETWORK_LN);
gsm_sim800_replace_space_with_null(gsm_sim800_registered_network, REGISTERED_NETWORK_LN);
text_replace_space_with_null(gsm_sim800_registered_network, REGISTERED_NETWORK_LN);
}
}

Wyświetl plik

@ -16,8 +16,13 @@
uint8_t sim800_poolers_five = 3;
void gsm_sim800_poolers_one_minute(srl_context_t * srl_context, gsm_sim800_state_t * state){
void gsm_sim800_poolers_ten_seconds(srl_context_t * srl_context, gsm_sim800_state_t * state){
if ( gsm_sim800_engineering_is_enabled == 0 &&
gsm_sim800_gprs_ready == 1 &&
aprsis_connected == 0) {
aprsis_connect_and_login_default(1);
}
// gsm_sim800_tcpip_connect(TEST_IP, strlen(TEST_IP), TEST_PORT, strlen(TEST_PORT), srl_context, state);
// //gsm_sim800_engineering_enable(srl_context, state);
@ -45,12 +50,6 @@ void gsm_sim800_poolers_one_second(srl_context_t * srl_context, gsm_sim800_state
return;
}
if ( gsm_sim800_engineering_is_enabled == 0 &&
gsm_sim800_gprs_ready == 1 &&
aprsis_connected == 0) {
aprsis_connect_and_login_default(1);
}
}
}

Wyświetl plik

@ -5,6 +5,7 @@
#include "main.h"
#include "delay.h"
#include "io.h"
#include "text.h"
#include <string.h>
@ -15,12 +16,13 @@ const static char * QUOTATION_MARK = "\"\0";
const static char * NEWLINE = "\r\0";
const static char * CLOSE_TCP = "AT+CIPCLOSE\r\0";
//static const char * ESCAPE = "+++\0";
#define CLOSED_TCP_LN 8
const static char * CLOSED_TCP = "CLOSE OK\0";
#define CLOSED_ERROR_LN 5
const static char * CLOSED_ERROR = "ERROR\0";
#define CONNECT_LN 13
static const char * CONNECT = "OK\r\n\r\nCONNECT\0";
//static const char * OK = "OK\0";
#define DISCONNECTED_LN 6
static const char * DISCONNECTED = "CLOSED\0";
@ -182,7 +184,7 @@ sim800_return_t gsm_sim800_tcpip_async_receive(srl_context_t * srl_context, gsm_
}
// check if library is in state when reception could be done
if (state == SIM800_TCP_CONNECTED || gsm_sim800_tcpip_receiving == 0) {
if (*state == SIM800_TCP_CONNECTED || gsm_sim800_tcpip_receiving == 0) {
gsm_sim800_tcpip_async_receive_cbk = rx_done_callback;
@ -242,7 +244,6 @@ sim800_return_t gsm_sim800_tcpip_receive(uint8_t * buffer, uint16_t buffer_size,
}
return out;
// return waiting_result;
}
sim800_return_t gsm_sim800_tcpip_async_write(uint8_t * data, uint16_t data_len, srl_context_t * srl_context, gsm_sim800_state_t * state) {
@ -285,51 +286,33 @@ sim800_return_t gsm_sim800_tcpip_write(uint8_t * data, uint16_t data_len, srl_co
return out;
}
void gsm_sim800_tcpip_close(srl_context_t * srl_context, gsm_sim800_state_t * state, uint8_t force) {
/**
* Closes established TCP connection
* @param srl_context pointer to serial context used to communication with gprs module
* @param state
* @param force force changing internal connection state even if there
* were problems with a response to diconnection AT command.
* @return SIM800_OK connection was closed successfully
* SIM800_TCP_CLOSE_ALREADY connection has been closed in the meantime by remote server
* SIM800_TCP_CLOSE_UNCERTAIN no valid response was received from gprs module on disconnect request
* SIM800_WRONG_STATE_TO_CLOSE no connection has been
*/
sim800_return_t gsm_sim800_tcpip_close(srl_context_t * srl_context, gsm_sim800_state_t * state, uint8_t force) {
/**
* Name : srl_rx_buf_pointer
Details:0x20000828 <srl_usart3_rx_buffer> "AT+CIPCLOSE\r\r\nERROR\r\n"
*
*Name : srl_rx_buf_pointer
Details:0x20000828 <srl_usart3_rx_buffer> "AT+CIPCLOSE\r\r\nCLOSE OK"
*
*/
sim800_return_t out = SIM800_UNSET;
uint8_t receive_result = 0;
if (*state == SIM800_TCP_CONNECTED || force == 1) {
// 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);
if (*state == SIM800_TCP_CONNECTED) {
io___cntrl_gprs_dtr_low();
@ -356,11 +339,54 @@ void gsm_sim800_tcpip_close(srl_context_t * srl_context, gsm_sim800_state_t * st
// wait for it to finish
srl_wait_for_rx_completion_or_timeout(srl_context, & receive_result);
if (receive_result == SRL_OK) {
// if force is set to one ignore a result and just set the state
// to alive, assuming that connection was closed
if (force == 1) {
*state = SIM800_ALIVE;
out = SIM800_OK;
}
else {
if (receive_result == SRL_OK) {
// go back to the last character in case that they are some newlines after response
const int offset = text_rewind_front_end_till_first_printable((char*)srl_get_rx_buffer(srl_context), srl_get_num_bytes_rxed(srl_context));
int result = strncmp((char*)srl_get_rx_buffer(srl_context) + offset - CLOSED_TCP_LN, CLOSED_TCP, CLOSED_TCP_LN);
// connection was closed successfully
if (result == 0) {
out = SIM800_OK;
}
else {
// if not check if it is maybe already closed and gprs module returned ERROR
result = strncmp((char*)srl_get_rx_buffer(srl_context) + offset - CLOSED_ERROR_LN, CLOSED_ERROR, CLOSED_ERROR_LN);
if (result == 0) {
out = SIM800_TCP_CLOSE_ALREADY;
}
else {
// something weird happened
out = SIM800_TCP_CLOSE_UNCERTAIN;
}
}
*state = SIM800_ALIVE;
}
else {
// something weird happened
out = SIM800_RECEIVING_TIMEOUT;
}
}
}
else {
out = SIM800_WRONG_STATE_TO_CLOSE;
}
return out;
}
void gsm_sim800_tcpip_rx_done_callback(srl_context_t * srl_context, gsm_sim800_state_t * state) {