serialized dlms over tcp prime gatewayww1.microchip.com/downloads/en/appnotes/serialized... · mngp...

12
Serialized DLMS over TCP PRIME Gateway Summary DLMS over TCP (DLMSoTCP) is a protocol used by PRIME Data Concentrator Units (DCU) to communicate remotely via TCP/IP with meters that are part of a PRIME network managed by a Base Node that acts as Gateway. Figure 1. DLMS over TCP in PRIME Network Schema TCP/IP NET PRIME NET PRIME SN Smart Meters PRIME DCU PRIME GW This application note develops an example of DLMS over TCP PRIME bridge addressing a PRIME Base Node (BN) Modem making use of PLC Universal Serial Interface (USI) usi_host package (more information available in document USI Host User Guide). Figure 2. DLMS over TCP PRIME Gateway PRIME GW HOST DLMSoTCP Bridge PRIME BN MODEM USI © 2019 Microchip Technology Inc. DS00003285A-page 1

Upload: others

Post on 12-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

  • Serialized DLMS over TCP PRIME Gateway

    Summary

    DLMS over TCP (DLMSoTCP) is a protocol used by PRIME Data Concentrator Units (DCU) to communicateremotely via TCP/IP with meters that are part of a PRIME network managed by a Base Node that acts as Gateway.

    Figure 1. DLMS over TCP in PRIME Network Schema

    TCP/IPNET

    PRIMENET

    PRIME SN Smart Meters

    PRIMEDCU

    PRIMEGW

    This application note develops an example of DLMS over TCP PRIME bridge addressing a PRIME Base Node (BN)Modem making use of PLC Universal Serial Interface (USI) usi_host package (more information available indocument USI Host User Guide).

    Figure 2. DLMS over TCP PRIME Gateway

    PRIME GW

    HOSTDLMSoTCP

    Bridge

    PRIMEBN

    MODEMUSI

    © 2019 Microchip Technology Inc. DS00003285A-page 1

  • Table of Contents

    Summary........................................................................................................................................................1

    1. Hardware Description..............................................................................................................................3

    2. Software Description............................................................................................................................... 4

    2.1. ATPL230ABN Embedded Project.................................................................................................42.2. Windows Environment Set-up......................................................................................................42.3. DLMS over TCP PRIME Gateway Application Features..............................................................52.4. Building DLMS over TCP PRIME Gateway Application............................................................... 5

    3. Start-up DLMS over TCP PRIME Gateway.............................................................................................6

    4. Abbreviations.......................................................................................................................................... 8

    5. Revision History...................................................................................................................................... 9

    5.1. Rev A - 10/2019........................................................................................................................... 9

    The Microchip Website.................................................................................................................................10

    Product Change Notification Service............................................................................................................10

    Customer Support........................................................................................................................................ 10

    Microchip Devices Code Protection Feature................................................................................................ 10

    Legal Notice................................................................................................................................................. 10

    Trademarks...................................................................................................................................................11

    Quality Management System....................................................................................................................... 11

    Worldwide Sales and Service.......................................................................................................................12

    © 2019 Microchip Technology Inc. DS00003285A-page 2

  • 1. Hardware DescriptionThe DLMSoverTCP application runs on the main host (a PC in this case but could be any kind of μP) of a PRIMEGateway connected through a serial port to the ATPL230ABN PRIME Base Node Evaluation Kit.

    The development is based on this evaluation board:

    • PRIME BASE NODE Evaluation Kit– https://www.microchip.com/developmenttools/ProductDetails/ATbasenode-ek

    Figure 1-1. ATPL230ABN Board

    This board is already available as Evaluation Kits from Microchipdirect.com and Distributors containing Software,Hardware Schematics, Bill of Materials and PCB Designs.

    Interconnection with the PRIME Base Node is based on USB connector (UART0 USB).

    Hardware Description

    © 2019 Microchip Technology Inc. DS00003285A-page 3

    https://www.microchip.com/developmenttools/ProductDetails/ATbasenode-ek

  • 2. Software DescriptionThis application note will allow users to build, on a Windows environment, a DLMS over TCP bridge running on anycomputer. The same implementation could run on another embedded platform based on Linux for example. TheATPL230ABN board runs the application example prime_base_modem included in the Microchip PRIME stackrelease and the communication interface between both components is handled via USI serialization. The project usesthe usi_host implementation of USI protocol PROTOCOL_PRIME_API.Figure 2-1 shows the typical scenario and the software and hardware relationships between the different elements.

    Figure 2-1. DLMS over TCP PRIME Gateway Application Diagram

    prime_base_modem

    PRIME Gateway

    USISerial Port

    SAME70MAIN HOST

    addUSI

    MNGP LAYER

    userFnc Usi

    BASE MNG

    USI_HOST HAL

    PRIME FW

    PRIME API

    PL360B

    SPI

    PRIMEBASE NODE EK

    USB PHY

    PRIME API

    CL4-32

    PRIME MNG

    TCP/IP

    Bridge DLMS/TCP to 432

    2.1 ATPL230ABN Embedded ProjectATPL230ABN-EK is flashed with the example project prime_base_modem from the last Firmware package release.For this project, USI interface can be accessed through Enhanced COM Port.

    The PRIME Base Node Modem example is located on path thirdparty\prime_ng\apps_1_4\prime_base_modem.Please compile the project and program the board to be used as PRIME Base Node Modem.

    Important:  Microchip does not provide a PRIME Data Concentrator Unit (DCU) that requests DLMSobjects from PRIME Service Nodes. Note this application acts as a gateway placed between the MicrochipBN and a PRIME Data Concentrator by means of DLMS over TCP.

    2.2 Windows Environment Set-upAny Windows Build Environment can be used to compile DLMS over TCP PRIME Gateway C application. TheWindows environment to generate all the necessary Windows executables to run DLMSoTCP application is based onCygwin (https://cygwin.com/), a tool to generate a Linux environment for compilation on Windows.

    These steps must be followed:

    1. Download Cygwin Setup Application2. Configure gcc and make for installation3. Configure bash for installation4. Include Cygwin installation folders cygwin64/bin, cygwin64/sbin and cygwin64/usr/sbin on Windows PATH

    Environment Variables5. Run bash on a Windows Command Prompt

    Software Description

    © 2019 Microchip Technology Inc. DS00003285A-page 4

    https://cygwin.com/

  • 2.3 DLMS over TCP PRIME Gateway Application FeaturesThe example developed in this application note uses the package usi-host-v2.0.0.Considering Figure 2-1 and USI Host User Guide, the main features developed on DLMS over TCP PRIME Gatewayexample are:

    • USI Project Configuration (PrjCfg.h): definitions required to enable PROTOCOL_PRIME_API, MNGP_PRIME andserial port configuration to ttySx and speed 115200bps (depending on the Enhanced COM port)

    • USI user functions (tty_usi.c): implements addUsi_Open(), addUsi_TxMsg() and addUsi_RxChar()functions required for the USI implementation

    • USI host processing runs on main loop: calls to addUsi_Process() function on infinite while loop• DLMS over TCP PRIME Gateway Application(dlmsotcp.c): implements the interface between a DCU and the

    PRIME Base Node

    The process to run the DLMS over TCP server follows these steps:

    • Initialize the TCP/IP Server and wait listening for connections from DCU• Initialize the USI interface against the PRIME Base Node Modem• Initialize the callbacks for messages coming from USI interface:

    – Base Node Management: indications about PRIME Network events such as reboot– PRIME CL 4-32: indications about Convergence Layer 4-32 Data Tx/Rx and Network Join/Leave– PRIME Management: process the information about 4-32 connections from Base Node

    • Request information about all the connected nodes (PIB_432_CONNECTED_NODES_LIST) from BN• Main loop:

    – Wait for DCU connections– Wait for events from PRIME Network to update list of 4-32 connections

    If a DCU connection exists when main loop is running:

    • If information comes from PRIME DCU, DLMSoTCP packet is forwarded to PRIME Base Node• If any event from PRIME Network like CL 4-32 join or leave happens, DLMSoTCP Server information is updated

    and corresponding DLMS/TCP custom messages are sent to PRIME DCU

    2.4 Building DLMS over TCP PRIME Gateway ApplicationFollow next steps to build the application:

    1. Open a bash shell window and go to the path where usi_host package is installed.$ cd ~/010-usi-host/dlmsotcp

    2. Build the application:$ make clean && make all

    Software Description

    © 2019 Microchip Technology Inc. DS00003285A-page 5

  • 3. Start-up DLMS over TCP PRIME GatewayA fully compliant PRIME PLC network comprised of four devices can be used to evaluate DLMS over TCP PRIMEGateway:

    • PRIME Service Node: running prime_service_dlms_app project on a Microchip PL360-EK• PRIME Gateway: based on the combination of:

    – PRIME Base Node Modem running in the Microchip Base Node ATPL230A-EK, takes care of the networkformation and management

    – DLMS over TCP PRIME Gateway running on a Windows Computer connected to PRIME Base NodeModem via USI host interface and routing DLMS traffic from TCP/IP Network to PRIME Network and viceversa

    • Commercially available DCU: request information, through a TCP/IP Network, from PRIME Network connectingto DLMS over TCP PRIME Gateway running on the PRIME Gateway

    Figure 3-1. PRIME PLC Network for DLMS over TCP Evaluation

    TCP/IPNET

    PRIMENET

    PRIME SN Smart Meter PRIME DCU

    PRIME DLMS over TCP GW

    PRIME BN MODEM

    In order to trace all the events on the PRIME Network, the PRIME Service Nodes must be switched on after theconnection between PRIME DCU and DLMS over TCP PRIME Gateway is established.

    On a Cygwin windows terminal run the DLMS over TCP server:

    # cd ~/010-usi-host/dlmsotcp #./dlmsotcp.exe -t /dev/ttyS10 -b 115200 -s 4059 -v 5 --verboseDLMSoTCP server up.Tty port is open.USI TTY ready...............New Connection established..................._dlmsotcp_cl_432_join_ind_cb_dlmsotcp_cl_432_dl_data_cfm_cbTX DATA OK: Free 5, Pending 0

    _dlmsotcp_cl_432_dl_data_ind_cb SRC=1, DEST=0, LEN=43_dlmsotcp_cl_432_dl_data_cfm_cbTX DATA OK: Free 5, Pending 0

    _dlmsotcp_cl_432_dl_data_ind_cb SRC=1, DEST=0, LEN=24_dlmsotcp_cl_432_dl_data_cfm_cbTX DATA OK: Free 5, Pending 0

    Start-up DLMS over TCP PRIME Gateway

    © 2019 Microchip Technology Inc. DS00003285A-page 6

  • _dlmsotcp_cl_432_dl_data_ind_cb SRC=1, DEST=0, LEN=5_dlmsotcp_cl_432_dl_data_cfm_cbTX DATA OK: Free 5, Pending 0

    _dlmsotcp_cl_432_dl_data_ind_cb SRC=1, DEST=0, LEN=43_dlmsotcp_cl_432_dl_data_cfm_cbTX DATA OK: Free 5, Pending 0

    _dlmsotcp_cl_432_dl_data_ind_cb SRC=1, DEST=0, LEN=16_dlmsotcp_cl_432_dl_data_cfm_cbTX DATA OK: Free 5, Pending 0

    _dlmsotcp_cl_432_dl_data_ind_cb SRC=1, DEST=0, LEN=12._dlmsotcp_cl_432_dl_data_cfm_cbTX DATA OK: Free 5, Pending 0

    _dlmsotcp_cl_432_dl_data_ind_cb SRC=1, DEST=0, LEN=24._dlmsotcp_cl_432_dl_data_cfm_cbTX DATA OK: Free 5, Pending 0

    _dlmsotcp_cl_432_dl_data_ind_cb SRC=1, DEST=0, LEN=5................._dlmsotcp_cl_432_leave_ind_cb

    Use the option -h (-help) for additional options.

    # dlmsotcp.exe -helpDLMSoTCP Gateway v1,1Usage: dlsmotcp [--verbose|silent] [OPTIONS] -t tty : tty device connecting to a base node, default: /dev/ttyUSB0 -b baudrate : tty baudrate configuration, default: 115200 -s server : TCP server port, default ,4059 -v verbose : Verbose Log Level, default: Error(0)

    Start-up DLMS over TCP PRIME Gateway

    © 2019 Microchip Technology Inc. DS00003285A-page 7

  • 4. AbbreviationsBN PRIME Base Node

    DCU Data Concentrator Unit

    DLMS Device Language Message Specification

    MAC Medium Access Channel

    PCB Printed Circuit Board

    PLC Power Line Communications

    SN PRIME Service Node

    TCP Transmission Control Protocol

    USB Universal Serial Bus

    USI Universal Serial Interface

    Abbreviations

    © 2019 Microchip Technology Inc. DS00003285A-page 8

  • 5. Revision History

    5.1 Rev A - 10/2019Document Initial document release.

    Revision History

    © 2019 Microchip Technology Inc. DS00003285A-page 9

  • The Microchip WebsiteMicrochip provides online support via our website at http://www.microchip.com/. This website is used to make filesand information easily available to customers. Some of the content available includes:

    • Product Support – Data sheets and errata, application notes and sample programs, design resources, user’sguides and hardware support documents, latest software releases and archived software

    • General Technical Support – Frequently Asked Questions (FAQs), technical support requests, onlinediscussion groups, Microchip design partner program member listing

    • Business of Microchip – Product selector and ordering guides, latest Microchip press releases, listing ofseminars and events, listings of Microchip sales offices, distributors and factory representatives

    Product Change Notification ServiceMicrochip’s product change notification service helps keep customers current on Microchip products. Subscribers willreceive email notification whenever there are changes, updates, revisions or errata related to a specified productfamily or development tool of interest.

    To register, go to http://www.microchip.com/pcn and follow the registration instructions.

    Customer SupportUsers of Microchip products can receive assistance through several channels:

    • Distributor or Representative• Local Sales Office• Embedded Solutions Engineer (ESE)• Technical Support

    Customers should contact their distributor, representative or ESE for support. Local sales offices are also available tohelp customers. A listing of sales offices and locations is included in this document.

    Technical support is available through the website at: http://www.microchip.com/support

    Microchip Devices Code Protection FeatureNote the following details of the code protection feature on Microchip devices:

    • Microchip products meet the specification contained in their particular Microchip Data Sheet.• Microchip believes that its family of products is one of the most secure families of its kind on the market today,

    when used in the intended manner and under normal conditions.• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these

    methods, to our knowledge, require using the Microchip products in a manner outside the operatingspecifications contained in Microchip’s Data Sheets. Most likely, the person doing so is engaged in theft ofintellectual property.

    • Microchip is willing to work with the customer who is concerned about the integrity of their code.• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code

    protection does not mean that we are guaranteeing the product as “unbreakable.”

    Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protectionfeatures of our products. Attempts to break Microchip’s code protection feature may be a violation of the DigitalMillennium Copyright Act. If such acts allow unauthorized access to your software or other copyrighted work, youmay have a right to sue for relief under that Act.

    Legal NoticeInformation contained in this publication regarding device applications and the like is provided only for yourconvenience and may be superseded by updates. It is your responsibility to ensure that your application meets with

    © 2019 Microchip Technology Inc. DS00003285A-page 10

    http://www.microchip.com/http://www.microchip.com/pcnhttp://www.microchip.com/support

  • your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHEREXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION,INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY ORFITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchipdevices in life support and/or safety applications is entirely at the buyer’s risk, and the buyer agrees to defend,indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from suchuse. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights unlessotherwise stated.

    TrademarksThe Microchip name and logo, the Microchip logo, Adaptec, AnyRate, AVR, AVR logo, AVR Freaks, BesTime,BitCloud, chipKIT, chipKIT logo, CryptoMemory, CryptoRF, dsPIC, FlashFlex, flexPWR, HELDO, IGLOO, JukeBlox,KeeLoq, Kleer, LANCheck, LinkMD, maXStylus, maXTouch, MediaLB, megaAVR, Microsemi, Microsemi logo, MOST,MOST logo, MPLAB, OptoLyzer, PackeTime, PIC, picoPower, PICSTART, PIC32 logo, PolarFire, Prochip Designer,QTouch, SAM-BA, SenGenuity, SpyNIC, SST, SST Logo, SuperFlash, Symmetricom, SyncServer, Tachyon,TempTrackr, TimeSource, tinyAVR, UNI/O, Vectron, and XMEGA are registered trademarks of Microchip TechnologyIncorporated in the U.S.A. and other countries.

    APT, ClockWorks, The Embedded Control Solutions Company, EtherSynch, FlashTec, Hyper Speed Control,HyperLight Load, IntelliMOS, Libero, motorBench, mTouch, Powermite 3, Precision Edge, ProASIC, ProASIC Plus,ProASIC Plus logo, Quiet-Wire, SmartFusion, SyncWorld, Temux, TimeCesium, TimeHub, TimePictra, TimeProvider,Vite, WinPath, and ZL are registered trademarks of Microchip Technology Incorporated in the U.S.A.

    Adjacent Key Suppression, AKS, Analog-for-the-Digital Age, Any Capacitor, AnyIn, AnyOut, BlueSky, BodyCom,CodeGuard, CryptoAuthentication, CryptoAutomotive, CryptoCompanion, CryptoController, dsPICDEM,dsPICDEM.net, Dynamic Average Matching, DAM, ECAN, EtherGREEN, In-Circuit Serial Programming, ICSP,INICnet, Inter-Chip Connectivity, JitterBlocker, KleerNet, KleerNet logo, memBrain, Mindi, MiWi, MPASM, MPF,MPLAB Certified logo, MPLIB, MPLINK, MultiTRAK, NetDetach, Omniscient Code Generation, PICDEM,PICDEM.net, PICkit, PICtail, PowerSmart, PureSilicon, QMatrix, REAL ICE, Ripple Blocker, SAM-ICE, Serial QuadI/O, SMART-I.S., SQI, SuperSwitcher, SuperSwitcher II, Total Endurance, TSHARC, USBCheck, VariSense,ViewSpan, WiperLock, Wireless DNA, and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A.and other countries.

    SQTP is a service mark of Microchip Technology Incorporated in the U.S.A.

    The Adaptec logo, Frequency on Demand, Silicon Storage Technology, and Symmcom are registered trademarks ofMicrochip Technology Inc. in other countries.

    GestIC is a registered trademark of Microchip Technology Germany II GmbH & Co. KG, a subsidiary of MicrochipTechnology Inc., in other countries.

    All other trademarks mentioned herein are property of their respective companies.© 2019, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved.

    ISBN: 978-1-5224-5164-8

    Quality Management SystemFor information regarding Microchip’s Quality Management Systems, please visit http://www.microchip.com/quality.

    © 2019 Microchip Technology Inc. DS00003285A-page 11

    http://www.microchip.com/quality

  • AMERICAS ASIA/PACIFIC ASIA/PACIFIC EUROPECorporate Office2355 West Chandler Blvd.Chandler, AZ 85224-6199Tel: 480-792-7200Fax: 480-792-7277Technical Support:http://www.microchip.com/supportWeb Address:http://www.microchip.comAtlantaDuluth, GATel: 678-957-9614Fax: 678-957-1455Austin, TXTel: 512-257-3370BostonWestborough, MATel: 774-760-0087Fax: 774-760-0088ChicagoItasca, ILTel: 630-285-0071Fax: 630-285-0075DallasAddison, TXTel: 972-818-7423Fax: 972-818-2924DetroitNovi, MITel: 248-848-4000Houston, TXTel: 281-894-5983IndianapolisNoblesville, INTel: 317-773-8323Fax: 317-773-5453Tel: 317-536-2380Los AngelesMission Viejo, CATel: 949-462-9523Fax: 949-462-9608Tel: 951-273-7800Raleigh, NCTel: 919-844-7510New York, NYTel: 631-435-6000San Jose, CATel: 408-735-9110Tel: 408-436-4270Canada - TorontoTel: 905-695-1980Fax: 905-695-2078

    Australia - SydneyTel: 61-2-9868-6733China - BeijingTel: 86-10-8569-7000China - ChengduTel: 86-28-8665-5511China - ChongqingTel: 86-23-8980-9588China - DongguanTel: 86-769-8702-9880China - GuangzhouTel: 86-20-8755-8029China - HangzhouTel: 86-571-8792-8115China - Hong Kong SARTel: 852-2943-5100China - NanjingTel: 86-25-8473-2460China - QingdaoTel: 86-532-8502-7355China - ShanghaiTel: 86-21-3326-8000China - ShenyangTel: 86-24-2334-2829China - ShenzhenTel: 86-755-8864-2200China - SuzhouTel: 86-186-6233-1526China - WuhanTel: 86-27-5980-5300China - XianTel: 86-29-8833-7252China - XiamenTel: 86-592-2388138China - ZhuhaiTel: 86-756-3210040

    India - BangaloreTel: 91-80-3090-4444India - New DelhiTel: 91-11-4160-8631India - PuneTel: 91-20-4121-0141Japan - OsakaTel: 81-6-6152-7160Japan - TokyoTel: 81-3-6880- 3770Korea - DaeguTel: 82-53-744-4301Korea - SeoulTel: 82-2-554-7200Malaysia - Kuala LumpurTel: 60-3-7651-7906Malaysia - PenangTel: 60-4-227-8870Philippines - ManilaTel: 63-2-634-9065SingaporeTel: 65-6334-8870Taiwan - Hsin ChuTel: 886-3-577-8366Taiwan - KaohsiungTel: 886-7-213-7830Taiwan - TaipeiTel: 886-2-2508-8600Thailand - BangkokTel: 66-2-694-1351Vietnam - Ho Chi MinhTel: 84-28-5448-2100

    Austria - WelsTel: 43-7242-2244-39Fax: 43-7242-2244-393Denmark - CopenhagenTel: 45-4450-2828Fax: 45-4485-2829Finland - EspooTel: 358-9-4520-820France - ParisTel: 33-1-69-53-63-20Fax: 33-1-69-30-90-79Germany - GarchingTel: 49-8931-9700Germany - HaanTel: 49-2129-3766400Germany - HeilbronnTel: 49-7131-72400Germany - KarlsruheTel: 49-721-625370Germany - MunichTel: 49-89-627-144-0Fax: 49-89-627-144-44Germany - RosenheimTel: 49-8031-354-560Israel - Ra’ananaTel: 972-9-744-7705Italy - MilanTel: 39-0331-742611Fax: 39-0331-466781Italy - PadovaTel: 39-049-7625286Netherlands - DrunenTel: 31-416-690399Fax: 31-416-690340Norway - TrondheimTel: 47-72884388Poland - WarsawTel: 48-22-3325737Romania - BucharestTel: 40-21-407-87-50Spain - MadridTel: 34-91-708-08-90Fax: 34-91-708-08-91Sweden - GothenbergTel: 46-31-704-60-40Sweden - StockholmTel: 46-8-5090-4654UK - WokinghamTel: 44-118-921-5800Fax: 44-118-921-5820

    Worldwide Sales and Service

    © 2019 Microchip Technology Inc. DS00003285A-page 12

    http://www.microchip.com/supporthttp://www.microchip.com

    SummaryTable of Contents1. Hardware Description2. Software Description2.1. ATPL230ABN Embedded Project2.2. Windows Environment Set-up2.3. DLMS over TCP PRIME Gateway Application Features2.4. Building DLMS over TCP PRIME Gateway Application

    3. Start-up DLMS over TCP PRIME Gateway4. Abbreviations5. Revision History5.1. Rev A - 10/2019

    The Microchip WebsiteProduct Change Notification ServiceCustomer SupportMicrochip Devices Code Protection FeatureLegal NoticeTrademarksQuality Management SystemWorldwide Sales and Service