8 Commits

Author SHA1 Message Date
cf89d77981 pip micro disable piintrospection piwaitevent
PIP_NO_SOCET
2025-10-18 11:20:18 +03:00
4885623492 Add pico sdk define 2025-10-18 08:53:47 +03:00
6c3c763934 try fix old mingw 2025-10-17 11:30:41 +03:00
4d841787fc version 5.5.2
PIVariant complex(f,d,ld) full support
2025-10-16 11:47:55 +03:00
790246afea add miss files, add PIUnits::Distance and PIUnits::Mass 2025-10-10 19:47:25 +03:00
978e350722 version 5.5.1
add SipHash and HalfSipHash for PIDigest
2025-10-08 21:15:28 +03:00
1d76cacae2 code brush some digest 2025-10-08 16:59:56 +03:00
db954ffdaa version 5.5.0
add PIIODevice::threadedReadTimeout
2025-09-29 18:48:20 +03:00
48 changed files with 5163 additions and 567 deletions

121
3rd/BLAKE2/COPYING Normal file
View File

@@ -0,0 +1,121 @@
Creative Commons Legal Code
CC0 1.0 Universal
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.
For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:
i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.

219
3rd/SipHash/LICENSE_A2LLVM Normal file
View File

@@ -0,0 +1,219 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
---- LLVM Exceptions to the Apache 2.0 License ----
As an exception, if, as a result of your compiling your source code, portions
of this Software are embedded into an Object form of such source code, you
may redistribute such embedded portions in such Object form without complying
with the conditions of Sections 4(a), 4(b) and 4(d) of the License.
In addition, if you combine or link compiled forms of this Software with
software that is licensed under the GPLv2 ("Combined Software") and if a
court of competent jurisdiction determines that the patent provision (Section
3), the indemnity provision (Section 9) or other Section of the License
conflicts with the conditions of the GPLv2, you may retroactively and
prospectively choose to deem waived or otherwise exclude such Section(s) of
the License, but only in their entirety and only with respect to the Combined
Software.

116
3rd/SipHash/LICENSE_CC0 Normal file
View File

@@ -0,0 +1,116 @@
CC0 1.0 Universal
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator and
subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for the
purpose of contributing to a commons of creative, cultural and scientific
works ("Commons") that the public can reliably and without fear of later
claims of infringement build upon, modify, incorporate in other works, reuse
and redistribute as freely as possible in any form whatsoever and for any
purposes, including without limitation commercial purposes. These owners may
contribute to the Commons to promote the ideal of a free culture and the
further production of creative, cultural and scientific works, or to gain
reputation or greater distribution for their Work in part through the use and
efforts of others.
For these and/or other purposes and motivations, and without any expectation
of additional consideration or compensation, the person associating CC0 with a
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
and publicly distribute the Work under its terms, with knowledge of his or her
Copyright and Related Rights in the Work and the meaning and intended legal
effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not limited
to, the following:
i. the right to reproduce, adapt, distribute, perform, display, communicate,
and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or likeness
depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data in
a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation thereof,
including any amended or successor version of such directive); and
vii. other similar, equivalent or corresponding rights throughout the world
based on applicable law or treaty, and any national implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention of,
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
and Related Rights and associated claims and causes of action, whether now
known or unknown (including existing as well as future claims and causes of
action), in the Work (i) in all territories worldwide, (ii) for the maximum
duration provided by applicable law or treaty (including future time
extensions), (iii) in any current or future medium and for any number of
copies, and (iv) for any purpose whatsoever, including without limitation
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
the Waiver for the benefit of each member of the public at large and to the
detriment of Affirmer's heirs and successors, fully intending that such Waiver
shall not be subject to revocation, rescission, cancellation, termination, or
any other legal or equitable action to disrupt the quiet enjoyment of the Work
by the public as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason be
judged legally invalid or ineffective under applicable law, then the Waiver
shall be preserved to the maximum extent permitted taking into account
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
is so judged Affirmer hereby grants to each affected person a royalty-free,
non transferable, non sublicensable, non exclusive, irrevocable and
unconditional license to exercise Affirmer's Copyright and Related Rights in
the Work (i) in all territories worldwide, (ii) for the maximum duration
provided by applicable law or treaty (including future time extensions), (iii)
in any current or future medium and for any number of copies, and (iv) for any
purpose whatsoever, including without limitation commercial, advertising or
promotional purposes (the "License"). The License shall be deemed effective as
of the date CC0 was applied by Affirmer to the Work. Should any part of the
License for any reason be judged legally invalid or ineffective under
applicable law, such partial invalidity or ineffectiveness shall not
invalidate the remainder of the License, and in such case Affirmer hereby
affirms that he or she will not (i) exercise any of his or her remaining
Copyright and Related Rights in the Work or (ii) assert any associated claims
and causes of action with respect to the Work, in either case contrary to
Affirmer's express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or warranties
of any kind concerning the Work, express, implied, statutory or otherwise,
including without limitation warranties of title, merchantability, fitness
for a particular purpose, non infringement, or the absence of latent or
other defects, accuracy, or the present or absence of errors, whether or not
discoverable, all to the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without limitation
any person's Copyright and Related Rights in the Work. Further, Affirmer
disclaims responsibility for obtaining any necessary consents, permissions
or other rights required for any use of the Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to this
CC0 or use of the Work.
For more information, please see
<http://creativecommons.org/publicdomain/zero/1.0/>

7
3rd/SipHash/LICENSE_MIT Normal file
View File

@@ -0,0 +1,7 @@
Copyright 2012-2024 JP Aumasson
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

166
3rd/SipHash/halfsiphash.c Normal file
View File

@@ -0,0 +1,166 @@
/*
SipHash reference C implementation
Copyright (c) 2016 Jean-Philippe Aumasson <jeanphilippe.aumasson@gmail.com>
To the extent possible under law, the author(s) have dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along
with
this software. If not, see
<http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#include "halfsiphash.h"
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
/* default: SipHash-2-4 */
#ifndef cROUNDS
#define cROUNDS 2
#endif
#ifndef dROUNDS
#define dROUNDS 4
#endif
#define ROTL(x, b) (uint32_t)(((x) << (b)) | ((x) >> (32 - (b))))
#define U32TO8_LE(p, v) \
(p)[0] = (uint8_t)((v)); \
(p)[1] = (uint8_t)((v) >> 8); \
(p)[2] = (uint8_t)((v) >> 16); \
(p)[3] = (uint8_t)((v) >> 24);
#define U8TO32_LE(p) \
(((uint32_t)((p)[0])) | ((uint32_t)((p)[1]) << 8) | \
((uint32_t)((p)[2]) << 16) | ((uint32_t)((p)[3]) << 24))
#define SIPROUND \
do { \
v0 += v1; \
v1 = ROTL(v1, 5); \
v1 ^= v0; \
v0 = ROTL(v0, 16); \
v2 += v3; \
v3 = ROTL(v3, 8); \
v3 ^= v2; \
v0 += v3; \
v3 = ROTL(v3, 7); \
v3 ^= v0; \
v2 += v1; \
v1 = ROTL(v1, 13); \
v1 ^= v2; \
v2 = ROTL(v2, 16); \
} while (0)
#ifdef DEBUG_SIPHASH
#include <stdio.h>
#define TRACE \
do { \
printf("(%3zu) v0 %08" PRIx32 "\n", inlen, v0); \
printf("(%3zu) v1 %08" PRIx32 "\n", inlen, v1); \
printf("(%3zu) v2 %08" PRIx32 "\n", inlen, v2); \
printf("(%3zu) v3 %08" PRIx32 "\n", inlen, v3); \
} while (0)
#else
#define TRACE
#endif
/*
Computes a SipHash value
*in: pointer to input data (read-only)
inlen: input data length in bytes (any size_t value)
*k: pointer to the key data (read-only), must be 8 bytes
*out: pointer to output data (write-only), outlen bytes must be allocated
outlen: length of the output in bytes, must be 4 or 8
*/
int halfsiphash(const void *in, const size_t inlen, const void *k, uint8_t *out,
const size_t outlen) {
const unsigned char *ni = (const unsigned char *)in;
const unsigned char *kk = (const unsigned char *)k;
assert((outlen == 4) || (outlen == 8));
uint32_t v0 = 0;
uint32_t v1 = 0;
uint32_t v2 = UINT32_C(0x6c796765);
uint32_t v3 = UINT32_C(0x74656462);
uint32_t k0 = U8TO32_LE(kk);
uint32_t k1 = U8TO32_LE(kk + 4);
uint32_t m;
int i;
const unsigned char *end = ni + inlen - (inlen % sizeof(uint32_t));
const int left = inlen & 3;
uint32_t b = ((uint32_t)inlen) << 24;
v3 ^= k1;
v2 ^= k0;
v1 ^= k1;
v0 ^= k0;
if (outlen == 8)
v1 ^= 0xee;
for (; ni != end; ni += 4) {
m = U8TO32_LE(ni);
v3 ^= m;
TRACE;
for (i = 0; i < cROUNDS; ++i)
SIPROUND;
v0 ^= m;
}
switch (left) {
case 3:
b |= ((uint32_t)ni[2]) << 16;
/* FALLTHRU */
case 2:
b |= ((uint32_t)ni[1]) << 8;
/* FALLTHRU */
case 1:
b |= ((uint32_t)ni[0]);
break;
case 0:
break;
}
v3 ^= b;
TRACE;
for (i = 0; i < cROUNDS; ++i)
SIPROUND;
v0 ^= b;
if (outlen == 8)
v2 ^= 0xee;
else
v2 ^= 0xff;
TRACE;
for (i = 0; i < dROUNDS; ++i)
SIPROUND;
b = v1 ^ v3;
U32TO8_LE(out, b);
if (outlen == 4)
return 0;
v1 ^= 0xdd;
TRACE;
for (i = 0; i < dROUNDS; ++i)
SIPROUND;
b = v1 ^ v3;
U32TO8_LE(out + 4, b);
return 0;
}

34
3rd/SipHash/halfsiphash.h Normal file
View File

@@ -0,0 +1,34 @@
/*
SipHash reference C implementation
Copyright (c) 2012-2021 Jean-Philippe Aumasson
<jeanphilippe.aumasson@gmail.com>
Copyright (c) 2012-2014 Daniel J. Bernstein <djb@cr.yp.to>
To the extent possible under law, the author(s) have dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along
with
this software. If not, see
<http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#ifndef HALFSIPHASH_H
#define HALFSIPHASH_H
#include <stddef.h>
#include <stdint.h>
#if defined(__cplusplus)
extern "C" {
#endif
int halfsiphash(const void * in, const size_t inlen, const void * k, uint8_t * out, const size_t outlen);
#if defined(__cplusplus)
}
#endif
#endif

185
3rd/SipHash/siphash.c Normal file
View File

@@ -0,0 +1,185 @@
/*
SipHash reference C implementation
Copyright (c) 2012-2022 Jean-Philippe Aumasson
<jeanphilippe.aumasson@gmail.com>
Copyright (c) 2012-2014 Daniel J. Bernstein <djb@cr.yp.to>
To the extent possible under law, the author(s) have dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along
with
this software. If not, see
<http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#include "siphash.h"
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
/* default: SipHash-2-4 */
#ifndef cROUNDS
#define cROUNDS 2
#endif
#ifndef dROUNDS
#define dROUNDS 4
#endif
#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b))))
#define U32TO8_LE(p, v) \
(p)[0] = (uint8_t)((v)); \
(p)[1] = (uint8_t)((v) >> 8); \
(p)[2] = (uint8_t)((v) >> 16); \
(p)[3] = (uint8_t)((v) >> 24);
#define U64TO8_LE(p, v) \
U32TO8_LE((p), (uint32_t)((v))); \
U32TO8_LE((p) + 4, (uint32_t)((v) >> 32));
#define U8TO64_LE(p) \
(((uint64_t)((p)[0])) | ((uint64_t)((p)[1]) << 8) | \
((uint64_t)((p)[2]) << 16) | ((uint64_t)((p)[3]) << 24) | \
((uint64_t)((p)[4]) << 32) | ((uint64_t)((p)[5]) << 40) | \
((uint64_t)((p)[6]) << 48) | ((uint64_t)((p)[7]) << 56))
#define SIPROUND \
do { \
v0 += v1; \
v1 = ROTL(v1, 13); \
v1 ^= v0; \
v0 = ROTL(v0, 32); \
v2 += v3; \
v3 = ROTL(v3, 16); \
v3 ^= v2; \
v0 += v3; \
v3 = ROTL(v3, 21); \
v3 ^= v0; \
v2 += v1; \
v1 = ROTL(v1, 17); \
v1 ^= v2; \
v2 = ROTL(v2, 32); \
} while (0)
#ifdef DEBUG_SIPHASH
#include <stdio.h>
#define TRACE \
do { \
printf("(%3zu) v0 %016" PRIx64 "\n", inlen, v0); \
printf("(%3zu) v1 %016" PRIx64 "\n", inlen, v1); \
printf("(%3zu) v2 %016" PRIx64 "\n", inlen, v2); \
printf("(%3zu) v3 %016" PRIx64 "\n", inlen, v3); \
} while (0)
#else
#define TRACE
#endif
/*
Computes a SipHash value
*in: pointer to input data (read-only)
inlen: input data length in bytes (any size_t value)
*k: pointer to the key data (read-only), must be 16 bytes
*out: pointer to output data (write-only), outlen bytes must be allocated
outlen: length of the output in bytes, must be 8 or 16
*/
int siphash(const void *in, const size_t inlen, const void *k, uint8_t *out,
const size_t outlen) {
const unsigned char *ni = (const unsigned char *)in;
const unsigned char *kk = (const unsigned char *)k;
assert((outlen == 8) || (outlen == 16));
uint64_t v0 = UINT64_C(0x736f6d6570736575);
uint64_t v1 = UINT64_C(0x646f72616e646f6d);
uint64_t v2 = UINT64_C(0x6c7967656e657261);
uint64_t v3 = UINT64_C(0x7465646279746573);
uint64_t k0 = U8TO64_LE(kk);
uint64_t k1 = U8TO64_LE(kk + 8);
uint64_t m;
int i;
const unsigned char *end = ni + inlen - (inlen % sizeof(uint64_t));
const int left = inlen & 7;
uint64_t b = ((uint64_t)inlen) << 56;
v3 ^= k1;
v2 ^= k0;
v1 ^= k1;
v0 ^= k0;
if (outlen == 16)
v1 ^= 0xee;
for (; ni != end; ni += 8) {
m = U8TO64_LE(ni);
v3 ^= m;
TRACE;
for (i = 0; i < cROUNDS; ++i)
SIPROUND;
v0 ^= m;
}
switch (left) {
case 7:
b |= ((uint64_t)ni[6]) << 48;
/* FALLTHRU */
case 6:
b |= ((uint64_t)ni[5]) << 40;
/* FALLTHRU */
case 5:
b |= ((uint64_t)ni[4]) << 32;
/* FALLTHRU */
case 4:
b |= ((uint64_t)ni[3]) << 24;
/* FALLTHRU */
case 3:
b |= ((uint64_t)ni[2]) << 16;
/* FALLTHRU */
case 2:
b |= ((uint64_t)ni[1]) << 8;
/* FALLTHRU */
case 1:
b |= ((uint64_t)ni[0]);
break;
case 0:
break;
}
v3 ^= b;
TRACE;
for (i = 0; i < cROUNDS; ++i)
SIPROUND;
v0 ^= b;
if (outlen == 16)
v2 ^= 0xee;
else
v2 ^= 0xff;
TRACE;
for (i = 0; i < dROUNDS; ++i)
SIPROUND;
b = v0 ^ v1 ^ v2 ^ v3;
U64TO8_LE(out, b);
if (outlen == 8)
return 0;
v1 ^= 0xdd;
TRACE;
for (i = 0; i < dROUNDS; ++i)
SIPROUND;
b = v0 ^ v1 ^ v2 ^ v3;
U64TO8_LE(out + 8, b);
return 0;
}

34
3rd/SipHash/siphash.h Normal file
View File

