Skip to content

Commit

Permalink
Rover Project CLI
Browse files Browse the repository at this point in the history
First working version of rower project
  • Loading branch information
adamkaliszan committed Sep 18, 2019
1 parent 67a3dec commit b198b6c
Show file tree
Hide file tree
Showing 17 changed files with 214 additions and 169 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ dkms.conf
Projects/AtXmega/DvrController.X/nbproject/private/

Projects/AtXmega/RoverController.X/nbproject/private/

*.eep
39 changes: 19 additions & 20 deletions Lib/include/tlvProt.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
#endif // TLV_BUF_LEN


struct tlvInterpreter;
struct TlvInterpreter;

typedef struct tlvInterpreter tlvInterpreter_t;
typedef struct TlvInterpreter TlvInterpreter_t;

typedef struct tlvMsg
typedef struct TlvMsg
{
uint8_t sync; // = TLV_SYNC
uint8_t address; // Device address
Expand All @@ -37,35 +37,34 @@ typedef struct tlvMsg
uint8_t crcLo;
uint8_t crcHi;
uint8_t data[0];
} tlvMsg_t;
} TlvMsg_t;


typedef struct tlvCommand
typedef struct TlvCommand
{
uint8_t type;
void (*fun)(tlvInterpreter_t *tlvInt, tlvMsg_t *myTlvMsg);
} tlvCommand_t;
void (*fun)(TlvInterpreter_t *tlvInt, TlvMsg_t *myTlvMsg);
} TlvCommand_t;

struct tlvInterpreter
struct TlvInterpreter
{
uint8_t buffer[TLV_BUF_LEN];
uint8_t bufIdx;
const tlvCommand_t *commands;
uint8_t noOfCmds;
uint8_t buffer[TLV_BUF_LEN];
uint8_t bufIdx;
const TlvCommand_t *commands;
uint8_t noOfCmds;
FILE *ioStr;
FILE *errStr;
};

void tlvIinitializeInterpreter(tlvInterpreter_t *tlvInt, FILE *ioStr, FILE *errStr, const tlvCommand_t *commands);
void tlvIinitializeInterpreter(TlvInterpreter_t *tlvInt, FILE *ioStr, FILE *errStr, const TlvCommand_t *commands);

void tlvCalculateCrc(tlvMsg_t *message);
void tlvCalculateCrcSepDta(tlvMsg_t *message, const uint8_t dta[]);
void tlvCalculateCrc(TlvMsg_t *message);
void tlvCalculateCrcSepDta(TlvMsg_t *message, const uint8_t dta[]);

uint8_t tlvCheckCrc(tlvMsg_t *message);

void tlvProcessDta(tlvInterpreter_t *tlvInt, uint8_t dta);
void sendTlvMsg(tlvMsg_t *message, FILE *ostream);
void sendTlvMsgDta(tlvMsg_t *message, const uint8_t const *msgDta, FILE *ostream);
uint8_t tlvCheckCrc(TlvMsg_t *message);

void tlvProcessDta(TlvInterpreter_t *tlvInt, uint8_t dta);
void sendTlvMsg(TlvMsg_t *message, FILE *ostream);
void sendTlvMsgDta(TlvMsg_t *message, const uint8_t const *msgDta, FILE *ostream);

#endif
73 changes: 53 additions & 20 deletions Lib/tlvProt.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <string.h>

#include "tlvProt.h"

