Loggy_McLogger/Core/Src/testmode.c
2024-06-24 20:13:52 -05:00

131 lines
2.5 KiB
C

/**
*********************************************************************
*
* @file testmode.c
* @brief
*
* @date 2024-04-14 13:31:47
* @author CT
*
* @details Provides control of GPIO and communication bus's to evaluate board design
* Commands available:
* Enable/Disable PWR_HOLDUP output
* Enable/Disable SD_PWR_EN output
* Enable/Disable Radio_Wake output
* Enable/Disable LED output
* Enable/Disable RAM_CE output
* Enable/Disable SD_CE output
* Read BAT_V analog counts
* Read temperature from SHT40
* Read relative humidity from SHT40
* Write arbitrary byte to external RAM
* Read arbitrary address from external RAM
*
*************************************************************************
**/
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "data_table.h"
#include "testmode.h"
/*
* Interface:
* Command line style <COMMAND> <FLAGS> <ARGUMENTS>
* COMMAND: single byte
* FLAGS: dash then single byte space separated modifiers
* ARGUMENTS: variable length additional data for specific command
* Example: Set LED high
* W -1 3
*/
/*
* Command parser
* Expects to be passed a single line stripped of EOL chars and null terminated
*/
void command_parser(char* input, uint32_t len)
{
uint32_t flags[8] = {0};
uint32_t flag_index = 0;
uint32_t args[64] = {0};
uint32_t args_index = 0;
bool next_is_flag = false;
bool next_is_arg = false;
if(0x00 == input[0])
{
return;
}
uint8_t command = input[0];
for(uint32_t i = 1; i < len; i++)
{
if('-' == input[i])
{
next_is_flag = true;
}
else if(next_is_flag)
{
flags[flag_index++] = input[i];
next_is_flag = false;
}
else if(' ' == input[i])
{
next_is_arg = true;
}
else if(next_is_arg)
{
args[args_index++] = input[i];
next_is_arg = false;
}
}
command_executor(command, flags, args);
}
/*
* Executor
* Takes the command, flags, and arguments and executes the command
* Uses first flag and first arg only
* TODO: expand to take multiple args
*/
void command_executor(uint8_t cmd, uint32_t* flags, uint32_t* args)
{
switch (cmd)
{
case TESTMODE_READ:
// Read ignores flags
switch (args[0])
{
case TESTMODE_PWR_HOLDEUP:
report(app_get_pwr_holdup());
break;
default:
break;
}
break;
case TESTMODE_WRITE:
break;
default:
break;
}
}
/*
Reports back the output of the last command
*/
void report(uint32_t val)
{
}