<commit_before>package com.ericsson.auto.remote.vehicleentry;

import android.util.Base64;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * Created by stoffe on 6/8/15.
 */
public abstract class RviConnection  {
    public abstract InputStream getInputStream() throws IOException;
    public abstract OutputStream getOutputStream() throws IOException;


    //                     String output = "{\"tid\":1,\"cmd\":\"authorize\",\"addr\":"+
    //                            "\"00:1B:DC:06:7D:66\",\"chan\":1,\"rvi_proto\":"+
    //                            "\"rvi_json\",\"certificate\":\"\",\"signature\":\"\"}";
//    public static JSONObject createBtAuth(int tid, String addr, int ch, String cert, String sig) throws JSONException {
//        JSONObject auth = new JSONObject();
//        auth.put("tid", tid);
//        auth.put("cmd", "authorize");
//        auth.put("addr", addr);
//        auth.put("chan", ch);
//        auth.put("rvi_proto", "rvi_json");
//        auth.put("certificate", cert);
//        auth.put("signature", sig);
//        return auth;
//    }

    //{"tid":1,"cmd":"au","addr":"127.0.0.1","port":8807,"ver":"1.0","cert":"","sign":"" }
    public static JSONObject createAuth(int tid, String addr, int port, String cert, String sig) throws JSONException {
        JSONObject auth = new JSONObject();
        auth.put("tid", tid);
        auth.put("cmd", "au");
        auth.put("addr", addr);
        auth.put("port", port);
        auth.put("ver", "1.0");
        auth.put("certificate", cert);
        auth.put("signature", sig);
        return auth;
    }

    public static JSONObject createReceiveData(int tid, String service, JSONArray params, String cert, String sig) throws JSONException {
        JSONObject payload = new JSONObject();
        payload.put("service", service);
        payload.put("timeout", 1433266704); //TODO
        payload.put("parameters", params);
        payload.put("certificate", cert);
        payload.put("signature", sig);

        JSONObject rcvData = new JSONObject();
        rcvData.put("tid", tid);
        rcvData.put("cmd", "receive_data");

        rcvData.put("proto_mod", "proto_json_rpc");
        String enc = Base64.encodeToString(payload.toString().getBytes(), 0);
        rcvData.put("payload", enc);

        Log.d("STOFFE", "sa : " + rcvData.toString());
        return rcvData;
    }
}<commit_msg>Updated and validated with 0.0.3 release of PI<commit_after>package com.ericsson.auto.remote.vehicleentry;

import android.util.Base64;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * Created by stoffe on 6/8/15.
 */
public abstract class RviConnection  {
    public abstract InputStream getInputStream() throws IOException;
    public abstract OutputStream getOutputStream() throws IOException;


    //                     String output = "{\"tid\":1,\"cmd\":\"authorize\",\"addr\":"+
    //                            "\"00:1B:DC:06:7D:66\",\"chan\":1,\"rvi_proto\":"+
    //                            "\"rvi_json\",\"certificate\":\"\",\"signature\":\"\"}";
//    public static JSONObject createBtAuth(int tid, String addr, int ch, String cert, String sig) throws JSONException {
//        JSONObject auth = new JSONObject();
//        auth.put("tid", tid);
//        auth.put("cmd", "authorize");
//        auth.put("addr", addr);
//        auth.put("chan", ch);
//        auth.put("rvi_proto", "rvi_json");
//        auth.put("certificate", cert);
//        auth.put("signature", sig);
//        return auth;
//    }

    //{"tid":1,"cmd":"au","addr":"127.0.0.1","port":8807,"ver":"1.0","cert":"","sign":"" }
    public static JSONObject createAuth(int tid, String addr, int port, String cert, String sig) throws JSONException {
        JSONObject auth = new JSONObject();
        auth.put("tid", tid);
        auth.put("cmd", "au");
        auth.put("addr", addr);
        auth.put("port", port);
        auth.put("ver", "1.0");
        auth.put("certificate", cert);
        auth.put("signature", sig);
        return auth;
    }

    //{"tid":1,"cmd":"rcv","mod":"proto_json_rpc","data":"<KEY>
    //<KEY>
    //<KEY>}
    //
    // Decoded
    // {"service":"jlr.com/bt/stoffe/lock","timeout":1434053259000,"parameters":[{"a":"b"}],"signature":"signature","certificate":"certificate"}

    public static JSONObject createReceiveData(int tid, String service, JSONArray params, String cert, String sig) throws JSONException {
        JSONObject payload = new JSONObject();
        payload.put("service", service);
        payload.put("timeout", 1433266704); //TODO
        payload.put("parameters", params);
        payload.put("certificate", cert);
        payload.put("signature", sig);

        JSONObject rcvData = new JSONObject();
        rcvData.put("tid", tid);
        rcvData.put("cmd", "rcv");

        rcvData.put("mod", "proto_json_rpc");
        String enc = Base64.encodeToString(payload.toString().getBytes(), 0);
        rcvData.put("data", enc);

        Log.d("STOFFE", "sa : " + rcvData.toString());
        return rcvData;
    }
}
{'fraction_non_alphanumeric': 0.18120805369127516, 'fraction_numerical': 0.019574944071588368, 'mean_word_length': 2.7025534851621806, 'pattern_counts': {'":': 38, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '535399', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1595, 'n_words': 344}