From 59b0f74e73011ffb3df7dafd979d3a1554cee570 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 15 Aug 2020 08:31:38 -0400 Subject: [PATCH 001/150] Update README.md --- README.md | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index a40d8112..e06955ce 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,5 @@ # CubeSatSim -To test out the PD120 SSTV image transmit after performing the software install steps below: - - -`cd ~/CubeSatSim` - -`git checkout dev` - -`git pull` - -`echo "ARG1=s" > .mode` - -`cd ~/pi-power-button` - -`git checkout dev` - -`git pull` - -`./script/install` - -`sudo systemctl restart cubesatsim` - - - - -You can also press and hold the push button and release on 4 flashes to switch to SSTV mode! - The CubeSat Simulator https://github.com/alanbjohnston/CubeSatSim/wiki is a low cost satellite emulator that runs on solar panels and batteries, transmits UHF radio telemetry, has a 3D printed frame, and can be extended by additional sensors and modules. This project is sponsored by the not-for-profit [Radio Amateur Satellite Corporation, AMSATĀ®](https://amsat.org). There are several hardware versions and software branches to go with them - see below for information. @@ -182,11 +156,13 @@ Press and release after two blinks of green LED: switches to FSK mode. After abo Press and release after three blinks of green LED: switches to BPSK mode. After about 5 seconds, the telemetry mode will switch to BPSK. +Press and release after four blinks of green LED: switches to SSTV mode. After about 5 seconds, the telemetry mode will switch to SSTV transmitting PD120 mode SSTV. + Press and release after green LED begins slow blinking: shuts down CubeSatSim. Once the CubeSatSim shuts down, the RBF pin can then be safely inserted. Removing the RBF pin or pressing the push button will cause the CubeSatSim to start up again. It will use the same mode it was running when it was shutdown. -You can also change the telemetry mode using the command line. Edit the CubeSatSim/.mode file and change the value to change the mode. A value of ARG1=a will give you AFSK, ARG1=f will give you FSK, and ARG2=b gives BPSK. After saving the .mode file, restart the cubesatsim service to switch the mode by typing: +You can also change the telemetry mode using the command line. Edit the CubeSatSim/.mode file and change the value to change the mode. A value of ARG1=a will give you AFSK, ARG1=f will give you FSK, ARG1=b gives BPSK, and ARG1=s gives SSTV. After saving the .mode file, restart the cubesatsim service to switch the mode by typing: `sudo systemctl restart cubesatsim` From efd3a1f19bcd13009a8405b1621b2aed44415c25 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 16 Aug 2020 07:42:13 -0400 Subject: [PATCH 002/150] Create ina219_test --- python/ina219_test | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 python/ina219_test diff --git a/python/ina219_test b/python/ina219_test new file mode 100644 index 00000000..037ddbc9 --- /dev/null +++ b/python/ina219_test @@ -0,0 +1,42 @@ +"""Sample code and test for adafruit_in219""" + +import time +import board +from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219 + + +i2c_bus = board.I2C() + +ina219 = INA219(i2c_bus) + +print("ina219 test") + +# display some of the advanced field (just to test) +print("Config register:") +print(" bus_voltage_range: 0x%1X" % ina219.bus_voltage_range) +print(" gain: 0x%1X" % ina219.gain) +print(" bus_adc_resolution: 0x%1X" % ina219.bus_adc_resolution) +print(" shunt_adc_resolution: 0x%1X" % ina219.shunt_adc_resolution) +print(" mode: 0x%1X" % ina219.mode) +print("") + +# optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage +ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S +ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S +# optional : change voltage range to 16V +ina219.bus_voltage_range = BusVoltageRange.RANGE_16V + +# measure and display loop +while True: + bus_voltage = ina219.bus_voltage # voltage on V- (load side) + shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt + current = ina219.current # current in mA + + # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage + print("PSU Voltage: {:6.3f} V".format(bus_voltage + shunt_voltage)) + print("Shunt Voltage: {:9.6f} V".format(shunt_voltage)) + print("Load Voltage: {:6.3f} V".format(bus_voltage)) + print("Current: {:9.6f} A".format(current / 1000)) + print("") + + time.sleep(2) From 3bc3848f43c7c8b132af66f9cc44fcfbb8b6b540 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 16 Aug 2020 07:52:52 -0400 Subject: [PATCH 003/150] Rename ina219_test to ina219_test.py --- python/{ina219_test => ina219_test.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename python/{ina219_test => ina219_test.py} (100%) diff --git a/python/ina219_test b/python/ina219_test.py similarity index 100% rename from python/ina219_test rename to python/ina219_test.py From c1d8a9442635ff42cd167414c6473738cc639519 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 16 Aug 2020 07:58:46 -0400 Subject: [PATCH 004/150] Update ina219_test.py --- python/ina219_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/ina219_test.py b/python/ina219_test.py index 037ddbc9..2a48de5c 100644 --- a/python/ina219_test.py +++ b/python/ina219_test.py @@ -7,6 +7,8 @@ from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219 i2c_bus = board.I2C() +print(i2c_bus) + ina219 = INA219(i2c_bus) print("ina219 test") From e65f36947857cdad67ed8b129081b0774dce4320 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 16 Aug 2020 08:12:45 -0400 Subject: [PATCH 005/150] Update ina219_test.py --- python/ina219_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ina219_test.py b/python/ina219_test.py index 2a48de5c..d7fc2639 100644 --- a/python/ina219_test.py +++ b/python/ina219_test.py @@ -5,7 +5,7 @@ import board from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219 -i2c_bus = board.I2C() +i2c_bus = board.I2C(GPIO.27, GPIO.28) print(i2c_bus) From dabebd1f91bc8feff6fd06f6a5f0910164bf8a62 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 16 Aug 2020 13:38:39 +0100 Subject: [PATCH 006/150] working --- python/ina219_test.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/python/ina219_test.py b/python/ina219_test.py index d7fc2639..38435a84 100644 --- a/python/ina219_test.py +++ b/python/ina219_test.py @@ -2,14 +2,19 @@ import time import board +import smbus from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219 +i2c_bus2 = smbus.SMBus(3) +b1 = i2c_bus2.read_i2c_block_data(0x45, 0x01, 2) +print (b1) -i2c_bus = board.I2C(GPIO.27, GPIO.28) + +i2c_bus = board.I2C() print(i2c_bus) -ina219 = INA219(i2c_bus) +ina219 = INA219(i2c_bus, 0x45) print("ina219 test") From 53c053916fdfff8d5adf07295369a5b2da8ccfda Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sun, 16 Aug 2020 23:14:24 +0100 Subject: [PATCH 007/150] can select bus 1 or 3 --- python/ina219_both_bus.py | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 python/ina219_both_bus.py diff --git a/python/ina219_both_bus.py b/python/ina219_both_bus.py new file mode 100644 index 00000000..4db29553 --- /dev/null +++ b/python/ina219_both_bus.py @@ -0,0 +1,62 @@ +"""Sample code and test for adafruit_in219""" + +import time +import board +import busio +import smbus +#from adafruit_blinka.microcontroller.bcm283x import pin +from adafruit_extended_bus import ExtendedI2C as I2C + +from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219 + +i2c_bus2 = smbus.SMBus(3) # 3 +b1 = i2c_bus2.read_i2c_block_data(0x45, 0x01, 2) +print (b1) + +#p = busio.I2C(scl, sda) +#p = busio.I2C(pin.D1,pin.D0) +#p = board.I2C(pin.D1,pin.D0) +#p.deinit() + +# Create library object using our Extended Bus I2C port +i2c_bus = I2C(3) # 1 Device is /dev/i2c-1 + + +#i2c_bus = board.I2C() +#i2c_bus = p + +print(i2c_bus) + +ina219 = INA219(i2c_bus, 0x45) + +print("ina219 test") + +# display some of the advanced field (just to test) +print("Config register:") +print(" bus_voltage_range: 0x%1X" % ina219.bus_voltage_range) +print(" gain: 0x%1X" % ina219.gain) +print(" bus_adc_resolution: 0x%1X" % ina219.bus_adc_resolution) +print(" shunt_adc_resolution: 0x%1X" % ina219.shunt_adc_resolution) +print(" mode: 0x%1X" % ina219.mode) +print("") + +# optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage +ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S +ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S +# optional : change voltage range to 16V +ina219.bus_voltage_range = BusVoltageRange.RANGE_16V + +# measure and display loop +while True: + bus_voltage = ina219.bus_voltage # voltage on V- (load side) + shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt + current = ina219.current # current in mA + + # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage + print("PSU Voltage: {:6.3f} V".format(bus_voltage + shunt_voltage)) + print("Shunt Voltage: {:9.6f} V".format(shunt_voltage)) + print("Load Voltage: {:6.3f} V".format(bus_voltage)) + print("Current: {:9.6f} A".format(current / 1000)) + print("") + + time.sleep(2) From 419065c881b25ff0946dbe6574420e22f7b55b34 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Mon, 17 Aug 2020 03:08:41 +0100 Subject: [PATCH 008/150] tested with bus 11 and mA --- python/ina219_both_bus.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python/ina219_both_bus.py b/python/ina219_both_bus.py index 4db29553..f6ee90d0 100644 --- a/python/ina219_both_bus.py +++ b/python/ina219_both_bus.py @@ -3,15 +3,15 @@ import time import board import busio -import smbus +#import smbus #from adafruit_blinka.microcontroller.bcm283x import pin from adafruit_extended_bus import ExtendedI2C as I2C from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219 -i2c_bus2 = smbus.SMBus(3) # 3 -b1 = i2c_bus2.read_i2c_block_data(0x45, 0x01, 2) -print (b1) +#i2c_bus2 = smbus.SMBus(3) # 3 +#b1 = i2c_bus2.read_i2c_block_data(0x45, 0x01, 2) +#print (b1) #p = busio.I2C(scl, sda) #p = busio.I2C(pin.D1,pin.D0) @@ -19,7 +19,7 @@ print (b1) #p.deinit() # Create library object using our Extended Bus I2C port -i2c_bus = I2C(3) # 1 Device is /dev/i2c-1 +i2c_bus = I2C(11) # 1 Device is /dev/i2c-1 #i2c_bus = board.I2C() @@ -56,7 +56,7 @@ while True: print("PSU Voltage: {:6.3f} V".format(bus_voltage + shunt_voltage)) print("Shunt Voltage: {:9.6f} V".format(shunt_voltage)) print("Load Voltage: {:6.3f} V".format(bus_voltage)) - print("Current: {:9.6f} A".format(current / 1000)) + print("Current: {:9.1f} mA".format(current)) print("") time.sleep(2) From fbbc8d53006157e7c21cfa96d704f8bf390c02ed Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 16 Aug 2020 22:22:38 -0400 Subject: [PATCH 009/150] Create voltage.py --- python/voltage.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 python/voltage.py diff --git a/python/voltage.py b/python/voltage.py new file mode 100644 index 00000000..84d8bbd2 --- /dev/null +++ b/python/voltage.py @@ -0,0 +1,48 @@ +"""Sample code and test for adafruit_in219""" + +import time +import board +import busio +from adafruit_extended_bus import ExtendedI2C as I2C +from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219 + +if __name__ == "__main__": +# print 'Length: ', len(sys.argv) + + if (len(sys.argv)) > 1: +# print("There are arguments!") +# if (('a' == sys.argv[1]) or ('afsk' in sys.argv[1])): + bus = int(sys.argv[1], base=10) + if (len(sys.argv)) > 2: + address = int(sys.argv[2], base=16) + elif + address = 0x40 + elfi + bus = 1 + address = 0x40 + + # Create library object using Extended Bus I2C port + i2c_bus = I2C(bus) # 1 Device is /dev/i2c-1 + + ina219 = INA219(i2c_bus, 0x45) + +# print("ina219 test") + +# optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage + ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S + ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S +# optional : change voltage range to 16V + ina219.bus_voltage_range = BusVoltageRange.RANGE_16V + + bus_voltage = ina219.bus_voltage # voltage on V- (load side) + shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt +# current = ina219.current # current in mA + + # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage + print("{:6.3f}".format(bus_voltage + shunt_voltage)) +# print("Shunt Voltage: {:9.6f} V".format(shunt_voltage)) +# print("Load Voltage: {:6.3f} V".format(bus_voltage)) +# print("Current: {:9.1f} mA".format(current)) +# print("") + +# time.sleep(2) From f88b5c3d55b6db7a19f25434ff81506ea36bc6f2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 16 Aug 2020 22:23:41 -0400 Subject: [PATCH 010/150] Update voltage.py --- python/voltage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/voltage.py b/python/voltage.py index 84d8bbd2..5d601ca5 100644 --- a/python/voltage.py +++ b/python/voltage.py @@ -15,9 +15,9 @@ if __name__ == "__main__": bus = int(sys.argv[1], base=10) if (len(sys.argv)) > 2: address = int(sys.argv[2], base=16) - elif + elif: address = 0x40 - elfi + elfi: bus = 1 address = 0x40 From 261aaaa63d92ddb53ba4732420f19876a6905233 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 16 Aug 2020 22:24:38 -0400 Subject: [PATCH 011/150] Update voltage.py --- python/voltage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/voltage.py b/python/voltage.py index 5d601ca5..fc7976fc 100644 --- a/python/voltage.py +++ b/python/voltage.py @@ -15,9 +15,9 @@ if __name__ == "__main__": bus = int(sys.argv[1], base=10) if (len(sys.argv)) > 2: address = int(sys.argv[2], base=16) - elif: + else: address = 0x40 - elfi: + else: bus = 1 address = 0x40 From 8fbedacbc09bb302f61ac5059cea1551628a85fc Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 16 Aug 2020 22:25:30 -0400 Subject: [PATCH 012/150] Update voltage.py --- python/voltage.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/voltage.py b/python/voltage.py index fc7976fc..6017d82d 100644 --- a/python/voltage.py +++ b/python/voltage.py @@ -34,12 +34,12 @@ if __name__ == "__main__": # optional : change voltage range to 16V ina219.bus_voltage_range = BusVoltageRange.RANGE_16V - bus_voltage = ina219.bus_voltage # voltage on V- (load side) - shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt + bus_voltage = ina219.bus_voltage # voltage on V- (load side) + shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt # current = ina219.current # current in mA # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage - print("{:6.3f}".format(bus_voltage + shunt_voltage)) + print("{:6.3f}".format(bus_voltage + shunt_voltage)) # print("Shunt Voltage: {:9.6f} V".format(shunt_voltage)) # print("Load Voltage: {:6.3f} V".format(bus_voltage)) # print("Current: {:9.1f} mA".format(current)) From 6f388cdfd1f113a57ddd79b488c171382774958c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 16 Aug 2020 22:26:06 -0400 Subject: [PATCH 013/150] Update voltage.py --- python/voltage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/voltage.py b/python/voltage.py index 6017d82d..e5270884 100644 --- a/python/voltage.py +++ b/python/voltage.py @@ -1,6 +1,6 @@ """Sample code and test for adafruit_in219""" -import time +import sys import board import busio from adafruit_extended_bus import ExtendedI2C as I2C From f6d31e9a30adc351cd3410af1d19e657e3575c28 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 16 Aug 2020 22:28:31 -0400 Subject: [PATCH 014/150] Update voltage.py --- python/voltage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/voltage.py b/python/voltage.py index e5270884..bb213882 100644 --- a/python/voltage.py +++ b/python/voltage.py @@ -20,11 +20,11 @@ if __name__ == "__main__": else: bus = 1 address = 0x40 - + # Create library object using Extended Bus I2C port i2c_bus = I2C(bus) # 1 Device is /dev/i2c-1 - ina219 = INA219(i2c_bus, 0x45) + ina219 = INA219(i2c_bus, address) # print("ina219 test") From 87921fd725ac06b0e4bac030f2e429f79f2d85cf Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 16 Aug 2020 22:30:21 -0400 Subject: [PATCH 015/150] Create current.py --- python/current.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 python/current.py diff --git a/python/current.py b/python/current.py new file mode 100644 index 00000000..30b24dd3 --- /dev/null +++ b/python/current.py @@ -0,0 +1,48 @@ +"""Sample code and test for adafruit_in219""" + +import sys +import board +import busio +from adafruit_extended_bus import ExtendedI2C as I2C +from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219 + +if __name__ == "__main__": +# print 'Length: ', len(sys.argv) + + if (len(sys.argv)) > 1: +# print("There are arguments!") +# if (('a' == sys.argv[1]) or ('afsk' in sys.argv[1])): + bus = int(sys.argv[1], base=10) + if (len(sys.argv)) > 2: + address = int(sys.argv[2], base=16) + else: + address = 0x40 + else: + bus = 1 + address = 0x40 + + # Create library object using Extended Bus I2C port + i2c_bus = I2C(bus) # 1 Device is /dev/i2c-1 + + ina219 = INA219(i2c_bus, address) + +# print("ina219 test") + +# optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage + ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S + ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S +# optional : change voltage range to 16V + ina219.bus_voltage_range = BusVoltageRange.RANGE_16V + + bus_voltage = ina219.bus_voltage # voltage on V- (load side) + shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt +# current = ina219.current # current in mA + + # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage +# print("{:6.3f}".format(bus_voltage + shunt_voltage)) +# print("Shunt Voltage: {:9.6f} V".format(shunt_voltage)) +# print("Load Voltage: {:6.3f} V".format(bus_voltage)) + print("{:9.1f}".format(current)) +# print("") + +# time.sleep(2) From 7c684b461eca977254f592d2125941175594d482 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 16 Aug 2020 22:31:22 -0400 Subject: [PATCH 016/150] Update current.py --- python/current.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/current.py b/python/current.py index 30b24dd3..0a91e670 100644 --- a/python/current.py +++ b/python/current.py @@ -34,9 +34,9 @@ if __name__ == "__main__": # optional : change voltage range to 16V ina219.bus_voltage_range = BusVoltageRange.RANGE_16V - bus_voltage = ina219.bus_voltage # voltage on V- (load side) - shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt -# current = ina219.current # current in mA +# bus_voltage = ina219.bus_voltage # voltage on V- (load side) +# shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt + current = ina219.current # current in mA # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage # print("{:6.3f}".format(bus_voltage + shunt_voltage)) From a54a31cfe7cfa5e60d7357120f3ce6e22a4c3425 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 16:58:54 -0400 Subject: [PATCH 017/150] add try exception for error --- python/voltage.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/python/voltage.py b/python/voltage.py index bb213882..38e91528 100644 --- a/python/voltage.py +++ b/python/voltage.py @@ -21,28 +21,24 @@ if __name__ == "__main__": bus = 1 address = 0x40 + try: # Create library object using Extended Bus I2C port - i2c_bus = I2C(bus) # 1 Device is /dev/i2c-1 + i2c_bus = I2C(bus) # 1 Device is /dev/i2c-1 + ina219 = INA219(i2c_bus, address) - ina219 = INA219(i2c_bus, address) - # print("ina219 test") # optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage - ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S - ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S + ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S + ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S # optional : change voltage range to 16V - ina219.bus_voltage_range = BusVoltageRange.RANGE_16V + ina219.bus_voltage_range = BusVoltageRange.RANGE_16V - bus_voltage = ina219.bus_voltage # voltage on V- (load side) - shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt + bus_voltage = ina219.bus_voltage # voltage on V- (load side) + shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt # current = ina219.current # current in mA +# INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage + print("{:6.3f}".format(bus_voltage + shunt_voltage)) - # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage - print("{:6.3f}".format(bus_voltage + shunt_voltage)) -# print("Shunt Voltage: {:9.6f} V".format(shunt_voltage)) -# print("Load Voltage: {:6.3f} V".format(bus_voltage)) -# print("Current: {:9.1f} mA".format(current)) -# print("") - -# time.sleep(2) + exception: + printf("0 Error\n") From a5f02a825d1d2382cbd0d65fda64bf9a1879dc57 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 16:59:53 -0400 Subject: [PATCH 018/150] Update voltage.py --- python/voltage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/voltage.py b/python/voltage.py index 38e91528..a9d569d1 100644 --- a/python/voltage.py +++ b/python/voltage.py @@ -40,5 +40,5 @@ if __name__ == "__main__": # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage print("{:6.3f}".format(bus_voltage + shunt_voltage)) - exception: + except: printf("0 Error\n") From 7ce40b8426e2f75003d3dbd98dbf597ce00e35e9 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 17:01:27 -0400 Subject: [PATCH 019/150] Update voltage.py --- python/voltage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/voltage.py b/python/voltage.py index a9d569d1..ca4f0efa 100644 --- a/python/voltage.py +++ b/python/voltage.py @@ -41,4 +41,4 @@ if __name__ == "__main__": print("{:6.3f}".format(bus_voltage + shunt_voltage)) except: - printf("0 Error\n") + print("0 Error\n") From 3f18dddaa0570d11a78ef114b53754b64bd5d512 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 17:02:18 -0400 Subject: [PATCH 020/150] Update voltage.py --- python/voltage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/voltage.py b/python/voltage.py index ca4f0efa..46be24de 100644 --- a/python/voltage.py +++ b/python/voltage.py @@ -41,4 +41,4 @@ if __name__ == "__main__": print("{:6.3f}".format(bus_voltage + shunt_voltage)) except: - print("0 Error\n") + print("0.0 Error") From 136a0fd055177d4f7a23caf80cd3a0228e253343 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 17:03:43 -0400 Subject: [PATCH 021/150] add try except --- python/current.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/python/current.py b/python/current.py index 0a91e670..634b18bd 100644 --- a/python/current.py +++ b/python/current.py @@ -21,28 +21,20 @@ if __name__ == "__main__": bus = 1 address = 0x40 - # Create library object using Extended Bus I2C port - i2c_bus = I2C(bus) # 1 Device is /dev/i2c-1 + try: +# Create library object using Extended Bus I2C port + i2c_bus = I2C(bus) # 1 Device is /dev/i2c-1 - ina219 = INA219(i2c_bus, address) - -# print("ina219 test") - + ina219 = INA219(i2c_bus, address) + # optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage - ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S - ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S + ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S + ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S # optional : change voltage range to 16V - ina219.bus_voltage_range = BusVoltageRange.RANGE_16V - -# bus_voltage = ina219.bus_voltage # voltage on V- (load side) -# shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt - current = ina219.current # current in mA + ina219.bus_voltage_range = BusVoltageRange.RANGE_16V - # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage -# print("{:6.3f}".format(bus_voltage + shunt_voltage)) -# print("Shunt Voltage: {:9.6f} V".format(shunt_voltage)) -# print("Load Voltage: {:6.3f} V".format(bus_voltage)) - print("{:9.1f}".format(current)) -# print("") + current = ina219.current # current in mA + print("{:9.1f}".format(current)) -# time.sleep(2) + except: + print("0.0 Error") From 3670d738c5be68ec1f3b7505c8ddf841b3468658 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 18:34:04 -0400 Subject: [PATCH 022/150] started adding python read --- afsk/telem.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 0e956f0e..1ecc7113 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -49,6 +49,7 @@ #define MINUS_Z 6 #define BUS 7 #define OFF -1 +#define ON 1 int twosToInt(int val, int len); @@ -58,6 +59,7 @@ struct SensorConfig { int calValue; int powerMultiplier; int currentDivider; + char command[30]; }; struct SensorData { @@ -82,11 +84,30 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { struct SensorData data = { .current = 0, .voltage = 0, - .power = 0 }; + .power = 0 + }; if (sensor.fd < 0) { return data; } + + FILE* file = popen("python3 /home/pi/CubeSatSim/python/voltage.py 1 0x44", "r"); + char cmdbuffer[1000]; + fgets(cmdbuffer, 1000, file); + pclose(file); + data.voltage = atof(cmdbuffer); + + printf("current: %s \n", cmdbuffer); + + file = popen("python3 /home/pi/CubeSatSim/python/current.py 1 0x44", "r"); + fgets(cmdbuffer, 1000, file); + pclose(file); + + printf("current: %s \n", cmdbuffer); + + data.current = atof(cmdbuffer); + +/* // doesn't read negative currents accurately, shows -0.1mA wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); @@ -107,7 +128,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { // power has very low resolution, seems to step in 512mW values delay(1); data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; - + */ return data; } @@ -152,7 +173,9 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { printf("ERROR: %s bus has a problem \n Check I2C wiring and pullup resistors \n", bus); data.fd = OFF; return (data); - } + } + data.fd = ON; +/* data.fd = wiringPiI2CSetupInterface(bus, address); data.config = INA219_CONFIG_BVOLTAGERANGE_32V | @@ -177,7 +200,8 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { // data.config, data.calValue, data.currentDivider, data.powerMultiplier); // printf("Sensor %s %x | ", bus, address); //#endif - return data; +*/ + return data; } struct SensorConfig sensorV; From 9568ac764b1f5aeebf07c6db0a42468f6f454666 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 18:46:34 -0400 Subject: [PATCH 023/150] Update telem.c --- afsk/telem.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 1ecc7113..536b1810 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -97,7 +97,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { pclose(file); data.voltage = atof(cmdbuffer); - printf("current: %s \n", cmdbuffer); + printf("voltage: %s \n", cmdbuffer); file = popen("python3 /home/pi/CubeSatSim/python/current.py 1 0x44", "r"); fgets(cmdbuffer, 1000, file); @@ -175,7 +175,20 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { return (data); } data.fd = ON; -/* + + char space[2] = " "; + char python[50] = "python3 /home/pi/CubeSatSim/python/voltage.py "; + + strcat (python, &bus[pos]); + strcat (python, space); + char addr[10]; + itoa(address, addr, 10); + strcat (python, addr); + strcpy (data.command, python); + + printf("Command: %s \n", data.command); + + /* data.fd = wiringPiI2CSetupInterface(bus, address); data.config = INA219_CONFIG_BVOLTAGERANGE_32V | From 48d3c7be053d3966fd9c76b2c8cc89b4083bbd1c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 18:50:24 -0400 Subject: [PATCH 024/150] snprintf --- afsk/telem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index 536b1810..463ca9a9 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -182,7 +182,8 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { strcat (python, &bus[pos]); strcat (python, space); char addr[10]; - itoa(address, addr, 10); + snprintf( addr, 10, "%d", address ); +// itoa(address, addr, 10); strcat (python, addr); strcpy (data.command, python); From 4b37f4b9e02ad306be08ead9f5c99833dc7bc967 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 18:52:25 -0400 Subject: [PATCH 025/150] Update telem.c --- afsk/telem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index 463ca9a9..5302e855 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -59,7 +59,7 @@ struct SensorConfig { int calValue; int powerMultiplier; int currentDivider; - char command[30]; + char command[100]; }; struct SensorData { From 8c1c9be42d728da3f2af00ece1c7435dbded5363 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 18:57:18 -0400 Subject: [PATCH 026/150] added current --- afsk/telem.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 5302e855..7d230a0e 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -59,7 +59,8 @@ struct SensorConfig { int calValue; int powerMultiplier; int currentDivider; - char command[100]; + char commandv[100]; + char commandi[100]; }; struct SensorData { @@ -177,17 +178,24 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { data.fd = ON; char space[2] = " "; - char python[50] = "python3 /home/pi/CubeSatSim/python/voltage.py "; - - strcat (python, &bus[pos]); - strcat (python, space); + char pythonv[50] = "python3 /home/pi/CubeSatSim/python/voltage.py "; + char pythoni[50] = "python3 /home/pi/CubeSatSim/python/current.py "; + + strcat (pythonv, &bus[pos]); + strcat (pythonv, space); char addr[10]; - snprintf( addr, 10, "%d", address ); -// itoa(address, addr, 10); - strcat (python, addr); - strcpy (data.command, python); + snprintf( addr, 10, "%x", address ); + strcat (pythonv, addr); + strcpy (data.commandv, pythonv); + + printf("V Command: %s \n", data.vcommand); + + strcat (pythoni, &bus[pos]); + strcat (pythoni, space); + strcat (pythoni, addr); + strcpy (data.commandi, pythoni); - printf("Command: %s \n", data.command); + printf("V Command: %s \n", data.commandi); /* data.fd = wiringPiI2CSetupInterface(bus, address); From 0c2c7df8bb00d946562ca6e2e5f1cfadd3f93285 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 18:57:59 -0400 Subject: [PATCH 027/150] Update telem.c --- afsk/telem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index 7d230a0e..30b285e0 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -188,7 +188,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { strcat (pythonv, addr); strcpy (data.commandv, pythonv); - printf("V Command: %s \n", data.vcommand); + printf("V Command: %s \n", data.commandv); strcat (pythoni, &bus[pos]); strcat (pythoni, space); From 78d9e0260eebd7b72bb2221dce16ad08efd899d2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 19:00:55 -0400 Subject: [PATCH 028/150] Update telem.c --- afsk/telem.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 30b285e0..211c7349 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -92,7 +92,8 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { return data; } - FILE* file = popen("python3 /home/pi/CubeSatSim/python/voltage.py 1 0x44", "r"); +// FILE* file = popen("python3 /home/pi/CubeSatSim/python/voltage.py 1 0x44", "r"); + FILE* file = popen(data.commandv, "r"); char cmdbuffer[1000]; fgets(cmdbuffer, 1000, file); pclose(file); @@ -100,7 +101,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { printf("voltage: %s \n", cmdbuffer); - file = popen("python3 /home/pi/CubeSatSim/python/current.py 1 0x44", "r"); + file = popen(data.commandi, "r"); fgets(cmdbuffer, 1000, file); pclose(file); @@ -177,7 +178,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { } data.fd = ON; - char space[2] = " "; + char space[4] = " 0x"; char pythonv[50] = "python3 /home/pi/CubeSatSim/python/voltage.py "; char pythoni[50] = "python3 /home/pi/CubeSatSim/python/current.py "; From d7cc00952d41178d3f6be3049a325d9491e5bad7 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 19:02:51 -0400 Subject: [PATCH 029/150] Update telem.c --- afsk/telem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 211c7349..54404801 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -93,7 +93,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { } // FILE* file = popen("python3 /home/pi/CubeSatSim/python/voltage.py 1 0x44", "r"); - FILE* file = popen(data.commandv, "r"); + FILE* file = popen(sensor.commandv, "r"); char cmdbuffer[1000]; fgets(cmdbuffer, 1000, file); pclose(file); @@ -101,7 +101,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { printf("voltage: %s \n", cmdbuffer); - file = popen(data.commandi, "r"); + file = popen(sensor.commandi, "r"); fgets(cmdbuffer, 1000, file); pclose(file); From c15f9ef73443d9b82e0aa6ed645d9d3d53e7f4a1 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 19:05:03 -0400 Subject: [PATCH 030/150] Update telem.c --- afsk/telem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index 54404801..2414ed94 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -178,7 +178,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { } data.fd = ON; - char space[4] = " 0x"; + char space[] = " 0x"; char pythonv[50] = "python3 /home/pi/CubeSatSim/python/voltage.py "; char pythoni[50] = "python3 /home/pi/CubeSatSim/python/current.py "; From 13c8bda5a971ea53fa7f359989562ea42acc06f4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 19:06:39 -0400 Subject: [PATCH 031/150] Update telem.c --- afsk/telem.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 2414ed94..dffff5ed 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -178,21 +178,22 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { } data.fd = ON; - char space[] = " 0x"; - char pythonv[50] = "python3 /home/pi/CubeSatSim/python/voltage.py "; - char pythoni[50] = "python3 /home/pi/CubeSatSim/python/current.py "; + char spacev[] = " 0x"; + char pythonv[100] = "python3 /home/pi/CubeSatSim/python/voltage.py "; + char pythoni[100] = "python3 /home/pi/CubeSatSim/python/current.py "; strcat (pythonv, &bus[pos]); - strcat (pythonv, space); + strcat (pythonv, spacev); char addr[10]; snprintf( addr, 10, "%x", address ); strcat (pythonv, addr); strcpy (data.commandv, pythonv); printf("V Command: %s \n", data.commandv); - + + char spacei[] = " 0x"; strcat (pythoni, &bus[pos]); - strcat (pythoni, space); + strcat (pythoni, spacei); strcat (pythoni, addr); strcpy (data.commandi, pythoni); From 85fb433d1d90c8e416aa6a1d27d1162d2e9faec6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 20:26:46 -0400 Subject: [PATCH 032/150] use strtok --- afsk/telem.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/afsk/telem.c b/afsk/telem.c index dffff5ed..21a0899d 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -155,6 +155,14 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { return (data); } + //char st[] ="Where there is will, there is a way."; + char *ch; + const char s[2] = "-"; + ch = strtok(bus, "-"); + printf("ch: %s\n", ch); + ch = strtok(NULL, "-"); + printf("ch: %s\n", ch); + char result[128]; int pos = strlen(bus) / sizeof(bus[0]) - 1; // printf("Bus size %d \n", pos); From 4ec7458671077a5161cf3cf7211393e97bbca6a2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 20:29:39 -0400 Subject: [PATCH 033/150] Update telem.c --- afsk/telem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index 21a0899d..c8c086ee 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -158,7 +158,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { //char st[] ="Where there is will, there is a way."; char *ch; const char s[2] = "-"; - ch = strtok(bus, "-"); + ch = strtok(&bus, "-"); printf("ch: %s\n", ch); ch = strtok(NULL, "-"); printf("ch: %s\n", ch); From b8f0064de13183b93cc02061a6e33a92b7da7ca6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 20:31:30 -0400 Subject: [PATCH 034/150] Update telem.c --- afsk/telem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index c8c086ee..fce8f63e 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -157,10 +157,10 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { //char st[] ="Where there is will, there is a way."; char *ch; - const char s[2] = "-"; - ch = strtok(&bus, "-"); + const char dash[2] = "-"; + ch = strtok(&bus, dash); printf("ch: %s\n", ch); - ch = strtok(NULL, "-"); + ch = strtok(NULL, dash); printf("ch: %s\n", ch); char result[128]; From 92847b48d064813574a22cb819d6aa431baf7791 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 20:32:36 -0400 Subject: [PATCH 035/150] Update telem.c --- afsk/telem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index fce8f63e..063b8074 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -158,7 +158,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { //char st[] ="Where there is will, there is a way."; char *ch; const char dash[2] = "-"; - ch = strtok(&bus, dash); + ch = strtok(bus, dash); printf("ch: %s\n", ch); ch = strtok(NULL, dash); printf("ch: %s\n", ch); From c49b3a0c1863c29d0728d3408bfb8b647972504d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 20:35:28 -0400 Subject: [PATCH 036/150] Update telem.c --- afsk/telem.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 063b8074..acd7f85c 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -155,10 +155,11 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { return (data); } - //char st[] ="Where there is will, there is a way."; + char str[100]; + strcpy (str, &bus); char *ch; const char dash[2] = "-"; - ch = strtok(bus, dash); + ch = strtok(str, dash); printf("ch: %s\n", ch); ch = strtok(NULL, dash); printf("ch: %s\n", ch); From f8880adf9d1450ba4af99386e35b0296ccbc409c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 20:36:02 -0400 Subject: [PATCH 037/150] Update telem.c --- afsk/telem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index acd7f85c..b37a7233 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -156,7 +156,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { } char str[100]; - strcpy (str, &bus); + strcpy (str, bus); char *ch; const char dash[2] = "-"; ch = strtok(str, dash); From 742f10d9acc28e127e1ad7a9b946ff90e55ed46f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 20:39:01 -0400 Subject: [PATCH 038/150] Update telem.c --- afsk/telem.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index b37a7233..8e08914e 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -157,19 +157,21 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { char str[100]; strcpy (str, bus); - char *ch; + char *buss; const char dash[2] = "-"; - ch = strtok(str, dash); - printf("ch: %s\n", ch); - ch = strtok(NULL, dash); - printf("ch: %s\n", ch); + buss = strtok(str, dash); +// printf("buss: %s\n", buss); + buss = strtok(NULL, dash); +// printf("bus: %s\n", buss); char result[128]; int pos = strlen(bus) / sizeof(bus[0]) - 1; // printf("Bus size %d \n", pos); // printf("Bus value %d \n", atoi(&bus[pos])); char command[50] = "timeout 10 i2cdetect -y "; - strcat (command, &bus[pos]); +// strcat (command, &bus[pos]); + strcat (command, buss); + printf("Command: %s \n", command); FILE *i2cdetect = popen(command, "r"); while (fgets(result, 128, i2cdetect) != NULL) { @@ -191,7 +193,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { char pythonv[100] = "python3 /home/pi/CubeSatSim/python/voltage.py "; char pythoni[100] = "python3 /home/pi/CubeSatSim/python/current.py "; - strcat (pythonv, &bus[pos]); + strcat (pythonv, buss); strcat (pythonv, spacev); char addr[10]; snprintf( addr, 10, "%x", address ); @@ -201,7 +203,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { printf("V Command: %s \n", data.commandv); char spacei[] = " 0x"; - strcat (pythoni, &bus[pos]); + strcat (pythoni, buss); strcat (pythoni, spacei); strcat (pythoni, addr); strcpy (data.commandi, pythoni); From 469a2bfbefd757c4088b71976729d3a148c495c9 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 17 Aug 2020 20:42:33 -0400 Subject: [PATCH 039/150] cleanup after dealing with bus 11 properly and using python read --- afsk/telem.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 8e08914e..2255de10 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -99,13 +99,13 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { pclose(file); data.voltage = atof(cmdbuffer); - printf("voltage: %s \n", cmdbuffer); +// printf("voltage: %s \n", cmdbuffer); file = popen(sensor.commandi, "r"); fgets(cmdbuffer, 1000, file); pclose(file); - printf("current: %s \n", cmdbuffer); +// printf("current: %s \n", cmdbuffer); data.current = atof(cmdbuffer); @@ -171,7 +171,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { char command[50] = "timeout 10 i2cdetect -y "; // strcat (command, &bus[pos]); strcat (command, buss); - printf("Command: %s \n", command); +// printf("Command: %s \n", command); FILE *i2cdetect = popen(command, "r"); while (fgets(result, 128, i2cdetect) != NULL) { @@ -200,7 +200,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { strcat (pythonv, addr); strcpy (data.commandv, pythonv); - printf("V Command: %s \n", data.commandv); +// printf("V Command: %s \n", data.commandv); char spacei[] = " 0x"; strcat (pythoni, buss); @@ -208,7 +208,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { strcat (pythoni, addr); strcpy (data.commandi, pythoni); - printf("V Command: %s \n", data.commandi); +// printf("V Command: %s \n", data.commandi); /* data.fd = wiringPiI2CSetupInterface(bus, address); From 017607379e7c64e8f2c4e3b4934f0ddc20955561 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 09:47:51 -0400 Subject: [PATCH 040/150] changed ADC from 32S to 1S --- python/current.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/current.py b/python/current.py index 634b18bd..0a579fad 100644 --- a/python/current.py +++ b/python/current.py @@ -28,8 +28,8 @@ if __name__ == "__main__": ina219 = INA219(i2c_bus, address) # optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage - ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S - ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S + ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_1S // 32S + ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_1S // 32S # optional : change voltage range to 16V ina219.bus_voltage_range = BusVoltageRange.RANGE_16V From 6ca076737449501663a7c47194ab36d5b398b699 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 09:48:34 -0400 Subject: [PATCH 041/150] changed ADC from 32S to 1S --- python/voltage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/voltage.py b/python/voltage.py index 46be24de..2afd2f2a 100644 --- a/python/voltage.py +++ b/python/voltage.py @@ -29,8 +29,8 @@ if __name__ == "__main__": # print("ina219 test") # optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage - ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S - ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S + ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_1S // 32S + ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_1S // 32S # optional : change voltage range to 16V ina219.bus_voltage_range = BusVoltageRange.RANGE_16V From a2a99f26e99818a7c453916ae6d9799e5551592d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 09:49:27 -0400 Subject: [PATCH 042/150] typo --- python/voltage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/voltage.py b/python/voltage.py index 2afd2f2a..dc00ff81 100644 --- a/python/voltage.py +++ b/python/voltage.py @@ -29,8 +29,8 @@ if __name__ == "__main__": # print("ina219 test") # optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage - ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_1S // 32S - ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_1S // 32S + ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_1S # 32S + ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_1S # 32S # optional : change voltage range to 16V ina219.bus_voltage_range = BusVoltageRange.RANGE_16V From f95a2e6d58041c27ec6861b5b58d83600084eb9c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 09:49:57 -0400 Subject: [PATCH 043/150] typo --- python/current.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/current.py b/python/current.py index 0a579fad..409ca7ba 100644 --- a/python/current.py +++ b/python/current.py @@ -28,8 +28,8 @@ if __name__ == "__main__": ina219 = INA219(i2c_bus, address) # optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage - ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_1S // 32S - ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_1S // 32S + ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_1S # 32S + ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_1S # 32S # optional : change voltage range to 16V ina219.bus_voltage_range = BusVoltageRange.RANGE_16V From 4e41238f9f21efbf20c7ec7ba4216fcbd655289a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 14:31:29 -0400 Subject: [PATCH 044/150] Create voltcurrent.py --- python/voltcurrent.py | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 python/voltcurrent.py diff --git a/python/voltcurrent.py b/python/voltcurrent.py new file mode 100644 index 00000000..d00a997a --- /dev/null +++ b/python/voltcurrent.py @@ -0,0 +1,51 @@ +"""Sample code and test for adafruit_in219""" +# Reads all voltage and current sensors for two I2C buses + +import sys +#import board +import busio +from adafruit_extended_bus import ExtendedI2C as I2C +from adafruit_ina219 import INA219 + +if __name__ == "__main__": +# print 'Length: ', len(sys.argv) + + buses = [1, 3] # default I2C buses + + if (len(sys.argv)) > 1: +# print("There are arguments!") +# if (('a' == sys.argv[1]) or ('afsk' in sys.argv[1])): + buses[1] = int(sys.argv[1], base=10) + if (len(sys.argv)) > 2: + buses[2] = int(sys.argv[2], base=10) + if (len(sys.argv)) > 3: + if sys.argv[3] == 'c' + config = True + from adafruit_ina219 import ADCResolution, BusVoltageRange + + addresses = [0x40, 0x41, 0x44, 0x45] #INA219 addresses on the bus + + for x in buses: + for y in addresses: + try: + # Create library object using Extended Bus I2C port + i2c_bus = I2C(buses[x]) # 1 Device is /dev/i2c-1 + ina219 = INA219(i2c_bus, addresses[y]) + +# print("ina219 test") + if config: +# optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage + ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_1S # 32S + ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_1S # 32S +# optional : change voltage range to 16V + ina219.bus_voltage_range = BusVoltageRange.RANGE_16V + + bus_voltage = ina219.bus_voltage # voltage on V- (load side) +# shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt + current = ina219.current # current in mA +# INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage +# print("{:6.3f}".format(bus_voltage + shunt_voltage)) + print(bus_voltage, " ", current, " ") + except: + print("0.0 Error") + From 62970cbea5318ba96222b8d13f12a3c894fcda6a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 14:32:31 -0400 Subject: [PATCH 045/150] typo --- python/voltcurrent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index d00a997a..dfd0018f 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -19,7 +19,7 @@ if __name__ == "__main__": if (len(sys.argv)) > 2: buses[2] = int(sys.argv[2], base=10) if (len(sys.argv)) > 3: - if sys.argv[3] == 'c' + if sys.argv[3] == "c" config = True from adafruit_ina219 import ADCResolution, BusVoltageRange From 6b949a363cfcf170a770ad0e3f67003d2d2583d7 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 14:33:13 -0400 Subject: [PATCH 046/150] Update voltcurrent.py --- python/voltcurrent.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index dfd0018f..67746e59 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -11,6 +11,7 @@ if __name__ == "__main__": # print 'Length: ', len(sys.argv) buses = [1, 3] # default I2C buses + config = False if (len(sys.argv)) > 1: # print("There are arguments!") @@ -19,7 +20,7 @@ if __name__ == "__main__": if (len(sys.argv)) > 2: buses[2] = int(sys.argv[2], base=10) if (len(sys.argv)) > 3: - if sys.argv[3] == "c" + if sys.argv[3] == "c": config = True from adafruit_ina219 import ADCResolution, BusVoltageRange From 8f2981249c01522a18847109c723188aaf716b60 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 14:33:58 -0400 Subject: [PATCH 047/150] Update voltcurrent.py --- python/voltcurrent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 67746e59..8f7f787b 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -48,5 +48,5 @@ if __name__ == "__main__": # print("{:6.3f}".format(bus_voltage + shunt_voltage)) print(bus_voltage, " ", current, " ") except: - print("0.0 Error") + print("0.0 Error") From 3d1708d027169d378497604dbeebdb40f83fce07 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 14:45:00 -0400 Subject: [PATCH 048/150] Update voltcurrent.py --- python/voltcurrent.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 8f7f787b..9dbf6273 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -30,11 +30,13 @@ if __name__ == "__main__": for y in addresses: try: # Create library object using Extended Bus I2C port + print("bus: ", buses[x], " addr: ", addresses[y]) i2c_bus = I2C(buses[x]) # 1 Device is /dev/i2c-1 ina219 = INA219(i2c_bus, addresses[y]) # print("ina219 test") if config: + print("Configuring") # optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_1S # 32S ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_1S # 32S From 7ecfe08988821a0ac6bf37e2619bcf188d10923a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 14:48:57 -0400 Subject: [PATCH 049/150] Update voltcurrent.py --- python/voltcurrent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 9dbf6273..1c67f9eb 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -16,9 +16,9 @@ if __name__ == "__main__": if (len(sys.argv)) > 1: # print("There are arguments!") # if (('a' == sys.argv[1]) or ('afsk' in sys.argv[1])): - buses[1] = int(sys.argv[1], base=10) + buses[0] = int(sys.argv[1], base=10) if (len(sys.argv)) > 2: - buses[2] = int(sys.argv[2], base=10) + buses[1] = int(sys.argv[2], base=10) if (len(sys.argv)) > 3: if sys.argv[3] == "c": config = True From c56134ffe404d7a0839158fec09892bbfa60f70d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 14:50:14 -0400 Subject: [PATCH 050/150] Update voltcurrent.py --- python/voltcurrent.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 1c67f9eb..51fbdfd6 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -25,9 +25,10 @@ if __name__ == "__main__": from adafruit_ina219 import ADCResolution, BusVoltageRange addresses = [0x40, 0x41, 0x44, 0x45] #INA219 addresses on the bus - + print("buses: ", buses, " addr: ", addresses) for x in buses: for y in addresses: + print(x,y) try: # Create library object using Extended Bus I2C port print("bus: ", buses[x], " addr: ", addresses[y]) From d1dd66377e9361922dbce91958ea905a2dbb24f6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 14:50:55 -0400 Subject: [PATCH 051/150] Update voltcurrent.py --- python/voltcurrent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 51fbdfd6..820c8186 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -24,7 +24,7 @@ if __name__ == "__main__": config = True from adafruit_ina219 import ADCResolution, BusVoltageRange - addresses = [0x40, 0x41, 0x44, 0x45] #INA219 addresses on the bus + addresses = [40, 41, 44, 45] #INA219 addresses on the bus print("buses: ", buses, " addr: ", addresses) for x in buses: for y in addresses: From 5b368bc3bff5e494251de95a4035d6830a7461a4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 14:52:46 -0400 Subject: [PATCH 052/150] Update voltcurrent.py --- python/voltcurrent.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 820c8186..dbcb11da 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -29,7 +29,7 @@ if __name__ == "__main__": for x in buses: for y in addresses: print(x,y) - try: +# try: # Create library object using Extended Bus I2C port print("bus: ", buses[x], " addr: ", addresses[y]) i2c_bus = I2C(buses[x]) # 1 Device is /dev/i2c-1 @@ -50,6 +50,6 @@ if __name__ == "__main__": # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage # print("{:6.3f}".format(bus_voltage + shunt_voltage)) print(bus_voltage, " ", current, " ") - except: - print("0.0 Error") +# except: +# print("0.0 Error") From 6aa1723bdf82a1958cf6e0230c7d503b8a540237 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 14:53:36 -0400 Subject: [PATCH 053/150] Update voltcurrent.py --- python/voltcurrent.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index dbcb11da..19e491df 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -29,7 +29,8 @@ if __name__ == "__main__": for x in buses: for y in addresses: print(x,y) -# try: +# try: + if True: # Create library object using Extended Bus I2C port print("bus: ", buses[x], " addr: ", addresses[y]) i2c_bus = I2C(buses[x]) # 1 Device is /dev/i2c-1 From 6a9c956d1dff496d1d0fd3c34bab02a1f464315f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 14:55:08 -0400 Subject: [PATCH 054/150] Update voltcurrent.py --- python/voltcurrent.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 19e491df..b8e6d6db 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -32,9 +32,9 @@ if __name__ == "__main__": # try: if True: # Create library object using Extended Bus I2C port - print("bus: ", buses[x], " addr: ", addresses[y]) - i2c_bus = I2C(buses[x]) # 1 Device is /dev/i2c-1 - ina219 = INA219(i2c_bus, addresses[y]) + print("bus: ", x, " addr: ", y) + i2c_bus = I2C(x) # 1 Device is /dev/i2c-1 + ina219 = INA219(i2c_bus, y) # print("ina219 test") if config: From bb1573c00d76936eb3633d5cd2b0c034af66b5d4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 14:56:08 -0400 Subject: [PATCH 055/150] Update voltcurrent.py --- python/voltcurrent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index b8e6d6db..84dee0b3 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -24,7 +24,7 @@ if __name__ == "__main__": config = True from adafruit_ina219 import ADCResolution, BusVoltageRange - addresses = [40, 41, 44, 45] #INA219 addresses on the bus + addresses = [0x40, 0x41, 0x44, 0x45] #INA219 addresses on the bus print("buses: ", buses, " addr: ", addresses) for x in buses: for y in addresses: From d81234322a214550d9c2297b7d9f940abf63e7f1 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 14:58:58 -0400 Subject: [PATCH 056/150] Update voltcurrent.py --- python/voltcurrent.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 84dee0b3..0b10c635 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -28,11 +28,10 @@ if __name__ == "__main__": print("buses: ", buses, " addr: ", addresses) for x in buses: for y in addresses: - print(x,y) -# try: - if True: + # print(x,y) + try: # Create library object using Extended Bus I2C port - print("bus: ", x, " addr: ", y) +# print("bus: ", x, " addr: ", y) i2c_bus = I2C(x) # 1 Device is /dev/i2c-1 ina219 = INA219(i2c_bus, y) @@ -51,6 +50,6 @@ if __name__ == "__main__": # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage # print("{:6.3f}".format(bus_voltage + shunt_voltage)) print(bus_voltage, " ", current, " ") -# except: -# print("0.0 Error") + except: +# print("0.0 Error) From 3076df58408bd9434b14db4e8e4ae78790eaee84 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 15:00:03 -0400 Subject: [PATCH 057/150] Update voltcurrent.py --- python/voltcurrent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 0b10c635..38f6c639 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -52,4 +52,4 @@ if __name__ == "__main__": print(bus_voltage, " ", current, " ") except: # print("0.0 Error) - + pass From 5b08dffe035c419a3d1fadb879118e4fea063a70 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 15:02:09 -0400 Subject: [PATCH 058/150] Update voltcurrent.py --- python/voltcurrent.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 38f6c639..49f370f8 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -49,7 +49,7 @@ if __name__ == "__main__": current = ina219.current # current in mA # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage # print("{:6.3f}".format(bus_voltage + shunt_voltage)) - print(bus_voltage, " ", current, " ") + print(bus_voltage, " ", current, " ", end = '') except: -# print("0.0 Error) - pass + print("0.0 0.0", end = '') +# pass From 83ec55bfeb714c96b92d72f07155ea864bee1b23 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 15:03:10 -0400 Subject: [PATCH 059/150] Update voltcurrent.py --- python/voltcurrent.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 49f370f8..ef359398 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -25,7 +25,7 @@ if __name__ == "__main__": from adafruit_ina219 import ADCResolution, BusVoltageRange addresses = [0x40, 0x41, 0x44, 0x45] #INA219 addresses on the bus - print("buses: ", buses, " addr: ", addresses) +# print("buses: ", buses, " addr: ", addresses) for x in buses: for y in addresses: # print(x,y) @@ -51,5 +51,6 @@ if __name__ == "__main__": # print("{:6.3f}".format(bus_voltage + shunt_voltage)) print(bus_voltage, " ", current, " ", end = '') except: - print("0.0 0.0", end = '') + print("0.0 0.0 ", end = '') # pass + print(" ") From 4893f306e86973f808cc7a46e0391d69a7b27752 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 15:18:55 -0400 Subject: [PATCH 060/150] Update voltcurrent.py --- python/voltcurrent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index ef359398..cd40bf0c 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -49,8 +49,8 @@ if __name__ == "__main__": current = ina219.current # current in mA # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage # print("{:6.3f}".format(bus_voltage + shunt_voltage)) - print(bus_voltage, " ", current, " ", end = '') + print("{:6.3f} ".format(bus_voltage), "{:6.3f} ".format(current) , end = '') except: - print("0.0 0.0 ", end = '') + print("{:6.3f} ".format(0), "{:6.3f} ".format(0), end = '') # pass print(" ") From d6a11e46773f60dfc9efd36d31a2105578793606 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 15:20:03 -0400 Subject: [PATCH 061/150] Update voltcurrent.py --- python/voltcurrent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index cd40bf0c..4673c4bb 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -49,8 +49,8 @@ if __name__ == "__main__": current = ina219.current # current in mA # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage # print("{:6.3f}".format(bus_voltage + shunt_voltage)) - print("{:6.3f} ".format(bus_voltage), "{:6.3f} ".format(current) , end = '') + print("{:5.3f} ".format(bus_voltage), "{:6.1f} ".format(current) , end = '') except: - print("{:6.3f} ".format(0), "{:6.3f} ".format(0), end = '') + print("{:5.3f} ".format(0), "{:6.1f} ".format(0), end = '') # pass print(" ") From 6f5ead79dc3b311a9f6d4340d6929e319a9464fa Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 15:21:06 -0400 Subject: [PATCH 062/150] Update voltcurrent.py --- python/voltcurrent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 4673c4bb..cd40bf0c 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -49,8 +49,8 @@ if __name__ == "__main__": current = ina219.current # current in mA # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage # print("{:6.3f}".format(bus_voltage + shunt_voltage)) - print("{:5.3f} ".format(bus_voltage), "{:6.1f} ".format(current) , end = '') + print("{:6.3f} ".format(bus_voltage), "{:6.3f} ".format(current) , end = '') except: - print("{:5.3f} ".format(0), "{:6.1f} ".format(0), end = '') + print("{:6.3f} ".format(0), "{:6.3f} ".format(0), end = '') # pass print(" ") From bc44069034d2f3c4db248b9b7f8ec4ea2aad85c5 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 15:22:15 -0400 Subject: [PATCH 063/150] Update voltcurrent.py --- python/voltcurrent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index cd40bf0c..aab35a13 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -39,8 +39,8 @@ if __name__ == "__main__": if config: print("Configuring") # optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage - ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_1S # 32S - ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_1S # 32S + ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S + ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S # optional : change voltage range to 16V ina219.bus_voltage_range = BusVoltageRange.RANGE_16V From 0729d647b6d0ffeb46151af31e348b59bc199eee Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:09:55 -0400 Subject: [PATCH 064/150] Rename telem.c to telem.c.bk --- afsk/{telem.c => telem.c.bk} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename afsk/{telem.c => telem.c.bk} (100%) diff --git a/afsk/telem.c b/afsk/telem.c.bk similarity index 100% rename from afsk/telem.c rename to afsk/telem.c.bk From d4c79e405e47e3a22ecc614d84b3f1505754683e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:10:10 -0400 Subject: [PATCH 065/150] Rename telem.c.bk to telem.c --- afsk/{telem.c.bk => telem.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename afsk/{telem.c.bk => telem.c} (100%) diff --git a/afsk/telem.c.bk b/afsk/telem.c similarity index 100% rename from afsk/telem.c.bk rename to afsk/telem.c From ad5800a48d79cd8d30d844827320227fd085acf4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:21:50 -0400 Subject: [PATCH 066/150] switching to voltcurrent.py --- afsk/telem.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index 2255de10..bb561091 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -328,9 +328,47 @@ int main(int argc, char *argv[]) { } // Reading I2C voltage and current sensors + + FILE* file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3 c", "r"); + pclose(file); + + char cmdbuffer[1000]; + fgets(cmdbuffer, 1000, file); + pclose(file); + data.voltage = atof(cmdbuffer); + int count; - for (count = 0; count < 8; count++) +// for (count = 0; count < 8; count++) + { + + file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3 c", "r"); + char cmdbuffer[1000]; + fgets(cmdbuffer, 1000, file); + printf("result: %s\n", cmdbuffer); + pclose(file); + + char *token; + const char space[2] = " "; + token = strtok(cmdbuffer, space); + printf(token: %s\n", token); + token = strtok(NULL, space); + printf(token: %s\n", token); + token = strtok(NULL, space); + printf(token: %s\n", token); + + + + // data.voltage = atof(cmdbuffer); + + + + + } + + return; + { + reading[count] = read_sensor_data(sensor[count]); // printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", // count, reading[count].voltage, reading[count].current, reading[count].power); From 32dcfc5548ee88b52e1aff981fb0ddc80aedde68 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:33:17 -0400 Subject: [PATCH 067/150] Update telem.c --- afsk/telem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index bb561091..3a66c0ba 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -350,11 +350,11 @@ int main(int argc, char *argv[]) { char *token; const char space[2] = " "; token = strtok(cmdbuffer, space); - printf(token: %s\n", token); + printf("token: %s\n", token); token = strtok(NULL, space); - printf(token: %s\n", token); + printf("token: %s\n", token); token = strtok(NULL, space); - printf(token: %s\n", token); + printf("token: %s\n", token); From 4a54977194127c0bb302c0c793570475cb8e1361 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:35:33 -0400 Subject: [PATCH 068/150] Update telem.c --- afsk/telem.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 3a66c0ba..c7e8335a 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -334,15 +334,16 @@ int main(int argc, char *argv[]) { char cmdbuffer[1000]; fgets(cmdbuffer, 1000, file); + printf("result: %s\n", cmdbuffer); pclose(file); - data.voltage = atof(cmdbuffer); +// data.voltage = atof(cmdbuffer); int count; // for (count = 0; count < 8; count++) { file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3 c", "r"); - char cmdbuffer[1000]; +// char cmdbuffer[1000]; fgets(cmdbuffer, 1000, file); printf("result: %s\n", cmdbuffer); pclose(file); From c8ed3787aa482b52e2e75f45d667bf033c052567 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:36:43 -0400 Subject: [PATCH 069/150] Update voltcurrent.py --- python/voltcurrent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index aab35a13..28b454f3 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -37,7 +37,7 @@ if __name__ == "__main__": # print("ina219 test") if config: - print("Configuring") +# print("Configuring") # optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S From a98f71abcf0718e5e8d109dcdeb62741308aeb8f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:41:42 -0400 Subject: [PATCH 070/150] Update telem.c --- afsk/telem.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index c7e8335a..70268423 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -331,16 +331,8 @@ int main(int argc, char *argv[]) { FILE* file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3 c", "r"); pclose(file); - - char cmdbuffer[1000]; - fgets(cmdbuffer, 1000, file); - printf("result: %s\n", cmdbuffer); - pclose(file); -// data.voltage = atof(cmdbuffer); int count; -// for (count = 0; count < 8; count++) - { file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3 c", "r"); // char cmdbuffer[1000]; @@ -350,12 +342,14 @@ int main(int argc, char *argv[]) { char *token; const char space[2] = " "; + + for (count = 0; count < 8; count++) + { token = strtok(cmdbuffer, space); - printf("token: %s\n", token); + printf("voltage: %s ", token); token = strtok(NULL, space); - printf("token: %s\n", token); - token = strtok(NULL, space); - printf("token: %s\n", token); + printf("current: %s\n", token); + } From 45105e2304c563d18c73711270ec0d1f39de6b82 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:43:19 -0400 Subject: [PATCH 071/150] Update telem.c --- afsk/telem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index 70268423..a9588925 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -335,7 +335,7 @@ int main(int argc, char *argv[]) { int count; file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3 c", "r"); -// char cmdbuffer[1000]; + char cmdbuffer[1000]; fgets(cmdbuffer, 1000, file); printf("result: %s\n", cmdbuffer); pclose(file); From e0087bacd955d8e4465915e18cc072a06a8db561 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:44:39 -0400 Subject: [PATCH 072/150] Update telem.c --- afsk/telem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index a9588925..f49c37da 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -358,7 +358,7 @@ int main(int argc, char *argv[]) { - } +// } return; From 4705dd55e6807a48cc703722f48aa2ea09f9ccf7 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:46:41 -0400 Subject: [PATCH 073/150] Update telem.c --- afsk/telem.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index f49c37da..1e98be88 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -342,13 +342,14 @@ int main(int argc, char *argv[]) { char *token; const char space[2] = " "; - + token = strtok(cmdbuffer, space); for (count = 0; count < 8; count++) { - token = strtok(cmdbuffer, space); + printf("voltage: %s ", token); token = strtok(NULL, space); printf("current: %s\n", token); + token = strtok(NULL, space); } From 7248b254a9ba01f3ada3f91bfd6b85aa351aad00 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:50:35 -0400 Subject: [PATCH 074/150] Update telem.c --- afsk/telem.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 1e98be88..965599cf 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -332,25 +332,17 @@ int main(int argc, char *argv[]) { FILE* file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3 c", "r"); pclose(file); - int count; - - file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3 c", "r"); - char cmdbuffer[1000]; - fgets(cmdbuffer, 1000, file); - printf("result: %s\n", cmdbuffer); - pclose(file); - - char *token; + int count; + char *token; const char space[2] = " "; token = strtok(cmdbuffer, space); - for (count = 0; count < 8; count++) - { - - printf("voltage: %s ", token); - token = strtok(NULL, space); - printf("current: %s\n", token); - token = strtok(NULL, space); - } + for (count = 0; count < 8; count++) + { + printf("voltage: %s ", token); + token = strtok(NULL, space); + printf("current: %s\n", token); + token = strtok(NULL, space); + } From 38e8f60ec57e487989a1a216dba48f09257aab4c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:51:27 -0400 Subject: [PATCH 075/150] Update telem.c --- afsk/telem.c | 1 + 1 file changed, 1 insertion(+) diff --git a/afsk/telem.c b/afsk/telem.c index 965599cf..c2c934b8 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -334,6 +334,7 @@ int main(int argc, char *argv[]) { int count; char *token; + char cmdbuffer[100]; const char space[2] = " "; token = strtok(cmdbuffer, space); for (count = 0; count < 8; count++) From b579bc0b4ccfbe15a6a57d5027a468051afa474a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:54:04 -0400 Subject: [PATCH 076/150] Update telem.c --- afsk/telem.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/afsk/telem.c b/afsk/telem.c index c2c934b8..96e0040c 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -328,6 +328,7 @@ int main(int argc, char *argv[]) { } // Reading I2C voltage and current sensors + printf("Starting\n"); FILE* file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3 c", "r"); pclose(file); @@ -335,6 +336,14 @@ int main(int argc, char *argv[]) { int count; char *token; char cmdbuffer[100]; + + file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3", "r"); +// char cmdbuffer[1000]; +// char cmdbuffer[1000]; + fgets(cmdbuffer, 1000, file); + printf("result: %s\n", cmdbuffer); + pclose(file); + const char space[2] = " "; token = strtok(cmdbuffer, space); for (count = 0; count < 8; count++) From dc7e47ad24ddb105b3749fc0a24d7312c3aa914a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:56:09 -0400 Subject: [PATCH 077/150] Update telem.c --- afsk/telem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index 96e0040c..fdf46469 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -331,11 +331,13 @@ int main(int argc, char *argv[]) { printf("Starting\n"); FILE* file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3 c", "r"); + char cmdbuffer[1000]; + fgets(cmdbuffer, 1000, file); pclose(file); int count; char *token; - char cmdbuffer[100]; +// char cmdbuffer[1000]; file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3", "r"); // char cmdbuffer[1000]; From a665677357da3af46d2151d68ab17839afe9f559 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:57:53 -0400 Subject: [PATCH 078/150] Update telem.c --- afsk/telem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index fdf46469..5500cedd 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -339,6 +339,7 @@ int main(int argc, char *argv[]) { char *token; // char cmdbuffer[1000]; + while (true) { file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3", "r"); // char cmdbuffer[1000]; // char cmdbuffer[1000]; @@ -356,7 +357,8 @@ int main(int argc, char *argv[]) { token = strtok(NULL, space); } - + printf("\n"); + } // data.voltage = atof(cmdbuffer); From bf860bb976b97b2967fe06f5f4ef7f41bdb27e89 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 16:58:29 -0400 Subject: [PATCH 079/150] Update telem.c --- afsk/telem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index 5500cedd..c580865d 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -339,7 +339,7 @@ int main(int argc, char *argv[]) { char *token; // char cmdbuffer[1000]; - while (true) { + while (1) { file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3", "r"); // char cmdbuffer[1000]; // char cmdbuffer[1000]; From 95e33b8cc9b16c3850e5068a605930694e2d2e28 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 17:07:34 -0400 Subject: [PATCH 080/150] Update telem.c --- afsk/telem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index c580865d..77dd3681 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -344,7 +344,7 @@ int main(int argc, char *argv[]) { // char cmdbuffer[1000]; // char cmdbuffer[1000]; fgets(cmdbuffer, 1000, file); - printf("result: %s\n", cmdbuffer); +// printf("result: %s\n", cmdbuffer); pclose(file); const char space[2] = " "; From e84367a3312d0ab28709d02d97af1da6f1f9f227 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 18 Aug 2020 17:09:18 -0400 Subject: [PATCH 081/150] Update voltcurrent.py --- python/voltcurrent.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 28b454f3..68961867 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -27,12 +27,13 @@ if __name__ == "__main__": addresses = [0x40, 0x41, 0x44, 0x45] #INA219 addresses on the bus # print("buses: ", buses, " addr: ", addresses) for x in buses: + i2c_bus = I2C(x) # Device is /dev/i2c-x for y in addresses: # print(x,y) try: # Create library object using Extended Bus I2C port # print("bus: ", x, " addr: ", y) - i2c_bus = I2C(x) # 1 Device is /dev/i2c-1 + ina219 = INA219(i2c_bus, y) # print("ina219 test") From 853b2bcec98c2640fb7094fc402dc03b374a2ed0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 19 Aug 2020 16:00:14 -0400 Subject: [PATCH 082/150] start converting to voltcurrent.py --- afsk/main.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/afsk/main.c b/afsk/main.c index d5a17302..e74d19b7 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -481,6 +481,11 @@ else tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); } + FILE* file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11 c", "r"); + char cmdbuffer[1000]; + fgets(cmdbuffer, 1000, file); + pclose(file); + // try connecting to Arduino payload using UART if (!ax5043) // don't test if AX5043 is present @@ -1045,7 +1050,31 @@ if (firstTime != ON) sampleTime = millis(); } else printf("first time - no sleep\n"); + +int count; + char *token; +// char cmdbuffer[1000]; + while (1) { + file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); + fgets(cmdbuffer, 1000, file); +// printf("result: %s\n", cmdbuffer); + pclose(file); + + const char space[2] = " "; + token = strtok(cmdbuffer, space); + for (count = 0; count < 8; count++) + { + printf("voltage: %s ", token); + token = strtok(NULL, space); + printf("current: %s\n", token); + token = strtok(NULL, space); + } + + printf("\n"); + } + + int count; for (count = 0; count < 8; count++) { From e655b220094f224f036b76d34af72a28b197c4fe Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 19 Aug 2020 16:01:45 -0400 Subject: [PATCH 083/150] Update main.c --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index e74d19b7..ec991f1e 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1053,10 +1053,10 @@ if (firstTime != ON) int count; char *token; -// char cmdbuffer[1000]; + char cmdbuffer[1000]; while (1) { - file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); + FILE *file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); fgets(cmdbuffer, 1000, file); // printf("result: %s\n", cmdbuffer); pclose(file); From d833b6bbb68afea5847f7dd0ebe43ca51e5868a9 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 19 Aug 2020 16:03:26 -0400 Subject: [PATCH 084/150] Update main.c --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index ec991f1e..a57b8693 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1051,7 +1051,7 @@ if (firstTime != ON) } else printf("first time - no sleep\n"); -int count; + int count1; char *token; char cmdbuffer[1000]; @@ -1063,7 +1063,7 @@ int count; const char space[2] = " "; token = strtok(cmdbuffer, space); - for (count = 0; count < 8; count++) + for (count1 = 0; count1 < 8; count1++) { printf("voltage: %s ", token); token = strtok(NULL, space); From 1bcf93e5ee013c1d34bc828053c61e0b7b512dd0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 19 Aug 2020 16:05:13 -0400 Subject: [PATCH 085/150] Update main.c --- afsk/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index a57b8693..4cecfab8 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -481,10 +481,10 @@ else tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); } - FILE* file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11 c", "r"); + FILE* file1 = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11 c", "r"); char cmdbuffer[1000]; - fgets(cmdbuffer, 1000, file); - pclose(file); + fgets(cmdbuffer, 1000, file1); + pclose(file1); // try connecting to Arduino payload using UART From 2c5594ca1e07cc820ec200042a12cf673f1c622b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 19 Aug 2020 16:07:09 -0400 Subject: [PATCH 086/150] Update main.c --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 4cecfab8..e3bc42da 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1055,7 +1055,7 @@ if (firstTime != ON) char *token; char cmdbuffer[1000]; - while (1) { +// while (1) { FILE *file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); fgets(cmdbuffer, 1000, file); // printf("result: %s\n", cmdbuffer); @@ -1072,7 +1072,7 @@ if (firstTime != ON) } printf("\n"); - } +// } int count; From 06f94b0cc7dbe403a01499e9799df48a562aac7e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 19 Aug 2020 16:20:52 -0400 Subject: [PATCH 087/150] Update main.c --- afsk/main.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index e3bc42da..1f767bd7 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1063,22 +1063,27 @@ if (firstTime != ON) const char space[2] = " "; token = strtok(cmdbuffer, space); + + float voltage[9], current[9]; + for (count1 = 0; count1 < 8; count1++) { - printf("voltage: %s ", token); + voltage[count1] = atof(token); + printf("voltage: %f ", voltage[count1]); token = strtok(NULL, space); - printf("current: %s\n", token); + current[count1] = atof(token); + printf("current: %f\n", current[count1]); token = strtok(NULL, space); } printf("\n"); // } - + int count; for (count = 0; count < 8; count++) { - reading[count] = read_sensor_data(sensor[count]); + reading[count] = read_sensor_data(sensor[count]); #ifdef DEBUG_LOGGING // printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", // count, reading[count].voltage, reading[count].current, reading[count].power); From d4ad54652076d1d3389934e7585c12286eeef97d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 19 Aug 2020 16:27:01 -0400 Subject: [PATCH 088/150] switched to voltage[] and current[] --- afsk/main.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 1f767bd7..ff229048 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1144,7 +1144,8 @@ if (firstTime != ON) if (mode == BPSK) h[6] = 99; - + +/* // posXv = reading[PLUS_X].current; posXi = (int)reading[PLUS_X].current + 2048; posYi = (int)reading[PLUS_Y].current + 2048; @@ -1164,7 +1165,26 @@ if (firstTime != ON) battCurr = (int)reading[BAT].current + 2048; PSUVoltage = (int)(reading[BUS].voltage * 100); PSUCurrent = (int)reading[BUS].current + 2048; +*/ + + posXi = (int)current[PLUS_X] + 2048; + posYi = (int)cuurent[PLUS_Y] + 2048; + posZi = (int)current[PLUS_Z] + 2048; + negXi = (int)current[MINUS_X] + 2048; + negYi = (int)current[MINUS_Y] + 2048; + negZi = (int)current[MINUS_Z] + 2048; + + posXv = (int)(voltage[PLUS_X] * 100); + posYv = (int)(voltage[PLUS_Y] * 100); + posZv = (int)(voltage[PLUS_Z] * 100); + negXv = (int)(voltage[MINUS_X] * 100); + negYv = (int)(voltage[MINUS_Y] * 100); + negZv = (int)(voltage[MINUS_Z] * 100); + batt_c_v = (int)(voltage[BAT] * 100); + battCurr = (int)current[BAT] + 2048; + PSUVoltage = (int)(voltage[BUS] * 100); + PSUCurrent = (int)current[BUS] + 2048; if (payload == ON) STEMBoardFailure = 0; From d1ab2889289cd918ff1de054f4aa70ce7c4fcef2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 19 Aug 2020 16:27:46 -0400 Subject: [PATCH 089/150] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index ff229048..60629503 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1168,7 +1168,7 @@ if (firstTime != ON) */ posXi = (int)current[PLUS_X] + 2048; - posYi = (int)cuurent[PLUS_Y] + 2048; + posYi = (int)current[PLUS_Y] + 2048; posZi = (int)current[PLUS_Z] + 2048; negXi = (int)current[MINUS_X] + 2048; negYi = (int)current[MINUS_Y] + 2048; From a319ec76022645ce0fb28b4f36ca60512afd3df7 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 19 Aug 2020 16:33:06 -0400 Subject: [PATCH 090/150] changed sensor numbers --- afsk/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 60629503..c681df1f 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -54,12 +54,12 @@ #define PLUS_X 0 #define PLUS_Y 1 -#define PLUS_Z 2 -#define BAT 3 +#define PLUS_Z 6 +#define BAT 2 #define MINUS_X 4 #define MINUS_Y 5 -#define MINUS_Z 6 -#define BUS 7 +#define MINUS_Z 7 +#define BUS 3 #define OFF -1 #define ON 1 From e8d3422f1ebffa068e01d5aa70e871a135f639cc Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 29 Aug 2020 09:10:19 -0400 Subject: [PATCH 091/150] starting string operations for python commands --- afsk/main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index c681df1f..6c6d1d50 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -127,6 +127,9 @@ int cw_id = ON; int vB4 = FALSE, vB5 = FALSE, ax5043 = FALSE, transmit = FALSE, onLed, onLedOn, onLedOff, txLed, txLedOn, txLedOff, payload = OFF; float batteryThreshold = 0; +char pythonCmd = "ython3 /home/pi/CubeSatSim/python/voltcurrent.py "; +char pythonStr[100]; + struct SensorConfig { int fd; uint16_t config; @@ -481,9 +484,14 @@ else tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); } - FILE* file1 = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11 c", "r"); + strcpy(pythonStr, pythonCmd); + strcat(pythonStr, "1 11 c") + +// FILE* file1 = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11 c", "r"); + FILE* file1 = popen(pythonStr, "r"); char cmdbuffer[1000]; fgets(cmdbuffer, 1000, file1); + printf("pythonStr result: %s\n", cmdbuffer); pclose(file1); // try connecting to Arduino payload using UART From 9439f12cf8f7c4a8856c3b9f4729463afaafc120 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 29 Aug 2020 09:12:23 -0400 Subject: [PATCH 092/150] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 6c6d1d50..8e32a650 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -485,7 +485,7 @@ else } strcpy(pythonStr, pythonCmd); - strcat(pythonStr, "1 11 c") + strcat(pythonStr, "1 11 c"); // FILE* file1 = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11 c", "r"); FILE* file1 = popen(pythonStr, "r"); From d63b9c30c28bffab5fe4a1ed7dbeb355e20b3f29 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 29 Aug 2020 09:14:34 -0400 Subject: [PATCH 093/150] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 8e32a650..f521e8ec 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -127,7 +127,7 @@ int cw_id = ON; int vB4 = FALSE, vB5 = FALSE, ax5043 = FALSE, transmit = FALSE, onLed, onLedOn, onLedOff, txLed, txLedOn, txLedOff, payload = OFF; float batteryThreshold = 0; -char pythonCmd = "ython3 /home/pi/CubeSatSim/python/voltcurrent.py "; +const char pythonCmd[] = "python3 /home/pi/CubeSatSim/python/voltcurrent.py "; char pythonStr[100]; struct SensorConfig { From 5aef3312c78d2edb57509a5dbba3b4cfa33ab529 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 29 Aug 2020 09:22:23 -0400 Subject: [PATCH 094/150] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index f521e8ec..4841a455 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -485,7 +485,7 @@ else } strcpy(pythonStr, pythonCmd); - strcat(pythonStr, "1 11 c"); + strcat(pythonStr, "1 3 c"); // FILE* file1 = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11 c", "r"); FILE* file1 = popen(pythonStr, "r"); From 0b381b401e565b52310a5a8060ed281762ebb282 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 29 Aug 2020 09:30:45 -0400 Subject: [PATCH 095/150] use bus string for python sensor read --- afsk/main.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 4841a455..a0bc0f8d 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -128,7 +128,7 @@ int vB4 = FALSE, vB5 = FALSE, ax5043 = FALSE, transmit = FALSE, onLed, onLedOn, float batteryThreshold = 0; const char pythonCmd[] = "python3 /home/pi/CubeSatSim/python/voltcurrent.py "; -char pythonStr[100]; +char pythonStr[100], pythonConfigStr[100], busStr[10]; struct SensorConfig { int fd; @@ -451,6 +451,7 @@ if (vB4) sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x41, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x44, 400); sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x45, 400); + strcpy(busStr,"1 0"); } else if (vB5) { @@ -464,11 +465,13 @@ else if (vB5) sensor[MINUS_X] = config_sensor("/dev/i2c-11", 0x41, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-11", 0x44, 400); sensor[MINUS_Z] = config_sensor("/dev/i2c-11", 0x45, 400); + strcpy(busStr,"1 11"); } else { sensor[PLUS_Z] = config_sensor("/dev/i2c-3", 0x40, 400); sensor[MINUS_X] = config_sensor("/dev/i2c-3", 0x41, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-3", 0x44, 400); sensor[MINUS_Z] = config_sensor("/dev/i2c-3", 0x45, 400); + strcpy(busStr,"1 3"); } } else @@ -481,17 +484,20 @@ else sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); - tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); + tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); + strcpy(busStr,"1 0"); } strcpy(pythonStr, pythonCmd); - strcat(pythonStr, "1 3 c"); + strcat(pythonStr, busStr); + strcat(pythonConfigStr, pythonStr); + strcat(pythonConfigStr, " c"); // FILE* file1 = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11 c", "r"); - FILE* file1 = popen(pythonStr, "r"); + FILE* file1 = popen(pythonConfigStr, "r"); char cmdbuffer[1000]; fgets(cmdbuffer, 1000, file1); - printf("pythonStr result: %s\n", cmdbuffer); +// printf("pythonStr result: %s\n", cmdbuffer); pclose(file1); // try connecting to Arduino payload using UART @@ -1063,9 +1069,9 @@ if (firstTime != ON) char *token; char cmdbuffer[1000]; -// while (1) { - FILE *file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); - fgets(cmdbuffer, 1000, file); +// FILE *file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); + FILE* file = popen(pythonStr, "r"); + fgets(cmdbuffer, 1000, file); // printf("result: %s\n", cmdbuffer); pclose(file); @@ -1084,10 +1090,8 @@ if (firstTime != ON) token = strtok(NULL, space); } - printf("\n"); -// } + printf("\n"); - int count; for (count = 0; count < 8; count++) { From 72e12763b0669b9ced5474e442132ae25188366f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 29 Aug 2020 11:02:40 -0400 Subject: [PATCH 096/150] added null checking around token parsing --- afsk/main.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index a0bc0f8d..9d7ac303 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1079,15 +1079,24 @@ if (firstTime != ON) token = strtok(cmdbuffer, space); float voltage[9], current[9]; - + memset(voltage, 0, 9*sizeof(voltage[0])); + memset(current, 0, 9*sizeof(current[0])); + for (count1 = 0; count1 < 8; count1++) { + if (token != NULL) + { voltage[count1] = atof(token); - printf("voltage: %f ", voltage[count1]); - token = strtok(NULL, space); - current[count1] = atof(token); - printf("current: %f\n", current[count1]); - token = strtok(NULL, space); + printf("voltage: %f ", voltage[count1]); + + token = strtok(NULL, space); + if (token != NULL) + { + current[count1] = atof(token); + printf("current: %f\n", current[count1]); + token = strtok(NULL, space); + } + } } printf("\n"); From 20d6b946c83486bce59deb997dda717eb9e12751 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 29 Aug 2020 19:17:33 -0400 Subject: [PATCH 097/150] added mapping of sensor numbers for different boards --- afsk/main.c | 119 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 83 insertions(+), 36 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 9d7ac303..77d2849f 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -54,12 +54,13 @@ #define PLUS_X 0 #define PLUS_Y 1 -#define PLUS_Z 6 #define BAT 2 +#define BUS 3 #define MINUS_X 4 #define MINUS_Y 5 +#define PLUS_Z 6 #define MINUS_Z 7 -#define BUS 3 + #define OFF -1 #define ON 1 @@ -129,7 +130,7 @@ float batteryThreshold = 0; const char pythonCmd[] = "python3 /home/pi/CubeSatSim/python/voltcurrent.py "; char pythonStr[100], pythonConfigStr[100], busStr[10]; - +int map[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 0x45}; struct SensorConfig { int fd; uint16_t config; @@ -451,14 +452,17 @@ if (vB4) sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x41, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x44, 400); sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x45, 400); + map[2] = BUS; + map[3] = BAT; strcpy(busStr,"1 0"); } else if (vB5) { sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x45, 400); sensor[BAT] = config_sensor("/dev/i2c-1", 0x44, 400); + sensor[BUS] = config_sensor("/dev/i2c-1", 0x45, 400); + if (access("/dev/i2c-11", W_OK | R_OK) >= 0) { // Test if I2C Bus 11 is present printf("/dev/i2c-11 is present\n\n"); sensor[PLUS_Z] = config_sensor("/dev/i2c-11", 0x40, 400); @@ -484,7 +488,13 @@ else sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); + tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); + map[2] = PLUS_Z; + map[3] = BAT; + map[4] = MINUS_X; + map[5] = BUS; + map[8] = 0x4a; // 2000 mA on bus 1 strcpy(busStr,"1 0"); } @@ -595,7 +605,8 @@ printf("After command\n"); while (loop-- != 0) { frames_sent++; - float batteryVoltage = read_sensor_data(sensor[BAT]).voltage; +// float batteryVoltage = read_sensor_data(sensor[BAT]).voltage; + float batteryVoltage = voltage(map[BAT]); #ifdef DEBUG_LOGGING fprintf(stderr,"INFO: Battery voltage: %f V Battery Threshold %f V\n", batteryVoltage, batteryThreshold); #endif @@ -770,6 +781,41 @@ for (int j = 0; j < frameCnt; j++) memset(tlm, 0, sizeof tlm); // Reading I2C voltage and current sensors + + int count1; + char *token; + char cmdbuffer[1000]; + +// FILE *file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); + FILE* file = popen(pythonStr, "r"); + fgets(cmdbuffer, 1000, file); +// printf("result: %s\n", cmdbuffer); + pclose(file); + + const char space[2] = " "; + token = strtok(cmdbuffer, space); + + float voltage[9], current[9]; + memset(voltage, 0, sizeof(voltage)); + memset(current, 0, sizeof(current)); + + for (count1 = 0; count1 < 8; count1++) + { + if (token != NULL) + { + voltage[count1] = atof(token); + printf("voltage: %f ", voltage[count1]); + + token = strtok(NULL, space); + if (token != NULL) + { + current[count1] = atof(token); + printf("current: %f\n", current[count1]); + token = strtok(NULL, space); + } + } + } + int count; for (count = 0; count < 8; count++) { @@ -780,18 +826,18 @@ for (int j = 0; j < frameCnt; j++) #endif } - tlm[1][A] = (int)(reading[BUS].voltage /15.0 + 0.5) % 100; // Current of 5V supply to Pi - tlm[1][B] = (int) (99.5 - reading[PLUS_X].current/10.0) % 100; // +X current [4] - tlm[1][C] = (int) (99.5 - reading[MINUS_X].current/10.0) % 100; // X- current [10] - tlm[1][D] = (int) (99.5 - reading[PLUS_Y].current/10.0) % 100; // +Y current [7] - - tlm[2][A] = (int) (99.5 - reading[MINUS_Y].current/10.0) % 100; // -Y current [10] - tlm[2][B] = (int) (99.5 - reading[PLUS_Z].current/10.0) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel - tlm[2][C] = (int) (99.5 - reading[MINUS_Z].current/10.0) % 100; // -Z current (was timestamp) - tlm[2][D] = (int)(50.5 + reading[BAT].current/10.0) % 100; // NiMH Battery current + tlm[1][A] = (int)(voltage[map[BUS]] /15.0 + 0.5) % 100; // Current of 5V supply to Pi + tlm[1][B] = (int) (99.5 - current[map[PLUS_X]]/10.0) % 100; // +X current [4] + tlm[1][C] = (int) (99.5 - current[map[MINUS_X]]/10.0) % 100; // X- current [10] + tlm[1][D] = (int) (99.5 - current[map[PLUS_Y]]/10.0) % 100; // +Y current [7] + + tlm[2][A] = (int) (99.5 - current[map[MINUS_Y]]/10.0) % 100; // -Y current [10] + tlm[2][B] = (int) (99.5 - current[map[PLUS_Z]]/10.0) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel + tlm[2][C] = (int) (99.5 - current[map[MINUS_Z]]/10.0) % 100; // -Z current (was timestamp) + tlm[2][D] = (int)(50.5 + current[map[BAT]]/10.0) % 100; // NiMH Battery current - tlm[3][A] = abs((int)((reading[BAT].voltage * 10.0) - 65.5) % 100); - tlm[3][B] = (int)(reading[BUS].voltage * 10.0) % 100; // 5V supply to Pi + tlm[3][A] = abs((int)((voltage[map[BAT]] * 10.0) - 65.5) % 100); + tlm[3][B] = (int)(voltage[map[BUS]] * 10.0) % 100; // 5V supply to Pi if (ax5043) { @@ -1079,8 +1125,8 @@ if (firstTime != ON) token = strtok(cmdbuffer, space); float voltage[9], current[9]; - memset(voltage, 0, 9*sizeof(voltage[0])); - memset(current, 0, 9*sizeof(current[0])); + memset(voltage, 0, sizeof(voltage)); + memset(current, 0, sizeof(current)); for (count1 = 0; count1 < 8; count1++) { @@ -1099,12 +1145,13 @@ if (firstTime != ON) } } - printf("\n"); +// printf("\n"); int count; for (count = 0; count < 8; count++) { reading[count] = read_sensor_data(sensor[count]); + reading[count] = read_sensor_data(sensor[count]); #ifdef DEBUG_LOGGING // printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", // count, reading[count].voltage, reading[count].current, reading[count].power); @@ -1188,24 +1235,24 @@ if (firstTime != ON) PSUCurrent = (int)reading[BUS].current + 2048; */ - posXi = (int)current[PLUS_X] + 2048; - posYi = (int)current[PLUS_Y] + 2048; - posZi = (int)current[PLUS_Z] + 2048; - negXi = (int)current[MINUS_X] + 2048; - negYi = (int)current[MINUS_Y] + 2048; - negZi = (int)current[MINUS_Z] + 2048; - - posXv = (int)(voltage[PLUS_X] * 100); - posYv = (int)(voltage[PLUS_Y] * 100); - posZv = (int)(voltage[PLUS_Z] * 100); - negXv = (int)(voltage[MINUS_X] * 100); - negYv = (int)(voltage[MINUS_Y] * 100); - negZv = (int)(voltage[MINUS_Z] * 100); + posXi = (int)current[map[PLUS_X]] + 2048; + posYi = (int)current[map[PLUS_Y]] + 2048; + posZi = (int)current[map[PLUS_Z]] + 2048; + negXi = (int)current[map[MINUS_X]] + 2048; + negYi = (int)current[map[MINUS_Y]] + 2048; + negZi = (int)current[map[MINUS_Z]] + 2048; + + posXv = (int)(voltage[map[PLUS_X]] * 100); + posYv = (int)(voltage[map[PLUS_Y]] * 100); + posZv = (int)(voltage[map[PLUS_Z]] * 100); + negXv = (int)(voltage[map[MINUS_X]] * 100); + negYv = (int)(voltage[map[MINUS_Y]] * 100); + negZv = (int)(voltage[map[MINUS_Z]] * 100); - batt_c_v = (int)(voltage[BAT] * 100); - battCurr = (int)current[BAT] + 2048; - PSUVoltage = (int)(voltage[BUS] * 100); - PSUCurrent = (int)current[BUS] + 2048; + batt_c_v = (int)(voltage[map[BAT]] * 100); + battCurr = (int)current[map[BAT]] + 2048; + PSUVoltage = (int)(voltage[map[BUS]] * 100); + PSUCurrent = (int)current[map[BUS]] + 2048; if (payload == ON) STEMBoardFailure = 0; From ee77e6c494d570f227fa1622400768de7631530c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 29 Aug 2020 19:21:07 -0400 Subject: [PATCH 098/150] moved batteryVoltage --- afsk/main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 77d2849f..eae51bc6 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -126,7 +126,7 @@ float sleepTime; int sampleTime = 0, frames_sent = 0; int cw_id = ON; int vB4 = FALSE, vB5 = FALSE, ax5043 = FALSE, transmit = FALSE, onLed, onLedOn, onLedOff, txLed, txLedOn, txLedOff, payload = OFF; -float batteryThreshold = 0; +float batteryThreshold = 0, batteryVoltage; const char pythonCmd[] = "python3 /home/pi/CubeSatSim/python/voltcurrent.py "; char pythonStr[100], pythonConfigStr[100], busStr[10]; @@ -606,7 +606,7 @@ while (loop-- != 0) { frames_sent++; // float batteryVoltage = read_sensor_data(sensor[BAT]).voltage; - float batteryVoltage = voltage(map[BAT]); + #ifdef DEBUG_LOGGING fprintf(stderr,"INFO: Battery voltage: %f V Battery Threshold %f V\n", batteryVoltage, batteryThreshold); #endif @@ -839,6 +839,8 @@ for (int j = 0; j < frameCnt; j++) tlm[3][A] = abs((int)((voltage[map[BAT]] * 10.0) - 65.5) % 100); tlm[3][B] = (int)(voltage[map[BUS]] * 10.0) % 100; // 5V supply to Pi + batteryVoltage = voltage[map[BAT]]; + if (ax5043) { if (tempSensor.fd != OFF) { @@ -1255,7 +1257,9 @@ if (firstTime != ON) PSUCurrent = (int)current[map[BUS]] + 2048; if (payload == ON) STEMBoardFailure = 0; - + + batteryVoltage = voltage[map[BAT]]; + encodeA(b, 0 + head_offset, batt_a_v); encodeB(b, 1 + head_offset, batt_b_v); encodeA(b, 3 + head_offset, batt_c_v); From d6768d1c09df7df9bf4b1e9582769b987927d5a5 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 29 Aug 2020 19:49:28 -0400 Subject: [PATCH 099/150] added batteryThreshold for original board --- afsk/main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index eae51bc6..038eb2ae 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -126,7 +126,7 @@ float sleepTime; int sampleTime = 0, frames_sent = 0; int cw_id = ON; int vB4 = FALSE, vB5 = FALSE, ax5043 = FALSE, transmit = FALSE, onLed, onLedOn, onLedOff, txLed, txLedOn, txLedOff, payload = OFF; -float batteryThreshold = 0, batteryVoltage; +float batteryThreshold = 3.0, batteryVoltage; const char pythonCmd[] = "python3 /home/pi/CubeSatSim/python/voltcurrent.py "; char pythonStr[100], pythonConfigStr[100], busStr[10]; @@ -399,7 +399,6 @@ int main(int argc, char *argv[]) { onLed = 0; onLedOn = HIGH; onLedOff = LOW; - batteryThreshold = 3.0; transmit = TRUE; } else @@ -417,7 +416,6 @@ int main(int argc, char *argv[]) { onLed = 27; onLedOn = HIGH; onLedOff = LOW; - batteryThreshold = 3.0; transmit = TRUE; } } @@ -496,6 +494,7 @@ else map[5] = BUS; map[8] = 0x4a; // 2000 mA on bus 1 strcpy(busStr,"1 0"); + batteryThreshold = 8.0; } strcpy(pythonStr, pythonCmd); From cda631ea6446d07198b2a35b496f98227e34f8ce Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 29 Aug 2020 19:56:14 -0400 Subject: [PATCH 100/150] removed sensor structs and functions --- afsk/main.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 038eb2ae..aab817c2 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -131,6 +131,7 @@ float batteryThreshold = 3.0, batteryVoltage; const char pythonCmd[] = "python3 /home/pi/CubeSatSim/python/voltcurrent.py "; char pythonStr[100], pythonConfigStr[100], busStr[10]; int map[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 0x45}; +/* struct SensorConfig { int fd; uint16_t config; @@ -156,7 +157,7 @@ struct SensorData { * @param sensor A structure containing sensor configuration including the file descriptor. * @return struct SensorData A struct that contains the current, voltage, and power readings * from the requested sensor. - */ + * struct SensorData read_sensor_data(struct SensorConfig sensor) { struct SensorData data = { .current = 0, @@ -199,7 +200,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { * @param sensor A file descriptor that can be used to read from the sensor. * @param milliAmps The mA configuration, either 400mA or 2A are supported. * @return struct SensorConfig A struct that contains the configuraton of the sensor. - */ + * //struct SensorConfig config_sensor(int sensor, int milliAmps) { struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { struct SensorConfig data; @@ -261,6 +262,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { struct SensorConfig sensor[8]; // 8 current sensors in Solar Power PCB vB4/5 struct SensorData reading[8]; // 8 current sensors in Solar Power PCB vB4/5 struct SensorConfig tempSensor; +*/ char src_addr[5] = ""; char dest_addr[5] = "CQ"; @@ -442,43 +444,43 @@ int main(int argc, char *argv[]) { if (vB4) { - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); +/* sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); sensor[BUS] = config_sensor("/dev/i2c-1", 0x44, 400); sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); sensor[PLUS_Z] = config_sensor("/dev/i2c-0", 0x40, 400); sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x41, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x44, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x45, 400); + sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x45, 400); */ map[2] = BUS; map[3] = BAT; strcpy(busStr,"1 0"); } else if (vB5) { - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); +/* sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); sensor[BAT] = config_sensor("/dev/i2c-1", 0x44, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x45, 400); + sensor[BUS] = config_sensor("/dev/i2c-1", 0x45, 400); */ if (access("/dev/i2c-11", W_OK | R_OK) >= 0) { // Test if I2C Bus 11 is present printf("/dev/i2c-11 is present\n\n"); - sensor[PLUS_Z] = config_sensor("/dev/i2c-11", 0x40, 400); + /* sensor[PLUS_Z] = config_sensor("/dev/i2c-11", 0x40, 400); sensor[MINUS_X] = config_sensor("/dev/i2c-11", 0x41, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-11", 0x44, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-11", 0x45, 400); + sensor[MINUS_Z] = config_sensor("/dev/i2c-11", 0x45, 400); */ strcpy(busStr,"1 11"); } else { - sensor[PLUS_Z] = config_sensor("/dev/i2c-3", 0x40, 400); + /* sensor[PLUS_Z] = config_sensor("/dev/i2c-3", 0x40, 400); sensor[MINUS_X] = config_sensor("/dev/i2c-3", 0x41, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-3", 0x44, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-3", 0x45, 400); + sensor[MINUS_Z] = config_sensor("/dev/i2c-3", 0x45, 400); */ strcpy(busStr,"1 3"); } } else { - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); +/* sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); @@ -487,7 +489,7 @@ else sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); - tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); + tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); */ map[2] = PLUS_Z; map[3] = BAT; map[4] = MINUS_X; @@ -814,7 +816,7 @@ for (int j = 0; j < frameCnt; j++) } } } - +/* int count; for (count = 0; count < 8; count++) { @@ -824,7 +826,7 @@ for (int j = 0; j < frameCnt; j++) // count, reading[count].voltage, reading[count].current, reading[count].power); #endif } - +*/ tlm[1][A] = (int)(voltage[map[BUS]] /15.0 + 0.5) % 100; // Current of 5V supply to Pi tlm[1][B] = (int) (99.5 - current[map[PLUS_X]]/10.0) % 100; // +X current [4] tlm[1][C] = (int) (99.5 - current[map[MINUS_X]]/10.0) % 100; // X- current [10] @@ -840,6 +842,7 @@ for (int j = 0; j < frameCnt; j++) batteryVoltage = voltage[map[BAT]]; +/* if (ax5043) { if (tempSensor.fd != OFF) { @@ -854,7 +857,8 @@ for (int j = 0; j < frameCnt; j++) tlm[4][A] = (int)((95.8 - temp)/1.48 + 0.5) % 100; } - } + } +*/ FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); if (cpuTempSensor) { double cpuTemp; @@ -1147,7 +1151,7 @@ if (firstTime != ON) } // printf("\n"); - +/* int count; for (count = 0; count < 8; count++) { @@ -1158,6 +1162,7 @@ if (firstTime != ON) // count, reading[count].voltage, reading[count].current, reading[count].power); #endif } +*/ /* if (tempSensor.fd != OFF) { int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); From aa43cd5540cc8138015c3d75ab3eeea472f4cd81 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 29 Aug 2020 20:03:42 -0400 Subject: [PATCH 101/150] Update main.c --- afsk/main.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index aab817c2..dbb1b195 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -805,14 +805,17 @@ for (int j = 0; j < frameCnt; j++) if (token != NULL) { voltage[count1] = atof(token); - printf("voltage: %f ", voltage[count1]); - + #ifdef DEBUG_LOGGING + printf("voltage: %f ", voltage[count1]); + #endif token = strtok(NULL, space); if (token != NULL) { current[count1] = atof(token); - printf("current: %f\n", current[count1]); - token = strtok(NULL, space); + #ifdef DEBUG_LOGGING + printf("current: %f\n", current[count1]); + #endif + token = strtok(NULL, space); } } } @@ -1138,14 +1141,17 @@ if (firstTime != ON) if (token != NULL) { voltage[count1] = atof(token); - printf("voltage: %f ", voltage[count1]); - + #ifdef DEBUG_LOGGING + printf("voltage: %f ", voltage[count1]); + #endif token = strtok(NULL, space); if (token != NULL) { current[count1] = atof(token); - printf("current: %f\n", current[count1]); - token = strtok(NULL, space); + #ifdef DEBUG_LOGGING + printf("current: %f\n", current[count1]); + #endif + token = strtok(NULL, space); } } } From db52c0328e8c85a14e8cb22ea029fadadeff7b90 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 1 Sep 2020 14:10:45 -0400 Subject: [PATCH 102/150] added python package installs --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index e06955ce..92817c6f 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,14 @@ Remove the following text in cmdline.txt to prevent a console from running on th Press Ctrl-X then type `y` then hit Enter to save the file and exit the editor. You should back at the pi@... prompt. +Now install the python packages: + +`sudo apt install -y python3-pip python-smbus` + +`sudo pip3 install --upgrade setuptools` + +`sudo pip3 install adafruit-blinka RPI.GPIO adafruit-extended-bus adafruit-circuitpython-ina219` + Reboot by typing: `sudo reboot now` From ad251a3a4ef489cd1100780c5ad08fa9f75a3010 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 3 Sep 2020 18:11:15 -0400 Subject: [PATCH 103/150] changing mapping for vB3 --- afsk/main.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index dbb1b195..4718ccdc 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -452,8 +452,8 @@ if (vB4) sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x41, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x44, 400); sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x45, 400); */ - map[2] = BUS; - map[3] = BAT; + map[BAT] = BUS; + map[BUS] = BAT; strcpy(busStr,"1 0"); } else if (vB5) @@ -490,10 +490,12 @@ else sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); */ - map[2] = PLUS_Z; - map[3] = BAT; - map[4] = MINUS_X; - map[5] = BUS; + map[BAT] = PLUS_Z; + map[BUS] = BAT; + map[PLUS_Z] = BUS; + map[MINUS_Z] = BUS; +// map[4] = MINUS_X; +// map[5] = BUS; map[8] = 0x4a; // 2000 mA on bus 1 strcpy(busStr,"1 0"); batteryThreshold = 8.0; From abf74b3366a638d172e7818516bfe12d392ba5e5 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Fri, 4 Sep 2020 07:09:53 -0400 Subject: [PATCH 104/150] added reading of 0x4a bus sensor --- python/voltcurrent.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 68961867..22d05edf 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -29,12 +29,16 @@ if __name__ == "__main__": for x in buses: i2c_bus = I2C(x) # Device is /dev/i2c-x for y in addresses: - # print(x,y) + print(x,y) try: # Create library object using Extended Bus I2C port # print("bus: ", x, " addr: ", y) - - ina219 = INA219(i2c_bus, y) + if x == 0 and y == 0x45: + print("Reading INA219 in MoPower Board") + i2c_bus = I2C(1) + ina219 = INA219(i2c_bus, 0x4a) + else: + ina219 = INA219(i2c_bus, y) # print("ina219 test") if config: From f6a48a4b20714526b5c3486d59bd97f33d60e2ca Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Fri, 4 Sep 2020 07:13:27 -0400 Subject: [PATCH 105/150] added 10x multiplier for 0x4a current sensor --- python/voltcurrent.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 22d05edf..577ae08a 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -29,12 +29,12 @@ if __name__ == "__main__": for x in buses: i2c_bus = I2C(x) # Device is /dev/i2c-x for y in addresses: - print(x,y) + # print(x,y) try: # Create library object using Extended Bus I2C port # print("bus: ", x, " addr: ", y) if x == 0 and y == 0x45: - print("Reading INA219 in MoPower Board") +% print("Reading INA219 in MoPower Board") i2c_bus = I2C(1) ina219 = INA219(i2c_bus, 0x4a) else: @@ -52,6 +52,8 @@ if __name__ == "__main__": bus_voltage = ina219.bus_voltage # voltage on V- (load side) # shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt current = ina219.current # current in mA + if x == 0 and y == 0x45: + current = current * 10 # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage # print("{:6.3f}".format(bus_voltage + shunt_voltage)) print("{:6.3f} ".format(bus_voltage), "{:6.3f} ".format(current) , end = '') From 891180b1c4f70d6a6d666b4f4996baac209f59d2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Fri, 4 Sep 2020 07:14:05 -0400 Subject: [PATCH 106/150] 0x4a sensor reading working --- python/voltcurrent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/voltcurrent.py b/python/voltcurrent.py index 577ae08a..51d4444e 100644 --- a/python/voltcurrent.py +++ b/python/voltcurrent.py @@ -34,7 +34,7 @@ if __name__ == "__main__": # Create library object using Extended Bus I2C port # print("bus: ", x, " addr: ", y) if x == 0 and y == 0x45: -% print("Reading INA219 in MoPower Board") +# print("Reading INA219 in MoPower Board") i2c_bus = I2C(1) ina219 = INA219(i2c_bus, 0x4a) else: From 1b770af05087ffe10563c494809b9702bc2c3eff Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Fri, 4 Sep 2020 07:22:41 -0400 Subject: [PATCH 107/150] fixed mapping for vB3 board --- afsk/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 4718ccdc..5256fce1 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -490,13 +490,13 @@ else sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); */ - map[BAT] = PLUS_Z; - map[BUS] = BAT; - map[PLUS_Z] = BUS; - map[MINUS_Z] = BUS; + map[BUS] = MINUS_Z; + map[BAT] = BUS; + map[PLUS_Z] = BAT; + map[MINUS_Z] = PLUS_Z; // map[4] = MINUS_X; // map[5] = BUS; - map[8] = 0x4a; // 2000 mA on bus 1 + map[8] = 0x4a; // strcpy(busStr,"1 0"); batteryThreshold = 8.0; } From 7a6a9389d133e402b67754dc7f905d82a1efe4d1 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Fri, 4 Sep 2020 13:16:58 +0000 Subject: [PATCH 108/150] added 10 second delay for SPI startup --- demo.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/demo.sh b/demo.sh index 20aef361..bf29c4ce 100755 --- a/demo.sh +++ b/demo.sh @@ -2,6 +2,8 @@ echo -e "\nDemo of CubeSatSim at 434.9 MHz\n" +sleep 10 + sudo systemctl restart rpitx if [ "$1" = "a" ]; then From 16800022d5c391e0f146128882e964927980430d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 08:34:40 -0400 Subject: [PATCH 109/150] reduce BPSK sleep time to reduce sample time to 3 s --- afsk/main.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 5256fce1..e13a4ff8 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -666,8 +666,10 @@ while (loop-- != 0) bufLen = (frameCnt * (syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen))) * samples); // samplePeriod = ((float)((syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen))))/(float)bitRate) * 1000 - 1800; - samplePeriod = 3000; - sleepTime = 3.0; +// samplePeriod = 3000; +// sleepTime = 3.0; + samplePeriod = 1000; // reduce dut to python and sensor querying delays + sleepTime = 1.0; printf("\n BPSK Mode, bufLen: %d, %d bits per frame, %d bits per second, %d seconds per frame %d ms sample period\n", bufLen, bufLen/(samples * frameCnt), bitRate, bufLen/(samples * frameCnt * bitRate), samplePeriod); @@ -1091,16 +1093,6 @@ int get_tlm_fox() { { if (firstTime != ON) -/* -{// digitalWrite (3, HIGH); - if (mode == BPSK) - sleep(3); - // sleep(3.5); -// digitalWrite (3, LOW); -} - - if (mode == FSK) -*/ { // delay for sample period digitalWrite (txLed, txLedOn); From 48bc9dc6a4ef6ad3b6ebc1efab2deb3b77783c9e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 08:38:42 -0400 Subject: [PATCH 110/150] increase time --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index e13a4ff8..328e78ea 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -668,8 +668,8 @@ while (loop-- != 0) // samplePeriod = ((float)((syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen))))/(float)bitRate) * 1000 - 1800; // samplePeriod = 3000; // sleepTime = 3.0; - samplePeriod = 1000; // reduce dut to python and sensor querying delays - sleepTime = 1.0; + samplePeriod = 2000; // reduce dut to python and sensor querying delays + sleepTime = 2.0; printf("\n BPSK Mode, bufLen: %d, %d bits per frame, %d bits per second, %d seconds per frame %d ms sample period\n", bufLen, bufLen/(samples * frameCnt), bitRate, bufLen/(samples * frameCnt * bitRate), samplePeriod); From 00b13bf51b7b3d1cc5e1da078065b7b0e149b78c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 08:42:23 -0400 Subject: [PATCH 111/150] 2.5 --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 328e78ea..e72791f0 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -668,8 +668,8 @@ while (loop-- != 0) // samplePeriod = ((float)((syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen))))/(float)bitRate) * 1000 - 1800; // samplePeriod = 3000; // sleepTime = 3.0; - samplePeriod = 2000; // reduce dut to python and sensor querying delays - sleepTime = 2.0; + samplePeriod = 2500; // reduce dut to python and sensor querying delays + sleepTime = 2.5; printf("\n BPSK Mode, bufLen: %d, %d bits per frame, %d bits per second, %d seconds per frame %d ms sample period\n", bufLen, bufLen/(samples * frameCnt), bitRate, bufLen/(samples * frameCnt * bitRate), samplePeriod); From 1aa6351106cec0f1d6952a5a9cd01d3528b69bf6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 08:44:12 -0400 Subject: [PATCH 112/150] Update main.c --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index e72791f0..dccc5de7 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -668,8 +668,8 @@ while (loop-- != 0) // samplePeriod = ((float)((syncBits + 10 * (headerLen + rsFrames * (rsFrameLen + parityLen))))/(float)bitRate) * 1000 - 1800; // samplePeriod = 3000; // sleepTime = 3.0; - samplePeriod = 2500; // reduce dut to python and sensor querying delays - sleepTime = 2.5; + samplePeriod = 2200; // reduce dut to python and sensor querying delays + sleepTime = 2.2; printf("\n BPSK Mode, bufLen: %d, %d bits per frame, %d bits per second, %d seconds per frame %d ms sample period\n", bufLen, bufLen/(samples * frameCnt), bitRate, bufLen/(samples * frameCnt * bitRate), samplePeriod); From abfbb5db89d00ab29ac0c3ce9b767f787b01f49d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 08:49:19 -0400 Subject: [PATCH 113/150] set map array back to 8 values --- afsk/main.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index dccc5de7..f6a9e1ab 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -130,7 +130,7 @@ float batteryThreshold = 3.0, batteryVoltage; const char pythonCmd[] = "python3 /home/pi/CubeSatSim/python/voltcurrent.py "; char pythonStr[100], pythonConfigStr[100], busStr[10]; -int map[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 0x45}; +int map[8] = { 0, 1, 2, 3, 4, 5, 6, 7}; /* struct SensorConfig { int fd; @@ -494,9 +494,6 @@ else map[BAT] = BUS; map[PLUS_Z] = BAT; map[MINUS_Z] = PLUS_Z; -// map[4] = MINUS_X; -// map[5] = BUS; - map[8] = 0x4a; // strcpy(busStr,"1 0"); batteryThreshold = 8.0; } From 95a297ad81def76e1a39322e2c32e20735892515 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 08:57:43 -0400 Subject: [PATCH 114/150] removed old sensor and rpitx code that was commented out --- afsk/main.c | 356 +--------------------------------------------------- 1 file changed, 4 insertions(+), 352 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index f6a9e1ab..5c55cc0e 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -131,139 +131,6 @@ float batteryThreshold = 3.0, batteryVoltage; const char pythonCmd[] = "python3 /home/pi/CubeSatSim/python/voltcurrent.py "; char pythonStr[100], pythonConfigStr[100], busStr[10]; int map[8] = { 0, 1, 2, 3, 4, 5, 6, 7}; -/* -struct SensorConfig { - int fd; - uint16_t config; - int calValue; - int powerMultiplier; - int currentDivider; -}; - -struct SensorData { - double current; - double voltage; - double power; -}; - -/** - * @brief Read the data from one of the i2c current sensors. - * - * Reads the current data from the requested i2c current sensor configuration and - * stores it into a SensorData struct. An invalid file descriptor (i.e. less than zero) - * results in a SensorData struct being returned that has both its #current and #power members - * set to NAN. - * - * @param sensor A structure containing sensor configuration including the file descriptor. - * @return struct SensorData A struct that contains the current, voltage, and power readings - * from the requested sensor. - * -struct SensorData read_sensor_data(struct SensorConfig sensor) { - struct SensorData data = { - .current = 0, - .voltage = 0, - .power = 0 }; - - if (sensor.fd < 0) { - return data; - } - // doesn't read negative currents accurately, shows -0.1mA - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - sleep(0.01); - int value = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - if (value == -1) - { - sensor.fd = -1; - return data; - } - data.current = (float) twosToInt(value, 16) / (float) sensor.currentDivider; - - wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); - delay(1); // Max 12-bit conversion time is 586us per sample - value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); - data.voltage = ((float)(value >> 3) * 4) / 1000; - // power has very low resolution, seems to step in 512mW values - data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; - - return data; -} - -/** - * @brief Configures an i2c current sensor. - * - * Calculates the configuration values of the i2c sensor so that - * current, voltage, and power can be read using read_sensor_data. - * Supports 16V 400mA and 16V 2.0A settings. - * - * @param sensor A file descriptor that can be used to read from the sensor. - * @param milliAmps The mA configuration, either 400mA or 2A are supported. - * @return struct SensorConfig A struct that contains the configuraton of the sensor. - * -//struct SensorConfig config_sensor(int sensor, int milliAmps) { -struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { - struct SensorConfig data; - - if (access(bus, W_OK | R_OK) < 0) { // Test if I2C Bus is missing - printf("ERROR: %s bus not present\n Check raspi-config Interfacing Options/I2C and /boot/config.txt \n", bus); - data.fd = OFF; - return (data); - } - char result[128]; - int pos = strlen(bus) / sizeof(bus[0]) - 1; - // printf("Bus size %d \n", pos); - // printf("Bus value %d \n", atoi(&bus[pos])); - char command[50] = "timeout 10 i2cdetect -y "; - strcat (command, &bus[pos]); - FILE *i2cdetect = popen(command, "r"); - - while (fgets(result, 128, i2cdetect) != NULL) { - ; - // printf("result: %s", result); - } - - int error = pclose(i2cdetect)/256; - - // printf("%s error: %d \n", &command, error); - if (error != 0) - { - printf("ERROR: %s bus has a problem \n Check I2C wiring and pullup resistors \n", bus); - data.fd = OFF; - return (data); - } - - data.fd = wiringPiI2CSetupInterface(bus, address); - - data.config = INA219_CONFIG_BVOLTAGERANGE_32V | - INA219_CONFIG_GAIN_1_40MV | - INA219_CONFIG_BADCRES_12BIT | - INA219_CONFIG_SADCRES_12BIT_1S_532US | - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; - - if (milliAmps == 400) { // INA219 16V 400mA configuration - data.calValue = 8192; - data.powerMultiplier = 1; - data.currentDivider = 20; // 40; in Adafruit config - } - else { // INA219 16V 2A configuration - data.calValue = 40960; - data.powerMultiplier = 2; - data.currentDivider = 10; // 20; in Adafruit config - } - - #ifdef DEBUG_LOGGING - printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd, - data.config, data.calValue, data.currentDivider, data.powerMultiplier); - #endif - return data; -} - -struct SensorConfig sensor[8]; // 8 current sensors in Solar Power PCB vB4/5 -struct SensorData reading[8]; // 8 current sensors in Solar Power PCB vB4/5 -struct SensorConfig tempSensor; -*/ - char src_addr[5] = ""; char dest_addr[5] = "CQ"; @@ -444,52 +311,21 @@ int main(int argc, char *argv[]) { if (vB4) { -/* sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x44, 400); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); - sensor[PLUS_Z] = config_sensor("/dev/i2c-0", 0x40, 400); - sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x41, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x44, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x45, 400); */ map[BAT] = BUS; map[BUS] = BAT; strcpy(busStr,"1 0"); } else if (vB5) { -/* sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x44, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x45, 400); */ - if (access("/dev/i2c-11", W_OK | R_OK) >= 0) { // Test if I2C Bus 11 is present printf("/dev/i2c-11 is present\n\n"); - /* sensor[PLUS_Z] = config_sensor("/dev/i2c-11", 0x40, 400); - sensor[MINUS_X] = config_sensor("/dev/i2c-11", 0x41, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-11", 0x44, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-11", 0x45, 400); */ strcpy(busStr,"1 11"); } else { - /* sensor[PLUS_Z] = config_sensor("/dev/i2c-3", 0x40, 400); - sensor[MINUS_X] = config_sensor("/dev/i2c-3", 0x41, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-3", 0x44, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-3", 0x45, 400); */ strcpy(busStr,"1 3"); } } else { -/* sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); - sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); - - tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); */ map[BUS] = MINUS_Z; map[BAT] = BUS; map[PLUS_Z] = BAT; @@ -498,7 +334,7 @@ else batteryThreshold = 8.0; } - strcpy(pythonStr, pythonCmd); + strcpy(pythonStr, pythonCmd); strcat(pythonStr, busStr); strcat(pythonConfigStr, pythonStr); strcat(pythonConfigStr, " c"); @@ -559,49 +395,7 @@ else //uint8_t data[1024]; tx_freq_hz -= tx_channel * 50000; -/* - if (transmit == FALSE) - { - - fprintf(stderr,"\nNo CubeSatSim Band Pass Filter detected. No transmissions after the CW ID.\n"); - fprintf(stderr, " See http://cubesatsim.org/wiki for info about building a CubeSatSim\n\n"); - } -// Send ID in CW (Morse Code) -cw_id = OFF; -if (cw_id == ON) // Don't send CW if using AX5043 or in mode cycling or set by 3rd argument -{ - char cw_str[200]; - char cw_header[] = "echo 'de "; - char cw_footer[] = "' > id.txt && gen_packets -M 20 id.txt -o morse.wav -r 48000 > /dev/null 2>&1 && cat morse.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.897e3"; - - strcpy(cw_str, cw_header); -//printf("Before 1st strcpy\n"); - strcat(cw_str, call); -//printf("Before 1st strcpy\n"); - strcat(cw_str, cw_footer); -//printf("Before 1st strcpy\n"); - digitalWrite (txLed, txLedOn); - #ifdef DEBUG_LOGGING - printf("Tx LED On\n"); - #endif -//printf("Before cmd\n"); -//printf("CW String: %s\n", cw_str); -// FILE* f; - system(cw_str); -// printf("File %d \n", f); -// printf("close: %d \n", pclose(f)); // execute command and wait for termination before continuing -printf("After command\n"); -// sleep(7); -//printf("Before Write\n"); - digitalWrite (txLed, txLedOn); - #ifdef DEBUG_LOGGING - printf("Tx LED On\n"); - #endif -//printf("After Write\n"); -} -//printf("Done CW!\n"); -*/ while (loop-- != 0) { frames_sent++; @@ -712,21 +506,7 @@ while (loop-- != 0) sleep(loop_count); printf("Done sleeping\n"); } -/* -// int transmit = popen("timeout 1 sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.897e3","r"); - int txResult = popen("sudo killall -9 rpitx > /dev/null 2>&1", "r"); - pclose(txResult); - txResult = popen("sudo killall -9 sendiq > /dev/null 2>&1", "r"); - pclose(txResult); - txResult = popen("sudo fuser -k 8080/tcp > /dev/null 2>&1", "r"); - pclose(txResult); - if(cw_id == ON) // only turn off Power LED if CW ID is enabled (i.e. not demo.sh mode cycling) - digitalWrite (onLed, onLedOff); - #ifdef DEBUG_LOGGING - printf("Tx LED Off\n"); - #endif -*/ return 0; } @@ -820,17 +600,7 @@ for (int j = 0; j < frameCnt; j++) } } } -/* - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); - #ifdef DEBUG_LOGGING -// printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", -// count, reading[count].voltage, reading[count].current, reading[count].power); - #endif - } -*/ + tlm[1][A] = (int)(voltage[map[BUS]] /15.0 + 0.5) % 100; // Current of 5V supply to Pi tlm[1][B] = (int) (99.5 - current[map[PLUS_X]]/10.0) % 100; // +X current [4] tlm[1][C] = (int) (99.5 - current[map[MINUS_X]]/10.0) % 100; // X- current [10] @@ -845,24 +615,7 @@ for (int j = 0; j < frameCnt; j++) tlm[3][B] = (int)(voltage[map[BUS]] * 10.0) % 100; // 5V supply to Pi batteryVoltage = voltage[map[BAT]]; - -/* - if (ax5043) - { - if (tempSensor.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); - uint8_t lower = (uint8_t) (tempValue & 0xff); - float temp = (float)lower + ((float)upper / 0x100); - - #ifdef DEBUG_LOGGING - printf("Temp Sensor Read: %6.1f\n", temp); - #endif - - tlm[4][A] = (int)((95.8 - temp)/1.48 + 0.5) % 100; - } - } -*/ + FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); if (cpuTempSensor) { double cpuTemp; @@ -1148,33 +901,7 @@ if (firstTime != ON) } // printf("\n"); -/* - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); - reading[count] = read_sensor_data(sensor[count]); - #ifdef DEBUG_LOGGING -// printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", -// count, reading[count].voltage, reading[count].current, reading[count].power); - #endif - } -*/ -/* - if (tempSensor.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); - uint8_t lower = (uint8_t) (tempValue & 0xff); - float temp = (float)lower + ((float)upper / 0x100); - - #ifdef DEBUG_LOGGING - printf("Temp Sensor Read: %6.1f\n", temp); - #endif - - TxTemp = (int)((temp * 10.0) + 0.5); - encodeB(b, 34 + head_offset, TxTemp); - } -*/ + FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); if (cpuTempSensor) { double cpuTemp; @@ -1215,28 +942,6 @@ if (firstTime != ON) if (mode == BPSK) h[6] = 99; - -/* -// posXv = reading[PLUS_X].current; - posXi = (int)reading[PLUS_X].current + 2048; - posYi = (int)reading[PLUS_Y].current + 2048; - posZi = (int)reading[PLUS_Z].current + 2048; - negXi = (int)reading[MINUS_X].current + 2048; - negYi = (int)reading[MINUS_Y].current + 2048; - negZi = (int)reading[MINUS_Z].current + 2048; - - posXv = (int)(reading[PLUS_X].voltage * 100); - posYv = (int)(reading[PLUS_Y].voltage* 100); - posZv = (int)(reading[PLUS_Z].voltage * 100); - negXv = (int)(reading[MINUS_X].voltage * 100); - negYv = (int)(reading[MINUS_Y].voltage * 100); - negZv = (int)(reading[MINUS_Z].voltage * 100); - - batt_c_v = (int)(reading[BAT].voltage * 100); - battCurr = (int)reading[BAT].current + 2048; - PSUVoltage = (int)(reading[BUS].voltage * 100); - PSUCurrent = (int)reading[BUS].current + 2048; -*/ posXi = (int)current[map[PLUS_X]] + 2048; posYi = (int)current[map[PLUS_Y]] + 2048; @@ -1474,64 +1179,11 @@ if (firstTime != ON) int error = 0; int count; -// for (count = 0; count < DATA_LEN; count++) { // for (count = 0; count < dataLen; count++) { // printf("%02X", b[count]); // } // printf("\n"); -// rpitx -/* - char cmdbuffer[1000]; - FILE* txResult; - if ((rpitxStatus != mode)) // || ((loop % 1000) == 0)) - - { // change rpitx mode - rpitxStatus = mode; - printf("Changing rpitx mode!\n"); -// txResult = popen("ps -ef | grep rpitx | grep -v grep | awk '{print $2}' | sudo xargs kill -9 > /dev/null 2>&1", "r"); - txResult = popen("sudo killall -9 rpitx > /dev/null 2>&1", "r"); - pclose(txResult); -// printf("1\n"); -// sleep(1); -// txResult = popen("ps -ef | grep sendiq | grep -v grep | awk '{print $2}' | sudo xargs kill -9 > /dev/null 2>&1", "r"); - txResult = popen("sudo killall -9 sendiq > /dev/null 2>&1", "r"); - pclose(txResult); -// printf("2\n"); -// digitalWrite (txLed, txLedOn); - sleep(1); - txResult = popen("sudo fuser -k 8080/tcp > /dev/null 2>&1", "r"); - pclose(txResult); - socket_open = 0; - -// printf("3\n"); - sleep(1); -// digitalWrite (txLed, txLedOff); - - if (transmit) - { - if (mode == FSK) { - // txResult = popen("sudo nc -l 8080 | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.896e3&", "r"); - txResult = popen("sudo nc -l 8080 | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | while true; do sudo timeout -k 1 60m /home/pi/rpitx/rpitx -i- -m RF -f 434.897e3; done &", "r"); - pclose(txResult); - // printf("4\n"); - } else if (mode == BPSK) { -// txResult = popen("sudo nc -l 8080 | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/CubeSatSim/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.8925e6 -t float 2>&1&", "r"); - txResult = popen("sudo nc -l 8080 | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | while true; do sudo timeout -k 1 60m /home/pi/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.8945e6 -t float 2>&1; done &", "r"); - pclose(txResult); } -// fgets(cmdbuffer, 1000, txResult); - - } - else - { - fprintf(stderr,"\nNo CubeSatSim Band Pass Filter detected. No transmissions after the CW ID.\n"); - fprintf(stderr, " See http://cubesatsim.org/wiki for info about building a CubeSatSim\n\n"); - } - sleep(2); -// printf("Results of transmit command: %s\n", cmdbuffer); - } -*/ - // socket write if (!socket_open && transmit) From 02ff418e3e6cd2f1181cac174683e89ead8ece05 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 09:58:10 -0400 Subject: [PATCH 115/150] switching to python start --- afsk/telem.c | 133 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 94 insertions(+), 39 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 77dd3681..c15c8974 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -42,17 +42,23 @@ #define PLUS_X 0 #define PLUS_Y 1 -#define PLUS_Z 2 -#define BAT 3 +#define BAT 2 +#define BUS 3 #define MINUS_X 4 #define MINUS_Y 5 -#define MINUS_Z 6 -#define BUS 7 +#define PLUS_Z 6 +#define MINUS_Z 7 + #define OFF -1 #define ON 1 int twosToInt(int val, int len); +const char pythonCmd[] = "python3 /home/pi/CubeSatSim/python/voltcurrent.py "; +char pythonStr[100], pythonConfigStr[100], busStr[10]; +int map[8] = { 0, 1, 2, 3, 4, 5, 6, 7}; + +/* struct SensorConfig { int fd; uint16_t config; @@ -80,7 +86,7 @@ struct SensorData { * @param sensor A structure containing sensor configuration including the file descriptor. * @return struct SensorData A struct that contains the current, voltage, and power readings * from the requested sensor. - */ + * struct SensorData read_sensor_data(struct SensorConfig sensor) { struct SensorData data = { .current = 0, @@ -130,7 +136,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { // power has very low resolution, seems to step in 512mW values delay(1); data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; - */ + * return data; } @@ -144,7 +150,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { * @param sensor A file descriptor that can be used to read from the sensor. * @param milliAmps The mA configuration, either 400mA or 2A are supported. * @return struct SensorConfig A struct that contains the configuraton of the sensor. - */ + * //struct SensorConfig config_sensor(int sensor, int milliAmps) { struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { struct SensorConfig data; @@ -235,16 +241,19 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { // data.config, data.calValue, data.currentDivider, data.powerMultiplier); // printf("Sensor %s %x | ", bus, address); //#endif -*/ +* return data; } +* + struct SensorConfig sensorV; struct SensorData readingV; struct SensorConfig tempSensor; struct SensorConfig sensor[8]; // 8 current sensors in Solar Power PCB vB4/5 struct SensorData reading[8]; // 8 current sensors in Solar Power PCB vB4/5 +*/ int main(int argc, char *argv[]) { @@ -262,14 +271,15 @@ int main(int argc, char *argv[]) { if (digitalRead(2) != HIGH) { printf("vB3 with TFB Present\n"); - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); +/* sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); } + sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); */ + } else { pinMode (3, INPUT); @@ -278,14 +288,17 @@ int main(int argc, char *argv[]) { if (digitalRead(3) != HIGH) { printf("vB4 Present\n"); - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); +/* sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); sensor[BUS] = config_sensor("/dev/i2c-1", 0x44, 400); sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); sensor[PLUS_Z] = config_sensor("/dev/i2c-0", 0x40, 400); sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x41, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x44, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x45, 400); + sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x45, 400); */ + map[BAT] = BUS; + map[BUS] = BAT; + strcpy(busStr,"1 0"); } else { @@ -295,41 +308,97 @@ int main(int argc, char *argv[]) { if (digitalRead(26) != HIGH) { printf("vB5 Present\n"); // Don't print normal board detection - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); +/* sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); sensor[BUS] = config_sensor("/dev/i2c-1", 0x45, 400); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x44, 400); + sensor[BAT] = config_sensor("/dev/i2c-1", 0x44, 400); */ if (access("/dev/i2c-11", W_OK | R_OK) >= 0) { // Test if I2C Bus 11 is present printf("/dev/i2c-11 is present\n\n"); - sensor[PLUS_Z] = config_sensor("/dev/i2c-11", 0x40, 400); + /* sensor[PLUS_Z] = config_sensor("/dev/i2c-11", 0x40, 400); sensor[MINUS_X] = config_sensor("/dev/i2c-11", 0x41, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-11", 0x44, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-11", 0x45, 400); + sensor[MINUS_Z] = config_sensor("/dev/i2c-11", 0x45, 400); */ } else { - sensor[PLUS_Z] = config_sensor("/dev/i2c-3", 0x40, 400); + /* sensor[PLUS_Z] = config_sensor("/dev/i2c-3", 0x40, 400); sensor[MINUS_X] = config_sensor("/dev/i2c-3", 0x41, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-3", 0x44, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-3", 0x45, 400); + sensor[MINUS_Z] = config_sensor("/dev/i2c-3", 0x45, 400); */ } } else { printf("VB3 Present\n"); - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); +/* sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); } + sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); */ + map[BUS] = MINUS_Z; + map[BAT] = BUS; + map[PLUS_Z] = BAT; + map[MINUS_Z] = PLUS_Z; + strcpy(busStr,"1 0"); + } } } // Reading I2C voltage and current sensors printf("Starting\n"); + + strcpy(pythonStr, pythonCmd); + strcat(pythonStr, busStr); + strcat(pythonConfigStr, pythonStr); + strcat(pythonConfigStr, " c"); + +// FILE* file1 = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11 c", "r"); + FILE* file1 = popen(pythonConfigStr, "r"); + char cmdbuffer[1000]; + fgets(cmdbuffer, 1000, file1); +// printf("pythonStr result: %s\n", cmdbuffer); + pclose(file1); + + int count1; + char *token; + char cmdbuffer[1000]; + +// FILE *file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); + FILE* file = popen(pythonStr, "r"); + fgets(cmdbuffer, 1000, file); +// printf("result: %s\n", cmdbuffer); + pclose(file); + + const char space[2] = " "; + token = strtok(cmdbuffer, space); + + float voltage[9], current[9]; + memset(voltage, 0, sizeof(voltage)); + memset(current, 0, sizeof(current)); + + for (count1 = 0; count1 < 8; count1++) + { + if (token != NULL) + { + voltage[count1] = atof(token); + #ifdef DEBUG_LOGGING + printf("voltage: %f ", voltage[count1]); + #endif + token = strtok(NULL, space); + if (token != NULL) + { + current[count1] = atof(token); + #ifdef DEBUG_LOGGING + printf("current: %f\n", current[count1]); + #endif + token = strtok(NULL, space); + } + } + } +/* FILE* file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3 c", "r"); char cmdbuffer[1000]; fgets(cmdbuffer, 1000, file); @@ -359,19 +428,16 @@ int main(int argc, char *argv[]) { printf("\n"); } - - // data.voltage = atof(cmdbuffer); - - - +*/ + // data.voltage = atof(cmdbuffer); // } - return; +// return; - { +// { - reading[count] = read_sensor_data(sensor[count]); +// reading[count] = read_sensor_data(sensor[count]); // printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", // count, reading[count].voltage, reading[count].current, reading[count].power); } @@ -424,17 +490,6 @@ int main(int argc, char *argv[]) { printf("Bus | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", // BUS, readingV.voltage, readingV.current, readingV.power); BUS, reading[BUS].voltage, reading[BUS].current, reading[BUS].power); - - /* - sensorV = config_sensor("/dev/i2c-3", 0x48, 0); - if (sensorV.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(sensorV.fd, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); - uint8_t lower = (uint8_t) (tempValue & 0xff); - float temp = (float)lower + ((float)upper / 0x100); - printf("T | % 4.1f C \n", temp); - } - */ printf("\n\n"); From 4a29e547c4021fb944268fb00dd3c6b51619b5de Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 09:59:48 -0400 Subject: [PATCH 116/150] Update telem.c --- afsk/telem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index c15c8974..2cc4a5f0 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -363,7 +363,7 @@ int main(int argc, char *argv[]) { int count1; char *token; - char cmdbuffer[1000]; +// char cmdbuffer[1000]; // FILE *file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); FILE* file = popen(pythonStr, "r"); @@ -440,7 +440,7 @@ int main(int argc, char *argv[]) { // reading[count] = read_sensor_data(sensor[count]); // printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", // count, reading[count].voltage, reading[count].current, reading[count].power); - } +// } printf("\n"); // sensorV = config_sensor("/dev/i2c-1", 0x40, 400); From 552b28de253b2c72227f1156a0156cbdf5fbed5e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 10:01:22 -0400 Subject: [PATCH 117/150] Update telem.c --- afsk/telem.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 2cc4a5f0..0b4de19e 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -442,13 +442,14 @@ int main(int argc, char *argv[]) { // count, reading[count].voltage, reading[count].current, reading[count].power); // } printf("\n"); - + + // sensorV = config_sensor("/dev/i2c-1", 0x40, 400); // readingV = read_sensor_data(sensorV); - printf("+X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("+X | sensor[%d] % 4.2fV % 6.1fmA \n", // PLUS_X, readingV.voltage, readingV.current, readingV.power); - PLUS_X, reading[PLUS_X].voltage, reading[PLUS_X].current, reading[PLUS_X].power); - + PLUS_X, voltage[map[PLUS_X]], current[mapPLUS_X]]); +/* // sensorV = config_sensor("/dev/i2c-1", 0x41, 400); // readingV = read_sensor_data(sensorV); printf("+Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", @@ -490,7 +491,7 @@ int main(int argc, char *argv[]) { printf("Bus | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", // BUS, readingV.voltage, readingV.current, readingV.power); BUS, reading[BUS].voltage, reading[BUS].current, reading[BUS].power); - +*/ printf("\n\n"); return 0; From aa2a3b71fdfd939fb3e74a769b139d30d567e7e2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 10:02:00 -0400 Subject: [PATCH 118/150] Update telem.c --- afsk/telem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index 0b4de19e..3b20b382 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -448,7 +448,7 @@ int main(int argc, char *argv[]) { // readingV = read_sensor_data(sensorV); printf("+X | sensor[%d] % 4.2fV % 6.1fmA \n", // PLUS_X, readingV.voltage, readingV.current, readingV.power); - PLUS_X, voltage[map[PLUS_X]], current[mapPLUS_X]]); + PLUS_X, voltage[map[PLUS_X]], current[map[PLUS_X]]); /* // sensorV = config_sensor("/dev/i2c-1", 0x41, 400); // readingV = read_sensor_data(sensorV); From 807bf5431150cf25ef8763ff7a838ffacd7e6d93 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 10:04:56 -0400 Subject: [PATCH 119/150] Update telem.c --- afsk/telem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/afsk/telem.c b/afsk/telem.c index 3b20b382..92882ad7 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -319,11 +319,13 @@ int main(int argc, char *argv[]) { sensor[MINUS_X] = config_sensor("/dev/i2c-11", 0x41, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-11", 0x44, 400); sensor[MINUS_Z] = config_sensor("/dev/i2c-11", 0x45, 400); */ + strcpy(busStr,"1 11"); } else { /* sensor[PLUS_Z] = config_sensor("/dev/i2c-3", 0x40, 400); sensor[MINUS_X] = config_sensor("/dev/i2c-3", 0x41, 400); sensor[MINUS_Y] = config_sensor("/dev/i2c-3", 0x44, 400); sensor[MINUS_Z] = config_sensor("/dev/i2c-3", 0x45, 400); */ + strcpy(busStr,"1 3"); } } else From cc776b3cf7d2ee43716307efd8199b37d2959dc2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 11:49:52 -0400 Subject: [PATCH 120/150] print all values --- afsk/telem.c | 379 +++++---------------------------------------------- 1 file changed, 36 insertions(+), 343 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 92882ad7..ec123dd6 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -52,208 +52,9 @@ #define OFF -1 #define ON 1 -int twosToInt(int val, int len); - const char pythonCmd[] = "python3 /home/pi/CubeSatSim/python/voltcurrent.py "; char pythonStr[100], pythonConfigStr[100], busStr[10]; -int map[8] = { 0, 1, 2, 3, 4, 5, 6, 7}; - -/* -struct SensorConfig { - int fd; - uint16_t config; - int calValue; - int powerMultiplier; - int currentDivider; - char commandv[100]; - char commandi[100]; -}; - -struct SensorData { - double current; - double voltage; - double power; -}; - -/** - * @brief Read the data from one of the i2c current sensors. - * - * Reads the current data from the requested i2c current sensor configuration and - * stores it into a SensorData struct. An invalid file descriptor (i.e. less than zero) - * results in a SensorData struct being returned that has both its #current and #power members - * set to NAN. - * - * @param sensor A structure containing sensor configuration including the file descriptor. - * @return struct SensorData A struct that contains the current, voltage, and power readings - * from the requested sensor. - * -struct SensorData read_sensor_data(struct SensorConfig sensor) { - struct SensorData data = { - .current = 0, - .voltage = 0, - .power = 0 - }; - - if (sensor.fd < 0) { - return data; - } - -// FILE* file = popen("python3 /home/pi/CubeSatSim/python/voltage.py 1 0x44", "r"); - FILE* file = popen(sensor.commandv, "r"); - char cmdbuffer[1000]; - fgets(cmdbuffer, 1000, file); - pclose(file); - data.voltage = atof(cmdbuffer); - -// printf("voltage: %s \n", cmdbuffer); - - file = popen(sensor.commandi, "r"); - fgets(cmdbuffer, 1000, file); - pclose(file); - -// printf("current: %s \n", cmdbuffer); - - data.current = atof(cmdbuffer); - -/* - // doesn't read negative currents accurately, shows -0.1mA - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - delay(1); - int value = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - if (value == -1) - { - sensor.fd = -1; - return data; - } - data.current = (float) twosToInt(value, 16) / (float) sensor.currentDivider; - - wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); - delay(1); // Max 12-bit conversion time is 586us per sample - value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); - data.voltage = ((float)(value >> 3) * 4) / 1000; - // power has very low resolution, seems to step in 512mW values - delay(1); - data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; - * - return data; -} - -/** - * @brief Configures an i2c current sensor. - * - * Calculates the configuration values of the i2c sensor so that - * current, voltage, and power can be read using read_sensor_data. - * Supports 16V 400mA and 16V 2.0A settings. - * - * @param sensor A file descriptor that can be used to read from the sensor. - * @param milliAmps The mA configuration, either 400mA or 2A are supported. - * @return struct SensorConfig A struct that contains the configuraton of the sensor. - * -//struct SensorConfig config_sensor(int sensor, int milliAmps) { -struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { - struct SensorConfig data; - - if (access(bus, W_OK | R_OK) < 0) { // Test if I2C Bus is missing - printf("ERROR: %s bus not present \n Check raspi-config Interfacing Options/I2C and /boot/config.txt \n", bus); - data.fd = OFF; - return (data); - } - - char str[100]; - strcpy (str, bus); - char *buss; - const char dash[2] = "-"; - buss = strtok(str, dash); -// printf("buss: %s\n", buss); - buss = strtok(NULL, dash); -// printf("bus: %s\n", buss); - - char result[128]; - int pos = strlen(bus) / sizeof(bus[0]) - 1; -// printf("Bus size %d \n", pos); -// printf("Bus value %d \n", atoi(&bus[pos])); - char command[50] = "timeout 10 i2cdetect -y "; -// strcat (command, &bus[pos]); - strcat (command, buss); -// printf("Command: %s \n", command); - FILE *i2cdetect = popen(command, "r"); - - while (fgets(result, 128, i2cdetect) != NULL) { - ; -// printf("result: %s", result); - } - - int error = pclose(i2cdetect)/256; -// printf("%s error: %d \n", &command, error); - if (error != 0) - { - printf("ERROR: %s bus has a problem \n Check I2C wiring and pullup resistors \n", bus); - data.fd = OFF; - return (data); - } - data.fd = ON; - - char spacev[] = " 0x"; - char pythonv[100] = "python3 /home/pi/CubeSatSim/python/voltage.py "; - char pythoni[100] = "python3 /home/pi/CubeSatSim/python/current.py "; - - strcat (pythonv, buss); - strcat (pythonv, spacev); - char addr[10]; - snprintf( addr, 10, "%x", address ); - strcat (pythonv, addr); - strcpy (data.commandv, pythonv); - -// printf("V Command: %s \n", data.commandv); - - char spacei[] = " 0x"; - strcat (pythoni, buss); - strcat (pythoni, spacei); - strcat (pythoni, addr); - strcpy (data.commandi, pythoni); - -// printf("V Command: %s \n", data.commandi); - - /* - data.fd = wiringPiI2CSetupInterface(bus, address); - - data.config = INA219_CONFIG_BVOLTAGERANGE_32V | - INA219_CONFIG_GAIN_1_40MV | - INA219_CONFIG_BADCRES_12BIT | - INA219_CONFIG_SADCRES_12BIT_1S_532US | - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; - - if (milliAmps == 400) { // INA219 16V 400mA configuration - data.calValue = 8192; - data.powerMultiplier = 1; - data.currentDivider = 20; // 40; in Adafruit config - } - else { // INA219 16V 2A configuration - data.calValue = 40960; - data.powerMultiplier = 2; - data.currentDivider = 10; // 20; in Adafruit config - } - - //#ifdef DEBUG_LOGGING -// printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd, -// data.config, data.calValue, data.currentDivider, data.powerMultiplier); -// printf("Sensor %s %x | ", bus, address); - //#endif -* - return data; -} - -* - -struct SensorConfig sensorV; -struct SensorData readingV; -struct SensorConfig tempSensor; -struct SensorConfig sensor[8]; // 8 current sensors in Solar Power PCB vB4/5 -struct SensorData reading[8]; // 8 current sensors in Solar Power PCB vB4/5 - -*/ +int map[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; int main(int argc, char *argv[]) { @@ -271,14 +72,11 @@ int main(int argc, char *argv[]) { if (digitalRead(2) != HIGH) { printf("vB3 with TFB Present\n"); -/* sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); - sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); */ + map[BUS] = MINUS_Z; + map[BAT] = BUS; + map[PLUS_Z] = BAT; + map[MINUS_Z] = PLUS_Z; + strcpy(busStr,"1 0"); } else { @@ -288,14 +86,6 @@ int main(int argc, char *argv[]) { if (digitalRead(3) != HIGH) { printf("vB4 Present\n"); -/* sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x44, 400); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); - sensor[PLUS_Z] = config_sensor("/dev/i2c-0", 0x40, 400); - sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x41, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x44, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x45, 400); */ map[BAT] = BUS; map[BUS] = BAT; strcpy(busStr,"1 0"); @@ -307,56 +97,35 @@ int main(int argc, char *argv[]) { if (digitalRead(26) != HIGH) { - printf("vB5 Present\n"); // Don't print normal board detection -/* sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x45, 400); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x44, 400); */ + printf("vB5 Present\n"); // Don't print normal board detection - if (access("/dev/i2c-11", W_OK | R_OK) >= 0) { // Test if I2C Bus 11 is present - printf("/dev/i2c-11 is present\n\n"); - /* sensor[PLUS_Z] = config_sensor("/dev/i2c-11", 0x40, 400); - sensor[MINUS_X] = config_sensor("/dev/i2c-11", 0x41, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-11", 0x44, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-11", 0x45, 400); */ - strcpy(busStr,"1 11"); - } else { - /* sensor[PLUS_Z] = config_sensor("/dev/i2c-3", 0x40, 400); - sensor[MINUS_X] = config_sensor("/dev/i2c-3", 0x41, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-3", 0x44, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-3", 0x45, 400); */ - strcpy(busStr,"1 3"); - } + if (access("/dev/i2c-11", W_OK | R_OK) >= 0) { // Test if I2C Bus 11 is present + printf("/dev/i2c-11 is present\n\n"); + strcpy(busStr,"1 11"); + } else { + strcpy(busStr,"1 3"); + } } else { printf("VB3 Present\n"); -/* sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); - sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); */ map[BUS] = MINUS_Z; map[BAT] = BUS; map[PLUS_Z] = BAT; map[MINUS_Z] = PLUS_Z; strcpy(busStr,"1 0"); } - } + } } // Reading I2C voltage and current sensors - printf("Starting\n"); +// printf("Starting\n"); strcpy(pythonStr, pythonCmd); strcat(pythonStr, busStr); strcat(pythonConfigStr, pythonStr); strcat(pythonConfigStr, " c"); -// FILE* file1 = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11 c", "r"); FILE* file1 = popen(pythonConfigStr, "r"); char cmdbuffer[1000]; fgets(cmdbuffer, 1000, file1); @@ -365,13 +134,11 @@ int main(int argc, char *argv[]) { int count1; char *token; -// char cmdbuffer[1000]; -// FILE *file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); - FILE* file = popen(pythonStr, "r"); - fgets(cmdbuffer, 1000, file); -// printf("result: %s\n", cmdbuffer); - pclose(file); + FILE* file = popen(pythonStr, "r"); + fgets(cmdbuffer, 1000, file); +// printf("result: %s\n", cmdbuffer); + pclose(file); const char space[2] = " "; token = strtok(cmdbuffer, space); @@ -385,125 +152,51 @@ int main(int argc, char *argv[]) { if (token != NULL) { voltage[count1] = atof(token); - #ifdef DEBUG_LOGGING - printf("voltage: %f ", voltage[count1]); - #endif +// #ifdef DEBUG_LOGGING +// printf("voltage: %f ", voltage[count1]); +// #endif token = strtok(NULL, space); if (token != NULL) { current[count1] = atof(token); - #ifdef DEBUG_LOGGING - printf("current: %f\n", current[count1]); - #endif +// #ifdef DEBUG_LOGGING +// printf("current: %f\n", current[count1]); +// #endif token = strtok(NULL, space); } - } - } - -/* - FILE* file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3 c", "r"); - char cmdbuffer[1000]; - fgets(cmdbuffer, 1000, file); - pclose(file); - - int count; - char *token; -// char cmdbuffer[1000]; - - while (1) { - file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 3", "r"); -// char cmdbuffer[1000]; -// char cmdbuffer[1000]; - fgets(cmdbuffer, 1000, file); -// printf("result: %s\n", cmdbuffer); - pclose(file); - - const char space[2] = " "; - token = strtok(cmdbuffer, space); - for (count = 0; count < 8; count++) - { - printf("voltage: %s ", token); - token = strtok(NULL, space); - printf("current: %s\n", token); - token = strtok(NULL, space); - } - - printf("\n"); - } -*/ - // data.voltage = atof(cmdbuffer); - -// } - -// return; - -// { - -// reading[count] = read_sensor_data(sensor[count]); -// printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", -// count, reading[count].voltage, reading[count].current, reading[count].power); -// } + } + } printf("\n"); - -// sensorV = config_sensor("/dev/i2c-1", 0x40, 400); -// readingV = read_sensor_data(sensorV); - printf("+X | sensor[%d] % 4.2fV % 6.1fmA \n", -// PLUS_X, readingV.voltage, readingV.current, readingV.power); - PLUS_X, voltage[map[PLUS_X]], current[map[PLUS_X]]); -/* -// sensorV = config_sensor("/dev/i2c-1", 0x41, 400); -// readingV = read_sensor_data(sensorV); - printf("+Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", -// PLUS_Y, readingV.voltage, readingV.current, readingV.power); - PLUS_Y, reading[PLUS_Y].voltage, reading[PLUS_Y].current, reading[PLUS_Y].power); + printf("+X | % 4.2fV % 6.1fmA \n", voltage[map[PLUS_X]], current[map[PLUS_X]]); + + printf("+Y | % 4.2fV % 6.1fmA \n", voltage[map[PLUS_Y]], current[map[PLUS_Y]]); //sensorV = config_sensor("/dev/i2c-0", 0x40, 400); //readingV = read_sensor_data(sensorV); - printf("+Z | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", -// PLUS_Z, readingV.voltage, readingV.current, readingV.power); - PLUS_Z, reading[PLUS_Z].voltage, reading[PLUS_Z].current, reading[PLUS_Z].power); + printf("+Z | % 4.2fV % 6.1fmA \n", voltage[map[PLUS_Z]], current[map[PLUS_Z]]); // sensorV = config_sensor("/dev/i2c-0", 0x41, 400); // readingV = read_sensor_data(sensorV); - printf("-X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", -// MINUS_X, readingV.voltage, readingV.current, readingV.power); - MINUS_X, reading[MINUS_X].voltage, reading[MINUS_X].current, reading[MINUS_X].power); + printf("-X | % 4.2fV % 6.1fmA \n", voltage[map[MINUS_X]], current[map[MINUS_X]]); // sensorV = config_sensor("/dev/i2c-0", 0x44, 400); // readingV = read_sensor_data(sensorV); - printf("-Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", -// MINUS_Y, readingV.voltage, readingV.current, readingV.power); - MINUS_Y, reading[MINUS_Y].voltage, reading[MINUS_Y].current, reading[MINUS_Y].power); + printf("-Y | % 4.2fV % 6.1fmA \n", voltage[map[[MINUS_Y]], current[map[MINUS_Y]]); //sensorV = config_sensor("/dev/i2c-0", 0x45, 400); // readingV = read_sensor_data(sensorV); - printf("-Z | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", -// MINUS_Z, readingV.voltage, readingV.current, readingV.power); - MINUS_Z, reading[MINUS_Z].voltage, reading[MINUS_Z].current, reading[MINUS_Z].power); + printf("-Z | % 4.2fV % 6.1fmA \n", voltage[map[MINUS_Z]], current[map[MINUS_Z]]); // sensorV = config_sensor("/dev/i2c-1", 0x45, 400); // readingV = read_sensor_data(sensorV); - printf("Bat | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", -// BAT, readingV.voltage, readingV.current, readingV.power); - BAT, reading[BAT].voltage, reading[BAT].current, reading[BAT].power); + printf("Bat | % 4.2fV % 6.1fmA \n", voltage[map[BAT]], current[map[BAT]]); // sensorV = config_sensor("/dev/i2c-1", 0x44, 400); // readingV = read_sensor_data(sensorV); - printf("Bus | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", -// BUS, readingV.voltage, readingV.current, readingV.power); - BUS, reading[BUS].voltage, reading[BUS].current, reading[BUS].power); + printf("Bus | % 4.2fV % 6.1fmA \n", voltage[map[BUS]], current[map[BUS]]); */ printf("\n\n"); return 0; } - -int twosToInt(int val,int len) { // Convert twos compliment to integer -// from https://www.raspberrypi.org/forums/viewtopic.php?t=55815 - - if(val & (1 << (len - 1))) - val = val - (1 << len); - - return(val); -} From c9311b149948cc0145ac899fb3ff6acb38d30abd Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 11:52:55 -0400 Subject: [PATCH 121/150] Update telem.c --- afsk/telem.c | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index ec123dd6..d39bbc18 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -168,35 +168,14 @@ int main(int argc, char *argv[]) { } printf("\n"); - printf("+X | % 4.2fV % 6.1fmA \n", voltage[map[PLUS_X]], current[map[PLUS_X]]); - - printf("+Y | % 4.2fV % 6.1fmA \n", voltage[map[PLUS_Y]], current[map[PLUS_Y]]); - - //sensorV = config_sensor("/dev/i2c-0", 0x40, 400); - //readingV = read_sensor_data(sensorV); - printf("+Z | % 4.2fV % 6.1fmA \n", voltage[map[PLUS_Z]], current[map[PLUS_Z]]); - -// sensorV = config_sensor("/dev/i2c-0", 0x41, 400); -// readingV = read_sensor_data(sensorV); - printf("-X | % 4.2fV % 6.1fmA \n", voltage[map[MINUS_X]], current[map[MINUS_X]]); - -// sensorV = config_sensor("/dev/i2c-0", 0x44, 400); -// readingV = read_sensor_data(sensorV); - printf("-Y | % 4.2fV % 6.1fmA \n", voltage[map[[MINUS_Y]], current[map[MINUS_Y]]); - -//sensorV = config_sensor("/dev/i2c-0", 0x45, 400); -// readingV = read_sensor_data(sensorV); - printf("-Z | % 4.2fV % 6.1fmA \n", voltage[map[MINUS_Z]], current[map[MINUS_Z]]); - -// sensorV = config_sensor("/dev/i2c-1", 0x45, 400); -// readingV = read_sensor_data(sensorV); - printf("Bat | % 4.2fV % 6.1fmA \n", voltage[map[BAT]], current[map[BAT]]); - - // sensorV = config_sensor("/dev/i2c-1", 0x44, 400); - // readingV = read_sensor_data(sensorV); - printf("Bus | % 4.2fV % 6.1fmA \n", voltage[map[BUS]], current[map[BUS]]); -*/ - printf("\n\n"); + printf("+X | % 4.2fV % 6.0fmA \n", voltage[map[PLUS_X]], current[map[PLUS_X]]); + printf("+Y | % 4.2fV % 6.0fmA \n", voltage[map[PLUS_Y]], current[map[PLUS_Y]]); + printf("+Z | % 4.2fV % 6.0fmA \n", voltage[map[PLUS_Z]], current[map[PLUS_Z]]); + printf("-X | % 4.2fV % 6.0fmA \n", voltage[map[MINUS_X]], current[map[MINUS_X]]); + printf("-Y | % 4.2fV % 6.0fmA \n", voltage[map[MINUS_Y]], current[map[MINUS_Y]]); + printf("-Z | % 4.2fV % 6.0fmA \n", voltage[map[MINUS_Z]], current[map[MINUS_Z]]); + printf("Bat | % 4.2fV % 6.0fmA \n", voltage[map[BAT]], current[map[BAT]]); + printf("Bus | % 4.2fV % 6.0fmA \n\n", voltage[map[BUS]], current[map[BUS]]); return 0; } From 8579fe62160048bf9b539a0f9ae22e3a14231466 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 11:54:23 -0400 Subject: [PATCH 122/150] updated to use python voltcurrent.py --- afsk/telem.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index d39bbc18..9fc45515 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -168,14 +168,14 @@ int main(int argc, char *argv[]) { } printf("\n"); - printf("+X | % 4.2fV % 6.0fmA \n", voltage[map[PLUS_X]], current[map[PLUS_X]]); - printf("+Y | % 4.2fV % 6.0fmA \n", voltage[map[PLUS_Y]], current[map[PLUS_Y]]); - printf("+Z | % 4.2fV % 6.0fmA \n", voltage[map[PLUS_Z]], current[map[PLUS_Z]]); - printf("-X | % 4.2fV % 6.0fmA \n", voltage[map[MINUS_X]], current[map[MINUS_X]]); - printf("-Y | % 4.2fV % 6.0fmA \n", voltage[map[MINUS_Y]], current[map[MINUS_Y]]); - printf("-Z | % 4.2fV % 6.0fmA \n", voltage[map[MINUS_Z]], current[map[MINUS_Z]]); - printf("Bat | % 4.2fV % 6.0fmA \n", voltage[map[BAT]], current[map[BAT]]); - printf("Bus | % 4.2fV % 6.0fmA \n\n", voltage[map[BUS]], current[map[BUS]]); + printf("+X | % 4.2fV % 5.0fmA \n", voltage[map[PLUS_X]], current[map[PLUS_X]]); + printf("+Y | % 4.2fV % 5.0fmA \n", voltage[map[PLUS_Y]], current[map[PLUS_Y]]); + printf("+Z | % 4.2fV % 5.0fmA \n", voltage[map[PLUS_Z]], current[map[PLUS_Z]]); + printf("-X | % 4.2fV % 5.0fmA \n", voltage[map[MINUS_X]], current[map[MINUS_X]]); + printf("-Y | % 4.2fV % 5.0fmA \n", voltage[map[MINUS_Y]], current[map[MINUS_Y]]); + printf("-Z | % 4.2fV % 5.0fmA \n", voltage[map[MINUS_Z]], current[map[MINUS_Z]]); + printf("Bat | % 4.2fV % 5.0fmA \n", voltage[map[BAT]], current[map[BAT]]); + printf("Bus | % 4.2fV % 5.0fmA \n\n", voltage[map[BUS]], current[map[BUS]]); return 0; } From c0337aa11ba69ee43198a68b90d39d5bc93d3026 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 11:56:44 -0400 Subject: [PATCH 123/150] Update telem.c --- afsk/telem.c | 57 ++++++++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 37 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 9fc45515..fa5922b6 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -1,39 +1,22 @@ /* - * Generates telemetry for CubeSat Simulator + * Displays voltage and current sensors for CubeSatSim * - * Copyright Alan B. Johnston - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * INA219 Raspberry Pi wiringPi code is based on Adafruit Arduino wire code - * from https://github.com/adafruit/Adafruit_INA219. */ -#include +//#include #include #include -#include +//#include #include -#include "status.h" -#include "ax5043.h" -#include "ax25.h" -#include "spi/ax5043spi.h" -#include -#include -#include -#include -#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino +//#include "status.h" +//#include "ax5043.h" +//#include "ax25.h" +//#include "spi/ax5043spi.h" +//#include +//#include +//#include +//#include +//#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino #define A 1 #define B 2 @@ -168,14 +151,14 @@ int main(int argc, char *argv[]) { } printf("\n"); - printf("+X | % 4.2fV % 5.0fmA \n", voltage[map[PLUS_X]], current[map[PLUS_X]]); - printf("+Y | % 4.2fV % 5.0fmA \n", voltage[map[PLUS_Y]], current[map[PLUS_Y]]); - printf("+Z | % 4.2fV % 5.0fmA \n", voltage[map[PLUS_Z]], current[map[PLUS_Z]]); - printf("-X | % 4.2fV % 5.0fmA \n", voltage[map[MINUS_X]], current[map[MINUS_X]]); - printf("-Y | % 4.2fV % 5.0fmA \n", voltage[map[MINUS_Y]], current[map[MINUS_Y]]); - printf("-Z | % 4.2fV % 5.0fmA \n", voltage[map[MINUS_Z]], current[map[MINUS_Z]]); - printf("Bat | % 4.2fV % 5.0fmA \n", voltage[map[BAT]], current[map[BAT]]); - printf("Bus | % 4.2fV % 5.0fmA \n\n", voltage[map[BUS]], current[map[BUS]]); + printf("+X | % 4.2f V % 5.0f mA \n", voltage[map[PLUS_X]], current[map[PLUS_X]]); + printf("+Y | % 4.2f V % 5.0f mA \n", voltage[map[PLUS_Y]], current[map[PLUS_Y]]); + printf("+Z | % 4.2f V % 5.0f mA \n", voltage[map[PLUS_Z]], current[map[PLUS_Z]]); + printf("-X | % 4.2f V % 5.0f mA \n", voltage[map[MINUS_X]], current[map[MINUS_X]]); + printf("-Y | % 4.2f V % 5.0f mA \n", voltage[map[MINUS_Y]], current[map[MINUS_Y]]); + printf("-Z | % 4.2f V % 5.0f mA \n", voltage[map[MINUS_Z]], current[map[MINUS_Z]]); + printf("Bat | % 4.2f V % 5.0f mA \n", voltage[map[BAT]], current[map[BAT]]); + printf("Bus | % 4.2f V % 5.0f mA \n\n", voltage[map[BUS]], current[map[BUS]]); return 0; } From d6c3cfab599562dbf53d23092f8ed1bb97e2fb5b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 11:57:37 -0400 Subject: [PATCH 124/150] Update telem.c --- afsk/telem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index fa5922b6..5da92888 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -8,7 +8,7 @@ #include //#include #include -//#include "status.h" +#include "status.h" //#include "ax5043.h" //#include "ax25.h" //#include "spi/ax5043spi.h" From 9b5fc5619cb9ed2d19136a64f4af1a86bfb96a1e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 11:58:08 -0400 Subject: [PATCH 125/150] Update telem.c --- afsk/telem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 5da92888..dbb6e283 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -3,12 +3,12 @@ * */ -//#include +#include #include #include -//#include +#include #include -#include "status.h" +//#include "status.h" //#include "ax5043.h" //#include "ax25.h" //#include "spi/ax5043spi.h" From 53b4f870a4701ba3017ee8f01a111edf8470f68a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 11:58:39 -0400 Subject: [PATCH 126/150] Update telem.c --- afsk/telem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index dbb6e283..1f95830b 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -12,8 +12,8 @@ //#include "ax5043.h" //#include "ax25.h" //#include "spi/ax5043spi.h" -//#include -//#include +#include +#include //#include //#include //#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino From 5ee28dbbb177b296837ef0c7562f5d1001fd14bd Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 12:01:07 -0400 Subject: [PATCH 127/150] fixed -0 display --- afsk/telem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/afsk/telem.c b/afsk/telem.c index 1f95830b..34367402 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -142,6 +142,8 @@ int main(int argc, char *argv[]) { if (token != NULL) { current[count1] = atof(token); + if ((current[count1] < 0) && (current[count1] > -1)) + current[count1] *= (-1.0); // #ifdef DEBUG_LOGGING // printf("current: %f\n", current[count1]); // #endif From af3c8b1bd0e5001c4fd33eefeb04fc2e489ded93 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 12:02:17 -0400 Subject: [PATCH 128/150] cleanup --- afsk/telem.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 34367402..42ef098a 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -8,20 +8,8 @@ #include #include #include -//#include "status.h" -//#include "ax5043.h" -//#include "ax25.h" -//#include "spi/ax5043spi.h" #include #include -//#include -//#include -//#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino - -#define A 1 -#define B 2 -#define C 3 -#define D 4 #define PLUS_X 0 #define PLUS_Y 1 From a13e3cbceb06d27518dd55a90be362d18e0fbcbc Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 12:10:37 -0400 Subject: [PATCH 129/150] cleanup --- afsk/main.c | 72 ++++++++++++++++------------------------------------- 1 file changed, 22 insertions(+), 50 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 5c55cc0e..5880c38e 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1,5 +1,5 @@ /* - * Transmits CubeSat Telemetry at 434.9MHz in AO-7 format + * Transmits CubeSat Telemetry at 434.9MHz in AFSK, FSK, or BPSK format * * Copyright Alan B. Johnston * @@ -17,9 +17,6 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * INA219 Raspberry Pi wiringPi code is based on Adafruit Arduino wire code - * from https://github.com/adafruit/Adafruit_INA219. */ #include @@ -111,11 +108,6 @@ int nrd; void write_to_buffer(int i, int symbol, int val); void write_wave(int i, short int *buffer); -//#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (8 + 6 * DATA_LEN + 96)) * SAMPLES) -//#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (HEADER_LEN + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN))) * SAMPLES) -//short int buffer[BUF_LEN]; -//short int data10[HEADER_LEN + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN)]; -//short int data8[HEADER_LEN + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN)]; int reset_count; float uptime_sec; long int uptime; @@ -287,7 +279,7 @@ int main(int argc, char *argv[]) { onLedOff = LOW; transmit = TRUE; } - } + } } } pinMode (txLed, OUTPUT); @@ -301,9 +293,6 @@ int main(int argc, char *argv[]) { printf("Power LED On\n"); #endif -// if ((cycle == ON) && !ax5043) // don't cycle modes if using AX5043 -// mode = (reset_count) % 3; // alternate between the three modes - config_file = fopen("sim.cfg","w"); fprintf(config_file, "%s %d", call, reset_count); fclose(config_file); @@ -334,7 +323,7 @@ else batteryThreshold = 8.0; } - strcpy(pythonStr, pythonCmd); + strcpy(pythonStr, pythonCmd); strcat(pythonStr, busStr); strcat(pythonConfigStr, pythonStr); strcat(pythonConfigStr, " c"); @@ -399,7 +388,6 @@ else while (loop-- != 0) { frames_sent++; -// float batteryVoltage = read_sensor_data(sensor[BAT]).voltage; #ifdef DEBUG_LOGGING fprintf(stderr,"INFO: Battery voltage: %f V Battery Threshold %f V\n", batteryVoltage, batteryThreshold); @@ -568,11 +556,10 @@ for (int j = 0; j < frameCnt; j++) char *token; char cmdbuffer[1000]; -// FILE *file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); - FILE* file = popen(pythonStr, "r"); - fgets(cmdbuffer, 1000, file); -// printf("result: %s\n", cmdbuffer); - pclose(file); + FILE* file = popen(pythonStr, "r"); + fgets(cmdbuffer, 1000, file); +// printf("result: %s\n", cmdbuffer); + pclose(file); const char space[2] = " "; token = strtok(cmdbuffer, space); @@ -593,12 +580,14 @@ for (int j = 0; j < frameCnt; j++) if (token != NULL) { current[count1] = atof(token); + if ((current[count1] < 0) && (current[count1] > -0.5)) + current[count1] *= (-1.0); #ifdef DEBUG_LOGGING printf("current: %f\n", current[count1]); #endif token = strtok(NULL, space); } - } + } } tlm[1][A] = (int)(voltage[map[BUS]] /15.0 + 0.5) % 100; // Current of 5V supply to Pi @@ -697,23 +686,12 @@ for (int j = 0; j < frameCnt; j++) #ifdef DEBUG_LOGGING printf("Tx LED On\n"); #endif -//printf("Before cmd\n"); -//printf("CW telem String: %s\n", cw_str2); -// FILE* f; - if (mode == CW) + if (mode == CW) system(cw_str2); -// printf("File %d \n", f); -// printf("close: %d \n", pclose(f)); // execute command and wait for termination before continuing -//printf("After command\n"); -// sleep(7); -//printf("Before Write\n"); digitalWrite (txLed, txLedOn); #ifdef DEBUG_LOGGING printf("Tx LED On\n"); #endif -//printf("After Write\n"); -//} -//printf("Done CW!\n"); if (ax5043) { @@ -770,24 +748,18 @@ for (int j = 0; j < frameCnt; j++) printf("Tx LED On\n"); #endif } - - //digitalWrite (txLed, txLedOff); - } +} -//printf("End of get_tlm and rpitx =========================================================\n"); - - digitalWrite (txLed, txLedOff); - #ifdef DEBUG_LOGGING - printf("Tx LED Off\n"); - #endif +digitalWrite (txLed, txLedOff); +#ifdef DEBUG_LOGGING +printf("Tx LED Off\n"); +#endif return; } int get_tlm_fox() { - -// memset(b, 0, 64); // Reading I2C voltage and current sensors @@ -867,11 +839,10 @@ if (firstTime != ON) char *token; char cmdbuffer[1000]; -// FILE *file = popen("python3 /home/pi/CubeSatSim/python/voltcurrent.py 1 11", "r"); - FILE* file = popen(pythonStr, "r"); - fgets(cmdbuffer, 1000, file); -// printf("result: %s\n", cmdbuffer); - pclose(file); + FILE* file = popen(pythonStr, "r"); + fgets(cmdbuffer, 1000, file); +// printf("result: %s\n", cmdbuffer); + pclose(file); const char space[2] = " "; token = strtok(cmdbuffer, space); @@ -892,7 +863,8 @@ if (firstTime != ON) if (token != NULL) { current[count1] = atof(token); - #ifdef DEBUG_LOGGING + if ((current[count1] < 0) && (current[count1] > -0.5)) + current[count1] *= (-1.0); #ifdef DEBUG_LOGGING printf("current: %f\n", current[count1]); #endif token = strtok(NULL, space); From a416c3c7cdba6589406b04a903d5677e9541b94b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 12:12:29 -0400 Subject: [PATCH 130/150] Delete main.c.bk --- afsk/main.c.bk | 92 -------------------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 afsk/main.c.bk diff --git a/afsk/main.c.bk b/afsk/main.c.bk deleted file mode 100644 index a85269dc..00000000 --- a/afsk/main.c.bk +++ /dev/null @@ -1,92 +0,0 @@ -/* - * A sample application transmitting AFSK at 1200 baud - * - * Portions Copyright (C) 2018 Jonathan Brandenburg - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include "status.h" -#include "ax5043.h" -#include "ax25.h" -#include "spi/ax5043spi.h" - -ax5043_conf_t hax5043; -ax25_conf_t hax25; - -static void init_rf(); -void config_x25(); -void trans_x25(); - -int main(void) { - setSpiChannel(SPI_CHANNEL); - setSpiSpeed(SPI_SPEED); - initializeSpi(); - - int ret; - uint8_t data[1024]; - // 0x03 is a UI frame - // 0x0F is no Level 3 protocol - const char *str = "\x03\x0fThis is an AX.25 Packet from CubeSatSim!!!"; - - /* Infinite loop */ - for (;;) { - sleep(2); - - // send X.25 packet - - init_rf(); - - ax25_init(&hax25, (uint8_t *) "CQ", '2', (uint8_t *) "DX", '2', - AX25_PREAMBLE_LEN, - AX25_POSTAMBLE_LEN); - - - printf("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(); - if (ret) { - fprintf(stderr, - "ERROR: Failed to transmit entire AX.25 frame with error code %d\n", - ret); - exit(EXIT_FAILURE); - } - - } - - return 0; -} - -static void init_rf() { - int ret; - 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); - } -} - From 959acb6975be10b192c8de48235f056dd915f0e8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 12:12:38 -0400 Subject: [PATCH 131/150] Delete main2.c --- afsk/main2.c | 1137 -------------------------------------------------- 1 file changed, 1137 deletions(-) delete mode 100644 afsk/main2.c diff --git a/afsk/main2.c b/afsk/main2.c deleted file mode 100644 index 96083285..00000000 --- a/afsk/main2.c +++ /dev/null @@ -1,1137 +0,0 @@ -/* - * Transmits CubeSat Telemetry at 434.9MHz in AO-7 format - * - * Copyright Alan B. Johnston - * - * Portions Copyright (C) 2018 Jonathan Brandenburg - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * INA219 Raspberry Pi wiringPi code is based on Adafruit Arduino wire code - * from https://github.com/adafruit/Adafruit_INA219. - */ - -#include -#include -#include -#include -#include -#include "status.h" -#include "ax5043.h" -#include "ax25.h" -#include "spi/ax5043spi.h" -#include -#include -#include -#include -#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino -#include "make_wav.h" - -#define A 1 -#define B 2 -#define C 3 -#define D 4 - -#define PLUS_X 0 -#define PLUS_Y 1 -#define PLUS_Z 2 -#define BAT 3 -#define MINUS_X 4 -#define MINUS_Y 5 -#define MINUS_Z 6 -#define BUS 7 -#define OFF -1 - -uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET; -uint32_t tx_channel = 0; - -ax5043_conf_t hax5043; -ax25_conf_t hax25; - -static void init_rf(); -int twosToInt(int val, int len); -int get_tlm(char *str); -int get_tlm_fox(); -int encodeA(short int *b, int index, int val); -int encodeB(short int *b, int index, int val); -void config_x25(); -void trans_x25(); -int upper_digit(int number); -int lower_digit(int number); - -#define S_RATE (48000) // (44100) -#define BUF_SIZE (S_RATE*10) /* 2 second buffer */ - -// BPSK Settings -#define BIT_RATE 1200 // 200 for DUV -#define DUV 0 // 1 for DUV -#define RS_FRAMES 3 // 3 frames for BPSK, 1 for DUV -#define PAYLOADS 6 // 1 for DUV -#define DATA_LEN 78 // 56 for DUV -#define RS_FRAME_LEN 159 // 64 for DUV -#define SYNC_BITS 31 // 10 for DUV -#define SYNC_WORD 0b1000111110011010010000101011101 // 0b0011111010 for DUV -#define HEADER_LEN 8 // 6 for DUV -/* -// DUV Settings -#define BIT_RATE 200 -#define DUV 1 -#define RS_FRAMES 1 -#define PAYLOADS 1 -#define RS_FRAME_LEN 64 -#define HEADER_LEN 6 -#define DATA_LEN 58 -#define SYNC_BITS 10 -#define SYNC_WORD 0b0011111010 -*/ - -#define PARITY_LEN 32 - -float amplitude = 32767/3; // 20000; // 32767/(10%amp+5%amp+100%amp) -float freq_Hz = 3000; // 1200 - -int smaller; -int flip_ctr = 0; -int phase = 1; -int ctr = 0; -void write_to_buffer(int i, int symbol, int val); -void write_wave(); -#define SAMPLES (S_RATE / BIT_RATE) -#define FRAME_CNT 33 // Add 3 frames to the count - -//#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (8 + 6 * DATA_LEN + 96)) * SAMPLES) -#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (HEADER_LEN + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN))) * SAMPLES) -short int buffer[BUF_LEN]; -short int data10[8 + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN)]; -short int data8[8 + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN)]; -int reset_count; -float uptime_sec; -long int uptime; -char call[5]; - -struct SensorConfig { - int fd; - uint16_t config; - int calValue; - int powerMultiplier; - int currentDivider; -}; - -struct SensorData { - double current; - double voltage; - double power; -}; - -/** - * @brief Read the data from one of the i2c current sensors. - * - * Reads the current data from the requested i2c current sensor configuration and - * stores it into a SensorData struct. An invalid file descriptor (i.e. less than zero) - * results in a SensorData struct being returned that has both its #current and #power members - * set to NAN. - * - * @param sensor A structure containing sensor configuration including the file descriptor. - * @return struct SensorData A struct that contains the current, voltage, and power readings - * from the requested sensor. - */ -struct SensorData read_sensor_data(struct SensorConfig sensor) { - struct SensorData data = { - .current = NAN, - .voltage = NAN, - .power = NAN }; - - if (sensor.fd < 0) { - return data; - } - // doesn't read negative currents accurately, shows -0.1mA - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - int value = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - data.current = (float) twosToInt(value, 16) / (float) sensor.currentDivider; - - wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); - delay(1); // Max 12-bit conversion time is 586us per sample - value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); - data.voltage = ((float)(value >> 3) * 4) / 1000; - // power has very low resolution, seems to step in 512mW values - data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; - - return data; -} - -/** - * @brief Configures an i2c current sensor. - * - * Calculates the configuration values of the i2c sensor so that - * current, voltage, and power can be read using read_sensor_data. - * Supports 16V 400mA and 16V 2.0A settings. - * - * @param sensor A file descriptor that can be used to read from the sensor. - * @param milliAmps The mA configuration, either 400mA or 2A are supported. - * @return struct SensorConfig A struct that contains the configuraton of the sensor. - */ -//struct SensorConfig config_sensor(int sensor, int milliAmps) { -struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { - struct SensorConfig data; - - if (access(bus, W_OK | R_OK) < 0) { // Test if I2C Bus is missing - printf("ERROR: %s bus not present \n", bus); - data.fd = OFF; - return (data); - } - - data.fd = wiringPiI2CSetupInterface(bus, address); - - data.config = INA219_CONFIG_BVOLTAGERANGE_32V | - INA219_CONFIG_GAIN_1_40MV | - INA219_CONFIG_BADCRES_12BIT | - INA219_CONFIG_SADCRES_12BIT_1S_532US | - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; - - if (milliAmps == 400) { // INA219 16V 400mA configuration - data.calValue = 8192; - data.powerMultiplier = 1; - data.currentDivider = 20; // 40; in Adafruit config - } - else { // INA219 16V 2A configuration - data.calValue = 40960; - data.powerMultiplier = 2; - data.currentDivider = 10; // 20; in Adafruit config - } - - #ifdef DEBUG_LOGGING - printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd, - data.config, data.calValue, data.currentDivider, data.powerMultiplier); - #endif - return data; -} - -struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorConfig tempSensor; - -char src_addr[5] = ""; -char dest_addr[5] = "CQ"; - -int main(int argc, char *argv[]) { - - if (argc > 1) { - strcpy(src_addr, argv[1]); - } - - wiringPiSetup (); - pinMode (0, OUTPUT); - - //setSpiChannel(SPI_CHANNEL); - //setSpiSpeed(SPI_SPEED); - //initializeSpi(); - - FILE* config_file = fopen("sim.cfg","r"); - if (config_file == NULL) - { - printf("Creating config file."); - config_file = fopen("sim.cfg","w"); - fprintf(config_file, "%s %d", "KU2Y", 100); - fclose(config_file); - config_file = fopen("sim.cfg","r"); - } - - char* cfg_buf[100]; - fscanf(config_file, "%s %d", call, &reset_count); - fclose(config_file); - printf("%s %d\n", call, reset_count); - - reset_count = (reset_count + 1) % 0xffff; - - config_file = fopen("sim.cfg","w"); - fprintf(config_file, "%s %d", call, reset_count); - fclose(config_file); - config_file = fopen("sim.cfg","r"); - - tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); - - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); - sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); - - int ret; - uint8_t data[1024]; - - tx_freq_hz -= tx_channel * 50000; - - //init_rf(); - - ax25_init(&hax25, (uint8_t *) dest_addr, '1', (uint8_t *) src_addr, '1', - AX25_PREAMBLE_LEN, - AX25_POSTAMBLE_LEN); - - /* Infinite loop */ - //for (;;) - - { - // sleep(1); // Delay 1 second - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Getting TLM Data\n"); - #endif - - char str[1000]; - // uint8_t b[64]; - char header_str[] = "\x03\xf0"; - strcpy(str, header_str); - - printf("%s-1>%s-1:", (uint8_t *)src_addr, (uint8_t *)dest_addr); - -// get_tlm(str); - get_tlm_fox(); - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Getting ready to send\n"); - #endif - - char cmdbuffer[1000]; - FILE* transmit; - if (DUV == 1) { - transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/CubeSatSim/rpitx/rpitx -i- -m RF -f 434.9e3 2>&1", "r"); - } else { - transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/CubeSatSim/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.9e6 -t float 2>&1", "r"); - } - fgets(cmdbuffer, 1000, transmit); - pclose(transmit); - printf("Results of transmit command: %s\n", cmdbuffer); - - - -// printf("%s \n", b); -/* - digitalWrite (0, LOW); - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Transmitting X.25 packet\n"); - #endif - 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); - - if (ret) { - fprintf(stderr, - "ERROR: Failed to transmit entire AX.25 frame with error code %d\n", - ret); - exit(EXIT_FAILURE); - } -*/ - } - - return 0; -} - -static void init_rf() { - int ret; - #ifdef DEBUG_LOGGING - fprintf(stderr,"Initializing AX5043\n"); - #endif - 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 -// -int lower_digit(int number) { - - int digit = 0; - if (number < 100) - digit = number - ((int)(number/10) * 10); - else - fprintf(stderr,"ERROR: Not a digit in lower_digit!\n"); - return digit; -} - -// Returns upper digit of a number which must be less than 99 -// -int upper_digit(int number) { - - int digit = 0; - if (number < 100) - digit = (int)(number/10); - else - fprintf(stderr,"ERROR: Not a digit in upper_digit!\n"); - return digit; -} - -int get_tlm(char *str) { - - int tlm[7][5]; - memset(tlm, 0, sizeof tlm); - -// Reading I2C voltage and current sensors - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - count, reading[count].voltage, reading[count].current, reading[count].power); - #endif - } - - tlm[1][A] = (int)(reading[BUS].voltage /15.0 + 0.5) % 100; // Current of 5V supply to Pi - tlm[1][B] = (int) (99.5 - reading[PLUS_X].current/10.0) % 100; // +X current [4] - tlm[1][C] = (int) (99.5 - reading[MINUS_X].current/10.0) % 100; // X- current [10] - tlm[1][D] = (int) (99.5 - reading[PLUS_Y].current/10.0) % 100; // +Y current [7] - - tlm[2][A] = (int) (99.5 - reading[MINUS_Y].current/10.0) % 100; // -Y current [10] - tlm[2][B] = (int) (99.5 - reading[PLUS_Z].current/10.0) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel - tlm[2][C] = (int) (99.5 - reading[MINUS_Z].current/10.0) % 100; // -Z current (was timestamp) - tlm[2][D] = (int)(50.5 + reading[BAT].current/10.0) % 100; // NiMH Battery current - - tlm[3][A] = abs((int)((reading[BAT].voltage * 10.0) - 65.5) % 100); - tlm[3][B] = (int)(reading[BUS].voltage * 10.0) % 100; // 5V supply to Pi - - if (tempSensor.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); - uint8_t lower = (uint8_t) (tempValue & 0xff); - float temp = (float)lower + ((float)upper / 0x100); - - #ifdef DEBUG_LOGGING - printf("Temp Sensor Read: %6.1f\n", temp); - #endif - - tlm[4][A] = (int)((95.8 - temp)/1.48 + 0.5) % 100; - } - - FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); - if (cpuTempSensor) { - double cpuTemp; - fscanf (cpuTempSensor, "%lf", &cpuTemp); - cpuTemp /= 1000; - - #ifdef DEBUG_LOGGING - printf("CPU Temp Read: %6.1f\n", cpuTemp); - #endif - - tlm[4][B] = (int)((95.8 - cpuTemp)/1.48 + 0.5) % 100; - fclose (cpuTempSensor); - } - - tlm[6][B] = 0 ; - tlm[6][D] = 49 + rand() % 3; - - #ifdef DEBUG_LOGGING -// Display tlm - int k, j; - for (k = 1; k < 7; k++) { - for (j = 1; j < 5; j++) { - printf(" %2d ", tlm[k][j]); - } - printf("\n"); - } - #endif - - char tlm_str[1000]; - - char header_str[] = "hi hi "; - strcpy(str, header_str); -// printf("%s-1>%s-1:hi hi ", (uint8_t *)src_addr, (uint8_t *)dest_addr); - - int channel; - for (channel = 1; channel < 7; channel++) { - 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",tlm_str); - strcat(str, tlm_str); - } -// printf("\n"); - -return; -} - -int get_tlm_fox() { - -// memset(b, 0, 64); - -// Reading I2C voltage and current sensors -/* - FILE* uptime_file = fopen("/proc/uptime", "r"); - fscanf(uptime_file, "%f", &uptime_sec); - uptime = (int) uptime_sec; - printf("Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime); - fclose(uptime_file); -*/ - int i; - long int sync = SYNC_WORD; - - smaller = S_RATE/(2 * freq_Hz); -/* - short int b[DATA_LEN] = {0x00,0x7E,0x03, - 0x00,0x00,0x00,0x00,0xE6,0x01,0x00,0x27,0xD1,0x02, - 0xE5,0x40,0x04,0x18,0xE1,0x04,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - - short int h[HEADER_LEN] = {0x05,0x00,0x00,0x00,0x00,0x10,0x00,0x00}; -*/ - - short int b[DATA_LEN * PAYLOADS]; // for each payload -// memset(b, 0, sizeof(b)); - - short int h[HEADER_LEN]; -// memset(h, 0, sizeof(h)); - - short int b10[DATA_LEN], h10[HEADER_LEN]; - short int rs_frame[RS_FRAMES][223]; - unsigned char parities[RS_FRAMES][PARITY_LEN],inputByte; -/* - int id = 5, frm_type = 0x01, TxTemp = 0, IHUcpuTemp = 0; - int batt_a_v = 0, batt_b_v = 0, batt_c_v = 8.95 * 100, battCurr = 48.6 * 10; - int posXv = 296, negXv = 45, posYv = 220, negYv = 68, - posZv = 280, negZv = 78; -*/ - int id = 5, frm_type = 0x01, TxTemp = 0, IHUcpuTemp = 0; - int batt_a_v = 0, batt_b_v = 0, batt_c_v = 0, battCurr = 0; - int posXv = 0, negXv = 0, posYv = 0, negYv = 0, - posZv = 0, negZv = 0; - int head_offset = 0; - - for (int frames = 0; frames < FRAME_CNT; frames++) - { - memset(rs_frame,0,sizeof(rs_frame)); - memset(parities,0,sizeof(parities)); - - FILE *uptime_file = fopen("/proc/uptime", "r"); - fscanf(uptime_file, "%f", &uptime_sec); - uptime = (int) uptime_sec; - fclose(uptime_file); - printf("Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime); - - h[0] = (h[0] & 0xf8) | (id & 0x07); // 3 bits - printf("h[0] %x\n", h[0]); - h[0] = (h[0] & 0x07)| ((reset_count & 0x1f) << 3); - printf("h[0] %x\n", h[0]); - h[1] = (reset_count >> 5) & 0xff; - printf("h[1] %x\n", h[1]); - h[2] = (h[2] & 0xf8) | ((reset_count >> 13) & 0x07); - printf("h[2] %x\n", h[2]); - h[2] = (h[2] & 0x0e) | ((uptime & 0x1f) << 3); - printf("h[2] %x\n", h[2]); - h[3] = (uptime >> 5) & 0xff; - h[4] = (uptime >> 13) & 0xff; - h[5] = (h[5] & 0xf0) | ((uptime >> 21) & 0x0f); - h[5] = (h[5] & 0x0f) | (frm_type << 4); - - - -/* batt_c_v += 10; - battCurr -= 10; - encodeA(b, 3 + head_offset, batt_c_v); - encodeA(b, 9 + head_offset, battCurr); -*/ - - int ctr1 = 0; - int ctr3 = 0; - for (i = 0; i < RS_FRAME_LEN; i++) - { - for (int j = 0; j < RS_FRAMES ; j++) - { - - if ((ctr3 % DATA_LEN) == 0) - { - // sleep - // clear b and h - // get uptime and encode in h - // read telem data and encode in b - sleep(1); - - memset(b, 0, sizeof(b)); - memset(h, 0, sizeof(h)); - - FILE *uptime_file = fopen("/proc/uptime", "r"); - fscanf(uptime_file, "%f", &uptime_sec); - uptime = (int) uptime_sec; - fclose(uptime_file); - printf("Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime); - - h[0] = (h[0] & 0xf8) | (id & 0x07); // 3 bits - printf("h[0] %x\n", h[0]); - h[0] = (h[0] & 0x07)| ((reset_count & 0x1f) << 3); - printf("h[0] %x\n", h[0]); - h[1] = (reset_count >> 5) & 0xff; - printf("h[1] %x\n", h[1]); - h[2] = (h[2] & 0xf8) | ((reset_count >> 13) & 0x07); - printf("h[2] %x\n", h[2]); - h[2] = (h[2] & 0x0e) | ((uptime & 0x1f) << 3); - printf("h[2] %x\n", h[2]); - h[3] = (uptime >> 5) & 0xff; - h[4] = (uptime >> 13) & 0xff; - h[5] = (h[5] & 0xf0) | ((uptime >> 21) & 0x0f); - h[5] = (h[5] & 0x0f) | (frm_type << 4); - - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - count, reading[count].voltage, reading[count].current, reading[count].power); - #endif - } -/* - if (tempSensor.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); - uint8_t lower = (uint8_t) (tempValue & 0xff); - float temp = (float)lower + ((float)upper / 0x100); - - #ifdef DEBUG_LOGGING - printf("Temp Sensor Read: %6.1f\n", temp); - #endif - - TxTemp = (int)((temp * 10.0) + 0.5); - encodeB(b, 34 + head_offset, TxTemp); - } -*/ - FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); - if (cpuTempSensor) { - double cpuTemp; - fscanf (cpuTempSensor, "%lf", &cpuTemp); - cpuTemp /= 1000; - - #ifdef DEBUG_LOGGING - printf("CPU Temp Read: %6.1f\n", cpuTemp); - #endif - - IHUcpuTemp = (int)((cpuTemp * 10.0) + 0.5); - encodeA(b, 39 + head_offset, IHUcpuTemp); - } -// sleep(1); - - posXv = reading[PLUS_X].current * 10; - posYv = reading[PLUS_Y].current * 10; - posZv = reading[PLUS_Z].current * 10; - negXv = reading[MINUS_X].current * 10; - negYv = reading[MINUS_Y].current * 10; - negZv = reading[MINUS_Z].current * 10; - - batt_c_v = reading[BAT].voltage * 100; - battCurr = reading[BAT].current * 10; - - encodeA(b, 0 + head_offset, batt_a_v); - encodeB(b, 1 + head_offset, batt_b_v); - encodeA(b, 3 + head_offset, batt_c_v); - encodeA(b, 9 + head_offset, battCurr); - encodeA(b, 12 + head_offset,posXv); - encodeB(b, 13 + head_offset,posYv); - encodeA(b, 15 + head_offset,posZv); - encodeB(b, 16 + head_offset,negXv); - encodeA(b, 18 + head_offset,negYv); - encodeB(b, 19 + head_offset,negZv); - } - - if (!((i == (RS_FRAME_LEN - 1)) && (j == 2))) // skip last one for BPSK - { - if (ctr1 < HEADER_LEN) - { - rs_frame[j][i] = h[ctr1]; - update_rs(parities[j], h[ctr1]); - // printf("header %d rs_frame[%d][%d] = %x \n", ctr1, j, i, h[ctr1]); - data8[ctr1++] = rs_frame[j][i]; - // printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]); - } - else - { - rs_frame[j][i] = b[ctr3 % DATA_LEN]; - update_rs(parities[j], b[ctr3 % DATA_LEN]); - // printf("%d rs_frame[%d][%d] = %x %d \n", - // ctr1, j, i, b[ctr3 % DATA_LEN], ctr3 % DATA_LEN); - data8[ctr1++] = rs_frame[j][i]; - // printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]); - ctr3++; - } - } - } - } - - printf("Parities "); - for (int m = 0; m < PARITY_LEN; m++) { - printf("%d ", parities[0][m]); - } - printf("\n"); - - int ctr2 = 0; - memset(data10,0,sizeof(data10)); - int rd = 0; - int nrd; - - for (i = 0; i < DATA_LEN * PAYLOADS + HEADER_LEN; i++) // 476 for BPSK - { - data10[ctr2] = (Encode_8b10b[rd][((int)data8[ctr2])] & 0x3ff); - nrd = (Encode_8b10b[rd][((int)data8[ctr2])] >> 10) & 1; - // printf ("data10[%d] = encoded data8[%d] = %x \n", - // ctr2, ctr2, data10[ctr2]); - - rd = nrd; // ^ nrd; - ctr2++; - } - - for (i = 0; i < PARITY_LEN; i++) - { - for (int j = 0; j < RS_FRAMES; j++) - { - data10[ctr2++] = (Encode_8b10b[rd][((int)parities[j][i])] & 0x3ff); - nrd = (Encode_8b10b[rd][((int)parities[j][i])] >> 10) & 1; - // printf ("data10[%d] = encoded parities[%d][%d] = %x \n", - // ctr2 - 1, j, i, data10[ctr2 - 1]); - - rd = nrd; - } - } - - int data; - int val; - int offset = 0; - - for (i = 1; i <= SYNC_BITS * SAMPLES; i++) - { - write_wave(ctr); - if ( (i % SAMPLES) == 0) { - int bit = SYNC_BITS - i/SAMPLES + 1; - val = sync; - data = val & 1 << (bit - 1); - // printf ("%d i: %d new frame %d sync bit %d = %d \n", - // ctr/SAMPLES, i, frames, bit, (data > 0) ); - if (DUV) - { - phase = ((data != 0) * 2) - 1; - // printf("Sending a %d\n", phase); - } - else - { - if (data == 0) { - phase *= -1; - if ( (ctr - smaller) > 0) - { - for (int j = 1; j <= smaller; j++) - buffer[ctr - j] = buffer[ctr - j] * 0.4; - } - flip_ctr = ctr; - } - } - } - } - - for (i = 1; - i <= (10 * (HEADER_LEN + DATA_LEN * PAYLOADS + RS_FRAMES * PARITY_LEN) * SAMPLES); i++) // 572 - { - write_wave(ctr); - if ( (i % SAMPLES) == 0) { - int symbol = (int)((i - 1)/ (SAMPLES * 10)); - int bit = 10 - (i - symbol * SAMPLES * 10) / SAMPLES + 1; - val = data10[symbol]; - data = val & 1 << (bit - 1); - // printf ("%d i: %d new frame %d data10[%d] = %x bit %d = %d \n", - // ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) ); - if (DUV) - { - phase = ((data != 0) * 2) - 1; - // printf("Sending a %d\n", phase); - } - else - { - if (data == 0) { - phase *= -1; - if ( (ctr - smaller) > 0) - { - for (int j = 1; j <= smaller; j ++) - buffer[ctr - j] = buffer[ctr - j] * 0.4; - } - flip_ctr = ctr; - } - } - } - } - } - write_wav("transmit.wav", BUF_LEN, buffer, S_RATE); - - int count; - for (count = 0; count < DATA_LEN; count++) { - printf("%02X", b[count]); - } - printf("\n"); - -return 0; -} - -// wav file generation code - -/* make_wav.c - * Creates a WAV file from an array of ints. - * Output is monophonic, signed 16-bit samples - * copyright - * Fri Jun 18 16:36:23 PDT 2010 Kevin Karplus - * Creative Commons license Attribution-NonCommercial - * http://creativecommons.org/licenses/by-nc/3.0/ - * - * Edited by Dolin Sergey. dlinyj@gmail.com - * April 11 12:58 2014 - */ - - // gcc -o make_enc_wav make_enc_wav.c -lm - // ./make_enc_wav - - /* - * TelemEncoding.h - * - * Created on: Feb 3, 2014 - * Author: fox - */ - -#include -#include -#include -#include -#include -#include - -//#include "make_wav.h" - -#define false 0 -#define true 1 - -//static int twosToInt(int val,int len); -//static int encodeB(short int *b, int index, int val); -//static int encodeA(short int *b, int index, int val); - - static int NOT_FRAME = /* 0fa */ 0xfa & 0x3ff; - static int FRAME = /* 0fa */ ~0xfa & 0x3ff; - -/* - * TelemEncoding.c - * - Fox-1 telemetry encoder - January 2014 Phil Karn KA9Q - - This file has two external functions: - void update_rs(unsigned char parity[32],unsigned char data); - int encode_8b10b(int *state,int data). - - update_rs() is the Reed-Solomon encoder. Its first argument is the 32-byte - encoder shift register, the second is the 8-bit data byte being encoded. It updates - the shift register in place and returns void. At the end of each frame, it contains - the parities ready for transmission, starting with parity[0]. - Be sure to zero this array before each new frame! - - encode_8b10b() is the 8b10b encoder. Its first argument is a pointer to a single integer - with the 1-bit encoder state (the current run disparity, or RD). Initialize it to 0 - JUST ONCE at startup (not between frames). - The second argument is the data byte being encoded. It updates the state and returns - an integer containing the 10-bit encoded word, right justified. - Transmit this word from left to right. - - The data argument is an int so it can hold the special value -1 to indicate end of frame; - it generates the 8b10b control word K.28.5, which is used as an inter-frame flag. - - Some assert() calls are made to verify legality of arguments. These can be turned off in - production code. - - - sample frame transmission code: - - unsigned char data[64]; // Data block to be sent - unsigned char parity[32]; // RS parities - void transmit_word(int); // User provided transmit function: 10 bits of data in bits 9....0 - int state,i; - - state = 0; // Only once at startup, not between frames - memset(parity,0,sizeof(parity); // Do this before every frame - // Transmit the data, updating the RS encoder - for(i=0;i<64;i++){ - update_rs(parity,data[i]); - transmit_word(encode_8b10b(&state,data[i]); - } - // Transmit the RS parities - for(i=0;i<32;i++) - transmit_word(encode_8b10b(&state,parity[i]); - - transmit_word(encode_8b10b(&state,-1); // Transmit end-of-frame flag -*/ - - -#include -//#include "Fox.h" -//#include "TelemEncoding.h" - -#ifndef NULL -#define NULL ((void *)0) -#endif - -#define NN (0xff) // Frame size in symbols -#define A0 (NN) // special value for log(0) - - -// GF Antilog lookup table table -static unsigned char CCSDS_alpha_to[NN+1] = { -0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x87,0x89,0x95,0xad,0xdd,0x3d,0x7a,0xf4, -0x6f,0xde,0x3b,0x76,0xec,0x5f,0xbe,0xfb,0x71,0xe2,0x43,0x86,0x8b,0x91,0xa5,0xcd, -0x1d,0x3a,0x74,0xe8,0x57,0xae,0xdb,0x31,0x62,0xc4,0x0f,0x1e,0x3c,0x78,0xf0,0x67, -0xce,0x1b,0x36,0x6c,0xd8,0x37,0x6e,0xdc,0x3f,0x7e,0xfc,0x7f,0xfe,0x7b,0xf6,0x6b, -0xd6,0x2b,0x56,0xac,0xdf,0x39,0x72,0xe4,0x4f,0x9e,0xbb,0xf1,0x65,0xca,0x13,0x26, -0x4c,0x98,0xb7,0xe9,0x55,0xaa,0xd3,0x21,0x42,0x84,0x8f,0x99,0xb5,0xed,0x5d,0xba, -0xf3,0x61,0xc2,0x03,0x06,0x0c,0x18,0x30,0x60,0xc0,0x07,0x0e,0x1c,0x38,0x70,0xe0, -0x47,0x8e,0x9b,0xb1,0xe5,0x4d,0x9a,0xb3,0xe1,0x45,0x8a,0x93,0xa1,0xc5,0x0d,0x1a, -0x34,0x68,0xd0,0x27,0x4e,0x9c,0xbf,0xf9,0x75,0xea,0x53,0xa6,0xcb,0x11,0x22,0x44, -0x88,0x97,0xa9,0xd5,0x2d,0x5a,0xb4,0xef,0x59,0xb2,0xe3,0x41,0x82,0x83,0x81,0x85, -0x8d,0x9d,0xbd,0xfd,0x7d,0xfa,0x73,0xe6,0x4b,0x96,0xab,0xd1,0x25,0x4a,0x94,0xaf, -0xd9,0x35,0x6a,0xd4,0x2f,0x5e,0xbc,0xff,0x79,0xf2,0x63,0xc6,0x0b,0x16,0x2c,0x58, -0xb0,0xe7,0x49,0x92,0xa3,0xc1,0x05,0x0a,0x14,0x28,0x50,0xa0,0xc7,0x09,0x12,0x24, -0x48,0x90,0xa7,0xc9,0x15,0x2a,0x54,0xa8,0xd7,0x29,0x52,0xa4,0xcf,0x19,0x32,0x64, -0xc8,0x17,0x2e,0x5c,0xb8,0xf7,0x69,0xd2,0x23,0x46,0x8c,0x9f,0xb9,0xf5,0x6d,0xda, -0x33,0x66,0xcc,0x1f,0x3e,0x7c,0xf8,0x77,0xee,0x5b,0xb6,0xeb,0x51,0xa2,0xc3,0x00, -}; - -// GF log lookup table. Special value represents log(0) -static unsigned char CCSDS_index_of[NN+1] = { - A0, 0, 1, 99, 2,198,100,106, 3,205,199,188,101,126,107, 42, - 4,141,206, 78,200,212,189,225,102,221,127, 49,108, 32, 43,243, - 5, 87,142,232,207,172, 79,131,201,217,213, 65,190,148,226,180, -103, 39,222,240,128,177, 50, 53,109, 69, 33, 18, 44, 13,244, 56, - 6,155, 88, 26,143,121,233,112,208,194,173,168, 80,117,132, 72, -202,252,218,138,214, 84, 66, 36,191,152,149,249,227, 94,181, 21, -104, 97, 40,186,223, 76,241, 47,129,230,178, 63, 51,238, 54, 16, -110, 24, 70,166, 34,136, 19,247, 45,184, 14, 61,245,164, 57, 59, - 7,158,156,157, 89,159, 27, 8,144, 9,122, 28,234,160,113, 90, -209, 29,195,123,174, 10,169,145, 81, 91,118,114,133,161, 73,235, -203,124,253,196,219, 30,139,210,215,146, 85,170, 67, 11, 37,175, -192,115,153,119,150, 92,250, 82,228,236, 95, 74,182,162, 22,134, -105,197, 98,254, 41,125,187,204,224,211, 77,140,242, 31, 48,220, -130,171,231, 86,179,147, 64,216, 52,176,239, 38, 55, 12, 17, 68, -111,120, 25,154, 71,116,167,193, 35, 83,137,251, 20, 93,248,151, - 46, 75,185, 96, 15,237, 62,229,246,135,165, 23, 58,163, 60,183, -}; - -// Only half the coefficients are given here because the -// generator polynomial is palindromic; G0 = G32, G1 = G31, etc. -// Only G16 is unique -static unsigned char CCSDS_poly[] = { - 0,249, 59, 66, 4, 43,126,251, 97, 30, 3,213, 50, 66,170, 5, - 24, -}; - - -static inline int modnn(int x){ - while (x >= NN) { - x -= NN; - x = (x >> 8) + (x & NN); - } - return x; -} - - -// Update Reed-Solomon encoder -// parity -> 32-byte reed-solomon encoder state; clear this to zero before each frame -void update_rs( - unsigned char parity[32], // 32-byte encoder state; zero before each frame - unsigned char c) // Current data byte to update -{ - unsigned char feedback; - int j,t; - - assert(parity != NULL); - feedback = CCSDS_index_of[c ^ parity[0]]; - if(feedback != A0){ // only if feedback is non-zero - // Take advantage of palindromic polynomial to halve the multiplies - // Do G1...G15, which is the same as G17...G31 - for(j=1;j0) - { buf = word & 0xff; - fwrite(&buf, 1,1, wav_file); - num_bytes--; - word >>= 8; - } -} - -/* information about the WAV file format from - -http://ccrma.stanford.edu/courses/422/projects/WaveFormat/ - - */ - -void write_wav(char * filename, unsigned long num_samples, short int * data, int s_rate) -{ - FILE* wav_file; - unsigned int sample_rate; - unsigned int num_channels; - unsigned int bytes_per_sample; - unsigned int byte_rate; - unsigned long i; /* counter for samples */ - - num_channels = 1; /* monoaural */ - bytes_per_sample = 2; - - if (s_rate<=0) sample_rate = 44100; - else sample_rate = (unsigned int) s_rate; - - byte_rate = sample_rate*num_channels*bytes_per_sample; - - wav_file = fopen(filename, "w"); - assert(wav_file); /* make sure it opened */ - - /* write RIFF header */ - fwrite("RIFF", 1, 4, wav_file); - write_little_endian(36 + bytes_per_sample* num_samples*num_channels, 4, wav_file); - fwrite("WAVE", 1, 4, wav_file); - - /* write fmt subchunk */ - fwrite("fmt ", 1, 4, wav_file); - write_little_endian(16, 4, wav_file); /* SubChunk1Size is 16 */ - write_little_endian(1, 2, wav_file); /* PCM is format 1 */ - write_little_endian(num_channels, 2, wav_file); - write_little_endian(sample_rate, 4, wav_file); - write_little_endian(byte_rate, 4, wav_file); - write_little_endian(num_channels*bytes_per_sample, 2, wav_file); /* block align */ - write_little_endian(8*bytes_per_sample, 2, wav_file); /* bits/sample */ - - /* write data subchunk */ - fwrite("data", 1, 4, wav_file); - write_little_endian(bytes_per_sample* num_samples*num_channels, 4, wav_file); - - for (i=0; i< num_samples; i++) - { write_little_endian((unsigned int)(data[i]),bytes_per_sample, wav_file); - } - - fclose(wav_file); -} - - - -//int main(int argc, char * argv[]) -//{ - -// return 0; -//} - -void write_wave(int i) -{ - if (DUV) - { -// if ((ctr - flip_ctr) < smaller) -// buffer[ctr++] = 0.1 * phase * (ctr - flip_ctr) / smaller; -// else - buffer[ctr++] = 0.25 * amplitude * phase; - } - else - { - if ((ctr - flip_ctr) < smaller) - buffer[ctr++] = (int)(amplitude * 0.4 * phase * - sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - else - buffer[ctr++] = (int)(amplitude * phase * - sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - } -// printf("%d %d \n", i, buffer[ctr - 1]); - -} - -/** - * - * FOX 1 Telemetry Decoder - * @author chris.e.thompson g0kla/ac2cz - * - * Copyright (C) 2015 amsat.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General License for more details. - * - * You should have received a copy of the GNU General License - * along with this program. If not, see . - * - * - * Static variables and methods to encode and decode 8b10b - * - * - */ - -int encodeA(short int *b, int index, int val) { -// printf("Encoding A\n"); - b[index] = val & 0xff; - b[index + 1] = (b[index + 1] & 0xf0) | ((val >> 8) & 0x0f); - return 0; -} - -int encodeB(short int *b, int index, int val) { -// printf("Encoding B\n"); - b[index] = (b[index] & 0x0f) | ((val << 4) & 0xf0); - b[index + 1] = (val >> 4 ) & 0xff; - return 0; -} - -int twosToInt(int val,int len) { // Convert twos compliment to integer -// from https://www.raspberrypi.org/forums/viewtopic.php?t=55815 - - if(val & (1 << (len - 1))) - val = val - (1 << len); - - return(val); -} From aa3ee9244e7974d86b8f18b9e133a9c0bc29c9d4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 12:12:47 -0400 Subject: [PATCH 132/150] Delete main3.c --- afsk/main3.c | 1126 -------------------------------------------------- 1 file changed, 1126 deletions(-) delete mode 100644 afsk/main3.c diff --git a/afsk/main3.c b/afsk/main3.c deleted file mode 100644 index 5e344633..00000000 --- a/afsk/main3.c +++ /dev/null @@ -1,1126 +0,0 @@ -/* - * Transmits CubeSat Telemetry at 434.9MHz in AO-7 format - * - * Copyright Alan B. Johnston - * - * Portions Copyright (C) 2018 Jonathan Brandenburg - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * INA219 Raspberry Pi wiringPi code is based on Adafruit Arduino wire code - * from https://github.com/adafruit/Adafruit_INA219. - */ - -#include -#include -#include -#include -#include -#include "status.h" -#include "ax5043.h" -#include "ax25.h" -#include "spi/ax5043spi.h" -#include -#include -#include -#include -#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino -#include "make_wav.h" - -#define A 1 -#define B 2 -#define C 3 -#define D 4 - -#define PLUS_X 0 -#define PLUS_Y 1 -#define PLUS_Z 2 -#define BAT 3 -#define MINUS_X 4 -#define MINUS_Y 5 -#define MINUS_Z 6 -#define BUS 7 -#define OFF -1 - -uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET; -uint32_t tx_channel = 0; - -ax5043_conf_t hax5043; -ax25_conf_t hax25; - -static void init_rf(); -int twosToInt(int val, int len); -int get_tlm(char *str); -int get_tlm_fox(); -int encodeA(short int *b, int index, int val); -int encodeB(short int *b, int index, int val); -void config_x25(); -void trans_x25(); -int upper_digit(int number); -int lower_digit(int number); - -#define S_RATE (48000) // (44100) -#define BUF_SIZE (S_RATE*10) /* 2 second buffer */ - -// BPSK Settings -#define BIT_RATE 1200 // 200 for DUV -#define DUV 0 // 1 for DUV -#define RS_FRAMES 3 // 3 frames for BPSK, 1 for DUV -#define PAYLOADS 6 // 1 for DUV -#define DATA_LEN 78 // 56 for DUV -#define RS_FRAME_LEN 159 // 64 for DUV -#define SYNC_BITS 31 // 10 for DUV -#define SYNC_WORD 0b1000111110011010010000101011101 // 0b0011111010 for DUV -#define HEADER_LEN 8 // 6 for DUV -/* -// DUV Settings -#define BIT_RATE 200 -#define DUV 1 -#define RS_FRAMES 1 -#define PAYLOADS 1 -#define RS_FRAME_LEN 64 -#define HEADER_LEN 6 -#define DATA_LEN 58 -#define SYNC_BITS 10 -#define SYNC_WORD 0b0011111010 -*/ - -#define PARITY_LEN 32 - -float amplitude = 32767/3; // 20000; // 32767/(10%amp+5%amp+100%amp) -float freq_Hz = 3000; // 1200 - -int smaller; -int flip_ctr = 0; -int phase = 1; -int ctr = 0; -long int ptr = 0; - -void copy_samples(); -void write_to_buffer(int i, int symbol, int val); -void write_wave(); -#define SAMPLES (S_RATE / BIT_RATE) -#define FRAME_CNT 33 // Add 3 frames to the count - -//#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (8 + 6 * DATA_LEN + 96)) * SAMPLES) -#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (HEADER_LEN + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN))) * SAMPLES) -short int buffer[BUF_LEN]; -short int phase0[SAMPLES], phase1[SAMPLES]; -int size_of_phase; -short int data10[8 + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN)]; -short int data8[8 + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN)]; -int reset_count; -float uptime_sec; -long int uptime; -char call[5]; - -struct SensorConfig { - int fd; - uint16_t config; - int calValue; - int powerMultiplier; - int currentDivider; -}; - -struct SensorData { - double current; - double voltage; - double power; -}; - -/** - * @brief Read the data from one of the i2c current sensors. - * - * Reads the current data from the requested i2c current sensor configuration and - * stores it into a SensorData struct. An invalid file descriptor (i.e. less than zero) - * results in a SensorData struct being returned that has both its #current and #power members - * set to NAN. - * - * @param sensor A structure containing sensor configuration including the file descriptor. - * @return struct SensorData A struct that contains the current, voltage, and power readings - * from the requested sensor. - */ -struct SensorData read_sensor_data(struct SensorConfig sensor) { - struct SensorData data = { - .current = NAN, - .voltage = NAN, - .power = NAN }; - - if (sensor.fd < 0) { - return data; - } - // doesn't read negative currents accurately, shows -0.1mA - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - int value = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - data.current = (float) twosToInt(value, 16) / (float) sensor.currentDivider; - - wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); - delay(1); // Max 12-bit conversion time is 586us per sample - value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); - data.voltage = ((float)(value >> 3) * 4) / 1000; - // power has very low resolution, seems to step in 512mW values - data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; - - return data; -} - -/** - * @brief Configures an i2c current sensor. - * - * Calculates the configuration values of the i2c sensor so that - * current, voltage, and power can be read using read_sensor_data. - * Supports 16V 400mA and 16V 2.0A settings. - * - * @param sensor A file descriptor that can be used to read from the sensor. - * @param milliAmps The mA configuration, either 400mA or 2A are supported. - * @return struct SensorConfig A struct that contains the configuraton of the sensor. - */ -//struct SensorConfig config_sensor(int sensor, int milliAmps) { -struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { - struct SensorConfig data; - - if (access(bus, W_OK | R_OK) < 0) { // Test if I2C Bus is missing - printf("ERROR: %s bus not present \n", bus); - data.fd = OFF; - return (data); - } - - data.fd = wiringPiI2CSetupInterface(bus, address); - - data.config = INA219_CONFIG_BVOLTAGERANGE_32V | - INA219_CONFIG_GAIN_1_40MV | - INA219_CONFIG_BADCRES_12BIT | - INA219_CONFIG_SADCRES_12BIT_1S_532US | - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; - - if (milliAmps == 400) { // INA219 16V 400mA configuration - data.calValue = 8192; - data.powerMultiplier = 1; - data.currentDivider = 20; // 40; in Adafruit config - } - else { // INA219 16V 2A configuration - data.calValue = 40960; - data.powerMultiplier = 2; - data.currentDivider = 10; // 20; in Adafruit config - } - - #ifdef DEBUG_LOGGING - printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd, - data.config, data.calValue, data.currentDivider, data.powerMultiplier); - #endif - return data; -} - -struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorConfig tempSensor; - -char src_addr[5] = ""; -char dest_addr[5] = "CQ"; - -int main(int argc, char *argv[]) { - - if (argc > 1) { - strcpy(src_addr, argv[1]); - } - - wiringPiSetup (); - pinMode (0, OUTPUT); - - //setSpiChannel(SPI_CHANNEL); - //setSpiSpeed(SPI_SPEED); - //initializeSpi(); - - FILE* config_file = fopen("sim.cfg","r"); - if (config_file == NULL) - { - printf("Creating config file."); - config_file = fopen("sim.cfg","w"); - fprintf(config_file, "%s %d", "KU2Y", 100); - fclose(config_file); - config_file = fopen("sim.cfg","r"); - } - - char* cfg_buf[100]; - fscanf(config_file, "%s %d", call, &reset_count); - fclose(config_file); - printf("%s %d\n", call, reset_count); - - reset_count = (reset_count + 1) % 0xffff; - - config_file = fopen("sim.cfg","w"); - fprintf(config_file, "%s %d", call, reset_count); - fclose(config_file); - config_file = fopen("sim.cfg","r"); - - tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); - - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); - sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); - - int ret; - uint8_t data[1024]; - - tx_freq_hz -= tx_channel * 50000; - - //init_rf(); - - ax25_init(&hax25, (uint8_t *) dest_addr, '1', (uint8_t *) src_addr, '1', - AX25_PREAMBLE_LEN, - AX25_POSTAMBLE_LEN); - - /* Infinite loop */ - //for (;;) - - { - // sleep(1); // Delay 1 second - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Getting TLM Data\n"); - #endif - - char str[1000]; - // uint8_t b[64]; - char header_str[] = "\x03\xf0"; - strcpy(str, header_str); - - printf("%s-1>%s-1:", (uint8_t *)src_addr, (uint8_t *)dest_addr); - -// get_tlm(str); - get_tlm_fox(); - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Getting ready to send\n"); - #endif - - char cmdbuffer[1000]; - FILE* transmit; - if (DUV == 1) { - transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/CubeSatSim/rpitx/rpitx -i- -m RF -f 434.9e3 2>&1", "r"); - } else { - transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/CubeSatSim/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.9e6 -t float 2>&1", "r"); - } - fgets(cmdbuffer, 1000, transmit); - pclose(transmit); - printf("Results of transmit command: %s\n", cmdbuffer); - - - -// printf("%s \n", b); -/* - digitalWrite (0, LOW); - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Transmitting X.25 packet\n"); - #endif - 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); - - if (ret) { - fprintf(stderr, - "ERROR: Failed to transmit entire AX.25 frame with error code %d\n", - ret); - exit(EXIT_FAILURE); - } -*/ - } - - return 0; -} - -static void init_rf() { - int ret; - #ifdef DEBUG_LOGGING - fprintf(stderr,"Initializing AX5043\n"); - #endif - 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 -// -int lower_digit(int number) { - - int digit = 0; - if (number < 100) - digit = number - ((int)(number/10) * 10); - else - fprintf(stderr,"ERROR: Not a digit in lower_digit!\n"); - return digit; -} - -// Returns upper digit of a number which must be less than 99 -// -int upper_digit(int number) { - - int digit = 0; - if (number < 100) - digit = (int)(number/10); - else - fprintf(stderr,"ERROR: Not a digit in upper_digit!\n"); - return digit; -} - -int get_tlm(char *str) { - - int tlm[7][5]; - memset(tlm, 0, sizeof tlm); - -// Reading I2C voltage and current sensors - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - count, reading[count].voltage, reading[count].current, reading[count].power); - #endif - } - - tlm[1][A] = (int)(reading[BUS].voltage /15.0 + 0.5) % 100; // Current of 5V supply to Pi - tlm[1][B] = (int) (99.5 - reading[PLUS_X].current/10.0) % 100; // +X current [4] - tlm[1][C] = (int) (99.5 - reading[MINUS_X].current/10.0) % 100; // X- current [10] - tlm[1][D] = (int) (99.5 - reading[PLUS_Y].current/10.0) % 100; // +Y current [7] - - tlm[2][A] = (int) (99.5 - reading[MINUS_Y].current/10.0) % 100; // -Y current [10] - tlm[2][B] = (int) (99.5 - reading[PLUS_Z].current/10.0) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel - tlm[2][C] = (int) (99.5 - reading[MINUS_Z].current/10.0) % 100; // -Z current (was timestamp) - tlm[2][D] = (int)(50.5 + reading[BAT].current/10.0) % 100; // NiMH Battery current - - tlm[3][A] = abs((int)((reading[BAT].voltage * 10.0) - 65.5) % 100); - tlm[3][B] = (int)(reading[BUS].voltage * 10.0) % 100; // 5V supply to Pi - - if (tempSensor.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); - uint8_t lower = (uint8_t) (tempValue & 0xff); - float temp = (float)lower + ((float)upper / 0x100); - - #ifdef DEBUG_LOGGING - printf("Temp Sensor Read: %6.1f\n", temp); - #endif - - tlm[4][A] = (int)((95.8 - temp)/1.48 + 0.5) % 100; - } - - FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); - if (cpuTempSensor) { - double cpuTemp; - fscanf (cpuTempSensor, "%lf", &cpuTemp); - cpuTemp /= 1000; - - #ifdef DEBUG_LOGGING - printf("CPU Temp Read: %6.1f\n", cpuTemp); - #endif - - tlm[4][B] = (int)((95.8 - cpuTemp)/1.48 + 0.5) % 100; - fclose (cpuTempSensor); - } - - tlm[6][B] = 0 ; - tlm[6][D] = 49 + rand() % 3; - - #ifdef DEBUG_LOGGING -// Display tlm - int k, j; - for (k = 1; k < 7; k++) { - for (j = 1; j < 5; j++) { - printf(" %2d ", tlm[k][j]); - } - printf("\n"); - } - #endif - - char tlm_str[1000]; - - char header_str[] = "hi hi "; - strcpy(str, header_str); -// printf("%s-1>%s-1:hi hi ", (uint8_t *)src_addr, (uint8_t *)dest_addr); - - int channel; - for (channel = 1; channel < 7; channel++) { - 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",tlm_str); - strcat(str, tlm_str); - } -// printf("\n"); - -return; -} - -int get_tlm_fox() { - -// memset(b, 0, 64); - -// Reading I2C voltage and current sensors - - FILE* uptime_file = fopen("/proc/uptime", "r"); - fscanf(uptime_file, "%f", &uptime_sec); - uptime = (int) uptime_sec; - printf("Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime); - fclose(uptime_file); - - int i; - long int sync = SYNC_WORD; - - smaller = S_RATE/(2 * freq_Hz); -/* - short int b[DATA_LEN] = {0x00,0x7E,0x03, - 0x00,0x00,0x00,0x00,0xE6,0x01,0x00,0x27,0xD1,0x02, - 0xE5,0x40,0x04,0x18,0xE1,0x04,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - - short int h[HEADER_LEN] = {0x05,0x00,0x00,0x00,0x00,0x10,0x00,0x00}; -*/ - - short int b[DATA_LEN]; - memset(b, 0, sizeof(b)); - - short int h[HEADER_LEN]; - memset(h, 0, sizeof(h)); - - short int b10[DATA_LEN], h10[HEADER_LEN]; - short int rs_frame[RS_FRAMES][223]; - unsigned char parities[RS_FRAMES][PARITY_LEN],inputByte; -/* - int id = 5, frm_type = 0x01, TxTemp = 0, IHUcpuTemp = 0; - int batt_a_v = 0, batt_b_v = 0, batt_c_v = 8.95 * 100, battCurr = 48.6 * 10; - int posXv = 296, negXv = 45, posYv = 220, negYv = 68, - posZv = 280, negZv = 78; -*/ - int id = 5, frm_type = 0x01, TxTemp = 0, IHUcpuTemp = 0; - int batt_a_v = 0, batt_b_v = 0, batt_c_v = 0, battCurr = 0; - int posXv = 0, negXv = 0, posYv = 0, negYv = 0, - posZv = 0, negZv = 0; - int head_offset = 0; - - for (int frames = 0; frames < FRAME_CNT; frames++) - { - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - count, reading[count].voltage, reading[count].current, reading[count].power); - #endif - } -/* - if (tempSensor.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); - uint8_t lower = (uint8_t) (tempValue & 0xff); - float temp = (float)lower + ((float)upper / 0x100); - - #ifdef DEBUG_LOGGING - printf("Temp Sensor Read: %6.1f\n", temp); - #endif - - TxTemp = (int)((temp * 10.0) + 0.5); - encodeB(b, 34 + head_offset, TxTemp); - } -*/ - FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); - if (cpuTempSensor) { - double cpuTemp; - fscanf (cpuTempSensor, "%lf", &cpuTemp); - cpuTemp /= 1000; - - #ifdef DEBUG_LOGGING - printf("CPU Temp Read: %6.1f\n", cpuTemp); - #endif - - IHUcpuTemp = (int)((cpuTemp * 10.0) + 0.5); - encodeA(b, 39 + head_offset, IHUcpuTemp); - } - sleep(1); - - memset(rs_frame,0,sizeof(rs_frame)); - memset(parities,0,sizeof(parities)); - - FILE *uptime_file = fopen("/proc/uptime", "r"); - fscanf(uptime_file, "%f", &uptime_sec); - uptime = (int) uptime_sec; - fclose(uptime_file); - printf("Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime); - - h[0] = (h[0] & 0xf8) | (id & 0x07); // 3 bits - printf("h[0] %x\n", h[0]); - h[0] = (h[0] & 0x07)| ((reset_count & 0x1f) << 3); - printf("h[0] %x\n", h[0]); - h[1] = (reset_count >> 5) & 0xff; - printf("h[1] %x\n", h[1]); - h[2] = (h[2] & 0xf8) | ((reset_count >> 13) & 0x07); - printf("h[2] %x\n", h[2]); - h[2] = (h[2] & 0x0e) | ((uptime & 0x1f) << 3); - printf("h[2] %x\n", h[2]); - h[3] = (uptime >> 5) & 0xff; - h[4] = (uptime >> 13) & 0xff; - h[5] = (h[5] & 0xf0) | ((uptime >> 21) & 0x0f); - h[5] = (h[5] & 0x0f) | (frm_type << 4); - - posXv = reading[PLUS_X].current * 10; - posYv = reading[PLUS_Y].current * 10; - posZv = reading[PLUS_Z].current * 10; - negXv = reading[MINUS_X].current * 10; - negYv = reading[MINUS_Y].current * 10; - negZv = reading[MINUS_Z].current * 10; - - batt_c_v = reading[BAT].voltage * 100; - battCurr = reading[BAT].current * 10; - - encodeA(b, 0 + head_offset, batt_a_v); - encodeB(b, 1 + head_offset, batt_b_v); - encodeA(b, 3 + head_offset, batt_c_v); - encodeA(b, 9 + head_offset, battCurr); - encodeA(b, 12 + head_offset,posXv); - encodeB(b, 13 + head_offset,posYv); - encodeA(b, 15 + head_offset,posZv); - encodeB(b, 16 + head_offset,negXv); - encodeA(b, 18 + head_offset,negYv); - encodeB(b, 19 + head_offset,negZv); - -/* batt_c_v += 10; - battCurr -= 10; - encodeA(b, 3 + head_offset, batt_c_v); - encodeA(b, 9 + head_offset, battCurr); -*/ - int ctr1 = 0; - int ctr3 = 0; - for (i = 0; i < RS_FRAME_LEN; i++) - { - for (int j = 0; j < RS_FRAMES ; j++) - { - if (!((i == (RS_FRAME_LEN - 1)) && (j == 2))) // skip last one for BPSK - { - if (ctr1 < HEADER_LEN) - { - rs_frame[j][i] = h[ctr1]; - update_rs(parities[j], h[ctr1]); - // printf("header %d rs_frame[%d][%d] = %x \n", ctr1, j, i, h[ctr1]); - data8[ctr1++] = rs_frame[j][i]; - // printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]); - } - else - { - rs_frame[j][i] = b[ctr3 % DATA_LEN]; - update_rs(parities[j], b[ctr3 % DATA_LEN]); - // printf("%d rs_frame[%d][%d] = %x %d \n", - // ctr1, j, i, b[ctr3 % DATA_LEN], ctr3 % DATA_LEN); - data8[ctr1++] = rs_frame[j][i]; - // printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]); - ctr3++; - } - } - } - } - - printf("Parities "); - for (int m = 0; m < PARITY_LEN; m++) { - printf("%d ", parities[0][m]); - } - printf("\n"); - - int ctr2 = 0; - memset(data10,0,sizeof(data10)); - int rd = 0; - int nrd; - - for (i = 0; i < DATA_LEN * PAYLOADS + HEADER_LEN; i++) // 476 for BPSK - { - data10[ctr2] = (Encode_8b10b[rd][((int)data8[ctr2])] & 0x3ff); - nrd = (Encode_8b10b[rd][((int)data8[ctr2])] >> 10) & 1; - // printf ("data10[%d] = encoded data8[%d] = %x \n", - // ctr2, ctr2, data10[ctr2]); - - rd = nrd; // ^ nrd; - ctr2++; - } - - for (i = 0; i < PARITY_LEN; i++) - { - for (int j = 0; j < RS_FRAMES; j++) - { - data10[ctr2++] = (Encode_8b10b[rd][((int)parities[j][i])] & 0x3ff); - nrd = (Encode_8b10b[rd][((int)parities[j][i])] >> 10) & 1; - // printf ("data10[%d] = encoded parities[%d][%d] = %x \n", - // ctr2 - 1, j, i, data10[ctr2 - 1]); - - rd = nrd; - } - } - - int data; - int val; - int offset = 0; - ptr = 0; - size_of_phase = sizeof(phase0); - - phase = 1; - for (i = 0; i < SAMPLES; i++) - { - write_wave(i, phase1); - } - phase = 0 - for (i = 0; i < SAMPLES; i++) - { - write_wave(i, phase0); - } - - for (i = 1; i <= SYNC_BITS; i++) - { - copy_samples(); - if ( (i % SAMPLES) == 0) { - int bit = SYNC_BITS - i + 1; - val = sync; - data = val & 1 << (bit - 1); - // printf ("%d i: %d new frame %d sync bit %d = %d \n", - // ctr, i, frames, bit, (data > 0) ); - if (DUV) - { - phase = ((data != 0) * 2) - 1; - // printf("Sending a %d\n", phase); - } - else - { - if (data == 0) { - phase *= -1; -// if ( (ctr - smaller) > 0) -// { -// for (int j = 1; j <= smaller; j++) -// buffer[ctr - j] = buffer[ctr - j] * 0.4; -// } -// flip_ctr = ctr; - } - } - } - } - - for (i = 1; - i <= (10 * (HEADER_LEN + DATA_LEN * PAYLOADS + RS_FRAMES * PARITY_LEN) * 1); i++) // 572 - { - copy_samples(); -// if ( (i % SAMPLES) == 0) { - int symbol = (int)((i - 1)/ 10); - int bit = 10 - (i - symbol * 10); - val = data10[symbol]; - data = val & 1 << (bit - 1); - // printf ("%d i: %d new frame %d data10[%d] = %x bit %d = %d \n", - // ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) ); - if (DUV) - { - phase = ((data != 0) * 2) - 1; - // printf("Sending a %d\n", phase); - } - else - { - if (data == 0) { - phase *= -1; -// if ( (ctr - smaller) > 0) -// { -// for (int j = 1; j <= smaller; j ++) -// buffer[ctr - j] = buffer[ctr - j] * 0.4; -// } -// flip_ctr = ctr; - } - } -// } - } - } - write_wav("transmit.wav", BUF_LEN, buffer, S_RATE); - - int count; - for (count = 0; count < DATA_LEN; count++) { - printf("%02X", b[count]); - } - printf("\n"); - -return 0; -} - -// wav file generation code - -/* make_wav.c - * Creates a WAV file from an array of ints. - * Output is monophonic, signed 16-bit samples - * copyright - * Fri Jun 18 16:36:23 PDT 2010 Kevin Karplus - * Creative Commons license Attribution-NonCommercial - * http://creativecommons.org/licenses/by-nc/3.0/ - * - * Edited by Dolin Sergey. dlinyj@gmail.com - * April 11 12:58 2014 - */ - - // gcc -o make_enc_wav make_enc_wav.c -lm - // ./make_enc_wav - - /* - * TelemEncoding.h - * - * Created on: Feb 3, 2014 - * Author: fox - */ - -#include -#include -#include -#include -#include -#include - -//#include "make_wav.h" - -#define false 0 -#define true 1 - -//static int twosToInt(int val,int len); -//static int encodeB(short int *b, int index, int val); -//static int encodeA(short int *b, int index, int val); - - static int NOT_FRAME = /* 0fa */ 0xfa & 0x3ff; - static int FRAME = /* 0fa */ ~0xfa & 0x3ff; - -/* - * TelemEncoding.c - * - Fox-1 telemetry encoder - January 2014 Phil Karn KA9Q - - This file has two external functions: - void update_rs(unsigned char parity[32],unsigned char data); - int encode_8b10b(int *state,int data). - - update_rs() is the Reed-Solomon encoder. Its first argument is the 32-byte - encoder shift register, the second is the 8-bit data byte being encoded. It updates - the shift register in place and returns void. At the end of each frame, it contains - the parities ready for transmission, starting with parity[0]. - Be sure to zero this array before each new frame! - - encode_8b10b() is the 8b10b encoder. Its first argument is a pointer to a single integer - with the 1-bit encoder state (the current run disparity, or RD). Initialize it to 0 - JUST ONCE at startup (not between frames). - The second argument is the data byte being encoded. It updates the state and returns - an integer containing the 10-bit encoded word, right justified. - Transmit this word from left to right. - - The data argument is an int so it can hold the special value -1 to indicate end of frame; - it generates the 8b10b control word K.28.5, which is used as an inter-frame flag. - - Some assert() calls are made to verify legality of arguments. These can be turned off in - production code. - - - sample frame transmission code: - - unsigned char data[64]; // Data block to be sent - unsigned char parity[32]; // RS parities - void transmit_word(int); // User provided transmit function: 10 bits of data in bits 9....0 - int state,i; - - state = 0; // Only once at startup, not between frames - memset(parity,0,sizeof(parity); // Do this before every frame - // Transmit the data, updating the RS encoder - for(i=0;i<64;i++){ - update_rs(parity,data[i]); - transmit_word(encode_8b10b(&state,data[i]); - } - // Transmit the RS parities - for(i=0;i<32;i++) - transmit_word(encode_8b10b(&state,parity[i]); - - transmit_word(encode_8b10b(&state,-1); // Transmit end-of-frame flag -*/ - - -#include -//#include "Fox.h" -//#include "TelemEncoding.h" - -#ifndef NULL -#define NULL ((void *)0) -#endif - -#define NN (0xff) // Frame size in symbols -#define A0 (NN) // special value for log(0) - - -// GF Antilog lookup table table -static unsigned char CCSDS_alpha_to[NN+1] = { -0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x87,0x89,0x95,0xad,0xdd,0x3d,0x7a,0xf4, -0x6f,0xde,0x3b,0x76,0xec,0x5f,0xbe,0xfb,0x71,0xe2,0x43,0x86,0x8b,0x91,0xa5,0xcd, -0x1d,0x3a,0x74,0xe8,0x57,0xae,0xdb,0x31,0x62,0xc4,0x0f,0x1e,0x3c,0x78,0xf0,0x67, -0xce,0x1b,0x36,0x6c,0xd8,0x37,0x6e,0xdc,0x3f,0x7e,0xfc,0x7f,0xfe,0x7b,0xf6,0x6b, -0xd6,0x2b,0x56,0xac,0xdf,0x39,0x72,0xe4,0x4f,0x9e,0xbb,0xf1,0x65,0xca,0x13,0x26, -0x4c,0x98,0xb7,0xe9,0x55,0xaa,0xd3,0x21,0x42,0x84,0x8f,0x99,0xb5,0xed,0x5d,0xba, -0xf3,0x61,0xc2,0x03,0x06,0x0c,0x18,0x30,0x60,0xc0,0x07,0x0e,0x1c,0x38,0x70,0xe0, -0x47,0x8e,0x9b,0xb1,0xe5,0x4d,0x9a,0xb3,0xe1,0x45,0x8a,0x93,0xa1,0xc5,0x0d,0x1a, -0x34,0x68,0xd0,0x27,0x4e,0x9c,0xbf,0xf9,0x75,0xea,0x53,0xa6,0xcb,0x11,0x22,0x44, -0x88,0x97,0xa9,0xd5,0x2d,0x5a,0xb4,0xef,0x59,0xb2,0xe3,0x41,0x82,0x83,0x81,0x85, -0x8d,0x9d,0xbd,0xfd,0x7d,0xfa,0x73,0xe6,0x4b,0x96,0xab,0xd1,0x25,0x4a,0x94,0xaf, -0xd9,0x35,0x6a,0xd4,0x2f,0x5e,0xbc,0xff,0x79,0xf2,0x63,0xc6,0x0b,0x16,0x2c,0x58, -0xb0,0xe7,0x49,0x92,0xa3,0xc1,0x05,0x0a,0x14,0x28,0x50,0xa0,0xc7,0x09,0x12,0x24, -0x48,0x90,0xa7,0xc9,0x15,0x2a,0x54,0xa8,0xd7,0x29,0x52,0xa4,0xcf,0x19,0x32,0x64, -0xc8,0x17,0x2e,0x5c,0xb8,0xf7,0x69,0xd2,0x23,0x46,0x8c,0x9f,0xb9,0xf5,0x6d,0xda, -0x33,0x66,0xcc,0x1f,0x3e,0x7c,0xf8,0x77,0xee,0x5b,0xb6,0xeb,0x51,0xa2,0xc3,0x00, -}; - -// GF log lookup table. Special value represents log(0) -static unsigned char CCSDS_index_of[NN+1] = { - A0, 0, 1, 99, 2,198,100,106, 3,205,199,188,101,126,107, 42, - 4,141,206, 78,200,212,189,225,102,221,127, 49,108, 32, 43,243, - 5, 87,142,232,207,172, 79,131,201,217,213, 65,190,148,226,180, -103, 39,222,240,128,177, 50, 53,109, 69, 33, 18, 44, 13,244, 56, - 6,155, 88, 26,143,121,233,112,208,194,173,168, 80,117,132, 72, -202,252,218,138,214, 84, 66, 36,191,152,149,249,227, 94,181, 21, -104, 97, 40,186,223, 76,241, 47,129,230,178, 63, 51,238, 54, 16, -110, 24, 70,166, 34,136, 19,247, 45,184, 14, 61,245,164, 57, 59, - 7,158,156,157, 89,159, 27, 8,144, 9,122, 28,234,160,113, 90, -209, 29,195,123,174, 10,169,145, 81, 91,118,114,133,161, 73,235, -203,124,253,196,219, 30,139,210,215,146, 85,170, 67, 11, 37,175, -192,115,153,119,150, 92,250, 82,228,236, 95, 74,182,162, 22,134, -105,197, 98,254, 41,125,187,204,224,211, 77,140,242, 31, 48,220, -130,171,231, 86,179,147, 64,216, 52,176,239, 38, 55, 12, 17, 68, -111,120, 25,154, 71,116,167,193, 35, 83,137,251, 20, 93,248,151, - 46, 75,185, 96, 15,237, 62,229,246,135,165, 23, 58,163, 60,183, -}; - -// Only half the coefficients are given here because the -// generator polynomial is palindromic; G0 = G32, G1 = G31, etc. -// Only G16 is unique -static unsigned char CCSDS_poly[] = { - 0,249, 59, 66, 4, 43,126,251, 97, 30, 3,213, 50, 66,170, 5, - 24, -}; - - -static inline int modnn(int x){ - while (x >= NN) { - x -= NN; - x = (x >> 8) + (x & NN); - } - return x; -} - - -// Update Reed-Solomon encoder -// parity -> 32-byte reed-solomon encoder state; clear this to zero before each frame -void update_rs( - unsigned char parity[32], // 32-byte encoder state; zero before each frame - unsigned char c) // Current data byte to update -{ - unsigned char feedback; - int j,t; - - assert(parity != NULL); - feedback = CCSDS_index_of[c ^ parity[0]]; - if(feedback != A0){ // only if feedback is non-zero - // Take advantage of palindromic polynomial to halve the multiplies - // Do G1...G15, which is the same as G17...G31 - for(j=1;j0) - { buf = word & 0xff; - fwrite(&buf, 1,1, wav_file); - num_bytes--; - word >>= 8; - } -} - -/* information about the WAV file format from - -http://ccrma.stanford.edu/courses/422/projects/WaveFormat/ - - */ - -void write_wav(char * filename, unsigned long num_samples, short int * data, int s_rate) -{ - FILE* wav_file; - unsigned int sample_rate; - unsigned int num_channels; - unsigned int bytes_per_sample; - unsigned int byte_rate; - unsigned long i; /* counter for samples */ - - num_channels = 1; /* monoaural */ - bytes_per_sample = 2; - - if (s_rate<=0) sample_rate = 44100; - else sample_rate = (unsigned int) s_rate; - - byte_rate = sample_rate*num_channels*bytes_per_sample; - - wav_file = fopen(filename, "w"); - assert(wav_file); /* make sure it opened */ - - /* write RIFF header */ - fwrite("RIFF", 1, 4, wav_file); - write_little_endian(36 + bytes_per_sample* num_samples*num_channels, 4, wav_file); - fwrite("WAVE", 1, 4, wav_file); - - /* write fmt subchunk */ - fwrite("fmt ", 1, 4, wav_file); - write_little_endian(16, 4, wav_file); /* SubChunk1Size is 16 */ - write_little_endian(1, 2, wav_file); /* PCM is format 1 */ - write_little_endian(num_channels, 2, wav_file); - write_little_endian(sample_rate, 4, wav_file); - write_little_endian(byte_rate, 4, wav_file); - write_little_endian(num_channels*bytes_per_sample, 2, wav_file); /* block align */ - write_little_endian(8*bytes_per_sample, 2, wav_file); /* bits/sample */ - - /* write data subchunk */ - fwrite("data", 1, 4, wav_file); - write_little_endian(bytes_per_sample* num_samples*num_channels, 4, wav_file); - - for (i=0; i< num_samples; i++) - { write_little_endian((unsigned int)(data[i]),bytes_per_sample, wav_file); - } - - fclose(wav_file); -} - - - -//int main(int argc, char * argv[]) -//{ - -// return 0; -//} - -void write_wave(int i, short int *buf) -{ - if (DUV) - { -// if ((ctr - flip_ctr) < smaller) -// buffer[ctr++] = 0.1 * phase * (ctr - flip_ctr) / smaller; -// else - buf[i] = 0.25 * amplitude * phase; - } - else - { -// if ((ctr - flip_ctr) < smaller) - // buffer[ctr++] = (int)(amplitude * 0.4 * phase * - // sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - // else - buf[i] = (int)(amplitude * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - } - printf("%d %d \n", i, buf[i]); -} - -void copy_samples() -{ - if (phase == 0) - memcpy(buffer[ptr], phase0, size_of_phase); - else - memcpy(buffer[ptr], phase1, size_of_phase); - - ptr += size_of_phase; -} - -/** - * - * FOX 1 Telemetry Decoder - * @author chris.e.thompson g0kla/ac2cz - * - * Copyright (C) 2015 amsat.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General License for more details. - * - * You should have received a copy of the GNU General License - * along with this program. If not, see . - * - * - * Static variables and methods to encode and decode 8b10b - * - * - */ - -int encodeA(short int *b, int index, int val) { -// printf("Encoding A\n"); - b[index] = val & 0xff; - b[index + 1] = (b[index + 1] & 0xf0) | ((val >> 8) & 0x0f); - return 0; -} - -int encodeB(short int *b, int index, int val) { -// printf("Encoding B\n"); - b[index] = (b[index] & 0x0f) | ((val << 4) & 0xf0); - b[index + 1] = (val >> 4 ) & 0xff; - return 0; -} - -int twosToInt(int val,int len) { // Convert twos compliment to integer -// from https://www.raspberrypi.org/forums/viewtopic.php?t=55815 - - if(val & (1 << (len - 1))) - val = val - (1 << len); - - return(val); -} From f50e5bfdd203de2d7cd06222b0ca81c7c7a2be6f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 12:12:59 -0400 Subject: [PATCH 133/150] Delete main4.c --- afsk/main4.c | 1100 -------------------------------------------------- 1 file changed, 1100 deletions(-) delete mode 100644 afsk/main4.c diff --git a/afsk/main4.c b/afsk/main4.c deleted file mode 100644 index 9b03fc06..00000000 --- a/afsk/main4.c +++ /dev/null @@ -1,1100 +0,0 @@ -/* - * Transmits CubeSat Telemetry at 434.9MHz in AO-7 format - * - * Copyright Alan B. Johnston - * - * Portions Copyright (C) 2018 Jonathan Brandenburg - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * INA219 Raspberry Pi wiringPi code is based on Adafruit Arduino wire code - * from https://github.com/adafruit/Adafruit_INA219. - */ - -#include -#include -#include -#include -#include -#include "status.h" -#include "ax5043.h" -#include "ax25.h" -#include "spi/ax5043spi.h" -#include -#include -#include -#include -#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino -#include "make_wav.h" - -#define A 1 -#define B 2 -#define C 3 -#define D 4 - -#define PLUS_X 0 -#define PLUS_Y 1 -#define PLUS_Z 2 -#define BAT 3 -#define MINUS_X 4 -#define MINUS_Y 5 -#define MINUS_Z 6 -#define BUS 7 -#define OFF -1 - -uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET; -uint32_t tx_channel = 0; - -ax5043_conf_t hax5043; -ax25_conf_t hax25; - -static void init_rf(); -int twosToInt(int val, int len); -int get_tlm(char *str); -int get_tlm_fox(); -int encodeA(short int *b, int index, int val); -int encodeB(short int *b, int index, int val); -void config_x25(); -void trans_x25(); -int upper_digit(int number); -int lower_digit(int number); - -#define S_RATE (48000) // (44100) -#define BUF_SIZE (S_RATE*10) /* 2 second buffer */ - -// BPSK Settings -#define BIT_RATE 1200 // 200 for DUV -#define DUV 0 // 1 for DUV -#define RS_FRAMES 3 // 3 frames for BPSK, 1 for DUV -#define PAYLOADS 6 // 1 for DUV -#define DATA_LEN 78 // 56 for DUV -#define RS_FRAME_LEN 159 // 64 for DUV -#define SYNC_BITS 31 // 10 for DUV -#define SYNC_WORD 0b1000111110011010010000101011101 // 0b0011111010 for DUV -#define HEADER_LEN 8 // 6 for DUV -/* -// DUV Settings -#define BIT_RATE 200 -#define DUV 1 -#define RS_FRAMES 1 -#define PAYLOADS 1 -#define RS_FRAME_LEN 64 -#define HEADER_LEN 6 -#define DATA_LEN 58 -#define SYNC_BITS 10 -#define SYNC_WORD 0b0011111010 -*/ - -#define PARITY_LEN 32 - -float amplitude = 32767/3; // 20000; // 32767/(10%amp+5%amp+100%amp) -float freq_Hz = 3000; // 1200 - -int smaller; -int flip_ctr = 0; -int phase = 1; -int ctr = 0; -void write_to_buffer(int i, int symbol, int val); -void write_wave(); -#define SAMPLES (S_RATE / BIT_RATE) -#define FRAME_CNT 33 // Add 3 frames to the count - -//#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (8 + 6 * DATA_LEN + 96)) * SAMPLES) -#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (HEADER_LEN + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN))) * SAMPLES) -short int buffer[BUF_LEN]; -short int data10[8 + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN)]; -short int data8[8 + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN)]; -int reset_count; -float uptime_sec; -long int uptime; -char call[5]; - -struct SensorConfig { - int fd; - uint16_t config; - int calValue; - int powerMultiplier; - int currentDivider; -}; - -struct SensorData { - double current; - double voltage; - double power; -}; - -/** - * @brief Read the data from one of the i2c current sensors. - * - * Reads the current data from the requested i2c current sensor configuration and - * stores it into a SensorData struct. An invalid file descriptor (i.e. less than zero) - * results in a SensorData struct being returned that has both its #current and #power members - * set to NAN. - * - * @param sensor A structure containing sensor configuration including the file descriptor. - * @return struct SensorData A struct that contains the current, voltage, and power readings - * from the requested sensor. - */ -struct SensorData read_sensor_data(struct SensorConfig sensor) { - struct SensorData data = { - .current = NAN, - .voltage = NAN, - .power = NAN }; - - if (sensor.fd < 0) { - return data; - } - // doesn't read negative currents accurately, shows -0.1mA - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - int value = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - data.current = (float) twosToInt(value, 16) / (float) sensor.currentDivider; - - wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); - delay(1); // Max 12-bit conversion time is 586us per sample - value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); - data.voltage = ((float)(value >> 3) * 4) / 1000; - // power has very low resolution, seems to step in 512mW values - data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; - - return data; -} - -/** - * @brief Configures an i2c current sensor. - * - * Calculates the configuration values of the i2c sensor so that - * current, voltage, and power can be read using read_sensor_data. - * Supports 16V 400mA and 16V 2.0A settings. - * - * @param sensor A file descriptor that can be used to read from the sensor. - * @param milliAmps The mA configuration, either 400mA or 2A are supported. - * @return struct SensorConfig A struct that contains the configuraton of the sensor. - */ -//struct SensorConfig config_sensor(int sensor, int milliAmps) { -struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { - struct SensorConfig data; - - if (access(bus, W_OK | R_OK) < 0) { // Test if I2C Bus is missing - printf("ERROR: %s bus not present \n", bus); - data.fd = OFF; - return (data); - } - - data.fd = wiringPiI2CSetupInterface(bus, address); - - data.config = INA219_CONFIG_BVOLTAGERANGE_32V | - INA219_CONFIG_GAIN_1_40MV | - INA219_CONFIG_BADCRES_12BIT | - INA219_CONFIG_SADCRES_12BIT_1S_532US | - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; - - if (milliAmps == 400) { // INA219 16V 400mA configuration - data.calValue = 8192; - data.powerMultiplier = 1; - data.currentDivider = 20; // 40; in Adafruit config - } - else { // INA219 16V 2A configuration - data.calValue = 40960; - data.powerMultiplier = 2; - data.currentDivider = 10; // 20; in Adafruit config - } - - #ifdef DEBUG_LOGGING - printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd, - data.config, data.calValue, data.currentDivider, data.powerMultiplier); - #endif - return data; -} - -struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorConfig tempSensor; - -char src_addr[5] = ""; -char dest_addr[5] = "CQ"; - -int main(int argc, char *argv[]) { - - if (argc > 1) { - strcpy(src_addr, argv[1]); - } - - wiringPiSetup (); - pinMode (0, OUTPUT); - - //setSpiChannel(SPI_CHANNEL); - //setSpiSpeed(SPI_SPEED); - //initializeSpi(); - - FILE* config_file = fopen("sim.cfg","r"); - if (config_file == NULL) - { - printf("Creating config file."); - config_file = fopen("sim.cfg","w"); - fprintf(config_file, "%s %d", "KU2Y", 100); - fclose(config_file); - config_file = fopen("sim.cfg","r"); - } - - char* cfg_buf[100]; - fscanf(config_file, "%s %d", call, &reset_count); - fclose(config_file); - printf("%s %d\n", call, reset_count); - - reset_count = (reset_count + 1) % 0xffff; - - config_file = fopen("sim.cfg","w"); - fprintf(config_file, "%s %d", call, reset_count); - fclose(config_file); - config_file = fopen("sim.cfg","r"); - - tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); - - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); - sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); - - int ret; - uint8_t data[1024]; - - tx_freq_hz -= tx_channel * 50000; - - //init_rf(); - - ax25_init(&hax25, (uint8_t *) dest_addr, '1', (uint8_t *) src_addr, '1', - AX25_PREAMBLE_LEN, - AX25_POSTAMBLE_LEN); - - /* Infinite loop */ - //for (;;) - - { - // sleep(1); // Delay 1 second - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Getting TLM Data\n"); - #endif - - char str[1000]; - // uint8_t b[64]; - char header_str[] = "\x03\xf0"; - strcpy(str, header_str); - - printf("%s-1>%s-1:", (uint8_t *)src_addr, (uint8_t *)dest_addr); - -// get_tlm(str); - get_tlm_fox(); - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Getting ready to send\n"); - #endif - - char cmdbuffer[1000]; - FILE* transmit; - if (DUV == 1) { - transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/CubeSatSim/rpitx/rpitx -i- -m RF -f 434.9e3 2>&1", "r"); - } else { - transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/CubeSatSim/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.9e6 -t float 2>&1", "r"); - } - fgets(cmdbuffer, 1000, transmit); - pclose(transmit); - printf("Results of transmit command: %s\n", cmdbuffer); - - - -// printf("%s \n", b); -/* - digitalWrite (0, LOW); - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Transmitting X.25 packet\n"); - #endif - 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); - - if (ret) { - fprintf(stderr, - "ERROR: Failed to transmit entire AX.25 frame with error code %d\n", - ret); - exit(EXIT_FAILURE); - } -*/ - } - - return 0; -} - -static void init_rf() { - int ret; - #ifdef DEBUG_LOGGING - fprintf(stderr,"Initializing AX5043\n"); - #endif - 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 -// -int lower_digit(int number) { - - int digit = 0; - if (number < 100) - digit = number - ((int)(number/10) * 10); - else - fprintf(stderr,"ERROR: Not a digit in lower_digit!\n"); - return digit; -} - -// Returns upper digit of a number which must be less than 99 -// -int upper_digit(int number) { - - int digit = 0; - if (number < 100) - digit = (int)(number/10); - else - fprintf(stderr,"ERROR: Not a digit in upper_digit!\n"); - return digit; -} - -int get_tlm(char *str) { - - int tlm[7][5]; - memset(tlm, 0, sizeof tlm); - -// Reading I2C voltage and current sensors - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - count, reading[count].voltage, reading[count].current, reading[count].power); - #endif - } - - tlm[1][A] = (int)(reading[BUS].voltage /15.0 + 0.5) % 100; // Current of 5V supply to Pi - tlm[1][B] = (int) (99.5 - reading[PLUS_X].current/10.0) % 100; // +X current [4] - tlm[1][C] = (int) (99.5 - reading[MINUS_X].current/10.0) % 100; // X- current [10] - tlm[1][D] = (int) (99.5 - reading[PLUS_Y].current/10.0) % 100; // +Y current [7] - - tlm[2][A] = (int) (99.5 - reading[MINUS_Y].current/10.0) % 100; // -Y current [10] - tlm[2][B] = (int) (99.5 - reading[PLUS_Z].current/10.0) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel - tlm[2][C] = (int) (99.5 - reading[MINUS_Z].current/10.0) % 100; // -Z current (was timestamp) - tlm[2][D] = (int)(50.5 + reading[BAT].current/10.0) % 100; // NiMH Battery current - - tlm[3][A] = abs((int)((reading[BAT].voltage * 10.0) - 65.5) % 100); - tlm[3][B] = (int)(reading[BUS].voltage * 10.0) % 100; // 5V supply to Pi - - if (tempSensor.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); - uint8_t lower = (uint8_t) (tempValue & 0xff); - float temp = (float)lower + ((float)upper / 0x100); - - #ifdef DEBUG_LOGGING - printf("Temp Sensor Read: %6.1f\n", temp); - #endif - - tlm[4][A] = (int)((95.8 - temp)/1.48 + 0.5) % 100; - } - - FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); - if (cpuTempSensor) { - double cpuTemp; - fscanf (cpuTempSensor, "%lf", &cpuTemp); - cpuTemp /= 1000; - - #ifdef DEBUG_LOGGING - printf("CPU Temp Read: %6.1f\n", cpuTemp); - #endif - - tlm[4][B] = (int)((95.8 - cpuTemp)/1.48 + 0.5) % 100; - fclose (cpuTempSensor); - } - - tlm[6][B] = 0 ; - tlm[6][D] = 49 + rand() % 3; - - #ifdef DEBUG_LOGGING -// Display tlm - int k, j; - for (k = 1; k < 7; k++) { - for (j = 1; j < 5; j++) { - printf(" %2d ", tlm[k][j]); - } - printf("\n"); - } - #endif - - char tlm_str[1000]; - - char header_str[] = "hi hi "; - strcpy(str, header_str); -// printf("%s-1>%s-1:hi hi ", (uint8_t *)src_addr, (uint8_t *)dest_addr); - - int channel; - for (channel = 1; channel < 7; channel++) { - 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",tlm_str); - strcat(str, tlm_str); - } -// printf("\n"); - -return; -} - -int get_tlm_fox() { - -// memset(b, 0, 64); - -// Reading I2C voltage and current sensors - - FILE* uptime_file = fopen("/proc/uptime", "r"); - fscanf(uptime_file, "%f", &uptime_sec); - uptime = (int) uptime_sec; - printf("Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime); - fclose(uptime_file); - - int i; - long int sync = SYNC_WORD; - - smaller = S_RATE/(2 * freq_Hz); -/* - short int b[DATA_LEN] = {0x00,0x7E,0x03, - 0x00,0x00,0x00,0x00,0xE6,0x01,0x00,0x27,0xD1,0x02, - 0xE5,0x40,0x04,0x18,0xE1,0x04,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - - short int h[HEADER_LEN] = {0x05,0x00,0x00,0x00,0x00,0x10,0x00,0x00}; -*/ - - short int b[DATA_LEN]; - memset(b, 0, sizeof(b)); - - short int h[HEADER_LEN]; - memset(h, 0, sizeof(h)); - - short int b10[DATA_LEN], h10[HEADER_LEN]; - short int rs_frame[RS_FRAMES][223]; - unsigned char parities[RS_FRAMES][PARITY_LEN],inputByte; -/* - int id = 5, frm_type = 0x01, TxTemp = 0, IHUcpuTemp = 0; - int batt_a_v = 0, batt_b_v = 0, batt_c_v = 8.95 * 100, battCurr = 48.6 * 10; - int posXv = 296, negXv = 45, posYv = 220, negYv = 68, - posZv = 280, negZv = 78; -*/ - int id = 5, frm_type = 0x01, TxTemp = 0, IHUcpuTemp = 0; - int batt_a_v = 0, batt_b_v = 0, batt_c_v = 0, battCurr = 0; - int posXv = 0, negXv = 0, posYv = 0, negYv = 0, - posZv = 0, negZv = 0; - int head_offset = 0; - - for (int frames = 0; frames < FRAME_CNT; frames++) - { - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - count, reading[count].voltage, reading[count].current, reading[count].power); - #endif - } -/* - if (tempSensor.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); - uint8_t lower = (uint8_t) (tempValue & 0xff); - float temp = (float)lower + ((float)upper / 0x100); - - #ifdef DEBUG_LOGGING - printf("Temp Sensor Read: %6.1f\n", temp); - #endif - - TxTemp = (int)((temp * 10.0) + 0.5); - encodeB(b, 34 + head_offset, TxTemp); - } -*/ - FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); - if (cpuTempSensor) { - double cpuTemp; - fscanf (cpuTempSensor, "%lf", &cpuTemp); - cpuTemp /= 1000; - - #ifdef DEBUG_LOGGING - printf("CPU Temp Read: %6.1f\n", cpuTemp); - #endif - - IHUcpuTemp = (int)((cpuTemp * 10.0) + 0.5); - encodeA(b, 39 + head_offset, IHUcpuTemp); - } - sleep(1); - - memset(rs_frame,0,sizeof(rs_frame)); - memset(parities,0,sizeof(parities)); - - FILE *uptime_file = fopen("/proc/uptime", "r"); - fscanf(uptime_file, "%f", &uptime_sec); - uptime = (int) uptime_sec; - fclose(uptime_file); - printf("Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime); - - h[0] = (h[0] & 0xf8) | (id & 0x07); // 3 bits - printf("h[0] %x\n", h[0]); - h[0] = (h[0] & 0x07)| ((reset_count & 0x1f) << 3); - printf("h[0] %x\n", h[0]); - h[1] = (reset_count >> 5) & 0xff; - printf("h[1] %x\n", h[1]); - h[2] = (h[2] & 0xf8) | ((reset_count >> 13) & 0x07); - printf("h[2] %x\n", h[2]); - h[2] = (h[2] & 0x0e) | ((uptime & 0x1f) << 3); - printf("h[2] %x\n", h[2]); - h[3] = (uptime >> 5) & 0xff; - h[4] = (uptime >> 13) & 0xff; - h[5] = (h[5] & 0xf0) | ((uptime >> 21) & 0x0f); - h[5] = (h[5] & 0x0f) | (frm_type << 4); - - posXv = reading[PLUS_X].current * 10; - posYv = reading[PLUS_Y].current * 10; - posZv = reading[PLUS_Z].current * 10; - negXv = reading[MINUS_X].current * 10; - negYv = reading[MINUS_Y].current * 10; - negZv = reading[MINUS_Z].current * 10; - - batt_c_v = reading[BAT].voltage * 100; - battCurr = reading[BAT].current * 10; - - encodeA(b, 0 + head_offset, batt_a_v); - encodeB(b, 1 + head_offset, batt_b_v); - encodeA(b, 3 + head_offset, batt_c_v); - encodeA(b, 9 + head_offset, battCurr); - encodeA(b, 12 + head_offset,posXv); - encodeB(b, 13 + head_offset,posYv); - encodeA(b, 15 + head_offset,posZv); - encodeB(b, 16 + head_offset,negXv); - encodeA(b, 18 + head_offset,negYv); - encodeB(b, 19 + head_offset,negZv); - -/* batt_c_v += 10; - battCurr -= 10; - encodeA(b, 3 + head_offset, batt_c_v); - encodeA(b, 9 + head_offset, battCurr); -*/ - int ctr1 = 0; - int ctr3 = 0; - for (i = 0; i < RS_FRAME_LEN; i++) - { - for (int j = 0; j < RS_FRAMES ; j++) - { - if (!((i == (RS_FRAME_LEN - 1)) && (j == 2))) // skip last one for BPSK - { - if (ctr1 < HEADER_LEN) - { - rs_frame[j][i] = h[ctr1]; - update_rs(parities[j], h[ctr1]); - // printf("header %d rs_frame[%d][%d] = %x \n", ctr1, j, i, h[ctr1]); - data8[ctr1++] = rs_frame[j][i]; - // printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]); - } - else - { - rs_frame[j][i] = b[ctr3 % DATA_LEN]; - update_rs(parities[j], b[ctr3 % DATA_LEN]); - // printf("%d rs_frame[%d][%d] = %x %d \n", - // ctr1, j, i, b[ctr3 % DATA_LEN], ctr3 % DATA_LEN); - data8[ctr1++] = rs_frame[j][i]; - // printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]); - ctr3++; - } - } - } - } - - printf("Parities "); - for (int m = 0; m < PARITY_LEN; m++) { - printf("%d ", parities[0][m]); - } - printf("\n"); - - int ctr2 = 0; - memset(data10,0,sizeof(data10)); - int rd = 0; - int nrd; - - for (i = 0; i < DATA_LEN * PAYLOADS + HEADER_LEN; i++) // 476 for BPSK - { - data10[ctr2] = (Encode_8b10b[rd][((int)data8[ctr2])] & 0x3ff); - nrd = (Encode_8b10b[rd][((int)data8[ctr2])] >> 10) & 1; - // printf ("data10[%d] = encoded data8[%d] = %x \n", - // ctr2, ctr2, data10[ctr2]); - - rd = nrd; // ^ nrd; - ctr2++; - } - - for (i = 0; i < PARITY_LEN; i++) - { - for (int j = 0; j < RS_FRAMES; j++) - { - data10[ctr2++] = (Encode_8b10b[rd][((int)parities[j][i])] & 0x3ff); - nrd = (Encode_8b10b[rd][((int)parities[j][i])] >> 10) & 1; - // printf ("data10[%d] = encoded parities[%d][%d] = %x \n", - // ctr2 - 1, j, i, data10[ctr2 - 1]); - - rd = nrd; - } - } - - int data; - int val; - int offset = 0; - - for (i = 1; i <= SYNC_BITS * SAMPLES; i++) - { - write_wave(ctr); - if ( (i % SAMPLES) == 0) { - int bit = SYNC_BITS - i/SAMPLES + 1; - val = sync; - data = val & 1 << (bit - 1); - // printf ("%d i: %d new frame %d sync bit %d = %d \n", - // ctr/SAMPLES, i, frames, bit, (data > 0) ); - if (DUV) - { - phase = ((data != 0) * 2) - 1; - // printf("Sending a %d\n", phase); - } - else - { - if (data == 0) { - phase *= -1; - if ( (ctr - smaller) > 0) - { - for (int j = 1; j <= smaller; j++) - buffer[ctr - j] = buffer[ctr - j] * 0.4; - } - flip_ctr = ctr; - } - } - } - } - - for (i = 1; - i <= (10 * (HEADER_LEN + DATA_LEN * PAYLOADS + RS_FRAMES * PARITY_LEN) * SAMPLES); i++) // 572 - { - write_wave(ctr); - if ( (i % SAMPLES) == 0) { - int symbol = (int)((i - 1)/ (SAMPLES * 10)); - int bit = 10 - (i - symbol * SAMPLES * 10) / SAMPLES + 1; - val = data10[symbol]; - data = val & 1 << (bit - 1); - // printf ("%d i: %d new frame %d data10[%d] = %x bit %d = %d \n", - // ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) ); - if (DUV) - { - phase = ((data != 0) * 2) - 1; - // printf("Sending a %d\n", phase); - } - else - { - if (data == 0) { - phase *= -1; - if ( (ctr - smaller) > 0) - { - for (int j = 1; j <= smaller; j ++) - buffer[ctr - j] = buffer[ctr - j] * 0.4; - } - flip_ctr = ctr; - } - } - } - } - } - write_wav("transmit.wav", BUF_LEN, buffer, S_RATE); - - int count; - for (count = 0; count < DATA_LEN; count++) { - printf("%02X", b[count]); - } - printf("\n"); - -return 0; -} - -// wav file generation code - -/* make_wav.c - * Creates a WAV file from an array of ints. - * Output is monophonic, signed 16-bit samples - * copyright - * Fri Jun 18 16:36:23 PDT 2010 Kevin Karplus - * Creative Commons license Attribution-NonCommercial - * http://creativecommons.org/licenses/by-nc/3.0/ - * - * Edited by Dolin Sergey. dlinyj@gmail.com - * April 11 12:58 2014 - */ - - // gcc -o make_enc_wav make_enc_wav.c -lm - // ./make_enc_wav - - /* - * TelemEncoding.h - * - * Created on: Feb 3, 2014 - * Author: fox - */ - -#include -#include -#include -#include -#include -#include - -//#include "make_wav.h" - -#define false 0 -#define true 1 - -//static int twosToInt(int val,int len); -//static int encodeB(short int *b, int index, int val); -//static int encodeA(short int *b, int index, int val); - - static int NOT_FRAME = /* 0fa */ 0xfa & 0x3ff; - static int FRAME = /* 0fa */ ~0xfa & 0x3ff; - -/* - * TelemEncoding.c - * - Fox-1 telemetry encoder - January 2014 Phil Karn KA9Q - - This file has two external functions: - void update_rs(unsigned char parity[32],unsigned char data); - int encode_8b10b(int *state,int data). - - update_rs() is the Reed-Solomon encoder. Its first argument is the 32-byte - encoder shift register, the second is the 8-bit data byte being encoded. It updates - the shift register in place and returns void. At the end of each frame, it contains - the parities ready for transmission, starting with parity[0]. - Be sure to zero this array before each new frame! - - encode_8b10b() is the 8b10b encoder. Its first argument is a pointer to a single integer - with the 1-bit encoder state (the current run disparity, or RD). Initialize it to 0 - JUST ONCE at startup (not between frames). - The second argument is the data byte being encoded. It updates the state and returns - an integer containing the 10-bit encoded word, right justified. - Transmit this word from left to right. - - The data argument is an int so it can hold the special value -1 to indicate end of frame; - it generates the 8b10b control word K.28.5, which is used as an inter-frame flag. - - Some assert() calls are made to verify legality of arguments. These can be turned off in - production code. - - - sample frame transmission code: - - unsigned char data[64]; // Data block to be sent - unsigned char parity[32]; // RS parities - void transmit_word(int); // User provided transmit function: 10 bits of data in bits 9....0 - int state,i; - - state = 0; // Only once at startup, not between frames - memset(parity,0,sizeof(parity); // Do this before every frame - // Transmit the data, updating the RS encoder - for(i=0;i<64;i++){ - update_rs(parity,data[i]); - transmit_word(encode_8b10b(&state,data[i]); - } - // Transmit the RS parities - for(i=0;i<32;i++) - transmit_word(encode_8b10b(&state,parity[i]); - - transmit_word(encode_8b10b(&state,-1); // Transmit end-of-frame flag -*/ - - -#include -//#include "Fox.h" -//#include "TelemEncoding.h" - -#ifndef NULL -#define NULL ((void *)0) -#endif - -#define NN (0xff) // Frame size in symbols -#define A0 (NN) // special value for log(0) - - -// GF Antilog lookup table table -static unsigned char CCSDS_alpha_to[NN+1] = { -0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x87,0x89,0x95,0xad,0xdd,0x3d,0x7a,0xf4, -0x6f,0xde,0x3b,0x76,0xec,0x5f,0xbe,0xfb,0x71,0xe2,0x43,0x86,0x8b,0x91,0xa5,0xcd, -0x1d,0x3a,0x74,0xe8,0x57,0xae,0xdb,0x31,0x62,0xc4,0x0f,0x1e,0x3c,0x78,0xf0,0x67, -0xce,0x1b,0x36,0x6c,0xd8,0x37,0x6e,0xdc,0x3f,0x7e,0xfc,0x7f,0xfe,0x7b,0xf6,0x6b, -0xd6,0x2b,0x56,0xac,0xdf,0x39,0x72,0xe4,0x4f,0x9e,0xbb,0xf1,0x65,0xca,0x13,0x26, -0x4c,0x98,0xb7,0xe9,0x55,0xaa,0xd3,0x21,0x42,0x84,0x8f,0x99,0xb5,0xed,0x5d,0xba, -0xf3,0x61,0xc2,0x03,0x06,0x0c,0x18,0x30,0x60,0xc0,0x07,0x0e,0x1c,0x38,0x70,0xe0, -0x47,0x8e,0x9b,0xb1,0xe5,0x4d,0x9a,0xb3,0xe1,0x45,0x8a,0x93,0xa1,0xc5,0x0d,0x1a, -0x34,0x68,0xd0,0x27,0x4e,0x9c,0xbf,0xf9,0x75,0xea,0x53,0xa6,0xcb,0x11,0x22,0x44, -0x88,0x97,0xa9,0xd5,0x2d,0x5a,0xb4,0xef,0x59,0xb2,0xe3,0x41,0x82,0x83,0x81,0x85, -0x8d,0x9d,0xbd,0xfd,0x7d,0xfa,0x73,0xe6,0x4b,0x96,0xab,0xd1,0x25,0x4a,0x94,0xaf, -0xd9,0x35,0x6a,0xd4,0x2f,0x5e,0xbc,0xff,0x79,0xf2,0x63,0xc6,0x0b,0x16,0x2c,0x58, -0xb0,0xe7,0x49,0x92,0xa3,0xc1,0x05,0x0a,0x14,0x28,0x50,0xa0,0xc7,0x09,0x12,0x24, -0x48,0x90,0xa7,0xc9,0x15,0x2a,0x54,0xa8,0xd7,0x29,0x52,0xa4,0xcf,0x19,0x32,0x64, -0xc8,0x17,0x2e,0x5c,0xb8,0xf7,0x69,0xd2,0x23,0x46,0x8c,0x9f,0xb9,0xf5,0x6d,0xda, -0x33,0x66,0xcc,0x1f,0x3e,0x7c,0xf8,0x77,0xee,0x5b,0xb6,0xeb,0x51,0xa2,0xc3,0x00, -}; - -// GF log lookup table. Special value represents log(0) -static unsigned char CCSDS_index_of[NN+1] = { - A0, 0, 1, 99, 2,198,100,106, 3,205,199,188,101,126,107, 42, - 4,141,206, 78,200,212,189,225,102,221,127, 49,108, 32, 43,243, - 5, 87,142,232,207,172, 79,131,201,217,213, 65,190,148,226,180, -103, 39,222,240,128,177, 50, 53,109, 69, 33, 18, 44, 13,244, 56, - 6,155, 88, 26,143,121,233,112,208,194,173,168, 80,117,132, 72, -202,252,218,138,214, 84, 66, 36,191,152,149,249,227, 94,181, 21, -104, 97, 40,186,223, 76,241, 47,129,230,178, 63, 51,238, 54, 16, -110, 24, 70,166, 34,136, 19,247, 45,184, 14, 61,245,164, 57, 59, - 7,158,156,157, 89,159, 27, 8,144, 9,122, 28,234,160,113, 90, -209, 29,195,123,174, 10,169,145, 81, 91,118,114,133,161, 73,235, -203,124,253,196,219, 30,139,210,215,146, 85,170, 67, 11, 37,175, -192,115,153,119,150, 92,250, 82,228,236, 95, 74,182,162, 22,134, -105,197, 98,254, 41,125,187,204,224,211, 77,140,242, 31, 48,220, -130,171,231, 86,179,147, 64,216, 52,176,239, 38, 55, 12, 17, 68, -111,120, 25,154, 71,116,167,193, 35, 83,137,251, 20, 93,248,151, - 46, 75,185, 96, 15,237, 62,229,246,135,165, 23, 58,163, 60,183, -}; - -// Only half the coefficients are given here because the -// generator polynomial is palindromic; G0 = G32, G1 = G31, etc. -// Only G16 is unique -static unsigned char CCSDS_poly[] = { - 0,249, 59, 66, 4, 43,126,251, 97, 30, 3,213, 50, 66,170, 5, - 24, -}; - - -static inline int modnn(int x){ - while (x >= NN) { - x -= NN; - x = (x >> 8) + (x & NN); - } - return x; -} - - -// Update Reed-Solomon encoder -// parity -> 32-byte reed-solomon encoder state; clear this to zero before each frame -void update_rs( - unsigned char parity[32], // 32-byte encoder state; zero before each frame - unsigned char c) // Current data byte to update -{ - unsigned char feedback; - int j,t; - - assert(parity != NULL); - feedback = CCSDS_index_of[c ^ parity[0]]; - if(feedback != A0){ // only if feedback is non-zero - // Take advantage of palindromic polynomial to halve the multiplies - // Do G1...G15, which is the same as G17...G31 - for(j=1;j0) - { buf = word & 0xff; - fwrite(&buf, 1,1, wav_file); - num_bytes--; - word >>= 8; - } -} - -/* information about the WAV file format from - -http://ccrma.stanford.edu/courses/422/projects/WaveFormat/ - - */ - -void write_wav(char * filename, unsigned long num_samples, short int * data, int s_rate) -{ - FILE* wav_file; - unsigned int sample_rate; - unsigned int num_channels; - unsigned int bytes_per_sample; - unsigned int byte_rate; - unsigned long i; /* counter for samples */ - - num_channels = 1; /* monoaural */ - bytes_per_sample = 2; - - if (s_rate<=0) sample_rate = 44100; - else sample_rate = (unsigned int) s_rate; - - byte_rate = sample_rate*num_channels*bytes_per_sample; - - wav_file = fopen(filename, "w"); - assert(wav_file); /* make sure it opened */ - - /* write RIFF header */ - fwrite("RIFF", 1, 4, wav_file); - write_little_endian(36 + bytes_per_sample* num_samples*num_channels, 4, wav_file); - fwrite("WAVE", 1, 4, wav_file); - - /* write fmt subchunk */ - fwrite("fmt ", 1, 4, wav_file); - write_little_endian(16, 4, wav_file); /* SubChunk1Size is 16 */ - write_little_endian(1, 2, wav_file); /* PCM is format 1 */ - write_little_endian(num_channels, 2, wav_file); - write_little_endian(sample_rate, 4, wav_file); - write_little_endian(byte_rate, 4, wav_file); - write_little_endian(num_channels*bytes_per_sample, 2, wav_file); /* block align */ - write_little_endian(8*bytes_per_sample, 2, wav_file); /* bits/sample */ - - /* write data subchunk */ - fwrite("data", 1, 4, wav_file); - write_little_endian(bytes_per_sample* num_samples*num_channels, 4, wav_file); - - for (i=0; i< num_samples; i++) - { write_little_endian((unsigned int)(data[i]),bytes_per_sample, wav_file); - } - - fclose(wav_file); -} - - - -//int main(int argc, char * argv[]) -//{ - -// return 0; -//} - -void write_wave(int i) -{ - if (DUV) - { -// if ((ctr - flip_ctr) < smaller) -// buffer[ctr++] = 0.1 * phase * (ctr - flip_ctr) / smaller; -// else - buffer[ctr++] = 0.25 * amplitude * phase; - } - else - { - if ((ctr - flip_ctr) < smaller) - buffer[ctr++] = (int)(amplitude * 0.4 * phase * - sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - else - buffer[ctr++] = (int)(amplitude * phase * - sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - } -// printf("%d %d \n", i, buffer[ctr - 1]); - -} - -/** - * - * FOX 1 Telemetry Decoder - * @author chris.e.thompson g0kla/ac2cz - * - * Copyright (C) 2015 amsat.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General License for more details. - * - * You should have received a copy of the GNU General License - * along with this program. If not, see . - * - * - * Static variables and methods to encode and decode 8b10b - * - * - */ - -int encodeA(short int *b, int index, int val) { -// printf("Encoding A\n"); - b[index] = val & 0xff; - b[index + 1] = (b[index + 1] & 0xf0) | ((val >> 8) & 0x0f); - return 0; -} - -int encodeB(short int *b, int index, int val) { -// printf("Encoding B\n"); - b[index] = (b[index] & 0x0f) | ((val << 4) & 0xf0); - b[index + 1] = (val >> 4 ) & 0xff; - return 0; -} - -int twosToInt(int val,int len) { // Convert twos compliment to integer -// from https://www.raspberrypi.org/forums/viewtopic.php?t=55815 - - if(val & (1 << (len - 1))) - val = val - (1 << len); - - return(val); -} From f9f50a88b54dd7a9ba7fb8a3f9eac590bfdb6e1e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 12:13:09 -0400 Subject: [PATCH 134/150] Delete main_memcpy.c --- afsk/main_memcpy.c | 1128 -------------------------------------------- 1 file changed, 1128 deletions(-) delete mode 100644 afsk/main_memcpy.c diff --git a/afsk/main_memcpy.c b/afsk/main_memcpy.c deleted file mode 100644 index fc935697..00000000 --- a/afsk/main_memcpy.c +++ /dev/null @@ -1,1128 +0,0 @@ -/* - * Transmits CubeSat Telemetry at 434.9MHz in AO-7 format - * - * Copyright Alan B. Johnston - * - * Portions Copyright (C) 2018 Jonathan Brandenburg - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * INA219 Raspberry Pi wiringPi code is based on Adafruit Arduino wire codeF - * from https://github.com/adafruit/Adafruit_INA219. - */ - -#include -#include -#include -#include -#include -#include "status.h" -#include "ax5043.h" -#include "ax25.h" -#include "spi/ax5043spi.h" -#include -#include -#include -#include -#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino -#include "make_wav.h" - -#define A 1 -#define B 2 -#define C 3 -#define D 4 - -#define PLUS_X 0 -#define PLUS_Y 1 -#define PLUS_Z 2 -#define BAT 3 -#define MINUS_X 4 -#define MINUS_Y 5 -#define MINUS_Z 6 -#define BUS 7 -#define OFF -1 - -uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET; -uint32_t tx_channel = 0; - -ax5043_conf_t hax5043; -ax25_conf_t hax25; - -static void init_rf(); -int twosToInt(int val, int len); -int get_tlm(char *str); -int get_tlm_fox(); -int encodeA(short int *b, int index, int val); -int encodeB(short int *b, int index, int val); -void config_x25(); -void trans_x25(); -int upper_digit(int number); -int lower_digit(int number); - -#define S_RATE (48000) // (44100) -#define BUF_SIZE (S_RATE*10) /* 2 second buffer */ - -// BPSK Settings -#define BIT_RATE 1200 // 200 for DUV -#define DUV 0 // 1 for DUV -#define RS_FRAMES 3 // 3 frames for BPSK, 1 for DUV -#define PAYLOADS 6 // 1 for DUV -#define DATA_LEN 78 // 56 for DUV -#define RS_FRAME_LEN 159 // 64 for DUV -#define SYNC_BITS 31 // 10 for DUV -#define SYNC_WORD 0b1000111110011010010000101011101 // 0b0011111010 for DUV -#define HEADER_LEN 8 // 6 for DUV -/* -// DUV Settings -#define BIT_RATE 200 -#define DUV 1 -#define RS_FRAMES 1 -#define PAYLOADS 1 -#define RS_FRAME_LEN 64 -#define HEADER_LEN 6 -#define DATA_LEN 58 -#define SYNC_BITS 10 -#define SYNC_WORD 0b0011111010 -*/ - -#define PARITY_LEN 32 - -float amplitude = 32767/3; // 20000; // 32767/(10%amp+5%amp+100%amp) -float freq_Hz = 3000; // 1200 - -int smaller; -int flip_ctr = 0; -int phase = 1; -int ctr = 0; -long int ptr = 0; - -void copy_samples(); -void write_to_buffer(int i, int symbol, int val); -void write_wave(); -#define SAMPLES (S_RATE / BIT_RATE) -#define FRAME_CNT 33 // Add 3 frames to the count - -//#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (8 + 6 * DATA_LEN + 96)) * SAMPLES) -#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (HEADER_LEN + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN))) * SAMPLES) -short int buffer[BUF_LEN]; -short int phase0[SAMPLES], phase1[SAMPLES]; -int size_of_phase; -short int data10[8 + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN)]; -short int data8[8 + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN)]; -int reset_count; -float uptime_sec; -long int uptime; -char call[5]; - -struct SensorConfig { - int fd; - uint16_t config; - int calValue; - int powerMultiplier; - int currentDivider; -}; - -struct SensorData { - double current; - double voltage; - double power; -}; - -/** - * @brief Read the data from one of the i2c current sensors. - * - * Reads the current data from the requested i2c current sensor configuration and - * stores it into a SensorData struct. An invalid file descriptor (i.e. less than zero) - * results in a SensorData struct being returned that has both its #current and #power members - * set to NAN. - * - * @param sensor A structure containing sensor configuration including the file descriptor. - * @return struct SensorData A struct that contains the current, voltage, and power readings - * from the requested sensor. - */ -struct SensorData read_sensor_data(struct SensorConfig sensor) { - struct SensorData data = { - .current = NAN, - .voltage = NAN, - .power = NAN }; - - if (sensor.fd < 0) { - return data; - } - // doesn't read negative currents accurately, shows -0.1mA - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - int value = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - data.current = (float) twosToInt(value, 16) / (float) sensor.currentDivider; - - wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); - delay(1); // Max 12-bit conversion time is 586us per sample - value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); - data.voltage = ((float)(value >> 3) * 4) / 1000; - // power has very low resolution, seems to step in 512mW values - data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; - - return data; -} - -/** - * @brief Configures an i2c current sensor. - * - * Calculates the configuration values of the i2c sensor so that - * current, voltage, and power can be read using read_sensor_data. - * Supports 16V 400mA and 16V 2.0A settings. - * - * @param sensor A file descriptor that can be used to read from the sensor. - * @param milliAmps The mA configuration, either 400mA or 2A are supported. - * @return struct SensorConfig A struct that contains the configuraton of the sensor. - */ -//struct SensorConfig config_sensor(int sensor, int milliAmps) { -struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { - struct SensorConfig data; - - if (access(bus, W_OK | R_OK) < 0) { // Test if I2C Bus is missing - printf("ERROR: %s bus not present \n", bus); - data.fd = OFF; - return (data); - } - - data.fd = wiringPiI2CSetupInterface(bus, address); - - data.config = INA219_CONFIG_BVOLTAGERANGE_32V | - INA219_CONFIG_GAIN_1_40MV | - INA219_CONFIG_BADCRES_12BIT | - INA219_CONFIG_SADCRES_12BIT_1S_532US | - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; - - if (milliAmps == 400) { // INA219 16V 400mA configuration - data.calValue = 8192; - data.powerMultiplier = 1; - data.currentDivider = 20; // 40; in Adafruit config - } - else { // INA219 16V 2A configuration - data.calValue = 40960; - data.powerMultiplier = 2; - data.currentDivider = 10; // 20; in Adafruit config - } - - #ifdef DEBUG_LOGGING - printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd, - data.config, data.calValue, data.currentDivider, data.powerMultiplier); - #endif - return data; -} - -struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorConfig tempSensor; - -char src_addr[5] = ""; -char dest_addr[5] = "CQ"; - -int main(int argc, char *argv[]) { - - if (argc > 1) { - strcpy(src_addr, argv[1]); - } - - wiringPiSetup (); - pinMode (0, OUTPUT); - - //setSpiChannel(SPI_CHANNEL); - //setSpiSpeed(SPI_SPEED); - //initializeSpi(); - - FILE* config_file = fopen("sim.cfg","r"); - if (config_file == NULL) - { - printf("Creating config file."); - config_file = fopen("sim.cfg","w"); - fprintf(config_file, "%s %d", "KU2Y", 100); - fclose(config_file); - config_file = fopen("sim.cfg","r"); - } - - char* cfg_buf[100]; - fscanf(config_file, "%s %d", call, &reset_count); - fclose(config_file); - printf("%s %d\n", call, reset_count); - - reset_count = (reset_count + 1) % 0xffff; - - config_file = fopen("sim.cfg","w"); - fprintf(config_file, "%s %d", call, reset_count); - fclose(config_file); - config_file = fopen("sim.cfg","r"); - - tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); - - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); - sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); - - int ret; - uint8_t data[1024]; - - tx_freq_hz -= tx_channel * 50000; - - //init_rf(); - - ax25_init(&hax25, (uint8_t *) dest_addr, '1', (uint8_t *) src_addr, '1', - AX25_PREAMBLE_LEN, - AX25_POSTAMBLE_LEN); - - ptr = 0; - size_of_phase = sizeof(phase0); - int j; - phase = 1; - for (j = 0; j < SAMPLES; j++) - { - write_wave(j, phase1); - } - phase = -1; - for (j = 0; j < SAMPLES; j++) - { - write_wave(j, phase0); - } - - - /* Infinite loop */ - //for (;;) - - { - // sleep(1); // Delay 1 second - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Getting TLM Data\n"); - #endif - - char str[1000]; - // uint8_t b[64]; - char header_str[] = "\x03\xf0"; - strcpy(str, header_str); - - printf("%s-1>%s-1:", (uint8_t *)src_addr, (uint8_t *)dest_addr); - -// get_tlm(str); - get_tlm_fox(); - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Getting ready to send\n"); - #endif - - char cmdbuffer[1000]; - FILE* transmit; - if (DUV == 1) { - transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/CubeSatSim/rpitx/rpitx -i- -m RF -f 434.9e3 2>&1", "r"); - } else { - transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/CubeSatSim/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.9e6 -t float 2>&1", "r"); - } - fgets(cmdbuffer, 1000, transmit); - pclose(transmit); - printf("Results of transmit command: %s\n", cmdbuffer); - - - -// printf("%s \n", b); -/* - digitalWrite (0, LOW); - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Transmitting X.25 packet\n"); - #endif - 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); - - if (ret) { - fprintf(stderr, - "ERROR: Failed to transmit entire AX.25 frame with error code %d\n", - ret); - exit(EXIT_FAILURE); - } -*/ - } - - return 0; -} - -static void init_rf() { - int ret; - #ifdef DEBUG_LOGGING - fprintf(stderr,"Initializing AX5043\n"); - #endif - 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 -// -int lower_digit(int number) { - - int digit = 0; - if (number < 100) - digit = number - ((int)(number/10) * 10); - else - fprintf(stderr,"ERROR: Not a digit in lower_digit!\n"); - return digit; -} - -// Returns upper digit of a number which must be less than 99 -// -int upper_digit(int number) { - - int digit = 0; - if (number < 100) - digit = (int)(number/10); - else - fprintf(stderr,"ERROR: Not a digit in upper_digit!\n"); - return digit; -} - -int get_tlm(char *str) { - - int tlm[7][5]; - memset(tlm, 0, sizeof tlm); - -// Reading I2C voltage and current sensors - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - count, reading[count].voltage, reading[count].current, reading[count].power); - #endif - } - - tlm[1][A] = (int)(reading[BUS].voltage /15.0 + 0.5) % 100; // Current of 5V supply to Pi - tlm[1][B] = (int) (99.5 - reading[PLUS_X].current/10.0) % 100; // +X current [4] - tlm[1][C] = (int) (99.5 - reading[MINUS_X].current/10.0) % 100; // X- current [10] - tlm[1][D] = (int) (99.5 - reading[PLUS_Y].current/10.0) % 100; // +Y current [7] - - tlm[2][A] = (int) (99.5 - reading[MINUS_Y].current/10.0) % 100; // -Y current [10] - tlm[2][B] = (int) (99.5 - reading[PLUS_Z].current/10.0) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel - tlm[2][C] = (int) (99.5 - reading[MINUS_Z].current/10.0) % 100; // -Z current (was timestamp) - tlm[2][D] = (int)(50.5 + reading[BAT].current/10.0) % 100; // NiMH Battery current - - tlm[3][A] = abs((int)((reading[BAT].voltage * 10.0) - 65.5) % 100); - tlm[3][B] = (int)(reading[BUS].voltage * 10.0) % 100; // 5V supply to Pi - - if (tempSensor.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); - uint8_t lower = (uint8_t) (tempValue & 0xff); - float temp = (float)lower + ((float)upper / 0x100); - - #ifdef DEBUG_LOGGING - printf("Temp Sensor Read: %6.1f\n", temp); - #endif - - tlm[4][A] = (int)((95.8 - temp)/1.48 + 0.5) % 100; - } - - FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); - if (cpuTempSensor) { - double cpuTemp; - fscanf (cpuTempSensor, "%lf", &cpuTemp); - cpuTemp /= 1000; - - #ifdef DEBUG_LOGGING - printf("CPU Temp Read: %6.1f\n", cpuTemp); - #endif - - tlm[4][B] = (int)((95.8 - cpuTemp)/1.48 + 0.5) % 100; - fclose (cpuTempSensor); - } - - tlm[6][B] = 0 ; - tlm[6][D] = 49 + rand() % 3; - - #ifdef DEBUG_LOGGING -// Display tlm - int k, j; - for (k = 1; k < 7; k++) { - for (j = 1; j < 5; j++) { - printf(" %2d ", tlm[k][j]); - } - printf("\n"); - } - #endif - - char tlm_str[1000]; - - char header_str[] = "hi hi "; - strcpy(str, header_str); -// printf("%s-1>%s-1:hi hi ", (uint8_t *)src_addr, (uint8_t *)dest_addr); - - int channel; - for (channel = 1; channel < 7; channel++) { - 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",tlm_str); - strcat(str, tlm_str); - } -// printf("\n"); - -return; -} - -int get_tlm_fox() { - -// memset(b, 0, 64); - -// Reading I2C voltage and current sensors - - FILE* uptime_file = fopen("/proc/uptime", "r"); - fscanf(uptime_file, "%f", &uptime_sec); - uptime = (int) uptime_sec; - printf("Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime); - fclose(uptime_file); - - int i; - long int sync = SYNC_WORD; - - smaller = S_RATE/(2 * freq_Hz); -/* - short int b[DATA_LEN] = {0x00,0x7E,0x03, - 0x00,0x00,0x00,0x00,0xE6,0x01,0x00,0x27,0xD1,0x02, - 0xE5,0x40,0x04,0x18,0xE1,0x04,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - - short int h[HEADER_LEN] = {0x05,0x00,0x00,0x00,0x00,0x10,0x00,0x00}; -*/ - - short int b[DATA_LEN]; - memset(b, 0, sizeof(b)); - - short int h[HEADER_LEN]; - memset(h, 0, sizeof(h)); - - short int b10[DATA_LEN], h10[HEADER_LEN]; - short int rs_frame[RS_FRAMES][223]; - unsigned char parities[RS_FRAMES][PARITY_LEN],inputByte; -/* - int id = 5, frm_type = 0x01, TxTemp = 0, IHUcpuTemp = 0; - int batt_a_v = 0, batt_b_v = 0, batt_c_v = 8.95 * 100, battCurr = 48.6 * 10; - int posXv = 296, negXv = 45, posYv = 220, negYv = 68, - posZv = 280, negZv = 78; -*/ - int id = 5, frm_type = 0x01, TxTemp = 0, IHUcpuTemp = 0; - int batt_a_v = 0, batt_b_v = 0, batt_c_v = 0, battCurr = 0; - int posXv = 0, negXv = 0, posYv = 0, negYv = 0, - posZv = 0, negZv = 0; - int head_offset = 0; - - for (int frames = 0; frames < FRAME_CNT; frames++) - { - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - count, reading[count].voltage, reading[count].current, reading[count].power); - #endif - } -/* - if (tempSensor.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); - uint8_t lower = (uint8_t) (tempValue & 0xff); - float temp = (float)lower + ((float)upper / 0x100); - - #ifdef DEBUG_LOGGING - printf("Temp Sensor Read: %6.1f\n", temp); - #endif - - TxTemp = (int)((temp * 10.0) + 0.5); - encodeB(b, 34 + head_offset, TxTemp); - } -*/ - FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); - if (cpuTempSensor) { - double cpuTemp; - fscanf (cpuTempSensor, "%lf", &cpuTemp); - cpuTemp /= 1000; - - #ifdef DEBUG_LOGGING - printf("CPU Temp Read: %6.1f\n", cpuTemp); - #endif - - IHUcpuTemp = (int)((cpuTemp * 10.0) + 0.5); - encodeA(b, 39 + head_offset, IHUcpuTemp); - } - sleep(1); - - memset(rs_frame,0,sizeof(rs_frame)); - memset(parities,0,sizeof(parities)); - - FILE *uptime_file = fopen("/proc/uptime", "r"); - fscanf(uptime_file, "%f", &uptime_sec); - uptime = (int) uptime_sec; - fclose(uptime_file); - printf("Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime); - - h[0] = (h[0] & 0xf8) | (id & 0x07); // 3 bits - printf("h[0] %x\n", h[0]); - h[0] = (h[0] & 0x07)| ((reset_count & 0x1f) << 3); - printf("h[0] %x\n", h[0]); - h[1] = (reset_count >> 5) & 0xff; - printf("h[1] %x\n", h[1]); - h[2] = (h[2] & 0xf8) | ((reset_count >> 13) & 0x07); - printf("h[2] %x\n", h[2]); - h[2] = (h[2] & 0x0e) | ((uptime & 0x1f) << 3); - printf("h[2] %x\n", h[2]); - h[3] = (uptime >> 5) & 0xff; - h[4] = (uptime >> 13) & 0xff; - h[5] = (h[5] & 0xf0) | ((uptime >> 21) & 0x0f); - h[5] = (h[5] & 0x0f) | (frm_type << 4); - - posXv = reading[PLUS_X].current * 10; - posYv = reading[PLUS_Y].current * 10; - posZv = reading[PLUS_Z].current * 10; - negXv = reading[MINUS_X].current * 10; - negYv = reading[MINUS_Y].current * 10; - negZv = reading[MINUS_Z].current * 10; - - batt_c_v = reading[BAT].voltage * 100; - battCurr = reading[BAT].current * 10; - - encodeA(b, 0 + head_offset, batt_a_v); - encodeB(b, 1 + head_offset, batt_b_v); - encodeA(b, 3 + head_offset, batt_c_v); - encodeA(b, 9 + head_offset, battCurr); - encodeA(b, 12 + head_offset,posXv); - encodeB(b, 13 + head_offset,posYv); - encodeA(b, 15 + head_offset,posZv); - encodeB(b, 16 + head_offset,negXv); - encodeA(b, 18 + head_offset,negYv); - encodeB(b, 19 + head_offset,negZv); - -/* batt_c_v += 10; - battCurr -= 10; - encodeA(b, 3 + head_offset, batt_c_v); - encodeA(b, 9 + head_offset, battCurr); -*/ - int ctr1 = 0; - int ctr3 = 0; - for (i = 0; i < RS_FRAME_LEN; i++) - { - for (int j = 0; j < RS_FRAMES ; j++) - { - if (!((i == (RS_FRAME_LEN - 1)) && (j == 2))) // skip last one for BPSK - { - if (ctr1 < HEADER_LEN) - { - rs_frame[j][i] = h[ctr1]; - update_rs(parities[j], h[ctr1]); - // printf("header %d rs_frame[%d][%d] = %x \n", ctr1, j, i, h[ctr1]); - data8[ctr1++] = rs_frame[j][i]; - // printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]); - } - else - { - rs_frame[j][i] = b[ctr3 % DATA_LEN]; - update_rs(parities[j], b[ctr3 % DATA_LEN]); - // printf("%d rs_frame[%d][%d] = %x %d \n", - // ctr1, j, i, b[ctr3 % DATA_LEN], ctr3 % DATA_LEN); - data8[ctr1++] = rs_frame[j][i]; - // printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]); - ctr3++; - } - } - } - } - - printf("Parities "); - for (int m = 0; m < PARITY_LEN; m++) { - printf("%d ", parities[0][m]); - } - printf("\n"); - - int ctr2 = 0; - memset(data10,0,sizeof(data10)); - int rd = 0; - int nrd; - - for (i = 0; i < DATA_LEN * PAYLOADS + HEADER_LEN; i++) // 476 for BPSK - { - data10[ctr2] = (Encode_8b10b[rd][((int)data8[ctr2])] & 0x3ff); - nrd = (Encode_8b10b[rd][((int)data8[ctr2])] >> 10) & 1; - // printf ("data10[%d] = encoded data8[%d] = %x \n", - // ctr2, ctr2, data10[ctr2]); - - rd = nrd; // ^ nrd; - ctr2++; - } - - for (i = 0; i < PARITY_LEN; i++) - { - for (int j = 0; j < RS_FRAMES; j++) - { - data10[ctr2++] = (Encode_8b10b[rd][((int)parities[j][i])] & 0x3ff); - nrd = (Encode_8b10b[rd][((int)parities[j][i])] >> 10) & 1; - // printf ("data10[%d] = encoded parities[%d][%d] = %x \n", - // ctr2 - 1, j, i, data10[ctr2 - 1]); - - rd = nrd; - } - } - - int data; - int val; - int offset = 0; - - for (i = 1; i <= SYNC_BITS; i++) - { - copy_samples(); - if ( (i % SAMPLES) == 0) { - int bit = SYNC_BITS - i + 1; - val = sync; - data = val & 1 << (bit - 1); - // printf ("%d i: %d new frame %d sync bit %d = %d \n", - // ctr, i, frames, bit, (data > 0) ); - if (DUV) - { - phase = ((data != 0) * 2) - 1; - // printf("Sending a %d\n", phase); - } - else - { - if (data == 0) { - phase *= -1; -// if ( (ctr - smaller) > 0) -// { -// for (int j = 1; j <= smaller; j++) -// buffer[ctr - j] = buffer[ctr - j] * 0.4; -// } -// flip_ctr = ctr; - } - } - } - } - - for (i = 1; - i <= (10 * (HEADER_LEN + DATA_LEN * PAYLOADS + RS_FRAMES * PARITY_LEN) * 1); i++) // 572 - { - copy_samples(); -// if ( (i % SAMPLES) == 0) { - int symbol = (int)((i - 1)/ 10); - int bit = 10 - (i - symbol * 10); - val = data10[symbol]; - data = val & 1 << (bit - 1); - // printf ("%d i: %d new frame %d data10[%d] = %x bit %d = %d \n", - // ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) ); - if (DUV) - { - phase = ((data != 0) * 2) - 1; - // printf("Sending a %d\n", phase); - } - else - { - if (data == 0) { - phase *= -1; -// if ( (ctr - smaller) > 0) -// { -// for (int j = 1; j <= smaller; j ++) -// buffer[ctr - j] = buffer[ctr - j] * 0.4; -// } -// flip_ctr = ctr; - } - } -// } - } - } - write_wav("transmit.wav", BUF_LEN, buffer, S_RATE); - - int count; - for (count = 0; count < DATA_LEN; count++) { - printf("%02X", b[count]); - } - printf("\n"); - -return 0; -} - -// wav file generation code - -/* make_wav.c - * Creates a WAV file from an array of ints. - * Output is monophonic, signed 16-bit samples - * copyright - * Fri Jun 18 16:36:23 PDT 2010 Kevin Karplus - * Creative Commons license Attribution-NonCommercial - * http://creativecommons.org/licenses/by-nc/3.0/ - * - * Edited by Dolin Sergey. dlinyj@gmail.com - * April 11 12:58 2014 - */ - - // gcc -o make_enc_wav make_enc_wav.c -lm - // ./make_enc_wav - - /* - * TelemEncoding.h - * - * Created on: Feb 3, 2014 - * Author: fox - */ - -#include -#include -#include -#include -#include -#include - -//#include "make_wav.h" - -#define false 0 -#define true 1 - -//static int twosToInt(int val,int len); -//static int encodeB(short int *b, int index, int val); -//static int encodeA(short int *b, int index, int val); - - static int NOT_FRAME = /* 0fa */ 0xfa & 0x3ff; - static int FRAME = /* 0fa */ ~0xfa & 0x3ff; - -/* - * TelemEncoding.c - * - Fox-1 telemetry encoder - January 2014 Phil Karn KA9Q - - This file has two external functions: - void update_rs(unsigned char parity[32],unsigned char data); - int encode_8b10b(int *state,int data). - - update_rs() is the Reed-Solomon encoder. Its first argument is the 32-byte - encoder shift register, the second is the 8-bit data byte being encoded. It updates - the shift register in place and returns void. At the end of each frame, it contains - the parities ready for transmission, starting with parity[0]. - Be sure to zero this array before each new frame! - - encode_8b10b() is the 8b10b encoder. Its first argument is a pointer to a single integer - with the 1-bit encoder state (the current run disparity, or RD). Initialize it to 0 - JUST ONCE at startup (not between frames). - The second argument is the data byte being encoded. It updates the state and returns - an integer containing the 10-bit encoded word, right justified. - Transmit this word from left to right. - - The data argument is an int so it can hold the special value -1 to indicate end of frame; - it generates the 8b10b control word K.28.5, which is used as an inter-frame flag. - - Some assert() calls are made to verify legality of arguments. These can be turned off in - production code. - - - sample frame transmission code: - - unsigned char data[64]; // Data block to be sent - unsigned char parity[32]; // RS parities - void transmit_word(int); // User provided transmit function: 10 bits of data in bits 9....0 - int state,i; - - state = 0; // Only once at startup, not between frames - memset(parity,0,sizeof(parity); // Do this before every frame - // Transmit the data, updating the RS encoder - for(i=0;i<64;i++){ - update_rs(parity,data[i]); - transmit_word(encode_8b10b(&state,data[i]); - } - // Transmit the RS parities - for(i=0;i<32;i++) - transmit_word(encode_8b10b(&state,parity[i]); - - transmit_word(encode_8b10b(&state,-1); // Transmit end-of-frame flag -*/ - - -#include -//#include "Fox.h" -//#include "TelemEncoding.h" - -#ifndef NULL -#define NULL ((void *)0) -#endif - -#define NN (0xff) // Frame size in symbols -#define A0 (NN) // special value for log(0) - - -// GF Antilog lookup table table -static unsigned char CCSDS_alpha_to[NN+1] = { -0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x87,0x89,0x95,0xad,0xdd,0x3d,0x7a,0xf4, -0x6f,0xde,0x3b,0x76,0xec,0x5f,0xbe,0xfb,0x71,0xe2,0x43,0x86,0x8b,0x91,0xa5,0xcd, -0x1d,0x3a,0x74,0xe8,0x57,0xae,0xdb,0x31,0x62,0xc4,0x0f,0x1e,0x3c,0x78,0xf0,0x67, -0xce,0x1b,0x36,0x6c,0xd8,0x37,0x6e,0xdc,0x3f,0x7e,0xfc,0x7f,0xfe,0x7b,0xf6,0x6b, -0xd6,0x2b,0x56,0xac,0xdf,0x39,0x72,0xe4,0x4f,0x9e,0xbb,0xf1,0x65,0xca,0x13,0x26, -0x4c,0x98,0xb7,0xe9,0x55,0xaa,0xd3,0x21,0x42,0x84,0x8f,0x99,0xb5,0xed,0x5d,0xba, -0xf3,0x61,0xc2,0x03,0x06,0x0c,0x18,0x30,0x60,0xc0,0x07,0x0e,0x1c,0x38,0x70,0xe0, -0x47,0x8e,0x9b,0xb1,0xe5,0x4d,0x9a,0xb3,0xe1,0x45,0x8a,0x93,0xa1,0xc5,0x0d,0x1a, -0x34,0x68,0xd0,0x27,0x4e,0x9c,0xbf,0xf9,0x75,0xea,0x53,0xa6,0xcb,0x11,0x22,0x44, -0x88,0x97,0xa9,0xd5,0x2d,0x5a,0xb4,0xef,0x59,0xb2,0xe3,0x41,0x82,0x83,0x81,0x85, -0x8d,0x9d,0xbd,0xfd,0x7d,0xfa,0x73,0xe6,0x4b,0x96,0xab,0xd1,0x25,0x4a,0x94,0xaf, -0xd9,0x35,0x6a,0xd4,0x2f,0x5e,0xbc,0xff,0x79,0xf2,0x63,0xc6,0x0b,0x16,0x2c,0x58, -0xb0,0xe7,0x49,0x92,0xa3,0xc1,0x05,0x0a,0x14,0x28,0x50,0xa0,0xc7,0x09,0x12,0x24, -0x48,0x90,0xa7,0xc9,0x15,0x2a,0x54,0xa8,0xd7,0x29,0x52,0xa4,0xcf,0x19,0x32,0x64, -0xc8,0x17,0x2e,0x5c,0xb8,0xf7,0x69,0xd2,0x23,0x46,0x8c,0x9f,0xb9,0xf5,0x6d,0xda, -0x33,0x66,0xcc,0x1f,0x3e,0x7c,0xf8,0x77,0xee,0x5b,0xb6,0xeb,0x51,0xa2,0xc3,0x00, -}; - -// GF log lookup table. Special value represents log(0) -static unsigned char CCSDS_index_of[NN+1] = { - A0, 0, 1, 99, 2,198,100,106, 3,205,199,188,101,126,107, 42, - 4,141,206, 78,200,212,189,225,102,221,127, 49,108, 32, 43,243, - 5, 87,142,232,207,172, 79,131,201,217,213, 65,190,148,226,180, -103, 39,222,240,128,177, 50, 53,109, 69, 33, 18, 44, 13,244, 56, - 6,155, 88, 26,143,121,233,112,208,194,173,168, 80,117,132, 72, -202,252,218,138,214, 84, 66, 36,191,152,149,249,227, 94,181, 21, -104, 97, 40,186,223, 76,241, 47,129,230,178, 63, 51,238, 54, 16, -110, 24, 70,166, 34,136, 19,247, 45,184, 14, 61,245,164, 57, 59, - 7,158,156,157, 89,159, 27, 8,144, 9,122, 28,234,160,113, 90, -209, 29,195,123,174, 10,169,145, 81, 91,118,114,133,161, 73,235, -203,124,253,196,219, 30,139,210,215,146, 85,170, 67, 11, 37,175, -192,115,153,119,150, 92,250, 82,228,236, 95, 74,182,162, 22,134, -105,197, 98,254, 41,125,187,204,224,211, 77,140,242, 31, 48,220, -130,171,231, 86,179,147, 64,216, 52,176,239, 38, 55, 12, 17, 68, -111,120, 25,154, 71,116,167,193, 35, 83,137,251, 20, 93,248,151, - 46, 75,185, 96, 15,237, 62,229,246,135,165, 23, 58,163, 60,183, -}; - -// Only half the coefficients are given here because the -// generator polynomial is palindromic; G0 = G32, G1 = G31, etc. -// Only G16 is unique -static unsigned char CCSDS_poly[] = { - 0,249, 59, 66, 4, 43,126,251, 97, 30, 3,213, 50, 66,170, 5, - 24, -}; - - -static inline int modnn(int x){ - while (x >= NN) { - x -= NN; - x = (x >> 8) + (x & NN); - } - return x; -} - - -// Update Reed-Solomon encoder -// parity -> 32-byte reed-solomon encoder state; clear this to zero before each frame -void update_rs( - unsigned char parity[32], // 32-byte encoder state; zero before each frame - unsigned char c) // Current data byte to update -{ - unsigned char feedback; - int j,t; - - assert(parity != NULL); - feedback = CCSDS_index_of[c ^ parity[0]]; - if(feedback != A0){ // only if feedback is non-zero - // Take advantage of palindromic polynomial to halve the multiplies - // Do G1...G15, which is the same as G17...G31 - for(j=1;j0) - { buf = word & 0xff; - fwrite(&buf, 1,1, wav_file); - num_bytes--; - word >>= 8; - } -} - -/* information about the WAV file format from - -http://ccrma.stanford.edu/courses/422/projects/WaveFormat/ - - */ - -void write_wav(char * filename, unsigned long num_samples, short int * data, int s_rate) -{ - FILE* wav_file; - unsigned int sample_rate; - unsigned int num_channels; - unsigned int bytes_per_sample; - unsigned int byte_rate; - unsigned long i; /* counter for samples */ - - num_channels = 1; /* monoaural */ - bytes_per_sample = 2; - - if (s_rate<=0) sample_rate = 44100; - else sample_rate = (unsigned int) s_rate; - - byte_rate = sample_rate*num_channels*bytes_per_sample; - - wav_file = fopen(filename, "w"); - assert(wav_file); /* make sure it opened */ - - /* write RIFF header */ - fwrite("RIFF", 1, 4, wav_file); - write_little_endian(36 + bytes_per_sample* num_samples*num_channels, 4, wav_file); - fwrite("WAVE", 1, 4, wav_file); - - /* write fmt subchunk */ - fwrite("fmt ", 1, 4, wav_file); - write_little_endian(16, 4, wav_file); /* SubChunk1Size is 16 */ - write_little_endian(1, 2, wav_file); /* PCM is format 1 */ - write_little_endian(num_channels, 2, wav_file); - write_little_endian(sample_rate, 4, wav_file); - write_little_endian(byte_rate, 4, wav_file); - write_little_endian(num_channels*bytes_per_sample, 2, wav_file); /* block align */ - write_little_endian(8*bytes_per_sample, 2, wav_file); /* bits/sample */ - - /* write data subchunk */ - fwrite("data", 1, 4, wav_file); - write_little_endian(bytes_per_sample* num_samples*num_channels, 4, wav_file); - - for (i=0; i< num_samples; i++) - { write_little_endian((unsigned int)(data[i]),bytes_per_sample, wav_file); - } - - fclose(wav_file); -} - - - -//int main(int argc, char * argv[]) -//{ - -// return 0; -//} - -void write_wave(int i, short int *buf) -{ - if (DUV) - { -// if ((ctr - flip_ctr) < smaller) -// buffer[ctr++] = 0.1 * phase * (ctr - flip_ctr) / smaller; -// else - buf[i] = 0.25 * amplitude * phase; - } - else - { -// if ((ctr - flip_ctr) < smaller) - // buffer[ctr++] = (int)(amplitude * 0.4 * phase * - // sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - // else - buf[i] = (int)(amplitude * phase * sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - } - printf("%d %d \n", i, buf[i]); -} - -void copy_samples() -{ - if (phase == 0) - memcpy(&buffer[ptr], &phase0, size_of_phase); - else - memcpy(&buffer[ptr], &phase1, size_of_phase); - - ptr += size_of_phase; -} - -/** - * - * FOX 1 Telemetry Decoder - * @author chris.e.thompson g0kla/ac2cz - * - * Copyright (C) 2015 amsat.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General License for more details. - * - * You should have received a copy of the GNU General License - * along with this program. If not, see . - * - * - * Static variables and methods to encode and decode 8b10b - * - * - */ - -int encodeA(short int *b, int index, int val) { -// printf("Encoding A\n"); - b[index] = val & 0xff; - b[index + 1] = (b[index + 1] & 0xf0) | ((val >> 8) & 0x0f); - return 0; -} - -int encodeB(short int *b, int index, int val) { -// printf("Encoding B\n"); - b[index] = (b[index] & 0x0f) | ((val << 4) & 0xf0); - b[index + 1] = (val >> 4 ) & 0xff; - return 0; -} - -int twosToInt(int val,int len) { // Convert twos compliment to integer -// from https://www.raspberrypi.org/forums/viewtopic.php?t=55815 - - if(val & (1 << (len - 1))) - val = val - (1 << len); - - return(val); -} From a784d1c35c5a19e6d9e87f0012a0f97dd49bcc56 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 12:13:18 -0400 Subject: [PATCH 135/150] Delete main_not_working.c --- afsk/main_not_working.c | 1157 --------------------------------------- 1 file changed, 1157 deletions(-) delete mode 100644 afsk/main_not_working.c diff --git a/afsk/main_not_working.c b/afsk/main_not_working.c deleted file mode 100644 index 05629dd8..00000000 --- a/afsk/main_not_working.c +++ /dev/null @@ -1,1157 +0,0 @@ -/* - * Transmits CubeSat Telemetry at 434.9MHz in AO-7 format - * - * Copyright Alan B. Johnston - * - * Portions Copyright (C) 2018 Jonathan Brandenburg - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * INA219 Raspberry Pi wiringPi code is based on Adafruit Arduino wire code - * from https://github.com/adafruit/Adafruit_INA219. - */ - -#include -#include -#include -#include -#include -#include "status.h" -#include "ax5043.h" -#include "ax25.h" -#include "spi/ax5043spi.h" -#include -#include -#include -#include -#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino -#include "make_wav.h" -#include -#include -#include -#include -#include -#define PORT 8080 - -#define A 1 -#define B 2 -#define C 3 -#define D 4 - -#define PLUS_X 0 -#define PLUS_Y 1 -#define PLUS_Z 2 -#define BAT 3 -#define MINUS_X 4 -#define MINUS_Y 5 -#define MINUS_Z 6 -#define BUS 7 -#define OFF -1 - -uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET; -uint32_t tx_channel = 0; - -ax5043_conf_t hax5043; -ax25_conf_t hax25; - -static void init_rf(); -int twosToInt(int val, int len); -int get_tlm(char *str); -int get_tlm_fox(); -int encodeA(short int *b, int index, int val); -int encodeB(short int *b, int index, int val); -void config_x25(); -void trans_x25(); -int upper_digit(int number); -int lower_digit(int number); - -#define S_RATE (48000) // (44100) -#define BUF_SIZE (S_RATE*10) /* 2 second buffer */ -/* -// BPSK Settings -#define BIT_RATE 1200 // 200 for DUV -#define FSK 0 // 1 for DUV -#define RS_FRAMES 3 // 3 frames for BPSK, 1 for DUV -#define PAYLOADS 6 // 1 for DUV -#define DATA_LEN 78 // 56 for DUV -#define RS_FRAME_LEN 159 // 64 for DUV -#define SYNC_BITS 31 // 10 for DUV -#define SYNC_WORD 0b1000111110011010010000101011101 // 0b0011111010 for DUV -#define HEADER_LEN 8 // 6 for DUV -*/ -// FSK Settings -#define BIT_RATE 200 -#define FSK 1 -#define RS_FRAMES 1 -#define PAYLOADS 1 -#define RS_FRAME_LEN 64 -#define HEADER_LEN 6 -#define DATA_LEN 58 -#define SYNC_BITS 10 -#define SYNC_WORD 0b0011111010 - - -#define PARITY_LEN 32 - -float amplitude = 32767/3; // 20000; // 32767/(10%amp+5%amp+100%amp) -float freq_Hz = 3000; // 1200 - -int smaller; -int flip_ctr = 0; -int phase = 1; -int ctr = 0; -int sock = 0; - -void write_to_buffer(int i, int symbol, int val); -void write_wave(); -#define SAMPLES (S_RATE / BIT_RATE) -<<<<<<< HEAD -#define FRAME_CNT 60// 11 //33 // Add 3 frames to the count -======= -#define FRAME_CNT 11// //33 // Add 3 frames to the count ->>>>>>> 363442c3e93a3058a0bb88473dc4fa192b6425ad - -//#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (8 + 6 * DATA_LEN + 96)) * SAMPLES) -#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (HEADER_LEN + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN))) * SAMPLES) -short int buffer[BUF_LEN]; -short int data10[8 + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN)]; -short int data8[8 + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN)]; -int reset_count; -float uptime_sec; -long int uptime; -char call[5]; - -struct SensorConfig { - int fd; - uint16_t config; - int calValue; - int powerMultiplier; - int currentDivider; -}; - -struct SensorData { - double current; - double voltage; - double power; -}; - -/** - * @brief Read the data from one of the i2c current sensors. - * - * Reads the current data from the requested i2c current sensor configuration and - * stores it into a SensorData struct. An invalid file descriptor (i.e. less than zero) - * results in a SensorData struct being returned that has both its #current and #power members - * set to NAN. - * - * @param sensor A structure containing sensor configuration including the file descriptor. - * @return struct SensorData A struct that contains the current, voltage, and power readings - * from the requested sensor. - */ -struct SensorData read_sensor_data(struct SensorConfig sensor) { - struct SensorData data = { - .current = NAN, - .voltage = NAN, - .power = NAN }; - - if (sensor.fd < 0) { - return data; - } - // doesn't read negative currents accurately, shows -0.1mA - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - int value = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - data.current = (float) twosToInt(value, 16) / (float) sensor.currentDivider; - - wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); - delay(1); // Max 12-bit conversion time is 586us per sample - value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); - data.voltage = ((float)(value >> 3) * 4) / 1000; - // power has very low resolution, seems to step in 512mW values - data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; - - return data; -} - -/** - * @brief Configures an i2c current sensor. - * - * Calculates the configuration values of the i2c sensor so that - * current, voltage, and power can be read using read_sensor_data. - * Supports 16V 400mA and 16V 2.0A settings. - * - * @param sensor A file descriptor that can be used to read from the sensor. - * @param milliAmps The mA configuration, either 400mA or 2A are supported. - * @return struct SensorConfig A struct that contains the configuraton of the sensor. - */ -//struct SensorConfig config_sensor(int sensor, int milliAmps) { -struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { - struct SensorConfig data; - - if (access(bus, W_OK | R_OK) < 0) { // Test if I2C Bus is missing - printf("ERROR: %s bus not present \n", bus); - data.fd = OFF; - return (data); - } - - data.fd = wiringPiI2CSetupInterface(bus, address); - - data.config = INA219_CONFIG_BVOLTAGERANGE_32V | - INA219_CONFIG_GAIN_1_40MV | - INA219_CONFIG_BADCRES_12BIT | - INA219_CONFIG_SADCRES_12BIT_1S_532US | - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; - - if (milliAmps == 400) { // INA219 16V 400mA configuration - data.calValue = 8192; - data.powerMultiplier = 1; - data.currentDivider = 20; // 40; in Adafruit config - } - else { // INA219 16V 2A configuration - data.calValue = 40960; - data.powerMultiplier = 2; - data.currentDivider = 10; // 20; in Adafruit config - } - - #ifdef DEBUG_LOGGING - printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd, - data.config, data.calValue, data.currentDivider, data.powerMultiplier); - #endif - return data; -} - -struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorConfig tempSensor; - -char src_addr[5] = ""; -char dest_addr[5] = "CQ"; - -int main(int argc, char *argv[]) { - - if (argc > 1) { - strcpy(src_addr, argv[1]); - } - - wiringPiSetup (); - pinMode (0, OUTPUT); - - //setSpiChannel(SPI_CHANNEL); - //setSpiSpeed(SPI_SPEED); - //initializeSpi(); - - FILE* config_file = fopen("sim.cfg","r"); - if (config_file == NULL) - { - printf("Creating config file."); - config_file = fopen("sim.cfg","w"); - fprintf(config_file, "%s %d", "KU2Y", 100); - fclose(config_file); - config_file = fopen("sim.cfg","r"); - } - - char* cfg_buf[100]; - fscanf(config_file, "%s %d", call, &reset_count); - fclose(config_file); - printf("%s %d\n", call, reset_count); - - reset_count = (reset_count + 1) % 0xffff; - - config_file = fopen("sim.cfg","w"); - fprintf(config_file, "%s %d", call, reset_count); - fclose(config_file); - config_file = fopen("sim.cfg","r"); - - tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); - - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); - sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); - - int ret; - uint8_t data[1024]; - - tx_freq_hz -= tx_channel * 50000; - - //init_rf(); - - ax25_init(&hax25, (uint8_t *) dest_addr, '1', (uint8_t *) src_addr, '1', - AX25_PREAMBLE_LEN, - AX25_POSTAMBLE_LEN); - -// socket open - int error = 0; - struct sockaddr_in address; - int valread; - struct sockaddr_in serv_addr; -// char *hello = "Hello from client"; -// char buffer[1024] = {0}; - if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) - { - printf("\n Socket creation error \n"); - error = 1; - } - - memset(&serv_addr, '0', sizeof(serv_addr)); - - serv_addr.sin_family = AF_INET; - serv_addr.sin_port = htons(PORT); - - // Convert IPv4 and IPv6 addresses from text to binary form - if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0) - { - printf("\nInvalid address/ Address not supported \n"); - error = 1; - } - - if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) - { - printf("\nConnection Failed \n"); - error = 1; - } - - /* Infinite loop */ - //for (;;) - - { - // sleep(1); // Delay 1 second - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Getting TLM Data\n"); - #endif - - char str[1000]; - // uint8_t b[64]; - char header_str[] = "\x03\xf0"; - strcpy(str, header_str); - - printf("%s-1>%s-1:", (uint8_t *)src_addr, (uint8_t *)dest_addr); - -// get_tlm(str); - get_tlm_fox(); - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Getting ready to send\n"); - #endif -/* - char cmdbuffer[1000]; - FILE* transmit; - if (FSK == 1) { - transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/CubeSatSim/rpitx/rpitx -i- -m RF -f 434.9e3 2>&1", "r"); - } else { - transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/CubeSatSim/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.9e6 -t float 2>&1", "r"); - } - fgets(cmdbuffer, 1000, transmit); - pclose(transmit); - printf("Results of transmit command: %s\n", cmdbuffer); -*/ - - -// printf("%s \n", b); -/* - digitalWrite (0, LOW); - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Transmitting X.25 packet\n"); - #endif - 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); - - if (ret) { - fprintf(stderr, - "ERROR: Failed to transmit entire AX.25 frame with error code %d\n", - ret); - exit(EXIT_FAILURE); - } -*/ - } - - return 0; -} - -static void init_rf() { - int ret; - #ifdef DEBUG_LOGGING - fprintf(stderr,"Initializing AX5043\n"); - #endif - 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 -// -int lower_digit(int number) { - - int digit = 0; - if (number < 100) - digit = number - ((int)(number/10) * 10); - else - fprintf(stderr,"ERROR: Not a digit in lower_digit!\n"); - return digit; -} - -// Returns upper digit of a number which must be less than 99 -// -int upper_digit(int number) { - - int digit = 0; - if (number < 100) - digit = (int)(number/10); - else - fprintf(stderr,"ERROR: Not a digit in upper_digit!\n"); - return digit; -} - -int get_tlm(char *str) { - - int tlm[7][5]; - memset(tlm, 0, sizeof tlm); - -// Reading I2C voltage and current sensors - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - count, reading[count].voltage, reading[count].current, reading[count].power); - #endif - } - - tlm[1][A] = (int)(reading[BUS].voltage /15.0 + 0.5) % 100; // Current of 5V supply to Pi - tlm[1][B] = (int) (99.5 - reading[PLUS_X].current/10.0) % 100; // +X current [4] - tlm[1][C] = (int) (99.5 - reading[MINUS_X].current/10.0) % 100; // X- current [10] - tlm[1][D] = (int) (99.5 - reading[PLUS_Y].current/10.0) % 100; // +Y current [7] - - tlm[2][A] = (int) (99.5 - reading[MINUS_Y].current/10.0) % 100; // -Y current [10] - tlm[2][B] = (int) (99.5 - reading[PLUS_Z].current/10.0) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel - tlm[2][C] = (int) (99.5 - reading[MINUS_Z].current/10.0) % 100; // -Z current (was timestamp) - tlm[2][D] = (int)(50.5 + reading[BAT].current/10.0) % 100; // NiMH Battery current - - tlm[3][A] = abs((int)((reading[BAT].voltage * 10.0) - 65.5) % 100); - tlm[3][B] = (int)(reading[BUS].voltage * 10.0) % 100; // 5V supply to Pi - - if (tempSensor.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); - uint8_t lower = (uint8_t) (tempValue & 0xff); - float temp = (float)lower + ((float)upper / 0x100); - - #ifdef DEBUG_LOGGING - printf("Temp Sensor Read: %6.1f\n", temp); - #endif - - tlm[4][A] = (int)((95.8 - temp)/1.48 + 0.5) % 100; - } - - FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); - if (cpuTempSensor) { - double cpuTemp; - fscanf (cpuTempSensor, "%lf", &cpuTemp); - cpuTemp /= 1000; - - #ifdef DEBUG_LOGGING - printf("CPU Temp Read: %6.1f\n", cpuTemp); - #endif - - tlm[4][B] = (int)((95.8 - cpuTemp)/1.48 + 0.5) % 100; - fclose (cpuTempSensor); - } - - tlm[6][B] = 0 ; - tlm[6][D] = 49 + rand() % 3; - - #ifdef DEBUG_LOGGING -// Display tlm - int k, j; - for (k = 1; k < 7; k++) { - for (j = 1; j < 5; j++) { - printf(" %2d ", tlm[k][j]); - } - printf("\n"); - } - #endif - - char tlm_str[1000]; - - char header_str[] = "hi hi "; - strcpy(str, header_str); -// printf("%s-1>%s-1:hi hi ", (uint8_t *)src_addr, (uint8_t *)dest_addr); - - int channel; - for (channel = 1; channel < 7; channel++) { - 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",tlm_str); - strcat(str, tlm_str); - } -// printf("\n"); - -return; -} - -int get_tlm_fox() { - -// memset(b, 0, 64); - -// Reading I2C voltage and current sensors - - FILE* uptime_file = fopen("/proc/uptime", "r"); - fscanf(uptime_file, "%f", &uptime_sec); - uptime = (int) uptime_sec; - printf("Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime); - fclose(uptime_file); - - int i; - long int sync = SYNC_WORD; - - smaller = S_RATE/(2 * freq_Hz); -/* - short int b[DATA_LEN] = {0x00,0x7E,0x03, - 0x00,0x00,0x00,0x00,0xE6,0x01,0x00,0x27,0xD1,0x02, - 0xE5,0x40,0x04,0x18,0xE1,0x04,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - - short int h[HEADER_LEN] = {0x05,0x00,0x00,0x00,0x00,0x10,0x00,0x00}; -*/ - - short int b[DATA_LEN]; - memset(b, 0, sizeof(b)); - - short int h[HEADER_LEN]; - memset(h, 0, sizeof(h)); - - short int b10[DATA_LEN], h10[HEADER_LEN]; - short int rs_frame[RS_FRAMES][223]; - unsigned char parities[RS_FRAMES][PARITY_LEN],inputByte; -/* - int id = 7, frm_type = 0x01, TxTemp = 0, IHUcpuTemp = 0; - int batt_a_v = 0, batt_b_v = 0, batt_c_v = 8.95 * 100, battCurr = 48.6 * 10; - int posXv = 296, negXv = 45, posYv = 220, negYv = 68, - posZv = 280, negZv = 78; -*/ - int id = 7, frm_type = 0x01, TxTemp = 0, IHUcpuTemp = 0; - int batt_a_v = 0, batt_b_v = 0, batt_c_v = 0, battCurr = 0; - int posXv = 0, negXv = 0, posYv = 0, negYv = 0, - posZv = 0, negZv = 0; - int head_offset = 0; - - for (int frames = 0; frames < FRAME_CNT; frames++) - { - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - count, reading[count].voltage, reading[count].current, reading[count].power); - #endif - } -/* - if (tempSensor.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); - uint8_t lower = (uint8_t) (tempValue & 0xff); - float temp = (float)lower + ((float)upper / 0x100); - - #ifdef DEBUG_LOGGING - printf("Temp Sensor Read: %6.1f\n", temp); - #endif - - TxTemp = (int)((temp * 10.0) + 0.5); - encodeB(b, 34 + head_offset, TxTemp); - } -*/ - FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); - if (cpuTempSensor) { - double cpuTemp; - fscanf (cpuTempSensor, "%lf", &cpuTemp); - cpuTemp /= 1000; - - #ifdef DEBUG_LOGGING - printf("CPU Temp Read: %6.1f\n", cpuTemp); - #endif - - IHUcpuTemp = (int)((cpuTemp * 10.0) + 0.5); - encodeA(b, 39 + head_offset, IHUcpuTemp); - } - sleep(1); - - memset(rs_frame,0,sizeof(rs_frame)); - memset(parities,0,sizeof(parities)); - - FILE *uptime_file = fopen("/proc/uptime", "r"); - fscanf(uptime_file, "%f", &uptime_sec); - uptime = (int) uptime_sec; - fclose(uptime_file); - printf("Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime); - - h[0] = (h[0] & 0xf8) | (id & 0x07); // 3 bits - printf("h[0] %x\n", h[0]); - h[0] = (h[0] & 0x07)| ((reset_count & 0x1f) << 3); - printf("h[0] %x\n", h[0]); - h[1] = (reset_count >> 5) & 0xff; - printf("h[1] %x\n", h[1]); - h[2] = (h[2] & 0xf8) | ((reset_count >> 13) & 0x07); - printf("h[2] %x\n", h[2]); - h[2] = (h[2] & 0x0e) | ((uptime & 0x1f) << 3); - printf("h[2] %x\n", h[2]); - h[3] = (uptime >> 5) & 0xff; - h[4] = (uptime >> 13) & 0xff; - h[5] = (h[5] & 0xf0) | ((uptime >> 21) & 0x0f); - h[5] = (h[5] & 0x0f) | (frm_type << 4); - - posXv = reading[PLUS_X].current * 10; - posYv = reading[PLUS_Y].current * 10; - posZv = reading[PLUS_Z].current * 10; - negXv = reading[MINUS_X].current * 10; - negYv = reading[MINUS_Y].current * 10; - negZv = reading[MINUS_Z].current * 10; - - batt_c_v = reading[BAT].voltage * 100; - battCurr = reading[BAT].current * 10; - - encodeA(b, 0 + head_offset, batt_a_v); - encodeB(b, 1 + head_offset, batt_b_v); - encodeA(b, 3 + head_offset, batt_c_v); - encodeA(b, 9 + head_offset, battCurr); - encodeA(b, 12 + head_offset,posXv); - encodeB(b, 13 + head_offset,posYv); - encodeA(b, 15 + head_offset,posZv); - encodeB(b, 16 + head_offset,negXv); - encodeA(b, 18 + head_offset,negYv); - encodeB(b, 19 + head_offset,negZv); - -/* batt_c_v += 10; - battCurr -= 10; - encodeA(b, 3 + head_offset, batt_c_v); - encodeA(b, 9 + head_offset, battCurr); -*/ - int ctr1 = 0; - int ctr3 = 0; - for (i = 0; i < RS_FRAME_LEN; i++) - { - for (int j = 0; j < RS_FRAMES ; j++) - { - if (!((i == (RS_FRAME_LEN - 1)) && (j == 2))) // skip last one for BPSK - { - if (ctr1 < HEADER_LEN) - { - rs_frame[j][i] = h[ctr1]; - update_rs(parities[j], h[ctr1]); - // printf("header %d rs_frame[%d][%d] = %x \n", ctr1, j, i, h[ctr1]); - data8[ctr1++] = rs_frame[j][i]; - // printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]); - } - else - { - rs_frame[j][i] = b[ctr3 % DATA_LEN]; - update_rs(parities[j], b[ctr3 % DATA_LEN]); - // printf("%d rs_frame[%d][%d] = %x %d \n", - // ctr1, j, i, b[ctr3 % DATA_LEN], ctr3 % DATA_LEN); - data8[ctr1++] = rs_frame[j][i]; - // printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]); - ctr3++; - } - } - } - } - - printf("Parities "); - for (int m = 0; m < PARITY_LEN; m++) { - printf("%d ", parities[0][m]); - } - printf("\n"); - - int ctr2 = 0; - memset(data10,0,sizeof(data10)); - int rd = 0; - int nrd; - - for (i = 0; i < DATA_LEN * PAYLOADS + HEADER_LEN; i++) // 476 for BPSK - { - data10[ctr2] = (Encode_8b10b[rd][((int)data8[ctr2])] & 0x3ff); - nrd = (Encode_8b10b[rd][((int)data8[ctr2])] >> 10) & 1; - // printf ("data10[%d] = encoded data8[%d] = %x \n", - // ctr2, ctr2, data10[ctr2]); - - rd = nrd; // ^ nrd; - ctr2++; - } - - for (i = 0; i < PARITY_LEN; i++) - { - for (int j = 0; j < RS_FRAMES; j++) - { - data10[ctr2++] = (Encode_8b10b[rd][((int)parities[j][i])] & 0x3ff); - nrd = (Encode_8b10b[rd][((int)parities[j][i])] >> 10) & 1; - // printf ("data10[%d] = encoded parities[%d][%d] = %x \n", - // ctr2 - 1, j, i, data10[ctr2 - 1]); - - rd = nrd; - } - } - - int data; - int val; - int offset = 0; - ctr = 0; - flip_ctr = 0; - phase = 1; - - for (i = 1; i <= SYNC_BITS * SAMPLES; i++) - { - write_wave(ctr); - if ( (i % SAMPLES) == 0) { - int bit = SYNC_BITS - i/SAMPLES + 1; - val = sync; - data = val & 1 << (bit - 1); - // printf ("%d i: %d new frame %d sync bit %d = %d \n", - // ctr/SAMPLES, i, frames, bit, (data > 0) ); - if (FSK) - { - phase = ((data != 0) * 2) - 1; - // printf("Sending a %d\n", phase); - } - else - { - if (data == 0) { - phase *= -1; - if ( (ctr - smaller) > 0) - { - for (int j = 1; j <= smaller; j++) - buffer[ctr - j] = buffer[ctr - j] * 0.4; - } - flip_ctr = ctr; - } - } - } - } - - for (i = 1; - i <= (10 * (HEADER_LEN + DATA_LEN * PAYLOADS + RS_FRAMES * PARITY_LEN) * SAMPLES); i++) // 572 - { - write_wave(ctr); - if ( (i % SAMPLES) == 0) { - int symbol = (int)((i - 1)/ (SAMPLES * 10)); - int bit = 10 - (i - symbol * SAMPLES * 10) / SAMPLES + 1; - val = data10[symbol]; - data = val & 1 << (bit - 1); - // printf ("%d i: %d new frame %d data10[%d] = %x bit %d = %d \n", - // ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) ); - if (FSK) - { - phase = ((data != 0) * 2) - 1; - // printf("Sending a %d\n", phase); - } - else - { - if (data == 0) { - phase *= -1; - if ( (ctr - smaller) > 0) - { - for (int j = 1; j <= smaller; j ++) - buffer[ctr - j] = buffer[ctr - j] * 0.4; - } - flip_ctr = ctr; - } - } - } - } - } -// write_wav("transmit.wav", BUF_LEN, buffer, S_RATE); - - int error = 0; - int count; - for (count = 0; count < DATA_LEN; count++) { - printf("%02X", b[count]); - } - printf("\n"); - -// socket write - - if (!error) - { - printf("Sending buffer over socket!\n"); - send(sock, buffer, sizeof(buffer), 0); - } - -sleep(20); - -return 0; -} - -// wav file generation code - -/* make_wav.c - * Creates a WAV file from an array of ints. - * Output is monophonic, signed 16-bit samples - * copyright - * Fri Jun 18 16:36:23 PDT 2010 Kevin Karplus - * Creative Commons license Attribution-NonCommercial - * http://creativecommons.org/licenses/by-nc/3.0/ - * - * Edited by Dolin Sergey. dlinyj@gmail.com - * April 11 12:58 2014 - */ - - // gcc -o make_enc_wav make_enc_wav.c -lm - // ./make_enc_wav - - /* - * TelemEncoding.h - * - * Created on: Feb 3, 2014 - * Author: fox - */ - -#include -#include -#include -#include -#include -#include - -//#include "make_wav.h" - -#define false 0 -#define true 1 - -//static int twosToInt(int val,int len); -//static int encodeB(short int *b, int index, int val); -//static int encodeA(short int *b, int index, int val); - - static int NOT_FRAME = /* 0fa */ 0xfa & 0x3ff; - static int FRAME = /* 0fa */ ~0xfa & 0x3ff; - -/* - * TelemEncoding.c - * - Fox-1 telemetry encoder - January 2014 Phil Karn KA9Q - - This file has two external functions: - void update_rs(unsigned char parity[32],unsigned char data); - int encode_8b10b(int *state,int data). - - update_rs() is the Reed-Solomon encoder. Its first argument is the 32-byte - encoder shift register, the second is the 8-bit data byte being encoded. It updates - the shift register in place and returns void. At the end of each frame, it contains - the parities ready for transmission, starting with parity[0]. - Be sure to zero this array before each new frame! - - encode_8b10b() is the 8b10b encoder. Its first argument is a pointer to a single integer - with the 1-bit encoder state (the current run disparity, or RD). Initialize it to 0 - JUST ONCE at startup (not between frames). - The second argument is the data byte being encoded. It updates the state and returns - an integer containing the 10-bit encoded word, right justified. - Transmit this word from left to right. - - The data argument is an int so it can hold the special value -1 to indicate end of frame; - it generates the 8b10b control word K.28.5, which is used as an inter-frame flag. - - Some assert() calls are made to verify legality of arguments. These can be turned off in - production code. - - - sample frame transmission code: - - unsigned char data[64]; // Data block to be sent - unsigned char parity[32]; // RS parities - void transmit_word(int); // User provided transmit function: 10 bits of data in bits 9....0 - int state,i; - - state = 0; // Only once at startup, not between frames - memset(parity,0,sizeof(parity); // Do this before every frame - // Transmit the data, updating the RS encoder - for(i=0;i<64;i++){ - update_rs(parity,data[i]); - transmit_word(encode_8b10b(&state,data[i]); - } - // Transmit the RS parities - for(i=0;i<32;i++) - transmit_word(encode_8b10b(&state,parity[i]); - - transmit_word(encode_8b10b(&state,-1); // Transmit end-of-frame flag -*/ - - -#include -//#include "Fox.h" -//#include "TelemEncoding.h" - -#ifndef NULL -#define NULL ((void *)0) -#endif - -#define NN (0xff) // Frame size in symbols -#define A0 (NN) // special value for log(0) - - -// GF Antilog lookup table table -static unsigned char CCSDS_alpha_to[NN+1] = { -0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x87,0x89,0x95,0xad,0xdd,0x3d,0x7a,0xf4, -0x6f,0xde,0x3b,0x76,0xec,0x5f,0xbe,0xfb,0x71,0xe2,0x43,0x86,0x8b,0x91,0xa5,0xcd, -0x1d,0x3a,0x74,0xe8,0x57,0xae,0xdb,0x31,0x62,0xc4,0x0f,0x1e,0x3c,0x78,0xf0,0x67, -0xce,0x1b,0x36,0x6c,0xd8,0x37,0x6e,0xdc,0x3f,0x7e,0xfc,0x7f,0xfe,0x7b,0xf6,0x6b, -0xd6,0x2b,0x56,0xac,0xdf,0x39,0x72,0xe4,0x4f,0x9e,0xbb,0xf1,0x65,0xca,0x13,0x26, -0x4c,0x98,0xb7,0xe9,0x55,0xaa,0xd3,0x21,0x42,0x84,0x8f,0x99,0xb5,0xed,0x5d,0xba, -0xf3,0x61,0xc2,0x03,0x06,0x0c,0x18,0x30,0x60,0xc0,0x07,0x0e,0x1c,0x38,0x70,0xe0, -0x47,0x8e,0x9b,0xb1,0xe5,0x4d,0x9a,0xb3,0xe1,0x45,0x8a,0x93,0xa1,0xc5,0x0d,0x1a, -0x34,0x68,0xd0,0x27,0x4e,0x9c,0xbf,0xf9,0x75,0xea,0x53,0xa6,0xcb,0x11,0x22,0x44, -0x88,0x97,0xa9,0xd5,0x2d,0x5a,0xb4,0xef,0x59,0xb2,0xe3,0x41,0x82,0x83,0x81,0x85, -0x8d,0x9d,0xbd,0xfd,0x7d,0xfa,0x73,0xe6,0x4b,0x96,0xab,0xd1,0x25,0x4a,0x94,0xaf, -0xd9,0x35,0x6a,0xd4,0x2f,0x5e,0xbc,0xff,0x79,0xf2,0x63,0xc6,0x0b,0x16,0x2c,0x58, -0xb0,0xe7,0x49,0x92,0xa3,0xc1,0x05,0x0a,0x14,0x28,0x50,0xa0,0xc7,0x09,0x12,0x24, -0x48,0x90,0xa7,0xc9,0x15,0x2a,0x54,0xa8,0xd7,0x29,0x52,0xa4,0xcf,0x19,0x32,0x64, -0xc8,0x17,0x2e,0x5c,0xb8,0xf7,0x69,0xd2,0x23,0x46,0x8c,0x9f,0xb9,0xf5,0x6d,0xda, -0x33,0x66,0xcc,0x1f,0x3e,0x7c,0xf8,0x77,0xee,0x5b,0xb6,0xeb,0x51,0xa2,0xc3,0x00, -}; - -// GF log lookup table. Special value represents log(0) -static unsigned char CCSDS_index_of[NN+1] = { - A0, 0, 1, 99, 2,198,100,106, 3,205,199,188,101,126,107, 42, - 4,141,206, 78,200,212,189,225,102,221,127, 49,108, 32, 43,243, - 5, 87,142,232,207,172, 79,131,201,217,213, 65,190,148,226,180, -103, 39,222,240,128,177, 50, 53,109, 69, 33, 18, 44, 13,244, 56, - 6,155, 88, 26,143,121,233,112,208,194,173,168, 80,117,132, 72, -202,252,218,138,214, 84, 66, 36,191,152,149,249,227, 94,181, 21, -104, 97, 40,186,223, 76,241, 47,129,230,178, 63, 51,238, 54, 16, -110, 24, 70,166, 34,136, 19,247, 45,184, 14, 61,245,164, 57, 59, - 7,158,156,157, 89,159, 27, 8,144, 9,122, 28,234,160,113, 90, -209, 29,195,123,174, 10,169,145, 81, 91,118,114,133,161, 73,235, -203,124,253,196,219, 30,139,210,215,146, 85,170, 67, 11, 37,175, -192,115,153,119,150, 92,250, 82,228,236, 95, 74,182,162, 22,134, -105,197, 98,254, 41,125,187,204,224,211, 77,140,242, 31, 48,220, -130,171,231, 86,179,147, 64,216, 52,176,239, 38, 55, 12, 17, 68, -111,120, 25,154, 71,116,167,193, 35, 83,137,251, 20, 93,248,151, - 46, 75,185, 96, 15,237, 62,229,246,135,165, 23, 58,163, 60,183, -}; - -// Only half the coefficients are given here because the -// generator polynomial is palindromic; G0 = G32, G1 = G31, etc. -// Only G16 is unique -static unsigned char CCSDS_poly[] = { - 0,249, 59, 66, 4, 43,126,251, 97, 30, 3,213, 50, 66,170, 5, - 24, -}; - - -static inline int modnn(int x){ - while (x >= NN) { - x -= NN; - x = (x >> 8) + (x & NN); - } - return x; -} - - -// Update Reed-Solomon encoder -// parity -> 32-byte reed-solomon encoder state; clear this to zero before each frame -void update_rs( - unsigned char parity[32], // 32-byte encoder state; zero before each frame - unsigned char c) // Current data byte to update -{ - unsigned char feedback; - int j,t; - - assert(parity != NULL); - feedback = CCSDS_index_of[c ^ parity[0]]; - if(feedback != A0){ // only if feedback is non-zero - // Take advantage of palindromic polynomial to halve the multiplies - // Do G1...G15, which is the same as G17...G31 - for(j=1;j0) - { buf = word & 0xff; - fwrite(&buf, 1,1, wav_file); - num_bytes--; - word >>= 8; - } -} - -/* information about the WAV file format from - -http://ccrma.stanford.edu/courses/422/projects/WaveFormat/ - - */ - -void write_wav(char * filename, unsigned long num_samples, short int * data, int s_rate) -{ - FILE* wav_file; - unsigned int sample_rate; - unsigned int num_channels; - unsigned int bytes_per_sample; - unsigned int byte_rate; - unsigned long i; /* counter for samples */ - - num_channels = 1; /* monoaural */ - bytes_per_sample = 2; - - if (s_rate<=0) sample_rate = 44100; - else sample_rate = (unsigned int) s_rate; - - byte_rate = sample_rate*num_channels*bytes_per_sample; - - wav_file = fopen(filename, "w"); - assert(wav_file); /* make sure it opened */ - - /* write RIFF header */ - fwrite("RIFF", 1, 4, wav_file); - write_little_endian(36 + bytes_per_sample* num_samples*num_channels, 4, wav_file); - fwrite("WAVE", 1, 4, wav_file); - - /* write fmt subchunk */ - fwrite("fmt ", 1, 4, wav_file); - write_little_endian(16, 4, wav_file); /* SubChunk1Size is 16 */ - write_little_endian(1, 2, wav_file); /* PCM is format 1 */ - write_little_endian(num_channels, 2, wav_file); - write_little_endian(sample_rate, 4, wav_file); - write_little_endian(byte_rate, 4, wav_file); - write_little_endian(num_channels*bytes_per_sample, 2, wav_file); /* block align */ - write_little_endian(8*bytes_per_sample, 2, wav_file); /* bits/sample */ - - /* write data subchunk */ - fwrite("data", 1, 4, wav_file); - write_little_endian(bytes_per_sample* num_samples*num_channels, 4, wav_file); - - for (i=0; i< num_samples; i++) - { write_little_endian((unsigned int)(data[i]),bytes_per_sample, wav_file); - } - - fclose(wav_file); -} - - - -//int main(int argc, char * argv[]) -//{ - -// return 0; -//} - -void write_wave(int i) -{ - if (FSK) - { -// if ((ctr - flip_ctr) < smaller) -// buffer[ctr++] = 0.1 * phase * (ctr - flip_ctr) / smaller; -// else - buffer[ctr++] = 0.25 * amplitude * phase; - } - else - { - if ((ctr - flip_ctr) < smaller) - buffer[ctr++] = (int)(amplitude * 0.4 * phase * - sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - else - buffer[ctr++] = (int)(amplitude * phase * - sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - } -// printf("%d %d \n", i, buffer[ctr - 1]); - -} - -/** - * - * FOX 1 Telemetry Decoder - * @author chris.e.thompson g0kla/ac2cz - * - * Copyright (C) 2015 amsat.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General License for more details. - * - * You should have received a copy of the GNU General License - * along with this program. If not, see . - * - * - * Static variables and methods to encode and decode 8b10b - * - * - */ - -int encodeA(short int *b, int index, int val) { -// printf("Encoding A\n"); - b[index] = val & 0xff; - b[index + 1] = (b[index + 1] & 0xf0) | ((val >> 8) & 0x0f); - return 0; -} - -int encodeB(short int *b, int index, int val) { -// printf("Encoding B\n"); - b[index] = (b[index] & 0x0f) | ((val << 4) & 0xf0); - b[index + 1] = (val >> 4 ) & 0xff; - return 0; -} - -int twosToInt(int val,int len) { // Convert twos compliment to integer -// from https://www.raspberrypi.org/forums/viewtopic.php?t=55815 - - if(val & (1 << (len - 1))) - val = val - (1 << len); - - return(val); -} From fa10e3d9787b35a9048b5d578cc09b7b2a0fbef4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 12:13:27 -0400 Subject: [PATCH 136/150] Delete make_wav.h --- afsk/make_wav.h | 562 ------------------------------------------------ 1 file changed, 562 deletions(-) delete mode 100644 afsk/make_wav.h diff --git a/afsk/make_wav.h b/afsk/make_wav.h deleted file mode 100644 index 4b78c660..00000000 --- a/afsk/make_wav.h +++ /dev/null @@ -1,562 +0,0 @@ -/* make_wav.h - * Fri Jun 18 17:06:02 PDT 2010 Kevin Karplus - */ - -#ifndef MAKE_WAV_H -#define MAKE_WAV_H - -void write_wav(char * filename, unsigned long num_samples, short int * data, int s_rate); - /* open a file named filename, write signed 16-bit values as a - monoaural WAV file at the specified sampling rate - and close the file - */ - -#endif - -/* - * TelemEncoding.h - * - * Created on: Feb 3, 2014 - * Author: fox - */ - -#ifndef TELEMENCODING_H_ -#define TELEMENCODING_H_ - -void update_rs( - unsigned char parity[32], // 32-byte encoder state; zero before each frame - unsigned char c // Current data byte to update -); - -#define CHARACTER_BITS 10 -#define CHARACTERS_PER_LONGWORD 3 -#define CHARACTER_MASK ((1< Date: Sat, 5 Sep 2020 12:13:37 -0400 Subject: [PATCH 137/150] Delete main_old.c --- afsk/main_old.c | 1144 ----------------------------------------------- 1 file changed, 1144 deletions(-) delete mode 100644 afsk/main_old.c diff --git a/afsk/main_old.c b/afsk/main_old.c deleted file mode 100644 index 5d43b46f..00000000 --- a/afsk/main_old.c +++ /dev/null @@ -1,1144 +0,0 @@ -/* - * Transmits CubeSat Telemetry at 434.9MHz in AO-7 format - * - * Copyright Alan B. Johnston - * - * Portions Copyright (C) 2018 Jonathan Brandenburg - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * INA219 Raspberry Pi wiringPi code is based on Adafruit Arduino wire code - * from https://github.com/adafruit/Adafruit_INA219. - */ - -#include -#include -#include -#include -#include -#include "status.h" -#include "ax5043.h" -#include "ax25.h" -#include "spi/ax5043spi.h" -#include -#include -#include -#include -#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino -#include "make_wav.h" -#include -#include -#include -#include -#include -#define PORT 8080 - -#define A 1 -#define B 2 -#define C 3 -#define D 4 - -#define PLUS_X 0 -#define PLUS_Y 1 -#define PLUS_Z 2 -#define BAT 3 -#define MINUS_X 4 -#define MINUS_Y 5 -#define MINUS_Z 6 -#define BUS 7 -#define OFF -1 - -uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET; -uint32_t tx_channel = 0; - -ax5043_conf_t hax5043; -ax25_conf_t hax25; - -static void init_rf(); -int twosToInt(int val, int len); -int get_tlm(char *str); -int get_tlm_fox(); -int encodeA(short int *b, int index, int val); -int encodeB(short int *b, int index, int val); -void config_x25(); -void trans_x25(); -int upper_digit(int number); -int lower_digit(int number); - -#define S_RATE (48000) // (44100) -#define BUF_SIZE (S_RATE*10) /* 2 second buffer */ -/* -// BPSK Settings -#define BIT_RATE 1200 // 200 for DUV -#define FSK 0 // 1 for DUV -#define RS_FRAMES 3 // 3 frames for BPSK, 1 for DUV -#define PAYLOADS 6 // 1 for DUV -#define DATA_LEN 78 // 56 for DUV -#define RS_FRAME_LEN 159 // 64 for DUV -#define SYNC_BITS 31 // 10 for DUV -#define SYNC_WORD 0b1000111110011010010000101011101 // 0b0011111010 for DUV -#define HEADER_LEN 8 // 6 for DUV -*/ -// FSK Settings -#define BIT_RATE 200 -#define FSK 1 -#define RS_FRAMES 1 -#define PAYLOADS 1 -#define RS_FRAME_LEN 64 -#define HEADER_LEN 6 -#define DATA_LEN 58 -#define SYNC_BITS 10 -#define SYNC_WORD 0b0011111010 - - -#define PARITY_LEN 32 - -float amplitude = 32767/3; // 20000; // 32767/(10%amp+5%amp+100%amp) -float freq_Hz = 3000; // 1200 - -int smaller; -int flip_ctr = 0; -int phase = 1; -int ctr = 0; -void write_to_buffer(int i, int symbol, int val); -void write_wave(); -#define SAMPLES (S_RATE / BIT_RATE) -#define FRAME_CNT 60// 11 //33 // Add 3 frames to the count - -//#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (8 + 6 * DATA_LEN + 96)) * SAMPLES) -#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (HEADER_LEN + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN))) * SAMPLES) -short int buffer[BUF_LEN]; -short int data10[8 + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN)]; -short int data8[8 + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN)]; -int reset_count; -float uptime_sec; -long int uptime; -char call[5]; - -struct SensorConfig { - int fd; - uint16_t config; - int calValue; - int powerMultiplier; - int currentDivider; -}; - -struct SensorData { - double current; - double voltage; - double power; -}; - -/** - * @brief Read the data from one of the i2c current sensors. - * - * Reads the current data from the requested i2c current sensor configuration and - * stores it into a SensorData struct. An invalid file descriptor (i.e. less than zero) - * results in a SensorData struct being returned that has both its #current and #power members - * set to NAN. - * - * @param sensor A structure containing sensor configuration including the file descriptor. - * @return struct SensorData A struct that contains the current, voltage, and power readings - * from the requested sensor. - */ -struct SensorData read_sensor_data(struct SensorConfig sensor) { - struct SensorData data = { - .current = NAN, - .voltage = NAN, - .power = NAN }; - - if (sensor.fd < 0) { - return data; - } - // doesn't read negative currents accurately, shows -0.1mA - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - int value = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - data.current = (float) twosToInt(value, 16) / (float) sensor.currentDivider; - - wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); - delay(1); // Max 12-bit conversion time is 586us per sample - value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); - data.voltage = ((float)(value >> 3) * 4) / 1000; - // power has very low resolution, seems to step in 512mW values - data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; - - return data; -} - -/** - * @brief Configures an i2c current sensor. - * - * Calculates the configuration values of the i2c sensor so that - * current, voltage, and power can be read using read_sensor_data. - * Supports 16V 400mA and 16V 2.0A settings. - * - * @param sensor A file descriptor that can be used to read from the sensor. - * @param milliAmps The mA configuration, either 400mA or 2A are supported. - * @return struct SensorConfig A struct that contains the configuraton of the sensor. - */ -//struct SensorConfig config_sensor(int sensor, int milliAmps) { -struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { - struct SensorConfig data; - - if (access(bus, W_OK | R_OK) < 0) { // Test if I2C Bus is missing - printf("ERROR: %s bus not present \n", bus); - data.fd = OFF; - return (data); - } - - data.fd = wiringPiI2CSetupInterface(bus, address); - - data.config = INA219_CONFIG_BVOLTAGERANGE_32V | - INA219_CONFIG_GAIN_1_40MV | - INA219_CONFIG_BADCRES_12BIT | - INA219_CONFIG_SADCRES_12BIT_1S_532US | - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; - - if (milliAmps == 400) { // INA219 16V 400mA configuration - data.calValue = 8192; - data.powerMultiplier = 1; - data.currentDivider = 20; // 40; in Adafruit config - } - else { // INA219 16V 2A configuration - data.calValue = 40960; - data.powerMultiplier = 2; - data.currentDivider = 10; // 20; in Adafruit config - } - - #ifdef DEBUG_LOGGING - printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd, - data.config, data.calValue, data.currentDivider, data.powerMultiplier); - #endif - return data; -} - -struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorConfig tempSensor; - -char src_addr[5] = ""; -char dest_addr[5] = "CQ"; - -int main(int argc, char *argv[]) { - - if (argc > 1) { - strcpy(src_addr, argv[1]); - } - - wiringPiSetup (); - pinMode (0, OUTPUT); - - //setSpiChannel(SPI_CHANNEL); - //setSpiSpeed(SPI_SPEED); - //initializeSpi(); - - FILE* config_file = fopen("sim.cfg","r"); - if (config_file == NULL) - { - printf("Creating config file."); - config_file = fopen("sim.cfg","w"); - fprintf(config_file, "%s %d", "KU2Y", 100); - fclose(config_file); - config_file = fopen("sim.cfg","r"); - } - - char* cfg_buf[100]; - fscanf(config_file, "%s %d", call, &reset_count); - fclose(config_file); - printf("%s %d\n", call, reset_count); - - reset_count = (reset_count + 1) % 0xffff; - - config_file = fopen("sim.cfg","w"); - fprintf(config_file, "%s %d", call, reset_count); - fclose(config_file); - config_file = fopen("sim.cfg","r"); - - tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); - - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); - sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); - - int ret; - uint8_t data[1024]; - - tx_freq_hz -= tx_channel * 50000; - - //init_rf(); - - ax25_init(&hax25, (uint8_t *) dest_addr, '1', (uint8_t *) src_addr, '1', - AX25_PREAMBLE_LEN, - AX25_POSTAMBLE_LEN); - - /* Infinite loop */ - //for (;;) - - { - // sleep(1); // Delay 1 second - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Getting TLM Data\n"); - #endif - - char str[1000]; - // uint8_t b[64]; - char header_str[] = "\x03\xf0"; - strcpy(str, header_str); - - printf("%s-1>%s-1:", (uint8_t *)src_addr, (uint8_t *)dest_addr); - -// get_tlm(str); - get_tlm_fox(); - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Getting ready to send\n"); - #endif -/* - char cmdbuffer[1000]; - FILE* transmit; - if (FSK == 1) { - transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/CubeSatSim/rpitx/rpitx -i- -m RF -f 434.9e3 2>&1", "r"); - } else { - transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/CubeSatSim/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.9e6 -t float 2>&1", "r"); - } - fgets(cmdbuffer, 1000, transmit); - pclose(transmit); - printf("Results of transmit command: %s\n", cmdbuffer); -*/ - - -// printf("%s \n", b); -/* - digitalWrite (0, LOW); - - #ifdef DEBUG_LOGGING - fprintf(stderr,"INFO: Transmitting X.25 packet\n"); - #endif - 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); - - if (ret) { - fprintf(stderr, - "ERROR: Failed to transmit entire AX.25 frame with error code %d\n", - ret); - exit(EXIT_FAILURE); - } -*/ - } - - return 0; -} - -static void init_rf() { - int ret; - #ifdef DEBUG_LOGGING - fprintf(stderr,"Initializing AX5043\n"); - #endif - 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 -// -int lower_digit(int number) { - - int digit = 0; - if (number < 100) - digit = number - ((int)(number/10) * 10); - else - fprintf(stderr,"ERROR: Not a digit in lower_digit!\n"); - return digit; -} - -// Returns upper digit of a number which must be less than 99 -// -int upper_digit(int number) { - - int digit = 0; - if (number < 100) - digit = (int)(number/10); - else - fprintf(stderr,"ERROR: Not a digit in upper_digit!\n"); - return digit; -} - -int get_tlm(char *str) { - - int tlm[7][5]; - memset(tlm, 0, sizeof tlm); - -// Reading I2C voltage and current sensors - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - count, reading[count].voltage, reading[count].current, reading[count].power); - #endif - } - - tlm[1][A] = (int)(reading[BUS].voltage /15.0 + 0.5) % 100; // Current of 5V supply to Pi - tlm[1][B] = (int) (99.5 - reading[PLUS_X].current/10.0) % 100; // +X current [4] - tlm[1][C] = (int) (99.5 - reading[MINUS_X].current/10.0) % 100; // X- current [10] - tlm[1][D] = (int) (99.5 - reading[PLUS_Y].current/10.0) % 100; // +Y current [7] - - tlm[2][A] = (int) (99.5 - reading[MINUS_Y].current/10.0) % 100; // -Y current [10] - tlm[2][B] = (int) (99.5 - reading[PLUS_Z].current/10.0) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel - tlm[2][C] = (int) (99.5 - reading[MINUS_Z].current/10.0) % 100; // -Z current (was timestamp) - tlm[2][D] = (int)(50.5 + reading[BAT].current/10.0) % 100; // NiMH Battery current - - tlm[3][A] = abs((int)((reading[BAT].voltage * 10.0) - 65.5) % 100); - tlm[3][B] = (int)(reading[BUS].voltage * 10.0) % 100; // 5V supply to Pi - - if (tempSensor.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); - uint8_t lower = (uint8_t) (tempValue & 0xff); - float temp = (float)lower + ((float)upper / 0x100); - - #ifdef DEBUG_LOGGING - printf("Temp Sensor Read: %6.1f\n", temp); - #endif - - tlm[4][A] = (int)((95.8 - temp)/1.48 + 0.5) % 100; - } - - FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); - if (cpuTempSensor) { - double cpuTemp; - fscanf (cpuTempSensor, "%lf", &cpuTemp); - cpuTemp /= 1000; - - #ifdef DEBUG_LOGGING - printf("CPU Temp Read: %6.1f\n", cpuTemp); - #endif - - tlm[4][B] = (int)((95.8 - cpuTemp)/1.48 + 0.5) % 100; - fclose (cpuTempSensor); - } - - tlm[6][B] = 0 ; - tlm[6][D] = 49 + rand() % 3; - - #ifdef DEBUG_LOGGING -// Display tlm - int k, j; - for (k = 1; k < 7; k++) { - for (j = 1; j < 5; j++) { - printf(" %2d ", tlm[k][j]); - } - printf("\n"); - } - #endif - - char tlm_str[1000]; - - char header_str[] = "hi hi "; - strcpy(str, header_str); -// printf("%s-1>%s-1:hi hi ", (uint8_t *)src_addr, (uint8_t *)dest_addr); - - int channel; - for (channel = 1; channel < 7; channel++) { - 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",tlm_str); - strcat(str, tlm_str); - } -// printf("\n"); - -return; -} - -int get_tlm_fox() { - -// memset(b, 0, 64); - -// Reading I2C voltage and current sensors - - FILE* uptime_file = fopen("/proc/uptime", "r"); - fscanf(uptime_file, "%f", &uptime_sec); - uptime = (int) uptime_sec; - printf("Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime); - fclose(uptime_file); - - int i; - long int sync = SYNC_WORD; - - smaller = S_RATE/(2 * freq_Hz); -/* - short int b[DATA_LEN] = {0x00,0x7E,0x03, - 0x00,0x00,0x00,0x00,0xE6,0x01,0x00,0x27,0xD1,0x02, - 0xE5,0x40,0x04,0x18,0xE1,0x04,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - - short int h[HEADER_LEN] = {0x05,0x00,0x00,0x00,0x00,0x10,0x00,0x00}; -*/ - - short int b[DATA_LEN]; - memset(b, 0, sizeof(b)); - - short int h[HEADER_LEN]; - memset(h, 0, sizeof(h)); - - short int b10[DATA_LEN], h10[HEADER_LEN]; - short int rs_frame[RS_FRAMES][223]; - unsigned char parities[RS_FRAMES][PARITY_LEN],inputByte; -/* - int id = 7, frm_type = 0x01, TxTemp = 0, IHUcpuTemp = 0; - int batt_a_v = 0, batt_b_v = 0, batt_c_v = 8.95 * 100, battCurr = 48.6 * 10; - int posXv = 296, negXv = 45, posYv = 220, negYv = 68, - posZv = 280, negZv = 78; -*/ - int id = 7, frm_type = 0x01, TxTemp = 0, IHUcpuTemp = 0; - int batt_a_v = 0, batt_b_v = 0, batt_c_v = 0, battCurr = 0; - int posXv = 0, negXv = 0, posYv = 0, negYv = 0, - posZv = 0, negZv = 0; - int head_offset = 0; - - for (int frames = 0; frames < FRAME_CNT; frames++) - { - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - count, reading[count].voltage, reading[count].current, reading[count].power); - #endif - } -/* - if (tempSensor.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); - uint8_t lower = (uint8_t) (tempValue & 0xff); - float temp = (float)lower + ((float)upper / 0x100); - - #ifdef DEBUG_LOGGING - printf("Temp Sensor Read: %6.1f\n", temp); - #endif - - TxTemp = (int)((temp * 10.0) + 0.5); - encodeB(b, 34 + head_offset, TxTemp); - } -*/ - FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); - if (cpuTempSensor) { - double cpuTemp; - fscanf (cpuTempSensor, "%lf", &cpuTemp); - cpuTemp /= 1000; - - #ifdef DEBUG_LOGGING - printf("CPU Temp Read: %6.1f\n", cpuTemp); - #endif - - IHUcpuTemp = (int)((cpuTemp * 10.0) + 0.5); - encodeA(b, 39 + head_offset, IHUcpuTemp); - } - sleep(1); - - memset(rs_frame,0,sizeof(rs_frame)); - memset(parities,0,sizeof(parities)); - - FILE *uptime_file = fopen("/proc/uptime", "r"); - fscanf(uptime_file, "%f", &uptime_sec); - uptime = (int) uptime_sec; - fclose(uptime_file); - printf("Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime); - - h[0] = (h[0] & 0xf8) | (id & 0x07); // 3 bits - printf("h[0] %x\n", h[0]); - h[0] = (h[0] & 0x07)| ((reset_count & 0x1f) << 3); - printf("h[0] %x\n", h[0]); - h[1] = (reset_count >> 5) & 0xff; - printf("h[1] %x\n", h[1]); - h[2] = (h[2] & 0xf8) | ((reset_count >> 13) & 0x07); - printf("h[2] %x\n", h[2]); - h[2] = (h[2] & 0x0e) | ((uptime & 0x1f) << 3); - printf("h[2] %x\n", h[2]); - h[3] = (uptime >> 5) & 0xff; - h[4] = (uptime >> 13) & 0xff; - h[5] = (h[5] & 0xf0) | ((uptime >> 21) & 0x0f); - h[5] = (h[5] & 0x0f) | (frm_type << 4); - - posXv = reading[PLUS_X].current * 10; - posYv = reading[PLUS_Y].current * 10; - posZv = reading[PLUS_Z].current * 10; - negXv = reading[MINUS_X].current * 10; - negYv = reading[MINUS_Y].current * 10; - negZv = reading[MINUS_Z].current * 10; - - batt_c_v = reading[BAT].voltage * 100; - battCurr = reading[BAT].current * 10; - - encodeA(b, 0 + head_offset, batt_a_v); - encodeB(b, 1 + head_offset, batt_b_v); - encodeA(b, 3 + head_offset, batt_c_v); - encodeA(b, 9 + head_offset, battCurr); - encodeA(b, 12 + head_offset,posXv); - encodeB(b, 13 + head_offset,posYv); - encodeA(b, 15 + head_offset,posZv); - encodeB(b, 16 + head_offset,negXv); - encodeA(b, 18 + head_offset,negYv); - encodeB(b, 19 + head_offset,negZv); - -/* batt_c_v += 10; - battCurr -= 10; - encodeA(b, 3 + head_offset, batt_c_v); - encodeA(b, 9 + head_offset, battCurr); -*/ - int ctr1 = 0; - int ctr3 = 0; - for (i = 0; i < RS_FRAME_LEN; i++) - { - for (int j = 0; j < RS_FRAMES ; j++) - { - if (!((i == (RS_FRAME_LEN - 1)) && (j == 2))) // skip last one for BPSK - { - if (ctr1 < HEADER_LEN) - { - rs_frame[j][i] = h[ctr1]; - update_rs(parities[j], h[ctr1]); - // printf("header %d rs_frame[%d][%d] = %x \n", ctr1, j, i, h[ctr1]); - data8[ctr1++] = rs_frame[j][i]; - // printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]); - } - else - { - rs_frame[j][i] = b[ctr3 % DATA_LEN]; - update_rs(parities[j], b[ctr3 % DATA_LEN]); - // printf("%d rs_frame[%d][%d] = %x %d \n", - // ctr1, j, i, b[ctr3 % DATA_LEN], ctr3 % DATA_LEN); - data8[ctr1++] = rs_frame[j][i]; - // printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]); - ctr3++; - } - } - } - } - - printf("Parities "); - for (int m = 0; m < PARITY_LEN; m++) { - printf("%d ", parities[0][m]); - } - printf("\n"); - - int ctr2 = 0; - memset(data10,0,sizeof(data10)); - int rd = 0; - int nrd; - - for (i = 0; i < DATA_LEN * PAYLOADS + HEADER_LEN; i++) // 476 for BPSK - { - data10[ctr2] = (Encode_8b10b[rd][((int)data8[ctr2])] & 0x3ff); - nrd = (Encode_8b10b[rd][((int)data8[ctr2])] >> 10) & 1; - // printf ("data10[%d] = encoded data8[%d] = %x \n", - // ctr2, ctr2, data10[ctr2]); - - rd = nrd; // ^ nrd; - ctr2++; - } - - for (i = 0; i < PARITY_LEN; i++) - { - for (int j = 0; j < RS_FRAMES; j++) - { - data10[ctr2++] = (Encode_8b10b[rd][((int)parities[j][i])] & 0x3ff); - nrd = (Encode_8b10b[rd][((int)parities[j][i])] >> 10) & 1; - // printf ("data10[%d] = encoded parities[%d][%d] = %x \n", - // ctr2 - 1, j, i, data10[ctr2 - 1]); - - rd = nrd; - } - } - - int data; - int val; - int offset = 0; - - for (i = 1; i <= SYNC_BITS * SAMPLES; i++) - { - write_wave(ctr); - if ( (i % SAMPLES) == 0) { - int bit = SYNC_BITS - i/SAMPLES + 1; - val = sync; - data = val & 1 << (bit - 1); - // printf ("%d i: %d new frame %d sync bit %d = %d \n", - // ctr/SAMPLES, i, frames, bit, (data > 0) ); - if (FSK) - { - phase = ((data != 0) * 2) - 1; - // printf("Sending a %d\n", phase); - } - else - { - if (data == 0) { - phase *= -1; - if ( (ctr - smaller) > 0) - { - for (int j = 1; j <= smaller; j++) - buffer[ctr - j] = buffer[ctr - j] * 0.4; - } - flip_ctr = ctr; - } - } - } - } - - for (i = 1; - i <= (10 * (HEADER_LEN + DATA_LEN * PAYLOADS + RS_FRAMES * PARITY_LEN) * SAMPLES); i++) // 572 - { - write_wave(ctr); - if ( (i % SAMPLES) == 0) { - int symbol = (int)((i - 1)/ (SAMPLES * 10)); - int bit = 10 - (i - symbol * SAMPLES * 10) / SAMPLES + 1; - val = data10[symbol]; - data = val & 1 << (bit - 1); - // printf ("%d i: %d new frame %d data10[%d] = %x bit %d = %d \n", - // ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) ); - if (FSK) - { - phase = ((data != 0) * 2) - 1; - // printf("Sending a %d\n", phase); - } - else - { - if (data == 0) { - phase *= -1; - if ( (ctr - smaller) > 0) - { - for (int j = 1; j <= smaller; j ++) - buffer[ctr - j] = buffer[ctr - j] * 0.4; - } - flip_ctr = ctr; - } - } - } - } - } -// write_wav("transmit.wav", BUF_LEN, buffer, S_RATE); - - int error = 0; - int count; - for (count = 0; count < DATA_LEN; count++) { - printf("%02X", b[count]); - } - printf("\n"); - -// socket write - - struct sockaddr_in address; - int sock = 0, valread; - struct sockaddr_in serv_addr; -// char *hello = "Hello from client"; -// char buffer[1024] = {0}; - if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) - { - printf("\n Socket creation error \n"); - error = 1; - } - - memset(&serv_addr, '0', sizeof(serv_addr)); - - serv_addr.sin_family = AF_INET; - serv_addr.sin_port = htons(PORT); - - // Convert IPv4 and IPv6 addresses from text to binary form - if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0) - { - printf("\nInvalid address/ Address not supported \n"); - error = 1; - } - - if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) - { - printf("\nConnection Failed \n"); - error = 1; - } - - if (!error) - { - printf("Sending buffer over socket!\n"); - send(sock, buffer, sizeof(buffer), 0); - } - -return 0; -} - -// wav file generation code - -/* make_wav.c - * Creates a WAV file from an array of ints. - * Output is monophonic, signed 16-bit samples - * copyright - * Fri Jun 18 16:36:23 PDT 2010 Kevin Karplus - * Creative Commons license Attribution-NonCommercial - * http://creativecommons.org/licenses/by-nc/3.0/ - * - * Edited by Dolin Sergey. dlinyj@gmail.com - * April 11 12:58 2014 - */ - - // gcc -o make_enc_wav make_enc_wav.c -lm - // ./make_enc_wav - - /* - * TelemEncoding.h - * - * Created on: Feb 3, 2014 - * Author: fox - */ - -#include -#include -#include -#include -#include -#include - -//#include "make_wav.h" - -#define false 0 -#define true 1 - -//static int twosToInt(int val,int len); -//static int encodeB(short int *b, int index, int val); -//static int encodeA(short int *b, int index, int val); - - static int NOT_FRAME = /* 0fa */ 0xfa & 0x3ff; - static int FRAME = /* 0fa */ ~0xfa & 0x3ff; - -/* - * TelemEncoding.c - * - Fox-1 telemetry encoder - January 2014 Phil Karn KA9Q - - This file has two external functions: - void update_rs(unsigned char parity[32],unsigned char data); - int encode_8b10b(int *state,int data). - - update_rs() is the Reed-Solomon encoder. Its first argument is the 32-byte - encoder shift register, the second is the 8-bit data byte being encoded. It updates - the shift register in place and returns void. At the end of each frame, it contains - the parities ready for transmission, starting with parity[0]. - Be sure to zero this array before each new frame! - - encode_8b10b() is the 8b10b encoder. Its first argument is a pointer to a single integer - with the 1-bit encoder state (the current run disparity, or RD). Initialize it to 0 - JUST ONCE at startup (not between frames). - The second argument is the data byte being encoded. It updates the state and returns - an integer containing the 10-bit encoded word, right justified. - Transmit this word from left to right. - - The data argument is an int so it can hold the special value -1 to indicate end of frame; - it generates the 8b10b control word K.28.5, which is used as an inter-frame flag. - - Some assert() calls are made to verify legality of arguments. These can be turned off in - production code. - - - sample frame transmission code: - - unsigned char data[64]; // Data block to be sent - unsigned char parity[32]; // RS parities - void transmit_word(int); // User provided transmit function: 10 bits of data in bits 9....0 - int state,i; - - state = 0; // Only once at startup, not between frames - memset(parity,0,sizeof(parity); // Do this before every frame - // Transmit the data, updating the RS encoder - for(i=0;i<64;i++){ - update_rs(parity,data[i]); - transmit_word(encode_8b10b(&state,data[i]); - } - // Transmit the RS parities - for(i=0;i<32;i++) - transmit_word(encode_8b10b(&state,parity[i]); - - transmit_word(encode_8b10b(&state,-1); // Transmit end-of-frame flag -*/ - - -#include -//#include "Fox.h" -//#include "TelemEncoding.h" - -#ifndef NULL -#define NULL ((void *)0) -#endif - -#define NN (0xff) // Frame size in symbols -#define A0 (NN) // special value for log(0) - - -// GF Antilog lookup table table -static unsigned char CCSDS_alpha_to[NN+1] = { -0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x87,0x89,0x95,0xad,0xdd,0x3d,0x7a,0xf4, -0x6f,0xde,0x3b,0x76,0xec,0x5f,0xbe,0xfb,0x71,0xe2,0x43,0x86,0x8b,0x91,0xa5,0xcd, -0x1d,0x3a,0x74,0xe8,0x57,0xae,0xdb,0x31,0x62,0xc4,0x0f,0x1e,0x3c,0x78,0xf0,0x67, -0xce,0x1b,0x36,0x6c,0xd8,0x37,0x6e,0xdc,0x3f,0x7e,0xfc,0x7f,0xfe,0x7b,0xf6,0x6b, -0xd6,0x2b,0x56,0xac,0xdf,0x39,0x72,0xe4,0x4f,0x9e,0xbb,0xf1,0x65,0xca,0x13,0x26, -0x4c,0x98,0xb7,0xe9,0x55,0xaa,0xd3,0x21,0x42,0x84,0x8f,0x99,0xb5,0xed,0x5d,0xba, -0xf3,0x61,0xc2,0x03,0x06,0x0c,0x18,0x30,0x60,0xc0,0x07,0x0e,0x1c,0x38,0x70,0xe0, -0x47,0x8e,0x9b,0xb1,0xe5,0x4d,0x9a,0xb3,0xe1,0x45,0x8a,0x93,0xa1,0xc5,0x0d,0x1a, -0x34,0x68,0xd0,0x27,0x4e,0x9c,0xbf,0xf9,0x75,0xea,0x53,0xa6,0xcb,0x11,0x22,0x44, -0x88,0x97,0xa9,0xd5,0x2d,0x5a,0xb4,0xef,0x59,0xb2,0xe3,0x41,0x82,0x83,0x81,0x85, -0x8d,0x9d,0xbd,0xfd,0x7d,0xfa,0x73,0xe6,0x4b,0x96,0xab,0xd1,0x25,0x4a,0x94,0xaf, -0xd9,0x35,0x6a,0xd4,0x2f,0x5e,0xbc,0xff,0x79,0xf2,0x63,0xc6,0x0b,0x16,0x2c,0x58, -0xb0,0xe7,0x49,0x92,0xa3,0xc1,0x05,0x0a,0x14,0x28,0x50,0xa0,0xc7,0x09,0x12,0x24, -0x48,0x90,0xa7,0xc9,0x15,0x2a,0x54,0xa8,0xd7,0x29,0x52,0xa4,0xcf,0x19,0x32,0x64, -0xc8,0x17,0x2e,0x5c,0xb8,0xf7,0x69,0xd2,0x23,0x46,0x8c,0x9f,0xb9,0xf5,0x6d,0xda, -0x33,0x66,0xcc,0x1f,0x3e,0x7c,0xf8,0x77,0xee,0x5b,0xb6,0xeb,0x51,0xa2,0xc3,0x00, -}; - -// GF log lookup table. Special value represents log(0) -static unsigned char CCSDS_index_of[NN+1] = { - A0, 0, 1, 99, 2,198,100,106, 3,205,199,188,101,126,107, 42, - 4,141,206, 78,200,212,189,225,102,221,127, 49,108, 32, 43,243, - 5, 87,142,232,207,172, 79,131,201,217,213, 65,190,148,226,180, -103, 39,222,240,128,177, 50, 53,109, 69, 33, 18, 44, 13,244, 56, - 6,155, 88, 26,143,121,233,112,208,194,173,168, 80,117,132, 72, -202,252,218,138,214, 84, 66, 36,191,152,149,249,227, 94,181, 21, -104, 97, 40,186,223, 76,241, 47,129,230,178, 63, 51,238, 54, 16, -110, 24, 70,166, 34,136, 19,247, 45,184, 14, 61,245,164, 57, 59, - 7,158,156,157, 89,159, 27, 8,144, 9,122, 28,234,160,113, 90, -209, 29,195,123,174, 10,169,145, 81, 91,118,114,133,161, 73,235, -203,124,253,196,219, 30,139,210,215,146, 85,170, 67, 11, 37,175, -192,115,153,119,150, 92,250, 82,228,236, 95, 74,182,162, 22,134, -105,197, 98,254, 41,125,187,204,224,211, 77,140,242, 31, 48,220, -130,171,231, 86,179,147, 64,216, 52,176,239, 38, 55, 12, 17, 68, -111,120, 25,154, 71,116,167,193, 35, 83,137,251, 20, 93,248,151, - 46, 75,185, 96, 15,237, 62,229,246,135,165, 23, 58,163, 60,183, -}; - -// Only half the coefficients are given here because the -// generator polynomial is palindromic; G0 = G32, G1 = G31, etc. -// Only G16 is unique -static unsigned char CCSDS_poly[] = { - 0,249, 59, 66, 4, 43,126,251, 97, 30, 3,213, 50, 66,170, 5, - 24, -}; - - -static inline int modnn(int x){ - while (x >= NN) { - x -= NN; - x = (x >> 8) + (x & NN); - } - return x; -} - - -// Update Reed-Solomon encoder -// parity -> 32-byte reed-solomon encoder state; clear this to zero before each frame -void update_rs( - unsigned char parity[32], // 32-byte encoder state; zero before each frame - unsigned char c) // Current data byte to update -{ - unsigned char feedback; - int j,t; - - assert(parity != NULL); - feedback = CCSDS_index_of[c ^ parity[0]]; - if(feedback != A0){ // only if feedback is non-zero - // Take advantage of palindromic polynomial to halve the multiplies - // Do G1...G15, which is the same as G17...G31 - for(j=1;j0) - { buf = word & 0xff; - fwrite(&buf, 1,1, wav_file); - num_bytes--; - word >>= 8; - } -} - -/* information about the WAV file format from - -http://ccrma.stanford.edu/courses/422/projects/WaveFormat/ - - */ - -void write_wav(char * filename, unsigned long num_samples, short int * data, int s_rate) -{ - FILE* wav_file; - unsigned int sample_rate; - unsigned int num_channels; - unsigned int bytes_per_sample; - unsigned int byte_rate; - unsigned long i; /* counter for samples */ - - num_channels = 1; /* monoaural */ - bytes_per_sample = 2; - - if (s_rate<=0) sample_rate = 44100; - else sample_rate = (unsigned int) s_rate; - - byte_rate = sample_rate*num_channels*bytes_per_sample; - - wav_file = fopen(filename, "w"); - assert(wav_file); /* make sure it opened */ - - /* write RIFF header */ - fwrite("RIFF", 1, 4, wav_file); - write_little_endian(36 + bytes_per_sample* num_samples*num_channels, 4, wav_file); - fwrite("WAVE", 1, 4, wav_file); - - /* write fmt subchunk */ - fwrite("fmt ", 1, 4, wav_file); - write_little_endian(16, 4, wav_file); /* SubChunk1Size is 16 */ - write_little_endian(1, 2, wav_file); /* PCM is format 1 */ - write_little_endian(num_channels, 2, wav_file); - write_little_endian(sample_rate, 4, wav_file); - write_little_endian(byte_rate, 4, wav_file); - write_little_endian(num_channels*bytes_per_sample, 2, wav_file); /* block align */ - write_little_endian(8*bytes_per_sample, 2, wav_file); /* bits/sample */ - - /* write data subchunk */ - fwrite("data", 1, 4, wav_file); - write_little_endian(bytes_per_sample* num_samples*num_channels, 4, wav_file); - - for (i=0; i< num_samples; i++) - { write_little_endian((unsigned int)(data[i]),bytes_per_sample, wav_file); - } - - fclose(wav_file); -} - - - -//int main(int argc, char * argv[]) -//{ - -// return 0; -//} - -void write_wave(int i) -{ - if (FSK) - { -// if ((ctr - flip_ctr) < smaller) -// buffer[ctr++] = 0.1 * phase * (ctr - flip_ctr) / smaller; -// else - buffer[ctr++] = 0.25 * amplitude * phase; - } - else - { - if ((ctr - flip_ctr) < smaller) - buffer[ctr++] = (int)(amplitude * 0.4 * phase * - sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - else - buffer[ctr++] = (int)(amplitude * phase * - sin((float)(2*M_PI*i*freq_Hz/S_RATE))); - } -// printf("%d %d \n", i, buffer[ctr - 1]); - -} - -/** - * - * FOX 1 Telemetry Decoder - * @author chris.e.thompson g0kla/ac2cz - * - * Copyright (C) 2015 amsat.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General License for more details. - * - * You should have received a copy of the GNU General License - * along with this program. If not, see . - * - * - * Static variables and methods to encode and decode 8b10b - * - * - */ - -int encodeA(short int *b, int index, int val) { -// printf("Encoding A\n"); - b[index] = val & 0xff; - b[index + 1] = (b[index + 1] & 0xf0) | ((val >> 8) & 0x0f); - return 0; -} - -int encodeB(short int *b, int index, int val) { -// printf("Encoding B\n"); - b[index] = (b[index] & 0x0f) | ((val << 4) & 0xf0); - b[index + 1] = (val >> 4 ) & 0xff; - return 0; -} - -int twosToInt(int val,int len) { // Convert twos compliment to integer -// from https://www.raspberrypi.org/forums/viewtopic.php?t=55815 - - if(val & (1 << (len - 1))) - val = val - (1 << len); - - return(val); -} From 8cb6d2b26e9f430cc8bc2248a928c12295c06ea7 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 12:15:07 -0400 Subject: [PATCH 138/150] removed unneeded .h files --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 5880c38e..0576f63f 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -33,8 +33,8 @@ #include #include #include -#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino -#include "make_wav.h" +//#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino +//#include "make_wav.h" #include #include #include From 60a25ae5479b736955b08692cce4a71ce3e064c6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 12:17:26 -0400 Subject: [PATCH 139/150] Update main.c --- afsk/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 0576f63f..2977283e 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -864,7 +864,8 @@ if (firstTime != ON) { current[count1] = atof(token); if ((current[count1] < 0) && (current[count1] > -0.5)) - current[count1] *= (-1.0); #ifdef DEBUG_LOGGING + current[count1] *= (-1.0); + #ifdef DEBUG_LOGGING printf("current: %f\n", current[count1]); #endif token = strtok(NULL, space); From 9d2be29edb2d26289428311b736a81818e62b308 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 12:19:57 -0400 Subject: [PATCH 140/150] Update main.c --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 2977283e..fd6b0962 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -33,8 +33,8 @@ #include #include #include -//#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino -//#include "make_wav.h" +#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino +#include "make_wav.h" #include #include #include From de783bcf8daf3d66112090cc1c2085de7e7870b0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 12:22:33 -0400 Subject: [PATCH 141/150] added TelemEncoding.h --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index fd6b0962..64540900 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -34,7 +34,7 @@ #include #include #include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino -#include "make_wav.h" +#include "TelemEncoding.h" #include #include #include From 61752931adfcc429024c46e78f24a8c59ea36fb6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 12:22:57 -0400 Subject: [PATCH 142/150] Create TelemEncoding.h --- afsk/TelemEncoding.h | 546 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 546 insertions(+) create mode 100644 afsk/TelemEncoding.h diff --git a/afsk/TelemEncoding.h b/afsk/TelemEncoding.h new file mode 100644 index 00000000..fcd7f2e8 --- /dev/null +++ b/afsk/TelemEncoding.h @@ -0,0 +1,546 @@ +/* + * TelemEncoding.h + * + * Created on: Feb 3, 2014 + * Author: fox + */ + +#ifndef TELEMENCODING_H_ +#define TELEMENCODING_H_ + +void update_rs( + unsigned char parity[32], // 32-byte encoder state; zero before each frame + unsigned char c // Current data byte to update +); + +#define CHARACTER_BITS 10 +#define CHARACTERS_PER_LONGWORD 3 +#define CHARACTER_MASK ((1< Date: Sat, 5 Sep 2020 14:39:41 -0400 Subject: [PATCH 143/150] Delete ina219.h --- afsk/ina219.h | 80 --------------------------------------------------- 1 file changed, 80 deletions(-) delete mode 100644 afsk/ina219.h diff --git a/afsk/ina219.h b/afsk/ina219.h deleted file mode 100644 index 0a7372e3..00000000 --- a/afsk/ina219.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Modified from https://github.com/foglamp/foglamp-south-ina219/blob/develop/include/ina219.h - * - * FogLAMP south service plugin - * - * Copyright (c) 2018 Dianomic Systems - * - * Released under the Apache 2.0 Licence - * - * Author: Mark Riddoch - */ - -/** - * Values for the gain setting - */ -enum { - INA219_CONFIG_GAIN_40MV = 0x0000, // 40mV Range - INA219_CONFIG_GAIN_80MV = 0x0800, // 80mV Range - INA219_CONFIG_GAIN_160MV = 0x1000, // 160mV Range - INA219_CONFIG_GAIN_320MV = 0x1800, // 320mV Range -}; - -enum -{ - INA219_CONFIG_BVOLTAGERANGE_16V = 0x0000, // 0-16V Range - INA219_CONFIG_BVOLTAGERANGE_32V = 0x2000, // 0-32V Range -}; - -#define INA219_CONFIG_BADCRES_MASK 0x0780 // ADC Resulotion Mask -enum -{ - INA219_CONFIG_BADCRES_9BIT = 0x0000, // 9-bit bus res = 0..511 - INA219_CONFIG_BADCRES_10BIT = 0x0080, // 10-bit bus res = 0..1023 - INA219_CONFIG_BADCRES_11BIT = 0x0100, // 11-bit bus res = 0..2047 - INA219_CONFIG_BADCRES_12BIT = 0x0180, // 12-bit bus res = 0..4097 -}; - -#define INA219_CONFIG_SADCRES_MASK 0x0078 // Mask for shunt ADC resolution bits -enum -{ - INA219_CONFIG_SADCRES_9BIT_1S_84US = 0x00, // 1 x 9-bit shunt sample - INA219_CONFIG_SADCRES_10BIT_1S_148US = 0x08, // 1 x 10-bit shunt sample - INA219_CONFIG_SADCRES_11BIT_1S_276US = 0x10, // 1 x 11-bit shunt sample - INA219_CONFIG_SADCRES_12BIT_1S_532US = 0x18, // 1 x 12-bit shunt sample - INA219_CONFIG_SADCRES_12BIT_2S_1060US = 0x48, // 2 x 12-bit shunt samples averaged together - INA219_CONFIG_SADCRES_12BIT_4S_2130US = 0x50, // 4 x 12-bit shunt samples averaged together - INA219_CONFIG_SADCRES_12BIT_8S_4260US = 0x58, // 8 x 12-bit shunt samples averaged together - INA219_CONFIG_SADCRES_12BIT_16S_8510US = 0x60, // 16 x 12-bit shunt samples averaged together - INA219_CONFIG_SADCRES_12BIT_32S_17MS = 0x68, // 32 x 12-bit shunt samples averaged together - INA219_CONFIG_SADCRES_12BIT_64S_34MS = 0x70, // 64 x 12-bit shunt samples averaged together - INA219_CONFIG_SADCRES_12BIT_128S_69MS = 0x78, // 128 x 12-bit shunt samples averaged together -}; - -#define INA219_CONFIG_MODE_MASK 0x0007 // Operating Mode Mask -enum { - INA219_CONFIG_MODE_POWERDOWN = 0x0000, - INA219_CONFIG_MODE_SVOLT_TRIGGERED = 0x0001, - INA219_CONFIG_MODE_BVOLT_TRIGGERED = 0x0002, - INA219_CONFIG_MODE_SANDBVOLT_TRIGGERED = 0x0003, - INA219_CONFIG_MODE_ADCOFF = 0x0004, - INA219_CONFIG_MODE_SVOLT_CONTINUOUS = 0x0005, - INA219_CONFIG_MODE_BVOLT_CONTINUOUS = 0x0006, - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS = 0x0007, -}; - -typedef enum { - CONF_16V_400MA, - CONF_32V_1A, - CONF_32V_2A -} INA219_CONFIGURATION; - -/* - * INA219 Registers - */ -#define INA219_REG_CONFIG 0x00 -#define INA219_REG_SHUNTVOLTAGE 0x01 -#define INA219_REG_BUSVOLTAGE 0x02 -#define INA219_REG_POWER 0x03 -#define INA219_REG_CURRENT 0x04 -#define INA219_REG_CALIBRATION 0x05 From ef2be210131fe736013ed156a99cdc16fa32e722 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 14:40:15 -0400 Subject: [PATCH 144/150] Delete send_afsk.c --- afsk/send_afsk.c | 125 ----------------------------------------------- 1 file changed, 125 deletions(-) delete mode 100644 afsk/send_afsk.c diff --git a/afsk/send_afsk.c b/afsk/send_afsk.c deleted file mode 100644 index 4c551b50..00000000 --- a/afsk/send_afsk.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * transmits a frame of AO-7 telemetry as 1k2 AFSK in X.25 format - * - * Portions Copyright (C) 2018 Jonathan Brandenburg - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include "status.h" -#include "ax5043.h" -#include "ax25.h" -#include "spi/ax5043spi.h" - -ax5043_conf_t hax5043; -ax25_conf_t hax25; - -static void init_rf(); -void config_x25(); -void trans_x25(); -extern int upper_digit(int number); -extern int lower_digit(int number); - -int config_afsk() { - - init_rf(); - - printf("INFO: Initiating radio for X.25\n"); - - ax25_init(&hax25, (uint8_t *) "CQ", '2', (uint8_t *) "DX", '2', - AX25_PREAMBLE_LEN, - AX25_POSTAMBLE_LEN); - return(1); - -} -int send_afsk(int tlm[][5]) { -// printf("INFO: Configuring rf for X.25\n"); - -// setSpiChannel(SPI_CHANNEL); -// setSpiSpeed(SPI_SPEED); -// initializeSpi(); - - int ret; - uint8_t data[1024]; - // 0x03 is a UI frame - // 0x0F is no Level 3 protocol - // rest is dummy CubeSatSim telemetry in AO-7 format - //const char *str = "\x03\x0fhi hi 101 102 103 104 202 203 204 205 303 304 305 306 404 405 406 407 408 505 506 507 508 606 607 608 609\n"; - - /* Infinite loop */ -// for (;;) { -// sleep(2); - - // send X.25 packet - - printf("INFO: Preparing X.25 packet\n"); - - char str[1000]; - char tlm_str[1000]; - - char header_str[] = "\x03\x0fhi 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); - } - - printf("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(); - if (ret) { - fprintf(stderr, - "ERROR: Failed to transmit entire AX.25 frame with error code %d\n", - ret); - exit(EXIT_FAILURE); - } - - // } - // sleep(20); - - return 0; -} - -static void init_rf() { - printf("INFO: Before rf init\n"); - int ret; - ret = ax5043_init(&hax5043, XTAL_FREQ_HZ, VCO_INTERNAL); - printf("INFO: After rf init\n"); - if (ret != PQWS_SUCCESS) { - fprintf(stderr, - "ERROR: Failed to initialize AX5043 with error code %d\n", ret); - exit(EXIT_FAILURE); - } -} - From a54ebe7a515632df3d34c3912a1b96ee83ff93d3 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 14:40:29 -0400 Subject: [PATCH 145/150] Delete send_afsk.h --- afsk/send_afsk.h | 1 - 1 file changed, 1 deletion(-) delete mode 100644 afsk/send_afsk.h diff --git a/afsk/send_afsk.h b/afsk/send_afsk.h deleted file mode 100644 index 27c69d95..00000000 --- a/afsk/send_afsk.h +++ /dev/null @@ -1 +0,0 @@ -int send_afsk(int tlm[][5]); From 0a3d4b343692ab60ed0fb3692f1a7b15867ce62a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 14:41:02 -0400 Subject: [PATCH 146/150] Delete Adafruit_INA219.h --- afsk/Adafruit_INA219.h | 154 ----------------------------------------- 1 file changed, 154 deletions(-) delete mode 100644 afsk/Adafruit_INA219.h diff --git a/afsk/Adafruit_INA219.h b/afsk/Adafruit_INA219.h deleted file mode 100644 index 1e8c0c63..00000000 --- a/afsk/Adafruit_INA219.h +++ /dev/null @@ -1,154 +0,0 @@ -/*! - * @file Adafruit_INA219.h - * - * This is a library for the Adafruit INA219 breakout board - * ----> https://www.adafruit.com/products/904 - * - * Adafruit invests time and resources providing this open source code, - * please support Adafruit and open-source hardware by purchasing - * products from Adafruit! - * - * Written by Kevin "KTOWN" Townsend for Adafruit Industries. - * - * BSD license, all text here must be included in any redistribution. - * - * Converted to C for Raspberry Pi by Alan Johnston KU2Y - * - */ - -#include - -/** default I2C address **/ -#define INA219_ADDRESS (0x40) // 1000000 (A0+A1=GND) - -/** read **/ -#define INA219_READ (0x01) - -/*========================================================================= - CONFIG REGISTER (R/W) -**************************************************************************/ - -/** config register address **/ -#define INA219_REG_CONFIG (0x00) - -/** reset bit **/ -#define INA219_CONFIG_RESET (0x8000) // Reset Bit - -/** mask for bus voltage range **/ -#define INA219_CONFIG_BVOLTAGERANGE_MASK (0x2000) // Bus Voltage Range Mask - -/** bus voltage range values **/ -enum { - INA219_CONFIG_BVOLTAGERANGE_16V = (0x0000), // 0-16V Range - INA219_CONFIG_BVOLTAGERANGE_32V = (0x2000), // 0-32V Range -}; - -/** mask for gain bits **/ -#define INA219_CONFIG_GAIN_MASK (0x1800) // Gain Mask - -/** values for gain bits **/ -enum { - INA219_CONFIG_GAIN_1_40MV = (0x0000), // Gain 1, 40mV Range - INA219_CONFIG_GAIN_2_80MV = (0x0800), // Gain 2, 80mV Range - INA219_CONFIG_GAIN_4_160MV = (0x1000), // Gain 4, 160mV Range - INA219_CONFIG_GAIN_8_320MV = (0x1800), // Gain 8, 320mV Range -}; - -/** mask for bus ADC resolution bits **/ -#define INA219_CONFIG_BADCRES_MASK (0x0780) - -/** values for bus ADC resolution **/ -enum { - INA219_CONFIG_BADCRES_9BIT = (0x0000), // 9-bit bus res = 0..511 - INA219_CONFIG_BADCRES_10BIT = (0x0080), // 10-bit bus res = 0..1023 - INA219_CONFIG_BADCRES_11BIT = (0x0100), // 11-bit bus res = 0..2047 - INA219_CONFIG_BADCRES_12BIT = (0x0180), // 12-bit bus res = 0..4097 -}; - -/** mask for shunt ADC resolution bits **/ -#define INA219_CONFIG_SADCRES_MASK \ - (0x0078) // Shunt ADC Resolution and Averaging Mask - -/** values for shunt ADC resolution **/ -enum { - INA219_CONFIG_SADCRES_9BIT_1S_84US = (0x0000), // 1 x 9-bit shunt sample - INA219_CONFIG_SADCRES_10BIT_1S_148US = (0x0008), // 1 x 10-bit shunt sample - INA219_CONFIG_SADCRES_11BIT_1S_276US = (0x0010), // 1 x 11-bit shunt sample - INA219_CONFIG_SADCRES_12BIT_1S_532US = (0x0018), // 1 x 12-bit shunt sample - INA219_CONFIG_SADCRES_12BIT_2S_1060US = - (0x0048), // 2 x 12-bit shunt samples averaged together - INA219_CONFIG_SADCRES_12BIT_4S_2130US = - (0x0050), // 4 x 12-bit shunt samples averaged together - INA219_CONFIG_SADCRES_12BIT_8S_4260US = - (0x0058), // 8 x 12-bit shunt samples averaged together - INA219_CONFIG_SADCRES_12BIT_16S_8510US = - (0x0060), // 16 x 12-bit shunt samples averaged together - INA219_CONFIG_SADCRES_12BIT_32S_17MS = - (0x0068), // 32 x 12-bit shunt samples averaged together - INA219_CONFIG_SADCRES_12BIT_64S_34MS = - (0x0070), // 64 x 12-bit shunt samples averaged together - INA219_CONFIG_SADCRES_12BIT_128S_69MS = - (0x0078), // 128 x 12-bit shunt samples averaged together -}; - -/** mask for operating mode bits **/ -#define INA219_CONFIG_MODE_MASK (0x0007) // Operating Mode Mask - -/** values for operating mode **/ -enum { - INA219_CONFIG_MODE_POWERDOWN, - INA219_CONFIG_MODE_SVOLT_TRIGGERED, - INA219_CONFIG_MODE_BVOLT_TRIGGERED, - INA219_CONFIG_MODE_SANDBVOLT_TRIGGERED, - INA219_CONFIG_MODE_ADCOFF, - INA219_CONFIG_MODE_SVOLT_CONTINUOUS, - INA219_CONFIG_MODE_BVOLT_CONTINUOUS, - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS -}; - -/** shunt voltage register **/ -#define INA219_REG_SHUNTVOLTAGE (0x01) - -/** bus voltage register **/ -#define INA219_REG_BUSVOLTAGE (0x02) - -/** power register **/ -#define INA219_REG_POWER (0x03) - -/** current register **/ -#define INA219_REG_CURRENT (0x04) - -/** calibration register **/ -#define INA219_REG_CALIBRATION (0x05) - -/*! - * functions for interacting with INA219 - * current/power monitor IC - */ - //void begin(TwoWire *theWire = &Wire); - void setCalibration_32V_2A(int fd); - void setCalibration_32V_1A(int fd); - void setCalibration_16V_400mA(int fd); - void setCalibration_16V_2A(int fd); - float getBusVoltage_V(int fd); - float getShuntVoltage_mV(int fd); - float getCurrent_mA(int fd); - float getPower_mW(int fd); - void powerSave(int fd, int on); - - uint8_t ina219_i2caddr; - //uint32_t ina219_calValue; - uint16_t ina219_calValue; - uint16_t ina219_config; - // The following multipliers are used to convert raw current and power - // values to mA and mW, taking into account the current config settings - uint32_t ina219_currentDivider_mA; - float ina219_powerMultiplier_mW; - - void init(); - void wireWriteRegister(int fd, uint8_t reg, uint16_t value); - uint16_t wireReadRegister(int fd, uint8_t reg); - int16_t getBusVoltage_raw(int fd); - int16_t getShuntVoltage_raw(int fd); - int16_t getCurrent_raw(int fd); - int16_t getPower_raw(int fd); From 3646a249c9ba957cfb74e0e8eecabe5de4866c3c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 14:42:29 -0400 Subject: [PATCH 147/150] Delete readme.txt --- documentation/readme.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 documentation/readme.txt diff --git a/documentation/readme.txt b/documentation/readme.txt deleted file mode 100644 index 978a68dc..00000000 --- a/documentation/readme.txt +++ /dev/null @@ -1 +0,0 @@ -These files are papers and presentations given about the CubeSat Simulator at the AMSAT Space Symposium and other places. From c034aa20c35fc153b7e77f18725cd8f0112286ea Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 14:43:41 -0400 Subject: [PATCH 148/150] Update Makefile --- Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Makefile b/Makefile index 5688ac1c..88e8270f 100644 --- a/Makefile +++ b/Makefile @@ -236,11 +236,9 @@ 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 -afsk/main.o: afsk/Adafruit_INA219.h cd afsk; gcc -std=gnu99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c main.c; cd .. afsk/telem.o: afsk/telem.c -afsk/telem.o: afsk/Adafruit_INA219.h cd afsk; gcc -std=gnu99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c telem.c; cd .. afsk/send_afsk.o: afsk/send_afsk.c From 628b450805abcad5d4232505d802d520cd8e8274 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 14:45:22 -0400 Subject: [PATCH 149/150] removed ina219 .h --- afsk/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 64540900..aedeee1b 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -33,7 +33,6 @@ #include #include #include -#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino #include "TelemEncoding.h" #include #include From aad2e434d00e95a2b91a8a59b9caaeea820adfd6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 5 Sep 2020 14:47:54 -0400 Subject: [PATCH 150/150] removed send_afsk and radiocw old apps --- Makefile | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/Makefile b/Makefile index 88e8270f..147c4e26 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,11 @@ all: DEBUG_BEHAVIOR= all: libax5043.a all: radioafsk -all: radiocw all: telem debug: DEBUG_BEHAVIOR = -DDEBUG_LOGGING debug: libax5043.a debug: radioafsk -debug: radiocw debug: telem rebuild: clean @@ -17,7 +15,6 @@ lib: libax5043.a clean: rm -f radiochat - rm -f radiocw rm -f radiopiglatin rm -f testax5043rx rm -f testax5043tx @@ -55,13 +52,6 @@ radiochat: libax5043.a radiochat: chat/chat_main.o gcc -std=gnu99 $(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 -std=gnu99 $(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 -std=gnu99 $(DEBUG_BEHAVIOR) -o radiopiglatin -pedantic -Wall -Wextra -L./ piglatin/piglatin_main.o -lwiringPi -lax5043 @@ -241,13 +231,6 @@ afsk/main.o: ax5043/spi/ax5043spi.h afsk/telem.o: afsk/telem.c cd afsk; gcc -std=gnu99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c telem.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 -std=gnu99 $(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 cw/cw_main.o: ax5043/spi/ax5043spi_p.h