Skip to content
Snippets Groups Projects
aci_test_sound.c 7.5 KiB
Newer Older
/**
 * Copyright 2023
 * 
 * Bernd-Christian Renner, and
 * Hamburg University of Technology (TUHH).
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "aci.h"
#include "aci/types/test_sound_cmd.h"
#include "aci_test_sound.h"

#include <hal_adda.h>


/**************************************************************************
 * private prototypes
 */


/**************************************************************************
 * variables
 */

/*
 * This file was auto-generated by genFsk.py for the range 4500:1000:4500 Hz
*/

Bernd-Christian Renner's avatar
Bernd-Christian Renner committed
static const fp16_t FREQ_TEST_SOUND[TX_SAMPLES_PER_SYMBOL] = {
  0x0000, 0x0964, 0x1294, 0x1b5d, 0x238e, 0x2afa, 0x3179, 0x36e5,
  0x3b20, 0x3e14, 0x3fb1, 0x3fec, 0x3ec5, 0x3c42, 0x3871, 0x3367,
  0x2d41, 0x261f, 0x1e2b, 0x158f, 0x0c7c, 0x0323, 0xf9bb, 0xf074,
  0xe783, 0xdf19, 0xd767, 0xd095, 0xcaca, 0xc626, 0xc2c2, 0xc0b2,
  0xc000, 0xc0b2, 0xc2c2, 0xc626, 0xcaca, 0xd095, 0xd767, 0xdf19,
  0xe783, 0xf074, 0xf9bb, 0x0323, 0x0c7c, 0x158f, 0x1e2b, 0x261f,
  0x2d41, 0x3367, 0x3871, 0x3c42, 0x3ec5, 0x3fec, 0x3fb1, 0x3e14,
  0x3b20, 0x36e5, 0x3179, 0x2afa, 0x238e, 0x1b5d, 0x1294, 0x0964,
  0x0000, 0xf69c, 0xed6c, 0xe4a3, 0xdc72, 0xd506, 0xce87, 0xc91b,
  0xc4e0, 0xc1ec, 0xc04f, 0xc014, 0xc13b, 0xc3be, 0xc78f, 0xcc99,
  0xd2bf, 0xd9e1, 0xe1d5, 0xea71, 0xf384, 0xfcdd, 0x0645, 0x0f8c,
  0x187d, 0x20e7, 0x2899, 0x2f6b, 0x3536, 0x39da, 0x3d3e, 0x3f4e,
  0x4000, 0x3f4e, 0x3d3e, 0x39da, 0x3536, 0x2f6b, 0x2899, 0x20e7,
  0x187d, 0x0f8c, 0x0645, 0xfcdd, 0xf384, 0xea71, 0xe1d5, 0xd9e1,
  0xd2bf, 0xcc99, 0xc78f, 0xc3be, 0xc13b, 0xc014, 0xc04f, 0xc1ec,
  0xc4e0, 0xc91b, 0xce87, 0xd506, 0xdc72, 0xe4a3, 0xed6c, 0xf69c,
  0x0000, 0x0964, 0x1294, 0x1b5d, 0x238e, 0x2afa, 0x3179, 0x36e5,
  0x3b20, 0x3e14, 0x3fb1, 0x3fec, 0x3ec5, 0x3c42, 0x3871, 0x3367,
  0x2d41, 0x261f, 0x1e2b, 0x158f, 0x0c7c, 0x0323, 0xf9bb, 0xf074,
  0xe783, 0xdf19, 0xd767, 0xd095, 0xcaca, 0xc626, 0xc2c2, 0xc0b2,
  0xc000, 0xc0b2, 0xc2c2, 0xc626, 0xcaca, 0xd095, 0xd767, 0xdf19,
  0xe783, 0xf074, 0xf9bb, 0x0323, 0x0c7c, 0x158f, 0x1e2b, 0x261f,
  0x2d41, 0x3367, 0x3871, 0x3c42, 0x3ec5, 0x3fec, 0x3fb1, 0x3e14,
  0x3b20, 0x36e5, 0x3179, 0x2afa, 0x238e, 0x1b5d, 0x1294, 0x0964,
  0x0000, 0xf69c, 0xed6c, 0xe4a3, 0xdc72, 0xd506, 0xce87, 0xc91b,
  0xc4e0, 0xc1ec, 0xc04f, 0xc014, 0xc13b, 0xc3be, 0xc78f, 0xcc99,
  0xd2bf, 0xd9e1, 0xe1d5, 0xea71, 0xf384, 0xfcdd, 0x0645, 0x0f8c,
  0x187d, 0x20e7, 0x2899, 0x2f6b, 0x3536, 0x39da, 0x3d3e, 0x3f4e,
  0x4000, 0x3f4e, 0x3d3e, 0x39da, 0x3536, 0x2f6b, 0x2899, 0x20e7,
  0x187d, 0x0f8c, 0x0645, 0xfcdd, 0xf384, 0xea71, 0xe1d5, 0xd9e1,
  0xd2bf, 0xcc99, 0xc78f, 0xc3be, 0xc13b, 0xc014, 0xc04f, 0xc1ec,
  0xc4e0, 0xc91b, 0xce87, 0xd506, 0xdc72, 0xe4a3, 0xed6c, 0xf69c,
  0x0000, 0x0964, 0x1294, 0x1b5d, 0x238e, 0x2afa, 0x3179, 0x36e5,
  0x3b20, 0x3e14, 0x3fb1, 0x3fec, 0x3ec5, 0x3c42, 0x3871, 0x3367,
  0x2d41, 0x261f, 0x1e2b, 0x158f, 0x0c7c, 0x0323, 0xf9bb, 0xf074,
  0xe783, 0xdf19, 0xd767, 0xd095, 0xcaca, 0xc626, 0xc2c2, 0xc0b2,
  0xc000, 0xc0b2, 0xc2c2, 0xc626, 0xcaca, 0xd095, 0xd767, 0xdf19,
  0xe783, 0xf074, 0xf9bb, 0x0323, 0x0c7c, 0x158f, 0x1e2b, 0x261f,
  0x2d41, 0x3367, 0x3871, 0x3c42, 0x3ec5, 0x3fec, 0x3fb1, 0x3e14,
  0x3b20, 0x36e5, 0x3179, 0x2afa, 0x238e, 0x1b5d, 0x1294, 0x0964,
  0x0000, 0xf69c, 0xed6c, 0xe4a3, 0xdc72, 0xd506, 0xce87, 0xc91b,
  0xc4e0, 0xc1ec, 0xc04f, 0xc014, 0xc13b, 0xc3be, 0xc78f, 0xcc99,
  0xd2bf, 0xd9e1, 0xe1d5, 0xea71, 0xf384, 0xfcdd, 0x0645, 0x0f8c,
  0x187d, 0x20e7, 0x2899, 0x2f6b, 0x3536, 0x39da, 0x3d3e, 0x3f4e,
  0x4000, 0x3f4e, 0x3d3e, 0x39da, 0x3536, 0x2f6b, 0x2899, 0x20e7,
  0x187d, 0x0f8c, 0x0645, 0xfcdd, 0xf384, 0xea71, 0xe1d5, 0xd9e1,
  0xd2bf, 0xcc99, 0xc78f, 0xc3be, 0xc13b, 0xc014, 0xc04f, 0xc1ec,
  0xc4e0, 0xc91b, 0xce87, 0xd506, 0xdc72, 0xe4a3, 0xed6c, 0xf69c,
  0x0000, 0x0964, 0x1294, 0x1b5d, 0x238e, 0x2afa, 0x3179, 0x36e5,
  0x3b20, 0x3e14, 0x3fb1, 0x3fec, 0x3ec5, 0x3c42, 0x3871, 0x3367,
  0x2d41, 0x261f, 0x1e2b, 0x158f, 0x0c7c, 0x0323, 0xf9bb, 0xf074,
  0xe783, 0xdf19, 0xd767, 0xd095, 0xcaca, 0xc626, 0xc2c2, 0xc0b2,
  0xc000, 0xc0b2, 0xc2c2, 0xc626, 0xcaca, 0xd095, 0xd767, 0xdf19,
  0xe783, 0xf074, 0xf9bb, 0x0323, 0x0c7c, 0x158f, 0x1e2b, 0x261f,
  0x2d41, 0x3367, 0x3871, 0x3c42, 0x3ec5, 0x3fec, 0x3fb1, 0x3e14,
  0x3b20, 0x36e5, 0x3179, 0x2afa, 0x238e, 0x1b5d, 0x1294, 0x0964,
  0x0000, 0xf69c, 0xed6c, 0xe4a3, 0xdc72, 0xd506, 0xce87, 0xc91b,
  0xc4e0, 0xc1ec, 0xc04f, 0xc014, 0xc13b, 0xc3be, 0xc78f, 0xcc99,
  0xd2bf, 0xd9e1, 0xe1d5, 0xea71, 0xf384, 0xfcdd, 0x0645, 0x0f8c,
  0x187d, 0x20e7, 0x2899, 0x2f6b, 0x3536, 0x39da, 0x3d3e, 0x3f4e,
  0x4000, 0x3f4e, 0x3d3e, 0x39da, 0x3536, 0x2f6b, 0x2899, 0x20e7,
  0x187d, 0x0f8c, 0x0645, 0xfcdd, 0xf384, 0xea71, 0xe1d5, 0xd9e1,
  0xd2bf, 0xcc99, 0xc78f, 0xc3be, 0xc13b, 0xc014, 0xc04f, 0xc1ec,
  0xc4e0, 0xc91b, 0xce87, 0xd506, 0xdc72, 0xe4a3, 0xed6c, 0xf69c };



