diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..65c5ca88a67c30becee01c5a8816d964b03862f9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b347596884ac92225f5e60628ee944f3cf68f34a --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# Description +This repository contains several libraries intended for the STM32 micro- +processors. + +This repository also includes implementations of several communication +peripherals compatible with the Comm library for several families of the STM32 +micro-processors. + +This libraries include: + +## Utils +An implementation of a simple circular buffer and a placeholder to handle time +functions using a hardware timer. + +## Memory +A set of data structures that simplifies the managment of the memory space of a +Dynamixel slave. It allows to allocate a specific ammount of memory either in +RAM or EPPOM, and also at a pre-defined position or anywhere in the available +memory space. + +It also provides user defined read and write callback functions to further +simplify read and write operations started from the bus master. + +## Comm +A generic communication device which allows working either in blocking mode, in +interrupt mode or DMA mode with almost any communcation peripheral in the STM32. + +It provides a set of user defined callback functions, both on the low level +peripheral side and also in the high level application side, which simplifies +handling the communciation channel. + +## Dynamixel base +This library implements the whole Dynamixel protocol, both version 1 and 2, and +also as a master and as a slave. This implementation is idependant of the +communication channel because it uses the comm library. + +All the operations of both supported versions are available. + +## Dynamixel manager +An experimental library designed to simplify the bus access to the shared +Dynamixel bus by several heterogeneous modules. This library allows to configure +the necessary transactions (READ, WRITE, SYNC_READ, SYNC_WRITE, BULK_READ or +BULK_WRITE) on several dynamixel buses. + +Additionally, each transaction can be configured as periodic or one shot. + + +# Dependencies + + diff --git a/dynamixel_base/include/dynamixel_master.h b/dynamixel_base/include/dynamixel_master.h index 497678494b2f133b149cda4692506c4af707be48..7da7c90be7873723a8b9b27c5db894b792ad787e 100644 --- a/dynamixel_base/include/dynamixel_master.h +++ b/dynamixel_base/include/dynamixel_master.h @@ -6,11 +6,11 @@ #include "dynamixel2.h" #ifndef MAX_DYN_MASTER_TX_BUFFER_LEN - #define MAX_DYN_MASTER_TX_BUFFER_LEN 1024 + #define MAX_DYN_MASTER_TX_BUFFER_LEN 256 #endif #ifndef MAX_DYN_MASTER_RX_BUFFER_LEN - #define MAX_DYN_MASTER_RX_BUFFER_LEN 1024 + #define MAX_DYN_MASTER_RX_BUFFER_LEN 256 #endif /** diff --git a/dynamixel_base/include/dynamixel_slave.h b/dynamixel_base/include/dynamixel_slave.h index 08600215793138be01b2bc230fcb2a2f22b8b4d5..37902b616fd26d24244cd6cfbba0adf54164e5d6 100644 --- a/dynamixel_base/include/dynamixel_slave.h +++ b/dynamixel_base/include/dynamixel_slave.h @@ -8,15 +8,15 @@ #include "ram.h" #ifndef MAX_DYN_SLAVE_TX_BUFFER_LEN - #define MAX_DYN_SLAVE_TX_BUFFER_LEN 1024 + #define MAX_DYN_SLAVE_TX_BUFFER_LEN 256 #endif #ifndef MAX_DYN_SLAVE_RX_BUFFER_LEN - #define MAX_DYN_SLAVE_RX_BUFFER_LEN 1024 + #define MAX_DYN_SLAVE_RX_BUFFER_LEN 256 #endif #ifndef MAX_DYN_SLAVE_REG_BUFFER_LEN - #define MAX_DYN_SLAVE_REG_BUFFER_LEN 1024 + #define MAX_DYN_SLAVE_REG_BUFFER_LEN 256 #endif /** diff --git a/dynamixel_base/src/dynamixel2.c b/dynamixel_base/src/dynamixel2.c index bc3bd0fbeea617889221a1c1fb8005e2995da977..e645c1de97f8b22b5f2616528571bbc0c343a6bb 100644 --- a/dynamixel_base/src/dynamixel2.c +++ b/dynamixel_base/src/dynamixel2.c @@ -41,27 +41,29 @@ void dyn2_set_checksum(unsigned char *packet) { unsigned short int crc_accum=0x0000,i,j,length; - length=*((unsigned short int *)&packet[DYN2_LENGTH_OFF])+5; + length=dyn2_get_length(packet)+5; for(j=0;j<length;j++) { i=((unsigned short)(crc_accum>>8)^packet[j])&0xFF; crc_accum=(crc_accum<<8)^crc_table[i]; } - - *((unsigned short int *)&packet[length])=crc_accum; + + packet[length]=crc_accum%256; + packet[length+1]=crc_accum/256; } unsigned char dyn2_check_checksum(unsigned char *packet) { unsigned short int crc_accum=0x0000,i,j,length; - length=*((unsigned short int *)&packet[DYN2_LENGTH_OFF])+5; + length=dyn2_get_length(packet)+5; for(j=0;j<length;j++) { i=((unsigned short)(crc_accum>>8)^packet[j])&0xFF; crc_accum=(crc_accum<<8)^crc_table[i]; } - if(*((unsigned short int *)&packet[length])==crc_accum) + crc_accum-=(packet[length]+packet[length+1]*256); + if(crc_accum==0) return 0x01; else return 0x00; @@ -72,7 +74,7 @@ void dyn2_copy_packet(unsigned char *source, unsigned char *destination) { unsigned short int i,length; - length=*((unsigned short int *)&source[DYN2_LENGTH_OFF])+7; + length=dyn2_get_length(source)+7; for(i=0;i<length;i++) destination[i]=source[i]; } @@ -84,7 +86,7 @@ unsigned char dyn2_get_id(unsigned char *packet) unsigned short int dyn2_get_length(unsigned char *packet) { - return *((unsigned short int *)&packet[DYN2_LENGTH_OFF]); + return (packet[DYN2_LENGTH_OFF]+packet[DYN2_LENGTH_OFF+1]*256); } TDynInstruction dyn2_get_instruction(unsigned char *packet) @@ -136,19 +138,21 @@ void dyn2_init_read_packet(unsigned char *packet,unsigned char id,unsigned short packet[DYN2_LENGTH_OFF]=0x07; packet[DYN2_LENGTH_OFF+1]=0x00; packet[DYN2_INST_OFF]=DYN_READ; - *((unsigned short int *)&packet[DYN2_DATA_OFF])=address; - *((unsigned short int *)&packet[DYN2_DATA_OFF+2])=length; + packet[DYN2_DATA_OFF]=address%256; + packet[DYN2_DATA_OFF+1]=address/256; + packet[DYN2_DATA_OFF+2]=length%256; + packet[DYN2_DATA_OFF+3]=length/256; dyn2_set_checksum(packet); } unsigned short int dyn2_get_read_length(unsigned char *packet) { - return *((unsigned short int *)&packet[DYN2_DATA_OFF+2]); + return (packet[DYN2_DATA_OFF+2]+packet[DYN2_DATA_OFF+3]*256); } unsigned short int dyn2_get_read_address(unsigned char *packet) { - return *((unsigned short int *)&packet[DYN2_DATA_OFF]); + return (packet[DYN2_DATA_OFF]+packet[DYN2_DATA_OFF+1]*256); } /* write instruction */ @@ -161,9 +165,11 @@ void dyn2_init_write_packet(unsigned char *packet,unsigned char id,unsigned shor packet[DYN2_HEADER_OFF+2]=0xFD; packet[DYN2_RESERVED]=0x00; packet[DYN2_ID_OFF]=id; - *((unsigned short int *)&packet[DYN2_LENGTH_OFF])=5+length; + packet[DYN2_LENGTH_OFF]=(length+5)%256; + packet[DYN2_LENGTH_OFF+1]=(length+5)/256; packet[DYN2_INST_OFF]=DYN_WRITE; - *((unsigned short int *)&packet[DYN2_DATA_OFF])=address; + packet[DYN2_DATA_OFF]=address%256; + packet[DYN2_DATA_OFF+1]=address/256; for(i=0;i<length;i++) packet[DYN2_DATA_OFF+i+2]=data[i]; dyn2_set_checksum(packet); @@ -171,12 +177,12 @@ void dyn2_init_write_packet(unsigned char *packet,unsigned char id,unsigned shor unsigned short int dyn2_get_write_address(unsigned char *packet) { - return *((unsigned short int *)&packet[DYN2_DATA_OFF]); + return (packet[DYN2_DATA_OFF]+packet[DYN2_DATA_OFF+1]*256); } unsigned short int dyn2_get_write_length(unsigned char *packet) { - return *((unsigned short int *)&packet[DYN2_LENGTH_OFF])-5; + return (packet[DYN2_LENGTH_OFF]+packet[DYN2_LENGTH_OFF+1]*256)-5; } unsigned short int dyn2_get_write_data(unsigned char *packet,unsigned char *data) @@ -200,9 +206,11 @@ void dyn2_init_reg_write_packet(unsigned char *packet,unsigned char id,unsigned packet[DYN2_HEADER_OFF+2]=0xFD; packet[DYN2_RESERVED]=0x00; packet[DYN2_ID_OFF]=id; - *((unsigned short int *)&packet[DYN2_LENGTH_OFF])=5+length; + packet[DYN2_LENGTH_OFF]=(length+5)%256; + packet[DYN2_LENGTH_OFF+1]=(length+5)/256; packet[DYN2_INST_OFF]=DYN_REG_WRITE; - *((unsigned short int *)&packet[DYN2_DATA_OFF])=address; + packet[DYN2_DATA_OFF]=address%256; + packet[DYN2_DATA_OFF+1]=address/256; for(i=0;i<length;i++) packet[DYN2_DATA_OFF+i+2]=data[i]; dyn2_set_checksum(packet); @@ -210,12 +218,12 @@ void dyn2_init_reg_write_packet(unsigned char *packet,unsigned char id,unsigned unsigned short int dyn2_get_reg_write_address(unsigned char *packet) { - return *((unsigned short int *)&packet[DYN2_DATA_OFF]); + return (packet[DYN2_DATA_OFF]+packet[DYN2_DATA_OFF+1]*256); } unsigned short int dyn2_get_reg_write_length(unsigned char *packet) { - return *((unsigned short int *)&packet[DYN2_LENGTH_OFF])-5; + return (packet[DYN2_LENGTH_OFF]+packet[DYN2_LENGTH_OFF+1]*256)-5; } unsigned short int dyn2_get_reg_write_data(unsigned char *packet,unsigned char *data) @@ -262,17 +270,21 @@ void dyn2_init_reset_packet(unsigned char *packet,unsigned char id,unsigned char void dyn2_init_sync_write_packet(unsigned char *packet,unsigned char num_servos,unsigned char *servo_ids,unsigned short int address,unsigned short int length,unsigned char * const data[]) { unsigned char i; - unsigned short int j; + unsigned short int j,len; packet[DYN2_HEADER_OFF]=0xFF; packet[DYN2_HEADER_OFF+1]=0xFF; packet[DYN2_HEADER_OFF+2]=0xFD; packet[DYN2_RESERVED]=0x00; packet[DYN2_ID_OFF]=0xFE; - *((unsigned short int *)&packet[DYN2_LENGTH_OFF])=7+(length+1)*num_servos; + len=7+(length+1)*num_servos; + packet[DYN2_LENGTH_OFF]=len%256; + packet[DYN2_LENGTH_OFF+1]=len/256; packet[DYN2_INST_OFF]=DYN_SYNC_WRITE; - *((unsigned short int *)&packet[DYN2_DATA_OFF])=address; - *((unsigned short int *)&packet[DYN2_DATA_OFF+2])=length; + packet[DYN2_DATA_OFF]=address%256; + packet[DYN2_DATA_OFF+1]=address/256; + packet[DYN2_DATA_OFF+2]=length%256; + packet[DYN2_DATA_OFF+3]=length/256; for(i=0;i<num_servos;i++) { packet[DYN2_DATA_OFF+4+(length+1)*i]=servo_ids[i]; @@ -287,13 +299,13 @@ unsigned char dyn2_sync_write_id_present(unsigned char *packet,unsigned char id, unsigned char num_servos,i; unsigned short int j,len; - len=*((unsigned short int *)&packet[DYN2_DATA_OFF+2]); - num_servos=(*((unsigned short int *)&packet[DYN2_LENGTH_OFF])-7)/(len+1); + len=packet[DYN2_DATA_OFF+2]+packet[DYN2_DATA_OFF+3]*256; + num_servos=((packet[DYN2_LENGTH_OFF]+packet[DYN2_LENGTH_OFF+1]*256)-7)/(len+1); for(i=0;i<num_servos;i++) if(packet[DYN2_DATA_OFF+4+(len+1)*i]==id) { - (*address)=*((unsigned short int *)&packet[DYN2_DATA_OFF]); - (*length)=*((unsigned short int *)&packet[DYN2_DATA_OFF+2]); + (*address)=packet[DYN2_DATA_OFF]+packet[DYN2_DATA_OFF+1]*256; + (*length)=packet[DYN2_DATA_OFF+2]+packet[DYN2_DATA_OFF+3]*256; for(j=0;j<(*length);j++) data[j]=packet[DYN2_DATA_OFF+4+(len+1)*i+j+1]; return 0x01; @@ -311,10 +323,13 @@ void dyn2_init_sync_read_packet(unsigned char *packet,unsigned char num_servos,u packet[DYN2_HEADER_OFF+2]=0xFD; packet[DYN2_RESERVED]=0x00; packet[DYN2_ID_OFF]=0xFE; - *((unsigned short int *)&packet[DYN2_LENGTH_OFF])=7+num_servos; + packet[DYN2_LENGTH_OFF]=(7+num_servos)%256; + packet[DYN2_LENGTH_OFF+1]=(7+num_servos)/256; packet[DYN2_INST_OFF]=DYN_SYNC_READ; - *((unsigned short int *)&packet[DYN2_DATA_OFF])=address; - *((unsigned short int *)&packet[DYN2_DATA_OFF+2])=length; + packet[DYN2_DATA_OFF]=address%256; + packet[DYN2_DATA_OFF+1]=address/256; + packet[DYN2_DATA_OFF+2]=length%256; + packet[DYN2_DATA_OFF+3]=length/256; for(i=0;i<num_servos;i++) packet[DYN2_DATA_OFF+4+i]=servo_ids[i]; dyn2_set_checksum(packet); @@ -324,12 +339,12 @@ unsigned char dyn2_sync_read_id_present(unsigned char *packet,unsigned char id,u { unsigned char num_servos,i; - num_servos=(*((unsigned short int *)&packet[DYN2_LENGTH_OFF])-7); + num_servos=(packet[DYN2_LENGTH_OFF]+packet[DYN2_LENGTH_OFF+1]*256)-7; for(i=0;i<num_servos;i++) if(packet[DYN2_DATA_OFF+4+i]==id) { - (*address)=*((unsigned short int *)&packet[DYN2_DATA_OFF]); - (*length)=*((unsigned short int *)&packet[DYN2_DATA_OFF+2]); + (*address)=packet[DYN2_DATA_OFF]+packet[DYN2_DATA_OFF+1]*256; + (*length)=packet[DYN2_DATA_OFF+2]+packet[DYN2_DATA_OFF+3]*256; if(i==0) return 0x00; else @@ -342,19 +357,24 @@ unsigned char dyn2_sync_read_id_present(unsigned char *packet,unsigned char id,u void dyn2_init_bulk_read_packet(unsigned char *packet,unsigned char num_servos,unsigned char *servo_ids,unsigned short int *address,unsigned short int *length) { unsigned char i; + unsigned short int len; packet[DYN2_HEADER_OFF]=0xFF; packet[DYN2_HEADER_OFF+1]=0xFF; packet[DYN2_HEADER_OFF+2]=0xFD; packet[DYN2_RESERVED]=0x00; packet[DYN2_ID_OFF]=0xFE; - *((unsigned short int *)&packet[DYN2_LENGTH_OFF])=3+5*num_servos; + len=3+5*num_servos; + packet[DYN2_LENGTH_OFF]=len%256; + packet[DYN2_LENGTH_OFF+1]=len/256; packet[DYN2_INST_OFF]=DYN_BULK_READ; for(i=0;i<num_servos;i++) { packet[DYN2_DATA_OFF+i*5]=servo_ids[i]; - *((unsigned short int *)&packet[DYN2_DATA_OFF+i*5+1])=address[i]; - *((unsigned short int *)&packet[DYN2_DATA_OFF+i*5+3])=length[i]; + packet[DYN2_DATA_OFF+i*5+1]=address[i]%256; + packet[DYN2_DATA_OFF+i*5+2]=address[i]/256; + packet[DYN2_DATA_OFF+i*5+3]=length[i]%256; + packet[DYN2_DATA_OFF+i*5+4]=length[i]/256; } dyn2_set_checksum(packet); } @@ -363,12 +383,12 @@ unsigned char dyn2_bulk_read_id_present(unsigned char *packet,unsigned char id,u { unsigned char num_servos,i,prev_id=0xFF; - num_servos=(*((unsigned short int *)&packet[DYN2_LENGTH_OFF])-3)/5; + num_servos=(packet[DYN2_LENGTH_OFF]+packet[DYN2_LENGTH_OFF+1]*256-3)/5; for(i=0;i<num_servos;i++) if(packet[DYN2_DATA_OFF+i*5]==id) { - (*address)=*((unsigned short int *)&packet[DYN2_DATA_OFF+i*5+1]); - (*length)=*((unsigned short int *)&packet[DYN2_DATA_OFF+i*5+3]); + (*address)=packet[DYN2_DATA_OFF+i*5+1]+packet[DYN2_DATA_OFF+i*5+2]*256; + (*length)=packet[DYN2_DATA_OFF+i*5+3]+packet[DYN2_DATA_OFF+i*5+4]*256; if(i==0) return 0x00; else @@ -392,15 +412,17 @@ void dyn2_init_bulk_write_packet(unsigned char *packet,unsigned char num_servos, packet[DYN2_ID_OFF]=0xFE; for(i=0;i<num_servos;i++) total_length+=length[i]+5; - *((unsigned short int *)&packet[DYN2_LENGTH_OFF])=3+total_length; + packet[DYN2_LENGTH_OFF]=(3+total_length)%256; + packet[DYN2_LENGTH_OFF+1]=(3+total_length)/256; packet[DYN2_INST_OFF]=DYN_BULK_WRITE; total_length=0; for(i=0;i<num_servos;i++) { packet[DYN2_DATA_OFF+total_length]=servo_ids[i]; - *((unsigned short int *)&packet[DYN2_DATA_OFF+total_length+1])=address[i]; - *((unsigned short int *)&packet[DYN2_DATA_OFF+total_length+3])=length[i]; - packet[DYN2_DATA_OFF+total_length+4]=(length[i]>>8)&0x00FF; + packet[DYN2_DATA_OFF+total_length+1]=address[i]%256; + packet[DYN2_DATA_OFF+total_length+2]=address[i]/256; + packet[DYN2_DATA_OFF+total_length+3]=length[i]%256; + packet[DYN2_DATA_OFF+total_length+4]=length[i]/256; for(j=0;j<length[i];j++) packet[DYN2_DATA_OFF+total_length+5+j]=data[i][j]; total_length+=length[i]+5; @@ -412,19 +434,19 @@ unsigned char dyn2_bulk_write_id_present(unsigned char *packet,unsigned char id, { unsigned short int len,offset=0,i; - len=*((unsigned short int *)&packet[DYN2_LENGTH_OFF])-3; + len=packet[DYN2_LENGTH_OFF]+packet[DYN2_LENGTH_OFF+1]*256-3; while(offset<len) { if(packet[DYN2_DATA_OFF+offset]==id) { - (*address)=*((unsigned short int *)&packet[DYN2_DATA_OFF+offset+1]); - (*length)=*((unsigned short int *)&packet[DYN2_DATA_OFF+offset+3]); - for(i=0;i<*((unsigned short int *)&packet[DYN2_DATA_OFF+offset+3]);i++) + (*address)=packet[DYN2_DATA_OFF+offset+1]+packet[DYN2_DATA_OFF+offset+2]*256; + (*length)=packet[DYN2_DATA_OFF+offset+3]+packet[DYN2_DATA_OFF+offset+4]*256; + for(i=0;i<(*length);i++) data[i]=packet[DYN2_DATA_OFF+offset+5+i]; return 0x01; } else - offset+=*((unsigned short int *)&packet[DYN2_DATA_OFF+offset+3])+5; + offset+=packet[DYN2_DATA_OFF+offset+3]+packet[DYN2_DATA_OFF+offset+4]*256+5; } return 0x00; @@ -460,7 +482,8 @@ void dyn2_init_status_packet(unsigned char *packet,unsigned char id,TDynError er packet[DYN2_HEADER_OFF+2]=0xFD; packet[DYN2_RESERVED]=0x00; packet[DYN2_ID_OFF]=id; - *((unsigned short int *)&packet[DYN2_LENGTH_OFF])=4+length; + packet[DYN2_LENGTH_OFF]=(4+length)%256; + packet[DYN2_LENGTH_OFF+1]=(4+length)/256; packet[DYN2_INST_OFF]=0x55; packet[DYN2_DATA_OFF]=error; for(i=0;i<length;i++) @@ -478,7 +501,7 @@ unsigned short int dyn2_get_read_status_data(unsigned char *packet,unsigned char { unsigned short int i,length; - length=*((unsigned short int *)&packet[DYN2_LENGTH_OFF])-4; + length=packet[DYN2_LENGTH_OFF]+packet[DYN2_LENGTH_OFF+1]*256-4; for(i=0;i<length;i++) data[i]=packet[DYN2_DATA_OFF+1+i]; diff --git a/dynamixel_base/src/dynamixel_slave.c b/dynamixel_base/src/dynamixel_slave.c index 69a43fa2f67af55c9b46b811b6044b5cadd67fe5..e1818981fa23d44bc06a1f2ae9d8159010b2acab 100644 --- a/dynamixel_base/src/dynamixel_slave.c +++ b/dynamixel_base/src/dynamixel_slave.c @@ -177,7 +177,6 @@ unsigned char dummy_dyn_slave_on_relay(TDynVersion version,unsigned char *inst_p return DYN_NO_DEVICE; } - void dyn_slave_send_status_packet(TDynamixelSlave *slave,unsigned char error,unsigned short int length, unsigned char *data) { if(slave!=0x00000000) diff --git a/f1/usart/src/usart1.c b/f1/usart/src/usart1.c index 1be5b4adaa7d61dd333d5095cdb12396a049dfef..7a087719a9ac2e54cb0fee8e483b14636d1c4476 100644 --- a/f1/usart/src/usart1.c +++ b/f1/usart/src/usart1.c @@ -1,5 +1,4 @@ #include "usart1.h" -#include "gpio.h" #define USART USART1 #define USART_ENABLE_CLK __HAL_RCC_USART1_CLK_ENABLE() diff --git a/utils/include/buffer.h b/utils/include/buffer.h index 18382d2460faab2935d1830ffcd8102c0dc603c4..69a3274385fbd520334684dbfea4e0fe9df39d91 100644 --- a/utils/include/buffer.h +++ b/utils/include/buffer.h @@ -8,7 +8,7 @@ * \brief Size of the buffer in bytes * */ - #define MAX_BUFFER_LENGTH 512 + #define MAX_BUFFER_LENGTH 256 #endif /**