MAIN

Dependencies:   LPS25H hts221

Fork of SOFT253_Template_Weather_OS_54 by Stage-1 Students SoCEM

Committer:
J_Satchell
Date:
Mon May 15 11:38:07 2017 +0000
Revision:
37:13f74964a045
Parent:
36:af6abc6f7590
fff

Who changed what in which revision?

UserRevisionLine numberNew contents of line
J_Satchell 36:af6abc6f7590 1 #include "Data.hpp"
J_Satchell 37:13f74964a045 2 /* log holds all functions for storing records in circular buffer*/
J_Satchell 36:af6abc6f7590 3 Data queue_array[120];
J_Satchell 36:af6abc6f7590 4 int rear = 0;
J_Satchell 36:af6abc6f7590 5 int front = 0;
J_Satchell 36:af6abc6f7590 6
J_Satchell 36:af6abc6f7590 7 Mutex mutex_l;
J_Satchell 36:af6abc6f7590 8
J_Satchell 36:af6abc6f7590 9 void log_init()
J_Satchell 36:af6abc6f7590 10 {
J_Satchell 36:af6abc6f7590 11
J_Satchell 36:af6abc6f7590 12 }
J_Satchell 36:af6abc6f7590 13
J_Satchell 37:13f74964a045 14 /*pushes new record on front of queue*/
J_Satchell 36:af6abc6f7590 15 void log_push(Data data)
J_Satchell 36:af6abc6f7590 16 {
J_Satchell 36:af6abc6f7590 17 rear = (rear + 1) % 120;
J_Satchell 36:af6abc6f7590 18
J_Satchell 36:af6abc6f7590 19 if (rear == front){
J_Satchell 36:af6abc6f7590 20 front = (front + 1) % 120;
J_Satchell 36:af6abc6f7590 21 }
J_Satchell 36:af6abc6f7590 22
J_Satchell 36:af6abc6f7590 23 queue_array[rear] = data;
J_Satchell 36:af6abc6f7590 24 }
J_Satchell 36:af6abc6f7590 25
J_Satchell 37:13f74964a045 26 /*deletes a record*/
J_Satchell 36:af6abc6f7590 27 Data log_pop()
J_Satchell 36:af6abc6f7590 28 {
J_Satchell 36:af6abc6f7590 29 Data record;
J_Satchell 36:af6abc6f7590 30 if (front != rear)
J_Satchell 36:af6abc6f7590 31 { record = queue_array[rear];
J_Satchell 36:af6abc6f7590 32 rear = (rear + 1) % 120;
J_Satchell 36:af6abc6f7590 33 }
J_Satchell 36:af6abc6f7590 34 return record;
J_Satchell 36:af6abc6f7590 35
J_Satchell 36:af6abc6f7590 36 }
J_Satchell 36:af6abc6f7590 37
J_Satchell 37:13f74964a045 38 /*gets length of array*/
J_Satchell 36:af6abc6f7590 39 int log_length()
J_Satchell 36:af6abc6f7590 40 {
J_Satchell 36:af6abc6f7590 41
J_Satchell 36:af6abc6f7590 42 int length;
J_Satchell 36:af6abc6f7590 43 length = (120 + rear - front) % 120;
J_Satchell 36:af6abc6f7590 44
J_Satchell 36:af6abc6f7590 45 return length;
J_Satchell 36:af6abc6f7590 46
J_Satchell 36:af6abc6f7590 47 }
J_Satchell 36:af6abc6f7590 48
J_Satchell 37:13f74964a045 49 /*gets a specific record*/
J_Satchell 36:af6abc6f7590 50 Data log_get(int index)
J_Satchell 36:af6abc6f7590 51 {
J_Satchell 36:af6abc6f7590 52
J_Satchell 36:af6abc6f7590 53 Data record;
J_Satchell 36:af6abc6f7590 54 record = queue_array[(front + index) % 120];
J_Satchell 36:af6abc6f7590 55
J_Satchell 36:af6abc6f7590 56 return record;
J_Satchell 36:af6abc6f7590 57
J_Satchell 36:af6abc6f7590 58 }