void tlvIinitializeInterpreter(tlvInterpreter_t *tlvInt, FILE *ioStr, FILE *errStr, const tlvCommand_t *commands)
void tlvIinitializeInterpreter(TlvInterpreter_t *tlvInt, FILE *ioStr, FILE *errStr, const TlvCommand_t *commands)
{
tlvCommand_t tmpCmd;
memset(tlvInt, 0, sizeof(struct tlvInterpreter));
TlvCommand_t tmpCmd;
memset(tlvInt, 0, sizeof(struct TlvInterpreter));

tlvInt->ioStr = ioStr;
tlvInt->errStr = errStr;
Expand All @@ -12,14 +14,18 @@ void tlvIinitializeInterpreter(tlvInterpreter_t *tlvInt, FILE *ioStr, FILE *errS
tlvInt->noOfCmds = -1;
do
{
memcpy_P(&tmpCmd, commands, sizeof(tlvCommand_t));
#if USE_XC8
memcpy(&tmpCmd, commands, sizeof(TlvCommand_t));
#else
memcpy_P(&tmpCmd, commands, sizeof(TlvCommand_t));
#endif
tlvInt->noOfCmds++;
commands++;
}
while(tmpCmd.type != 0);
}

void tlvCalculateCrc(tlvMsg_t *message)
void tlvCalculateCrc(TlvMsg_t *message)
{
uint16_t crc;
crc = _crc16_update(0, message->address);
Expand All @@ -34,7 +40,7 @@ void tlvCalculateCrc(tlvMsg_t *message)
message->crcHi = (uint8_t) crc>>8;
}

void tlvCalculateCrcSepDta(tlvMsg_t *message, const uint8_t dta[])
void tlvCalculateCrcSepDta(TlvMsg_t *message, const uint8_t dta[])
{
uint16_t crc;
crc = _crc16_update(0, message->address);
Expand All @@ -49,7 +55,7 @@ void tlvCalculateCrcSepDta(tlvMsg_t *message, const uint8_t dta[])
message->crcHi = (uint8_t) crc>>8;
}

uint8_t tlvCheckCrc(tlvMsg_t *message)
uint8_t tlvCheckCrc(TlvMsg_t *message)
{
uint16_t crc;
crc = _crc16_update(0, message->address);
Expand All @@ -72,14 +78,18 @@ uint8_t tlvCheckCrc(tlvMsg_t *message)
return 1;
}

void tlvProcessDta(tlvInterpreter_t *tlvInt, uint8_t dta)
void tlvProcessDta(TlvInterpreter_t *tlvInt, uint8_t dta)
{
uint8_t i, j;
struct tlvMsg *myRecMsg = (struct tlvMsg *)tlvInt->buffer;
struct TlvMsg *myRecMsg = (struct TlvMsg *)(tlvInt->buffer);

if (tlvInt->bufIdx >= TLV_BUF_LEN)
{
#ifdef USE_XC8
fprintf(tlvInt->errStr, "# TLV buffer overflow");
#else
fprintf_P(tlvInt->errStr, PSTR("# TLV buffer overflow"));
#endif
tlvInt->bufIdx = 0;
}

Expand All @@ -89,14 +99,27 @@ void tlvProcessDta(tlvInterpreter_t *tlvInt, uint8_t dta)
tlvInt->buffer[tlvInt->bufIdx] = dta;
tlvInt->bufIdx++;

if (tlvInt->bufIdx < sizeof(struct tlvMsg))
if (tlvInt->bufIdx < sizeof(struct TlvMsg))
return;

if (tlvInt->bufIdx < myRecMsg->dtaLen + sizeof(struct tlvMsg))
if (tlvInt->bufIdx < myRecMsg->dtaLen + sizeof(struct TlvMsg))
return;

if (tlvCheckCrc(myRecMsg) == 0)
{
#ifdef USE_XC8
fprintf(tlvInt->errStr, "# CRC mismatch: buffer idx %d\r\n", tlvInt->bufIdx);
fprintf(tlvInt->errStr, "\taddress : %x\r\n", myRecMsg->address);
fprintf(tlvInt->errStr, "\tmsg type : %x\r\n", myRecMsg->type);
fprintf(tlvInt->errStr, "\tcrc lo : %x\r\n", myRecMsg->crcLo);
fprintf(tlvInt->errStr, "\tcrc hi : %x\r\n", myRecMsg->crcHi);
fprintf(tlvInt->errStr, "\tdta len : %x\r\n", myRecMsg->dtaLen);

fprintf(tlvInt->errStr, "\tdata:");
for(i=sizeof(struct TlvMsg); i<tlvInt->bufIdx; i++)
fprintf(tlvInt->errStr, " %2x", tlvInt->buffer[i]);
fprintf(tlvInt->errStr, "\r\n");
#else
fprintf_P(tlvInt->errStr, PSTR("# CRC mismatch: buffer idx %d\r\n"), tlvInt->bufIdx);
fprintf_P(tlvInt->errStr, PSTR("\taddress : %x\r\n"), myRecMsg->address);
fprintf_P(tlvInt->errStr, PSTR("\tmsg type : %x\r\n"), myRecMsg->type);
Expand All @@ -105,10 +128,10 @@ void tlvProcessDta(tlvInterpreter_t *tlvInt, uint8_t dta)
fprintf_P(tlvInt->errStr, PSTR("\tdta len : %x\r\n"), myRecMsg->dtaLen);

fprintf_P(tlvInt->errStr, PSTR("\tdata:"));
for(i=sizeof(struct tlvMsg); i<tlvInt->bufIdx; i++)
for(i=sizeof(struct TlvMsg); i<tlvInt->bufIdx; i++)
fprintf_P(tlvInt->errStr, PSTR(" %2x"), tlvInt->buffer[i]);
fprintf_P(tlvInt->errStr, PSTR("\r\n"));

#endif
for (i=1; i<tlvInt->bufIdx; i++)
{
if (tlvInt->buffer[i] == TLV_SYNC)
Expand All @@ -124,28 +147,38 @@ void tlvProcessDta(tlvInterpreter_t *tlvInt, uint8_t dta)
return;
}

tlvCommand_t tmp; // We need to create this object. We can't directly
TlvCommand_t tmp; // We need to create this object. We can't directly
for (i=0; i<tlvInt->noOfCmds; i++)
{
memcpy_P(&tmp, &tlvInt->commands[i], sizeof(tlvCommand_t));
#if USE_XC8
memcpy(&tmp, &tlvInt->commands[i], sizeof(TlvCommand_t));
#else
memcpy_P(&tmp, &tlvInt->commands[i], sizeof(TlvCommand_t));
#endif
if (myRecMsg->type == tmp.type)
{
tmp.fun(tlvInt, myRecMsg);
break;
}
}
#if USE_XC8
if (i == tlvInt->noOfCmds)
fprintf(tlvInt->errStr, "! Unknown command: %d\r\n", myRecMsg->type);
else
fprintf(tlvInt->errStr, "TLV command %x was executed\r\n", myRecMsg->type);
#else
if (i == tlvInt->noOfCmds)
fprintf_P(tlvInt->errStr, PSTR("! Unknown command: %d\r\n"), myRecMsg->type);
else
fprintf_P(tlvInt->errStr, PSTR("TLV command %x was executed\r\n"), myRecMsg->type);

#endif
tlvInt->bufIdx = 0;
}

void sendTlvMsg(tlvMsg_t *message, FILE *ostream)
void sendTlvMsg(TlvMsg_t *message, FILE *ostream)
{
int i, len;
len = sizeof(struct tlvMsg) + message->dtaLen;
len = sizeof(struct TlvMsg) + message->dtaLen;
uint8_t *ptr = (uint8_t *) message;

for (i=0; i<len; i++)
Expand All @@ -155,10 +188,10 @@ void sendTlvMsg(tlvMsg_t *message, FILE *ostream)
}
}

void sendTlvMsgDta(tlvMsg_t *message, const uint8_t const *msgDta, FILE *ostream)
void sendTlvMsgDta(TlvMsg_t *message, const uint8_t const *msgDta, FILE *ostream)
{
int i, len;
len = sizeof(struct tlvMsg);
len = sizeof(struct TlvMsg);
uint8_t const *ptr = (uint8_t *) message;

for (i=0; i<len; i++)
Expand Down
4 changes: 4 additions & 0 deletions Projects/AtXmega/RoverController.X/cli_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
void vTaskVTYusb(void *cliStatePtr)
{
cmdState_t *state = (cmdState_t *)(cliStatePtr);
#ifdef USE_XC8
fprintf_P(state->myStdInOut, PSTR("Restart\r\n"));
#else
fprintf_P(state->myStdInOut, PSTR("Restart\r\n"));
#endif
cmdlineInputFunc('\r', state);

char recSymbol;
Expand Down
20 changes: 0 additions & 20 deletions Projects/AtXmega/RoverController.X/flash.sh

This file was deleted.

21 changes: 10 additions & 11 deletions Projects/AtXmega/RoverController.X/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ xQueueHandle xSIM900Rec;
xQueueHandle xSIM900Tx;

cmdState_t *CLIStateSerialUsb;
tlvInterpreter_t *TLVstate;
TlvInterpreter_t *TLVstate;

FILE usbStream;
FILE hc12Stream;
Expand Down Expand Up @@ -129,7 +129,7 @@ portSHORT main( void )


CLIStateSerialUsb = xmalloc(sizeof(cmdState_t));
TLVstate = xmalloc(sizeof(tlvInterpreter_t));
TLVstate = xmalloc(sizeof(TlvInterpreter_t));

Hc12semaphore = xSemaphoreCreateMutex();

Expand All @@ -144,7 +144,7 @@ portSHORT main( void )

xTaskCreate(vTaskVTYusb, NULL /*"VTY" */, STACK_SIZE_VTY, (void *)(CLIStateSerialUsb), 1, &xHandleVTY_USB);
xTaskCreate(vTaskTLV, NULL /*"TLV" */, STACK_SIZE_VTY, (void *)(TLVstate), 1, &xHandleTLV);
xTaskCreate(vTaskMain, NULL /*"TLV" */, STACK_SIZE_VTY, NULL, 1, &xHandleMain);
// xTaskCreate(vTaskMain, NULL /*"TLV" */, STACK_SIZE_VTY, NULL, 1, &xHandleMain);

vTaskStartScheduler();

Expand All @@ -160,14 +160,13 @@ void vApplicationIdleHook( void )
}
}


void vApplicationTickHook( void )
{
static uint16_t tickCntr = configTICK_RATE_HZ;
if (--tickCntr == 0)
{
tickCntr = configTICK_RATE_HZ;
#ifdef USENET
arpTimer();
#endif
}
//static uint16_t tickCntr = configTICK_RATE_HZ;
//if (--tickCntr == 0)
//{
// tickCntr = configTICK_RATE_HZ;
//
//}
}
2 changes: 1 addition & 1 deletion Projects/AtXmega/RoverController.X/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#define SYSTEM_NAME "FreeRtos+"
#define S_VERSION "0.11"

extern const tlvCommand_t tlvCmdList[];
extern const TlvCommand_t tlvCmdList[];

void my_init_clock (void) __attribute__ ((naked)) __attribute__ ((section (".init0")));

Expand Down
Loading

0 comments on commit b198b6c

Please sign in to comment.