├── .github
└── workflows
│ └── docker-image.yml
├── .gitignore
├── LICENSE
├── README.md
├── docker-compose.yml
├── docker
├── Dockerfile-python3-x64
├── Dockerfile-python3-x86
├── build.sh
├── docker-compose.yml
└── run.sh
├── img
├── main.png
└── open.png
├── requirements.txt
├── src
├── apim.py
├── asbuilt.py
├── encoder.py
└── statics.py
└── web
├── Dockerfile
├── api
├── __init__.py
└── wsgi.py
├── docker
├── docker-entrypoint.sh
├── nginx.conf
├── supervisord.conf
└── uwsgi.ini
├── package-lock.json
├── package.json
└── public
├── app.css
├── app.js
└── index.html
/.github/workflows/docker-image.yml:
--------------------------------------------------------------------------------
1 | # This workflow uses actions that are not certified by GitHub.
2 | # They are provided by a third-party and are governed by
3 | # separate terms of service, privacy policy, and support
4 | # documentation.
5 |
6 | name: Create and publish a Docker image
7 |
8 | on:
9 | workflow_dispatch:
10 |
11 | env:
12 | REGISTRY: ghcr.io
13 | IMAGE_NAME: ${{ github.repository }}
14 |
15 | jobs:
16 | build-and-push-image:
17 | runs-on: ubuntu-latest
18 | permissions:
19 | contents: read
20 | packages: write
21 |
22 | steps:
23 | - name: Checkout repository
24 | uses: actions/checkout@v2
25 |
26 | - uses: actions/setup-node@v2
27 |
28 | - name: Run NPM Install in web folder
29 | run: cd web; npm install
30 |
31 | - name: Log in to the Container registry
32 | uses: docker/login-action@v1.12.0
33 | with:
34 | registry: ${{ env.REGISTRY }}
35 | username: ${{ github.actor }}
36 | password: ${{ secrets.GITHUB_TOKEN }}
37 |
38 | - name: Extract metadata (tags, labels) for Docker
39 | id: meta
40 | uses: docker/metadata-action@v3.6.2
41 | with:
42 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
43 |
44 | - name: Build and push Docker image
45 | uses: docker/build-push-action@v2.7.0
46 | with:
47 | context: .
48 | file: ./web/Dockerfile
49 | push: true
50 | tags: ${{ steps.meta.outputs.tags }}
51 | labels: ${{ steps.meta.outputs.labels }}
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | __pycache__
2 | .DS_Store
3 | node_modules
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Ford APIM AsBuilt decoder tool
2 | ## Current state
3 | Latest "Stable" release version: [1.3](https://github.com/consp/apim-asbuilt-decode/releases)
4 | ## Intro
5 | This repository is meant for users who want to edit their values of the AsBuilt data of the Ford Sync 3 APIM and do not have a tool which has all information built in. The data has been collected from code (extracting debug information from the QNX applications) and other peoples findings on fora.
6 |
7 | Please note that some settings change quite a lot. Most radio and CGEA/C1MCA settings change quite a lot internally.
8 |
9 | As with all DIY tools: YMMV and you do everything at your own risk. Changing stuff might brick your APIM, you have been warned!
10 |
11 | ## Acknowledgements
12 | - F150Forum's Livinitup and F150chief for the Sync 3 ASBuild sheet and information about Sync 3.x which was not present in the source code (or at least not obvious).
13 | - F150Forum's Livinitup for the Sync 4 config sheet
14 |
15 |
16 | ## Inconsistencies and known issues
17 | - After opening some files or misformed file the application might crash, this has been mostly mitigated
18 |
19 | ## Features
20 | - Dumps your abt binary data into something 'somewhat' readable
21 | - Lets you compare files to figure out you prefered configuration
22 | - Uses GUI to change options more easy and lets you see the results in the files if you change them.
23 | - Being an offline tool so you can use it while doing stuff in your garage.
24 |
25 | ## Todo
26 | - Finish Sync 4 support by adding 7D0-08/09/10
27 |
28 | ## Usage and requirements
29 | Requires the following:
30 | - Python 3.5 and up
31 | - Qt5 libraries and PyQt5.
32 | - Or: download the x64 windows executables which have everything built in, 32bit require meddeling with pyqt5 if you are unlucky.
33 | - As built file(s) in either Ford XML format (.ab) or ForScan dump format (.abt) in new or old style or a UCDS xml file.
34 |
35 | GUI: ```python3 src/apim.py``` or run the excutable. You can open a file, change stuff and save it
36 | 
37 | 
38 |
39 | Command line options: Either one or two files need to be present
40 | ```
41 | > python3 src/apim.py YOURVINHERE.ab forscanfile.abt
42 | Loading YOURVINHERE.ab
43 | Loading Ford XML file
44 | Loaded 7 blocks, 57 bytes
45 | Loading forscanfile.abt
46 | Forscan ABT format
47 | New forscan format
48 | Loaded 8 blocks, 67 bytes
49 | Block 1 (7D0-01 or DE00)
50 | #Name - Field Loc Byte Loc bit Val1 Val2
51 | Smart DSP: ..................................................................... 7D0-01-01 Xnnn nnnn nn 1....... 88 08
52 | 2> 00: Do not log missing DSP Messages
53 | 1> 80: Enable, Log missing DSP Messages (When configured for Smart DSP and Lincoln then enable THX Deep Note)
54 | AAM (Module is related to Smart DSP): .......................................... 7D0-01-01 Xnnn nnnn nn .0...... 88 08
55 | 1> 2> 00: Do not log missing AAM messages
56 | 40: Enable, Log Missing AAM messages (Send speaker walkaround request to ACM)
57 | SDARS: ......................................................................... 7D0-01-01 Xnnn nnnn nn ..0..... 88 08
58 | 1> 2> 00: Do not log missing SDARS (ACM) message
59 | 20: Enable, Log Missing SDARS (ACM) message
60 | RSEM: .......................................................................... 7D0-01-01 Xnnn nnnn nn ...0.... 88 08
61 | 1> 2> 00: Do not log missing RSEM messages
62 | 10: Enable, Log Missing RSEM messages
63 | PDC HMI: ....................................................................... 7D0-01-01 nXnn nnnn nn ....1... 88 08
64 | 00: Off
65 | 1> 2> 08: On
66 | Rear Camera: ................................................................... 7D0-01-01 nXnn nnnn nn .....00. 88 08
67 | 1> 2> 00: RVC Not Present
68 | 02: RVC Present
69 | 04: Reserved
70 | 06: Reserved
71 | Illumination: .................................................................. 7D0-01-01 nXnn nnnn nn .......0 88 08
72 | 1> 2> 00: FNA Strategy
73 | 01: FoE Strategy
74 | Extended Play: ................................................................. 7D0-01-01 nnXn nnnn nn 0....... 6A 68
75 | 1> 2> 00: On
76 | 80: Off
77 | ...
78 | ```
79 |
80 | Command line options:
81 | ```
82 | usage: apim.py [-h] [--debug] [--noprint] [--save] [abtfile [abtfile ...]]
83 |
84 | Open and compare asbuilt files or use the GUI to edit them. The debug options
85 | should notmally not be used as they provide no useful information to non
86 | developers. Run without arguments to start the GUI.
87 |
88 | positional arguments:
89 | abtfile ForScan abt filename of 7D0 region, ford asbuilt xml or ucds
90 | asbuilt xml file. Supported for two filenames which can be
91 | compared. First file is marked with 1>, second with 2>. If no
92 | filename is given the GUI will start.
93 |
94 | optional arguments:
95 | -h, --help show this help message and exit
96 | --debug print debug info
97 | --noprint don't print data, use with debug
98 | --save save data to forscan abt file (e.g. in case you want to fix the
99 | checksums)
100 |
101 | ```
102 |
103 |
104 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3"
2 | services:
3 | apim-web:
4 | build:
5 | context: .
6 | dockerfile: ${PWD}/web/Dockerfile
7 | ports:
8 | - 8000:8000
9 | environment:
10 | FLASK_ENV: development
11 |
--------------------------------------------------------------------------------
/docker/Dockerfile-python3-x64:
--------------------------------------------------------------------------------
1 | FROM cdrx/pyinstaller-windows:python3
2 |
3 | RUN apt-get update -y
4 | RUN pip install --upgrade PyQt5
5 | RUN pip install --upgrade sip
6 | RUN mkdir /app
7 | COPY run.sh /app
8 |
9 | WORKDIR /src
10 | RUN chmod uga+x /app/run.sh
11 | CMD ["/app/run.sh"]
12 |
--------------------------------------------------------------------------------
/docker/Dockerfile-python3-x86:
--------------------------------------------------------------------------------
1 | FROM cdrx/pyinstaller-windows:python3-32bit
2 |
3 | RUN apt-get update -y
4 | RUN pip install --upgrade PyQt5
5 | RUN pip install --upgrade sip
6 | RUN mkdir /app
7 | COPY run.sh /app
8 |
9 | WORKDIR /src
10 | RUN chmod uga+x /app/run.sh
11 | CMD ["/app/run.sh"]
12 |
--------------------------------------------------------------------------------
/docker/build.sh:
--------------------------------------------------------------------------------
1 | docker-compose build
2 | docker-compose run python3-x64
3 | mv ../bin/apim.exe ../bin/apim-python3-Qt5-x64.exe
4 | docker-compose run python3-x86
5 | mv ../bin/apim.exe ../bin/apim-python3-Qt5-x86-32bit.exe
6 |
--------------------------------------------------------------------------------
/docker/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3"
2 | services:
3 | python3-x64:
4 | build:
5 | context: .
6 | dockerfile: Dockerfile-python3-x64
7 | volumes:
8 | - ../src/:/src/
9 | - ../bin/:/dist/
10 | - ../build/:/build/
11 | python3-x86:
12 | build:
13 | context: .
14 | dockerfile: Dockerfile-python3-x86
15 | volumes:
16 | - ../src/:/src/
17 | - ../bin/:/dist/
18 | - ../build/:/build/
19 |
--------------------------------------------------------------------------------
/docker/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | cd /src/
3 | pyinstaller --onefile --distpath /dist/ --workpath /build/ apim.py
4 |
--------------------------------------------------------------------------------
/img/main.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cyanlabs/apim-asbuilt-decode/4c8ba509b4e51ee5520a43094fc26c468289b998/img/main.png
--------------------------------------------------------------------------------
/img/open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cyanlabs/apim-asbuilt-decode/4c8ba509b4e51ee5520a43094fc26c468289b998/img/open.png
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | PyQt5
2 |
--------------------------------------------------------------------------------
/src/apim.py:
--------------------------------------------------------------------------------
1 | import sys
2 |
3 | if sys.version_info[0] < 3:
4 | raise Exception("Must be using Python 3")
5 | if sys.version_info[1] < 4:
6 | raise Exception("Must be using Python 3.4 or up")
7 | # QT Imports
8 | try:
9 | from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QHBoxLayout, QLabel, QFileDialog, QGroupBox, QMessageBox, QComboBox, QScrollArea, QSizePolicy, QTabWidget, QLineEdit, QStatusBar
10 | from PyQt5.QtGui import QDoubleValidator, QRegExpValidator
11 | from PyQt5.QtCore import QRegExp, Qt
12 | from functools import partial
13 | except:
14 | raise Exception("PyQt5 required")
15 |
16 | # Specific imports
17 | from binascii import unhexlify, hexlify
18 |
19 | # local imports
20 | from asbuilt import AsBuilt
21 | from encoder import print_bits_known_de07_08, ItemEncoder, print_duplicates
22 | from statics import JumpTables, Fields, ThemeConfig
23 | # global imports
24 | import argparse
25 |
26 | def calc_change(block, loc, cfield, fields):
27 | x = []
28 | x.append(0x07)
29 | x.append(0xD0)
30 | x.append(block)
31 | x.append(loc)
32 | for f in fields:
33 | x.append(int(f.text(), 16))
34 |
35 | cfield.setText("%02X" % (sum(x) & 0x00FF))
36 |
37 | class QtApp(object):
38 |
39 | app = None
40 | main_layout = None
41 | main_window = None
42 | button_open = None
43 | button_exit = None
44 | button_save = None
45 | button_save_as = None
46 |
47 | current_window = None
48 |
49 | picker_window = None
50 | picker_layout = None
51 |
52 | selected_file = None
53 | asbuilt = None
54 | encoder = None
55 |
56 | blockdata = None
57 |
58 | block = 1
59 |
60 | textblocks = []
61 |
62 | def open_file(self):
63 | window = self.current_window
64 | options = QFileDialog.Options()
65 | options |= QFileDialog.DontUseNativeDialog
66 | files, _ = QFileDialog.getOpenFileName(window, "Select ASBuilt file...", "","ForScan files (*.abt);;Ford ASBuilt XML (*.ab);;UCDS XML files (*.xml);;All Files (*)", options=options)
67 | if files:
68 | self.selected_file = files
69 |
70 | if self.selected_file is not None:
71 | try:
72 | self.asbuilt = AsBuilt(self.selected_file)
73 | self.encoder = ItemEncoder(self.asbuilt)
74 | self.launch_picker()
75 | except ValueError as e:
76 | QMessageBox.critical(self.current_window, "Error opening file", str(e))
77 | self.selected_file = None
78 | self.current_window.show()
79 |
80 |
81 | def save_file_as(self, window=None):
82 | window = self.current_window
83 | options = QFileDialog.Options()
84 | options |= QFileDialog.DontUseNativeDialog
85 | files, things = QFileDialog.getSaveFileName(window, "Save file to ...", "","ForScan files (*.abt)", options=options)
86 | if files:
87 | self.selected_file = files
88 | if self.selected_file.endswith(".ab"):
89 | self.selected_file = self.selected_file[:-3]
90 | if not self.selected_file.endswith(".abt"):
91 | self.selected_file = self.selected_file + ".abt"
92 |
93 | if self.selected_file is not None and files is not None and len(files) > 0:
94 | self.save(overwrite=True)
95 |
96 | def save(self, overwrite=False):
97 | for x in range(0, self.asbuilt.block_size()):
98 | block = list(self.asbuilt.blocks[x])
99 | for b in range(0, len(self.textblocks[x])):
100 | block[b] = int(self.textblocks[x][b].text(), 16)
101 | self.asbuilt.blocks[x] = bytes(block)
102 | string = self.asbuilt.save()
103 |
104 | print("Saving to %s" % self.selected_file)
105 | print(string)
106 | item = False
107 | if not overwrite:
108 | item = QMessageBox.question(self.current_window, "Save...", "Do you want to overwrite %s?" % (self.selected_file), QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
109 | if item == QMessageBox.Yes or overwrite:
110 | print("saving")
111 | try:
112 | with open(self.selected_file, "w") as f:
113 | f.write(string)
114 | f.flush()
115 | f.close()
116 | except Exception as e:
117 | QMessageBox.critical(self.current_window, "Error saving to file", str(e))
118 | pass
119 |
120 |
121 |
122 |
123 | def block_change(self):
124 | print("Selected item %d" % (self.block_combo_box.currentIndex()))
125 | self.block = self.block_combo_box.currentIndex() + 1
126 | self.add_blockitems()
127 |
128 |
129 | def launch_picker(self):
130 | self.main_window.hide()
131 | if self.picker_window is not None:
132 | self.picker_window.hide()
133 |
134 | self.picker_window = QWidget()
135 | self.picker_window.resize(1024, 800)
136 |
137 | self.picker_layout = QVBoxLayout()
138 |
139 | ## main group
140 | self.button_group = QGroupBox("Main things")
141 | self.button_group_layout = QHBoxLayout()
142 | self.button_save = QPushButton("Save") if self.button_save is None else self.button_save
143 | self.button_save_as = QPushButton("Save as ...") if self.button_save_as is None else self.button_save_as
144 | self.button_save_as.clicked.connect(self.save_file_as)
145 | self.button_save.clicked.connect(self.save)
146 | self.syncversion = QComboBox()
147 | if self.asbuilt.s4:
148 | self.syncversion.addItems(["4"])
149 | self.syncversion.setEnabled(False)
150 | else:
151 | self.syncversion.addItems(["3.0-3.2", "3.4"])
152 | self.syncversion.setCurrentIndex(1)
153 |
154 | self.button_group_layout.addWidget(self.button_open)
155 | self.button_group_layout.addWidget(self.button_save)
156 | self.button_group_layout.addWidget(self.button_save_as)
157 | self.button_group_layout.addWidget(self.button_exit)
158 | self.button_group_layout.addWidget(self.syncversion)
159 | self.button_group.setLayout(self.button_group_layout)
160 |
161 | ## Block group
162 | self.block_group = QGroupBox("Select block")
163 | self.block_group_layout = QVBoxLayout()
164 |
165 | #self.block_combo_box = QComboBox()
166 |
167 | #self.block_combo_box.addItems(["7D0-%02X or DE%02X" % (x, x-1) for x in range(1, self.asbuilt.size()+1)])
168 | #self.block_combo_box.currentIndexChanged.connect(self.block_change)
169 |
170 | self.tabs = QTabWidget()
171 | self.tab = []
172 | self.textblocks = []
173 | for x in range(1, self.asbuilt.block_size() + 1):
174 | block_items_group = QGroupBox()
175 | block_items_layout = QVBoxLayout()
176 | block_items_group.setLayout(block_items_layout)
177 |
178 | setup = QWidget()
179 |
180 | scroll_area = QScrollArea()
181 | scroll_area.setWidget(block_items_group)
182 | scroll_area.setWidgetResizable(True)
183 |
184 | blockview = QGroupBox("Binary")
185 | blockview_layout = QHBoxLayout()
186 | blockview.setLayout(blockview_layout)
187 | self.textblocks.append([])
188 | bt = 0
189 | for byte in self.asbuilt.block(x-1):
190 | text = QLineEdit()
191 | text.setValidator(QRegExpValidator(QRegExp("[0-9A-F][0-9A-F]")))
192 | text.setText("%02X" % (byte))
193 | text.setMaximumWidth(22)
194 | text.setReadOnly(True)
195 | if (bt % 5) == 0:
196 | label = QLabel()
197 | label.setText("7D0-%02X-%02X" % (x, (bt//5)+1))
198 | label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
199 | blockview_layout.addWidget(label, stretch=0)
200 | blockview_layout.addWidget(text, stretch=1)
201 | else:
202 | blockview_layout.addWidget(text, stretch=0)
203 | if bt % 5 == 1 or bt % 5 == 3:
204 | label2 = QLabel()
205 | label2.setText(" ")
206 | label2.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
207 | label2.adjustSize()
208 | blockview_layout.addWidget(label2, stretch=0)
209 |
210 |
211 |
212 | bt += 1
213 | self.textblocks[x-1].append(text)
214 |
215 | if bt % 5 == 0:
216 | text = QLineEdit()
217 | text.setValidator(QRegExpValidator(QRegExp("[0-9A-F][0-9A-F]")))
218 | calc_change(x, ((bt-1) // 5) + 1, text, self.textblocks[x-1][bt-5:bt])
219 | text.setMaximumWidth(22)
220 | text.setReadOnly(True)
221 | for n in self.textblocks[x-1][bt-5:bt]:
222 | n.textChanged.connect(partial(calc_change, x, ((bt-1) // 5) + 1, text, self.textblocks[x-1][bt-5:bt]))
223 | blockview_layout.addWidget(text)
224 | blockview_layout.addStretch(1)
225 | if bt % 5 != 0:
226 | text = QLineEdit()
227 | text.setValidator(QRegExpValidator(QRegExp("[0-9A-F][0-9A-F]")))
228 | calc_change(x, ((bt-1) // 5) + 1, text, self.textblocks[x-1][bt-(bt % 5):bt])
229 | text.setMaximumWidth(22)
230 | text.setReadOnly(True)
231 | for n in self.textblocks[x-1][bt-(bt % 5):bt]:
232 | n.textChanged.connect(partial(calc_change, x, ((bt-1) // 5) + 1, text, self.textblocks[x-1][bt-(bt % 5):bt]))
233 | blockview_layout.addWidget(text)
234 | blockview_layout.addStretch(1)
235 |
236 | setup = QWidget()
237 | setup_layout = QVBoxLayout()
238 | setup_layout.addWidget(blockview)
239 | setup_layout.addWidget(scroll_area)
240 | setup.setLayout(setup_layout)
241 |
242 | items = self.encoder.QtItemList(x, self.asbuilt, self.textblocks[x-1], self.themechange)
243 | for item in items:
244 | block_items_layout.addLayout(item)
245 | self.tab.append(setup)
246 | self.tabs.addTab(self.tab[x - 1], "7D0-%02X" % (x))
247 |
248 |
249 |
250 | #self.block_group_layout.addWidget(self.block_combo_box)
251 | self.block_group_layout.addWidget(self.tabs)
252 | self.block_group.setLayout(self.block_group_layout)
253 |
254 | self.picker_layout.addWidget(self.button_group)
255 | self.picker_layout.addWidget(self.block_group)
256 |
257 | self.picker_window.setLayout(self.picker_layout)
258 | self.current_window = self.picker_window
259 | #self.picker_window.setSizePolicy(QSizePolicy.Expanding)
260 | self.statusBar = QStatusBar()
261 | self.picker_layout.addWidget(self.statusBar)
262 | self.statusBar.showMessage("")
263 | self.picker_window.show()
264 |
265 | def themechange(self):
266 |
267 | animation = int(self.textblocks[1][2].text(), 16)
268 | theme = int(self.textblocks[2][2].text(), 16)
269 | brand = (int(self.textblocks[0][5].text(), 16) & 0b11100000) >> 5
270 |
271 | #print(theme, animation, brand, self.syncversion.currentText())
272 | matches = ThemeConfig.validate(brand, theme, animation, version=self.syncversion.currentText())
273 |
274 | message = "No themes found matching configuration!" if len(matches) == 0 else matches[0] if len(matches) == 1 else "Found %d themes: %s" % (len(matches), "".join(matches))
275 | self.statusBar.showMessage(message)
276 | #print(matches)
277 | #f = ThemeConfig.validate()
278 |
279 |
280 | def launch_qt(self):
281 | self.app = QApplication([])
282 | self.app.setStyle('Fusion')
283 |
284 | self.main_window = QWidget()
285 | self.main_layout = QVBoxLayout()
286 |
287 | self.button_open = QPushButton("Open File ...")
288 | self.button_open.clicked.connect(self.open_file)
289 | self.button_exit = QPushButton("Exit")
290 | self.button_exit.clicked.connect(sys.exit)
291 |
292 |
293 | self.main_layout.addWidget(self.button_open)
294 | self.main_layout.addWidget(self.button_exit)
295 |
296 | self.main_window.setLayout(self.main_layout)
297 | self.current_window = self.main_window
298 | self.main_window.show()
299 | self.app.exec_()
300 |
301 | if __name__ == "__main__":
302 | parser = argparse.ArgumentParser(description="""
303 | Open and compare asbuilt files or use the GUI to edit them. The debug options should notmally not be used as they provide no useful information to non developers.
304 |
305 | Run without arguments to start the GUI.
306 | """
307 | )
308 |
309 | parser.add_argument("abtfile", help="ForScan abt filename of 7D0 region, ford asbuilt xml or ucds asbuilt xml file. \nSupported for two filenames which can be compared. First file is marked with 1>, second with 2>.\nIf no filename is given the GUI will start.", type=str, nargs='*')
310 | parser.add_argument("--debug", help="print debug info", action="store_true")
311 | parser.add_argument("--noprint", help="don't print data, use with debug", action="store_true")
312 | parser.add_argument("--save", help="save data to forscan abt file (e.g. in case you want to fix the checksums)", action="store_true")
313 | args = parser.parse_args()
314 |
315 | abtfile = args.abtfile
316 | debug = args.debug
317 |
318 | asbuilt1 = AsBuilt(abtfile[0]) if len(abtfile) > 0 else None
319 | asbuilt2 = AsBuilt(abtfile[1]) if len(abtfile) > 1 else None
320 | if asbuilt1 is not None and len(abtfile) > 0 and not debug:
321 |
322 | if not args.noprint:
323 | try:
324 | print(ItemEncoder(asbuilt1).format_all(asbuilt1, asbuilt2))
325 | except Exception as e:
326 | print(asbuilt1.filename, asbuilt1.blocks)
327 | raise
328 | elif not debug:
329 | app = QtApp()
330 | app.launch_qt()
331 | elif debug:
332 | print_bits_known_de07_08()
333 | print_duplicates()
334 | print(asbuilt1.filename, str(asbuilt1), sep="\n") if asbuilt1 is not None else ""
335 | print(asbuilt2.filename, str(asbuilt2), sep="\n") if asbuilt2 is not None else ""
336 |
337 |
338 |
339 |
--------------------------------------------------------------------------------
/src/asbuilt.py:
--------------------------------------------------------------------------------
1 | from binascii import unhexlify, hexlify
2 |
3 | import xml.etree.ElementTree as ET
4 | import struct
5 |
6 | class AsBuilt(object):
7 | fieldsizes_s3 = [10, 12, 5, 7, 6, 1, 16, 10, 20, 20]
8 | fieldsizes_s4 = [20, 15, 15, 5, 15, 6, 16, 10, 25, 25]
9 | blocks = [] # 3.2 and up and later 3.0 models have 8, 9 for 3.4 from late 2019 and my20
10 | filename = ""
11 |
12 | s4 = False
13 | fieldsizes = None
14 |
15 | def __init__(self, filename):
16 | bits = ""
17 | print("Loading", filename)
18 | if filename.lower().endswith(".abt"):
19 | # file from ForScan
20 | print("Forscan ABT format")
21 | with open(filename, "r") as f:
22 | data = f.read()
23 | if "G" in data:
24 | print("New forscan format")
25 | data.replace("G", "0") # fix new format
26 | data = data.split("\n")
27 | bits = ""
28 | for line in data:
29 | if len(line) == 0 or line[0] == ";":
30 | continue
31 | bits = bits + line[7:-2]
32 | elif filename.lower().endswith(".ab"):
33 | print("Loading Ford XML file")
34 | # ab file from motorcraft site / ford
35 | tree = ET.parse(filename)
36 | root = tree.getroot()
37 | data = root.find(".//BCE_MODULE")
38 | for child in list(data):
39 | block = child.attrib['LABEL']
40 | if block.startswith('7D0'):
41 | #b = int(block[4:6], 16)
42 | for code in child.findall(".//CODE"):
43 | if code.text is not None:
44 | bits = bits + code.text
45 | bits = bits[:-2]
46 | elif filename.lower().endswith(".xml"):
47 | print("Loading UCDS Direct configuration XML file")
48 | # ab file from motorcraft site / ford
49 | tree = ET.parse(filename)
50 | root = tree.getroot()
51 | data = root.find(".//VEHICLE")
52 | for child in list(data):
53 | block = child.attrib['ID']
54 | if block.startswith('DE'):
55 | bits = bits + child.text
56 | else:
57 | raise ValueError("File type not supported")
58 | self.filename = filename
59 | # detect actual length
60 | length = len(unhexlify(bits.encode()))
61 | for i in range(0, len(self.fieldsizes_s3)+1):
62 | s4 = sum(self.fieldsizes_s3[0:i])
63 | if s4 == length:
64 | self.s4 = False
65 | self.fieldsizes = self.fieldsizes_s3
66 |
67 | for i in range(0, len(self.fieldsizes_s4)+1):
68 | s4 = sum(self.fieldsizes_s4[0:i])
69 | if s4 == length:
70 | self.s4 = True
71 | self.fieldsizes = self.fieldsizes_s4
72 | self.decode_bytes(unhexlify(bits.encode()))
73 | print("Loaded %d blocks, %d bytes" % (len(self.blocks), len(bytes(self))))
74 | if self.s4:
75 | print("Device is Sync 4")
76 | else:
77 | print("Device is Sync 3")
78 |
79 |
80 | def decode_bytes(self, data):
81 | if len(self.blocks) > 0:
82 | self.blocks = []
83 | i = 0
84 |
85 | while len(data) > 0:
86 | try:
87 | if self.s4:
88 | self.blocks.append(data[:self.fieldsizes_s4[i]])
89 | data = data[self.fieldsizes_s4[i]:]
90 | else:
91 | self.blocks.append(data[:self.fieldsizes_s4[i]])
92 | data = data[self.fieldsizes[i]:]
93 | i += 1
94 | except:
95 | print(len(data))
96 | print(hexlify(data).decode())
97 | print(i)
98 | if self.s4:
99 | print(self.fieldsizes_s4[i])
100 | else:
101 | print(self.fieldsizes[i])
102 |
103 | def checksum(self, major, minor):
104 | return (0x07 + 0xD0 + major + minor + sum(self.blocks[major - 1][(minor-1) * 5:minor * 5])) & 0x00FF
105 |
106 | def save(self):
107 | string = "; Created with apim.py, https://github.com/consp/apim-asbuilt-decode\n"
108 | for x in range(1, self.block_size() + 1):
109 | # 7D0G5G1169B1674263E
110 | string = string + "; Block %d \n" % (x)
111 | for z in range(0, len(self.blocks[x - 1]),5):
112 | string = string + "7D0G%dG%d" % (x, (z // 5) + 1)
113 | for d in self.blocks[x - 1][z:z+5]:
114 | string = string + "%02X" % (d)
115 | string = string + "%02X" % (self.checksum(x, (z // 5) + 1)) + "\n"
116 | return string
117 |
118 | def byte(self, byte):
119 | if byte > sum(self.fieldsizes) or byte > (self.size() // 8) - 1:
120 | return None
121 | return bytes(self)[byte]
122 |
123 | def bytes(self, start, stop):
124 | return bytes(self)[start // 8:((stop-1) // 8)+1]
125 |
126 | def word(self, index):
127 | if index+1 > sum(self.fieldsizes):
128 | return None
129 | return ((bytes(self)[index]) << 8) + (bytes(self)[index+1])
130 |
131 | def int(self, start, end):
132 | if end > sum(self.fieldsizes):
133 | return None
134 | return int(hexlify(bytes(self)[start:end]), 16)
135 |
136 | def size(self):
137 | return len(bytes(self) * 8)
138 |
139 | def bit(self, start, stop=-1):
140 | if stop == -1:
141 | stop = start + 1
142 | else:
143 | stop = start + stop
144 | if start > self.size():
145 | return -1
146 | bitdata = "".join([format(x, "08b") for x in bytes(self)])
147 | return int(bitdata[start:stop], 2)
148 |
149 | def start_byte(self, block):
150 | return sum(self.fieldsizes[:block-1]) if len(self.blocks) >= block else 0 if block <= 0 else -1
151 |
152 | def start_bit(self, block):
153 | return self.start_byte(block) * 8
154 |
155 | def block(self, block):
156 | return self.blocks[block]
157 |
158 | def block_size(self):
159 | return len(self.blocks)
160 |
161 | def hasblock(self, block):
162 | return block <= len(self.blocks)
163 |
164 | def mask_string(self, start, stop, values=False):
165 | i = 1
166 | value = int.from_bytes(self.bytes(start, stop), byteorder="big")
167 | for f in self.fieldsizes:
168 | if f * 8 > start:
169 | break
170 | start -= f * 8
171 | stop -= f * 8
172 | i += 1
173 | l = (start // 40) + 1
174 | string = ""
175 | cnt = 0
176 | fin = 40
177 | string = string + "7D0-%02X-%02X"% (i, l)
178 | for n in range((start // 40) * 40, stop, 40):
179 | string = string + " -" if cnt > 0 else string
180 | y = start % 40
181 | z = stop % 40
182 | if (stop > n and z < y and cnt == 0) or stop % 40 == 0:
183 | z = 40
184 | if y > z and cnt > 0:
185 | y = 0
186 | if cnt > 0:
187 | fin = z
188 | #string = string + " %d %d %d " % (z, y, fin)
189 | for x in range(0, y - (y % 4), 4):
190 | if x % 16 == 0:
191 | string = string + " "
192 | string = string + "n"
193 | for x in range(y - (y % 4), (z + (4 - (z % 4))), 4):
194 | if x % 16 == 0:
195 | string = string + " "
196 | if x == z and z != fin:
197 | string = string + "n"
198 | continue
199 | if x != fin:
200 | string = string + "X"
201 | for x in range(max(z + (4 - (z % 4)), y), fin, 4):
202 | if x % 16 == 0:
203 | string = string + " "
204 | string = string + "n"
205 | l += 1
206 | cnt += 1
207 | mask = ((2**(stop - start)) - 1) << (7-((stop-1) % 8))
208 | string = string + " %02X & %02X = %02X" % (value, mask, value & mask) if values else string
209 |
210 | return string
211 |
212 | def __len__(self):
213 | return len(bytes(self))
214 |
215 | def __bytes__(self):
216 | return b"".join(self.blocks)
217 |
218 | def __str__(self):
219 | string = ""
220 | major = 0
221 | for item in self.blocks:
222 | major += 1
223 | minor = 0
224 | for block in [item[x:x+5] for x in range(0, len(item), 5)]:
225 | minor += 1
226 | string = string + "7D0-%02X-%02X " % (major, minor)
227 | for field in [block[x:x+2] if x < 4 else block[x:x+1] for x in range(0, len(block), 2) if x < 5]:
228 | string = string + "%02X%02X " % (field[0], field[1]) if len(field) > 1 else string + "%02X" % field[0]
229 | string = string + "%02X\n" % self.checksum(major, minor)
230 | return string
231 |
--------------------------------------------------------------------------------
/src/encoder.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLayout, QVBoxLayout, QHBoxLayout, QLabel, QFileDialog, QGroupBox, QMessageBox, QComboBox, QScrollArea, QLineEdit, QSizePolicy, QFrame, QLabel
2 | from PyQt5.QtGui import QDoubleValidator, QRegExpValidator
3 | from PyQt5.QtCore import QRegExp, Qt
4 |
5 | from functools import partial
6 | from statics import JumpTables, Fields, Fields_s4
7 | from asbuilt import AsBuilt
8 |
9 |
10 | DEBUG=False
11 |
12 | import struct
13 | class HmiData(object):
14 | data = None
15 | items = [] # block 0-3
16 | high_items = [] # block 5-7
17 | index_locations_high = [ # offset to DE04, includes DE05 and DE06 (7D0-05-07), format [byte start, byte end, bitvalue (first bit is 1)]
18 | [0, 2], [2, 2], [4, 2], [6, 1, 1], [6, 1, 2], [7, 1], [8, 1], [9, 1], [10, 1], [11, 1], [12, 2], [14, 2], [16, 2], [18, 1], [19, 1], [20, 1], [21, 2]
19 | ]
20 |
21 | fields = None
22 |
23 | def output_stuff(self, ab):
24 | for x in range(1, 5):
25 | print(" de%02X = [" % (x-1))
26 | for item in self.items:
27 | l = self.bit(item['index'])//8
28 | if l < ab.start_byte(x+1) and l >= ab.start_byte(x):
29 | print(" {")
30 | print(" 'name': '%s'," % item['name'])
31 | print(" 'index': %d," % (item['index'] + 1))
32 | print(" 'byte': %d," % (self.byte(item['index']) - ab.start_byte(x)))
33 | print(" 'bit': %d," % (self.bit(item['index']) % 8)) # reverse
34 | print(" 'size': %d," % (item['items']))
35 | if item['items'] >= 255 or '255' in item:
36 | print(" 'type': 'table',")
37 | try:
38 | print(" 'table': '%s'," % (item['255']))
39 | except:
40 | print(item)
41 | raise
42 | continue
43 | print(" 'items':", item['items'], ",")
44 | print(" 'type': 'mask',")
45 | for z in range(0, item['items']):
46 | print(" '%d': '%s'," % (z, item['%d'%z]))
47 | print(" },")
48 | print(" ]\n\n")
49 |
50 | for x in range(5, 8):
51 | print(" de%02X = [" % (x))
52 | for item in self.high_items:
53 | l = ab.start_byte(5) + self.index_locations_high[item['index']][0]
54 | if l < ab.start_byte(x+1) and l >= ab.start_byte(x):
55 | print(" {")
56 | print(" 'name': '%s'," % item['name'])
57 | print(" 'index': %d," % (item['index'] + 135))
58 | print(" 'byte': %d," % ((ab.start_byte(x) - ab.start_byte(5)) + self.index_locations_high[item['index']][0]))
59 | print(" 'size': %d," % (2**(self.index_locations_high[item['index']][1]*8) - 1))
60 | if len(self.index_locations_high[item['index']]) == 2:
61 | print(" 'bit': %d," % (0))
62 | print(" 'type': 'mul',")
63 | print(" 'min': %s," % (item['min']))
64 | print(" 'max': %s," % (item['max']))
65 | print(" 'offset': %s," % (item['offset']))
66 | print(" 'multiplier': %s," % (item['multiplier']))
67 | print(" 'unit': '%s'," % (item['255']))
68 | else:
69 | print(" 'bit': %d," % (self.index_locations_high[item['index']][2]-1))
70 | for z in range(0, item['items']):
71 | print(" '%d': '%s'," % (z, item['%d'%z]))
72 | print(" 'items':", item['items'], ",")
73 | print(" },")
74 | print(" ]\n\n")
75 |
76 | def __init__(self, filename):
77 | """
78 | The fields are as follows:
79 | [index][minor index][127 * name][\0][index][minor index][255 * value][\0]
80 | for a total of 378 bytes per item
81 | The index is the number of the setting, the minor index is the option (e.g. 0, 1, 2, 3 for a 4 bit field)
82 | """
83 | try:
84 | with open(filename, "rb") as f:
85 | inp = f.read()
86 | try:
87 | rawdata = unhexlify(inp.replace(b"\n", b"").replace(b" ", b""))
88 | except:
89 | rawdata = inp
90 | except:
91 | print("Requires hmi file to be present. Expecting %s but not found" % hmifile)
92 | exit(1)
93 |
94 | data = rawdata[rawdata.find(b"Smart DSP")-2:]
95 | self.data = b""
96 | item = {}
97 | items = [] # de00-03
98 | try:
99 | for i in range(0, len(data), 128 + 256 + 4):
100 | index = data[i]
101 | itemindex = data[i+1]
102 | name = data[i+2:i+130].replace(b"\x00", b"")
103 |
104 | if len(items) < index + 1:
105 | items.append({})
106 | items[index]['name'] = name.decode()
107 | items[index]['index'] = index
108 | valueindex = data[i+129]
109 | valueindex_minor = data[i+130]
110 | value = data[i+131:i+131+257].replace(b"\x00", b"")
111 | if "%d" % valueindex_minor not in items[index]:
112 | items[index]["%d" % valueindex_minor] = value.decode()
113 | if 'items' not in items[index]:
114 | items[index]['items'] = 1
115 | else:
116 | items[index]['items'] = items[index]['items'] + 1
117 | if valueindex_minor == 255:
118 | if value.decode() == "_BPT":
119 | items[index]['items'] = 1048575 # replaced by Sync Connect settings
120 | elif value.decode() == "BAPI":
121 | items[index]['items'] = 65535 # double block
122 | elif value.decode() == "___C":
123 | items[index]['items'] = 31
124 | else:
125 | items[index]['items'] = 255
126 | elif valueindex_minor == 254:
127 | items[index]['items'] = 254
128 | self.data = self.data + data[i:i+128 + 256 + 4]
129 | if index == 133: # there are 134 categorized items out 178 in total which this data blob contains, 135 for sync 3.4 but one is unencoded
130 | break
131 | #print("%d %d %s %d %d %s" % (index, itemindex, name, valueindex, valueindex_minor, value))
132 | except Exception as e:
133 | raise
134 | high_items = [] # de04-07
135 | try:
136 | data = rawdata[rawdata.find(b"Front Track") - 2:]
137 | for i in range(0, len(data), 212):
138 | if i > 0x12 * 212:
139 | break
140 | item = {}
141 | index = data[i]
142 | name = data[i+2:i+2+128].replace(b"\x00", b"")
143 | mul = struct.unpack(""
217 | marker2 = "" if ab2 is None else "2>"
218 |
219 | string = "# -bits-loc- %-76s - Field Location Msk&Val = Res\n" % ("Name")
220 | for i in range(self.size()):
221 | mask = (2**((self.bit(i)+self.bits(i) - self.bit(i)) - 1)) << (7-((self.bit(i) + self.bits(i) - 1) % 8))
222 | value = int.from_bytes(ab2.bytes(self.bit(i), self.bit(i)+self.bits(i)), byteorder='big') if ab2 is not None else None
223 | string = string + "%-03s - %-02d - %-d %-s %-s %-s %s\n" % (
224 | self.index(i)+1,
225 | self.bits(i),
226 | self.bit(i),
227 | self.name(i),
228 | "." * (78 - len(self.name(i))),
229 | self.calc_field(ab1, i),
230 | "vs %02X & %02X = %02X" % (value, mask, value & mask) if value is not None else ""
231 | )
232 | if self.is_table(i):
233 | string = string + "\t\t\t Identifier type: %s -> %02X\n" % (self.value(i), ab1.byte(self.byte(i)))
234 | if hasattr(JumpTables, self.value(i).replace("___", "_").replace("__", "_")):
235 | table = getattr(JumpTables, self.value(i).replace("___", "_").replace("__", "_"))
236 | for x in range(0, len(table)):
237 | string = string + ("\t\t %2s %2s %02X:\t%s\n" % (marker1 if x == ab1.bit(self.bit(i), self.bits(i)) else "", marker2 if ab2 is not None and x == ab2.bit(self.bit(i), self.bits(i)) else "", x, table[x]))
238 | else:
239 | string = string + ("Attribute %s not found\n" % (self.value(i)))
240 | continue
241 | for x in range(0, len(self.value(i))):
242 | string = string + "\t\t %2s %2s %d:\t%s\n" % (
243 | marker1 if ab1.bit(self.bit(i), self.bits(i)) == int(x) else "",
244 | marker2 if ab2 is not None and ab2.bit(self.bit(i), self.bits(i)) == int(x) else "",
245 | x,
246 | self.value(i)[x]
247 | )
248 | return string
249 |
250 | def format_de4_6(self, ab1, ab2=None):
251 | """
252 | Blocks 4 to 6 are mostly offset, multiplier values. Thet are located in the .rodata of the HMI
253 | as well but not included and manually decoded.
254 | The function reading them has the following fields for each item:
255 | [32bit float multiplier][32bit usigned int offset][32bit float min][32bit float max][24 char unit]
256 | If the unit equals "unitless" (yes a string compare is present) nothing is displayed
257 |
258 | """
259 | string = ""
260 | start = ab1.start_byte(5)
261 | num = 135
262 | for i in range(0, len(self.high_items)):
263 | if '255' in self.high_items[i]:
264 | a1v = (ab1.int(start + self.index_locations_high[i][0], start + self.index_locations_high[i][0]+self.index_locations_high[i][1]))
265 | a2v = (ab2.int(start + self.index_locations_high[i][0], start + self.index_locations_high[i][0]+self.index_locations_high[i][1])) if ab2 is not None else None
266 | val1 = (self.high_items[i]['multiplier'] * a1v) + self.high_items[i]['offset']
267 | val2 = (self.high_items[i]['multiplier'] * a2v) + self.high_items[i]['offset'] if ab2 is not None else None
268 | string = string + "%-3s - %-48s%-32s\t%s%s\t%-16s%-16s\tMin: %0.1f\tMax: %0.1f\n" %(
269 | num,
270 | self.high_items[i]['name'],
271 | ab1.mask_string((start + self.index_locations_high[i][0])*8, (start + self.index_locations_high[i][0]+self.index_locations_high[i][1])*8),
272 | "%04X" % a1v,
273 | " vs %04X" % a2v if a2v is not None else "",
274 | "%0.1f %s%s" % (val1, self.high_items[i]['unit'], " (%0.1f cm)" % (val1 * 2.54) if self.high_items[i]['unit'] == "In" else ""),
275 | " vs %0.1f %s%s" % (val2, self.high_items[i]['unit'], " (%0.1f cm)" % (val2 * 2.54) if self.high_items[i]['unit'] == "In" else "") if val2 is not None else "",
276 | self.high_items[i]['min'],
277 | self.high_items[i]['max']
278 | )
279 | else:
280 | a1byte = (ab1.int(start + self.index_locations_high[i][0], start + self.index_locations_high[i][0]+self.index_locations_high[i][1]))
281 | a2byte = (ab2.int(start + self.index_locations_high[i][0], start + self.index_locations_high[i][0]+self.index_locations_high[i][1])) if ab2 is not None else None
282 | a1v = 0x1 & (a1byte >> (8 - self.index_locations_high[i][2]))
283 | a2v = 0x1 & (a2byte >> (7 - self.index_locations_high[i][2])) if ab2 is not None else None
284 |
285 | string = string + "%-3s - %-48s%-32s: %s%s\n" %(
286 | num,
287 | self.high_items[i]['name'],
288 | ab1.mask_string(((start + self.index_locations_high[i][0])*8) + (self.index_locations_high[i][2])-1, ((start + self.index_locations_high[i][0])*8) + (self.index_locations_high[i][2])),
289 | "%02X" % a1byte,
290 | "" if a2v is None else "vs %02X" % a2byte
291 | )
292 | for x in range(0, self.high_items[i]['items']):
293 | string = string + "%-24s%-2s %-2s %02X: %s\n" % (
294 | "",
295 | "1>" if a1v == x and a2v is not None else ">>" if a1v == x else "",
296 | "2>" if a2v is not None and a2v == x else "",
297 | x,
298 | self.high_items[i]["%d"%x]
299 | )
300 | num += 1
301 | return string
302 |
303 | def format_de07(self, ab1, ab2=None):
304 | """
305 |
306 |
307 | { 'name': 'INTELLIGENT_ACCESS',
308 | 'index': 289,
309 | 'byte': 6,
310 | 'bit': 5,
311 | 'size': 1,
312 | 'items': 0,
313 | },
314 | """
315 | string = "#%s%-96s - Field Location Msk&Val = Res\n" % (" -bits-loc - " if DEBUG else "", "Name")
316 | if ab1.start_byte(8) == -1 and ab2.start_byte(8) == -1 or ab1.start_byte(8) == -1:
317 | return string
318 | fields = Fields
319 | if ab1.s4:
320 | fields = Fields_s4
321 | for item in fields.de07:
322 | bit = 7 - item['bit']
323 | bitloc = ab1.start_bit(8) + ((item['byte']) * 8) + bit
324 | value1 = ab1.bit(bitloc, item['size'].bit_length())
325 | value2 = ab2.bit(bitloc, item['size'].bit_length()) if ab2 is not None else None
326 | byte1 = ab1.byte(ab1.start_byte(8) + item['byte'])
327 | byte2 = ab2.byte(ab1.start_byte(8) + item['byte']) if ab2 is not None else None
328 | string = string + "%s%-s: %s %s // %s %s\n" % ("%d - %d - %d\t " if DEBUG else "",
329 | item['index'],
330 | item['size'].bit_length(),
331 | bitloc,
332 | item['name'],
333 | "." * (98 - len(item['name'])),
334 | ab1.mask_string(bitloc, bitloc + item['size'].bit_length()),
335 | "0x%02X" % byte1,
336 | "" if byte2 is None else "0x%02X" % byte2
337 | )
338 | # for now assume enable // disable if one bit or multi bit strategy
339 | for x in range(0, item['size']+1):
340 | string = string + "\t\t %2s %2s %s:\t%s\n" % (
341 | ">>" if ab2 is None and x == value1 else "1>" if x == value1 else "",
342 | "2>" if ab2 is not None and x == value2 else "",
343 | "%02X" % x,
344 | "" # no known values
345 | )
346 |
347 | return string
348 |
349 | def format_de08(self, ab1, ab2=None):
350 | string = "# -bits-loc - %-96s - Field Location Msk&Val = Res\n" % ("Name")
351 | if ab1.start_byte(9) == -1 and ab2.start_byte(9) == -1 or ab1.start_byte(9) == -1:
352 | return string
353 | fields = Fields
354 | if ab1.s4:
355 | fields = Fields_s4
356 |
357 | for item in fields.de08:
358 | bit = 7 - item['bit']
359 | bitloc = ab1.start_bit(9) + ((item['byte']) * 8) + bit
360 | value1 = ab1.bit(bitloc, item['size'].bit_length())
361 | value2 = ab2.bit(bitloc, item['size'].bit_length()) if ab2 is not None else None
362 | byte1 = ab1.byte(ab1.start_byte(9) + item['byte'])
363 | byte2 = ab2.byte(ab1.start_byte(9) + item['byte']) if ab2 is not None else None
364 | string = string + "%d - %d - %d\t %-s: %s %s // %s %s\n" % (
365 | item['index'],
366 | item['size'].bit_length(),
367 | bitloc,
368 | item['name'],
369 | "." * (98 - len(item['name'])),
370 | ab1.mask_string(bitloc, bitloc + item['size'].bit_length()),
371 | "0x%02X" % byte1,
372 | "" if byte2 is None else "0x%02X" % byte2
373 | )
374 | # for now assume enable // disable if one bit or multi bit strategy
375 | for x in range(0, item['size']+1):
376 | string = string + "\t\t %2s %2s %s:\t%s\n" % (
377 | ">>" if ab2 is None and x == value1 else "1>" if x == value1 else "",
378 | "2>" if ab2 is not None and x == value2 else "",
379 | "%02X" % x,
380 | "" # no known values
381 | )
382 |
383 | return string
384 |
385 |
386 |
387 | def format(self, ab1, ab2=None):
388 | string = self.format_de0_3(ab1, ab2)
389 | string = string + self.format_de4_6(ab1, ab2)
390 | string = string + self.format_de07(ab1, ab2)
391 | string = string + self.format_de08(ab1, ab2)
392 | return string
393 |
394 | def combo_change(box, item, bitfieldblock, *args, **kwargs):
395 | value = box.currentIndex()
396 | data = int(bitfieldblock.text(), 16)
397 | bitdata = '{0:08b}'.format(data)
398 | bitdata = bitdata[:item['bit']] + ("{0:0%db}" % (item['size'])).format(value) + bitdata[item['bit']+item['size']:]
399 | data = int(bitdata, 2)
400 |
401 | bitfieldblock.setText("%02X" % (data))
402 |
403 | def value_change(box, item, bitfieldblock, *args, **kwargs):
404 | value = float(box.text())
405 |
406 |
407 | if value > item['max']:
408 | value = item['max']
409 | elif value < item['min']:
410 | value = item['min']
411 | v = ((value - item['offset']) / item['multiplier'])
412 | box.setText("%.2f" % value)
413 | data = int(bitfieldblock[0].text(), 16) if len(bitfieldblock) == 1 else int(bitfieldblock[0].text() + bitfieldblock[1].text(), 16)
414 | bitdata = ('{0:0%db}' % (item['size'])).format(data)
415 | bitdata = bitdata[:item['bit']] + ("{0:0%db}" % (item['size'])).format(int(v)) + bitdata[item['bit']+item['size']:]
416 | data = int(bitdata, 2)
417 | string = "%04X" % (data)
418 | if item['size'] > 8:
419 | bitfieldblock[0].setText(string[:2])
420 | bitfieldblock[1].setText(string[2:])
421 | else:
422 | bitfieldblock[0].setText(string[2:])
423 |
424 |
425 | def ascii_change(box, item, bitfieldblock, *args, **kwargs):
426 | value = box.text()
427 | #bitdata = bitdata[:item['bit']] + ("{0:0%db}" % (item['size'])).format(value) + bitdata[item['bit']+item['size']:]
428 | bitfieldblock.setText("%02X" % (ord(value[0])))
429 |
430 | class ItemEncoder(object):
431 | items = []
432 |
433 | def byte_loc_string(self, i, bits):
434 | if i == 0:
435 | if bits <= 8:
436 | return "NNxx xxxx xxcc"
437 | else:
438 | return "NNNN xxxx xxcc"
439 | elif i == 1:
440 | if bits <= 8:
441 | return "xxNN xxxx xxcc"
442 | else:
443 | return "xxNN NNxx xxcc"
444 | elif i == 2:
445 | if bits <= 8:
446 | return "xxxx NNxx xxcc"
447 | else:
448 | return "xxxx NNNN xxcc"
449 | elif i == 3:
450 | if bits <= 8:
451 | return "xxxx xxNN xxcc"
452 | else:
453 | return "xxxx xxNN NNcc"
454 | if bits <= 8:
455 | return "xxxx xxxx NNcc"
456 | else:
457 | return "xxxx xxxx NNcc + NNxx xxxx xxcc"
458 |
459 | def __init__(self, ab):
460 | fields = Fields
461 | if ab.s4:
462 | fields = Fields_s4
463 | self.items = [fields.block(block) for block in range(1, 10)]
464 |
465 | def QtItemList(self, block, asbuilt, bitfields, themechange):
466 | qtitems = []
467 | prevbyte = -1
468 | fields = Fields
469 | if asbuilt.s4:
470 | fields = Fields_s4
471 |
472 | for item in fields.block(block):
473 | if prevbyte != item['byte']:
474 | layout = QHBoxLayout()
475 | label = QLabel()
476 | label.setAlignment(Qt.AlignLeft | Qt.AlignTop)
477 | label.setText("7D0-%02X-%02X %s" % (block, (item['byte'] // 5) + 1, self.byte_loc_string(item['byte'] % 5, item['size'])))
478 | label.adjustSize()
479 | line = QFrame()
480 | line.setFrameShape(QFrame.HLine)
481 | line.setFrameShadow(QFrame.Sunken)
482 | layout.addWidget(label)
483 | layout.addWidget(line, stretch=1)
484 | qtitems.append(layout)
485 | prevbyte = item['byte']
486 | bitloc = asbuilt.start_bit(block) + ((item['byte']) * 8) + item['bit']
487 | layout = QHBoxLayout()
488 | label = QLabel(item['name'])
489 | option = QComboBox()
490 | unit = None
491 | value = asbuilt.bit(bitloc, item['size'])
492 | if item['type'] == 'mul':
493 | # inputfield
494 | value = (asbuilt.bit(bitloc, item['size']) * item['multiplier']) + item['offset']
495 | option = QLineEdit()
496 | option.setValidator(QDoubleValidator())
497 | option.setText("%.02f" % (value))
498 | option.setMaximumWidth(50)
499 | option.editingFinished.connect(partial(value_change, option, item, bitfields[item['byte']:item['byte']+2 if item['size'] > 8 else item['byte']+1]))
500 | unit = QLabel(item['unit'])
501 | unit.setMaximumWidth(50)
502 | unit.setMinimumWidth(50)
503 | elif item['type'] == 'mask':
504 | # combobox
505 | for x in range(0, item['items']):
506 | option.addItem("" if '%d' % x not in item else item['%d' % x], x)
507 | option.setMaximumWidth(400)
508 | option.setCurrentIndex(value)
509 | #print(item['byte'])
510 | #print(bitfields)
511 | try:
512 | option.currentIndexChanged.connect(partial(combo_change, option, item, bitfields[item['byte']]))
513 | except:
514 | print("out of range", item)
515 |
516 |
517 | elif item['type'] == 'ascii':
518 | option = QLineEdit()
519 | option.setValidator(QRegExpValidator(QRegExp("[A-Z]")))
520 | option.setText("%s" % (chr(value)))
521 | option.editingFinished.connect(partial(ascii_change, option, item, bitfields[item['byte']]))
522 | option.setMaximumWidth(50)
523 | elif item['type'] == 'table':
524 | table = JumpTables.table(item['table'])
525 | for x in range(0, len(table)):
526 | option.addItem(table[x], x)
527 | option.setMaximumWidth(400)
528 | option.setCurrentIndex(value)
529 | try:
530 | option.currentIndexChanged.connect(partial(combo_change, option, item, bitfields[item['byte']]))
531 | except:
532 | print("out of range", item)
533 |
534 | if 'theme' in item:
535 | option.currentIndexChanged.connect(partial(themechange))
536 | layout.addWidget(label)
537 | layout.addWidget(option)
538 | if unit is not None:
539 | layout.addWidget(unit)
540 | option.abitem = item
541 | qtitems.append(layout)
542 |
543 |
544 | return qtitems
545 |
546 | def format_all(self, ab1, ab2):
547 | if ab2 is not None and len(ab1) < len(ab2):
548 | ab3 = ab1
549 | ab1 = ab2
550 | ab2 = ab3
551 |
552 | string = ""
553 | for block in range(1, len(ab1.blocks) + 1):
554 | string = string + self.format(block, ab1, ab2)
555 |
556 | return string
557 |
558 | def format(self, block, ab1, ab2):
559 | if not ab1.hasblock(block) or (ab2 is not None and not ab2.hasblock(block)):
560 | return "Block %d not present in %s\n" % (block, "%s and %s" % (ab1.filename, ab2.filename) if not ab1.hasblock(block) and ab2 is not None and not ab2.hasblock(block) else ab1.filename if not ab1.hasblock(block) else ab2.filename)
561 | string = "Block %d (7D0-%02X or DE%02X)\n" % (block, block, block - 1)
562 | if block in [1, 2, 3, 4, 6, 8, 9]:
563 | string = string + "#%s%-76s - Field Loc Byte Loc bit Val1 %s\n" % (" - bit - loc - " if DEBUG else "", "Name", "Val2" if ab2 is not None else "")
564 | else:
565 | string = string + "Block contains multiplier/offset values:\n"
566 |
567 | # Parking Assistance: ................................................................................ 7D0-04-02 nnXX nnnn nn 01 & FF = 01
568 | # Front Track 7D0-05-01 XXXX nnnn nn 169B & FFFF = 169B 169B5.8 In (14.7 cm) Min: 0.0Max: 655.4
569 | try:
570 | if len(self.items) >= block:
571 | for item in self.items[block-1]:
572 | bitloc = ab1.start_bit(block) + ((item['byte']) * 8) + item['bit']
573 | mask = ((2**item['size'])-1) << (((7 - item['bit']) - (item['size'] - 1)) % 8)
574 | value1 = ab1.bit(bitloc, item['size'])
575 | value2 = ab2.bit(bitloc, item['size']) if ab2 is not None else None
576 | byte1 = ab1.int(ab1.start_byte(block) + item['byte'], 1 + ab1.start_byte(block) + item['byte'] + (item['size'] // 8) if item['size'] % 8 != 0 else ab1.start_byte(block) + item['byte'] + (item['size'] // 8))
577 | byte2 = ab2.int(ab1.start_byte(block) + item['byte'], 1 + ab1.start_byte(block) + item['byte'] + (item['size'] // 8) if item['size'] % 8 != 0 else ab1.start_byte(block) + item['byte'] + (item['size'] // 8)) if ab2 is not None else None
578 |
579 | if mask < 256:
580 | bitmask = "{:.>8b}".format(mask)
581 | bitmask = bitmask.replace("0", ".")
582 | bitmask = bitmask[:bitmask.find("1")] + ("{:0%db}" % bitmask.count("1")).format(value1) + bitmask[bitmask.find("1")+bitmask.count("1"):]
583 | else:
584 | bitmask = "too big "
585 | if item['type'] == 'mul':
586 | # multiplier type
587 | value1 = (ab1.bit(bitloc, item['size']) * item['multiplier']) + item['offset']
588 | value2 = (ab2.bit(bitloc, item['size']) * item['multiplier']) + item['offset'] if ab2 is not None else None
589 | string = string + "%s%-48s%-44s\t%s%s\t%-16s%-16s\tMin: %0.1f\tMax: %0.1f\n" %(
590 | "%-3s - " % item['index'] if DEBUG else "",
591 | item['name'],
592 | ab1.mask_string(bitloc, bitloc + item['size']),
593 | "%04X" % byte1,
594 | " vs %04X" % byte2 if byte2 is not None else "",
595 | "%0.1f %s%s" % (value1, item['unit'] if item['unit'] != 'unitless' else "", " (%0.1f cm)" % (value1 * 2.54) if item['unit'] == "In" else ""),
596 | " vs %0.1f %s%s" % (value2, item['unit'] if item['unit'] != 'unitless' else "", " (%0.1f cm)" % (value2 * 2.54) if item['unit'] == "In" else "") if value2 is not None else "",
597 | item['min'],
598 | item['max']
599 | )
600 | elif item['type'] == 'mask':
601 | # bitmask typebit = 7 - item['bit']
602 | string = string + "%s%-s: %s %s %s %s\n" % (
603 | "%-4s- %-3s - %-3s\t " % (item['index'], item['size'], bitloc) if DEBUG else "",
604 | item['name'],
605 | "." * (78 - len(item['name'])),
606 | ab1.mask_string(bitloc, bitloc + item['size']),
607 | bitmask,
608 | "%02X" % byte1 if ab2 is None else " %02X %02X" % (byte1, byte2)
609 | #"vs %02X & %02X = %02X" % (value2, mask, value2 & mask) if value2 is not None else ""
610 | )
611 | # for now assume enable // disable if one bit or multi bit strategy
612 | for x in range(0, item['items']):
613 | string = string + "%s %2s %2s %s:\t%s\n" % ("\t\t" if DEBUG else "",
614 | ">>" if ab2 is None and x == value1 else "1>" if x == value1 else "",
615 | "2>" if ab2 is not None and x == value2 else "",
616 | "%02X" % (x << (((7 - item['bit']) - (item['size'] - 1)) % 8)),
617 | "" if '%d' % x not in item else item['%d' % x]
618 | )
619 | elif item['type'] == 'ascii':
620 | letterstring = " %02X: %s %s" % (value1, chr(value1), "vs %02X: %s" % (value2, chr(value2)) if value2 is not None else "")
621 | string = string + "%s%-s: %s %s %s\n" % ("%-4s- %-3s - %-3s\t " % (item['index'], item['size'], bitloc) if DEBUG else "",
622 | item['name'],
623 | letterstring + "." * (78 - len(item['name']) - len(letterstring)),
624 | ab1.mask_string(bitloc, bitloc + item['size']),
625 | "vs %02X & %02X = %02X" % (value2, mask, value2 & mask) if value2 is not None else ""
626 | )
627 | elif item['type'] == 'table':
628 | string = string + "%s%-s: %s %s %s %s\n" % ("%-4s- %-3s - %-3s\t " % (item['index'], item['size'], bitloc) if DEBUG else "",
629 | item['name'],
630 | "." * (78 - len(item['name'])),
631 | ab1.mask_string(bitloc, bitloc + item['size']),
632 | bitmask,
633 | "%02X" % byte1 if ab2 is None else " %02X %02X" % (byte1, byte2)
634 | #"vs %02X & %02X = %02X" % (value2, mask, value2 & mask) if value2 is not None else ""
635 | )
636 | # for now assume enable // disable if one bit or multi bit strategy
637 | table = JumpTables.table(item['table'])
638 | for x in range(0, len(table)):
639 | string = string + "%s %2s %2s %s:\t%s\n" % ("\t\t" if DEBUG else "",
640 | ">>" if ab2 is None and x == value1 else "1>" if x == value1 else "",
641 | "2>" if ab2 is not None and x == value2 else "",
642 | "%02X" % x,
643 | "" if len(table) < x not in item else table[x]
644 | )
645 | # table type
646 | pass
647 | except Exception as e:
648 | print(block)
649 | raise e
650 | return string + "\n"
651 |
652 |
653 | def print_bits_known_de07_08():
654 | de7 = [0] * (10*8)
655 | de8 = [0] * (20*8)
656 |
657 | for i in Fields.de07:
658 | if i['size'] == 1:
659 | de7[(i['byte'] * 8) + i['bit']] = 1
660 | else:
661 | x = (i['byte'] * 8) + i['bit']
662 | de7 = de7[:x] + [1] * i['size'] + de7[x+i['size']:]
663 | c = 0
664 | print("Known bits in DE07 // 7D0-08-xx")
665 | for x in de7:
666 | if c % 8 == 0 and c > 0:
667 | print(" ", end="")
668 | if c % 40 == 0 and c > 0:
669 | print("")
670 | print("%d"%x, end="")
671 | c += 1
672 | print("")
673 |
674 | print("Known bits in DE08 // 7D0-09-xx")
675 | for i in Fields.de08:
676 | if i['size'] == 1:
677 | loc = ((i['byte']) * 8) + i['bit']
678 | if de8[loc] == 1:
679 | print("duplicate: ", i['index'])
680 | de8[loc] = 1
681 | else:
682 | x = ((i['byte']) * 8) + i['bit']
683 | if de8[x] == 1:
684 | print("duplicate: %d", i['index'])
685 | de8 = de8[:x] + [1] * i['size'] + de8[x+i['size']:]
686 | c = 0
687 | for x in de8:
688 | if c % 8 == 0 and c > 0:
689 | print(" ", end="")
690 | if c % 40 == 0 and c > 0:
691 | print("")
692 | print("%d"%x, end="")
693 | c += 1
694 | print("")
695 |
696 | def print_duplicates():
697 | indexes = []
698 | for i in range(1, 10):
699 | block = Fields.block(i)
700 | for item in block:
701 | if item['index'] in indexes:
702 | print("Duplicate: %d" % item['index'])
703 | else:
704 | indexes.append(item['index'])
705 | indexes = []
706 | for i in range(1, 11):
707 | block = Fields_s4.block(i)
708 | for item in block:
709 | if item['index'] in indexes:
710 | print("Duplicate: %d" % item['index'])
711 | else:
712 | indexes.append(item['index'])
713 |
--------------------------------------------------------------------------------
/web/Dockerfile:
--------------------------------------------------------------------------------
1 | # Use the standard Nginx image from Docker Hub
2 | FROM nginx
3 |
4 | RUN apt-get update -y
5 |
6 | # install python, uwsgi, and supervisord
7 | RUN apt-get install -y supervisor uwsgi python3 python3-pip procps nano libgl1-mesa-glx libglib2.0-0
8 | RUN /usr/bin/pip3 install uwsgi flask
9 |
10 | # Copy up cli side of the app
11 | COPY ./src/ /app
12 |
13 | # Apim specific
14 | RUN /usr/bin/pip3 install PyQt5 sip
15 |
16 | # Source code file
17 | COPY ./web/ /webapp
18 | COPY ./web/node_modules/@forevolve/bootstrap-dark/dist /webapp/public/bootstrap
19 |
20 | # Copy the configuration file from the current directory and paste
21 | # it inside the container to use it as Nginx's default config.
22 | COPY ./web/docker/nginx.conf /etc/nginx/nginx.conf
23 |
24 | # setup NGINX config
25 | RUN mkdir -p /spool/nginx /run/pid && \
26 | chmod -R 777 /var/log/nginx /var/cache/nginx /etc/nginx /var/run /run /run/pid /spool/nginx && \
27 | chgrp -R 0 /var/log/nginx /var/cache/nginx /etc/nginx /var/run /run /run/pid /spool/nginx && \
28 | chmod -R g+rwX /var/log/nginx /var/cache/nginx /etc/nginx /var/run /run /run/pid /spool/nginx && \
29 | rm /etc/nginx/conf.d/default.conf
30 |
31 | # Copy the base uWSGI ini file to enable default dynamic uwsgi process number
32 | COPY ./web/docker/uwsgi.ini /etc/uwsgi/apps-available/uwsgi.ini
33 | RUN ln -s /etc/uwsgi/apps-available/uwsgi.ini /etc/uwsgi/apps-enabled/uwsgi.ini
34 |
35 | COPY ./web/docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
36 | RUN touch /var/log/supervisor/supervisord.log
37 |
38 | EXPOSE 8000:8000
39 |
40 | # setup entrypoint
41 | COPY ./web/docker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
42 |
43 | # https://github.com/moby/moby/issues/31243#issuecomment-406879017
44 | #RUN ln -s /usr/local/bin/docker-entrypoint.sh / && \
45 | RUN chmod 777 /usr/local/bin/docker-entrypoint.sh && \
46 | chgrp -R 0 /usr/local/bin/docker-entrypoint.sh && \
47 | chown -R nginx:root /usr/local/bin/docker-entrypoint.sh
48 |
49 | # https://docs.openshift.com/container-platform/3.3/creating_images/guidelines.html
50 | RUN chgrp -R 0 /var/log /var/cache /run/pid /spool/nginx /var/run /run /tmp /etc/uwsgi /etc/nginx && \
51 | chmod -R g+rwX /var/log /var/cache /run/pid /spool/nginx /var/run /run /tmp /etc/uwsgi /etc/nginx && \
52 | chown -R nginx:root /webapp && \
53 | chmod -R 777 /webapp /etc/passwd
54 |
55 | # enter
56 | WORKDIR /webapp
57 | ENTRYPOINT ["docker-entrypoint.sh"]
58 | CMD ["supervisord"]
59 |
--------------------------------------------------------------------------------
/web/api/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cyanlabs/apim-asbuilt-decode/4c8ba509b4e51ee5520a43094fc26c468289b998/web/api/__init__.py
--------------------------------------------------------------------------------
/web/api/wsgi.py:
--------------------------------------------------------------------------------
1 | from flask import Flask, request, jsonify, flash, redirect, url_for
2 | from werkzeug.utils import secure_filename
3 | import json
4 | import time
5 |
6 | import os
7 | import sys
8 | sys.path.append('/app')
9 |
10 | import re
11 |
12 | # local imports
13 | from asbuilt import AsBuilt
14 | from encoder import print_bits_known_de07_08, ItemEncoder, print_duplicates
15 | from statics import JumpTables, Fields
16 |
17 | UPLOAD_FOLDER = '/tmp'
18 | ALLOWED_EXTENSIONS = {'xml', 'ab', 'abt'}
19 |
20 | app = Flask(__name__)
21 | app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
22 |
23 | @app.after_request
24 | def add_security_headers(resp):
25 | resp.headers['Access-Control-Allow-Origin']='https://cyanlabs.net'
26 | return resp
27 |
28 | @app.route('/')
29 | def index():
30 | return 'OK'
31 |
32 | def allowed_file(filename):
33 | return '.' in filename and \
34 | filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
35 |
36 | @app.route('/upload', methods=['POST'])
37 | def upload_file():
38 | if request.method == 'POST':
39 | # check if the post request has the file part
40 | if 'file' not in request.files:
41 | return jsonify({
42 | 'status': 'ERR',
43 | 'message': 'Upload interrupted'
44 | })
45 | file = request.files['file']
46 | # if user does not select file, browser also
47 | # submit an empty part without filename
48 | if file.filename == '':
49 | return jsonify({
50 | 'status': 'ERR',
51 | 'message': 'No file uploaded'
52 | })
53 | if file and allowed_file(file.filename):
54 | filename = secure_filename(file.filename)
55 | file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
56 | return jsonify({
57 | 'status': 'OK',
58 | 'filename': filename
59 | })
60 |
61 | # If we end up here, go back home
62 | return jsonify({
63 | 'status': 'ERR',
64 | 'message': 'General Error'
65 | })
66 |
67 | @app.route('/post-xml', methods=['POST'])
68 | def post_xml():
69 | if request.method == 'POST':
70 | filename = secure_filename(str(int(time.time())) + '.xml')
71 |
72 | # Save to file
73 | text_file = open(os.path.join(app.config['UPLOAD_FOLDER'], filename), "w")
74 | text_file.write(request.form.get('xml'))
75 | text_file.close()
76 |
77 | return jsonify({
78 | 'status': 'OK',
79 | 'filename': filename
80 | })
81 |
82 | # If we end up here, go back home
83 | return jsonify({
84 | 'status': 'ERR',
85 | 'message': 'General Error'
86 | })
87 |
88 | @app.route('/process')
89 | def process():
90 |
91 | file = os.path.join(app.config['UPLOAD_FOLDER'], request.args.get('filename'))
92 |
93 | if os.path.isfile(file) == False:
94 | return jsonify({
95 | 'status': 'ERR',
96 | 'message': 'File not found'
97 | })
98 |
99 | asbuilt1 = AsBuilt(file)
100 | item_encoder = ItemEncoder(asbuilt1)
101 |
102 | output = []
103 | for block in range(1, len(asbuilt1.blocks) + 1):
104 | block_section = {
105 | 'block': block,
106 | 'name': '',
107 | 'values': []
108 | }
109 |
110 | result = item_encoder.format(block, asbuilt1, None)
111 |
112 | parsed_section = {
113 | 'name': '',
114 | 'values': []
115 | }
116 | for line in result.split('\n'):
117 | # Skip if line starts with "Block"
118 | line_regex = re.search("^Block ([0-9]+)", line)
119 | if line_regex is not None:
120 | block_section['name'] = line
121 | continue
122 |
123 | # Process option heading
124 | regex = r"^(.{80}) (.{9}) (.{12}) (.{8}) (.+)$"
125 | for match_num, match in enumerate(re.finditer(regex, line, re.MULTILINE), start=1):
126 | # print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group(1)}")
127 | if match.group(1)[0] == '#': continue
128 | if parsed_section['name']: block_section['values'].append(parsed_section)
129 | parsed_section = {
130 | 'name': match.group(1).replace('.', '').replace(': ', ''),
131 | 'values': []
132 | }
133 | continue
134 |
135 | # Process option values
136 | regex = r"^(.{11})([0-9]+):\s(.*?)$"
137 | for match_num, match in enumerate(re.finditer(regex, line, re.MULTILINE), start=1):
138 | # print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group(1)}")
139 | selected = False
140 | if match.group(1).strip() == '>>':
141 | selected = True
142 | parsed_section['values'].append({
143 | 'selected': selected,
144 | 'code': match.group(2),
145 | 'text': match.group(3)
146 | })
147 |
148 | output.append(block_section)
149 |
150 | return jsonify({
151 | 'status': 'OK',
152 | 'data': output
153 | })
154 |
155 | if __name__ == '__main__':
156 | app.run(
157 | debug=True,
158 | host='0.0.0.0',
159 | port=8001
160 | )
161 |
--------------------------------------------------------------------------------
/web/docker/docker-entrypoint.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -e
3 |
4 | # http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
5 | # if the running user is an Arbitrary User ID
6 | if ! whoami &> /dev/null; then
7 | # make sure we have read/write access to /etc/passwd
8 | if [ -w /etc/passwd ]; then
9 | # write a line in /etc/passwd for the Arbitrary User ID in the 'root' group
10 | echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:${HOME}:/sbin/nologin" >> /etc/passwd
11 | fi
12 | fi
13 |
14 | # https://success.docker.com/article/use-a-script-to-initialize-stateful-container-data
15 | if [ "$1" = 'supervisord' ]; then
16 | exec /usr/bin/supervisord
17 | fi
18 |
19 |
20 | exec "$@"
21 |
--------------------------------------------------------------------------------
/web/docker/nginx.conf:
--------------------------------------------------------------------------------
1 | pid /run/nginx.pid;
2 | error_log /var/log/nginx/error.log;
3 |
4 | events {
5 | worker_connections 1024;
6 | }
7 |
8 | http {
9 | include /etc/nginx/mime.types;
10 | default_type application/octet-stream;
11 | sendfile on;
12 | tcp_nopush on;
13 |
14 | client_body_temp_path /spool/nginx/client_temp 1 2;
15 | fastcgi_temp_path /spool/nginx/fastcgi_temp 1 2;
16 | proxy_temp_path /spool/nginx/proxy_temp 1 2;
17 | scgi_temp_path /spool/nginx/scgi_temp 1 2;
18 | uwsgi_temp_path /spool/nginx/uwsgi_temp 1 2;
19 |
20 | server {
21 | listen 8000;
22 | server_name localhost;
23 |
24 | access_log /var/log/nginx/access.log;
25 |
26 | location / {
27 | # try_files $uri @app;
28 | root /webapp/public;
29 | }
30 | location /api {
31 | rewrite /api/(.*) /$1 break;
32 | include uwsgi_params;
33 | uwsgi_pass unix:///run/uwsgi.sock;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/web/docker/supervisord.conf:
--------------------------------------------------------------------------------
1 | [unix_http_server]
2 | file=/run/supervisor.sock
3 | chmod=0770
4 |
5 | [supervisord]
6 | nodaemon=true
7 | pidfile=/run/pid/supervisord.pid
8 | logfile=/var/log/supervisor/supervisord.log
9 | childlogdir=/var/log/supervisor
10 | logfile_maxbytes=50MB
11 | logfile_backups=1
12 |
13 | [rpcinterface:supervisor]
14 | supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
15 |
16 | [supervisorctl]
17 | serverurl=unix:///run/supervisor.sock
18 |
19 | [program:nginx]
20 | command=/usr/sbin/nginx -g "daemon off;" -c /etc/nginx/nginx.conf
21 | stdout_logfile=/dev/stdout
22 | stdout_logfile_maxbytes=0
23 | stderr_logfile=/dev/stderr
24 | stderr_logfile_maxbytes=0
25 |
26 | [program:uwsgi]
27 | command=/usr/local/bin/uwsgi --ini /etc/uwsgi/apps-enabled/uwsgi.ini
28 | stdout_logfile=/dev/stdout
29 | stdout_logfile_maxbytes=0
30 | stderr_logfile=/dev/stderr
31 | stderr_logfile_maxbytes=0
32 |
--------------------------------------------------------------------------------
/web/docker/uwsgi.ini:
--------------------------------------------------------------------------------
1 | [uwsgi]
2 | chdir=/webapp/api
3 | chdir2=/webapp/api
4 | master = true
5 |
6 | module=wsgi
7 | callable=app
8 | buffer-size=65535
9 | lazy=true
10 |
11 | socket = /run/uwsgi.sock
12 | chown-socket = nginx:nginx
13 | chmod-socket = 664
14 | cheaper = 2
15 | processes = 16
16 |
17 | py-autoreload = 1
18 |
--------------------------------------------------------------------------------
/web/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "requires": true,
3 | "lockfileVersion": 1,
4 | "dependencies": {
5 | "@forevolve/bootstrap-dark": {
6 | "version": "1.0.0-alpha.1091",
7 | "resolved": "https://registry.npmjs.org/@forevolve/bootstrap-dark/-/bootstrap-dark-1.0.0-alpha.1091.tgz",
8 | "integrity": "sha512-nclqiPd77TfSPfHfA/rTfJrsH2vpwybnCIOotw7iU7Nb43JzroQqBDHnTev6N64lS5lgNLqwoVe43DlX3n0fbQ==",
9 | "requires": {
10 | "bootstrap": "^4.5.0",
11 | "jquery": "^3.5.1",
12 | "popper.js": "^1.16.1"
13 | }
14 | },
15 | "bootstrap": {
16 | "version": "4.5.3",
17 | "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.5.3.tgz",
18 | "integrity": "sha512-o9ppKQioXGqhw8Z7mah6KdTYpNQY//tipnkxppWhPbiSWdD+1raYsnhwEZjkTHYbGee4cVQ0Rx65EhOY/HNLcQ=="
19 | },
20 | "jquery": {
21 | "version": "3.5.1",
22 | "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.5.1.tgz",
23 | "integrity": "sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg=="
24 | },
25 | "popper.js": {
26 | "version": "1.16.1",
27 | "resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.16.1.tgz",
28 | "integrity": "sha512-Wb4p1J4zyFTbM+u6WuO4XstYx4Ky9Cewe4DWrel7B0w6VVICvPwdOpotjzcf6eD8TsckVnIMNONQyPIUFOUbCQ=="
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/web/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "apim-asbuilt-decode-web",
3 | "version": "1.0.0",
4 | "dependencies": {
5 | "@forevolve/bootstrap-dark": "^1.0.0-alpha.1091",
6 | "bootstrap": "4.5.3",
7 | "jquery": "3.5.1",
8 | "popper.js": "1.16.1"
9 | },
10 | "author": "Jiminald"
11 | }
12 |
--------------------------------------------------------------------------------
/web/public/app.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding-top: 5rem;
3 | }
4 |
5 | div.raw_output {
6 | background-color: #eee;
7 | border: 1px solid #999;
8 | display: block;
9 | padding: 20px;
10 | }
11 |
12 | body.bootstrap-dark div.raw_output {
13 | color: #4e4e4e;
14 | }
15 |
--------------------------------------------------------------------------------
/web/public/app.js:
--------------------------------------------------------------------------------
1 | var files;
2 | var local_storage_available = false;
3 | let searchParams = new URLSearchParams(window.location.search)
4 |
5 | // Detect local storage
6 | if (typeof(Storage) !== "undefined") {
7 | local_storage_available = true;
8 | }
9 |
10 | $(document).ready(function() {
11 | // Theme toggle
12 | $('#theme-switch').on('change', toggle_theme);
13 | if (localStorage.getItem('theme') == 'dark') {
14 | $('#theme-switch').prop('checked', true).trigger('change');
15 | } // End of if "Do we want a dark theme"
16 |
17 | // Do we have a file to process
18 | if (searchParams.has('filename') == true) {
19 | process_file(searchParams.get('filename'));
20 | } // End of if "Checking file param"
21 |
22 | // Upload
23 | $('input[type=file]').on('change', prepare_upload);
24 | bsCustomFileInput.init();
25 |
26 | $('#upload').on('submit', function(event) {
27 | event.preventDefault();
28 | upload_file();
29 | });
30 | });
31 |
32 | function toggle_theme() {
33 | if ($('body').hasClass('bootstrap-dark') == true) {
34 | $('body').removeClass('bootstrap-dark').addClass('bootstrap');
35 | localStorage.setItem('theme', 'light');
36 | } else {
37 | $('body').removeClass('bootstrap').addClass('bootstrap-dark');
38 | localStorage.setItem('theme', 'dark');
39 | }
40 | } // End of function "toggle_theme"
41 |
42 | // Upload and process //
43 |
44 | function prepare_upload(event) {
45 | files = event.target.files;
46 | } // End of function "prepare_upload"
47 |
48 | function upload_file() {
49 | var fd = new FormData();
50 | var files = $('#customFile')[0].files;
51 | fd.append('file', files[0]);
52 |
53 | $.ajax({
54 | url: '/api/upload',
55 | type: 'POST',
56 | data: fd,
57 | cache: false,
58 | dataType: 'json',
59 | processData: false, // Don't process the files
60 | contentType: false, // Set content type to false as jQuery will tell the server its a query string request
61 | }).done(function(data, textStatus, jqXHR) {
62 | if (data.status == 'OK') {
63 | process_file(data.filename);
64 | } else {
65 | Swal.fire({
66 | icon: 'error',
67 | title: 'Oops...',
68 | text: data.message,
69 | });
70 | } // End of if "Do we have a valid response"
71 | }).fail(function(jqXHR, textStatus, errorThrown) {
72 | Swal.fire({
73 | icon: 'error',
74 | title: 'Oops...',
75 | text: errorThrown,
76 | });
77 | });
78 | } // End of function "upload_file"
79 |
80 | function process_file(filename) {
81 | $.ajax({
82 | url: '/api/process',
83 | data: {
84 | 'filename': filename
85 | },
86 | dataType: 'json',
87 | }).done(function(response_data, textStatus, jqXHR) {
88 | if (response_data.status == 'OK') {
89 | var data = response_data.data;
90 |
91 | // Cleanup
92 | $('#output').addClass('d-none');
93 | $('#tabs').html('');
94 | $('#tab-content').html('');
95 |
96 | // Loop blocks
97 | $.each(data, function(i) {
98 | var block = data[i];
99 | $('#tabs').append('