---
# System prepended metadata

title: 4 Bytes ID - LoRa P2P JOIN Mechanism
tags: [Acer]

---

---
tags: 'Acer'
---
4 Bytes ID - LoRa P2P JOIN Mechanism
====
[TOC]
### Commands
#### JOIN Command:  ( Send by Slave )
    ```
    typedef struct
    {
        UINT8    Ack;
        UINT8    payloadType=7;
        UINT8    UUID[16];
        UINT8    firmwareVersion[3];
        UINT8    protocolVersion;   // protocolVersion=1
        UINT32   meterType;
        UINT16   CRC
    } STC_P2P_JOIN_PACKAGE;
    ```
    
    Ack : Always be 0
    payloadType: Always be 7
    UUID : 16 Bytes UUID

* JOIN Command Response 1: ( Send by Master )
    ```
    #pragma pack(1)
    typedef struct
    {
        UINT32   P2P_ID;
        UINT8    payloadType=8;
        UINT8    UUID[16];
        UINT8    protocolVersion;   // protocolVersion=1
        UINT8    currentDateTime[6];   //  ( YYMMDDHHMMSS in binary )
        UINT16   CRC;
    } STC_P2P_JOIN_PACKAGE_RESPONSE1;
    #pragma pack()
    ```
    After receving the response package from master,
    meter should ack the package as follow:
    ```
    #pragma pack(1)
    typedef struct
    {
        UINT32   P2P_ID;
        UINT8    payloadType=9;
        UINT8    protocolVersion;   // protocolVersion=1
        UINT16   CRC;
    } STC_P2P_JOIN_PACKAGE_RESPONSE2;
    #pragma pack()
    ``` 
    
    After receving Ack from Meter,
    Master will send out the response 2 format as follow:
    ```
    #pragma pack(1)
    typedef struct
    {
        UINT32  P2P_ID;
        UINT8   payloadType=10;
        UINT8   uplinkHour;
        UINT8   uplinkMin;
        UINT8   uplinkSec;
        UINT8   retryTimes;
        UINT16  retryPeriod;
        UINT16  timeSlice;
        //FLOAT32 dataChannel;     // data channel ,Unit: MHz
        UINT8   protocolVersion;   // protocolVersion=1
        UINT32  samplingPeriod;  // Unit: Second
        UINT32  uplinkPeriod;    // Unit: Second
        UINT16  samplingShift; 
        UINT16  CRC;
    } STC_P2P_JOIN_PACKAGE_RESPONSE2;
    #pragma pack()
    ```   

    P2P_ID: the id used in report format ( Always bigger than 0 )

  
#### Report Command: ( Send by Slave )
    ```
    #pragma pack(1)
    typedef struct
    {
        UINT32      P2P_ID;
        UINT8       payloadType=11;
        FLOAT64     meterValue;
        FLOAT32     batteryVoltage;
        FLOAT32     RSSI;
        UINT8       recordDate[6];  // YMDHMS
        UINT8       protocolVersion;   // protocolVersion=1
        UINT16      CRC;
    } STC_P2P_REPORT_PACKAGE;
    pragma pack()
    ```  
    P2P_ID: which got from JOIN process
    payloadType: Always be 11
    meterValue:
    batteryVoltage:
    RSSI:

* Report Command Ack: ( Send by Master )
    ```
    #pragma pack(1)
    typedef struct
    {
        UINT32  P2P_ID;
        UINT8   payloadType=12;
        UINT8   currentDateTime[6];   //  ( YYMMDDHHMMSS in binary )
        UINT8   uplinkHour;
        UINT8   uplinkMin;
        UINT8   uplinkSec;
        UINT8   retryTimes;
        UINT16  retryPeriod;
        UINT16  timeSlice;
        // FLOAT32 dataChannel;    // data channel ,Unit: MHz
        UINT8   protocolVersion;   // protocolVersion=1
        UINT32  samplingPeriod; // Unit: Second
        UINT32  uplinkPeriod;    // Unit: Second
        UINT16  samplingShift; 
        UINT16  CRC;
    } STC_P2P_REPORT_PACKAGE_RESPONSE;
    #pragma pack()
    ```  
#### Upload Image Command: ( Send by Slave )

 ```C=
{
    UINT32    P2P_ID;
    UINT8     commandCode=13;      
    UINT16    dataLength;
    UINT16    batchIndex;
    UINT8     protocolVersion;   // protocolVersion=1
    UINT8     data[18];   
    UINT16    CRC;
}
```
* Upload Image Response
```C=
{
    UINT32    P2P_ID;
    UINT8     commandCode=14;      
    UINT16    dataLength;
    UINT16    batchIndex;
    UINT8     currentDateTime[6];   //  ( YYMMDDHHMMSS in binary )
    UINT8     protocolVersion;      // protocolVersion=1
    UINT16    CRC;
}
```
#### Query Command: ( Send by Slave )

 ```C=
{
    UINT32    P2P_ID=p2pId;
    UINT8     commandCode=15;
    UINT8     protocolVersion;      // protocolVersion=1
    UINT16    CRC;
}
```
* Query Command Response
```C=
{
    UINT32    P2P_ID;
    UINT8     commandCode=16;      
    UINT8     currentDateTime[6];   //  ( YYMMDDHHMMSS in binary )
    UINT16    command;              // Mask 0x01: upload image
    UINT8     imageDate[6];         // The picture took on
    UINT16    imageStartBatchIndex;
    UINT8     getImageTime[6];      // The time to send out image
    UINT16    imageTimeSlice;
    UINT8     protocolVersion;      // protocolVersion=1
    UINT16    CRC;
}
```
* Command:
    * 0x01: upload image
    * 0x02: upload ROI
    * 0x03: download ROI - no used yet.
    * 0x04: upload fill-up data

