kopia lustrzana https://github.com/SP8EBC/ParaTNC
sim800 periodically pool engineering data
rodzic
739ea29a82
commit
c23e013710
16
src/main.c
16
src/main.c
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "gsm/sim800c.h"
|
||||
#include "gsm/sim800c_engineering.h"
|
||||
#include "gsm/sim800c_poolers.h"
|
||||
#endif
|
||||
|
||||
#include <delay.h>
|
||||
|
@ -989,8 +990,9 @@ int main(int argc, char* argv[]){
|
|||
gsm_sim800_tx_done_event_handler(main_gsm_srl_ctx_ptr, &main_gsm_state);
|
||||
}
|
||||
|
||||
gsm_sim800_engineering_enable(main_gsm_srl_ctx_ptr, &main_gsm_state);
|
||||
gsm_sim800_engineering_request_data(main_gsm_srl_ctx_ptr, &main_gsm_state);
|
||||
// gsm_sim800_engineering_enable(main_gsm_srl_ctx_ptr, &main_gsm_state);
|
||||
// gsm_sim800_engineering_request_data(main_gsm_srl_ctx_ptr, &main_gsm_state);
|
||||
// gsm_sim800_engineering_disable(main_gsm_srl_ctx_ptr, &main_gsm_state);
|
||||
}
|
||||
|
||||
// if Victron VE.direct client is enabled
|
||||
|
@ -1120,6 +1122,12 @@ int main(int argc, char* argv[]){
|
|||
packet_tx_handler(main_config_data_basic, main_config_data_mode);
|
||||
#endif
|
||||
|
||||
#ifdef PARAMETEO
|
||||
if (main_config_data_mode->gsm == 1) {
|
||||
gsm_sim800_poolers_one_minute(main_gsm_srl_ctx_ptr, &main_gsm_state);
|
||||
}
|
||||
#endif
|
||||
|
||||
main_one_minute_pool_timer = 60000;
|
||||
}
|
||||
|
||||
|
@ -1130,7 +1138,9 @@ int main(int argc, char* argv[]){
|
|||
digi_pool_viscous();
|
||||
|
||||
#ifdef PARAMETEO
|
||||
gsm_sim800_pool(main_gsm_srl_ctx_ptr, &main_gsm_state);
|
||||
gsm_sim800_initialization_pool(main_gsm_srl_ctx_ptr, &main_gsm_state);
|
||||
|
||||
gsm_sim800_poolers_one_second(main_gsm_srl_ctx_ptr, &main_gsm_state);
|
||||
#endif
|
||||
|
||||
if ((main_config_data_mode->wx & WX_ENABLED) == 1) {
|
||||
|
|
|
@ -22,7 +22,7 @@ extern char gsm_sim800_lac[5];
|
|||
|
||||
void gsm_sim800_init(gsm_sim800_state_t * state, uint8_t enable_echo);
|
||||
|
||||
void gsm_sim800_pool(srl_context_t * srl_context, gsm_sim800_state_t * state);
|
||||
void gsm_sim800_initialization_pool(srl_context_t * srl_context, gsm_sim800_state_t * state);
|
||||
uint8_t gsm_sim800_rx_terminating_callback(uint8_t current_data, const uint8_t * const rx_buffer, uint16_t rx_bytes_counter); // callback used to detect echo
|
||||
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);
|
||||
|
|
|
@ -15,6 +15,10 @@ extern const char * ENGINEERING_ENABLE;
|
|||
extern const char * ENGINEERING_DISABLE;
|
||||
extern const char * ENGINEERING_GET;
|
||||
|
||||
extern uint8_t gsm_sim800_engineering_is_enabled;
|
||||
|
||||
extern uint8_t gsm_sim800_engineering_successed;
|
||||
|
||||
void gsm_sim800_engineering_enable(srl_context_t * srl_context, gsm_sim800_state_t * state);
|
||||
void gsm_sim800_engineering_disable(srl_context_t * srl_context, gsm_sim800_state_t * state);
|
||||
void gsm_sim800_engineering_request_data(srl_context_t * srl_context, gsm_sim800_state_t * state);
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* sim800_poolers.h
|
||||
*
|
||||
* Created on: Jan 27, 2022
|
||||
* Author: mateusz
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_GSM_SIM800C_POOLERS_H_
|
||||
#define INCLUDE_GSM_SIM800C_POOLERS_H_
|
||||
|
||||
#include "drivers/serial.h"
|
||||
#include "gsm/sim800_state_t.h"
|
||||
|
||||
void gsm_sim800_poolers_one_minute(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);
|
||||
|
||||
#endif /* INCLUDE_GSM_SIM800C_POOLERS_H_ */
|
|
@ -83,7 +83,7 @@ void gsm_sim800_init(gsm_sim800_state_t * state, uint8_t enable_echo) {
|
|||
}
|
||||
}
|
||||
|
||||
void gsm_sim800_pool(srl_context_t * srl_context, gsm_sim800_state_t * state) {
|
||||
void gsm_sim800_initialization_pool(srl_context_t * srl_context, gsm_sim800_state_t * state) {
|
||||
|
||||
if (*state == SIM800_NOT_YET_COMM) {
|
||||
|
||||
|
@ -102,6 +102,9 @@ void gsm_sim800_pool(srl_context_t * srl_context, gsm_sim800_state_t * state) {
|
|||
// start data reception
|
||||
srl_receive_data_with_callback(srl_context, gsm_sim800_rx_terminating_callback);
|
||||
|
||||
// start timeout calculation
|
||||
srl_context->srl_rx_timeout_calc_started = 1;
|
||||
|
||||
// record when the handshake has been sent
|
||||
gsm_time_of_last_command_send_to_module = main_get_master_time();
|
||||
}
|
||||
|
@ -124,6 +127,12 @@ void gsm_sim800_pool(srl_context_t * srl_context, gsm_sim800_state_t * state) {
|
|||
|
||||
srl_receive_data_with_callback(srl_context, gsm_sim800_rx_terminating_callback);
|
||||
|
||||
// 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_NETWORK_REGISTRATION) {
|
||||
// ask for network registration status
|
||||
|
@ -138,6 +147,12 @@ void gsm_sim800_pool(srl_context_t * srl_context, gsm_sim800_state_t * state) {
|
|||
|
||||
srl_receive_data_with_callback(srl_context, gsm_sim800_rx_terminating_callback);
|
||||
|
||||
// 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_PIN_STATUS) {
|
||||
// ask for network registration status
|
||||
|
@ -151,6 +166,12 @@ void gsm_sim800_pool(srl_context_t * srl_context, gsm_sim800_state_t * state) {
|
|||
gsm_waiting_for_command_response = 1;
|
||||
|
||||
srl_receive_data_with_callback(srl_context, gsm_sim800_rx_terminating_callback);
|
||||
|
||||
// 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_REGISTERED_NETWORK) {
|
||||
// ask for signal level
|
||||
|
@ -164,6 +185,12 @@ void gsm_sim800_pool(srl_context_t * srl_context, gsm_sim800_state_t * state) {
|
|||
gsm_waiting_for_command_response = 1;
|
||||
|
||||
srl_receive_data_with_callback(srl_context, gsm_sim800_rx_terminating_callback);
|
||||
|
||||
// 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_SIGNAL_LEVEL) {
|
||||
*state = SIM800_ALIVE;
|
||||
|
@ -272,7 +299,7 @@ void gsm_sim800_rx_done_event_handler(srl_context_t * srl_context, gsm_sim800_st
|
|||
comparision_result = atoi((const char *)(srl_context->srl_rx_buf_pointer + gsm_response_start_idx + 6));
|
||||
|
||||
if (comparision_result > 1 && comparision_result < 32) {
|
||||
gsm_sim800_signal_level_dbm = -110 + 2 * comparision_result;
|
||||
gsm_sim800_signal_level_dbm = (int8_t)(-110 + 2 * (comparision_result - 2));
|
||||
}
|
||||
else if (comparision_result == 1) {
|
||||
gsm_sim800_signal_level_dbm = -111;
|
||||
|
@ -292,6 +319,10 @@ void gsm_sim800_rx_done_event_handler(srl_context_t * srl_context, gsm_sim800_st
|
|||
else if (gsm_at_command_sent_last == ENGINEERING_GET) {
|
||||
gsm_sim800_engineering_response_callback(srl_context, state, gsm_response_start_idx);
|
||||
}
|
||||
else if (gsm_at_command_sent_last == ENGINEERING_DISABLE) {
|
||||
gsm_sim800_engineering_response_callback(srl_context, state, gsm_response_start_idx);
|
||||
|
||||
}
|
||||
|
||||
*state = SIM800_ALIVE;
|
||||
}
|
||||
|
@ -301,7 +332,12 @@ void gsm_sim800_tx_done_event_handler(srl_context_t * srl_context, gsm_sim800_st
|
|||
if (*state == SIM800_ALIVE_SENDING_TO_MODEM) {
|
||||
srl_receive_data_with_callback(srl_context, gsm_sim800_rx_terminating_callback);
|
||||
|
||||
// start timeout calculation
|
||||
srl_context->srl_rx_timeout_calc_started = 1;
|
||||
|
||||
*state = SIM800_ALIVE_WAITING_MODEM_RESP;
|
||||
|
||||
gsm_time_of_last_command_send_to_module = main_get_master_time();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
const char * ENGINEERING_ENABLE = "AT+CENG=4,0\r\0";
|
||||
const char * ENGINEERING_DISABLE = "AT+CENG=4,0\r\0";
|
||||
const char * ENGINEERING_DISABLE = "AT+CENG=0,0\r\0";
|
||||
const char * ENGINEERING_GET = "AT+CENG?\r\0";
|
||||
|
||||
static const char * OK = "OK\r\n\0";
|
||||
|
@ -32,6 +32,10 @@ static const char * CENG0 = "+CENG: 0,\0";
|
|||
|
||||
uint8_t gsm_sim800_engineering_is_enabled = 0;
|
||||
|
||||
// set to one if correct response has been received for engineering data request. This is reset back to zero
|
||||
// after disabling CENG or after 'gsm_sim800_engineering_request_data' is called
|
||||
uint8_t gsm_sim800_engineering_successed = 0;
|
||||
|
||||
|
||||
static uint16_t gsm_sim800_rewind_to_ceng_0(uint8_t *srl_rx_buf_pointer, uint16_t buffer_ln, uint16_t gsm_response_start_idx) {
|
||||
|
||||
|
@ -113,12 +117,28 @@ void gsm_sim800_engineering_enable(srl_context_t * srl_context, gsm_sim800_state
|
|||
}
|
||||
|
||||
void gsm_sim800_engineering_disable(srl_context_t * srl_context, gsm_sim800_state_t * state) {
|
||||
if (*state == SIM800_ALIVE && gsm_sim800_engineering_is_enabled == 1) {
|
||||
// send a command to module
|
||||
srl_send_data(srl_context, (const uint8_t*) ENGINEERING_DISABLE, SRL_MODE_ZERO, strlen(ENGINEERING_DISABLE), SRL_INTERNAL);
|
||||
|
||||
// set what has been just send
|
||||
gsm_at_command_sent_last = ENGINEERING_DISABLE;
|
||||
|
||||
// switch the internal state
|
||||
*state = SIM800_ALIVE_SENDING_TO_MODEM;
|
||||
|
||||
// clear the flag
|
||||
gsm_sim800_engineering_successed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void gsm_sim800_engineering_request_data(srl_context_t * srl_context, gsm_sim800_state_t * state) {
|
||||
|
||||
if (*state == SIM800_ALIVE && gsm_sim800_engineering_is_enabled == 1) {
|
||||
|
||||
// clear the flag
|
||||
gsm_sim800_engineering_successed = 0;
|
||||
|
||||
// send a command to module
|
||||
srl_send_data(srl_context, (const uint8_t*) ENGINEERING_GET, SRL_MODE_ZERO, strlen(ENGINEERING_GET), SRL_INTERNAL);
|
||||
|
||||
|
@ -145,11 +165,34 @@ void gsm_sim800_engineering_response_callback(srl_context_t * srl_context, gsm_s
|
|||
}
|
||||
}
|
||||
else if (gsm_at_command_sent_last == ENGINEERING_GET) {
|
||||
|
||||
// check if anything has been received
|
||||
if (srl_context->srl_rx_state == SRL_RX_ERROR) {
|
||||
|
||||
gsm_sim800_engineering_successed = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
else {
|
||||
gsm_sim800_engineering_successed = 1;
|
||||
}
|
||||
|
||||
// look for the start of '+CENG: 0,' record
|
||||
uint16_t ceng_start = gsm_sim800_rewind_to_ceng_0(srl_context->srl_rx_buf_pointer, srl_context->srl_rx_buf_ln, gsm_response_start_idx);
|
||||
|
||||
// if it has been found
|
||||
gsm_sim800_engineering_parse_ceng_0(srl_context->srl_rx_buf_pointer, ceng_start);
|
||||
}
|
||||
else if (gsm_at_command_sent_last == ENGINEERING_DISABLE) {
|
||||
int comparision_result = strcmp(OK, (const char *)(srl_context->srl_rx_buf_pointer + gsm_response_start_idx));
|
||||
|
||||
if (comparision_result == 0) {
|
||||
gsm_sim800_engineering_is_enabled = 0;
|
||||
|
||||
}
|
||||
else {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* sim800_poolers.c
|
||||
*
|
||||
* Created on: Jan 27, 2022
|
||||
* Author: mateusz
|
||||
*/
|
||||
|
||||
#include "gsm/sim800c_poolers.h"
|
||||
#include "gsm/sim800c_engineering.h"
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t sim800_poolers_five = 4;
|
||||
|
||||
void gsm_sim800_poolers_one_minute(srl_context_t * srl_context, gsm_sim800_state_t * state){
|
||||
|
||||
sim800_poolers_five++;
|
||||
|
||||
if (sim800_poolers_five == 5) {
|
||||
|
||||
gsm_sim800_engineering_enable(srl_context, state);
|
||||
|
||||
sim800_poolers_five = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void gsm_sim800_poolers_one_second(srl_context_t * srl_context, gsm_sim800_state_t * state) {
|
||||
|
||||
if (gsm_sim800_engineering_is_enabled == 1 && gsm_sim800_engineering_successed == 0) {
|
||||
gsm_sim800_engineering_request_data(srl_context, state);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (gsm_sim800_engineering_successed == 1) {
|
||||
gsm_sim800_engineering_disable(srl_context, state);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue