├── COPYING ├── README ├── rfbb ├── COPYING ├── Makefile └── rfbb.c ├── rfbb_cmd ├── Makefile └── rfbb_cmd.c ├── rfbb_hardware.txt └── rfcmd ├── COPYING ├── Makefile └── rfcmd.c /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 19yy 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) 19yy name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | rf-bitbanger 2 | ============ 3 | Simple tools for experiments with bitbanged RF communication. 4 | 5 | License: GPL v2. See the COPYING file. 6 | 7 | Disclaimer 8 | ---------- 9 | Do not use the tools and code in situations where operation or lack of operation may result in 10 | property damage, personal injury, or death. 11 | Rules and regulations may control the use of RF communication at a national level. 12 | Do not use rf-bitbanger tools or code to break applicable laws and regulations. 13 | 14 | rfbb driver 15 | ----------- 16 | LIRC style device driver that transmits and records pulse and pause-lengths using gpio. 17 | Uses code from lirc_serial.c by Ralph Metzler et al. 18 | See rfbb_hardware.txt for information on how to connect the GPIO to a common 433 MHz TX module. 19 | 20 | To build on target: 21 | 22 | > cd rf-bitbanger/rfbb 23 | > make KERNELDIR=~/linux 24 | > sudo insmod rfbb.ko 25 | 26 | Check for device node and add if not already there using dialout as group: 27 | > ls -al /dev/rfbb 28 | > dmesg 29 | > sudo mknod /dev/rfbb c 252 0 30 | > sudo chown root:dialout /dev/rfbb 31 | > sudo chmod g+rw /dev/rfbb 32 | 33 | 34 | rfbb_cmd 35 | -------- 36 | rfbb_cmd is a small tool, that acts as a remote control for switches that use 37 | simple unidirectional communication based on OOK (On Off Keying) modulation on a 433 MHz 38 | carrier. 39 | rfbb_cmd uses the linux rfbb kernel driver. 40 | 41 | To build: 42 | 43 | > cd rf-bitbanger/rfbb_cmd 44 | > make 45 | > sudo make install 46 | 47 | A simple test on an old style (not selflearning) NEXA/PROVE/ARC set to group D, channel 1. 48 | 49 | > rfbb_cmd -d /dev/rfbb -i RFBB -p NEXA -g D -c 1 -l 1 50 | > rfbb_cmd -d /dev/rfbb -i RFBB -p NEXA -g D -c 1 -l 0 51 | 52 | Issue rfbb_cmd --help to get more information on supported protocols and options. 53 | Note! All protocols might not be fully tested due to lack of receivers and time :). 54 | 55 | rfcmd 56 | ----- 57 | rfcmd is a another small tool that acts as a remote control for switches that use simple unidirectional 58 | communication based on OOK (On Off Keying) modulation on a 433 MHz. 59 | rfcmd use tellstick (www.telldus.se) as transmitter instead of rfbb. 60 | 61 | To build and test: 62 | 63 | > cd rf-bitbanger/rfcmd 64 | > make 65 | > sudo make install 66 | > rfcmd /dev/ttyUSB0 NEXA A 1 1 67 | > rfcmd /dev/ttyUSB0 NEXA A 1 0 68 | 69 | Issue rfcmd --help to get more information on supported protocols and options. 70 | 71 | 72 | /Last update: 2012-07-03 Tord Andersson 73 | -------------------------------------------------------------------------------- /rfbb/COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 19yy 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) 19yy name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | -------------------------------------------------------------------------------- /rfbb/Makefile: -------------------------------------------------------------------------------- 1 | ifneq ($(KERNELRELEASE),) 2 | #invoked from the kernel build system 3 | 4 | obj-m += rfbb.o 5 | 6 | else 7 | #invoked directly from the command line 8 | ifneq ($(KERNEL_DIR),) 9 | KERNELDIR := $(KERNEL_DIR) 10 | endif 11 | 12 | ifneq ($(EBT_ARCH),) 13 | ARGS += ARCH=$(EBT_ARCH) 14 | endif 15 | 16 | ifneq ($(EBT_HOST_CROSS),) 17 | ARGS += CROSS_COMPILE=$(EBT_HOST_CROSS) 18 | endif 19 | 20 | 21 | PWD := $(shell pwd) 22 | 23 | default: 24 | $(MAKE) -C $(KERNELDIR) M=$(PWD) $(ARGS) modules 25 | 26 | clean: 27 | $(MAKE) -C $(KERNELDIR) M=$(PWD) $(ARGS) clean 28 | 29 | endif 30 | -------------------------------------------------------------------------------- /rfbb/rfbb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rfbb.c 3 | * 4 | * rfbb - Device driver that transmits and records pulse 5 | * and pause-lengths using gpio. 6 | * Previous name rf_bitbanger.c. 7 | * Based on lirc_serial.c by Ralph Metzler et al 8 | * Uses code parts from the lirc framework (www.lirc.org). 9 | * 10 | * Copyright (C) 2010, 2012 Tord Andersson 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | * 25 | */ 26 | 27 | 28 | #ifdef HAVE_CONFIG_H 29 | # include 30 | #endif 31 | 32 | #include 33 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32) 34 | #error "**********************************************************" 35 | #error " Sorry, this driver needs kernel version 2.6.32 or higher " 36 | #error "**********************************************************" 37 | #endif 38 | 39 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33) 40 | #include 41 | #endif 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | 69 | 70 | #define RFBB_DRIVER_VERSION "0.05" 71 | #define RFBB_DRIVER_NAME "rfbb" 72 | 73 | #define MAX_RFBB_DEVS 1 /* One device only */ 74 | 75 | #define HW_MODE_POWER_DOWN 0 /* Transceiver in power down mode */ 76 | #define HW_MODE_RX 1 77 | #define HW_MODE_TX 2 78 | 79 | /* Borrowed LIRC definitions */ 80 | #define LIRC_MODE2_SPACE 0x00000000 81 | #define LIRC_MODE2_PULSE 0x01000000 82 | #define LIRC_MODE2_TIMEOUT 0x03000000 83 | 84 | #define LIRC_VALUE_MASK 0x00FFFFFF 85 | #define LIRC_MODE2_MASK 0xFF000000 86 | 87 | typedef int32_t lirc_t; 88 | 89 | /* 90 | * We export one rfbb device. 91 | */ 92 | static struct cdev rfbbDevs[MAX_RFBB_DEVS]; 93 | 94 | struct rfbb { 95 | int tx_pin; 96 | int rx_pin; 97 | int tx_ctrl_pin; 98 | int rf_enable_pin; 99 | void (*send_pulse)(unsigned long length); 100 | void (*send_space)(unsigned long length); 101 | }; 102 | 103 | #define RFBB_GPIO 0 /* RFBB_TYPE */ 104 | #define RFBB_NO_GPIO_PIN -1 105 | #define RFBB_NO_RX_IRQ -1 106 | 107 | static int type = RFBB_GPIO; 108 | static int rfbb_major = 0; /* use dynamic major number assignment */ 109 | 110 | static int share_irq = 0; 111 | static int interrupt_enabled = 0; 112 | static bool debug = false; 113 | static int device_open = 0; 114 | static int hw_mode = HW_MODE_POWER_DOWN; 115 | 116 | static DEFINE_MUTEX(read_lock); 117 | 118 | #define dprintk(fmt, args...) \ 119 | do { \ 120 | if (debug) \ 121 | printk(KERN_DEBUG RFBB_DRIVER_NAME ": " \ 122 | fmt, ## args); \ 123 | } while (0) 124 | 125 | /* forward declarations */ 126 | static void set_tx_mode(void); /* set up transceiver for transmission */ 127 | static void set_rx_mode(void); /* set up transceiver for reception */ 128 | static void on(void); /* TX signal on */ 129 | static void off(void); /* TX signal off */ 130 | static void send_pulse_gpio(unsigned long length); 131 | static void send_space_gpio(unsigned long length); 132 | static void rfbb_exit_module(void); 133 | 134 | static struct rfbb hardware[] = { 135 | [RFBB_GPIO] = { 136 | .tx_pin = 17, 137 | .rx_pin = RFBB_NO_GPIO_PIN, /* only tx now */ 138 | .tx_ctrl_pin = RFBB_NO_GPIO_PIN, /* not used */ 139 | .rf_enable_pin = RFBB_NO_GPIO_PIN, /* not used */ 140 | .send_pulse = send_pulse_gpio, 141 | .send_space = send_space_gpio, 142 | }, 143 | }; 144 | 145 | #define RS_ISR_PASS_LIMIT 256 146 | 147 | /* 148 | * A long pulse code from a remote might take up to 300 bytes. The 149 | * daemon should read the bytes as soon as they are generated, so take 150 | * the number of keys you think you can push before the daemon runs 151 | * and multiply by 300. The driver will warn you if you overrun this 152 | * buffer. If you have a slow computer or non-busmastering IDE disks, 153 | * maybe you will need to increase this. 154 | */ 155 | 156 | 157 | #define RBUF_LEN 4096 158 | #define WBUF_LEN 4096 159 | 160 | static int sense = 0; /* -1 = auto, 0 = active high, 1 = active low */ 161 | 162 | static int irq = RFBB_NO_RX_IRQ; 163 | 164 | static struct timeval lasttv = {0, 0}; 165 | 166 | /* static struct lirc_buffer rbuf; */ 167 | 168 | /* Use FIFO to store received pulses */ 169 | static DEFINE_KFIFO(rxfifo, int, RBUF_LEN); 170 | 171 | static int wbuf[WBUF_LEN]; 172 | 173 | /* AUREL RTX-MID transceiver TX setup sequence 174 | will use rf_enable as well as tx_ctrl pins. 175 | Not used for simple TX modules */ 176 | static void set_tx_mode(void) 177 | { 178 | off(); 179 | switch(hw_mode) 180 | { 181 | case HW_MODE_POWER_DOWN: 182 | if(hardware[type].rf_enable_pin != RFBB_NO_GPIO_PIN) 183 | { 184 | gpio_set_value(hardware[type].rf_enable_pin, 1); 185 | udelay(20); 186 | } 187 | if(hardware[type].tx_ctrl_pin != RFBB_NO_GPIO_PIN) 188 | { 189 | gpio_set_value(hardware[type].tx_ctrl_pin, 1); 190 | udelay(400); /* let it settle */ 191 | } 192 | break; 193 | 194 | case HW_MODE_TX: 195 | /* do nothing */ 196 | break; 197 | 198 | case HW_MODE_RX: 199 | if(hardware[type].rf_enable_pin != RFBB_NO_GPIO_PIN) 200 | { 201 | gpio_set_value(hardware[type].rf_enable_pin, 1); 202 | } 203 | if(hardware[type].tx_ctrl_pin != RFBB_NO_GPIO_PIN) 204 | { 205 | gpio_set_value(hardware[type].tx_ctrl_pin, 1); 206 | udelay(400); /* let it settle */ 207 | } 208 | break; 209 | 210 | default: 211 | printk(KERN_ERR RFBB_DRIVER_NAME": set_tx_mode. Illegal HW mode %d\n", hw_mode); 212 | break; 213 | } 214 | 215 | hw_mode = HW_MODE_TX; 216 | } 217 | 218 | /* AUREL RTX-MID transceiver RX setup sequence */ 219 | static void set_rx_mode(void) 220 | { 221 | off(); 222 | switch(hw_mode) 223 | { 224 | case HW_MODE_POWER_DOWN: 225 | /* Note this sequence is only needed for AUREL RTX-MID */ 226 | if((hardware[type].rf_enable_pin != RFBB_NO_GPIO_PIN) && (hardware[type].tx_ctrl_pin != RFBB_NO_GPIO_PIN)) 227 | { 228 | gpio_set_value(hardware[type].rf_enable_pin, 1); 229 | gpio_set_value(hardware[type].tx_ctrl_pin, 0); 230 | udelay(20); 231 | gpio_set_value(hardware[type].tx_ctrl_pin, 1); 232 | udelay(200); 233 | gpio_set_value(hardware[type].tx_ctrl_pin, 0); 234 | udelay(40); 235 | gpio_set_value(hardware[type].rf_enable_pin, 0); 236 | udelay(20); 237 | gpio_set_value(hardware[type].rf_enable_pin, 1); 238 | udelay(200); 239 | } 240 | break; 241 | 242 | case HW_MODE_RX: 243 | /* do nothing */ 244 | break; 245 | 246 | case HW_MODE_TX: 247 | if(hardware[type].tx_ctrl_pin != RFBB_NO_GPIO_PIN) 248 | { 249 | gpio_set_value(hardware[type].tx_ctrl_pin, 0); 250 | udelay(40); 251 | } 252 | if(hardware[type].rf_enable_pin != RFBB_NO_GPIO_PIN) 253 | { 254 | gpio_set_value(hardware[type].rf_enable_pin, 0); 255 | udelay(20); 256 | gpio_set_value(hardware[type].rf_enable_pin, 1); 257 | udelay(200); 258 | } 259 | break; 260 | 261 | default: 262 | printk(KERN_ERR RFBB_DRIVER_NAME 263 | ": set_rx_mode. Illegal HW mode %d\n", hw_mode); 264 | break; 265 | } 266 | 267 | hw_mode = HW_MODE_RX; 268 | } 269 | 270 | static void on(void) 271 | { 272 | gpio_set_value(hardware[type].tx_pin, 1); 273 | } 274 | 275 | static void off(void) 276 | { 277 | gpio_set_value(hardware[type].tx_pin, 0); 278 | } 279 | 280 | #ifndef MAX_UDELAY_MS 281 | #define MAX_UDELAY_US 5000 282 | #else 283 | #define MAX_UDELAY_US (MAX_UDELAY_MS*1000) 284 | #endif 285 | 286 | static void safe_udelay(unsigned long usecs) 287 | { 288 | while (usecs > MAX_UDELAY_US) { 289 | udelay(MAX_UDELAY_US); 290 | usecs -= MAX_UDELAY_US; 291 | } 292 | udelay(usecs); 293 | } 294 | 295 | static void send_pulse_gpio(unsigned long length) 296 | { 297 | on(); 298 | /* dprintk("send_pulse_gpio %ld us\n", length); */ 299 | safe_udelay(length); 300 | } 301 | 302 | static void send_space_gpio(unsigned long length) 303 | { 304 | off(); 305 | /* dprintk("send_space_gpio %ld us\n", length); */ 306 | safe_udelay(length); 307 | } 308 | 309 | static irqreturn_t irq_handler(int i, void *blah) 310 | { 311 | struct timeval tv; 312 | int status; 313 | long deltv; 314 | lirc_t data = 0; 315 | static int old_status = -1; 316 | static int counter = 0; /* to find burst problems */ 317 | /* static int intCount = 0; */ 318 | 319 | 320 | status = gpio_get_value(hardware[type].rx_pin); 321 | if (status != old_status) { 322 | counter = 0; 323 | 324 | /* get current time */ 325 | do_gettimeofday(&tv); 326 | 327 | /* New mode, written by Trent Piepho 328 | . */ 329 | 330 | /* 331 | * The old format was not very portable. 332 | * We now use an int to pass pulses 333 | * and spaces to user space. 334 | * 335 | * If PULSE_BIT is set a pulse has been 336 | * received, otherwise a space has been 337 | * received. The driver needs to know if your 338 | * receiver is active high or active low, or 339 | * the space/pulse sense could be 340 | * inverted. The bits denoted by PULSE_MASK are 341 | * the length in microseconds. Lengths greater 342 | * than or equal to 16 seconds are clamped to 343 | * PULSE_MASK. All other bits are unused. 344 | * This is a much simpler interface for user 345 | * programs, as well as eliminating "out of 346 | * phase" errors with space/pulse 347 | * autodetection. 348 | */ 349 | 350 | /* calc time since last interrupt in microseconds */ 351 | deltv = tv.tv_sec-lasttv.tv_sec; 352 | if (tv.tv_sec < lasttv.tv_sec || 353 | (tv.tv_sec == lasttv.tv_sec && 354 | tv.tv_usec < lasttv.tv_usec)) { 355 | printk(KERN_WARNING RFBB_DRIVER_NAME 356 | ": AIEEEE: your clock just jumped " 357 | "backwards\n"); 358 | printk(KERN_WARNING RFBB_DRIVER_NAME 359 | ": %d %lx %lx %lx %lx\n", 360 | sense, 361 | tv.tv_sec, lasttv.tv_sec, 362 | tv.tv_usec, lasttv.tv_usec); 363 | data = status ? (data | LIRC_VALUE_MASK) : (data | LIRC_MODE2_PULSE | LIRC_VALUE_MASK); /* handle as too long time */ 364 | } else if (deltv > 15) { 365 | data = status ? (data | LIRC_VALUE_MASK) : (data | LIRC_MODE2_PULSE | LIRC_VALUE_MASK); /* really long time */ 366 | } else 367 | data = (lirc_t) (deltv*1000000 + 368 | tv.tv_usec - 369 | lasttv.tv_usec); 370 | /* frbwrite(status ? data : (data|PULSE_BIT)); */ 371 | lasttv = tv; 372 | old_status = status; 373 | data = status ? data : (data | LIRC_MODE2_PULSE); 374 | /* dprintk("irq_handler. Nr: %d. Pin: %d time: %ld\n", ++intCount, status, (long)(data & PULSE_MASK));*/ 375 | kfifo_put(&rxfifo, &data); 376 | /* wake_up_interruptible(&rbuf.wait_poll); */ 377 | } 378 | else /* could have been a spike */ 379 | { 380 | counter++; 381 | if (counter > RS_ISR_PASS_LIMIT) { 382 | printk(KERN_WARNING RFBB_DRIVER_NAME ": AIEEEE: " 383 | "We're caught!\n"); 384 | counter = 0; /* to avoid flooding warnings */ 385 | } 386 | } 387 | return IRQ_RETVAL(IRQ_HANDLED); 388 | } 389 | 390 | static int hardware_init(void) 391 | { 392 | unsigned long flags; 393 | int err = 0; 394 | 395 | local_irq_save(flags); 396 | 397 | /* First of all, disable all interrupts */ 398 | 399 | if (type == RFBB_GPIO) { 400 | /* Setup all pins */ 401 | if(hardware[type].tx_pin != RFBB_NO_GPIO_PIN) 402 | { 403 | err = gpio_request_one(hardware[type].tx_pin, GPIOF_OUT_INIT_LOW, "RFBB_TX"); 404 | if (err) { 405 | printk(KERN_ERR RFBB_DRIVER_NAME 406 | "Could not request RFBB TX pin, error: %d\n", err); 407 | return -EIO; 408 | } 409 | } 410 | 411 | if(hardware[type].rx_pin != RFBB_NO_GPIO_PIN) 412 | { 413 | err = gpio_request_one(hardware[type].rx_pin, GPIOF_IN, "RFBB_RX"); 414 | if (err) { 415 | printk(KERN_ERR RFBB_DRIVER_NAME 416 | "Could not request RFBB RX pin, error: %d\n", err); 417 | return -EIO; 418 | } 419 | } 420 | 421 | if(hardware[type].tx_ctrl_pin != RFBB_NO_GPIO_PIN) 422 | { 423 | err = gpio_request_one(hardware[type].tx_ctrl_pin, GPIOF_OUT_INIT_LOW, "RFBB_TX_CTRL"); 424 | if (err) { 425 | printk(KERN_ERR RFBB_DRIVER_NAME 426 | "Could not request RFBB TX CTRL pin, error: %d\n", err); 427 | return -EIO; 428 | } 429 | } 430 | 431 | if(hardware[type].rf_enable_pin != RFBB_NO_GPIO_PIN) 432 | { 433 | err = gpio_request_one(hardware[type].rf_enable_pin, GPIOF_OUT_INIT_LOW, "RFBB_RF_ENABLE"); 434 | if (err) { 435 | printk(KERN_ERR RFBB_DRIVER_NAME 436 | "Could not request RFBB RF ENABLE pin, error: %d\n", err); 437 | return -EIO; 438 | } 439 | } 440 | 441 | /* start in TX mode, avoid interrupts */ 442 | set_tx_mode(); 443 | 444 | /* Export pins and make them able to change from sysfs for troubleshooting */ 445 | gpio_export(hardware[type].tx_pin, 1); 446 | if(hardware[type].rf_enable_pin != RFBB_NO_GPIO_PIN) 447 | { 448 | gpio_export(hardware[type].rf_enable_pin, 1); 449 | } 450 | if(hardware[type].tx_ctrl_pin != RFBB_NO_GPIO_PIN) 451 | { 452 | gpio_export(hardware[type].tx_ctrl_pin, 1); 453 | } 454 | if(hardware[type].rx_pin != RFBB_NO_GPIO_PIN) 455 | { 456 | gpio_export(hardware[type].rx_pin, 0); 457 | 458 | /* Get interrupt for RX */ 459 | irq = gpio_to_irq(hardware[type].rx_pin); 460 | dprintk("Interrupt %d for RX pin\n", irq); 461 | } 462 | } 463 | 464 | local_irq_restore(flags); 465 | return 0; 466 | } 467 | 468 | static int init_port(void) 469 | { 470 | int err = 0; 471 | 472 | err = hardware_init(); 473 | if (err) 474 | return err; 475 | else 476 | return 0; 477 | } 478 | 479 | 480 | static ssize_t rfbb_read(struct file *filp, char *buf, size_t length, loff_t *offset ) 481 | { 482 | ssize_t ret = 0; 483 | ssize_t copied = 0; 484 | 485 | set_rx_mode(); 486 | if(!interrupt_enabled) 487 | { 488 | //enable_irq(irq); 489 | interrupt_enabled = 1; 490 | } 491 | 492 | /* might need mutex */ 493 | ret = kfifo_to_user(&rxfifo, buf, length, &copied); 494 | 495 | dprintk("rfbb_read request %d bytes, result %d, copied bytes %d\n", length, ret, copied); 496 | 497 | return ret ? ret : copied; 498 | } 499 | 500 | 501 | static ssize_t rfbb_write(struct file *file, const char *buf, 502 | size_t n, loff_t *ppos) 503 | { 504 | int i, count; 505 | unsigned long flags; 506 | int result = 0; 507 | 508 | if(interrupt_enabled) 509 | { 510 | //disable_irq(irq); 511 | interrupt_enabled = 0; 512 | } 513 | set_tx_mode(); 514 | 515 | dprintk("rfbb_write %d bytes\n", n); 516 | 517 | if (n % sizeof(lirc_t)) 518 | return -EINVAL; 519 | count = n / sizeof(lirc_t); 520 | if (count > WBUF_LEN) 521 | { 522 | dprintk("Too many elements (%d) in TX buffer\n", count); 523 | return -EINVAL; 524 | } 525 | 526 | result = copy_from_user(wbuf, buf, n); 527 | if (result) 528 | { 529 | dprintk("Copy_from_user returns %d\n", result); 530 | return -EFAULT; 531 | } 532 | local_irq_save(flags); 533 | for (i = 0; i < count; i++) { 534 | if (wbuf[i] & LIRC_MODE2_PULSE) 535 | hardware[type].send_pulse(wbuf[i] & LIRC_VALUE_MASK); 536 | else 537 | hardware[type].send_space(wbuf[i] & LIRC_VALUE_MASK); 538 | } 539 | off(); 540 | local_irq_restore(flags); 541 | return n; 542 | } 543 | 544 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) 545 | static int rfbb_ioctl(struct inode *node, struct file *filep, unsigned int cmd, 546 | unsigned long arg) 547 | #else 548 | static long rfbb_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) 549 | #endif 550 | { 551 | switch (cmd) { 552 | 553 | default: 554 | return -ENOIOCTLCMD; 555 | } 556 | return 0; 557 | } 558 | 559 | static int rfbb_open(struct inode *ino, struct file *filep) 560 | { 561 | int result; 562 | unsigned long flags; 563 | 564 | if(device_open) 565 | { 566 | printk(KERN_ERR RFBB_DRIVER_NAME ": Already opened\n"); 567 | return -EBUSY; 568 | } 569 | 570 | 571 | /* Init read buffer. */ 572 | /* if (lirc_buffer_init(&rbuf, sizeof(lirc_t), RBUF_LEN) < 0) 573 | return -ENOMEM; */ 574 | 575 | /* initialize timestamp */ 576 | do_gettimeofday(&lasttv); 577 | 578 | if(irq != RFBB_NO_RX_IRQ) { 579 | local_irq_save(flags); 580 | result = request_irq(irq, irq_handler, 581 | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, 582 | RFBB_DRIVER_NAME, (void *)&hardware); 583 | 584 | switch (result) { 585 | case -EBUSY: 586 | printk(KERN_ERR RFBB_DRIVER_NAME ": IRQ %d busy\n", irq); 587 | /* lirc_buffer_free(&rbuf); */ 588 | return -EBUSY; 589 | case -EINVAL: 590 | printk(KERN_ERR RFBB_DRIVER_NAME ": Bad irq number or handler\n"); 591 | /* lirc_buffer_free(&rbuf); */ 592 | return -EINVAL; 593 | default: 594 | dprintk("Interrupt %d obtained\n", irq); 595 | break; 596 | }; 597 | 598 | local_irq_restore(flags); 599 | } 600 | 601 | if(interrupt_enabled) 602 | { 603 | //disable_irq(irq); 604 | interrupt_enabled = 0; 605 | } 606 | 607 | try_module_get(THIS_MODULE); 608 | device_open++; 609 | return 0; 610 | } 611 | 612 | static int rfbb_release(struct inode *node, struct file *file) 613 | { 614 | off(); 615 | 616 | if(interrupt_enabled) 617 | { 618 | //disable_irq(irq); 619 | interrupt_enabled = 0; 620 | } 621 | /* remove the RX interrupt */ 622 | if(irq != RFBB_NO_RX_IRQ) { 623 | free_irq(irq, (void *)&hardware); 624 | dprintk("Freed RX IRQ %d\n", irq); 625 | } 626 | 627 | /* lirc_buffer_free(&rbuf); */ 628 | 629 | device_open--; /* We're now ready for our next caller */ 630 | module_put(THIS_MODULE); 631 | return 0; 632 | } 633 | 634 | static struct file_operations rfbb_fops = { 635 | .owner = THIS_MODULE, 636 | .open = rfbb_open, 637 | .release = rfbb_release, 638 | .write = rfbb_write, 639 | .read = rfbb_read, 640 | 641 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) 642 | .ioctl = rfbb_ioctl, 643 | #else 644 | .unlocked_ioctl = rfbb_ioctl, 645 | #endif 646 | }; 647 | 648 | /* 649 | * Set up the cdev structure for a device. 650 | */ 651 | static void rfbb_setup_cdev(struct cdev *dev, int minor, 652 | struct file_operations *fops) 653 | { 654 | int err, devno = MKDEV(rfbb_major, minor); 655 | 656 | cdev_init(dev, fops); 657 | dev->owner = THIS_MODULE; 658 | dev->ops = fops; 659 | err = cdev_add(dev, devno, 1); 660 | /* Fail gracefully if need be */ 661 | if (err) 662 | printk(KERN_NOTICE "Error %d adding rfbb %d", err, minor); 663 | } 664 | 665 | static int rfbb_init(void) 666 | { 667 | 668 | int result; 669 | dev_t dev = 0; 670 | 671 | /* 672 | * Dynamic major if not set otherwise. 673 | */ 674 | if (rfbb_major) { 675 | dev = MKDEV(rfbb_major, 0); 676 | result = register_chrdev_region(dev, 1, "rfbb"); 677 | } else { 678 | result = alloc_chrdev_region(&dev, 0, 1, 679 | "rfbb"); 680 | rfbb_major = MAJOR(dev); 681 | } 682 | if (result < 0) { 683 | printk(KERN_WARNING "rfbb: can't get major %d\n", rfbb_major); 684 | return result; 685 | } 686 | 687 | rfbb_setup_cdev(rfbbDevs, 0, &rfbb_fops); 688 | 689 | return 0; 690 | } 691 | 692 | static int rfbb_init_module(void) 693 | { 694 | int result; 695 | 696 | result = rfbb_init(); 697 | if (result) 698 | goto exit_rfbb_exit; 699 | 700 | result = init_port(); 701 | if (result < 0) 702 | goto exit_rfbb_exit; 703 | 704 | printk(KERN_INFO 705 | RFBB_DRIVER_NAME " " RFBB_DRIVER_VERSION " registered\n"); 706 | dprintk("dev major = %d\n", rfbb_major); 707 | dprintk("IRQ = %d\n", irq); 708 | dprintk("share_irq = %d\n", share_irq); 709 | 710 | return 0; 711 | 712 | exit_rfbb_exit: 713 | rfbb_exit_module(); 714 | return result; 715 | } 716 | 717 | static void rfbb_exit_module(void) 718 | { 719 | cdev_del(rfbbDevs); 720 | unregister_chrdev_region(MKDEV(rfbb_major, 0), 1); 721 | if(hardware[type].tx_pin != RFBB_NO_GPIO_PIN) 722 | { 723 | gpio_unexport(hardware[type].tx_pin); 724 | gpio_free(hardware[type].tx_pin); 725 | } 726 | if(hardware[type].tx_ctrl_pin != RFBB_NO_GPIO_PIN) 727 | { 728 | gpio_unexport(hardware[type].tx_ctrl_pin); 729 | gpio_free(hardware[type].tx_ctrl_pin); 730 | } 731 | if(hardware[type].rx_pin != RFBB_NO_GPIO_PIN) 732 | { 733 | gpio_unexport(hardware[type].rx_pin); 734 | gpio_free(hardware[type].rx_pin); 735 | } 736 | dprintk("cleaned up module\n"); 737 | } 738 | 739 | 740 | module_init(rfbb_init_module); 741 | module_exit(rfbb_exit_module); 742 | 743 | MODULE_DESCRIPTION("RF transmitter and receiver driver for embedded CPU:s with GPIO. Based on lirc_serial"); 744 | MODULE_AUTHOR("Tord Andersson"); 745 | MODULE_LICENSE("GPL"); 746 | 747 | module_param(debug, bool, S_IRUGO | S_IWUSR); 748 | MODULE_PARM_DESC(debug, "Enable debugging messages"); 749 | -------------------------------------------------------------------------------- /rfbb_cmd/Makefile: -------------------------------------------------------------------------------- 1 | #rfbb_cmd makefile 2 | 3 | EXEC_NAME = rfbb_cmd 4 | SRCS = rfbb_cmd.c 5 | CROSS_COMPILE = 6 | CC = $(CROSS_COMPILE)gcc 7 | CFLAGS = -O2 -Wall 8 | LDFLAGS = 9 | LIBS = -lpthread -lrt 10 | #LIBS = -lrt 11 | OBJS = $(SRCS:.c=.o) 12 | TARGET_ROOT = 13 | INSTALL_DIR = $(TARGET_ROOT)/usr/local/bin 14 | 15 | all: $(EXEC_NAME) 16 | 17 | OBJS: $(SRCS:.c=.o) 18 | $(CC) $(CFLAGS) -c $< 19 | 20 | $(EXEC_NAME): $(OBJS) 21 | $(CC) -o $(EXEC_NAME) ${OBJS} $(LDFLAGS) $(LIBS) 22 | 23 | 24 | # Install will require root privilegies or sudo 25 | install: $(EXEC_NAME) 26 | cp $(EXEC_NAME) $(INSTALL_DIR) 27 | 28 | clean: 29 | rm -f *.o $(EXEC_NAME) core 30 | 31 | distclean: 32 | rm -f *~ 33 | rm -f *.o $(EXEC_NAME) core 34 | 35 | -------------------------------------------------------------------------------- /rfbb_cmd/rfbb_cmd.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** rfbb_cmd.c *********************************************************** 3 | **************************************************************************** 4 | * 5 | * rfbb_cmd - Utility to control NEXA and other RF remote 6 | * receivers through a RF bitbanger interface. Some code is borrowed from 7 | * rfcmd. 8 | * 9 | * Copyright (C) 2010 Tord Andersson 10 | * 11 | * License: GPL v. 2 12 | * 13 | * Authors: 14 | * Tord Andersson 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | 31 | #define PROG_NAME "rfbb_cmd" 32 | #define PROG_VERSION "0.0.2" 33 | 34 | #ifndef TRUE 35 | #define TRUE (1==1) 36 | #endif 37 | 38 | #ifndef FALSE 39 | #define FALSE !(TRUE) 40 | #endif 41 | 42 | #ifndef BOOL 43 | #define BOOL int 44 | #endif 45 | 46 | #define RF_MAX_TX_BITS 4000 /* Max TX pulse/space elements in one message */ 47 | #define RF_MAX_RX_BITS 4000 /* Max read RX pulse/space elements at one go */ 48 | 49 | #define DEFAULT_DEVICE "/dev/rfbb" 50 | 51 | /* We will borrow a set of LIRC pulse/space definitions */ 52 | #define LIRC_MODE2_SPACE 0x00000000 53 | #define LIRC_MODE2_PULSE 0x01000000 54 | #define LIRC_MODE2_TIMEOUT 0x03000000 55 | 56 | #define LIRC_VALUE_MASK 0x00FFFFFF 57 | #define LIRC_MODE2_MASK 0xFF000000 58 | 59 | #define LIRC_SPACE(val) (((val)&LIRC_VALUE_MASK) | LIRC_MODE2_SPACE) 60 | #define LIRC_PULSE(val) (((val)&LIRC_VALUE_MASK) | LIRC_MODE2_PULSE) 61 | #define LIRC_TIMEOUT(val) (((val)&LIRC_VALUE_MASK) | LIRC_MODE2_TIMEOUT) 62 | 63 | #define LIRC_VALUE(val) ((val)&LIRC_VALUE_MASK) 64 | #define LIRC_MODE2(val) ((val)&LIRC_MODE2_MASK) 65 | 66 | #define LIRC_IS_SPACE(val) (LIRC_MODE2(val) == LIRC_MODE2_SPACE) 67 | #define LIRC_IS_PULSE(val) (LIRC_MODE2(val) == LIRC_MODE2_PULSE) 68 | #define LIRC_IS_TIMEOUT(val) (LIRC_MODE2(val) == LIRC_MODE2_TIMEOUT) 69 | 70 | /* Protocol defines */ 71 | #define NEXA_SHORT_PERIOD 340 /* microseconds */ 72 | #define NEXA_LONG_PERIOD 1020 /* microseconds */ 73 | #define NEXA_SYNC_PERIOD (32 * NEXA_SHORT_PERIOD) /* between frames */ 74 | #define NEXA_REPEAT 4 75 | 76 | #define SARTANO_SHORT_PERIOD 320 /* microseconds */ 77 | #define SARTANO_LONG_PERIOD 960 /* microseconds */ 78 | #define SARTANO_SYNC_PERIOD (32 * SARTANO_SHORT_PERIOD) /* between frames */ 79 | #define SARTANO_REPEAT 4 80 | 81 | 82 | typedef enum {MODE_UNKNOWN, MODE_READ, MODE_WRITE} rfMode_t; 83 | typedef enum {IFC_UNKNOWN, IFC_RFBB, IFC_CUL, IFC_TELLSTICK} rfInterface_t; 84 | typedef enum {PROT_UNKNOWN, PROT_RAW, PROT_NEXA, PROT_PROOVE, PROT_NEXA_L, 85 | PROT_SARTANO, PROT_WAVEMAN, PROT_IKEA, PROT_ESIC, PROT_IMPULS} rfProtocol_t; 86 | 87 | /* LIRC pulse/space element */ 88 | typedef int32_t lirc_t; 89 | 90 | /* Local function declarations */ 91 | int createNexaBitstream(const char * pHouseStr, const char * pChannelStr, 92 | const char * pOn_offStr, BOOL waveman, lirc_t * txBitstream, int * repeatCount); 93 | 94 | int createSartanoBitstream(const char * pChannelStr, const char * pOn_offStr, 95 | lirc_t * txBitstream, int * repeatCount); 96 | int createImpulsBitstream(const char * pChannelStr, const char * pOn_offStr, 97 | lirc_t * txBitstream, int * repeatCount); 98 | int createIkeaBitstream(const char * pSystemStr, const char * pChannelStr, 99 | const char * pLevelStr, const char *pDimStyle, 100 | lirc_t * txBitstream, int * repeatCount); 101 | int txBitstream2culStr(lirc_t * pTxBitstream, int txItemCount, int repeatCount, char * txStrCul); 102 | 103 | static void printUsage(void); 104 | static void printVersion(void); 105 | static void signalTerminate(int signo); 106 | 107 | /* Local variables */ 108 | BOOL verbose = FALSE; /* -v option */ 109 | BOOL stopNow = FALSE; 110 | 111 | /* Command line option handling */ 112 | static const char *optString = "d:i:p:rwg:c:l:vh?"; 113 | 114 | static const struct option longOpts[] = { 115 | { "device", required_argument, NULL, 'd' }, 116 | { "interface", required_argument, NULL, 'i' }, 117 | { "protocol", required_argument, NULL, 'p' }, 118 | { "read", no_argument, NULL, 'r' }, 119 | { "write", no_argument, NULL, 'w' }, 120 | { "group", required_argument, NULL, 'g' }, 121 | { "channel", required_argument, NULL, 'c' }, 122 | { "serialnumber", required_argument, NULL, 's' }, 123 | { "level", required_argument, NULL, 'l' }, 124 | { "verbose", no_argument, NULL, 'v' }, 125 | { "help", no_argument, NULL, 'h' }, 126 | { NULL, no_argument, NULL, 0 } 127 | }; 128 | 129 | int main( int argc, char **argv ) 130 | { 131 | struct termios tio; 132 | int fd = -1; 133 | sem_t * portMutex; 134 | char SEM_NAME[]= "RFCMD_SEM"; /* Semaphore for multiple access ctrl */ 135 | int opt = 0; 136 | int longIndex = 0; 137 | rfInterface_t rfInterface = IFC_RFBB; 138 | char defaultDevice[255] = DEFAULT_DEVICE; 139 | char * device = defaultDevice; /* -d option */ 140 | rfMode_t mode = MODE_WRITE; /* read/write */ 141 | char * rfProtocolStr = NULL; 142 | rfProtocol_t rfProtocol = PROT_NEXA; /* protocol */ 143 | const char * groupStr = NULL; /* house/group/system opåtion */ 144 | const char * channelStr = NULL; /* -c (channel/unit) option */ 145 | const char * levelStr = NULL; /* level 0 - 100 % or on/off */ 146 | lirc_t txBitstream[RF_MAX_TX_BITS]; 147 | lirc_t rxBitstream[RF_MAX_RX_BITS]; 148 | lirc_t rxValue = 0; 149 | int rxCount = 0; 150 | int txItemCount = 0; 151 | int repeatCount = 0; 152 | int i; 153 | char asciiCmdStr[RF_MAX_TX_BITS * 6]; /* hex/ASCII repr is longer than bitstream */ 154 | int asciiCmdLength = 0; 155 | 156 | if(argc < 2) 157 | { 158 | printUsage(); 159 | exit(1); 160 | } 161 | 162 | opt = getopt_long( argc, argv, optString, longOpts, &longIndex ); 163 | 164 | /* parse command options */ 165 | while( opt != -1 ) 166 | { 167 | 168 | switch( opt ) 169 | { 170 | case 'd': 171 | if (optarg) 172 | { 173 | device = optarg; 174 | } 175 | else 176 | { 177 | fprintf(stderr, "Error. Missing device path.\n"); 178 | printUsage(); 179 | exit(1); 180 | } 181 | break; 182 | 183 | case 'i': 184 | if (optarg) 185 | { 186 | if(strcmp( "RFBB", optarg) == 0) 187 | { 188 | rfInterface = IFC_RFBB; 189 | } 190 | else if(strcmp( "CUL", optarg) == 0) 191 | { 192 | rfInterface = IFC_CUL; 193 | } 194 | else if(strcmp( "TELLSTICK", optarg ) == 0) 195 | { 196 | rfInterface = IFC_TELLSTICK; 197 | } 198 | else 199 | { 200 | rfInterface = IFC_UNKNOWN; 201 | fprintf(stderr, "Error. Unknown interface type: %s\n", optarg); 202 | printUsage(); 203 | exit(1); 204 | } 205 | } 206 | else 207 | { 208 | fprintf(stderr, "Error. Missing interface type.\n"); 209 | printUsage(); 210 | exit(1); 211 | } 212 | break; 213 | 214 | case 'r': 215 | mode = MODE_READ; 216 | break; 217 | 218 | case 'w': 219 | mode = MODE_WRITE; 220 | break; 221 | 222 | case 'p': 223 | if (optarg) 224 | { 225 | rfProtocolStr = optarg; 226 | if(strcmp( "NEXA", rfProtocolStr) == 0) 227 | { 228 | rfProtocol = PROT_NEXA; 229 | } 230 | else if(strcmp( "PROOVE", rfProtocolStr) == 0) 231 | { 232 | rfProtocol = PROT_NEXA; 233 | } 234 | else if(strcmp( "WAVEMAN", rfProtocolStr) == 0) 235 | { 236 | rfProtocol = PROT_WAVEMAN; 237 | } 238 | else if(strcmp( "SARTANO", rfProtocolStr ) == 0) 239 | { 240 | rfProtocol = PROT_SARTANO; 241 | } 242 | else if(strcmp( "IMPULS", rfProtocolStr ) == 0) 243 | { 244 | rfProtocol = PROT_IMPULS; 245 | } 246 | else if(strcmp( "NEXA_L", rfProtocolStr ) == 0) 247 | { 248 | rfProtocol = PROT_NEXA_L; 249 | } 250 | else 251 | { 252 | rfProtocol = PROT_UNKNOWN; 253 | fprintf(stderr, "Error. Unknown protocol: %s\n", rfProtocolStr); 254 | printUsage(); 255 | exit(1); 256 | } 257 | } 258 | else 259 | { 260 | fprintf(stderr, "Error. Missing protocol\n"); 261 | printUsage(); 262 | exit(1); 263 | } 264 | break; 265 | 266 | case 'g': 267 | if (optarg) 268 | { 269 | groupStr = optarg; 270 | } 271 | else 272 | { 273 | fprintf(stderr, "Error. Missing group/house/system ID\n"); 274 | printUsage(); 275 | exit(1); 276 | } 277 | break; 278 | 279 | case 'c': 280 | if (optarg) 281 | { 282 | channelStr = optarg; 283 | } 284 | else 285 | { 286 | fprintf(stderr, "Error. Missing channel number\n"); 287 | printUsage(); 288 | exit(1); 289 | } 290 | break; 291 | 292 | case 'l': 293 | if (optarg) 294 | { 295 | levelStr = optarg; 296 | } 297 | else 298 | { 299 | fprintf(stderr, "Error. Missing level\n"); 300 | printUsage(); 301 | exit(1); 302 | } 303 | break; 304 | 305 | case 'v': 306 | verbose = TRUE; 307 | break; 308 | 309 | case 'h': /* Fall through by design */ 310 | case '?': 311 | printVersion(); 312 | printUsage(); 313 | exit(0); 314 | break; 315 | 316 | case 0: /* Long option without a short arg */ 317 | if (longOpts[longIndex].flag != 0) 318 | break; 319 | printf ("option %s", longOpts[longIndex].name); 320 | if (optarg) 321 | printf (" with arg %s", optarg); 322 | printf ("\n"); 323 | 324 | default: 325 | /* You won't actually get here. */ 326 | break; 327 | } 328 | 329 | opt = getopt_long( argc, argv, optString, longOpts, &longIndex ); 330 | } 331 | 332 | 333 | /* Build generic transmit bitstream for the selected protocol */ 334 | if(mode == MODE_WRITE) 335 | { 336 | switch(rfProtocol) 337 | { 338 | case PROT_NEXA: 339 | if(verbose) 340 | { 341 | printf("NEXA protocol selected\n"); 342 | } 343 | txItemCount = createNexaBitstream(groupStr, channelStr, levelStr, FALSE, txBitstream, &repeatCount); 344 | if (txItemCount == 0) { 345 | printUsage(); 346 | exit(1); 347 | } 348 | break; 349 | 350 | case PROT_WAVEMAN: 351 | if(verbose) 352 | { 353 | printf("WAVEMAN protocol selected\n"); 354 | } 355 | txItemCount = createNexaBitstream(groupStr, channelStr, levelStr, TRUE, txBitstream, &repeatCount); 356 | if (txItemCount == 0) { 357 | printUsage(); 358 | exit(1); 359 | } 360 | break; 361 | 362 | case PROT_SARTANO: 363 | if(verbose) 364 | { 365 | printf("SARTANO protocol selected\n"); 366 | } 367 | txItemCount = createSartanoBitstream(channelStr, levelStr, txBitstream, &repeatCount); 368 | if (txItemCount == 0) { 369 | printUsage(); 370 | exit(1); 371 | } 372 | break; 373 | 374 | case PROT_IMPULS: 375 | if(verbose) 376 | { 377 | printf("IMPULS protocol selected\n"); 378 | } 379 | txItemCount = createImpulsBitstream(channelStr, levelStr, txBitstream, &repeatCount); 380 | if (txItemCount == 0) { 381 | printUsage(); 382 | exit(1); 383 | } 384 | break; 385 | case PROT_IKEA: 386 | if(verbose) 387 | { 388 | printf("IKEA protocol selected\n"); 389 | } 390 | txItemCount = createIkeaBitstream(groupStr, channelStr, levelStr, "1", txBitstream, &repeatCount); 391 | if (txItemCount == 0) { 392 | printUsage(); 393 | exit(1); 394 | } 395 | break; 396 | 397 | default: 398 | fprintf(stderr, "Protocol: %s is currently not supported\n", rfProtocolStr); 399 | printUsage(); 400 | exit(1); 401 | 402 | } 403 | } 404 | 405 | /* create the semaphore - will reuse an existing one if it exists */ 406 | portMutex = sem_open(SEM_NAME,O_CREAT,0644,1); 407 | if(portMutex == SEM_FAILED) 408 | { 409 | fprintf(stderr, "%s - Error creating port semaphore\n", PROG_NAME); 410 | perror("Semaphore open error"); 411 | sem_unlink(SEM_NAME); 412 | exit(1); 413 | } 414 | 415 | /* lock semaphore to protect port from multiple access */ 416 | if(sem_wait(portMutex) != 0) 417 | { 418 | fprintf(stderr, "%s - Error aquiring port semaphore\n", PROG_NAME); 419 | sem_unlink(SEM_NAME); 420 | sem_close(portMutex); 421 | exit(1); 422 | } 423 | 424 | /* Transmit/read handling for each interface type */ 425 | switch (rfInterface) { 426 | 427 | case IFC_RFBB: 428 | 429 | if(verbose) 430 | { 431 | printf("Selected RFBB interface (RF Bitbanger)\n"); 432 | } 433 | 434 | if( 0 > ( fd = open( device, O_RDWR ) ) ) { 435 | fprintf(stderr, "%s - Error opening %s\n", PROG_NAME, device); 436 | if(sem_post(portMutex) != 0) 437 | { 438 | fprintf(stderr, "%s - Error releasing port semaphore\n", PROG_NAME); 439 | } 440 | sem_unlink(SEM_NAME); 441 | sem_close(portMutex); 442 | exit(1); 443 | } 444 | 445 | if(mode == MODE_WRITE) 446 | { 447 | if(verbose) 448 | { 449 | printf("Writing %d pulse_space_items, (%d bytes) to %s\n", txItemCount * repeatCount, txItemCount * 4 * repeatCount, device); 450 | } 451 | for(i=0; i ( fd = open( *(argv+1), O_RDWR ) ) ) { 524 | fprintf(stderr, "%s - Error opening %s\n", PROG_NAME, *(argv+1)); 525 | if(sem_post(portMutex) != 0) 526 | { 527 | fprintf(stderr, "%s - Error releasing port semaphore\n", PROG_NAME); 528 | } 529 | sem_unlink(SEM_NAME); 530 | sem_close(portMutex); 531 | exit(1); 532 | } 533 | 534 | /* adjust serial port parameters */ 535 | bzero(&tio, sizeof(tio)); /* clear struct for new port settings */ 536 | tio.c_cflag = B4800 | CS8 | CLOCAL | CREAD; /* CREAD not used yet */ 537 | tio.c_iflag = IGNPAR; 538 | tio.c_oflag = 0; 539 | tio.c_ispeed = 4800; 540 | tio.c_ospeed = 4800; 541 | tcflush(fd, TCIFLUSH); 542 | tcsetattr(fd,TCSANOW,&tio); 543 | if( write(fd, txStr, strlen(txStr)) < 0) 544 | { 545 | perror("Error writing to Tellstick device"); 546 | } 547 | sleep(1); /* one second sleep to avoid device 'choking' */ 548 | close(fd); 549 | #endif 550 | break; 551 | 552 | case IFC_CUL: 553 | if(verbose) 554 | { 555 | printf("Selected CUL433 interface\n"); 556 | } 557 | 558 | if( 0 > ( fd = open( device, O_RDWR ) ) ) { 559 | fprintf(stderr, "%s - Error opening %s\n", PROG_NAME, device); 560 | if(sem_post(portMutex) != 0) 561 | { 562 | fprintf(stderr, "%s - Error releasing port semaphore\n", PROG_NAME); 563 | } 564 | sem_unlink(SEM_NAME); 565 | sem_close(portMutex); 566 | exit(1); 567 | } 568 | 569 | /* adjust serial port parameters */ 570 | bzero(&tio, sizeof(tio)); /* clear struct for new port settings */ 571 | tio.c_cflag = B115200 | CS8 | CLOCAL | CREAD; /* CREAD not used yet */ 572 | tio.c_iflag = IGNPAR; 573 | tio.c_oflag = 0; 574 | tio.c_ispeed = 115200; 575 | tio.c_ospeed = 115200; 576 | tcflush(fd, TCIFLUSH); 577 | tcsetattr(fd,TCSANOW,&tio); 578 | 579 | printf("Mode : %d\n", mode); 580 | 581 | if(mode == MODE_WRITE) 582 | { 583 | 584 | /* CUL433 nethome format */ 585 | asciiCmdLength = txBitstream2culStr(txBitstream, txItemCount, repeatCount, asciiCmdStr); 586 | 587 | printf("CUL cmd: %s\n", asciiCmdStr); 588 | 589 | if( write(fd, asciiCmdStr, asciiCmdLength) < 0) 590 | { 591 | perror("Error writing to CUL device"); 592 | } 593 | sleep(1); 594 | } 595 | else if(mode == MODE_READ) 596 | { 597 | stopNow = FALSE; 598 | if(verbose) 599 | { 600 | printf("Reading pulse_space_items\n"); 601 | } 602 | 603 | /* 604 | * Set up signal handlers to act on CTRL-C events 605 | */ 606 | if (signal(SIGINT, signalTerminate) == SIG_ERR) 607 | { 608 | perror("Can't register signal handler for CTRL-C et al: "); 609 | exit (-1); 610 | } 611 | /* start rx */ 612 | if( write(fd, "\r\nX01\r\n", 7) < 0) 613 | { 614 | perror("Error issuing RX cmd to CUL device"); 615 | stopNow = TRUE; 616 | } 617 | 618 | while(stopNow == FALSE) /* repeat until CTRL-C */ 619 | { 620 | rxCount = read(fd, rxBitstream, 5); 621 | if(rxCount == 5) 622 | { 623 | rxValue = (uint32_t)*&rxBitstream[0]; 624 | printf("\n%08X: ", rxValue); 625 | if(rxValue & 0x8000) 626 | { 627 | printf("1 - %05d us", rxValue & 0x7FFF); 628 | } 629 | else 630 | { 631 | printf("0 - %05d us", rxValue & 0x7FFF); 632 | } 633 | if((rxValue & 0x7FFF) == 0x7FFF) 634 | { 635 | printf(" - Timeout"); 636 | } 637 | } 638 | else 639 | { 640 | if(rxCount == 0) 641 | { 642 | usleep(100*1000); /* 100 ms */ 643 | printf("."); 644 | fflush(stdout); 645 | } 646 | else 647 | { 648 | printf("Read %d bytes\n", rxCount); 649 | fflush(stdout); 650 | } 651 | } 652 | } 653 | } 654 | close(fd); 655 | break; 656 | 657 | 658 | default: 659 | fprintf(stderr, "%s - Illegal interface type (%d)\n", PROG_NAME, rfInterface); 660 | break; 661 | 662 | 663 | } 664 | 665 | 666 | /* Unlock semaphore */ 667 | if(sem_post(portMutex) != 0) 668 | { 669 | fprintf(stderr, "%s - Error releasing port semaphore\n", PROG_NAME); 670 | sem_unlink(SEM_NAME); 671 | sem_close(portMutex); 672 | exit(1); 673 | } 674 | else 675 | { 676 | sem_unlink(SEM_NAME); 677 | sem_close(portMutex); 678 | } 679 | 680 | exit(0); 681 | } 682 | 683 | 684 | int createNexaBitstream(const char * pHouseStr, const char * pChannelStr, 685 | const char * pOn_offStr, BOOL waveman, lirc_t * pTxBitstream, int * repeatCount) 686 | { 687 | int houseCode; 688 | int channelCode; 689 | int on_offCode; 690 | int txCode = 0; 691 | const int unknownCode = 0x6; 692 | int bit; 693 | int bitmask = 0x0001; 694 | int itemCount = 0; 695 | 696 | *repeatCount = NEXA_REPEAT; 697 | 698 | houseCode = (int)((* pHouseStr) - 65); /* House 'A'..'P' */ 699 | channelCode = atoi(pChannelStr) - 1; /* Channel 1..16 */ 700 | on_offCode = atoi(pOn_offStr); /* ON/OFF 0..1 */ 701 | 702 | if(verbose) 703 | { 704 | printf("House: %d, channel: %d, on_off: %d\n", houseCode, channelCode, on_offCode); 705 | } 706 | 707 | /* check converted parameters for validity */ 708 | if((houseCode < 0) || (houseCode > 15) || // House 'A'..'P' 709 | (channelCode < 0) || (channelCode > 15) || 710 | (on_offCode < 0) || (on_offCode > 1)) 711 | { 712 | fprintf(stderr,"Invalid group (house), channel or on/off code\n"); 713 | return 0; 714 | } 715 | else 716 | { 717 | /* b0..b11 txCode where 'X' will be represented by 1 for simplicity. 718 | b0 will be sent first */ 719 | txCode = houseCode; 720 | txCode |= (channelCode << 4); 721 | if (waveman && on_offCode == 0) { 722 | } else { 723 | txCode |= (unknownCode << 8); 724 | txCode |= (on_offCode << 11); 725 | } 726 | 727 | /* convert to send cmd bitstream */ 728 | for(bit=0;bit<12;bit++) 729 | { 730 | if((bitmask & txCode) == 0) { 731 | /* bit timing might need further refinement */ 732 | /* 340 us high, 1020 us low, 340 us high, 1020 us low */ 733 | pTxBitstream[itemCount++] = LIRC_PULSE(NEXA_SHORT_PERIOD); 734 | pTxBitstream[itemCount++] = LIRC_SPACE(NEXA_LONG_PERIOD); 735 | pTxBitstream[itemCount++] = LIRC_PULSE(NEXA_SHORT_PERIOD); 736 | pTxBitstream[itemCount++] = LIRC_SPACE(NEXA_LONG_PERIOD); 737 | } 738 | else 739 | { /* add 'X' (floating bit) */ 740 | /* 340 us high, 1020 us low, 1020 us high, 350 us low */ 741 | pTxBitstream[itemCount++] = LIRC_PULSE(NEXA_SHORT_PERIOD); 742 | pTxBitstream[itemCount++] = LIRC_SPACE(NEXA_LONG_PERIOD); 743 | pTxBitstream[itemCount++] = LIRC_PULSE(NEXA_LONG_PERIOD); 744 | pTxBitstream[itemCount++] = LIRC_SPACE(NEXA_SHORT_PERIOD); 745 | } 746 | bitmask = bitmask<<1; 747 | } 748 | /* add stop/sync bit and command termination char '+'*/ 749 | pTxBitstream[itemCount++] = LIRC_PULSE(NEXA_SHORT_PERIOD); 750 | pTxBitstream[itemCount++] = LIRC_SPACE(NEXA_SYNC_PERIOD); 751 | } 752 | 753 | return itemCount; 754 | } 755 | 756 | int createImpulsBitstream(const char * pChannelStr, const char * pOn_offStr, 757 | lirc_t * pTxBitstream, int * repeatCount) 758 | { 759 | int itemCount = 0; 760 | int on_offCode; 761 | int bit; 762 | 763 | on_offCode = atoi(pOn_offStr); /* ON/OFF 0..1 */ 764 | *repeatCount = SARTANO_REPEAT; 765 | 766 | if(verbose) 767 | { 768 | printf("Channel: %s, on_off: %d\n", pChannelStr, on_offCode); 769 | } 770 | 771 | /* check converted parameters for validity */ 772 | if((strlen(pChannelStr) != 10) || 773 | (on_offCode < 0) || (on_offCode > 1)) 774 | { 775 | fprintf(stderr,"Invalid channel or on/off code\n"); 776 | return 0; 777 | } 778 | else 779 | { 780 | // The house code: 781 | for(bit=0; bit < 5 ;bit++) 782 | { 783 | /* "1" bit */ 784 | // 11101110 is on 785 | if(strncmp(pChannelStr+bit, "1", 1) == 0) 786 | { 787 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_LONG_PERIOD); 788 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_SHORT_PERIOD); 789 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_LONG_PERIOD); 790 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_SHORT_PERIOD); 791 | } 792 | /* "0" bit */ 793 | else 794 | { 795 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 796 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 797 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_LONG_PERIOD); 798 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_SHORT_PERIOD); 799 | } 800 | } 801 | // The group code 802 | for(bit=5; bit < 10 ;bit++) 803 | { 804 | /* "1" bit */ 805 | // 10001000 is on 806 | if(strncmp(pChannelStr+bit, "1", 1) == 0) 807 | { 808 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 809 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 810 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 811 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 812 | } 813 | /* "0" bit */ 814 | else 815 | { 816 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 817 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 818 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_LONG_PERIOD); 819 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_SHORT_PERIOD); 820 | } 821 | } 822 | if (on_offCode >= 1) 823 | { 824 | /* ON == "10" */ 825 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 826 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 827 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_LONG_PERIOD); 828 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_SHORT_PERIOD); 829 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 830 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 831 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 832 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 833 | } 834 | else 835 | { 836 | /* OFF == "01" */ 837 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 838 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 839 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 840 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 841 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 842 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 843 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_LONG_PERIOD); 844 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_SHORT_PERIOD); 845 | } 846 | 847 | /* add stop/sync bit and command termination char '+'*/ 848 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 849 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_SYNC_PERIOD); 850 | } 851 | 852 | return itemCount; 853 | } 854 | 855 | int createSartanoBitstream(const char * pChannelStr, const char * pOn_offStr, 856 | lirc_t * pTxBitstream, int * repeatCount) 857 | { 858 | int itemCount = 0; 859 | int on_offCode; 860 | int bit; 861 | 862 | on_offCode = atoi(pOn_offStr); /* ON/OFF 0..1 */ 863 | *repeatCount = SARTANO_REPEAT; 864 | 865 | if(verbose) 866 | { 867 | printf("Channel: %s, on_off: %d\n", pChannelStr, on_offCode); 868 | } 869 | 870 | /* check converted parameters for validity */ 871 | if((strlen(pChannelStr) != 10) || 872 | (on_offCode < 0) || (on_offCode > 1)) 873 | { 874 | fprintf(stderr,"Invalid channel or on/off code\n"); 875 | return 0; 876 | } 877 | else 878 | { 879 | for(bit=0;bit<=9;bit++) 880 | { 881 | /* "1" bit */ 882 | if(strncmp(pChannelStr+bit, "1", 1) == 0) 883 | { 884 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 885 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 886 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 887 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 888 | } 889 | /* "0" bit */ 890 | else 891 | { 892 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 893 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 894 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_LONG_PERIOD); 895 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_SHORT_PERIOD); 896 | } 897 | } 898 | if (on_offCode >= 1) 899 | { 900 | /* ON == "10" */ 901 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 902 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 903 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 904 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 905 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 906 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 907 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_LONG_PERIOD); 908 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_SHORT_PERIOD); 909 | } 910 | else 911 | { 912 | /* OFF == "01" */ 913 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 914 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 915 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_LONG_PERIOD); 916 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_SHORT_PERIOD); 917 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 918 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 919 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 920 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_LONG_PERIOD); 921 | } 922 | 923 | /* add stop/sync bit and command termination char '+'*/ 924 | pTxBitstream[itemCount++] = LIRC_PULSE(SARTANO_SHORT_PERIOD); 925 | pTxBitstream[itemCount++] = LIRC_SPACE(SARTANO_SYNC_PERIOD); 926 | } 927 | 928 | return itemCount; 929 | } 930 | 931 | int createIkeaBitstream(const char * pSystemStr, const char * pChannelStr, 932 | const char * pLevelStr, const char *pDimStyle, 933 | lirc_t * txBitstream, int * repeatCount) 934 | { 935 | #if 0 936 | *pStrReturn = '\0'; /* Make sure tx Bitstream is empty */ 937 | 938 | const char STARTCODE[] = "STTTTTT�"; 939 | const char TT[] = "TT"; 940 | const char A[] = "�"; 941 | int systemCode = atoi(pSystemStr) - 1; /* System 1..16 */ 942 | int channelCode = atoi(pChannelStr); /* Channel 1..10 */ 943 | int Level = atoi(pLevelStr); /* off,10,20,..,90,on */ 944 | int DimStyle = atoi(pDimStyle); 945 | int intCode = 0; 946 | int checksum1 = 0; 947 | int checksum2 = 0; 948 | int intFade ; 949 | int i ; 950 | int rawChannelCode = 0; 951 | 952 | /* check converted parameters for validity */ 953 | if ( (channelCode <= 0) || (channelCode > 10) || 954 | (systemCode < 0) || (systemCode > 15) || 955 | (Level < 0) || (Level > 10) || 956 | (DimStyle < 0) || (DimStyle > 1)) 957 | { 958 | return 0; 959 | } 960 | 961 | if (channelCode == 10) { 962 | channelCode = 0; 963 | } 964 | rawChannelCode = (1<<(9-channelCode)); 965 | 966 | strcat(pStrReturn, STARTCODE ) ; //Startcode, always like this; 967 | intCode = (systemCode << 10) | rawChannelCode; 968 | 969 | for ( i = 13; i >= 0; --i) { 970 | if ((intCode>>i) & 1) { 971 | strcat(pStrReturn, TT ); 972 | if (i % 2 == 0) { 973 | checksum2++; 974 | } else { 975 | checksum1++; 976 | } 977 | } else { 978 | strcat(pStrReturn,A); 979 | } 980 | } 981 | 982 | if (checksum1 %2 == 0) { 983 | strcat(pStrReturn, TT ); 984 | } else { 985 | strcat(pStrReturn, A) ; //1st checksum 986 | } 987 | 988 | if (checksum2 %2 == 0) { 989 | strcat(pStrReturn, TT ); 990 | } else { 991 | strcat(pStrReturn, A ) ; //2nd checksum 992 | } 993 | 994 | if (DimStyle == 1) { 995 | intFade = 11 << 4; //Smooth 996 | } else { 997 | intFade = 1 << 4; //Instant 998 | } 999 | 1000 | switch ( Level ) 1001 | { 1002 | case 0 : 1003 | intCode = (10 | intFade) ; //Concat level and fade 1004 | break; 1005 | case 1 : 1006 | intCode = (1 | intFade) ; //Concat level and fade 1007 | break; 1008 | case 2 : 1009 | intCode = (2 | intFade) ; //Concat level and fade 1010 | break; 1011 | case 3 : 1012 | intCode = (3 | intFade) ; //Concat level and fade 1013 | break; 1014 | case 4 : 1015 | intCode = (4 | intFade) ; //Concat level and fade 1016 | break; 1017 | case 5 : 1018 | intCode = (5 | intFade) ; //Concat level and fade 1019 | break; 1020 | case 6 : 1021 | intCode = (6 | intFade) ; //Concat level and fade 1022 | break; 1023 | case 7 : 1024 | intCode = (7 | intFade) ; //Concat level and fade 1025 | break; 1026 | case 8 : 1027 | intCode = (8 | intFade) ; //Concat level and fade 1028 | break; 1029 | case 9 : 1030 | intCode = (9 | intFade) ; //Concat level and fade 1031 | break; 1032 | case 10 : 1033 | default : 1034 | intCode = (0 | intFade) ; //Concat level and fade 1035 | break; 1036 | } 1037 | 1038 | checksum1 = 0; 1039 | checksum2 = 0; 1040 | 1041 | for (i = 0; i < 6; ++i) { 1042 | if ((intCode>>i) & 1) { 1043 | strcat(pStrReturn, TT); 1044 | 1045 | if (i % 2 == 0) { 1046 | checksum1++; 1047 | } else { 1048 | checksum2++; 1049 | } 1050 | } else { 1051 | strcat(pStrReturn, A ); 1052 | } 1053 | } 1054 | 1055 | if (checksum1 %2 == 0) { 1056 | strcat(pStrReturn, TT); 1057 | } else { 1058 | strcat(pStrReturn, A ) ; //2nd checksum 1059 | } 1060 | 1061 | if (checksum2 %2 == 0) { 1062 | strcat(pStrReturn, TT ); 1063 | } else { 1064 | strcat(pStrReturn, A ) ; //2nd checksum 1065 | } 1066 | 1067 | strcat(pStrReturn, "+"); 1068 | 1069 | return strlen(pStrReturn); 1070 | #endif 1071 | return 0; 1072 | } 1073 | 1074 | /* Convert generic bitstream format to CUL433 format */ 1075 | int txBitstream2culStr(lirc_t * pTxBitstream, int txItemCount, int repeatCount, char * txStrCul) 1076 | { 1077 | int i; 1078 | int pulses = 0; 1079 | char * pCulStr = txStrCul; 1080 | char tmpStr [20]; 1081 | 1082 | * pCulStr = '\0'; 1083 | 1084 | strcat(pCulStr, "\r\nX01\r\n"); /* start radio */ 1085 | strcat(pCulStr, "E\r\n"); /* empty tx buffer */ 1086 | 1087 | for(i=0;i 1) 1106 | { 1107 | 1108 | /* number of repetitions */ 1109 | sprintf(tmpStr, "S%02d\r\n", repeatCount); 1110 | strcat(pCulStr, tmpStr); 1111 | return strlen(pCulStr); 1112 | } 1113 | else 1114 | { 1115 | txStrCul[0] = '\0'; 1116 | return 0; 1117 | } 1118 | } 1119 | 1120 | static void printUsage(void) 1121 | { 1122 | printf("\nUsage: %s <-diprwgcslvh> [value]\n", PROG_NAME); 1123 | printf("\t -d --device defaults to %s\n", DEFAULT_DEVICE); 1124 | printf("\t -i --interface. RFBB, CUL or TELLSTICK. Defaults to RFBB (RF Bitbanger)\n"); 1125 | printf("\t -p --protocol. NEXA, NEXA_L, SARTANO, WAVEMAN, IKEA or RAW\n"); 1126 | printf("\t -r --read. Raw space/pulse reading. For interfaces above that supports reading\n"); 1127 | printf("\t -w --write. Send command (default)\n"); 1128 | printf("\t -g --group. The group/house/system number or letter\n"); 1129 | printf("\t -c --channel. The channel/unit number\n"); 1130 | printf("\t -s --serialnumber. The serial/unique number used by NEXA L (self-learning)\n"); 1131 | printf("\t -l --level. 0 - 100. All values above 0 will switch on non dimmable devices\n"); 1132 | printf("\t -v --verbose\n"); 1133 | printf("\t -h --help\n"); 1134 | printf("\n\t Some useful protocol arguments - NEXA, WAVEMAN:\n"); 1135 | printf("\t\tgroup: A..P\n\t\tchannel: 1..16\n\t\toff/on: 0..1\n" ); 1136 | printf("\n"); 1137 | printf("\t Protocol arguments - SARTANO:\n"); 1138 | printf("\t\tchannel: 0000000000..1111111111\n\t\toff/on: 0..1\n" ); 1139 | printf("\n"); 1140 | printf("\t Protocol arguments - IKEA:\n"); 1141 | printf("\t\tgroup (system): 1..16\n\t\tchannel(device): 1..10\n"); 1142 | printf("\t\tlevel: 0..100\n\t\t(dimstyle 0..1)\n\n"); 1143 | printf("\tA typical example (NEXA D1 on): %s -d /dev/rfbb -i RFBB -p NEXA -g D -c 1 -l 1\n\n", PROG_NAME); 1144 | 1145 | 1146 | } 1147 | 1148 | static void printVersion(void) { 1149 | printf("%s (RF Bitbanger cmd tool) v%s\n", PROG_NAME, PROG_VERSION); 1150 | printf("\n"); 1151 | printf("Copyright (C) Tord Andersson 2010\n"); 1152 | printf("License: GPL v. 2\n"); 1153 | printf("Written by Tord Andersson. Code fragments from rfcmd by Tord Andersson, Micke Prag, \nGudmund Berggren, Tapani Rintala and others\n"); 1154 | } 1155 | 1156 | static void signalTerminate(int signo) 1157 | { 1158 | /* 1159 | * This will force the exit handler to run 1160 | */ 1161 | if(verbose) 1162 | { 1163 | printf("Signal handler for %d signal\n", signo); 1164 | } 1165 | stopNow = TRUE; 1166 | } 1167 | 1168 | -------------------------------------------------------------------------------- /rfbb_hardware.txt: -------------------------------------------------------------------------------- 1 | Hardware for the rfbb driver 2 | ============================ 3 | Latest update 2012-10-11, Tord Andersson 4 | 5 | Note! A monospaced font might make it easier to read tables below! 6 | 7 | RF Transmitter module pinout 8 | ---------------------------- 9 | 10 | A common RF transmitter module like TX433N (433.92MHz) has the following pinout: 11 | 12 | Pin Function 13 | 1 GND 14 | 2 Data in 15 | 3 VCC 16 | 4 Antenna 17 | 18 | Make sure that VCC is able to operate from 5V DC and the Data In threshold 19 | is compatible with 3.3V logic. 20 | The range is often 3 - 12 V DC, but there might be other versions! 21 | 22 | 23 | Raspberry Pi example 24 | -------------------- 25 | 26 | RPI TX433N 27 | Pin, function - Pin, function 28 | P1-02, 5V0 - 3, VCC 29 | P1-06, GND - 1, GND 30 | P1-11, GPIO17 - 2, Data in 31 | No connection - 4, Antenna. Connect a 170mm wire as antenna 32 | 33 | -------------------------------------------------------------------------------- /rfcmd/COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 19yy 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) 19yy name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | -------------------------------------------------------------------------------- /rfcmd/Makefile: -------------------------------------------------------------------------------- 1 | #rfcmd makefile 2 | 3 | EXEC_NAME = rfcmd 4 | SRCS = rfcmd.c 5 | CROSS_COMPILE = 6 | CC = $(CROSS_COMPILE)gcc 7 | CFLAGS = -O2 -Wall 8 | LDFLAGS = 9 | LIBS = -lpthread 10 | #LIBS = -lrt 11 | OBJS = $(SRCS:.c=.o) 12 | TARGET_ROOT = 13 | INSTALL_DIR = $(TARGET_ROOT)/usr/local/bin 14 | 15 | all: $(EXEC_NAME) 16 | 17 | OBJS: $(SRCS:.c=.o) 18 | $(CC) $(CFLAGS) -c $< 19 | 20 | $(EXEC_NAME): $(OBJS) 21 | $(CC) -o $(EXEC_NAME) ${OBJS} $(LDFLAGS) $(LIBS) 22 | 23 | 24 | # Install will require root privilegies or sudo 25 | install: $(EXEC_NAME) 26 | cp $(EXEC_NAME) $(INSTALL_DIR) 27 | 28 | clean: 29 | rm -f *.o $(EXEC_NAME) core 30 | 31 | distclean: 32 | rm -f *~ 33 | rm -f *.o $(EXEC_NAME) core 34 | 35 | -------------------------------------------------------------------------------- /rfcmd/rfcmd.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tandersson/rf-bitbanger/39fe09b198e0f46adf079d605ed918e0de73b850/rfcmd/rfcmd.c --------------------------------------------------------------------------------