view uptools/atcmd/smsend_cmgw.c @ 995:74024eb17e04

fc-loadtool help: improve language regarding 16 MiB flash chips In FC project history, 16 MiB flash originally meant Pirelli DP-L10. Then we got FCDEV3B with the same flash (our own design), but now we are discovering more Calypso devices that used such large flash, both late Calypso era (Sony Ericsson K2x0) as well as much earlier ones (FIC FLUID devices.txt file with 2004 dates, Leonardo+ rev 5). Hence we need to migrate to more generic or neutral language in associated documentation, without giving elevated status to specific examples that drove our early project history.
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 03 Dec 2023 21:11:12 +0000
parents dc2fd8e6f42c
children
line wrap: on
line source

/*
 * The handling of +CMGW responses and send-after-write for fcup-smsend
 * family is implemented here.
 */

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "../../rvinterf/include/exitcodes.h"
#include "resp_parse.h"

extern char at_response[];
extern int sms_write_mode;

struct saw_rec {
	unsigned	msgid;
	struct saw_rec	*next;
};

struct saw_rec *sendafterwr_head, **sendafterwr_tail = &sendafterwr_head;

add_sendafterwr_record(msgid)
	unsigned msgid;
{
	struct saw_rec *rec;

	rec = malloc(sizeof(struct saw_rec));
	if (!rec) {
		perror("malloc for send-after-write record");
		exit(ERROR_UNIX);
	}
	rec->msgid = msgid;
	rec->next = 0;
	*sendafterwr_tail = rec;
	sendafterwr_tail = &rec->next;
}

cmgw_callback()
{
	struct resp_field fields[1];
	int cc;

	/* skip empty lines */
	if (!at_response[1])
		return;
	/* if not empty, it MUST be +CMGW */
	if (strncmp(at_response+1, "+CMGW: ", 7)) {
		fprintf(stderr, "error: response from target is not +CMGW\n");
		exit(ERROR_TARGET);
	}
	if (sms_write_mode == 2) {
		puts(at_response+1);
		return;
	}
	if (parse_structured_response(at_response+8, fields, 1) != 1) {
malformed:	fprintf(stderr, "error: malformed +CMGW response\n");
		exit(ERROR_TARGET);
	}
	if (fields[0].type != RESP_FIELD_NUMBER)
		goto malformed;
	add_sendafterwr_record(fields[0].num);
}

sendafterwr_process()
{
	struct saw_rec *rec;
	char cmss_cmd[32];

	if (!sendafterwr_head) {
		fprintf(stderr,
			"error: no +CMGW response received from target\n");
		exit(ERROR_TARGET);
	}
	if (sendafterwr_head->next)
		atinterf_exec_cmd_needok("AT+CMMS=1", (char *) 0, (void *) 0);
	for (rec = sendafterwr_head; rec; rec = rec->next) {
		sprintf(cmss_cmd, "AT+CMSS=%u", rec->msgid);
		atinterf_exec_cmd_needok(cmss_cmd, (char *) 0, (void *) 0);
	}
	if (sendafterwr_head->next)
		atinterf_exec_cmd_needok("AT+CMMS=0", (char *) 0, (void *) 0);
}