[
  {
    "path": ".development",
    "content": ""
  },
  {
    "path": ".github/ISSUE_TEMPLATE/config.yml",
    "content": "blank_issues_enabled: false\ncontact_links:\n  - name: 💬 Questions, Help & Discussion\n    about: Ask anything, or get help\n    url: https://github.com/markqvist/Reticulum/discussions/new/choose\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/🐛-bug-report.md",
    "content": "---\nname: \"\\U0001F41B Bug Report\"\nabout: Report a reproducible bug. Do NOT use this for ideas, features or help requests.\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n**Read the Contribution Guidelines**\nBefore creating a bug report on this issue tracker, you **must** read the [Contribution Guidelines](https://github.com/markqvist/Reticulum/blob/master/Contributing.md). Issues that do not follow the contribution guidelines **will be deleted without comment**.\n\n- The issue tracker is used by developers of this project. **Do not use it to ask general questions, or for support requests**.\n- Ideas and feature requests can be made on the [Discussions](https://github.com/markqvist/Reticulum/discussions). **Only** feature requests accepted by maintainers and developers are tracked and included on the issue tracker. **Do not post feature requests here**.\n- After reading the [Contribution Guidelines](https://github.com/markqvist/Reticulum/blob/master/Contributing.md), delete this section from your bug report.\n\n**Describe the Bug**\nA clear and concise description of what the bug is.\n\n**To Reproduce**\nDescribe in detail how to reproduce the bug.\n\n**Expected Behavior**\nA clear and concise description of what you expected to happen.\n\n**Logs & Screenshots**\nPlease include any relevant log output. If applicable, also add screenshots to help explain your problem.\n\n**System Information**\n- OS and version\n- Python version\n- Program version\n\n**Additional context**\nAdd any other context about the problem here.\n"
  },
  {
    "path": "LICENSE",
    "content": "(This project uses BertOS for some functionality. BertOS is licensed under GPLv2. Please see http://www.bertos.org for details. All files in the \"bertos\" directory originates from BertOS.)\n\nGNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    {one line to give the program's name and a brief idea of what it does.}\n    Copyright (C) {year}  {name of author}\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    {project}  Copyright (C) {year}  {fullname}\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<http://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<http://www.gnu.org/philosophy/why-not-lgpl.html>.\n\n"
  },
  {
    "path": "README.md",
    "content": "LibAPRS\n==========\n\nLibAPRS is an Arduino IDE library that makes it easy to send and receive APRS packets with a [MicroModem](http://unsigned.io/micromodem)-compatible modem.\n\nYou can buy a complete modem from [my shop](http://unsigned.io/shop), or you can build one yourself pretty easily. Take a look at the documentation in the [MicroModem](https://github.com/markqvist/MicroModem) repository for information and getting started guides!\n\nSee the example included in the library for info on how to use it!\n\n## Some features\n\n- Send and receive AX.25 APRS packets\n- Full modulation and demodulation in software\n- Easy configuration of callsign and path settings\n- Easily process incoming packets\n- Shorthand functions for sending location updates and messages, so you don't need to manually create the packets\n- Ability to send raw packets\n- Support for settings APRS symbols\n- Support for power/height/gain info in location updates\n- Can run with open squelch\n\n## Installation\n\n1. Download the library: https://github.com/markqvist/LibAPRS/archive/master.zip\n1. (In the Arduino IDE) Sketch > Include Library > Add .ZIP Library... > select the downloaded file > Open\n\n## Getting started\n\nYou should read through the \"Basic_usage\" example included with the library. It contains an explanation of all the functions and a basic sketch to get you up and running with sending and receiving packets.\n\n## Got bugs?\n\nThis library is very early, and being actively developed all the time. This means you should expect to find bugs. If you do, please report them here, so I can fix them! It also means I might have to make changes that will break code, and that you will have to rewrite your sketch. If you don't think that sounds good, wait a little while for a stable release of the library :)"
  },
  {
    "path": "examples/Basic_usage/Basic_usage.ino",
    "content": "// Include LibAPRS\n#include <LibAPRS.h>\n\n// You must define what reference voltage the ADC\n// of your device is running at. If you bought a\n// MicroModem from unsigned.io, it will be running\n// at 3.3v if the \"hw rev\" is greater than 2.0.\n// This is the most common. If you build your own\n// modem, you should know this value yourself :)\n#define ADC_REFERENCE REF_3V3\n// OR\n//#define ADC_REFERENCE REF_5V\n\n// You can also define whether your modem will be\n// running with an open squelch radio:\n#define OPEN_SQUELCH false\n\n// You always need to include this function. It will\n// get called by the library every time a packet is\n// received, so you can process incoming packets.\n//\n// If you are only interested in transmitting, you\n// should just leave this function empty.\n// \n// IMPORTANT! This function is called from within an\n// interrupt. That means that you should only do things\n// here that are FAST. Don't print out info directly\n// from this function, instead set a flag and print it\n// from your main loop, like this:\n\nboolean gotPacket = false;\nAX25Msg incomingPacket;\nuint8_t *packetData;\nvoid aprs_msg_callback(struct AX25Msg *msg) {\n  // If we already have a packet waiting to be\n  // processed, we must drop the new one.\n  if (!gotPacket) {\n    // Set flag to indicate we got a packet\n    gotPacket = true;\n\n    // The memory referenced as *msg is volatile\n    // and we need to copy all the data to a\n    // local variable for later processing.\n    memcpy(&incomingPacket, msg, sizeof(AX25Msg));\n\n    // We need to allocate a new buffer for the\n    // data payload of the packet. First we check\n    // if there is enough free RAM.\n    if (freeMemory() > msg->len) {\n      packetData = (uint8_t*)malloc(msg->len);\n      memcpy(packetData, msg->info, msg->len);\n      incomingPacket.info = packetData;\n    } else {\n      // We did not have enough free RAM to receive\n      // this packet, so we drop it.\n      gotPacket = false;\n    }\n  }\n}\n\nvoid setup() {\n  // Set up serial port\n  Serial.begin(115200);\n  \n  // Initialise APRS library - This starts the modem\n  APRS_init(ADC_REFERENCE, OPEN_SQUELCH);\n  \n  // You must at a minimum configure your callsign and SSID\n  APRS_setCallsign(\"NOCALL\", 1);\n  \n  // You don't need to set the destination identifier, but\n  // if you want to, this is how you do it:\n  // APRS_setDestination(\"APZMDM\", 0);\n  \n  // Path parameters are set to sensible values by\n  // default, but this is how you can configure them:\n  // APRS_setPath1(\"WIDE1\", 1);\n  // APRS_setPath2(\"WIDE2\", 2);\n  \n  // You can define preamble and tail like this:\n  // APRS_setPreamble(350);\n  // APRS_setTail(50);\n  \n  // You can use the normal or alternate symbol table:\n  // APRS_useAlternateSymbolTable(false);\n  \n  // And set what symbol you want to use:\n  // APRS_setSymbol('n');\n  \n  // We can print out all the settings\n  APRS_printSettings();\n  Serial.print(F(\"Free RAM:     \")); Serial.println(freeMemory());\n}\n\nvoid locationUpdateExample() {\n  // Let's first set our latitude and longtitude.\n  // These should be in NMEA format!\n  APRS_setLat(\"5530.80N\");\n  APRS_setLon(\"01143.89E\");\n  \n  // We can optionally set power/height/gain/directivity\n  // information. These functions accept ranges\n  // from 0 to 10, directivity 0 to 9.\n  // See this site for a calculator:\n  // http://www.aprsfl.net/phgr.php\n  // LibAPRS will only add PHG info if all four variables\n  // are defined!\n  APRS_setPower(2);\n  APRS_setHeight(4);\n  APRS_setGain(7);\n  APRS_setDirectivity(0);\n  \n  // We'll define a comment string\n  char *comment = \"LibAPRS location update\";\n    \n  // And send the update\n  APRS_sendLoc(comment, strlen(comment));\n  \n}\n\nvoid messageExample() {\n  // We first need to set the message recipient\n  APRS_setMessageDestination(\"AA3BBB\", 0);\n  \n  // And define a string to send\n  char *message = \"Hi there! This is a message.\";\n  APRS_sendMsg(message, strlen(message));\n  \n}\n\n// Here's a function to process incoming packets\n// Remember to call this function often, so you\n// won't miss any packets due to one already\n// waiting to be processed\nvoid processPacket() {\n  if (gotPacket) {\n    gotPacket = false;\n    \n    Serial.print(F(\"Received APRS packet. SRC: \"));\n    Serial.print(incomingPacket.src.call);\n    Serial.print(F(\"-\"));\n    Serial.print(incomingPacket.src.ssid);\n    Serial.print(F(\". DST: \"));\n    Serial.print(incomingPacket.dst.call);\n    Serial.print(F(\"-\"));\n    Serial.print(incomingPacket.dst.ssid);\n    Serial.print(F(\". Data: \"));\n\n    for (int i = 0; i < incomingPacket.len; i++) {\n      Serial.write(incomingPacket.info[i]);\n    }\n    Serial.println(\"\");\n\n    // Remeber to free memory for our buffer!\n    free(packetData);\n\n    // You can print out the amount of free\n    // RAM to check you don't have any memory\n    // leaks\n    // Serial.print(F(\"Free RAM: \")); Serial.println(freeMemory());\n  }\n}\n\nboolean whichExample = false;\nvoid loop() {\n  \n  delay(1000);\n  if (whichExample) {\n    locationUpdateExample();\n  } else {\n    messageExample();\n  }\n  whichExample ^= true;\n\n  delay(500);\n  processPacket();\n}\n"
  },
  {
    "path": "library.properties",
    "content": "name=LibAPRS\nversion=1.0\nauthor=Mark Qvist\nmaintainer=Mark Qvist\nsentence=A library that turns the aruino into a Ax.25 Modem\nparagraph=\"LibAPRS is a library for the Arduino IDE, that makes it easy to write your own APRS applications for a MicroModem, or compatible build. It allows you to send and receive APRS packets, location updates and messages using simple functions in the Arduino IDE. All the AFSK modulation/demodulation, AX.25 handling, and such is running transparently in the “background” in interrupts, so you can focus on implementing exactly what you want!\"\ncategory=Communication\nurl=http://unsigned.io/projects/libaprs/\narchitectures=avr\nincludes=LibAPRS.h"
  },
  {
    "path": "src/AFSK.cpp",
    "content": "#include <string.h>\n#include \"AFSK.h\"\n#include \"Arduino.h\"\n\nextern unsigned long custom_preamble;\nextern unsigned long custom_tail;\nextern int LibAPRS_vref;\nextern bool LibAPRS_open_squelch;\n\nbool hw_afsk_dac_isr = false;\nbool hw_5v_ref = false;\nAfsk *AFSK_modem;\n\n\n// Forward declerations\nint afsk_getchar(void);\nvoid afsk_putchar(char c);\n\nvoid AFSK_hw_refDetect(void) {\n    // This is manual for now\n    if (LibAPRS_vref == REF_5V) {\n        hw_5v_ref = true;\n    } else {\n        hw_5v_ref = false;\n    }\n}\n\nvoid AFSK_hw_init(void) {\n    // Set up ADC\n\n    AFSK_hw_refDetect();\n\n    TCCR1A = 0;                                    \n    TCCR1B = _BV(CS10) | _BV(WGM13) | _BV(WGM12);\n    ICR1 = (((CPU_FREQ+FREQUENCY_CORRECTION)) / 9600) - 1;\n\n    if (hw_5v_ref) {\n        ADMUX = _BV(REFS0) | 0;\n    } else {\n        ADMUX = 0;\n    }\n\n    ADC_DDR  &= ~_BV(0);\n    ADC_PORT &= ~_BV(0);\n    DIDR0 |= _BV(0);\n    ADCSRB =    _BV(ADTS2) |\n                _BV(ADTS1) |\n                _BV(ADTS0);  \n    ADCSRA =    _BV(ADEN) |\n                _BV(ADSC) |\n                _BV(ADATE)|\n                _BV(ADIE) |\n                _BV(ADPS2);\n\n    AFSK_DAC_INIT();\n    LED_TX_INIT();\n    LED_RX_INIT();\n}\n\nvoid AFSK_init(Afsk *afsk) {\n    // Allocate modem struct memory\n    memset(afsk, 0, sizeof(*afsk));\n    AFSK_modem = afsk;\n    // Set phase increment\n    afsk->phaseInc = MARK_INC;\n    // Initialise FIFO buffers\n    fifo_init(&afsk->delayFifo, (uint8_t *)afsk->delayBuf, sizeof(afsk->delayBuf));\n    fifo_init(&afsk->rxFifo, afsk->rxBuf, sizeof(afsk->rxBuf));\n    fifo_init(&afsk->txFifo, afsk->txBuf, sizeof(afsk->txBuf));\n\n    // Fill delay FIFO with zeroes\n    for (int i = 0; i<SAMPLESPERBIT / 2; i++) {\n        fifo_push(&afsk->delayFifo, 0);\n    }\n\n    AFSK_hw_init();\n\n}\n\nstatic void AFSK_txStart(Afsk *afsk) {\n    if (!afsk->sending) {\n        afsk->phaseInc = MARK_INC;\n        afsk->phaseAcc = 0;\n        afsk->bitstuffCount = 0;\n        afsk->sending = true;\n        LED_TX_ON();\n        afsk->preambleLength = DIV_ROUND(custom_preamble * BITRATE, 8000);\n        AFSK_DAC_IRQ_START();\n    }\n    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {\n      afsk->tailLength = DIV_ROUND(custom_tail * BITRATE, 8000);\n    }\n}\n\nvoid afsk_putchar(char c) {\n    AFSK_txStart(AFSK_modem);\n    while(fifo_isfull_locked(&AFSK_modem->txFifo)) { /* Wait */ }\n    fifo_push_locked(&AFSK_modem->txFifo, c);\n}\n\nint afsk_getchar(void) {\n    if (fifo_isempty_locked(&AFSK_modem->rxFifo)) {\n        return EOF;\n    } else {\n        return fifo_pop_locked(&AFSK_modem->rxFifo);\n    }\n}\n\nvoid AFSK_transmit(char *buffer, size_t size) {\n    fifo_flush(&AFSK_modem->txFifo);\n    int i = 0;\n    while (size--) {\n        afsk_putchar(buffer[i++]);\n    }\n}\n\nuint8_t AFSK_dac_isr(Afsk *afsk) {\n    if (afsk->sampleIndex == 0) {\n        if (afsk->txBit == 0) {\n            if (fifo_isempty(&afsk->txFifo) && afsk->tailLength == 0) {\n                AFSK_DAC_IRQ_STOP();\n                afsk->sending = false;\n                LED_TX_OFF();\n                return 0;\n            } else {\n                if (!afsk->bitStuff) afsk->bitstuffCount = 0;\n                afsk->bitStuff = true;\n                if (afsk->preambleLength == 0) {\n                    if (fifo_isempty(&afsk->txFifo)) {\n                        afsk->tailLength--;\n                        afsk->currentOutputByte = HDLC_FLAG;\n                    } else {\n                        afsk->currentOutputByte = fifo_pop(&afsk->txFifo);\n                    }\n                } else {\n                    afsk->preambleLength--;\n                    afsk->currentOutputByte = HDLC_FLAG;\n                }\n                if (afsk->currentOutputByte == AX25_ESC) {\n                    if (fifo_isempty(&afsk->txFifo)) {\n                        AFSK_DAC_IRQ_STOP();\n                        afsk->sending = false;\n                        LED_TX_OFF();\n                        return 0;\n                    } else {\n                        afsk->currentOutputByte = fifo_pop(&afsk->txFifo);\n                    }\n                } else if (afsk->currentOutputByte == HDLC_FLAG || afsk->currentOutputByte == HDLC_RESET) {\n                    afsk->bitStuff = false;\n                }\n            }\n            afsk->txBit = 0x01;\n        }\n\n        if (afsk->bitStuff && afsk->bitstuffCount >= BIT_STUFF_LEN) {\n            afsk->bitstuffCount = 0;\n            afsk->phaseInc = SWITCH_TONE(afsk->phaseInc);\n        } else {\n            if (afsk->currentOutputByte & afsk->txBit) {\n                afsk->bitstuffCount++;\n            } else {\n                afsk->bitstuffCount = 0;\n                afsk->phaseInc = SWITCH_TONE(afsk->phaseInc);\n            }\n            afsk->txBit <<= 1;\n        }\n\n        afsk->sampleIndex = SAMPLESPERBIT;\n    }\n\n    afsk->phaseAcc += afsk->phaseInc;\n    afsk->phaseAcc %= SIN_LEN;\n    afsk->sampleIndex--;\n\n    return sinSample(afsk->phaseAcc);\n}\n\nstatic bool hdlcParse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) {\n    // Initialise a return value. We start with the\n    // assumption that all is going to end well :)\n    bool ret = true;\n\n    // Bitshift our byte of demodulated bits to\n    // the left by one bit, to make room for the\n    // next incoming bit\n    hdlc->demodulatedBits <<= 1;\n    // And then put the newest bit from the \n    // demodulator into the byte.\n    hdlc->demodulatedBits |= bit ? 1 : 0;\n\n    // Now we'll look at the last 8 received bits, and\n    // check if we have received a HDLC flag (01111110)\n    if (hdlc->demodulatedBits == HDLC_FLAG) {\n        // If we have, check that our output buffer is\n        // not full.\n        if (!fifo_isfull(fifo)) {\n            // If it isn't, we'll push the HDLC_FLAG into\n            // the buffer and indicate that we are now\n            // receiving data. For bling we also turn\n            // on the RX LED.\n            fifo_push(fifo, HDLC_FLAG);\n            hdlc->receiving = true;\n            if(!LibAPRS_open_squelch) {\n                LED_RX_ON();\n            }\n        } else {\n            // If the buffer is full, we have a problem\n            // and abort by setting the return value to     \n            // false and stopping the here.\n            \n            ret = false;\n            hdlc->receiving = false;\n            LED_RX_OFF();\n        }\n\n        // Everytime we receive a HDLC_FLAG, we reset the\n        // storage for our current incoming byte and bit\n        // position in that byte. This effectively\n        // synchronises our parsing to  the start and end\n        // of the received bytes.\n        hdlc->currentByte = 0;\n        hdlc->bitIndex = 0;\n        return ret;\n    }\n\n    // Check if we have received a RESET flag (01111111)\n    // In this comparison we also detect when no transmission\n    // (or silence) is taking place, and the demodulator\n    // returns an endless stream of zeroes. Due to the NRZ\n    // coding, the actual bits send to this function will\n    // be an endless stream of ones, which this AND operation\n    // will also detect.\n    if ((hdlc->demodulatedBits & HDLC_RESET) == HDLC_RESET) {\n        // If we have, something probably went wrong at the\n        // transmitting end, and we abort the reception.\n        hdlc->receiving = false;\n        LED_RX_OFF();\n        return ret;\n    }\n\n    // If we have not yet seen a HDLC_FLAG indicating that\n    // a transmission is actually taking place, don't bother\n    // with anything.\n    if (!hdlc->receiving)\n        return ret;\n\n    // First check if what we are seeing is a stuffed bit.\n    // Since the different HDLC control characters like\n    // HDLC_FLAG, HDLC_RESET and such could also occur in\n    // a normal data stream, we employ a method known as\n    // \"bit stuffing\". All control characters have more than\n    // 5 ones in a row, so if the transmitting party detects\n    // this sequence in the _data_ to be transmitted, it inserts\n    // a zero to avoid the receiving party interpreting it as\n    // a control character. Therefore, if we detect such a\n    // \"stuffed bit\", we simply ignore it and wait for the\n    // next bit to come in.\n    // \n    // We do the detection by applying an AND bit-mask to the\n    // stream of demodulated bits. This mask is 00111111 (0x3f)\n    // if the result of the operation is 00111110 (0x3e), we\n    // have detected a stuffed bit.\n    if ((hdlc->demodulatedBits & 0x3f) == 0x3e)\n        return ret;\n\n    // If we have an actual 1 bit, push this to the current byte\n    // If it's a zero, we don't need to do anything, since the\n    // bit is initialized to zero when we bitshifted earlier.\n    if (hdlc->demodulatedBits & 0x01)\n        hdlc->currentByte |= 0x80;\n\n    // Increment the bitIndex and check if we have a complete byte\n    if (++hdlc->bitIndex >= 8) {\n        // If we have a HDLC control character, put a AX.25 escape\n        // in the received data. We know we need to do this,\n        // because at this point we must have already seen a HDLC\n        // flag, meaning that this control character is the result\n        // of a bitstuffed byte that is equal to said control\n        // character, but is actually part of the data stream.\n        // By inserting the escape character, we tell the protocol\n        // layer that this is not an actual control character, but\n        // data.\n        if ((hdlc->currentByte == HDLC_FLAG ||\n             hdlc->currentByte == HDLC_RESET ||\n             hdlc->currentByte == AX25_ESC)) {\n            // We also need to check that our received data buffer\n            // is not full before putting more data in\n            if (!fifo_isfull(fifo)) {\n                fifo_push(fifo, AX25_ESC);\n            } else {\n                // If it is, abort and return false\n                hdlc->receiving = false;\n                LED_RX_OFF();\n                ret = false;\n            }\n        }\n\n        // Push the actual byte to the received data FIFO,\n        // if it isn't full.\n        if (!fifo_isfull(fifo)) {\n            fifo_push(fifo, hdlc->currentByte);\n        } else {\n            // If it is, well, you know by now!\n            hdlc->receiving = false;\n            LED_RX_OFF();\n            ret = false;\n        }\n\n        // Wipe received byte and reset bit index to 0\n        hdlc->currentByte = 0;\n        hdlc->bitIndex = 0;\n\n    } else {\n        // We don't have a full byte yet, bitshift the byte\n        // to make room for the next bit\n        hdlc->currentByte >>= 1;\n    }\n\n    //digitalWrite(13, LOW);\n    return ret;\n}\n\n\nvoid AFSK_adc_isr(Afsk *afsk, int8_t currentSample) {\n    // To determine the received frequency, and thereby\n    // the bit of the sample, we multiply the sample by\n    // a sample delayed by (samples per bit / 2).\n    // We then lowpass-filter the samples with a\n    // Chebyshev filter. The lowpass filtering serves\n    // to \"smooth out\" the variations in the samples.\n\n    afsk->iirX[0] = afsk->iirX[1];\n    afsk->iirX[1] = ((int8_t)fifo_pop(&afsk->delayFifo) * currentSample) >> 2;\n\n    afsk->iirY[0] = afsk->iirY[1];\n    \n    afsk->iirY[1] = afsk->iirX[0] + afsk->iirX[1] + (afsk->iirY[0] >> 1); // Chebyshev filter\n\n\n    // We put the sampled bit in a delay-line:\n    // First we bitshift everything 1 left\n    afsk->sampledBits <<= 1;\n    // And then add the sampled bit to our delay line\n    afsk->sampledBits |= (afsk->iirY[1] > 0) ? 1 : 0;\n\n    // Put the current raw sample in the delay FIFO\n    fifo_push(&afsk->delayFifo, currentSample);\n\n    // We need to check whether there is a signal transition.\n    // If there is, we can recalibrate the phase of our \n    // sampler to stay in sync with the transmitter. A bit of\n    // explanation is required to understand how this works.\n    // Since we have PHASE_MAX/PHASE_BITS = 8 samples per bit,\n    // we employ a phase counter (currentPhase), that increments\n    // by PHASE_BITS everytime a sample is captured. When this\n    // counter reaches PHASE_MAX, it wraps around by modulus\n    // PHASE_MAX. We then look at the last three samples we\n    // captured and determine if the bit was a one or a zero.\n    //\n    // This gives us a \"window\" looking into the stream of\n    // samples coming from the ADC. Sort of like this:\n    //\n    //   Past                                      Future\n    //       0000000011111111000000001111111100000000\n    //                   |________|\n    //                       ||     \n    //                     Window\n    //\n    // Every time we detect a signal transition, we adjust\n    // where this window is positioned little. How much we\n    // adjust it is defined by PHASE_INC. If our current phase\n    // phase counter value is less than half of PHASE_MAX (ie, \n    // the window size) when a signal transition is detected,\n    // add PHASE_INC to our phase counter, effectively moving\n    // the window a little bit backward (to the left in the\n    // illustration), inversely, if the phase counter is greater\n    // than half of PHASE_MAX, we move it forward a little.\n    // This way, our \"window\" is constantly seeking to position\n    // it's center at the bit transitions. Thus, we synchronise\n    // our timing to the transmitter, even if it's timing is\n    // a little off compared to our own.\n    if (SIGNAL_TRANSITIONED(afsk->sampledBits)) {\n        if (afsk->currentPhase < PHASE_THRESHOLD) {\n            afsk->currentPhase += PHASE_INC;\n        } else {\n            afsk->currentPhase -= PHASE_INC;\n        }\n    }\n\n    // We increment our phase counter\n    afsk->currentPhase += PHASE_BITS;\n\n    // Check if we have reached the end of\n    // our sampling window.\n    if (afsk->currentPhase >= PHASE_MAX) {\n        // If we have, wrap around our phase\n        // counter by modulus\n        afsk->currentPhase %= PHASE_MAX;\n\n        // Bitshift to make room for the next\n        // bit in our stream of demodulated bits\n        afsk->actualBits <<= 1;\n\n        // We determine the actual bit value by reading\n        // the last 3 sampled bits. If there is three or\n        // more 1's, we will assume that the transmitter\n        // sent us a one, otherwise we assume a zero\n        uint8_t bits = afsk->sampledBits & 0x07;\n        if (bits == 0x07 || // 111\n            bits == 0x06 || // 110\n            bits == 0x05 || // 101\n            bits == 0x03    // 011\n            ) {\n            afsk->actualBits |= 1;\n        }\n\n         //// Alternative using five bits ////////////////\n         // uint8_t bits = afsk->sampledBits & 0x0f;\n         // uint8_t c = 0;\n         // c += bits & BV(1);\n         // c += bits & BV(2);\n         // c += bits & BV(3);\n         // c += bits & BV(4);\n         // c += bits & BV(5);\n         // if (c >= 3) afsk->actualBits |= 1;\n        /////////////////////////////////////////////////\n\n        // Now we can pass the actual bit to the HDLC parser.\n        // We are using NRZ coding, so if 2 consecutive bits\n        // have the same value, we have a 1, otherwise a 0.\n        // We use the TRANSITION_FOUND function to determine this.\n        //\n        // This is smart in combination with bit stuffing,\n        // since it ensures a transmitter will never send more\n        // than five consecutive 1's. When sending consecutive\n        // ones, the signal stays at the same level, and if\n        // this happens for longer periods of time, we would\n        // not be able to synchronize our phase to the transmitter\n        // and would start experiencing \"bit slip\".\n        //\n        // By combining bit-stuffing with NRZ coding, we ensure\n        // that the signal will regularly make transitions\n        // that we can use to synchronize our phase.\n        //\n        // We also check the return of the Link Control parser\n        // to check if an error occured.\n\n        if (!hdlcParse(&afsk->hdlc, !TRANSITION_FOUND(afsk->actualBits), &afsk->rxFifo)) {\n            afsk->status |= 1;\n            if (fifo_isfull(&afsk->rxFifo)) {\n                fifo_flush(&afsk->rxFifo);\n                afsk->status = 0;\n            }\n        }\n    }\n\n}\n\nextern void APRS_poll();\nuint8_t poll_timer = 0;\nISR(ADC_vect) {\n    TIFR1 = _BV(ICF1);\n    AFSK_adc_isr(AFSK_modem, ((int16_t)((ADC) >> 2) - 128));\n    if (hw_afsk_dac_isr) {\n        DAC_PORT = (AFSK_dac_isr(AFSK_modem) & 0xF0) | _BV(3); \n    } else {\n        DAC_PORT = 128;\n    }\n\n    poll_timer++;\n    if (poll_timer > 3) {\n        poll_timer = 0;\n        APRS_poll();\n    }\n}\n"
  },
  {
    "path": "src/AFSK.h",
    "content": "#ifndef AFSK_H\n#define AFSK_H\n\n#include \"device.h\"\n#include <stdint.h>\n#include <stdbool.h>\n#include <stdio.h>\n#include <avr/pgmspace.h>\n#include \"FIFO.h\"\n#include \"HDLC.h\"\n\n#define SIN_LEN 512\nstatic const uint8_t sin_table[] PROGMEM =\n{\n    128, 129, 131, 132, 134, 135, 137, 138, 140, 142, 143, 145, 146, 148, 149, 151,\n    152, 154, 155, 157, 158, 160, 162, 163, 165, 166, 167, 169, 170, 172, 173, 175,\n    176, 178, 179, 181, 182, 183, 185, 186, 188, 189, 190, 192, 193, 194, 196, 197,\n    198, 200, 201, 202, 203, 205, 206, 207, 208, 210, 211, 212, 213, 214, 215, 217,\n    218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233,\n    234, 234, 235, 236, 237, 238, 238, 239, 240, 241, 241, 242, 243, 243, 244, 245,\n    245, 246, 246, 247, 248, 248, 249, 249, 250, 250, 250, 251, 251, 252, 252, 252,\n    253, 253, 253, 253, 254, 254, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255,\n};\n\ninline static uint8_t sinSample(uint16_t i) {\n    uint16_t newI = i % (SIN_LEN/2);\n    newI = (newI >= (SIN_LEN/4)) ? (SIN_LEN/2 - newI -1) : newI;\n    uint8_t sine = pgm_read_byte(&sin_table[newI]);\n    return (i >= (SIN_LEN/2)) ? (255 - sine) : sine;\n}\n\n\n#define SWITCH_TONE(inc)  (((inc) == MARK_INC) ? SPACE_INC : MARK_INC)\n#define BITS_DIFFER(bits1, bits2) (((bits1)^(bits2)) & 0x01)\n#define DUAL_XOR(bits1, bits2) ((((bits1)^(bits2)) & 0x03) == 0x03)\n#define SIGNAL_TRANSITIONED(bits) DUAL_XOR((bits), (bits) >> 2)\n#define TRANSITION_FOUND(bits) BITS_DIFFER((bits), (bits) >> 1)\n\n#define CPU_FREQ F_CPU\n\n#define CONFIG_AFSK_RX_BUFLEN 64\n#define CONFIG_AFSK_TX_BUFLEN 64   \n#define CONFIG_AFSK_RXTIMEOUT 0\n#define CONFIG_AFSK_PREAMBLE_LEN 150UL\n#define CONFIG_AFSK_TRAILER_LEN 50UL\n#define SAMPLERATE 9600\n#define BITRATE    1200\n#define SAMPLESPERBIT (SAMPLERATE / BITRATE)\n#define BIT_STUFF_LEN 5\n#define MARK_FREQ  1200\n#define SPACE_FREQ 2200\n#define PHASE_BITS   8                              // How much to increment phase counter each sample\n#define PHASE_INC    1                              // Nudge by an eigth of a sample each adjustment\n#define PHASE_MAX    (SAMPLESPERBIT * PHASE_BITS)   // Resolution of our phase counter = 64\n#define PHASE_THRESHOLD  (PHASE_MAX / 2)            // Target transition point of our phase window\n\n\ntypedef struct Hdlc\n{\n    uint8_t demodulatedBits;\n    uint8_t bitIndex;\n    uint8_t currentByte;\n    bool receiving;\n} Hdlc;\n\ntypedef struct Afsk\n{\n    // Stream access to modem\n    FILE fd;\n\n    // General values\n    Hdlc hdlc;                              // We need a link control structure\n    uint16_t preambleLength;                // Length of sync preamble\n    uint16_t tailLength;                    // Length of transmission tail\n\n    // Modulation values\n    uint8_t sampleIndex;                    // Current sample index for outgoing bit \n    uint8_t currentOutputByte;              // Current byte to be modulated\n    uint8_t txBit;                          // Mask of current modulated bit\n    bool bitStuff;                          // Whether bitstuffing is allowed\n\n    uint8_t bitstuffCount;                  // Counter for bit-stuffing\n\n    uint16_t phaseAcc;                      // Phase accumulator\n    uint16_t phaseInc;                      // Phase increment per sample\n\n    FIFOBuffer txFifo;                      // FIFO for transmit data\n    uint8_t txBuf[CONFIG_AFSK_TX_BUFLEN];   // Actial data storage for said FIFO\n\n    volatile bool sending;                  // Set when modem is sending\n\n    // Demodulation values\n    FIFOBuffer delayFifo;                   // Delayed FIFO for frequency discrimination\n    int8_t delayBuf[SAMPLESPERBIT / 2 + 1]; // Actual data storage for said FIFO\n\n    FIFOBuffer rxFifo;                      // FIFO for received data\n    uint8_t rxBuf[CONFIG_AFSK_RX_BUFLEN];   // Actual data storage for said FIFO\n\n    int16_t iirX[2];                        // IIR Filter X cells\n    int16_t iirY[2];                        // IIR Filter Y cells\n\n    uint8_t sampledBits;                    // Bits sampled by the demodulator (at ADC speed)\n    int8_t currentPhase;                    // Current phase of the demodulator\n    uint8_t actualBits;                     // Actual found bits at correct bitrate\n\n    volatile int status;                    // Status of the modem, 0 means OK\n\n} Afsk;\n\n#define DIV_ROUND(dividend, divisor)  (((dividend) + (divisor) / 2) / (divisor))\n#define MARK_INC   (uint16_t)(DIV_ROUND(SIN_LEN * (uint32_t)MARK_FREQ, CONFIG_AFSK_DAC_SAMPLERATE))\n#define SPACE_INC  (uint16_t)(DIV_ROUND(SIN_LEN * (uint32_t)SPACE_FREQ, CONFIG_AFSK_DAC_SAMPLERATE))\n\n#define AFSK_DAC_IRQ_START()   do { extern bool hw_afsk_dac_isr; hw_afsk_dac_isr = true; } while (0)\n#define AFSK_DAC_IRQ_STOP()    do { extern bool hw_afsk_dac_isr; hw_afsk_dac_isr = false; } while (0)\n#define AFSK_DAC_INIT()        do { DAC_DDR |= 0xF8; } while (0)\n\n// Here's some macros for controlling the RX/TX LEDs\n// THE _INIT() functions writes to the DDRB register\n// to configure the pins as output pins, and the _ON()\n// and _OFF() functions writes to the PORT registers\n// to turn the pins on or off.\n#define LED_TX_INIT() do { LED_DDR |= _BV(1); } while (0)\n#define LED_TX_ON()   do { LED_PORT |= _BV(1); } while (0)\n#define LED_TX_OFF()  do { LED_PORT &= ~_BV(1); } while (0)\n\n#define LED_RX_INIT() do { LED_DDR |= _BV(2); } while (0)\n#define LED_RX_ON()   do { LED_PORT |= _BV(2); } while (0)\n#define LED_RX_OFF()  do { LED_PORT &= ~_BV(2); } while (0)\n\nvoid AFSK_init(Afsk *afsk);\nvoid AFSK_transmit(char *buffer, size_t size);\nvoid AFSK_poll(Afsk *afsk);\n\nvoid afsk_putchar(char c);\nint afsk_getchar(void);\n\n#endif\n"
  },
  {
    "path": "src/AX25.cpp",
    "content": "// Based on work by Francesco Sacchi\n\n#include \"Arduino.h\"\n#include <string.h>\n#include <ctype.h>\n#include \"AX25.h\"\n#include \"HDLC.h\"\n#include \"CRC-CCIT.h\"\n#include \"AFSK.h\"\n\n#define countof(a) sizeof(a)/sizeof(a[0])\n#define MIN(a,b) ({ typeof(a) _a = (a); typeof(b) _b = (b); ((typeof(_a))((_a < _b) ? _a : _b)); })\n#define DECODE_CALL(buf, addr) for (unsigned i = 0; i < sizeof((addr))-CALL_OVERSPACE; i++) { char c = (*(buf)++ >> 1); (addr)[i] = (c == ' ') ? '\\x0' : c; }\n#define AX25_SET_REPEATED(msg, idx, val) do { if (val) { (msg)->rpt_flags |= _BV(idx); } else { (msg)->rpt_flags &= ~_BV(idx) ; } } while(0)\n\nextern int LibAPRS_vref;\nextern bool LibAPRS_open_squelch;\n\nvoid ax25_init(AX25Ctx *ctx, ax25_callback_t hook) {\n    memset(ctx, 0, sizeof(*ctx));\n    ctx->hook = hook;\n    ctx->crc_in = ctx->crc_out = CRC_CCIT_INIT_VAL;\n}\n\nstatic void ax25_decode(AX25Ctx *ctx) {\n    AX25Msg msg;\n    uint8_t *buf = ctx->buf;\n\n    DECODE_CALL(buf, msg.dst.call);\n    msg.dst.ssid = (*buf++ >> 1) & 0x0F;\n    msg.dst.call[6] = 0;\n\n    DECODE_CALL(buf, msg.src.call);\n    msg.src.ssid = (*buf >> 1) & 0x0F;\n    msg.src.call[6] = 0;\n\n    for (msg.rpt_count = 0; !(*buf++ & 0x01) && (msg.rpt_count < countof(msg.rpt_list)); msg.rpt_count++) {\n        DECODE_CALL(buf, msg.rpt_list[msg.rpt_count].call);\n        //db1sb: terminate rpt_list.call-entries\n        msg.rpt_list[msg.rpt_count].call[6] = 0; \n        msg.rpt_list[msg.rpt_count].ssid = (*buf >> 1) & 0x0F;\n        AX25_SET_REPEATED(&msg, msg.rpt_count, (*buf & 0x80));\n    }\n\n    msg.ctrl = *buf++;\n    if (msg.ctrl != AX25_CTRL_UI) { return; }\n\n    msg.pid = *buf++;\n    if (msg.pid != AX25_PID_NOLAYER3) { return; }\n\n    msg.len = ctx->frame_len - 2 - (buf - ctx->buf);\n    msg.info = buf;\n\n    if (ctx->hook) {\n        cli();\n        ctx->hook(&msg);\n        sei();\n    }   \n\n}\n\nvoid ax25_poll(AX25Ctx *ctx) {\n    int c;\n\n    while ((c = afsk_getchar()) != EOF) {\n        if (!ctx->escape && c == HDLC_FLAG) {\n            if (ctx->frame_len >= AX25_MIN_FRAME_LEN) {\n                if (ctx->crc_in == AX25_CRC_CORRECT) {\n                    if(LibAPRS_open_squelch) {\n                        LED_RX_ON();\n                    }\n                    ax25_decode(ctx);\n                }\n            }\n            ctx->sync = true;\n            ctx->crc_in = CRC_CCIT_INIT_VAL;\n            ctx->frame_len = 0;\n            continue;\n        }\n\n        if (!ctx->escape && c == HDLC_RESET) {\n            ctx->sync = false;\n            continue;\n        }\n\n        if (!ctx->escape && c == AX25_ESC) {\n            ctx->escape = true;\n            continue;\n        }\n\n        if (ctx->sync) {\n            if (ctx->frame_len < AX25_MAX_FRAME_LEN) {\n                ctx->buf[ctx->frame_len++] = c;\n                ctx->crc_in = update_crc_ccit(c, ctx->crc_in);\n            } else {\n                ctx->sync = false;\n            }\n        }\n        ctx->escape = false;\n    }\n}\n\nstatic void ax25_putchar(AX25Ctx *ctx, uint8_t c)\n{\n    if (c == HDLC_FLAG || c == HDLC_RESET || c == AX25_ESC) afsk_putchar(AX25_ESC);\n    ctx->crc_out = update_crc_ccit(c, ctx->crc_out);\n    afsk_putchar(c);\n}\n\nvoid ax25_sendRaw(AX25Ctx *ctx, void *_buf, size_t len) {\n    ctx->crc_out = CRC_CCIT_INIT_VAL;\n    afsk_putchar(HDLC_FLAG);\n    const uint8_t *buf = (const uint8_t *)_buf;\n    while (len--) ax25_putchar(ctx, *buf++);\n\n    uint8_t crcl = (ctx->crc_out & 0xff) ^ 0xff;\n    uint8_t crch = (ctx->crc_out >> 8) ^ 0xff;\n    ax25_putchar(ctx, crcl);\n    ax25_putchar(ctx, crch);\n\n    afsk_putchar(HDLC_FLAG);\n}\n\nstatic void ax25_sendCall(AX25Ctx *ctx, const AX25Call *addr, bool last){\n    unsigned len = MIN((sizeof(addr->call) - CALL_OVERSPACE), strlen(addr->call));\n\n    for (unsigned i = 0; i < len; i++) {\n        uint8_t c = addr->call[i];\n        c = toupper(c);\n        ax25_putchar(ctx, c << 1);\n    }\n\n    if (len < (sizeof(addr->call) - CALL_OVERSPACE)) {\n        for (unsigned i = 0; i < (sizeof(addr->call) - CALL_OVERSPACE) - len; i++) {\n            ax25_putchar(ctx, ' ' << 1);\n        }\n    }\n\n    uint8_t ssid = 0x60 | (addr->ssid << 1) | (last ? 0x01 : 0);\n    ax25_putchar(ctx, ssid);\n}\n\nvoid ax25_sendVia(AX25Ctx *ctx, const AX25Call *path, size_t path_len, const void *_buf, size_t len) {\n    const uint8_t *buf = (const uint8_t *)_buf;\n\n    ctx->crc_out = CRC_CCIT_INIT_VAL;\n    afsk_putchar(HDLC_FLAG);\n\n    for (size_t i = 0; i < path_len; i++) {\n        ax25_sendCall(ctx, &path[i], (i == path_len - 1));\n    }\n\n    ax25_putchar(ctx, AX25_CTRL_UI);\n    ax25_putchar(ctx, AX25_PID_NOLAYER3);\n\n    while (len--) {\n        ax25_putchar(ctx, *buf++);\n    }\n\n    uint8_t crcl = (ctx->crc_out & 0xff) ^ 0xff;\n    uint8_t crch = (ctx->crc_out >> 8) ^ 0xff;\n    ax25_putchar(ctx, crcl);\n    ax25_putchar(ctx, crch);\n\n    afsk_putchar(HDLC_FLAG);\n}\n"
  },
  {
    "path": "src/AX25.h",
    "content": "#ifndef PROTOCOL_AX25_H\n#define PROTOCOL_AX25_H\n\n#include <stdio.h>\n#include <stdbool.h>\n#include \"device.h\"\n\n#define AX25_MIN_FRAME_LEN 18\n#ifndef CUSTOM_FRAME_SIZE\n    #define AX25_MAX_FRAME_LEN 330\n#else\n    #define AX25_MAX_FRAME_LEN CUSTOM_FRAME_SIZE\n#endif\n\n#define AX25_CRC_CORRECT  0xF0B8\n\n#define AX25_CTRL_UI      0x03\n#define AX25_PID_NOLAYER3 0xF0\n\nstruct AX25Ctx;     // Forward declarations\nstruct AX25Msg;\n\ntypedef void (*ax25_callback_t)(struct AX25Msg *msg);\n\ntypedef struct AX25Ctx {\n    uint8_t buf[AX25_MAX_FRAME_LEN];\n    FILE *ch;\n    size_t frame_len;\n    uint16_t crc_in;\n    uint16_t crc_out;\n    ax25_callback_t hook;\n    bool sync;\n    bool escape;\n} AX25Ctx;\n\n\n#define AX25_CALL(str, id) {.call = (str), .ssid = (id) }\n#define AX25_MAX_RPT 8\n#define AX25_REPEATED(msg, n) ((msg)->rpt_flags & BV(n))\n\n#define CALL_OVERSPACE 1\n\ntypedef struct AX25Call {\n    char call[6+CALL_OVERSPACE];\n    //char STRING_TERMINATION = 0;\n    uint8_t ssid;\n} AX25Call;\n\ntypedef struct AX25Msg {\n    AX25Call src;\n    AX25Call dst;\n    AX25Call rpt_list[AX25_MAX_RPT];\n    uint8_t  rpt_count;\n    uint8_t  rpt_flags;\n    uint16_t ctrl;\n    uint8_t  pid;\n    const uint8_t *info;\n    size_t len;\n} AX25Msg;\n\nvoid ax25_sendVia(AX25Ctx *ctx, const AX25Call *path, size_t path_len, const void *_buf, size_t len);\n#define ax25_send(ctx, dst, src, buf, len) ax25_sendVia(ctx, ({static AX25Call __path[]={dst, src}; __path;}), 2, buf, len)\n\n\n\nvoid ax25_poll(AX25Ctx *ctx);\nvoid ax25_sendRaw(AX25Ctx *ctx, void *_buf, size_t len);\nvoid ax25_init(AX25Ctx *ctx, ax25_callback_t hook);\n\n#endif\n"
  },
  {
    "path": "src/CRC-CCIT.c",
    "content": "#include \"CRC-CCIT.h\"\n\nconst uint16_t crc_ccit_table[256] PROGMEM = {\n    0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,\n    0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,\n    0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,\n    0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,\n    0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,\n    0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,\n    0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,\n    0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,\n    0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,\n    0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,\n    0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,\n    0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,\n    0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,\n    0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,\n    0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,\n    0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,\n    0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,\n    0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,\n    0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,\n    0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,\n    0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,\n    0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,\n    0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,\n    0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,\n    0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,\n    0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,\n    0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,\n    0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,\n    0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,\n    0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,\n    0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,\n    0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78,\n};\n"
  },
  {
    "path": "src/CRC-CCIT.h",
    "content": "// CRC-CCIT Implementation based on work by Francesco Sacchi\n\n#ifndef CRC_CCIT_H\n#define CRC_CCIT_H\n\n#include <stdint.h>\n#include <avr/pgmspace.h>\n\n#define CRC_CCIT_INIT_VAL ((uint16_t)0xFFFF)\n\nextern const uint16_t crc_ccit_table[256];\n\ninline uint16_t update_crc_ccit(uint8_t c, uint16_t prev_crc) {\n    return (prev_crc >> 8) ^ pgm_read_word(&crc_ccit_table[(prev_crc ^ c) & 0xff]);\n}\n\n\n#endif\n"
  },
  {
    "path": "src/FIFO.h",
    "content": "#ifndef UTIL_FIFO_H\n#define UTIL_FIFO_H\n\n#include <stddef.h>\n#include <util/atomic.h>\n\ntypedef struct FIFOBuffer\n{\n  unsigned char *begin;\n  unsigned char *end;\n  unsigned char * volatile head;\n  unsigned char * volatile tail;\n} FIFOBuffer;\n\ninline bool fifo_isempty(const FIFOBuffer *f) {\n  return f->head == f->tail;\n}\n\ninline bool fifo_isfull(const FIFOBuffer *f) {\n  return ((f->head == f->begin) && (f->tail == f->end)) || (f->tail == f->head - 1);\n}\n\ninline void fifo_push(FIFOBuffer *f, unsigned char c) {\n  *(f->tail) = c;\n  \n  if (f->tail == f->end) {\n    f->tail = f->begin;\n  } else {\n    f->tail++;\n  }\n}\n\ninline unsigned char fifo_pop(FIFOBuffer *f) {\n  if(f->head == f->end) {\n    f->head = f->begin;\n    return *(f->end);\n  } else {\n    return *(f->head++);\n  }\n}\n\ninline void fifo_flush(FIFOBuffer *f) {\n  f->head = f->tail;\n}\n\ninline bool fifo_isempty_locked(const FIFOBuffer *f) {\n  bool result;\n  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {\n    result = fifo_isempty(f);\n  }\n  return result;\n}\n\ninline bool fifo_isfull_locked(const FIFOBuffer *f) {\n  bool result;\n  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {\n    result = fifo_isfull(f);\n  }\n  return result;\n}\n\ninline void fifo_push_locked(FIFOBuffer *f, unsigned char c) {\n  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {\n    fifo_push(f, c);\n  }\n}\n\ninline unsigned char fifo_pop_locked(FIFOBuffer *f) {\n  unsigned char c;\n  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {\n    c = fifo_pop(f);\n  }\n  return c;\n}\n\ninline void fifo_init(FIFOBuffer *f, unsigned char *buffer, size_t size) {\n  f->head = f->tail = f->begin = buffer;\n  f->end = buffer + size -1;\n}\n\ninline size_t fifo_len(FIFOBuffer *f) {\n  return f->end - f->begin;\n}\n\n#endif\n"
  },
  {
    "path": "src/HDLC.h",
    "content": "#ifndef PROTOCOL_HDLC_H\n#define PROTOCOL_HDLC_H\n\n#define HDLC_FLAG  0x7E\n#define HDLC_RESET 0x7F\n#define AX25_ESC   0x1B\n\n#endif\n"
  },
  {
    "path": "src/LibAPRS.cpp",
    "content": "#include \"Arduino.h\"\n#include \"AFSK.h\"\n#include \"AX25.h\"\n\nAfsk modem;\nAX25Ctx AX25;\nextern void aprs_msg_callback(struct AX25Msg *msg);\n#define countof(a) sizeof(a)/sizeof(a[0])\n\nint LibAPRS_vref = REF_3V3;\nbool LibAPRS_open_squelch = false;\n\nunsigned long custom_preamble = 350UL;\nunsigned long custom_tail = 50UL;\n\nAX25Call src;\nAX25Call dst;\nAX25Call path1;\nAX25Call path2;\n\nchar CALL[7] = \"NOCALL\";\nint CALL_SSID = 0;\nchar DST[7] = \"APZMDM\";\nint DST_SSID = 0;\nchar PATH1[7] = \"WIDE1\";\nint PATH1_SSID = 1;\nchar PATH2[7] = \"WIDE2\";\nint PATH2_SSID = 2;\n\nAX25Call path[4];\n\n// Location packet assembly fields\nchar latitude[9];\nchar longtitude[10];\nchar symbolTable = '/';\nchar symbol = 'n';\n\nuint8_t power = 10;\nuint8_t height = 10;\nuint8_t gain = 10;\nuint8_t directivity = 10;\n/////////////////////////\n\n// Message packet assembly fields\nchar message_recip[7];\nint message_recip_ssid = -1;\n\nint message_seq = 0;\nchar lastMessage[67];\nsize_t lastMessageLen;\nbool message_autoAck = false;\n/////////////////////////\n\nvoid APRS_init(int reference, bool open_squelch) {\n    LibAPRS_vref = reference;\n    LibAPRS_open_squelch = open_squelch;\n\n    AFSK_init(&modem);\n    ax25_init(&AX25, aprs_msg_callback);\n}\n\nvoid APRS_poll(void) {\n    ax25_poll(&AX25);\n}\n\nvoid APRS_setCallsign(char *call, int ssid) {\n    memset(CALL, 0, 7);\n    int i = 0;\n    while (i < 6 && call[i] != 0) {\n        CALL[i] = call[i];\n        i++;\n    }\n    CALL_SSID = ssid;\n}\n\nvoid APRS_setDestination(char *call, int ssid) {\n    memset(DST, 0, 7);\n    int i = 0;\n    while (i < 6 && call[i] != 0) {\n        DST[i] = call[i];\n        i++;\n    }\n    DST_SSID = ssid;\n}\n\nvoid APRS_setPath1(char *call, int ssid) {\n    memset(PATH1, 0, 7);\n    int i = 0;\n    while (i < 6 && call[i] != 0) {\n        PATH1[i] = call[i];\n        i++;\n    }\n    PATH1_SSID = ssid;\n}\n\nvoid APRS_setPath2(char *call, int ssid) {\n    memset(PATH2, 0, 7);\n    int i = 0;\n    while (i < 6 && call[i] != 0) {\n        PATH2[i] = call[i];\n        i++;\n    }\n    PATH2_SSID = ssid;\n}\n\nvoid APRS_setMessageDestination(char *call, int ssid) {\n    memset(message_recip, 0, 7);\n    int i = 0;\n    while (i < 6 && call[i] != 0) {\n        message_recip[i] = call[i];\n        i++;\n    }\n    message_recip_ssid = ssid;\n}\n\nvoid APRS_setPreamble(unsigned long pre) {\n    custom_preamble = pre;\n}\n\nvoid APRS_setTail(unsigned long tail) {\n    custom_tail = tail;\n}\n\nvoid APRS_useAlternateSymbolTable(bool use) {\n    if (use) {\n        symbolTable = '\\\\';\n    } else {\n        symbolTable = '/';\n    }\n}\n\nvoid APRS_setSymbol(char sym) {\n    symbol = sym;\n}\n\nvoid APRS_setLat(char *lat) {\n    memset(latitude, 0, 9);\n    int i = 0;\n    while (i < 8 && lat[i] != 0) {\n        latitude[i] = lat[i];\n        i++;\n    }\n}\n\nvoid APRS_setLon(char *lon) {\n    memset(longtitude, 0, 10);\n    int i = 0;\n    while (i < 9 && lon[i] != 0) {\n        longtitude[i] = lon[i];\n        i++;\n    }\n}\n\nvoid APRS_setPower(int s) {\n    if (s >= 0 && s < 10) {\n        power = s;\n    }\n}\n\nvoid APRS_setHeight(int s) {\n    if (s >= 0 && s < 10) {\n        height = s;\n    }\n}\n\nvoid APRS_setGain(int s) {\n    if (s >= 0 && s < 10) {\n        gain = s;\n    }\n}\n\nvoid APRS_setDirectivity(int s) {\n    if (s >= 0 && s < 10) {\n        directivity = s;\n    }\n}\n\nvoid APRS_printSettings() {\n    Serial.println(F(\"LibAPRS Settings:\"));\n    Serial.print(F(\"Callsign:     \")); Serial.print(CALL); Serial.print(F(\"-\")); Serial.println(CALL_SSID);\n    Serial.print(F(\"Destination:  \")); Serial.print(DST); Serial.print(F(\"-\")); Serial.println(DST_SSID);\n    Serial.print(F(\"Path1:        \")); Serial.print(PATH1); Serial.print(F(\"-\")); Serial.println(PATH1_SSID);\n    Serial.print(F(\"Path2:        \")); Serial.print(PATH2); Serial.print(F(\"-\")); Serial.println(PATH2_SSID);\n    Serial.print(F(\"Message dst:  \")); if (message_recip[0] == 0) { Serial.println(F(\"N/A\")); } else { Serial.print(message_recip); Serial.print(F(\"-\")); Serial.println(message_recip_ssid); }\n    Serial.print(F(\"TX Preamble:  \")); Serial.println(custom_preamble);\n    Serial.print(F(\"TX Tail:      \")); Serial.println(custom_tail);\n    Serial.print(F(\"Symbol table: \")); if (symbolTable == '/') { Serial.println(F(\"Normal\")); } else { Serial.println(F(\"Alternate\")); }\n    Serial.print(F(\"Symbol:       \")); Serial.println(symbol);\n    Serial.print(F(\"Power:        \")); if (power < 10) { Serial.println(power); } else { Serial.println(F(\"N/A\")); }\n    Serial.print(F(\"Height:       \")); if (height < 10) { Serial.println(height); } else { Serial.println(F(\"N/A\")); }\n    Serial.print(F(\"Gain:         \")); if (gain < 10) { Serial.println(gain); } else { Serial.println(F(\"N/A\")); }\n    Serial.print(F(\"Directivity:  \")); if (directivity < 10) { Serial.println(directivity); } else { Serial.println(F(\"N/A\")); }\n    Serial.print(F(\"Latitude:     \")); if (latitude[0] != 0) { Serial.println(latitude); } else { Serial.println(F(\"N/A\")); }\n    Serial.print(F(\"Longtitude:   \")); if (longtitude[0] != 0) { Serial.println(longtitude); } else { Serial.println(F(\"N/A\")); }\n}\n\nvoid APRS_sendPkt(void *_buffer, size_t length) {\n\n    uint8_t *buffer = (uint8_t *)_buffer;\n\n    memcpy(dst.call, DST, 6);\n    dst.ssid = DST_SSID;\n\n    memcpy(src.call, CALL, 6);\n    src.ssid = CALL_SSID;\n\n    memcpy(path1.call, PATH1, 6);\n    path1.ssid = PATH1_SSID;\n\n    memcpy(path2.call, PATH2, 6);\n    path2.ssid = PATH2_SSID;\n\n    path[0] = dst;\n    path[1] = src;\n    path[2] = path1;\n    path[3] = path2;\n\n    ax25_sendVia(&AX25, path, countof(path), buffer, length);\n}\n\n// Dynamic RAM usage of this function is 30 bytes\nvoid APRS_sendLoc(void *_buffer, size_t length) {\n    size_t payloadLength = 20+length;\n    bool usePHG = false;\n    if (power < 10 && height < 10 && gain < 10 && directivity < 9) {\n        usePHG = true;\n        payloadLength += 7;\n    }\n    uint8_t *packet = (uint8_t*)malloc(payloadLength);\n    uint8_t *ptr = packet;\n    packet[0] = '=';\n    packet[9] = symbolTable;\n    packet[19] = symbol;\n    ptr++;\n    memcpy(ptr, latitude, 8);\n    ptr += 9;\n    memcpy(ptr, longtitude, 9);\n    ptr += 10;\n    if (usePHG) {\n        packet[20] = 'P';\n        packet[21] = 'H';\n        packet[22] = 'G';\n        packet[23] = power+48;\n        packet[24] = height+48;\n        packet[25] = gain+48;\n        packet[26] = directivity+48;\n        ptr+=7;\n    }\n    if (length > 0) {\n        uint8_t *buffer = (uint8_t *)_buffer;\n        memcpy(ptr, buffer, length);\n    }\n\n    APRS_sendPkt(packet, payloadLength);\n    free(packet);\n}\n\n// Dynamic RAM usage of this function is 18 bytes\nvoid APRS_sendMsg(void *_buffer, size_t length) {\n    if (length > 67) length = 67;\n    size_t payloadLength = 11+length+4;\n\n    uint8_t *packet = (uint8_t*)malloc(payloadLength);\n    uint8_t *ptr = packet;\n    packet[0] = ':';\n    int callSize = 6;\n    int count = 0;\n    while (callSize--) {\n        if (message_recip[count] != 0) {\n            packet[1+count] = message_recip[count];\n            count++;\n        }\n    }\n    if (message_recip_ssid != -1) {\n        packet[1+count] = '-'; count++;\n        if (message_recip_ssid < 10) {\n            packet[1+count] = message_recip_ssid+48; count++;\n        } else {\n            packet[1+count] = 49; count++;\n            packet[1+count] = message_recip_ssid-10+48; count++;\n        }\n    }\n    while (count < 9) {\n        packet[1+count] = ' '; count++;\n    }\n    packet[1+count] = ':';\n    ptr += 11;\n    if (length > 0) {\n        uint8_t *buffer = (uint8_t *)_buffer;\n        memcpy(ptr, buffer, length);\n        memcpy(lastMessage, buffer, length);\n        lastMessageLen = length;\n    }\n\n    message_seq++;\n    if (message_seq > 999) message_seq = 0;\n\n    packet[11+length] = '{';\n    int n = message_seq % 10;\n    int d = ((message_seq % 100) - n)/10;\n    int h = (message_seq - d - n) / 100;\n\n    packet[12+length] = h+48;\n    packet[13+length] = d+48;\n    packet[14+length] = n+48;\n    \n    APRS_sendPkt(packet, payloadLength);\n    free(packet);\n}\n\nvoid APRS_msgRetry() {\n    message_seq--;\n    APRS_sendMsg(lastMessage, lastMessageLen);\n}\n\n// For getting free memory, from:\n// http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1213583720/15\n\nextern unsigned int __heap_start;\nextern void *__brkval;\n\nstruct __freelist {\n  size_t sz;\n  struct __freelist *nx;\n};\n\nextern struct __freelist *__flp;\n\nint freeListSize() {\n  struct __freelist* current;\n  int total = 0;\n  for (current = __flp; current; current = current->nx) {\n    total += 2; /* Add two bytes for the memory block's header  */\n    total += (int) current->sz;\n  }\n  return total;\n}\n\nint freeMemory() {\n  int free_memory;\n  if ((int)__brkval == 0) {\n    free_memory = ((int)&free_memory) - ((int)&__heap_start);\n  } else {\n    free_memory = ((int)&free_memory) - ((int)__brkval);\n    free_memory += freeListSize();\n  }\n  return free_memory;\n}\n"
  },
  {
    "path": "src/LibAPRS.h",
    "content": "#include \"Arduino.h\"\n#include <stdint.h>\n#include <stdbool.h>\n\n#include \"FIFO.h\"\n#include \"CRC-CCIT.h\"\n#include \"HDLC.h\"\n#include \"AFSK.h\"\n#include \"AX25.h\"\n\nvoid APRS_init(int reference, bool open_squelch);\nvoid APRS_poll(void);\n\nvoid APRS_setCallsign(char *call, int ssid);\nvoid APRS_setDestination(char *call, int ssid);\nvoid APRS_setMessageDestination(char *call, int ssid);\nvoid APRS_setPath1(char *call, int ssid);\nvoid APRS_setPath2(char *call, int ssid);\n\nvoid APRS_setPreamble(unsigned long pre);\nvoid APRS_setTail(unsigned long tail);\nvoid APRS_useAlternateSymbolTable(bool use);\nvoid APRS_setSymbol(char sym);\n\nvoid APRS_setLat(char *lat);\nvoid APRS_setLon(char *lon);\nvoid APRS_setPower(int s);\nvoid APRS_setHeight(int s);\nvoid APRS_setGain(int s);\nvoid APRS_setDirectivity(int s);\n\nvoid APRS_sendPkt(void *_buffer, size_t length);\nvoid APRS_sendLoc(void *_buffer, size_t length);\nvoid APRS_sendMsg(void *_buffer, size_t length);\nvoid APRS_msgRetry();\n\nvoid APRS_printSettings();\n\nint freeMemory();\n"
  },
  {
    "path": "src/constants.h",
    "content": "#define m328p  0x01\n#define m1284p 0x02\n#define m644p  0x03\n\n#define REF_3V3 0x01\n#define REF_5V  0x02\n"
  },
  {
    "path": "src/device.h",
    "content": "#include \"constants.h\"\n\n#ifndef DEVICE_CONFIGURATION\n#define DEVICE_CONFIGURATION\n\n// CPU settings\n#ifndef TARGET_CPU\n    #define TARGET_CPU m328p\n#endif\n\n#ifndef F_CPU\n    #define F_CPU 16000000\n#endif\n\n#ifndef FREQUENCY_CORRECTION\n    #define FREQUENCY_CORRECTION 0\n#endif\n\n// Sampling & timer setup\n#define CONFIG_AFSK_DAC_SAMPLERATE 9600\n\n// Port settings\n#if TARGET_CPU == m328p\n    #define DAC_PORT PORTD\n    #define DAC_DDR  DDRD\n    #define LED_PORT PORTB\n    #define LED_DDR  DDRB\n    #define ADC_PORT PORTC\n    #define ADC_DDR  DDRC\n#endif\n\n#endif\n"
  },
  {
    "path": "src/src.ino",
    "content": "// Do not add to this file (src.ino) it only serves to allow users to easily open the underlying c/c++ and header files of LibAPRS to view/edit in arduino IDE\n\n"
  }
]