view uptools/libcoding/number_encode.c @ 497:74610c4f10f7

target-utils: added 10 ms delay at the end of abb_power_off() The deosmification of the ABB access code (replacement of osmo_delay_ms() bogus delays with correctly-timed ones, which are significantly shorter) had one annoying side effect: when executing the poweroff command from any of the programs, one last '=' prompt character was being sent (and received by the x86 host) as the Calypso board powers off. With delays being shorter now, the abb_power_off() function was returning and the standalone program's main loop was printing its prompt before the Iota chip fully executed the switch-off sequence! I thought about inserting an endless tight loop at the end of the abb_power_off() function, but the implemented solution of a 10 ms delay is a little nicer IMO because if the DEVOFF operation doesn't happen for some reason in a manual hacking scenario, there won't be an artificial blocker in the form of a tight loop keeping us from further poking around.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 25 May 2019 20:44:05 +0000
parents 7154a231e4b5
children
line wrap: on
line source

/*
 * This library module implements the function that parses SMS destination
 * addresses given by the user and encodes them into the GSM 03.40
 * TP-Destination-Address structure.
 */

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

digit_char_to_gsm(ch)
{
	switch (ch) {
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':
		return (ch - '0');
	case '*':
		return 0xA;
	case '#':
		return 0xB;
	case 'a':
	case 'b':
	case 'c':
		return (ch - 'a' + 0xC);
	case 'A':
	case 'B':
	case 'C':
		return (ch - 'A' + 0xC);
	}
	return (-1);
}

parse_and_encode_dest_addr(input, outbuf)
	char *input;
	u_char *outbuf;
{
	char *cp, *endp;
	int d;
	u_char digits[20];
	unsigned n;

	cp = input;
	if (*cp == '+') {
		outbuf[1] = 0x91;
		cp++;
	} else
		outbuf[1] = 0x81;
	if (digit_char_to_gsm(*cp) < 0)
		return(-1);
	n = 0;
	while ((d = digit_char_to_gsm(*cp)) >= 0) {
		cp++;
		if (n >= 20)
			return(-1);
		digits[n++] = d;
	}
	outbuf[0] = n;
	while (n < 20)
		digits[n++] = 0xF;
	if (*cp == ',') {
		cp++;
		if (!isdigit(*cp))
			return(-1);
		outbuf[1] = strtoul(cp, &endp, 0);
		if (*endp)
			return(-1);
	} else if (*cp)
		return(-1);
	for (n = 0; n < 10; n++)
		outbuf[2+n] = (digits[n*2+1] << 4) | digits[n*2];
	return(0);
}