Paul Paterson / ppCANOpen

Dependents:   ppCANOpen_Example DISCO-F746NG_rtos_test

Committer:
ptpaterson
Date:
Wed Dec 30 13:33:41 2015 +0000
Revision:
2:c724ff3a4e4d
Child:
3:12b3c25bdeba
Implement simple Object Dictionary and derived class.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ptpaterson 2:c724ff3a4e4d 1 /**
ptpaterson 2:c724ff3a4e4d 2 ******************************************************************************
ptpaterson 2:c724ff3a4e4d 3 * @file
ptpaterson 2:c724ff3a4e4d 4 * @author Paul Paterson
ptpaterson 2:c724ff3a4e4d 5 * @version
ptpaterson 2:c724ff3a4e4d 6 * @date 2015-12-22
ptpaterson 2:c724ff3a4e4d 7 * @brief CANOpen implementation library
ptpaterson 2:c724ff3a4e4d 8 ******************************************************************************
ptpaterson 2:c724ff3a4e4d 9 * @attention
ptpaterson 2:c724ff3a4e4d 10 *
ptpaterson 2:c724ff3a4e4d 11 * <h2><center>&copy; COPYRIGHT(c) 2015 Paul Paterson
ptpaterson 2:c724ff3a4e4d 12 *
ptpaterson 2:c724ff3a4e4d 13 * All rights reserved.
ptpaterson 2:c724ff3a4e4d 14
ptpaterson 2:c724ff3a4e4d 15 This program is free software: you can redistribute it and/or modify
ptpaterson 2:c724ff3a4e4d 16 it under the terms of the GNU General Public License as published by
ptpaterson 2:c724ff3a4e4d 17 the Free Software Foundation, either version 3 of the License, or
ptpaterson 2:c724ff3a4e4d 18 (at your option) any later version.
ptpaterson 2:c724ff3a4e4d 19
ptpaterson 2:c724ff3a4e4d 20 This program is distributed in the hope that it will be useful,
ptpaterson 2:c724ff3a4e4d 21 but WITHOUT ANY WARRANTY; without even the implied warranty of
ptpaterson 2:c724ff3a4e4d 22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ptpaterson 2:c724ff3a4e4d 23 GNU General Public License for more details.
ptpaterson 2:c724ff3a4e4d 24
ptpaterson 2:c724ff3a4e4d 25 You should have received a copy of the GNU General Public License
ptpaterson 2:c724ff3a4e4d 26 along with this program. If not, see <http://www.gnu.org/licenses/>.
ptpaterson 2:c724ff3a4e4d 27 */
ptpaterson 2:c724ff3a4e4d 28
ptpaterson 2:c724ff3a4e4d 29 #include "ServiceProvider.h"
ptpaterson 2:c724ff3a4e4d 30 #include "Node.h"
ptpaterson 2:c724ff3a4e4d 31
ptpaterson 2:c724ff3a4e4d 32 #include "canopen_api.h"
ptpaterson 2:c724ff3a4e4d 33
ptpaterson 2:c724ff3a4e4d 34 #include <string.h>
ptpaterson 2:c724ff3a4e4d 35
ptpaterson 2:c724ff3a4e4d 36 namespace ppCANOpen
ptpaterson 2:c724ff3a4e4d 37 {
ptpaterson 2:c724ff3a4e4d 38
ptpaterson 2:c724ff3a4e4d 39
ptpaterson 2:c724ff3a4e4d 40 ServiceProvider::ServiceProvider (void) : nodeCount(0)
ptpaterson 2:c724ff3a4e4d 41 {
ptpaterson 2:c724ff3a4e4d 42 memset (nodes, 0, sizeof(Node) * SERVICE_MAX_NODES );
ptpaterson 2:c724ff3a4e4d 43 }
ptpaterson 2:c724ff3a4e4d 44
ptpaterson 2:c724ff3a4e4d 45 /*=============================================================================
ptpaterson 2:c724ff3a4e4d 46 * main loop
ptpaterson 2:c724ff3a4e4d 47 *=============================================================================
ptpaterson 2:c724ff3a4e4d 48 */
ptpaterson 2:c724ff3a4e4d 49
ptpaterson 2:c724ff3a4e4d 50 void ServiceProvider::Run (void)
ptpaterson 2:c724ff3a4e4d 51 {
ptpaterson 2:c724ff3a4e4d 52
ptpaterson 2:c724ff3a4e4d 53 while (1) {
ptpaterson 2:c724ff3a4e4d 54 /* Check for new messages */
ptpaterson 2:c724ff3a4e4d 55 CanOpenMessage msg;
ptpaterson 2:c724ff3a4e4d 56 if (CanOpenApiRead (&msg)) {
ptpaterson 2:c724ff3a4e4d 57 /* if new message exisits, determine who it was for and execute */
ptpaterson 2:c724ff3a4e4d 58 //Node::DispatchMessage(&msg);
ptpaterson 2:c724ff3a4e4d 59 }
ptpaterson 2:c724ff3a4e4d 60
ptpaterson 2:c724ff3a4e4d 61
ptpaterson 2:c724ff3a4e4d 62 for (int i=0; i < nodeCount; i++) {
ptpaterson 2:c724ff3a4e4d 63
ptpaterson 2:c724ff3a4e4d 64 if (NMT_STATE_OPERATIONAL == nodes[i]->state.nmtState) {
ptpaterson 2:c724ff3a4e4d 65 nodes[i]->Update();
ptpaterson 2:c724ff3a4e4d 66 }
ptpaterson 2:c724ff3a4e4d 67
ptpaterson 2:c724ff3a4e4d 68 }
ptpaterson 2:c724ff3a4e4d 69 }
ptpaterson 2:c724ff3a4e4d 70 }
ptpaterson 2:c724ff3a4e4d 71
ptpaterson 2:c724ff3a4e4d 72 /*=============================================================================
ptpaterson 2:c724ff3a4e4d 73 * Add Node to list
ptpaterson 2:c724ff3a4e4d 74 *=============================================================================
ptpaterson 2:c724ff3a4e4d 75 */
ptpaterson 2:c724ff3a4e4d 76
ptpaterson 2:c724ff3a4e4d 77 int ServiceProvider::AddNode (Node * node)
ptpaterson 2:c724ff3a4e4d 78 {
ptpaterson 2:c724ff3a4e4d 79 int result = 1;
ptpaterson 2:c724ff3a4e4d 80
ptpaterson 2:c724ff3a4e4d 81 if (nodeCount < SERVICE_MAX_NODES) {
ptpaterson 2:c724ff3a4e4d 82 nodes[nodeCount++] = node;
ptpaterson 2:c724ff3a4e4d 83 } else {
ptpaterson 2:c724ff3a4e4d 84 result = 0;
ptpaterson 2:c724ff3a4e4d 85 }
ptpaterson 2:c724ff3a4e4d 86
ptpaterson 2:c724ff3a4e4d 87 return result;
ptpaterson 2:c724ff3a4e4d 88 }
ptpaterson 2:c724ff3a4e4d 89
ptpaterson 2:c724ff3a4e4d 90 /* ========================================================================
ptpaterson 2:c724ff3a4e4d 91 * Methods to handle message requests and responses
ptpaterson 2:c724ff3a4e4d 92 * ========================================================================
ptpaterson 2:c724ff3a4e4d 93 */
ptpaterson 2:c724ff3a4e4d 94
ptpaterson 2:c724ff3a4e4d 95 void ServiceProvider::RequestPdo (const int pdoNum)
ptpaterson 2:c724ff3a4e4d 96 {}
ptpaterson 2:c724ff3a4e4d 97
ptpaterson 2:c724ff3a4e4d 98 void ServiceProvider::ProducePdo (const int pdoNum, char * data)
ptpaterson 2:c724ff3a4e4d 99 {}
ptpaterson 2:c724ff3a4e4d 100
ptpaterson 2:c724ff3a4e4d 101 int ServiceProvider::SendNodeControl (NmtCommandSpecifier cs, unsigned int targetId)
ptpaterson 2:c724ff3a4e4d 102 {
ptpaterson 2:c724ff3a4e4d 103 // CanOpenMessage canOpenMsg;
ptpaterson 2:c724ff3a4e4d 104 //
ptpaterson 2:c724ff3a4e4d 105 // canOpenMsg.data[0] = (char)cs;
ptpaterson 2:c724ff3a4e4d 106 // canOpenMsg.data[1] = (char)nodeId;
ptpaterson 2:c724ff3a4e4d 107 // canOpenMsg.dataCount = 2;
ptpaterson 2:c724ff3a4e4d 108 // canOpenMsg.type = CANOPEN_TYPE_DATA;
ptpaterson 2:c724ff3a4e4d 109 // canOpenMsg.format = CANOPEN_FORMAT_STANDARD;
ptpaterson 2:c724ff3a4e4d 110 //
ptpaterson 2:c724ff3a4e4d 111 // return CanOpenApiWrite (&canOpenMsg);
ptpaterson 2:c724ff3a4e4d 112
ptpaterson 2:c724ff3a4e4d 113 return 0;
ptpaterson 2:c724ff3a4e4d 114 }
ptpaterson 2:c724ff3a4e4d 115
ptpaterson 2:c724ff3a4e4d 116 int ServiceProvider::RequestErrorControl (NmtCommandSpecifier cs, unsigned int targetId)
ptpaterson 2:c724ff3a4e4d 117 {
ptpaterson 2:c724ff3a4e4d 118 //NMT_STATE_SET(Node::state.nmtState, NMT_STATE_UNKNOWN);
ptpaterson 2:c724ff3a4e4d 119 return 0;
ptpaterson 2:c724ff3a4e4d 120 }
ptpaterson 2:c724ff3a4e4d 121
ptpaterson 2:c724ff3a4e4d 122 int ServiceProvider::RespondErrorControl (NmtCommandSpecifier cs, unsigned int targetId)
ptpaterson 2:c724ff3a4e4d 123 {
ptpaterson 2:c724ff3a4e4d 124 //NMT_STATE_SET(Node::state.nmtState, NMT_STATE_UNKNOWN);
ptpaterson 2:c724ff3a4e4d 125 return 0;
ptpaterson 2:c724ff3a4e4d 126 }
ptpaterson 2:c724ff3a4e4d 127
ptpaterson 2:c724ff3a4e4d 128
ptpaterson 2:c724ff3a4e4d 129 } /* namspace ppCANOpen */
ptpaterson 2:c724ff3a4e4d 130
ptpaterson 2:c724ff3a4e4d 131
ptpaterson 2:c724ff3a4e4d 132
ptpaterson 2:c724ff3a4e4d 133
ptpaterson 2:c724ff3a4e4d 134
ptpaterson 2:c724ff3a4e4d 135
ptpaterson 2:c724ff3a4e4d 136