Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Take-Home-Test Server

(Accelerometer data server)

Prerequisites

To build and run this program you will need to install basic build essentials (compiler, etc) and cmake. There is nothing fancy used in the "C" source or build system so anything fairly recent will do.

The code was built and tested on an Apple Macbook Pro M1 running Tahoe 26.5.2 using Xcode commandline tools and cmake version 4.3.4 (but anything after 3.20.x should work).

Apple clang version 21.0.0 (clang-2100.0.123.102)
Target: arm64-apple-darwin25.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

The code should be buildable directly on any Unixy like system like Linux but that has not been tested. Primarily the timer code is different for Linux and might need some fixing up to work properly.

Building

Get the source from git

git clone git@github.com:bdodge/thtest_client.git

Move to the thtest_client directory and run the script

./buildme.sh

Or, to build the debug version

./buildme.sh debug

Alternatively, you can just run cmake directly

mkdir ./build
cmake -B build . -DCMAKE_BUILD_TYPE=Debug
cmake --build build

Build Options

There are a few manifests that control details of server configuration. The are listed and documented in th_test.h in the src directory. The most important ones are

  • DEBUG - indicated debug features should be included if defined
  • TH_SMOOTH_SAMPLES - when set to non-0, the server will set the "filter" flag in the accelerometer control register

Running

To run the program simply

./build/thtest

The program waits for a client TCP connection on port 5678 and then waits on the TCP connection for commands to start / etc. Once started, simulated accelerometer data is sent up to the client in CSV format:

where m is the magnitude of <x,y,z>

TCP Protcol

This server reads client data from the TCP connection and understands the following commands:

  • start start data production
  • stop stop data production

Also, if any of the control characters ^C or ^D (or EOF 0xff) are received, the server will stop production and close the client connection.

When producing data, the data is sent up the TCP connection in CSV format:

n,x,y,z,m

Where

  • n is the sample sequence number in unsigned decimal format
  • x,y,x are the accelerometer readings in Q16.16 format (decimal)
  • m is the magnitude (sqrt(x^2+y^2+z^2) in Q16.16 format (decimal)

Testing

A simple way to test the server is run it (see Running above) and then in another terminal window

telnet localhost 5678

Then when connected type into the telnet terminal start and you should see formatted data as described in TCP Protcol above

You can then hit ^C or type stop and enter to stop

Unit-Testing

The debug build has built-in unit tests which are run when the program starts. Just build the debug version and run it.

Enhancements

A command line parser could be made to parse options to make testing easier

Examples are:

  • a switch to set the port the server listens on
  • a switch to control accelerometer data filtering on/off and level
  • a switch to allow dumping of raw data for debug

About

server component for thtest

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages