@@ -82,7 +82,7 @@ static void SlaveReadRegisters(tag_AvrModbusSlaveCtrl *Slave, tag_QueryResponseI
8282 - 없음.
8383
8484 3) 설명
85- - Master의 'ReadHolding ' 명령에 대한 처리.
85+ - Master의 'Read Holding Registers' / 'Read Input Registers ' 명령에 대한 처리.
8686 */
8787
8888 StartAddr = (tU16 ) (RxQue -> Buf [2 ] << 8 ) + RxQue -> Buf [3 ];
@@ -131,6 +131,17 @@ static void SlaveReadStatus(tag_AvrModbusSlaveCtrl *Slave, tag_QueryResponseInfo
131131 tU16 StartAddr , NumberOfPoint , Crc16 , i , MapStartAddr ;
132132 tU8 * BaseAddr ;
133133
134+ /*
135+ 1) 인수
136+ - Slave : tag_AvrModbusSlaveCtrl 인스턴스의 주소.
137+
138+ 2) 반환
139+ - 없음.
140+
141+ 3) 설명
142+ - Master의 'Read Coil Status' / 'Read Input Status' 명령에 대한 처리.
143+ */
144+
134145 StartAddr = (tU16 ) (RxQue -> Buf [2 ] << 8 ) + RxQue -> Buf [3 ];
135146 NumberOfPoint = (tU16 ) (RxQue -> Buf [4 ] << 8 ) + RxQue -> Buf [5 ];
136147 MapStartAddr = StartAddr == 0 ? 0 : QueryResponseInfo -> MapStartAddr ;
@@ -176,6 +187,17 @@ static void SlaveForceSingleCoil(tag_AvrModbusSlaveCtrl *Slave, tag_QueryRespons
176187 tU16 RegisterAddr , ForceData , Crc16 , Move ;
177188 tU8 * BaseAddr ;
178189
190+ /*
191+ 1) 인수
192+ - Slave : tag_AvrModbusSlaveCtrl 인스턴스의 주소.
193+
194+ 2) 반환
195+ - 없음.
196+
197+ 3) 설명
198+ - Master의 'Force Single Coil' 명령에 대한 처리.
199+ */
200+
179201 RegisterAddr = (tU16 ) (RxQue -> Buf [2 ] << 8 ) + RxQue -> Buf [3 ];
180202 ForceData = (tU16 ) (RxQue -> Buf [4 ] << 8 ) + RxQue -> Buf [5 ];
181203
@@ -354,6 +376,18 @@ static void SlaveReadSerialNumber(tag_AvrModbusSlaveCtrl *Slave)
354376 tU16 StartAddr , NumberOfPoint , Crc16 , i ;
355377 tU8 * BaseAddr ;
356378
379+ /*
380+ 1) 인수
381+ - Slave : tag_AvrModbusSlaveCtrl 인스턴스의 주소.
382+
383+ 2) 반환
384+ - 없음.
385+
386+ 3) 설명
387+ - modbus standard에는 없는 비표준 커맨드 'ReadSerialNumber' 명령에 대한 처리.
388+ - tag_AvrModbusSlaveCtrl::AvrModbusSlaveLinkSerialNumber()를 호출하여 일련번호 먼저 추가 필요.
389+ */
390+
357391 StartAddr = (tU16 ) (RxQue -> Buf [2 ] << 8 ) + RxQue -> Buf [3 ];
358392 NumberOfPoint = strlen (Slave -> SerialNumberAddr ) / 2 ;
359393 if (strlen (Slave -> SerialNumberAddr ) % 2 ) NumberOfPoint += 1 ;
@@ -569,6 +603,30 @@ tU8 AvrModbusSlaveLinkSerialNumber(tag_AvrModbusSlaveCtrl *Slave, char *SerialNu
569603tU8 AvrModbusSlaveSetQueryResponseInfo (tag_AvrModbusSlaveCtrl * Slave , enum_AvrModbusFunction Function , tU8 * BaseAddr , tU16 MapStartAddr )
570604{
571605 tag_QueryResponseInfo * pQueryResponseInfo ;
606+
607+ /*
608+ 1) 인수
609+ - Slave : tag_AvrModbusSlaveCtrl 인스턴스의 주소.
610+ - Function : 대상 modbus command
611+ - BaseAddr : command와 bind 대상 변수 주소.
612+ - MapStartAddr : command의 시작 주소.
613+
614+ 2) 반환
615+ - 0 : 초기화 실패
616+ - 1 : 초기화 성공
617+
618+ 3) 설명
619+ - 마스터 query 요청 command의 modbus map start address를 설정하고, 대상 변수(메모리 주소)를 bind한다.
620+ - tU16 RegInput[10];
621+ AvrModbusSlaveSetQueryResponseInfo(&slave, AVR_MODBUS_ReadInputRegister, (tU8 *) &RegInput, 50);
622+
623+ 위와 같이 설정하면 AVR_MODBUS_ReadInputRegister 요청에 아래와 같이 응답.
624+ 50번지 : RegInput[0]
625+ 51번지 : RegInput[1]
626+ 52번지 : RegInput[2]
627+ ...
628+ 59번지 : RegInput[9]
629+ */
572630
573631 switch (Function )
574632 {
@@ -790,6 +848,18 @@ static void MasterReceiveRegister(tag_AvrModbusMasterSlavePollData *PollData, ta
790848{
791849 tU16 Length , i , j = 3 ;
792850
851+ /*
852+ 1) 인수
853+ - PollData : tag_AvrModbusMasterSlavePollData 타입 인스턴스 주소.
854+ - RxQue : tag_AvrUartRingBuf 타입 인스턴즈 주소.
855+
856+ 2) 반환
857+ - 없음.
858+
859+ 3) 설명
860+ - Big endian -> Little endian conversion.
861+ */
862+
793863 Length = PollData -> NumberOfRegister * 2 ;
794864 for (i = 0 ; i < Length ; i += 2 )
795865 {
@@ -802,6 +872,18 @@ static void MasterReceiveStatus(tag_AvrModbusMasterSlavePollData *PollData, tag_
802872{
803873 tU8 ByteCount ;
804874
875+ /*
876+ 1) 인수
877+ - PollData : tag_AvrModbusMasterSlavePollData 타입 인스턴스 주소.
878+ - RxQue : tag_AvrUartRingBuf 타입 인스턴즈 주소.
879+
880+ 2) 반환
881+ - 없음.
882+
883+ 3) 설명
884+ - bit 단위 status command 대한 수신 처리.
885+ */
886+
805887 ByteCount = RxQue -> Buf [2 ];
806888 if (ByteCount > (RxQue -> Size - 4 )) ByteCount = RxQue -> Size - 4 ;
807889 memcpy (PollData -> BaseAddr , & RxQue -> Buf [3 ], ByteCount );
@@ -812,6 +894,18 @@ static tU16 GetExpectRxCnt(tag_AvrModbusMasterSlavePollData *PollData)
812894 const tU8 HeaderSize = 5 ; //slave address / function / byte count / crc / crc
813895 tU16 Cnt ;
814896
897+ /*
898+ 1) 인수
899+ - PollData : tag_AvrModbusMasterSlavePollData 타입 인스턴스 주소.
900+
901+ 2) 반환
902+ - 예상 수신 데이터 길이(byte)
903+
904+ 3) 설명
905+ - 매개 변수 PollData에는 마스터가 호출할 데이터의 길이 정보가 있다. 이 정보를 이용하여
906+ 마스터가 수신 해야 하는 데이터의 길이를 계산하여 반환한다.
907+ */
908+
815909 switch (PollData -> PollFunction )
816910 {
817911 case AVR_MODBUS_ReadInputStatus :
@@ -1184,6 +1278,7 @@ void AvrModbusMasterProc(tag_AvrModbusMasterCtrl *Master)
11841278
11851279 3) 설명
11861280 - Master 동작 처리.
1281+ - 이 함수를 application loop에서 주기적 호출해야 합니다.
11871282 */
11881283
11891284 if ((Master -> Bit .InitComplete == false) || (Master -> AddedSlave == 0 ))
0 commit comments