From 862780607857cf3b658c4815c50aaa5497ea43e2 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Thu, 11 Oct 2012 18:36:28 +0200 Subject: [PATCH] added JSON read for EmuLink --- lib/JSON-SIMPLE-LICENSE | 202 +++++++++++++++++++++++++++ lib/json-simple-1.1.1.jar | Bin 0 -> 23737 bytes se/sics/mspsim/emulink/EmuLink.java | 207 ++++++++++++++++++++++++---- 3 files changed, 380 insertions(+), 29 deletions(-) create mode 100644 lib/JSON-SIMPLE-LICENSE create mode 100644 lib/json-simple-1.1.1.jar diff --git a/lib/JSON-SIMPLE-LICENSE b/lib/JSON-SIMPLE-LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/lib/JSON-SIMPLE-LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/lib/json-simple-1.1.1.jar b/lib/json-simple-1.1.1.jar new file mode 100644 index 0000000000000000000000000000000000000000..66347a6c86b7d6442358ca7643e4dc484fb01866 GIT binary patch literal 23737 zcmbTd1F-HrvM;=B+qSK}Y}>YNuf4pNZQHhO+qP}&yWg4l4(2;Eb z`gNz1$V&l(pa4Mp`E5EW@dNyqf&u^nAS0qIKr10DN-rZID~!`e@eToh5T$~(hjq7(B(IUFf+ zC?_{co=FHeKB!Ndsk3(5${O&V7 zFJ96YRa#9;oTUB9SfG6U`C5d_JDdtFtG&KQG+K58D#&cY#g zQ=?5h>)R%GY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#`-%UNqyZW!}>c5NO#|4$KYx6|%Nc>aAkIU!T_l$3@ihoKY zxhU=dw5tdE$Bgm&p*DFoNnJzkJ4NzP+=J#XvVU|`+|NaBEkjbG??H^==aKC5t=dmU zZtC(Q8Rp<`$oBO8`^m`d1NioawfoGC`PXFRt}y%A$hG(+%Yi-Uvj3XxCj)~0l;rZg zA7`t_@oP#lNk2K+{-sA!{O!T($j@Zo%N)o_NDG5p0!PyO?VfAh!EG?Y|YiPkg^{Y(FV^0m+Y}JudTG(qC1d?I$MR z4DNoUWI!wYmYA#>Wj`PJ9~@~5xrYO$f8ZnAP@3pd?f%kGP_U97ySIOW1?km)0Pd{B A{Qv*} literal 0 HcmV?d00001 diff --git a/se/sics/mspsim/emulink/EmuLink.java b/se/sics/mspsim/emulink/EmuLink.java index f6bda39..d125a5e 100755 --- a/se/sics/mspsim/emulink/EmuLink.java +++ b/se/sics/mspsim/emulink/EmuLink.java @@ -1,66 +1,215 @@ +/* + * Copyright (c) 2012, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * ----------------------------------------------------------------- + * + * EmuLink + * + * Authors : Joakim Eriksson, Niclas Finne + * Created : 11 oct 2012 + */ + package se.sics.mspsim.emulink; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; +import java.io.Reader; import java.net.ServerSocket; import java.net.Socket; +import se.sics.json.JSONArray; +import se.sics.json.JSONObject; +import se.sics.json.ParseException; public class EmuLink { - - PrintWriter out; - boolean close = false; + private Socket socket; + private BufferedReader in; + private PrintWriter out; + private boolean isConnected = false; - int mode; int json = 0; - StringBuffer buffer = new StringBuffer(); - - void processInput(int data) { - System.out.println("Data: " + data); - /* create JSON here */ + StringBuilder buffer = new StringBuilder(); + + public boolean isConnected() { + return !isConnected; + } + + protected void processInput(Reader input) throws IOException, ParseException { + StringBuilder sb = new StringBuilder(); + int brackets = 0; + boolean stuffed = false; + boolean quoted = false; + while (isConnected()) { + int c = input.read(); + if (c < 0) { + disconnect(); + break; + } + sb.append((char)c); + if (stuffed) { + stuffed = false; + } else if (c == '\\') { + stuffed = true; + } else if (quoted) { + if (c == '"') { + quoted = false; + } + } else if (c == '"') { + quoted = true; + } else if (c == '{') { + brackets++; + } else if (c == '}') { + brackets--; + if (brackets == 0) { + JSONObject json = JSONObject.parseJSONObject(sb.toString()); + sb.setLength(0); + if (!handleMessage(json)) { + // This connection should no longer be kept alive + break; + } + } + } + } }; - + + protected boolean handleMessage(JSONObject json) { + System.out.println("EmuLink: RECV " + json.toJSONString()); + String event = json.getAsString("event"); + if ("emulation_control".equals(event)) { + // TODO control emulation + sendToSimulator("{\"response\":\"emulation_control\",\"data\":1}"); + + if ("close".equals(json.getAsString("data"))) { + // Time to close the connection + return false; + } + } else if ("create".equals(event)) { + // TODO setup emulated node + sendToSimulator("{\"response\":\"create\",\"data\":1}"); + } else if ("serial".equals(event)) { + int data = json.getAsInt("data", -1); + JSONArray nodes; + String node; + if (data < 0) { + // No data - ignore serial event + } else if ((nodes = json.getJSONArray("node")) != null) { + for(int i = 0, n = nodes.size(); i < n; i++) { + node = nodes.getAsString(i); + if (node != null) { + sendSerialToNode(node, data); + } + } + } else if ((node = json.getAsString("node")) != null) { + sendSerialToNode(node, data); + } else { + // No target node specified + } + } else { + System.err.println("EmuLink: ignoring unhandled event '" + event + "'"); + } + return true; + } + + protected void sendToSimulator(String message) { + if (out != null) { + out.write(message); + out.flush(); + } + } + + protected void sendSerialToNode(String node, int data) { + } + + protected void disconnect() { + boolean wasConnected = isConnected; + isConnected = false; + try { + if (wasConnected) { + System.err.println("EmuLink: disconnecting..."); + } + if (out != null) { + out.close(); + out = null; + } + if (in != null) { + in.close(); + in = null; + } + if (socket != null) { + socket.close(); + socket = null; + } + if (wasConnected) { + System.err.println("EmuLink: disconnected"); + } + } catch (IOException e) { + System.err.println("EmuLink: failed to close emulation link connection"); + e.printStackTrace(); + } + } + public void run() throws IOException { try { - ServerSocket serverSocket = null; - serverSocket = new ServerSocket(8000); + ServerSocket serverSocket = new ServerSocket(8000); while(true) { System.out.println("EmuLink: Waiting for connection..."); - Socket socket = null; try { socket = serverSocket.accept(); - } - catch (IOException e) { + } catch (IOException e) { System.out.println("Accept failed: 8000"); System.exit(-1); } System.out.println("EmuLink: Connection accepted..."); - out = new PrintWriter(socket.getOutputStream(), true); - BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); - int c; - out.println("EmuLink - mspsim"); - while (!close && (c = in.read()) != -1) { - processInput(c); + try { + out = new PrintWriter(socket.getOutputStream(), true); + in = new BufferedReader(new InputStreamReader(socket.getInputStream())); + processInput(in); + } catch (Exception e) { + System.err.println("EmuLink: emulator link connection failed"); + e.printStackTrace(); + } finally { + disconnect(); } - - in.close(); - out.close(); - socket.close(); - close = false; } - } - catch (IOException e) { + } catch (IOException e) { System.out.println("Could not listen on port: 8000"); System.exit(-1); } } - + public static void main(String[] args) throws IOException { EmuLink el = new EmuLink(); el.run();