git-svn-id: https://svn.code.sf.net/p/openv2g/code/trunk@31 d9f2db14-54d0-4bde-b00c-16405c910529

This commit is contained in:
sebastiankb 2010-12-22 14:38:36 +00:00
parent 19d0d4c9b4
commit 138bdd4ae6
8 changed files with 0 additions and 714 deletions

View file

@ -1,42 +0,0 @@
/*
* Copyright (C) 2007-2010 Siemens AG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*******************************************************************
*
* @author Daniel.Peintner.EXT@siemens.com
* @author Sebastian.Kaebisch.EXT@siemens.com
* @version 0.3
* @contact Joerg.Heuer@siemens.com
*
* <p>Switch for sample programs: EXI codec only or for entire V2G service</p>
*
********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "main.h"
int main(int argc, char *argv[]) {
/* EXI codec only */
/*return main_codec(argc, argv);*/
/* V2G client / service example scenario */
return main_service(argc, argv);
}

View file

@ -1,34 +0,0 @@
/*
* Copyright (C) 2007-2010 Siemens AG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*******************************************************************
*
* @author Daniel.Peintner.EXT@siemens.com
* @author Sebastian.Kaebisch.EXT@siemens.com
* @version 0.3
* @contact Joerg.Heuer@siemens.com
*
*
********************************************************************/
#ifndef MAIN_H_
#define MAIN_H_
int main_codec(int argc, char *argv[]);
int main_service(int argc, char *argv[]);
#endif

View file

