Home Code Example
Code Example
PDF Print

The following examples show handshake and ac_charging snippets of the OpenV2G project.

A simple demo which shows the request - response interaction between PEV and EVSE can be found in the file main_example.c located in src/test of the OpenV2G source folder.

 

static int appHandshake()
{
    bitstream_t stream1;
    bitstream_t stream2;

    uint16_t payloadLengthDec;
    uint16_t pos1 = V2GTP_HEADER_LENGTH; /* v2gtp header */
    uint16_t pos2;

    struct appHandEXIDocument handshake;
    struct appHandEXIDocument handshakeResp;

    int errn = 0;

    char* ns0 = "urn:iso:15118:2:2010:MsgDef";
    char* ns1 = "urn:din:70121:2012:MsgDef";

    stream1.size = BUFFER_SIZE;
    stream1.data = buffer1;
    stream1.pos = &pos1;

    stream2.size = BUFFER_SIZE;
    stream2.data = buffer2;
    stream2.pos = &pos2;

    init_appHandEXIDocument(&handshake);

    printf("EV side: setup data for the supported application handshake request message\n");

    /* set up ISO/IEC 15118 Version 1.0 information */
    handshake.supportedAppProtocolReq_isUsed = 1u;    
/* we have only two protocols implemented */
  handshake.supportedAppProtocolReq.AppProtocol.arrayLen = 2; handshake.supportedAppProtocolReq.AppProtocol.array[0].ProtocolNamespace.charactersLen = writeStringToEXIString(ns0, handshake.supportedAppProtocolReq.AppProtocol.array[0].
ProtocolNamespace
.characters); handshake.supportedAppProtocolReq.AppProtocol.array[0].SchemaID = 1; handshake.supportedAppProtocolReq.AppProtocol.array[0].VersionNumberMajor = 1; handshake.supportedAppProtocolReq.AppProtocol.array[0].VersionNumberMinor = 0; handshake.supportedAppProtocolReq.AppProtocol.array[0].Priority = 1; handshake.supportedAppProtocolReq.AppProtocol.array[1].ProtocolNamespace.charactersLen = writeStringToEXIString(ns1, handshake.supportedAppProtocolReq.AppProtocol.array[1].
ProtocolNamespace
.characters); handshake.supportedAppProtocolReq.AppProtocol.array[1].SchemaID = 2; handshake.supportedAppProtocolReq.AppProtocol.array[1].VersionNumberMajor = 1; handshake.supportedAppProtocolReq.AppProtocol.array[1].VersionNumberMinor = 0; handshake.supportedAppProtocolReq.AppProtocol.array[1].Priority = 2; /* send app handshake request */ if( (errn = encode_appHandExiDocument(&stream1, &handshake)) == 0) { if ( write_v2gtpHeader(stream1.data, pos1-V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE) == 0 ) { printf("EV side: send message to the EVSE\n"); } } ... } static int ac_charging() { int errn = 0; int i, j; struct v2gEXIDocument exiIn; struct v2gEXIDocument exiOut; struct v2gServiceDiscoveryResType serviceDiscoveryRes; struct v2gServiceDetailResType serviceDetailRes; struct v2gPaymentServiceSelectionResType paymentServiceSelectionRes; struct v2gPaymentDetailsResType paymentDetailsRes; /* setup header information */ init_v2gEXIDocument(&exiIn); exiIn.V2G_Message_isUsed = 1u; init_v2gMessageHeaderType(&exiIn.V2G_Message.Header);
/* sessionID is always '0' at the beginning (the response contains the valid sessionID)*/
  exiIn.V2G_Message.Header.SessionID.bytes[0] = 0; exiIn.V2G_Message.Header.SessionID.bytes[1] = 0; exiIn.V2G_Message.Header.SessionID.bytes[2] = 0; exiIn.V2G_Message.Header.SessionID.bytes[3] = 0; exiIn.V2G_Message.Header.SessionID.bytes[4] = 0; exiIn.V2G_Message.Header.SessionID.bytes[5] = 0; exiIn.V2G_Message.Header.SessionID.bytes[6] = 0; exiIn.V2G_Message.Header.SessionID.bytes[7] = 0;
/* length of the byte session array is always 8*/
 exiIn.V2G_Message.Header.SessionID.bytesLen = 8;
/* no notification */ exiIn.V2G_Message.Header.Notification_isUsed = 0u; exiIn.V2G_Message.Header.Signature_isUsed = 0u; /************************ * sessionSetup * ************************/ init_v2gBodyType(&exiIn.V2G_Message.Body); exiIn.V2G_Message.Body.SessionSetupReq_isUsed = 1u; init_v2gSessionSetupReqType(&exiIn.V2G_Message.Body.SessionSetupReq); exiIn.V2G_Message.Body.SessionSetupReq.EVCCID.bytesLen = 1; exiIn.V2G_Message.Body.SessionSetupReq.EVCCID.bytes[0] = 10; printf("EV side: call EVSE sessionSetup"); errn = request_response(&exiIn, &exiOut); ... }
 
 

Initiated by

 

Co-Initiated by

 

Supported by