view src/g23m-aci/aci/ati_fcmisc.c @ 301:4bb5772a05a3

AT%SPVER: new command for setting custom speech version lists The speech version list in the Bearer Capability IE tells the network which speech codecs are supported by the MS, and in which order of preference. The standard behaviour is to list all codecs that are supported by the hw+fw platform, and the standard preference order is newer over older, FR over HR. But sometimes it is desirable (for network testing) to artificially restrict which codecs the test MS will declare as supported, and/or to list them in some peculiar non-standard order of preference. Add a new private AT command, AT%SPVER, allowing the user to set and clear custom speech version lists for the Bearer Capability IE composer in CC.
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 May 2023 21:43:10 +0000
parents 91e61d00a6b5
children d32ac4edb634
line wrap: on
line source

/*
 * This module implements miscellaneous FreeCalypso-added AT commands.
 */

#ifndef ATI_FCMISC_C
#define ATI_FCMISC_C

#include "aci_all.h"

#include <ctype.h>
#include <string.h>

#include "aci_cmh.h"
#include "ati_cmd.h"
#include "aci_cmd.h"
#include "aci_io.h"
#include "aci_cmd.h"
#include "l4_tim.h"
#include "line_edit.h"
#include "aci_lst.h"

#include "pcm.h"
#include "audio.h"
#include "aci.h"
#include "rx.h"
#include "pwr.h"
#include "l4_tim.h"

#ifdef GPRS
#ifdef DTI
#include "dti.h"
#include "dti_conn_mng.h"
#include "dti_cntrl_mng.h"
#endif /* DTI */
#include "gaci.h"
#include "gaci_cmh.h"
#include "gaci_cmd.h"
#endif  /* GPRS */

#include "aci_mem.h"
#include "aci_prs.h"

#include "ati_int.h"

#ifndef _SIMULATION_
#include "ffs/ffs.h"
#endif

#ifdef FF_ATI_BAT

#include "typedefs.h"
#include "gdd.h"
#include "bat.h"

#include "ati_bat.h"

#endif /*FF_ATI_BAT*/

#include "cl_user_spver.h"

#include "rv/rv_defined_swe.h"     /* for RVM_BUZM_SWE and RVM_VIBR_SWE */
#include "main/sys_types.h"
#include "fc-target.h"
#include "armio.h"

#ifdef RVM_BUZM_SWE
#include "buzm/buzm_api.h"
#endif

#ifdef RVM_VIBR_SWE
#include "vibr/vibr_api.h"
#endif

extern SYS_UWORD8 SIM_allow_speed_enhancement;

/* AT@SPENH - enable or disable SIM speed enhancement */
GLOBAL T_ATI_RSLT atAtSPENH ( char *cl, UBYTE srcId )
{
	int state, nonvol = 0;

	TRACE_FUNCTION("atAtSPENH()");

	cl = parse(cl, "Dd", &state, &nonvol);
	if (!cl)
		return (ATI_FAIL);
	if (state != 0 && state != 1)
		return (ATI_FAIL);
	SIM_allow_speed_enhancement = state;
	if (!nonvol)
		return (ATI_CMPL);
	ffs_mkdir("/etc");
	if (ffs_file_write("/etc/SIM_spenh", &SIM_allow_speed_enhancement, 1,
			   FFS_O_CREATE | FFS_O_TRUNC) == EFFS_OK)
		return (ATI_CMPL);
	else
		return (ATI_FAIL);
}

GLOBAL T_ATI_RSLT queatAtSPENH (char *cl, UBYTE srcId)
{
	char *me="@SPENH: ";

	TRACE_FUNCTION("queatAtSPENH()");

	sprintf(g_sa, "%s%u", me, SIM_allow_speed_enhancement);
	io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT);
	return (ATI_CMPL);
}

/* AT%SPVER - set custom speech version list */
GLOBAL T_ATI_RSLT atPercentSPVER (char *cl, UBYTE srcId)
{
	UBYTE spver_set;
	UBYTE spver_list[5] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
	UBYTE spver_rc;

	TRACE_FUNCTION("atPercentSPVER()");

	cl = parse(cl, "Xxxxxx", &spver_set, &spver_list[0], &spver_list[1],
		   &spver_list[2], &spver_list[3], &spver_list[4]);
	if (!cl)
		return (ATI_FAIL);
	switch (spver_set) {
	case CL_USER_SPVER_IS_NOT_SET:
		cl_user_spver_reset();
		return (ATI_CMPL);
	case CL_USER_SPVER_IS_SET:
		spver_rc = cl_user_spver_set(spver_list);
		if (spver_rc == CL_USER_SPVER_SET_OK)
			return (ATI_CMPL);
		else
			return (ATI_FAIL);
	default:
		return (ATI_FAIL);
	}
}

GLOBAL T_ATI_RSLT queatPercentSPVER (char *cl, UBYTE srcId)
{
	UBYTE spver_set, rad_chan_req;
	UBYTE spver_list[5], n, sv;
	char *me="%SPVER: ";
	char add[5];

	spver_set = cl_user_spver_get(spver_list, &rad_chan_req);
	sprintf(g_sa, "%s%u", me, spver_set);
	if (spver_set == CL_USER_SPVER_IS_SET) {
		for (n = 0; n < 5; n++) {
			sv = spver_list[n];
			if (sv == NOT_PRESENT_8BIT)
				break;
			sprintf(add, ",%u", sv);
			strcat(g_sa, add);
		}
	}
	io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT);
	return (ATI_CMPL);
}

