diff uptools/atcmd/smsend_main.c @ 381:40b1498ec39d

fcup-smsend: UCS-2 send mode implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 09 Mar 2018 02:31:15 +0000
parents a8abaa85c378
children ed9b67e7e741
line wrap: on
line diff
--- a/uptools/atcmd/smsend_main.c	Fri Mar 09 00:43:36 2018 +0000
+++ b/uptools/atcmd/smsend_main.c	Fri Mar 09 02:31:15 2018 +0000
@@ -17,9 +17,6 @@
 int concat_enable, concat_refno_set, concat_quiet;
 u_char dest_addr[12];
 char msgtext[MAX_MSG_CHARS*2+2];
-u_char msgtext_gsm7[MAX_MSG_CHARS];
-u_short msgtext_uni[MAX_MSG_UNI];
-unsigned msgtext_gsmlen, msgtext_unilen;
 u_char concat_refno;
 
 process_cmdline(argc, argv)
@@ -150,6 +147,8 @@
 
 gsm7_mode_main()
 {
+	u_char msgtext_gsm7[MAX_MSG_CHARS];
+	unsigned msgtext_gsmlen;
 	int rc;
 	unsigned nparts, n;
 	u_char udh[5];
@@ -229,11 +228,77 @@
 	exit(0);
 }
 
+ucs2_mode_main()
+{
+	u_short msgtext_uni[MAX_MSG_UNI];
+	unsigned msgtext_unilen;
+	int rc;
+	unsigned nparts, n;
+	u_char udh[5];
+	unsigned pos, remain, chunk;
+
+	rc = utf8_to_ucs2(msgtext, msgtext_uni, MAX_MSG_UNI, &msgtext_unilen);
+	if (rc == -1) {
+		fprintf(stderr, "error: invalid UTF-8 message\n");
+		exit(ERROR_USAGE);
+	}
+	if (rc == -2) {
+		fprintf(stderr, "error: message too long for max concat SMS\n");
+		exit(ERROR_USAGE);
+	}
+	if (msgtext_unilen <= 70) {
+		common_init();
+		prep_for_pdu_mode();
+		send_pdu_ucs2(dest_addr, msgtext_uni, msgtext_unilen, 0, 0);
+		if (sms_write_mode == 1)
+			sendafterwr_process();
+		if (concat_enable && !concat_quiet)
+			printf("Message sent as single SMS\n");
+		exit(0);
+	}
+	if (!concat_enable) {
+		fprintf(stderr, "error: message exceeds 70 UCS-2 chars\n");
+		exit(ERROR_USAGE);
+	}
+	if (!concat_refno_set)
+		concat_refno = get_concsms_refno_from_host_fs();
+	nparts = (msgtext_unilen + 66) / 67;
+	udh[0] = 0x00;
+	udh[1] = 0x03;
+	udh[2] = concat_refno;
+	udh[3] = nparts;
+	common_init();
+	prep_for_pdu_mode();
+	if (sms_write_mode == 0)
+		atinterf_exec_cmd_needok("AT+CMMS=1", 0, 0);
+	pos = 0;
+	remain = msgtext_unilen;
+	for (n = 1; n <= nparts; n++) {
+		udh[4] = n;
+		chunk = 67;
+		if (chunk > remain)
+			chunk = remain;
+		send_pdu_ucs2(dest_addr, msgtext_uni + pos, chunk, udh, 5);
+		pos += chunk;
+		remain -= chunk;
+	}
+	if (sms_write_mode == 0)
+		atinterf_exec_cmd_needok("AT+CMMS=0", 0, 0);
+	if (sms_write_mode == 1)
+		sendafterwr_process();
+	if (!concat_quiet)
+		printf("Message sent as %u SMS segments\n", nparts);
+	exit(0);
+}
+
 main(argc, argv)
 	char **argv;
 {
 	if (!process_cmdline(argc, argv))
 		read_msgtext_from_stdin();
 	trim_trailing_newlines();
-	gsm7_mode_main();
+	if (ucs2_mode)
+		ucs2_mode_main();
+	else
+		gsm7_mode_main();
 }