@ -1,231 +0,0 @@
/*
* Copyright (C) 2007-2010 Siemens AG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*******************************************************************
*
* @author Daniel.Peintner.EXT@siemens.com
* @version 0.3
* @contact Joerg.Heuer@siemens.com
*
* <p>Sample program to illustrate how to read an EXI stream and
* directly write it again to an output</p>
*
* <p>e.g., data/test/sessionSetupReq.xml.exi out/test/sessionSetupReq.xml.exi</p>
********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "EXIDecoder.h"
#include "StringTable.h"
#include "EXIEncoder.h"
#include "EXITypes.h"
#include "ByteStream.h"
#define BUFFER_SIZE 100
#define ARRAY_SIZE_BYTES 50
#define ARRAY_SIZE_STRINGS 50
/* avoids warning: initializer element is not computable at load time */
uint8_t bufferIn[BUFFER_SIZE];
uint8_t bufferOut[BUFFER_SIZE];
uint8_t data[ARRAY_SIZE_BYTES];
uint32_t codepoints[ARRAY_SIZE_STRINGS];
int main_codec(int argc, char *argv[]) {
int errn = 0;
unsigned int i;
bitstream_t iStream, oStream;
size_t posDecode;
size_t posEncode;
/* EXI set-up */
exi_state_t stateDecode;
exi_state_t stateEncode;
exi_event_t event;
eqname_t eqn;
exi_value_t val;
/* BINARY memory setup */
bytes_t bytes = { ARRAY_SIZE_BYTES, data, 0 };
/* STRING memory setuo */
string_ucs_t string = { ARRAY_SIZE_STRINGS, codepoints, 0 };
const char * localName;
const char * namespaceURI;
int noEndOfDocument = 1; /* true */
if (argc != 3) {
printf("Usage: %s exiInput exiOutput\n", argv[0]);
return -1;
}
/* input pos */
posDecode = 0;
/* parse EXI stream to internal byte structures */
readBytesFromFile(argv[1], bufferIn, BUFFER_SIZE, posDecode);
/* setup input stream */
iStream.size = BUFFER_SIZE;
iStream.data = bufferIn;
iStream.pos = &posDecode;
iStream.buffer = 0;
iStream.capacity = 0;
/* setup output stream */
posEncode = 0;
oStream.size = BUFFER_SIZE;
oStream.data = bufferOut;
oStream.pos = &posEncode;
oStream.buffer = 0;
oStream.capacity = 8;
val.binary = bytes;
val.string = string;
/* init decoder (read header, set initial state) */
exiInitDecoder(&iStream, &stateDecode);
/* init encoder (write header, set initial state) */
exiInitEncoder(&oStream, &stateEncode);
printf("[DECODE] >>> EXI >>> [ENCODE] \n");
do {
if (errn < 0) {
printf("[Encode-ERROR] %d \n", errn);
return errn;
}
errn = exiDecodeNextEvent(&iStream, &stateDecode, &event);
if (errn < 0) {
printf("[Decode-ERROR] %d \n", errn);
return errn;
}
switch (event) {
case START_DOCUMENT:
/* decode */
errn = exiDecodeStartDocument(&iStream, &stateDecode);
if (errn < 0) {
printf("[Decode-ERROR] %d \n", errn);
return errn;
}
printf(">> START_DOCUMENT \n");
/* encode */
errn = exiEncodeStartDocument(&oStream, &stateEncode);
break;
case END_DOCUMENT:
/* decode */
errn = exiDecodeEndDocument(&iStream, &stateDecode);
if (errn < 0) {
printf("[Decode-ERROR] %d \n", errn);
return errn;
}
printf(">> END_DOCUMENT \n");
/* encode */
errn = exiEncodeEndDocument(&oStream, &stateEncode);
/* signalize end of document */
noEndOfDocument = 0; /* false */
break;
case START_ELEMENT:
/* decode */
errn = exiDecodeStartElement(&iStream, &stateDecode, &eqn);
if (errn < 0) {
printf("[Decode-ERROR] %d \n", errn);
return errn;
}
exiGetLocalName(eqn.namespaceURI, eqn.localPart, &localName);
exiGetUri(eqn.namespaceURI, &namespaceURI);
printf(">> SE {%s}%s \n", namespaceURI, localName);
/* encode */
errn = exiEncodeStartElement(&oStream, &stateEncode, &eqn);
break;
case END_ELEMENT:
/* decode */
errn = exiDecodeEndElement(&iStream, &stateDecode, &eqn);
if (errn < 0) {
printf("[Decode-ERROR] %d \n", errn);
return errn;
}
exiGetLocalName(eqn.namespaceURI, eqn.localPart, &localName);
exiGetUri(eqn.namespaceURI, &namespaceURI);
printf("<< EE {%s}%s \n", namespaceURI, localName);
/* encode */
errn = exiEncodeEndElement(&oStream, &stateEncode, &eqn);
break;
case CHARACTERS:
/* decode */
errn = exiDecodeCharacters(&iStream, &stateDecode, &val);
if (errn < 0) {
printf("[Decode-ERROR] %d \n", errn);
return errn;
}
if (val.type == INTEGER_BIG) {
printf(" CH int64 : %lld \n", val.int64);
} else if (val.type == BINARY_BASE64 || val.type == BINARY_HEX) {
printf(" CH Binary (len == %d) : ", val.binary.len);
for(i=0; i<val.binary.len; i++) {
printf(" [%d]", val.binary.data[i]);
}
printf("\n");
} else if (val.type == BOOLEAN) {
printf(" CH Boolean : %d \n", val.boolean);
} else if (val.type == STRING) {
printf(" CH String (len==%d) : '", val.string.len);
for(i=0;i<val.string.len; i++) {
printf("%c", (char)val.string.codepoints[i]);
}
printf("'\n");
} else {
printf(" CH ?? \n");
}
/* encode */
errn = exiEncodeCharacters(&oStream, &stateEncode, &val);
break;
case ATTRIBUTE:
/* decode */
errn = exiDecodeAttribute(&iStream, &stateDecode, &eqn, &val);
if (errn < 0) {
printf("[Decode-ERROR] %d \n", errn);
return errn;
}
exiGetLocalName(eqn.namespaceURI, eqn.localPart, &localName);
exiGetUri(eqn.namespaceURI, &namespaceURI);
printf(" AT {%s}%s \n", namespaceURI, localName);
/* encode */
errn = exiEncodeAttribute(&oStream, &stateEncode, &eqn, &val);
break;
default:
/* ERROR */
return -1;
}
} while (noEndOfDocument);
/* write to file */
writeBytesToFile(oStream.data, iStream.size, argv[2]);
return 0;
}

View file

@ -1,142 +0,0 @@
/*
* Copyright (C) 2007-2010 Siemens AG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*******************************************************************
*
* @author Sebastian.Kaebisch.EXT@siemens.com
* @version 0.3
* @contact Joerg.Heuer@siemens.com
*
********************************************************************/
#include "v2g_service.h"
#include "v2g_serviceDataTypes.h"
#include "v2g_serviceClientStubs.h"
#include "EXITypes.h"
#include "doIP.h"
#include <stdio.h>
#define MAX_BYTE_SIZE 128
#define MAX_STRING_SIZE 256
#define MAX_STREAM_SIZE 60
static void printErrorMessage(struct v2gService* service);
int main_service(int argc, char *argv[])
{
static uint8_t byte_array[MAX_BYTE_SIZE]; /* define MAX_BYTE_SIZE before*/
static uint32_t string_array[MAX_STRING_SIZE]; /* define MAX_STRING_SIZE before*/
/* define in and out byte stream */
uint8_t inStream[MAX_STREAM_SIZE]; /* define MAX_STREAM_SIZE before */
uint8_t outStream[MAX_STREAM_SIZE]; /* define MAX_STREAM_SIZE before */
/* define offset variable for transport header data */
uint16_t transportHeaderOffset;
/* service data structure */
struct v2gService service;
struct HeaderType v2gHeader;
struct SessionSetupReqType sessionSetup;
struct SessionSetupResType resultSessionSetup;
/*struct PowerDiscoveryReqType powerDiscovery;
struct PowerDiscoveryResType resultPowerDiscovery; */
/* BINARY memory setup */
bytes_t bytes = { MAX_BYTE_SIZE, byte_array, 0 };
/* STRING memory setup */
string_ucs_t string = { MAX_STRING_SIZE, string_array, 0 };
/* setup offset for DoIP header (otherwise set
* transportHeaderOffset=0 if no transfer protocol is used)*/
transportHeaderOffset = DOIP_HEADER_LENGTH;
printf("+++Start V2G Client / Service Example+++\n\n");
/*******************
* Init V2G Client *
*******************/
init_v2gServiceClient(&service,bytes,string,inStream,MAX_STREAM_SIZE, outStream, MAX_STREAM_SIZE, transportHeaderOffset);
/*******************************
* Setup data for sessionSetup *
*******************************/
/* setup header information */
v2gHeader.SessionInformation.SessionID.arraylen.data = 0; /* no session id in the initial message -> array length = 0*/
v2gHeader.SessionInformation.ProtocolVersion.data[0]='1'; /* assign protocol version number*/
v2gHeader.SessionInformation.ProtocolVersion.arraylen.data=1; /* array string length =1 of protocol version */
v2gHeader.SessionInformation.isused.ProtocolVersion = 1; /* important: signalize, protocol version is used */
v2gHeader.isused.Notification=0; /* no notification */
/* setup sessionSetup parameter */
sessionSetup.isused.PEVID=1; /* no PEVID is transported */
sessionSetup.PEVStatus.ChargerStandby=1; /* charger standby = true */
sessionSetup.PEVStatus.ConnectorLocked=0; /* connector locked = false */
printf("PEV: call EVSE sessionSetup\n");
/*********************
* Call sessionSetup *
*********************/
if(call_sessionSetup(&service,&v2gHeader,&sessionSetup,&resultSessionSetup))
{
printErrorMessage(&service);
}
else
{
/* show result of the answer message of EVSE sessionSetup*/
printf("PEV: received response message from EVSE\n");
printf("\tResponseCode=%d\n",resultSessionSetup.ResponseCode);
printf("\tEVSEID=%d\n", resultSessionSetup.EVSEID.data[0]);
printf("\tEVSEStatus:\n\t\tConnectorLocked=%d\n",resultSessionSetup.EVSEStatus.ConnectorLocked);
printf("\t\tEVSEStandby=%d\n",resultSessionSetup.EVSEStatus.EVSEStandby);
printf("\t\tFatalError=%d\n",resultSessionSetup.EVSEStatus.FatalError);
printf("\t\tPowerSwitchClosed=%d\n",resultSessionSetup.EVSEStatus.PowerSwitchClosed);
printf("\t\tRCD=%d\n",resultSessionSetup.EVSEStatus.RCD);
printf("\t\tShutDownTime=%d\n",resultSessionSetup.EVSEStatus.ShutDownTime);
printf("\tTCurrent=%d\n",resultSessionSetup.TCurrent);
}
printf("\n+++Terminate V2G Client / Service Example+++");
return 0;
}
static void printErrorMessage(struct v2gService* service)
{
if(service->errorCode==V2G_NON_VALID_MESSAGE)
{
printf("PEV did not send a valid V2G message!\n");
}
else if(service->errorCode==V2G_SERIALIZATION_FAILED)
{
printf("EVSE error: Could not serialize the response message\n");
}
}

