⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atgen.c

📁 NOKIA手机开发包
💻 C
📖 第 1 页 / 共 4 页
字号:
	if (sm_message_send(strlen(req), GN_OP_DeleteSMS, req, state)) 		return GN_ERR_NOTREADY;	return sm_block_no_retry(GN_OP_DeleteSMS, data, state);}/*  * Hey nokia users. don't expect this to return anything useful. * You can't read the number set by the phone menu with this command, * nor can you change this number by AT commands. Worse, an ATZ will * clear a SMS Center Number set by AT commands. This doesn't affect * the number set by the phone menu  */static gn_error AT_GetSMSCenter(gn_data *data, struct gn_statemachine *state){ 	if (sm_message_send(9, GN_OP_GetSMSCenter, "AT+CSCA?\r", state))		return GN_ERR_NOTREADY;	return sm_block_no_retry(GN_OP_GetSMSCenter, data, state);}static gn_error AT_GetSecurityCodeStatus(gn_data *data, struct gn_statemachine *state){ 	if (sm_message_send(9, GN_OP_GetSecurityCodeStatus, "AT+CPIN?\r", state))		return GN_ERR_NOTREADY;	return sm_block_no_retry(GN_OP_GetSecurityCodeStatus, data, state);}static gn_error AT_EnterSecurityCode(gn_data *data, struct gn_statemachine *state){	unsigned char req[32];	if (data->security_code->type != GN_SCT_Pin)		return GN_ERR_NOTIMPLEMENTED;	sprintf(req, "AT+CPIN=\"%s\"\r", data->security_code->code); 	if (sm_message_send(strlen(req), GN_OP_EnterSecurityCode, req, state))		return GN_ERR_NOTREADY;	return sm_block_no_retry(GN_OP_EnterSecurityCode, data, state);}static gn_error AT_DialVoice(gn_data *data, struct gn_statemachine *state){	unsigned char req[32];	if (!data->call_info)		return GN_ERR_INTERNALERROR;	snprintf(req, sizeof(req), "ATDT%s;\r", data->call_info->number);	if (sm_message_send(strlen(req), GN_OP_MakeCall, req, state))		return GN_ERR_NOTREADY;	return sm_block_no_retry(GN_OP_MakeCall, data, state);}static gn_error AT_AnswerCall(gn_data *data, struct gn_statemachine *state){	if (sm_message_send(4, GN_OP_AnswerCall, "ATA\r", state))		return GN_ERR_NOTREADY;	return sm_block_no_retry(GN_OP_AnswerCall, data, state);}static gn_error AT_CancelCall(gn_data *data, struct gn_statemachine *state){	if (sm_message_send(8, GN_OP_CancelCall, "AT+CHUP\r", state))		return GN_ERR_NOTREADY;	return sm_block_no_retry(GN_OP_CancelCall, data, state);}static gn_error AT_GetNetworkInfo(gn_data *data, struct gn_statemachine *state){	gn_error error;	if (!data->network_info)		return GN_ERR_INTERNALERROR;	if (sm_message_send(10, GN_OP_GetNetworkInfo, "AT+CREG=2\r", state))		return GN_ERR_NOTREADY;	error = sm_block_no_retry(GN_OP_GetNetworkInfo, data, state);	if (sm_message_send(9, GN_OP_GetNetworkInfo, "AT+CREG?\r", state))		return GN_ERR_NOTREADY;	error = sm_block_no_retry(GN_OP_GetNetworkInfo, data, state);	if (sm_message_send(9, GN_OP_GetNetworkInfo, "AT+COPS?\r", state))		return GN_ERR_NOTREADY;	return sm_block_no_retry(GN_OP_GetNetworkInfo, data, state);}static gn_error ReplyReadPhonebook(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state){	at_driver_instance *drvinst = AT_DRVINST(state);	at_line_buffer buf;	char *pos, *endpos;	int l;	if (buffer[0] != GN_AT_OK)		return GN_ERR_INVALIDLOCATION;	buf.line1 = buffer + 1;	buf.length = length;	splitlines(&buf);	if (strncmp(buf.line1, "AT+CPBR", 7)) {		return GN_ERR_UNKNOWN;	}	if (!strncmp(buf.line2, "OK", 2)) {		/* Empty phonebook location found */		if (data->phonebook_entry) {			*(data->phonebook_entry->number) = '\0';			*(data->phonebook_entry->name) = '\0';			data->phonebook_entry->caller_group = 0;			data->phonebook_entry->subentries_count = 0;			data->phonebook_entry->empty = true;		}		return GN_ERR_NONE;	}	if (data->phonebook_entry) {		data->phonebook_entry->caller_group = 0;		data->phonebook_entry->subentries_count = 0;		/* store number */		pos = strchr(buf.line2, '\"');		endpos = NULL;		if (pos)			endpos = strchr(++pos, '\"');		if (endpos) {			*endpos = '\0';			strcpy(data->phonebook_entry->number, pos);		}		/* store name */		pos = NULL;		if (endpos)			pos = strchr(endpos+2, ',');		endpos = NULL;		if (pos) {			pos = strip_quotes(pos+1);			at_decode(drvinst->charset, data->phonebook_entry->name, pos, strlen(pos));		}	}	return GN_ERR_NONE;}static gn_error ReplyGetSMSCenter(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state){	at_line_buffer buf;	unsigned char *pos, *aux;	if (buffer[0] != GN_AT_OK)		return GN_ERR_UNKNOWN; /* FIXME */	buf.line1 = buffer + 1;	buf.length= length;	splitlines(&buf);		if (data->message_center && strstr(buf.line2,"+CSCA")) {		pos = strchr(buf.line2 + 8, '\"');		if (pos) {			*pos++ = '\0';			data->message_center->id = 1;			strncpy(data->message_center->smsc.number, buf.line2 + 8, GN_BCD_STRING_MAX_LENGTH);			data->message_center->smsc.number[GN_BCD_STRING_MAX_LENGTH - 1] = '\0';			/* Now we look for the number type */			data->message_center->smsc.type = 0;			aux = strchr(pos, ',');			if (aux)				data->message_center->smsc.type = atoi(++aux);			else if (data->message_center->smsc.number[0] == '+')				data->message_center->smsc.type = GN_GSM_NUMBER_International;			if (!data->message_center->smsc.type)				data->message_center->smsc.type = GN_GSM_NUMBER_Unknown;		} else {			data->message_center->id = 0;			strncpy(data->message_center->name, "SMS Center", GN_SMS_CENTER_NAME_MAX_LENGTH);			data->message_center->smsc.type = GN_GSM_NUMBER_Unknown;		}		data->message_center->default_name = 1; /* use default name */		data->message_center->format = GN_SMS_MF_Text; /* whatever */		data->message_center->validity = GN_SMS_VP_Max;		strcpy(data->message_center->recipient.number, "") ;	}	return GN_ERR_NONE;}static gn_error ReplyMemoryStatus(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state){	at_driver_instance *drvinst = AT_DRVINST(state);	at_line_buffer buf;	char *pos;	if (buffer[0] != GN_AT_OK)		return GN_ERR_INVALIDMEMORYTYPE;	buf.line1 = buffer + 1;	buf.length= length;	splitlines(&buf);	if (data->memory_status && strstr(buf.line2, "+CPBS")) {		pos = strchr(buf.line2, ',');		if (pos) {			data->memory_status->used = atoi(++pos);		} else {			data->memory_status->used = drvinst->memorysize;			data->memory_status->free = 0;			return GN_ERR_NOTSUPPORTED;		}		pos = strchr(pos, ',');		if (pos) {			data->memory_status->free = atoi(++pos) - data->memory_status->used;		} else {			return GN_ERR_UNKNOWN;		}	}	return GN_ERR_NONE;}static gn_error ReplyMemoryRange(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state){	at_driver_instance *drvinst = AT_DRVINST(state);	at_line_buffer buf;	char *pos, *s, *t;	drvinst->memoryoffset = 0;	drvinst->memorysize = 100;	if (buffer[0] != GN_AT_OK)		return GN_ERR_UNKNOWN;	buf.line1 = buffer + 1;	buf.length= length;	splitlines(&buf);	if (strncmp(buf.line2, "+CPBR: ", 7) == 0) {		s = buf.line2 + 7;		pos = strchr(s, ',');		if (pos) {			*pos = '\0';			s = strip_brackets(s);			t = strchr(s, '-');			if (t) {				int first, last;				first = atoi(s);				last = atoi(t+1);				drvinst->memoryoffset = first - 1;				drvinst->memorysize = last - first + 1;			}		}	}	return GN_ERR_NONE;}static gn_error ReplyGetBattery(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state){	at_line_buffer buf;	char *pos;	if (buffer[0] != GN_AT_OK)		return GN_ERR_UNKNOWN;	buf.line1 = buffer + 1;	buf.length= length;		splitlines(&buf);	if (!strncmp(buf.line1, "AT+CBC", 6)) { /* FIXME realy needed? */		if (data->battery_level) {			*(data->battery_unit) = GN_BU_Percentage;			pos = strchr(buf.line2, ',');			if (pos) {				pos++;				*(data->battery_level) = atoi(pos);			} else {				*(data->battery_level) = 1;			}		}		if (data->power_source) {			*(data->power_source) = 0;			if (*buf.line2 == '1') *(data->power_source) = GN_PS_ACDC;			if (*buf.line2 == '0') *(data->power_source) = GN_PS_BATTERY;		}	}	return GN_ERR_NONE;}static gn_error ReplyGetRFLevel(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state){	at_line_buffer buf;	char *pos1, *pos2;	if (buffer[0] != GN_AT_OK)		return GN_ERR_UNKNOWN;			buf.line1 = buffer + 1;	buf.length= length;		splitlines(&buf);	if (data->rf_unit && !strncmp(buf.line1, "AT+CSQ", 6)) { /* FIXME realy needed? */		*(data->rf_unit) = GN_RF_CSQ;		pos1 = buf.line2 + 6;		pos2 = strchr(buf.line2, ',');		if (pos1 < pos2) {			*(data->rf_level) = atoi(pos1);		} else {			*(data->rf_level) = 1;		}	}	return GN_ERR_NONE;}static gn_error ReplyIdentify(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state){	at_line_buffer buf;	if (buffer[0] != GN_AT_OK)		return GN_ERR_UNKNOWN;		/* FIXME */	buf.line1 = buffer + 1;	buf.length = length;	splitlines(&buf);	if (!strncmp(buf.line1, "AT+CG", 5)) {		reply_simpletext(buf.line1+2, buf.line2, "+CGSN: ", data->imei);		reply_simpletext(buf.line1+2, buf.line2, "+CGMM: ", data->model);		reply_simpletext(buf.line1+2, buf.line2, "+CGMI: ", data->manufacturer);		reply_simpletext(buf.line1+2, buf.line2, "+CGMR: ", data->revision);	}	return GN_ERR_NONE;}static gn_error ReplyCallDivert(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state){	int i;	for (i = 0; i < length; i++) {		dprintf("%02x ", buffer[i + 1]);	}	dprintf("\n");	return GN_ERR_NONE;}static gn_error ReplyGetPrompt(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state){	return (buffer[0] == GN_AT_PROMPT) ? GN_ERR_NONE : GN_ERR_INTERNALERROR;}static gn_error ReplyGetSMSStatus(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state){	at_line_buffer buf;	if (buffer[0] != GN_AT_OK) return GN_ERR_FAILED;	buf.line1 = buffer + 1;	buf.length = length;	splitlines(&buf);	if (sscanf(buf.line2, "+CPMS: %d", &data->sms_status->number) != 1)		return GN_ERR_FAILED;	data->sms_status->unread = 0;	data->sms_status->changed = 0;	data->sms_status->folders_count = 0;	return GN_ERR_NONE;}static gn_error ReplySendSMS(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state){	at_line_buffer buf;	if (buffer[0] != GN_AT_OK)		return GN_ERR_FAILED;	buf.line1 = buffer + 1;	buf.length = length;	splitlines(&buf);	/* SendSMS or SaveSMS */	if (!strncmp("+CMGW:", buf.line2, 6) ||	    !strncmp("+CMGS:", buf.line2, 6))		data->raw_sms->number = atoi(buf.line2 + 6);	else		data->raw_sms->number = -1;	dprintf("Message sent okay\n");	return GN_ERR_NONE;}static gn_error ReplyGetSMS(int messagetype, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state){	at_line_buffer buf;	gn_error ret = GN_ERR_NONE;	unsigned int sms_len, l, offset = 0;	char *tmp;		if (buffer[0] != GN_AT_OK)		return GN_ERR_INTERNALERROR;	buf.line1 = buffer + 1;	buf.length = length;	splitlines(&buf);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -