kopia lustrzana https://github.com/bertrik/picoballoon
Apply "indent -kr -i2 -nut" to format whitespace roughly to the arduino standard
rodzic
63d97fa4be
commit
3fc42153d3
116
V1_0.ino
116
V1_0.ino
|
@ -72,13 +72,16 @@ void setup()
|
|||
|
||||
//Setup GPS
|
||||
uint8_t setNav[] = {
|
||||
0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x05, 0x00, 0xFA,
|
||||
0x00, 0xFA, 0x00, 0x64, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0xDC};
|
||||
0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x06, 0x03, 0x00, 0x00,
|
||||
0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x05, 0x00, 0xFA,
|
||||
0x00, 0xFA, 0x00, 0x64, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0xDC
|
||||
};
|
||||
|
||||
uint8_t ecoMode[] = {0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x00, 0x04, 0x1D, 0x85};
|
||||
uint8_t ecoMode[] =
|
||||
{ 0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x00, 0x04, 0x1D, 0x85 };
|
||||
|
||||
while(!gps_set_sucess)
|
||||
{
|
||||
while (!gps_set_sucess) {
|
||||
sendUBX(setNav, sizeof(setNav) / sizeof(uint8_t));
|
||||
gps_set_sucess = getUBX_ACK(setNav);
|
||||
/*sendUBX(ecoMode, sizeof(ecoMode)/sizeof(uint8_t));
|
||||
|
@ -96,14 +99,11 @@ void setup()
|
|||
delay(500);
|
||||
digitalWrite(LED, LOW);
|
||||
|
||||
while(sats < 6 && flat == 0)
|
||||
{
|
||||
while(Serial.available())
|
||||
{
|
||||
while (sats < 6 && flat == 0) {
|
||||
while (Serial.available()) {
|
||||
char c = Serial.read();
|
||||
newData = gps.encode(c);
|
||||
if(newData)
|
||||
{
|
||||
if (newData) {
|
||||
gps.f_get_position(&flat, &flon, &age);
|
||||
sats = gps.satellites();
|
||||
}
|
||||
|
@ -121,31 +121,26 @@ void loop()
|
|||
unsigned long chars;
|
||||
unsigned short sentences, failed;
|
||||
|
||||
while(Serial.available())
|
||||
{
|
||||
while (Serial.available()) {
|
||||
char c = Serial.read();
|
||||
if (gps.encode(c)) // Did a new valid sentence come in?
|
||||
newData = true;
|
||||
}
|
||||
|
||||
if (newData)
|
||||
{
|
||||
if (newData) {
|
||||
digitalWrite(LED, HIGH);
|
||||
gps.f_get_position(&flat, &flon, &age);
|
||||
sats = gps.satellites();
|
||||
dtostrf(flat, 10, 6, latbuf);
|
||||
dtostrf(flon, 9, 6, lonbuf);
|
||||
if(lonbuf[0] == ' ')
|
||||
{
|
||||
if (lonbuf[0] == ' ') {
|
||||
lonbuf[0] = '+';
|
||||
}
|
||||
if(latbuf[0] == ' ')
|
||||
{
|
||||
if (latbuf[0] == ' ') {
|
||||
latbuf[0] = '+';
|
||||
}
|
||||
ialt = (gps.altitude() / 100);
|
||||
if(ialt >= 0)
|
||||
{
|
||||
if (ialt >= 0) {
|
||||
itoa(ialt, altbuf, 10);
|
||||
}
|
||||
|
||||
|
@ -162,7 +157,9 @@ void loop()
|
|||
snprintf(voltage, sizeof(voltage), "%i.%02i", v1, v2);
|
||||
|
||||
cBusy = true;
|
||||
sprintf(datastring,"$$$$%s,%li,%02i:%02i:%02i,%s,%s,%s,%i,%s",callsign,ticks,hour,minute,second,latbuf,lonbuf,altbuf,sats,voltage);
|
||||
sprintf(datastring, "$$$$%s,%li,%02i:%02i:%02i,%s,%s,%s,%i,%s",
|
||||
callsign, ticks, hour, minute, second, latbuf, lonbuf, altbuf,
|
||||
sats, voltage);
|
||||
unsigned int CHECKSUM = gps_CRC16_checksum(datastring); // Calculates the checksum for this datastring
|
||||
char checksum_str[7];
|
||||
sprintf(checksum_str, "*%04X\n", CHECKSUM);
|
||||
|
@ -171,13 +168,10 @@ void loop()
|
|||
|
||||
gps.stats(&chars, &sentences, &failed);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
digitalWrite(LED, LOW);
|
||||
}
|
||||
if(reinit == true)
|
||||
{
|
||||
if (reinit == true) {
|
||||
setupRadio();
|
||||
reinit = false;
|
||||
}
|
||||
|
@ -195,17 +189,12 @@ ISR(TIMER1_COMPA_vect)
|
|||
}
|
||||
break;
|
||||
case 1: // Initialise transmission, take a copy of the string so it doesn't change mid transmission.
|
||||
if(reinit == false)
|
||||
{
|
||||
if(cBusy == false)
|
||||
{
|
||||
if(reinitcntr == reinitcnt)
|
||||
{
|
||||
if (reinit == false) {
|
||||
if (cBusy == false) {
|
||||
if (reinitcntr == reinitcnt) {
|
||||
reinit = true;
|
||||
reinitcntr = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
strcpy(txstring, datastring);
|
||||
txstringlength = strlen(txstring);
|
||||
if (txstringlength != 0)
|
||||
|
@ -218,45 +207,38 @@ ISR(TIMER1_COMPA_vect)
|
|||
}
|
||||
break;
|
||||
case 2: // Grab a char and lets go transmit it.
|
||||
if ( txj < txstringlength)
|
||||
{
|
||||
if (txj < txstringlength) {
|
||||
txc = txstring[txj];
|
||||
txj++;
|
||||
txstatus = 3;
|
||||
rtty_txbit(0); // Start Bit;
|
||||
txi = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
txstatus = 0; // Should be finished
|
||||
txj = 0;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(txi<ASCII)
|
||||
{
|
||||
if (txi < ASCII) {
|
||||
txi++;
|
||||
if (txc & 1) rtty_txbit(1);
|
||||
else rtty_txbit(0);
|
||||
if (txc & 1)
|
||||
rtty_txbit(1);
|
||||
else
|
||||
rtty_txbit(0);
|
||||
txc = txc >> 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
rtty_txbit(1); // Stop Bit
|
||||
txstatus = 4;
|
||||
txi = 0;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
if(STOPBITS==2)
|
||||
{
|
||||
if (STOPBITS == 2) {
|
||||
rtty_txbit(1); // Stop Bit
|
||||
txstatus = 2;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
txstatus = 2;
|
||||
break;
|
||||
}
|
||||
|
@ -266,24 +248,23 @@ ISR(TIMER1_COMPA_vect)
|
|||
|
||||
void rtty_txbit(int bit)
|
||||
{
|
||||
if (bit)
|
||||
{
|
||||
if (bit) {
|
||||
radio1.write(0x73, 0x03); // High
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
radio1.write(0x73, 0x00); // Low
|
||||
}
|
||||
}
|
||||
|
||||
void setupGPSpower() {
|
||||
void setupGPSpower()
|
||||
{
|
||||
//Set GPS ot Power Save Mode
|
||||
uint8_t setPSM[] = { 0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x08, 0x01, 0x22, 0x92 }; // Setup for Power Save Mode (Default Cyclic 1s)
|
||||
|
||||
sendUBX(setPSM, sizeof(setPSM) / sizeof(uint8_t));
|
||||
}
|
||||
|
||||
void setupRadio(){
|
||||
void setupRadio()
|
||||
{
|
||||
pinMode(RFM22B_SDN, OUTPUT); // RFM22B SDN is on ARDUINO A3
|
||||
digitalWrite(RFM22B_SDN, LOW);
|
||||
delay(1000);
|
||||
|
@ -308,14 +289,14 @@ uint16_t gps_CRC16_checksum (char *string)
|
|||
crc = 0xFFFF;
|
||||
|
||||
// Calculate checksum ignoring the first four $s
|
||||
for (i = 4; i < strlen(string); i++)
|
||||
{
|
||||
for (i = 4; i < strlen(string); i++) {
|
||||
c = string[i];
|
||||
crc = _crc_xmodem_update(crc, c);
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
void initialise_interrupt()
|
||||
{
|
||||
// initialize Timer1
|
||||
|
@ -333,7 +314,8 @@ void initialise_interrupt()
|
|||
}
|
||||
|
||||
// Send a byte array of UBX protocol to the GPS
|
||||
void sendUBX(uint8_t *MSG, uint8_t len) {
|
||||
void sendUBX(uint8_t * MSG, uint8_t len)
|
||||
{
|
||||
for (int i = 0; i < len; i++) {
|
||||
Serial.write(MSG[i]);
|
||||
//mySerial.print(MSG[i], HEX);
|
||||
|
@ -342,7 +324,8 @@ void sendUBX(uint8_t *MSG, uint8_t len) {
|
|||
}
|
||||
|
||||
// Calculate expected UBX ACK packet and parse UBX response from GPS
|
||||
boolean getUBX_ACK(uint8_t *MSG) {
|
||||
boolean getUBX_ACK(uint8_t * MSG)
|
||||
{
|
||||
uint8_t b;
|
||||
uint8_t ackByteID = 0;
|
||||
uint8_t ackPacket[10];
|
||||
|
@ -375,13 +358,11 @@ boolean getUBX_ACK(uint8_t *MSG) {
|
|||
//mySerial.println(" (SUCCESS!)");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Timeout if no valid response in 3 seconds
|
||||
if (millis() - startTime > 3000) {
|
||||
//mySerial.println(" (FAILED!)");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure data is available to read
|
||||
if (Serial.available()) {
|
||||
b = Serial.read();
|
||||
|
@ -390,8 +371,7 @@ boolean getUBX_ACK(uint8_t *MSG) {
|
|||
if (b == ackPacket[ackByteID]) {
|
||||
ackByteID++;
|
||||
//mySerial.print(b, HEX);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ackByteID = 0; // Reset and look again, invalid order
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue