works well
This commit is contained in:
		
							parent
							
								
									0b55fce9b8
								
							
						
					
					
						commit
						d5c9e11e5f
					
				
							
								
								
									
										36
									
								
								collar.cpp
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								collar.cpp
									
									
									
									
									
								
							@ -22,10 +22,6 @@ static osjob_t sendjob;
 | 
			
		||||
 | 
			
		||||
static const u4_t DEVADDR = 0x260212B6;
 | 
			
		||||
 | 
			
		||||
// void printf(char *str) {
 | 
			
		||||
//    Serial.println(str);
 | 
			
		||||
// }
 | 
			
		||||
 | 
			
		||||
void debug_function(char *str) {
 | 
			
		||||
  // Serial.println(str);
 | 
			
		||||
}
 | 
			
		||||
@ -50,7 +46,6 @@ const lmic_pinmap lmic_pins = {
 | 
			
		||||
 ***************************************************/
 | 
			
		||||
TinyGPSPlus gps;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint8_t general_int;
 | 
			
		||||
volatile uint8_t n_poly;
 | 
			
		||||
#define isr general_int
 | 
			
		||||
@ -63,6 +58,8 @@ const uint8_t N_POLY_MAX=10;
 | 
			
		||||
float polyx[N_POLY_MAX*2+5];
 | 
			
		||||
float * const polyy = polyx + N_POLY_MAX;
 | 
			
		||||
 | 
			
		||||
void do_send(osjob_t* j);
 | 
			
		||||
 | 
			
		||||
/****************************************************
 | 
			
		||||
 * Check a pair of coordinates against two lists
 | 
			
		||||
 * of vertices
 | 
			
		||||
@ -112,20 +109,15 @@ inline void import_protobuf(const uint8_t *protobuffer, const uint8_t size) {
 | 
			
		||||
  n_poly = isr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void do_send(osjob_t* j);
 | 
			
		||||
 | 
			
		||||
void onEvent (ev_t ev) {
 | 
			
		||||
  if(ev == EV_TXCOMPLETE) {
 | 
			
		||||
    if (LMIC.dataLen) {
 | 
			
		||||
      Serial.print(F(" -Received: "));
 | 
			
		||||
      Serial.println(LMIC.dataLen);
 | 
			
		||||
      import_protobuf(LMIC.frame + LMIC.dataBeg, LMIC.dataLen);
 | 
			
		||||
    }
 | 
			
		||||
    // Schedule next transmission
 | 
			
		||||
    os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
 | 
			
		||||
 | 
			
		||||
    if (LMIC.dataLen) {
 | 
			
		||||
      import_protobuf(LMIC.frame + LMIC.dataBeg, LMIC.dataLen);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -195,7 +187,6 @@ inline void on_wait_gps() {
 | 
			
		||||
#define FIELD_TWO_FLOAT 0x15
 | 
			
		||||
#define FIELD_TWO_VARIANT 0x10
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const char oob[] = " -OUT OF BOUNDS";
 | 
			
		||||
const char inb[] = " -IN BOUNDS";
 | 
			
		||||
uint8_t buffer[] = {
 | 
			
		||||
@ -215,7 +206,7 @@ void send_lora() {
 | 
			
		||||
    const float latitude  = gps.location.lat();
 | 
			
		||||
    const float longitude = gps.location.lng();
 | 
			
		||||
    if(n_poly>0) {
 | 
			
		||||
      const uint8_t out_of_bounds = check_bounds(latitude, longitude);
 | 
			
		||||
      const uint8_t out_of_bounds = !check_bounds(latitude, longitude);
 | 
			
		||||
      if(out_of_bounds) {
 | 
			
		||||
        Serial.println(oob);
 | 
			
		||||
      } else {
 | 
			
		||||
@ -232,7 +223,6 @@ void send_lora() {
 | 
			
		||||
    LMIC_setTxData2(1, buffer, sizeof(buffer)-1, 0);
 | 
			
		||||
  }
 | 
			
		||||
  since = millis();
 | 
			
		||||
  
 | 
			
		||||
  state = WAIT_LORA;
 | 
			
		||||
}
 | 
			
		||||
void do_send(osjob_t* j){
 | 
			
		||||
@ -243,7 +233,6 @@ void do_send(osjob_t* j){
 | 
			
		||||
void on_wait_lora() {
 | 
			
		||||
  if(millis()- since > TX_INTERVAL*1000UL) {
 | 
			
		||||
    Serial.println(" -Lora Done Sending");
 | 
			
		||||
    
 | 
			
		||||
    state = START_GPS;
 | 
			
		||||
  }
 | 
			
		||||
  if(millis() - since > TIMEOUT) {
 | 
			
		||||
@ -253,7 +242,6 @@ void on_wait_lora() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define LOOP_LATENCY_MS 200L
 | 
			
		||||
 | 
			
		||||
uint32_t time_last = 0;
 | 
			
		||||
void loop() {
 | 
			
		||||
  uint32_t time = millis();
 | 
			
		||||
@ -274,21 +262,7 @@ void loop() {
 | 
			
		||||
    else if(state == WAIT_LORA) {
 | 
			
		||||
      on_wait_lora();
 | 
			
		||||
    }
 | 
			
		||||
  } else {
 | 
			
		||||
    // Serial.print('.');
 | 
			
		||||
  }
 | 
			
		||||
  // if(data_available) {
 | 
			
		||||
  //   Serial.println("Data available");
 | 
			
		||||
  //    for(uint8_t i=0;i<n_poly;i++) {
 | 
			
		||||
  //      Serial.print('(');
 | 
			
		||||
  //      Serial.print((int)(polyy[i]*100));
 | 
			
		||||
  //      Serial.print(',');
 | 
			
		||||
  //      Serial.print((int)(polyx[i]*100));
 | 
			
		||||
  //      Serial.print(')');
 | 
			
		||||
  //      Serial.print(',');
 | 
			
		||||
  //    }
 | 
			
		||||
  //   data_available = 0;
 | 
			
		||||
  // }
 | 
			
		||||
  } 
 | 
			
		||||
  read_gps();
 | 
			
		||||
  os_runloop_once();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -47,7 +47,7 @@ static uint8_t rx_bit = 0;
 | 
			
		||||
static uint16_t rx_target;
 | 
			
		||||
static volatile uint8_t rx_buffer_head;
 | 
			
		||||
static volatile uint8_t rx_buffer_tail;
 | 
			
		||||
#define RX_BUFFER_SIZE 30 
 | 
			
		||||
#define RX_BUFFER_SIZE 20 
 | 
			
		||||
static volatile uint8_t rx_buffer[RX_BUFFER_SIZE];
 | 
			
		||||
 | 
			
		||||
const static uint32_t cycles_per_bit = 1667UL;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										135
									
								
								test.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										135
									
								
								test.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,135 @@
 | 
			
		||||
#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;
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user