View file

@ -1,90 +0,0 @@
/*
* Copyright (C) 2007-2010 Siemens AG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*******************************************************************
*
* @author Sebastian.Kaebisch.EXT@siemens.com
* @version 0.3
* @contact Joerg.Heuer@siemens.com
*
********************************************************************/
#include "v2g_server.h"
#include "v2g_service.h"
#include "v2g_serviceDispatcher.h"
#include "doIP.h"
#define MAX_BYTE_SIZE 128
#define MAX_STRING_SIZE 256
#define MAX_STREAM_SIZE 60
int testV2GService(uint8_t* inStream, size_t inStreamLength, uint8_t* outStream, size_t* outStreamLength)
{
static uint8_t byte_array[MAX_BYTE_SIZE]; /* define MAX_BYTE_SIZE before*/
static uint32_t string_array[MAX_STRING_SIZE]; /* define MAX_STRING_SIZE before*/
size_t exiMsgLength;
struct v2gService service;
/* BINARY memory setup */
bytes_t bytes = { MAX_BYTE_SIZE, byte_array, 0 };
/* STRING memory setup */
string_ucs_t string = { MAX_STRING_SIZE, string_array, 0 };
/**********************************************
* Init V2G server and initialize array types *
* for the EXI decoding as well as the offset *
* for the transportation header *
**********************************************/
init_v2gservice(&service, bytes, string, DOIP_HEADER_LENGTH);
/* check, if the DoIP header is correct and determine payload */
if(read_doIPHeader(inStream,inStreamLength, &exiMsgLength))
{
/* DoIP header not correct */
write_doIPNack(outStream, outStreamLength, service.errorCode);
return -1;
}
/****************************************************************************
* Pass the received EXI message stream (inStream + exiMsgLength) to the *
* v2g message dispatcher. The outStream contains the response message *
* stream. *
****************************************************************************/
if(messageDispatcher(&service, inStream, exiMsgLength, outStream, MAX_STREAM_SIZE, outStreamLength))
{
/* write DoIP failure */
write_doIPNack(outStream, outStreamLength, service.errorCode);
}
else
{
/* write DoIP header */
write_doIPHeader(outStream, outStreamLength, DOIP_EXI_TYPE);
}
return 0;
}

View file