/**************************************************************************
 * private functions
 */

// determine number of symbols from duration in ms, round to nearest
Bernd-Christian Renner's avatar
Bernd-Christian Renner committed
#define MS_TO_TX_SYMBOLS(t)  ((MS_TO_TICKS(t) + TX_SAMPLES_PER_SYMBOL / 2) / TX_SAMPLES_PER_SYMBOL)


/**************************************************************************
 * public functions
 */

aci_test_sound_processCmd(const mm_packet_t * pkt)
{
  uint16_t  i, j;
  uint16_t  dur;
  aci_test_sound_cmd_t * p = (aci_test_sound_cmd_t *)pkt->payload;
  
  // sanity check
  if (pkt->header.len != sizeof(aci_test_sound_cmd_t)) {
Bernd-Christian Renner's avatar
Bernd-Christian Renner committed
  dur = MS_TO_TX_SYMBOLS(10 * p->dur);  // p->dur in 1/100 ms
  if (dur < MS_TO_TX_SYMBOLS(10)) {
    dur = MS_TO_TX_SYMBOLS(10);
  } else if (dur > MS_TO_TX_SYMBOLS(2500)) {
    dur = MS_TO_TX_SYMBOLS(2500);
  }

  // init tx mode
  adda_activateTransmission();

  // repeat symbol to match duration
  for (j = 0; j < dur; j++) {
Bernd-Christian Renner's avatar
Bernd-Christian Renner committed
    for (i = 0; i < TX_SAMPLES_PER_SYMBOL; i++) {
      adda_setSample(FREQ_TEST_SOUND[i]);
    }
  }
  
  adda_setNeutralSample();
  
  // wait until transmitter runs out of samples
  while (adda_hasSample()) {
    ;
  }

  // return to rx mode
  adda_activateSampling();
}



uint8_t
aci_test_sound_fillReply(uint8_t * payload)
{
  return 0;
}