view uptools/libcoding/gsm7_encode.c @ 1014:961efadd530a default tip

fc-shell TCH DL handler: add support for CSD modes TCH DL capture mechanism in FC Tourmaline firmware has been extended to support CSD modes in addition to speech - add the necessary support on the host tools side. It needs to be noted that this mechanism in its present state does NOT provide the debug utility value that was sought: as we learned only after the code was implemented, TI's DSP has a misfeature in that the buffer we are reading (a_dd_0[]) is zeroed out when the IDS block is enabled, i.e., we are reading all zeros and not the real DL bits we were after. But since the code has already been written, we are keeping it - perhaps we can do some tests with IDS disabled.
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 26 Nov 2024 06:27:43 +0000
parents ec7e23d5151f
children
line wrap: on
line source

/*
 * This library module implements the function for encoding from ISO 8859-1
 * into the GSM 7-bit default alphabet (03.38 or 23.038).
 */

#include <sys/types.h>
#include <ctype.h>

extern u_char gsm7_encode_table[256];

static unsigned
handle_escape(ipp)
	u_char **ipp;
{
	unsigned c;

	c = *(*ipp)++;
	if (c >= '0' && c <= '7' && isxdigit(**ipp)) {
		c = ((c - '0') << 4) | decode_hex_digit(*(*ipp)++);
		return c;
	}
	switch (c) {
	case 'n':
		return '\n';
	case 'r':
		return '\r';
	case 'e':
		return 0x1B;
	case 'E':		/* Euro currency symbol */
		return 0xE5;
	case '"':
	case '\\':
		c = gsm7_encode_table[c];
		return c;
	default:
		return 0xFF;
	}
}

latin1_to_gsm7(inbuf, outbuf, outmax, outlenp, allow_escape)
	u_char *inbuf, *outbuf;
	unsigned outmax, *outlenp;
{
	u_char *ip = inbuf, *op = outbuf;
	unsigned outcnt = 0, c, n;

	while (c = *ip++) {
		if (c == '\\' && allow_escape) {
			c = handle_escape(&ip);
			if (c == 0xFF)
				return(-3);
		} else {
			c = gsm7_encode_table[c];
			if (c == 0xFF)
				return(-1);
		}
		if (c & 0x80)
			n = 2;
		else
			n = 1;
		if (outcnt + n > outmax)
			return(-2);
		if (c & 0x80) {
			*op++ = 0x1B;
			*op++ = c & 0x7F;
		} else
			*op++ = c;
		outcnt += n;
	}
	*outlenp = outcnt;
	return(0);
}