Programme de contrôle de l'octopode 4DOF, Theraphosa-Salconi.

Dependencies:   debug mbed

CtrlBridge

  • fonction quelquonque pour communiquer avec les module
  • fonction quelquonque pour faire des recherche dans les module dispo
  • autre fonction pour jouer avec MemRegistre

Version 1.2.0

  • Ajout d'un mode de simulation pour tester le code avec seulement un contrôleur stm32
Committer:
salco
Date:
Wed Apr 22 19:27:44 2015 +0000
Revision:
15:91b3c572d9df
Voila la communication est authentifier des deux coter. Reste plus qu'a utiliser les bytes transporter dans cette communication.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
salco 15:91b3c572d9df 1 #include "CRC16.h"
salco 15:91b3c572d9df 2
salco 15:91b3c572d9df 3 /*
salco 15:91b3c572d9df 4 * FUNCTION: calcCRC calculates a 2-byte CRC on serial data using
salco 15:91b3c572d9df 5 * CRC-CCITT 16-bit standard maintained by the ITU
salco 15:91b3c572d9df 6 * ARGUMENTS: queue_ptr is pointer to queue holding are a to be CRCed
salco 15:91b3c572d9df 7 * queue_size is offset into buffer where to stop CRC calculation
salco 15:91b3c572d9df 8 * RETURNS: 2-byte CRC
salco 15:91b3c572d9df 9 */
salco 15:91b3c572d9df 10
salco 15:91b3c572d9df 11 #define POLY 0x8005//0x8408
salco 15:91b3c572d9df 12 /*
salco 15:91b3c572d9df 13 // 16 12 5
salco 15:91b3c572d9df 14 // this is the CCITT CRC 16 polynomial X + X + X + 1.
salco 15:91b3c572d9df 15 // This works out to be 0x1021, but the way the algorithm works
salco 15:91b3c572d9df 16 // lets us use 0x8408 (the reverse of the bit pattern). The high
salco 15:91b3c572d9df 17 // bit is always assumed to be set, thus we only use 16 bits to
salco 15:91b3c572d9df 18 // represent the 17 bit value.
salco 15:91b3c572d9df 19 */
salco 15:91b3c572d9df 20
salco 15:91b3c572d9df 21
salco 15:91b3c572d9df 22 uint16_t CRC16_BUYPASS(const char *data, size_t len) {
salco 15:91b3c572d9df 23 uint16_t crc = 0x0000;
salco 15:91b3c572d9df 24 size_t j;
salco 15:91b3c572d9df 25 int i;
salco 15:91b3c572d9df 26 for (j=len; j>0; j--) {
salco 15:91b3c572d9df 27 crc ^= (uint16_t)(*data++) << 8;
salco 15:91b3c572d9df 28 for (i=0; i<8; i++) {
salco 15:91b3c572d9df 29 if (crc & 0x8000) crc = (crc<<1) ^ 0x8005;
salco 15:91b3c572d9df 30 else crc <<= 1;
salco 15:91b3c572d9df 31 }
salco 15:91b3c572d9df 32 }
salco 15:91b3c572d9df 33 return (crc);
salco 15:91b3c572d9df 34 }
salco 15:91b3c572d9df 35
salco 15:91b3c572d9df 36 /*int main() {
salco 15:91b3c572d9df 37 uint8_t test[9] = {0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
salco 15:91b3c572d9df 38 uint8_t tgil[29] = {0x00,0x0B,0x01,0x0E,0x01,0xC6,0x00,0x00,0x00,0x00,
salco 15:91b3c572d9df 39 0x00,0x00,0x33,0x31,0x30,0x31,0x34,0x31,0x30,0x30,
salco 15:91b3c572d9df 40 0x41,0x00,0x00,0x04,0x24,0x14,0x16,0x06,0x49};
salco 15:91b3c572d9df 41 uint16_t crc;
salco 15:91b3c572d9df 42 crc = CRC16_BUYPASS(test, 9);
salco 15:91b3c572d9df 43 //printf("Rocksoft check value: 0x%04X, test ", crc);
salco 15:91b3c572d9df 44 //if (crc==0xFEE8) printf("passed.\n"); else printf("failed!\n");
salco 15:91b3c572d9df 45 crc = CRC16_BUYPASS(tgil, 29);
salco 15:91b3c572d9df 46 //printf("CRC gil's data: 0x%04X\n", crc);
salco 15:91b3c572d9df 47 return 0;
salco 15:91b3c572d9df 48 } */
salco 15:91b3c572d9df 49
salco 15:91b3c572d9df 50 unsigned short calculateCRC16(const char *data_p, unsigned short length)
salco 15:91b3c572d9df 51 {
salco 15:91b3c572d9df 52 unsigned char i;
salco 15:91b3c572d9df 53 unsigned int data;
salco 15:91b3c572d9df 54 unsigned int crc = 0xffff;
salco 15:91b3c572d9df 55
salco 15:91b3c572d9df 56 if (length == 0)
salco 15:91b3c572d9df 57 return (~crc);
salco 15:91b3c572d9df 58
salco 15:91b3c572d9df 59 do
salco 15:91b3c572d9df 60 {
salco 15:91b3c572d9df 61 for (i=0, data=(unsigned int)0xff & *data_p++;
salco 15:91b3c572d9df 62 i < 8;
salco 15:91b3c572d9df 63 i++, data >>= 1)
salco 15:91b3c572d9df 64 {
salco 15:91b3c572d9df 65 if ((crc & 0x0001) ^ (data & 0x0001))
salco 15:91b3c572d9df 66 crc = (crc >> 1) ^ POLY;
salco 15:91b3c572d9df 67 else crc >>= 1;
salco 15:91b3c572d9df 68 }
salco 15:91b3c572d9df 69 } while (--length);
salco 15:91b3c572d9df 70
salco 15:91b3c572d9df 71 crc = ~crc;
salco 15:91b3c572d9df 72 data = crc;
salco 15:91b3c572d9df 73 crc = (crc << 8) | (data >> 8 & 0xff);
salco 15:91b3c572d9df 74
salco 15:91b3c572d9df 75 return (crc);
salco 15:91b3c572d9df 76 }