Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:db73b542b7bc
- Parent:
- 0:c81f86a07902
diff -r c81f86a07902 -r db73b542b7bc main.cpp
--- a/main.cpp Thu Jun 09 10:43:58 2022 +0000
+++ b/main.cpp Fri Jun 10 08:41:49 2022 +0000
@@ -7,6 +7,8 @@
riempio il buffer e ritrasmetto con i caratteri riconvertiti
comando per azionamento periferiche: SPARE
+
+modifica sulla ricezione: devo ricevere solo se un certo comando è stato selezionato
*/
// ************* INFO *******************
@@ -31,7 +33,6 @@
#define OPTION_2 90608 // 5663 * 16
#define tb 7 // bit sampling period
#define BufferXOR 175 // 2800/16 - 1
-#define TIMEOUT 15000 // milliseconds
#define word 16
@@ -43,6 +44,10 @@
// ************** TIMER *****************
Timer t;
+float TIMEOUT = 10;
+float tTimeStart;
+float tTimeStop;
+float tTimeRead;
// ******* L16 Actuatonix - Relay ********
PwmOut M1 (PA_6); // D12
@@ -67,7 +72,7 @@
volatile int LEN; // numero di bit da ricevere per ricezione corretta
volatile int commandId;
volatile int payloadDec;
-volatile int size;
+volatile int sizeBuffer;
volatile unsigned char data; // in arrivo da MIMA per telemetria
int base = 2; // base per l'esponenziale (conversione binary to decimal)
@@ -110,7 +115,7 @@
Relay12V = 1;
Relay15_15_5V = 1; // +15, -15, -5
Relay24V = 1;
-
+
// diagnostic
SC.printf("*******Starting... *******\n\r");
@@ -136,8 +141,6 @@
// clear
void clearBuffer(char *arr, int arrLen)
{
- // reset pacchetto
- nIndex = 0;
for (nIndex = 0; nIndex < arrLen; nIndex++)
{
arr[nIndex] = '\0';
@@ -437,9 +440,7 @@
// aggiungere timeout, perché non so se raggiungo il numero dei caratteri
while (MIMA.readable())
- {
- t.start();
-
+ {
// char prova = MIMA.getc();
// SC.printf("> Text: %c\n\r", prova);
// check del payload per scelta del buffer
@@ -481,48 +482,45 @@
// 5606 words
if (option_1 == 0)
{
- size = 0; // reset
- clearBuffer(TLM, sizeof(TLM) / sizeof(TLM[0]));
-
- if (t.read() < TIMEOUT)
+ sizeBuffer = 0; // reset
+ clearBuffer(TLM, sizeof(TLM)/sizeof(TLM[0]));
+
+ t.start();
+ tTimeStart = t.read(); // in secondi
+ tTimeRead = tTimeStart;
+
+ while (sizeBuffer < OPTION_1 && ((tTimeRead - tTimeStart) < TIMEOUT))
{
- while (size < OPTION_1)
- {
- data = MIMA.getc(); // prendi carattere in arrivo
- TLM[size++] = data;
- }
+ data = MIMA.getc(); // prendi carattere in arrivo
+ TLM[sizeBuffer++] = data;
+ tTimeRead = t.read();
}
- else
+
+ tTimeRead = t.read();
+
+ if ((tTimeRead - tTimeStart) >= TIMEOUT)
{
- t.stop();
- SC.printf("> Time elapsed: %.2f\n\r", t.read());
- clearBuffer(TLM, sizeof(TLM) / sizeof(TLM[0]));
- }
+ sizeBuffer = 0;
+ clearBuffer(TLM, OPTION_1);
+ SC.printf("> Time elapsed: %f \n", tTimeRead);
+ }
+
}
else if (option_2 == 0)
{
- size = 0;
- clearBuffer(TLM_SD, sizeof(TLM_SD) / sizeof(TLM_SD[0]));
+ sizeBuffer = 0;
+ clearBuffer(TLM_SD, sizeof(TLM_SD)/sizeof(TLM_SD[0]));
- t.start();
- if (t.read() < TIMEOUT)
+ while (sizeBuffer < OPTION_2)
{
- while (size < OPTION_2)
- {
- data = MIMA.getc(); // prendi carattere in arrivo
- TLM_SD[size++] = data;
- }
- //checksum(TLM_SD, OPTION_2);
- }
- else
- {
- t.stop();
- clearBuffer(TLM_SD, sizeof(TLM_SD) / sizeof(TLM_SD[0]));
+ data = MIMA.getc(); // prendi carattere in arrivo
+ TLM_SD[sizeBuffer++] = data;
}
}
- TxTelemetry();
}
+
+ TxTelemetry();
}
}
@@ -593,19 +591,13 @@
if (option_1 == 0)
{
SC.printf("\n\r> Receiving 57 words from MIMA... \n\r");
-
+
for (int i = 0; i < OPTION_1; i++)
{
SC.putc(TLM[i]);
}
- /*SC.printf("\n\r> Receiving 57 words from DORA... \n\r");
-
- for (int i = 0; i < OPTION_1; i++)
- {
- ARDUINO.putc(DEVICE.putc(TLM[i]));
- }
- */
+ SC.printf("\n\r");
}
else if (option_2 == 0)
{
@@ -613,17 +605,17 @@
for (int i = 0; i < OPTION_2; i++)
{
- SC.putc(TLM_SD[i]);
+ if (i % word == 0)
+ {
+ SC.printf("\n\r");
+ }
+ else
+ {
+ SC.putc(TLM_SD[i]);
+ }
}
- /*
- SC.printf("\n\r> Receiving 5663 words from DORA... \n\r");
-
- for (int i = 0; i < OPTION_2; i++)
- {
- ARDUINO.putc(DEVICE.putc(TLM_SD[i]));
- }
- */
+ SC.printf("\n\r");
}
}