@@ -72,6 +72,17 @@ char aprsFrame[100]; // APRS Frame array
7272static max_m10s_dev_s gps_dev ;
7373static max_m10s_init_s gps_init ;
7474
75+ // APRS input values
76+ uint8_t analogValues [5 ][5 ] = {
77+ "001," ,
78+ "002," ,
79+ "003," ,
80+ "004," ,
81+ "005,"
82+ };
83+ char * digitalValue = "00001100" ;
84+ char * comment = "hello!" ;
85+
7586/* ================================ */
7687/* Helper Functions */
7788/* ================================ */
@@ -83,54 +94,6 @@ PUTCHAR_PROTOTYPE {
8394 return ch ;
8495}
8596
86- /* ================================ */
87- /* LTR-329 Sensor Functions */
88- /* ================================ */
89- /* --- LTR-329 initialization --- */
90- // static void LTR329_Init(void) {
91- // uint8_t data[2];
92- // data[0] = LTR329_CONTR;
93- // data[1] = 0x01; // Active mode, gain 1x
94- // HAL_I2C_Master_Transmit(&hi2c1, LTR329_ADDR, data, 2, HAL_MAX_DELAY);
95-
96- // data[0] = LTR329_MEAS_RATE;
97- // data[1] = 0x02; // 2Hz integration, 100ms measurement
98- // HAL_I2C_Master_Transmit(&hi2c1, LTR329_ADDR, data, 2, HAL_MAX_DELAY);
99-
100- // printf("LTR-329 Initialized!\r\n");
101- // }
102-
103- // /* --- LTR-329 read ambient light --- */
104- // static uint16_t LTR329_ReadALS(void) {
105- // uint8_t reg = LTR329_DATA_START;
106- // uint8_t data[4];
107- // HAL_I2C_Master_Transmit(&hi2c1, LTR329_ADDR, ®, 1, HAL_MAX_DELAY);
108- // HAL_I2C_Master_Receive(&hi2c1, LTR329_ADDR, data, 4, HAL_MAX_DELAY);
109- // return (uint16_t)((data[1] << 8) | data[0]);
110- // }
111-
112- /* ================================ */
113- /* MCP9808 Sensor Functions */
114- /* ================================ */
115- // /* --- MCP9808 initialization --- */
116- // static void MCP9808_Init(void) {
117- // printf("MCP9808 Initialized!\r\n");
118- // }
119-
120- // /* --- MCP9808 read temperature in Celsius --- */
121- // static float MCP9808_ReadTemp(void) {
122- // uint8_t reg = MCP9808_REG_AMBIENT_TEMP;
123- // uint8_t data[2];
124- // HAL_I2C_Master_Transmit(&hi2c1, MCP9808_ADDR, ®, 1, HAL_MAX_DELAY);
125- // HAL_I2C_Master_Receive(&hi2c1, MCP9808_ADDR, data, 2, HAL_MAX_DELAY);
126-
127- // uint16_t raw = (data[0] << 8) | data[1];
128- // float temperature = (raw & 0x0FFF) / 16.0f;
129- // if (raw & 0x1000) { // negative bit
130- // temperature -= 256;
131- // }
132- // return temperature;
133- // }
13497
13598/* ================================ */
13699/* LED Blinking Functions */
@@ -166,38 +129,7 @@ static void print_status(const char* message, gps_status_e status) {
166129 }
167130 printf ("%s: %s (0x%02X)\r\n" , message , status_str , status );
168131}
169- // === 1) Define a one‐shot GPS read function ===
170- // void GPS_ReadOnce(void) {
171- // gps_status_e status;
172-
173- // // 1a) send the PVT command
174- // status = max_m10s_command(&gps_dev, GPS_CMD_PVT);
175- // print_status("PVT cmd", status);
176- // if (status != UBLOX_OK) return;
177-
178- // // 1b) small pause to let the module prep its data
179- // HAL_Delay(100);
180-
181- // // 1c) read the response
182- // status = max_m10s_read(&gps_dev);
183- // print_status("PVT read", status);
184- // if (status != UBLOX_OK) return;
185-
186- // // 1d) validate it
187- // status = max_m10s_validate_response(&gps_dev, GPS_CMD_PVT);
188- // print_status("PVT validate", status);
189- // if (status != UBLOX_OK) return;
190-
191- // // 1e) parse UBX‐PVT into a struct
192- // gps_pvt_data_t pvt;
193- // if (ubx_parse_gps_pvt(gps_dev.rx_buffer, gps_dev.rx_size, &pvt) == UBLOX_OK) {
194- // float lat = pvt.lat / 1e7f;
195- // float lon = pvt.lon / 1e7f;
196- // printf("↳ GPS fix: Lat=%.7f°, Lon=%.7f°\r\n", lat, lon);
197- // } else {
198- // printf("↳ PVT parse error\r\n");
199- // }
200- // }
132+
201133void GPS_ReadOnce (void ) {
202134 gps_status_e status ;
203135
@@ -240,11 +172,7 @@ void GPS_ReadOnce(void) {
240172 (buf [6 + 29 ] << 8 ) |
241173 (buf [6 + 30 ] << 16 ) |
242174 (buf [6 + 31 ] << 24 ));
243- // float lon = lon_raw / 1e7f;
244- // float lat = lat_raw / 1e7f;
245-
246- // printf("GPS fix: Lat=%.7f°, Lon=%.7f°\r\n", lat, lon);
247- // split into degrees + fractional part
175+
248176
249177 // Float printing was giving me trouble, so this is the workaround for that
250178 int32_t lat_deg = lat_raw / 10000000 ;
@@ -286,13 +214,7 @@ void wait_for_gps_fix(void) {
286214 return ;
287215 }
288216
289- // // at this point we have a fix, so lat/lon are valid
290- // int32_t lat_raw = pvt->lat, lon_raw = pvt->lon;
291- // int32_t lat_deg = lat_raw / 10000000, lat_rem = abs(lat_raw % 10000000);
292- // int32_t lon_deg = lon_raw / 10000000, lon_rem = abs(lon_raw % 10000000);
293- // printf("GPS fix: Lat=%ld.%07ld°, Lon=%ld.%07ld°\r\n",
294- // lat_deg, lat_rem,
295- // lon_deg, lon_rem);
217+
296218}
297219/* ================================ */
298220/* BME68x Sensor Function */
@@ -329,18 +251,6 @@ void BME_SensorRead(void) {
329251 return ;
330252 }
331253
332- // it still doesn't print floats
333- // float T = bme.sensor_data.temperature; // °C
334- // float P = bme.sensor_data.pressure; // Pa
335- // float H = bme.sensor_data.humidity; // %RH (or %RH×1000—check your API)
336- // float G = bme.sensor_data.gas_resistance; // Ω
337-
338- // // If humidity is in ‰ (x1000), divide by 1000.0f to get percent:
339- // printf("BME68x: T=%.2f °C, P=%.0f Pa, H=%.3f %%, G=%.0f Ω\r\n",
340- // T,
341- // P,
342- // H / 1000.0f,
343- // G);
344254
345255 // but ints work
346256 int32_t rawT = bme .sensor_data .temperature ; // e.g. 2236 => 22.36 °C
@@ -362,76 +272,7 @@ void BME_SensorRead(void) {
362272 alt_int );
363273}
364274
365- // void BME_SensorRead(void) {
366- // // Create bme interface struct and initialize it
367- // bme68x_sensor_t bme;
368- // bme_init(&bme, &hi2c1, &delay_us_timer);
369-
370- // // Check status, should be 0 for OK
371- // int bme_status = bme_check_status(&bme);
372- // {
373- // if (bme_status == BME68X_ERROR) {
374- // printf("Sensor error:" + bme_status);
375- // return BME68X_ERROR;
376- // } else if (bme_status == BME68X_WARNING) {
377- // printf("Sensor Warning:" + bme_status);
378- // }
379- // }
380- // // Set temp, pressure, humidity oversampling configuration
381- // // Trying with defaults
382- // bme_set_TPH_default(&bme);
383- // // Set the heater configuration to 300 deg C for 100ms for Forced mode
384- // bme_set_heaterprof(&bme, 300, 100);
385-
386- // // Read sensor id
387- // uint8_t sensor_id;
388- // bme_read(0xD0, &sensor_id, 4, &hi2c1);
389- // debug_print("Received sensor ID: 0x%X\r\n", sensor_id);
390-
391- // // Set to forced mode, which takes a single sample and returns to sleep mode
392- // bme_set_opmode(&bme, BME68X_FORCED_MODE);
393- // /** @todo: May adjust the specific timing function called here, but it should be based on bme_get_meas_dur */
394- // delay_us_timer(bme_get_meas_dur(&bme, BME68X_SLEEP_MODE), &hi2c1);
395- // // Fetch data
396- // int fetch_success = bme_fetch_data(&bme);
397- // if (fetch_success) {
398- // // Print raw values
399- // debug_print("Raw Temperature : %d\n", bme.sensor_data.temperature);
400- // debug_print("Raw Pressure : %d\n", bme.sensor_data.pressure);
401- // debug_print("Raw Humidity : %d\n", bme.sensor_data.humidity);
402- // debug_print("Raw Gas Resistance : %d\n", bme.sensor_data.gas_resistance);
403-
404- // // Convert and print the processed values
405- // // Temperature: Divide by 100 to get the value in °C with 2 decimal places
406- // debug_print("Temperature : %d.%02d°C\n",
407- // (int)(bme.sensor_data.temperature / 100.0f), // Integer part
408- // (int)fmod(bme.sensor_data.temperature, 100.0f)); // Fractional part (2 decimal places)
409-
410- // // Pressure: Divide by 100 to get the value in Pa
411- // debug_print("Pressure : %d Pa\n",
412- // bme.sensor_data.pressure);
413-
414- // // Humidity: Divide by 1000 to get the value in % with 3 decimal places
415- // debug_print("Humidity : %d.%03d%%\n",
416- // (int)(bme.sensor_data.humidity / 1000.0f), // Integer part
417- // (int)fmod(bme.sensor_data.humidity, 1000.0f)); // Fractional part (3 decimal places)
418-
419- // // Gas Resistance: Convert to kΩ and display with 3 decimal places
420- // debug_print("Gas Resistance : %d.%03d kΩ\n",
421- // (int)(bme.sensor_data.gas_resistance / 1000.0f), // Integer part (kΩ)
422- // (int)fmod(bme.sensor_data.gas_resistance, 1000.0f)); // Fractional part (milliΩ)
423-
424- // // Print the status in hexadecimal
425- // debug_print("Status : 0x%X\n", bme.sensor_data.status);
426-
427- // debug_print("\n---------------------------------------\n");
428- // }
429-
430- // // The "blink" code is a simple verification of program execution,
431- // // separate from the BME68x sensor testing above
432- // HAL_GPIO_TogglePin(UserLED_GPIO_Port, UserLED_Pin);
433- // HAL_Delay(1000);
434- // }
275+
435276
436277/* ================================ */
437278/* System Initialization */
@@ -561,6 +402,24 @@ void ADC_READ_TEST() {
561402 HAL_Delay (2000 ); // Delay to allow some time before next reading (optional for testing)
562403}
563404
405+ void APRS_CreatePacket (uint8_t * analogValues , char * digitalValue , char * comment ){
406+ telemetryInfoFrame * tFrame = initTFrame ();
407+ updateTelemData (tFrame , analogValues ,(uint8_t * ) digitalValue , comment );
408+ concatTelemData (tFrame );
409+
410+ //wrap aprs packet in ax25 packet
411+ ax25Frame * frame = initFrame (tFrame -> tData , tFrame -> tDataSize );
412+ encodedAx25Frame encodedFrame = processFrameVerbose (frame );
413+
414+
415+ //clean up
416+ freeFrames (tFrame , NULL , NULL , NULL , NULL , & encodedFrame );
417+
418+ //blinky
419+ HAL_GPIO_TogglePin (UserLED_GPIO_Port , UserLED_Pin );
420+
421+ HAL_Delay (10000 );
422+ }
564423/* USER CODE BEGIN 4 */
565424
566425int main (void ) {
@@ -585,25 +444,7 @@ int main(void) {
585444 wait_for_gps_fix ();
586445 printf ("back in main(), now calling BME_SensorRead()\r\n" );
587446 BME_SensorRead ();
588-
589- printf ("Waiting for good ADC value (aka button) \n\n" );
590- // Loop waiting for user interaction (button press) to confirm system is ready
591- while (1 ) {
592-
593- HAL_Delay (2000 );
594-
595- // Check if the button was pressed (set by external interrupt callback)
596- if (buttonPressed == 1 ) {
597- // Confirm good capacitor values via button press
598- printf ("Capacitor values are good! (Button Pressed!)\n" );
599- HAL_Delay (1000 );
600-
601- // Clear the button press flag
602- buttonPressed = 0 ;
603- break ; // Exit the while loop
604- }
605- }
606-
447+ APRS_CreatePacket (analogValues , & digitalValue , & comment );
607448 // Indicate system is entering standby mode
608449 Enter_Standby_Mode ();
609450 }
@@ -626,4 +467,4 @@ int main(void) {
626467 }
627468 // Normally unreachable, but good practice to return 0 in main
628469 return 0 ;
629- }
470+ }
0 commit comments