Fix PB Encoding

This commit is contained in:
Ryan Alder 2020-02-22 16:39:33 -08:00
parent 60bf5d84d6
commit 5e48c293bf

View File

@ -1,6 +1,6 @@
#include <SPI.h> #include <SPI.h>
#include <LoRa.h> #include <LoRa.h>
#include <TinyGPS.h> #include <TinyGPS++.h>
#include <SoftwareSerial.h> #include <SoftwareSerial.h>
#include "pb_common.h" #include "pb_common.h"
@ -16,7 +16,7 @@ float lng = 0;
TinyGPSPlus gps; TinyGPSPlus gps;
SoftwareSerial ss(5, 6); SoftwareSerial ss(6, 7);
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
@ -49,7 +49,7 @@ void loop() {
previousMillis = currentMillis; previousMillis = currentMillis;
// Gather GPS data // Gather GPS data
if (gps.location.isValid()) { if (gps.encode(ss.read()) && gps.location.isValid()) {
Serial.println("Valid GPS"); Serial.println("Valid GPS");
lat = gps.location.lat(); lat = gps.location.lat();
lng = gps.location.lng(); lng = gps.location.lng();
@ -59,17 +59,20 @@ void loop() {
} }
// Encode as protobuf packet // Encode as protobuf packet
if (1) { if (lat && lng) {
uint8_t buffer[10]; uint8_t buffer[50] = {0};
Fenceless_Coordinate m = Fenceless_Coordinate_init_zero; Fenceless_CollarResponse m = Fenceless_CollarResponse_init_zero;
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
//m.x = lat; m.loc.x = lat;
//m.y = lng; m.loc.y = lng;
m.x = 44.558750;
m.y = -123.283744;
if (!pb_encode(&stream, Fenceless_Coordinate_fields, &m)) { int status = pb_encode(&stream, Fenceless_CollarResponse_fields, &m);
if (!status) {
Serial.println("Failed to encode"); Serial.println("Failed to encode");
} else {
Serial.print("Status: ");
Serial.println(status);
} }
Serial.print("Sending packet Lat / Long: "); Serial.print("Sending packet Lat / Long: ");