Skip to content
Snippets Groups Projects
Commit 990a2de5 authored by burneykb's avatar burneykb
Browse files

Fixing message id formating and cmd tokenizing

parent 1308937f
No related branches found
No related tags found
No related merge requests found
...@@ -53,7 +53,7 @@ int checkInt(char *intString, int *value) { ...@@ -53,7 +53,7 @@ int checkInt(char *intString, int *value) {
// Formatting commands from ground station CLI // Formatting commands from ground station CLI
int formatCommand(char *command, unsigned char **formattedCommand) { int formatCommand(char *command, unsigned char **formattedCommand) {
fprintf(stderr, "length = %li , received '%s'\n", strlen(command), command); //fprintf(stderr, "length = %li , received '%s'\n", strlen(command), command);
char cmd[strlen(command)]; char cmd[strlen(command)];
strncpy(cmd, command, strlen(command)); strncpy(cmd, command, strlen(command));
cmd[strlen(command)] = '\0'; cmd[strlen(command)] = '\0';
...@@ -65,7 +65,7 @@ int formatCommand(char *command, unsigned char **formattedCommand) { ...@@ -65,7 +65,7 @@ int formatCommand(char *command, unsigned char **formattedCommand) {
metadata_t metadata; metadata_t metadata;
// ---------------------------------------------- // ----------------------------------------------
if(tokens.numTokens > 1) { if(tokens.numTokens > 0) {
for(int type = 0; type < MAX_TYPE; type++) for(int type = 0; type < MAX_TYPE; type++)
{ {
for(int subtype = 0; subtype < MAX_SUBTYPE; subtype++) for(int subtype = 0; subtype < MAX_SUBTYPE; subtype++)
...@@ -79,36 +79,41 @@ int formatCommand(char *command, unsigned char **formattedCommand) { ...@@ -79,36 +79,41 @@ int formatCommand(char *command, unsigned char **formattedCommand) {
{ {
// Validate the float input // Validate the float input
case floatType: case floatType:
valid = checkFloat(tokens.tokens[1], &floatValue);
if(!valid) {
return -1;
}
printf("%f, %s\n", floatValue, tokens.tokens[1]);
metadata.begin_char = (char) BEGIN_CHAR; metadata.begin_char = (char) BEGIN_CHAR;
metadata.msg_type = MessageTypes[type].ID; metadata.msg_type = MessageTypes[type].ID;
metadata.msg_subtype = MessageTypes[type].subtypes[subtype].ID; metadata.msg_subtype = MessageTypes[type].subtypes[subtype].ID;
metadata.msg_id = msgNum++;
metadata.data_len = sizeof(floatValue); if(MessageTypes[type].ID == 0x01) {
valid = checkFloat(tokens.tokens[1], &floatValue);
if(!valid) {
return -1;
}
metadata.data_len = sizeof(floatValue);
} else {
metadata.data_len = 0;
}
metadata.msg_id = msgNum++;
formatPacket(&metadata, &floatValue, formattedCommand); formatPacket(&metadata, &floatValue, formattedCommand);
break; break;
// Validate the integer input // Validate the integer input
case intType: case intType:
valid = checkInt(tokens.tokens[1], &intValue);
if(!valid) {
return -1;
}
metadata.begin_char = (char) BEGIN_CHAR; metadata.begin_char = (char) BEGIN_CHAR;
metadata.msg_type = MessageTypes[type].ID; metadata.msg_type = MessageTypes[type].ID;
metadata.msg_subtype = MessageTypes[type].subtypes[subtype].ID; metadata.msg_subtype = MessageTypes[type].subtypes[subtype].ID;
metadata.msg_id = msgNum++;
metadata.data_len = sizeof(intValue);
if(MessageTypes[type].ID == 0x01) {
valid = checkInt(tokens.tokens[1], &intValue);
if(!valid) {
return -1;
}
metadata.data_len = sizeof(intValue);
} else {
metadata.data_len = 0;
}
metadata.msg_id = msgNum++;
formatPacket(&metadata, &intValue, formattedCommand); formatPacket(&metadata, &intValue, formattedCommand);
break; break;
...@@ -160,7 +165,8 @@ int formatPacket(metadata_t *metadata, void *data, unsigned char **formattedComm ...@@ -160,7 +165,8 @@ int formatPacket(metadata_t *metadata, void *data, unsigned char **formattedComm
(*formattedCommand)[2] = metadata->msg_subtype; (*formattedCommand)[2] = metadata->msg_subtype;
//Msg id (msgNum is 2 bytes) //Msg id (msgNum is 2 bytes)
(*formattedCommand)[3] = metadata->msg_id; (*formattedCommand)[3] = (metadata->msg_id & 0x000000ff);
(*formattedCommand)[4] = ((metadata->msg_id >> 8) & 0x000000ff);
// Data length and data - bytes 5&6 for len, 7+ for data // Data length and data - bytes 5&6 for len, 7+ for data
(*formattedCommand)[5] = metadata->data_len & 0x000000ff; (*formattedCommand)[5] = metadata->data_len & 0x000000ff;
...@@ -176,7 +182,7 @@ int formatPacket(metadata_t *metadata, void *data, unsigned char **formattedComm ...@@ -176,7 +182,7 @@ int formatPacket(metadata_t *metadata, void *data, unsigned char **formattedComm
{ {
data_checksum ^= (*formattedCommand)[i]; data_checksum ^= (*formattedCommand)[i];
} }
printf("checksum = %x\n", (unsigned )data_checksum);
(*formattedCommand)[7 + metadata->data_len] = data_checksum; (*formattedCommand)[7 + metadata->data_len] = data_checksum;
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment