kopia lustrzana https://github.com/SP8EBC/ParaTNC
sim800 initializing gprs and checking status
rodzic
01f9f33aab
commit
18cd4a2c01
|
@ -20,6 +20,18 @@ extern float gsm_sim800_bcch_frequency;
|
|||
extern char gsm_sim800_cellid[5];
|
||||
extern char gsm_sim800_lac[5];
|
||||
|
||||
inline void replace_non_printable_with_space(char * str) {
|
||||
for (int i = 0; *(str + i) != 0 ; i++) {
|
||||
char current = *(str + i);
|
||||
|
||||
if (current != 0x00) {
|
||||
if (current < 0x21 || current > 0x7A) {
|
||||
*(str + i) = ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gsm_sim800_init(gsm_sim800_state_t * state, uint8_t enable_echo);
|
||||
|
||||
void gsm_sim800_initialization_pool(srl_context_t * srl_context, gsm_sim800_state_t * state);
|
||||
|
|
|
@ -16,7 +16,10 @@
|
|||
extern const char * START_CONFIG_APN;
|
||||
extern const char * SHUTDOWN_GPRS;
|
||||
extern const char * SHUTDOWN_GRPS_RESPONSE;
|
||||
|
||||
extern const char * ENABLE_EDGE;
|
||||
extern const char * START_GPRS;
|
||||
extern const char * GET_IP_ADDRESS;
|
||||
extern const char * GET_CONNECTION_STATUS;
|
||||
|
||||
extern int8_t gsm_sim800_gprs_ready;
|
||||
|
||||
|
|
|
@ -63,18 +63,6 @@ char gsm_sim800_cellid[5] = {0, 0, 0, 0, 0};
|
|||
char gsm_sim800_lac[5] = {0, 0, 0, 0, 0};
|
||||
|
||||
|
||||
static void replace_non_printable_with_space(char * str) {
|
||||
for (int i = 0; *(str + i) != 0 ; i++) {
|
||||
char current = *(str + i);
|
||||
|
||||
if (current != 0x00) {
|
||||
if (current < 0x21 || current > 0x7A) {
|
||||
*(str + i) = ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t gsm_sim800_get_waiting_for_command_response(void) {
|
||||
return gsm_waiting_for_command_response;
|
||||
}
|
||||
|
@ -114,6 +102,8 @@ void gsm_sim800_initialization_pool(srl_context_t * srl_context, gsm_sim800_stat
|
|||
|
||||
// record when the handshake has been sent
|
||||
gsm_time_of_last_command_send_to_module = main_get_master_time();
|
||||
|
||||
gsm_at_command_sent_last = 0;
|
||||
}
|
||||
else if (*state == SIM800_INITIALIZING && gsm_waiting_for_command_response == 0) {
|
||||
|
||||
|
@ -243,8 +233,95 @@ void gsm_sim800_initialization_pool(srl_context_t * srl_context, gsm_sim800_stat
|
|||
|
||||
gsm_waiting_for_command_response = 1;
|
||||
|
||||
// 'AT+CIICR' has maximum response time of 85 seconds
|
||||
srl_switch_timeout(srl_context, 1, 85000);
|
||||
srl_receive_data_with_callback(srl_context, gsm_sim800_rx_terminating_callback);
|
||||
|
||||
srl_switch_timeout(srl_context, 1, 0);
|
||||
|
||||
// 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 == START_CONFIG_APN) {
|
||||
|
||||
srl_send_data(srl_context, (const uint8_t*) START_GPRS, SRL_MODE_ZERO, strlen(START_GPRS), SRL_INTERNAL);
|
||||
|
||||
// wait for command completion
|
||||
srl_wait_for_tx_completion(srl_context);
|
||||
|
||||
gsm_at_command_sent_last = START_GPRS;
|
||||
|
||||
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, 15000); // 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 == START_GPRS) {
|
||||
|
||||
srl_send_data(srl_context, (const uint8_t*) GET_IP_ADDRESS, SRL_MODE_ZERO, strlen(GET_IP_ADDRESS), SRL_INTERNAL);
|
||||
|
||||
// wait for command completion
|
||||
srl_wait_for_tx_completion(srl_context);
|
||||
|
||||
gsm_at_command_sent_last = GET_IP_ADDRESS;
|
||||
|
||||
gsm_waiting_for_command_response = 1;
|
||||
|
||||
srl_receive_data_with_callback(srl_context, gsm_sim800_rx_terminating_callback);
|
||||
|
||||
// reverting back to default timeout
|
||||
srl_switch_timeout(srl_context, 1, 0);
|
||||
|
||||
// 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();
|
||||
|
||||
// srl_send_data(srl_context, (const uint8_t*) ENABLE_EDGE, SRL_MODE_ZERO, strlen(ENABLE_EDGE), SRL_INTERNAL);
|
||||
//
|
||||
// // wait for command completion
|
||||
// srl_wait_for_tx_completion(srl_context);
|
||||
//
|
||||
// gsm_at_command_sent_last = ENABLE_EDGE;
|
||||
//
|
||||
// gsm_waiting_for_command_response = 1;
|
||||
//
|
||||
// srl_receive_data_with_callback(srl_context, gsm_sim800_rx_terminating_callback);
|
||||
//
|
||||
// // this command has standard response time
|
||||
// srl_switch_timeout(srl_context, 1, 0);
|
||||
//
|
||||
// // 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 == GET_IP_ADDRESS) {
|
||||
srl_send_data(srl_context, (const uint8_t*) GET_CONNECTION_STATUS, SRL_MODE_ZERO, strlen(GET_CONNECTION_STATUS), SRL_INTERNAL);
|
||||
|
||||
// wait for command completion
|
||||
srl_wait_for_tx_completion(srl_context);
|
||||
|
||||
gsm_at_command_sent_last = GET_CONNECTION_STATUS;
|
||||
|
||||
gsm_waiting_for_command_response = 1;
|
||||
|
||||
srl_receive_data_with_callback(srl_context, gsm_sim800_rx_terminating_callback);
|
||||
|
||||
// reverting back to default timeout
|
||||
srl_switch_timeout(srl_context, 1, 0);
|
||||
|
||||
// start timeout calculation
|
||||
srl_context->srl_rx_timeout_calc_started = 1;
|
||||
|
@ -271,6 +348,10 @@ uint8_t gsm_sim800_rx_terminating_callback(uint8_t current_data, const uint8_t *
|
|||
terminating_newline_counter = 4;
|
||||
}
|
||||
|
||||
if (gsm_at_command_sent_last == GET_CONNECTION_STATUS) {
|
||||
terminating_newline_counter = 3;
|
||||
}
|
||||
|
||||
if (rx_bytes_counter > 0) {
|
||||
before = (char) *(rx_buffer + rx_bytes_counter - 1);
|
||||
}
|
||||
|
|
|
@ -7,20 +7,29 @@
|
|||
#include <string.h>
|
||||
|
||||
|
||||
const char * START_CONFIG_APN = "AT+CSTT=\0";
|
||||
const char * START_CONFIG_APN = "AT+CSTT=\0";
|
||||
const char * SHUTDOWN_GPRS = "AT+CIPSHUT\r\0";
|
||||
const char * SHUTDOWN_GRPS_RESPONSE = "SHUT OK\0";
|
||||
const char * SHUTDOWN_GRPS_RESPONSE = "SHUT OK\0";
|
||||
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";
|
||||
|
||||
|
||||
static const char * OK = "OK\r\n\0";
|
||||
static const char * QUOTATION = "\"\0";
|
||||
static const char * COMMA = ",\0";
|
||||
static const char * NEWLINE = "\r\0";
|
||||
static const char * STATE = "STATE\0";
|
||||
|
||||
config_data_gsm_t * gsm_sim800_gprs_config_gsm;
|
||||
|
||||
int8_t gsm_sim800_gprs_ready = 0;
|
||||
|
||||
char gsm_sim800_ip_address[18];
|
||||
|
||||
char gsm_sim800_connection_status_str[24];
|
||||
|
||||
void sim800_gprs_initialize(srl_context_t * srl_context, gsm_sim800_state_t * state, config_data_gsm_t * config_gsm) {
|
||||
|
||||
if (*state != SIM800_ALIVE) {
|
||||
|
@ -80,15 +89,41 @@ void sim800_gprs_response_callback(srl_context_t * srl_context, gsm_sim800_state
|
|||
|
||||
int comparision_result = 0;
|
||||
|
||||
if (gsm_at_command_sent_last == SHUTDOWN_GPRS) {
|
||||
if (gsm_at_command_sent_last == SHUTDOWN_GPRS && srl_context->srl_rx_state != SRL_RX_ERROR) {
|
||||
comparision_result = strncmp(SHUTDOWN_GRPS_RESPONSE, (const char *)(srl_context->srl_rx_buf_pointer + gsm_response_start_idx), 7);
|
||||
}
|
||||
else {
|
||||
else if (gsm_at_command_sent_last == START_GPRS && srl_context->srl_rx_state != SRL_RX_ERROR) {
|
||||
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_IP_ADDRESS) {
|
||||
memset(gsm_sim800_ip_address, 0, 18);
|
||||
|
||||
strncpy(gsm_sim800_ip_address, (const char *)(srl_context->srl_rx_buf_pointer + gsm_response_start_idx), 18);
|
||||
|
||||
replace_non_printable_with_space(gsm_sim800_ip_address);
|
||||
}
|
||||
else if (gsm_at_command_sent_last == GET_CONNECTION_STATUS ) {
|
||||
// TODO
|
||||
|
||||
//for (comparision_result = gsm_response_start_idx; comparision_result > 0 && (strncmp(STATE, (const char *)(srl_context->srl_rx_buf_pointer + gsm_response_start_idx), 5)); comparision_result--);
|
||||
|
||||
/**
|
||||
* AT+CIPSTATUS
|
||||
OK
|
||||
|
||||
STATE: IP STATUS
|
||||
*
|
||||
*/
|
||||
|
||||
memset(gsm_sim800_connection_status_str, 0x00, 24);
|
||||
}
|
||||
else if (srl_context->srl_rx_state == SRL_RX_DONE || srl_context->srl_rx_state == SRL_RX_IDLE){
|
||||
comparision_result = strncmp(OK, (const char *)(srl_context->srl_rx_buf_pointer + gsm_response_start_idx), 2);
|
||||
}
|
||||
|
||||
if (comparision_result != 0) {
|
||||
*state = SIM800_HANDSHAKING;
|
||||
*state = SIM800_NOT_YET_COMM;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue