From e330af7224f47aa96961d7d5569a409a1301ce4d Mon Sep 17 00:00:00 2001 From: incmve Date: Tue, 6 Dec 2016 20:50:19 +0100 Subject: [PATCH] First --- Images/cntrl panel.JPG | Bin 0 -> 32366 bytes Images/serial.JPG | Bin 0 -> 30113 bytes Itho-WIFI-remote.ino | 212 ++++++ LICENSE.md | 674 +++++++++++++++++++ Library/Itho/CC1101.cpp | 272 ++++++++ Library/Itho/CC1101.h | 207 ++++++ Library/Itho/CC1101Packet.h | 25 + Library/Itho/IthoCC1101.cpp | 1243 +++++++++++++++++++++++++++++++++++ Library/Itho/IthoCC1101.h | 167 +++++ Library/Itho/IthoPacket.h | 38 ++ README.md | 43 ++ 11 files changed, 2881 insertions(+) create mode 100644 Images/cntrl panel.JPG create mode 100644 Images/serial.JPG create mode 100644 Itho-WIFI-remote.ino create mode 100644 LICENSE.md create mode 100644 Library/Itho/CC1101.cpp create mode 100644 Library/Itho/CC1101.h create mode 100644 Library/Itho/CC1101Packet.h create mode 100644 Library/Itho/IthoCC1101.cpp create mode 100644 Library/Itho/IthoCC1101.h create mode 100644 Library/Itho/IthoPacket.h create mode 100644 README.md diff --git a/Images/cntrl panel.JPG b/Images/cntrl panel.JPG new file mode 100644 index 0000000000000000000000000000000000000000..207b9f0ae61bfdbd22785c70d3ec7f1f129b45e5 GIT binary patch literal 32366 zcmeFa1z256wk|peZXqGK2M_KRJi&vzyJz9<5+K1PxVuAex1fOl!QCB#yDjcYdiUPD z&+9(#^u7DO@7{N^_zK2cRkNzbUowZ)RH4!}TYC@E8D|^zRb<%twJ-^FtCqunYNx z@PqpG`GvqQ1b!j#3xQt<{6gTrBLdR;c811pA)LcTLjRN`Fdz~`MkLJdbaiypPa2wo z833ZA|DgYnDiA*YK<<}R@!xU&{Nni+0>2RWg}^Taej)G&0xV3-96Zb{JWL!UEKEGi z+&s)|z(4yAV#xsX0Xx7DFa~}IArC9axMmIxHav`sR`v|~M%D(#42ISqMi+e>MrH;k zMu1nq#YW%I(%6B-z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%uGijrRmQuDn z_4K=@2hU!>9gn~W8yhrvU3^F9dT!eX;~yn)ildvW{!d zy04AQiSNfY5|l?gTU?m0-b^i2C*Ow24w$pu#@D*iM+Vdz_i(%*UyqxsquPWq`UZE7 z8M4BsbEtK6v$)G70^2)F^Hm!Rw(T}H0@`>(dkcF zdSC5i?y8&qNagCX{u7tiKi)c*XWI8kZu>%BzcM&FU3uajz3Q|EGwjpnkQGk@o{_VA z=X-wSZ`)e^`#$&Ws8_q{7Ao$T?Ym?CiHc_mY#H}i5;sobczxk>>{Q@Nj!Kzn(-*yt zTHf*Y>wS^6YgcS?i{>@E=B&`N{!rsqcJ7K2UATTj#;;~knQzS zo~Pg5-aO6o!0w-gwV&nN6^r_&@omSpw8gmet&wlEmqGL?rFoXgJ6dmBmmhn0MW#%( zptjd>N#^&{tL|mp+I9PAX|YIwj@YFwD`hew`sYsdRM{=R%kcQMZ5fLbEMwgdi*GO6 zr`cthz`Mpsy7tU{Jw+Gm9gnBl8XwJmy(?zcy2;-vR0U()b%GDQoxA&S!7Dy%p&fR| zw!B!tldJ5%FE;FR*wt(Iv{%nq+?cR!>Qax#PDg6qtnyU7@%Lh%-B!2vhr=fW7o<6F z@?ihA^oY>mY4#c}y?*a3ES)dgt_IGtSk@LF4xcsm+F}(Uhefa7SetK@_@r)RS76Ivp%`)nwM}qPc$wp@q1vU!jq3z z<`gzYwjY{4xnlC$-u&e^+)~SS?AkEPWzt8<2$o5*yNgepo|ZiI0nf)9fzHIwxANWZ8v{^NcEMeusS(d3Q8LROJ3^px$-!e`~JHLadSTNZEpCi=w)yX;`j3}AQKq$v g95!xyxO4W^8S|ez2vMsqFlr8c`(9YWoALim0A6~#ZU6uP literal 0 HcmV?d00001 diff --git a/Images/serial.JPG b/Images/serial.JPG new file mode 100644 index 0000000000000000000000000000000000000000..a053ad0741affeb1bb08ae35636e3ce7d1166e16 GIT binary patch literal 30113 zcmeHv2Ut`|w*Ms~s07Jbf}rG_X@VpXkeop>h-8o;*b0(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r~h9q?m7BDuF;I$pp8oywA7Ch*IS z2!8p}q@;1!XYouQ#5@8_y#)=n%@o8DXt0Hz8f-qNX*pn;*3_FII3q>n2`c#V24UFg z>pY|HP3&O*RbFd8{Lh_@F~nB<{t~`;coD|`n-mgp+C??*2?Vce(^S*EiDAxLB>GO0t+tKsfGC0rF)G8eq5g) zV27Ml9sfM@{7S#UPEA<}Ug!iEGrFnylPMcMvEL7cYu))fF#Z+1{Hy8IJ?ixy0*(2f z9s^Ae?y*igHYIZ|YdN)~D9{G+KFu2cfv43YpgNH4-(W_;MxW(hQt{PV`7dc`R#w-R m`wa_SjR7LRx9ZkjT?-4pe`1rK9m2^u5c;YR2I-+ie*1rq!*l`w literal 0 HcmV?d00001 diff --git a/Itho-WIFI-remote.ino b/Itho-WIFI-remote.ino new file mode 100644 index 0000000..88ae989 --- /dev/null +++ b/Itho-WIFI-remote.ino @@ -0,0 +1,212 @@ +#include +#include "IthoCC1101.h" +#include +#include +#include +#include + +SerialCommand sCmd; +IthoCC1101 rf; + +// webserver +ESP8266WebServer server(80); + +// WIFI +String ssid = "SSID"; +String password = "PASS"; +String espName = "Itho"; +String ClientIP; + +String Version = "0.3"; + + +// HTML + +String header = "Itho control panel"; +String navbar = " "; + +String containerStart = "
"; +String containerEnd = "
"; +String siteEnd = ""; + +String panelHeaderName = "
"; +String panelEnd = "
"; + +String panelBodySymbol = "
"; +String panelBodyValue = ""; +String panelcenter = "
"; +String panelBodyEnd = "
"; + +String inputBodyStart = "
"; +String inputBodyName = "
"; +String inputBodyPOST = "
"; +String ithocontrol = " Low Medium High Timer
Learn
"; + + + +void setup(void) { + Serial.begin(115200); + WiFi.begin(ssid.c_str(), password.c_str()); + int i = 0; + while (WiFi.status() != WL_CONNECTED && i < 31) + { + delay(1000); + Serial.print("."); + ++i; + } + if (WiFi.status() != WL_CONNECTED && i >= 30) + { + WiFi.disconnect(); + delay(1000); + Serial.println(""); + Serial.println("Couldn't connect to network :( "); + Serial.println("Review your WIFI settings"); + } + else + { + Serial.println(""); + Serial.print("Connected to "); + Serial.println(ssid); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); + Serial.print("Hostname: "); + Serial.println(espName); + + } + delay(500); + Serial.println("setup begin"); + rf.init(); + Serial.println("setup done"); + sendRegister(); // Your Itho only accepts this command while in learning mode, powercycle your itho then start the nodemcu. + Serial.println("join command sent"); + // Setup callbacks for SerialCommand commands + sCmd.addCommand("High", sendFullSpeed); + sCmd.addCommand("Medium", sendMediumSpeed); + sCmd.addCommand("Low", sendLowSpeed); + sCmd.addCommand("Timer", sendTimer); + sCmd.addCommand("Learn", sendRegister); // Register remote in ithon fan + sCmd.setDefaultHandler(unrecognized); // Handler for command that isn't matched (says "What?") + server.on("/api", handle_api); + server.on("/", handle_root); + server.begin(); +} + +void loop(void) { + + sCmd.readSerial(); + server.handleClient(); +} + +void sendRegister() { + Serial.println("sending join..."); + rf.sendCommand(IthoJoin); + Serial.println("sending join done."); + handle_root(); +} + +void sendLowSpeed() { + Serial.println("sending low..."); + rf.sendCommand(IthoLow); + Serial.println("sending low done."); + handle_root(); +} + +void sendMediumSpeed() { + Serial.println("sending medium..."); + rf.sendCommand(IthoMedium); + Serial.println("sending medium done."); + handle_root(); +} + +void sendFullSpeed() { + Serial.println("sending FullSpeed..."); + rf.sendCommand(IthoFull); + Serial.println("sending FullSpeed done."); + handle_root(); +} + +void sendTimer() { + Serial.println("sending timer..."); + rf.sendCommand(IthoTimer1); + Serial.println("sending timer done."); + handle_root(); +} + +void unrecognized(const char *command) { + Serial.println("What?"); +} + +void handle_api() +{ + // Get vars for all commands + String action = server.arg("action"); + String value = server.arg("value"); + String api = server.arg("api"); + + if (action == "High") + { + sendFullSpeed(); + server.send ( 200, "text/html", "Full Powerrr!!!"); + } + + if (action == "Medium") + { + sendMediumSpeed(); + server.send ( 200, "text/html", "Medium speed selected"); + } + + if (action == "Low") + { + sendLowSpeed(); + server.send ( 200, "text/html", "Slow speed selected"); + } + + if (action == "Timer") + { + sendTimer(); + server.send ( 200, "text/html", "Timer on selected"); + } + + if (action == "Learn") + { + sendRegister(); + server.send ( 200, "text/html", "Send learn command OK"); + } + + + if (action == "reset" && value == "true") + { + server.send ( 200, "text/html", "Reset ESP OK"); + delay(500); + Serial.println("RESET"); + ESP.restart(); + } +} + +void handle_root() +{ + + // get IP + IPAddress ip = WiFi.localIP(); + ClientIP = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]); + delay(500); + + String title1 = panelHeaderName + String("Itho WIFI remote") + panelHeaderEnd; + String IPAddClient = panelBodySymbol + String("globe") + panelBodyName + String("IP Address") + panelBodyValue + ClientIP + panelBodyEnd; + String ClientName = panelBodySymbol + String("tag") + panelBodyName + String("Client Name") + panelBodyValue + espName + panelBodyEnd; + String Uptime = panelBodySymbol + String("time") + panelBodyName + String("Uptime") + panelBodyValue + hour() + String(" h ") + minute() + String(" min ") + second() + String(" sec") + panelBodyEnd + panelEnd; + + + String title3 = panelHeaderName + String("Commands") + panelHeaderEnd; + + String commands = panelBodySymbol + panelBodyName + panelcenter + ithocontrol + panelBodyEnd; + + + server.send ( 200, "text/html", header + navbar + containerStart + title1 + IPAddClient + ClientName + Uptime + title3 + commands + containerEnd + siteEnd); + +} + + diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..9cecc1d --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/Library/Itho/CC1101.cpp b/Library/Itho/CC1101.cpp new file mode 100644 index 0000000..ed62063 --- /dev/null +++ b/Library/Itho/CC1101.cpp @@ -0,0 +1,272 @@ +/* + * Author: Klusjesman, modified bij supersjimmie for Arduino/ESP8266 + */ + +#include "CC1101.h" + +// default constructor +CC1101::CC1101() +{ + SPI.begin(); +#ifdef ESP8266 + pinMode(SS, OUTPUT); +#endif +} //CC1101 + +// default destructor +CC1101::~CC1101() +{ +} //~CC1101 + +/***********************/ +// SPI helper functions select() and deselect() +inline void CC1101::select(void) { + digitalWrite(SS, LOW); +} + +inline void CC1101::deselect(void) { + digitalWrite(SS, HIGH); +} + +void CC1101::spi_waitMiso() +{ + while(digitalRead(MISO) == HIGH) yield(); +} + +void CC1101::init() +{ + reset(); +} + +void CC1101::reset() +{ + deselect(); + delayMicroseconds(5); + select(); + delayMicroseconds(10); + deselect(); + delayMicroseconds(45); + select(); + + spi_waitMiso(); + SPI.transfer(CC1101_SRES); + delay(10); + spi_waitMiso(); + deselect(); +} + +uint8_t CC1101::writeCommand(uint8_t command) +{ + uint8_t result; + + select(); + spi_waitMiso(); + result = SPI.transfer(command); + deselect(); + + return result; +} + +void CC1101::writeRegister(uint8_t address, uint8_t data) +{ + select(); + spi_waitMiso(); + SPI.transfer(address); + SPI.transfer(data); + deselect(); +} + +uint8_t CC1101::readRegister(uint8_t address) +{ + uint8_t val; + + select(); + spi_waitMiso(); + SPI.transfer(address); + val = SPI.transfer(0); + deselect(); + + return val; +} + +uint8_t CC1101::readRegisterMedian3(uint8_t address) +{ + uint8_t val, val1, val2, val3; + + select(); + spi_waitMiso(); + SPI.transfer(address); + val1 = SPI.transfer(0); + SPI.transfer(address); + val2 = SPI.transfer(0); + SPI.transfer(address); + val3 = SPI.transfer(0); + deselect(); + // reverse sort (largest in val1) because this is te expected order for TX_BUFFER + if (val3 > val2) {val = val3; val3 = val2; val2 = val; } //Swap(val3,val2) + if (val2 > val1) {val = val2; val2 = val1, val1 = val; } //Swap(val2,val1) + if (val3 > val2) {val = val3; val3 = val2, val2 = val; } //Swap(val3,val2) + + return val2; +} + +/* Known SPI/26MHz synchronization bug (see CC1101 errata) +This issue affects the following registers: SPI status byte (fields STATE and FIFO_BYTES_AVAILABLE), +FREQEST or RSSI while the receiver is active, MARCSTATE at any time other than an IDLE radio state, +RXBYTES when receiving or TXBYTES when transmitting, and WORTIME1/WORTIME0 at any time.*/ +uint8_t CC1101::readRegisterWithSyncProblem(uint8_t address, uint8_t registerType) +{ + uint8_t value1, value2; + + value1 = readRegister(address | registerType); + + //if two consecutive reads gives us the same result then we know we are ok + do + { + value2 = value1; + value1 = readRegister(address | registerType); + } + while (value1 != value2); + + return value1; +} + +//registerType = CC1101_CONFIG_REGISTER or CC1101_STATUS_REGISTER +uint8_t CC1101::readRegister(uint8_t address, uint8_t registerType) +{ + switch (address) + { + case CC1101_FREQEST: + case CC1101_MARCSTATE: + case CC1101_RXBYTES: + case CC1101_TXBYTES: + case CC1101_WORTIME1: + case CC1101_WORTIME0: + return readRegisterWithSyncProblem(address, registerType); + + default: + return readRegister(address | registerType); + } +} + +void CC1101::writeBurstRegister(uint8_t address, uint8_t* data, uint8_t length) +{ + uint8_t i; + + select(); + spi_waitMiso(); + SPI.transfer(address | CC1101_WRITE_BURST); + for (i = 0; i < length; i++) { + SPI.transfer(data[i]); + } + deselect(); +} + +void CC1101::readBurstRegister(uint8_t* buffer, uint8_t address, uint8_t length) +{ + uint8_t i; + + select(); + spi_waitMiso(); + SPI.transfer(address | CC1101_READ_BURST); + + for (i = 0; i < length; i++) { + buffer[i] = SPI.transfer(0x00); + } + + deselect(); +} + +//wait for fixed length in rx fifo +uint8_t CC1101::receiveData(CC1101Packet* packet, uint8_t length) +{ + uint8_t rxBytes = readRegisterWithSyncProblem(CC1101_RXBYTES, CC1101_STATUS_REGISTER); + rxBytes = rxBytes & CC1101_BITS_RX_BYTES_IN_FIFO; + + //check for rx fifo overflow + if ((readRegisterWithSyncProblem(CC1101_MARCSTATE, CC1101_STATUS_REGISTER) & CC1101_BITS_MARCSTATE) == CC1101_MARCSTATE_RXFIFO_OVERFLOW) + { + writeCommand(CC1101_SIDLE); //idle + writeCommand(CC1101_SFRX); //flush RX buffer + writeCommand(CC1101_SRX); //switch to RX state + } + else if (rxBytes == length) + { + readBurstRegister(packet->data, CC1101_RXFIFO, rxBytes); + + //continue RX + writeCommand(CC1101_SIDLE); //idle + writeCommand(CC1101_SFRX); //flush RX buffer + writeCommand(CC1101_SRX); //switch to RX state + + packet->length = rxBytes; + } + else + { + //empty fifo + packet->length = 0; + } + + return packet->length; +} + +//This function is able to send packets bigger then the FIFO size. +bool CC1101::sendData(CC1101Packet *packet) +{ + uint8_t index = 0; + uint8_t txStatus, MarcState; + uint8_t length; + + writeCommand(CC1101_SIDLE); //idle + + txStatus = readRegisterWithSyncProblem(CC1101_TXBYTES, CC1101_STATUS_REGISTER); + + //clear TX fifo if needed + if (txStatus & CC1101_BITS_TX_FIFO_UNDERFLOW) + { + writeCommand(CC1101_SIDLE); //idle + writeCommand(CC1101_SFTX); //flush TX buffer + } + + writeCommand(CC1101_SIDLE); //idle + + //determine how many bytes to send + length = (packet->length <= CC1101_DATA_LEN ? packet->length : CC1101_DATA_LEN); + + writeBurstRegister(CC1101_TXFIFO, packet->data, length); + + writeCommand(CC1101_SIDLE); + //start sending packet + writeCommand(CC1101_STX); + + //continue sending when packet is bigger than 64 bytes + if (packet->length > CC1101_DATA_LEN) + { + index += length; + + //loop until all bytes are transmitted + while (index < packet->length) + { + //check if there is free space in the fifo + while ((txStatus = (readRegisterMedian3(CC1101_TXBYTES | CC1101_STATUS_REGISTER) & CC1101_BITS_RX_BYTES_IN_FIFO)) > (CC1101_DATA_LEN - 2)); + + //calculate how many bytes we can send + length = (CC1101_DATA_LEN - txStatus); + length = ((packet->length - index) < length ? (packet->length - index) : length); + + //send some more bytes + for (int i=0; idata[index+i]); + + index += length; + } + } + + //wait until transmission is finished (TXOFF_MODE is expected to be set to 0/IDLE or TXFIFO_UNDERFLOW) + do + { + MarcState = (readRegisterWithSyncProblem(CC1101_MARCSTATE, CC1101_STATUS_REGISTER) & CC1101_BITS_MARCSTATE); + if (MarcState == CC1101_MARCSTATE_TXFIFO_UNDERFLOW) Serial.print("TXFIFO_UNDERFLOW occured in sendData() \n"); + } + while((MarcState != CC1101_MARCSTATE_IDLE) && (MarcState != CC1101_MARCSTATE_TXFIFO_UNDERFLOW)); +} diff --git a/Library/Itho/CC1101.h b/Library/Itho/CC1101.h new file mode 100644 index 0000000..7e4ddb2 --- /dev/null +++ b/Library/Itho/CC1101.h @@ -0,0 +1,207 @@ +/* + * Author: Klusjesman, modified bij supersjimmie for Arduino/ESP8266 + */ + +#ifndef __CC1101_H__ +#define __CC1101_H__ + +#include +#include "CC1101Packet.h" +#include +// On Arduino, SPI pins are predefined + +/* Type of transfers */ +#define CC1101_WRITE_BURST 0x40 +#define CC1101_READ_SINGLE 0x80 +#define CC1101_READ_BURST 0xC0 + +/* Type of register */ +#define CC1101_CONFIG_REGISTER CC1101_READ_SINGLE +#define CC1101_STATUS_REGISTER CC1101_READ_BURST + +/* PATABLE & FIFO's */ +#define CC1101_PATABLE 0x3E // PATABLE address +#define CC1101_TXFIFO 0x3F // TX FIFO address +#define CC1101_RXFIFO 0x3F // RX FIFO address +#define CC1101_PA_LowPower 0x60 +#define CC1101_PA_LongDistance 0xC0 + +/* Command strobes */ +#define CC1101_SRES 0x30 // Reset CC1101 chip +#define CC1101_SFSTXON 0x31 // Enable and calibrate frequency synthesizer (if MCSM0.FS_AUTOCAL=1). If in RX (with CCA): Go to a wait state where only the synthesizer is running (for quick RX / TX turnaround). +#define CC1101_SXOFF 0x32 // Turn off crystal oscillator +#define CC1101_SCAL 0x33 // Calibrate frequency synthesizer and turn it off. SCAL can be strobed from IDLE mode without setting manual calibration mode (MCSM0.FS_AUTOCAL=0) +#define CC1101_SRX 0x34 // Enable RX. Perform calibration first if coming from IDLE and MCSM0.FS_AUTOCAL=1 +#define CC1101_STX 0x35 // In IDLE state: Enable TX. Perform calibration first if MCSM0.FS_AUTOCAL=1. If in RX state and CCA is enabled: Only go to TX if channel is clear +#define CC1101_SIDLE 0x36 // Exit RX / TX, turn off frequency synthesizer and exit Wake-On-Radio mode if applicable +#define CC1101_SWOR 0x38 // Start automatic RX polling sequence (Wake-on-Radio) as described in Section 19.5 if WORCTRL.RC_PD=0 +#define CC1101_SPWD 0x39 // Enter power down mode when CSn goes high +#define CC1101_SFRX 0x3A // Flush the RX FIFO buffer. Only issue SFRX in IDLE or RXFIFO_OVERFLOW states +#define CC1101_SFTX 0x3B // Flush the TX FIFO buffer. Only issue SFTX in IDLE or TXFIFO_UNDERFLOW states +#define CC1101_SWORRST 0x3C // Reset real time clock to Event1 value +#define CC1101_SNOP 0x3D // No operation. May be used to get access to the chip status byte + +/* CC1101 configuration registers */ +#define CC1101_IOCFG2 0x00 // GDO2 Output Pin Configuration +#define CC1101_IOCFG1 0x01 // GDO1 Output Pin Configuration +#define CC1101_IOCFG0 0x02 // GDO0 Output Pin Configuration +#define CC1101_FIFOTHR 0x03 // RX FIFO and TX FIFO Thresholds +#define CC1101_SYNC1 0x04 // Sync Word, High Byte +#define CC1101_SYNC0 0x05 // Sync Word, Low Byte +#define CC1101_PKTLEN 0x06 // Packet Length +#define CC1101_PKTCTRL1 0x07 // Packet Automation Control +#define CC1101_PKTCTRL0 0x08 // Packet Automation Control +#define CC1101_ADDR 0x09 // Device Address +#define CC1101_CHANNR 0x0A // Channel Number +#define CC1101_FSCTRL1 0x0B // Frequency Synthesizer Control +#define CC1101_FSCTRL0 0x0C // Frequency Synthesizer Control +#define CC1101_FREQ2 0x0D // Frequency Control Word, High Byte +#define CC1101_FREQ1 0x0E // Frequency Control Word, Middle Byte +#define CC1101_FREQ0 0x0F // Frequency Control Word, Low Byte +#define CC1101_MDMCFG4 0x10 // Modem Configuration +#define CC1101_MDMCFG3 0x11 // Modem Configuration +#define CC1101_MDMCFG2 0x12 // Modem Configuration +#define CC1101_MDMCFG1 0x13 // Modem Configuration +#define CC1101_MDMCFG0 0x14 // Modem Configuration +#define CC1101_DEVIATN 0x15 // Modem Deviation Setting +#define CC1101_MCSM2 0x16 // Main Radio Control State Machine Configuration +#define CC1101_MCSM1 0x17 // Main Radio Control State Machine Configuration +#define CC1101_MCSM0 0x18 // Main Radio Control State Machine Configuration +#define CC1101_FOCCFG 0x19 // Frequency Offset Compensation Configuration +#define CC1101_BSCFG 0x1A // Bit Synchronization Configuration +#define CC1101_AGCCTRL2 0x1B // AGC Control +#define CC1101_AGCCTRL1 0x1C // AGC Control +#define CC1101_AGCCTRL0 0x1D // AGC Control +#define CC1101_WOREVT1 0x1E // High Byte Event0 Timeout +#define CC1101_WOREVT0 0x1F // Low Byte Event0 Timeout +#define CC1101_WORCTRL 0x20 // Wake On Radio Control +#define CC1101_FREND1 0x21 // Front End RX Configuration +#define CC1101_FREND0 0x22 // Front End TX Configuration +#define CC1101_FSCAL3 0x23 // Frequency Synthesizer Calibration +#define CC1101_FSCAL2 0x24 // Frequency Synthesizer Calibration +#define CC1101_FSCAL1 0x25 // Frequency Synthesizer Calibration +#define CC1101_FSCAL0 0x26 // Frequency Synthesizer Calibration +#define CC1101_RCCTRL1 0x27 // RC Oscillator Configuration +#define CC1101_RCCTRL0 0x28 // RC Oscillator Configuration +#define CC1101_FSTEST 0x29 // Frequency Synthesizer Calibration Control +#define CC1101_PTEST 0x2A // Production Test +#define CC1101_AGCTEST 0x2B // AGC Test +#define CC1101_TEST2 0x2C // Various Test Settings +#define CC1101_TEST1 0x2D // Various Test Settings +#define CC1101_TEST0 0x2E // Various Test Settings + +/* Status registers */ +#define CC1101_PARTNUM 0x30 // Chip ID +#define CC1101_VERSION 0x31 // Chip ID +#define CC1101_FREQEST 0x32 // Frequency Offset Estimate from Demodulator +#define CC1101_LQI 0x33 // Demodulator Estimate for Link Quality +#define CC1101_RSSI 0x34 // Received Signal Strength Indication +#define CC1101_MARCSTATE 0x35 // Main Radio Control State Machine State +#define CC1101_WORTIME1 0x36 // High Byte of WOR Time +#define CC1101_WORTIME0 0x37 // Low Byte of WOR Time +#define CC1101_PKTSTATUS 0x38 // Current GDOx Status and Packet Status +#define CC1101_VCO_VC_DAC 0x39 // Current Setting from PLL Calibration Module +#define CC1101_TXBYTES 0x3A // Underflow and Number of Bytes +#define CC1101_RXBYTES 0x3B // Overflow and Number of Bytes +#define CC1101_RCCTRL1_STATUS 0x3C // Last RC Oscillator Calibration Result +#define CC1101_RCCTRL0_STATUS 0x3D // Last RC Oscillator Calibration Result + +/* Bit fields in the chip status byte */ +#define CC1101_STATUS_CHIP_RDYn_BM 0x80 +#define CC1101_STATUS_STATE_BM 0x70 +#define CC1101_STATUS_FIFO_BYTES_AVAILABLE_BM 0x0F + +/* Masks to retrieve status bit */ +#define CC1101_BITS_TX_FIFO_UNDERFLOW 0x80 +#define CC1101_BITS_RX_BYTES_IN_FIFO 0x7F +#define CC1101_BITS_MARCSTATE 0x1F + + +/* Marc states */ +enum CC1101MarcStates +{ + CC1101_MARCSTATE_SLEEP = 0x00, + CC1101_MARCSTATE_IDLE = 0x01, + CC1101_MARCSTATE_XOFF = 0x02, + CC1101_MARCSTATE_VCOON_MC = 0x03, + CC1101_MARCSTATE_REGON_MC = 0x04, + CC1101_MARCSTATE_MANCAL = 0x05, + CC1101_MARCSTATE_VCOON = 0x06, + CC1101_MARCSTATE_REGON = 0x07, + CC1101_MARCSTATE_STARTCAL = 0x08, + CC1101_MARCSTATE_BWBOOST = 0x09, + CC1101_MARCSTATE_FS_LOCK = 0x0A, + CC1101_MARCSTATE_IFADCON = 0x0B, + CC1101_MARCSTATE_ENDCAL = 0x0C, + CC1101_MARCSTATE_RX = 0x0D, + CC1101_MARCSTATE_RX_END = 0x0E, + CC1101_MARCSTATE_RX_RST = 0x0F, + CC1101_MARCSTATE_TXRX_SWITCH = 0x10, + CC1101_MARCSTATE_RXFIFO_OVERFLOW = 0x11, + CC1101_MARCSTATE_FSTXON = 0x12, + CC1101_MARCSTATE_TX = 0x13, + CC1101_MARCSTATE_TX_END = 0x14, + CC1101_MARCSTATE_RXTX_SWITCH = 0x15, + CC1101_MARCSTATE_TXFIFO_UNDERFLOW = 0x16 +}; + + +/* Chip states */ +enum CC1101ChipStates +{ + CC1101_STATE_MASK = 0x70, + CC1101_STATE_IDLE = 0x00, + CC1101_STATE_RX = 0x10, + CC1101_STATE_TX = 0x20, + CC1101_STATE_FSTXON = 0x30, + CC1101_STATE_CALIBRATE = 0x40, + CC1101_STATE_SETTLING = 0x50, + CC1101_STATE_RX_OVERFLOW = 0x60, + CC1101_STATE_TX_UNDERFLOW = 0x70 +}; + + + +class CC1101 +{ + protected: + + //functions + public: + CC1101(); + ~CC1101(); + + //spi + void spi_waitMiso(); + + //cc1101 + void init(); + + uint8_t writeCommand(uint8_t command); + void writeRegister(uint8_t address, uint8_t data); + + uint8_t readRegister(uint8_t address, uint8_t registerType); + + void writeBurstRegister(uint8_t address, uint8_t* data, uint8_t length); + void readBurstRegister(uint8_t* buffer, uint8_t address, uint8_t length); + + bool sendData(CC1101Packet *packet); + uint8_t receiveData(CC1101Packet* packet, uint8_t length); + + private: + CC1101( const CC1101 &c ); + CC1101& operator=( const CC1101 &c ); + // SPI helper functions + void select(void); + void deselect(void); + + protected: + uint8_t readRegister(uint8_t address); + uint8_t readRegisterMedian3(uint8_t address); + uint8_t readRegisterWithSyncProblem(uint8_t address, uint8_t registerType); + + void reset(); + +}; //CC1101 + +#endif //__CC1101_H__ diff --git a/Library/Itho/CC1101Packet.h b/Library/Itho/CC1101Packet.h new file mode 100644 index 0000000..e79552c --- /dev/null +++ b/Library/Itho/CC1101Packet.h @@ -0,0 +1,25 @@ +/* + * Author: Klusjesman, modified bij supersjimmie for Arduino/ESP8266 + */ + +#ifndef CC1101PACKET_H_ +#define CC1101PACKET_H_ + +#include +#ifdef ESP8266 +#include +#endif + +#define CC1101_BUFFER_LEN 64 +#define CC1101_DATA_LEN CC1101_BUFFER_LEN - 3 + + +class CC1101Packet +{ + public: + uint8_t length; + uint8_t data[72]; +}; + + +#endif /* CC1101PACKET_H_ */ \ No newline at end of file diff --git a/Library/Itho/IthoCC1101.cpp b/Library/Itho/IthoCC1101.cpp new file mode 100644 index 0000000..4c5c123 --- /dev/null +++ b/Library/Itho/IthoCC1101.cpp @@ -0,0 +1,1243 @@ +/* + * Author: Klusjesman, modified bij supersjimmie for Arduino/ESP8266 + */ + +#include "IthoCC1101.h" +#include +#include +#include + +// default constructor +IthoCC1101::IthoCC1101(uint8_t counter, uint8_t sendTries) : CC1101() +{ + this->outIthoPacket.counter = counter; + this->outIthoPacket.previous = IthoLow; + this->sendTries = sendTries; + this->receiveState = ExpectMessageStart; + + //fixed device id + this->outIthoPacket.deviceId[0] = 101; + this->outIthoPacket.deviceId[1] = 89; + this->outIthoPacket.deviceId[2] = 154; + this->outIthoPacket.deviceId[3] = 153; + this->outIthoPacket.deviceId[4] = 170; + this->outIthoPacket.deviceId[5] = 105; + this->outIthoPacket.deviceId[6] = 154; + this->outIthoPacket.deviceId[7] = 86; +} //IthoCC1101 + +// default destructor +IthoCC1101::~IthoCC1101() +{ +} //~IthoCC1101 + +void IthoCC1101::initSendMessage1() +{ + /* + Configuration reverse engineered from remote print. The commands below are used by IthoDaalderop. + + Base frequency 868.299866MHz + Channel 0 + Channel spacing 199.951172kHz + Carrier frequency 868.299866MHz + Xtal frequency 26.000000MHz + Data rate 8.00896kBaud + Manchester disabled + Modulation 2-FSK + Deviation 25.390625kHz + TX power ? + PA ramping enabled + Whitening disabled + */ + writeCommand(CC1101_SRES); + delayMicroseconds(1); + writeRegister(CC1101_IOCFG0 ,0x2E); //High impedance (3-state) + writeRegister(CC1101_FREQ2 ,0x21); //00100001 878MHz-927.8MHz + writeRegister(CC1101_FREQ1 ,0x65); //01100101 + writeRegister(CC1101_FREQ0 ,0x6A); //01101010 + writeRegister(CC1101_MDMCFG4 ,0x07); //00000111 + writeRegister(CC1101_MDMCFG3 ,0x43); //01000011 + writeRegister(CC1101_MDMCFG2 ,0x00); //00000000 2-FSK, no manchester encoding/decoding, no preamble/sync + writeRegister(CC1101_MDMCFG1 ,0x22); //00100010 + writeRegister(CC1101_MDMCFG0 ,0xF8); //11111000 + writeRegister(CC1101_CHANNR ,0x00); //00000000 + writeRegister(CC1101_DEVIATN ,0x40); //01000000 + writeRegister(CC1101_FREND0 ,0x17); //00010111 use index 7 in PA table + writeRegister(CC1101_MCSM0 ,0x18); //00011000 PO timeout Approx. 146µs - 171µs, Auto calibrate When going from IDLE to RX or TX (or FSTXON) + writeRegister(CC1101_FSCAL3 ,0xA9); //10101001 + writeRegister(CC1101_FSCAL2 ,0x2A); //00101010 + writeRegister(CC1101_FSCAL1 ,0x00); //00000000 + writeRegister(CC1101_FSCAL0 ,0x11); //00010001 + writeRegister(CC1101_FSTEST ,0x59); //01011001 For test only. Do not write to this register. + writeRegister(CC1101_TEST2 ,0x81); //10000001 For test only. Do not write to this register. + writeRegister(CC1101_TEST1 ,0x35); //00110101 For test only. Do not write to this register. + writeRegister(CC1101_TEST0 ,0x0B); //00001011 For test only. Do not write to this register. + writeRegister(CC1101_PKTCTRL0 ,0x12); //00010010 Enable infinite length packets, CRC disabled, Turn data whitening off, Serial Synchronous mode + writeRegister(CC1101_ADDR ,0x00); //00000000 + writeRegister(CC1101_PKTLEN ,0xFF); //11111111 //Not used, no hardware packet handling + + //0x6F,0x26,0x2E,0x8C,0x87,0xCD,0xC7,0xC0 + writeBurstRegister(CC1101_PATABLE | CC1101_WRITE_BURST, (uint8_t*)ithoPaTableSend, 8); + + writeCommand(CC1101_SIDLE); + writeCommand(CC1101_SIDLE); + writeCommand(CC1101_SIDLE); + + writeRegister(CC1101_MDMCFG4 ,0x08); //00001000 + writeRegister(CC1101_MDMCFG3 ,0x43); //01000011 + writeRegister(CC1101_DEVIATN ,0x40); //01000000 + writeRegister(CC1101_IOCFG0 ,0x2D); //GDO0_Z_EN_N. When this output is 0, GDO0 is configured as input (for serial TX data). + writeRegister(CC1101_IOCFG1 ,0x0B); //Serial Clock. Synchronous to the data in synchronous serial mode. + + writeCommand(CC1101_STX); + writeCommand(CC1101_SIDLE); + delayMicroseconds(1); + writeCommand(CC1101_SIDLE); + + writeRegister(CC1101_MDMCFG4 ,0x08); //00001000 + writeRegister(CC1101_MDMCFG3 ,0x43); //01000011 + writeRegister(CC1101_DEVIATN ,0x40); //01000000 + //writeRegister(CC1101_IOCFG0 ,0x2D); //GDO0_Z_EN_N. When this output is 0, GDO0 is configured as input (for serial TX data). + //writeRegister(CC1101_IOCFG1 ,0x0B); //Serial Clock. Synchronous to the data in synchronous serial mode. + + //Itho is using serial mode for transmit. We want to use the TX FIFO with fixed packet length for simplicity. + writeRegister(CC1101_IOCFG0 ,0x2E); + writeRegister(CC1101_IOCFG1 ,0x2E); + writeRegister(CC1101_PKTLEN , 19); + writeRegister(CC1101_PKTCTRL0 ,0x00); + writeRegister(CC1101_PKTCTRL1 ,0x00); +} + +void IthoCC1101::initSendMessage2(IthoCommand command) +{ + //finishTransfer(); + writeCommand(CC1101_SIDLE); + delayMicroseconds(1); + writeRegister(CC1101_IOCFG0 ,0x2E); + delayMicroseconds(1); + writeRegister(CC1101_IOCFG1 ,0x2E); + delayMicroseconds(1); + writeCommand(CC1101_SIDLE); + writeCommand(CC1101_SPWD); + delayMicroseconds(1); + + /* + Configuration reverse engineered from remote print. The commands below are used by IthoDaalderop. + + Base frequency 868.299866MHz + Channel 0 + Channel spacing 199.951172kHz + Carrier frequency 868.299866MHz + Xtal frequency 26.000000MHz + Data rate 38.3835kBaud + Manchester disabled + Modulation 2-FSK + Deviation 50.781250kHz + TX power ? + PA ramping enabled + Whitening disabled + */ + writeCommand(CC1101_SRES); + delayMicroseconds(1); + writeRegister(CC1101_IOCFG0 ,0x2E); //High impedance (3-state) + writeRegister(CC1101_FREQ2 ,0x21); //00100001 878MHz-927.8MHz + writeRegister(CC1101_FREQ1 ,0x65); //01100101 + writeRegister(CC1101_FREQ0 ,0x6A); //01101010 + writeRegister(CC1101_MDMCFG4 ,0x5A); //difference compared to message1 + writeRegister(CC1101_MDMCFG3 ,0x83); //difference compared to message1 + writeRegister(CC1101_MDMCFG2 ,0x00); //00000000 2-FSK, no manchester encoding/decoding, no preamble/sync + writeRegister(CC1101_MDMCFG1 ,0x22); //00100010 + writeRegister(CC1101_MDMCFG0 ,0xF8); //11111000 + writeRegister(CC1101_CHANNR ,0x00); //00000000 + writeRegister(CC1101_DEVIATN ,0x50); //difference compared to message1 + writeRegister(CC1101_FREND0 ,0x17); //00010111 use index 7 in PA table + writeRegister(CC1101_MCSM0 ,0x18); //00011000 PO timeout Approx. 146µs - 171µs, Auto calibrate When going from IDLE to RX or TX (or FSTXON) + writeRegister(CC1101_FSCAL3 ,0xA9); //10101001 + writeRegister(CC1101_FSCAL2 ,0x2A); //00101010 + writeRegister(CC1101_FSCAL1 ,0x00); //00000000 + writeRegister(CC1101_FSCAL0 ,0x11); //00010001 + writeRegister(CC1101_FSTEST ,0x59); //01011001 For test only. Do not write to this register. + writeRegister(CC1101_TEST2 ,0x81); //10000001 For test only. Do not write to this register. + writeRegister(CC1101_TEST1 ,0x35); //00110101 For test only. Do not write to this register. + writeRegister(CC1101_TEST0 ,0x0B); //00001011 For test only. Do not write to this register. + writeRegister(CC1101_PKTCTRL0 ,0x12); //00010010 Enable infinite length packets, CRC disabled, Turn data whitening off, Serial Synchronous mode + writeRegister(CC1101_ADDR ,0x00); //00000000 + writeRegister(CC1101_PKTLEN ,0xFF); //11111111 //Not used, no hardware packet handling + + //0x6F,0x26,0x2E,0x8C,0x87,0xCD,0xC7,0xC0 + writeBurstRegister(CC1101_PATABLE | CC1101_WRITE_BURST, (uint8_t*)ithoPaTableSend, 8); + + //difference, message1 sends a STX here + writeCommand(CC1101_SIDLE); + writeCommand(CC1101_SIDLE); + + writeRegister(CC1101_MDMCFG4 ,0x5A); //difference compared to message1 + writeRegister(CC1101_MDMCFG3 ,0x83); //difference compared to message1 + writeRegister(CC1101_DEVIATN ,0x50); //difference compared to message1 + writeRegister(CC1101_IOCFG0 ,0x2D); //GDO0_Z_EN_N. When this output is 0, GDO0 is configured as input (for serial TX data). + writeRegister(CC1101_IOCFG1 ,0x0B); //Serial Clock. Synchronous to the data in synchronous serial mode. + + writeCommand(CC1101_STX); + writeCommand(CC1101_SIDLE); + + writeRegister(CC1101_MDMCFG4 ,0x5A); //difference compared to message1 + writeRegister(CC1101_MDMCFG3 ,0x83); //difference compared to message1 + writeRegister(CC1101_DEVIATN ,0x50); //difference compared to message1 + //writeRegister(CC1101_IOCFG0 ,0x2D); //GDO0_Z_EN_N. When this output is 0, GDO0 is configured as input (for serial TX data). + //writeRegister(CC1101_IOCFG1 ,0x0B); //Serial Clock. Synchronous to the data in synchronous serial mode. + + //Itho is using serial mode for transmit. We want to use the TX FIFO with fixed packet length for simplicity. + writeRegister(CC1101_IOCFG0 ,0x2E); + writeRegister(CC1101_IOCFG1 ,0x2E); + writeRegister(CC1101_PKTCTRL0 ,0x00); + writeRegister(CC1101_PKTCTRL1 ,0x00); + + switch (command) + { + case IthoJoin: + writeRegister(CC1101_PKTLEN , 72); + break; + + case IthoLeave: + writeRegister(CC1101_PKTLEN , 57); + break; + + default: + writeRegister(CC1101_PKTLEN , 50); + break; + } +} + +void IthoCC1101::finishTransfer() +{ + writeCommand(CC1101_SIDLE); + delayMicroseconds(1); + + writeRegister(CC1101_IOCFG0 ,0x2E); + writeRegister(CC1101_IOCFG1 ,0x2E); + + writeCommand(CC1101_SIDLE); + writeCommand(CC1101_SPWD); +} + +void IthoCC1101::initReceive() +{ + /* + Configuration reverse engineered from RFT print. + + Base frequency 868.299866MHz + Channel 0 + Channel spacing 199.951172kHz + Carrier frequency 868.299866MHz + Xtal frequency 26.000000MHz + Data rate 38.3835kBaud + RX filter BW 325.000000kHz + Manchester disabled + Modulation 2-FSK + Deviation 50.781250kHz + TX power 0x6F,0x26,0x2E,0x7F,0x8A,0x84,0xCA,0xC4 + PA ramping enabled + Whitening disabled + */ + writeCommand(CC1101_SRES); + + writeRegister(CC1101_TEST0 ,0x09); + writeRegister(CC1101_FSCAL2 ,0x00); + + //0x6F,0x26,0x2E,0x7F,0x8A,0x84,0xCA,0xC4 + writeBurstRegister(CC1101_PATABLE | CC1101_WRITE_BURST, (uint8_t*)ithoPaTableReceive, 8); + + writeCommand(CC1101_SCAL); + + //wait for calibration to finish + while ((readRegisterWithSyncProblem(CC1101_MARCSTATE, CC1101_STATUS_REGISTER)) != CC1101_MARCSTATE_IDLE) yield(); + + writeRegister(CC1101_FSCAL2 ,0x00); + writeRegister(CC1101_MCSM0 ,0x18); //no auto calibrate + writeRegister(CC1101_FREQ2 ,0x21); + writeRegister(CC1101_FREQ1 ,0x65); + writeRegister(CC1101_FREQ0 ,0x6A); + writeRegister(CC1101_IOCFG0 ,0x2E); //High impedance (3-state) + writeRegister(CC1101_IOCFG2 ,0x2E); //High impedance (3-state) + writeRegister(CC1101_FSCTRL1 ,0x06); + writeRegister(CC1101_FSCTRL0 ,0x00); + writeRegister(CC1101_MDMCFG4 ,0x5A); + writeRegister(CC1101_MDMCFG3 ,0x83); + writeRegister(CC1101_MDMCFG2 ,0x00); //Enable digital DC blocking filter before demodulator, 2-FSK, Disable Manchester encoding/decoding, No preamble/sync + writeRegister(CC1101_MDMCFG1 ,0x22); //Disable FEC + writeRegister(CC1101_MDMCFG0 ,0xF8); + writeRegister(CC1101_CHANNR ,0x00); + writeRegister(CC1101_DEVIATN ,0x50); + writeRegister(CC1101_FREND1 ,0x56); + writeRegister(CC1101_FREND0 ,0x17); + writeRegister(CC1101_MCSM0 ,0x18); //no auto calibrate + writeRegister(CC1101_FOCCFG ,0x16); + writeRegister(CC1101_BSCFG ,0x6C); + writeRegister(CC1101_AGCCTRL2 ,0x43); + writeRegister(CC1101_AGCCTRL1 ,0x40); + writeRegister(CC1101_AGCCTRL0 ,0x91); + writeRegister(CC1101_FSCAL3 ,0xA9); + writeRegister(CC1101_FSCAL2 ,0x2A); + writeRegister(CC1101_FSCAL1 ,0x00); + writeRegister(CC1101_FSCAL0 ,0x11); + writeRegister(CC1101_FSTEST ,0x59); + writeRegister(CC1101_TEST2 ,0x81); + writeRegister(CC1101_TEST1 ,0x35); + writeRegister(CC1101_TEST0 ,0x0B); + writeRegister(CC1101_PKTCTRL1 ,0x04); //No address check, Append two bytes with status RSSI/LQI/CRC OK, + writeRegister(CC1101_PKTCTRL0 ,0x32); //Infinite packet length mode, CRC disabled for TX and RX, No data whitening, Asynchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins + writeRegister(CC1101_ADDR ,0x00); + writeRegister(CC1101_PKTLEN ,0xFF); + writeRegister(CC1101_TEST0 ,0x09); + writeRegister(CC1101_FSCAL2 ,0x00); + + writeCommand(CC1101_SCAL); + + //wait for calibration to finish + while ((readRegisterWithSyncProblem(CC1101_MARCSTATE, CC1101_STATUS_REGISTER)) != CC1101_MARCSTATE_IDLE) yield(); + + writeRegister(CC1101_MCSM0 ,0x18); //no auto calibrate + + writeCommand(CC1101_SIDLE); + writeCommand(CC1101_SIDLE); + + writeRegister(CC1101_MDMCFG2 ,0x00); //Enable digital DC blocking filter before demodulator, 2-FSK, Disable Manchester encoding/decoding, No preamble/sync + writeRegister(CC1101_IOCFG0 ,0x0D); //Serial Data Output. Used for asynchronous serial mode. + + writeCommand(CC1101_SRX); + + while ((readRegisterWithSyncProblem(CC1101_MARCSTATE, CC1101_STATUS_REGISTER)) != CC1101_MARCSTATE_RX) yield(); + + initReceiveMessage1(); +} + +void IthoCC1101::initReceiveMessage1() +{ + uint8_t marcState; + + writeCommand(CC1101_SIDLE); //idle + + //set datarate + writeRegister(CC1101_MDMCFG4 ,0x08); + writeRegister(CC1101_MDMCFG3 ,0x43); + writeRegister(CC1101_DEVIATN ,0x40); + + //set fifo mode with fixed packet length and sync bytes + writeRegister(CC1101_PKTLEN , 15); //15 bytes message (sync at beginning of message is removed by CC1101) + writeRegister(CC1101_PKTCTRL0 ,0x00); + writeRegister(CC1101_SYNC1 ,170); //message1 byte2 + writeRegister(CC1101_SYNC0 ,173); //message1 byte3 + writeRegister(CC1101_MDMCFG2 ,0x02); + writeRegister(CC1101_PKTCTRL1 ,0x00); + + writeCommand(CC1101_SRX); //switch to RX state + + // Check that the RX state has been entered + while (((marcState = readRegisterWithSyncProblem(CC1101_MARCSTATE, CC1101_STATUS_REGISTER)) & CC1101_BITS_MARCSTATE) != CC1101_MARCSTATE_RX) + { + if (marcState == CC1101_MARCSTATE_RXFIFO_OVERFLOW) // RX_OVERFLOW + writeCommand(CC1101_SFRX); //flush RX buffer + yield(); + } + + receiveState = ExpectMessageStart; +} + +void IthoCC1101::initReceiveMessage2(IthoCommand expectedCommand) +{ + uint8_t marcState; + + writeCommand(CC1101_SIDLE); //idle + + //set datarate + writeRegister(CC1101_MDMCFG4 ,0x5A); + writeRegister(CC1101_MDMCFG3 ,0x83); + writeRegister(CC1101_DEVIATN ,0x50); + + //set packet length based on expected message + switch (expectedCommand) + { + case IthoJoin: + writeRegister(CC1101_PKTLEN ,64); + receiveState = ExpectJoinCommand; + break; + + case IthoLeave: + writeRegister(CC1101_PKTLEN ,57); + receiveState = ExpectLeaveCommand; + break; + + default: + writeRegister(CC1101_PKTLEN ,42); //42 bytes message (sync at beginning of message is removed by CC1101) + receiveState = ExpectNormalCommand; + break; + } + + //set fifo mode with fixed packet length and sync bytes + writeRegister(CC1101_PKTCTRL0 ,0x00); + writeRegister(CC1101_SYNC1 ,170); //message2 byte6 + writeRegister(CC1101_SYNC0 ,171); //message2 byte7 + writeRegister(CC1101_MDMCFG2 ,0x02); + writeRegister(CC1101_PKTCTRL1 ,0x00); + + writeCommand(CC1101_SRX); //switch to RX state + + // Check that the RX state has been entered + while (((marcState = readRegisterWithSyncProblem(CC1101_MARCSTATE, CC1101_STATUS_REGISTER)) & CC1101_BITS_MARCSTATE) != CC1101_MARCSTATE_RX) + { + if (marcState == CC1101_MARCSTATE_RXFIFO_OVERFLOW) // RX_OVERFLOW + writeCommand(CC1101_SFRX); //flush RX buffer + yield(); + } +} + +bool IthoCC1101::checkForNewPacket() +{ + bool result = false; + uint8_t length; + + switch (receiveState) + { + case ExpectMessageStart: + length = receiveData(&inMessage1, 15); + + //check if message1 is received + if ((length > 0) && (isValidMessageStart())) + { + parseMessageStart(); + + //switch to message2 RF settings + initReceiveMessage2(inIthoPacket.command); + + lastMessage1Received = millis(); + } + + break; + + case ExpectNormalCommand: + length = receiveData(&inMessage2, 42); + + //check if message2 is received + if ((length > 0) && (isValidMessageCommand())) + { + parseMessageCommand(); + + //bug detection + //testCreateMessage(); + + //switch back to message1 RF settings + initReceiveMessage1(); + + //both messages are received + result = true; + } + else + { + //check if waiting timeout is reached (message2 is expected within 22ms after message1) + if (millis() - lastMessage1Received > 24) + { + //switch back to message1 RF settings + initReceiveMessage1(); + } + } + + break; + + case ExpectJoinCommand: + length = receiveData(&inMessage2, 64); + + //check if message2 is received + if ((length > 0) && (isValidMessageCommand()) && isValidMessageJoin()) + { + parseMessageCommand(); + parseMessageJoin(); + + //bug detection + //testCreateMessage(); + + //switch back to message1 RF settings + initReceiveMessage1(); + + //both messages are received + result = true; + } + else + { + //check if waiting timeout is reached (message2 is expected within 22ms after message1) + if (millis() - lastMessage1Received > 24) + { + //switch back to message1 RF settings + initReceiveMessage1(); + } + } + + break; + + case ExpectLeaveCommand: + length = receiveData(&inMessage2, 45); + + //check if message2 is received + if ((length > 0) && (isValidMessageCommand()) && isValidMessageLeave()) + { + parseMessageCommand(); + parseMessageLeave(); + + //bug detection + //testCreateMessage(); + + //switch back to message1 RF settings + initReceiveMessage1(); + + //both messages are received + result = true; + } + else + { + //check if waiting timeout is reached (message2 is expected within 22ms after message1) + if (millis() - lastMessage1Received > 24) + { + //switch back to message1 RF settings + initReceiveMessage1(); + } + } + + break; + + } + + return result; +} + +bool IthoCC1101::isValidMessageStart() +{ + if (inMessage1.data[12] != 170) + { + return false; + } + + return true; +} + +bool IthoCC1101::isValidMessageCommand() +{ + if (inMessage2.data[37] != 170) + { + return false; + } + + return true; +} + +bool IthoCC1101::isValidMessageJoin() +{ + /* + if (inMessage2.data[37] != 170) + { + return false; + } + */ + return true; +} + +bool IthoCC1101::isValidMessageLeave() +{ + /* + if (inMessage2.data[37] != 170) + { + return false; + } + */ + return true; +} + +void IthoCC1101::parseMessageStart() +{ + bool isFullCommand = true; + bool isMediumCommand = true; + bool isLowCommand = true; + bool isTimer1Command = true; + bool isTimer2Command = true; + bool isTimer3Command = true; + bool isJoinCommand = true; + bool isLeaveCommand = true; + + //copy device id from packet + // TODO: verify if this really is this the device id + inIthoPacket.deviceId[0] = inMessage1.data[2]; + inIthoPacket.deviceId[1] = inMessage1.data[3]; + inIthoPacket.deviceId[2] = inMessage1.data[4] & 0b11111110; //last bit is part of command + + //copy command data from packet + //message1 command starts at index 5, last bit! + uint8_t commandBytes[7]; + commandBytes[0] = inMessage1.data[5] & 0b00000001; + commandBytes[1] = inMessage1.data[6]; + commandBytes[2] = inMessage1.data[7]; + commandBytes[3] = inMessage1.data[8]; + commandBytes[4] = inMessage1.data[9]; + commandBytes[5] = inMessage1.data[10]; + commandBytes[6] = inMessage1.data[11]; + + //match received commandBytes with known command bytes + for (int i=0; i<7; i++) + { + if (commandBytes[i] != ithoMessage1FullCommandBytes[i]) isFullCommand = false; + if (commandBytes[i] != ithoMessage1MediumCommandBytes[i]) isMediumCommand = false; + if (commandBytes[i] != ithoMessage1LowCommandBytes[i]) isLowCommand = false; + if (commandBytes[i] != ithoMessage1Timer1CommandBytes[i]) isTimer1Command = false; + if (commandBytes[i] != ithoMessage1Timer2CommandBytes[i]) isTimer2Command = false; + if (commandBytes[i] != ithoMessage1Timer3CommandBytes[i]) isTimer3Command = false; + if (commandBytes[i] != ithoMessage1JoinCommandBytes[i]) isJoinCommand = false; + if (commandBytes[i] != ithoMessage1LeaveCommandBytes[i]) isLeaveCommand = false; + } + + //determine command + inIthoPacket.command = IthoUnknown; + if (isFullCommand) inIthoPacket.command = IthoFull; + if (isMediumCommand) inIthoPacket.command = IthoMedium; + if (isLowCommand) inIthoPacket.command = IthoLow; + if (isTimer1Command) inIthoPacket.command = IthoTimer1; + if (isTimer2Command) inIthoPacket.command = IthoTimer2; + if (isTimer3Command) inIthoPacket.command = IthoTimer3; + if (isJoinCommand) inIthoPacket.command = IthoJoin; + if (isLeaveCommand) inIthoPacket.command = IthoLeave; + + //previous command + inIthoPacket.previous = getMessage1PreviousCommand(inMessage1.data[14]); +} + +void IthoCC1101::parseMessageCommand() +{ + bool isFullCommand = true; + bool isMediumCommand = true; + bool isLowCommand = true; + bool isTimer1Command = true; + bool isTimer2Command = true; + bool isTimer3Command = true; + bool isJoinCommand = true; + bool isLeaveCommand = true; + + //device id + inIthoPacket.deviceId[0] = inMessage2.data[8]; + inIthoPacket.deviceId[1] = inMessage2.data[9]; + inIthoPacket.deviceId[2] = inMessage2.data[10]; + inIthoPacket.deviceId[3] = inMessage2.data[11]; + inIthoPacket.deviceId[4] = inMessage2.data[12]; + inIthoPacket.deviceId[5] = inMessage2.data[13]; + inIthoPacket.deviceId[6] = inMessage2.data[14]; + inIthoPacket.deviceId[7] = inMessage2.data[15]; + + //counter1 + uint8_t row0 = inMessage2.data[16]; + uint8_t row1 = inMessage2.data[17]; + uint8_t row2 = inMessage2.data[18] & 0b11110000; //4 bits are part of command + inIthoPacket.counter = calculateMessageCounter(row0, row1, row2); + + //copy command data from packet + uint8_t commandBytes[15]; + commandBytes[0] = inMessage2.data[18] & 0b00001111; //4 bits are part of counter1 + commandBytes[1] = inMessage2.data[19]; + commandBytes[2] = inMessage2.data[20]; + commandBytes[3] = inMessage2.data[21]; + commandBytes[4] = inMessage2.data[22]; + commandBytes[5] = inMessage2.data[23]; + commandBytes[6] = inMessage2.data[24]; + commandBytes[7] = inMessage2.data[25]; + commandBytes[8] = inMessage2.data[26]; + commandBytes[9] = inMessage2.data[27]; + commandBytes[10] = inMessage2.data[28]; + commandBytes[11] = inMessage2.data[29]; + commandBytes[12] = inMessage2.data[30]; + commandBytes[13] = inMessage2.data[31]; + commandBytes[14] = inMessage2.data[32]; + + //match received commandBytes with known command bytes + for (int i=0; i<15; i++) + { + if (commandBytes[i] != ithoMessage2FullCommandBytes[i]) isFullCommand = false; + if (commandBytes[i] != ithoMessage2MediumCommandBytes[i]) isMediumCommand = false; + if (commandBytes[i] != ithoMessage2LowCommandBytes[i]) isLowCommand = false; + if (commandBytes[i] != ithoMessage2Timer1CommandBytes[i]) isTimer1Command = false; + if (commandBytes[i] != ithoMessage2Timer2CommandBytes[i]) isTimer2Command = false; + if (commandBytes[i] != ithoMessage2Timer3CommandBytes[i]) isTimer3Command = false; + if (commandBytes[i] != ithoMessage2JoinCommandBytes[i]) isJoinCommand = false; + if (commandBytes[i] != ithoMessage2LeaveCommandBytes[i]) isLeaveCommand = false; + } + + //determine command + inIthoPacket.command = IthoUnknown; + if (isFullCommand) inIthoPacket.command = IthoFull; + if (isMediumCommand) inIthoPacket.command = IthoMedium; + if (isLowCommand) inIthoPacket.command = IthoLow; + if (isTimer1Command) inIthoPacket.command = IthoTimer1; + if (isTimer2Command) inIthoPacket.command = IthoTimer2; + if (isTimer3Command) inIthoPacket.command = IthoTimer3; + if (isJoinCommand) inIthoPacket.command = IthoJoin; + if (isLeaveCommand) inIthoPacket.command = IthoLeave; +} + +void IthoCC1101::parseMessageJoin() +{ + /* + for (int i=0;ilength = 19; + + //fixed + packet->data[0] = 170; + packet->data[1] = 170; + packet->data[2] = 170; + packet->data[3] = 173; + + //?? + packet->data[4] = 51; + packet->data[5] = 83; + packet->data[6] = 51; + packet->data[7] = 43; + packet->data[8] = 84; + packet->data[9] = 204; //last bit is part of command + + //command + uint8_t *commandBytes = getMessage1CommandBytes(itho->command); + packet->data[9] = packet->data[9] | commandBytes[0]; //only last bit is set + packet->data[10] = commandBytes[1]; + packet->data[11] = commandBytes[2]; + packet->data[12] = commandBytes[3]; + packet->data[13] = commandBytes[4]; + packet->data[14] = commandBytes[5]; + packet->data[15] = commandBytes[6]; + + //fixed + packet->data[16] = 170; + packet->data[17] = 171; + + //previous command + packet->data[18] = getMessage1Byte18(itho->previous); +} + +void IthoCC1101::createMessageCommand(IthoPacket *itho, CC1101Packet *packet) +{ + packet->length = 50; + + //fixed + packet->data[0] = 170; + packet->data[1] = 170; + packet->data[2] = 170; + packet->data[3] = 170; + packet->data[4] = 170; + packet->data[5] = 170; + packet->data[6] = 170; + packet->data[7] = 171; + packet->data[8] = 254; + packet->data[9] = 0; + packet->data[10] = 179; + packet->data[11] = 42; + packet->data[12] = 171; + packet->data[13] = 42; + packet->data[14] = 149; + packet->data[15] = 154; + + //device id + packet->data[16] = itho->deviceId[0]; + packet->data[17] = itho->deviceId[1]; + packet->data[18] = itho->deviceId[2]; + packet->data[19] = itho->deviceId[3]; + packet->data[20] = itho->deviceId[4]; + packet->data[21] = itho->deviceId[5]; + packet->data[22] = itho->deviceId[6]; + packet->data[23] = itho->deviceId[7]; + + //counter bytes + packet->data[24] = calculateMessage2Byte24(itho->counter); + packet->data[25] = calculateMessage2Byte25(itho->counter); + packet->data[26] = calculateMessage2Byte26(itho->counter); + + //command + uint8_t *commandBytes = getMessage2CommandBytes(itho->command); + packet->data[26] = packet->data[26] | commandBytes[0]; + packet->data[27] = commandBytes[1]; + packet->data[28] = commandBytes[2]; + packet->data[29] = commandBytes[3]; + packet->data[30] = commandBytes[4]; + packet->data[31] = commandBytes[5]; + packet->data[32] = commandBytes[6]; + packet->data[33] = commandBytes[7]; + packet->data[34] = commandBytes[8]; + packet->data[35] = commandBytes[9]; + packet->data[36] = commandBytes[10]; + packet->data[37] = commandBytes[11]; + packet->data[38] = commandBytes[12]; + packet->data[39] = commandBytes[13]; + packet->data[40] = commandBytes[14]; + + //counter bytes + packet->data[41] = calculateMessage2Byte41(itho->counter, itho->command); + packet->data[42] = calculateMessage2Byte42(itho->counter, itho->command); + packet->data[43] = calculateMessage2Byte43(itho->counter, itho->command); + + //fixed + packet->data[44] = 172; + packet->data[45] = 170; + packet->data[46] = 170; + packet->data[47] = 170; + packet->data[48] = 170; + packet->data[49] = 170; +} + +void IthoCC1101::createMessageJoin(IthoPacket *itho, CC1101Packet *packet) +{ + //message3 is an extension on message2 + createMessageCommand(itho, packet); + + packet->length = 72; + + //part of device id?? + packet->data[44] = itho->deviceId[3]; + packet->data[45] = itho->deviceId[4]; + packet->data[46] = itho->deviceId[5]; + packet->data[47] = itho->deviceId[6]; + packet->data[48] = itho->deviceId[7]; + + //command join + packet->data[49] = 85; + + //fixed + packet->data[50] = 165; + packet->data[51] = 105; + packet->data[52] = 89; + packet->data[53] = 86; + packet->data[54] = 106; + packet->data[55] = 149; + + //device id + packet->data[56] = itho->deviceId[0]; + packet->data[57] = itho->deviceId[1]; + packet->data[58] = itho->deviceId[2]; + packet->data[59] = itho->deviceId[3]; + packet->data[60] = itho->deviceId[4]; + packet->data[61] = itho->deviceId[5]; + packet->data[62] = itho->deviceId[6]; + packet->data[63] = itho->deviceId[7]; + + //counter bytes + packet->data[64] = calculateMessage2Byte64(itho->counter); + packet->data[65] = calculateMessage2Byte65(itho->counter); + packet->data[66] = calculateMessage2Byte66(itho->counter); + + //fixed + packet->data[67] = 202; + packet->data[68] = 170; + packet->data[69] = 170; + packet->data[70] = 170; + packet->data[71] = 170; +} + +void IthoCC1101::createMessageLeave(IthoPacket *itho, CC1101Packet *packet) +{ + //message3 is an extension on message2 + createMessageCommand(itho, packet); + + packet->length = 57; + + //part of device id?? + packet->data[44] = itho->deviceId[3]; + packet->data[45] = itho->deviceId[4]; + packet->data[46] = itho->deviceId[5]; + packet->data[47] = itho->deviceId[6]; + packet->data[48] = itho->deviceId[7]; + + //counter bytes + packet->data[49] = calculateMessage2Byte49(itho->counter); + packet->data[50] = calculateMessage2Byte50(itho->counter); + packet->data[51] = calculateMessage2Byte51(itho->counter); + + //fixed + packet->data[52] = 202; + packet->data[53] = 170; + packet->data[54] = 170; + packet->data[55] = 170; + packet->data[56] = 170; +} + +//calculate 0-255 number out of 3 counter bytes +uint8_t IthoCC1101::calculateMessageCounter(uint8_t byte24, uint8_t byte25, uint8_t byte26) +{ + uint8_t result; + + uint8_t a = getCounterIndex(&counterBytes24a[0],2,byte24 & 0b00000011); //last 2 bits only + uint8_t b = getCounterIndex(&counterBytes24b[0],8,byte24 & 0b11111100); //first 6 bits + uint8_t c = getCounterIndex(&counterBytes25[0],8,byte25); + uint8_t d = getCounterIndex(&counterBytes26[0],2,byte26); + + result = (a * 128) + (b * 16) + (d * 8) + c; + + return result; +} + +IthoCommand IthoCC1101::getMessage1PreviousCommand(uint8_t byte18) +{ + switch (byte18) + { + case 77: + return IthoJoin; + + case 82: + return IthoLeave; + + case 85: + return IthoLow; + } +} + +uint8_t IthoCC1101::getMessage1Byte18(IthoCommand command) +{ + switch (command) + { + case IthoJoin: + return 77; + + case IthoLeave: + return 82; + + default: + return 85; + } +} + +uint8_t IthoCC1101::calculateMessage2Byte24(uint8_t counter) +{ + //the following code skips the counterBytes arrays, this saves 10 bytes of memory but will increase program size with 30 bytes + //uint8_t index = (counter & 0x7F) >> 4; + //return ((counter >> 7) + 1) | (84 + (((index + 1) >> 1) << 6) - ((index >> 1) * 48) - (index >= 4 ? 28 : 0)); + + return counterBytes24a[(counter / 128)] | counterBytes24b[(counter % 128) / 16]; +} + +uint8_t IthoCC1101::calculateMessage2Byte25(uint8_t counter) +{ + return counterBytes25[(counter % 16) % 8]; +} + +uint8_t IthoCC1101::calculateMessage2Byte26(uint8_t counter) +{ + return counterBytes26[(counter % 16) / 8]; +} + +uint8_t IthoCC1101::calculateMessage2Byte41(uint8_t counter, IthoCommand command) +{ + int var = 0; + uint8_t hi = 0; + + switch (command) + { + case IthoTimer1: + case IthoTimer3: + hi = 160; + var = 48 - command; + if (counter < var) counter = 64 - counter; + break; + + case IthoJoin: + hi = 96; + counter = 0; + break; + + case IthoLeave: + hi = 160; + counter = 0; + break; + + case IthoLow: + case IthoMedium: + case IthoFull: + case IthoTimer2: + hi = 96; + var = 48 - command; + if (counter < var) counter = 74 - counter; + break; + } + + return (hi | counterBytes41[((counter - var) % 64) / 16]); +} + +uint8_t IthoCC1101::calculateMessage2Byte42(uint8_t counter, IthoCommand command) +{ + uint8_t result; + + if (command == IthoJoin || command == IthoLeave) + { + counter = 1; + } + else + { + counter += command; + } + + result = counterBytes42[counter / 64]; + + if (counter % 2 == 1) result -= 1; + + return result; +} + +uint8_t IthoCC1101::calculateMessage2Byte43(uint8_t counter, IthoCommand command) +{ + switch (command) + { + case IthoMedium: + break; + + case IthoLow: + case IthoTimer2: + if (counter % 2 == 0) counter -= 1; + break; + + case IthoFull: + counter += 2; + if (counter % 2 == 0) counter -= 1; + break; + + case IthoTimer1: + counter += 6; + if (counter % 2 == 0) counter -= 1; + break; + + case IthoTimer3: + counter += 10; + if (counter % 2 == 0) counter -= 1; + break; + + case IthoJoin: + case IthoLeave: + counter = 0; + break; + } + + return counterBytes43[(counter % 16) / 2]; +} + +uint8_t IthoCC1101::calculateMessage2Byte49(uint8_t counter) +{ + counter += 47; + return counterBytes64[(counter / 16)]; +} + +uint8_t IthoCC1101::calculateMessage2Byte50(uint8_t counter) +{ + counter -= 4; + return counterBytes65[counter % 8]; +} + +uint8_t IthoCC1101::calculateMessage2Byte51(uint8_t counter) +{ + counter -= 1; + return counterBytes66[(counter % 16) / 8]; +} + +uint8_t IthoCC1101::calculateMessage2Byte64(uint8_t counter) +{ + counter += 3; + return counterBytes64[counter / 16]; +} + +uint8_t IthoCC1101::calculateMessage2Byte65(uint8_t counter) +{ + return counterBytes65[counter % 8]; +} + +uint8_t IthoCC1101::calculateMessage2Byte66(uint8_t counter) +{ + counter -= 13; + return counterBytes66[(counter % 16) / 8]; +} + +uint8_t* IthoCC1101::getMessage1CommandBytes(IthoCommand command) +{ + switch (command) + { + case IthoFull: + return (uint8_t*)&ithoMessage1FullCommandBytes[0]; + case IthoMedium: + return (uint8_t*)&ithoMessage1MediumCommandBytes[0]; + case IthoLow: + return (uint8_t*)&ithoMessage1LowCommandBytes[0]; + case IthoTimer1: + return (uint8_t*)&ithoMessage1Timer1CommandBytes[0]; + case IthoTimer2: + return (uint8_t*)&ithoMessage1Timer2CommandBytes[0]; + case IthoTimer3: + return (uint8_t*)&ithoMessage1Timer3CommandBytes[0]; + case IthoJoin: + return (uint8_t*)&ithoMessage1JoinCommandBytes[0]; + case IthoLeave: + return (uint8_t*)&ithoMessage1LeaveCommandBytes[0]; + } +} + +uint8_t* IthoCC1101::getMessage2CommandBytes(IthoCommand command) +{ + switch (command) + { + case IthoFull: + return (uint8_t*)&ithoMessage2FullCommandBytes[0]; + case IthoMedium: + return (uint8_t*)&ithoMessage2MediumCommandBytes[0]; + case IthoLow: + return (uint8_t*)&ithoMessage2LowCommandBytes[0]; + case IthoTimer1: + return (uint8_t*)&ithoMessage2Timer1CommandBytes[0]; + case IthoTimer2: + return (uint8_t*)&ithoMessage2Timer2CommandBytes[0]; + case IthoTimer3: + return (uint8_t*)&ithoMessage2Timer3CommandBytes[0]; + case IthoJoin: + return (uint8_t*)&ithoMessage2JoinCommandBytes[0]; + case IthoLeave: + return (uint8_t*)&ithoMessage2LeaveCommandBytes[0]; + } +} + +//lookup value in array +uint8_t IthoCC1101::getCounterIndex(const uint8_t *arr, uint8_t length, uint8_t value) +{ + for (uint8_t i=0; i +#include "CC1101.h" +#include "IthoPacket.h" + + +//pa table settings +const uint8_t ithoPaTableSend[8] = {0x6F, 0x26, 0x2E, 0x8C, 0x87, 0xCD, 0xC7, 0xC0}; +const uint8_t ithoPaTableReceive[8] = {0x6F, 0x26, 0x2E, 0x7F, 0x8A, 0x84, 0xCA, 0xC4}; + +//message 1 commands +const uint8_t ithoMessage1FullCommandBytes[] = {1,84,213,85,50,203,52}; +const uint8_t ithoMessage1MediumCommandBytes[] = {1,84,213,85,74,213,52}; +const uint8_t ithoMessage1LowCommandBytes[] = {1,84,213,85,83,83,84}; +const uint8_t ithoMessage1Timer1CommandBytes[] = {1,83,83,84,204,202,180}; +const uint8_t ithoMessage1Timer2CommandBytes[] = {1,83,83,83,53,52,180}; +const uint8_t ithoMessage1Timer3CommandBytes[] = {1,83,83,82,173,82,180}; +const uint8_t ithoMessage1JoinCommandBytes[] = {0,170,171,85,84,202,180}; +const uint8_t ithoMessage1LeaveCommandBytes[] = {0,170,173,85,83,43,84}; + +//message 2 commands +const uint8_t ithoMessage2FullCommandBytes[] = {6,89,150,170,165,101,90,150,85,149,101,89,102,85,150}; +const uint8_t ithoMessage2MediumCommandBytes[] = {6,89,150,170,165,101,90,150,85,149,101,90,150,85,150}; +const uint8_t ithoMessage2LowCommandBytes[] = {6,89,150,170,165,101,90,150,85,149,101,89,150,85,150}; +const uint8_t ithoMessage2Timer1CommandBytes[] = {6,89,150,170,169,101,90,150,85,149,101,89,86,85,153}; +const uint8_t ithoMessage2Timer2CommandBytes[] = {6,89,150,170,169,101,90,150,85,149,101,89,86,149,150}; +const uint8_t ithoMessage2Timer3CommandBytes[] = {6,89,150,170,169,101,90,150,85,149,101,89,86,149,154}; +const uint8_t ithoMessage2JoinCommandBytes[] = {9,90,170,90,165,165,89,106,85,149,102,89,150,170,165}; +const uint8_t ithoMessage2LeaveCommandBytes[] = {9,90,170,90,165,165,89,166,85,149,105,90,170,90,165}; + +/* +TODO: last 3 bytes of join/leave are not the same for every remote! +*/ + +//message 2, counter +const uint8_t counterBytes24a[] = {1,2}; +const uint8_t counterBytes24b[] = {84,148,100,164,88,152,104,168}; +const uint8_t counterBytes25[] = {149,165,153,169,150,166,154,170}; +const uint8_t counterBytes26[] = {96,160}; +const uint8_t counterBytes41[] = {5, 10, 6, 9}; +const uint8_t counterBytes42[] = {90, 170, 106, 154}; +const uint8_t counterBytes43[] = {154, 90, 166, 102, 150, 86, 170, 106}; +//join/leave +const uint8_t counterBytes64[] = {154,90,166,102,150,86,169,105,153,89,165,101,149,85,170,106}; +const uint8_t counterBytes65[] = {150,169,153,165,149,170,154,166}; +const uint8_t counterBytes66[] = {170,106}; + + +//state machine +typedef enum IthoReceiveStates +{ + ExpectMessageStart, + ExpectNormalCommand, + ExpectJoinCommand, + ExpectLeaveCommand +}; + + + +class IthoCC1101 : protected CC1101 +{ + private: + //receive + IthoReceiveStates receiveState; //state machine receive + unsigned long lastMessage1Received; //used for timeout detection + CC1101Packet inMessage1; //temp storage message1 + CC1101Packet inMessage2; //temp storage message2 + IthoPacket inIthoPacket; //stores last received message data + + //send + IthoPacket outIthoPacket; //stores state of "remote" + + //settings + uint8_t sendTries; //number of times a command is send at one button press + + //functions + public: + IthoCC1101(uint8_t counter = 0, uint8_t sendTries = 3); //set initial counter value + ~IthoCC1101(); + + //init + void init() { CC1101::init(); } //init,reset CC1101 + void initReceive(); + uint8_t getLastCounter() { return outIthoPacket.counter; } //counter is increased before sending a command + void setSendTries(uint8_t sendTries) { this->sendTries = sendTries; } + + //- deviceid should be a setting as well? random gen function? TODO + + //receive + bool checkForNewPacket(); //check RX fifo for new data + IthoPacket getLastPacket() { return inIthoPacket; } //retrieve last received/parsed packet from remote + + //send + void sendCommand(IthoCommand command); + + protected: + private: + IthoCC1101( const IthoCC1101 &c ); + IthoCC1101& operator=( const IthoCC1101 &c ); + + //init CC1101 for receiving + void initReceiveMessage1(); + void initReceiveMessage2(IthoCommand expectedCommand); + + //init CC1101 for sending + void initSendMessage1(); + void initSendMessage2(IthoCommand command); + void finishTransfer(); + + //receive message validation + bool isValidMessageStart(); + bool isValidMessageCommand(); + bool isValidMessageJoin(); + bool isValidMessageLeave(); + + //parse received message + void parseReceivedPackets(); + void parseMessageStart(); + void parseMessageCommand(); + void parseMessageJoin(); + void parseMessageLeave(); + + //send + void createMessageStart(IthoPacket *itho, CC1101Packet *packet); + void createMessageCommand(IthoPacket *itho, CC1101Packet *packet); + void createMessageJoin(IthoPacket *itho, CC1101Packet *packet); + void createMessageLeave(IthoPacket *itho, CC1101Packet *packet); + uint8_t* getMessage1CommandBytes(IthoCommand command); + uint8_t* getMessage2CommandBytes(IthoCommand command); + + //counter bytes calculation (send) + uint8_t getMessage1Byte18(IthoCommand command); + IthoCommand getMessage1PreviousCommand(uint8_t byte18); + uint8_t calculateMessage2Byte24(uint8_t counter); + uint8_t calculateMessage2Byte25(uint8_t counter); + uint8_t calculateMessage2Byte26(uint8_t counter); + uint8_t calculateMessage2Byte41(uint8_t counter, IthoCommand command); + uint8_t calculateMessage2Byte42(uint8_t counter, IthoCommand command); + uint8_t calculateMessage2Byte43(uint8_t counter, IthoCommand command); + uint8_t calculateMessage2Byte49(uint8_t counter); + uint8_t calculateMessage2Byte50(uint8_t counter); + uint8_t calculateMessage2Byte51(uint8_t counter); + uint8_t calculateMessage2Byte64(uint8_t counter); + uint8_t calculateMessage2Byte65(uint8_t counter); + uint8_t calculateMessage2Byte66(uint8_t counter); + + //counter calculation (receive) + uint8_t calculateMessageCounter(uint8_t byte24, uint8_t byte25, uint8_t byte26); + + //general + uint8_t getCounterIndex(const uint8_t *arr, uint8_t length, uint8_t value); + + //test + void testCreateMessage(); + +}; //IthoCC1101 + + +extern volatile uint32_t data1[]; + +#endif //__ITHOCC1101_H__ diff --git a/Library/Itho/IthoPacket.h b/Library/Itho/IthoPacket.h new file mode 100644 index 0000000..ce0406b --- /dev/null +++ b/Library/Itho/IthoPacket.h @@ -0,0 +1,38 @@ +/* + * Author: Klusjesman, modified bij supersjimmie for Arduino/ESP8266 + */ + +#ifndef ITHOPACKET_H_ +#define ITHOPACKET_H_ + + +//do not change enum because they are used in calculations! +typedef enum IthoCommand +{ + IthoUnknown = 0, + + IthoJoin = 4, + IthoLeave = 8, + + IthoLow = 35, + IthoMedium = 36, + IthoFull = 37, + + IthoTimer1 = 41, + IthoTimer2 = 51, + IthoTimer3 = 61 +}; + + +class IthoPacket +{ + public: + uint8_t deviceId[8]; + IthoCommand command; + IthoCommand previous; + + uint8_t counter; //0-255, counter is increased on every remote button press +}; + + +#endif /* ITHOPACKET_H_ */ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d3762d2 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# IthoEcoFanRFT +Cloned from https://github.com/supersjimmie/IthoEcoFanRFT + +I used A CC1101 module, might work with others like CC1150. +``` +Connections between the CC1101 and the ESP8266 or Arduino: +CC11xx pins ESP pins Arduino pins Description +* 1 - VCC VCC VCC 3v3 +* 2 - GND GND GND Ground +* 3 - MOSI 13=D7 Pin 11 Data input to CC11xx +* 4 - SCK 14=D5 Pin 13 Clock pin +* 5 - MISO/GDO1 12=D6 Pin 12 Data output from CC11xx / serial clock from CC11xx +* 6 - GDO2 ? Pin ? Programmable output +* 7 - GDO0 ? Pin ? Programmable output +* 8 - CSN 15=D8 Pin 10 Chip select / (SPI_SS) +``` + + +Beware that the CC11xx modules are 3.3V (3.6V max) on all pins! +This won't be a problem with an ESP8266, but for Arduino you either need to use a 3.3V Arduino or use levelshifters and a separate 3.3V power source. + +For SPI, pins 12-15 ()aka D5-D8) are used, a larger ESP8266 model like (but not only) the ESP-03, ESP-07, ESP-12(D, E) or a NodeMCU board is required. + +Added a web interface and simple API to control it from something like https://pimatic.org/ + +![alt tag](https://github.com/incmve/Itho-WIFI-remote/blob/master/Images/cntrl panel.JPG) + +Also able to give commands by USB + +![alt tag](https://github.com/incmve/Itho-WIFI-remote/blob/master/Images/serial.JPG) + + +API work like this: +``` +http://192.168.x.x/api?action=Low +http://192.168.x.x/api?action=Medium +http://192.168.x.x/api?action=High +http://192.168.x.x/api?action=Timer +http://192.168.x.x/api?action=Learn +http://192.168.x.x/api?action=reset&value=true +``` + +Use at your own RISK!! \ No newline at end of file