123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #include <stdio.h>
- #include <string.h> // memset
- #include <gfa/gfaserial.h>
- #include <gfa/gfamininetmst.h>
- #include "../src/dbghlp.h"
- ////////////////////////////////////////////////////////////////////////////////////
- #define _DEVICE_NAME "/dev/ttyO4"
- #define _NODE_ADDR 0x11
- #define _BAUD_RATE 19200
- #define _DATA_BITS 8
- #define _STOP_BITS 1
- #define _PARITY 'N'
- ////////////////////////////////////////////////////////////////////////////////////
- static int _BootloaderGetExecutionContext(HGFAMINEMST hMinem, uint8_t nNodeAddr)
- {
- if(hMinem && !NODE_IS_MULTICAST(nNodeAddr))
- {
- uint8_t nIndex;
- ssize_t nRet, nLen;
- char txb[32], rxb[256];
- nLen = GfaMininetMasterBuildFrame(hMinem, nNodeAddr, 0, "BU", 2, txb, sizeof(txb));
- if((nRet = GfaMininetMasterTransmitFrame(hMinem, txb, nLen)) != nLen)
- return -1;
- if((nLen = GfaMininetMasterReceiveFrame(hMinem, rxb, sizeof(rxb), true)) <= 0)
- return -1;
- nRet = GfaMininetMasterEvaluateSlaveResponse(hMinem, nNodeAddr, rxb, nLen, true, &nIndex);
- if(nRet == MINET_SLAVE_RESPONSE_SUCCESS)
- return -1; // Slave is neither a Bootloader nor an App
- if(nRet == MINET_SLAVE_RESPONSE_ACK)
- return 0; // Bootloader responding
- else if(nRet == MINET_SLAVE_RESPONSE_INDEX_IS_STATUS_CODE)
- return 1; // Application responding
- return -1;
- }
- return -1;
- }
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- int main(void)
- {
- int nRet = 0;
- ////////////////////////////////////////////////////////////////////////////////
- GFA_MININET_MST_CFG_PARAMS mmcp;
- memset(&mmcp, 0, sizeof(mmcp));
- if(GfaSerialGetDeviceInterface(&mmcp.devcfg.itf))
- {
- HGFAMINEMST hMinem;
- GFA_SER_CFG_PARAMS scp;
- memset(&scp, 0, sizeof(scp));
- ////////////////////////////////////////////////////////////////////////////
- // serial interface configuration
- scp.baud = _BAUD_RATE;
- scp.data = _DATA_BITS;
- scp.stop = _STOP_BITS;
- scp.parity = _PARITY;
- scp.bHandleTxEcho = true;
- ////////////////////////////////////////////////////////////////////////////
- // mininet master configuration
- mmcp.devcfg.pszDeviceName = _DEVICE_NAME;
- mmcp.devcfg.pDevParams = &scp;
- mmcp.devcfg.nSizeDevParams = sizeof(scp);
- ////////////////////////////////////////////////////////////////////////////
- //
- if((hMinem = GfaMininetMasterOpen(&mmcp)))
- {
- do
- {
- if((nRet = GfaMininetMasterSetVerbosity(hMinem, 4)) < 0) // enable output of frames
- break;
- if((nRet = GfaMininetMasterResetSlaveIndex(hMinem, _NODE_ADDR)) < 0)
- break;
- if((nRet = GfaMininetMasterPingSlave(hMinem, _NODE_ADDR)) < 0)
- break;
- nRet = _BootloaderGetExecutionContext(hMinem, _NODE_ADDR); // demonstrates the implementation of commands
- }
- while(0);
- GfaMininetMasterClose(hMinem);
- }
- }
- return nRet;
- }
|