# cat-tracker

A multi-function application designed to run on a pi node. When used in a mesh network, this app will help track your cat with a CC2500 based radio collar, using complementary CC2500 based radio modules interfaced with your Pi. 

The implementation here uses CC2500 register values which intend to mimic my [Girafus M07A](https://www.girafus.com/en-en/collections/peilsender/products/ersatzteil-basismodul-fur-girafus%C2%AE-pro-track-tor-katzen-hunde-haustier-kleintier-sucher) unit. This unit is paired with my associated [tracker](https://www.girafus.com/en-en/collections/peilsender/products/extra-sender-tag-fur-den-girafus%C2%AE-pro-track-tor-haustier-hund-katze-kleintier-finder-sucher-ortung) 

## Links
* [Arduion Forum Port](https://forum.arduino.cc/t/replicating-a-signal-from-a-locating-device-2-4ghz-to-locate-tag/321993/2)
* [cc2500 data sheet](./cc2500.pdf)
* [C Code transciever example](https://github.com/alexbirkett/cc2500-raspberry-pi)

## CC2500 to Raspberry Pi GPIO Pin Mapping

| CC2500 Pin | Function Description                                 | Raspberry Pi GPIO Pin         | GPIO Number |
|------------|------------------------------------------------------|-------------------------------|-------------|
| GND        | Ground                                               | Pin 6                         | -           |
| VCC        | 3.3V Power (⚠️ **Do not use 5V**)                     | Pin 1 or Pin 17               | -           |

### SPI Connections

| CC2500 Pin | Function | Raspberry Pi GPIO Pin         | GPIO Number |
|------------|----------|-------------------------------|-------------|
| SI         | MOSI     | Pin 19                        | GPIO 10     |
| SCK        | SCLK     | Pin 23                        | GPIO 11     |
| CSN        | CE0 (Chip Select) | Pin 24              | GPIO 8      |
| SO         | MISO     | Pin 21                        | GPIO 9      |

### Interrupt Pins

| CC2500 Pin | Function                                  | Raspberry Pi GPIO Pin         | GPIO Number |
|------------|-------------------------------------------|-------------------------------|-------------|
| GDO0       | Interrupt/Data Ready                      | Pin 11                        | GPIO 17     |
| GDO2       | Additional Interrupt/Data Line            | Pin 23                        | GPIO 27     |

### Power Amplifier Pins (If Applicable)

| CC2500 Pin | Function                                  | Raspberry Pi GPIO Pin         | Notes                                  |
|------------|-------------------------------------------|-------------------------------|----------------------------------------|
| PA_EN      | Control Power Amplifier (Optional)        | Any GPIO Pin                  | Connect if amplifier control is needed |
| PA_EX      | Reserved                                  | Not Connected                 | Only connect if required               |

## Reverse Engineering the Registers

### SmartRF Studio

#### Install
[SmartRF Studio](https://www.ti.com/tool/SMARTRFTM-STUDIO#downloads) will automatically generate a configuration for the CC2500 Radio based on some RF parameters
* A free registration and login is required to download this app from Texas Instruments
* The app seems to run well via `wine` on linux. I chose to install it on an actual Windows OS, then copy the binaries.

#### Copy Register JSON template
When this is installed, copy the code export json file to help export the initial register configuration in a JSON format

```bash
cp srfexp_json.xml "~/Documents/Texas Instruments/SmartRF Studio v7/codeexport/."
# Example copy command for linux+wine 
```

#### Understanding necessary RF Parameters
In SmartRF Studio, open the CC2500 Device Controller under the 2.4 GHZ list.

At the time of writing, it is believed this device uses 250 kBaud MSK encoding. We will choose this option.

Next we need to figure out the Base Frequency, Channel numbers, and Channel Spacing
![smart_rf](./images/smart_rf.png)

### Singal Capture
I have captured the initial signal emitted by the handheld unit when it is first powered on. To do this, I have used a HackRF SDR + gqrx application on linux.

The known frequency range is 2400 – 2483.5 MHz, and my SDR has a 20 MHZ bandwidth. I choose sweep for signals by tuning the following frequencies
| Sweep # | Center Frequency | Center Frequency (kHz) | Approx. Coverage (MHz) | Approx. Coverage (kHz)     |
|---------|------------------|-------------------------|-------------------------|-----------------------------|
| 1       | 2410 MHz         | 2,410,000 kHz           | 2400 – 2420 MHz         | 2,400,000 – 2,420,000 kHz   |
| 2       | 2430 MHz         | 2,430,000 kHz           | 2420 – 2440 MHz         | 2,420,000 – 2,440,000 kHz   |
| 3       | 2450 MHz         | 2,450,000 kHz           | 2440 – 2460 MHz         | 2,440,000 – 2,460,000 kHz   |
| 4       | 2470 MHz         | 2,470,000 kHz           | 2460 – 2480 MHz         | 2,460,000 – 2,480,000 kHz   |
| 5       | 2483.5 MHz       | 2,483,500 kHz           | 2473.5 – 2483.5 MHz     | 2,473,500 – 2,483,500 kHz   |

#### Signal 00
2.423257000 GHz | 2423.257000 MHz | 2423257.000 kHz |
![signal_00](./images/signals/signal00.png)
#### Signal 0
2.431258000 GHz | 2431.258000 MHz| 2431258.000 kHz
![signal_0](./images/signals/signal0.png)
#### Signal 1
2.447257000 GHz | 2447.257000 MHz | 2447257.000 kHz
![signal_1](./images/signals/signal1.png)
#### Signal 2
2.450225000 GHz | 2450.225000 MHz | 2450225.000 kHz
![signal_2](./images/signals/signal2.png)
#### Signal 3
2.471275000 GHz | 2471.275000 MHz | 2471275.000 kHz
![signal_3](./images/signals/signal3.png)

#### Signal Summary

* Base frequency: ? MHz
* Date Rate ? Baud
* Channel spacing: ? kHz
* Signal channels:
* Signal 00 → Channel ?
* Signal 0 → Channel ?
* Signal 1 → Channel ?
* Signal 2 → Channel ?
* Signal 3 → Channel ?


## Run
`python3 -m src.main`