diff options
| author | Aditya Naik | 2020-03-25 15:59:57 -0400 |
|---|---|---|
| committer | Aditya Naik | 2020-03-25 15:59:57 -0400 |
| commit | 9320bd2d2516d62e8db13e853222e86608a09471 (patch) | |
| tree | 2174cff9e9194ee894e912223b933a7514d62fba | |
| parent | c973626653856e74926d633cd3ea3dea0cd3575e (diff) | |
Debugging AF errors on MDK ACK
| -rw-r--r-- | Src/main.c | 73 |
1 files changed, 49 insertions, 24 deletions
@@ -118,18 +118,12 @@ int main(void) HAL_UART_Transmit(&huart1, reset_string, sizeof(reset_string), 100);
#endif /* MASTER */
#endif /* TESTING_ENABLE */
- /* USER CODE END 2 */
-
- /* Infinite loop */
- /* USER CODE BEGIN WHILE */
- /* while (1) */
- /* { */
#ifdef MASTER
uint8_t MDR_req_buf[64], debug_buf[128] = {0}, term[]="\r\n";
m2s_MDR_request MDR_req_message;
pb_ostream_t MDR_req_stream = pb_ostream_from_buffer(MDR_req_buf, sizeof(MDR_req_buf));
- MDR_req_message.record_type = 1; /* Placeholder for default record type */
+ MDR_req_message.record_type = 7; /* Placeholder for default record type */
if(!pb_encode(&MDR_req_stream, m2s_MDR_request_fields, &MDR_req_message)) {
#ifdef DEBUG_ENABLE
uint8_t err_buf[] = "MDR reqest encoding error\r\n";
@@ -161,25 +155,43 @@ int main(void) }
HAL_GPIO_TogglePin(led_GPIO_Port, led_Pin);
- while (HAL_I2C_Master_Receive(&hi2c1, (uint8_t)I2C_ADDRESS, (uint8_t*)MDR_req_buf, 2, 10000) != HAL_OK);
+ uint8_t MDR_ACK_buf[8] = {0};
+ if (HAL_I2C_Master_Receive(&hi2c1, (uint8_t)I2C_ADDRESS, (uint8_t*)MDR_ACK_buf, 2, 10000) != HAL_OK) {
+#ifdef DEBUG_ENABLE
+ sprintf((char*)debug_buf, "Unable to get MDR ACK. I2C error: %ld\r\n", HAL_I2C_GetError(&hi2c1));
+ HAL_UART_Transmit(&huart1, debug_buf, sizeof(debug_buf), 100);
+ memset(debug_buf, 0, 128);
+#endif /* DEBUG_ENABLE */
+ }
+
+#ifdef TESTING_ENABLE
uint8_t bufbuf2[] = "MDR ACK buffer: ";
HAL_UART_Transmit(&huart1, bufbuf2, sizeof(bufbuf2), 100);
- for(int x=0; x<2; x++) {
- sprintf((char*)debug_buf+x, "%x", MDR_req_buf[x]);
+ for (int x=0; x<2; x++) {
+ sprintf((char*)debug_buf+x, "%x|", MDR_ACK_buf[x]);
}
HAL_UART_Transmit(&huart1, debug_buf, 2, 100);
HAL_UART_Transmit(&huart1, term, 2, 100);
memset(debug_buf, 0, 128);
+#endif /* TESTING_ENABLE */
- pb_istream_t MDR_ACK_istream = pb_istream_from_buffer(MDR_req_buf, 2);
+ pb_istream_t MDR_ACK_istream = pb_istream_from_buffer(MDR_ACK_buf, 2);
s2m_MDR_req_ACK MDR_ACK;
- pb_decode(&MDR_ACK_istream, s2m_MDR_req_ACK_fields, &MDR_ACK);
+ if (!pb_decode(&MDR_ACK_istream, s2m_MDR_req_ACK_fields, &MDR_ACK)) {
+#ifdef DEBUG_ENABLE
+ uint8_t errbuf[] = "MDR ACK decoding error\r\n";
+ HAL_UART_Transmit(&huart1, errbuf, sizeof(errbuf), 100);
+#endif /* DEBUG_ENABLE */
+ }
+ else {
#ifdef TESTING_ENABLE
- sprintf((char*)debug_buf, "Got MDR message length: %ld\r\n", MDR_ACK.MDR_res_length);
- HAL_UART_Transmit(&huart1, debug_buf, sizeof(debug_buf), 100);
- memset(debug_buf, 0, 128);
+ sprintf((char*)debug_buf, "Got MDR message length: %ld\r\n", MDR_ACK.MDR_res_length);
+ HAL_UART_Transmit(&huart1, debug_buf, sizeof(debug_buf), 100);
+ memset(debug_buf, 0, 128);
#endif /* TESTING_ENABLE */
+ }
+
#else /* MASTER */
uint8_t buffer[128], debug_buf[128], term[]="\r\n";
@@ -207,7 +219,8 @@ int main(void) sprintf((char*)debug_buf, "MDR Encoded size: %d\r\n", MDR_enc_size);
HAL_UART_Transmit(&huart1, debug_buf, sizeof(debug_buf), 100);
memset(debug_buf, 0, 128);
- uint8_t bufbuf[] = "Buffer: ";
+
+ uint8_t bufbuf[] = "MDR Buffer: ";
HAL_UART_Transmit(&huart1, bufbuf, sizeof(bufbuf), 100);
for(int x=0; x<MDR_enc_size; x++) {
sprintf((char*)debug_buf+x, "%x", buffer[x]);
@@ -217,7 +230,7 @@ int main(void) memset(debug_buf, 0, 128);
#endif
- uint8_t MDR_ACK_buf[8];
+ uint8_t MDR_ACK_buf[8] = {0};
s2m_MDR_req_ACK ack;
ack.MDR_res_length = MDR_enc_size;
pb_ostream_t MDR_ack_ostream = pb_ostream_from_buffer(MDR_ACK_buf,
@@ -266,7 +279,7 @@ int main(void) #ifdef DEBUG_ENABLE
uint8_t errbuf[] = "MDR request decoding error\r\n";
HAL_UART_Transmit(&huart1, errbuf, sizeof(errbuf), 100);
-#endif /* DEBUG_ENABLE */
+#endif /* DEBUG_ENABLE */
/* continue; */
}
@@ -278,12 +291,24 @@ int main(void) HAL_GPIO_TogglePin(led_GPIO_Port, led_Pin);
- HAL_I2C_Slave_Transmit(&hi2c1, (uint8_t*)MDR_ACK_buf, 2, 10000);
+ if (HAL_I2C_Slave_Transmit(&hi2c1, (uint8_t*)MDR_ACK_buf, 2, 1000) != HAL_OK) {
+#ifdef DEBUG_ENABLE
+ sprintf((char*)debug_buf, "Unable to send MDR ACK. I2C error: %ld\r\n", HAL_I2C_GetError(&hi2c1));
+ HAL_UART_Transmit(&huart1, debug_buf, sizeof(debug_buf), 100);
+ memset(debug_buf, 0, 128);
+#endif /* DEBUG_ENABLE */
+ }
#endif /* MASTER */
- /* USER CODE END WHILE */
- /* USER CODE BEGIN 3 */
- /* } */
- /* USER CODE END 3 */
+
+ /* USER CODE END 2 */
+ /* Infinite loop */
+ /* USER CODE BEGIN WHILE */
+ while (1)
+ {
+ /* USER CODE END WHILE */
+ /* USER CODE BEGIN 3 */
+ }
+ /* USER CODE END 3 */
}
/**
@@ -422,7 +447,7 @@ static void MX_GPIO_Init(void) bool encode_subscription_callback(pb_ostream_t *ostream, const pb_field_t *field, void * const *arg)
{
if(ostream!=NULL && field->tag == s2m_MDR_response_subscriptions_tag) {
- for (int x=0; x<25; x++) {
+ for (int x=0; x<2; x++) {
_subscriptions subs;
subs.module_id = x+10*x;
subs.i2c_address = x+1;
|
