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.
emetteur.cpp@0:56caa4d851d2, 2022-03-31 (annotated)
- Committer:
- snec_student
- Date:
- Thu Mar 31 13:31:18 2022 +0000
- Revision:
- 0:56caa4d851d2
- Child:
- 1:e9dad14e0d53
version avec Jo : envoi trame OK mais signale erreur transmission
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
snec_student | 0:56caa4d851d2 | 1 | #include "emetteur.h" |
snec_student | 0:56caa4d851d2 | 2 | |
snec_student | 0:56caa4d851d2 | 3 | Emetteur::Emetteur():kimSerial(PTC17,PTC16,4800),power(D4) |
snec_student | 0:56caa4d851d2 | 4 | { |
snec_student | 0:56caa4d851d2 | 5 | } |
snec_student | 0:56caa4d851d2 | 6 | |
snec_student | 0:56caa4d851d2 | 7 | char* Emetteur::get_ID() |
snec_student | 0:56caa4d851d2 | 8 | { |
snec_student | 0:56caa4d851d2 | 9 | for(uint8_t i=0; i<6; i++)command[i] = AT_ID[i]; |
snec_student | 0:56caa4d851d2 | 10 | for(uint8_t i=0; i<3; i++)command[6+i] = AT_REQUEST[i]; |
snec_student | 0:56caa4d851d2 | 11 | send_ATCommand(); |
snec_student | 0:56caa4d851d2 | 12 | return response; |
snec_student | 0:56caa4d851d2 | 13 | } |
snec_student | 0:56caa4d851d2 | 14 | |
snec_student | 0:56caa4d851d2 | 15 | |
snec_student | 0:56caa4d851d2 | 16 | char* Emetteur::get_SN() |
snec_student | 0:56caa4d851d2 | 17 | { |
snec_student | 0:56caa4d851d2 | 18 | for(uint8_t i=0; i<6; i++)command[i] = AT_SN[i]; |
snec_student | 0:56caa4d851d2 | 19 | for(uint8_t i=0; i<3; i++)command[6+i] = AT_REQUEST[i]; |
snec_student | 0:56caa4d851d2 | 20 | send_ATCommand(); |
snec_student | 0:56caa4d851d2 | 21 | return response; |
snec_student | 0:56caa4d851d2 | 22 | } |
snec_student | 0:56caa4d851d2 | 23 | |
snec_student | 0:56caa4d851d2 | 24 | char* Emetteur::get_FW() |
snec_student | 0:56caa4d851d2 | 25 | { |
snec_student | 0:56caa4d851d2 | 26 | for(uint8_t i=0; i<6; i++)command[i] = AT_FW[i]; |
snec_student | 0:56caa4d851d2 | 27 | for(uint8_t i=0; i<3; i++)command[6+i] = AT_REQUEST[i]; |
snec_student | 0:56caa4d851d2 | 28 | send_ATCommand(); |
snec_student | 0:56caa4d851d2 | 29 | return response; |
snec_student | 0:56caa4d851d2 | 30 | } |
snec_student | 0:56caa4d851d2 | 31 | |
snec_student | 0:56caa4d851d2 | 32 | char* Emetteur::get_PWR() |
snec_student | 0:56caa4d851d2 | 33 | { |
snec_student | 0:56caa4d851d2 | 34 | for(uint8_t i=0; i<7; i++)command[i] = AT_PWR[i]; |
snec_student | 0:56caa4d851d2 | 35 | for(uint8_t i=0; i<3; i++)command[7+i] = AT_REQUEST[i]; |
snec_student | 0:56caa4d851d2 | 36 | send_ATCommand(); |
snec_student | 0:56caa4d851d2 | 37 | return response; |
snec_student | 0:56caa4d851d2 | 38 | } |
snec_student | 0:56caa4d851d2 | 39 | |
snec_student | 0:56caa4d851d2 | 40 | char* Emetteur::get_BAND() |
snec_student | 0:56caa4d851d2 | 41 | { |
snec_student | 0:56caa4d851d2 | 42 | for(uint8_t i=0; i<8; i++)command[i] = AT_BAND[i]; |
snec_student | 0:56caa4d851d2 | 43 | for(uint8_t i=0; i<3; i++)command[8+i] = AT_REQUEST[i]; |
snec_student | 0:56caa4d851d2 | 44 | send_ATCommand(); |
snec_student | 0:56caa4d851d2 | 45 | return response; |
snec_student | 0:56caa4d851d2 | 46 | } |
snec_student | 0:56caa4d851d2 | 47 | |
snec_student | 0:56caa4d851d2 | 48 | char* Emetteur::get_FRQ() |
snec_student | 0:56caa4d851d2 | 49 | { |
snec_student | 0:56caa4d851d2 | 50 | for(uint8_t i=0; i<7; i++)command[i] = AT_FRQ[i]; |
snec_student | 0:56caa4d851d2 | 51 | for(uint8_t i=0; i<3; i++)command[7+i] = AT_REQUEST[i]; |
snec_student | 0:56caa4d851d2 | 52 | send_ATCommand(); |
snec_student | 0:56caa4d851d2 | 53 | return response; |
snec_student | 0:56caa4d851d2 | 54 | } |
snec_student | 0:56caa4d851d2 | 55 | |
snec_student | 0:56caa4d851d2 | 56 | char* Emetteur::get_TCXOWU() |
snec_student | 0:56caa4d851d2 | 57 | { |
snec_student | 0:56caa4d851d2 | 58 | for(uint8_t i=0; i<10; i++)command[i] = AT_TCXOWU[i]; |
snec_student | 0:56caa4d851d2 | 59 | for(uint8_t i=0; i<3; i++)command[10+i] = AT_REQUEST[i]; |
snec_student | 0:56caa4d851d2 | 60 | send_ATCommand(); |
snec_student | 0:56caa4d851d2 | 61 | return response; |
snec_student | 0:56caa4d851d2 | 62 | } |
snec_student | 0:56caa4d851d2 | 63 | |
snec_student | 0:56caa4d851d2 | 64 | RetStatusKIMTypeDef Emetteur::set_PWR(char* PWR, uint8_t len) |
snec_student | 0:56caa4d851d2 | 65 | { |
snec_student | 0:56caa4d851d2 | 66 | for(uint8_t i=0; i<7; i++)command[i] = AT_PWR[i]; |
snec_student | 0:56caa4d851d2 | 67 | for(uint8_t i=0; i<len; i++)command[7+i] = PWR[i]; |
snec_student | 0:56caa4d851d2 | 68 | command[7+len] = '\r'; |
snec_student | 0:56caa4d851d2 | 69 | command[8+len] = '\0'; |
snec_student | 0:56caa4d851d2 | 70 | return (send_ATCommand()); |
snec_student | 0:56caa4d851d2 | 71 | } |
snec_student | 0:56caa4d851d2 | 72 | |
snec_student | 0:56caa4d851d2 | 73 | RetStatusKIMTypeDef Emetteur::set_BAND(char* BAND, uint8_t len) |
snec_student | 0:56caa4d851d2 | 74 | { |
snec_student | 0:56caa4d851d2 | 75 | for(uint8_t i=0; i<8; i++)command[i] = AT_BAND[i]; |
snec_student | 0:56caa4d851d2 | 76 | for(uint8_t i=0; i<len; i++)command[8+i] = BAND[i]; |
snec_student | 0:56caa4d851d2 | 77 | command[8+len] = '\r'; |
snec_student | 0:56caa4d851d2 | 78 | command[9+len] = '\0'; |
snec_student | 0:56caa4d851d2 | 79 | return (send_ATCommand()); |
snec_student | 0:56caa4d851d2 | 80 | } |
snec_student | 0:56caa4d851d2 | 81 | |
snec_student | 0:56caa4d851d2 | 82 | RetStatusKIMTypeDef Emetteur::set_FRQ(char* FRQ, uint8_t len) |
snec_student | 0:56caa4d851d2 | 83 | { |
snec_student | 0:56caa4d851d2 | 84 | for(uint8_t i=0; i<7; i++)command[i] = AT_FRQ[i]; |
snec_student | 0:56caa4d851d2 | 85 | for(uint8_t i=0; i<len; i++)command[7+i] = FRQ[i]; |
snec_student | 0:56caa4d851d2 | 86 | command[7+len] = '\r'; |
snec_student | 0:56caa4d851d2 | 87 | command[8+len] = '\0'; |
snec_student | 0:56caa4d851d2 | 88 | return (send_ATCommand()); |
snec_student | 0:56caa4d851d2 | 89 | } |
snec_student | 0:56caa4d851d2 | 90 | |
snec_student | 0:56caa4d851d2 | 91 | bool Emetteur::set_sleepMode(bool mode) |
snec_student | 0:56caa4d851d2 | 92 | { |
snec_student | 0:56caa4d851d2 | 93 | if (mode==false) { // mise en mode sleep du module |
snec_student | 0:56caa4d851d2 | 94 | /* while (kimSerial.readable()>0) { //Clean RX buffer |
snec_student | 0:56caa4d851d2 | 95 | response[0] = kimSerial.getc(); |
snec_student | 0:56caa4d851d2 | 96 | //pc.printf("caractere lu : %x \n",response[0]); |
snec_student | 0:56caa4d851d2 | 97 | wait(0.1); |
snec_student | 0:56caa4d851d2 | 98 | } // fin while */ |
snec_student | 0:56caa4d851d2 | 99 | response[0] = '\0'; |
snec_student | 0:56caa4d851d2 | 100 | power=1; // activation du module |
snec_student | 0:56caa4d851d2 | 101 | for(int i=0; i<2; i++) { |
snec_student | 0:56caa4d851d2 | 102 | //Clean RX buffer car envoie SN number a la mise sous tension |
snec_student | 0:56caa4d851d2 | 103 | response[i] = kimSerial.getc(); |
snec_student | 0:56caa4d851d2 | 104 | //pc.printf("caractere lu : %x \n",response[0]); |
snec_student | 0:56caa4d851d2 | 105 | wait(0.1); |
snec_student | 0:56caa4d851d2 | 106 | } // fin for |
snec_student | 0:56caa4d851d2 | 107 | if (response[0] !=0) |
snec_student | 0:56caa4d851d2 | 108 | {return (true); |
snec_student | 0:56caa4d851d2 | 109 | } |
snec_student | 0:56caa4d851d2 | 110 | else |
snec_student | 0:56caa4d851d2 | 111 | {return (false); |
snec_student | 0:56caa4d851d2 | 112 | } |
snec_student | 0:56caa4d851d2 | 113 | }// fin if mode |
snec_student | 0:56caa4d851d2 | 114 | else { |
snec_student | 0:56caa4d851d2 | 115 | power=0; // mise en mode sleep du module |
snec_student | 0:56caa4d851d2 | 116 | return(true); |
snec_student | 0:56caa4d851d2 | 117 | } // fin else mode |
snec_student | 0:56caa4d851d2 | 118 | } // fin fonction |
snec_student | 0:56caa4d851d2 | 119 | |
snec_student | 0:56caa4d851d2 | 120 | |
snec_student | 0:56caa4d851d2 | 121 | // -------------------------------------------------------------------------- // |
snec_student | 0:56caa4d851d2 | 122 | //! Send data to satellites |
snec_student | 0:56caa4d851d2 | 123 | // -------------------------------------------------------------------------- // |
snec_student | 0:56caa4d851d2 | 124 | |
snec_student | 0:56caa4d851d2 | 125 | RetStatusKIMTypeDef Emetteur::send_data(char *data, uint8_t len) |
snec_student | 0:56caa4d851d2 | 126 | { |
snec_student | 0:56caa4d851d2 | 127 | for(uint8_t i=0; i<6; i++) |
snec_student | 0:56caa4d851d2 | 128 | command[i] = AT_TX[i]; |
snec_student | 0:56caa4d851d2 | 129 | |
snec_student | 0:56caa4d851d2 | 130 | for(uint8_t i=0; i<len; i++) |
snec_student | 0:56caa4d851d2 | 131 | command[6+i] = data[i]; |
snec_student | 0:56caa4d851d2 | 132 | |
snec_student | 0:56caa4d851d2 | 133 | command[6+len] = '\r'; |
snec_student | 0:56caa4d851d2 | 134 | command[7+len] = '\0'; |
snec_student | 0:56caa4d851d2 | 135 | |
snec_student | 0:56caa4d851d2 | 136 | return send_ATCommand(); |
snec_student | 0:56caa4d851d2 | 137 | } |
snec_student | 0:56caa4d851d2 | 138 | |
snec_student | 0:56caa4d851d2 | 139 | |
snec_student | 0:56caa4d851d2 | 140 | |
snec_student | 0:56caa4d851d2 | 141 | RetStatusKIMTypeDef Emetteur::send_ATCommand() |
snec_student | 0:56caa4d851d2 | 142 | { |
snec_student | 0:56caa4d851d2 | 143 | //Serial pc(USBTX,USBRX); |
snec_student | 0:56caa4d851d2 | 144 | while (kimSerial.readable()>0) { //Clean RX buffer |
snec_student | 0:56caa4d851d2 | 145 | response[0] = kimSerial.getc(); |
snec_student | 0:56caa4d851d2 | 146 | //pc.printf("caractere lu : %x \n",response[0]); |
snec_student | 0:56caa4d851d2 | 147 | wait(0.1); |
snec_student | 0:56caa4d851d2 | 148 | } // fin while |
snec_student | 0:56caa4d851d2 | 149 | response[0] = '\0'; |
snec_student | 0:56caa4d851d2 | 150 | //pc.printf("\non a vide buffer\n"); |
snec_student | 0:56caa4d851d2 | 151 | kimSerial.printf(command); |
snec_student | 0:56caa4d851d2 | 152 | char carac=0; |
snec_student | 0:56caa4d851d2 | 153 | char i=0; |
snec_student | 0:56caa4d851d2 | 154 | while ((carac!=0x0a)) { |
snec_student | 0:56caa4d851d2 | 155 | carac=kimSerial.getc(); |
snec_student | 0:56caa4d851d2 | 156 | response[i]=carac; |
snec_student | 0:56caa4d851d2 | 157 | i++; |
snec_student | 0:56caa4d851d2 | 158 | } |
snec_student | 0:56caa4d851d2 | 159 | response[i]=0; |
snec_student | 0:56caa4d851d2 | 160 | //pc.printf("reponse KIM : %x \n",response); |
snec_student | 0:56caa4d851d2 | 161 | if((response[0] != '\0') && ( |
snec_student | 0:56caa4d851d2 | 162 | response[1] == 'K' /*OK*/ || |
snec_student | 0:56caa4d851d2 | 163 | response[1] == 'I' /*+ID*/ || |
snec_student | 0:56caa4d851d2 | 164 | response[1] == 'S' /*+SN*/ || |
snec_student | 0:56caa4d851d2 | 165 | response[1] == 'F' /*+FW*/ || |
snec_student | 0:56caa4d851d2 | 166 | response[1] == 'B' /*+BAND*/|| |
snec_student | 0:56caa4d851d2 | 167 | response[1] == 'F' /*+FRQ*/ || |
snec_student | 0:56caa4d851d2 | 168 | response[1] == 'P' /*+PWR*/)) { |
snec_student | 0:56caa4d851d2 | 169 | return OK_KIM; |
snec_student | 0:56caa4d851d2 | 170 | } else if (response[0] != '\0' && response[1] == 'R') { |
snec_student | 0:56caa4d851d2 | 171 | /*ERROR*/ |
snec_student | 0:56caa4d851d2 | 172 | return ERROR_KIM; |
snec_student | 0:56caa4d851d2 | 173 | } else if (response[0] != '\0') { |
snec_student | 0:56caa4d851d2 | 174 | return UNKNOWN_ERROR_KIM; |
snec_student | 0:56caa4d851d2 | 175 | } // fin if else |
snec_student | 0:56caa4d851d2 | 176 | return (TIMEOUT_KIM); |
snec_student | 0:56caa4d851d2 | 177 | } |