KETCube
Macros | Functions | Variables
ketCube_remote_terminal.c File Reference

This file contains the KETCube remote terminal. More...

#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include "utilities.h"
#include "ketCube_remote_terminal.h"

Macros

#define KETCUBE_REMOTE_TERMINAL_BUF_SIZE   64
 

Functions

static void ketCube_remoteTerminal_sendError (ketCube_terminal_command_errorCode_t err, char **response, int *responseLen)
 Appends error output to command response buffer. More...
 
static void ketCube_remoteTerminal_tryExecuteCmd (ketCube_terminal_cmd_t *cmd, ketCube_terminal_command_flags_t activeFlags, char *paramBuf, int bufLen, char **responseTarget, int *responseLen)
 After validating context, this function executes commands, if parameters are correct and the command could be executed. More...
 
int ketCube_remoteTerminal_deferCmd (char *bytes, int len, ketCube_remoteTerminal_responseFnc_t respFnc)
 Defers command to be processed outside radio IRQ context (in the next base period) More...
 
static int ketCube_remoteTerminal_processCmd (char *startItr, int len, char **response, int *responseLen, ketCube_remoteTerminal_packet_header_t *inHdr, ketCube_remoteTerminal_single_cmd_header_t *cmdHdr)
 Processes a command from byte buffer. More...
 
static int ketCube_remoteTerminal_processSingleCmd (char *startItr, int len, char **response, int *responseLen, ketCube_remoteTerminal_packet_header_t *inHdr)
 Processes single command from buffer (single cmd opcode) More...
 
int ketCube_remoteTerminal_processCommandBatch (char *cmdBuf, int length, char **response, int *responseLen, ketCube_remoteTerminal_packet_header_t *inHdr)
 Processes command batch from buffer (command batch opcode) More...
 
int ketCube_remoteTerminal_processDeferredCmd (char **response, int *responseLen)
 Processes deferred command, if any. More...
 
void ketCube_remoteTerminal_ProcessCMD (void)
 Interface function - process deferred command, if any. More...
 

Variables

static char deferCmdBuf [KETCUBE_REMOTE_TERMINAL_BUF_SIZE]
 
static int deferCmdBufLen = 0
 
static bool isCmdDefered = FALSE
 
static char responseBuf [KETCUBE_REMOTE_TERMINAL_BUF_SIZE]
 
static ketCube_remoteTerminal_responseFnc_t responseFnc
 

Detailed Description

This file contains the KETCube remote terminal.

Author
Martin Ubl
Version
0.1
Date
2019-03-30
Attention

© Copyright (c) 2018 University of West Bohemia in Pilsen All rights reserved.

Developed by: The SmartCampus Team Department of Technologies and Measurement www.smartcampus.cz | www.zcu.cz

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.

Macro Definition Documentation

◆ KETCUBE_REMOTE_TERMINAL_BUF_SIZE

#define KETCUBE_REMOTE_TERMINAL_BUF_SIZE   64

Function Documentation

◆ ketCube_remoteTerminal_deferCmd()

int ketCube_remoteTerminal_deferCmd ( char *  bytes,
int  len,
ketCube_remoteTerminal_responseFnc_t  respFnc 
)

Defers command to be processed outside radio IRQ context (in the next base period)

Parameters
bytesincoming bytes pointer
lenincoming bytes count
respFncresponse function pointer to use for response

◆ ketCube_remoteTerminal_processCmd()

static int ketCube_remoteTerminal_processCmd ( char *  startItr,
int  len,
char **  response,
int *  responseLen,
ketCube_remoteTerminal_packet_header_t inHdr,
ketCube_remoteTerminal_single_cmd_header_t cmdHdr 
)
static

Processes a command from byte buffer.

Parameters
startItrstart pointer (where the actual command block begins)
lenlength of command block in bytes
responsepointer to response buffer (iterator; will be modified)
responseLencurrent response buffer length (will be modified)

◆ ketCube_remoteTerminal_ProcessCMD()

void ketCube_remoteTerminal_ProcessCMD ( void  )

Interface function - process deferred command, if any.

◆ ketCube_remoteTerminal_processCommandBatch()

int ketCube_remoteTerminal_processCommandBatch ( char *  cmdBuf,
int  length,
char **  response,
int *  responseLen,
ketCube_remoteTerminal_packet_header_t inHdr 
)

Processes command batch from buffer (command batch opcode)

Parameters
cmdBufstart pointer (where the actual command block begins)
lengthlength of command block in bytes
responsepointer to response buffer (iterator; will be modified)
responseLencurrent response buffer length (will be modified)

◆ ketCube_remoteTerminal_processDeferredCmd()

int ketCube_remoteTerminal_processDeferredCmd ( char **  response,
int *  responseLen 
)

Processes deferred command, if any.

Parameters
responsepointer to response buffer (will be filled with actual address)
responseLenwhere to put response length

◆ ketCube_remoteTerminal_processSingleCmd()

static int ketCube_remoteTerminal_processSingleCmd ( char *  startItr,
int  len,
char **  response,
int *  responseLen,
ketCube_remoteTerminal_packet_header_t inHdr 
)
static

Processes single command from buffer (single cmd opcode)

Parameters
startItrstart pointer (where the actual command block begins)
lenlength of command block in bytes
responsepointer to response buffer (iterator; will be modified)
responseLencurrent response buffer length (will be modified)

◆ ketCube_remoteTerminal_sendError()

static void ketCube_remoteTerminal_sendError ( ketCube_terminal_command_errorCode_t  err,
char **  response,
int *  responseLen 
)
static

Appends error output to command response buffer.

Parameters
errerror code
responsepointer to response buffer (iterator; will be modified)
responseLencurrent response buffer length (will be modified)

◆ ketCube_remoteTerminal_tryExecuteCmd()

static void ketCube_remoteTerminal_tryExecuteCmd ( ketCube_terminal_cmd_t cmd,
ketCube_terminal_command_flags_t  activeFlags,
char *  paramBuf,
int  bufLen,
char **  responseTarget,
int *  responseLen 
)
static

After validating context, this function executes commands, if parameters are correct and the command could be executed.

Parameters
cmdcommand pointer
activeFlagscurrently used flags
paramBufremaining command bytes pointer (contains parameters)
bufLenremaining command bytes buffer length (not necesarilly exclusive)
responseTargetpointer to response buffer (iterator; will be modified)
responseLencurrent response buffer length (will be modified)

Variable Documentation

◆ deferCmdBuf

char deferCmdBuf[KETCUBE_REMOTE_TERMINAL_BUF_SIZE]
static

◆ deferCmdBufLen

int deferCmdBufLen = 0
static

◆ isCmdDefered

bool isCmdDefered = FALSE
static

◆ responseBuf

char responseBuf[KETCUBE_REMOTE_TERMINAL_BUF_SIZE]
static

◆ responseFnc