changeset 334:f40530e2d48d

uptools/libcoding: GSM timestamp decoding implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 04 Feb 2018 00:01:37 +0000
parents 74d5e95ee84a
children 097ce8431d11
files uptools/libcoding/Makefile uptools/libcoding/gsmtime.c
diffstat 2 files changed, 29 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/uptools/libcoding/Makefile	Sat Feb 03 23:53:20 2018 +0000
+++ b/uptools/libcoding/Makefile	Sun Feb 04 00:01:37 2018 +0000
@@ -1,7 +1,8 @@
 CC=	gcc
 CFLAGS=	-O2
 OBJS=	alpha_addr.o decode_helpers.o gsm7_decode.o gsm7_decode_tables.o \
-	gsm7_unpack.o hexdecode.o number_decode.o scaddr.o ucs2_decode.o
+	gsm7_unpack.o gsmtime.o hexdecode.o number_decode.o scaddr.o \
+	ucs2_decode.o
 LIB=	libcoding.a
 
 all:	${LIB}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uptools/libcoding/gsmtime.c	Sun Feb 04 00:01:37 2018 +0000
@@ -0,0 +1,27 @@
+/*
+ * This library module implements decoding of GSM timestamps.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+
+gsm_timestamp_decode(inbuf, outbuf)
+	u_char *inbuf;
+	char *outbuf;
+{
+	u_char rev[7];
+	int i, d1, d2, tzsign;
+
+	for (i = 0; i < 7; i++) {
+		d1 = inbuf[i] & 0xF;
+		d2 = inbuf[i] >> 4;
+		rev[i] = (d1 << 4) | d2;
+	}
+	if (rev[6] & 0x80) {
+		rev[6] &= 0x7F;
+		tzsign = '-';
+	} else
+		tzsign = '+';
+	sprintf(outbuf, "%02X/%02X/%02X,%02X:%02X:%02X%c%02X", rev[0], rev[1],
+		rev[2], rev[3], rev[4], rev[5], tzsign, rev[6]);
+}