@ -1,33 +0,0 @@
/*
* Copyright (C) 2007-2010 Siemens AG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*******************************************************************
*
* @author Sebastian.Kaebisch.EXT@siemens.com
* @version 0.3
* @contact Joerg.Heuer@siemens.com
*
********************************************************************/
#ifndef V2G_SERVER_H_
#define V2G_SERVER_H_
#include "EXITypes.h"
int testV2GService(uint8_t* inStream, size_t inStreamLength, uint8_t* outStream,size_t* outStreamLength);
#endif /* V2G_SERVER_H_ */

View file

@ -1,47 +0,0 @@
/*
* Copyright (C) 2007-2010 Siemens AG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*******************************************************************
*
* @author Sebastian.Kaebisch.EXT@siemens.com
* @version 0.3
* @contact Joerg.Heuer@siemens.com
*
********************************************************************/
#include "v2g_serviceClientDataTransmitter.h"
#include "v2g_server.h"
#include "doIP.h"
/* This method has to be implemented!
* Send EXI stream (outStream) to EVSE and receive response stream (inStream)*/
int serviceDataTransmitter(uint8_t* outStream, size_t outStreamLength, uint8_t* inStream)
{
/* send output stream to the underlying network to the EVSE and wait for response
* --> here provide data to the V2G server directly*/
size_t inStreamLength = 0;
size_t payloadLength = 0;
/* setup DoIP header information; outStreamLength==payloadLength*/
write_doIPHeader(outStream,&outStreamLength,DOIP_EXI_TYPE);
/* send data to EVSE server (add DoIP offset)*/
testV2GService(outStream, outStreamLength, inStream, &inStreamLength);
return read_doIPHeader(inStream,inStreamLength, &payloadLength);
}

View file

@ -1,95 +0,0 @@
/*
* Copyright (C) 2007-2010 Siemens AG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*******************************************************************
*
* @author Sebastian.Kaebisch.EXT@siemens.com
* @version 0.3
* @contact Joerg.Heuer@siemens.com
*
********************************************************************/
#include "v2g_serviceMethods.h"
#include "v2g_serviceDataTypes.h"
#include <stdio.h>
/* This service methods has to be implemented by the EVSE server */
int sessionSetup(struct SessionSetupReqType* param, struct SessionSetupResType* result)
{
printf("EVSE: sessionSetup called\n" );
printf("\tReceived data:\n");
printf("\t\t PEVStatus ChargerStandby=%d\n",param->PEVStatus.ChargerStandby);
printf("\t\t PEVStatus ConnectorLocked=%d\n", param->PEVStatus.ConnectorLocked);
/* Prepare data for PEV */
result->ResponseCode = OK_SessionSetup;
result->EVSEID.data[0]='E';
result->EVSEID.arraylen.data=1;
result->EVSEStatus.ConnectorLocked=0;
result->EVSEStatus.EVSEStandby=1;
result->EVSEStatus.FatalError=0;
result->EVSEStatus.PowerSwitchClosed=1;
result->EVSEStatus.RCD=1;
result->EVSEStatus.ShutDownTime=12345678L;
result->TCurrent=12345678L;
return 0;
}
int serviceDiscovery(struct ServiceDiscoveryReqType* param, struct ServiceDiscoveryResType* result)
{
return 0;
}
int selectedServicePayment(struct ServicePaymentSelectionReqType* param, struct ServicePaymentSelectionResType* result)
{
return 0;
}
int paymentDetails(struct PaymentDetailsReqType* param, struct PaymentDetailsResType* result)
{
return 0;
}
int powerDiscovery(struct PowerDiscoveryReqType* param, struct PowerDiscoveryResType* result)
{
return 0;
}
int lineLock(struct LineLockReqType* param, struct LineLockResType* result)
{
return 0;
}
int powerDelivery(struct PowerDeliveryReqType* param, struct PowerDeliveryResType* result)
{
return 0;
}
int meteringStatus(struct MeteringStatusReqType* param, struct MeteringStatusResType* result)
{
return 0;
}
int meteringReceipt(struct MeteringReceiptReqType* param, struct MeteringReceiptResType* result)
{
return 0;
}