Refactor afsk/main.c to have better formatting and use ifdef guards instead of commenting out logging.

pull/3/head
jmclemo6 7 years ago committed by Jacob McLemore
parent 78daccace0
commit 55660e29fb

@ -1,7 +1,13 @@
all: DEBUG_BEHAVIOR=
all: libax5043.a
all: radioafsk
all: radiocw
debug: DEBUG_BEHAVIOR = -DDEBUG_LOGGING
debug: libax5043.a
debug: radioafsk
debug: radiocw
rebuild: clean
rebuild: all
@ -44,47 +50,47 @@ libax5043.a: ax5043/spi/ax5043spi.o
radiochat: libax5043.a
radiochat: chat/chat_main.o
gcc -o radiochat -pthread -L./ chat/chat_main.o -lwiringPi -lax5043
gcc -std=c99 $(DEBUG_BEHAVIOR) -o radiochat -pthread -L./ chat/chat_main.o -lwiringPi -lax5043
radiocw: libax5043.a
radiocw: cw/cw_main.o
radiocw: afsk/ax25.o
radiocw: afsk/ax5043.o
radiocw: afsk/send_afsk.o
gcc -o radiocw -L./ afsk/ax25.o afsk/ax5043.o afsk/send_afsk.o cw/cw_main.o -lwiringPi -lax5043
gcc -std=c99 $(DEBUG_BEHAVIOR) -o radiocw -L./ afsk/ax25.o afsk/ax5043.o afsk/send_afsk.o cw/cw_main.o -lwiringPi -lax5043
radiopiglatin: libax5043.a
radiopiglatin: piglatin/piglatin_main.o
gcc -o radiopiglatin -pedantic -Wall -Wextra -L./ piglatin/piglatin_main.o -lwiringPi -lax5043
gcc -std=c99 $(DEBUG_BEHAVIOR) -o radiopiglatin -pedantic -Wall -Wextra -L./ piglatin/piglatin_main.o -lwiringPi -lax5043
testax5043tx: libax5043.a
testax5043tx: transmit/transmit_main.o
gcc -o testax5043tx -pedantic -Wall -Wextra -L./ transmit/transmit_main.o -lwiringPi -lax5043
gcc -std=c99 $(DEBUG_BEHAVIOR) -o testax5043tx -pedantic -Wall -Wextra -L./ transmit/transmit_main.o -lwiringPi -lax5043
testax5043rx: libax5043.a
testax5043rx: receive/receive_main.o
gcc -o testax5043rx -pedantic -Wall -Wextra -L./ receive/receive_main.o -lwiringPi -lax5043
gcc -std=c99 $(DEBUG_BEHAVIOR) -o testax5043rx -pedantic -Wall -Wextra -L./ receive/receive_main.o -lwiringPi -lax5043
testax5043init: libax5043.a
testax5043init: init/init_main.o
gcc -o testax5043init -pedantic -Wall -Wextra -L./ init/init_main.o -lwiringPi -lax5043
gcc -std=c99 $(DEBUG_BEHAVIOR) -o testax5043init -pedantic -Wall -Wextra -L./ init/init_main.o -lwiringPi -lax5043
testax50432freq: libax5043.a
testax50432freq: transmit2freq/transmit2freq_main.o
gcc -o testax50432freq -pedantic -Wall -Wextra -L./ transmit2freq/transmit2freq_main.o -lwiringPi -lax5043
gcc -std=c99 $(DEBUG_BEHAVIOR) -o testax50432freq -pedantic -Wall -Wextra -L./ transmit2freq/transmit2freq_main.o -lwiringPi -lax5043
testafsktx: libax5043.a
testafsktx: afsktx/ax25.o
testafsktx: afsktx/ax5043.o
testafsktx: afsktx/main.o
gcc -o testafsktx -pedantic -Wall -Wextra -L./ afsktx/ax25.o afsktx/ax5043.o afsktx/main.o -lwiringPi -lax5043
gcc -std=c99 $(DEBUG_BEHAVIOR) -o testafsktx -pedantic -Wall -Wextra -L./ afsktx/ax25.o afsktx/ax5043.o afsktx/main.o -lwiringPi -lax5043
radioafsk: libax5043.a
radioafsk: afsk/ax25.o
radioafsk: afsk/ax5043.o
radioafsk: afsk/main.o
radioafsk: afsk/ina219.h
gcc -o radioafsk -pedantic -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o afsk/main.o -lwiringPi -lax5043
gcc -std=c99 $(DEBUG_BEHAVIOR) -o radioafsk -pedantic -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o afsk/main.o -lwiringPi -lax5043
ax5043/generated/configcommon.o: ax5043/generated/configcommon.c
@ -92,19 +98,19 @@ ax5043/generated/configcommon.o: ax5043/generated/configrx.h
ax5043/generated/configcommon.o: ax5043/generated/configtx.h
ax5043/generated/configcommon.o: ax5043/axradio/axradioinit.h
ax5043/generated/configcommon.o: ax5043/axradio/axradioinit_p.h
cd ax5043/generated; gcc -pedantic -Wall -Wextra -c configcommon.c
cd ax5043/generated; gcc -std=c99 $(DEBUG_BEHAVIOR) -pedantic -Wall -Wextra -c configcommon.c
ax5043/generated/configrx.o: ax5043/generated/configrx.c
ax5043/generated/configrx.o: ax5043/generated/configrx.h
ax5043/generated/configrx.o: ax5043/axradio/axradioinit.h
ax5043/generated/configrx.o: ax5043/axradio/axradioinit_p.h
cd ax5043/generated; gcc -pedantic -Wall -Wextra -c configrx.c
cd ax5043/generated; gcc -std=c99 $(DEBUG_BEHAVIOR) -pedantic -Wall -Wextra -c configrx.c
ax5043/generated/configtx.o: ax5043/generated/configtx.c
ax5043/generated/configtx.o: ax5043/generated/configtx.h
ax5043/generated/configtx.o: ax5043/axradio/axradioinit.h
ax5043/generated/configtx.o: ax5043/axradio/axradioinit_p.h
cd ax5043/generated; gcc -pedantic -Wall -Wextra -c configtx.c
cd ax5043/generated; gcc -std=c99 $(DEBUG_BEHAVIOR) -pedantic -Wall -Wextra -c configtx.c
ax5043/generated/config.o: ax5043/generated/config.c
ax5043/generated/config.o: ax5043/generated/config.h
@ -113,12 +119,12 @@ ax5043/generated/config.o: ax5043/axradio/axradioinit_p.h
ax5043/generated/config.o: ax5043/spi/ax5043spi.h
ax5043/generated/config.o: ax5043/spi/ax5043spi_p.h
ax5043/generated/config.o: ax5043/crc/crc.h
cd ax5043/generated; gcc -pedantic -Wall -Wextra -c config.c
cd ax5043/generated; gcc -std=c99 $(DEBUG_BEHAVIOR) -pedantic -Wall -Wextra -c config.c
ax5043/spi/ax5043spi.o: ax5043/spi/ax5043spi.c
ax5043/spi/ax5043spi.o: ax5043/spi/ax5043spi.h
ax5043/spi/ax5043spi.o: ax5043/spi/ax5043spi_p.h
cd ax5043/spi; gcc -pedantic -Wall -Wextra -c ax5043spi.c
cd ax5043/spi; gcc -std=c99 $(DEBUG_BEHAVIOR) -pedantic -Wall -Wextra -c ax5043spi.c
ax5043/ax5043support/ax5043init.o: ax5043/ax5043support/ax5043init.c
ax5043/ax5043support/ax5043init.o: ax5043/ax5043support/ax5043init.h
@ -126,7 +132,7 @@ ax5043/ax5043support/ax5043init.o: ax5043/axradio/axradioinit.h
ax5043/ax5043support/ax5043init.o: ax5043/axradio/axradioinit_p.h
ax5043/ax5043support/ax5043init.o: ax5043/spi/ax5043spi.h
ax5043/ax5043support/ax5043init.o: ax5043/spi/ax5043spi_p.h
cd ax5043/ax5043support; gcc -pedantic -Wall -Wextra -c ax5043init.c
cd ax5043/ax5043support; gcc -std=c99 $(DEBUG_BEHAVIOR) -pedantic -Wall -Wextra -c ax5043init.c
ax5043/ax5043support/ax5043rx.o: ax5043/ax5043support/ax5043rx.c
ax5043/ax5043support/ax5043rx.o: ax5043/ax5043support/ax5043rx.h
@ -134,7 +140,7 @@ ax5043/ax5043support/ax5043rx.o: ax5043/axradio/axradioinit.h
ax5043/ax5043support/ax5043rx.o: ax5043/axradio/axradioinit_p.h
ax5043/ax5043support/ax5043rx.o: ax5043/spi/ax5043spi.h
ax5043/ax5043support/ax5043rx.o: ax5043/spi/ax5043spi_p.h
cd ax5043/ax5043support; gcc -pedantic -Wall -Wextra -c ax5043rx.c
cd ax5043/ax5043support; gcc -std=c99 $(DEBUG_BEHAVIOR) -pedantic -Wall -Wextra -c ax5043rx.c
ax5043/ax5043support/ax5043tx.o: ax5043/ax5043support/ax5043tx.c
ax5043/ax5043support/ax5043tx.o: ax5043/ax5043support/ax5043tx.h
@ -142,7 +148,7 @@ ax5043/ax5043support/ax5043tx.o: ax5043/axradio/axradioinit.h
ax5043/ax5043support/ax5043tx.o: ax5043/axradio/axradioinit_p.h
ax5043/ax5043support/ax5043tx.o: ax5043/spi/ax5043spi.h
ax5043/ax5043support/ax5043tx.o: ax5043/spi/ax5043spi_p.h
cd ax5043/ax5043support; gcc -pedantic -Wall -Wextra -c ax5043tx.c
cd ax5043/ax5043support; gcc -std=c99 $(DEBUG_BEHAVIOR) -pedantic -Wall -Wextra -c ax5043tx.c
ax5043/axradio/axradioinit.o: ax5043/axradio/axradioinit.c
ax5043/axradio/axradioinit.o: ax5043/axradio/axradioinit.h
@ -152,7 +158,7 @@ ax5043/axradio/axradioinit.o: ax5043/spi/ax5043spi.h
ax5043/axradio/axradioinit.o: ax5043/spi/ax5043spi_p.h
ax5043/axradio/axradioinit.o: ax5043/generated/config.h
ax5043/axradio/axradioinit.o: ax5043/crc/crc.h
cd ax5043/axradio; gcc -pedantic -Wall -Wextra -c axradioinit.c
cd ax5043/axradio; gcc -std=c99 $(DEBUG_BEHAVIOR) -pedantic -Wall -Wextra -c axradioinit.c
ax5043/axradio/axradiomode.o: ax5043/axradio/axradiomode.c
ax5043/axradio/axradiomode.o: ax5043/axradio/axradiomode.h
@ -162,7 +168,7 @@ ax5043/axradio/axradiomode.o: ax5043/axradio/axradioinit_p.h
ax5043/axradio/axradiomode.o: ax5043/spi/ax5043spi.h
ax5043/axradio/axradiomode.o: ax5043/spi/ax5043spi_p.h
ax5043/axradio/axradiomode.o: ax5043/generated/config.h
cd ax5043/axradio; gcc -pedantic -Wall -Wextra -c axradiomode.c
cd ax5043/axradio; gcc -std=c99 $(DEBUG_BEHAVIOR) -pedantic -Wall -Wextra -c axradiomode.c
ax5043/axradio/axradiorx.o: ax5043/axradio/axradiorx.c
ax5043/axradio/axradiorx.o: ax5043/axradio/axradiorx.h
@ -172,7 +178,7 @@ ax5043/axradio/axradiorx.o: ax5043/axradio/axradioinit.h
ax5043/axradio/axradiorx.o: ax5043/axradio/axradioinit_p.h
ax5043/axradio/axradiorx.o: ax5043/spi/ax5043spi.h
ax5043/axradio/axradiorx.o: ax5043/spi/ax5043spi_p.h
cd ax5043/axradio; gcc -pedantic -Wall -Wextra -c axradiorx.c
cd ax5043/axradio; gcc -std=c99 $(DEBUG_BEHAVIOR) -pedantic -Wall -Wextra -c axradiorx.c
ax5043/axradio/axradiotx.o: ax5043/axradio/axradiotx.c
ax5043/axradio/axradiotx.o: ax5043/axradio/axradiotx.h
@ -186,11 +192,11 @@ ax5043/axradio/axradiotx.o: ax5043/generated/config.h
ax5043/axradio/axradiotx.o: ax5043/axradio/axradiomode.h
ax5043/axradio/axradiotx.o: ax5043/axradio/axradiomode_p.h
ax5043/axradio/axradiotx.o: ax5043/crc/crc.h
cd ax5043/axradio; gcc -pedantic -Wall -Wextra -c axradiotx.c
cd ax5043/axradio; gcc -std=c99 $(DEBUG_BEHAVIOR) -pedantic -Wall -Wextra -c axradiotx.c
ax5043/crc/crc.o: ax5043/crc/crc.c
ax5043/crc/crc.o: ax5043/crc/crc.h
cd ax5043/crc; gcc -pedantic -Wall -Wextra -c crc.c
cd ax5043/crc; gcc -std=c99 $(DEBUG_BEHAVIOR) -pedantic -Wall -Wextra -c crc.c
chat/chat_main.o: chat/chat_main.c
chat/chat_main.o: ax5043/spi/ax5043spi.h
@ -204,13 +210,13 @@ chat/chat_main.o: ax5043/axradio/axradiorx_p.h
chat/chat_main.o: ax5043/axradio/axradiotx.h
chat/chat_main.o: ax5043/axradio/axradiotx_p.h
chat/chat_main.o: ax5043/generated/configtx.h
cd chat; gcc -I../ax5043 -pedantic -Wconversion -Wall -Wextra -c chat_main.c; cd ..
cd chat; gcc -std=c99 $(DEBUG_BEHAVIOR) -I../ax5043 -pedantic -Wconversion -Wall -Wextra -c chat_main.c; cd ..
afsk/ax25.o: afsk/ax25.c
afsk/ax25.o: afsk/ax25.h
afsk/ax25.o: afsk/ax5043.h
afsk/ax25.o: afsk/status.h
cd afsk; gcc -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c ax25.c; cd ..
cd afsk; gcc -std=c99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c ax25.c; cd ..
afsk/ax5043.o: afsk/ax5043.c
afsk/ax5043.o: afsk/ax25.h
@ -219,21 +225,21 @@ afsk/ax5043.o: afsk/status.h
afsk/ax5043.o: afsk/utils.h
afsk/ax5043.o: afsk/main.c
afsk/ax5043.o: ax5043/spi/ax5043spi.h
cd afsk; gcc -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c ax5043.c; cd ..
cd afsk; gcc -std=c99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c ax5043.c; cd ..
afsk/main.o: afsk/main.c
afsk/main.o: afsk/status.h
afsk/main.o: afsk/ax5043.h
afsk/main.o: afsk/ax25.h
afsk/main.o: ax5043/spi/ax5043spi.h
cd afsk; gcc -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c main.c; cd ..
cd afsk; gcc -std=c99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c main.c; cd ..
afsk/send_afsk.o: afsk/send_afsk.c
afsk/send_afsk.o: afsk/send_afsk.h
afsk/send_afsk.o: afsk/status.h
afsk/send_afsk.o: afsk/ax5043.h
afsk/send_afsk.o: afsk/ax25.h
cd afsk; gcc -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c send_afsk.c; cd ..
cd afsk; gcc -std=c99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c send_afsk.c; cd ..
cw/cw_main.o: cw/cw_main.c
cw/cw_main.o: ax5043/spi/ax5043spi.h
@ -247,7 +253,7 @@ cw/cw_main.o: ax5043/axradio/axradiorx_p.h
cw/cw_main.o: ax5043/axradio/axradiotx.h
cw/cw_main.o: ax5043/axradio/axradiotx_p.h
cw/cw_main.o: ax5043/generated/configtx.h
cd cw; gcc -I../ax5043 -pedantic -Wconversion -Wall -Wextra -c cw_main.c; cd ..
cd cw; gcc -std=c99 $(DEBUG_BEHAVIOR) -I../ax5043 -pedantic -Wconversion -Wall -Wextra -c cw_main.c; cd ..
piglatin/piglatin_main.o: piglatin/piglatin_main.c
piglatin/piglatin_main.o: ax5043/spi/ax5043spi.h
@ -261,7 +267,7 @@ piglatin/piglatin_main.o: ax5043/axradio/axradiorx_p.h
piglatin/piglatin_main.o: ax5043/axradio/axradiotx.h
piglatin/piglatin_main.o: ax5043/axradio/axradiotx_p.h
piglatin/piglatin_main.o: ax5043/generated/configtx.h
cd piglatin; gcc -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c piglatin_main.c; cd ..
cd piglatin; gcc -std=c99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c piglatin_main.c; cd ..
receive/receive_main.o: receive/receive_main.c
receive/receive_main.o: ax5043/axradio/axradioinit.h
@ -273,7 +279,7 @@ receive/receive_main.o: ax5043/axradio/axradiomode_p.h
receive/receive_main.o: ax5043/axradio/axradiorx.h
receive/receive_main.o: ax5043/axradio/axradiorx_p.h
receive/receive_main.o: ax5043/generated/configrx.h
cd receive; gcc -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c receive_main.c; cd ..
cd receive; gcc -std=c99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c receive_main.c; cd ..
transmit/transmit_main.o: transmit/transmit_main.c
transmit/transmit_main.o: ax5043/axradio/axradioinit.h
@ -285,7 +291,7 @@ transmit/transmit_main.o: ax5043/axradio/axradiomode_p.h
transmit/transmit_main.o: ax5043/axradio/axradiotx.h
transmit/transmit_main.o: ax5043/axradio/axradiotx_p.h
transmit/transmit_main.o: ax5043/generated/configtx.h
cd transmit; gcc -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c transmit_main.c; cd ..
cd transmit; gcc -std=c99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c transmit_main.c; cd ..
transmit2freq/transmit2freq_main.o: transmit2freq/transmit2freq_main.c
transmit2freq/transmit2freq_main.o: ax5043/axradio/axradioinit.h
@ -297,20 +303,20 @@ transmit2freq/transmit2freq_main.o: ax5043/axradio/axradiomode_p.h
transmit2freq/transmit2freq_main.o: ax5043/axradio/axradiotx.h
transmit2freq/transmit2freq_main.o: ax5043/axradio/axradiotx_p.h
transmit2freq/transmit2freq_main.o: ax5043/generated/configtx.h
cd transmit2freq; gcc -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c transmit2freq_main.c; cd ..
cd transmit2freq; gcc -std=c99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c transmit2freq_main.c; cd ..
init/init_main.o: init/init_main.c
init/init_main.o: ax5043/axradio/axradioinit.h
init/init_main.o: ax5043/axradio/axradioinit_p.h
init/init_main.o: ax5043/spi/ax5043spi.h
init/init_main.o: ax5043/spi/ax5043spi_p.h
cd init; gcc -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c init_main.c; cd ..
cd init; gcc -std=c99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c init_main.c; cd ..
afsktx/ax25.o: afsktx/ax25.c
afsktx/ax25.o: afsktx/ax25.h
afsktx/ax25.o: afsktx/ax5043.h
afsktx/ax25.o: afsktx/status.h
cd afsktx; gcc -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c ax25.c; cd ..
cd afsktx; gcc -std=c99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c ax25.c; cd ..
afsktx/ax5043.o: afsktx/ax5043.c
afsktx/ax5043.o: afsktx/ax25.h
@ -318,11 +324,11 @@ afsktx/ax5043.o: afsktx/ax5043.h
afsktx/ax5043.o: afsktx/status.h
afsktx/ax5043.o: afsktx/utils.h
afsktx/ax5043.o: ax5043/spi/ax5043spi.h
cd afsktx; gcc -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c ax5043.c; cd ..
cd afsktx; gcc -std=c99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c ax5043.c; cd ..
afsktx/main.o: afsktx/main.c
afsktx/main.o: afsktx/status.h
afsktx/main.o: afsktx/ax5043.h
afsktx/main.o: afsktx/ax25.h
afsktx/main.o: ax5043/spi/ax5043spi.h
cd afsktx; gcc -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c main.c; cd ..
cd afsktx; gcc -std=c99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c main.c; cd ..