#ifdef TARGET_HAS_LPG
/* AT@LPG - program LPG output */
GLOBAL T_ATI_RSLT atAtLPG ( char *cl, UBYTE srcId )
{
	unsigned glob, period = 0, ontime = 0;

	TRACE_FUNCTION("atAtLPG()");

	cl = parse(cl, "Ddd", &glob, &period, &ontime);
	if (!cl)
		return (ATI_FAIL);
	if (glob > 3 || period > 7 || ontime > 7)
		return (ATI_FAIL);
	*(volatile SYS_UWORD8 *)0xFFFE7801 = 0x01;
	*(volatile SYS_UWORD8 *)0xFFFE7800 =
					(glob << 6) | (ontime << 3) | period;
	return (ATI_CMPL);
}

GLOBAL T_ATI_RSLT queatAtLPG (char *cl, UBYTE srcId)
{
	char *me="@LPG: ";
	SYS_UWORD8 regval;
	unsigned glob, period, ontime;

	TRACE_FUNCTION("queatAtLPG()");

	regval = *(volatile SYS_UWORD8 *)0xFFFE7800;
	glob = (regval >> 6) & 3;
	ontime = (regval >> 3) & 7;
	period = regval & 7;
	sprintf(g_sa, "%s%u,%u,%u", me, glob, period, ontime);
	io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT);
	return (ATI_CMPL);
}
#endif	/* TARGET_HAS_LPG */

#ifdef TARGET_HAS_PWL
/* AT@PWL - program PWL output */
GLOBAL T_ATI_RSLT atAtPWL ( char *cl, UBYTE srcId )
{
	unsigned level;

	TRACE_FUNCTION("atAtPWL()");

	cl = parse(cl, "D", &level);
	if (!cl)
		return (ATI_FAIL);
	if (level > 255)
		return (ATI_FAIL);
	*(volatile SYS_UWORD8 *)0xFFFE8000 = level;
	*(volatile SYS_UWORD8 *)0xFFFE8001 = 0x01;
	return (ATI_CMPL);
}

GLOBAL T_ATI_RSLT queatAtPWL (char *cl, UBYTE srcId)
{
	char *me="@PWL: ";
	SYS_UWORD8 regval;

	TRACE_FUNCTION("queatAtPWL()");

	regval = *(volatile SYS_UWORD8 *)0xFFFE8000;
	sprintf(g_sa, "%s%u", me, regval);
	io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT);
	return (ATI_CMPL);
}
#endif	/* TARGET_HAS_PWL */

/* AT+IOR - read GPIO pin */
GLOBAL T_ATI_RSLT atPlusIOR (char *cl, UBYTE srcId)
{
	char *me="+IOR: ";
	unsigned ionum;
	int state;

	TRACE_FUNCTION("atPlusIOR()");

	cl = parse(cl, "D", &ionum);
	if (!cl)
		return (ATI_FAIL);
	if (ionum > 13)
		return (ATI_FAIL);
	state = AI_ReadBit(ionum);
	sprintf(g_sa, "%s%u,%d", me, ionum, state);
	io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT);
	return (ATI_CMPL);
}

/* AT+IOW - set GPIO pin */
GLOBAL T_ATI_RSLT atPlusIOW (char *cl, UBYTE srcId)
{
	unsigned ionum;
	int state;

	TRACE_FUNCTION("atPlusIOW()");

	cl = parse(cl, "DD", &ionum, &state);
	if (!cl)
		return (ATI_FAIL);
	if (ionum > 13)
		return (ATI_FAIL);
	if (state)
		AI_SetBit(ionum);
	else
		AI_ResetBit(ionum);
	return (ATI_CMPL);
}

#ifdef RVM_BUZM_SWE
/* AT@BUZ - play a buzzer melody */
GLOBAL T_ATI_RSLT atAtBUZ ( char *cl, UBYTE srcId )
{
	char melody_name[20];
	int play_volume = BUZM_VOLUME_MAX;
	int loopback = 0;

	cl = parse(cl, "Sdd", (LONG)(sizeof(melody_name)), melody_name,
		   &play_volume, &loopback);
	if (!cl || !melody_name[0])
		return (ATI_FAIL);
	if (buzm_play_melody(melody_name, play_volume, loopback) == RV_OK)
		return (ATI_CMPL);
	else
		return (ATI_FAIL);
}

/* AT@BZSTOP - stop melody started with AT@BUZ */
GLOBAL T_ATI_RSLT atAtBZSTOP ( char *cl, UBYTE srcId )
{
	if (buzm_stop_melody() == RV_OK)
		return (ATI_CMPL);
	else
		return (ATI_FAIL);
}
#endif

#ifdef RVM_VIBR_SWE
/* AT@VIBR - run the vibrator by way of VIBR SWE */
GLOBAL T_ATI_RSLT atAtVIBR ( char *cl, UBYTE srcId )
{
	int num_pulses = VIBR_INFINITE;
	int vibr_level = VIBR_LEVEL_MAX;

	cl = parse(cl, "dd", &num_pulses, &vibr_level);
	if (!cl)
		return (ATI_FAIL);
	if (vibr_pulse_train_start(num_pulses, vibr_level) == RV_OK)
		return (ATI_CMPL);
	else
		return (ATI_FAIL);
}

/* AT@VIBS - stop vibration that was started with AT@VIBR */
GLOBAL T_ATI_RSLT atAtVIBS ( char *cl, UBYTE srcId )
{
	if (vibr_pulse_train_stop() == RV_OK)
		return (ATI_CMPL);
	else
		return (ATI_FAIL);
}
#endif

#endif /* ATI_FCMISC_C */