@@ -0,0 +1,34 @@
/*
SipHash reference C implementation
Copyright (c) 2012-2021 Jean-Philippe Aumasson
<jeanphilippe.aumasson@gmail.com>
Copyright (c) 2012-2014 Daniel J. Bernstein <djb@cr.yp.to>
To the extent possible under law, the author(s) have dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along
with
this software. If not, see
<http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#ifndef SIPHASH_H
#define SIPHASH_H
#include <stddef.h>
#include <stdint.h>
#if defined(__cplusplus)
extern "C" {
#endif
int siphash(const void * in, const size_t inlen, const void * k, uint8_t * out, const size_t outlen);
#if defined(__cplusplus)
}
#endif
#endif

2826
3rd/SipHash/vectors.h Normal file
View File

@@ -0,0 +1,2826 @@
#include <stdint.h>
const uint8_t vectors_sip64[64][8] = {
{
0x31,
0x0e,
0x0e,
0xdd,
0x47,
0xdb,
0x6f,
0x72,
},
{
0xfd,
0x67,
0xdc,
0x93,
0xc5,
0x39,
0xf8,
0x74,
},
{
0x5a,
0x4f,
0xa9,
0xd9,
0x09,
0x80,
0x6c,
0x0d,
},
{
0x2d,
0x7e,
0xfb,
0xd7,
0x96,
0x66,
0x67,
0x85,
},
{
0xb7,
0x87,
0x71,
0x27,
0xe0,
0x94,
0x27,
0xcf,
},
{
0x8d,
0xa6,
0x99,
0xcd,
0x64,
0x55,
0x76,
0x18,
},
{
0xce,
0xe3,
0xfe,
0x58,
0x6e,
0x46,
0xc9,
0xcb,
},
{
0x37,
0xd1,
0x01,
0x8b,
0xf5,
0x00,
0x02,
0xab,
},
{
0x62,
0x24,
0x93,
0x9a,
0x79,
0xf5,
0xf5,
0x93,
},
{
0xb0,
0xe4,
0xa9,
0x0b,
0xdf,
0x82,
0x00,
0x9e,
},
{
0xf3,
0xb9,
0xdd,
0x94,
0xc5,
0xbb,
0x5d,
0x7a,
},
{
0xa7,
0xad,
0x6b,
0x22,
0x46,
0x2f,
0xb3,
0xf4,
},
{
0xfb,
0xe5,
0x0e,
0x86,
0xbc,
0x8f,
0x1e,
0x75,
},
{
0x90,
0x3d,
0x84,
0xc0,
0x27,
0x56,
0xea,
0x14,
},
{
0xee,
0xf2,
0x7a,
0x8e,
0x90,
0xca,
0x23,
0xf7,
},
{
0xe5,
0x45,
0xbe,
0x49,
0x61,
0xca,
0x29,
0xa1,
},
{
0xdb,
0x9b,
0xc2,
0x57,
0x7f,
0xcc,
0x2a,
0x3f,
},
{
0x94,
0x47,
0xbe,
0x2c,
0xf5,
0xe9,
0x9a,
0x69,
},
{
0x9c,
0xd3,
0x8d,
0x96,
0xf0,
0xb3,
0xc1,
0x4b,
},
{
0xbd,
0x61,
0x79,
0xa7,
0x1d,
0xc9,
0x6d,
0xbb,
},
{
0x98,
0xee,
0xa2,
0x1a,
0xf2,
0x5c,
0xd6,
0xbe,
},
{
0xc7,
0x67,
0x3b,
0x2e,
0xb0,
0xcb,
0xf2,
0xd0,
},
{
0x88,
0x3e,
0xa3,
0xe3,
0x95,
0x67,
0x53,
0x93,
},
{
0xc8,
0xce,
0x5c,
0xcd,
0x8c,
0x03,
0x0c,
0xa8,
},
{
0x94,
0xaf,
0x49,
0xf6,
0xc6,
0x50,
0xad,
0xb8,
},
{
0xea,
0xb8,
0x85,
0x8a,
0xde,
0x92,
0xe1,
0xbc,
},
{
0xf3,
0x15,
0xbb,
0x5b,
0xb8,
0x35,
0xd8,
0x17,
},
{
0xad,
0xcf,
0x6b,
0x07,
0x63,
0x61,
0x2e,
0x2f,
},
{
0xa5,
0xc9,
0x1d,
0xa7,
0xac,
0xaa,
0x4d,
0xde,
},
{
0x71,
0x65,
0x95,
0x87,
0x66,
0x50,
0xa2,
0xa6,
},
{
0x28,
0xef,
0x49,
0x5c,
0x53,
0xa3,
0x87,
0xad,
},
{
0x42,
0xc3,
0x41,
0xd8,
0xfa,
0x92,
0xd8,
0x32,
},
{
0xce,
0x7c,
0xf2,
0x72,
0x2f,
0x51,
0x27,
0x71,
},
{
0xe3,
0x78,
0x59,
0xf9,
0x46,
0x23,
0xf3,
0xa7,
},
{
0x38,
0x12,
0x05,
0xbb,
0x1a,
0xb0,
0xe0,
0x12,
},
{
0xae,
0x97,
0xa1,
0x0f,
0xd4,
0x34,
0xe0,
0x15,
},
{
0xb4,
0xa3,
0x15,
0x08,
0xbe,
0xff,
0x4d,
0x31,
},
{
0x81,
0x39,
0x62,
0x29,
0xf0,
0x90,
0x79,
0x02,
},
{
0x4d,
0x0c,
0xf4,
0x9e,
0xe5,
0xd4,
0xdc,
0xca,
},
{
0x5c,
0x73,
0x33,
0x6a,
0x76,
0xd8,
0xbf,
0x9a,
},
{
0xd0,
0xa7,
0x04,
0x53,
0x6b,
0xa9,
0x3e,
0x0e,
},
{
0x92,
0x59,
0x58,
0xfc,
0xd6,
0x42,
0x0c,
0xad,
},
{
0xa9,
0x15,
0xc2,
0x9b,
0xc8,
0x06,
0x73,
0x18,
},
{
0x95,
0x2b,
0x79,
0xf3,
0xbc,
0x0a,
0xa6,
0xd4,
},
{
0xf2,
0x1d,
0xf2,
0xe4,
0x1d,
0x45,
0x35,
0xf9,
},
{
0x87,
0x57,
0x75,
0x19,
0x04,
0x8f,
0x53,
0xa9,
},
{
0x10,
0xa5,
0x6c,
0xf5,
0xdf,
0xcd,
0x9a,
0xdb,
},
{
0xeb,
0x75,
0x09,
0x5c,
0xcd,
0x98,
0x6c,
0xd0,
},
{
0x51,
0xa9,
0xcb,
0x9e,
0xcb,
0xa3,
0x12,
0xe6,
},
{
0x96,
0xaf,
0xad,
0xfc,
0x2c,
0xe6,
0x66,
0xc7,
},
{
0x72,
0xfe,
0x52,
0x97,
0x5a,
0x43,
0x64,
0xee,
},
{
0x5a,
0x16,
0x45,
0xb2,
0x76,
0xd5,
0x92,
0xa1,
},
{
0xb2,
0x74,
0xcb,
0x8e,
0xbf,
0x87,
0x87,
0x0a,
},
{
0x6f,
0x9b,
0xb4,
0x20,
0x3d,
0xe7,
0xb3,
0x81,
},
{
0xea,
0xec,
0xb2,
0xa3,
0x0b,
0x22,
0xa8,
0x7f,
},
{
0x99,
0x24,
0xa4,
0x3c,
0xc1,
0x31,
0x57,
0x24,
},
{
0xbd,
0x83,
0x8d,
0x3a,
0xaf,
0xbf,
0x8d,
0xb7,
},
{
0x0b,
0x1a,
0x2a,
0x32,
0x65,
0xd5,
0x1a,
0xea,
},
{
0x13,
0x50,
0x79,
0xa3,
0x23,
0x1c,
0xe6,
0x60,
},
{
0x93,
0x2b,
0x28,
0x46,
0xe4,
0xd7,
0x06,
0x66,
},
{
0xe1,
0x91,
0x5f,
0x5c,
0xb1,
0xec,
0xa4,
0x6c,
},
{
0xf3,
0x25,
0x96,
0x5c,
0xa1,
0x6d,
0x62,
0x9f,
},
{
0x57,
0x5f,
0xf2,
0x8e,
0x60,
0x38,
0x1b,
0xe5,
},
{
0x72,
0x45,
0x06,
0xeb,
0x4c,
0x32,
0x8a,
0x95,
},
};
const uint8_t vectors_sip128[64][16] = {
{
0xa3,
0x81,
0x7f,
0x04,
0xba,
0x25,
0xa8,
0xe6,
0x6d,
0xf6,
0x72,
0x14,
0xc7,
0x55,
0x02,
0x93,
},
{
0xda,
0x87,
0xc1,
0xd8,
0x6b,
0x99,
0xaf,
0x44,
0x34,
0x76,
0x59,
0x11,
0x9b,
0x22,
0xfc,
0x45,
},
{
0x81,
0x77,
0x22,
0x8d,
0xa4,
0xa4,
0x5d,
0xc7,
0xfc,
0xa3,
0x8b,
0xde,
0xf6,
0x0a,
0xff,
0xe4,
},
{
0x9c,
0x70,
0xb6,
0x0c,
0x52,
0x67,
0xa9,
0x4e,
0x5f,
0x33,
0xb6,
0xb0,
0x29,
0x85,
0xed,
0x51,
},
{
0xf8,
0x81,
0x64,
0xc1,
0x2d,
0x9c,
0x8f,
0xaf,
0x7d,
0x0f,
0x6e,
0x7c,
0x7b,
0xcd,
0x55,
0x79,
},
{
0x13,
0x68,
0x87,
0x59,
0x80,
0x77,
0x6f,
0x88,
0x54,
0x52,
0x7a,
0x07,
0x69,
0x0e,
0x96,
0x27,
},
{
0x14,
0xee,
0xca,
0x33,
0x8b,
0x20,
0x86,
0x13,
0x48,
0x5e,
0xa0,
0x30,
0x8f,
0xd7,
0xa1,
0x5e,
},
{
0xa1,
0xf1,
0xeb,
0xbe,
0xd8,
0xdb,
0xc1,
0x53,
0xc0,
0xb8,
0x4a,
0xa6,
0x1f,
0xf0,
0x82,
0x39,
},
{
0x3b,
0x62,
0xa9,
0xba,
0x62,
0x58,
0xf5,
0x61,
0x0f,
0x83,
0xe2,
0x64,
0xf3,
0x14,
0x97,
0xb4,
},
{
0x26,
0x44,
0x99,
0x06,
0x0a,
0xd9,
0xba,
0xab,
0xc4,
0x7f,
0x8b,
0x02,
0xbb,
0x6d,
0x71,
0xed,
},
{
0x00,
0x11,
0x0d,
0xc3,
0x78,
0x14,
0x69,
0x56,
0xc9,
0x54,
0x47,
0xd3,
0xf3,
0xd0,
0xfb,
0xba,
},
{
0x01,
0x51,
0xc5,
0x68,
0x38,
0x6b,
0x66,
0x77,
0xa2,
0xb4,
0xdc,
0x6f,
0x81,
0xe5,
0xdc,
0x18,
},
{
0xd6,
0x26,
0xb2,
0x66,
0x90,
0x5e,
0xf3,
0x58,
0x82,
0x63,
0x4d,
0xf6,
0x85,
0x32,
0xc1,
0x25,
},
{
0x98,
0x69,
0xe2,
0x47,
0xe9,
0xc0,
0x8b,
0x10,
0xd0,
0x29,
0x93,
0x4f,
0xc4,
0xb9,
0x52,
0xf7,
},
{
0x31,
0xfc,
0xef,
0xac,
0x66,
0xd7,
0xde,
0x9c,
0x7e,
0xc7,
0x48,
0x5f,
0xe4,
0x49,
0x49,
0x02,
},
{
0x54,
0x93,
0xe9,
0x99,
0x33,
0xb0,
0xa8,
0x11,
0x7e,
0x08,
0xec,
0x0f,
0x97,
0xcf,
0xc3,
0xd9,
},
{
0x6e,
0xe2,
0xa4,
0xca,
0x67,
0xb0,
0x54,
0xbb,
0xfd,
0x33,
0x15,
0xbf,
0x85,
0x23,
0x05,
0x77,
},
{
0x47,
0x3d,
0x06,
0xe8,
0x73,
0x8d,
0xb8,
0x98,
0x54,
0xc0,
0x66,
0xc4,
0x7a,
0xe4,
0x77,
0x40,
},
{
0xa4,
0x26,
0xe5,
0xe4,
0x23,
0xbf,
0x48,
0x85,
0x29,
0x4d,
0xa4,
0x81,
0xfe,
0xae,
0xf7,
0x23,
},
{
0x78,
0x01,
0x77,
0x31,
0xcf,
0x65,
0xfa,
0xb0,
0x74,
0xd5,
0x20,
0x89,
0x52,
0x51,
0x2e,
0xb1,
},
{
0x9e,
0x25,
0xfc,
0x83,
0x3f,
0x22,
0x90,
0x73,
0x3e,
0x93,
0x44,
0xa5,
0xe8,
0x38,
0x39,
0xeb,
},
{
0x56,
0x8e,
0x49,
0x5a,
0xbe,
0x52,
0x5a,
0x21,
0x8a,
0x22,
0x14,
0xcd,
0x3e,
0x07,
0x1d,
0x12,
},
{
0x4a,
0x29,
0xb5,
0x45,
0x52,
0xd1,
0x6b,
0x9a,
0x46,
0x9c,
0x10,
0x52,
0x8e,
0xff,
0x0a,
0xae,
},
{
0xc9,
0xd1,
0x84,
0xdd,
0xd5,
0xa9,
0xf5,
0xe0,
0xcf,
0x8c,
0xe2,
0x9a,
0x9a,
0xbf,
0x69,
0x1c,
},
{
0x2d,
0xb4,
0x79,
0xae,
0x78,
0xbd,
0x50,
0xd8,
0x88,
0x2a,
0x8a,
0x17,
0x8a,
0x61,
0x32,
0xad,
},
{
0x8e,
0xce,
0x5f,
0x04,
0x2d,
0x5e,
0x44,
0x7b,
0x50,
0x51,
0xb9,
0xea,
0xcb,
0x8d,
0x8f,
0x6f,
},
{
0x9c,
0x0b,
0x53,
0xb4,
0xb3,
0xc3,
0x07,
0xe8,
0x7e,
0xae,
0xe0,
0x86,
0x78,
0x14,
0x1f,
0x66,
},
{
0xab,
0xf2,
0x48,
0xaf,
0x69,
0xa6,
0xea,
0xe4,
0xbf,
0xd3,
0xeb,
0x2f,
0x12,
0x9e,
0xeb,
0x94,
},
{
0x06,
0x64,
0xda,
0x16,
0x68,
0x57,
0x4b,
0x88,
0xb9,
0x35,
0xf3,
0x02,
0x73,
0x58,
0xae,
0xf4,
},
{
0xaa,
0x4b,
0x9d,
0xc4,
0xbf,
0x33,
0x7d,
0xe9,
0x0c,
0xd4,
0xfd,
0x3c,
0x46,
0x7c,
0x6a,
0xb7,
},
{
0xea,
0x5c,
0x7f,
0x47,
0x1f,
0xaf,
0x6b,
0xde,
0x2b,
0x1a,
0xd7,
0xd4,
0x68,
0x6d,
0x22,
0x87,
},
{
0x29,
0x39,
0xb0,
0x18,
0x32,
0x23,
0xfa,
0xfc,
0x17,
0x23,
0xde,
0x4f,
0x52,
0xc4,
0x3d,
0x35,
},
{
0x7c,
0x39,
0x56,
0xca,
0x5e,
0xea,
0xfc,
0x3e,
0x36,
0x3e,
0x9d,
0x55,
0x65,
0x46,
0xeb,
0x68,
},
{
0x77,
0xc6,
0x07,
0x71,
0x46,
0xf0,
0x1c,
0x32,
0xb6,
0xb6,
0x9d,
0x5f,
0x4e,
0xa9,
0xff,
0xcf,
},
{
0x37,
0xa6,
0x98,
0x6c,
0xb8,
0x84,
0x7e,
0xdf,
0x09,
0x25,
0xf0,
0xf1,
0x30,
0x9b,
0x54,
0xde,
},
{
0xa7,
0x05,
0xf0,
0xe6,
0x9d,
0xa9,
0xa8,
0xf9,
0x07,
0x24,
0x1a,
0x2e,
0x92,
0x3c,
0x8c,
0xc8,
},
{
0x3d,
0xc4,
0x7d,
0x1f,
0x29,
0xc4,
0x48,
0x46,
0x1e,
0x9e,
0x76,
0xed,
0x90,
0x4f,
0x67,
0x11,
},
{
0x0d,
0x62,
0xbf,
0x01,
0xe6,
0xfc,
0x0e,
0x1a,
0x0d,
0x3c,
0x47,
0x51,
0xc5,
0xd3,
0x69,
0x2b,
},
{
0x8c,
0x03,
0x46,
0x8b,
0xca,
0x7c,
0x66,
0x9e,
0xe4,
0xfd,
0x5e,
0x08,
0x4b,
0xbe,
0xe7,
0xb5,
},
{
0x52,
0x8a,
0x5b,
0xb9,
0x3b,
0xaf,
0x2c,
0x9c,
0x44,
0x73,
0xcc,
0xe5,
0xd0,
0xd2,
0x2b,
0xd9,
},
{
0xdf,
0x6a,
0x30,
0x1e,
0x95,
0xc9,
0x5d,
0xad,
0x97,
0xae,
0x0c,
0xc8,
0xc6,
0x91,
0x3b,
0xd8,
},
{
0x80,
0x11,
0x89,
0x90,
0x2c,
0x85,
0x7f,
0x39,
0xe7,
0x35,
0x91,
0x28,
0x5e,
0x70,
0xb6,
0xdb,
},
{
0xe6,
0x17,
0x34,
0x6a,
0xc9,
0xc2,
0x31,
0xbb,
0x36,
0x50,
0xae,
0x34,
0xcc,
0xca,
0x0c,
0x5b,
},
{
0x27,
0xd9,
0x34,
0x37,
0xef,
0xb7,
0x21,
0xaa,
0x40,
0x18,
0x21,
0xdc,
0xec,
0x5a,
0xdf,
0x89,
},
{
0x89,
0x23,
0x7d,
0x9d,
0xed,
0x9c,
0x5e,
0x78,
0xd8,
0xb1,
0xc9,
0xb1,
0x66,
0xcc,
0x73,
0x42,
},
{
0x4a,
0x6d,
0x80,
0x91,
0xbf,
0x5e,
0x7d,
0x65,
0x11,
0x89,
0xfa,
0x94,
0xa2,
0x50,
0xb1,
0x4c,
},
{
0x0e,
0x33,
0xf9,
0x60,
0x55,
0xe7,
0xae,
0x89,
0x3f,
0xfc,
0x0e,
0x3d,
0xcf,
0x49,
0x29,
0x02,
},
{
0xe6,
0x1c,
0x43,
0x2b,
0x72,
0x0b,
0x19,
0xd1,
0x8e,
0xc8,
0xd8,
0x4b,
0xdc,
0x63,
0x15,
0x1b,
},
{
0xf7,
0xe5,
0xae,
0xf5,
0x49,
0xf7,
0x82,
0xcf,
0x37,
0x90,
0x55,
0xa6,
0x08,
0x26,
0x9b,
0x16,
},
{
0x43,
0x8d,
0x03,
0x0f,
0xd0,
0xb7,
0xa5,
0x4f,
0xa8,
0x37,
0xf2,
0xad,
0x20,
0x1a,
0x64,
0x03,
},
{
0xa5,
0x90,
0xd3,
0xee,
0x4f,
0xbf,
0x04,
0xe3,
0x24,
0x7e,
0x0d,
0x27,
0xf2,
0x86,
0x42,
0x3f,
},
{
0x5f,
0xe2,
0xc1,
0xa1,
0x72,
0xfe,
0x93,
0xc4,
0xb1,
0x5c,
0xd3,
0x7c,
0xae,
0xf9,
0xf5,
0x38,
},
{
0x2c,
0x97,
0x32,
0x5c,
0xbd,
0x06,
0xb3,
0x6e,
0xb2,
0x13,
0x3d,
0xd0,
0x8b,
0x3a,
0x01,
0x7c,
},
{
0x92,
0xc8,
0x14,
0x22,
0x7a,
0x6b,
0xca,
0x94,
0x9f,
0xf0,
0x65,
0x9f,
0x00,
0x2a,
0xd3,
0x9e,
},
{
0xdc,
0xe8,
0x50,
0x11,
0x0b,
0xd8,
0x32,
0x8c,
0xfb,
0xd5,
0x08,
0x41,
0xd6,
0x91,
0x1d,
0x87,
},
{
0x67,
0xf1,
0x49,
0x84,
0xc7,
0xda,
0x79,
0x12,
0x48,
0xe3,
0x2b,
0xb5,
0x92,
0x25,
0x83,
0xda,
},
{
0x19,
0x38,
0xf2,
0xcf,
0x72,
0xd5,
0x4e,
0xe9,
0x7e,
0x94,
0x16,
0x6f,
0xa9,
0x1d,
0x2a,
0x36,
},
{
0x74,
0x48,
0x1e,
0x96,
0x46,
0xed,
0x49,
0xfe,
0x0f,
0x62,
0x24,
0x30,
0x16,
0x04,
0x69,
0x8e,
},
{
0x57,
0xfc,
0xa5,
0xde,
0x98,
0xa9,
0xd6,
0xd8,
0x00,
0x64,
0x38,
0xd0,
0x58,
0x3d,
0x8a,
0x1d,
},
{
0x9f,
0xec,
0xde,
0x1c,
0xef,
0xdc,
0x1c,
0xbe,
0xd4,
0x76,
0x36,
0x74,
0xd9,
0x57,
0x53,
0x59,
},
{
0xe3,
0x04,
0x0c,
0x00,
0xeb,
0x28,
0xf1,
0x53,
0x66,
0xca,
0x73,
0xcb,
0xd8,
0x72,
0xe7,
0x40,
},
{
0x76,
0x97,
0x00,
0x9a,
0x6a,
0x83,
0x1d,
0xfe,
0xcc,
0xa9,
0x1c,
0x59,
0x93,
0x67,
0x0f,
0x7a,
},
{
0x58,
0x53,
0x54,
0x23,
0x21,
0xf5,
0x67,
0xa0,
0x05,
0xd5,
0x47,
0xa4,
0xf0,
0x47,
0x59,
0xbd,
},
{
0x51,
0x50,
0xd1,
0x77,
0x2f,
0x50,
0x83,
0x4a,
0x50,
0x3e,
0x06,
0x9a,
0x97,
0x3f,
0xbd,
0x7c,
},
};
const uint8_t vectors_hsip32[64][4] = {
{
0xa9,
0x35,
0x9f,
0x5b,
},
{
0x27,
0x47,
0x5a,
0xb8,
},
{
0xfa,
0x62,
0xa6,
0x03,
},
{
0x8a,
0xfe,
0xe7,
0x04,
},
{
0x2a,
0x6e,
0x46,
0x89,
},
{
0xc5,
0xfa,
0xb6,
0x69,
},
{
0x58,
0x63,
0xfc,
0x23,
},
{
0x8b,
0xcf,
0x63,
0xc5,
},
{
0xd0,
0xb8,
0x84,
0x8f,
},
{
0xf8,
0x06,
0xe7,
0x79,
},
{
0x94,
0xb0,
0x79,
0x34,
},
{
0x08,
0x08,
0x30,
0x50,
},
{
0x57,
0xf0,
0x87,
0x2f,
},
{
0x77,
0xe6,
0x63,
0xff,
},
{
0xd6,
0xff,
0xf8,
0x7c,
},
{
0x74,
0xfe,
0x2b,
0x97,
},
{
0xd9,
0xb5,
0xac,
0x84,
},
{
0xc4,
0x74,
0x64,
0x5b,
},
{
0x46,
0x5b,
0x8d,
0x9b,
},
{
0x7b,
0xef,
0xe3,
0x87,
},
{
0xe3,
0x4d,
0x10,
0x45,
},
{
0x61,
0x3f,
0x62,
0xb3,
},
{
0x70,
0xf3,
0x67,
0xfe,
},
{
0xe6,
0xad,
0xb8,
0xbd,
},
{
0x27,
0x40,
0x0c,
0x63,
},
{
0x26,
0x78,
0x78,
0x75,
},
{
0x4f,
0x56,
0x7b,
0x5f,
},
{
0x3a,
0xb0,
0xe6,
0x69,
},
{
0xb0,
0x64,
0x40,
0x00,
},
{
0xff,
0x67,
0x0f,
0xb4,
},
{
0x50,
0x9e,
0x33,
0x8b,
},
{
0x5d,
0x58,
0x9f,
0x1a,
},
{
0xfe,
0xe7,
0x21,
0x12,
},
{
0x33,
0x75,
0x32,
0x59,
},
{
0x6a,
0x43,
0x4f,
0x8c,
},
{
0xfe,
0x28,
0xb7,
0x29,
},
{
0xe7,
0x5c,
0xc6,
0xec,
},
{
0x69,
0x7e,
0x8d,
0x54,
},
{
0x63,
0x68,
0x8b,
0x0f,
},
{
0x65,
0x0b,
0x62,
0xb4,
},
{
0xb6,
0xbc,
0x18,
0x40,
},
{
0x5d,
0x07,
0x45,
0x05,
},
{
0x24,
0x42,
0xfd,
0x2e,
},
{
0x7b,
0xb7,
0x86,
0x3a,
},
{
0x77,
0x05,
0xd5,
0x48,
},
{
0xd7,
0x52,
0x08,
0xb1,
},
{
0xb6,
0xd4,
0x99,
0xc8,
},
{
0x08,
0x92,
0x20,
0x2e,
},
{
0x69,
0xe1,
0x2c,
0xe3,
},
{
0x8d,
0xb5,
0x80,
0xe5,
},
{
0x36,
0x97,
0x64,
0xc6,
},
{
0x01,
0x6e,
0x02,
0x04,
},
{
0x3b,
0x85,
0xf3,
0xd4,
},
{
0xfe,
0xdb,
0x66,
0xbe,
},
{
0x1e,
0x69,
0x2a,
0x3a,
},
{
0xc6,
0x89,
0x84,
0xc0,
},
{
0xa5,
0xc5,
0xb9,
0x40,
},
{
0x9b,
0xe9,
0xe8,
0x8c,
},
{
0x7d,
0xbc,
0x81,
0x40,
},
{
0x7c,
0x07,
0x8e,
0xc5,
},
{
0xd4,
0xe7,
0x6c,
0x73,
},
{
0x42,
0x8f,
0xcb,
0xb9,
},
{
0xbd,
0x83,
0x99,
0x7a,
},
{
0x59,
0xea,
0x4a,
0x74,
},
};
const uint8_t vectors_hsip64[64][8] = {
{
0x21,
0x8d,
0x1f,
0x59,
0xb9,
0xb8,
0x3c,
0xc8,
},
{
0xbe,
0x55,
0x24,
0x12,
0xf8,
0x38,
0x73,
0x15,
},
{
0x06,
0x4f,
0x39,
0xef,
0x7c,
0x50,
0xeb,
0x57,
},
{
0xce,
0x0f,
0x1a,
0x45,
0xf7,
0x06,
0x06,
0x79,
},
{
0xd5,
0xe7,
0x8a,
0x17,
0x5b,
0xe5,
0x2e,
0xa1,
},
{
0xcb,
0x9d,
0x7c,
0x3f,
0x2f,
0x3d,
0xb5,
0x80,
},
{
0xce,
0x3e,
0x91,
0x35,
0x8a,
0xa2,
0xbc,
0x25,
},
{
0xff,
0x20,
0x27,
0x28,
0xb0,
0x7b,
0xc6,
0x84,
},
{
0xed,
0xfe,
0xe8,
0x20,
0xbc,
0xe4,
0x85,
0x8c,
},
{
0x5b,
0x51,
0xcc,
0xcc,
0x13,
0x88,
0x83,
0x07,
},
{
0x95,
0xb0,
0x46,
0x9f,
0x06,
0xa6,
0xf2,
0xee,
},
{
0xae,
0x26,
0x33,
0x39,
0x94,
0xdd,
0xcd,
0x48,
},
{
0x7b,
0xc7,
0x1f,
0x9f,
0xae,
0xf5,
0xc7,
0x99,
},
{
0x5a,
0x23,
0x52,
0xd7,
0x5a,
0x0c,
0x37,
0x44,
},
{
0x3b,
0xb1,
0xa8,
0x70,
0xea,
0xe8,
0xe6,
0x58,
},
{
0x21,
0x7d,
0x0b,
0xcb,
0x4e,
0x81,
0xc9,
0x02,
},
{
0x73,
0x36,
0xaa,
0xd2,
0x5f,
0x7b,
0xf3,
0xb5,
},
{
0x37,
0xad,
0xc0,
0x64,
0x1c,
0x4c,
0x4f,
0x6a,
},
{
0xc9,
0xb2,
0xdb,
0x2b,
0x9a,
0x3e,
0x42,
0xf9,
},
{
0xf9,
0x10,
0xe4,
0x80,
0x20,
0xab,
0x36,
0x3c,
},
{
0x1b,
0xf5,
0x2b,
0x0a,
0x6f,
0xee,
0xa7,
0xdb,
},
{
0x00,
0x74,
0x1d,
0xc2,
0x69,
0xe8,
0xb3,
0xef,
},
{
0xe2,
0x01,
0x03,
0xfa,
0x1b,
0xa7,
0x76,
0xef,
},
{
0x4c,
0x22,
0x10,
0xe5,
0x4b,
0x68,
0x1d,
0x73,
},
{
0x70,
0x74,
0x10,
0x45,
0xae,
0x3f,
0xa6,
0xf1,
},
{
0x0c,
0x86,
0x40,
0x37,
0x39,
0x71,
0x40,
0x38,
},
{
0x0d,
0x89,
0x9e,
0xd8,
0x11,
0x29,
0x23,
0xf0,
},
{
0x22,
0x6b,
0xf5,
0xfa,
0xb8,
0x1e,
0xe1,
0xb8,
},
{
0x2d,
0x92,
0x5f,
0xfb,
0x1e,
0x00,
0x16,
0xb5,
},
{
0x36,
0x19,
0x58,
0xd5,
0x2c,
0xee,
0x10,
0xf1,
},
{
0x29,
0x1a,
0xaf,
0x86,
0x48,
0x98,
0x17,
0x9d,
},
{
0x86,
0x3c,
0x7f,
0x15,
0x5c,
0x34,
0x11,
0x7c,
},
{
0x28,
0x70,
0x9d,
0x46,
0xd8,
0x11,
0x62,
0x6c,
},
{
0x24,
0x84,
0x77,
0x68,
0x1d,
0x28,
0xf8,
0x9c,
},
{
0x83,
0x24,
0xe4,
0xd7,
0x52,
0x8f,
0x98,
0x30,
},
{
0xf9,
0xef,
0xd4,
0xe1,
0x3a,
0xea,
0x6b,
0xd8,
},
{
0x86,
0xd6,
0x7a,
0x40,
0xec,
0x42,
0x76,
0xdc,
},
{
0x3f,
0x62,
0x92,
0xec,
0xcc,
0xa9,
0x7e,
0x35,
},
{
0xcb,
0xd9,
0x2e,
0xe7,
0x24,
0xd4,
0x21,
0x09,
},
{
0x36,
0x8d,
0xf6,
0x80,
0x8d,
0x40,
0x3d,
0x79,
},
{
0x5b,
0x38,
0xc8,
0x1c,
0x67,
0xc8,
0xae,
0x4c,
},
{
0x95,
0xab,
0x71,
0x89,
0xd4,
0x39,
0xac,
0xb3,
},
{
0xa9,
0x1a,
0x52,
0xc0,
0x25,
0x32,
0x70,
0x24,
},
{
0x5b,
0x00,
0x87,
0xc6,
0x95,
0x28,
0xac,
0xea,
},
{
0x1e,
0x30,
0xf3,
0xad,
0x27,
0xdc,
0xb1,
0x5a,
},
{
0x69,
0x7f,
0x5c,
0x9a,
0x90,
0x32,
0x4e,
0xd4,
},
{
0x49,
0x5c,
0x0f,
0x99,
0x55,
0x57,
0xdc,
0x38,
},
{
0x94,
0x27,
0x20,
0x2a,
0x3c,
0x29,
0xf9,
0x4d,
},
{
0xa9,
0xea,
0xa8,
0xc0,
0x4b,
0xa9,
0x3e,
0x3e,
},
{
0xee,
0xa4,
0xc1,
0x73,
0x7d,
0x01,
0x12,
0x18,
},
{
0x91,
0x2d,
0x56,
0x8f,
0xd8,
0xf6,
0x5a,
0x49,
},
{
0x56,
0x91,
0x95,
0x96,
0xb0,
0xff,
0x5c,
0x97,
},
{
0x02,
0x44,
0x5a,
0x79,
0x98,
0xf5,
0x50,
0xe1,
},
{
0x86,
0xec,
0x46,
0x6c,
0xe7,
0x1d,
0x1f,
0xb2,
},
{
0x35,
0x95,
0x69,
0xe7,
0xd2,
0x89,
0xe3,
0xbc,
},
{
0x87,
0x1b,
0x05,
0xca,
0x62,
0xbb,
0x7c,
0x96,
},
{
0xa1,
0xa4,
0x92,
0xf9,
0x42,
0xf1,
0x5f,
0x1d,
},
{
0x12,
0xec,
0x26,
0x7f,
0xf6,
0x09,
0x5b,
0x6e,
},
{
0x5d,
0x1b,
0x5e,
0xa1,
0xb2,
0x31,
0xd8,
0x9d,
},
{
0xd8,
0xcf,
0xb4,
0x45,
0x3f,
0x92,
0xee,
0x54,
},
{
0xd6,
0x76,
0x28,
0x90,
0xbf,
0x26,
0xe4,
0x60,
},
{
0x31,
0x35,
0x63,
0xa4,
0xb7,
0xed,
0x5c,
0xf3,
},
{
0xf9,
0x0b,
0x3a,
0xb5,
0x72,
0xd4,
0x66,
0x93,
},
{
0x2e,
0xa6,
0x3c,
0x71,
0xbf,
0x32,
0x60,
0x87,
},
};

103
3rd/pcre2/LICENCE.md Normal file
View File

@@ -0,0 +1,103 @@
PCRE2 License
=============
| SPDX-License-Identifier: | BSD-3-Clause WITH PCRE2-exception |
|---------|-------|
PCRE2 is a library of functions to support regular expressions whose syntax
and semantics are as close as possible to those of the Perl 5 language.
Releases 10.00 and above of PCRE2 are distributed under the terms of the "BSD"
licence, as specified below, with one exemption for certain binary
redistributions. The documentation for PCRE2, supplied in the "doc" directory,
is distributed under the same terms as the software itself. The data in the
testdata directory is not copyrighted and is in the public domain.
The basic library functions are written in C and are freestanding. Also
included in the distribution is a just-in-time compiler that can be used to
optimize pattern matching. This is an optional feature that can be omitted when
the library is built.
COPYRIGHT
---------
### The basic library functions
Written by: Philip Hazel
Email local part: Philip.Hazel
Email domain: gmail.com
Retired from University of Cambridge Computing Service,
Cambridge, England.
Copyright (c) 1997-2007 University of Cambridge
Copyright (c) 2007-2024 Philip Hazel
All rights reserved.
### PCRE2 Just-In-Time compilation support
Written by: Zoltan Herczeg
Email local part: hzmester
Email domain: freemail.hu
Copyright (c) 2010-2024 Zoltan Herczeg
All rights reserved.
### Stack-less Just-In-Time compiler
Written by: Zoltan Herczeg
Email local part: hzmester
Email domain: freemail.hu
Copyright (c) 2009-2024 Zoltan Herczeg
All rights reserved.
### All other contributions
Many other contributors have participated in the authorship of PCRE2. As PCRE2
has never required a Contributor Licensing Agreement, or other copyright
assignment agreement, all contributions have copyright retained by each
original contributor or their employer.
THE "BSD" LICENCE
-----------------
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notices,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notices, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the University of Cambridge nor the names of any
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
EXEMPTION FOR BINARY LIBRARY-LIKE PACKAGES
------------------------------------------
The second condition in the BSD licence (covering binary redistributions) does
not apply all the way down a chain of software. If binary package A includes
PCRE2, it must respect the condition, but if package B is software that
includes package A, the condition is not imposed on package B unless it uses
PCRE2 independently.
End

View File

@@ -5,8 +5,8 @@ if (POLICY CMP0177)
endif() endif()
project(PIP) project(PIP)
set(PIP_MAJOR 5) set(PIP_MAJOR 5)
set(PIP_MINOR 4) set(PIP_MINOR 5)
set(PIP_REVISION 0) set(PIP_REVISION 2)
set(PIP_SUFFIX ) set(PIP_SUFFIX )
set(PIP_COMPANY SHS) set(PIP_COMPANY SHS)
set(PIP_DOMAIN org.SHS) set(PIP_DOMAIN org.SHS)
@@ -116,8 +116,10 @@ macro(pip_module NAME LIBS LABEL INCLUDES SOURCES MSG)
list(REMOVE_ITEM HS ${PHS}) list(REMOVE_ITEM HS ${PHS})
endif() endif()
if (NOT "x${SOURCES}" STREQUAL "x") if (NOT "x${SOURCES}" STREQUAL "x")
file(GLOB_RECURSE ASRC "${SOURCES}/*.cpp" "${SOURCES}/*.c") foreach (_s ${SOURCES})
list(APPEND CPPS ${ASRC}) file(GLOB_RECURSE ASRC "${_s}/*.cpp" "${_s}/*.c")
list(APPEND CPPS ${ASRC})
endforeach()
endif() endif()
list(APPEND HDRS ${HS}) list(APPEND HDRS ${HS})
list(APPEND PHDRS ${PHS}) list(APPEND PHDRS ${PHS})
@@ -219,11 +221,18 @@ if (TESTS)
add_subdirectory(tests) add_subdirectory(tests)
endif() endif()
if(PIP_FREERTOS) if(PIP_MICRO)
add_definitions(-DPIP_FREERTOS) add_definitions(-DMICRO_PIP)
set(ICU OFF) set(ICU OFF)
set(LOCAL ON) set(LOCAL ON)
endif() endif()
if(PIP_FREERTOS)
add_definitions(-DPIP_FREERTOS)
endif()
if(DEFINED PICO_BOARD)
add_definitions(-DPICO_SDK)
message(STATUS "Building PIP for Pi Pico SDK ${PICO_SDK_VERSION_STRING}")
endif()
# Check Bessel functions # Check Bessel functions
set(CMAKE_REQUIRED_INCLUDES math.h) set(CMAKE_REQUIRED_INCLUDES math.h)
@@ -327,7 +336,7 @@ if ((NOT DEFINED SHSTKPROJECT) AND (DEFINED ANDROID_PLATFORM))
#message("${ANDROID_NDK}/sysroot/usr/include") #message("${ANDROID_NDK}/sysroot/usr/include")
endif() endif()
if(NOT PIP_FREERTOS) if(NOT PIP_MICRO)
if(WIN32) if(WIN32)
if(${C_COMPILER} STREQUAL "cl.exe") if(${C_COMPILER} STREQUAL "cl.exe")
else() else()
@@ -348,7 +357,7 @@ if(NOT PIP_FREERTOS)
endif() endif()
endif() endif()
set(PIP_LIBS) set(PIP_LIBS)
if(PIP_FREERTOS) if(PIP_MICRO)
set(PIP_LIBS ${LIBS_MAIN}) set(PIP_LIBS ${LIBS_MAIN})
else() else()
foreach(LIB_ ${LIBS_MAIN}) foreach(LIB_ ${LIBS_MAIN})
@@ -362,11 +371,11 @@ if(WIN32)
endif() endif()
else() else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
if(DEFINED ENV{QNX_HOST} OR PIP_FREERTOS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth-32")
endif()
endif() endif()
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}") set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
if(DEFINED ENV{QNX_HOST} OR PIP_MICRO)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth-32")
endif()
set(PCRE2_BUILD_PCRE2_8 OFF) set(PCRE2_BUILD_PCRE2_8 OFF)
set(PCRE2_BUILD_PCRE2_16 ON ) set(PCRE2_BUILD_PCRE2_16 ON )
@@ -380,7 +389,7 @@ endif()
add_subdirectory("3rd/pcre2" EXCLUDE_FROM_ALL) add_subdirectory("3rd/pcre2" EXCLUDE_FROM_ALL)
list(APPEND LIBS_MAIN pcre2-16-static) list(APPEND LIBS_MAIN pcre2-16-static)
pip_module(main "${LIBS_MAIN}" "PIP main library" "" "${PIP_3PL_DIR}/BLAKE2" "") pip_module(main "${LIBS_MAIN}" "PIP main library" "" "${PIP_3PL_DIR}/BLAKE2;${PIP_3PL_DIR}/SipHash" "")
generate_export_header(pip) generate_export_header(pip)
list(APPEND HDRS "${CMAKE_CURRENT_BINARY_DIR}/pip_export.h") list(APPEND HDRS "${CMAKE_CURRENT_BINARY_DIR}/pip_export.h")
@@ -404,7 +413,7 @@ endif()
if (NOT CROSSTOOLS) if (NOT CROSSTOOLS)
if (NOT PIP_FREERTOS) if (NOT PIP_MICRO)
if (PIP_BUILD_CONSOLE) if (PIP_BUILD_CONSOLE)
pip_module(console "" "PIP console support" "" "" "") pip_module(console "" "PIP console support" "" "" "")
@@ -622,7 +631,7 @@ string(REPLACE ";" "," PIP_EXPORTS_STR "${PIP_EXPORTS}")
target_compile_definitions(pip PRIVATE "PICODE_DEFINES=\"${PIP_EXPORTS_STR}\"") target_compile_definitions(pip PRIVATE "PICODE_DEFINES=\"${PIP_EXPORTS_STR}\"")
if(NOT PIP_FREERTOS) if(NOT PIP_MICRO)
# Auxiliary # Auxiliary
if (NOT CROSSTOOLS) if (NOT CROSSTOOLS)
@@ -699,7 +708,7 @@ if(NOT LOCAL)
install(TARGETS ${PIP_MODULES} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) install(TARGETS ${PIP_MODULES} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
endif() endif()
else() else()
if(NOT PIP_FREERTOS) if(NOT PIP_MICRO)
if(WIN32) if(WIN32)
install(TARGETS ${PIP_MODULES} RUNTIME DESTINATION bin) install(TARGETS ${PIP_MODULES} RUNTIME DESTINATION bin)
install(TARGETS ${PIP_MODULES} ARCHIVE DESTINATION lib) install(TARGETS ${PIP_MODULES} ARCHIVE DESTINATION lib)
@@ -727,7 +736,7 @@ endif()
# #
# Build Documentation # Build Documentation
# #
if ((NOT PIP_FREERTOS) AND (NOT CROSSTOOLS)) if ((NOT PIP_MICRO) AND (NOT CROSSTOOLS))
include(PIPDocumentation) include(PIPDocumentation)
find_package(Doxygen) find_package(Doxygen)
if(DOXYGEN_FOUND) if(DOXYGEN_FOUND)
@@ -796,7 +805,7 @@ message(" Type : ${CMAKE_BUILD_TYPE}")
if (NOT LOCAL) if (NOT LOCAL)
message(" Install: \"${CMAKE_INSTALL_PREFIX}\"") message(" Install: \"${CMAKE_INSTALL_PREFIX}\"")
else() else()
if(NOT PIP_FREERTOS) if(NOT PIP_MICRO)
message(" Install: local \"bin\", \"lib\" and \"include\"") message(" Install: local \"bin\", \"lib\" and \"include\"")
endif() endif()
endif() endif()
@@ -829,7 +838,7 @@ message(" Utilites:")
foreach(_util ${PIP_UTILS_LIST}) foreach(_util ${PIP_UTILS_LIST})
message(" * ${_util}") message(" * ${_util}")
endforeach() endforeach()
if(NOT PIP_FREERTOS) if(NOT PIP_MICRO)
message("") message("")
message(" Using libraries:") message(" Using libraries:")
foreach(LIB_ ${LIBS_STATUS}) foreach(LIB_ ${LIBS_STATUS})

View File

@@ -71,7 +71,7 @@ if (NOT BUILDING_PIP)
find_library(PTHREAD_LIBRARY pthread) find_library(PTHREAD_LIBRARY pthread)
find_library(UTIL_LIBRARY util) find_library(UTIL_LIBRARY util)
set(_PIP_ADD_LIBS_ ${PTHREAD_LIBRARY} ${UTIL_LIBRARY}) set(_PIP_ADD_LIBS_ ${PTHREAD_LIBRARY} ${UTIL_LIBRARY})
if((NOT DEFINED ENV{QNX_HOST}) AND (NOT APPLE) AND (NOT PIP_FREERTOS)) if((NOT DEFINED ENV{QNX_HOST}) AND (NOT APPLE) AND (NOT PIP_MICRO))
find_library(RT_LIBRARY rt) find_library(RT_LIBRARY rt)
list(APPEND _PIP_ADD_LIBS_ ${RT_LIBRARY}) list(APPEND _PIP_ADD_LIBS_ ${RT_LIBRARY})
endif() endif()

View File

@@ -17,6 +17,7 @@ list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/thread")
set(COMPONENT_PRIV_REQUIRES pthread lwip freertos vfs spi_flash libsodium) set(COMPONENT_PRIV_REQUIRES pthread lwip freertos vfs spi_flash libsodium)
register_component() register_component()
set(PIP_FREERTOS ON) set(PIP_FREERTOS ON)
set(PIP_MICRO ON)
set(LIB OFF) set(LIB OFF)
set(INCLUDE_DIRS ${IDF_INCLUDE_DIRECTORIES}) set(INCLUDE_DIRS ${IDF_INCLUDE_DIRECTORIES})
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/newlib/platform_include) list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/newlib/platform_include)

Binary file not shown.

View File

@@ -622,6 +622,39 @@
<translation>Ошибка: Режим ReadWrite не поддерживается, используйте WriteOnly или ReadOnly</translation> <translation>Ошибка: Режим ReadWrite не поддерживается, используйте WriteOnly или ReadOnly</translation>
</message> </message>
</context> </context>
<context>
<name>PIUnitsMass</name>
<message>
<location filename="../libs/main/units/piunits_class_mass.cpp" line="35"/>
<source>g</source>
<translation>г</translation>
</message>
<message>
<location filename="../libs/main/units/piunits_class_mass.cpp" line="37"/>
<source>℥</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../libs/main/units/piunits_class_mass.cpp" line="36"/>
<source>lb</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../libs/main/units/piunits_class_mass.cpp" line="25"/>
<source>gram</source>
<translation>грамм</translation>
</message>
<message>
<location filename="../libs/main/units/piunits_class_mass.cpp" line="27"/>
<source>ounce</source>
<translation>унция</translation>
</message>
<message>
<location filename="../libs/main/units/piunits_class_mass.cpp" line="26"/>
<source>pound</source>
<translation>фунт</translation>
</message>
</context>
<context> <context>
<name>PIUnitsTime</name> <name>PIUnitsTime</name>
<message> <message>
@@ -815,15 +848,75 @@
<context> <context>
<name>PIUnitsDistance</name> <name>PIUnitsDistance</name>
<message> <message>
<location filename="../libs/main/units/piunits_class_distance.cpp" line="33"/> <location filename="../libs/main/units/piunits_class_distance.cpp" line="40"/>
<source>&quot;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../libs/main/units/piunits_class_distance.cpp" line="44"/>
<source>Å</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../libs/main/units/piunits_class_distance.cpp" line="39"/>
<source>m</source> <source>m</source>
<translation>м</translation> <translation>м</translation>
</message> </message>
<message>
<location filename="../libs/main/units/piunits_class_distance.cpp" line="45"/>
<source>au</source>
<translation>а. е.</translation>
</message>
<message>
<location filename="../libs/main/units/piunits_class_distance.cpp" line="42"/>
<source>ft</source>
<translation>фут</translation>
</message>
<message>
<location filename="../libs/main/units/piunits_class_distance.cpp" line="43"/>
<source>yd</source>
<translation>ярд</translation>
</message>
<message>
<location filename="../libs/main/units/piunits_class_distance.cpp" line="27"/>
<source>mil</source>
<translation>мил</translation>
</message>
<message>
<location filename="../libs/main/units/piunits_class_distance.cpp" line="28"/>
<source>foot</source>
<translation>фут</translation>
</message>
<message>
<location filename="../libs/main/units/piunits_class_distance.cpp" line="26"/>
<source>inch</source>
<translation>дюйм</translation>
</message>
<message>
<location filename="../libs/main/units/piunits_class_distance.cpp" line="41"/>
<source>thou</source>
<translation>мил</translation>
</message>
<message>
<location filename="../libs/main/units/piunits_class_distance.cpp" line="29"/>
<source>yard</source>
<translation>ярд</translation>
</message>
<message> <message>
<location filename="../libs/main/units/piunits_class_distance.cpp" line="25"/> <location filename="../libs/main/units/piunits_class_distance.cpp" line="25"/>
<source>meter</source> <source>meter</source>
<translation>метр</translation> <translation>метр</translation>
</message> </message>
<message>
<location filename="../libs/main/units/piunits_class_distance.cpp" line="30"/>
<source>angstrom</source>
<translation>ангстрем</translation>
</message>
<message>
<location filename="../libs/main/units/piunits_class_distance.cpp" line="31"/>
<source>astronomical unit</source>
<translation>астрономическая единица</translation>
</message>
</context> </context>
<context> <context>
<name>PIUnitsPressure</name> <name>PIUnitsPressure</name>

View File

@@ -113,7 +113,7 @@ bool PISystemMonitor::startOnProcess(int pID, PISystemTime interval) {
} }
# endif # endif
# else # else
PRIVATE->hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pID_); PRIVATE->hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pID_);
if (PRIVATE->hProc == 0) { if (PRIVATE->hProc == 0) {
piCoutObj << "Can`t open process with ID = %1, %2!"_tr("PISystemMonitor").arg(pID_).arg(errorString()); piCoutObj << "Can`t open process with ID = %1, %2!"_tr("PISystemMonitor").arg(pID_).arg(errorString());
return false; return false;
@@ -178,6 +178,9 @@ PISystemTime uint64toST(uint64_t v) {
void PISystemMonitor::run() { void PISystemMonitor::run() {
cur_tm.clear(); cur_tm.clear();
tbid.clear(); tbid.clear();
ProcessStats tstat;
tstat.ID = pID_;
#ifndef PIP_NO_THREADS
__PIThreadCollection * pitc = __PIThreadCollection::instance(); __PIThreadCollection * pitc = __PIThreadCollection::instance();
pitc->lock(); pitc->lock();
PIVector<PIThread *> tv = pitc->threads(); PIVector<PIThread *> tv = pitc->threads();
@@ -185,16 +188,14 @@ void PISystemMonitor::run() {
if (t->isPIObject()) tbid[t->tid()] = t->name(); if (t->isPIObject()) tbid[t->tid()] = t->name();
pitc->unlock(); pitc->unlock();
// piCout << tbid.keys().toType<uint>(); // piCout << tbid.keys().toType<uint>();
ProcessStats tstat; # ifdef FREERTOS
tstat.ID = pID_;
#ifdef MICRO_PIP
for (auto * t: tv) for (auto * t: tv)
if (t->isPIObject()) gatherThread(t->tid()); if (t->isPIObject()) gatherThread(t->tid());
#else # else // FREERTOS
# ifndef WINDOWS # ifndef WINDOWS
double delay_ms = delay_.toMilliseconds(); double delay_ms = delay_.toMilliseconds();
tbid[pID_] = "main"; tbid[pID_] = "main";
# ifdef MAC_OS # ifdef MAC_OS
rusage_info_current ru; rusage_info_current ru;
proc_pid_rusage(pID_, RUSAGE_INFO_CURRENT, (rusage_info_t *)&ru); proc_pid_rusage(pID_, RUSAGE_INFO_CURRENT, (rusage_info_t *)&ru);
// piCout << PISystemTime(((uint*)&(ru.ri_user_time))[1], ((uint*)&(ru.ri_user_time))[0]); // piCout << PISystemTime(((uint*)&(ru.ri_user_time))[1], ((uint*)&(ru.ri_user_time))[0]);
@@ -210,7 +211,7 @@ void PISystemMonitor::run() {
tstat.cpu_load_user = 100.f * (PRIVATE->cpu_u_cur - PRIVATE->cpu_u_prev).toMilliseconds() / delay_ms; tstat.cpu_load_user = 100.f * (PRIVATE->cpu_u_cur - PRIVATE->cpu_u_prev).toMilliseconds() / delay_ms;
cycle = 0; cycle = 0;
// piCout << (PRIVATE->cpu_u_cur - PRIVATE->cpu_u_prev).toMilliseconds() / delay_ms; // piCout << (PRIVATE->cpu_u_cur - PRIVATE->cpu_u_prev).toMilliseconds() / delay_ms;
# else # else // MAC_OS
PRIVATE->file.seekToBegin(); PRIVATE->file.seekToBegin();
PIString str = PIString::fromAscii(PRIVATE->file.readAll()); PIString str = PIString::fromAscii(PRIVATE->file.readAll());
int si = str.find('(') + 1, fi = 0, cc = 1; int si = str.find('(') + 1, fi = 0, cc = 1;
@@ -264,8 +265,8 @@ void PISystemMonitor::run() {
if (i.flags[PIFile::FileInfo::Dot] || i.flags[PIFile::FileInfo::DotDot]) continue; if (i.flags[PIFile::FileInfo::Dot] || i.flags[PIFile::FileInfo::DotDot]) continue;
gatherThread(i.name().toInt()); gatherThread(i.name().toInt());
} }
# endif # endif // MAC_OS
# else # else // WINDOWS
if (GetProcessMemoryInfo(PRIVATE->hProc, &PRIVATE->mem_cnt, sizeof(PRIVATE->mem_cnt)) != 0) { if (GetProcessMemoryInfo(PRIVATE->hProc, &PRIVATE->mem_cnt, sizeof(PRIVATE->mem_cnt)) != 0) {
tstat.physical_memsize = PRIVATE->mem_cnt.WorkingSetSize; tstat.physical_memsize = PRIVATE->mem_cnt.WorkingSetSize;
} }
@@ -315,8 +316,9 @@ void PISystemMonitor::run() {
tstat.cpu_load_user = 0.f; tstat.cpu_load_user = 0.f;
} }
PRIVATE->tm.reset(); PRIVATE->tm.reset();
# endif # endif // WINDOWS
#endif # endif // FREERTOS
#endif // PIP_NO_THREADS
tstat.cpu_load_system = piClampf(tstat.cpu_load_system, 0.f, 100.f); tstat.cpu_load_system = piClampf(tstat.cpu_load_system, 0.f, 100.f);
tstat.cpu_load_user = piClampf(tstat.cpu_load_user, 0.f, 100.f); tstat.cpu_load_user = piClampf(tstat.cpu_load_user, 0.f, 100.f);
@@ -352,7 +354,7 @@ void PISystemMonitor::gatherThread(llong id) {
#ifdef MICRO_PIP #ifdef MICRO_PIP
ts.name = tbid.value(id, "<PIThread>"); ts.name = tbid.value(id, "<PIThread>");
#else #else
ts.name = tbid.value(id, "<non-PIThread>"); ts.name = tbid.value(id, "<non-PIThread>");
# ifndef WINDOWS # ifndef WINDOWS
PIFile f(PRIVATE->proc_dir + "task/" + PIString::fromNumber(id) + "/stat"); PIFile f(PRIVATE->proc_dir + "task/" + PIString::fromNumber(id) + "/stat");
// piCout << f.path(); // piCout << f.path();

View File

@@ -18,9 +18,11 @@
*/ */
#include "pikbdlistener.h" #include "pikbdlistener.h"
#include "piincludes_p.h" #ifndef MICRO_PIP
#include "piliterals.h"
#include "piwaitevent_p.h" # include "piincludes_p.h"
# include "piliterals.h"
# include "piwaitevent_p.h"
// clang-format off // clang-format off
#ifndef WINDOWS #ifndef WINDOWS
# include <termios.h> # include <termios.h>
@@ -49,7 +51,7 @@ bool PIKbdListener::exiting;
PIKbdListener * PIKbdListener::_object = 0; PIKbdListener * PIKbdListener::_object = 0;
#ifndef WINDOWS # ifndef WINDOWS
// unix // unix
const PIKbdListener::EscSeq PIKbdListener::esc_seq[] = { const PIKbdListener::EscSeq PIKbdListener::esc_seq[] = {
{"OA", PIKbdListener::UpArrow, 0, 0, 1}, {"OA", PIKbdListener::UpArrow, 0, 0, 1},
@@ -130,22 +132,22 @@ void setupTerminal(bool on) {
printf(on ? "h" : "l"); printf(on ? "h" : "l");
fflush(0); fflush(0);
} }
#endif # endif
PRIVATE_DEFINITION_START(PIKbdListener) PRIVATE_DEFINITION_START(PIKbdListener)
#ifdef WINDOWS # ifdef WINDOWS
void *hIn, *hOut; void *hIn, *hOut;
DWORD smode, tmode; DWORD smode, tmode;
CONSOLE_SCREEN_BUFFER_INFO sbi; CONSOLE_SCREEN_BUFFER_INFO sbi;
#else # else
struct termios sterm, tterm; struct termios sterm, tterm;
#endif # endif
#ifdef WINDOWS # ifdef WINDOWS
DWORD DWORD
#else # else
int int
#endif # endif
ret; ret;
PIWaitEvent event; PIWaitEvent event;
PRIVATE_DEFINITION_END(PIKbdListener) PRIVATE_DEFINITION_END(PIKbdListener)
@@ -154,13 +156,13 @@ PRIVATE_DEFINITION_END(PIKbdListener)
PIKbdListener::PIKbdListener(KBFunc slot, void * _d, bool startNow): PIThread() { PIKbdListener::PIKbdListener(KBFunc slot, void * _d, bool startNow): PIThread() {
setName("keyboard_listener"_a); setName("keyboard_listener"_a);
_object = this; _object = this;
#ifdef WINDOWS # ifdef WINDOWS
PRIVATE->hIn = GetStdHandle(STD_INPUT_HANDLE); PRIVATE->hIn = GetStdHandle(STD_INPUT_HANDLE);
PRIVATE->hOut = GetStdHandle(STD_OUTPUT_HANDLE); PRIVATE->hOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleMode(PRIVATE->hIn, &PRIVATE->smode); GetConsoleMode(PRIVATE->hIn, &PRIVATE->smode);
#else # else
tcgetattr(0, &PRIVATE->sterm); tcgetattr(0, &PRIVATE->sterm);
#endif # endif
ret_func = slot; ret_func = slot;
kbddata_ = _d; kbddata_ = _d;
dbl_interval = 400; dbl_interval = 400;
@@ -178,10 +180,10 @@ PIKbdListener::~PIKbdListener() {
void PIKbdListener::begin() { void PIKbdListener::begin() {
#ifdef WINDOWS # ifdef WINDOWS
GetConsoleMode(PRIVATE->hIn, &PRIVATE->tmode); GetConsoleMode(PRIVATE->hIn, &PRIVATE->tmode);
SetConsoleMode(PRIVATE->hIn, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT | ENABLE_EXTENDED_FLAGS); SetConsoleMode(PRIVATE->hIn, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT | ENABLE_EXTENDED_FLAGS);
#else # else
struct termios term; struct termios term;
tcgetattr(0, &term); tcgetattr(0, &term);
term.c_lflag &= ~(ECHO | ICANON); term.c_lflag &= ~(ECHO | ICANON);
@@ -189,11 +191,11 @@ void PIKbdListener::begin() {
PRIVATE->tterm = term; PRIVATE->tterm = term;
tcsetattr(0, TCSANOW, &term); tcsetattr(0, TCSANOW, &term);
setupTerminal(true); setupTerminal(true);
#endif # endif
} }
#ifdef WINDOWS # ifdef WINDOWS
PIKbdListener::KeyModifiers getModifiers(DWORD v, bool * shift = 0) { PIKbdListener::KeyModifiers getModifiers(DWORD v, bool * shift = 0) {
PIKbdListener::KeyModifiers ret; PIKbdListener::KeyModifiers ret;
bool ctrl = v & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED); bool ctrl = v & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED);
@@ -214,7 +216,7 @@ PIKbdListener::MouseButtons getButtons(DWORD v) {
if (v & FROM_LEFT_2ND_BUTTON_PRESSED) ret |= PIKbdListener::MouseMiddle; if (v & FROM_LEFT_2ND_BUTTON_PRESSED) ret |= PIKbdListener::MouseMiddle;
return ret; return ret;
} }
#endif # endif
void PIKbdListener::readKeyboard() { void PIKbdListener::readKeyboard() {
@@ -222,7 +224,7 @@ void PIKbdListener::readKeyboard() {
ke.modifiers = 0; ke.modifiers = 0;
char rc[8]; char rc[8];
piZeroMemory(rc, 8); piZeroMemory(rc, 8);
#ifdef WINDOWS # ifdef WINDOWS
INPUT_RECORD ir; INPUT_RECORD ir;
ReadConsoleInput(PRIVATE->hIn, &ir, 1, &(PRIVATE->ret)); ReadConsoleInput(PRIVATE->hIn, &ir, 1, &(PRIVATE->ret));
switch (ir.EventType) { switch (ir.EventType) {
@@ -406,7 +408,7 @@ void PIKbdListener::readKeyboard() {
} break; } break;
default: piMSleep(10); return; default: piMSleep(10); return;
} }
#else # else
tcsetattr(0, TCSANOW, &PRIVATE->tterm); tcsetattr(0, TCSANOW, &PRIVATE->tterm);
if (!PRIVATE->event.wait(0)) return; if (!PRIVATE->event.wait(0)) return;
PRIVATE->ret = read(0, rc, 8); PRIVATE->ret = read(0, rc, 8);
@@ -533,7 +535,7 @@ void PIKbdListener::readKeyboard() {
cout << endl;*/ cout << endl;*/
} }
if (ke.key == 0 && PRIVATE->ret > 1) ke.key = PIChar::fromSystem(rc).unicode16Code(); if (ke.key == 0 && PRIVATE->ret > 1) ke.key = PIChar::fromSystem(rc).unicode16Code();
#endif # endif
if ((rc[0] == '\n' || rc[0] == '\r') && PRIVATE->ret == 1) ke.key = Return; if ((rc[0] == '\n' || rc[0] == '\r') && PRIVATE->ret == 1) ke.key = Return;
if (exit_enabled && ke.key == exit_key) { if (exit_enabled && ke.key == exit_key) {
PIKbdListener::exiting = true; PIKbdListener::exiting = true;
@@ -560,30 +562,32 @@ bool PIKbdListener::stopAndWait(PISystemTime timeout) {
void PIKbdListener::end() { void PIKbdListener::end() {
// cout << "list end" << endl; // cout << "list end" << endl;
#ifdef WINDOWS # ifdef WINDOWS
SetConsoleMode(PRIVATE->hIn, PRIVATE->smode); SetConsoleMode(PRIVATE->hIn, PRIVATE->smode);
#else # else
tcsetattr(0, TCSANOW, &PRIVATE->sterm); tcsetattr(0, TCSANOW, &PRIVATE->sterm);
setupTerminal(false); setupTerminal(false);
#endif # endif
} }
void PIKbdListener::setActive(bool yes) { void PIKbdListener::setActive(bool yes) {
is_active = yes; is_active = yes;
if (is_active) { if (is_active) {
#ifdef WINDOWS # ifdef WINDOWS
SetConsoleMode(PRIVATE->hIn, PRIVATE->tmode); SetConsoleMode(PRIVATE->hIn, PRIVATE->tmode);
#else # else
tcsetattr(0, TCSANOW, &PRIVATE->tterm); tcsetattr(0, TCSANOW, &PRIVATE->tterm);
setupTerminal(true); setupTerminal(true);
#endif # endif
} else { } else {
#ifdef WINDOWS # ifdef WINDOWS
SetConsoleMode(PRIVATE->hIn, PRIVATE->smode); SetConsoleMode(PRIVATE->hIn, PRIVATE->smode);
#else # else
tcsetattr(0, TCSANOW, &PRIVATE->sterm); tcsetattr(0, TCSANOW, &PRIVATE->sterm);
setupTerminal(false); setupTerminal(false);
#endif # endif
} }
} }
#endif // MICRO_PIP

View File

@@ -26,15 +26,19 @@
#ifndef PIKBDLISTENER_H #ifndef PIKBDLISTENER_H
#define PIKBDLISTENER_H #define PIKBDLISTENER_H
#include "pithread.h" #include "pibase.h"
#include "pitime.h"
#define WAIT_FOR_EXIT \ #ifndef MICRO_PIP
while (!PIKbdListener::exiting) \
piMSleep(PIP_MIN_MSLEEP * 5); \ # include "pithread.h"
if (PIKbdListener::instance()) { \ # include "pitime.h"
if (!PIKbdListener::instance()->stopAndWait(PISystemTime::fromSeconds(1))) PIKbdListener::instance()->terminate(); \
} # define WAIT_FOR_EXIT \
while (!PIKbdListener::exiting) \
piMSleep(PIP_MIN_MSLEEP * 5); \
if (PIKbdListener::instance()) { \
if (!PIKbdListener::instance()->stopAndWait(PISystemTime::fromSeconds(1))) PIKbdListener::instance()->terminate(); \
}
class PIP_EXPORT PIKbdListener: public PIThread { class PIP_EXPORT PIKbdListener: public PIThread {
@@ -231,7 +235,7 @@ private:
void run() override { readKeyboard(); } void run() override { readKeyboard(); }
void end() override; void end() override;
#ifndef WINDOWS # ifndef WINDOWS
struct PIP_EXPORT EscSeq { struct PIP_EXPORT EscSeq {
const char * seq; const char * seq;
int key; int key;
@@ -251,7 +255,7 @@ private:
}; };
static const EscSeq esc_seq[]; static const EscSeq esc_seq[];
#endif # endif
PRIVATE_DECLARATION(PIP_EXPORT) PRIVATE_DECLARATION(PIP_EXPORT)
KBFunc ret_func; KBFunc ret_func;
@@ -305,4 +309,5 @@ REGISTER_PIVARIANTSIMPLE(PIKbdListener::KeyEvent)
REGISTER_PIVARIANTSIMPLE(PIKbdListener::MouseEvent) REGISTER_PIVARIANTSIMPLE(PIKbdListener::MouseEvent)
REGISTER_PIVARIANTSIMPLE(PIKbdListener::WheelEvent) REGISTER_PIVARIANTSIMPLE(PIKbdListener::WheelEvent)
#endif // MICRO_PIP
#endif // PIKBDLISTENER_H #endif // PIKBDLISTENER_H

View File

@@ -18,18 +18,19 @@
*/ */
#include "piwaitevent_p.h" #include "piwaitevent_p.h"
#ifdef WINDOWS #ifndef MICRO_PIP
# ifdef WINDOWS
// # ifdef _WIN32_WINNT // # ifdef _WIN32_WINNT
// # undef _WIN32_WINNT // # undef _WIN32_WINNT
// # define _WIN32_WINNT 0x0600 // # define _WIN32_WINNT 0x0600
// # endif // # endif
# include <synchapi.h> # include <synchapi.h>
#else # else
# include <errno.h> # include <errno.h>
# include <fcntl.h> # include <fcntl.h>
# include <sys/ioctl.h> # include <sys/ioctl.h>
#endif # endif
#include "pistring.h" # include "pistring.h"
PIWaitEvent::~PIWaitEvent() { PIWaitEvent::~PIWaitEvent() {
@@ -39,12 +40,12 @@ PIWaitEvent::~PIWaitEvent() {
void PIWaitEvent::create() { void PIWaitEvent::create() {
destroy(); destroy();
#ifdef WINDOWS # ifdef WINDOWS
event = CreateEventA(NULL, TRUE, FALSE, NULL); event = CreateEventA(NULL, TRUE, FALSE, NULL);
if (!event) { if (!event) {
piCout << "Error with CreateEventA:" << errorString(); piCout << "Error with CreateEventA:" << errorString();
} }
#else # else
for (int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i)
piZeroMemory(fds[i]); piZeroMemory(fds[i]);
if (::pipe(pipe_fd) < 0) { if (::pipe(pipe_fd) < 0) {
@@ -53,34 +54,34 @@ void PIWaitEvent::create() {
fcntl(pipe_fd[ReadEnd], F_SETFL, O_NONBLOCK); fcntl(pipe_fd[ReadEnd], F_SETFL, O_NONBLOCK);
fcntl(pipe_fd[WriteEnd], F_SETFL, O_NONBLOCK); fcntl(pipe_fd[WriteEnd], F_SETFL, O_NONBLOCK);
} }
#endif # endif
} }
void PIWaitEvent::destroy() { void PIWaitEvent::destroy() {
#ifdef WINDOWS # ifdef WINDOWS
if (event) { if (event) {
CloseHandle(event); CloseHandle(event);
event = NULL; event = NULL;
} }
#else # else
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
if (pipe_fd[i] != 0) { if (pipe_fd[i] != 0) {
::close(pipe_fd[i]); ::close(pipe_fd[i]);
pipe_fd[i] = 0; pipe_fd[i] = 0;
} }
} }
#endif # endif
} }
bool PIWaitEvent::wait(int fd, CheckRole role) { bool PIWaitEvent::wait(int fd, CheckRole role) {
if (!isCreate()) return false; if (!isCreate()) return false;
#ifdef WINDOWS # ifdef WINDOWS
DWORD ret = WaitForSingleObjectEx(event, INFINITE, TRUE); DWORD ret = WaitForSingleObjectEx(event, INFINITE, TRUE);
ResetEvent(event); ResetEvent(event);
if (ret == WAIT_IO_COMPLETION || ret == WAIT_FAILED) return false; if (ret == WAIT_IO_COMPLETION || ret == WAIT_FAILED) return false;
#else # else
if (fd == -1) return false; if (fd == -1) return false;
int nfds = piMaxi(pipe_fd[ReadEnd], fd) + 1; int nfds = piMaxi(pipe_fd[ReadEnd], fd) + 1;
int fd_index = role; int fd_index = role;
@@ -97,18 +98,18 @@ bool PIWaitEvent::wait(int fd, CheckRole role) {
if (sr == EBADF || sr == EINTR) return false; if (sr == EBADF || sr == EINTR) return false;
if (FD_ISSET(fd, &(fds[CheckExeption]))) return true; if (FD_ISSET(fd, &(fds[CheckExeption]))) return true;
return FD_ISSET(fd, &(fds[fd_index])); return FD_ISSET(fd, &(fds[fd_index]));
#endif # endif
return true; return true;
} }
bool PIWaitEvent::sleep(int us) { bool PIWaitEvent::sleep(int us) {
if (!isCreate()) return false; if (!isCreate()) return false;
#ifdef WINDOWS # ifdef WINDOWS
DWORD ret = WaitForSingleObjectEx(event, us / 1000, TRUE); DWORD ret = WaitForSingleObjectEx(event, us / 1000, TRUE);
ResetEvent(event); ResetEvent(event);
return ret == WAIT_TIMEOUT; return ret == WAIT_TIMEOUT;
#else # else
int nfds = pipe_fd[ReadEnd] + 1; int nfds = pipe_fd[ReadEnd] + 1;
FD_ZERO(&(fds[CheckRead])); FD_ZERO(&(fds[CheckRead]));
FD_SET(pipe_fd[ReadEnd], &(fds[CheckRead])); FD_SET(pipe_fd[ReadEnd], &(fds[CheckRead]));
@@ -120,34 +121,36 @@ bool PIWaitEvent::sleep(int us) {
while (::read(pipe_fd[ReadEnd], &buf, sizeof(buf)) > 0) while (::read(pipe_fd[ReadEnd], &buf, sizeof(buf)) > 0)
; ;
return ret == 0; return ret == 0;
#endif # endif
} }
void PIWaitEvent::interrupt() { void PIWaitEvent::interrupt() {
if (!isCreate()) return; if (!isCreate()) return;
#ifdef WINDOWS # ifdef WINDOWS
SetEvent(event); SetEvent(event);
#else # else
auto _r = ::write(pipe_fd[WriteEnd], "", 1); auto _r = ::write(pipe_fd[WriteEnd], "", 1);
NO_UNUSED(_r); NO_UNUSED(_r);
#endif # endif
} }
bool PIWaitEvent::isCreate() const { bool PIWaitEvent::isCreate() const {
#ifdef WINDOWS # ifdef WINDOWS
return event; return event;
#else # else
return pipe_fd[ReadEnd] != 0; return pipe_fd[ReadEnd] != 0;
#endif # endif
} }
void * PIWaitEvent::getEvent() const { void * PIWaitEvent::getEvent() const {
#ifdef WINDOWS # ifdef WINDOWS
return event; return event;
#else # else
return nullptr; return nullptr;
#endif # endif
} }
#endif // MICRO_PIP

View File

@@ -20,7 +20,9 @@
#ifndef PIWAITEVENT_P_H #ifndef PIWAITEVENT_P_H
#define PIWAITEVENT_P_H #define PIWAITEVENT_P_H
#include "pibase.h" #ifndef MICRO_PIP
# include "pibase.h"
// clang-format off // clang-format off
#ifdef WINDOWS #ifdef WINDOWS
# include <stdarg.h> # include <stdarg.h>
@@ -52,17 +54,18 @@ public:
void * getEvent() const; // WINDOWS only void * getEvent() const; // WINDOWS only
private: private:
#ifdef WINDOWS # ifdef WINDOWS
void * event = nullptr; void * event = nullptr;
#else # else
int pipe_fd[2] = {0, 0}; int pipe_fd[2] = {0, 0};
fd_set fds[3]; fd_set fds[3];
enum { enum {
ReadEnd = 0, ReadEnd = 0,
WriteEnd = 1 WriteEnd = 1
}; };
#endif # endif
}; };
#endif // MICRO_PIP
#endif // PIWAITEVENT_P_H #endif // PIWAITEVENT_P_H

View File

@@ -25,6 +25,7 @@
#include "pidigest_md5_p.h" #include "pidigest_md5_p.h"
#include "pidigest_sha1_p.h" #include "pidigest_sha1_p.h"
#include "pidigest_sha2_p.h" #include "pidigest_sha2_p.h"
#include "pidigest_siphash_p.h"
int PIDigest::hashLength(Type type) { int PIDigest::hashLength(Type type) {
@@ -49,6 +50,10 @@ int PIDigest::hashLength(Type type) {
case Type::BLAKE2b_256: return 32; case Type::BLAKE2b_256: return 32;
case Type::BLAKE2b_384: return 48; case Type::BLAKE2b_384: return 48;
case Type::BLAKE2b_512: return 64; case Type::BLAKE2b_512: return 64;
case Type::SipHash_2_4_64: return 8;
case Type::SipHash_2_4_128: return 16;
case Type::HalfSipHash_2_4_32: return 4;
case Type::HalfSipHash_2_4_64: return 8;
default: break; default: break;
} }
return 0; return 0;
@@ -77,6 +82,10 @@ int PIDigest::blockLength(Type type) {
case Type::BLAKE2b_256: case Type::BLAKE2b_256:
case Type::BLAKE2b_384: case Type::BLAKE2b_384:
case Type::BLAKE2b_512: return 128; case Type::BLAKE2b_512: return 128;
case Type::SipHash_2_4_64: return 8;
case Type::SipHash_2_4_128: return 16;
case Type::HalfSipHash_2_4_32: return 4;
case Type::HalfSipHash_2_4_64: return 8;
default: break; default: break;
} }
return 0; return 0;
@@ -105,6 +114,10 @@ PIConstChars PIDigest::typeName(Type type) {
case Type::BLAKE2b_256: return "BLAKE2b_256"; case Type::BLAKE2b_256: return "BLAKE2b_256";
case Type::BLAKE2b_384: return "BLAKE2b_384"; case Type::BLAKE2b_384: return "BLAKE2b_384";
case Type::BLAKE2b_512: return "BLAKE2b_512"; case Type::BLAKE2b_512: return "BLAKE2b_512";
case Type::SipHash_2_4_64: return "SipHash_2_4_64";
case Type::SipHash_2_4_128: return "SipHash_2_4_128";
case Type::HalfSipHash_2_4_32: return "HalfSipHash_2_4_32";
case Type::HalfSipHash_2_4_64: return "HalfSipHash_2_4_64";
default: break; default: break;
} }
return "Unknown"; return "Unknown";
@@ -123,16 +136,42 @@ PIByteArray PIDigest::calculate(const PIByteArray & msg, Type type) {
case Type::SHA2_512: return SHA2::sha5xx(msg, SHA2::initial_512, 64); case Type::SHA2_512: return SHA2::sha5xx(msg, SHA2::initial_512, 64);
case Type::SHA2_512_224: return SHA2::sha5xx(msg, SHA2::initial_512_224, 28); case Type::SHA2_512_224: return SHA2::sha5xx(msg, SHA2::initial_512_224, 28);
case Type::SHA2_512_256: return SHA2::sha5xx(msg, SHA2::initial_512_256, 32); case Type::SHA2_512_256: return SHA2::sha5xx(msg, SHA2::initial_512_256, 32);
case Type::BLAKE2s_128: return BLAKE2::blake2s(msg, 16); case Type::BLAKE2s_128: return BLAKE2::blake2s(msg, {}, 16);
case Type::BLAKE2s_160: return BLAKE2::blake2s(msg, 20); case Type::BLAKE2s_160: return BLAKE2::blake2s(msg, {}, 20);
case Type::BLAKE2s_224: return BLAKE2::blake2s(msg, 28); case Type::BLAKE2s_224: return BLAKE2::blake2s(msg, {}, 28);
case Type::BLAKE2s_256: return BLAKE2::blake2s(msg, 32); case Type::BLAKE2s_256: return BLAKE2::blake2s(msg, {}, 32);
case Type::BLAKE2b_128: return BLAKE2::blake2b(msg, 16); case Type::BLAKE2b_128: return BLAKE2::blake2b(msg, {}, 16);
case Type::BLAKE2b_160: return BLAKE2::blake2b(msg, 20); case Type::BLAKE2b_160: return BLAKE2::blake2b(msg, {}, 20);
case Type::BLAKE2b_224: return BLAKE2::blake2b(msg, 28); case Type::BLAKE2b_224: return BLAKE2::blake2b(msg, {}, 28);
case Type::BLAKE2b_256: return BLAKE2::blake2b(msg, 32); case Type::BLAKE2b_256: return BLAKE2::blake2b(msg, {}, 32);
case Type::BLAKE2b_384: return BLAKE2::blake2b(msg, 48); case Type::BLAKE2b_384: return BLAKE2::blake2b(msg, {}, 48);
case Type::BLAKE2b_512: return BLAKE2::blake2b(msg, 64); case Type::BLAKE2b_512: return BLAKE2::blake2b(msg, {}, 64);
case Type::SipHash_2_4_64: return SipHash::siphash(msg, {}, 8);
case Type::SipHash_2_4_128: return SipHash::siphash(msg, {}, 16);
case Type::HalfSipHash_2_4_32: return SipHash::halfsiphash(msg, {}, 4);
case Type::HalfSipHash_2_4_64: return SipHash::halfsiphash(msg, {}, 8);
default: break;
}
return {};
}
PIByteArray PIDigest::calculateWithKey(const PIByteArray & msg, const PIByteArray & key, Type type) {
switch (type) {
case Type::BLAKE2s_128: return BLAKE2::blake2s(msg, key, 16);
case Type::BLAKE2s_160: return BLAKE2::blake2s(msg, key, 20);
case Type::BLAKE2s_224: return BLAKE2::blake2s(msg, key, 28);
case Type::BLAKE2s_256: return BLAKE2::blake2s(msg, key, 32);
case Type::BLAKE2b_128: return BLAKE2::blake2b(msg, key, 16);
case Type::BLAKE2b_160: return BLAKE2::blake2b(msg, key, 20);
case Type::BLAKE2b_224: return BLAKE2::blake2b(msg, key, 28);
case Type::BLAKE2b_256: return BLAKE2::blake2b(msg, key, 32);
case Type::BLAKE2b_384: return BLAKE2::blake2b(msg, key, 48);
case Type::BLAKE2b_512: return BLAKE2::blake2b(msg, key, 64);
case Type::SipHash_2_4_64: return SipHash::siphash(msg, key, 8);
case Type::SipHash_2_4_128: return SipHash::siphash(msg, key, 16);
case Type::HalfSipHash_2_4_32: return SipHash::halfsiphash(msg, key, 4);
case Type::HalfSipHash_2_4_64: return SipHash::halfsiphash(msg, key, 8);
default: break; default: break;
} }
return {}; return {};

View File

@@ -39,15 +39,18 @@ class PIP_EXPORT PIDigest {
public: public:
enum class Type { enum class Type {
SHA1, SHA1,
SHA2_224, SHA2_224,
SHA2_256, SHA2_256,
SHA2_384, SHA2_384,
SHA2_512, SHA2_512,
SHA2_512_224, SHA2_512_224,
SHA2_512_256, SHA2_512_256,
MD2, MD2,
MD4, MD4,
MD5, MD5,
BLAKE2s_128, BLAKE2s_128,
BLAKE2s_160, BLAKE2s_160,
BLAKE2s_224, BLAKE2s_224,
@@ -58,6 +61,12 @@ public:
BLAKE2b_256, BLAKE2b_256,
BLAKE2b_384, BLAKE2b_384,
BLAKE2b_512, BLAKE2b_512,
SipHash_2_4_64,
SipHash_2_4_128,
HalfSipHash_2_4_32,
HalfSipHash_2_4_64,
Count, Count,
}; };
@@ -66,6 +75,7 @@ public:
static PIConstChars typeName(Type type); static PIConstChars typeName(Type type);
static PIByteArray calculate(const PIByteArray & msg, Type type); static PIByteArray calculate(const PIByteArray & msg, Type type);
static PIByteArray calculateWithKey(const PIByteArray & msg, const PIByteArray & key, Type type);
static PIByteArray HMAC(const PIByteArray & msg, const PIByteArray & key, PIDigest::Type type); static PIByteArray HMAC(const PIByteArray & msg, const PIByteArray & key, PIDigest::Type type);
}; };

View File

@@ -21,44 +21,18 @@
#include "3rd/BLAKE2/blake2.h" #include "3rd/BLAKE2/blake2.h"
#define IMPLEMENT(func, key_len) \
PIByteArray BLAKE2::func(const PIByteArray & in, const PIByteArray & key, int out_bytes) { \
PIByteArray ret(out_bytes); \
::func(ret.data(), ret.size(), in.data(), in.size(), key.isEmpty() ? nullptr : key.data(), piMini(key.size(), key_len)); \
return ret; \
}
PIByteArray BLAKE2::blake2s(const PIByteArray & in, int out_bytes) { IMPLEMENT(blake2s, BLAKE2S_KEYBYTES)
PIByteArray ret(out_bytes); IMPLEMENT(blake2b, BLAKE2B_KEYBYTES)
::blake2s(ret.data(), ret.size(), in.data(), in.size(), nullptr, 0); IMPLEMENT(blake2sp, BLAKE2S_KEYBYTES)
return ret; IMPLEMENT(blake2bp, BLAKE2B_KEYBYTES)
} IMPLEMENT(blake2xs, BLAKE2S_KEYBYTES)
IMPLEMENT(blake2xb, BLAKE2B_KEYBYTES)
#undef IMPLEMENT
PIByteArray BLAKE2::blake2b(const PIByteArray & in, int out_bytes) {
PIByteArray ret(out_bytes);
::blake2b(ret.data(), ret.size(), in.data(), in.size(), nullptr, 0);
return ret;
}
PIByteArray BLAKE2::blake2sp(const PIByteArray & in, int out_bytes) {
PIByteArray ret(out_bytes);
::blake2sp(ret.data(), ret.size(), in.data(), in.size(), nullptr, 0);
return ret;
}
PIByteArray BLAKE2::blake2bp(const PIByteArray & in, int out_bytes) {
PIByteArray ret(out_bytes);
::blake2bp(ret.data(), ret.size(), in.data(), in.size(), nullptr, 0);
return ret;
}
PIByteArray BLAKE2::blake2xs(const PIByteArray & in, int out_bytes) {
PIByteArray ret(out_bytes);
::blake2xs(ret.data(), ret.size(), in.data(), in.size(), nullptr, 0);
return ret;
}
PIByteArray BLAKE2::blake2xb(const PIByteArray & in, int out_bytes) {
PIByteArray ret(out_bytes);
::blake2xb(ret.data(), ret.size(), in.data(), in.size(), nullptr, 0);
return ret;
}

View File

@@ -24,12 +24,12 @@
class BLAKE2 { class BLAKE2 {
public: public:
static PIByteArray blake2s(const PIByteArray & in, int out_bytes); static PIByteArray blake2s(const PIByteArray & in, const PIByteArray & key, int out_bytes);
static PIByteArray blake2b(const PIByteArray & in, int out_bytes); static PIByteArray blake2b(const PIByteArray & in, const PIByteArray & key, int out_bytes);
static PIByteArray blake2sp(const PIByteArray & in, int out_bytes); static PIByteArray blake2sp(const PIByteArray & in, const PIByteArray & key, int out_bytes);
static PIByteArray blake2bp(const PIByteArray & in, int out_bytes); static PIByteArray blake2bp(const PIByteArray & in, const PIByteArray & key, int out_bytes);
static PIByteArray blake2xs(const PIByteArray & in, int out_bytes); static PIByteArray blake2xs(const PIByteArray & in, const PIByteArray & key, int out_bytes);
static PIByteArray blake2xb(const PIByteArray & in, int out_bytes); static PIByteArray blake2xb(const PIByteArray & in, const PIByteArray & key, int out_bytes);
}; };
#endif #endif

View File

@@ -67,10 +67,10 @@ inline T shift_u(T v, int bits) {
} }
PIByteArray SHA2::sha2xx(const PIByteArray & in, const uint32_t * initial, int out_bytes) { PIByteArray SHA2::sha2xx(const PIByteArray & in, const uint32_t * initial, int out_bytes) {
constexpr int part_size = 64; constexpr int part_size = 64;
constexpr int rounds = 64; constexpr int rounds = 64;
static constexpr uint32_t k[part_size] = { static constexpr uint32_t k[rounds] = {
0x428A2F98u, 0x71374491u, 0xB5C0FBCFu, 0xE9B5DBA5u, 0x3956C25Bu, 0x59F111F1u, 0x923F82A4u, 0xAB1C5ED5u, 0xD807AA98u, 0x12835B01u, 0x428A2F98u, 0x71374491u, 0xB5C0FBCFu, 0xE9B5DBA5u, 0x3956C25Bu, 0x59F111F1u, 0x923F82A4u, 0xAB1C5ED5u, 0xD807AA98u, 0x12835B01u,
0x243185BEu, 0x550C7DC3u, 0x72BE5D74u, 0x80DEB1FEu, 0x9BDC06A7u, 0xC19BF174u, 0xE49B69C1u, 0xEFBE4786u, 0x0FC19DC6u, 0x240CA1CCu, 0x243185BEu, 0x550C7DC3u, 0x72BE5D74u, 0x80DEB1FEu, 0x9BDC06A7u, 0xC19BF174u, 0xE49B69C1u, 0xEFBE4786u, 0x0FC19DC6u, 0x240CA1CCu,
0x2DE92C6Fu, 0x4A7484AAu, 0x5CB0A9DCu, 0x76F988DAu, 0x983E5152u, 0xA831C66Du, 0xB00327C8u, 0xBF597FC7u, 0xC6E00BF3u, 0xD5A79147u, 0x2DE92C6Fu, 0x4A7484AAu, 0x5CB0A9DCu, 0x76F988DAu, 0x983E5152u, 0xA831C66Du, 0xB00327C8u, 0xBF597FC7u, 0xC6E00BF3u, 0xD5A79147u,
@@ -150,10 +150,10 @@ PIByteArray SHA2::sha2xx(const PIByteArray & in, const uint32_t * initial, int o
} }
PIByteArray SHA2::sha5xx(const PIByteArray & in, const uint64_t * initial, int out_bytes) { PIByteArray SHA2::sha5xx(const PIByteArray & in, const uint64_t * initial, int out_bytes) {
constexpr int part_size = 128; constexpr int part_size = 128;
constexpr int rounds = 80; constexpr int rounds = 80;
static constexpr uint64_t k[80] = { static constexpr uint64_t k[rounds] = {
0X428A2F98D728AE22U, 0X7137449123EF65CDU, 0XB5C0FBCFEC4D3B2FU, 0XE9B5DBA58189DBBCU, 0X3956C25BF348B538U, 0X59F111F1B605D019U, 0X428A2F98D728AE22U, 0X7137449123EF65CDU, 0XB5C0FBCFEC4D3B2FU, 0XE9B5DBA58189DBBCU, 0X3956C25BF348B538U, 0X59F111F1B605D019U,
0X923F82A4AF194F9BU, 0XAB1C5ED5DA6D8118U, 0XD807AA98A3030242U, 0X12835B0145706FBEU, 0X243185BE4EE4B28CU, 0X550C7DC3D5FFB4E2U, 0X923F82A4AF194F9BU, 0XAB1C5ED5DA6D8118U, 0XD807AA98A3030242U, 0X12835B0145706FBEU, 0X243185BE4EE4B28CU, 0X550C7DC3D5FFB4E2U,
0X72BE5D74F27B896FU, 0X80DEB1FE3B1696B1U, 0X9BDC06A725C71235U, 0XC19BF174CF692694U, 0XE49B69C19EF14AD2U, 0XEFBE4786384F25E3U, 0X72BE5D74F27B896FU, 0X80DEB1FE3B1696B1U, 0X9BDC06A725C71235U, 0XC19BF174CF692694U, 0XE49B69C19EF14AD2U, 0XEFBE4786384F25E3U,

View File

@@ -0,0 +1,58 @@
/*
PIP - Platform Independent Primitives
Digest algorithms
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pidigest_siphash_p.h"
#include "3rd/SipHash/halfsiphash.h"
#include "3rd/SipHash/siphash.h"
#include "3rd/SipHash/vectors.h"
PIByteArray SipHash::siphash(const PIByteArray & in, const PIByteArray & key, int out_bytes) {
PIByteArray ret(out_bytes);
static PIByteArray empty_key(16, 0);
if (key.isEmpty())
::siphash(in.data(), in.size(), empty_key.data(), ret.data(), ret.size());
else {
if (key.size() >= 16)
::siphash(in.data(), in.size(), key.data(), ret.data(), ret.size());
else {
auto skey = key.resized(16);
::siphash(in.data(), in.size(), skey.data(), ret.data(), ret.size());
}
}
return ret;
}
PIByteArray SipHash::halfsiphash(const PIByteArray & in, const PIByteArray & key, int out_bytes) {
PIByteArray ret(out_bytes);
static PIByteArray empty_key(8, 0);
if (key.isEmpty())
::halfsiphash(in.data(), in.size(), empty_key.data(), ret.data(), ret.size());
else {
if (key.size() >= 8)
::halfsiphash(in.data(), in.size(), key.data(), ret.data(), ret.size());
else {
auto skey = key.resized(8);
::halfsiphash(in.data(), in.size(), skey.data(), ret.data(), ret.size());
}
}
return ret;
}

View File

@@ -0,0 +1,31 @@
/*
PIP - Platform Independent Primitives
Digest algorithms
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef pidigest_siphash_h
#define pidigest_siphash_h
#include "pibytearray.h"
class SipHash {
public:
static PIByteArray siphash(const PIByteArray & in, const PIByteArray & key, int out_bytes);
static PIByteArray halfsiphash(const PIByteArray & in, const PIByteArray & key, int out_bytes);
};
#endif

View File

@@ -19,10 +19,12 @@
#include "piintrospection_server_p.h" #include "piintrospection_server_p.h"
#include "pichunkstream.h" #if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
#include "piinit.h"
#include "piobject.h" # include "pichunkstream.h"
#include "pisysteminfo.h" # include "piinit.h"
# include "piobject.h"
# include "pisysteminfo.h"
const uint PIIntrospection::sign = 0x0F1C2B3A; const uint PIIntrospection::sign = 0x0F1C2B3A;
@@ -111,9 +113,9 @@ PIByteArray PIIntrospection::packContainers() {
PIByteArray ret; PIByteArray ret;
PIVector<PIIntrospectionContainers::TypeInfo> data; PIVector<PIIntrospectionContainers::TypeInfo> data;
PIIntrospectionContainers * p = 0; PIIntrospectionContainers * p = 0;
#ifdef PIP_INTROSPECTION # ifdef PIP_INTROSPECTION
p = PIINTROSPECTION_CONTAINERS->p; p = PIINTROSPECTION_CONTAINERS->p;
#endif # endif
if (p) { if (p) {
data = p->getInfo(); data = p->getInfo();
} }
@@ -131,9 +133,9 @@ void PIIntrospection::unpackContainers(PIByteArray & ba, PIVector<PIIntrospectio
PIByteArray PIIntrospection::packThreads() { PIByteArray PIIntrospection::packThreads() {
PIByteArray ret; PIByteArray ret;
PIIntrospectionThreads * p = 0; PIIntrospectionThreads * p = 0;
#ifdef PIP_INTROSPECTION # ifdef PIP_INTROSPECTION
p = PIINTROSPECTION_THREADS->p; p = PIINTROSPECTION_THREADS->p;
#endif # endif
if (p) { if (p) {
p->mutex.lock(); p->mutex.lock();
PIMap<PIThread *, PIIntrospectionThreads::ThreadInfo> & tm(p->threads); PIMap<PIThread *, PIIntrospectionThreads::ThreadInfo> & tm(p->threads);
@@ -170,3 +172,5 @@ void PIIntrospection::unpackObjects(PIByteArray & ba, PIVector<PIIntrospection::
objects.clear(); objects.clear();
ba >> objects; ba >> objects;
} }
#endif // #if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)

View File

@@ -27,6 +27,7 @@
#include "piintrospection_threads_p.h" #include "piintrospection_threads_p.h"
#include "pisystemmonitor.h" #include "pisystemmonitor.h"
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
class PIP_EXPORT PIIntrospection { class PIP_EXPORT PIIntrospection {
public: public:
@@ -168,4 +169,5 @@ BINARY_STREAM_READ(PIIntrospection::ObjectInfo) {
return s; return s;
} }
#endif // #if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
#endif // PIINTROSPECTION_SERVER_P_H #endif // PIINTROSPECTION_SERVER_P_H

View File

@@ -19,6 +19,7 @@
#include "piintrospection_threads_p.h" #include "piintrospection_threads_p.h"
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
PIIntrospectionThreads::ThreadInfo::ThreadInfo() { PIIntrospectionThreads::ThreadInfo::ThreadInfo() {
id = delay = 0; id = delay = 0;
@@ -78,3 +79,5 @@ void PIIntrospectionThreads::threadRunDone(PIThread * t, ullong us) {
ThreadInfo & ti(threads[t]); ThreadInfo & ti(threads[t]);
ti.run_us = (ti.run_us * 0.8) + (us * 0.2); /// WARNING ti.run_us = (ti.run_us * 0.8) + (us * 0.2); /// WARNING
} }
#endif // #if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)

View File

@@ -20,6 +20,10 @@
#ifndef PIINTROSPECTION_THREADS_P_H #ifndef PIINTROSPECTION_THREADS_P_H
#define PIINTROSPECTION_THREADS_P_H #define PIINTROSPECTION_THREADS_P_H
#include "pibase.h"
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
#include "pimap.h" #include "pimap.h"
#include "pithread.h" #include "pithread.h"
@@ -68,4 +72,5 @@ BINARY_STREAM_READ(PIIntrospectionThreads::ThreadInfo) {
return s; return s;
} }
#endif // #if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
#endif // PIINTROSPECTION_THREADS_P_H #endif // PIINTROSPECTION_THREADS_P_H

View File

@@ -20,7 +20,7 @@
#include "pipropertystorage.h" #include "pipropertystorage.h"
#include "piwaitevent_p.h" #include "piwaitevent_p.h"
#if !defined(WINDOWS) && !defined(MAC_OS) && !defined(MICRO_PIP) #if !defined(WINDOWS) && !defined(MAC_OS) && !defined(PIP_NO_SOCKET)
# define PIP_CAN # define PIP_CAN
#endif #endif
#ifdef PIP_CAN #ifdef PIP_CAN
@@ -39,25 +39,29 @@
REGISTER_DEVICE(PICAN) REGISTER_DEVICE(PICAN)
#ifdef PIP_CAN
PRIVATE_DEFINITION_START(PICAN) PRIVATE_DEFINITION_START(PICAN)
PIWaitEvent event; PIWaitEvent event;
PRIVATE_DEFINITION_END(PICAN) PRIVATE_DEFINITION_END(PICAN)
#endif
PICAN::PICAN(const PIString & path, PIIODevice::DeviceMode mode): PIIODevice(path, mode) { PICAN::PICAN(const PIString & path, PIIODevice::DeviceMode mode): PIIODevice(path, mode) {
setThreadedReadBufferSize(256); setThreadedReadBufferSize(256);
setPath(path); setPath(path);
#ifdef PIP_CAN
can_id = 0; can_id = 0;
sock = 0; sock = 0;
PRIVATE->event.create(); PRIVATE->event.create();
#endif
} }
PICAN::~PICAN() { PICAN::~PICAN() {
stopAndWait(); stopAndWait();
close(); close();
#ifdef PIP_CAN
PRIVATE->event.destroy(); PRIVATE->event.destroy();
#endif
} }
@@ -164,7 +168,9 @@ int PICAN::readedCANID() const {
void PICAN::interrupt() { void PICAN::interrupt() {
#ifdef PIP_CAN
PRIVATE->event.interrupt(); PRIVATE->event.interrupt();
#endif
} }

View File

@@ -18,64 +18,65 @@
*/ */
#include "piethernet.h" #include "piethernet.h"
#include "piconfig.h" #ifndef PIP_NO_SOCKET
#include "piconstchars.h"
#include "piincludes_p.h"
#include "piliterals.h"
#include "pipropertystorage.h"
#include "pisysteminfo.h"
#include "pitranslator.h"
// clang-format off
#ifdef QNX
# include <arpa/inet.h>
# include <fcntl.h>
# include <hw/nicinfo.h>
# include <ifaddrs.h>
# include <net/if.h>
# include <net/if_dl.h>
# include <netdb.h>
# include <netinet/in.h>
# include <sys/ioctl.h>
# include <sys/socket.h>
# include <sys/time.h>
# include <sys/types.h>
# ifdef BLACKBERRY
# include <netinet/in.h>
# else
# include <sys/dcmd_io-net.h>
# endif
# define ip_mreqn ip_mreq
# define imr_address imr_interface
#else
# ifdef WINDOWS
# include <io.h>
# include <winsock2.h>
# include <iphlpapi.h>
# include <psapi.h>
# include <ws2tcpip.h>
# define ip_mreqn ip_mreq
# define imr_address imr_interface
# else
# include <fcntl.h>
# include <sys/ioctl.h>
# include <netinet/in.h>
# include <netinet/tcp.h>
# include <arpa/inet.h>
# include <sys/socket.h>
# include <netdb.h>
# include <net/if.h>
# if !defined(ANDROID) && !defined(LWIP)
# include <ifaddrs.h>
# endif
# ifdef LWIP
# include <lwip/sockets.h>
# endif
# endif
#endif
// clang-format on
#include "piwaitevent_p.h"
#include <errno.h> # include "piconfig.h"
# include "piconstchars.h"
# include "piincludes_p.h"
# include "piliterals.h"
# include "pipropertystorage.h"
# include "pisysteminfo.h"
# include "pitranslator.h"
# ifdef QNX
# include <arpa/inet.h>
# include <fcntl.h>
# include <hw/nicinfo.h>
# include <ifaddrs.h>
# include <net/if.h>
# include <net/if_dl.h>
# include <netdb.h>
# include <netinet/in.h>
# include <sys/ioctl.h>
# include <sys/socket.h>
# include <sys/time.h>
# include <sys/types.h>
# ifdef BLACKBERRY
# include <netinet/in.h>
# else
# include <sys/dcmd_io-net.h>
# endif
# define ip_mreqn ip_mreq
# define imr_address imr_interface
# else
# ifdef WINDOWS
# include <io.h>
# include <iphlpapi.h>
# include <psapi.h>
# include <winsock2.h>
# include <ws2tcpip.h>
# define ip_mreqn ip_mreq
# define imr_address imr_interface
# else
# include <arpa/inet.h>
# include <fcntl.h>
# include <net/if.h>
# include <netdb.h>
# include <netinet/in.h>
# include <netinet/tcp.h>
# include <sys/ioctl.h>
# include <sys/socket.h>
# if !defined(ANDROID) && !defined(LWIP)
# include <ifaddrs.h>
# endif
# ifdef LWIP
# include <lwip/sockets.h>
# endif
# endif
# endif
# include "piwaitevent_p.h"
# include <errno.h>
/** \class PIEthernet piethernet.h /** \class PIEthernet piethernet.h
@@ -100,11 +101,11 @@
* *
* */ * */
#ifndef WINDOWS # ifndef WINDOWS
PIString getSockAddr(sockaddr * s) { PIString getSockAddr(sockaddr * s) {
return s == 0 ? PIString() : PIStringAscii(inet_ntoa(((sockaddr_in *)s)->sin_addr)); return s == 0 ? PIString() : PIStringAscii(inet_ntoa(((sockaddr_in *)s)->sin_addr));
} }
#endif # endif
REGISTER_DEVICE(PIEthernet) REGISTER_DEVICE(PIEthernet)
@@ -196,11 +197,11 @@ void PIEthernet::construct() {
setMulticastTTL(1); setMulticastTTL(1);
server_thread_.setData(this); server_thread_.setData(this);
server_thread_.setName("_S.tcpserver"_a); server_thread_.setName("_S.tcpserver"_a);
#ifdef MICRO_PIP # ifdef LWIP
setThreadedReadBufferSize(512); setThreadedReadBufferSize(512);
#else # else
setThreadedReadBufferSize(64_KiB); setThreadedReadBufferSize(64_KiB);
#endif # endif
// setPriority(piHigh); // setPriority(piHigh);
} }
@@ -304,9 +305,9 @@ bool PIEthernet::openDevice() {
PRIVATE->addr_.sin_addr.s_addr = INADDR_ANY; PRIVATE->addr_.sin_addr.s_addr = INADDR_ANY;
else else
PRIVATE->addr_.sin_addr.s_addr = addr_r.ip(); PRIVATE->addr_.sin_addr.s_addr = addr_r.ip();
#ifdef QNX # ifdef QNX
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_); PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
#endif # endif
// piCout << "bind to" << (params[PIEthernet::Broadcast] ? "255.255.255.255" : ip_) << ":" << port_ << " ..."; // piCout << "bind to" << (params[PIEthernet::Broadcast] ? "255.255.255.255" : ip_) << ":" << port_ << " ...";
int tries = 0; int tries = 0;
while ((bind(sock, (sockaddr *)&PRIVATE->addr_, sizeof(PRIVATE->addr_)) == -1) && (tries < 2)) { while ((bind(sock, (sockaddr *)&PRIVATE->addr_, sizeof(PRIVATE->addr_)) == -1) && (tries < 2)) {
@@ -379,14 +380,14 @@ void PIEthernet::applyBuffers() {
void PIEthernet::applyTimeout(int fd, int opt, PISystemTime tm) { void PIEthernet::applyTimeout(int fd, int opt, PISystemTime tm) {
if (fd == 0) return; if (fd == 0) return;
// piCoutObj << "setReadIsBlocking" << yes; // piCoutObj << "setReadIsBlocking" << yes;
#ifdef WINDOWS # ifdef WINDOWS
DWORD _tm = tm.toMilliseconds(); DWORD _tm = tm.toMilliseconds();
#else # else
timeval _tm; timeval _tm;
_tm.tv_sec = tm.seconds; _tm.tv_sec = tm.seconds;
_tm.tv_usec = tm.nanoseconds / 1000; _tm.tv_usec = tm.nanoseconds / 1000;
#endif # endif
ethSetsockopt(fd, SOL_SOCKET, opt, &_tm, sizeof(_tm)); ethSetsockopt(fd, SOL_SOCKET, opt, &_tm, sizeof(_tm));
} }
@@ -411,30 +412,30 @@ bool PIEthernet::joinMulticastGroup(const PIString & group) {
return true; return true;
} }
addr_r.set(path()); addr_r.set(path());
#ifndef LWIP # ifndef LWIP
struct ip_mreqn mreq; struct ip_mreqn mreq;
#else # else
struct ip_mreq mreq; struct ip_mreq mreq;
#endif # endif
piZeroMemory(mreq); piZeroMemory(mreq);
#ifdef LINUX # ifdef LINUX
// mreq.imr_address.s_addr = INADDR_ANY; // mreq.imr_address.s_addr = INADDR_ANY;
/*PIEthernet::InterfaceList il = interfaces(); /*PIEthernet::InterfaceList il = interfaces();
const PIEthernet::Interface * ci = il.getByAddress(addr_r.ipString()); const PIEthernet::Interface * ci = il.getByAddress(addr_r.ipString());
if (ci != 0) mreq.imr_ifindex = ci->index;*/ if (ci != 0) mreq.imr_ifindex = ci->index;*/
#endif # endif
if (params[PIEthernet::Broadcast]) if (params[PIEthernet::Broadcast])
#ifndef LWIP # ifndef LWIP
mreq.imr_address.s_addr = INADDR_ANY; mreq.imr_address.s_addr = INADDR_ANY;
#else # else
mreq.imr_interface.s_addr = INADDR_ANY; mreq.imr_interface.s_addr = INADDR_ANY;
#endif # endif
else else
#ifndef LWIP # ifndef LWIP
mreq.imr_address.s_addr = addr_r.ip(); mreq.imr_address.s_addr = addr_r.ip();
#else # else
mreq.imr_interface.s_addr = addr_r.ip(); mreq.imr_interface.s_addr = addr_r.ip();
#endif # endif
// piCout << "join group" << group << "ip" << ip_ << "with index" << mreq.imr_ifindex << "socket" << sock; // piCout << "join group" << group << "ip" << ip_ << "with index" << mreq.imr_ifindex << "socket" << sock;
mreq.imr_multiaddr.s_addr = inet_addr(group.dataAscii()); mreq.imr_multiaddr.s_addr = inet_addr(group.dataAscii());
@@ -457,24 +458,24 @@ bool PIEthernet::leaveMulticastGroup(const PIString & group) {
return false; return false;
} }
addr_r.set(path()); addr_r.set(path());
#ifndef LWIP # ifndef LWIP
struct ip_mreqn mreq; struct ip_mreqn mreq;
#else # else
struct ip_mreq mreq; struct ip_mreq mreq;
#endif # endif
piZeroMemory(mreq); piZeroMemory(mreq);
if (params[PIEthernet::Broadcast]) if (params[PIEthernet::Broadcast])
#ifndef LWIP # ifndef LWIP
mreq.imr_address.s_addr = INADDR_ANY; mreq.imr_address.s_addr = INADDR_ANY;
#else # else
mreq.imr_interface.s_addr = INADDR_ANY; mreq.imr_interface.s_addr = INADDR_ANY;
#endif # endif
else else
#ifndef LWIP # ifndef LWIP
mreq.imr_address.s_addr = addr_r.ip(); mreq.imr_address.s_addr = addr_r.ip();
#else # else
mreq.imr_interface.s_addr = addr_r.ip(); mreq.imr_interface.s_addr = addr_r.ip();
#endif # endif
mreq.imr_multiaddr.s_addr = inet_addr(group.dataAscii()); mreq.imr_multiaddr.s_addr = inet_addr(group.dataAscii());
if (ethSetsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)) == -1) { if (ethSetsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)) == -1) {
piCoutObj << "Can`t leave multicast group" << group << "," << ethErrorString(); piCoutObj << "Can`t leave multicast group" << group << "," << ethErrorString();
@@ -498,9 +499,9 @@ bool PIEthernet::connect(bool threaded) {
PRIVATE->addr_.sin_port = htons(addr_r.port()); PRIVATE->addr_.sin_port = htons(addr_r.port());
PRIVATE->addr_.sin_addr.s_addr = addr_r.ip(); PRIVATE->addr_.sin_addr.s_addr = addr_r.ip();
PRIVATE->addr_.sin_family = AF_INET; PRIVATE->addr_.sin_family = AF_INET;
#ifdef QNX # ifdef QNX
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_); PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
#endif # endif
connecting_ = true; connecting_ = true;
connected_ = connectTCP(); connected_ = connectTCP();
connecting_ = false; connecting_ = false;
@@ -535,9 +536,9 @@ bool PIEthernet::listen(bool threaded) {
PRIVATE->addr_.sin_port = htons(addr_r.port()); PRIVATE->addr_.sin_port = htons(addr_r.port());
PRIVATE->addr_.sin_addr.s_addr = addr_r.ip(); PRIVATE->addr_.sin_addr.s_addr = addr_r.ip();
PRIVATE->addr_.sin_family = AF_INET; PRIVATE->addr_.sin_family = AF_INET;
#ifdef QNX # ifdef QNX
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_); PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
#endif # endif
opened_ = false; opened_ = false;
int tries = 0; int tries = 0;
while ((bind(sock, (sockaddr *)&PRIVATE->addr_, sizeof(PRIVATE->addr_)) == -1) && (tries < 2)) { while ((bind(sock, (sockaddr *)&PRIVATE->addr_, sizeof(PRIVATE->addr_)) == -1) && (tries < 2)) {
@@ -661,9 +662,9 @@ ssize_t PIEthernet::readDevice(void * read_to, ssize_t max_size) {
PRIVATE->addr_.sin_port = htons(addr_r.port()); PRIVATE->addr_.sin_port = htons(addr_r.port());
PRIVATE->addr_.sin_addr.s_addr = addr_r.ip(); PRIVATE->addr_.sin_addr.s_addr = addr_r.ip();
PRIVATE->addr_.sin_family = AF_INET; PRIVATE->addr_.sin_family = AF_INET;
#ifdef QNX # ifdef QNX
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_); PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
#endif # endif
// piCoutObj << "connect to " << path() << "..."; // piCoutObj << "connect to " << path() << "...";
connected_ = connectTCP(); connected_ = connectTCP();
// piCoutObj << "connect to " << path() << connected_; // piCoutObj << "connect to " << path() << connected_;
@@ -678,7 +679,7 @@ ssize_t PIEthernet::readDevice(void * read_to, ssize_t max_size) {
} }
if (!connected_) return -1; if (!connected_) return -1;
errorClear(); errorClear();
#ifdef WINDOWS # ifdef WINDOWS
{ {
long wr = waitForEvent(PRIVATE->event, FD_READ | FD_CLOSE); long wr = waitForEvent(PRIVATE->event, FD_READ | FD_CLOSE);
switch (wr) { switch (wr) {
@@ -694,34 +695,34 @@ ssize_t PIEthernet::readDevice(void * read_to, ssize_t max_size) {
default: break; default: break;
} }
} }
#else # else
if (PRIVATE->event.wait(sock)) { if (PRIVATE->event.wait(sock)) {
errorClear(); errorClear();
rs = ethRecv(sock, read_to, max_size); rs = ethRecv(sock, read_to, max_size);
} }
#endif # endif
// piCoutObj << "readed" << rs; // piCoutObj << "readed" << rs;
if (rs <= 0) { if (rs <= 0) {
lerr = ethErrorCore(); lerr = ethErrorCore();
// piCoutObj << "readed" << rs << "error" << lerr; // piCoutObj << "readed" << rs << "error" << lerr;
// async normal returns // async normal returns
#ifdef WINDOWS # ifdef WINDOWS
if (lerr == WSAEWOULDBLOCK) { if (lerr == WSAEWOULDBLOCK) {
#else # else
if (lerr == EWOULDBLOCK || lerr == EAGAIN || lerr == EINTR) { if (lerr == EWOULDBLOCK || lerr == EAGAIN || lerr == EINTR) {
#endif # endif
// piCoutObj << "Ignore would_block" << lerr; // piCoutObj << "Ignore would_block" << lerr;
return -1; return -1;
} }
// if no disconnect on timeout // if no disconnect on timeout
if (!params[DisonnectOnTimeout]) { if (!params[DisonnectOnTimeout]) {
#ifdef WINDOWS # ifdef WINDOWS
if (lerr == WSAETIMEDOUT) { if (lerr == WSAETIMEDOUT) {
#else # else
if (lerr == ETIMEDOUT) { if (lerr == ETIMEDOUT) {
#endif # endif
// piCoutObj << "Ignore read timeout"; // piCoutObj << "Ignore read timeout";
return -1; return -1;
} }
@@ -745,7 +746,7 @@ ssize_t PIEthernet::readDevice(void * read_to, ssize_t max_size) {
case UDP: { case UDP: {
piZeroMemory(PRIVATE->raddr_); piZeroMemory(PRIVATE->raddr_);
// piCoutObj << "read from" << path() << "..."; // piCoutObj << "read from" << path() << "...";
#ifdef WINDOWS # ifdef WINDOWS
long wr = waitForEvent(PRIVATE->event, FD_READ | FD_CLOSE); long wr = waitForEvent(PRIVATE->event, FD_READ | FD_CLOSE);
switch (wr) { switch (wr) {
case FD_READ: case FD_READ:
@@ -758,9 +759,9 @@ ssize_t PIEthernet::readDevice(void * read_to, ssize_t max_size) {
break; break;
default: break; default: break;
} }
#else # else
rs = ethRecvfrom(sock, read_to, max_size, 0, (sockaddr *)&PRIVATE->raddr_); rs = ethRecvfrom(sock, read_to, max_size, 0, (sockaddr *)&PRIVATE->raddr_);
#endif # endif
// piCoutObj << "read from" << path() << rs << "bytes"; // piCoutObj << "read from" << path() << rs << "bytes";
if (rs > 0) { if (rs > 0) {
addr_lr.set(uint(PRIVATE->raddr_.sin_addr.s_addr), ntohs(PRIVATE->raddr_.sin_port)); addr_lr.set(uint(PRIVATE->raddr_.sin_addr.s_addr), ntohs(PRIVATE->raddr_.sin_port));
@@ -793,11 +794,11 @@ ssize_t PIEthernet::writeDevice(const void * data, ssize_t max_size) {
return ethSendto(sock_s, return ethSendto(sock_s,
data, data,
max_size, max_size,
#ifndef WINDOWS # ifndef WINDOWS
isOptionSet(BlockingWrite) ? 0 : MSG_DONTWAIT isOptionSet(BlockingWrite) ? 0 : MSG_DONTWAIT
#else # else
0 0
#endif # endif
, ,
(sockaddr *)&PRIVATE->saddr_, (sockaddr *)&PRIVATE->saddr_,
sizeof(PRIVATE->saddr_)); sizeof(PRIVATE->saddr_));
@@ -809,9 +810,9 @@ ssize_t PIEthernet::writeDevice(const void * data, ssize_t max_size) {
PRIVATE->addr_.sin_port = htons(addr_r.port()); PRIVATE->addr_.sin_port = htons(addr_r.port());
PRIVATE->addr_.sin_addr.s_addr = addr_r.ip(); PRIVATE->addr_.sin_addr.s_addr = addr_r.ip();
PRIVATE->addr_.sin_family = AF_INET; PRIVATE->addr_.sin_family = AF_INET;
#ifdef QNX # ifdef QNX
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_); PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
#endif # endif
// piCoutObj << "connect to " << ip << ":" << port_; // piCoutObj << "connect to " << ip << ":" << port_;
connected_ = connectTCP(); connected_ = connectTCP();
if (!connected_) piCoutObj << "Can`t connect to" << addr_r << "," << ethErrorString(); if (!connected_) piCoutObj << "Can`t connect to" << addr_r << "," << ethErrorString();
@@ -847,11 +848,11 @@ ssize_t PIEthernet::writeDevice(const void * data, ssize_t max_size) {
int sr = ::send(sock, remain_data, remain_size, 0); int sr = ::send(sock, remain_data, remain_size, 0);
if (sr < 0) { if (sr < 0) {
int err = ethErrorCore(); int err = ethErrorCore();
#ifdef WINDOWS # ifdef WINDOWS
if (err == WSAEWOULDBLOCK) { if (err == WSAEWOULDBLOCK) {
#else # else
if (err == EAGAIN || err == EWOULDBLOCK) { if (err == EAGAIN || err == EWOULDBLOCK) {
#endif # endif
piMinSleep(); piMinSleep();
// piCoutObj << "wait for write"; // piCoutObj << "wait for write";
continue; continue;
@@ -910,30 +911,30 @@ void PIEthernet::server_func(void * eth) {
} }
sockaddr_in client_addr; sockaddr_in client_addr;
socklen_t slen = sizeof(client_addr); socklen_t slen = sizeof(client_addr);
#ifdef WINDOWS # ifdef WINDOWS
long wr = ce->waitForEvent(ce->PRIVATEWB->event, FD_ACCEPT | FD_CLOSE); long wr = ce->waitForEvent(ce->PRIVATEWB->event, FD_ACCEPT | FD_CLOSE);
if (wr != FD_ACCEPT) { if (wr != FD_ACCEPT) {
piMSleep(10); piMSleep(10);
return; return;
} }
#else # else
if (!ce->PRIVATEWB->event.wait(ce->sock)) { if (!ce->PRIVATEWB->event.wait(ce->sock)) {
piMSleep(10); piMSleep(10);
return; return;
} }
#endif # endif
// piCout << "server" << "accept ..."; // piCout << "server" << "accept ...";
int s = accept(ce->sock, (sockaddr *)&client_addr, &slen); int s = accept(ce->sock, (sockaddr *)&client_addr, &slen);
// piCout << "server" << "accept done" << ethErrorString(); // piCout << "server" << "accept done" << ethErrorString();
if (s == -1) { if (s == -1) {
int lerr = ethErrorCore(); int lerr = ethErrorCore();
#ifdef WINDOWS # ifdef WINDOWS
if (lerr == WSAETIMEDOUT) { if (lerr == WSAETIMEDOUT) {
#elif defined(ANDROID) # elif defined(ANDROID)
if ((lerr == EAGAIN || lerr == EINTR)) { if ((lerr == EAGAIN || lerr == EINTR)) {
#else # else
if (lerr == EAGAIN) { if (lerr == EAGAIN) {
#endif # endif
piMSleep(10); piMSleep(10);
return; return;
} }
@@ -969,7 +970,7 @@ void PIEthernet::setType(Type t, bool reopen) {
bool PIEthernet::connectTCP() { bool PIEthernet::connectTCP() {
::connect(sock, (sockaddr *)&(PRIVATE->addr_), sizeof(PRIVATE->addr_)); ::connect(sock, (sockaddr *)&(PRIVATE->addr_), sizeof(PRIVATE->addr_));
// piCout << errorString(); // piCout << errorString();
#ifdef WINDOWS # ifdef WINDOWS
long wr = waitForEvent(PRIVATE->event, FD_CONNECT | FD_CLOSE); long wr = waitForEvent(PRIVATE->event, FD_CONNECT | FD_CLOSE);
switch (wr) { switch (wr) {
case FD_CONNECT: case FD_CONNECT:
@@ -977,7 +978,7 @@ bool PIEthernet::connectTCP() {
return ethIsWriteable(sock); return ethIsWriteable(sock);
default: break; default: break;
} }
#else # else
if (PRIVATE->event.wait(sock, PIWaitEvent::CheckWrite)) { if (PRIVATE->event.wait(sock, PIWaitEvent::CheckWrite)) {
if (ethIsWriteable(sock)) if (ethIsWriteable(sock))
return true; return true;
@@ -986,12 +987,12 @@ bool PIEthernet::connectTCP() {
init(); init();
} }
} }
#endif # endif
return false; return false;
} }
#ifdef WINDOWS # ifdef WINDOWS
long PIEthernet::waitForEvent(PIWaitEvent & event, long mask) { long PIEthernet::waitForEvent(PIWaitEvent & event, long mask) {
if (!event.isCreate() || sock < 0) return 0; if (!event.isCreate() || sock < 0) return 0;
if (WSAEventSelect(sock, event.getEvent(), mask) == SOCKET_ERROR) { if (WSAEventSelect(sock, event.getEvent(), mask) == SOCKET_ERROR) {
@@ -1008,7 +1009,7 @@ long PIEthernet::waitForEvent(PIWaitEvent & event, long mask) {
} }
return 0; return 0;
} }
#endif # endif
bool PIEthernet::configureDevice(const void * e_main, const void * e_parent) { bool PIEthernet::configureDevice(const void * e_main, const void * e_parent) {
@@ -1118,7 +1119,7 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
Interface ci; Interface ci;
ci.index = -1; ci.index = -1;
ci.mtu = 1500; ci.mtu = 1500;
#ifdef WINDOWS # ifdef WINDOWS
int ret = 0; int ret = 0;
ulong ulOutBufLen = sizeof(IP_ADAPTER_INFO); ulong ulOutBufLen = sizeof(IP_ADAPTER_INFO);
PIP_ADAPTER_INFO pAdapterInfo = (PIP_ADAPTER_INFO)HeapAlloc(GetProcessHeap(), 0, sizeof(IP_ADAPTER_INFO)); PIP_ADAPTER_INFO pAdapterInfo = (PIP_ADAPTER_INFO)HeapAlloc(GetProcessHeap(), 0, sizeof(IP_ADAPTER_INFO));
@@ -1169,10 +1170,10 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
} }
} }
if (pAdapterInfo) HeapFree(GetProcessHeap(), 0, pAdapterInfo); if (pAdapterInfo) HeapFree(GetProcessHeap(), 0, pAdapterInfo);
#else
# ifdef MICRO_PIP
# else # else
# ifdef ANDROID # ifdef LWIP
# else
# ifdef ANDROID
struct ifconf ifc; struct ifconf ifc;
int s = ::socket(AF_INET, SOCK_STREAM, IPPROTO_IP); int s = ::socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
ifc.ifc_len = 256; ifc.ifc_len = 256;
@@ -1200,7 +1201,7 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
il << ci; il << ci;
} }
delete ifc.ifc_buf; delete ifc.ifc_buf;
# else # else
struct ifaddrs *ret, *cif = 0; struct ifaddrs *ret, *cif = 0;
int s = ::socket(AF_INET, SOCK_STREAM, IPPROTO_IP); int s = ::socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
if (getifaddrs(&ret) == 0) { if (getifaddrs(&ret) == 0) {
@@ -1218,8 +1219,8 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
ci.address = getSockAddr(cif->ifa_addr); ci.address = getSockAddr(cif->ifa_addr);
ci.netmask = getSockAddr(cif->ifa_netmask); ci.netmask = getSockAddr(cif->ifa_netmask);
ci.mac.clear(); ci.mac.clear();
# ifdef QNX # ifdef QNX
# ifndef BLACKBERRY # ifndef BLACKBERRY
int fd = ::open((PIString("/dev/io-net/") + ci.name).dataAscii(), O_RDONLY); int fd = ::open((PIString("/dev/io-net/") + ci.name).dataAscii(), O_RDONLY);
if (fd != 0) { if (fd != 0) {
nic_config_t nic; nic_config_t nic;
@@ -1227,9 +1228,9 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
::close(fd); ::close(fd);
ci.mac = macFromBytes(PIByteArray(nic.permanent_address, 6)); ci.mac = macFromBytes(PIByteArray(nic.permanent_address, 6));
} }
# endif # endif
# else # else
# ifdef MAC_OS # ifdef MAC_OS
PIString req = PISystemInfo::instance()->ifconfigPath + " " + ci.name + " | grep ether"; PIString req = PISystemInfo::instance()->ifconfigPath + " " + ci.name + " | grep ether";
FILE * fp = popen(req.dataAscii(), "r"); FILE * fp = popen(req.dataAscii(), "r");
if (fp != 0) { if (fp != 0) {
@@ -1240,7 +1241,7 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
} }
pclose(fp); pclose(fp);
} }
# else # else
if (s != -1) { if (s != -1) {
struct ifreq ir; struct ifreq ir;
memset(&ir, 0, sizeof(ir)); memset(&ir, 0, sizeof(ir));
@@ -1252,8 +1253,8 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
ci.mtu = ir.ifr_mtu; ci.mtu = ir.ifr_mtu;
} }
} }
# endif
# endif # endif
# endif
ci.flags = 0; ci.flags = 0;
if (cif->ifa_flags & IFF_UP) ci.flags |= PIEthernet::ifActive; if (cif->ifa_flags & IFF_UP) ci.flags |= PIEthernet::ifActive;
if (cif->ifa_flags & IFF_RUNNING) ci.flags |= PIEthernet::ifRunning; if (cif->ifa_flags & IFF_RUNNING) ci.flags |= PIEthernet::ifRunning;
@@ -1274,18 +1275,18 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
piCout << "[PIEthernet]" piCout << "[PIEthernet]"
<< "Can`t get interfaces: %1"_tr("PIEthernet").arg(errorString()); << "Can`t get interfaces: %1"_tr("PIEthernet").arg(errorString());
if (s != -1) ::close(s); if (s != -1) ::close(s);
# endif
# endif # endif
# endif # endif
#endif
return il; return il;
} }
PINetworkAddress PIEthernet::interfaceAddress(const PIString & interface_) { PINetworkAddress PIEthernet::interfaceAddress(const PIString & interface_) {
#if defined(WINDOWS) || defined(MICRO_PIP) # if defined(WINDOWS) || defined(LWIP)
piCout << "[PIEthernet] Not implemented, use \"PIEthernet::allAddresses\" or \"PIEthernet::interfaces\" instead"; piCout << "[PIEthernet] Not implemented, use \"PIEthernet::allAddresses\" or \"PIEthernet::interfaces\" instead";
return PINetworkAddress(); return PINetworkAddress();
#else # else
struct ifreq ifr; struct ifreq ifr;
piZeroMemory(ifr); piZeroMemory(ifr);
strcpy(ifr.ifr_name, interface_.dataAscii()); strcpy(ifr.ifr_name, interface_.dataAscii());
@@ -1294,7 +1295,7 @@ PINetworkAddress PIEthernet::interfaceAddress(const PIString & interface_) {
::close(s); ::close(s);
struct sockaddr_in * sa = (struct sockaddr_in *)&ifr.ifr_addr; struct sockaddr_in * sa = (struct sockaddr_in *)&ifr.ifr_addr;
return PINetworkAddress(uint(sa->sin_addr.s_addr)); return PINetworkAddress(uint(sa->sin_addr.s_addr));
#endif # endif
} }
@@ -1317,16 +1318,16 @@ PIVector<PINetworkAddress> PIEthernet::allAddresses() {
// System wrap // System wrap
int PIEthernet::ethErrorCore() { int PIEthernet::ethErrorCore() {
#ifdef WINDOWS # ifdef WINDOWS
return WSAGetLastError(); return WSAGetLastError();
#else # else
return errno; return errno;
#endif # endif
} }
PIString PIEthernet::ethErrorString() { PIString PIEthernet::ethErrorString() {
#ifdef WINDOWS # ifdef WINDOWS
char * msg = nullptr; char * msg = nullptr;
int err = WSAGetLastError(); int err = WSAGetLastError();
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
@@ -1343,18 +1344,18 @@ PIString PIEthernet::ethErrorString() {
} else } else
ret += '?'; ret += '?';
return ret; return ret;
#else # else
return errorString(); return errorString();
#endif # endif
} }
int PIEthernet::ethRecv(int sock, void * buf, int size, int flags) { int PIEthernet::ethRecv(int sock, void * buf, int size, int flags) {
if (sock < 0) return -1; if (sock < 0) return -1;
return recv(sock, return recv(sock,
#ifdef WINDOWS # ifdef WINDOWS
(char *) (char *)
#endif # endif
buf, buf,
size, size,
flags); flags);
@@ -1363,29 +1364,29 @@ int PIEthernet::ethRecv(int sock, void * buf, int size, int flags) {
int PIEthernet::ethRecvfrom(int sock, void * buf, int size, int flags, sockaddr * addr) { int PIEthernet::ethRecvfrom(int sock, void * buf, int size, int flags, sockaddr * addr) {
if (sock < 0) return -1; if (sock < 0) return -1;
#ifdef QNX # ifdef QNX
return recv(sock, buf, size, flags); return recv(sock, buf, size, flags);
#else # else
socklen_t len = sizeof(sockaddr); socklen_t len = sizeof(sockaddr);
return recvfrom(sock, return recvfrom(sock,
# ifdef WINDOWS # ifdef WINDOWS
(char *) (char *)
# endif # endif
buf, buf,
size, size,
flags, flags,
addr, addr,
&len); &len);
#endif # endif
} }
int PIEthernet::ethSendto(int sock, const void * buf, int size, int flags, sockaddr * addr, int addr_len) { int PIEthernet::ethSendto(int sock, const void * buf, int size, int flags, sockaddr * addr, int addr_len) {
if (sock < 0) return -1; if (sock < 0) return -1;
return sendto(sock, return sendto(sock,
#ifdef WINDOWS # ifdef WINDOWS
(const char *) (const char *)
#endif # endif
buf, buf,
size, size,
flags, flags,
@@ -1399,26 +1400,26 @@ void PIEthernet::ethClosesocket(int sock, bool shutdown) {
if (sock < 0) return; if (sock < 0) return;
if (shutdown) if (shutdown)
::shutdown(sock, ::shutdown(sock,
#ifdef WINDOWS # ifdef WINDOWS
SD_BOTH); SD_BOTH);
closesocket(sock); closesocket(sock);
#else # else
SHUT_RDWR); SHUT_RDWR);
::close(sock); ::close(sock);
#endif # endif
} }
int PIEthernet::ethSetsockopt(int sock, int level, int optname, const void * optval, int optlen) { int PIEthernet::ethSetsockopt(int sock, int level, int optname, const void * optval, int optlen) {
if (sock < 0) return -1; if (sock < 0) return -1;
auto ret = setsockopt(sock, auto ret = setsockopt(sock,
level, level,
optname, optname,
#ifdef WINDOWS # ifdef WINDOWS
(char *) (char *)
#endif # endif
optval, optval,
optlen); optlen);
if (ret != 0) piCout << "setsockopt error:" << ethErrorString(); if (ret != 0) piCout << "setsockopt error:" << ethErrorString();
return ret; return ret;
} }
@@ -1426,11 +1427,11 @@ int PIEthernet::ethSetsockopt(int sock, int level, int optname, const void * opt
int PIEthernet::ethSetsockoptInt(int sock, int level, int optname, int value) { int PIEthernet::ethSetsockoptInt(int sock, int level, int optname, int value) {
if (sock < 0) return -1; if (sock < 0) return -1;
#ifdef WINDOWS # ifdef WINDOWS
DWORD DWORD
#else # else
int int
#endif # endif
so = value; so = value;
return ethSetsockopt(sock, level, optname, &so, sizeof(so)); return ethSetsockopt(sock, level, optname, &so, sizeof(so));
} }
@@ -1438,11 +1439,11 @@ int PIEthernet::ethSetsockoptInt(int sock, int level, int optname, int value) {
int PIEthernet::ethSetsockoptBool(int sock, int level, int optname, bool value) { int PIEthernet::ethSetsockoptBool(int sock, int level, int optname, bool value) {
if (sock < 0) return -1; if (sock < 0) return -1;
#ifdef WINDOWS # ifdef WINDOWS
BOOL BOOL
#else # else
int int
#endif # endif
so = (value ? 1 : 0); so = (value ? 1 : 0);
return ethSetsockopt(sock, level, optname, &so, sizeof(so)); return ethSetsockopt(sock, level, optname, &so, sizeof(so));
} }
@@ -1450,12 +1451,12 @@ int PIEthernet::ethSetsockoptBool(int sock, int level, int optname, bool value)
void PIEthernet::ethNonblocking(int sock) { void PIEthernet::ethNonblocking(int sock) {
if (sock < 0) return; if (sock < 0) return;
#ifdef WINDOWS # ifdef WINDOWS
u_long mode = 1; u_long mode = 1;
ioctlsocket(sock, FIONBIO, &mode); ioctlsocket(sock, FIONBIO, &mode);
#else # else
fcntl(sock, F_SETFL, O_NONBLOCK); fcntl(sock, F_SETFL, O_NONBLOCK);
#endif # endif
} }
@@ -1471,7 +1472,7 @@ bool PIEthernet::ethIsWriteable(int sock) {
timeout.tv_sec = timeout.tv_usec = 0; timeout.tv_sec = timeout.tv_usec = 0;
::select(fds, nullptr, &fd_test, nullptr, &timeout); ::select(fds, nullptr, &fd_test, nullptr, &timeout);
return FD_ISSET(sock, &fd_test);*/ return FD_ISSET(sock, &fd_test);*/
#ifdef WINDOWS # ifdef WINDOWS
fd_set fd_test; fd_set fd_test;
FD_ZERO(&fd_test); FD_ZERO(&fd_test);
FD_SET(sock, &fd_test); FD_SET(sock, &fd_test);
@@ -1479,10 +1480,12 @@ bool PIEthernet::ethIsWriteable(int sock) {
timeout.tv_sec = timeout.tv_usec = 0; timeout.tv_sec = timeout.tv_usec = 0;
::select(0, nullptr, &fd_test, nullptr, &timeout); ::select(0, nullptr, &fd_test, nullptr, &timeout);
return FD_ISSET(sock, &fd_test); return FD_ISSET(sock, &fd_test);
#else # else
int ret = 0; int ret = 0;
socklen_t len = sizeof(ret); socklen_t len = sizeof(ret);
getsockopt(sock, SOL_SOCKET, SO_ERROR, (char *)&ret, &len); getsockopt(sock, SOL_SOCKET, SO_ERROR, (char *)&ret, &len);
return ret == 0; return ret == 0;
#endif # endif
} }
#endif // PIP_NO_SOCKET

View File

@@ -26,14 +26,17 @@
#ifndef PIETHERNET_H #ifndef PIETHERNET_H
#define PIETHERNET_H #define PIETHERNET_H
#include "piiodevice.h" #include "piiodevice.h"
#include "pinetworkaddress.h" #include "pinetworkaddress.h"
#ifdef ANDROID #ifndef PIP_NO_SOCKET
# ifdef ANDROID
struct struct
#else # else
class class
#endif # endif
sockaddr; sockaddr;
class PIP_EXPORT PIEthernet: public PIIODevice { class PIP_EXPORT PIEthernet: public PIIODevice {
@@ -439,7 +442,7 @@ public:
//! \} //! \}
//! \ioparams //! \ioparams
//! \{ //! \{
#ifdef DOXYGEN # ifdef DOXYGEN
//! \brief read ip, default "" //! \brief read ip, default ""
string ip; string ip;
@@ -460,7 +463,7 @@ public:
//! \brief time-to-live for multicast, default 1 //! \brief time-to-live for multicast, default 1
int multicastTTL; int multicastTTL;
#endif # endif
//! \} //! \}
protected: protected:
@@ -509,9 +512,9 @@ private:
static void server_func(void * eth); static void server_func(void * eth);
void setType(Type t, bool reopen = true); void setType(Type t, bool reopen = true);
bool connectTCP(); bool connectTCP();
#ifdef WINDOWS # ifdef WINDOWS
long waitForEvent(PIWaitEvent & event, long mask); long waitForEvent(PIWaitEvent & event, long mask);
#endif # endif
static int ethErrorCore(); static int ethErrorCore();
static PIString ethErrorString(); static PIString ethErrorString();
@@ -536,4 +539,5 @@ inline bool operator!=(const PIEthernet::Interface & v0, const PIEthernet::Inter
return (v0.name != v1.name || v0.address != v1.address || v0.netmask != v1.netmask); return (v0.name != v1.name || v0.address != v1.address || v0.netmask != v1.netmask);
} }
#endif // PIP_NO_SOCKET
#endif // PIETHERNET_H #endif // PIETHERNET_H

View File

@@ -45,7 +45,7 @@
# include <utime.h> # include <utime.h>
#endif #endif
#define S_IFHDN 0x40 #define S_IFHDN 0x40
#if defined(QNX) || defined(ANDROID) || defined(FREERTOS) #if defined(QNX) || defined(ANDROID) || defined(MICRO_PIP)
# define _fopen_call_ fopen # define _fopen_call_ fopen
# define _fseek_call_ fseek # define _fseek_call_ fseek
# define _ftell_call_ ftell # define _ftell_call_ ftell

View File

@@ -390,7 +390,7 @@ void PIIODevice::read_func() {
ssize_t readed_ = read(buffer_tr.data(), buffer_tr.size_s()); ssize_t readed_ = read(buffer_tr.data(), buffer_tr.size_s());
if (read_thread.isStopping()) return; if (read_thread.isStopping()) return;
if (readed_ <= 0) { if (readed_ <= 0) {
piMSleep(10); piMSleep(threaded_read_timeout_ms);
// cout << readed_ << ", " << errno << ", " << errorString() << endl; // cout << readed_ << ", " << errno << ", " << errorString() << endl;
return; return;
} }

View File

@@ -271,6 +271,10 @@ public:
bool waitThreadedReadFinished(PISystemTime timeout = {}); bool waitThreadedReadFinished(PISystemTime timeout = {});
uint threadedReadTimeout() const { return threaded_read_timeout_ms; }
void setThreadedReadTimeout(uint ms) { threaded_read_timeout_ms = ms; }
//! \~english Returns if threaded write is started //! \~english Returns if threaded write is started
//! \~russian Возвращает запущен ли поток записи //! \~russian Возвращает запущен ли поток записи
bool isThreadedWrite() const; bool isThreadedWrite() const;
@@ -591,7 +595,7 @@ private:
PIQueue<PIPair<PIByteArray, ullong>> write_queue; PIQueue<PIPair<PIByteArray, ullong>> write_queue;
PISystemTime reopen_timeout; PISystemTime reopen_timeout;
ullong tri = 0; ullong tri = 0;
uint threaded_read_buffer_size; uint threaded_read_buffer_size, threaded_read_timeout_ms = 10;
bool reopen_enabled = true, destroying = false; bool reopen_enabled = true, destroying = false;
static PIMutex nfp_mutex; static PIMutex nfp_mutex;

View File

@@ -19,38 +19,37 @@
#include "piserial.h" #include "piserial.h"
#include "piconfig.h" #ifndef MICRO_PIP
#include "pidir.h"
#include "piincludes_p.h"
#include "pipropertystorage.h"
#include "pitime.h"
#include "pitranslator.h"
#include "piwaitevent_p.h"
#include <errno.h> # include "piconfig.h"
# include "pidir.h"
# include "piincludes_p.h"
# include "pipropertystorage.h"
# include "pitime.h"
# include "pitranslator.h"
# include "piwaitevent_p.h"
#if defined(MICRO_PIP) # include <errno.h>
# define PISERIAL_NO_PINS
#endif # if defined(PISERIAL_NO_PINS) || defined(WINDOWS)
#if defined(PISERIAL_NO_PINS) || defined(WINDOWS) # define TIOCM_LE 1
# define TIOCM_LE 1 # define TIOCM_DTR 4
# define TIOCM_DTR 4 # define TIOCM_RTS 7
# define TIOCM_RTS 7 # define TIOCM_CTS 8
# define TIOCM_CTS 8 # define TIOCM_ST 3
# define TIOCM_ST 3 # define TIOCM_SR 2
# define TIOCM_SR 2 # define TIOCM_CAR 1
# define TIOCM_CAR 1 # define TIOCM_RNG 9
# define TIOCM_RNG 9 # define TIOCM_DSR 6
# define TIOCM_DSR 6
#endif
#ifdef WINDOWS
# ifndef INITGUID
# define INITGUID
# include <guiddef.h>
# undef INITGUID
# else
# include <guiddef.h>
# endif # endif
# ifdef WINDOWS
# ifndef INITGUID
# define INITGUID
# include <guiddef.h>
# undef INITGUID
# else
# include <guiddef.h>
# endif
// clang-format off // clang-format off
# include <ntddmodm.h> # include <ntddmodm.h>
# include <winreg.h> # include <winreg.h>
@@ -59,89 +58,89 @@
# include <cfgmgr32.h> # include <cfgmgr32.h>
# include <setupapi.h> # include <setupapi.h>
// clang-format on // clang-format on
# define B50 50 # define B50 50
# define B75 75 # define B75 75
# define B110 110 # define B110 110
# define B300 300 # define B300 300
# define B600 600 # define B600 600
# define B1200 1200 # define B1200 1200
# define B2400 2400 # define B2400 2400
# define B4800 4800 # define B4800 4800
# define B9600 9600 # define B9600 9600
# define B14400 14400 # define B14400 14400
# define B19200 19200 # define B19200 19200
# define B38400 38400 # define B38400 38400
# define B57600 57600 # define B57600 57600
# define B115200 115200 # define B115200 115200
# define B230400 230400 # define B230400 230400
# define B460800 460800 # define B460800 460800
# define B500000 500000 # define B500000 500000
# define B576000 576000 # define B576000 576000
# define B921600 921600 # define B921600 921600
# define B1000000 1000000 # define B1000000 1000000
# define B1152000 1152000 # define B1152000 1152000
# define B1500000 1500000 # define B1500000 1500000
# define B2000000 2000000 # define B2000000 2000000
# define B2500000 2500000 # define B2500000 2500000
# define B3000000 3000000 # define B3000000 3000000
# define B3500000 3500000 # define B3500000 3500000
# define B4000000 4000000 # define B4000000 4000000
#else # else
# include <fcntl.h> # include <fcntl.h>
# include <sys/ioctl.h> # include <sys/ioctl.h>
# include <termios.h> # include <termios.h>
# ifndef B50 # ifndef B50
# define B50 0000001 # define B50 0000001
# endif
# ifndef B75
# define B75 0000002
# endif
# ifndef B230400
# define B230400 0010003
# endif
# ifndef B460800
# define B460800 0010004
# endif
# ifndef B500000
# define B500000 0010005
# endif
# ifndef B576000
# define B576000 0010006
# endif
# ifndef B921600
# define B921600 0010007
# endif
# ifndef B1000000
# define B1000000 0010010
# endif
# ifndef B1152000
# define B1152000 0010011
# endif
# ifndef B1500000
# define B1500000 0010012
# endif
# ifndef B2000000
# define B2000000 0010013
# endif
# ifndef B2500000
# define B2500000 0010014
# endif
# ifndef B3000000
# define B3000000 0010015
# endif
# ifndef B3500000
# define B3500000 0010016
# endif
# ifndef B4000000
# define B4000000 0010017
# endif
# endif # endif
# ifndef B75 # ifndef CRTSCTS
# define B75 0000002 # define CRTSCTS 020000000000
# endif # endif
# ifndef B230400 # ifdef LINUX
# define B230400 0010003 # include <linux/serial.h>
# endif # endif
# ifndef B460800
# define B460800 0010004
# endif
# ifndef B500000
# define B500000 0010005
# endif
# ifndef B576000
# define B576000 0010006
# endif
# ifndef B921600
# define B921600 0010007
# endif
# ifndef B1000000
# define B1000000 0010010
# endif
# ifndef B1152000
# define B1152000 0010011
# endif
# ifndef B1500000
# define B1500000 0010012
# endif
# ifndef B2000000
# define B2000000 0010013
# endif
# ifndef B2500000
# define B2500000 0010014
# endif
# ifndef B3000000
# define B3000000 0010015
# endif
# ifndef B3500000
# define B3500000 0010016
# endif
# ifndef B4000000
# define B4000000 0010017
# endif
#endif
#ifndef CRTSCTS
# define CRTSCTS 020000000000
#endif
#ifdef LINUX
# include <linux/serial.h>
#endif
//! \class PISerial piserial.h //! \class PISerial piserial.h
@@ -177,16 +176,16 @@ REGISTER_DEVICE(PISerial)
PRIVATE_DEFINITION_START(PISerial) PRIVATE_DEFINITION_START(PISerial)
PIWaitEvent event; PIWaitEvent event;
#ifdef WINDOWS # ifdef WINDOWS
PIWaitEvent event_write; PIWaitEvent event_write;
DCB desc, sdesc; DCB desc, sdesc;
HANDLE hCom = nullptr; HANDLE hCom = nullptr;
DWORD readed = 0, mask = 0; DWORD readed = 0, mask = 0;
OVERLAPPED overlap, overlap_write; OVERLAPPED overlap, overlap_write;
#else # else
termios desc, sdesc; termios desc, sdesc;
uint readed = 0; uint readed = 0;
#endif # endif
PRIVATE_DEFINITION_END(PISerial) PRIVATE_DEFINITION_END(PISerial)
@@ -214,9 +213,9 @@ PISerial::~PISerial() {
stopAndWait(); stopAndWait();
close(); close();
PRIVATE->event.destroy(); PRIVATE->event.destroy();
#ifdef WINDOWS # ifdef WINDOWS
PRIVATE->event_write.destroy(); PRIVATE->event_write.destroy();
#endif # endif
} }
@@ -347,7 +346,7 @@ bool PISerial::setBreak(bool enabled) {
piCoutObj << "sendBreak error: \"" << path() << "\" is not opened!"; piCoutObj << "sendBreak error: \"" << path() << "\" is not opened!";
return false; return false;
} }
#ifdef WINDOWS # ifdef WINDOWS
if (enabled) { if (enabled) {
if (!SetCommBreak(PRIVATE->hCom)) { if (!SetCommBreak(PRIVATE->hCom)) {
piCoutObj << "setBreak error: " << errorString(); piCoutObj << "setBreak error: " << errorString();
@@ -363,14 +362,14 @@ bool PISerial::setBreak(bool enabled) {
return true; return true;
} }
} }
#else # else
if (ioctl(fd, enabled ? TIOCSBRK : TIOCCBRK) < 0) { if (ioctl(fd, enabled ? TIOCSBRK : TIOCCBRK) < 0) {
piCoutObj << "setBreak error: " << errorString(); piCoutObj << "setBreak error: " << errorString();
return false; return false;
} else { } else {
return true; return true;
} }
#endif # endif
return false; return false;
} }
@@ -380,8 +379,8 @@ bool PISerial::setBit(int bit, bool on, const PIString & bname) {
piCoutObj << "setBit" << bname << " error: \"" << path() << "\" is not opened!"; piCoutObj << "setBit" << bname << " error: \"" << path() << "\" is not opened!";
return false; return false;
} }
#ifndef PISERIAL_NO_PINS # ifndef PISERIAL_NO_PINS
# ifdef WINDOWS # ifdef WINDOWS
static int bit_map_on[] = {0, 0, 0, 0, SETDTR, 0, 0, SETRTS, 0, 0, 0}; static int bit_map_on[] = {0, 0, 0, 0, SETDTR, 0, 0, SETRTS, 0, 0, 0};
static int bit_map_off[] = {0, 0, 0, 0, CLRDTR, 0, 0, CLRRTS, 0, 0, 0}; static int bit_map_off[] = {0, 0, 0, 0, CLRDTR, 0, 0, CLRRTS, 0, 0, 0};
int action = (on ? bit_map_on : bit_map_off)[bit]; int action = (on ? bit_map_on : bit_map_off)[bit];
@@ -392,14 +391,14 @@ bool PISerial::setBit(int bit, bool on, const PIString & bname) {
} }
return true; return true;
} }
# else # else
if (ioctl(fd, on ? TIOCMBIS : TIOCMBIC, &bit) < 0) { if (ioctl(fd, on ? TIOCMBIS : TIOCMBIC, &bit) < 0) {
piCoutObj << "setBit" << bname << " error: " << errorString(); piCoutObj << "setBit" << bname << " error: " << errorString();
return false; return false;
} }
return true; return true;
# endif
# endif # endif
#endif
piCoutObj << "setBit" << bname << " doesn`t implemented, sorry :-("; piCoutObj << "setBit" << bname << " doesn`t implemented, sorry :-(";
return false; return false;
} }
@@ -410,23 +409,23 @@ bool PISerial::isBit(int bit, const PIString & bname) const {
piCoutObj << "isBit" << bname << " error: \"" << path() << "\" is not opened!"; piCoutObj << "isBit" << bname << " error: \"" << path() << "\" is not opened!";
return false; return false;
} }
#ifndef PISERIAL_NO_PINS # ifndef PISERIAL_NO_PINS
# ifdef WINDOWS # ifdef WINDOWS
# else # else
int ret = 0; int ret = 0;
if (ioctl(fd, TIOCMGET, &ret) < 0) piCoutObj << "isBit" << bname << " error: " << errorString(); if (ioctl(fd, TIOCMGET, &ret) < 0) piCoutObj << "isBit" << bname << " error: " << errorString();
return ret & bit; return ret & bit;
# endif
# endif # endif
#endif
piCoutObj << "isBit" << bname << " doesn`t implemented, sorry :-("; piCoutObj << "isBit" << bname << " doesn`t implemented, sorry :-(";
return false; return false;
} }
void PISerial::flush() { void PISerial::flush() {
#ifndef WINDOWS # ifndef WINDOWS
if (fd != -1) tcflush(fd, TCIOFLUSH); if (fd != -1) tcflush(fd, TCIOFLUSH);
#endif # endif
} }
@@ -441,9 +440,9 @@ int PISerial::convertSpeed(PISerial::Speed speed) {
case S2400: return B2400; case S2400: return B2400;
case S4800: return B4800; case S4800: return B4800;
case S9600: return B9600; case S9600: return B9600;
#ifdef WINDOWS # ifdef WINDOWS
case S14400: return B14400; case S14400: return B14400;
#endif # endif
case S19200: return B19200; case S19200: return B19200;
case S38400: return B38400; case S38400: return B38400;
case S57600: return B57600; case S57600: return B57600;
@@ -463,13 +462,13 @@ int PISerial::convertSpeed(PISerial::Speed speed) {
case S4000000: return B4000000; case S4000000: return B4000000;
default: break; default: break;
} }
#ifdef WINDOWS # ifdef WINDOWS
piCoutObj << "Warning: Custom speed %1"_tr("PISerial").arg((int)speed); piCoutObj << "Warning: Custom speed %1"_tr("PISerial").arg((int)speed);
return (int)speed; return (int)speed;
#else # else
piCoutObj << "Warning: Unknown speed %1, using 115200"_tr("PISerial").arg((int)speed); piCoutObj << "Warning: Unknown speed %1, using 115200"_tr("PISerial").arg((int)speed);
return B115200; return B115200;
#endif # endif
} }
@@ -672,9 +671,9 @@ bool PISerial::send(const void * data, int size) {
void PISerial::interrupt() { void PISerial::interrupt() {
// piCoutObj << "interrupt"; // piCoutObj << "interrupt";
PRIVATE->event.interrupt(); PRIVATE->event.interrupt();
#ifdef WINDOWS # ifdef WINDOWS
PRIVATE->event_write.interrupt(); PRIVATE->event_write.interrupt();
#endif # endif
} }
@@ -696,7 +695,7 @@ bool PISerial::openDevice() {
} }
} }
if (p.isEmpty()) return false; if (p.isEmpty()) return false;
#ifdef WINDOWS # ifdef WINDOWS
DWORD ds = 0, sm = 0; DWORD ds = 0, sm = 0;
if (isReadable()) { if (isReadable()) {
ds |= GENERIC_READ; ds |= GENERIC_READ;
@@ -714,7 +713,7 @@ bool PISerial::openDevice() {
return false; return false;
} }
fd = 0; fd = 0;
#else # else
int om = 0; int om = 0;
switch (mode()) { switch (mode()) {
case PIIODevice::ReadOnly: om = O_RDONLY; break; case PIIODevice::ReadOnly: om = O_RDONLY; break;
@@ -729,12 +728,12 @@ bool PISerial::openDevice() {
tcgetattr(fd, &PRIVATE->desc); tcgetattr(fd, &PRIVATE->desc);
PRIVATE->sdesc = PRIVATE->desc; PRIVATE->sdesc = PRIVATE->desc;
// piCoutObj << "Initialized " << p; // piCoutObj << "Initialized " << p;
#endif # endif
applySettings(); applySettings();
PRIVATE->event.create(); PRIVATE->event.create();
#ifdef WINDOWS # ifdef WINDOWS
PRIVATE->event_write.create(); PRIVATE->event_write.create();
#endif # endif
return true; return true;
} }
@@ -745,28 +744,28 @@ bool PISerial::closeDevice() {
stopThreadedRead(); stopThreadedRead();
} }
if (fd != -1) { if (fd != -1) {
#ifdef WINDOWS # ifdef WINDOWS
SetCommState(PRIVATE->hCom, &PRIVATE->sdesc); SetCommState(PRIVATE->hCom, &PRIVATE->sdesc);
SetCommMask(PRIVATE->hCom, PRIVATE->mask); SetCommMask(PRIVATE->hCom, PRIVATE->mask);
// piCoutObj << "close" << // piCoutObj << "close" <<
CloseHandle(PRIVATE->hCom); CloseHandle(PRIVATE->hCom);
PRIVATE->hCom = 0; PRIVATE->hCom = 0;
#else # else
tcsetattr(fd, TCSANOW, &PRIVATE->sdesc); tcsetattr(fd, TCSANOW, &PRIVATE->sdesc);
::close(fd); ::close(fd);
#endif # endif
fd = -1; fd = -1;
} }
PRIVATE->event.destroy(); PRIVATE->event.destroy();
#ifdef WINDOWS # ifdef WINDOWS
PRIVATE->event_write.destroy(); PRIVATE->event_write.destroy();
#endif # endif
return true; return true;
} }
void PISerial::applySettings() { void PISerial::applySettings() {
#ifdef WINDOWS # ifdef WINDOWS
if (fd == -1) return; if (fd == -1) return;
setTimeouts(); setTimeouts();
GetCommMask(PRIVATE->hCom, &PRIVATE->mask); GetCommMask(PRIVATE->hCom, &PRIVATE->mask);
@@ -792,7 +791,7 @@ void PISerial::applySettings() {
piCoutObj << "Unable to set comm state for \"%1\""_tr("PISerial").arg(path()); piCoutObj << "Unable to set comm state for \"%1\""_tr("PISerial").arg(path());
return; return;
} }
#else # else
if (fd == -1) return; if (fd == -1) return;
tcgetattr(fd, &PRIVATE->desc); tcgetattr(fd, &PRIVATE->desc);
PRIVATE->desc.c_oflag = PRIVATE->desc.c_lflag = PRIVATE->desc.c_cflag = 0; PRIVATE->desc.c_oflag = PRIVATE->desc.c_lflag = PRIVATE->desc.c_cflag = 0;
@@ -826,12 +825,12 @@ void PISerial::applySettings() {
piCoutObj << "Can`t set attributes for \"%1\""_tr("PISerial").arg(path()); piCoutObj << "Can`t set attributes for \"%1\""_tr("PISerial").arg(path());
return; return;
} }
#endif # endif
} }
void PISerial::setTimeouts() { void PISerial::setTimeouts() {
#ifdef WINDOWS # ifdef WINDOWS
COMMTIMEOUTS times; COMMTIMEOUTS times;
if (isOptionSet(BlockingRead)) { if (isOptionSet(BlockingRead)) {
times.ReadIntervalTimeout = MAXDWORD; times.ReadIntervalTimeout = MAXDWORD;
@@ -845,9 +844,9 @@ void PISerial::setTimeouts() {
times.WriteTotalTimeoutConstant = isOptionSet(BlockingWrite) ? 0 : 1; times.WriteTotalTimeoutConstant = isOptionSet(BlockingWrite) ? 0 : 1;
times.WriteTotalTimeoutMultiplier = 0; times.WriteTotalTimeoutMultiplier = 0;
if (SetCommTimeouts(PRIVATE->hCom, &times) == -1) piCoutObj << "Unable to set timeouts for \"" << path() << "\""; if (SetCommTimeouts(PRIVATE->hCom, &times) == -1) piCoutObj << "Unable to set timeouts for \"" << path() << "\"";
#else # else
fcntl(fd, F_SETFL, isOptionSet(BlockingRead) ? 0 : O_NONBLOCK); fcntl(fd, F_SETFL, isOptionSet(BlockingRead) ? 0 : O_NONBLOCK);
#endif # endif
} }
@@ -866,7 +865,7 @@ void PISerial::setTimeouts() {
//! //!
//! \~\sa \a readData(), \a readString() //! \~\sa \a readData(), \a readString()
ssize_t PISerial::readDevice(void * read_to, ssize_t max_size) { ssize_t PISerial::readDevice(void * read_to, ssize_t max_size) {
#ifdef WINDOWS # ifdef WINDOWS
if (!canRead()) return -1; if (!canRead()) return -1;
if (sending) return -1; if (sending) return -1;
// piCoutObj << "read ..." << PRIVATE->hCom << max_size; // piCoutObj << "read ..." << PRIVATE->hCom << max_size;
@@ -896,7 +895,7 @@ ssize_t PISerial::readDevice(void * read_to, ssize_t max_size) {
return -1; return -1;
// piCoutObj << "read" << (PRIVATE->readed) << errorString(); // piCoutObj << "read" << (PRIVATE->readed) << errorString();
return PRIVATE->readed; return PRIVATE->readed;
#else # else
if (!canRead()) return -1; if (!canRead()) return -1;
if (isOptionSet(PIIODevice::BlockingRead)) { if (isOptionSet(PIIODevice::BlockingRead)) {
if (!PRIVATE->event.wait(fd)) return -1; if (!PRIVATE->event.wait(fd)) return -1;
@@ -911,7 +910,7 @@ ssize_t PISerial::readDevice(void * read_to, ssize_t max_size) {
} }
} }
return ret; return ret;
#endif # endif
} }
@@ -920,7 +919,7 @@ ssize_t PISerial::writeDevice(const void * data, ssize_t max_size) {
// piCoutObj << "Can`t write to uninitialized COM"; // piCoutObj << "Can`t write to uninitialized COM";
return -1; return -1;
} }
#ifdef WINDOWS # ifdef WINDOWS
DWORD wrote(0); DWORD wrote(0);
// piCoutObj << "send ..." << max_size;// << ": " << PIString((char*)data, max_size); // piCoutObj << "send ..." << max_size;// << ": " << PIString((char*)data, max_size);
sending = true; sending = true;
@@ -932,11 +931,11 @@ ssize_t PISerial::writeDevice(const void * data, ssize_t max_size) {
} }
sending = false; sending = false;
// piCoutObj << "send ok" << wrote;// << " bytes in " << path(); // piCoutObj << "send ok" << wrote;// << " bytes in " << path();
#else # else
ssize_t wrote; ssize_t wrote;
wrote = ::write(fd, data, max_size); wrote = ::write(fd, data, max_size);
if (isOptionSet(BlockingWrite)) tcdrain(fd); if (isOptionSet(BlockingWrite)) tcdrain(fd);
#endif # endif
return (ssize_t)wrote; return (ssize_t)wrote;
// piCoutObj << "Error while sending"; // piCoutObj << "Error while sending";
} }
@@ -1061,9 +1060,9 @@ void PISerial::configureFromVariantDevice(const PIPropertyStorage & d) {
PIVector<int> PISerial::availableSpeeds() { PIVector<int> PISerial::availableSpeeds() {
PIVector<int> spds; PIVector<int> spds;
spds << 50 << 75 << 110 << 300 << 600 << 1200 << 2400 << 4800 << 9600 << spds << 50 << 75 << 110 << 300 << 600 << 1200 << 2400 << 4800 << 9600 <<
#ifdef WINDOWS # ifdef WINDOWS
14400 << 14400 <<
#endif # endif
19200 << 38400 << 57600 << 115200 << 230400 << 460800 << 500000 << 576000 << 921600 << 1000000 << 1152000 << 1500000 << 2000000 19200 << 38400 << 57600 << 115200 << 230400 << 460800 << 500000 << 576000 << 921600 << 1000000 << 1152000 << 1500000 << 2000000
<< 2500000 << 3000000 << 3500000 << 4000000; << 2500000 << 3000000 << 3500000 << 4000000;
return spds; return spds;
@@ -1079,7 +1078,7 @@ PIStringList PISerial::availableDevices(bool test) {
} }
#ifdef WINDOWS # ifdef WINDOWS
PIString devicePortName(HDEVINFO deviceInfoSet, PSP_DEVINFO_DATA deviceInfoData) { PIString devicePortName(HDEVINFO deviceInfoSet, PSP_DEVINFO_DATA deviceInfoData) {
PIString ret; PIString ret;
const HKEY key = SetupDiOpenDevRegKey(deviceInfoSet, deviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ); const HKEY key = SetupDiOpenDevRegKey(deviceInfoSet, deviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ);
@@ -1147,13 +1146,13 @@ bool parseID(PIString str, PISerial::DeviceInfo & di) {
if (i > 0) di.pID = str.mid(i + 4, 4).toInt(16); if (i > 0) di.pID = str.mid(i + 4, 4).toInt(16);
return (di.vID > 0) && (di.pID > 0); return (di.vID > 0) && (di.pID > 0);
} }
#endif # endif
PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) { PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
PIVector<DeviceInfo> ret; PIVector<DeviceInfo> ret;
DeviceInfo di; DeviceInfo di;
#ifdef WINDOWS # ifdef WINDOWS
static const GUID guids[] = {GUID_DEVINTERFACE_MODEM, GUID_DEVINTERFACE_COMPORT}; static const GUID guids[] = {GUID_DEVINTERFACE_MODEM, GUID_DEVINTERFACE_COMPORT};
static const int guids_cnt = sizeof(guids) / sizeof(GUID); static const int guids_cnt = sizeof(guids) / sizeof(GUID);
for (int i = 0; i < guids_cnt; ++i) { for (int i = 0; i < guids_cnt; ++i) {
@@ -1182,12 +1181,12 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
} }
SetupDiDestroyDeviceInfoList(dis); SetupDiDestroyDeviceInfoList(dis);
} }
#else # else
# ifndef ANDROID # ifndef ANDROID
PIStringList prefixes; PIStringList prefixes;
# ifdef QNX # ifdef QNX
prefixes << "ser"; prefixes << "ser";
# else # else
prefixes << "ttyS" prefixes << "ttyS"
<< "ttyO" << "ttyO"
<< "ttyUSB" << "ttyUSB"
@@ -1198,14 +1197,14 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
<< "ttyAMA" << "ttyAMA"
<< "rfcomm" << "rfcomm"
<< "ircomm"; << "ircomm";
# ifdef FREE_BSD # ifdef FREE_BSD
prefixes << "cu"; prefixes << "cu";
# endif # endif
# ifdef MAC_OS # ifdef MAC_OS
prefixes.clear(); prefixes.clear();
prefixes << "cu." prefixes << "cu."
<< "tty."; << "tty.";
# endif # endif
PIFile file_prefixes("/proc/tty/drivers", PIIODevice::ReadOnly); PIFile file_prefixes("/proc/tty/drivers", PIIODevice::ReadOnly);
if (file_prefixes.open()) { if (file_prefixes.open()) {
PIString fc = PIString::fromAscii(file_prefixes.readAll()), line, cpref; PIString fc = PIString::fromAscii(file_prefixes.readAll()), line, cpref;
@@ -1226,18 +1225,18 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
} }
prefixes.removeDuplicates(); prefixes.removeDuplicates();
} }
# endif # endif
PIDir dir("/dev"); PIDir dir("/dev");
PIVector<PIFile::FileInfo> de = dir.entries(); PIVector<PIFile::FileInfo> de = dir.entries();
# ifdef LINUX # ifdef LINUX
char linkbuf[1024]; char linkbuf[1024];
# endif # endif
for (const auto & e: de) { // TODO changes in FileInfo for (const auto & e: de) { // TODO changes in FileInfo
for (const auto & p: prefixes) { for (const auto & p: prefixes) {
if (e.name().startsWith(p)) { if (e.name().startsWith(p)) {
di = DeviceInfo(); di = DeviceInfo();
di.path = e.path; di.path = e.path;
# ifdef LINUX # ifdef LINUX
ssize_t lsz = readlink(("/sys/class/tty/" + e.name()).dataAscii(), linkbuf, 1024); ssize_t lsz = readlink(("/sys/class/tty/" + e.name()).dataAscii(), linkbuf, 1024);
if (lsz > 0) { if (lsz > 0) {
PIString fpath = "/sys/class/tty/" + PIString(linkbuf, lsz) + "/"; PIString fpath = "/sys/class/tty/" + PIString(linkbuf, lsz) + "/";
@@ -1253,16 +1252,16 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
if (di.pID > 0) break; if (di.pID > 0) break;
} }
} }
# endif # endif
ret << di; ret << di;
} }
} }
} }
# endif
# endif # endif
#endif
if (test) { if (test) {
for (int i = 0; i < ret.size_s(); ++i) { for (int i = 0; i < ret.size_s(); ++i) {
#ifdef WINDOWS # ifdef WINDOWS
void * hComm = CreateFileA(ret[i].path.dataAscii(), void * hComm = CreateFileA(ret[i].path.dataAscii(),
GENERIC_READ, GENERIC_READ,
FILE_SHARE_READ, FILE_SHARE_READ,
@@ -1271,31 +1270,31 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
0); 0);
if (hComm == INVALID_HANDLE_VALUE) { if (hComm == INVALID_HANDLE_VALUE) {
#else # else
int fd = ::open(ret[i].path.dataAscii(), O_NOCTTY | O_RDONLY); int fd = ::open(ret[i].path.dataAscii(), O_NOCTTY | O_RDONLY);
if (fd == -1) { if (fd == -1) {
#endif # endif
ret.remove(i); ret.remove(i);
--i; --i;
continue; continue;
} }
bool rok = true; bool rok = true;
#ifndef WINDOWS # ifndef WINDOWS
int void_ = 0; int void_ = 0;
fcntl(fd, F_SETFL, O_NONBLOCK); fcntl(fd, F_SETFL, O_NONBLOCK);
if (::read(fd, &void_, 1) == -1) rok = errno != EIO; if (::read(fd, &void_, 1) == -1) rok = errno != EIO;
#endif # endif
if (!rok) { if (!rok) {
ret.remove(i); ret.remove(i);
--i; --i;
continue; continue;
} }
#ifdef WINDOWS # ifdef WINDOWS
CloseHandle(hComm); CloseHandle(hComm);
#else # else
::close(fd); ::close(fd);
#endif # endif
} }
} }
return ret; return ret;
@@ -1309,12 +1308,14 @@ void PISerial::optionsChanged() {
void PISerial::threadedReadBufferSizeChanged() { void PISerial::threadedReadBufferSizeChanged() {
if (!isOpened()) return; if (!isOpened()) return;
#if defined(LINUX) # if defined(LINUX)
serial_struct ss; serial_struct ss;
ioctl(fd, TIOCGSERIAL, &ss); ioctl(fd, TIOCGSERIAL, &ss);
// piCoutObj << "b" << ss.xmit_fifo_size; // piCoutObj << "b" << ss.xmit_fifo_size;
ss.xmit_fifo_size = piMaxi(threadedReadBufferSize(), 4096); ss.xmit_fifo_size = piMaxi(threadedReadBufferSize(), 4096);
ioctl(fd, TIOCSSERIAL, &ss); ioctl(fd, TIOCSSERIAL, &ss);
// piCoutObj << "a" << ss.xmit_fifo_size; // piCoutObj << "a" << ss.xmit_fifo_size;
#endif # endif
} }
#endif // MICRO_PIP

View File

@@ -51,8 +51,14 @@
#ifdef PIP_FREERTOS #ifdef PIP_FREERTOS
# define FREERTOS # define FREERTOS
#endif #endif
#if defined(FREERTOS) || defined(PLATFORMIO) #ifdef MICRO_PIP
# define MICRO_PIP # ifndef FREERTOS
# define PIP_NO_THREADS
# endif
# ifndef LWIP
# define PIP_NO_SOCKET
# endif
# define PISERIAL_NO_PINS
#endif #endif
#ifndef WINDOWS #ifndef WINDOWS
# ifndef QNX # ifndef QNX

View File

@@ -15,6 +15,8 @@
# include <unistd.h> # include <unistd.h>
#else #else
// clang-format off // clang-format off
# undef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
# include <windows.h> # include <windows.h>
# include <setupapi.h> # include <setupapi.h>
extern "C" { extern "C" {

View File

@@ -130,6 +130,18 @@ void PIVariant::setValueFromString(const PIString & v) {
case PIVariant::pivLDouble: { case PIVariant::pivLDouble: {
setValue(v.toLDouble()); setValue(v.toLDouble());
} break; } break;
case PIVariant::pivComplexf: {
PIStringList sl = v.mid(1, v.size_s() - 2).split(';');
setValue(complexf(sl.size() > 0 ? sl[0].toFloat() : 0.f, sl.size() > 1 ? sl[1].toFloat() : 0.f));
}
case PIVariant::pivComplexd: {
PIStringList sl = v.mid(1, v.size_s() - 2).split(';');
setValue(complexd(sl.size() > 0 ? sl[0].toDouble() : 0., sl.size() > 1 ? sl[1].toDouble() : 0.));
}
case PIVariant::pivComplexld: {
PIStringList sl = v.mid(1, v.size_s() - 2).split(';');
setValue(complexld(sl.size() > 0 ? sl[0].toLDouble() : 0.L, sl.size() > 1 ? sl[1].toLDouble() : 0.L));
}
case PIVariant::pivTime: { case PIVariant::pivTime: {
setValue(PITime::fromString(v)); setValue(PITime::fromString(v));
} break; } break;
@@ -242,6 +254,7 @@ PIVariant::Type PIVariant::typeFromName(const PIString & tname) {
if (s == "float") return PIVariant::pivFloat; if (s == "float") return PIVariant::pivFloat;
if (s == "double" || s == "real") return PIVariant::pivDouble; if (s == "double" || s == "real") return PIVariant::pivDouble;
if (s == "ldouble" || s == "longdouble") return PIVariant::pivLDouble; if (s == "ldouble" || s == "longdouble") return PIVariant::pivLDouble;
if (s == "complexf" || s == "complex<float>") return PIVariant::pivComplexf;
if (s == "complexd" || s == "complex<double>") return PIVariant::pivComplexd; if (s == "complexd" || s == "complex<double>") return PIVariant::pivComplexd;
if (s == "complexld" || s == "complex<ldouble>" || s == "complex<longdouble>") return PIVariant::pivComplexld; if (s == "complexld" || s == "complex<ldouble>" || s == "complex<longdouble>") return PIVariant::pivComplexld;
if (s == "pibitarray" || s == "bitarray") return PIVariant::pivBitArray; if (s == "pibitarray" || s == "bitarray") return PIVariant::pivBitArray;
@@ -286,6 +299,7 @@ PIVariant::Type PIVariant::typeFromID(uint type_id) {
if (type_id == typeID<float>()) return PIVariant::pivFloat; if (type_id == typeID<float>()) return PIVariant::pivFloat;
if (type_id == typeID<double>()) return PIVariant::pivDouble; if (type_id == typeID<double>()) return PIVariant::pivDouble;
if (type_id == typeID<ldouble>()) return PIVariant::pivLDouble; if (type_id == typeID<ldouble>()) return PIVariant::pivLDouble;
if (type_id == typeID<complexf>()) return PIVariant::pivComplexf;
if (type_id == typeID<complexd>()) return PIVariant::pivComplexd; if (type_id == typeID<complexd>()) return PIVariant::pivComplexd;
if (type_id == typeID<complexld>()) return PIVariant::pivComplexld; if (type_id == typeID<complexld>()) return PIVariant::pivComplexld;
if (type_id == typeID<PIBitArray>()) return PIVariant::pivBitArray; if (type_id == typeID<PIBitArray>()) return PIVariant::pivBitArray;
@@ -336,6 +350,7 @@ uint PIVariant::typeIDFromType(Type type) {
case (PIVariant::pivFloat ): return typeID<float >(); case (PIVariant::pivFloat ): return typeID<float >();
case (PIVariant::pivDouble ): return typeID<double >(); case (PIVariant::pivDouble ): return typeID<double >();
case (PIVariant::pivLDouble ): return typeID<ldouble >(); case (PIVariant::pivLDouble ): return typeID<ldouble >();
case (PIVariant::pivComplexf ): return typeID<complexf >();
case (PIVariant::pivComplexd ): return typeID<complexd >(); case (PIVariant::pivComplexd ): return typeID<complexd >();
case (PIVariant::pivComplexld ): return typeID<complexld >(); case (PIVariant::pivComplexld ): return typeID<complexld >();
case (PIVariant::pivBitArray ): return typeID<PIBitArray >(); case (PIVariant::pivBitArray ): return typeID<PIBitArray >();
@@ -451,6 +466,7 @@ PIString PIVariant::typeName(PIVariant::Type type) {
case PIVariant::pivFloat: return "Float"; case PIVariant::pivFloat: return "Float";
case PIVariant::pivDouble: return "Double"; case PIVariant::pivDouble: return "Double";
case PIVariant::pivLDouble: return "LDouble"; case PIVariant::pivLDouble: return "LDouble";
case PIVariant::pivComplexf: return "Complexf";
case PIVariant::pivComplexd: return "Complexd"; case PIVariant::pivComplexd: return "Complexd";
case PIVariant::pivComplexld: return "Complexld"; case PIVariant::pivComplexld: return "Complexld";
case PIVariant::pivBitArray: return "BitArray"; case PIVariant::pivBitArray: return "BitArray";
@@ -691,6 +707,21 @@ int PIVariant::toInt() const {
ba >> r; ba >> r;
return r; return r;
} }
case PIVariant::pivComplexf: {
complexf r;
ba >> r;
return r.real();
}
case PIVariant::pivComplexd: {
complexd r;
ba >> r;
return r.real();
}
case PIVariant::pivComplexld: {
complexld r;
ba >> r;
return r.real();
}
case PIVariant::pivString: { case PIVariant::pivString: {
PIString r; PIString r;
ba >> r; ba >> r;
@@ -806,6 +837,21 @@ llong PIVariant::toLLong() const {
ba >> r; ba >> r;
return r; return r;
} }
case PIVariant::pivComplexf: {
complexf r;
ba >> r;
return r.real();
}
case PIVariant::pivComplexd: {
complexd r;
ba >> r;
return r.real();
}
case PIVariant::pivComplexld: {
complexld r;
ba >> r;
return r.real();
}
case PIVariant::pivString: { case PIVariant::pivString: {
PIString r; PIString r;
ba >> r; ba >> r;
@@ -916,6 +962,21 @@ float PIVariant::toFloat() const {
ba >> r; ba >> r;
return r; return r;
} }
case PIVariant::pivComplexf: {
complexf r;
ba >> r;
return r.real();
}
case PIVariant::pivComplexd: {
complexd r;
ba >> r;
return r.real();
}
case PIVariant::pivComplexld: {
complexld r;
ba >> r;
return r.real();
}
case PIVariant::pivString: { case PIVariant::pivString: {
PIString r; PIString r;
ba >> r; ba >> r;
@@ -1026,6 +1087,21 @@ double PIVariant::toDouble() const {
ba >> r; ba >> r;
return r; return r;
} }
case PIVariant::pivComplexf: {
complexf r;
ba >> r;
return r.real();
}
case PIVariant::pivComplexd: {
complexd r;
ba >> r;
return r.real();
}
case PIVariant::pivComplexld: {
complexld r;
ba >> r;
return r.real();
}
case PIVariant::pivString: { case PIVariant::pivString: {
PIString r; PIString r;
ba >> r; ba >> r;
@@ -1136,6 +1212,21 @@ ldouble PIVariant::toLDouble() const {
ba >> r; ba >> r;
return r; return r;
} }
case PIVariant::pivComplexf: {
complexf r;
ba >> r;
return r.real();
}
case PIVariant::pivComplexd: {
complexd r;
ba >> r;
return r.real();
}
case PIVariant::pivComplexld: {
complexld r;
ba >> r;
return r.real();
}
case PIVariant::pivString: { case PIVariant::pivString: {
PIString r; PIString r;
ba >> r; ba >> r;
@@ -1164,6 +1255,96 @@ ldouble PIVariant::toLDouble() const {
} }
complexf PIVariant::toComplexF() const {
PIByteArray ba(_content);
switch (_type) {
case PIVariant::pivComplexf: {
complexf r;
ba >> r;
return r;
}
case PIVariant::pivComplexd: {
complexd r;
ba >> r;
return complexf(r.real(), r.imag());
}
case PIVariant::pivComplexld: {
complexld r;
ba >> r;
return complexf(r.real(), r.imag());
}
case PIVariant::pivMathVector: {
PIMathVectord r;
ba >> r;
return complexf(r.size() > 0 ? r[0] : 0., r.size() > 1 ? r[1] : 0.);
}
case PIVariant::pivCustom: return getAsValue<complexf>(*this);
default: return complexf(toFloat(), 0.f);
}
return complexf();
}
complexd PIVariant::toComplexD() const {
PIByteArray ba(_content);
switch (_type) {
case PIVariant::pivComplexf: {
complexf r;
ba >> r;
return complexd(r.real(), r.imag());
}
case PIVariant::pivComplexd: {
complexd r;
ba >> r;
return r;
}
case PIVariant::pivComplexld: {
complexld r;
ba >> r;
return complexd(r.real(), r.imag());
}
case PIVariant::pivMathVector: {
PIMathVectord r;
ba >> r;
return complexd(r.size() > 0 ? r[0] : 0., r.size() > 1 ? r[1] : 0.);
}
case PIVariant::pivCustom: return getAsValue<complexd>(*this);
default: return complexd(toDouble(), 0.f);
}
return complexd();
}
complexld PIVariant::toComplexLD() const {
PIByteArray ba(_content);
switch (_type) {
case PIVariant::pivComplexf: {
complexf r;
return complexld(r.real(), r.imag());
ba >> r;
}
case PIVariant::pivComplexd: {
complexd r;
ba >> r;
return complexld(r.real(), r.imag());
}
case PIVariant::pivComplexld: {
complexld r;
ba >> r;
return r;
}
case PIVariant::pivMathVector: {
PIMathVectord r;
ba >> r;
return complexld(r.size() > 0 ? r[0] : 0., r.size() > 1 ? r[1] : 0.);
}
case PIVariant::pivCustom: return getAsValue<complexld>(*this);
default: return complexld(toLDouble(), 0.f);
}
return complexld();
}
//! \~\brief //! \~\brief
//! \~english Returns variant content as time //! \~english Returns variant content as time
//! \~russian Возвращает содержимое как время //! \~russian Возвращает содержимое как время
@@ -1418,6 +1599,21 @@ PIString PIVariant::toString() const {
ba >> r; ba >> r;
return PIString::fromNumber(r); return PIString::fromNumber(r);
} }
case PIVariant::pivComplexf: {
complexf r;
ba >> r;
return "(" + PIString::fromNumber(r.real()) + ";" + PIString::fromNumber(r.imag()) + ")";
}
case PIVariant::pivComplexd: {
complexd r;
ba >> r;
return "(" + PIString::fromNumber(r.real()) + ";" + PIString::fromNumber(r.imag()) + ")";
}
case PIVariant::pivComplexld: {
complexld r;
ba >> r;
return "(" + PIString::fromNumber(r.real()) + ";" + PIString::fromNumber(r.imag()) + ")";
}
case PIVariant::pivTime: { case PIVariant::pivTime: {
PITime r; PITime r;
ba >> r; ba >> r;
@@ -1910,21 +2106,45 @@ PINetworkAddress PIVariant::toNetworkAddress() const {
//! Для остальных типов возвращает пустой PIMathVectord. //! Для остальных типов возвращает пустой PIMathVectord.
//! //!
PIMathVectord PIVariant::toMathVector() const { PIMathVectord PIVariant::toMathVector() const {
PIMathVectord ret;
PIByteArray ba(_content); PIByteArray ba(_content);
if (_type == PIVariant::pivMathVector) { if (_type == PIVariant::pivComplexf) {
PIMathVectord r; complexf r;
ba >> r; ba >> r;
return r; ret.resize(2);
ret[0] = r.real();
ret[1] = r.imag();
return ret;
}
if (_type == PIVariant::pivComplexd) {
complexd r;
ba >> r;
ret.resize(2);
ret[0] = r.real();
ret[1] = r.imag();
return ret;
}
if (_type == PIVariant::pivComplexld) {
complexld r;
ba >> r;
ret.resize(2);
ret[0] = r.real();
ret[1] = r.imag();
return ret;
}
if (_type == PIVariant::pivMathVector) {
ba >> ret;
return ret;
} }
if (_type == PIVariant::pivPoint) { if (_type == PIVariant::pivPoint) {
PIPointd r; PIPointd r;
ba >> r; ba >> r;
PIMathVectord ret(2); ret.resize(2);
ret[0] = r.x; ret[0] = r.x;
ret[1] = r.y; ret[1] = r.y;
return ret; return ret;
} }
return PIMathVectord(); return ret;
} }

View File

@@ -260,6 +260,7 @@ public:
pivMathMatrix /** PIMathMatrix<double> */, pivMathMatrix /** PIMathMatrix<double> */,
pivLine /** PILine<double> */, pivLine /** PILine<double> */,
pivNetworkAddress /** PINetworkAddress */, pivNetworkAddress /** PINetworkAddress */,
pivComplexf /** complexf */,
pivCustom /** \~english Custom \~russian Свой тип */ = 0xFF pivCustom /** \~english Custom \~russian Свой тип */ = 0xFF
}; };
@@ -327,6 +328,18 @@ public:
//! \~russian Создает %PIVariant из вещественного числа. //! \~russian Создает %PIVariant из вещественного числа.
PIVariant(const ldouble & v) { initType(v); } PIVariant(const ldouble & v) { initType(v); }
//! \~english Constructs %PIVariant from complex number.
//! \~russian Создает %PIVariant из комплексного числа.
PIVariant(const complexf & v) { initType(v); }
//! \~english Constructs %PIVariant from complex number.
//! \~russian Создает %PIVariant из комплексного числа.
PIVariant(const complexd & v) { initType(v); }
//! \~english Constructs %PIVariant from complex number.
//! \~russian Создает %PIVariant из комплексного числа.
PIVariant(const complexld & v) { initType(v); }
//! \~english Constructs %PIVariant from bit array. //! \~english Constructs %PIVariant from bit array.
//! \~russian Создает %PIVariant из массива битов. //! \~russian Создает %PIVariant из массива битов.
PIVariant(const PIBitArray & v) { initType(v); } PIVariant(const PIBitArray & v) { initType(v); }
@@ -456,6 +469,18 @@ public:
//! \~russian Устанавливает значение и тип из вещественного числа //! \~russian Устанавливает значение и тип из вещественного числа
void setValue(const ldouble & v) { initType(v); } void setValue(const ldouble & v) { initType(v); }
//! \~english Set variant content and type to complex
//! \~russian Устанавливает значение и тип из комплексного числа
void setValue(const complexf & v) { initType(v); }
//! \~english Set variant content and type to complex
//! \~russian Устанавливает значение и тип из комплексного числа
void setValue(const complexd & v) { initType(v); }
//! \~english Set variant content and type to complex
//! \~russian Устанавливает значение и тип из комплексного числа
void setValue(const complexld & v) { initType(v); }
//! \~english Set variant content and type to bit array //! \~english Set variant content and type to bit array
//! \~russian Устанавливает значение и тип из массива битов //! \~russian Устанавливает значение и тип из массива битов
void setValue(const PIBitArray & v) { initType(v); } void setValue(const PIBitArray & v) { initType(v); }
@@ -545,6 +570,9 @@ public:
float toFloat() const; float toFloat() const;
double toDouble() const; double toDouble() const;
ldouble toLDouble() const; ldouble toLDouble() const;
complexf toComplexF() const;
complexd toComplexD() const;
complexld toComplexLD() const;
PITime toTime() const; PITime toTime() const;
PIDate toDate() const; PIDate toDate() const;
PIDateTime toDateTime() const; PIDateTime toDateTime() const;
@@ -680,6 +708,27 @@ public:
return *this; return *this;
} }
//! \~english Assign operator.
//! \~russian Оператор присваивания.
PIVariant & operator=(const complexf & v) {
setValue(v);
return *this;
}
//! \~english Assign operator.
//! \~russian Оператор присваивания.
PIVariant & operator=(const complexd & v) {
setValue(v);
return *this;
}
//! \~english Assign operator.
//! \~russian Оператор присваивания.
PIVariant & operator=(const complexld & v) {
setValue(v);
return *this;
}
//! \~english Assign operator. //! \~english Assign operator.
//! \~russian Оператор присваивания. //! \~russian Оператор присваивания.
PIVariant & operator=(const PIBitArray & v) { PIVariant & operator=(const PIBitArray & v) {
@@ -994,6 +1043,9 @@ template<> inline ullong PIVariant::value() const {return (ullong)toLLong();}
template<> inline float PIVariant::value() const {return toFloat();} template<> inline float PIVariant::value() const {return toFloat();}
template<> inline double PIVariant::value() const {return toDouble();} template<> inline double PIVariant::value() const {return toDouble();}
template<> inline ldouble PIVariant::value() const {return toLDouble();} template<> inline ldouble PIVariant::value() const {return toLDouble();}
template<> inline complexf PIVariant::value() const {return toComplexF();}
template<> inline complexd PIVariant::value() const {return toComplexD();}
template<> inline complexld PIVariant::value() const {return toComplexLD();}
template<> inline void* PIVariant::value() const {return (void*)toLLong();} template<> inline void* PIVariant::value() const {return (void*)toLLong();}
template<> inline const char* PIVariant::value() const {return toString().data();} template<> inline const char* PIVariant::value() const {return toString().data();}
template<> inline PITime PIVariant::value() const {return toTime();} template<> inline PITime PIVariant::value() const {return toTime();}
@@ -1027,6 +1079,9 @@ template<> inline PIVariant PIVariant::fromValue(const ullong & v) {return PIVar
template<> inline PIVariant PIVariant::fromValue(const float & v) {return PIVariant(v);} template<> inline PIVariant PIVariant::fromValue(const float & v) {return PIVariant(v);}
template<> inline PIVariant PIVariant::fromValue(const double & v) {return PIVariant(v);} template<> inline PIVariant PIVariant::fromValue(const double & v) {return PIVariant(v);}
template<> inline PIVariant PIVariant::fromValue(const ldouble & v) {return PIVariant(v);} template<> inline PIVariant PIVariant::fromValue(const ldouble & v) {return PIVariant(v);}
template<> inline PIVariant PIVariant::fromValue(const complexf & v) {return PIVariant(v);}
template<> inline PIVariant PIVariant::fromValue(const complexd & v) {return PIVariant(v);}
template<> inline PIVariant PIVariant::fromValue(const complexld & v) {return PIVariant(v);}
template<> inline PIVariant PIVariant::fromValue(const PIBitArray & v) {return PIVariant(v);} template<> inline PIVariant PIVariant::fromValue(const PIBitArray & v) {return PIVariant(v);}
template<> inline PIVariant PIVariant::fromValue(const PIByteArray & v) {return PIVariant(v);} template<> inline PIVariant PIVariant::fromValue(const PIByteArray & v) {return PIVariant(v);}
template<> inline PIVariant PIVariant::fromValue(const PIString & v) {return PIVariant(v);} template<> inline PIVariant PIVariant::fromValue(const PIString & v) {return PIVariant(v);}
@@ -1060,6 +1115,9 @@ template<> inline PIVariant::Type PIVariant::getType<ullong>() {return PIVariant
template<> inline PIVariant::Type PIVariant::getType<float>() {return PIVariant::pivFloat;} template<> inline PIVariant::Type PIVariant::getType<float>() {return PIVariant::pivFloat;}
template<> inline PIVariant::Type PIVariant::getType<double>() {return PIVariant::pivDouble;} template<> inline PIVariant::Type PIVariant::getType<double>() {return PIVariant::pivDouble;}
template<> inline PIVariant::Type PIVariant::getType<ldouble>() {return PIVariant::pivLDouble;} template<> inline PIVariant::Type PIVariant::getType<ldouble>() {return PIVariant::pivLDouble;}
template<> inline PIVariant::Type PIVariant::getType<complexf>() {return PIVariant:: pivComplexf;}
template<> inline PIVariant::Type PIVariant::getType<complexd>() {return PIVariant:: pivComplexd;}
template<> inline PIVariant::Type PIVariant::getType<complexld>() {return PIVariant::pivComplexld;}
template<> inline PIVariant::Type PIVariant::getType<PIBitArray>() {return PIVariant::pivBitArray;} template<> inline PIVariant::Type PIVariant::getType<PIBitArray>() {return PIVariant::pivBitArray;}
template<> inline PIVariant::Type PIVariant::getType<PIByteArray>() {return PIVariant::pivByteArray;} template<> inline PIVariant::Type PIVariant::getType<PIByteArray>() {return PIVariant::pivByteArray;}
template<> inline PIVariant::Type PIVariant::getType<PIString>() {return PIVariant::pivString;} template<> inline PIVariant::Type PIVariant::getType<PIString>() {return PIVariant::pivString;}
@@ -1093,6 +1151,9 @@ REGISTER_VARIANT(ullong)
REGISTER_VARIANT(float) REGISTER_VARIANT(float)
REGISTER_VARIANT(double) REGISTER_VARIANT(double)
REGISTER_VARIANT(ldouble) REGISTER_VARIANT(ldouble)
REGISTER_VARIANT(complexf)
REGISTER_VARIANT(complexd)
REGISTER_VARIANT(complexld)
REGISTER_VARIANT(PIBitArray) REGISTER_VARIANT(PIBitArray)
REGISTER_VARIANT(PIByteArray) REGISTER_VARIANT(PIByteArray)
REGISTER_VARIANT(PIString) REGISTER_VARIANT(PIString)

View File

@@ -29,6 +29,7 @@
#include "piunits_class_angle.h" #include "piunits_class_angle.h"
#include "piunits_class_distance.h" #include "piunits_class_distance.h"
#include "piunits_class_information.h" #include "piunits_class_information.h"
#include "piunits_class_mass.h"
#include "piunits_class_pressure.h" #include "piunits_class_pressure.h"
#include "piunits_class_temperature.h" #include "piunits_class_temperature.h"
#include "piunits_class_time.h" #include "piunits_class_time.h"

View File

@@ -23,6 +23,12 @@
PIString PIUnits::Class::Distance::name(int type) const { PIString PIUnits::Class::Distance::name(int type) const {
switch (type) { switch (type) {
case Meter: return "meter"_tr("PIUnitsDistance"); case Meter: return "meter"_tr("PIUnitsDistance");
case Inch: return "inch"_tr("PIUnitsDistance");
case Mil: return "mil"_tr("PIUnitsDistance");
case Foot: return "foot"_tr("PIUnitsDistance");
case Yard: return "yard"_tr("PIUnitsDistance");
case Angstrom: return "angstrom"_tr("PIUnitsDistance");
case AstronomicalUnit: return "astronomical unit"_tr("PIUnitsDistance");
} }
return Class::Internal::unknown; return Class::Internal::unknown;
} }
@@ -31,16 +37,42 @@ PIString PIUnits::Class::Distance::name(int type) const {
PIString PIUnits::Class::Distance::unit(int type) const { PIString PIUnits::Class::Distance::unit(int type) const {
switch (type) { switch (type) {
case Meter: return "m"_tr("PIUnitsDistance"); case Meter: return "m"_tr("PIUnitsDistance");
case Inch: return "\""_tr("PIUnitsDistance");
case Mil: return "thou"_tr("PIUnitsDistance");
case Foot: return "ft"_tr("PIUnitsDistance");
case Yard: return "yd"_tr("PIUnitsDistance");
case Angstrom: return "Å"_tr("PIUnitsDistance");
case AstronomicalUnit: return "au"_tr("PIUnitsDistance");
} }
return Class::Internal::unknown; return Class::Internal::unknown;
} }
double PIUnits::Class::Distance::convert(double v, int from, int to) const { double PIUnits::Class::Distance::convert(double v, int from, int to) const {
switch (to) { static constexpr double inch_to_m = 0.254;
case Meter: return v; static constexpr double mil_to_m = 0.254 * 1E-3;
static constexpr double foot_to_m = 0.3048;
static constexpr double yard_to_m = 0.9144;
static constexpr double angstrom_to_m = 1E-10;
static constexpr double astronomical_unit_to_m = 149597870700.;
double m = v;
switch (from) {
case Inch: m *= inch_to_m; break;
case Mil: m *= mil_to_m; break;
case Foot: m *= foot_to_m; break;
case Yard: m *= yard_to_m; break;
case Angstrom: m *= angstrom_to_m; break;
case AstronomicalUnit: m *= astronomical_unit_to_m; break;
} }
return v; switch (to) {
case Inch: m /= inch_to_m; break;
case Mil: m /= mil_to_m; break;
case Foot: m /= foot_to_m; break;
case Yard: m /= yard_to_m; break;
case Angstrom: m /= angstrom_to_m; break;
case AstronomicalUnit: m /= astronomical_unit_to_m; break;
}
return m;
} }
@@ -50,12 +82,12 @@ PIString PIUnits::Class::Distance::valueToString(double v, char format, int prec
bool PIUnits::Class::Distance::supportPrefixes(int type) const { bool PIUnits::Class::Distance::supportPrefixes(int type) const {
return true; return type == Meter;
} }
bool PIUnits::Class::Distance::supportPrefixesNon3(int type) const { bool PIUnits::Class::Distance::supportPrefixesNon3(int type) const {
return true; return type == Meter;
} }

View File

@@ -31,6 +31,14 @@
DECLARE_UNIT_CLASS_BEGIN(Distance, 0x600) DECLARE_UNIT_CLASS_BEGIN(Distance, 0x600)
enum { enum {
Meter = typeStart, Meter = typeStart,
Inch,
Mil,
Foot,
Yard,
Angstrom,
AstronomicalUnit,
_LastType, _LastType,
}; };
DECLARE_UNIT_CLASS_END(Distance) DECLARE_UNIT_CLASS_END(Distance)

View File

@@ -0,0 +1,81 @@
/*
PIP - Platform Independent Primitives
Mass units
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "piunits_class_mass.h"
PIString PIUnits::Class::Mass::name(int type) const {
switch (type) {
case Gram: return "gram"_tr("PIUnitsMass");
case Pound: return "pound"_tr("PIUnitsMass");
case Ounce: return "ounce"_tr("PIUnitsMass");
}
return Class::Internal::unknown;
}
PIString PIUnits::Class::Mass::unit(int type) const {
switch (type) {
case Gram: return "g"_tr("PIUnitsMass");
case Pound: return "lb"_tr("PIUnitsMass");
case Ounce: return ""_tr("PIUnitsMass");
}
return Class::Internal::unknown;
}
double PIUnits::Class::Mass::convert(double v, int from, int to) const {
static constexpr double pound_to_g = 453.59237;
static constexpr double ounce_to_g = 28.349523125;
double g = v;
switch (from) {
case Pound: g *= pound_to_g; break;
case Ounce: g *= ounce_to_g; break;
}
switch (to) {
case Pound: g /= pound_to_g; break;
case Ounce: g /= ounce_to_g; break;
}
return g;
}
PIString PIUnits::Class::Mass::valueToString(double v, char format, int prec) const {
return PIString::fromNumber(v, format, prec);
}
bool PIUnits::Class::Mass::supportPrefixes(int type) const {
return type == Gram;
}
bool PIUnits::Class::Mass::supportPrefixesNon3(int type) const {
return false;
}
bool PIUnits::Class::Mass::supportPrefixesGreater(int type) const {
return ClassBase::supportPrefixesGreater(type);
}
bool PIUnits::Class::Mass::supportPrefixesSmaller(int type) const {
return ClassBase::supportPrefixesSmaller(type);
}

View File

@@ -0,0 +1,40 @@
/*! \file piunits_class_distance.h
* \ingroup Core
* \~\brief
* \~english Mass units
* \~russian Единицы измерения массы
*/
/*
PIP - Platform Independent Primitives
Mass units
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIUNITS_CLASS_MASS_H
#define PIUNITS_CLASS_MASS_H
#include "piunits_base.h"
DECLARE_UNIT_CLASS_BEGIN(Mass, 0x700)
enum {
Gram = typeStart,
Pound,
Ounce,
_LastType,
};
DECLARE_UNIT_CLASS_END(Mass)
#endif

View File

@@ -2,6 +2,7 @@
#include "picodeparser.h" #include "picodeparser.h"
#include "pidigest.h" #include "pidigest.h"
#include "pihttpclient.h" #include "pihttpclient.h"
#include "piliterals.h"
#include "pip.h" #include "pip.h"
#include "piunits.h" #include "piunits.h"
#include "pivaluetree_conversions.h" #include "pivaluetree_conversions.h"
@@ -10,7 +11,76 @@ using namespace PICoutManipulators;
using namespace PIHTTP; using namespace PIHTTP;
using namespace PIUnits::Class; using namespace PIUnits::Class;
int rcnt = 0, scnt = 0;
inline PIByteArray SMBusTypeInfo_genHash(PIString n) {
PICrypt c;
return piSerialize(c.shorthash(n.removeAll(" "), PIString("SMBusDataHashKey").toByteArray()));
}
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
PICrypt _crypt;
// auto ba = PIFile::readAll("logo.png");
PIString str = "hello!"_a;
PIByteArray ba = str.toAscii();
PIByteArray key = PIString("SMBusDataHashKey").toByteArray();
const int times = 1000000;
PITimeMeasurer tm;
PISystemTime el;
tm.reset();
piForTimes(times) {
PIDigest::calculateWithKey(ba, key, PIDigest::Type::SipHash_2_4_128);
}
el = tm.elapsed();
piCout << "PIDigest" << el.toString();
tm.reset();
piForTimes(times) {
_crypt.shorthash(str, key);
}
el = tm.elapsed();
piCout << " sodium" << el.toString();
tm.reset();
piForTimes(times) {
PIDigest::calculateWithKey(ba, key, PIDigest::Type::BLAKE2b_128);
}
el = tm.elapsed();
piCout << " blake" << el.toString();
return 0;
PIEthernet *eth_r, *eth_s;
eth_r = PIIODevice::createFromFullPath("eth://udp: 192.168.1.25 :10000")->cast<PIEthernet>();
eth_s = PIIODevice::createFromFullPath("eth://udp: : : 192.168.1.25:10000")->cast<PIEthernet>();
eth_r->setReadBufferSize(1_MiB);
CONNECTL(eth_r, threadedReadEvent, [](const uchar * readed, ssize_t size) {
// piCout << "rec";
piMSleep(1);
++rcnt;
});
eth_r->startThreadedRead();
PIByteArray _ba(1400);
for (int i = 0; i < 100; ++i) {
eth_s->write(_ba);
++scnt;
}
0.2_s .sleep();
piCout << "snd" << scnt;
piCout << "rec" << rcnt;
piDeleteSafety(eth_r);
piDeleteSafety(eth_s);
return 0;
PITranslator::loadLang("ru"); PITranslator::loadLang("ru");
/*auto ucl = PIUnits::allClasses(); /*auto ucl = PIUnits::allClasses();
for (auto c: ucl) { for (auto c: ucl) {