Lets you control the FRDM-K64F board over the PC using the GUI software (https://github.com/navin-bhaskar/Controller) written in Python. To use the software, connect the FRDM-K64Fto your PC (via USB cable connected to USB port labelled as "open SDA") and start the software to control the FRDM-K64F. For more info on usage, please go to: http://navinbhaskar.blogspot.in/2013/02/arduino-controller-3.html

Dependencies:   mbed

Committer:
Navin
Date:
Fri Aug 08 02:27:42 2014 +0000
Revision:
0:7ce46d3f9f5d
This application lets you control the FRDM-K64F Frdm board with a front end GUI software written in Python (https://github.com/navin-bhaskar/Controller)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Navin 0:7ce46d3f9f5d 1 /*
Navin 0:7ce46d3f9f5d 2 * This program is free software; you can redistribute it and/or modify
Navin 0:7ce46d3f9f5d 3 * it under the terms of the GNU General Public License as published by
Navin 0:7ce46d3f9f5d 4 * the Free Software Foundation; either version 2 of the License, or
Navin 0:7ce46d3f9f5d 5 * (at your option) any later version.
Navin 0:7ce46d3f9f5d 6 *
Navin 0:7ce46d3f9f5d 7 * This program is distributed in the hope that it will be useful,
Navin 0:7ce46d3f9f5d 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Navin 0:7ce46d3f9f5d 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Navin 0:7ce46d3f9f5d 10 * GNU General Public License for more details.
Navin 0:7ce46d3f9f5d 11 *
Navin 0:7ce46d3f9f5d 12 * You should have received a copy of the GNU General Public License
Navin 0:7ce46d3f9f5d 13 * along with this program; if not, write to the Free Software
Navin 0:7ce46d3f9f5d 14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
Navin 0:7ce46d3f9f5d 15 * MA 02110-1301, USA.
Navin 0:7ce46d3f9f5d 16 *
Navin 0:7ce46d3f9f5d 17 */
Navin 0:7ce46d3f9f5d 18
Navin 0:7ce46d3f9f5d 19
Navin 0:7ce46d3f9f5d 20
Navin 0:7ce46d3f9f5d 21 /**
Navin 0:7ce46d3f9f5d 22 * \brief Implements a simple protocol for communication with PC
Navin 0:7ce46d3f9f5d 23 * \author Navin Bhaskar
Navin 0:7ce46d3f9f5d 24 */
Navin 0:7ce46d3f9f5d 25
Navin 0:7ce46d3f9f5d 26 #include "TransLayer.h"
Navin 0:7ce46d3f9f5d 27
Navin 0:7ce46d3f9f5d 28
Navin 0:7ce46d3f9f5d 29
Navin 0:7ce46d3f9f5d 30 /**
Navin 0:7ce46d3f9f5d 31 * \fn TransLayer()
Navin 0:7ce46d3f9f5d 32 * \brief constructor for trans layer. Initializes the pointers
Navin 0:7ce46d3f9f5d 33 * \param none
Navin 0:7ce46d3f9f5d 34 * \return none
Navin 0:7ce46d3f9f5d 35 */
Navin 0:7ce46d3f9f5d 36
Navin 0:7ce46d3f9f5d 37 TransLayer::TransLayer()
Navin 0:7ce46d3f9f5d 38 {
Navin 0:7ce46d3f9f5d 39 _head =_tail = NULL;
Navin 0:7ce46d3f9f5d 40 }
Navin 0:7ce46d3f9f5d 41
Navin 0:7ce46d3f9f5d 42 /**
Navin 0:7ce46d3f9f5d 43 * \fn AddService(call_back_ptr cb, char flag)
Navin 0:7ce46d3f9f5d 44 * \brief Adds a service to the layer. The arguments are passed to
Navin 0:7ce46d3f9f5d 45 * the call back function
Navin 0:7ce46d3f9f5d 46 * \param[in] cb call back pointer
Navin 0:7ce46d3f9f5d 47 * \param[in] flag flag to which this packet must respond
Navin 0:7ce46d3f9f5d 48 * \return -1 on error
Navin 0:7ce46d3f9f5d 49 */
Navin 0:7ce46d3f9f5d 50
Navin 0:7ce46d3f9f5d 51 int TransLayer::AddService(call_back_ptr cb, char flag)
Navin 0:7ce46d3f9f5d 52 {
Navin 0:7ce46d3f9f5d 53 service_ptr temp=_head, mid;
Navin 0:7ce46d3f9f5d 54
Navin 0:7ce46d3f9f5d 55 if (NULL == cb) {
Navin 0:7ce46d3f9f5d 56 return -1;
Navin 0:7ce46d3f9f5d 57 }
Navin 0:7ce46d3f9f5d 58
Navin 0:7ce46d3f9f5d 59 // we are going to maintain a linked list of services
Navin 0:7ce46d3f9f5d 60 mid = (service_ptr)malloc(sizeof(service_list));
Navin 0:7ce46d3f9f5d 61
Navin 0:7ce46d3f9f5d 62 if (NULL == mid) {
Navin 0:7ce46d3f9f5d 63 return -1;
Navin 0:7ce46d3f9f5d 64 }
Navin 0:7ce46d3f9f5d 65
Navin 0:7ce46d3f9f5d 66 // record entries
Navin 0:7ce46d3f9f5d 67 mid->service_function = cb;
Navin 0:7ce46d3f9f5d 68 mid->service_flag = flag;
Navin 0:7ce46d3f9f5d 69 if (NULL == _head) {
Navin 0:7ce46d3f9f5d 70 // first entry ever
Navin 0:7ce46d3f9f5d 71 _head = mid;
Navin 0:7ce46d3f9f5d 72 mid->next_service = NULL;
Navin 0:7ce46d3f9f5d 73 } else {
Navin 0:7ce46d3f9f5d 74 // traverese to end of the list for insertion
Navin 0:7ce46d3f9f5d 75 while (temp->next_service != NULL) {
Navin 0:7ce46d3f9f5d 76 temp = temp->next_service;
Navin 0:7ce46d3f9f5d 77 }
Navin 0:7ce46d3f9f5d 78 temp->next_service = mid;
Navin 0:7ce46d3f9f5d 79 mid->next_service = NULL;
Navin 0:7ce46d3f9f5d 80 }
Navin 0:7ce46d3f9f5d 81 return 0;
Navin 0:7ce46d3f9f5d 82 }
Navin 0:7ce46d3f9f5d 83
Navin 0:7ce46d3f9f5d 84
Navin 0:7ce46d3f9f5d 85
Navin 0:7ce46d3f9f5d 86 /**
Navin 0:7ce46d3f9f5d 87 * \fn LookForService(char flag)
Navin 0:7ce46d3f9f5d 88 * \brief This function looks for a service that services given flag
Navin 0:7ce46d3f9f5d 89 * \param[in] flag flag of the service
Navin 0:7ce46d3f9f5d 90 * \return service ptr containing that has info on service or NULL if service flag
Navin 0:7ce46d3f9f5d 91 * was not found
Navin 0:7ce46d3f9f5d 92 */
Navin 0:7ce46d3f9f5d 93
Navin 0:7ce46d3f9f5d 94 service_ptr TransLayer::LookForService(char flag)
Navin 0:7ce46d3f9f5d 95 {
Navin 0:7ce46d3f9f5d 96 service_ptr temp = _head;
Navin 0:7ce46d3f9f5d 97
Navin 0:7ce46d3f9f5d 98 while(temp != NULL) {
Navin 0:7ce46d3f9f5d 99 if(temp->service_flag == flag) {
Navin 0:7ce46d3f9f5d 100 return temp;
Navin 0:7ce46d3f9f5d 101 }
Navin 0:7ce46d3f9f5d 102 temp = temp->next_service;
Navin 0:7ce46d3f9f5d 103 }
Navin 0:7ce46d3f9f5d 104
Navin 0:7ce46d3f9f5d 105 return NULL;
Navin 0:7ce46d3f9f5d 106 }
Navin 0:7ce46d3f9f5d 107
Navin 0:7ce46d3f9f5d 108
Navin 0:7ce46d3f9f5d 109 /**
Navin 0:7ce46d3f9f5d 110 * \fn MainLoop(void)
Navin 0:7ce46d3f9f5d 111 * \brief This function waits for a flag and then calls appropraite service
Navin 0:7ce46d3f9f5d 112 * \param none
Navin 0:7ce46d3f9f5d 113 * \return none
Navin 0:7ce46d3f9f5d 114 * \note This function never returns has a while(1) at its heart
Navin 0:7ce46d3f9f5d 115 */
Navin 0:7ce46d3f9f5d 116
Navin 0:7ce46d3f9f5d 117 void TransLayer::MainLoop(Console * cons, PerAccess * per)
Navin 0:7ce46d3f9f5d 118 {
Navin 0:7ce46d3f9f5d 119 char temp, cmd=0;
Navin 0:7ce46d3f9f5d 120 char data_buff[20];
Navin 0:7ce46d3f9f5d 121 bool start_flag = false, data_start_flag=false, packet_formed = false;
Navin 0:7ce46d3f9f5d 122 int i =0;
Navin 0:7ce46d3f9f5d 123
Navin 0:7ce46d3f9f5d 124
Navin 0:7ce46d3f9f5d 125 while(1) {
Navin 0:7ce46d3f9f5d 126 if(cons->available() > 0) {
Navin 0:7ce46d3f9f5d 127 temp = cons->getCh();
Navin 0:7ce46d3f9f5d 128 if(PACKET_START == temp && data_start_flag == false) {
Navin 0:7ce46d3f9f5d 129 // start of packet, siganl the starting of packet
Navin 0:7ce46d3f9f5d 130 start_flag = true;
Navin 0:7ce46d3f9f5d 131 i=0;
Navin 0:7ce46d3f9f5d 132 } else if (start_flag == true) {
Navin 0:7ce46d3f9f5d 133 cmd = temp; // this the flag that is going to indicate the service
Navin 0:7ce46d3f9f5d 134 start_flag = false;
Navin 0:7ce46d3f9f5d 135 data_start_flag = true;
Navin 0:7ce46d3f9f5d 136 } else if(data_start_flag == true) {
Navin 0:7ce46d3f9f5d 137
Navin 0:7ce46d3f9f5d 138 if(temp != 0x0d || temp != 0x0a || temp != '\n') {
Navin 0:7ce46d3f9f5d 139 data_buff[i] = temp;
Navin 0:7ce46d3f9f5d 140 i++;
Navin 0:7ce46d3f9f5d 141 }
Navin 0:7ce46d3f9f5d 142 if(temp == 0x0d || temp == 0x0a) {
Navin 0:7ce46d3f9f5d 143 data_buff[i] = '\0';
Navin 0:7ce46d3f9f5d 144 packet_formed = true;
Navin 0:7ce46d3f9f5d 145 data_start_flag = false;
Navin 0:7ce46d3f9f5d 146 }
Navin 0:7ce46d3f9f5d 147
Navin 0:7ce46d3f9f5d 148 }
Navin 0:7ce46d3f9f5d 149 if(packet_formed == true) {
Navin 0:7ce46d3f9f5d 150 service_ptr ser;
Navin 0:7ce46d3f9f5d 151 //SeeServices();
Navin 0:7ce46d3f9f5d 152 ser = LookForService(cmd);
Navin 0:7ce46d3f9f5d 153 if(ser != NULL) {
Navin 0:7ce46d3f9f5d 154 ser->service_function(cons, per, data_buff, i);
Navin 0:7ce46d3f9f5d 155 }
Navin 0:7ce46d3f9f5d 156 packet_formed = false;
Navin 0:7ce46d3f9f5d 157 }
Navin 0:7ce46d3f9f5d 158 }
Navin 0:7ce46d3f9f5d 159 }
Navin 0:7ce46d3f9f5d 160 }
Navin 0:7ce46d3f9f5d 161
Navin 0:7ce46d3f9f5d 162
Navin 0:7ce46d3f9f5d 163
Navin 0:7ce46d3f9f5d 164
Navin 0:7ce46d3f9f5d 165