@ -90,7 +90,6 @@ int z_fd; // I2C bos 0 address 0x44
int main(void) {
wiringPiSetup () ;
pinMode (0, OUTPUT) ;
int blink;
@ -99,179 +98,193 @@ int main(void) {
digitalWrite (0, HIGH) ; delay (500) ;
digitalWrite (0, LOW) ; delay (500) ;
}
digitalWrite (0, HIGH) ;
setSpiChannel(SPI_CHANNEL);
setSpiSpeed(SPI_SPEED);
initializeSpi();
int tlm[7][5];
memset(tlm, 0, sizeof tlm);
timestamp = time(NULL);
int file_i2c;
//char *filenam1e = (char*)"/dev/i2c-3";
if ((file_i2c = open("/dev/i2c-3", O_RDWR)) < 0)
{
fprintf(stderr,"ERROR: /dev/ic2-3 bus not present\n");
tempSensor = -1;
} else
{
tempSensor = wiringPiI2CSetupInterface("/dev/i2c-3", 0x48);
}
digitalWrite (0, HIGH) ;
setSpiChannel(SPI_CHANNEL);
setSpiSpeed(SPI_SPEED);
initializeSpi();
int tlm[7][5];
memset(tlm, 0, sizeof tlm);
timestamp = time(NULL);
int file_i2c = open("/dev/i2c-3", O_RDWR);
//char *filenam1e = (char*)"/dev/i2c-3";
if (file_i2c < 0)
{
fprintf(stderr,"ERROR: /dev/ic2-3 bus not present\n");
tempSensor = -1;
} else
{
tempSensor = wiringPiI2CSetupInterface("/dev/i2c-3", 0x48);
}
// fprintf(stderr,"tempSensor: %d \n",tempSensor);
#ifdef DEBUG_LOGGING
fprintf(stderr,"tempSensor: %d \n",tempSensor);
#endif
int arduinoI2C;
if ((arduinoI2C = open("/dev/i2c-0", O_RDWR)) < 0)
{
fprintf(stderr,"ERROR: /dev/i2c-0 bus not present\n");
int arduinoI2C = open("dev/i2c-0", O_RDWR);
if (arduinoI2C < 0)
{
fprintf(stderr,"ERROR: /dev/i2c-0 bus not present\n");
} else {
arduinoI2C = wiringPiI2CSetupInterface("/dev/i2c-0", 0x4B);
#ifdef DEBUG_LOGGING
fprintf(stderr,"arduinoI2C: %d\n", arduinoI2C);
#endif
if (arduinoI2C > 0) {
if(wiringPiI2CReadReg16(arduinoI2C,0) < 0) {
arduinoI2C = -1; // Disable reading of Arduino payload information
fprintf(stderr,"Arduino payload not present\n");
}
} else {
arduinoI2C = wiringPiI2CSetupInterface("/dev/i2c-0", 0x4B);
// fprintf(stderr,"arduinoI2C: %d\n", arduinoI2C);
if (arduinoI2C > 0) {
if(wiringPiI2CReadReg16(arduinoI2C,0) < 0) {
arduinoI2C = -1; // Disable reading of Arduino payload information
fprintf(stderr,"Arduino payload not present\n");
}
} else {
fprintf(stderr,"Arduino payload not present\n");
}
fprintf(stderr,"Arduino payload not present\n");
}
}
// new INA219 current reading code
x_calValue = 8192;
x_powerMultiplier = 1;
x_currentDivider = 20;
config = INA219_CONFIG_BVOLTAGERANGE_16V |
INA219_CONFIG_GAIN_40MV |
INA219_CONFIG_BADCRES_12BIT |
INA219_CONFIG_SADCRES_12BIT_4S_2130US |
//INA219_CONFIG_SADCRES_12BIT_1S_532US |
INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;
if ((file_i2c = open("/dev/i2c-0", O_RDWR)) < 0)
{
fprintf(stderr,"ERROR: /dev/ic2-0 bus not present\n");
x_fd = -1; // Disable reading -X, -Y, and -Z telemetry
y_fd = -1;
z_fd = -1;
} else
{
x_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40);
// fprintf(stderr,"Opening of -X fd %d\n", x_fd);
y_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x41);
// printf("Opening of -Y fd %d\n", y_fd);
z_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x44);
// printf("Opening of -Z fd %d\n", z_fd);
}
x_calValue = 8192;
x_powerMultiplier = 1;
x_currentDivider = 20;
config = INA219_CONFIG_BVOLTAGERANGE_16V |
INA219_CONFIG_GAIN_40MV |
INA219_CONFIG_BADCRES_12BIT |
INA219_CONFIG_SADCRES_12BIT_4S_2130US |
//INA219_CONFIG_SADCRES_12BIT_1S_532US |
INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;
if ((file_i2c = open("/dev/i2c-0", O_RDWR)) < 0)
{
fprintf(stderr,"ERROR: /dev/ic2-0 bus not present\n");
x_fd = -1; // Disable reading -X, -Y, and -Z telemetry
y_fd = -1;
z_fd = -1;
} else
{
x_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40);
y_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x41);
z_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x44);
#ifdef DEBUG_LOGGING
fprintf(stderr, "Opening of -X fd %d\n", x_fd);
fprintf(stderr, "Opening of -Y fd %d\n", y_fd);
fprintf(stderr, "Opening of -Z fd %d\n", z_fd);
#endif
}
int ret;
uint8_t data[1024];
int ret;
uint8_t data[1024];
tx_freq_hz -= tx_channel * 50000;
tx_freq_hz -= tx_channel * 50000;
init_rf();
init_rf();
// ax25_init(&hax25, (uint8_t *) "CubeSatSim", '2', (uint8_t *) CALLSIGN, '2',
ax25_init(&hax25, (uint8_t *) "CQ", '1', (uint8_t *) CALLSIGN, '1',
AX25_PREAMBLE_LEN,
AX25_POSTAMBLE_LEN);
ax25_init(&hax25, (uint8_t *) "CQ", '1', (uint8_t *) CALLSIGN, '1',
AX25_PREAMBLE_LEN,
AX25_POSTAMBLE_LEN);
/* Infinite loop */
for (;;) {
sleep(1);
/* Infinite loop */
for (;;) {
sleep(1);
fprintf(stderr,"INFO: Getting TLM Data\n");
fprintf(stderr,"INFO: Getting TLM Data\n");
get_tlm(tlm);
get_tlm(tlm);
fprintf(stderr,"INFO: Preparing X.25 packet\n");
fprintf(stderr,"INFO: Preparing X.25 packet\n");
char str[1000];
char tlm_str[1000];
char str[1000];
char tlm_str[1000];
char header_str[] = "\x03\xf0hi hi ";
strcpy(str, header_str);
char header_str[] = "\x03\xf0hi hi ";
strcpy(str, header_str);
int channel;
for (channel = 1; channel < 7; channel++) {
// printf("%d %d %d %d \n", tlm[channel][1], tlm[channel][2], tlm[channel][3], tlm[channel][4]);
sprintf(tlm_str, "%d%d%d %d%d%d %d%d%d %d%d%d ",
channel, upper_digit(tlm[channel][1]), lower_digit(tlm[channel][1]),
channel, upper_digit(tlm[channel][2]), lower_digit(tlm[channel][2]),
channel, upper_digit(tlm[channel][3]), lower_digit(tlm[channel][3]),
channel, upper_digit(tlm[channel][4]), lower_digit(tlm[channel][4]));
printf("%s \n",tlm_str);
strcat(str, tlm_str);
}
int channel;
for (channel = 1; channel < 7; channel++) {
#ifdef DEBUG_LOGGING
printf("%d %d %d %d \n", tlm[channel][1], tlm[channel][2], tlm[channel][3], tlm[channel][4]);
#endif
if (arduinoI2C > 0) { /* Read Arduino payload */
for(int reg = 0; reg < 4; reg++) {
sprintf(tlm_str, " %04x",wiringPiI2CReadReg16(arduinoI2C,reg));
printf("%s \n",tlm_str);
strcat(str,tlm_str); /* Append payload telemetry */
usleep(100000);
}
}
sprintf(tlm_str, "%d%d%d %d%d%d %d%d%d %d%d%d ",
channel, upper_digit(tlm[channel][1]), lower_digit(tlm[channel][1]),
channel, upper_digit(tlm[channel][2]), lower_digit(tlm[channel][2]),
channel, upper_digit(tlm[channel][3]), lower_digit(tlm[channel][3]),
channel, upper_digit(tlm[channel][4]), lower_digit(tlm[channel][4]));
printf("%s \n",tlm_str);
strcat(str, tlm_str);
}
digitalWrite (0, LOW);
if (arduinoI2C > 0) { /* Read Arduino payload */
for(int reg = 0; reg < 4; reg++) {
sprintf(tlm_str, " %04x",wiringPiI2CReadReg16(arduinoI2C,reg));
printf("%s \n",tlm_str);
strcat(str,tlm_str); /* Append payload telemetry */
usleep(100000);
}
}
digitalWrite (0, LOW);
/*
char cmdbuffer[1000];
char cmdbuffer[1000];
if (charging) {
FILE* file1 = popen("/home/pi/mopower/mpcmd LED_STAT=1", "r");
fgets(cmdbuffer, 999, file1);
pclose(file1);
if (charging) {
FILE* file1 = popen("/home/pi/mopower/mpcmd LED_STAT=1", "r");
fgets(cmdbuffer, 999, file1);
pclose(file1);
// printf("LED state: %s\n", cmdbuffer);
}
}
*/
fprintf(stderr,"INFO: Transmitting X.25 packet\n");
memcpy(data, str, strnlen(str, 256));
ret = ax25_tx_frame(&hax25, &hax5043, data, strnlen(str, 256));
if (ret) {
fprintf(stderr,
"ERROR: Failed to transmit AX.25 frame with error code %d\n",
ret);
exit(EXIT_FAILURE);
}
ax5043_wait_for_transmit();
digitalWrite (0, HIGH);
fprintf(stderr,"INFO: Transmitting X.25 packet\n");
memcpy(data, str, strnlen(str, 256));
ret = ax25_tx_frame(&hax25, &hax5043, data, strnlen(str, 256));
if (ret) {
fprintf(stderr,
"ERROR: Failed to transmit AX.25 frame with error code %d\n",
ret);
exit(EXIT_FAILURE);
}
ax5043_wait_for_transmit();
digitalWrite (0, HIGH);
/*
FILE* file2 = popen("/home/pi/mopower/mpcmd LED_STAT=0", "r");
fgets(cmdbuffer, 999, file2);
pclose(file2);
FILE* file2 = popen("/home/pi/mopower/mpcmd LED_STAT=0", "r");
fgets(cmdbuffer, 999, file2);
pclose(file2);
// printf("LED state: %s\n", cmdbuffer);
*/
if (ret) {
fprintf(stderr,
"ERROR: Failed to transmit entire AX.25 frame with error code %d\n",
ret);
exit(EXIT_FAILURE);
}
if (ret) {
fprintf(stderr,
"ERROR: Failed to transmit entire AX.25 frame with error code %d\n",
ret);
exit(EXIT_FAILURE);
}
}
return 0;
return 0;
}
static void init_rf() {
int ret;
fprintf(stderr,"Initializing AX5043\n");
ret = ax5043_init(&hax5043, XTAL_FREQ_HZ, VCO_INTERNAL);
if (ret != PQWS_SUCCESS) {
fprintf(stderr,
"ERROR: Failed to initialize AX5043 with error code %d\n", ret);
exit(EXIT_FAILURE);
}
int ret;
fprintf(stderr,"Initializing AX5043\n");
ret = ax5043_init(&hax5043, XTAL_FREQ_HZ, VCO_INTERNAL);
if (ret != PQWS_SUCCESS) {
fprintf(stderr,
"ERROR: Failed to initialize AX5043 with error code %d\n", ret);
exit(EXIT_FAILURE);
}
}
// Returns lower digit of a number which must be less than 99
@ -297,119 +310,135 @@ int upper_digit(int number) {
fprintf(stderr,"ERROR: Not a digit in upper_digit!\n");
return digit;
}
int get_tlm(int tlm[][5]) {
// Reading I2C voltage and current sensors
char cmdbuffer[1000];
FILE* file = popen("sudo python /home/pi/CubeSatSim/python/readcurrent.py 2>&1", "r");
fgets(cmdbuffer, 999, file);
pclose(file);
fprintf(stderr,"I2C Sensor data: %s\n", cmdbuffer);
char ina219[16][20]; // voltage, currents, and power from the INA219 current sensors x4a, x40, x41, x44, and x45.
int i = 0;
char * data2 = strtok (cmdbuffer," ");
while (data2 != NULL) {
strcpy(ina219[i], data2);
// printf ("ina219[%d]=%s\n",i,ina219[i]);
data2 = strtok (NULL, " ");
i++;
}
int get_tlm(int tlm[][5]) {
// Reading I2C voltage and current sensors
char cmdbuffer[1000];
FILE* file = popen("sudo python /home/pi/CubeSatSim/python/readcurrent.py 2>&1", "r");
fgets(cmdbuffer, 999, file);
pclose(file);
fprintf(stderr,"I2C Sensor data: %s\n", cmdbuffer);
char ina219[16][20]; // voltage, currents, and power from the INA219 current sensors x4a, x40, x41, x44, and x45.
int i = 0;
char * data2 = strtok (cmdbuffer," ");
while (data2 != NULL) {
strcpy(ina219[i], data2);
#ifdef DEBUG_LOGGING
printf ("ina219[%d]=%s\n",i,ina219[i]);
#endif
data2 = strtok (NULL, " ");
i++;
}
// Reading MoPower telemetry info
// Reading MoPower telemetry info
/*
file = popen("/home/pi/mopower/mpcmd show data", "r");
file = popen("/home/pi/mopower/mpcmd show data", "r");
fgets(cmdbuffer, 999, file);
fgets(cmdbuffer, 999, file);
pclose(file);
pclose(file);
// printf("MoPower data: %s\n", cmdbuffer);
char mopower[64][14];
char mopower[64][14];
// char str[] ="- This, a sample string.";
char * pch;
char * pch;
// printf ("Splitting string \"%s\" into tokens:\n",str);
// pch = strtok (str," ");
i = 0;
pch = strtok (cmdbuffer," ,.-");
while (pch != NULL)
{
strcpy(mopower[i], pch);
i = 0;
pch = strtok (cmdbuffer," ,.-");
while (pch != NULL)
{
strcpy(mopower[i], pch);
// printf ("mopwer[%d]=%s\n",i,mopower[i]); // pch);
pch = strtok (NULL, " ");
i++;
}
printf("Battery voltage = %s\n", mopower[16]);
if (strtof(mopower[17],NULL) > -0.5) {
charging = 1;
printf("Charging on\n");
}
else {
charging = 0;
printf("Charging off\n");
pch = strtok (NULL, " ");
i++;
}
printf("Battery voltage = %s\n", mopower[16]);
if (strtof(mopower[17],NULL) > -0.5) {
charging = 1;
printf("Charging on\n");
}
else {
charging = 0;
printf("Charging off\n");
}
}
*/
// read i2c current sensors //
double current = 0, power = 0, y_current = 0, y_power = 0, z_current = 0, z_power = 0;
if (x_fd != -1) {
wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue);
wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, config);
wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue);
current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider;
power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier;
wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue);
wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, config);
wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue);
y_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider;
y_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier;
wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue);
wiringPiI2CWriteReg16(z_fd, INA219_REG_CONFIG, config);
wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue);
z_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider;
z_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier;
}
printf("-X 0x40 current %4.2f power %4.2f -Y 0x41 current %4.2f power %4.2f -Z 0x44 current %4.2f power %4.2f \n",
current, power, y_current, y_power, z_current, z_power);
double current = 0, power = 0, y_current = 0, y_power = 0, z_current = 0, z_power = 0;
if (x_fd != -1) {
wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue);
wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, config);
wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue);
current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider;
power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier;
wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue);
wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, config);
wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue);
y_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider;
y_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier;
wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue);
wiringPiI2CWriteReg16(z_fd, INA219_REG_CONFIG, config);
wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue);
z_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider;
z_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier;
}
printf("-X 0x40 current %4.2f power %4.2f -Y 0x41 current %4.2f power %4.2f -Z 0x44 current %4.2f power %4.2f \n",
current,
power,
y_current,
y_power,
z_current,
z_power);
#ifdef DEBUG_LOGGING
printf("1B: ina219[%d]: %s val: %f \n", SENSOR_40 + CURRENT, ina219[SENSOR_40 + CURRENT], strtof(ina219[SENSOR_40 + CURRENT], NULL));
#endif
tlm[1][A] = (int)(strtof(ina219[SENSOR_4A + CURRENT], NULL) / 15 + 0.5) % 100; // Current of 5V supply to Pi
tlm[1][B] = (int) (99.5 - strtof(ina219[SENSOR_40 + CURRENT], NULL)/10) % 100; // +X current [4]
tlm[1][C] = (int) (99.5 - current/10) % 100; // X- current [10]
tlm[1][D] = (int) (99.5 - strtof(ina219[SENSOR_41 + CURRENT], NULL)/10) % 100; // +Y current [7]
tlm[2][A] = (int) (99.5 - y_current/10) % 100; // -Y current [10]
tlm[2][B] = (int) (99.5 - strtof(ina219[SENSOR_44 + CURRENT], NULL)/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel
tlm[2][C] = (int) (99.5 - z_current/10) % 100; // -Z current (was timestamp)
// printf("1B: ina219[%d]: %s val: %f \n", SENSOR_40 + CURRENT, ina219[SENSOR_40 + CURRENT], strtof(ina219[SENSOR_40 + CURRENT], NULL));
// tlm[2][C] = (int)((time(NULL) - timestamp) / 15) % 100;
tlm[2][D] = (int)(50.5 + strtof(ina219[SENSOR_45 + CURRENT], NULL)/10.0) % 100; // NiMH Battery current
tlm[1][A] = (int)(strtof(ina219[SENSOR_4A + CURRENT], NULL) / 15 + 0.5) % 100; // Current of 5V supply to Pi
tlm[1][B] = (int) (99.5 - strtof(ina219[SENSOR_40 + CURRENT], NULL)/10) % 100; // +X current [4]
tlm[1][C] = (int) (99.5 - current/10) % 100; // X- current [10]
tlm[1][D] = (int) (99.5 - strtof(ina219[SENSOR_41 + CURRENT], NULL)/10) % 100; // +Y current [7]
tlm[3][A] = abs((int)((strtof(ina219[SENSOR_45 + VOLTAGE], NULL) * 10) - 65.5) % 100);
tlm[3][B] = (int)(strtof(ina219[SENSOR_4A + VOLTAGE], NULL) * 10.0) % 100; // 5V supply to Pi
tlm[2][A] = (int) (99.5 - y_current/10) % 100; // -Y current [10]
tlm[2][B] = (int) (99.5 - strtof(ina219[SENSOR_44 + CURRENT], NULL)/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel
tlm[2][C] = (int) (99.5 - z_current/10) % 100; // -Z current (was timestamp)
if (tempSensor != -1) {
int tempValue = wiringPiI2CReadReg16(tempSensor, 0);
#ifdef DEBUG_LOGGING
printf("Read: %x\n", tempValue);
#endif
// tlm[2][C] = (int)((time(NULL) - timestamp) / 15) % 100;
tlm[2][D] = (int)(50.5 + strtof(ina219[SENSOR_45 + CURRENT], NULL)/10.0) % 100; // NiMH Battery current
uint8_t upper = (uint8_t) (tempValue >> 8);
uint8_t lower = (uint8_t) (tempValue & 0xff);
float temp = (float)lower + ((float)upper / 0x100);
tlm[3][A] = abs((int)((strtof(ina219[SENSOR_45 + VOLTAGE], NULL) * 10) - 65.5) % 100);
tlm[3][B] = (int)(strtof(ina219[SENSOR_4A + VOLTAGE], NULL) * 10.0) % 100; // 5V supply to Pi
if (tempSensor != -1) {
int tempValue = wiringPiI2CReadReg16(tempSensor, 0);
// printf("Read: %x\n", tempValue);
uint8_t upper = (uint8_t) (tempValue >> 8);
uint8_t lower = (uint8_t) (tempValue & 0xff);
float temp = (float)lower + ((float)upper / 0x100);
tlm[4][A] = (int)((95.8 - temp)/1.48 + 0.5) % 100;
}
tlm[4][A] = (int)((95.8 - temp)/1.48 + 0.5) % 100;
}
tlm[6][B] = 0 ;
tlm[6][D] = 49 + rand() % 3;
tlm[6][B] = 0 ;
tlm[6][D] = 49 + rand() % 3;
// Display tlm
int k, j;
for (k = 1; k < 7; k++) {
for (j = 1; j < 5; j++) {
printf(" %2d ", tlm[k][j]);
}
printf("\n");
int k, j;
for (k = 1; k < 7; k++) {
for (j = 1; j < 5; j++) {
printf(" %2d ", tlm[k][j]);
}
return 0;
printf("\n");
}
return 0;
}

Loading…
Cancel
Save

Powered by TurnKey Linux.