collar/test.c

136 lines
3.5 KiB
C
Raw Permalink Normal View History

2020-05-15 23:58:13 -07:00
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#define TYPE_STRING 0x0A
#define TYPE_VARIANT 0x10
#define PROTO_LEN 0x0A
#define FIELD_ONE_FLOAT 0x0D
#define FIELD_TWO_FLOAT 0x15
#define FIELD_TWO_VARIANT 0x10
typedef struct {
float x,y;
} coord;
int main()
{
uint8_t send_buffer[] = {
TYPE_STRING,
PROTO_LEN,
FIELD_ONE_FLOAT, 0x00, 0x00, 0x48, 0x43,
FIELD_TWO_FLOAT, 0x00, 0x00, 0xc8, 0x42,
FIELD_TWO_VARIANT, 0};
printf("SIZEOF : %d\n", sizeof(send_buffer));
printf("Testing encode:");
float latitude = 200;
float longitude = 100;
uint8_t buffer[14] = {
TYPE_STRING,
PROTO_LEN,
FIELD_ONE_FLOAT, 0x00, 0x00, 0x48, 0x43,
FIELD_TWO_FLOAT, 0x00, 0x00, 0xc8, 0x42,
FIELD_TWO_VARIANT, 0};
memcpy(buffer+3, (void*)&latitude, 4);
memcpy(buffer+8, (void*)&longitude, 4);
for(int i=0;i<sizeof(buffer);i++)
{
printf("%02x - ", buffer[i]);
}
printf("\n");
#define FIELD_ONE_VARIANT 0x08
#define FIELD_TWO_STRING 0x12
#define FIELD_THREE_STRING 0x1A
#define FIELD_FOUR_STRING 0x22
#define FIELD_FIVE_STRING 0x2A
#define FIELD_SIX_STRING 0x32
#define FIELD_SEVEN_STRING 0x3A
#define FIELD_EIGHT_STRING 0x42
#define FIELD_NINE_STRING 0x4A
#define FIELD_TEN_STRING 0x52
#define FIELD_ELEVEN_STRING 0x5A
int32_t isr;
uint8_t buffer0[] = {
FIELD_ONE_VARIANT, 0x01,
FIELD_TWO_STRING, 0x0A,
FIELD_ONE_FLOAT, 0x1B, 0x91, 0xF6, 0xC2,
FIELD_TWO_FLOAT, 0x00, 0x00, 0x00, 0x40,
FIELD_THREE_STRING, 0x0A,
FIELD_ONE_FLOAT, 0xB5, 0x3B, 0x32, 0x42,
FIELD_TWO_FLOAT, 0x00, 0x00, 0x00, 0x40,
FIELD_FOUR_STRING, 0x0A,
FIELD_ONE_FLOAT, 0x00, 0x00, 0x80, 0x3F,
FIELD_TWO_FLOAT, 0x00, 0x00, 0x00, 0x40,
FIELD_FIVE_STRING, 0x0A,
FIELD_ONE_FLOAT, 0x00, 0x00, 0x80, 0x3F,
FIELD_TWO_FLOAT, 0x00, 0x00, 0x00, 0x40,
FIELD_SIX_STRING, 0x0A,
FIELD_ONE_FLOAT, 0x00, 0x00, 0x80, 0x3F,
FIELD_TWO_FLOAT, 0x00, 0x00, 0x00, 0x40,
FIELD_SEVEN_STRING, 0x0A,
FIELD_ONE_FLOAT, 0x00, 0x00, 0x80, 0x3F,
FIELD_TWO_FLOAT, 0x00, 0x00, 0x00, 0x40,
FIELD_EIGHT_STRING, 0x0A,
FIELD_ONE_FLOAT, 0x00, 0x00, 0x80, 0x3F,
FIELD_TWO_FLOAT, 0x00, 0x00, 0x00, 0x40,
FIELD_NINE_STRING, 0x0A,
FIELD_ONE_FLOAT, 0x00, 0x00, 0x80, 0x3F,
FIELD_TWO_FLOAT, 0x00, 0x00, 0x00, 0x40,
FIELD_TEN_STRING, 0x0A,
FIELD_ONE_FLOAT, 0x00, 0x00, 0x80, 0x3F,
FIELD_TWO_FLOAT, 0x00, 0x00, 0x00, 0x40,
FIELD_ELEVEN_STRING, 0x0A,
FIELD_ONE_FLOAT, 0x00, 0x00, 0x80, 0x3F,
FIELD_TWO_FLOAT, 0x00, 0x00, 0x00, 0x40
};
printf("size: %d\n", sizeof(buffer0));
/*
*
* this stuff does not work yet
*
*/
coord coordinates[10];
isr = 0;
isr = buffer0[1];
uint8_t *ptr = buffer0+5;
for(int i=0;i<10;i++)
{
memcpy(&coordinates[i].x, ptr + i*12, 4);
memcpy(&coordinates[i].y, ptr + i*12+5, 4);
}
printf("isr: %d\n", isr);
for(int i=0;i<10;i++)
{
printf("%f, %f\n", coordinates[i].x, coordinates[i].y);
}
printf("\n");
uint32_t test = 9999;
for(int i=0;i<4;i++)
{
printf("%02x - ", (uint8_t)test>>(8*i));
}
printf("\n");
// memcpy(coordinates[0].x, buffer0 + i+0+7, 4);
// memcpy(coordinates[0].y, buffer0 + i+5+7, 4);
// memcpy(coordinates[1].x, buffer0 + i+12+7, 4);
// memcpy(coordinates[1].y, buffer0 + i+17+7, 4);
//
// memcpy(coordinates[2].x, buffer0 + i+24+7, 4);
// memcpy(coordinates[2].y, buffer0 + i+29+7, 4);
return 0;
}