After JOIN / Report / Image action, device should query command.

#### upload ROI Command: ( Send by Slave )
```C=
{
    UINT32    P2P_ID;
    UINT8     commandCode=17;      
    FLOAT64   refferenceVolume;    
    UINT8     digitalNumbers;      
    UINT32    MeterType;
    UINT8     IntegerNo;
    UINT8     DecimalNo;
    INT16     ROI_Angle;          
    INT32     Max_Flow;            
    INT16     imageShift_y;       
    // UINT8     reserved;
    UINT8     protocolVersion;      // protocolVersion=1
    UINT16    CRC;
}
```
* Upload ROI Response
```C=
{
    UINT32    P2P_ID;
    UINT8     commandCode=18;  
    UINT8     protocolVersion;      // protocolVersion=1
    UINT16    CRC;
}
```

#### upload ROI digitals Command: ( Send by Slave )
```C=
{
    UINT32    P2P_ID;
    UINT8     commandCode=19;
    UINT8     digitalIndex;
    UINT16    xLeftTop;
    UINT16    yLeftTop;
    UINT16    xRightTop;
    UINT16    yRightTop;
    UINT16    xLeftBottom;
    UINT16    yLeftBottom;
    UINT16    xRightBottom;
    UINT16    yRightBottom;
    UINT8     OCRParameters;    
    UINT8     FontWidth;
    UINT8     FontId;
    UINT8     RoID;
    //UINT8     reserved;
    UINT8     protocolVersion;      // protocolVersion=1
    UINT16    CRC;
}
```
* Upload ROI Response
```C=
{
    UINT32    P2P_ID;
    UINT8     commandCode=20;      
    UINT8     protocolVersion;      // protocolVersion=1
    UINT16    CRC;
}
```
#### Download ROI Command: ( Send by Slave )
```C=
{
    UINT32    P2P_ID;
    UINT8     commandCode=21;      
    FLOAT64   refferenceVolume;    
    UINT8     digitalNumbers;      
    UINT32    MeterType;
    UINT8     IntegerNo;
    UINT8     DecimalNo;
    INT16     ROI_Angle;          
    INT32     Max_Flow;            
    INT16     imageShift_y;       
    //UINT8     reserved;
    UINT8     protocolVersion;      // protocolVersion=1
    UINT16    CRC;
}
```
* Upload ROI Response
```C=
{
    UINT32    P2P_ID;
    UINT8     commandCode=22;  
    UINT8     protocolVersion;      // protocolVersion=1
    UINT16    CRC;
}
```
#### Download ROI digitals Command: ( Send by Slave )
```C=
{
    UINT32     P2P_ID;
    UINT8     commandCode=23;
    UINT8     digitalIndex;
    UINT16    xLeftTop;
    UINT16    yLeftTop;
    UINT16    xRightTop;
    UINT16    yRightTop;
    UINT16    xLeftBottom;
    UINT16    yLeftBottom;
    UINT16    xRightBottom;
    UINT16    yRightBottom;
    UINT8     OCRParameters;    
    UINT8     FontWidth;
    UINT8     FontId;
    UINT8     RoID;
    //UINT8     reserved;
    UINT8     protocolVersion;      // protocolVersion=1
    UINT16    CRC;
}
```
* Upload ROI digitals Response
```C=
{
    UINT32    P2P_ID;
    UINT8     commandCode=24; 
    UINT8     protocolVersion;      // protocolVersion=1
    UINT16    CRC;
}
```
#### Upload fill-up data Command: ( Send by Slave )
```C=
{
    UINT32    P2P_ID;
    UINT8     commandCode=25;      
    UINT8     protocolVersion;      // protocolVersion=1
    UINT16    CRC;
}
```
* Upload fill-up data Response
```C=
{
    UINT32    P2P_ID;
    UINT8     commandCode=26;  
    UINT8     protocolVersion;      // protocolVersion=1
    UINT8     date1[4];             // date1[0]==0, if null
    UINT8     date2[4];             // date2[0]==0, if null
    UINT8     date3[4];             // date3[0]==0, if null
    UINT8     date4[4];             // date4[0]==0, if null
    UINT8     date5[4];             // date5[0]==0, if null
    UINT16    CRC;
}
// date: Year,Month,Day,Hour
```
### Master Mechanism
![](https://i.imgur.com/zughggx.png)
### Slave Mechanism
![](https://i.imgur.com/e4sEW8i.png)

