Skip to content
Snippets Groups Projects
Commit a9c4c752 authored by esc2's avatar esc2
Browse files

working

parent ec76b574
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
#include <stdint.h>
#ifndef SCNu8
#define SCNu8 "hhu"
#endif
#include "Distinguish.h"
int main(void){
//starting off with actually getting the data and then inputting it
//into the function ( void distinguish() ) that does the real work
printf("enter size of packet \n");
int size;
scanf("%d", &size);
int test;
uint8_t scanned [size];
int i = 0;
while(i<size){
printf("Enter the %dth index of packet data \n", i);
scanf("%8x" , &test);
scanned[i] = (unsigned char)test;
i++;
}
printf("\n\n");
Distinguish(scanned); //pass reference into real function
return 0; //done
}
// The only real stuff that happens. First I separate the data into respective variables, then
//identify the message_type either as display motor or neither (fail). Create input data from rest to
//be inputted and call correct function.
//
//Input: Array pointer to unsigned bytes (uint8_t *array)
//Output: Prints an error statement IF the message type isn't recognized
void Distinguish(uint8_t *data){
uint8_t packet_id = *data;
uint8_t message_type = *(data+1);
uint16_t message_length = *(data+2); // grouping useful data
if(message_type == 0x34){ //messagetype = display
char message_message [message_length];
int i = 0;
for(i = 0; i< message_length; i++){
message_message[i] = *(data+i + 4); //loop through data to creat string
}
display_message(message_message, message_length);
}
else if(message_type == 0x80){ //messagetpye = motor
int32_t forwardback=0;
int32_t leftright = 0;
for(int i=0; i<4; i++){ //loop places data bytes into right
forwardback += *(data+4+i); //spot
leftright += *(data+8+i);
if(i!=3){
leftright = leftright << 8;
forwardback = forwardback << 8; // left shift a byte except for last
}
}
update_motor(forwardback, leftright);
}
else{
printf(" unknown message_type \n");
return;
}
return;
}
void display_message(char *message, uint16_t message_length){
printf(" display_message() was called \n" );
printf(" message: ");
int i = 0;
for(i=0; i<message_length; i++){
printf("%c",message[i]);
}
return;
}
void update_motor( int32_t fowardback, int32_t leftright){
printf(" update_motor() was called \n");
printf(" Forward_back = %d \n", fowardback);
printf(" Left_Right = %d \n", leftright);
return;
}
#ifndef DEFINE
void Distinguish(uint8_t *data); //real function that is tested
void display_message(char* message, uint16_t message_length); //called if display message type
void update_motor( int32_t fowardback, int32_t leftright); //called if update_motor type
#endif
File added
CC = gcc
CFLAGS = -I
LDFLAGS = -lm
.PHONY: all
all: test
test: Distinguish.o
$(CC) -o test Distinguish.o
clean:
rm -f *.o test
......@@ -2,8 +2,9 @@ This is the code submission for Elliot Couvignou
To run this program all you need to do is:
1. type /make to compile
1. type make to compile (in the correct directory)
2. type ./test to begin
3. enter the packet data to distinguish (uint8_t 1D array)
4. check my result :).
if for some reason things dont work try /make clean and repeat the steps.
a.exe 0 → 100644
File added
a.out 0 → 100644
File added
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