kopia lustrzana https://github.com/SP8EBC/ParaTNC
sim800 tcp and gprs
rodzic
7facd24b9d
commit
5bb7fcb978
|
@ -18,6 +18,7 @@ typedef enum gsm_sim800_state_t {
|
|||
SIM800_ALIVE,
|
||||
SIM800_ALIVE_SENDING_TO_MODEM,
|
||||
SIM800_ALIVE_WAITING_MODEM_RESP,
|
||||
SIM800_TCP_CONNECTED,
|
||||
}gsm_sim800_state_t;
|
||||
|
||||
#endif /* INCLUDE_GSM_SIM800_STATE_T_H_ */
|
||||
|
|
|
@ -29,5 +29,6 @@ uint8_t gsm_sim800_rx_terminating_callback(uint8_t current_data, const uint8_t *
|
|||
void gsm_sim800_rx_done_event_handler(srl_context_t * srl_context, gsm_sim800_state_t * state);
|
||||
void gsm_sim800_tx_done_event_handler(srl_context_t * srl_context, gsm_sim800_state_t * state);
|
||||
uint8_t gsm_sim800_get_waiting_for_command_response(void);
|
||||
uint16_t gsm_sim800_get_response_start_idx(void);
|
||||
|
||||
#endif /* INCLUDE_GSM_SIM800C_H_ */
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* sim800c_tcpip.h
|
||||
*
|
||||
* Created on: Feb 17, 2022
|
||||
* Author: mateusz
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_GSM_SIM800C_TCPIP_H_
|
||||
#define INCLUDE_GSM_SIM800C_TCPIP_H_
|
||||
|
||||
#define TEST_IP "46.21.223.230\0"
|
||||
#define TEST_PORT "14580\0"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "drivers/serial.h"
|
||||
|
||||
#include "gsm/sim800_state_t.h"
|
||||
|
||||
extern const char * TCP3;
|
||||
extern const char * TCP4;
|
||||
|
||||
uint8_t gsm_sim800_tcpip_connect(char * ip_address, uint8_t ip_address_ln, char * port, uint8_t port_ln, srl_context_t * srl_context, gsm_sim800_state_t * state);
|
||||
|
||||
#endif /* INCLUDE_GSM_SIM800C_TCPIP_H_ */
|
|
@ -9,6 +9,7 @@
|
|||
#include "gsm/sim800c_engineering.h"
|
||||
#include "gsm/sim800c_gprs.h"
|
||||
#include "gsm/sim800c_inline.h"
|
||||
#include "gsm/sim800c_tcpip.h"
|
||||
|
||||
#include "main.h"
|
||||
|
||||
|
@ -24,6 +25,8 @@ static const char * GET_PIN_STATUS = "AT+CPIN?\r\0";
|
|||
static const char * GET_REGISTERED_NETWORK = "AT+COPS?\r\0";
|
||||
extern const char * START_CONFIG_APN;
|
||||
|
||||
static const char * TRANSPARENT_MODE_ON = "AT+CIPMODE=1\r\0";
|
||||
static const char * TRANSPARENT_MODE_OFF = "AT+CIPMODE=0\r\0";
|
||||
|
||||
static const char * OK = "OK\r\n\0";
|
||||
static const char * SIGNAL_LEVEL = "+CSQ:\0";
|
||||
|
@ -216,6 +219,11 @@ uint8_t gsm_sim800_get_waiting_for_command_response(void) {
|
|||
return gsm_waiting_for_command_response;
|
||||
}
|
||||
|
||||
//gsm_response_start_idx
|
||||
uint16_t gsm_sim800_get_response_start_idx(void) {
|
||||
return gsm_response_start_idx;
|
||||
}
|
||||
|
||||
void gsm_sim800_init(gsm_sim800_state_t * state, uint8_t enable_echo) {
|
||||
|
||||
gsm_at_comm_echo = enable_echo;
|
||||
|
@ -368,6 +376,27 @@ 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 == SHUTDOWN_GPRS) {
|
||||
srl_send_data(srl_context, (const uint8_t*) TRANSPARENT_MODE_ON, SRL_MODE_ZERO, strlen(TRANSPARENT_MODE_ON), SRL_INTERNAL);
|
||||
|
||||
// wait for command completion
|
||||
srl_wait_for_tx_completion(srl_context);
|
||||
|
||||
gsm_at_command_sent_last = TRANSPARENT_MODE_ON;
|
||||
|
||||
gsm_waiting_for_command_response = 1;
|
||||
|
||||
srl_receive_data_with_callback(srl_context, gsm_sim800_rx_terminating_callback);
|
||||
|
||||
// restore default timeout
|
||||
srl_switch_timeout(srl_context, 1, SIM800_DEFAULT_TIMEOUT);
|
||||
|
||||
// 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 == TRANSPARENT_MODE_ON) {
|
||||
// create GPRS APN configuration string
|
||||
sim800_gprs_create_apn_config_str((char * )srl_context->srl_tx_buf_pointer, srl_context->srl_tx_buf_ln);
|
||||
|
||||
|
@ -497,6 +526,12 @@ uint8_t gsm_sim800_rx_terminating_callback(uint8_t current_data, const uint8_t *
|
|||
else if (gsm_at_command_sent_last == GET_CONNECTION_STATUS) {
|
||||
gsm_terminating_newline_counter = 4;
|
||||
}
|
||||
else if (gsm_at_command_sent_last == TCP3) {
|
||||
gsm_terminating_newline_counter = 3;
|
||||
}
|
||||
else if (gsm_at_command_sent_last == TCP4) {
|
||||
gsm_terminating_newline_counter = 4;
|
||||
}
|
||||
else {
|
||||
gsm_terminating_newline_counter = 4;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "gsm/sim800c_poolers.h"
|
||||
#include "gsm/sim800c_engineering.h"
|
||||
#include "gsm/sim800c_gprs.h"
|
||||
#include "gsm/sim800c_tcpip.h"
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t sim800_poolers_five = 3;
|
||||
|
@ -18,7 +19,8 @@ void gsm_sim800_poolers_one_minute(srl_context_t * srl_context, gsm_sim800_state
|
|||
|
||||
if (sim800_poolers_five == 5) {
|
||||
|
||||
gsm_sim800_engineering_enable(srl_context, state);
|
||||
gsm_sim800_tcpip_connect(TEST_IP, strlen(TEST_IP), TEST_PORT, strlen(TEST_PORT), srl_context, state);
|
||||
//gsm_sim800_engineering_enable(srl_context, state);
|
||||
|
||||
sim800_poolers_five = 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
#include "gsm/sim800c_gprs.h"
|
||||
#include "gsm/sim800c_tcpip.h"
|
||||
#include "gsm/sim800c.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static const char * CONNECT_TCP = "AT+CIPSTART=\0";
|
||||
|
||||
static const char * CONNECT = "CONNECT\0";
|
||||
static const char * OK = "OK\0";
|
||||
|
||||
const char * TCP3 = "TCP3\0";
|
||||
const char * TCP4 = "TCP4\0";
|
||||
|
||||
static char local_buffer[32];
|
||||
|
||||
uint8_t gsm_sim800_tcpip_connect(char * ip_address, uint8_t ip_address_ln, char * port, uint8_t port_ln, srl_context_t * srl_context, gsm_sim800_state_t * state) {
|
||||
// this function has blocking io
|
||||
|
||||
uint8_t out = 0;
|
||||
|
||||
uint8_t receive_result = 0xFF;
|
||||
|
||||
int comparision_result = 0;
|
||||
|
||||
if (*state != SIM800_ALIVE) {
|
||||
out = 1;
|
||||
}
|
||||
else {
|
||||
// // enable transparent mode
|
||||
// srl_send_data(srl_context, (const uint8_t*) TRANSPARENT_MODE_ON, SRL_MODE_ZERO, strlen(TRANSPARENT_MODE_ON), SRL_INTERNAL);
|
||||
//
|
||||
// gsm_at_command_sent_last = TCP3;
|
||||
//
|
||||
// // wait for transmission completion
|
||||
// srl_wait_for_tx_completion(srl_context);
|
||||
//
|
||||
// // wait for response from
|
||||
// srl_receive_data_with_callback(srl_context, gsm_sim800_rx_terminating_callback);
|
||||
//
|
||||
// // start timeout calculation
|
||||
// srl_context->srl_rx_timeout_calc_started = 1;
|
||||
//
|
||||
// // wait for modem response
|
||||
// srl_wait_for_rx_completion_or_timeout(srl_context, & receive_result);
|
||||
//
|
||||
// // check if transparent mode has been enabled
|
||||
// comparision_result = strncmp(OK, (const char *)(srl_context->srl_rx_buf_pointer + gsm_sim800_get_response_start_idx()), 2);
|
||||
//
|
||||
// if (comparision_result == 0) {
|
||||
// memset(local_buffer, 0x00, sizeof(local_buffer));
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
Ładowanie…
Reference in New Issue