<commit_before>/*
 * th_upgprscdma.c
 *
 *  Created on: 2015-8-11
 *      Author: Johnnyzhang
 */



#include "threads.h"
#include "main.h"
#include "common.h"
#include "msg_que.h"
#include "protocol.h"
#include "up_comm.h"
#include "menu.h"
#include "devices.h"
#include "gprscdma.h"
#include "f_param.h"
#include "spont_alarm.h"
#include "language.h"

#define CONFIG_GPRSCDMA_THREAD_SLEEP 100

static UP_COMM_PRIVATE gprscdma_private = {
	.packetID = 1,
	.save_hb_packetID = 1,
};

static BOOL gprscdma_device_init(struct UP_COMM_ST *up);
static BOOL gprscdma_tcpip_connect(struct UP_COMM_ST *up);
static INT32 gprscdma_fep_receive(struct UP_COMM_ST *up, int timeout);
static BOOL gprscdma_fep_send(struct UP_COMM_ST *up);
static void gprscdma_disconnect(struct UP_COMM_ST *up);

static UP_COMM_INTERFACE gprscdma_comm = {
		.describe = "GPRS/CDMA",
		.fd = -1,
		.up_status = e_up_offline,
		.que_in = MSG_QUE_GPRSCDMA_IN,
		.que_out = MSG_QUE_GPRSCDMA_OUT,
		.need_diag = FALSE,
		.device_init = gprscdma_device_init,
		.connect = gprscdma_tcpip_connect,
		.login = NULL,
		.logout = NULL,
		.heartbeat_cycle = 60,
		.timeout = -1,
		.comm_receive = gprscdma_fep_receive,
		.comm_send = gprscdma_fep_send,
		.heartbeat_request = NULL,
		.disconnect = gprscdma_disconnect,
		.private = &gprscdma_private,
};

static BOOL check_gprscdma_online(struct UP_COMM_ST *up)
{
	BOOL ret = (up->up_status == e_up_online);

	if (ret) {
		lcd_update_info(c_login_ok_str);
	}

	lcd_update_head_info();
	return ret;
}

static BOOL gprscdma_device_init(struct UP_COMM_ST *up)
{
	return !!modem_check(modem_device, modem_lockname, MODEM_DEFAULT_BAUD);
}

static BOOL gprscdma_tcpip_connect(struct UP_COMM_ST *up)
{
	char ip_addr[16];
	BYTE host_ip[4], host_port[2];
	short ip_port;

	if (remote_ppp_connect(modem_device, modem_lockpid_name, MODEM_DEFAULT_BAUD_STR))
	{<commit_msg>1. not to show frequently "connected" log string on LCD screen.<commit_after>/*
 * th_upgprscdma.c
 *
 *  Created on: 2015-8-11
 *      Author: Johnnyzhang
 */



#include "threads.h"
#include "main.h"
#include "common.h"
#include "msg_que.h"
#include "protocol.h"
#include "up_comm.h"
#include "menu.h"
#include "devices.h"
#include "gprscdma.h"
#include "f_param.h"
#include "spont_alarm.h"
#include "language.h"

#define CONFIG_GPRSCDMA_THREAD_SLEEP 100

static UP_COMM_PRIVATE gprscdma_private = {
	.packetID = 1,
	.save_hb_packetID = 1,
};

static BOOL gprscdma_device_init(struct UP_COMM_ST *up);
static BOOL gprscdma_tcpip_connect(struct UP_COMM_ST *up);
static INT32 gprscdma_fep_receive(struct UP_COMM_ST *up, int timeout);
static BOOL gprscdma_fep_send(struct UP_COMM_ST *up);
static void gprscdma_disconnect(struct UP_COMM_ST *up);

static UP_COMM_INTERFACE gprscdma_comm = {
		.describe = "GPRS/CDMA",
		.fd = -1,
		.up_status = e_up_offline,
		.que_in = MSG_QUE_GPRSCDMA_IN,
		.que_out = MSG_QUE_GPRSCDMA_OUT,
		.need_diag = FALSE,
		.device_init = gprscdma_device_init,
		.connect = gprscdma_tcpip_connect,
		.login = NULL,
		.logout = NULL,
		.heartbeat_cycle = 60,
		.timeout = -1,
		.comm_receive = gprscdma_fep_receive,
		.comm_send = gprscdma_fep_send,
		.heartbeat_request = NULL,
		.disconnect = gprscdma_disconnect,
		.private = &gprscdma_private,
};

static BOOL check_gprscdma_online(struct UP_COMM_ST *up) /// change by wd 20170608
{
	BOOL ret = (up->up_status == e_up_online);
	static bool prev_state = false; // define and initialize prev_state, not assign value to prev_state false every time

	if (ret && prev_state == false) {
		lcd_update_info(c_login_ok_str);
		prev_state = true;
	}else{
		if(!ret)
			prev_state = false;
	}

	lcd_update_head_info();
	return ret;
}

static BOOL gprscdma_device_init(struct UP_COMM_ST *up)
{
	return !!modem_check(modem_device, modem_lockname, MODEM_DEFAULT_BAUD);
}

static BOOL gprscdma_tcpip_connect(struct UP_COMM_ST *up)
{
	char ip_addr[16];
	BYTE host_ip[4], host_port[2];
	short ip_port;

	if (remote_ppp_connect(modem_device, modem_lockpid_name, MODEM_DEFAULT_BAUD_STR))
	{
{'fraction_non_alphanumeric': 0.11285500747384156, 'fraction_numerical': 0.013203786746387643, 'mean_word_length': 5.120426829268292, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5275559', 'n_tokens_mistral': 1776, 'n_tokens_neox': 1670, 'n_words': 328}